Power System Platform  2026w10a-beta
Loading...
Searching...
No Matches
Machines Class Reference

Abstract class for rotary machines power elements. More...

#include <Machines.h>

Inheritance diagram for Machines:
Collaboration diagram for Machines:

Public Types

enum  SyncMachineModel {
  SM_MODEL_1 = 0 , SM_MODEL_2 , SM_MODEL_3 , SM_MODEL_4 ,
  SM_MODEL_5
}
 

Public Member Functions

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, so the parent must be a bus. The element basic points are calculated in this method, so apply this when the element is being inserted.
 
virtual bool Contains (wxPoint2DDouble position) const
 Checks if the element contains a position.
 
virtual void DrawDC (wxPoint2DDouble translation, double scale, wxGraphicsContext *gc) const
 Draw the element using GDI+.
 
virtual void DrawDC (wxPoint2DDouble translation, double scale, wxDC &dc) const
 Draw the element using wxDC.
 
virtual bool Intersects (wxRect2DDouble rect) const
 Check if the element's rect intersects other rect.
 
virtual void Move (wxPoint2DDouble position)
 Move the element other 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 RotateNode (Element *parent, bool clockwise=true)
 Rotate a node.
 
virtual void RemoveParent (Element *parent)
 Remove a parent.
 
virtual bool NodeContains (wxPoint2DDouble position)
 Check if a node contains a point. If contains, set the attributes related to node movement.
 
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 points related to the nodes will be calculated.
 
virtual void UpdateNodes ()
 Update the nodes according to the parents. If a parent is removed, use this method.
 
virtual void Rotate (bool clockwise=true)
 Rotate the element.
 
virtual void DrawDCSymbol (wxGraphicsContext *gc) const
 
virtual void DrawDCSymbol (wxDC &dc) const
 
virtual void SetPowerFlowDirection (PowerFlowDirection pfDirection)
 Set the direction of the power flow.
 
- Public Member Functions inherited from PowerElement
 PowerElement ()
 Constructor.
 
virtual ~PowerElement ()
 Destructor.
 
virtual wxPoint2DDouble GetSwitchPoint (Element *parent, wxPoint2DDouble parentPoint, wxPoint2DDouble secondPoint) const
 Get the correct switch position.
 
virtual bool SwitchesContains (wxPoint2DDouble position) const
 Check if switch contains position.
 
virtual void UpdateSwitches ()
 Update the switch position.
 
virtual void DrawDCSwitches (wxGraphicsContext *gc) const
 Draw switch.
 
virtual void DrawDCSwitches (wxDC &dc) const
 
virtual void CalculatePowerFlowPts (std::vector< wxPoint2DDouble > edges)
 Calculate the points of the power flow arrows.
 
virtual void DrawDCPowerFlowPts (wxGraphicsContext *gc) const
 Draw power flow arrows.
 
virtual void DrawDCPowerFlowPts (wxDC &dc) const
 
virtual void SetNominalVoltage (std::vector< double > nominalVoltage, std::vector< ElectricalUnit > nominalVoltageUnit)
 Set nominal voltage of the element.
 
virtual void SetSwitchingData (SwitchingData data)
 Set the switching data of the element.
 
virtual SwitchingData GetSwitchingData ()
 Returns the switching data of the element.
 
virtual PowerFlowDirection GetPowerFlowDirection () const
 Return the direction of the power flow.
 
virtual bool GetPlotData (ElementPlotData &plotData, PlotStudy study=PlotStudy::STABILITY)
 Fill the plot data.
 
virtual bool HaveDynamicEvent () const
 Check if the power element have dynamic event.
 
virtual void SetDynamicEvent (bool dynEvent=true)
 Set if the power element have dynamic event.
 
virtual double GetValueFromUnit (double value, ElectricalUnit valueUnit)
 
virtual void SaveCADProperties (rapidxml::xml_document<> &doc, rapidxml::xml_node<> *elementNode)
 
virtual void SaveSwitchingData (rapidxml::xml_document<> &doc, rapidxml::xml_node<> *electricalNode)
 
virtual bool OpenElement (rapidxml::xml_node<> *elementNode, std::vector< Element * > parentList)
 
virtual bool OpenCADProperties (rapidxml::xml_node<> *elementNode, std::vector< Element * > parentList)
 
virtual bool OpenSwitchingData (rapidxml::xml_node<> *electricalNode)
 
