Power System Platform  2026w23a-beta
Loading...
Searching...
No Matches
Element Class Referenceabstract

Base class of all elements of the program. This class is responsible for manage graphical and his data. More...

#include <Element.h>

Inheritance diagram for Element:

Public Member Functions

 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 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 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 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 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 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 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, 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)
 

Static Public Member Functions

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

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
 

Detailed Description

Base class of all elements of the program. This class is responsible for manage graphical and his data.

Author
Thales Lima Oliveira thale.nosp@m.s@uf.nosp@m.u.br
Date
19/09/2017
Warning
Don't use this base class directly. Always create a derivative element to use it.

Definition at line 113 of file Element.h.

Constructor & Destructor Documentation

◆ Element()

Element::Element ( )

Constructor.

Definition at line 28 of file Element.cpp.

29{
30 //m_selectionColour.Set(0, 128, 255, 128);
31}

◆ ~Element()

virtual Element::~Element ( )
inlinevirtual

Destructor.

Definition at line 124 of file Element.h.

124{}

Member Function Documentation

◆ AddChild()

void Element::AddChild ( Element child)
virtual

Add a child to the child list.

Parameters
childNew child.

Definition at line 499 of file Element.cpp.

499{ m_childList.push_back(child); }
Here is the caller graph for this function:

◆ AddParent() [1/2]

virtual void Element::AddParent ( Element parent)
inlinevirtual

Add a parent to the element.

Parameters
parentElement parent.

Definition at line 246 of file Element.h.

246{ m_parentList.push_back(parent); }

◆ AddParent() [2/2]

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

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 in Bus, Capacitor, EMTElement, HarmCurrent, Inductor, Line, Load, Machines, Transformer, and Text.

Definition at line 241 of file Element.h.

241{ return false; }

◆ AddPoint()

virtual void Element::AddPoint ( wxPoint2DDouble  point)
inlinevirtual

Add point to the list of points that connect the element to the bus.

Parameters
pointPoint to be added.

Reimplemented in Branch, and Line.

Definition at line 330 of file Element.h.

330{}

◆ CalculateBoundaries()

void Element::CalculateBoundaries ( wxPoint2DDouble &  leftUp,
wxPoint2DDouble &  rightBottom 
) const
virtual

Calculate the element boundaries.

Parameters
leftUpTop-left position of the element.
rightBottomBottom-right position of the element.

Reimplemented in Line.

Definition at line 411 of file Element.cpp.

412{
413 // Check rect corners boundaries.
414
415 // Get rectangle corners
416 wxPoint2DDouble rectCorner[4] = { m_rect.GetLeftTop(), m_rect.GetLeftBottom(), m_rect.GetRightBottom(),
417 m_rect.GetRightTop() };
418 // Rotate corners.
419 for (int i = 0; i < 4; ++i) { rectCorner[i] = RotateAtPosition(rectCorner[i], m_angle); }
420 leftUp = rectCorner[0];
421 rightBottom = rectCorner[0];
422 for (int i = 1; i < 4; ++i) {
423 if (rectCorner[i].m_x < leftUp.m_x) leftUp.m_x = rectCorner[i].m_x;
424 if (rectCorner[i].m_y < leftUp.m_y) leftUp.m_y = rectCorner[i].m_y;
425 if (rectCorner[i].m_x > rightBottom.m_x) rightBottom.m_x = rectCorner[i].m_x;
426 if (rectCorner[i].m_y > rightBottom.m_y) rightBottom.m_y = rectCorner[i].m_y;
427 }
428
429 // Check points list boundaries.
430 for (int i = 0; i < (int)m_pointList.size(); i++) {
431 if (m_pointList[i].m_x < leftUp.m_x) leftUp.m_x = m_pointList[i].m_x;
432 if (m_pointList[i].m_y < leftUp.m_y) leftUp.m_y = m_pointList[i].m_y;
433 if (m_pointList[i].m_x > rightBottom.m_x) rightBottom.m_x = m_pointList[i].m_x;
434 if (m_pointList[i].m_y > rightBottom.m_y) rightBottom.m_y = m_pointList[i].m_y;
435 }
436}
virtual wxPoint2DDouble RotateAtPosition(wxPoint2DDouble pointToRotate, double angle, bool degrees=true) const
Rotate a point as element position being the origin.
Definition Element.cpp:228
Here is the call graph for this function:

◆ Contains()

virtual bool Element::Contains ( wxPoint2DDouble  position) const
pure virtual

Checks if the element contains a position.

Parameters
positionPosition to be checked.

Implemented in ConnectionLine, Constant, Exponential, Gain, IOControl, Limiter, MathExpression, MathOperation, RateLimiter, Sum, TransferFunction, Branch, Bus, Capacitor, EMTElement, HarmCurrent, Inductor, Line, Machines, Shunt, Transformer, and Text.

Here is the caller graph for this function:

◆ DoubleFromString()

bool Element::DoubleFromString ( wxWindow *  parent,
wxString  strValue,
double &  value,
wxString  errorMsg 
)
static

Get a double value from a string. Show a error message if the conversion fail.

Parameters
parentMessage box parent.
strValueString value to be converted.
valueDouble value converted.
errorMsgError message.

Definition at line 438 of file Element.cpp.

439{
440 double dValue = 0.0;
441
442 if (!strValue.ToDouble(&dValue)) {
443 wxMessageDialog msgDialog(parent, errorMsg, _("Error"), wxOK | wxCENTRE | wxICON_ERROR);
444 msgDialog.ShowModal();
445 return false;
446 }
447
448 value = dValue;
449 return true;
450}

◆ DrawDC() [1/2]

virtual void Element::DrawDC ( GUIColour guiColour,
wxPoint2DDouble  translation,
double  scale,
wxDC &  dc 
) const
inlinevirtual

Draw the element using wxDC.

Parameters
guiColourColours of the system defined in properties.
translationTranslation of the system.
scaleScale of the system.
dcDevice context.

Reimplemented in Bus, Capacitor, EMTElement, HarmCurrent, Inductor, Line, Load, Machines, and Transformer.

Definition at line 314 of file Element.h.

314{}

◆ DrawDC() [2/2]

virtual void Element::DrawDC ( GUIColour guiColour,
wxPoint2DDouble  translation,
double  scale,
wxGraphicsContext *  gc 
) const
inlinevirtual

Draw the element using GDI+.

Parameters
guiColourColours of the system defined in properties.
translationTranslation of the system.
scaleScale of the system.
gcGraphics context

