-
Notifications
You must be signed in to change notification settings - Fork 808
/
sketchwidget.h
761 lines (698 loc) · 40.1 KB
/
sketchwidget.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
/*******************************************************************
Part of the Fritzing project - http://fritzing.org
Copyright (c) 2007-2019 Fritzing
Fritzing is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Fritzing is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fritzing. If not, see <http://www.gnu.org/licenses/>.
********************************************************************/
#ifndef SKETCHWIDGET_H
#define SKETCHWIDGET_H
#include <QGraphicsView>
#include <QGraphicsItem>
#include <QUndoStack>
#include <QRubberBand>
#include <QGraphicsEllipseItem>
#include <QSet>
#include <QHash>
#include <QMap>
#include <QTimer>
#include "../items/paletteitem.h"
#include "../referencemodel/referencemodel.h"
#include "../model/sketchmodel.h"
#include "../viewgeometry.h"
#include "infographicsview.h"
#include "../viewlayer.h"
#include "../utils/misc.h"
#include "../utils/graphutils.h"
#include "../commands.h"
#include "renderthing.h"
struct ItemCount {
int selCount;
int hasLabelCount;
int visLabelCount;
int itemsCount;
int selRotatable;
int sel45Rotatable;
int selHFlipable;
int selVFlipable;
int obsoleteCount;
int moveLockCount;
int wireCount;
};
struct SwapThing {
bool firstTime;
long newID;
ItemBase * itemBase;
long newModelIndex;
QString newModuleID;
ViewLayer::ViewLayerPlacement viewLayerPlacement;
QList<Wire *> wiresToDelete;
QUndoCommand * parentCommand;
QHash<ConnectorItem *, ChangeConnectionCommand *> reconnections;
QHash<ConnectorItem *, Connector *> byWire;
QHash<ConnectorItem *, ConnectorItem *> toConnectorItems;
QHash<ConnectorItem *, Connector *> swappedGender;
SketchWidget * bbView;
QMap<QString, QString> propsMap;
};
class SizeItem : public QObject, public QGraphicsLineItem
{
Q_OBJECT
public:
SizeItem() = default;
~SizeItem() = default;
};
class SketchWidget : public InfoGraphicsView
{
Q_OBJECT
Q_PROPERTY(QColor gridColor READ gridColor WRITE setGridColor DESIGNABLE true)
Q_PROPERTY(double ratsnestWidth READ ratsnestWidth WRITE setRatsnestWidth DESIGNABLE true)
Q_PROPERTY(double ratsnestOpacity READ ratsnestOpacity WRITE setRatsnestOpacity DESIGNABLE true)
public:
SketchWidget(ViewLayer::ViewID, QWidget *parent=0, int size=400, int minSize=300);
~SketchWidget();
void pushCommand(QUndoCommand *, QObject * signalTarget);
class WaitPushUndoStack * undoStack();
ItemBase * addItem(ModelPart *, ViewLayer::ViewLayerPlacement, BaseCommand::CrossViewType, const ViewGeometry &, long id, long modelIndex, AddDeleteItemCommand * originatingCommand);
ItemBase * addItemForCommand(const QString & moduleID, ViewLayer::ViewLayerPlacement, BaseCommand::CrossViewType, const ViewGeometry &, long id, long modelIndex, AddDeleteItemCommand * originatingCommand);
void deleteItemForCommand(long id, bool deleteModelPart, bool doEmit, bool later);
virtual void deleteItem(ItemBase *, bool deleteModelPart, bool doEmit, bool later);
void simpleMoveItemForCommand(long id, QPointF);
void moveItemForCommand(long id, ViewGeometry &, bool updateRatsnest);
void moveItem(long id, const QPointF & p, bool updateRatsnest);
void updateWireForCommand(long id, const QString & connectorID, bool updateRatsnest);
void rotateItemForCommand(long id, double degrees);
void transformItemForCommand(long id, const QTransform &);
void flipItemForCommand(long id, Qt::Orientations orientation);
void selectItemForCommand(long id, bool state, bool updateInfoView, bool doEmit);
void selectItem(ItemBase * itemBase);
void selectItems(QList<ItemBase *>);
void selectItemsWithModuleID(ModelPart *);
void addToSketch(QList<ModelPart *> &);
void selectDeselectAllCommand(bool state);
void changeWireForCommand(long fromID, QLineF line, QPointF pos, bool updateConnections, bool updateRatsnest);
void changeLegForCommand(long fromID, const QString & connectorID, const QPolygonF &, bool relative, const QString & why);
void recalcLegForCommand(long fromID, const QString & connectorID, const QPolygonF &, bool relative, bool active, const QString & why);
void rotateLegForCommand(long fromID, const QString & connectorID, const QPolygonF &, bool active);
void cut();
void copy();
void setReferenceModel(class ReferenceModel *referenceModel);
class ReferenceModel * referenceModel();
void setSketchModel(SketchModel *);
void setUndoStack(class WaitPushUndoStack *);
void clearSelection();
virtual void loadFromModelParts(QList<ModelPart *> & modelParts, BaseCommand::CrossViewType, QUndoCommand * parentCommand,
bool offsetPaste, const QRectF * boundingRect, bool seekOutsideConnections, QList<long> & newIDs);
void changeZForCommand(QHash<long, RealPair * >, double (*pairAccessor)(RealPair *) );
void sendToBack();
void sendBackward();
void bringForward();
void bringToFront();
void alignItems(Qt::Alignment);
double fitInWindow();
void rotateX(double degrees, bool rubberBandLegEnabled, ItemBase * originatingItem);
void flipX(Qt::Orientations orientation, bool rubberBandLegEnabled);
void addBendpoint(ItemBase * lastHoverEnterItem, ConnectorItem * lastHoverEnterConnectorItem, QPointF lastLocation);
void flattenCurve(ItemBase * lastHoverEnterItem, ConnectorItem * lastHoverEnterConnectorItem, QPointF lastLocation);
void deleteSelected(Wire *, bool minus);
PaletteItem *getSelectedPart();
void addViewLayer(ViewLayer *);
void setAllLayersVisible(bool visible);
void setLayerVisible(ViewLayer * viewLayer, bool visible, bool doChildLayers);
void setLayerVisible(ViewLayer::ViewLayerID viewLayerID, bool visible, bool doChildLayers);
void setLayerActive(ViewLayer * viewLayer, bool active);
void setLayerActive(ViewLayer::ViewLayerID viewLayerID, bool active);
bool layerIsVisible(ViewLayer::ViewLayerID);
bool layerIsActive(ViewLayer::ViewLayerID);
void sortAnyByZ(const QList<QGraphicsItem *> & items, QList<ItemBase *> & bases);
void mousePressConnectorEvent(ConnectorItem *, QGraphicsSceneMouseEvent *);
void setBackground(QColor);
void setBackgroundColor(QColor, bool setPref);
const QColor& background();
QColor standardBackground();
void setItemMenu(QMenu*);
void setWireMenu(QMenu*);
virtual void changeConnection(long fromID,
const QString & fromConnectorID,
long toID, const QString & toConnectorID,
ViewLayer::ViewLayerPlacement,
bool connect, bool doEmit,
bool updateConnections);
ItemCount calcItemCount();
constexpr ViewLayer::ViewID viewID() const noexcept { return m_viewID; }
void setViewLayerIDs(ViewLayer::ViewLayerID part, ViewLayer::ViewLayerID wire, ViewLayer::ViewLayerID connector, ViewLayer::ViewLayerID ruler, ViewLayer::ViewLayerID note);
void stickemForCommand(long stickTargetID, long stickSourceID, bool stick);
void stickyScoop(ItemBase * stickyOne, bool checkCurrent, CheckStickyCommand *);
void setChainDrag(bool);
void hoverEnterItem(QGraphicsSceneHoverEvent * event, ItemBase * item);
void hoverLeaveItem(QGraphicsSceneHoverEvent * event, ItemBase * item);
void hoverEnterConnectorItem(QGraphicsSceneHoverEvent * event, ConnectorItem * item);
void hoverLeaveConnectorItem(QGraphicsSceneHoverEvent * event, ConnectorItem * item);
void cleanUpWiresForCommand(bool doEmit, class CleanUpWiresCommand *);
void partLabelChanged(ItemBase *, const QString & oldText, const QString &newtext);
void noteChanged(ItemBase *, const QString & oldText, const QString &newtext, QSizeF oldSize, QSizeF newSize);
void setInfoViewOnHover(bool infoViewOnHover);
virtual ItemBase * addItemAux(ModelPart *, ViewLayer::ViewLayerPlacement, const ViewGeometry &, long id, bool doConnectors, ViewLayer::ViewID, bool temporary);
ItemBase * addItemAuxTemp(ModelPart *, ViewLayer::ViewLayerPlacement, const ViewGeometry &, long id, bool doConnectors, ViewLayer::ViewID, bool temporary);
bool swappingEnabled(ItemBase *);
virtual void addViewLayers();
void changeWireColorForCommand(long wireId, const QString& color, double opacity);
void changeWireWidthForCommand(long wireId, double width);
void changeWireFlags(long wireId, ViewGeometry::WireFlags wireFlags);
void setIgnoreSelectionChangeEvents(bool);
void hideConnectors(bool hide);
void saveLayerVisibility();
void restoreLayerVisibility();
void updateRoutingStatus(CleanUpWiresCommand*, RoutingStatus &, bool manual);
void updateRoutingStatus(RoutingStatus &, bool manual);
virtual bool hasAnyNets();
void ensureLayerVisible(ViewLayer::ViewLayerID);
const QString &selectedModuleID();
virtual bool canDeleteItem(QGraphicsItem * item, int count);
virtual bool canCopyItem(QGraphicsItem * item, int count);
constexpr const QString & viewName() const noexcept { return m_viewName; }
void makeDeleteItemCommand(ItemBase * itemBase, BaseCommand::CrossViewType, QUndoCommand * parentCommand);
virtual void forwardRoutingStatusForCommand(const RoutingStatus &);
void collectParts(QList<ItemBase *> & partList);
void movePartLabelForCommand(long itemID, QPointF newPos, QPointF newOffset);
void updateInfoView();
virtual void setCurrent(bool current);
void partLabelMoved(ItemBase *, QPointF oldPos, QPointF oldOffset, QPointF newPos, QPointF newOffset);
void rotateFlipPartLabelForCommand(ItemBase *, double degrees, Qt::Orientations flipDirection);
void rotateFlipPartLabelForCommand(long itemID, double degrees, Qt::Orientations flipDirection);
void showPartLabels(bool show);
void hidePartLabel(ItemBase * item);
void noteSizeChanged(ItemBase * itemBase, const QSizeF & oldSize, const QSizeF & newSize);
void resizeNoteForCommand(long itemID, const QSizeF & );
class SelectItemCommand* stackSelectionState(bool pushIt, QUndoCommand * parentCommand);
QString renderToSVG(RenderThing &, QGraphicsItem * board, const LayerList &, bool applyViewFromBelow = false);
bool spaceBarIsPressed() noexcept;
virtual long setUpSwap(SwapThing &, bool master);
ConnectorItem * lastHoverEnterConnectorItem();
ItemBase * lastHoverEnterItem();
LayerHash & viewLayers();
virtual void createTrace(Wire*, bool useLastWireColor);
virtual void selectAllWires(ViewGeometry::WireFlag);
virtual void tidyWires();
const QString & getShortName();
virtual void setClipEnds(class ClipableWire *, bool);
void getBendpointWidths(class Wire *, double w, double & w1, double & w2, bool & negativeOffsetRect);
virtual bool includeSymbols();
void disconnectAll();
virtual bool canDisconnectAll();
virtual bool ignoreFemale();
virtual ViewLayer::ViewLayerID getWireViewLayerID(const ViewGeometry & viewGeometry, ViewLayer::ViewLayerPlacement);
ItemBase * findItem(long id);
long createWire(ConnectorItem * from, ConnectorItem * to, ViewGeometry::WireFlags, bool dontUpdate, BaseCommand::CrossViewType, QUndoCommand * parentCommand);
QList<ItemBase *> selectAllObsolete();
int selectAllMoveLock();
void setMoveLockForCommand(long id, bool lock);
bool partLabelsVisible();
void restorePartLabelForCommand(long itemID, QDomElement & element);
void loadLogoImage(ItemBase *, const QString & oldSvg, const QSizeF oldAspectRatio, const QString & oldFilename, const QString & newFilename, bool addName);
void loadLogoImage(long itemID, const QString & oldSvg, const QSizeF oldAspectRatio, const QString & oldFilename);
void loadLogoImage(long itemID, const QString & newFilename, bool addName);
void setNoteFocus(QGraphicsItem *, bool inFocus);
void alignToGrid(bool);
bool alignedToGrid();
void showGrid(bool);
bool showingGrid();
void setGridSize(const QString &);
QString gridSizeText();
void saveZoom(double);
double retrieveZoom();
void initGrid();
virtual double defaultGridSizeInches();
void clearPasteOffset();
virtual ViewLayer::ViewLayerPlacement defaultViewLayerPlacement(ModelPart *);
void collectAllNets(QHash<class ConnectorItem *, int> & indexer, QList< QList<class ConnectorItem *>* > & allPartConnectorItems, bool includeSingletons, bool bothSides);
virtual bool routeBothSides();
virtual void changeLayerForCommand(long id, double z, ViewLayer::ViewLayerID viewLayerID);
void ratsnestConnect(ConnectorItem * connectorItem, bool connect);
void ratsnestConnect(ItemBase *, bool connect);
void ratsnestConnect(ConnectorItem * c1, ConnectorItem * c2, bool connect, bool wait);
virtual void addDefaultParts();
float getTopZ();
QGraphicsItem * addWatermark(const QString & filename);
void copyHeart(QList<ItemBase *> & bases, bool saveBoundingRects, QByteArray & itemData, QList<long> & modelIndexes);
void pasteHeart(QByteArray & itemData, bool seekOutsideConnections);
ViewGeometry::WireFlag getTraceFlag();
void changeBus(ItemBase *, bool connec, const QString & oldBus, const QString & newBus, QList<ConnectorItem *> &, const QString & message, const QString & oldLayout, const QString & newLayout);
const QString & filenameIf();
void setItemDropOffsetForCommand(long id, QPointF offset);
void prepLegBendpointMove(ConnectorItem * from, int index, QPointF oldPos, QPointF newPos, ConnectorItem * to, bool changeConnections);
void prepLegCurveChange(ConnectorItem * from, int index, const class Bezier * oldB, const class Bezier * newB, bool triggerFirstTime);
void prepLegBendpointChange(ConnectorItem * from, int oldCount, int newCount, int index, QPointF pos, const class Bezier *, const class Bezier *, const class Bezier *, bool triggerFirstTime);
void prepLegSelection(ItemBase *);
void changeWireCurveForCommand(long id, const Bezier *, bool autoroutable);
void changeLegCurveForCommand(long id, const QString & connectorID, int index, const Bezier *);
void addLegBendpointForCommand(long id, const QString & connectorID, int index, QPointF, const class Bezier *, const class Bezier *);
void removeLegBendpointForCommand(long id, const QString & connectorID, int index, const class Bezier *);
void moveLegBendpointForCommand(long id, const QString & connectorID, int index, QPointF);
bool curvyWires();
void setCurvyWires(bool);
bool curvyWiresIndicated(Qt::KeyboardModifiers);
void triggerRotate(ItemBase *, double degrees);
void makeWiresChangeConnectionCommands(const QList<Wire *> & wires, QUndoCommand * parentCommand);
void renamePins(ItemBase *, const QStringList & oldLabels, const QStringList & newLabels);
void renamePinsForCommand(long itemID, const QStringList & labels);
void getRatsnestColor(QColor &);
VirtualWire * makeOneRatsnestWire(ConnectorItem * source, ConnectorItem * dest, bool routed, QColor color, bool force);
double ratsnestOpacity();
void setRatsnestOpacity(double);
double ratsnestWidth();
void setRatsnestWidth(double);
void setAnyInRotation();
ConnectorItem * findConnectorItem(ConnectorItem * foreignConnectorItem);
void setGroundFillSeedForCommand(long id, const QString & connectorID, bool seed);
void setWireExtrasForCommand(long id, QDomElement &);
void resolveTemporary(bool, ItemBase *);
virtual bool sameElectricalLayer2(ViewLayer::ViewLayerID, ViewLayer::ViewLayerID);
void deleteMiddle(QSet<ItemBase *> & deletedItems, QUndoCommand * parentCommand);
void setPasting(bool);
void showUnrouted();
QPointF alignOneToGrid(ItemBase * itemBase);
void showEvent(QShowEvent * event);
void blockUI(bool);
void viewItemInfo(ItemBase * item);
virtual QHash<QString, QString> getAutorouterSettings();
virtual void setAutorouterSettings(QHash<QString, QString> &);
void hidePartLayerForCommand(long id, ViewLayer::ViewLayerID, bool hide);
void hidePartLayer(ItemBase *, ViewLayer::ViewLayerID, bool hide);
void moveItem(ItemBase *, double x, double y);
constexpr const QColor& gridColor() const noexcept { return m_gridColor; }
void setGridColor(QColor);
constexpr bool everZoomed() const noexcept { return m_everZoomed; }
void setEverZoomed(bool);
void testConnectors();
void updateWires();
void checkForReversedWires();
void getWireJoinCurves(Wire * wire1, Wire * wire2, QPointF * newPos, QLineF * newLine, Bezier * b0, Bezier * b1);
void setNoteTextForCommand(long itemID, const QString & newText);
void incInstanceTitleForCommand(long id);
void showPartLabelForCommand(long id, bool showIt);
void checkPartLabelLayerVisibilityForCommand(long itemID);
void resizeJumperItem(long id, QPointF pos, QPointF c0, QPointF c1);
protected:
void dragEnterEvent(QDragEnterEvent *);
bool dragEnterEventAux(QDragEnterEvent *);
virtual bool canDropModelPart(ModelPart *);
void dragLeaveEvent(QDragLeaveEvent *);
void dragMoveEvent(QDragMoveEvent *);
void dropEvent(QDropEvent *);
virtual void mousePressEvent(QMouseEvent *);
void mouseMoveEvent(QMouseEvent *);
void mouseReleaseEvent(QMouseEvent *);
void mouseDoubleClickEvent (QMouseEvent *);
void contextMenuEvent(QContextMenuEvent *);
bool viewportEvent(QEvent *);
void paintEvent(QPaintEvent *);
virtual PaletteItem* addPartItem(ModelPart *, ViewLayer::ViewLayerPlacement, PaletteItem *, bool doConnectors, bool & ok, ViewLayer::ViewID, bool temporary);
void clearHoldingSelectItem();
bool startZChange(QList<ItemBase *> & bases);
void continueZChange(QList<ItemBase *> & bases, int start, int end, bool (*test)(int current, int start), int inc, const QString & text);
void continueZChangeMax(QList<ItemBase *> & bases, int start, int end, bool (*test)(int current, int start), int inc, const QString & text);
void continueZChangeAux(QList<ItemBase *> & bases, const QString & text);
virtual ViewLayer::ViewLayerID getDragWireViewLayerID(ConnectorItem *);
ViewLayer::ViewLayerID getPartViewLayerID();
ViewLayer::ViewLayerID getRulerViewLayerID();
ViewLayer::ViewLayerID getConnectorViewLayerID();
virtual ViewLayer::ViewLayerID getLabelViewLayerID(ItemBase *);
ViewLayer::ViewLayerID getNoteViewLayerID();
void dragMoveHighlightConnector(QPoint eventPos);
void addToScene(ItemBase * item, ViewLayer::ViewLayerID viewLayerID);
ConnectorItem * findConnectorItem(ItemBase * item, const QString & connectorID, ViewLayer::ViewLayerPlacement);
bool checkMoved(bool wait);
void changeConnectionAux(long fromID, const QString & fromConnectorID,
long toID, const QString & toConnectorID,
ViewLayer::ViewLayerPlacement,
bool connect, bool updateConnections);
void cutDeleteAux(QString undoStackMessage, bool minus, Wire * wire);
void deleteAux(QSet<ItemBase *> & deletedItems, QUndoCommand * parentCommand, bool doPush);
ChangeConnectionCommand * extendChangeConnectionCommand(BaseCommand::CrossViewType, long fromID, const QString & fromConnectorID,
long toID, const QString & toConnectorID,
ViewLayer::ViewLayerPlacement,
bool connect, QUndoCommand * parent);
ChangeConnectionCommand * extendChangeConnectionCommand(BaseCommand::CrossViewType, ConnectorItem * fromConnectorItem, ConnectorItem * toConnectorItem,
ViewLayer::ViewLayerPlacement,
bool connect, QUndoCommand * parentCommand);
void keyPressEvent(QKeyEvent *);
void keyReleaseEvent(QKeyEvent *);
void clearTemporaries();
void dragWireChanged(class Wire* wire, ConnectorItem * from, ConnectorItem * to);
void dragRatsnestChanged();
void killDroppingItem();
ViewLayer::ViewLayerID getViewLayerID(ModelPart *, ViewLayer::ViewID, ViewLayer::ViewLayerPlacement);
ItemBase * overSticky(ItemBase *);
virtual void setNewPartVisible(ItemBase *);
virtual bool collectFemaleConnectees(ItemBase *, QSet<ItemBase *> &);
virtual bool checkUnder();
virtual void findConnectorsUnder(ItemBase * item);
bool currentlyInfoviewed(ItemBase *item);
void resizeEvent(QResizeEvent *);
void addViewLayersAux(const LayerList &, const LayerList & layersFromBelow, float startZ = 1.5);
virtual bool disconnectFromFemale(ItemBase * item, QHash<long, ItemBase *> & savedItems, ConnectorPairHash &, bool doCommand, bool rubberBandLegEnabled, QUndoCommand * parentCommand);
void clearDragWireTempCommand();
bool draggingWireEnd();
void moveItems(QPoint globalPos, bool checkAutoScroll, bool rubberBandLegEnabled);
void moveItemsScene(QPointF scenePos, bool checkAutoScrollFlag, bool rubberBandLegEnabled);
void moveItemsAux(QPointF scenePos, QPoint globalPos, bool checkAutoScrollFlag, bool rubberBandLegEnabled);
virtual ViewLayer::ViewLayerID multiLayerGetViewLayerID(ModelPart * modelPart, ViewLayer::ViewID, ViewLayer::ViewLayerPlacement, LayerList &);
virtual BaseCommand::CrossViewType wireSplitCrossView();
virtual bool canChainMultiple();
virtual bool canChainWire(Wire *);
virtual bool canDragWire(Wire *);
virtual bool canCreateWire(Wire * dragWire, ConnectorItem * from, ConnectorItem * to);
//virtual bool modifyNewWireConnections(Wire * dragWire, ConnectorItem * fromOnWire, ConnectorItem * from, ConnectorItem * to, QUndoCommand * parentCommand);
virtual void setUpColor(ConnectorItem * fromConnectorItem, ConnectorItem * toConnectorItem, Wire * wire, QUndoCommand * parentCommand);
void setupAutoscroll(bool moving);
void turnOffAutoscroll();
bool checkAutoscroll(QPoint globalPos);
virtual void setWireVisible(Wire *);
bool matchesLayer(ModelPart * modelPart);
QByteArray removeOutsideConnections(const QByteArray & itemData, QList<long> & modelIndexes);
void addWireExtras(long newID, QDomElement & view, QUndoCommand * parentCommand);
virtual const QString & hoverEnterWireConnectorMessage(QGraphicsSceneHoverEvent * event, ConnectorItem * item);
virtual const QString & hoverEnterPartConnectorMessage(QGraphicsSceneHoverEvent * event, ConnectorItem * item);
void partLabelChangedAux(ItemBase * pitem,const QString & oldText, const QString &newText);
void drawBackground( QPainter * painter, const QRectF & rect );
void handleConnect(QDomElement & connect, ModelPart *, const QString & fromConnectorID, ViewLayer::ViewLayerID, QStringList & alreadyConnected,
QHash<long, ItemBase *> & newItems, QUndoCommand * parentCommand, bool seekOutsideConnections);
void setUpSwapReconnect(SwapThing &, ItemBase * itemBase, long newID, bool master);
void setUpSwapRenamePins(SwapThing & swapThing, ItemBase * itemBase);
void makeSwapWire(SketchWidget *, ItemBase *, long newID, ConnectorItem * fromConnectorItem, ConnectorItem * toConnectorItem, Connector * newConnector, QUndoCommand * parentCommand);
bool swappedGender(ConnectorItem * originalConnectorItem, Connector * newConnector);
void setLastPaletteItemSelected(PaletteItem * paletteItem);
void setLastPaletteItemSelectedIf(ItemBase * itemBase);
void prepDragBendpoint(Wire *, QPoint eventPos, bool dragCurve);
void prepDragWire(Wire *);
void clickBackground(QMouseEvent *);
void categorizeDragWires(QSet<Wire *> & wires, QList<ItemBase *> & freeWires);
void categorizeDragLegs(bool rubberBandLegEnabled);
void prepMove(ItemBase * originatingItem, bool rubberBandLegEnabled, bool includeRatsnest);
void initBackgroundColor();
QPointF calcNewLoc(ItemBase * moveBase, ItemBase * detachFrom);
long findPartOrWire(long itemID);
AddItemCommand * newAddItemCommand(BaseCommand::CrossViewType crossViewType, ModelPart *,
QString moduleID, ViewLayer::ViewLayerPlacement, ViewGeometry & viewGeometry, qint64 id,
bool updateInfoView, long modelIndex, bool addSubparts, QUndoCommand *parent);
int selectAllItems(QSet<ItemBase *> & itemBases, const QString & msg);
bool moveByArrow(double dx, double dy, QKeyEvent * );
double gridSizeInches();
virtual bool canAlignToTopLeft(ItemBase *);
virtual bool canAlignToCenter(ItemBase *);
virtual void findAlignmentAnchor(ItemBase * originatingItem, QHash<long, ItemBase *> & savedItems, QHash<Wire *, ConnectorItem *> & savedWires);
void alignLoc(QPointF & loc, const QPointF startPoint, const QPointF newLoc, const QPointF originalLoc);
void copyAux(QList<ItemBase *> & bases, bool saveBoundingRects);
void copyDrop();
void dropItemEvent(QDropEvent *event);
virtual QString checkDroppedModuleID(const QString & moduleID);
QString makeWireSVG(Wire * wire, QPointF offset, double dpi, double printerscale, bool blackOnly);
QString makeWireSVGAux(Wire * wire, double width, const QString & color, QPointF offset, double dpi, double printerScale, bool blackOnly, bool dashed);
QString makeMoveSVG(double printerScale, double dpi, QPointF & offset);
void prepDeleteProps(ItemBase * itemBase, long id, const QString & newModuleID, QMap<QString, QString> & propsMap, QUndoCommand * parentCommand);
void prepDeleteOtherProps(ItemBase * itemBase, long id, const QString & newModuleID, QMap<QString, QString> & propsMap, QUndoCommand * parentCommand);
virtual ViewLayer::ViewLayerPlacement getViewLayerPlacement(ModelPart *, QDomElement & instance, QDomElement & view, ViewGeometry &);
virtual ViewLayer::ViewLayerPlacement wireViewLayerPlacement(ConnectorItem *);
virtual bool resizingJumperItemPress(ItemBase *);
virtual bool resizingJumperItemRelease();
bool resizingBoardPress(ItemBase *);
bool resizingBoardRelease();
void resizeBoard();
void resizeWithHandle(ItemBase * itemBase, double mmW, double mmH);
virtual bool acceptsTrace(const ViewGeometry &);
virtual ItemBase * placePartDroppedInOtherView(ModelPart *, ViewLayer::ViewLayerPlacement, const ViewGeometry & viewGeometry, long id, SketchWidget * dropOrigin);
void showPartLabelsAux(bool show, QList<ItemBase *> & itemBases);
virtual void extraRenderSvgStep(ItemBase *, QPointF offset, double dpi, double printerScale, QString & outputSvg);
virtual ViewLayer::ViewLayerPlacement createWireViewLayerPlacement(ConnectorItem * from, ConnectorItem * to);
virtual Wire * createTempWireForDragging(Wire * fromWire, ModelPart * wireModel, ConnectorItem * connectorItem, ViewGeometry & viewGeometry, ViewLayer::ViewLayerPlacement);
virtual void prereleaseTempWireForDragging(Wire*);
void checkFit(ModelPart * newModelPart, ItemBase * itemBase, long newID,
QHash<ConnectorItem *, Connector *> & found, QList<ConnectorItem *> & notFound,
QHash<ConnectorItem *, ConnectorItem *> & m2f, QHash<ConnectorItem *, Connector *> & byWire,
QHash<QString, QPolygonF> & legs, QHash<QString, ConnectorItem *> & formerLegs, QUndoCommand * parentCommand);
void checkFitAux(ItemBase * tempItemBase, ItemBase * itemBase, long newID,
QHash<ConnectorItem *, Connector *> & found, QList<ConnectorItem *> & notFound,
QHash<ConnectorItem *, ConnectorItem *> & m2f, QHash<ConnectorItem *, Connector *> & byWire,
QHash<QString, QPolygonF> & legs, QHash<QString, ConnectorItem *> & formerLegs, QUndoCommand * parentCommand);
void changeLegAux(long fromID, const QString & fromConnectorID, const QPolygonF &, bool reset, bool relative, bool active, const QString & why);
void moveLegBendpoints(bool undoOnly, QUndoCommand * parentCommand);
void moveLegBendpointsAux(ConnectorItem * connectorItem, bool undoOnly, QUndoCommand * parentCommand);
virtual void rotatePartLabels(double degrees, QTransform &, QPointF center, QUndoCommand * parentCommand);
bool checkUpdateRatsnest(QList<ConnectorItem *> & connectorItems);
void makeRatsnestViewGeometry(ViewGeometry & viewGeometry, ConnectorItem * source, ConnectorItem * dest);
virtual double getTraceWidth();
virtual const QString & traceColor(ViewLayer::ViewLayerPlacement);
void createTrace(Wire * fromWire, const QString & commandString, ViewGeometry::WireFlag, bool useLastWireColor);
bool createOneTrace(Wire * wire, ViewGeometry::WireFlag flag, bool allowAny, QList<Wire *> & done, bool useLastWireColor, QUndoCommand * parentCommand);
void removeWire(Wire * w, QList<ConnectorItem *> & ends, QList<Wire *> & done, QUndoCommand * parentCommand);
void selectAllWiresFrom(ViewGeometry::WireFlag flag, QList<QGraphicsItem *> & items);
bool canConnect(ItemBase * from, ItemBase * to);
virtual bool canConnect(Wire * from, ItemBase * to);
void removeDragWire();
QGraphicsItem * getClickedItem(QList<QGraphicsItem *> & items);
void cleanupRatsnests(QList< QPointer<ConnectorItem> > & connectorItems, bool connect);
void rotateWire(Wire *, QTransform & rotation, QPointF center, bool undoOnly, QUndoCommand * parentCommand);
QList<QGraphicsItem *> getVisibleItemsAndLabels(RenderThing & renderThing, const LayerList & layers);
QString renderToSVG(RenderThing &, QList<QGraphicsItem *> & itemsAndLabels, bool applyViewFromBelow = false);
QList<ItemBase *> collectSuperSubs(ItemBase *);
void squashShapes(QPointF scenePos);
void unsquashShapes();
virtual bool updateOK(ConnectorItem *, ConnectorItem *);
virtual void viewGeometryConversionHack(ViewGeometry &, ModelPart *);
void prepDeleteOtherPropsNumbers(const QString & propertyName, ItemBase * itemBase, long id, const QString & newModuleID, QUndoCommand * parentCommand);
protected:
static bool lessThan(int a, int b);
static bool greaterThan(int a, int b);
Q_SIGNALS:
void itemAddedSignal(ModelPart *, ItemBase *, ViewLayer::ViewLayerPlacement, const ViewGeometry &, long id, SketchWidget * dropOrigin);
void itemDeletedSignal(long id);
void clearSelectionSignal();
void itemSelectedSignal(long id, bool state);
void itemMovedSignal(ItemBase *);
void wireDisconnectedSignal(long fromID, QString fromConnectorID);
void wireConnectedSignal(long fromID, QString fromConnectorID, long toID, QString toConnectorID);
void changeConnectionSignal(long fromID, QString fromConnectorID,
long toID, QString toConnectorID,
ViewLayer::ViewLayerPlacement,
bool connect, bool updateConnections);
void copyBoundingRectsSignal(QHash<QString, QRectF> &);
void cleanUpWiresSignal(CleanUpWiresCommand *);
void selectionChangedSignal();
void resizeSignal();
void dropSignal(const QPoint &pos);
void routingStatusSignal(SketchWidget *, const RoutingStatus &);
void movingSignal(SketchWidget *, QUndoCommand * parentCommand);
void selectAllItemsSignal(bool state, bool doEmit);
void checkStickySignal(long id, bool doEmit, bool checkCurrent, CheckStickyCommand *);
void disconnectAllSignal(QList<ConnectorItem *>, QHash<ItemBase *, SketchWidget *> & itemsToDelete, QUndoCommand * parentCommand);
void setResistanceSignal(long itemID, QString resistance, QString pinSpacing, bool doEmit);
void setPropSignal(long itemID, const QString & prop, const QString & value, bool doRedraw, bool doEmit);
void setInstanceTitleSignal(long id, const QString & oldTitle, const QString & newTitle, bool isUndoable, bool doEmit);
void statusMessageSignal(QString, int timeout);
void showLabelFirstTimeSignal(long itemID, bool show, bool doEmit);
void dropPasteSignal(SketchWidget *);
void changeBoardLayersSignal(int, bool doEmit);
void deleteTracesSignal(QSet<ItemBase *> & deletedItems, QHash<ItemBase *, SketchWidget *> & otherDeletedItems, QList<long> & deletedIDs, bool isForeign, QUndoCommand * parentCommand);
void makeDeleteItemCommandPrepSignal(ItemBase * itemBase, bool foreign, QUndoCommand * parentCommand);
void makeDeleteItemCommandFinalSignal(ItemBase * itemBase, bool foreign, QUndoCommand * parentCommand);
void cursorLocationSignal(double xinches, double yinches, double width=0.0, double height=0.0);
void ratsnestConnectSignal(long id, const QString & connectorID, bool connect, bool doEmit);
void updatePartLabelInstanceTitleSignal(long itemID);
void filenameIfSignal(QString & filename);
void collectRatsnestSignal(QList<SketchWidget *> & foreignSketchWidgets);
void removeRatsnestSignal(QList<struct ConnectorEdge *> & cutSet, QUndoCommand * parentCommand);
void updateLayerMenuSignal();
void swapBoardImageSignal(SketchWidget * sketchWidget, ItemBase * itemBase, const QString & filename, const QString & moduleID, bool addName);
void canConnectSignal(Wire * from, ItemBase * to, bool & connect);
void swapStartSignal(SwapThing & swapThing, bool master);
void showing(SketchWidget *);
void clickedItemCandidateSignal(QGraphicsItem *, bool & ok);
void resizedSignal(ItemBase *);
void cleanupRatsnestsSignal(bool doEmit);
void addSubpartSignal(long id, long subpartID, bool doEmit);
void getDroppedItemViewLayerPlacementSignal(ModelPart * modelPart, ViewLayer::ViewLayerPlacement &);
void packItemsSignal(int columns, const QList<long> & ids, QUndoCommand *parent, bool doEmit);
protected Q_SLOTS:
void itemAddedSlot(ModelPart *, ItemBase *, ViewLayer::ViewLayerPlacement, const ViewGeometry &, long id, SketchWidget * dropOrigin);
void itemDeletedSlot(long id);
void clearSelectionSlot();
void itemSelectedSlot(long id, bool state);
void selectionChangedSlot();
void wireChangedSlot(class Wire*, const QLineF & oldLine, const QLineF & newLine, QPointF oldPos, QPointF newPos, ConnectorItem * from, ConnectorItem * to);
void wireChangedCurveSlot(class Wire*, const Bezier * oldB, const Bezier * newB, bool triggerFirstTime);
virtual void wireSplitSlot(class Wire*, QPointF newPos, QPointF oldPos, const QLineF & oldLine);
void wireJoinSlot(class Wire*, ConnectorItem * clickedConnectorItem);
void toggleLayerVisibility();
void wireConnectedSlot(long fromID, QString fromConnectorID, long toID, QString toConnectorID);
void wireDisconnectedSlot(long fromID, QString fromConnectorID);
void changeConnectionSlot(long fromID, QString fromConnectorID, long toID, QString toConnectorID, ViewLayer::ViewLayerPlacement, bool connect, bool updateConnections);
void restartPasteCount();
void dragIsDoneSlot(class ItemDrag *);
void statusMessage(QString message, int timeout = 0);
void cleanUpWiresSlot(CleanUpWiresCommand *);
void updateInfoViewSlot();
void spaceBarIsPressedSlot(bool);
void autoScrollTimeout();
void dragAutoScrollTimeout();
void moveAutoScrollTimeout();
void rememberSticky(long id, QUndoCommand * parentCommand);
void rememberSticky(ItemBase *, QUndoCommand * parentCommand);
void copyBoundingRectsSlot(QHash<QString, QRectF> &);
void deleteRatsnest(Wire *, QUndoCommand * parentCommand);
void deleteTracesSlot(QSet<ItemBase *> & deletedItems, QHash<ItemBase *, SketchWidget *> & otherDeletedItems, QList<long> & deletedIDs, bool isForeign, QUndoCommand * parentCommand);
void vScrollToZero();
void arrowTimerTimeout();
void makeDeleteItemCommandPrepSlot(ItemBase * itemBase, bool foreign, QUndoCommand * parentCommand);
void makeDeleteItemCommandFinalSlot(ItemBase * itemBase, bool foreign, QUndoCommand * parentCommand);
void updatePartLabelInstanceTitleSlot(long itemID);
void changePinLabelsSlot(ItemBase * itemBase);
void changePinLabels(ItemBase *);
void collectRatsnestSlot(QList<SketchWidget *> & foreignSketchWidgets);
void removeRatsnestSlot(QList<struct ConnectorEdge *> & cutSet, QUndoCommand * parentCommand);
void deleteTemporary();
void canConnect(Wire * from, ItemBase * to, bool & connect);
long swapStart(SwapThing & swapThing, bool master);
virtual void getDroppedItemViewLayerPlacement(ModelPart * modelPart, ViewLayer::ViewLayerPlacement &);
public Q_SLOTS:
void changeWireColor(const QString newColor);
void changeWireWidthMils(const QString newWidth);
void selectAllItems(bool state, bool doEmit);
void setInstanceTitleForCommand(long id, const QString & oldTitle, const QString & newTitle, bool isUndoable, bool doEmit);
void checkStickyForCommand(long id, bool doEmit, bool checkCurrent, CheckStickyCommand *);
virtual ItemBase * resizeBoard(long id, double w, double h);
void disconnectAllSlot(QList<ConnectorItem *>, QHash<ItemBase *, SketchWidget *> & itemsToDelete, QUndoCommand * parentCommand);
void setResistance(long itemID, QString resistance, QString pinSpacing, bool doEmit);
void setResistance(QString resistance, QString pinSpacing);
void setProp(long itemID, const QString & prop, const QString & value, bool redraw, bool doEmit);
virtual void setProp(ItemBase *, const QString & propName, const QString & translatedPropName, const QString & oldValue, const QString & newValue, bool redraw);
void setHoleSize(ItemBase *, const QString & propName, const QString & translatedPropName, const QString & oldValue, const QString & newValue, QRectF & oldRect, QRectF & newRect, bool redraw);
virtual void showLabelFirstTimeForCommand(long itemID, bool show, bool doEmit);
void resizeBoard(double w, double h, bool doEmit);
virtual void changeBoardLayers(int layers, bool doEmit);
void updateConnectors();
void ratsnestConnectForCommand(long id, const QString & connectorID, bool connect, bool doEmit);
void cleanupRatsnestsForCommand(bool doEmit);
void addSubpartForCommand(long id, long subpartid, bool doEmit);
void packItemsForCommand(int columns, const QList<long> & ids, QUndoCommand *parent, bool doEmit);
protected:
enum StatusConnectStatus {
StatusConnectNotTried,
StatusConnectSucceeded,
StatusConnectFailed
};
protected:
QPointer<class ReferenceModel> m_referenceModel;
QPointer<SketchModel> m_sketchModel;
ViewLayer::ViewID m_viewID;
class WaitPushUndoStack * m_undoStack = nullptr;
class SelectItemCommand * m_holdingSelectItemCommand = nullptr;
class SelectItemCommand * m_tempDragWireCommand = nullptr;
LayerHash m_viewLayers;
QHash<ViewLayer::ViewLayerID, bool> m_viewLayerVisibility;
QPointer<Wire> m_connectorDragWire;
QPointer<Wire> m_bendpointWire;
ViewGeometry m_bendpointVG;
QPointer<ConnectorItem> m_connectorDragConnector;
bool m_droppingWire = false;
QPointF m_droppingOffset;
QPointer<ItemBase> m_droppingItem;
int m_moveEventCount = 0;
//QList<QGraphicsItem *> m_lastSelected; hack for 4.5.something
ViewLayer::ViewLayerID m_wireViewLayerID;
ViewLayer::ViewLayerID m_partViewLayerID;
ViewLayer::ViewLayerID m_rulerViewLayerID;
ViewLayer::ViewLayerID m_connectorViewLayerID;
ViewLayer::ViewLayerID m_noteViewLayerID;
QList<QGraphicsItem *> m_temporaries;
bool m_chainDrag = false;
QPointF m_mousePressScenePos;
QPointF m_mousePressGlobalPos;
QTimer m_autoScrollTimer;
volatile int m_autoScrollX = 0;
volatile int m_autoScrollY = 0;
volatile int m_autoScrollCount = 0;
QPoint m_globalPos;
QPointer<PaletteItem> m_lastPaletteItemSelected;
int m_pasteCount = 0;
QPointF m_pasteOffset;
// Part Menu
QMenu *m_itemMenu = nullptr;
QMenu *m_wireMenu = nullptr;
bool m_infoViewOnHover;
QHash<long, ItemBase *> m_savedItems;
QHash<Wire *, ConnectorItem *> m_savedWires;
QList<ItemBase *> m_additionalSavedItems;
int m_ignoreSelectionChangeEvents = 0;
bool m_current = false;
QString m_lastColorSelected;
ConnectorPairHash m_moveDisconnectedFromFemale;
bool m_spaceBarIsPressed = false;
bool m_spaceBarWasPressed = false;
QPointer<ConnectorItem> m_lastHoverEnterConnectorItem;
QPointer<ItemBase> m_lastHoverEnterItem;
QString m_shortName;
QPointer<Wire> m_dragBendpointWire;
bool m_dragCurve = false;
QPoint m_dragBendpointPos;
StatusConnectStatus m_statusConnectState = StatusConnectNotTried;
QList<QGraphicsItem *> m_inFocus;
QString m_viewName;
bool m_movingByArrow = false;
double m_arrowTotalX = 0.0;
double m_arrowTotalY = 0.0;
bool m_movingByMouse = false;
bool m_alignToGrid = true;
bool m_showGrid = true;
double m_gridSizeInches = 0.0;
QString m_gridSizeText;
QPointer<ItemBase> m_alignmentItem;
QPointer<ItemBase> m_originatingItem;
QPointF m_alignmentStartPoint;
double m_zoom = 100;
bool m_draggingBendpoint = false;
QPointer<SizeItem> m_sizeItem;
int m_autoScrollThreshold = 0;
bool m_clearSceneRect = false;
QPointer<ItemBase> m_moveReferenceItem;
QPointer<QSvgRenderer> m_movingSVGRenderer;
QPointF m_movingSVGOffset;
QPointer<QGraphicsSvgItem> m_movingItem;
QList< QPointer<ConnectorItem> > m_ratsnestUpdateDisconnect;
QList< QPointer<ConnectorItem> > m_ratsnestUpdateConnect;
QList< QPointer<ConnectorItem> > m_ratsnestCacheDisconnect;
QList< QPointer<ConnectorItem> > m_ratsnestCacheConnect;
QList <ItemBase *> m_checkUnder;
bool m_addDefaultParts = false;
QPointer<ItemBase> m_addedDefaultPart;
float m_z;
QTimer m_arrowTimer;
bool m_middleMouseIsPressed = false;
QMultiHash<ItemBase *, ConnectorItem *> m_stretchingLegs;
bool m_curvyWires = false;
bool m_rubberBandLegWasEnabled = false;
RoutingStatus m_routingStatus;
bool m_anyInRotation;
bool m_pasting = false;
QPointer<class ResizableBoard> m_resizingBoard;
QList< QPointer<ItemBase> > m_squashShapes;
QColor m_gridColor;
bool m_everZoomed = false;
double m_ratsnestOpacity = 0.0;
double m_ratsnestWidth = 0.0;
public:
static ViewLayer::ViewLayerID defaultConnectorLayer(ViewLayer::ViewID viewId);
static constexpr int PropChangeDelay = 100;
static bool m_blockUI;
protected:
static constexpr int MoveAutoScrollThreshold = 5;
static constexpr int DragAutoScrollThreshold = 10;
};
#endif