1 /*******************************************************************
2 
3 Part of the Fritzing project - http://fritzing.org
4 Copyright (c) 2007-2014 Fachhochschule Potsdam - http://fh-potsdam.de
5 
6 Fritzing is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10 
11 Fritzing is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with Fritzing.  If not, see <http://www.gnu.org/licenses/>.
18 
19 ********************************************************************
20 
21 $Revision: 6912 $:
22 $Author: irascibl@gmail.com $:
23 $Date: 2013-03-09 08:18:59 +0100 (Sa, 09. Mrz 2013) $
24 
25 ********************************************************************/
26 
27 #include "infographicsview.h"
28 #include "../debugdialog.h"
29 #include "../infoview/htmlinfoview.h"
30 
31 #include <QMessageBox>
32 
33 static LayerHash ViewLayers;
34 
InfoGraphicsView(QWidget * parent)35 InfoGraphicsView::InfoGraphicsView( QWidget * parent )
36 	: ZoomableGraphicsView(parent)
37 {
38 	m_infoView = NULL;
39 	m_boardLayers = 1;
40 	m_hoverEnterMode = m_hoverEnterConnectorMode = false;
41     m_smdOrientation = Qt::Vertical;
42 }
43 
viewItemInfo(ItemBase * item)44 void InfoGraphicsView::viewItemInfo(ItemBase * item) {
45 	if (m_infoView == NULL) return;
46 
47 	m_infoView->viewItemInfo(this, item ? item->layerKinChief() : item, swappingEnabled(item));
48 }
49 
hoverEnterItem(QGraphicsSceneHoverEvent * event,ItemBase * itemBase)50 void InfoGraphicsView::hoverEnterItem(QGraphicsSceneHoverEvent * event, ItemBase * itemBase) {
51 	if (m_infoView == NULL) return;
52 
53 	if (event->modifiers() & Qt::ShiftModifier || itemBase->viewID() == ViewLayer::IconView) {
54 		m_hoverEnterMode = true;
55 		m_infoView->hoverEnterItem(this, event, itemBase ? itemBase->layerKinChief() : itemBase, swappingEnabled(itemBase));
56 	}
57 }
58 
hoverLeaveItem(QGraphicsSceneHoverEvent * event,ItemBase * itemBase)59 void InfoGraphicsView::hoverLeaveItem(QGraphicsSceneHoverEvent * event, ItemBase * itemBase) {
60 	if (m_infoView == NULL) return;
61 
62 	if (m_hoverEnterMode) {
63 		m_hoverEnterMode = false;
64 		m_infoView->hoverLeaveItem(this, event, itemBase ? itemBase->layerKinChief() : itemBase);
65 	}
66 }
67 
hoverEnterConnectorItem(QGraphicsSceneHoverEvent * event,ConnectorItem * item)68 void InfoGraphicsView::hoverEnterConnectorItem(QGraphicsSceneHoverEvent * event, ConnectorItem * item) {
69 	if (m_infoView == NULL) return;
70 
71 	if (event->modifiers() & Qt::ShiftModifier) {
72 		m_hoverEnterConnectorMode = true;
73 		m_infoView->hoverEnterConnectorItem(this, event, item, swappingEnabled(item->attachedTo()));
74 	}
75 }
76 
hoverLeaveConnectorItem(QGraphicsSceneHoverEvent * event,ConnectorItem * item)77 void InfoGraphicsView::hoverLeaveConnectorItem(QGraphicsSceneHoverEvent * event, ConnectorItem * item){
78 	if (m_infoView == NULL) return;
79 
80 	if (m_hoverEnterConnectorMode) {
81 		m_hoverEnterConnectorMode = false;
82 		m_infoView->hoverLeaveConnectorItem(this, event, item);
83 	}
84 }
85 
setInfoView(HtmlInfoView * infoView)86 void InfoGraphicsView::setInfoView(HtmlInfoView * infoView) {
87 	m_infoView = infoView;
88 }
89 
infoView()90 HtmlInfoView * InfoGraphicsView::infoView() {
91 	return m_infoView;
92 }
93 
mousePressConnectorEvent(ConnectorItem *,QGraphicsSceneMouseEvent *)94 void InfoGraphicsView::mousePressConnectorEvent(ConnectorItem *, QGraphicsSceneMouseEvent *) {
95 }
96 
hidePartLabel(ItemBase * item)97 void InfoGraphicsView::hidePartLabel(ItemBase * item) {
98 	Q_UNUSED(item);
99 }
100 
partLabelChanged(ItemBase * item,const QString & oldText,const QString & newText)101 void InfoGraphicsView::partLabelChanged(ItemBase * item, const QString &oldText, const QString & newText) {
102 	Q_UNUSED(item);
103 	Q_UNUSED(oldText);
104 	Q_UNUSED(newText);
105 }
106 
noteChanged(ItemBase * item,const QString & oldText,const QString & newText,QSizeF oldSize,QSizeF newSize)107 void InfoGraphicsView::noteChanged(ItemBase * item, const QString &oldText, const QString & newText, QSizeF oldSize, QSizeF newSize) {
108 	Q_UNUSED(item);
109 	Q_UNUSED(oldText);
110 	Q_UNUSED(newText);
111 	Q_UNUSED(oldSize);
112 	Q_UNUSED(newSize);
113 }
114 
selectedAux()115 QGraphicsItem *InfoGraphicsView::selectedAux() {
116 	QList<QGraphicsItem*> selItems = scene()->selectedItems();
117 	if(selItems.size() != 1) {
118 		return NULL;
119 	} else {
120 		return selItems[0];
121 	}
122 }
123 
partLabelMoved(ItemBase * itemBase,QPointF oldPos,QPointF oldOffset,QPointF newPos,QPointF newOffset)124 void InfoGraphicsView::partLabelMoved(ItemBase * itemBase, QPointF oldPos, QPointF oldOffset, QPointF newPos, QPointF newOffset)
125 {
126 	Q_UNUSED(itemBase);
127 	Q_UNUSED(oldPos);
128 	Q_UNUSED(oldOffset);
129 	Q_UNUSED(newPos);
130 	Q_UNUSED(newOffset);
131 }
132 
rotateFlipPartLabel(ItemBase * itemBase,double degrees,Qt::Orientations flipDirection)133 void InfoGraphicsView::rotateFlipPartLabel(ItemBase * itemBase, double degrees, Qt::Orientations flipDirection) {
134 	Q_UNUSED(itemBase);
135 	Q_UNUSED(degrees);
136 	Q_UNUSED(flipDirection);
137 }
138 
noteSizeChanged(ItemBase * itemBase,const QSizeF & oldSize,const QSizeF & newSize)139 void InfoGraphicsView::noteSizeChanged(ItemBase * itemBase, const QSizeF & oldSize, const QSizeF & newSize) {
140 	Q_UNUSED(itemBase);
141     Q_UNUSED(oldSize);
142     Q_UNUSED(newSize);
143 }
144 
spaceBarIsPressed()145 bool InfoGraphicsView::spaceBarIsPressed() {
146 	return false;
147 }
148 
getInfoGraphicsView(QGraphicsItem * item)149 InfoGraphicsView * InfoGraphicsView::getInfoGraphicsView(QGraphicsItem * item)
150 {
151 	if (item == NULL) return NULL;
152 
153 	QGraphicsScene * scene = item->scene();
154 	if (scene == NULL) return NULL;
155 
156 	return dynamic_cast<InfoGraphicsView *>(scene->parent());
157 }
158 
initWire(Wire *,int penWidth)159 void InfoGraphicsView::initWire(Wire *, int penWidth) {
160 	Q_UNUSED(penWidth);
161 }
162 
163 
getBendpointWidths(class Wire *,double w,double & w1,double & w2,bool & negativeOffsetRect)164 void InfoGraphicsView::getBendpointWidths(class Wire *, double w, double & w1, double & w2, bool & negativeOffsetRect) {
165 	Q_UNUSED(w);
166 	Q_UNUSED(w1);
167 	Q_UNUSED(w2);
168 	Q_UNUSED(negativeOffsetRect);
169 }
170 
getLabelFont(QFont &,QColor &,ItemBase *)171 void InfoGraphicsView::getLabelFont(QFont &, QColor &, ItemBase *) {
172 }
173 
getLabelFontSizeTiny()174 double InfoGraphicsView::getLabelFontSizeTiny() {
175         return 5;
176 }
177 
getLabelFontSizeSmall()178 double InfoGraphicsView::getLabelFontSizeSmall() {
179 	return 7;
180 }
181 
getLabelFontSizeMedium()182 double InfoGraphicsView::getLabelFontSizeMedium() {
183 	return 9;
184 }
185 
getLabelFontSizeLarge()186 double InfoGraphicsView::getLabelFontSizeLarge() {
187 	return 14;
188 }
189 
hasBigDots()190 bool InfoGraphicsView::hasBigDots() {
191 	return false;
192 }
193 
setVoltage(double v,bool doEmit)194 void InfoGraphicsView::setVoltage(double v, bool doEmit) {
195 	if (doEmit) {
196 		emit setVoltageSignal(v, false);
197 	}
198 }
199 
resizeBoard(double w,double h,bool doEmit)200 void InfoGraphicsView::resizeBoard(double w, double h, bool doEmit) {
201 	Q_UNUSED(w);
202 	Q_UNUSED(h);
203 	Q_UNUSED(doEmit);
204 }
205 
setResistance(QString resistance,QString pinSpacing)206 void InfoGraphicsView::setResistance(QString resistance, QString pinSpacing)
207 {
208 	Q_UNUSED(resistance);
209 	Q_UNUSED(pinSpacing);
210 }
211 
setProp(ItemBase * item,const QString & prop,const QString & trProp,const QString & oldValue,const QString & newValue,bool redraw)212 void InfoGraphicsView::setProp(ItemBase * item, const QString & prop, const QString & trProp, const QString & oldValue, const QString & newValue, bool redraw)
213 {
214 	Q_UNUSED(item);
215 	Q_UNUSED(prop);
216 	Q_UNUSED(trProp);
217 	Q_UNUSED(oldValue);
218 	Q_UNUSED(newValue);
219 	Q_UNUSED(redraw);
220 }
221 
setHoleSize(ItemBase * item,const QString & prop,const QString & trProp,const QString & oldValue,const QString & newValue,QRectF & oldRect,QRectF & newRect,bool redraw)222 void InfoGraphicsView::setHoleSize(ItemBase * item, const QString & prop, const QString & trProp, const QString & oldValue, const QString & newValue, QRectF & oldRect, QRectF & newRect, bool redraw)
223 {
224 	Q_UNUSED(item);
225 	Q_UNUSED(prop);
226 	Q_UNUSED(trProp);
227 	Q_UNUSED(oldValue);
228 	Q_UNUSED(newValue);
229 	Q_UNUSED(oldRect);
230 	Q_UNUSED(newRect);
231 	Q_UNUSED(redraw);
232 }
233 
changeWireWidthMils(const QString newWidth)234 void InfoGraphicsView::changeWireWidthMils(const QString newWidth) {
235 	Q_UNUSED(newWidth);
236 }
237 
changeWireColor(const QString newColor)238 void InfoGraphicsView::changeWireColor(const QString newColor) {
239 	Q_UNUSED(newColor);
240 }
241 
swap(const QString & family,const QString & prop,QMap<QString,QString> & propsMap,ItemBase * itemBase)242 void InfoGraphicsView::swap(const QString & family, const QString & prop, QMap<QString, QString> & propsMap, ItemBase * itemBase) {
243 	emit swapSignal(family, prop, propsMap, itemBase);
244 }
245 
setInstanceTitle(long id,const QString & oldTitle,const QString & newTitle,bool isUndoable,bool doEmit)246 void InfoGraphicsView::setInstanceTitle(long id, const QString & oldTitle, const QString & newTitle, bool isUndoable, bool doEmit) {
247 	Q_UNUSED(id);
248 	Q_UNUSED(newTitle);
249 	Q_UNUSED(oldTitle);
250 	Q_UNUSED(isUndoable);
251 	Q_UNUSED(doEmit);
252 }
253 
viewLayers()254 LayerHash & InfoGraphicsView::viewLayers() {
255 	return ViewLayers;
256 }
257 
loadLogoImage(ItemBase *,const QString & oldSvg,const QSizeF oldAspectRatio,const QString & oldFilename,const QString & newFilename,bool addName)258 void InfoGraphicsView::loadLogoImage(ItemBase *, const QString & oldSvg, const QSizeF oldAspectRatio, const QString & oldFilename, const QString & newFilename, bool addName) {
259 	Q_UNUSED(oldSvg);
260 	Q_UNUSED(oldAspectRatio);
261 	Q_UNUSED(oldFilename);
262 	Q_UNUSED(newFilename);
263 	Q_UNUSED(addName);
264 }
265 
setNoteFocus(QGraphicsItem * item,bool inFocus)266 void InfoGraphicsView::setNoteFocus(QGraphicsItem * item, bool inFocus) {
267 	Q_UNUSED(item);
268 	Q_UNUSED(inFocus);
269 }
270 
setBoardLayers(int layers,bool redraw)271 void InfoGraphicsView::setBoardLayers(int layers, bool redraw) {
272 	Q_UNUSED(redraw);
273 	m_boardLayers = layers;
274 }
275 
boardLayers()276 int InfoGraphicsView::boardLayers() {
277 	return m_boardLayers;
278 }
279 
makeOneRatsnestWire(ConnectorItem * source,ConnectorItem * dest,bool routed,QColor color,bool force)280 VirtualWire * InfoGraphicsView::makeOneRatsnestWire(ConnectorItem * source, ConnectorItem * dest, bool routed, QColor color, bool force) {
281 	Q_UNUSED(source);
282 	Q_UNUSED(dest);
283 	Q_UNUSED(routed);
284 	Q_UNUSED(color);
285 	Q_UNUSED(force);
286 	return NULL;
287 }
288 
getRatsnestColor(QColor & color)289 void InfoGraphicsView::getRatsnestColor(QColor & color)
290 {
291 	Q_UNUSED(color);
292 }
293 
changeBus(ItemBase *,bool connect,const QString & oldBus,const QString & newBus,QList<ConnectorItem * > &,const QString & message,const QString & oldLayout,const QString & newLayout)294 void InfoGraphicsView::changeBus(ItemBase *, bool connect, const QString & oldBus, const QString & newBus, QList<ConnectorItem *> &, const QString & message, const QString & oldLayout, const QString & newLayout)
295 {
296 	Q_UNUSED(connect);
297 	Q_UNUSED(oldBus);
298 	Q_UNUSED(newBus);
299 	Q_UNUSED(message);
300     Q_UNUSED(oldLayout);
301     Q_UNUSED(newLayout);
302 }
303 
filenameIf()304 const QString & InfoGraphicsView::filenameIf()
305 {
306 	return ___emptyString___;
307 }
308 
generateCopperFillUnit(ItemBase * itemBase,QPointF whereToStart)309 QString InfoGraphicsView::generateCopperFillUnit(ItemBase * itemBase, QPointF whereToStart)
310 {
311 	Q_UNUSED(itemBase);
312 	Q_UNUSED(whereToStart);
313 	return "";
314 }
315 
prepLegSelection(ItemBase *)316 void InfoGraphicsView::prepLegSelection(ItemBase *)
317 {
318 }
319 
prepLegBendpointMove(ConnectorItem * from,int index,QPointF oldPos,QPointF newPos,ConnectorItem * to,bool changeConnections)320 void InfoGraphicsView::prepLegBendpointMove(ConnectorItem * from, int index, QPointF oldPos, QPointF newPos, ConnectorItem * to, bool changeConnections)
321 {
322 	Q_UNUSED(from);
323 	Q_UNUSED(index);
324 	Q_UNUSED(oldPos);
325 	Q_UNUSED(newPos);
326 	Q_UNUSED(to);
327 	Q_UNUSED(changeConnections);
328 }
329 
prepLegCurveChange(ConnectorItem * from,int index,const class Bezier *,const class Bezier *,bool triggerFirstTime)330 void InfoGraphicsView::prepLegCurveChange(ConnectorItem * from, int index, const class Bezier *, const class Bezier *, bool triggerFirstTime)
331 {
332 	Q_UNUSED(from);
333 	Q_UNUSED(index);
334 	Q_UNUSED(triggerFirstTime);
335 }
336 
prepLegBendpointChange(ConnectorItem *,int oldCount,int newCount,int index,QPointF,const class Bezier *,const class Bezier *,const class Bezier *,bool triggerFirstTime)337 void InfoGraphicsView::prepLegBendpointChange(ConnectorItem *, int oldCount, int newCount, int index, QPointF, const class Bezier *, const class Bezier *, const class Bezier *, bool triggerFirstTime)
338 {
339 	Q_UNUSED(triggerFirstTime);
340 	Q_UNUSED(index);
341 	Q_UNUSED(oldCount);
342 	Q_UNUSED(newCount);
343 }
344 
getWireStrokeWidth(Wire *,double wireWidth)345 double InfoGraphicsView::getWireStrokeWidth(Wire *, double wireWidth)
346 {
347 	return wireWidth;
348 }
349 
curvyWiresIndicated(Qt::KeyboardModifiers)350 bool InfoGraphicsView::curvyWiresIndicated(Qt::KeyboardModifiers)
351 {
352 	return true;
353 }
354 
triggerRotate(ItemBase *,double degrees)355 void InfoGraphicsView::triggerRotate(ItemBase *, double degrees)
356 {
357 	Q_UNUSED(degrees);
358 }
359 
changePinLabels(ItemBase * itemBase,bool singleRow)360 void InfoGraphicsView::changePinLabels(ItemBase * itemBase, bool singleRow)
361 {
362 	Q_UNUSED(itemBase);
363 	Q_UNUSED(singleRow);
364 }
365 
renamePins(ItemBase *,const QStringList & oldLabels,const QStringList & newLabels,bool singleRow)366 void InfoGraphicsView::renamePins(ItemBase *, const QStringList & oldLabels, const QStringList & newLabels, bool singleRow)
367 {
368 	Q_UNUSED(oldLabels);
369 	Q_UNUSED(newLabels);
370 	Q_UNUSED(singleRow);
371 }
372 
getTraceFlag()373 ViewGeometry::WireFlag InfoGraphicsView::getTraceFlag()
374 {
375 	return ViewGeometry::NoFlag;
376 }
377 
setAnyInRotation()378 void InfoGraphicsView::setAnyInRotation()
379 {
380 }
381 
setActiveWire(Wire * wire)382 void InfoGraphicsView::setActiveWire(Wire * wire)
383 {
384 	emit setActiveWireSignal(wire);
385 }
386 
setActiveConnectorItem(ConnectorItem * connectorItem)387 void InfoGraphicsView::setActiveConnectorItem(ConnectorItem * connectorItem)
388 {
389 	emit setActiveConnectorItemSignal(connectorItem);
390 }
391 
resolveTemporary(bool,ItemBase *)392 void InfoGraphicsView::resolveTemporary(bool, ItemBase *)
393 {
394 }
newWire(Wire * wire)395 void InfoGraphicsView::newWire(Wire * wire)
396 {
397 	bool succeeded = connect(wire, SIGNAL(wireChangedSignal(Wire*, const QLineF & , const QLineF & , QPointF, QPointF, ConnectorItem *, ConnectorItem *)	),
398 			this, SLOT(wireChangedSlot(Wire*, const QLineF & , const QLineF & , QPointF, QPointF, ConnectorItem *, ConnectorItem *)),
399 			Qt::DirectConnection);		// DirectConnection means call the slot directly like a subroutine, without waiting for a thread or queue
400 	succeeded = connect(wire, SIGNAL(wireChangedCurveSignal(Wire*, const Bezier *, const Bezier *, bool)),
401 			this, SLOT(wireChangedCurveSlot(Wire*, const Bezier *, const Bezier *, bool)),
402 			Qt::DirectConnection);		// DirectConnection means call the slot directly like a subroutine, without waiting for a thread or queue
403 	succeeded = succeeded && connect(wire, SIGNAL(wireSplitSignal(Wire*, QPointF, QPointF, const QLineF & )),
404 			this, SLOT(wireSplitSlot(Wire*, QPointF, QPointF, const QLineF & )));
405 	succeeded = succeeded && connect(wire, SIGNAL(wireJoinSignal(Wire*, ConnectorItem *)),
406 			this, SLOT(wireJoinSlot(Wire*, ConnectorItem*)));
407 	if (!succeeded) {
408 		DebugDialog::debug("wire signal connect failed");
409 	}
410 
411 	emit newWireSignal(wire);
412 }
413 
setSMDOrientation(Qt::Orientations orientation)414 void InfoGraphicsView::setSMDOrientation(Qt::Orientations orientation) {
415     m_smdOrientation = orientation;
416 }
417 
smdOrientation()418 Qt::Orientations InfoGraphicsView::smdOrientation() {
419     return m_smdOrientation;
420 }
421 
moveItem(ItemBase *,double x,double y)422 void InfoGraphicsView::moveItem(ItemBase *, double x, double y) {
423     Q_UNUSED(x);
424     Q_UNUSED(y);
425 }
426 
updateRotation(ItemBase * itemBase)427 void InfoGraphicsView::updateRotation(ItemBase * itemBase) {
428     if (m_infoView) m_infoView->updateRotation(itemBase);
429 }
430 
rotateX(double degrees,bool rubberBandLegEnabled,ItemBase * originatingItem)431 void InfoGraphicsView::rotateX(double degrees, bool rubberBandLegEnabled, ItemBase * originatingItem)
432 {
433     Q_UNUSED(degrees);
434     Q_UNUSED(rubberBandLegEnabled);
435     Q_UNUSED(originatingItem);
436 }
437 
438