Reimplemented in ConnectionLine, Constant, Exponential, Gain, IOControl, Limiter, MathExpression, MathOperation, RateLimiter, Sum, TransferFunction, Bus, Capacitor, EMTElement, HarmCurrent, Inductor, Line, Load, Machines, and Transformer.

Definition at line 306 of file Element.h.

306{}

◆ DrawDCArc() [1/2]

void Element::DrawDCArc ( wxPoint2DDouble  position,
double  radius,
double  initAngle,
double  finalAngle,
int  numSegments,
wxGraphicsContext *  gc 
) const
virtual

Definition at line 190 of file Element.cpp.

191{
192 double initAngRad = wxDegToRad(initAngle);
193 double finalAngRad = wxDegToRad(finalAngle);
194 wxPoint2DDouble* points = new wxPoint2DDouble[numSegments + 2];
195 for (int i = 0; i <= numSegments; i++) {
196 double theta = initAngRad + (finalAngRad - initAngRad) * double(i) / double(numSegments);
197 points[i] = wxPoint2DDouble(radius * std::cos(theta) + position.m_x, radius * std::sin(theta) + position.m_y);
198 }
199
200 gc->StrokeLines(numSegments + 1, points);
201 delete[] points;
202}

◆ DrawDCArc() [2/2]

void Element::DrawDCArc ( wxPoint2DDouble  position,
double  radius,
double  initAngle,
double  finalAngle,
wxDC &  dc 
) const
virtual

Definition at line 204 of file Element.cpp.

205{
206 dc.DrawEllipticArc(wxRound(position.m_x - radius), wxRound(position.m_y - radius), wxRound(2 * radius), wxRound(2 * radius), initAngle, finalAngle);
207}

◆ DrawDCCircle() [1/2]

void Element::DrawDCCircle ( wxPoint2DDouble  position,
double  radius,
int  numSegments,
wxGraphicsContext *  gc 
) const
virtual

Draw a circle using device context.

Parameters
positionCircle position.
radiusCircle radius
numSegmentsNum of segments of the circle.
glDevice context.

Definition at line 173 of file Element.cpp.

174{
175 wxPoint2DDouble* pts = new wxPoint2DDouble[numSegments + 1];
176 for (int i = 0; i < numSegments; i++) {
177 double theta = 2.0 * 3.1415926 * double(i) / double(numSegments);
178 pts[i] = wxPoint2DDouble(radius * std::cos(theta) + position.m_x, radius * std::sin(theta) + position.m_y);
179 }
180 pts[numSegments] = pts[0];
181 gc->DrawLines(numSegments + 1, pts);
182 delete[] pts;
183}
Here is the caller graph for this function:

◆ DrawDCCircle() [2/2]

void Element::DrawDCCircle ( wxPoint2DDouble  position,
double  radius,
wxDC &  dc 
) const
virtual

Definition at line 185 of file Element.cpp.

186{
187 dc.DrawCircle(wxRound(position.m_x), wxRound(position.m_y), wxRound(radius));
188}

◆ DrawDCPickbox()

void Element::DrawDCPickbox ( wxPoint2DDouble  position,
wxGraphicsContext *  gc 
) const
virtual

Draw a point.

Parameters
positionPoint position.
sizePoint size.

Draw line.

Parameters
pointsLine vertices.
modeOpenGl primitive.

Draw pickbox.

Parameters
positionPickbox position.

Draw pickbox using direct context.

Parameters
positionPickbox position.
gcDirect context.

Definition at line 221 of file Element.cpp.

222{
223 gc->SetPen(wxPen(wxColour(0, 0, 0, 255)));
224 gc->SetBrush(wxBrush(wxColour(255, 255, 255, 204)));
225 gc->DrawRectangle(position.m_x, position.m_y, 8, 8);
226}
Here is the caller graph for this function:

◆ DrawDCRectangle()

void Element::DrawDCRectangle ( wxPoint2DDouble  position,
double  width,
double  height,
double  angle,
wxDC &  dc 
) const
virtual

Draw a circle.

Parameters
positionCircle position.
radiusCircle radius
numSegmentsNum of segments of the circle.
modeOpenGl primitive.

Definition at line 41 of file Element.cpp.

42{
43 if (angle == 0.0) {
44 wxPoint poly[4] = {
45 wxPoint((int)(position.m_x - width / 2.0), (int)(position.m_y - height / 2.0)),
46 wxPoint((int)(position.m_x + width / 2.0), (int)(position.m_y - height / 2.0)),
47 wxPoint((int)(position.m_x + width / 2.0), (int)(position.m_y + height / 2.0)),
48 wxPoint((int)(position.m_x - width / 2.0), (int)(position.m_y + height / 2.0))
49 };
50 dc.DrawPolygon(4, poly);
51 return;
52 }
53
54 double hw = width / 2.0;
55 double hh = height / 2.0;
56 double angleRad = wxDegToRad(angle);
57
58 // Retângulo centrado na origem
59 wxPoint2DDouble pts[4] = {
60 {-hw, -hh},
61 { hw, -hh},
62 { hw, hh},
63 {-hw, hh}
64 };
65
66 wxPoint poly[4];
67
68 for (int i = 0; i < 4; ++i)
69 {
70 double x = pts[i].m_x;
71 double y = pts[i].m_y;
72
73 // Rotação
74 double xr = x * cos(angleRad) - y * sin(angleRad);
75 double yr = x * sin(angleRad) + y * cos(angleRad);
76
77 // Translação para centro
78 poly[i].x = (int)(xr + position.m_x);
79 poly[i].y = (int)(yr + position.m_y);
80 }
81
82 dc.DrawPolygon(4, poly);
83
84}
Here is the caller graph for this function:

◆ DrawDCRoundedRectRotated()

void Element::DrawDCRoundedRectRotated ( wxDC &  dc,
const wxPoint2DDouble &  center,
double  width,
double  height,
double  radius,
double  angleDeg,
int  arcSegments = 8 
) const
virtual

Definition at line 86 of file Element.cpp.

