20#include "../controlElement/ControlElementContainer.h"
21#include "../controlElement/ControlElementSolver.h"
27 m_parentList.push_back(parent);
29 wxPoint2DDouble parentPt =
34 m_position = parentPt + wxPoint2DDouble(-100.0, 0.0);
35 m_width = m_height = 50.0;
36 m_rect = wxRect2DDouble(m_position.m_x - 25.0, m_position.m_y - 25.0, m_width, m_height);
38 m_pointList.push_back(parentPt);
39 m_pointList.push_back(
GetSwitchPoint(parent, parentPt, m_position));
40 m_pointList.push_back(m_position + wxPoint2DDouble(35.0, 0.0));
41 m_pointList.push_back(m_position + wxPoint2DDouble(25.0, 0.0));
44 wxRect2DDouble genRect(0, 0, 0, 0);
45 m_switchRect.push_back(genRect);
47 UpdatePowerFlowArrowsPosition();
100void Machines::DrawDC(wxPoint2DDouble translation,
double scale, wxGraphicsContext* gc)
const
102 wxColour elementColour;
105 elementColour = m_dynamicEventColour;
107 elementColour = m_onlineElementColour;
110 elementColour = m_offlineElementColour;
115 gc->SetPen(wxPen(m_selectionColour, 2 + m_borderSize * 2.0));
116 gc->SetBrush(*wxTRANSPARENT_BRUSH);
117 gc->StrokeLines(m_pointList.size(), &m_pointList[0]);
119 gc->SetPen(*wxTRANSPARENT_PEN);
120 gc->SetBrush(wxBrush(m_selectionColour));
121 DrawDCCircle(m_position, 25.0 + (m_borderSize + 1.5) / scale, 20, gc);
124 DrawDCCircle(m_pointList[0], 5.0 + m_borderSize / scale, 10, gc);
129 gc->SetPen(*wxTRANSPARENT_PEN);
130 gc->SetBrush(wxBrush(elementColour));
133 gc->SetPen(wxPen(wxColour(elementColour), 2));
134 gc->SetBrush(*wxTRANSPARENT_BRUSH);
135 gc->StrokeLines(m_pointList.size(), &m_pointList[0]);
141 gc->SetPen(*wxTRANSPARENT_PEN);
142 gc->SetBrush(*wxWHITE_BRUSH);
145 gc->SetPen(wxPen(elementColour, 2));
146 gc->SetBrush(*wxTRANSPARENT_BRUSH);
156 wxColour elementColour;
159 elementColour = m_dynamicEventColour;
161 elementColour = m_onlineElementColour;
164 elementColour = m_offlineElementColour;
166 std::vector<wxPoint> pointListInt;
167 for(
auto& pt : m_pointList) {
168 pointListInt.emplace_back(
static_cast<int>(pt.m_x),
static_cast<int>(pt.m_y));
174 dc.SetPen(wxPen(m_selectionColour, 2 + m_borderSize * 2.0));
175 dc.SetBrush(*wxTRANSPARENT_BRUSH);
176 dc.DrawLines(pointListInt.size(), &pointListInt[0]);
178 dc.SetPen(*wxTRANSPARENT_PEN);
179 dc.SetBrush(wxBrush(m_selectionColour));
180 DrawDCCircle(m_position, 25.0 + (m_borderSize + 1.5) / scale, dc);
183 DrawDCCircle(m_pointList[0], 5.0 + m_borderSize / scale, dc);
188 dc.SetPen(*wxTRANSPARENT_PEN);
189 dc.SetBrush(wxBrush(elementColour));
192 dc.SetPen(wxPen(wxColour(elementColour), 2));
193 dc.SetBrush(*wxTRANSPARENT_BRUSH);
194 dc.DrawLines(pointListInt.size(), &pointListInt[0]);
200 dc.SetPen(*wxTRANSPARENT_PEN);
201 dc.SetBrush(*wxWHITE_BRUSH);
204 dc.SetPen(wxPen(elementColour, 2));
205 dc.SetBrush(*wxTRANSPARENT_BRUSH);
213void Machines::UpdateSwitchesPosition()
215 if(m_parentList[0]) {
216 m_pointList[1] =
GetSwitchPoint(m_parentList[0], m_pointList[0], m_pointList[2]);
218 m_pointList[1] = m_pointList[0];
226 for(
int i = 2; i < (int)m_pointList.size(); i++) {
227 m_pointList[i] = m_movePts[i] + position - m_moveStartPt;
229 if(!m_parentList[0]) {
230 m_pointList[0] = m_movePts[0] + position - m_moveStartPt;
232 UpdateSwitchesPosition();
233 UpdatePowerFlowArrowsPosition();
239 if(element == m_parentList[0]) {
240 m_pointList[0] = m_movePts[0] + position - m_moveStartPt;
243 if(m_activeNodeID == 1) {
244 m_pointList[0] = m_movePts[0] + position - m_moveStartPt;
245 if(m_parentList[0]) {
246 m_parentList[0]->RemoveChild(
this);
247 m_parentList[0] =
nullptr;
254 UpdateSwitchesPosition();
255 UpdatePowerFlowArrowsPosition();
260 m_moveStartPt = position;
261 m_movePts = m_pointList;
262 m_movePos = m_position;
267 double rotAngle = m_rotationAngle;
268 if(!clockwise) rotAngle = -m_rotationAngle;
270 if(parent == m_parentList[0]) {
272 UpdateSwitchesPosition();
273 UpdatePowerFlowArrowsPosition();
279 if(parent == m_parentList[0]) {
280 m_parentList[0] =
nullptr;
282 UpdateSwitchesPosition();
283 UpdatePowerFlowArrowsPosition();
289 wxRect2DDouble nodeRect(m_pointList[0].m_x - 5.0 - m_borderSize, m_pointList[0].m_y - 5.0 - m_borderSize,
290 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize);
292 if(nodeRect.Contains(position)) {
303 if(parent && m_activeNodeID != 0) {
304 wxRect2DDouble nodeRect(m_pointList[0].m_x - 5.0 - m_borderSize, m_pointList[0].m_y - 5.0 - m_borderSize,
305 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize);
308 m_parentList[0] = parent;
311 wxPoint2DDouble parentPt =
315 m_pointList[0] = parentPt;
317 UpdateSwitchesPosition();
318 UpdatePowerFlowArrowsPosition();
321 m_parentList[0] =
nullptr;
330 if(m_parentList[0]) {
331 wxRect2DDouble nodeRect(m_pointList[0].m_x - 5.0 - m_borderSize, m_pointList[0].m_y - 5.0 - m_borderSize,
332 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize);
335 m_parentList[0]->RemoveChild(
this);
336 m_parentList[0] =
nullptr;
338 UpdateSwitchesPosition();
339 UpdatePowerFlowArrowsPosition();
346 double rotAngle = m_rotationAngle;
347 if(!clockwise) rotAngle = -m_rotationAngle;
350 if(m_angle >= 360 || m_angle <= -360) m_angle = 0.0;
353 UpdateSwitchesPosition();
354 UpdatePowerFlowArrowsPosition();
357void Machines::UpdatePowerFlowArrowsPosition()
359 std::vector<wxPoint2DDouble> edges;
360 switch(m_pfDirection) {
362 m_powerFlowArrow.clear();
365 edges.push_back(m_pointList[2]);
366 edges.push_back(m_pointList[1]);
369 edges.push_back(m_pointList[1]);
370 edges.push_back(m_pointList[2]);
381 m_pfDirection = pfDirection;
382 UpdatePowerFlowArrowsPosition();
PowerFlowDirection
Direction of power flow arrows.
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.
virtual void AddChild(Element *child)
Add a child to the child list.
virtual void DrawDCCircle(wxPoint2DDouble position, double radius, int numSegments, wxGraphicsContext *gc) const
Draw a circle using device context.
virtual void RemoveParent(Element *parent)
Remove a parent.
virtual bool Intersects(wxRect2DDouble rect) const
Check if the element's rect intersects other rect.
virtual void SetPowerFlowDirection(PowerFlowDirection pfDirection)
Set the direction of the power flow.
virtual void Move(wxPoint2DDouble position)
Move the element other position.
virtual void DrawDC(wxPoint2DDouble translation, double scale, wxGraphicsContext *gc) const
Draw the element using GDI+.
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 RotateNode(Element *parent, bool clockwise=true)
Rotate a node.
virtual bool AddParent(Element *parent, wxPoint2DDouble position)
Add a parent to the element. This method must be used on power elements that connect to a bus,...
virtual void StartMove(wxPoint2DDouble position)
Update the element attributes related to the movement.
virtual void Rotate(bool clockwise=true)
Rotate the element.
virtual void MoveNode(Element *element, wxPoint2DDouble position)
Move a node. StartMove(wxPoint2DDouble position) before start moving.
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...
Abstract class of power elements.
virtual void CalculatePowerFlowPts(std::vector< wxPoint2DDouble > edges)
Calculate the points of the power flow arrows.
virtual void DrawDCSwitches(wxGraphicsContext *gc) const
Draw switch.
virtual void UpdateSwitches()
Update the switch position.
virtual void DrawDCPowerFlowPts(wxGraphicsContext *gc) const
Draw power flow arrows.
virtual wxPoint2DDouble GetSwitchPoint(Element *parent, wxPoint2DDouble parentPoint, wxPoint2DDouble secondPoint) const
Get the correct switch position.