22void Shunt::UpdateSwitchesPosition()
25 m_pointList[1] =
GetSwitchPoint(m_parentList[0], m_pointList[0], m_pointList[2]);
27 m_pointList[1] = m_pointList[0];
35 for(
int i = 2; i < (int)m_pointList.size(); i++) {
36 m_pointList[i] = m_movePts[i] + position - m_moveStartPt;
38 if(!m_parentList[0]) {
39 m_pointList[0] = m_movePts[0] + position - m_moveStartPt;
41 UpdateSwitchesPosition();
42 UpdatePowerFlowArrowsPosition();
48 if(element == m_parentList[0]) {
49 m_pointList[0] = m_movePts[0] + position - m_moveStartPt;
52 if(m_activeNodeID == 1) {
53 m_pointList[0] = m_movePts[0] + position - m_moveStartPt;
55 m_parentList[0]->RemoveChild(
this);
56 m_parentList[0] =
nullptr;
63 UpdateSwitchesPosition();
64 UpdatePowerFlowArrowsPosition();
69 m_moveStartPt = position;
70 m_movePts = m_pointList;
71 m_movePos = m_position;
76 if(parent == m_parentList[0]) {
77 m_parentList[0] =
nullptr;
79 UpdateSwitchesPosition();
80 UpdatePowerFlowArrowsPosition();
86 wxRect2DDouble nodeRect(m_pointList[0].m_x - 5.0 - m_borderSize, m_pointList[0].m_y - 5.0 - m_borderSize,
87 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize);
89 if(nodeRect.Contains(position)) {
100 if(parent && m_activeNodeID != 0) {
101 wxRect2DDouble nodeRect(m_pointList[0].m_x - 5.0 - m_borderSize, m_pointList[0].m_y - 5.0 - m_borderSize,
102 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize);
105 m_parentList[0] = parent;
108 wxPoint2DDouble parentPt =
112 m_pointList[0] = parentPt;
114 UpdateSwitchesPosition();
115 UpdatePowerFlowArrowsPosition();
118 m_parentList[0] =
nullptr;
127 if(m_parentList[0]) {
128 wxRect2DDouble nodeRect(m_pointList[0].m_x - 5.0 - m_borderSize, m_pointList[0].m_y - 5.0 - m_borderSize,
129 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize);
132 m_parentList[0]->RemoveChild(
this);
133 m_parentList[0] =
nullptr;
135 UpdateSwitchesPosition();
136 UpdatePowerFlowArrowsPosition();
143 double rotAngle = m_rotationAngle;
144 if(!clockwise) rotAngle = -m_rotationAngle;
146 if(parent == m_parentList[0]) {
148 UpdateSwitchesPosition();
149 UpdatePowerFlowArrowsPosition();
168void Shunt::DrawDCGround(wxPoint2DDouble position, wxGraphicsContext* gc)
const
170 std::vector<wxPoint2DDouble> groundPts;
171 groundPts.push_back(position);
172 groundPts.push_back(position + wxPoint2DDouble(0, 10));
173 groundPts.push_back(position + wxPoint2DDouble(-10, 10));
174 groundPts.push_back(position + wxPoint2DDouble(10, 10));
175 groundPts.push_back(position + wxPoint2DDouble(-6, 15));
176 groundPts.push_back(position + wxPoint2DDouble(6, 15));
177 groundPts.push_back(position + wxPoint2DDouble(-3, 20));
178 groundPts.push_back(position + wxPoint2DDouble(3, 20));
180 gc->StrokeLines(2, &groundPts[0]);
181 gc->StrokeLines(2, &groundPts[2]);
182 gc->StrokeLines(2, &groundPts[4]);
183 gc->StrokeLines(2, &groundPts[6]);
186void Shunt::DrawDCGround(wxPoint2DDouble position, wxDC& dc)
const
188 wxPoint groundPts[8];
192 groundPts[0] = RotateAround(p, m_position, m_angle);
193 p = position + wxPoint2DDouble(0, 10);
194 groundPts[1] = RotateAround(p, m_position, m_angle);
195 p = position + wxPoint2DDouble(-10, 10);
196 groundPts[2] = RotateAround(p, m_position, m_angle);
197 p = position + wxPoint2DDouble(10, 10);
198 groundPts[3] = RotateAround(p, m_position, m_angle);
199 p = position + wxPoint2DDouble(-6, 15);
200 groundPts[4] = RotateAround(p, m_position, m_angle);
201 p = position + wxPoint2DDouble(6, 15);
202 groundPts[5] = RotateAround(p, m_position, m_angle);
203 p = position + wxPoint2DDouble(-3, 20);
204 groundPts[6] = RotateAround(p, m_position, m_angle);
205 p = position + wxPoint2DDouble(3, 20);
206 groundPts[7] = RotateAround(p, m_position, m_angle);
208 dc.DrawLines(2, &groundPts[0]);
209 dc.DrawLines(2, &groundPts[2]);
210 dc.DrawLines(2, &groundPts[4]);
211 dc.DrawLines(2, &groundPts[6]);
214void Shunt::UpdatePowerFlowArrowsPosition()
216 std::vector<wxPoint2DDouble> edges;
217 switch(m_pfDirection) {
219 m_powerFlowArrow.clear();
222 edges.push_back(m_pointList[2]);
223 edges.push_back(m_pointList[1]);
226 edges.push_back(m_pointList[1]);
227 edges.push_back(m_pointList[2]);
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.
void SetPosition(const wxPoint2DDouble position)
Set the element position and update the rectangle.
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 void CalculatePowerFlowPts(std::vector< wxPoint2DDouble > edges)
Calculate the points of the power flow arrows.
virtual void UpdateSwitches()
Update the switch position.
virtual wxPoint2DDouble GetSwitchPoint(Element *parent, wxPoint2DDouble parentPoint, wxPoint2DDouble secondPoint) const
Get the correct switch position.
virtual void MoveNode(Element *element, wxPoint2DDouble position)
Move a node. StartMove(wxPoint2DDouble position) before start moving.
virtual void StartMove(wxPoint2DDouble position)
Update the element attributes related to the movement.
virtual void RemoveParent(Element *parent)
Remove a parent.
virtual void RotateNode(Element *parent, bool clockwise=true)
Rotate a node.
virtual void Move(wxPoint2DDouble position)
Move the element other position.
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...
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 bool Intersects(wxRect2DDouble rect) const
Check if the element's rect intersects other rect.