- Public Member Functions inherited from Element
 Element ()
 Constructor.
 
virtual ~Element ()
 Destructor.
 
void SetDragging (bool dragging=true)
 Set if the element are being dragged.
 
void SetHeight (double height)
 Set element height.
 
void SetPosition (const wxPoint2DDouble position)
 Set the element position and update the rectangle.
 
void SetSelected (bool selected=true)
 Set element selection.
 
void SetWidth (double width)
 Set element width.
 
void SetAngle (double angle)
 Set element angle.
 
void ShowPickbox (bool showPickbox=true)
 Set if the pickbox is shown.
 
void SetBorderSize (double borderSize)
 Set the size of the border (shown in selected elements).
 
bool SetOnline (bool online=true)
 Set if the element is online or offline.
 
virtual void SetPointList (std::vector< wxPoint2DDouble > pointList)
 Set the list of points that connect the element to the bus.
 
ElementType GetElementType ()
 
wxRect2DDouble GetRect () const
 Get the element rectangle.
 
wxPoint2DDouble GetPosition () const
 Get the element position.
 
bool IsDragging () const
 Checks if the element is being dragged.
 
double GetHeight () const
 Get the element height.
 
bool IsSelected () const
 Checks if the element is selected.
 
double GetWidth () const
 Get the element width.
 
double GetAngle () const
 Get the element angle.
 
double GetRotationAngle () const
 Get the angle of rotation.
 
bool IsPickboxShown () const
 Checks if the pickbox is shown.
 
bool IsOnline () const
 Checks if the element is online or offline.
 
virtual std::vector< wxPoint2DDouble > GetPointList () const
 Get the list of points that connect the element to bus.
 
virtual void AddParent (Element *parent)
 Add a parent to the element.
 
virtual ElementGetCopy ()
 Get a the element copy.
 
virtual void SetID (int id)
 Set the element ID.
 
virtual int GetID () const
 Get the element ID.
 
virtual void AddChild (Element *child)
 Add a child to the child list.
 
virtual void RemoveChild (Element *child)
 Remove a child from the list.
 
virtual void ReplaceChild (Element *oldChild, Element *newChild)
 Replace a child from the list.
 
virtual wxString GetTipText () const
 Get the tip text.
 
virtual bool GetContextMenu (wxMenu &menu)
 Get the element contex menu.
 
virtual void AddPoint (wxPoint2DDouble point)
 Add point to the list of points that connect the element to the bus.
 
void SetParent (Element *parent, int num)
 
void SetChild (Element *child, int num)
 
virtual void ReplaceParent (Element *oldParent, Element *newParent)
 Replace a parent.
 
virtual bool PickboxContains (wxPoint2DDouble position)
 Check if a pickbox contains a point. If contains the attributes related to pickbox movement will be calculated.
 
virtual void MovePickbox (wxPoint2DDouble position)
 Move the pickbox.
 
virtual wxCursor GetBestPickboxCursor () const
 Get the best cursor to shown to the user when the mouse is above a pickbox.
 
virtual void ResetPickboxes ()
 Remove the pickboxes.
 
virtual void ResetNodes ()
 Remove the active nodes.
 
virtual wxPoint2DDouble WorldToScreen (wxPoint2DDouble translation, double scale, double offsetX=0.0, double offsetY=0.0) const
 Convert the element position to screen position.
 
virtual wxPoint2DDouble WorldToScreen (wxPoint2DDouble position, wxPoint2DDouble translation, double scale, double offsetX=0.0, double offsetY=0.0) const
 Convert a generic position to screen position.
 
virtual bool RotatedRectanglesIntersects (wxRect2DDouble rect1, wxRect2DDouble rect2, double angle1, double angle2) const
 Check if two roteted rectangles intersect.
 
virtual void DrawDCRectangle (wxPoint2DDouble position, double width, double height, double angle, wxDC &dc) const
 Draw a circle.
 
virtual void DrawDCRoundedRectRotated (wxDC &dc, const wxPoint2DDouble &center, double width, double height, double radius, double angleDeg, int arcSegments=8) const
 
virtual void DrawDCCircle (wxPoint2DDouble position, double radius, int numSegments, wxGraphicsContext *gc) const
 Draw a circle using device context.
 
virtual void DrawDCCircle (wxPoint2DDouble position, double radius, wxDC &dc) const
 
