22void Shunt::UpdateSwitchesPosition()
24 if (m_parentList[0]) {
25 m_pointList[1] =
GetSwitchPoint(m_parentList[0], m_pointList[0], m_pointList[2]);
28 m_pointList[1] = m_pointList[0];
36 for (
int i = 2; i < (int)m_pointList.size(); i++) {
37 m_pointList[i] = m_movePts[i] + position - m_moveStartPt;
39 if (!m_parentList[0]) {
40 m_pointList[0] = m_movePts[0] + position - m_moveStartPt;
42 UpdateSwitchesPosition();
43 UpdatePowerFlowArrowsPosition();
46void Shunt::AlignToGrid(
double gridSize)
52 wxPoint2DDouble oldPosition = m_position;
54 wxPoint2DDouble newPosition(
55 std::round(oldPosition.m_x / gridSize) * gridSize,
56 std::round(oldPosition.m_y / gridSize) * gridSize);
58 wxPoint2DDouble delta = newPosition - oldPosition;
60 m_position = newPosition;
69 for (
size_t i = 2; i < m_pointList.size(); ++i) {
70 m_pointList[i] += delta;
77 if (!m_parentList.empty() &&
79 m_pointList.size() >= 3) {
82 wxPoint2DDouble p2 = m_pointList[2];
86 wxPoint2DDouble p2Local = bus->RotateLocal(p2Delta, -bus->
GetAngle());
89 wxPoint2DDouble candidateLocal(p2Local.m_x, 0.0);
92 double halfWidth = bus->
GetWidth() / 2.0 + 2.0;
94 if (std::abs(candidateLocal.m_x) <= halfWidth) {
97 wxPoint2DDouble candidate = bus->
GetPosition() + bus->RotateLocal(candidateLocal, bus->
GetAngle());
98 m_pointList[0] = candidate;
101 else if (!m_pointList.empty()) {
104 m_pointList[0].m_x = std::round(m_pointList[0].m_x / gridSize) * gridSize;
105 m_pointList[0].m_y = std::round(m_pointList[0].m_y / gridSize) * gridSize;
109 UpdateSwitchesPosition();
110 UpdatePowerFlowArrowsPosition();
116 if (element == m_parentList[0]) {
117 m_pointList[0] = m_movePts[0] + position - m_moveStartPt;
121 if (m_activeNodeID == 1) {
122 m_pointList[0] = m_movePts[0] + position - m_moveStartPt;
123 if (m_parentList[0]) {
124 m_parentList[0]->RemoveChild(
this);
125 m_parentList[0] =
nullptr;
132 UpdateSwitchesPosition();
133 UpdatePowerFlowArrowsPosition();
138 m_moveStartPt = position;
139 m_movePts = m_pointList;
140 m_movePos = m_position;
145 if (parent == m_parentList[0]) {
146 m_parentList[0] =
nullptr;
148 UpdateSwitchesPosition();
149 UpdatePowerFlowArrowsPosition();
155 wxRect2DDouble nodeRect(m_pointList[0].m_x - 5.0 - m_borderSize, m_pointList[0].m_y - 5.0 - m_borderSize,
156 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize);
158 if (nodeRect.Contains(position)) {
169 if (parent && m_activeNodeID != 0) {
170 wxRect2DDouble nodeRect(m_pointList[0].m_x - 5.0 - m_borderSize, m_pointList[0].m_y - 5.0 - m_borderSize,
171 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize);
174 m_parentList[0] = parent;
177 wxPoint2DDouble parentPt =
181 m_pointList[0] = parentPt;
183 UpdateSwitchesPosition();
184 UpdatePowerFlowArrowsPosition();
188 m_parentList[0] =
nullptr;
197 if (m_parentList[0]) {
198 wxRect2DDouble nodeRect(m_pointList[0].m_x - 5.0 - m_borderSize, m_pointList[0].m_y - 5.0 - m_borderSize,
199 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize);
202 m_parentList[0]->RemoveChild(
this);
203 m_parentList[0] =
nullptr;
205 UpdateSwitchesPosition();
206 UpdatePowerFlowArrowsPosition();
213 double rotAngle = m_rotationAngle;
214 if (!clockwise) rotAngle = -m_rotationAngle;
216 if (parent == m_parentList[0]) {
218 UpdateSwitchesPosition();
219 UpdatePowerFlowArrowsPosition();
238void Shunt::DrawDCGround(wxPoint2DDouble position, wxGraphicsContext* gc)
const
240 std::vector<wxPoint2DDouble> groundPts;
241 groundPts.push_back(position);
242 groundPts.push_back(position + wxPoint2DDouble(0, 10));
243 groundPts.push_back(position + wxPoint2DDouble(-10, 10));
244 groundPts.push_back(position + wxPoint2DDouble(10, 10));
245 groundPts.push_back(position + wxPoint2DDouble(-6, 15));
246 groundPts.push_back(position + wxPoint2DDouble(6, 15));
247 groundPts.push_back(position + wxPoint2DDouble(-3, 20));
248 groundPts.push_back(position + wxPoint2DDouble(3, 20));
250 gc->StrokeLines(2, &groundPts[0]);
251 gc->StrokeLines(2, &groundPts[2]);
252 gc->StrokeLines(2, &groundPts[4]);
253 gc->StrokeLines(2, &groundPts[6]);
256void Shunt::DrawDCGround(wxPoint2DDouble position, wxDC& dc)
const
258 wxPoint groundPts[8];
262 groundPts[0] = RotateAround(p, m_position, m_angle);
263 p = position + wxPoint2DDouble(0, 10);
264 groundPts[1] = RotateAround(p, m_position, m_angle);
265 p = position + wxPoint2DDouble(-10, 10);
266 groundPts[2] = RotateAround(p, m_position, m_angle);
267 p = position + wxPoint2DDouble(10, 10);
268 groundPts[3] = RotateAround(p, m_position, m_angle);
269 p = position + wxPoint2DDouble(-6, 15);
270 groundPts[4] = RotateAround(p, m_position, m_angle);
271 p = position + wxPoint2DDouble(6, 15);
272 groundPts[5] = RotateAround(p, m_position, m_angle);
273 p = position + wxPoint2DDouble(-3, 20);
274 groundPts[6] = RotateAround(p, m_position, m_angle);
275 p = position + wxPoint2DDouble(3, 20);
276 groundPts[7] = RotateAround(p, m_position, m_angle);
278 dc.DrawLines(2, &groundPts[0]);
279 dc.DrawLines(2, &groundPts[2]);
280 dc.DrawLines(2, &groundPts[4]);
281 dc.DrawLines(2, &groundPts[6]);
284void Shunt::UpdatePowerFlowArrowsPosition()
286 std::vector<wxPoint2DDouble> edges;
287 switch (m_pfDirection) {
289 m_powerFlowArrow.clear();
292 edges.push_back(m_pointList[2]);
293 edges.push_back(m_pointList[1]);
296 edges.push_back(m_pointList[1]);
297 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.
double GetWidth() const
Get the element width.
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.