24 wxRect2DDouble nodeRect1(m_pointList[0].m_x - 5.0 - m_borderSize, m_pointList[0].m_y - 5.0 - m_borderSize,
25 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize);
26 wxRect2DDouble nodeRect2(m_pointList[m_pointList.size() - 1].m_x - 5.0 - m_borderSize,
27 m_pointList[m_pointList.size() - 1].m_y - 5.0 - m_borderSize, 10 + 2.0 * m_borderSize,
28 10 + 2.0 * m_borderSize);
30 if(nodeRect1.Contains(position)) {
34 if(nodeRect2.Contains(position)) {
45 if(m_activeNodeID == 1 && parent == m_parentList[0])
return false;
46 if(m_activeNodeID == 2 && parent == m_parentList[1])
return false;
48 if(parent && m_activeNodeID != 0) {
49 wxRect2DDouble nodeRect(0, 0, 0, 0);
50 if(m_activeNodeID == 1) {
51 nodeRect = wxRect2DDouble(m_pointList[0].m_x - 5.0 - m_borderSize, m_pointList[0].m_y - 5.0 - m_borderSize,
52 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize);
54 if(m_activeNodeID == 2) {
55 nodeRect = wxRect2DDouble(m_pointList[m_pointList.size() - 1].m_x - 5.0 - m_borderSize,
56 m_pointList[m_pointList.size() - 1].m_y - 5.0 - m_borderSize,
57 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize);
61 if(m_activeNodeID == 1) {
63 if(m_parentList[1] == parent) {
68 m_parentList[0] = parent;
72 m_pointList[0], -parent->
GetAngle());
75 m_pointList[0] = parentPt;
77 UpdateSwitchesPosition();
80 if(m_activeNodeID == 2) {
81 if(m_parentList[0] == parent) {
86 m_parentList[1] = parent;
88 wxPoint2DDouble parentPt =
92 m_pointList[m_pointList.size() - 1] = parentPt;
94 UpdateSwitchesPosition();
98 if(m_activeNodeID == 1) m_parentList[0] =
nullptr;
99 if(m_activeNodeID == 2) m_parentList[1] =
nullptr;
107 for(
unsigned int i = 0; i < m_parentList.size(); i++) {
108 if(parent == m_parentList[i]) {
109 m_parentList[i] =
nullptr;
111 UpdateSwitchesPosition();
118 if(m_parentList[0]) {
119 wxRect2DDouble nodeRect(m_pointList[0].m_x - 5.0 - m_borderSize, m_pointList[0].m_y - 5.0 - m_borderSize,
120 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize);
123 m_parentList[0]->RemoveChild(
this);
124 m_parentList[0] =
nullptr;
126 UpdateSwitchesPosition();
129 if(m_parentList[1]) {
130 wxRect2DDouble nodeRect = wxRect2DDouble(m_pointList[m_pointList.size() - 1].m_x - 5.0 - m_borderSize,
131 m_pointList[m_pointList.size() - 1].m_y - 5.0 - m_borderSize,
132 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize);
135 m_parentList[1]->RemoveChild(
this);
136 m_parentList[1] =
nullptr;
138 UpdateSwitchesPosition();
145 double rotAngle = m_rotationAngle;
146 if(!clockwise) rotAngle = -m_rotationAngle;
148 if(parent == m_parentList[0]) {
150 }
else if(parent == m_parentList[1]) {
151 m_pointList[m_pointList.size() - 1] = parent->
RotateAtPosition(m_pointList[m_pointList.size() - 1], rotAngle);
153 UpdateSwitchesPosition();
156void Branch::UpdateSwitchesPosition()
158 if (m_parentList.size() >= 1) {
159 if (m_parentList[0]) {
160 m_pointList[1] =
GetSwitchPoint(m_parentList[0], m_pointList[0], m_pointList[2]);
163 m_pointList[1] = m_pointList[0];
167 if (m_parentList.size() >= 2) {
168 if (m_parentList[1]) {
169 m_pointList[m_pointList.size() - 2] =
170 GetSwitchPoint(m_parentList[1], m_pointList[m_pointList.size() - 1], m_pointList[m_pointList.size() - 3]);
173 m_pointList[m_pointList.size() - 2] = m_pointList[m_pointList.size() - 1];
181 wxPoint2DDouble swCenter = wxPoint2DDouble((m_pointList[0].m_x + m_pointList[1].m_x) / 2.0,
182 (m_pointList[0].m_y + m_pointList[1].m_y) / 2.0);
183 m_switchRect[0] = wxRect2DDouble(swCenter.m_x - m_switchSize / 2.0, swCenter.m_y - m_switchSize / 2.0, m_switchSize,
186 if(m_switchRect.size() > 1) {
188 wxPoint2DDouble((m_pointList[m_pointList.size() - 1].m_x + m_pointList[m_pointList.size() - 2].m_x) / 2.0,
189 (m_pointList[m_pointList.size() - 1].m_y + m_pointList[m_pointList.size() - 2].m_y) / 2.0);
190 m_switchRect[1] = wxRect2DDouble(swCenter.m_x - m_switchSize / 2.0, swCenter.m_y - m_switchSize / 2.0,
191 m_switchSize, m_switchSize);
virtual void UpdateSwitches()
Update the switch position.
virtual void RotateNode(Element *parent, bool clockwise=true)
Rotate a node.
virtual void UpdateNodes()
Update the nodes according to the parents. If a parent is removed, use this method.
virtual bool NodeContains(wxPoint2DDouble position)
Check if a node contains a point. If contains, set the attributes related to node movement.
virtual void RemoveParent(Element *parent)
Remove a parent.
virtual bool Intersects(wxRect2DDouble rect) const
Check if the element's rect intersects other rect.
virtual bool SetNodeParent(Element *parent)
Set a perent to the node. If all conditions are met, a new parent are added to the element and the po...
Base class of all elements of the program. This class is responsible for manage graphical and his dat...
virtual bool Intersects(wxRect2DDouble rect) const =0
Check if the element's rect intersects other rect.
wxPoint2DDouble GetPosition() const
Get the element position.
double GetAngle() const
Get the element angle.
virtual wxPoint2DDouble RotateAtPosition(wxPoint2DDouble pointToRotate, double angle, bool degrees=true) const
Rotate a point as element position being the origin.
Abstract class of power elements.
virtual wxPoint2DDouble GetSwitchPoint(Element *parent, wxPoint2DDouble parentPoint, wxPoint2DDouble secondPoint) const
Get the correct switch position.