virtual void DrawDCArc (wxPoint2DDouble position, double radius, double initAngle, double finalAngle, int numSegments, wxGraphicsContext *gc) const
 
virtual void DrawDCArc (wxPoint2DDouble position, double radius, double initAngle, double finalAngle, wxDC &dc) const
 
virtual void DrawDCTriangle (std::vector< wxPoint2DDouble > points, wxGraphicsContext *gc) const
 Draw rectangle.
 
virtual void DrawDCTriangle (std::vector< wxPoint > points, wxDC &dc) const
 
virtual void DrawDCPickbox (wxPoint2DDouble position, wxGraphicsContext *gc) const
 Draw a point.
 
virtual wxPoint2DDouble RotateAtPosition (wxPoint2DDouble pointToRotate, double angle, bool degrees=true) const
 Rotate a point as element position being the origin.
 
virtual wxPoint2DDouble RotateLocal (wxPoint2DDouble local, double angleDeg) const
 
virtual wxPoint RotateAround (const wxPoint2DDouble &p, const wxPoint2DDouble &center, double angleDeg) const
 
virtual std::vector< Element * > GetParentList () const
 Get the parent list.
 
virtual std::vector< Element * > GetChildList () const
 Get the Child list.
 
virtual void CalculateBoundaries (wxPoint2DDouble &leftUp, wxPoint2DDouble &rightBottom) const
 Calculate the element boundaries.
 
virtual void GeneralMenuItens (wxMenu &menu)
 Insert general itens to context menu.
 
virtual bool ShowForm (wxWindow *parent, Element *element)
 Show element data form.
 
virtual double PointToLineDistance (wxPoint2DDouble point, int *segmentNumber=nullptr) const
 Calculate the distance between a line (formed by point list) and a point.
 
bool IsInserted () const
 Check if the element is properly inserted in the workspace.
 
void SetInserted (bool inserted=true)
 Set if the element is properly inserted in the workspace.
 
virtual rapidxml::xml_node * SaveElement (rapidxml::xml_document<> &doc, rapidxml::xml_node<> *elementListNode)
 
virtual bool OpenElement (rapidxml::xml_node<> *elementNode)
 
void SaveCADProperties (rapidxml::xml_document<> &doc, rapidxml::xml_node<> *elementNode)
 
bool OpenCADProperties (rapidxml::xml_node<> *elementNode)
 

Protected Member Functions

void UpdateSwitchesPosition ()
 
void UpdatePowerFlowArrowsPosition ()
 

Additional Inherited Members

- Static Public Member Functions inherited from Element
static bool DoubleFromString (wxWindow *parent, wxString strValue, double &value, wxString errorMsg)
 Get a double value from a string. Show a error message if the conversion fail.
 
static bool IntFromString (wxWindow *parent, wxString strValue, int &value, wxString errorMsg)
 Convert a string to int. Show a error message if the conversion fail.
 
static wxString StringFromDouble (double value, int minDecimal=1, int maxDecimals=13)
 Convert a double value to string.
 
- Protected Attributes inherited from PowerElement
SwitchingData m_swData
 
std::vector< std::vector< wxPoint2DDouble > > m_powerFlowArrow
 
PowerFlowDirection m_pfDirection = PowerFlowDirection::PF_NONE
 
wxColour m_busColour
 
wxColour m_onlineElementColour
 
wxColour m_offlineElementColour
 
wxColour m_closedSwitchColour
 
wxColour m_openedSwitchColour
 
wxColour m_powerFlowArrowColour
 
wxColour m_dynamicEventColour
 
bool m_dynEvent = false
 
- Protected Attributes inherited from Element
ElementType m_elementType = ElementType::TYPE_NONE
 
int m_elementID = 0
 
std::vector< Element * > m_parentList
 
std::vector< Element * > m_childList
 
wxRect2DDouble m_rect
 
wxPoint2DDouble m_position
 
double m_width = 0.0
 
double m_height = 0.0
 
double m_angle = 0.0
 
double m_borderSize = 2.0
 
double m_rotationAngle = 45.0
 
double m_switchSize = 10.0
 
std::vector< wxRect2DDouble > m_switchRect
 
bool m_selected = false
 
bool m_dragging = false
 
bool m_showPickbox = false
 
bool m_inserted = false
 
int m_activePickboxID = ID_PB_NONE
 
int m_activeNodeID = 0
 