87{
88 radius = std::min(radius, std::min(width, height) / 2.0);
89
90 double hw = width / 2.0;
91 double hh = height / 2.0;
92
93 double rad = wxDegToRad(angleDeg);
94 double c = std::cos(rad);
95 double s = std::sin(rad);
96
97 auto rotate = [&](double x, double y)
98 {
99 double xr = c * x - s * y + center.m_x;
100 double yr = s * x + c * y + center.m_y;
101 return wxPoint2DDouble(xr, yr);
102 };
103
104 auto drawArc = [&](double cx, double cy,
105 double startDeg)
106 {
107 wxPoint2DDouble arcCenterLocal(cx, cy);
108 wxPoint2DDouble arcCenter = rotate(arcCenterLocal.m_x,
109 arcCenterLocal.m_y);
110
111 double start = startDeg + angleDeg;
112 double end = start + 90.0;
113
114 dc.DrawEllipticArc(
115 wxRound(arcCenter.m_x - radius),
116 wxRound(arcCenter.m_y - radius),
117 wxRound(radius * 2),
118 wxRound(radius * 2),
119 start,
120 end
121 );
122 };
123
124 auto line = [&](double x1, double y1,
125 double x2, double y2,
126 wxPoint& p1, wxPoint& p2)
127 {
128 wxPoint2DDouble p1d = rotate(x1, y1);
129 wxPoint2DDouble p2d = rotate(x2, y2);
130 p1 = wxPoint(wxRound(p1d.m_x), wxRound(p1d.m_y));
131 p2 = wxPoint(wxRound(p2d.m_x), wxRound(p2d.m_y));
132
133 //dc.DrawLine(p1.x, p1.y, p2.x, p2.y);
134 };
135
136 wxPen pen = dc.GetPen();
137
138 wxPoint pts[4];
139 line(-hw + radius, -hh,
140 hw - radius, -hh,
141 pts[0], pts[1]);
142
143 line(hw - radius, hh,
144 -hw + radius, hh,
145 pts[2], pts[3]);
146
147 dc.SetPen(*wxTRANSPARENT_PEN);
148 dc.DrawPolygon(4, pts);
149 dc.SetPen(pen);
150 dc.DrawLine(pts[0].x, pts[0].y, pts[1].x, pts[1].y);
151 dc.DrawLine(pts[2].x, pts[2].y, pts[3].x, pts[3].y);
152
153 line(hw, -hh + radius,
154 hw, hh - radius,
155 pts[0], pts[1]);
156
157 line(-hw, hh - radius,
158 -hw, -hh + radius,
159 pts[2], pts[3]);
160
161 dc.SetPen(*wxTRANSPARENT_PEN);
162 dc.DrawPolygon(4, pts);
163 dc.SetPen(pen);
164 dc.DrawLine(pts[0].x, pts[0].y, pts[1].x, pts[1].y);
165 dc.DrawLine(pts[2].x, pts[2].y, pts[3].x, pts[3].y);
166
167 drawArc(hw - radius, -hh + radius, 0 - angleDeg * 2);
168 drawArc(hw - radius, hh - radius, 270 - angleDeg * 2);
169 drawArc(-hw + radius, hh - radius, 180 - angleDeg * 2);
170 drawArc(-hw + radius, -hh + radius, 90 - angleDeg * 2);
171}

◆ DrawDCTriangle() [1/2]

void Element::DrawDCTriangle ( std::vector< wxPoint >  points,
wxDC &  dc 
) const
virtual

Definition at line 215 of file Element.cpp.

216{
217 points.emplace_back(points[0]);
218 dc.DrawPolygon(4, &points[0]);
219}

◆ DrawDCTriangle() [2/2]

void Element::DrawDCTriangle ( std::vector< wxPoint2DDouble >  points,
wxGraphicsContext *  gc 
) const
virtual

Draw rectangle.

Parameters
positionRectangle position.
widthRectangle width.
heightRectangle height.
modeOpenGl primitive.

Draw rectangle.

Parameters
pointsRectangle vertices.
modeOpenGl primitive.

Draw a triangle.

Parameters
pointsTriangle vertices.
modeOpenGl primitive.

Draw a triangle.

Parameters
pointsTriangle vertices.
gcDevice context.

Definition at line 209 of file Element.cpp.

210{
211 points.emplace_back(points[0]);
212 gc->DrawLines(4, &points[0]);
213}
Here is the caller graph for this function:

◆ GeneralMenuItens()

void Element::GeneralMenuItens ( wxMenu &  menu)
virtual

Insert general itens to context menu.

Parameters
menuMenu that will be inserted the general itens.

Definition at line 393 of file Element.cpp.

394{
395 wxFileName exeFileName(wxStandardPaths::Get().GetExecutablePath());
396 //wxString exePath = exeFileName.GetPath();
397
398 wxMenuItem* clockItem = new wxMenuItem(&menu, ID_ROTATE_CLOCK, _("Rotate clockwise"));
399 clockItem->SetBitmap(wxImage(Paths::GetDataPath() + "/images/menu/rotateClock16.png"));
400 menu.Append(clockItem);
401
402 wxMenuItem* counterClockItem = new wxMenuItem(&menu, ID_ROTATE_COUNTERCLOCK, _("Rotate counter-clockwise"));
403 counterClockItem->SetBitmap(wxImage(Paths::GetDataPath() + "/images/menu/rotateCounterClock16.png"));
404 menu.Append(counterClockItem);
405
406 wxMenuItem* deleteItem = new wxMenuItem(&menu, ID_DELETE, _("Delete"));
407 deleteItem->SetBitmap(wxImage(Paths::GetDataPath() + "/images/menu/delete16.png"));
408 menu.Append(deleteItem);
409}
@ ID_DELETE
Definition Element.h:82
@ ID_ROTATE_CLOCK
Definition Element.h:80
@ ID_ROTATE_COUNTERCLOCK
Definition Element.h:81
Here is the caller graph for this function:

◆ GetAngle()

double Element::GetAngle ( ) const
inline

Get the element angle.

Returns
Angle value.

Definition at line 213 of file Element.h.

213{ return m_angle; }
Here is the caller graph for this function:

◆ GetBestPickboxCursor()

virtual wxCursor Element::GetBestPickboxCursor ( ) const
inlinevirtual

Get the best cursor to shown to the user when the mouse is above a pickbox.

Returns
Cursor.

Reimplemented in Branch, Bus, and Line.

Definition at line 404 of file Element.h.

404{ return wxCURSOR_ARROW; }

◆ GetChildList()

virtual std::vector< Element * > Element::GetChildList ( ) const
inlinevirtual

Get the Child list.

Returns
Child List.

Definition at line 567 of file Element.h.

567{ return m_childList; }

◆ GetContextMenu()

virtual bool Element::GetContextMenu ( wxMenu &  menu)
inlinevirtual

Get the element contex menu.

