Power System Platform  2026w34a-beta
Loading...
Searching...
No Matches
PowerElement Class Reference

Abstract class of power elements. More...

#include <PowerElement.h>

Inheritance diagram for PowerElement:
Collaboration diagram for PowerElement:

Public Member Functions

 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 UpdateSwitchesPosition ()
 
virtual void UpdatePowerFlowArrowsPosition ()
 
virtual void DrawDCSwitches (GUIColour *guiColour, wxGraphicsContext *gc) const
 Draw switch.
 
virtual void DrawDCSwitches (GUIColour *guiColour, wxDC &dc) const
 
virtual void CalculatePowerFlowPts (std::vector< wxPoint2DDouble > edges)
 Calculate the points of the power flow arrows.
 
virtual void DrawDCPowerFlowPts (GUIColour *guiColour, wxGraphicsContext *gc) const
 Draw power flow arrows.
 
virtual void DrawDCPowerFlowPts (GUIColour *guiColour, 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 void SetPowerFlowDirection (PowerFlowDirection pfDirection)
 Set the direction of the power flow.
 
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) const
 
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 std::vector< wxPoint2DDouble > & GetPointListRef ()
 
virtual bool AddParent (Element *parent, wxPoint2DDouble position, bool isOpening=false)
 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 void AddParent (Element *parent)
 Add a parent to the element.
 
virtual bool Contains (wxPoint2DDouble position) const =0
 Checks if the element contains a position.
 
virtual bool Intersects (wxRect2DDouble rect) const =0
 Check if the element's rect intersects other rect.
 
virtual Element * GetCopy ()
 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 void DrawDC (GUIColour *guiColour, wxPoint2DDouble translation, double scale, wxGraphicsContext *gc) const
 Draw the element using GDI+.
 
virtual void DrawDC (GUIColour *guiColour, wxPoint2DDouble translation, double scale, wxDC &dc) const
 Draw the element using wxDC.
 
virtual void Rotate (bool clockwise=true)
 Rotate the element.
 
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.
 
virtual void StartMove (wxPoint2DDouble position)
 Update the element attributes related to the movement.
 
virtual void Move (wxPoint2DDouble position)
 Move the element other position.
 
virtual void AlignToGrid (double gridSize=20.0)
 
virtual void MoveNode (Element *parent, wxPoint2DDouble position)
 Move a node. StartMove(wxPoint2DDouble position) before start moving.
 
virtual bool NodeContains (wxPoint2DDouble position)
 Check if a node contains a point. If contains, set the attributes related to node movement.
 
virtual void UpdateNodes ()
 Update the nodes according to the parents. If a parent is removed, use this method.
 
void SetParent (Element *parent, int num)
 
void SetChild (Element *child, int num)
 
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 RemoveParent (Element *parent)
 Remove a parent.
 
virtual void ReplaceParent (Element *oldParent, Element *newParent)
 Replace a parent.
 
virtual void RotateNode (Element *parent, bool clockwise=true)
 Rotate a node.
 
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 DrawStabilityEventGC (wxGraphicsContext *gc, wxPoint2DDouble translation, double scale, GUIColour *guiColour, bool rotateAnchor=false, wxPoint2DDouble iconPosition=wxPoint2DDouble(-1, -1)) 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 wxPoint2DDouble GetMoveStartPosition () const
 
virtual wxPoint2DDouble GetMovePosition () const
 
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, wxWindow *workspace=nullptr)
 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 Attributes

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
 

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.
 

Detailed Description

Abstract class of power elements.

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

Definition at line 95 of file PowerElement.h.

Constructor & Destructor Documentation

◆ PowerElement()

PowerElement::PowerElement ( )

Constructor.

Definition at line 24 of file PowerElement.cpp.

24 : Element()
25{
26 m_busColour.Set(0, 78, 255, 255);
27 m_onlineElementColour.Set(51, 51, 51, 255);
28 m_offlineElementColour.Set(128, 128, 128, 255);
29 m_closedSwitchColour.Set(0, 102, 0, 255);
30 m_openedSwitchColour.Set(255, 26, 26, 255);
31 m_powerFlowArrowColour.Set(255, 130, 0, 255);
32 m_dynamicEventColour.Set(255, 130, 0, 255);
33}
Element()
Constructor.
Definition Element.cpp:28