std::vector< wxPoint2DDouble > m_pointList
 
std::vector< wxPoint2DDouble > m_movePts
 
wxPoint2DDouble m_moveStartPt
 
wxPoint2DDouble m_movePos
 
bool m_online = true
 
wxColour m_selectionColour
 

Detailed Description

Abstract class for rotary machines power elements.

Author
Thales Lima Oliveira thale.nosp@m.s@uf.nosp@m.u.br
Date
06/10/2017

Definition at line 33 of file Machines.h.

Member Enumeration Documentation

◆ SyncMachineModel

enum Machines::SyncMachineModel

Definition at line 36 of file Machines.h.

36{ SM_MODEL_1 = 0, SM_MODEL_2, SM_MODEL_3, SM_MODEL_4, SM_MODEL_5 };

Constructor & Destructor Documentation

◆ Machines()

Machines::Machines ( )

Definition at line 23 of file Machines.cpp.

23: PowerElement() {}
PowerElement()
Constructor.

◆ ~Machines()

virtual Machines::~Machines ( )
inlinevirtual

Definition at line 39 of file Machines.h.

39{}

Member Function Documentation

◆ AddParent()

bool Machines::AddParent ( Element parent,
wxPoint2DDouble  position 
)
virtual

Add a parent to the element. This method must be used on power elements that connect to a bus, so the parent must be a bus. The element basic points are calculated in this method, so apply this when the element is being inserted.

Parameters
parentElement parent.
positionNode position in the parent.

Reimplemented from Element.

Definition at line 24 of file Machines.cpp.

25{
26 if(parent) {
27 m_parentList.push_back(parent);
28 parent->AddChild(this);
29 wxPoint2DDouble parentPt =
30 parent->RotateAtPosition(position, -parent->GetAngle()); // Rotate click to horizontal position.
31 parentPt.m_y = parent->GetPosition().m_y; // Centralize on bus.
32 parentPt = parent->RotateAtPosition(parentPt, parent->GetAngle()); // Rotate back.
33
34 m_position = parentPt + wxPoint2DDouble(-100.0, 0.0); // Shifts the position to the left of the bus.
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);
37
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));
42 m_inserted = true;
43
44 wxRect2DDouble genRect(0, 0, 0, 0);
45 m_switchRect.push_back(genRect); // Push a general rectangle.
47 UpdatePowerFlowArrowsPosition();
48 return true;
49 }
50 return false;
51}
wxPoint2DDouble GetPosition() const
Get the element position.
Definition Element.h:186
double GetAngle() const
Get the element angle.
Definition Element.h:211
virtual wxPoint2DDouble RotateAtPosition(wxPoint2DDouble pointToRotate, double angle, bool degrees=true) const
Rotate a point as element position being the origin.
Definition Element.cpp:292
virtual void AddChild(Element *child)
Add a child to the child list.
Definition Element.cpp:566
virtual void UpdateSwitches()
Update the switch position.
virtual wxPoint2DDouble GetSwitchPoint(Element *parent, wxPoint2DDouble parentPoint, wxPoint2DDouble secondPoint) const
Get the correct switch position.
Here is the call graph for this function:

◆ Contains()

virtual bool Machines::Contains ( wxPoint2DDouble  position) const
inlinevirtual

Checks if the element contains a position.

Parameters
positionPosition to be checked.

Implements Element.

Definition at line 42 of file Machines.h.

42{ return m_rect.Contains(position); }

◆ DrawDC() [1/2]

void Machines::DrawDC ( wxPoint2DDouble  translation,
double  scale,
wxDC &  dc 
) const
virtual

Draw the element using wxDC.

Parameters
translationTranslation of the system.
scaleScale of the system.
dcDevice context.

Reimplemented from Element.

Definition at line 154 of file Machines.cpp.