Parameters
menumenu that will be inserted the element itens.
Returns
True if was possible to build the menu, false otherwise.

Reimplemented in Branch, Bus, Capacitor, EMTElement, HarmCurrent, IndMotor, Inductor, Line, Load, SyncGenerator, SyncMotor, and Transformer.

Definition at line 325 of file Element.h.

325{ return false; }

◆ GetCopy()

virtual Element * Element::GetCopy ( )
inlinevirtual

Get a the element copy.

Returns
Copy of the element.

Reimplemented in ConnectionLine, Constant, Divider, Exponential, Gain, IOControl, Limiter, MathExpression, Multiplier, RateLimiter, Sum, TransferFunction, Bus, Capacitor, EMTElement, HarmCurrent, IndMotor, Inductor, Line, Load, SyncGenerator, SyncMotor, Transformer, and Text.

Definition at line 263 of file Element.h.

263{ return nullptr; }

◆ GetElementType()

ElementType Element::GetElementType ( )
inline

Definition at line 178 of file Element.h.

178{ return m_elementType; }

◆ GetHeight()

double Element::GetHeight ( ) const
inline

Get the element height.

Returns
Element height.

Definition at line 198 of file Element.h.

198{ return m_height; }

◆ GetID()

virtual int Element::GetID ( ) const
inlinevirtual

Get the element ID.

Returns
Element ID.

Definition at line 273 of file Element.h.

273{ return m_elementID; }

◆ GetParentList()

virtual std::vector< Element * > Element::GetParentList ( ) const
inlinevirtual

Get the parent list.

Returns
Parent list.

Definition at line 562 of file Element.h.

562{ return m_parentList; }
Here is the caller graph for this function:

◆ GetPointList()

virtual std::vector< wxPoint2DDouble > Element::GetPointList ( ) const
inlinevirtual

Get the list of points that connect the element to bus.

Returns
List of points.

Definition at line 233 of file Element.h.

233{ return m_pointList; }

◆ GetPosition()

wxPoint2DDouble Element::GetPosition ( ) const
inline

Get the element position.

Returns
Element position.

Definition at line 188 of file Element.h.

188{ return m_position; }
Here is the caller graph for this function:

◆ GetRect()

wxRect2DDouble Element::GetRect ( ) const
inline

Get the element rectangle.

Returns
Element rectangle.

Definition at line 183 of file Element.h.

183{ return m_rect; }

◆ GetRotationAngle()

double Element::GetRotationAngle ( ) const
inline

Get the angle of rotation.

Returns
Rotation angle.

Definition at line 218 of file Element.h.

218{ return m_rotationAngle; }

◆ GetTipText()

virtual wxString Element::GetTipText ( ) const
inlinevirtual

Get the tip text.

Returns
Tip text.

Reimplemented in Bus, Capacitor, EMTElement, HarmCurrent, IndMotor, Inductor, Line, Load, SyncGenerator, SyncMotor, and Transformer.

Definition at line 297 of file Element.h.

297{ return wxEmptyString; }

◆ GetWidth()

double Element::GetWidth ( ) const
inline

Get the element width.

Returns
Element width.

Definition at line 208 of file Element.h.

208{ return m_width; }

◆ Intersects()

virtual bool Element::Intersects ( wxRect2DDouble  rect) const
pure virtual

Check if the element's rect intersects other rect.

Parameters
rectRect to check intersection.

Implemented in ConnectionLine, Constant, Exponential, Gain, IOControl, Limiter, MathExpression, MathOperation, RateLimiter, Sum, TransferFunction, Branch, Bus, Capacitor, EMTElement, HarmCurrent, Inductor, Line, Machines, Shunt, Transformer, and Text.

Here is the caller graph for this function:

◆ IntFromString()

bool Element::IntFromString ( wxWindow *  parent,
wxString  strValue,
int &  value,
wxString  errorMsg 
)
static

Convert a string to int. Show a error message if the conversion fail.

Parameters
parentMessage box parent.
strValueString value to be converted.
valueInt value converted.
errorMsgError message.

Definition at line 452 of file Element.cpp.

453{
454 long int iValue = 0;
455
456 if (!strValue.ToLong(&iValue)) {
457 wxMessageDialog msgDialog(parent, errorMsg, _("Error"), wxOK | wxCENTRE | wxICON_ERROR);
458 msgDialog.ShowModal();
459 return false;
460 }
461
462 value = iValue;
463 return true;
464}

◆ IsDragging()

bool Element::IsDragging ( ) const
inline

Checks if the element is being dragged.

Returns
True if is being dragged, false otherwise.

Definition at line 193 of file Element.h.

193{ return m_dragging; }

◆ IsInserted()

bool Element::IsInserted ( ) const
inline

Check if the element is properly inserted in the workspace.

Returns
true if is inserted properly, false otherwise

Definition at line 628 of file Element.h.

628{ return m_inserted; }

◆ IsOnline()

bool Element::IsOnline ( ) const
inline

Checks if the element is online or offline.

Returns
True if online, false if offline.

Definition at line 228 of file Element.h.

228{ return m_online; }
Here is the caller graph for this function:

◆ IsPickboxShown()

bool Element::IsPickboxShown ( ) const
inline

Checks if the pickbox is shown.

Returns
True if the pickbox is show, false otherwise.

Definition at line 223 of file Element.h.

223{ return m_showPickbox; }

◆ IsSelected()

bool Element::IsSelected ( ) const
inline

Checks if the element is selected.

Returns
True if selected, false otherwise.

Definition at line 203 of file Element.h.

203{ return m_selected; }

◆ Move()

void Element::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 in ConnectionLine, ControlElement, Gain, Branch, Line, Machines, Shunt, and Transformer.

Definition at line 271 of file Element.cpp.

271{ SetPosition(m_movePos + position - m_moveStartPt); }
void SetPosition(const wxPoint2DDouble position)
Set the element position and update the rectangle.
Definition Element.cpp:33
Here is the call graph for this function:

◆ MoveNode()

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

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

Parameters
parentNode's parent.
positionNew node position.

Reimplemented in Machines, Shunt, Branch, Line, and Transformer.

Definition at line 349 of file Element.h.

349{}

◆ MovePickbox()

virtual void Element::MovePickbox ( wxPoint2DDouble  position)
inlinevirtual

Move the pickbox.

Parameters
positionposition that the pickbox will be moved.

Reimplemented in Branch, Bus, and Line.

Definition at line 399 of file Element.h.

399{}

◆ NodeContains()