◆ ~PowerElement()

virtual PowerElement::~PowerElement ( )
inlinevirtual

Destructor.

Definition at line 105 of file PowerElement.h.

105{}

Member Function Documentation

◆ CalculatePowerFlowPts()

void PowerElement::CalculatePowerFlowPts ( std::vector< wxPoint2DDouble >  edges)
virtual

Calculate the points of the power flow arrows.

Parameters
edgesPoints of the element that arrows point.

Definition at line 191 of file PowerElement.cpp.

192{
193 double arrowRate = 100.0; // One arrow to each "arrowRate" distance in pixels.
194
195 if (edges.size() < 2) return;
196
197 // Clear all power flow points
198 for (int i = 0; i < (int)m_powerFlowArrow.size(); i++) m_powerFlowArrow[i].clear();
199 m_powerFlowArrow.clear();
200
201 for (int i = 1; i < (int)edges.size(); i++) {
202 wxPoint2DDouble pt1 = edges[i - 1];
203 wxPoint2DDouble pt2 = edges[i];
204
205 double angle = std::atan2(pt2.m_y - pt1.m_y, pt2.m_x - pt1.m_x);
206
207 wxPoint2DDouble rotPt2(
208 std::cos(-angle) * (pt2.m_x - pt1.m_x) - std::sin(-angle) * (pt2.m_y - pt1.m_y) + pt1.m_x,
209 std::sin(-angle) * (pt2.m_x - pt1.m_x) + std::cos(-angle) * (pt2.m_y - pt1.m_y) + pt1.m_y);
210
211 int numArrows = std::abs(pt1.m_x - rotPt2.m_x) / arrowRate;
212 if (numArrows == 0) numArrows = 1;
213
214 for (int i = 0; i < numArrows; i++) {
215 wxPoint2DDouble arrowCenter(pt1.m_x + ((rotPt2.m_x - pt1.m_x) / double(numArrows + 1)) * double(i + 1),
216 pt1.m_y + ((rotPt2.m_y - pt1.m_y) / double(numArrows + 1)) * double(i + 1));
217
218 std::vector<wxPoint2DDouble> triPts;
219 triPts.push_back(arrowCenter + wxPoint2DDouble(5.0, 0.0));
220 triPts.push_back(arrowCenter + wxPoint2DDouble(-5.0, 5.0));
221 triPts.push_back(arrowCenter + wxPoint2DDouble(-5.0, -5.0));
222
223 // Rotate back.
224 for (int i = 0; i < 3; i++) {
225 triPts[i] = wxPoint2DDouble(
226 std::cos(angle) * (triPts[i].m_x - pt1.m_x) - std::sin(angle) * (triPts[i].m_y - pt1.m_y) + pt1.m_x,
227 std::sin(angle) * (triPts[i].m_x - pt1.m_x) + std::cos(angle) * (triPts[i].m_y - pt1.m_y) +
228 pt1.m_y);
229 }
230 m_powerFlowArrow.push_back(triPts);
231 }
232 }
233}

◆ DrawDCPowerFlowPts() [1/2]

void PowerElement::DrawDCPowerFlowPts ( GUIColour *  guiColour,
wxDC &  dc 
) const
virtual

Definition at line 252 of file PowerElement.cpp.

253{
254 dc.SetPen(*wxTRANSPARENT_PEN);
255 if (m_online) {
256 dc.SetBrush(wxBrush(guiColour->pfArrow));
257 for (auto arrow : m_powerFlowArrow) {
258 std::vector<wxPoint> arrowPts;
259 for (auto& pt : arrow) {
260 arrowPts.emplace_back(static_cast<int>(pt.m_x), static_cast<int>(pt.m_y));
261 }
262 DrawDCTriangle(arrowPts, dc);
263 }
264 }
265}
virtual void DrawDCTriangle(std::vector< wxPoint2DDouble > points, wxGraphicsContext *gc) const
Draw rectangle.
Definition Element.cpp:209

◆ DrawDCPowerFlowPts() [2/2]

void PowerElement::DrawDCPowerFlowPts ( GUIColour *  guiColour,
wxGraphicsContext *  gc 
) const
virtual

Draw power flow arrows.

Draw power flow arrows using device context.

Parameters
gcDevice context.

Definition at line 243 of file PowerElement.cpp.

244{
245 gc->SetPen(*wxTRANSPARENT_PEN);
246 if (m_online) {
247 gc->SetBrush(wxBrush(guiColour->pfArrow));
248 for (auto arrow : m_powerFlowArrow) { DrawDCTriangle(arrow, gc); }
249 }
250}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DrawDCSwitches() [1/2]

void PowerElement::DrawDCSwitches ( GUIColour *  guiColour,
wxDC &  dc 
) const
virtual

Definition at line 170 of file PowerElement.cpp.

171{
172 dc.SetPen(*wxTRANSPARENT_PEN);
173
174 int i = 0;
175 for (auto parent : m_parentList) {
176 if (parent) {
177 if (m_online) {
178 dc.SetBrush(wxBrush(guiColour->swClose));
179 }
180 else {
181 dc.SetBrush(wxBrush(guiColour->swOpen));
182 }
183
184 DrawDCRectangle(m_switchRect[i].GetPosition() + wxPoint2DDouble(m_switchSize / 2.0, m_switchSize / 2.0),
185 m_switchSize, m_switchSize, parent->GetAngle(), dc);
186 }
187 i++;
188 }
189}
wxPoint2DDouble GetPosition() const
Get the element position.
Definition Element.h:189
virtual void DrawDCRectangle(wxPoint2DDouble position, double width, double height, double angle, wxDC &dc) const
Draw a circle.
Definition Element.cpp:41

◆ DrawDCSwitches() [2/2]

void PowerElement::DrawDCSwitches ( GUIColour *  guiColour,
wxGraphicsContext *  gc 
) const
virtual

Draw switch.

Draw switch using device context.

Definition at line 140 of file PowerElement.cpp.

141{
142 gc->SetPen(*wxTRANSPARENT_PEN);
143
144 int i = 0;
145 for (auto parent : m_parentList) {
146 if (parent) {
147 if (m_online) {
148 gc->SetBrush(wxBrush(guiColour->swClose));
149 }
150 else {
151 gc->SetBrush(wxBrush(guiColour->swOpen));
152 }
153
154 gc->PushState();
155 gc->Translate(m_switchRect[i].GetPosition().m_x + m_switchSize / 2.0,
156 m_switchRect[i].GetPosition().m_y + m_switchSize / 2.0);
157 gc->Rotate(wxDegToRad(parent->GetAngle()));
158 gc->Translate(-m_switchRect[i].GetPosition().m_x - m_switchSize / 2.0,
159 -m_switchRect[i].GetPosition().m_y - m_switchSize / 2.0);
160
161 wxPoint2DDouble switchPos = m_switchRect[i].GetPosition();
162 gc->DrawRectangle(switchPos.m_x, switchPos.m_y, m_switchSize, m_switchSize);
163
164 gc->PopState();
165 }
166 i++;
167 }
168}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetPlotData()

virtual bool PowerElement::GetPlotData ( ElementPlotData &  plotData,
PlotStudy  study = PlotStudy::STABILITY 
)
inlinevirtual

Fill the plot data.

Parameters
plotDataPlot data to be filled.
Returns
true if the plot data was successfully filled, false otherwise.

Reimplemented in Bus, IndMotor, Load, and SyncGenerator.

Definition at line 193 of file PowerElement.h.

193{ return false; }

◆ GetPowerFlowDirection()

virtual PowerFlowDirection PowerElement::GetPowerFlowDirection ( ) const
inlinevirtual

Return the direction of the power flow.

Returns
Power flow direction.

Definition at line 187 of file PowerElement.h.

187{ return m_pfDirection; }

◆ GetSwitchingData()

virtual SwitchingData PowerElement::GetSwitchingData ( )
inlinevirtual

Returns the switching data of the element.

Returns
Element switching data.

Definition at line 177 of file PowerElement.h.

177{ return m_swData; }

◆ GetSwitchPoint()

wxPoint2DDouble PowerElement::GetSwitchPoint ( Element *  parent,
wxPoint2DDouble  parentPoint,
wxPoint2DDouble  secondPoint 
) const
virtual

Get the correct switch position.

Parameters
parentBus with switch.
parentPointPosition of node on parent.
secondPointNext point in element.

Definition at line 39 of file PowerElement.cpp.

40{
41 double swLineSize = 20.0;
42
43 double dist = std::sqrt(
44 (secondPoint.m_x - parentPoint.m_x) *
45 (secondPoint.m_x - parentPoint.m_x) +
46 (secondPoint.m_y - parentPoint.m_y) *
47 (secondPoint.m_y - parentPoint.m_y));
48
49 if (dist > 0.0 && dist < swLineSize) {
50 swLineSize = dist / 2.0;
51 }
52
53 double angle = parent->GetAngle();
54
55 // Transform secondPoint to the local coordinate system of the parent.
56 double rad = wxDegToRad(-angle);
57 double c = std::cos(rad);
58 double s = std::sin(rad);
59
60 double dx = secondPoint.m_x - parentPoint.m_x;
61 double dy = secondPoint.m_y - parentPoint.m_y;
62
63 double localX = c * dx - s * dy;
64 double localY = s * dx + c * dy;
65
66 // Keep the original behavior:
67 // the switch is always perpendicular to the bus.
68 //
69 // The local Y coordinate only determines which side of the bus the switch should be placed.
70 if (localY > 0.0) {
71 angle -= 180.0;
72 }
73
74 // The switch starts above the parent in its local coordinate system and is rotated according to the parent angle.
75 wxPoint2DDouble swPoint(parentPoint.m_x, parentPoint.m_y - swLineSize);
76
77 double backRad = wxDegToRad(angle);
78 double bc = std::cos(backRad);
79 double bs = std::sin(backRad);
80
81 wxPoint2DDouble pt(bc * (swPoint.m_x - parentPoint.m_x) - bs * (swPoint.m_y - parentPoint.m_y) + parentPoint.m_x,
82 bs * (swPoint.m_x - parentPoint.m_x) + bc * (swPoint.m_y - parentPoint.m_y) + parentPoint.m_y);
83
84 if (std::abs(pt.m_x - std::round(pt.m_x)) < 1e-4)
85 pt.m_x = std::round(pt.m_x);
86
87 if (std::abs(pt.m_y - std::round(pt.m_y)) < 1e-4)
88 pt.m_y = std::round(pt.m_y);
89
90 return pt;
91}
double GetAngle() const
Get the element angle.
Definition Element.h:214
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetValueFromUnit()

double PowerElement::GetValueFromUnit ( double  value,
ElectricalUnit  valueUnit 
) const
virtual

Definition at line 267 of file PowerElement.cpp.

268{
269 switch (valueUnit) {
270 case ElectricalUnit::UNIT_kV:
271 case ElectricalUnit::UNIT_kA:
272 case ElectricalUnit::UNIT_kW:
273 case ElectricalUnit::UNIT_kVA:
274 case ElectricalUnit::UNIT_kvar: {
275 return value * 1e3;
276 } break;
277 case ElectricalUnit::UNIT_MW:
278 case ElectricalUnit::UNIT_MVA:
279 case ElectricalUnit::UNIT_Mvar: {
280 return value * 1e6;
281 }
282 default:
283 break;
284 }
285 return value;
286}

◆ HaveDynamicEvent()

virtual bool PowerElement::HaveDynamicEvent ( ) const
inlinevirtual

Check if the power element have dynamic event.

Returns
true if the element have dynamic an event, false otherwise.

Definition at line 198 of file PowerElement.h.

198{ return m_dynEvent; }

◆ OpenCADProperties()

bool PowerElement::OpenCADProperties ( rapidxml::xml_node<> *  elementNode,
std::vector< Element * >  parentList 
)
virtual

Definition at line 288 of file PowerElement.cpp.

289{
290 auto cadPropNode = elementNode->first_node("CADProperties");
291 if (!cadPropNode) return false;
292
293 auto position = cadPropNode->first_node("Position");
294 double posX = XMLParser::GetNodeValueDouble(position, "X");
295 double posY = XMLParser::GetNodeValueDouble(position, "Y");
296 auto size = cadPropNode->first_node("Size");
297 m_width = XMLParser::GetNodeValueDouble(size, "Width");
298 m_height = XMLParser::GetNodeValueDouble(size, "Height");
299 double angle = XMLParser::GetNodeValueDouble(cadPropNode, "Angle");
300 SetPosition(wxPoint2DDouble(posX, posY));
301
302 auto nodePosition = cadPropNode->first_node("NodePosition");
303 double nodePosX = XMLParser::GetNodeValueDouble(nodePosition, "X");
304 double nodePosY = XMLParser::GetNodeValueDouble(nodePosition, "Y");
305
306 int parentID = XMLParser::GetNodeValueInt(cadPropNode, "ParentID");
307 // If the opened power element has no parent, set up the basics CAD properties of the element manually, otherwise
308 // just class method AddParent to calculate properly.
309 if (parentID == -1) {
310 m_parentList.push_back(nullptr);
311 m_pointList.push_back(wxPoint2DDouble(nodePosX, nodePosY));
312 m_pointList.push_back(wxPoint2DDouble(nodePosX, nodePosY));
313 m_pointList.push_back(m_position + wxPoint2DDouble(0.0, -m_height / 2.0 - 10.0));
314 m_pointList.push_back(m_position + wxPoint2DDouble(0.0, -m_height / 2.0));
315
316 wxRect2DDouble genRect(0, 0, 0, 0);
317 m_switchRect.push_back(genRect); // Push a general rectangle.
319
320 m_online = false; // Not connected elements are always offline.
321 }
322 else {
323 AddParent(parentList[parentID], wxPoint2DDouble(nodePosX, nodePosY), true);
324 }
325
326 // Set up the points properly.
327 StartMove(m_position);
328 Move(wxPoint2DDouble(posX, posY));
329
330 // Set the rotation properly.
331 int numRot = angle / m_rotationAngle;
332 bool clockwise = true;
333 if (numRot < 0) {
334 numRot = std::abs(numRot);
335 clockwise = false;
336 }
337 for (int i = 0; i < numRot; i++) Rotate(clockwise);
338
339 return true;
340}
virtual bool AddParent(Element *parent, wxPoint2DDouble position, bool isOpening=false)
Add a parent to the element. This method must be used on power elements that connect to a bus,...
Definition Element.h:243
virtual void StartMove(wxPoint2DDouble position)
Update the element attributes related to the movement.
Definition Element.cpp:335
void SetPosition(const wxPoint2DDouble position)
Set the element position and update the rectangle.
Definition Element.cpp:33
virtual void Move(wxPoint2DDouble position)
Move the element other position.
Definition Element.cpp:341
virtual void Rotate(bool clockwise=true)
Rotate the element.
Definition Element.h:321
virtual void UpdateSwitches()
Update the switch position.

◆ OpenElement()

virtual bool PowerElement::OpenElement ( rapidxml::xml_node<> *  elementNode,
std::vector< Element * >  parentList 
)
inlinevirtual

Definition at line 208 of file PowerElement.h.

208{ return true; }

◆ OpenSwitchingData()

bool PowerElement::OpenSwitchingData ( rapidxml::xml_node<> *  electricalNode)
virtual

Definition at line 380 of file PowerElement.cpp.

381{
382 auto switchingList = electricalNode->first_node("SwitchingList");
383 if (!switchingList) return false;
384 auto swNode = switchingList->first_node("Switching");
385 while (swNode) {
386 m_swData.swType.push_back((SwitchingType)XMLParser::GetNodeValueInt(swNode, "Type"));
387 m_swData.swTime.push_back(XMLParser::GetNodeValueDouble(swNode, "Time"));
388 swNode = swNode->next_sibling("Switching");
389 }
390 return true;
391}
SwitchingType
Type of switching.
std::vector< double > swTime
std::vector< SwitchingType > swType

◆ SaveCADProperties()

void PowerElement::SaveCADProperties ( rapidxml::xml_document<> &  doc,
rapidxml::xml_node<> *  elementNode 
)
virtual

Definition at line 342 of file PowerElement.cpp.

343{
344 auto cadProp = XMLParser::AppendNode(doc, elementNode, "CADProperties");
345 auto position = XMLParser::AppendNode(doc, cadProp, "Position");
346 auto posX = XMLParser::AppendNode(doc, position, "X");
347 XMLParser::SetNodeValue(doc, posX, m_position.m_x);
348 auto posY = XMLParser::AppendNode(doc, position, "Y");
349 XMLParser::SetNodeValue(doc, posY, m_position.m_y);
350 auto size = XMLParser::AppendNode(doc, cadProp, "Size");
351 auto width = XMLParser::AppendNode(doc, size, "Width");
352 XMLParser::SetNodeValue(doc, width, m_width);
353 auto height = XMLParser::AppendNode(doc, size, "Height");
354 XMLParser::SetNodeValue(doc, height, m_height);
355 auto angle = XMLParser::AppendNode(doc, cadProp, "Angle");
356 XMLParser::SetNodeValue(doc, angle, m_angle);
357 auto nodePos = XMLParser::AppendNode(doc, cadProp, "NodePosition");
358 auto nodePosX = XMLParser::AppendNode(doc, nodePos, "X");
359 XMLParser::SetNodeValue(doc, nodePosX, m_pointList[0].m_x);
360 auto nodePosY = XMLParser::AppendNode(doc, nodePos, "Y");
361 XMLParser::SetNodeValue(doc, nodePosY, m_pointList[0].m_y);
362 auto parentID = XMLParser::AppendNode(doc, cadProp, "ParentID");
363 Element* parent = m_parentList[0];
364 if (parent) XMLParser::SetNodeValue(doc, parentID, parent->GetID());
365}
Base class of all elements of the program. This class is responsible for manage graphical and his dat...
Definition Element.h:115
virtual int GetID() const
Get the element ID.
Definition Element.h:275

◆ SaveSwitchingData()

void PowerElement::SaveSwitchingData ( rapidxml::xml_document<> &  doc,
rapidxml::xml_node<> *  electricalNode 
)
virtual

Definition at line 367 of file PowerElement.cpp.

368{
369 auto switchingList = XMLParser::AppendNode(doc, electricalNode, "SwitchingList");
370 for (int i = 0; i < static_cast<int>(m_swData.swType.size()); i++) {
371 auto switching = XMLParser::AppendNode(doc, switchingList, "Switching");
372 XMLParser::SetNodeAttribute(doc, switching, "ID", i);
373 auto swType = XMLParser::AppendNode(doc, switching, "Type");
374 XMLParser::SetNodeValue(doc, swType, static_cast<int>(m_swData.swType[i]));
375 auto swTime = XMLParser::AppendNode(doc, switching, "Time");
376 XMLParser::SetNodeValue(doc, swTime, m_swData.swTime[i]);
377 }
378}

◆ SetDynamicEvent()

virtual void PowerElement::SetDynamicEvent ( bool  dynEvent = true)
inlinevirtual

Set if the power element have dynamic event.

Parameters
dynEventEvent occurrence.

Definition at line 203 of file PowerElement.h.

203{ m_dynEvent = dynEvent; }

◆ SetNominalVoltage()

void PowerElement::SetNominalVoltage ( std::vector< double >  nominalVoltage,
std::vector< ElectricalUnit >  nominalVoltageUnit 
)
virtual

Set nominal voltage of the element.

Parameters
nominalVoltageValue of the nominal voltage.
nominalVoltageUnitUnit of the nominal voltage.

Reimplemented in EMTElement, Line, SyncGenerator, SyncMotor, and Transformer.