155{
156 wxColour elementColour;
157 if (m_online) {
158 if (m_dynEvent)
159 elementColour = m_dynamicEventColour;
160 else
161 elementColour = m_onlineElementColour;
162 }
163 else
164 elementColour = m_offlineElementColour;
165
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));
169 }
170
171 if (m_inserted) {
172 // Draw Selection (layer 1).
173 if (m_selected) {
174 dc.SetPen(wxPen(m_selectionColour, 2 + m_borderSize * 2.0));
175 dc.SetBrush(*wxTRANSPARENT_BRUSH);
176 dc.DrawLines(pointListInt.size(), &pointListInt[0]);
177
178 dc.SetPen(*wxTRANSPARENT_PEN);
179 dc.SetBrush(wxBrush(m_selectionColour));
180 DrawDCCircle(m_position, 25.0 + (m_borderSize + 1.5) / scale, dc);
181
182 // Draw nodes selection.
183 DrawDCCircle(m_pointList[0], 5.0 + m_borderSize / scale, dc);
184 }
185
186 // Draw Machines (layer 2).
187 // Draw node.
188 dc.SetPen(*wxTRANSPARENT_PEN);
189 dc.SetBrush(wxBrush(elementColour));
190 DrawDCCircle(m_pointList[0], 5.0, dc);
191
192 dc.SetPen(wxPen(wxColour(elementColour), 2));
193 dc.SetBrush(*wxTRANSPARENT_BRUSH);
194 dc.DrawLines(pointListInt.size(), &pointListInt[0]);
195 DrawDCCircle(m_position, 25.0, dc);
196
197 DrawDCSwitches(dc);
199
200 dc.SetPen(*wxTRANSPARENT_PEN);
201 dc.SetBrush(*wxWHITE_BRUSH);
202 DrawDCCircle(m_position, 25.0, dc);
203
204 dc.SetPen(wxPen(elementColour, 2));
205 dc.SetBrush(*wxTRANSPARENT_BRUSH);
206 DrawDCCircle(m_position, 25.0, dc);
207
208 // Draw machine symbol.
209 DrawDCSymbol(dc);
210 }
211}
virtual void DrawDCCircle(wxPoint2DDouble position, double radius, int numSegments, wxGraphicsContext *gc) const
Draw a circle using device context.
Definition Element.cpp:177
virtual void DrawDCSwitches(wxGraphicsContext *gc) const
Draw switch.
virtual void DrawDCPowerFlowPts(wxGraphicsContext *gc) const
Draw power flow arrows.
Here is the call graph for this function:

◆ DrawDC() [2/2]

void Machines::DrawDC ( wxPoint2DDouble  translation,
double  scale,
wxGraphicsContext *  gc 
) const
virtual

Draw the element using GDI+.

Parameters
translationTranslation of the system.
scaleScale of the system.
gcGraphics context

Reimplemented from Element.

Definition at line 100 of file Machines.cpp.

101{
102 wxColour elementColour;
103 if (m_online) {
104 if (m_dynEvent)
105 elementColour = m_dynamicEventColour;
106 else
107 elementColour = m_onlineElementColour;
108 }
109 else
110 elementColour = m_offlineElementColour;
111
112 if (m_inserted) {
113 // Draw Selection (layer 1).
114 if (m_selected) {
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]);
118
119 gc->SetPen(*wxTRANSPARENT_PEN);
120 gc->SetBrush(wxBrush(m_selectionColour));
121 DrawDCCircle(m_position, 25.0 + (m_borderSize + 1.5) / scale, 20, gc);
122
123 // Draw nodes selection.
124 DrawDCCircle(m_pointList[0], 5.0 + m_borderSize / scale, 10, gc);
125 }
126
127 // Draw Machines (layer 2).
128 // Draw node.
129 gc->SetPen(*wxTRANSPARENT_PEN);
130 gc->SetBrush(wxBrush(elementColour));
131 DrawDCCircle(m_pointList[0], 5.0, 10, gc);
132
133 gc->SetPen(wxPen(wxColour(elementColour), 2));
134 gc->SetBrush(*wxTRANSPARENT_BRUSH);
135 gc->StrokeLines(m_pointList.size(), &m_pointList[0]);
136 DrawDCCircle(m_position, 25.0, 20.0, gc);
137
138 DrawDCSwitches(gc);
140
141 gc->SetPen(*wxTRANSPARENT_PEN);
142 gc->SetBrush(*wxWHITE_BRUSH);
143 DrawDCCircle(m_position, 25.0, 20.0, gc);
144
145 gc->SetPen(wxPen(elementColour, 2));
146 gc->SetBrush(*wxTRANSPARENT_BRUSH);
147 DrawDCCircle(m_position, 25.0, 20.0, gc);
148
149 // Draw machine symbol.
150 DrawDCSymbol(gc);
151 }
152}
Here is the call graph for this function:

◆ DrawDCSymbol() [1/2]