virtual bool Element::NodeContains ( wxPoint2DDouble  position)
inlinevirtual

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 in Branch, Machines, and Shunt.

Definition at line 355 of file Element.h.

355{ return false; }

◆ OpenCADProperties()

bool Element::OpenCADProperties ( rapidxml::xml_node<> *  elementNode)

Definition at line 588 of file Element.cpp.

589{
590 auto cadPropNode = elementNode->first_node("CADProperties");
591 if (!cadPropNode) return false;
592
593 auto position = cadPropNode->first_node("Position");
594 double posX = XMLParser::GetNodeValueDouble(position, "X");
595 double posY = XMLParser::GetNodeValueDouble(position, "Y");
596 auto size = cadPropNode->first_node("Size");
597 m_width = XMLParser::GetNodeValueDouble(size, "Width");
598 m_height = XMLParser::GetNodeValueDouble(size, "Height");
599 m_angle = XMLParser::GetNodeValueDouble(cadPropNode, "Angle");
600 SetPosition(wxPoint2DDouble(posX, posY));
601 return true;
602}

◆ OpenElement()

virtual bool Element::OpenElement ( rapidxml::xml_node<> *  elementNode)
inlinevirtual

Definition at line 637 of file Element.h.

637{ return true; }

◆ PickboxContains()

virtual bool Element::PickboxContains ( wxPoint2DDouble  position)
inlinevirtual

Check if a pickbox contains a point. If contains the attributes related to pickbox movement will be calculated.

Parameters
positionPosition to be checked.
Returns
True if the element constains the pickbox, false otherwise.

Reimplemented in Branch, Bus, and Line.

Definition at line 394 of file Element.h.

394{ return false; }

◆ PointToLineDistance()

double Element::PointToLineDistance ( wxPoint2DDouble  point,
int *  segmentNumber = nullptr 
) const
virtual

Calculate the distance between a line (formed by point list) and a point.

Parameters
pointorigin point.
segmentNumberSotores the segment number clicked
Returns
The distance between the point and the line.

Definition at line 534 of file Element.cpp.

535{
536 //[Ref] http://geomalgorithms.com/a02-_lines.html
537 double distance = 100.0; // Big initial distance.
538 wxPoint2DDouble p0 = point;
539
540 for (int i = 1; i < (int)m_pointList.size() - 2; i++) {
541 double d = 0.0;
542
543 wxPoint2DDouble p1 = m_pointList[i];
544 wxPoint2DDouble p2 = m_pointList[i + 1];
545
546 wxPoint2DDouble v = p2 - p1;
547 wxPoint2DDouble w = p0 - p1;
548
549 double c1 = w.m_x * v.m_x + w.m_y * v.m_y;
550 double c2 = v.m_x * v.m_x + v.m_y * v.m_y;
551
552 if (c1 <= 0.0) {
553 d = std::sqrt(std::pow(p0.m_y - p1.m_y, 2) + std::pow(p0.m_x - p1.m_x, 2));
554 }
555 else if (c2 <= c1) {
556 d = std::sqrt(std::pow(p0.m_y - p2.m_y, 2) + std::pow(p0.m_x - p2.m_x, 2));
557 }
558 else {
559 d = std::abs((p2.m_y - p1.m_y) * p0.m_x - (p2.m_x - p1.m_x) * p0.m_y + p2.m_x * p1.m_y - p2.m_y * p1.m_x) /
560 std::sqrt(std::pow(p2.m_y - p1.m_y, 2) + std::pow(p2.m_x - p1.m_x, 2));
561 }
562 if (d < distance) {
563 distance = d;
564 if (segmentNumber) *segmentNumber = i;
565 }
566 }
567
568 return distance;
569}
Here is the caller graph for this function:

◆ RemoveChild()

void Element::RemoveChild ( Element child)
virtual

Remove a child from the list.

Parameters
childChild to remove.

Definition at line 500 of file Element.cpp.

501{
502 for (auto it = m_childList.begin(); it != m_childList.end();) {
503 if (*it == child) it = m_childList.erase(it);
504 else ++it;
505 }
506}

◆ RemoveParent()

virtual void Element::RemoveParent ( Element parent)
inlinevirtual

Remove a parent.

Parameters
parentParent to be removed.

Reimplemented in ConnectionLine, Branch, Machines, and Shunt.

Definition at line 374 of file Element.h.

374{}

◆ ReplaceChild()

void Element::ReplaceChild ( Element oldChild,
Element newChild 
)
virtual

Replace a child from the list.

Parameters
oldChildOld child.
newChildNew child.

Definition at line 508 of file Element.cpp.

509{
510 for (int i = 0; i < (int)m_childList.size(); i++) {
511 if (m_childList[i] == oldChild) m_childList[i] = newChild;
512 }
513}

◆ ReplaceParent()

void Element::ReplaceParent ( Element oldParent,
Element newParent 
)
virtual

Replace a parent.

Parameters
oldParentParent to be replaced.
newParentNew parent.

Definition at line 492 of file Element.cpp.

493{
494 for (int i = 0; i < (int)m_parentList.size(); i++) {
495 if (m_parentList[i] == oldParent) m_parentList[i] = newParent;
496 }
497}

◆ ResetNodes()

virtual void Element::ResetNodes ( )
inlinevirtual

Remove the active nodes.

Definition at line 412 of file Element.h.

412{ m_activeNodeID = 0; }

◆ ResetPickboxes()

virtual void Element::ResetPickboxes ( )
inlinevirtual

Remove the pickboxes.

Definition at line 408 of file Element.h.

408{ m_activePickboxID = ID_PB_NONE; }
@ ID_PB_NONE
Definition Element.h:63

◆ Rotate()

virtual void Element::Rotate ( bool  clockwise = true)
inlinevirtual

Rotate the element.

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

Reimplemented in Constant, Exponential, Gain, IOControl, Limiter, MathExpression, MathOperation, RateLimiter, Sum, TransferFunction, Bus, Capacitor, EMTElement, HarmCurrent, Inductor, Load, Machines, Transformer, and Text.

Definition at line 319 of file Element.h.

319{}

◆ RotateAround()

wxPoint Element::RotateAround ( const wxPoint2DDouble &  p,
const wxPoint2DDouble &  center,
double  angleDeg 
) const
virtual

Definition at line 250 of file Element.cpp.

