-
Notifications
You must be signed in to change notification settings - Fork 3
/
GraphicItemWire.h
137 lines (102 loc) · 5.05 KB
/
GraphicItemWire.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
////////////////////////////////////////////////////////////////////////
// Copyright 2009-2018 NTESS. Under the terms
// of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
// Copyright (c) 2009-2018, NTESS
// All rights reserved.
//
// Portions are copyright of other developers:
// See the file CONTRIBUTORS.TXT in the top level directory
// the distribution for more information.
//
// This file is part of the SST software package. For license
// information, see the LICENSE file in the top level directory of the
// distribution.
////////////////////////////////////////////////////////////////////////
#ifndef GRAPHICITEMWIRE_H
#define GRAPHICITEMWIRE_H
#include "GlobalIncludes.h"
#include "GraphicItemWireLineSegment.h"
#include "GraphicItemWireHandle.h"
#include "GraphicItemPort.h"
// Forward declarations to allow compile
class GraphicItemWireLineSegment;
////////////////////////////////////////////////////////////
class GraphicItemWire : public QGraphicsObject, public GraphicItemBase
{
Q_OBJECT
public:
// Enumerations for Identifying the Wire Point Position
enum ConnectedState { NO_CONNECTIONS, STARTPOINT_CONNECTED, ENDPOINT_CONNECTED, FULL_CONNECTION };
// Required Virtual function for any QGraphicItem to provide a type value for the qgraphicsitem_cast function
enum { Type = UserType + ITEMTYPE_WIRE };
int type() const {return Type;}
// Constructor / Destructor
GraphicItemWire(int WireIndex, const QPointF& StartPoint, const QPointF& EndPoint, QGraphicsItem* parent = 0);
GraphicItemWire(QDataStream& DataStreamIn, int NewWireIndex = -1, QGraphicsItem* parent = 0); // Only used for serialization
virtual ~GraphicItemWire();
// General info on the wire
int GetWireIndex() {return m_WireIndex;}
// Serialization
void SaveData(QDataStream& DataStreamOut);
// Update the Start / End Point Positions (Main way to move a wire)
void UpdateStartPointPosition(const QPointF& NewPointLocation);
void UpdateEndPointPosition(const QPointF& NewPointLocation);
void SetPastePosition(int PasteOffset);
// Disconnect Ports
void DisconnectAllAttachedPorts();
void DisconnectPort(GraphicItemPort* Port, int MoveXOffset = 0);
// Get Information on the Connected Ports
GraphicItemPort* GetStartPointConnectedPort() {return m_StartPointCurrentPortConnected;}
GraphicItemPort* GetEndPointConnectedPort() {return m_EndPointCurrentPortConnected;}
// Set the Wire Selected State (Will call the sub objects to select them as necessary)
void SetWireSelected(bool SelectedState);
// Get Start / End Point Positions
QPointF GetStartPoint() {return m_StartPoint;}
QPointF GetEndPoint() {return m_EndPoint;}
// Callback Handlers from the Lower Level WireLiineSegments
void HandleWireLineSegmentItemChange(const QPointF& NewPos, GraphicItemWireLineSegment* CallingWireLineSegment, GraphicsItemChange change, const QVariant& value);
void HandleWireLineSegmentMouseReleaseEvent(QGraphicsSceneMouseEvent* event);
ConnectedState GetWireConnectedState() {return m_WireConnectedState;}
signals:
void ItemWireSetProjectDirty();
private:
// Update routines for the Wire Positions
void UpdatePointPositions(GraphicItemWireLineSegment* CallingWireLineSegment);
void UpdatePortAndWireHandleSettings();
void UpdateWireLineSegmentPositions(const QPointF& NewPos, GraphicItemWireLineSegment* CallingWireLineSegment);
void UpdateWireSelectedState(bool SelectedState);
void UpdateWireLineZOrder(qreal z);
void UpdateWireLinePens();
private:
// Overridden virtual functions
QPainterPath shape() const;
QRectF boundingRect() const;
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
QVariant itemChange(GraphicsItemChange change, const QVariant& value);
// Handle Changes to the Ports Properties
void PropertyChanged(QString& PropName, QString& NewPropValue);
private:
int m_WireIndex;
QLineF m_PointToPointLine;
QPointF m_StartPoint;
QPointF m_EndPoint;
QPointF m_MiddleStartVertical1Point;
QPointF m_MiddleEndVertical1Point;
qreal m_Current_x_VerticalDrawPoint;
GraphicItemPort* m_StartPointCurrentPortConnected;
GraphicItemPort* m_EndPointCurrentPortConnected;
GraphicItemWireHandle* m_StartPointHandle;
GraphicItemWireHandle* m_EndPointHandle;
GraphicItemWireLineSegment* m_StartPointLine;
GraphicItemWireLineSegment* m_MiddleVLine1;
GraphicItemWireLineSegment* m_EndPointLine;
bool m_AutomaticWireLinePositioning;
QColor m_CurrentWireColor;
QPen m_CurrentPen;
Qt::PenStyle m_CurrentPenStyle;
bool m_WireSelectedState;
ConnectedState m_WireConnectedState;
};
#endif // GRAPHICITEMWIRE_H