virtual void Machines::DrawDCSymbol ( wxDC &  dc) const
inlinevirtual

Definition at line 58 of file Machines.h.

58{}

◆ DrawDCSymbol() [2/2]

virtual void Machines::DrawDCSymbol ( wxGraphicsContext *  gc) const
inlinevirtual

Definition at line 57 of file Machines.h.

57{}

◆ Intersects()

virtual bool Machines::Intersects ( wxRect2DDouble  rect) const
inlinevirtual

Check if the element's rect intersects other rect.

Parameters
rectRect to check intersection.

Implements Element.

Definition at line 46 of file Machines.h.

46{ return m_rect.Intersects(rect); }
Here is the caller graph for this function:

◆ Move()

void Machines::Move ( wxPoint2DDouble  position)
virtual

Move the element other position.

Parameters
positionPosition that the element will be moved. Use StartMove(wxPoint2DDouble position) before start moving.

Reimplemented from Element.

Definition at line 223 of file Machines.cpp.

224{
225 SetPosition(m_movePos + position - m_moveStartPt);
226 for(int i = 2; i < (int)m_pointList.size(); i++) {
227 m_pointList[i] = m_movePts[i] + position - m_moveStartPt;
228 }
229 if(!m_parentList[0]) {
230 m_pointList[0] = m_movePts[0] + position - m_moveStartPt;
231 }
232 UpdateSwitchesPosition();
233 UpdatePowerFlowArrowsPosition();
234}
void SetPosition(const wxPoint2DDouble position)
Set the element position and update the rectangle.
Definition Element.cpp:27
Here is the call graph for this function:

◆ MoveNode()

void Machines::MoveNode ( Element parent,
wxPoint2DDouble  position 
)
virtual

Move a node. StartMove(wxPoint2DDouble position) before start moving.

Parameters
parentNode's parent.
positionNew node position.

Reimplemented from Element.

Definition at line 236 of file Machines.cpp.

237{
238 if(element) {
239 if(element == m_parentList[0]) {
240 m_pointList[0] = m_movePts[0] + position - m_moveStartPt;
241 }
242 } else {
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;
248 m_online = false;
249 }
250 }
251 }
252
253 // Recalculate switches positions
254 UpdateSwitchesPosition();
255 UpdatePowerFlowArrowsPosition();
256}

◆ NodeContains()

bool Machines::NodeContains ( wxPoint2DDouble  position)
virtual

Check if a node contains a point. If contains, set the attributes related to node movement.

Parameters
positionPosition tested.
Returns
True if at least one node contains the position, false otherwise.

Reimplemented from Element.

Definition at line 287 of file Machines.cpp.

288{
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);
291
292 if(nodeRect.Contains(position)) {
293 m_activeNodeID = 1;
294 return true;
295 }
296
297 m_activeNodeID = 0;
298 return false;
299}

◆ RemoveParent()

void Machines::RemoveParent ( Element parent)
virtual

Remove a parent.

Parameters
parentParent to be removed.

Reimplemented from Element.

Definition at line 277 of file Machines.cpp.

278{
279 if(parent == m_parentList[0]) {
280 m_parentList[0] = nullptr;
281 m_online = false;
282 UpdateSwitchesPosition();
283 UpdatePowerFlowArrowsPosition();
284 }
285}

◆ Rotate()

void Machines::Rotate ( bool  clockwise = true)
virtual

Rotate the element.

Parameters
clockwiseTrue to rotate clockwise, false to rotate counter-clockwise.

Reimplemented from Element.

Definition at line 344 of file Machines.cpp.

345{
346 double rotAngle = m_rotationAngle;
347 if(!clockwise) rotAngle = -m_rotationAngle;
348
349 m_angle += rotAngle;
350 if(m_angle >= 360 || m_angle <= -360) m_angle = 0.0;
351 m_pointList[2] = RotateAtPosition(m_pointList[2], rotAngle);
352 m_pointList[3] = RotateAtPosition(m_pointList[3], rotAngle);
353 UpdateSwitchesPosition();
354 UpdatePowerFlowArrowsPosition();
355}
Here is the call graph for this function:

◆ RotateNode()

void Machines::RotateNode ( Element parent,
bool  clockwise = true 
)
virtual

Rotate a node.

Parameters
parentNode's parent.
clockwiseTrue to rotate clockwise, false to rotate counter-clockwise.

Reimplemented from Element.

Definition at line 265 of file Machines.cpp.