251{
252 double rad = wxDegToRad(angleDeg);
253 double c = std::cos(rad);
254 double s = std::sin(rad);
255
256 double dx = p.m_x - center.m_x;
257 double dy = p.m_y - center.m_y;
258
259 double xr = c * dx - s * dy + center.m_x;
260 double yr = s * dx + c * dy + center.m_y;
261
262 return wxPoint(wxRound(xr), wxRound(yr));
263}

◆ RotateAtPosition()

wxPoint2DDouble Element::RotateAtPosition ( wxPoint2DDouble  pointToRotate,
double  angle,
bool  degrees = true 
) const
virtual

Rotate a point as element position being the origin.

Parameters
pointToRotatePoint that will be rotated.
angleAngle of rotation.
degreesTrue if the angle is in degrees, false if radians.

Definition at line 228 of file Element.cpp.

229{
230 double radAngle = angle;
231 if (degrees) radAngle = wxDegToRad(angle);
232 return wxPoint2DDouble(std::cos(radAngle) * (pointToRotate.m_x - m_position.m_x) -
233 std::sin(radAngle) * (pointToRotate.m_y - m_position.m_y) + m_position.m_x,
234 std::sin(radAngle) * (pointToRotate.m_x - m_position.m_x) +
235 std::cos(radAngle) * (pointToRotate.m_y - m_position.m_y) + m_position.m_y);
236}
Here is the caller graph for this function:

◆ RotatedRectanglesIntersects()

bool Element::RotatedRectanglesIntersects ( wxRect2DDouble  rect1,
wxRect2DDouble  rect2,
double  angle1,
double  angle2 
) const
virtual

Check if two roteted rectangles intersect.

Parameters
rect1First rect.
rect2Second rect.
angle1Rotation algle of first rectangle.
angle2Rotation angle of second rectangle.

Definition at line 295 of file Element.cpp.

299{
300 wxPoint2DDouble rect1Corners[4] = { rect1.GetLeftTop(), rect1.GetLeftBottom(), rect1.GetRightBottom(),
301 rect1.GetRightTop() };
302 wxPoint2DDouble rect2Corners[4] = { rect2.GetLeftTop(), rect2.GetLeftBottom(), rect2.GetRightBottom(),
303 rect2.GetRightTop() };
304 wxPoint2DDouble rect1Center(rect1.m_x + rect1.m_width / 2.0, rect1.m_y + rect1.m_height / 2.0);
305 wxPoint2DDouble rect2Center(rect2.m_x + rect2.m_width / 2.0, rect2.m_y + rect2.m_height / 2.0);
306
307 // Rotate the corners.
308 double radAngle1 = wxDegToRad(angle1);
309 double radAngle2 = wxDegToRad(angle2);
310
311 for (int i = 0; i < 4; i++) {
312 rect1Corners[i] =
313 wxPoint2DDouble(std::cos(radAngle1) * (rect1Corners[i].m_x - rect1Center.m_x) -
314 std::sin(radAngle1) * (rect1Corners[i].m_y - rect1Center.m_y) + rect1Center.m_x,
315 std::sin(radAngle1) * (rect1Corners[i].m_x - rect1Center.m_x) +
316 std::cos(radAngle1) * (rect1Corners[i].m_y - rect1Center.m_y) + rect1Center.m_y);
317
318 rect2Corners[i] =
319 wxPoint2DDouble(std::cos(radAngle2) * (rect2Corners[i].m_x - rect2Center.m_x) -
320 std::sin(radAngle2) * (rect2Corners[i].m_y - rect2Center.m_y) + rect2Center.m_x,
321 std::sin(radAngle2) * (rect2Corners[i].m_x - rect2Center.m_x) +
322 std::cos(radAngle2) * (rect2Corners[i].m_y - rect2Center.m_y) + rect2Center.m_y);
323 }
324
325 //[Ref] http://www.gamedev.net/page/resources/_/technical/game-programming/2d-rotated-rectangle-collision-r2604
326
327 // Find the rectangles axis to project
328 wxPoint2DDouble axis[4] = { rect1Corners[3] - rect1Corners[0], rect1Corners[3] - rect1Corners[2],
329 rect2Corners[3] - rect2Corners[0], rect2Corners[3] - rect2Corners[2] };
330
331 // Calculate the projected points to each axis
332 wxPoint2DDouble rect1ProjPts[4][4]; // [axis][corner]
333 wxPoint2DDouble rect2ProjPts[4][4]; // [axis][corner]
334 for (int i = 0; i < 4; i++) {
335 double den = axis[i].m_x * axis[i].m_x + axis[i].m_y * axis[i].m_y;
336 for (int j = 0; j < 4; j++) {
337 double m_rectProj = (rect1Corners[j].m_x * axis[i].m_x + rect1Corners[j].m_y * axis[i].m_y) / den;
338 double rectProj = (rect2Corners[j].m_x * axis[i].m_x + rect2Corners[j].m_y * axis[i].m_y) / den;
339
340 rect1ProjPts[i][j] = wxPoint2DDouble(m_rectProj * axis[i].m_x, m_rectProj * axis[i].m_y);
341 rect2ProjPts[i][j] = wxPoint2DDouble(rectProj * axis[i].m_x, rectProj * axis[i].m_y);
342 }
343 }
344
345 // Calculate the scalar value to identify the max and min values on projections
346 double rect1Scalar[4][4]; //[axis][corner]
347 double rect2Scalar[4][4]; //[axis][corner]
348 for (int i = 0; i < 4; i++) {
349 for (int j = 0; j < 4; j++) {
350 rect1Scalar[i][j] = rect1ProjPts[i][j].m_x * axis[i].m_x + rect1ProjPts[i][j].m_y * axis[i].m_y;
351 rect2Scalar[i][j] = rect2ProjPts[i][j].m_x * axis[i].m_x + rect2ProjPts[i][j].m_y * axis[i].m_y;
352 }
353 }
354 // Identify the max and min scalar values
355 double rect1Min[4];
356 double rect1Max[4];
357 double rect2Min[4];
358 double rect2Max[4];
359
360 for (int i = 0; i < 4; i++) {
361 rect1Max[i] = rect1Scalar[i][0];
362 rect2Max[i] = rect2Scalar[i][0];
363 rect1Min[i] = rect1Scalar[i][0];
364 rect2Min[i] = rect2Scalar[i][0];
365
366 for (int j = 1; j < 4; j++) {
367 if (rect1Max[i] < rect1Scalar[i][j]) rect1Max[i] = rect1Scalar[i][j];
368 if (rect2Max[i] < rect2Scalar[i][j]) rect2Max[i] = rect2Scalar[i][j];
369
370 if (rect1Min[i] > rect1Scalar[i][j]) rect1Min[i] = rect1Scalar[i][j];
371 if (rect2Min[i] > rect2Scalar[i][j]) rect2Min[i] = rect2Scalar[i][j];
372 }
373 }
374
375 // Check if any segment don't overlap
376 for (int i = 0; i < 4; i++) {
377 if (!(rect2Min[i] <= rect1Max[i] && rect2Max[i] >= rect1Min[i])) return false;
378 }
379
380 return true;
381}
Here is the caller graph for this function:

◆ RotateLocal()

wxPoint2DDouble Element::RotateLocal ( wxPoint2DDouble  local,
double  angleDeg 
) const
virtual

Definition at line 238 of file Element.cpp.

239{
240 double rad = wxDegToRad(angleDeg);
241 double c = std::cos(rad);
242 double s = std::sin(rad);
243
244 return wxPoint2DDouble(
245 c * local.m_x - s * local.m_y,
246 s * local.m_x + c * local.m_y
247 );
248}

◆ RotateNode()

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

Rotate a node.

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

Reimplemented in Transformer, Branch, Line, Machines, and Shunt.

Definition at line 387 of file Element.h.

387{}

◆ SaveCADProperties()

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

Definition at line 571 of file Element.cpp.

572{
573 auto cadProp = XMLParser::AppendNode(doc, elementNode, "CADProperties");
574 auto position = XMLParser::AppendNode(doc, cadProp, "Position");
575 auto posX = XMLParser::AppendNode(doc, position, "X");
576 XMLParser::SetNodeValue(doc, posX, m_position.m_x);
577 auto posY = XMLParser::AppendNode(doc, position, "Y");
578 XMLParser::SetNodeValue(doc, posY, m_position.m_y);
579 auto size = XMLParser::AppendNode(doc, cadProp, "Size");
580 auto width = XMLParser::AppendNode(doc, size, "Width");
581 XMLParser::SetNodeValue(doc, width, m_width);
582 auto height = XMLParser::AppendNode(doc, size, "Height");
583 XMLParser::SetNodeValue(doc, height, m_height);
584 auto angle = XMLParser::AppendNode(doc, cadProp, "Angle");
585 XMLParser::SetNodeValue(doc, angle, m_angle);
586}

◆ SaveElement()

virtual rapidxml::xml_node * Element::SaveElement ( rapidxml::xml_document<> &  doc,
rapidxml::xml_node<> *  elementListNode 
)
inlinevirtual

Definition at line 636 of file Element.h.

636{ return nullptr; }

◆ SetAngle()

void Element::SetAngle ( double  angle)
inline

Set element angle.

Parameters
angleAngle value in degrees.

Definition at line 156 of file Element.h.

156{ m_angle = angle; }

◆ SetBorderSize()

void Element::SetBorderSize ( double  borderSize)
inline

Set the size of the border (shown in selected elements).

Parameters
borderSizeBorder size.

Definition at line 166 of file Element.h.

166{ m_borderSize = borderSize; }

◆ SetChild()

void Element::SetChild ( Element child,
int  num 
)
inline

Definition at line 362 of file Element.h.

362{ m_childList[num] = child; }

◆ SetDragging()

void Element::SetDragging ( bool  dragging = true)
inline

Set if the element are being dragged.

Parameters
draggingTrue if is dragging, false otherwise.

Definition at line 130 of file Element.h.

130{ m_dragging = dragging; }

◆ SetHeight()

void Element::SetHeight ( double  height)
inline

Set element height.

Parameters
heightHeight value.

Definition at line 135 of file Element.h.

135{ m_height = height; }

◆ SetID()

virtual void Element::SetID ( int  id)
inlinevirtual

Set the element ID.

Parameters
idElement ID.

Definition at line 268 of file Element.h.

268{ m_elementID = id; }

◆ SetInserted()

void Element::SetInserted ( bool  inserted = true)
inline

Set if the element is properly inserted in the workspace.

Parameters
insertedtrue if is inserted properly, false otherwise

Definition at line 634 of file Element.h.

634{ m_inserted = inserted; }
Here is the caller graph for this function:

◆ SetNodeParent()

virtual bool Element::SetNodeParent ( Element parent)
inlinevirtual

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 in Branch, Line, Machines, Shunt, and Transformer.

Definition at line 369 of file Element.h.

369{ return false; }

◆ SetOnline()

bool Element::SetOnline ( bool  online = true)

Set if the element is online or offline.

Parameters
onlineTrue if online, false if offline.

Definition at line 383 of file Element.cpp.

384{
385 // Check if any parent is null.
386 for (auto it = m_parentList.begin(); it != m_parentList.end(); it++) {
387 if (!(*it)) return false;
388 }
389 m_online = online;
390 return true;
391}

◆ SetParent()

void Element::SetParent ( Element parent,
int  num 
)
inline

Definition at line 361 of file Element.h.

361{ m_parentList[num] = parent; }

◆ SetPointList()

virtual void Element::SetPointList ( std::vector< wxPoint2DDouble >  pointList)
inlinevirtual

Set the list of points that connect the element to the bus.

Parameters
pointListList of points.

Reimplemented in Line.

Definition at line 177 of file Element.h.

177{ m_pointList = pointList; }

◆ SetPosition()

void Element::SetPosition ( const wxPoint2DDouble  position)

Set the element position and update the rectangle.

Parameters
positionPosition value.

Definition at line 33 of file Element.cpp.

34{
35 m_position = position;
36 m_rect =
37 wxRect2DDouble(m_position.m_x - m_width / 2.0 - m_borderSize, m_position.m_y - m_height / 2.0 - m_borderSize,
38 m_width + 2.0 * m_borderSize, m_height + 2.0 * m_borderSize);
39}
Here is the caller graph for this function:

◆ SetSelected()

void Element::SetSelected ( bool  selected = true)
inline

Set element selection.

Parameters
selectedTrue if selected, false otherwise.

Definition at line 146 of file Element.h.

146{ m_selected = selected; }

◆ SetWidth()

void Element::SetWidth ( double  width)
inline

Set element width.

Parameters
widthWidth value.

Definition at line 151 of file Element.h.

151{ m_width = width; }

◆ ShowForm()

virtual bool Element::ShowForm ( wxWindow *  parent,
Element element,
wxWindow *  workspace = nullptr 
)
inlinevirtual

Show element data form.