Definition at line 35 of file PowerElement.cpp.

36{
37}

◆ SetPowerFlowDirection()

virtual void PowerElement::SetPowerFlowDirection ( PowerFlowDirection  pfDirection)
inlinevirtual

Set the direction of the power flow.

Parameters
pfDirectionPower flow direction.

Reimplemented in Line, Machines, and Transformer.

Definition at line 182 of file PowerElement.h.

182{ m_pfDirection = pfDirection; }
Here is the caller graph for this function:

◆ SetSwitchingData()

virtual void PowerElement::SetSwitchingData ( SwitchingData  data)
inlinevirtual

Set the switching data of the element.

Parameters
dataSwitching data.

Definition at line 172 of file PowerElement.h.

172{ m_swData = data; }

◆ SwitchesContains()

bool PowerElement::SwitchesContains ( wxPoint2DDouble  position) const
virtual

Check if switch contains position.

Parameters
positionposition to be checked.

Definition at line 93 of file PowerElement.cpp.

94{
95 for (int i = 0; i < (int)m_switchRect.size(); i++) {
96 if (m_parentList[i]) {
97 if (m_switchRect[i].Contains(position)) return true;
98 }
99 }
100 return false;
101}
virtual bool Contains(wxPoint2DDouble position) const =0
Checks if the element contains a position.
Here is the call graph for this function:

◆ UpdatePowerFlowArrowsPosition()

virtual void PowerElement::UpdatePowerFlowArrowsPosition ( )
inlinevirtual

Definition at line 128 of file PowerElement.h.

128{}

◆ UpdateSwitches()

void PowerElement::UpdateSwitches ( )
virtual

Update the switch position.

Reimplemented in Branch.

Definition at line 103 of file PowerElement.cpp.

104{
105 // General method, to one switch only.
106 wxPoint2DDouble swCenter = wxPoint2DDouble((m_pointList[0].m_x + m_pointList[1].m_x) / 2.0,
107 (m_pointList[0].m_y + m_pointList[1].m_y) / 2.0);
108 m_switchRect[0] = wxRect2DDouble(swCenter.m_x - m_switchSize / 2.0, swCenter.m_y - m_switchSize / 2.0, m_switchSize,
109 m_switchSize);
110}
Here is the caller graph for this function:

◆ UpdateSwitchesPosition()

virtual void PowerElement::UpdateSwitchesPosition ( )
inlinevirtual

Definition at line 127 of file PowerElement.h.

127{}

Member Data Documentation

◆ m_busColour

wxColour PowerElement::m_busColour
protected

Definition at line 217 of file PowerElement.h.

◆ m_closedSwitchColour

wxColour PowerElement::m_closedSwitchColour
protected

Definition at line 220 of file PowerElement.h.

◆ m_dynamicEventColour

wxColour PowerElement::m_dynamicEventColour
protected

Definition at line 223 of file PowerElement.h.

◆ m_dynEvent

bool PowerElement::m_dynEvent = false
protected

Definition at line 225 of file PowerElement.h.

◆ m_offlineElementColour

wxColour PowerElement::m_offlineElementColour
protected

Definition at line 219 of file PowerElement.h.

◆ m_onlineElementColour

wxColour PowerElement::m_onlineElementColour
protected

Definition at line 218 of file PowerElement.h.

◆ m_openedSwitchColour

wxColour PowerElement::m_openedSwitchColour
protected

Definition at line 221 of file PowerElement.h.

◆ m_pfDirection

PowerFlowDirection PowerElement::m_pfDirection = PowerFlowDirection::PF_NONE
protected

Definition at line 215 of file PowerElement.h.

◆ m_powerFlowArrow

std::vector<std::vector<wxPoint2DDouble> > PowerElement::m_powerFlowArrow
protected

Definition at line 214 of file PowerElement.h.

◆ m_powerFlowArrowColour

wxColour PowerElement::m_powerFlowArrowColour
protected

Definition at line 222 of file PowerElement.h.

◆ m_swData

SwitchingData PowerElement::m_swData
protected

Definition at line 213 of file PowerElement.h.


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