266{
267 double rotAngle = m_rotationAngle;
268 if(!clockwise) rotAngle = -m_rotationAngle;
269
270 if(parent == m_parentList[0]) {
271 m_pointList[0] = parent->RotateAtPosition(m_pointList[0], rotAngle);
272 UpdateSwitchesPosition();
273 UpdatePowerFlowArrowsPosition();
274 }
275}
Here is the call graph for this function:

◆ SetNodeParent()

bool Machines::SetNodeParent ( Element parent)
virtual

Set a perent to the node. If all conditions are met, a new parent are added to the element and the points related to the nodes will be calculated.

Parameters
parentNode parent.
Returns
True if was possible to set the parent.

Reimplemented from Element.

Definition at line 301 of file Machines.cpp.

302{
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);
306
307 if(parent->Intersects(nodeRect)) {
308 m_parentList[0] = parent;
309
310 // Centralize the node on bus.
311 wxPoint2DDouble parentPt =
312 parent->RotateAtPosition(m_pointList[0], -parent->GetAngle()); // Rotate click to horizontal position.
313 parentPt.m_y = parent->GetPosition().m_y; // Centralize on bus.
314 parentPt = parent->RotateAtPosition(parentPt, parent->GetAngle());
315 m_pointList[0] = parentPt;
316
317 UpdateSwitchesPosition();
318 UpdatePowerFlowArrowsPosition();
319 return true;
320 } else {
321 m_parentList[0] = nullptr;
322 m_online = false;
323 }
324 }
325 return false;
326}
virtual bool Intersects(wxRect2DDouble rect) const =0
Check if the element's rect intersects other rect.
Here is the call graph for this function:

◆ SetPowerFlowDirection()

void Machines::SetPowerFlowDirection ( PowerFlowDirection  pfDirection)
virtual

Set the direction of the power flow.

Parameters
pfDirectionPower flow direction.

Reimplemented from PowerElement.

Definition at line 379 of file Machines.cpp.

380{
381 m_pfDirection = pfDirection;
382 UpdatePowerFlowArrowsPosition();
383}
Here is the caller graph for this function:

◆ StartMove()

void Machines::StartMove ( wxPoint2DDouble  position)
virtual

Update the element attributes related to the movement.

Parameters
positionStart move position.

Reimplemented from Element.

Definition at line 258 of file Machines.cpp.

259{
260 m_moveStartPt = position;
261 m_movePts = m_pointList;
262 m_movePos = m_position;
263}

◆ UpdateNodes()

void Machines::UpdateNodes ( )
virtual

Update the nodes according to the parents. If a parent is removed, use this method.

Reimplemented from Element.

Definition at line 328 of file Machines.cpp.

329{
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);
333
334 if(!m_parentList[0]->Intersects(nodeRect)) {
335 m_parentList[0]->RemoveChild(this);
336 m_parentList[0] = nullptr;
337 m_online = false;
338 UpdateSwitchesPosition();
339 UpdatePowerFlowArrowsPosition();
340 }
341 }
342}
virtual bool Intersects(wxRect2DDouble rect) const
Check if the element's rect intersects other rect.
Definition Machines.h:46
Here is the call graph for this function:

◆ UpdatePowerFlowArrowsPosition()

void Machines::UpdatePowerFlowArrowsPosition ( )
protected

Definition at line 357 of file Machines.cpp.

358{
359 std::vector<wxPoint2DDouble> edges;
360 switch(m_pfDirection) {
362 m_powerFlowArrow.clear();
363 } break;
365 edges.push_back(m_pointList[2]);
366 edges.push_back(m_pointList[1]);
367 } break;
369 edges.push_back(m_pointList[1]);
370 edges.push_back(m_pointList[2]);
371 } break;
372 default:
373 break;
374 }
375
377}
virtual void CalculatePowerFlowPts(std::vector< wxPoint2DDouble > edges)
Calculate the points of the power flow arrows.

◆ UpdateSwitchesPosition()

void Machines::UpdateSwitchesPosition ( )
protected

Definition at line 213 of file Machines.cpp.

214{
215 if(m_parentList[0]) {
216 m_pointList[1] = GetSwitchPoint(m_parentList[0], m_pointList[0], m_pointList[2]);
217 } else {
218 m_pointList[1] = m_pointList[0];
219 }
221}

The documentation for this class was generated from the following files: