25 wxPoint2DDouble pt = firstNode->GetPosition();
27 for (
int i = 0; i < 6; i++) { m_pointList.push_back(pt); }
28 m_nodeList.push_back(firstNode);
29 firstNode->SetConnected();
32ConnectionLine::~ConnectionLine()
58 gc->SetBrush(*wxTRANSPARENT_BRUSH);
60 gc->SetPen(wxPen(guiColour->selection, 1.5 + m_borderSize * 2.0));
61 gc->StrokeLines(m_pointList.size(), &m_pointList[0]);
65 gc->SetPen(wxPen(guiColour->enabled, 2.0));
66 gc->StrokeLines(m_pointList.size(), &m_pointList[0]);
68 if (m_type == ConnectionLineType::ELEMENT_LINE) {
69 gc->SetPen(*wxTRANSPARENT_PEN);
70 gc->SetBrush(wxBrush(guiColour->enabled));
83 for (
auto it = m_pointList.begin(); it != m_pointList.end(); ++it) {
84 if (rect.Contains(*it))
return true;
89void ConnectionLine::UpdatePoints()
91 if (m_type == ConnectionLineType::ELEMENT_ELEMENT) {
92 bool hasOneNode =
true;
93 wxPoint2DDouble pt1 = m_nodeList[0]->GetPosition();
95 if (m_nodeList.size() == 1)
98 pt2 = m_nodeList[1]->GetPosition();
101 wxPoint2DDouble midPt = (pt1 + pt2) / 2.0 + wxPoint2DDouble(0.0, m_lineOffset);
103 m_pointList[0] = pt1;
104 if (m_nodeList[0]->
GetAngle() == 0.0)
105 m_pointList[1] = m_pointList[0] + wxPoint2DDouble(-10, 0);
106 else if (m_nodeList[0]->
GetAngle() == 90.0)
107 m_pointList[1] = m_pointList[0] + wxPoint2DDouble(0, -10);
108 else if (m_nodeList[0]->
GetAngle() == 180.0)
109 m_pointList[1] = m_pointList[0] + wxPoint2DDouble(10, 0);
110 else if (m_nodeList[0]->
GetAngle() == 270.0)
111 m_pointList[1] = m_pointList[0] + wxPoint2DDouble(0, 10);
113 m_pointList[2] = m_pointList[1] + wxPoint2DDouble(0.0, midPt.m_y - m_pointList[1].m_y);
115 m_pointList[5] = pt2;
117 m_pointList[4] = pt2;
119 if (m_nodeList[1]->
GetAngle() == 0.0)
120 m_pointList[4] = m_pointList[5] + wxPoint2DDouble(-10, 0);
121 else if (m_nodeList[1]->
GetAngle() == 90.0)
122 m_pointList[4] = m_pointList[5] + wxPoint2DDouble(0, -10);
123 else if (m_nodeList[1]->
GetAngle() == 180.0)
124 m_pointList[4] = m_pointList[5] + wxPoint2DDouble(10, 0);
125 else if (m_nodeList[1]->
GetAngle() == 270.0)
126 m_pointList[4] = m_pointList[5] + wxPoint2DDouble(0, 10);
129 m_pointList[3] = m_pointList[4] + wxPoint2DDouble(0.0, midPt.m_y - m_pointList[4].m_y);
131 else if (m_type == ConnectionLineType::ELEMENT_LINE) {
132 wxPoint2DDouble pt1 = m_nodeList[0]->GetPosition();
133 wxPoint2DDouble pt2 = m_parentLine->GetMidPoint();
134 wxPoint2DDouble midPt = (pt1 + pt2) / 2.0 + wxPoint2DDouble(0.0, m_lineOffset);
136 m_pointList[0] = pt1;
137 if (m_nodeList[0]->
GetAngle() == 0.0)
138 m_pointList[1] = m_pointList[0] + wxPoint2DDouble(-10, 0);
139 else if (m_nodeList[0]->
GetAngle() == 90.0)
140 m_pointList[1] = m_pointList[0] + wxPoint2DDouble(0, -10);
141 else if (m_nodeList[0]->
GetAngle() == 180.0)
142 m_pointList[1] = m_pointList[0] + wxPoint2DDouble(10, 0);
143 else if (m_nodeList[0]->
GetAngle() == 270.0)
144 m_pointList[1] = m_pointList[0] + wxPoint2DDouble(0, 10);
146 m_pointList[2] = m_pointList[1] + wxPoint2DDouble(0.0, midPt.m_y - m_pointList[1].m_y);
148 m_pointList[5] = pt2;
149 if (m_pointList[2].m_y > pt2.m_y) {
150 m_pointList[4] = m_pointList[5] + wxPoint2DDouble(0, 10);
153 m_pointList[4] = m_pointList[5] + wxPoint2DDouble(0, -10);
156 m_pointList[3] = m_pointList[4] + wxPoint2DDouble(0.0, midPt.m_y - m_pointList[4].m_y);
158 for (
auto it = m_childList.begin(), itEnd = m_childList.end(); it != itEnd; ++it) {
159 ConnectionLine* child =
static_cast<ConnectionLine*
>(*it);
160 child->UpdatePoints();
166 if (m_nodeList.size() != 1)
return false;
167 if (m_nodeList[0] == node)
return false;
168 if (m_nodeList[0]->GetNodeType() == node->GetNodeType())
return false;
169 auto nodeList = parent->GetNodeList();
170 for (
auto it = nodeList.begin(), itEnd = nodeList.end(); it != itEnd; ++it) {
171 Node* parentNode = *it;
172 if (parentNode == m_nodeList[0])
return false;
175 m_nodeList.push_back(node);
176 node->SetConnected();
182 m_lineOffset = m_moveStartOffset + position.m_y - m_moveStartPtY;
188 m_moveStartPtY = position.m_y;
189 m_moveStartOffset = m_lineOffset;
192wxPoint2DDouble ConnectionLine::GetMidPoint()
const {
return ((m_pointList[2] + m_pointList[3]) / 2.0); }
195 if (m_nodeList[0]->GetNodeType() != Node::NodeType::NODE_IN)
return false;
196 if (!parent)
return false;
198 m_type = ConnectionLineType::ELEMENT_LINE;
199 m_parentLine = parent;
203std::vector<ConnectionLine*> ConnectionLine::GetLineChildList()
const
205 std::vector<ConnectionLine*> childList;
206 for (
auto it = m_childList.begin(), itEnd = m_childList.end(); it != itEnd; ++it) {
207 ConnectionLine* child =
static_cast<ConnectionLine*
>(*it);
208 childList.push_back(child);
215 for (
auto it = m_parentList.begin(); it != m_parentList.end(); ++it) {
217 if (element == parent) m_parentList.erase(it--);
223 ConnectionLine* copy =
new ConnectionLine(*
this);
227bool ConnectionLine::Initialize()
Connection between two control elements or other connection line and an element.
Element * GetCopy()
Get a the element copy.
virtual void StartMove(wxPoint2DDouble position)
Update the element attributes related to the movement.
virtual void RemoveParent(Element *parent)
Remove a parent.
virtual void DrawDC(GUIColour *guiColour, wxPoint2DDouble translation, double scale, wxGraphicsContext *gc) const
Draw the element using GDI+.
virtual void Move(wxPoint2DDouble position)
Move the element other position.
virtual bool Contains(wxPoint2DDouble position) const
Checks if the element contains a position.
virtual bool Intersects(wxRect2DDouble rect) const
Check if the element's rect intersects other rect.
virtual double PointToLineDistance(wxPoint2DDouble point, int *segmentNumber=nullptr) const
Calculate the distance between a line (formed by point list) and a point.
double GetAngle() const
Get the element angle.
virtual void DrawDCCircle(wxPoint2DDouble position, double radius, int numSegments, wxGraphicsContext *gc) const
Draw a circle using device context.
Node of a control element. This class manages the user interaction with the connection and control el...