Parameters
parentForm parent
elementElement that will be edited.
Returns
True if the form is shown, false otherwise.

Reimplemented in Constant, Exponential, Gain, IOControl, Limiter, MathExpression, RateLimiter, Sum, TransferFunction, Bus, Capacitor, EMTElement, HarmCurrent, IndMotor, Inductor, Line, Load, SyncGenerator, SyncMotor, and Transformer.

Definition at line 590 of file Element.h.

590{ return false; }

◆ ShowPickbox()

void Element::ShowPickbox ( bool  showPickbox = true)
inline

Set if the pickbox is shown.

Parameters
showPickboxTrue if show, false otherwise.

Definition at line 161 of file Element.h.

161{ m_showPickbox = showPickbox; }

◆ StartMove()

void Element::StartMove ( wxPoint2DDouble  position)
virtual

Update the element attributes related to the movement.

Parameters
positionStart move position.

Reimplemented in ConnectionLine, ControlElement, Branch, Line, Machines, Shunt, and Transformer.

Definition at line 265 of file Element.cpp.

266{
267 this->m_moveStartPt = position;
268 this->m_movePos = m_position;
269}

◆ StringFromDouble()

wxString Element::StringFromDouble ( double  value,
int  minDecimal = 1,
int  maxDecimals = 13 
)
static

Convert a double value to string.

Parameters
valueValue to be converted.
minDecimalMinimum number of decimal places.

Definition at line 466 of file Element.cpp.

467{
468 wxString str = wxString::FromCDouble(value, maxDecimals);
469 int cutNumber = 0;
470 int numDecimal = 0;
471 bool foundCut = false;
472 for (int i = (int)str.length() - 1; i >= 0; i--) {
473 if (str[i] != '0' && !foundCut) {
474 cutNumber = i;
475 foundCut = true;
476 }
477 if (str[i] == '.') {
478 numDecimal = i;
479 break;
480 }
481 }
482
483 wxString formatedStr = "";
484 if (cutNumber - numDecimal > minDecimal)
485 formatedStr = wxString::FromDouble(value, cutNumber - numDecimal);
486 else
487 formatedStr = wxString::FromDouble(value, minDecimal);
488
489 return formatedStr;
490}
Here is the caller graph for this function:

◆ UpdateNodes()

virtual void Element::UpdateNodes ( )
inlinevirtual

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

Reimplemented in Branch, Machines, and Shunt.

Definition at line 359 of file Element.h.

359{}

◆ WorldToScreen() [1/2]

wxPoint2DDouble Element::WorldToScreen ( wxPoint2DDouble  position,
wxPoint2DDouble  translation,
double  scale,
double  offsetX = 0.0,
double  offsetY = 0.0 
) const
virtual

Convert a generic position to screen position.

Parameters
positionPosition to be converted.
translationSystem translation.
scaleSystem scale.
offsetXOffset in X axis.
offsetYOffset in Y axis.

Definition at line 278 of file Element.cpp.

283{
284 return wxPoint2DDouble(position.m_x + offsetX + translation.m_x, position.m_y + offsetY + translation.m_y) * scale;
285}

◆ WorldToScreen() [2/2]

wxPoint2DDouble Element::WorldToScreen ( wxPoint2DDouble  translation,
double  scale,
double  offsetX = 0.0,
double  offsetY = 0.0 
) const
virtual

Convert the element position to screen position.

Parameters
translationSystem translation.
scaleSystem scale
offsetXOffset in X axis.
offsetYOffset if Y axis.

Definition at line 272 of file Element.cpp.

273{
274 return wxPoint2DDouble(m_position.m_x + offsetX + translation.m_x, m_position.m_y + offsetY + translation.m_y) *
275 scale;
276}
Here is the caller graph for this function:

Member Data Documentation

◆ m_activeNodeID

int Element::m_activeNodeID = 0
protected

Definition at line 664 of file Element.h.

◆ m_activePickboxID

int Element::m_activePickboxID = ID_PB_NONE
protected

Definition at line 663 of file Element.h.

◆ m_angle

double Element::m_angle = 0.0
protected

Definition at line 651 of file Element.h.

◆ m_borderSize

double Element::m_borderSize = 2.0
protected

Definition at line 652 of file Element.h.

◆ m_childList

std::vector<Element*> Element::m_childList
protected

Definition at line 645 of file Element.h.

◆ m_dragging

bool Element::m_dragging = false
protected

Definition at line 659 of file Element.h.

◆ m_elementID

int Element::m_elementID = 0
protected

Definition at line 643 of file Element.h.

◆ m_elementType

ElementType Element::m_elementType = ElementType::TYPE_NONE
protected

Definition at line 642 of file Element.h.

◆ m_height

double Element::m_height = 0.0
protected

Definition at line 650 of file Element.h.

◆ m_inserted

bool Element::m_inserted = false
protected

Definition at line 661 of file Element.h.

◆ m_movePos

wxPoint2DDouble Element::m_movePos
protected

Definition at line 670 of file Element.h.

◆ m_movePts

std::vector<wxPoint2DDouble> Element::m_movePts
protected

Definition at line 667 of file Element.h.

◆ m_moveStartPt

wxPoint2DDouble Element::m_moveStartPt
protected

Definition at line 669 of file Element.h.

◆ m_online

bool Element::m_online = true
protected

Definition at line 672 of file Element.h.

◆ m_parentList

std::vector<Element*> Element::m_parentList
protected

Definition at line 644 of file Element.h.

◆ m_pointList

std::vector<wxPoint2DDouble> Element::m_pointList
protected

Definition at line 666 of file Element.h.

◆ m_position

wxPoint2DDouble Element::m_position
protected

Definition at line 648 of file Element.h.

◆ m_rect

wxRect2DDouble Element::m_rect
protected

Definition at line 647 of file Element.h.

◆ m_rotationAngle

double Element::m_rotationAngle = 45.0
protected

Definition at line 653 of file Element.h.

◆ m_selected

bool Element::m_selected = false
protected

Definition at line 658 of file Element.h.

◆ m_showPickbox

bool Element::m_showPickbox = false
protected

Definition at line 660 of file Element.h.

◆ m_switchRect

std::vector<wxRect2DDouble> Element::m_switchRect
protected

Definition at line 656 of file Element.h.

◆ m_switchSize

double Element::m_switchSize = 10.0
protected

Definition at line 654 of file Element.h.

◆ m_width

double Element::m_width = 0.0
protected

Definition at line 649 of file Element.h.


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