Power System Platform  2026w23a-beta
Loading...
Searching...
No Matches
Transformer Class Reference

Two-winding transformer power element. More...

#include <Transformer.h>

Inheritance diagram for Transformer:
Collaboration diagram for Transformer:

Public Member Functions

 Transformer (wxString name)
 
virtual ElementGetCopy ()
 Get a the element copy.
 
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 (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 bool Intersects (wxRect2DDouble rect) const
 Check if the element's rect intersects other rect.
 
virtual void Rotate (bool clockwise=true)
 Rotate the element.
 
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 void StartMove (wxPoint2DDouble position)
 Update the element attributes related to the movement.
 
virtual bool GetContextMenu (wxMenu &menu)
 Get the element contex menu.
 
virtual wxString GetTipText () const
 Get the tip text.
 
virtual void RotateNode (Element *parent, bool clockwise)
 Rotate a node.
 
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 SetPowerFlowDirection (PowerFlowDirection pfDirection)
 Set the direction of the power flow.
 
virtual bool ShowForm (wxWindow *parent, Element *element, wxWindow *workspace=nullptr)
 Show element data form.
 
virtual TransformerElectricalData GetElectricalData () const
 
virtual TransformerElectricalDataGetElectricalDataRef ()
 
virtual TransformerElectricalData GetPUElectricalData (double systemBasePower) const
 
virtual void SetElectricaData (TransformerElectricalData electricalData)
 
virtual void SetNominalVoltage (std::vector< double > nominalVoltage, std::vector< ElectricalUnit > nominalVoltageUnit)
 Set nominal voltage of the element.
 
virtual void SetBestPositionAndRotation ()
 
virtual rapidxml::xml_node * SaveElement (rapidxml::xml_document<> &doc, rapidxml::xml_node<> *elementListNode)
 
virtual bool OpenElement (rapidxml::xml_node<> *elementNode, std::vector< Element * > parentList)
 
- Public Member Functions inherited from Branch
virtual bool NodeContains (wxPoint2DDouble position)
 Check if a node contains a point. If contains, set the attributes related to node movement.
 
virtual void RemoveParent (Element *parent)
 Remove a parent.
 
virtual void UpdateNodes ()
 Update the nodes according to the parents. If a parent is removed, use this method.
 
virtual wxCursor GetBestPickboxCursor () const
 Get the best cursor to shown to the user when the mouse is above a pickbox.
 
virtual void MovePickbox (wxPoint2DDouble position)
 Move the pickbox.
 
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 AddPoint (wxPoint2DDouble point)
 Add point to the list of points that connect the element to the bus.
 
virtual void UpdateSwitchesPosition ()
 
virtual void UpdateSwitches ()
 Update the switch position.
 
- 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 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 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) 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 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 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.
 
void SetParent (Element *parent, int num)
 
void SetChild (Element *child, int num)
 
virtual void ReplaceParent (Element *oldParent, Element *newParent)
 Replace a parent.
 
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 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 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 UpdatePowerFlowArrowsPosition ()
 

Protected Attributes

TransformerElectricalData m_electricalData
 
- 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
 

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

Two-winding transformer power element.

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

Definition at line 83 of file Transformer.h.

Constructor & Destructor Documentation

◆ Transformer() [1/2]

Transformer::Transformer ( )

Definition at line 21 of file Transformer.cpp.

21 : Branch()
22{
23 m_elementType = TYPE_TRANSFORMER;
24 for (int i = 0; i < 2; i++) {
25 for (int j = 0; j < 3; j++) { m_electricalData.faultCurrent[i][j] = std::complex<double>(0.0, 0.0); }
26 }
27}
Abstract class for branch power elements.
Definition Branch.h:32

◆ Transformer() [2/2]

Transformer::Transformer ( wxString  name)

Definition at line 28 of file Transformer.cpp.

28 : Branch()
29{
30 m_elementType = TYPE_TRANSFORMER;
31 for (int i = 0; i < 2; i++) {
32 for (int j = 0; j < 3; j++) { m_electricalData.faultCurrent[i][j] = std::complex<double>(0.0, 0.0); }
33 }
34 m_electricalData.name = name;
35}

◆ ~Transformer()

Transformer::~Transformer ( )
virtual

Definition at line 36 of file Transformer.cpp.

36{}

Member Function Documentation

◆ AddParent()

bool Transformer::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 38 of file Transformer.cpp.

39{
40 if (parent) {
41 // First bus.
42 if (m_parentList.size() == 0) {
43 m_position = position;
44 m_parentList.push_back(parent);
45 parent->AddChild(this);
46 wxPoint2DDouble parentPt =
47 parent->RotateAtPosition(position, -parent->GetAngle()); // Rotate click to horizontal position.
48 parentPt.m_y = parent->GetPosition().m_y; // Centralize on bus.
49 parentPt = parent->RotateAtPosition(parentPt, parent->GetAngle()); // Rotate back.
50 m_pointList.push_back(parentPt); // First point
51 m_pointList.push_back(GetSwitchPoint(parent, parentPt, m_position));
52
53 wxRect2DDouble genRect(0, 0, 0, 0);
54 m_switchRect.push_back(genRect);
55
56 return false;
57 }
58 // Second bus.
59 else if (parent != m_parentList[0]) {
60 m_parentList.push_back(parent);
61 parent->AddChild(this);
62 wxPoint2DDouble parentPt =
63 parent->RotateAtPosition(position, -parent->GetAngle()); // Rotate click to horizontal position.
64 parentPt.m_y = parent->GetPosition().m_y; // Centralize on bus.
65 parentPt = parent->RotateAtPosition(parentPt, parent->GetAngle()); // Rotate back.
66
67 // Get the average between the two bus points.
68 m_position =
69 wxPoint2DDouble((m_pointList[0].m_x + parentPt.m_x) / 2.0, (m_pointList[0].m_y + parentPt.m_y) / 2.0);
70 // Set the transformer rectangle.
71 m_width = 70.0;
72 m_height = 40.0;
73 SetPosition(m_position); // This method calculates the rectangle propely.
74 // Set the "side" points.
75 m_pointList.push_back(
76 wxPoint2DDouble(m_rect.GetPosition() + wxPoint2DDouble(-10 - m_borderSize, m_height / 2.0)));
77 m_pointList.push_back(
78 wxPoint2DDouble(m_rect.GetPosition() + wxPoint2DDouble(m_width + 10 + m_borderSize, m_height / 2.0)));
79
80 // Set first switch point.
81 wxPoint2DDouble secondPoint = parentPt;
82 if (m_pointList.size() > 2) { secondPoint = m_pointList[2]; }
83 m_pointList[1] = GetSwitchPoint(m_parentList[0], m_pointList[0], secondPoint);
84
85 // Set the second switch point.
86 m_pointList.push_back(GetSwitchPoint(parent, parentPt, m_pointList[m_pointList.size() - 1]));
87
88 m_pointList.push_back(parentPt); // Last point.
89 m_inserted = true;
90
91 wxRect2DDouble genRect(0, 0, 0, 0);
92 m_switchRect.push_back(genRect);
94 UpdatePowerFlowArrowsPosition();
95
96 return true;
97 }
98 }
99 return false;
100}
virtual void UpdateSwitches()
Update the switch position.
Definition Branch.cpp:179
wxPoint2DDouble GetPosition() const
Get the element position.
Definition Element.h:188
double GetAngle() const
Get the element angle.
Definition Element.h:213
void SetPosition(const wxPoint2DDouble position)
Set the element position and update the rectangle.
Definition Element.cpp:33
virtual wxPoint2DDouble RotateAtPosition(wxPoint2DDouble pointToRotate, double angle, bool degrees=true) const
Rotate a point as element position being the origin.
Definition Element.cpp:228
virtual void AddChild(Element *child)
Add a child to the child list.
Definition Element.cpp:499
virtual wxPoint2DDouble GetSwitchPoint(Element *parent, wxPoint2DDouble parentPoint, wxPoint2DDouble secondPoint) const
Get the correct switch position.
Here is the call graph for this function:

◆ Contains()

bool Transformer::Contains ( wxPoint2DDouble  position) const
virtual

Checks if the element contains a position.

Parameters
positionPosition to be checked.

Reimplemented from Branch.

Definition at line 102 of file Transformer.cpp.

103{
104 wxPoint2DDouble ptR = RotateAtPosition(position, -m_angle);
105 return m_rect.Contains(ptR);
106}
Here is the call graph for this function:

◆ DrawDC() [1/2]

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

Draw the element using wxDC.

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

Reimplemented from Element.

Definition at line 272 of file Transformer.cpp.

273{
274 wxColour elementColour;
275 if (m_online) {
276 if (m_dynEvent)
277 elementColour = guiColour->eventElement;
278 else
279 elementColour = guiColour->enabled;
280 }
281 else
282 elementColour = guiColour->disable;
283
284 std::vector<wxPoint> pointList;
285 for (auto& pt : m_pointList) { pointList.emplace_back(static_cast<int>(pt.m_x), static_cast<int>(pt.m_y)); }
286
287 if (m_inserted) {
288 // Draw selection (layer 1).
289 if (m_selected) {
290 dc.SetPen(wxPen(wxColour(guiColour->selection), 2 + m_borderSize * 2.0));
291 dc.SetBrush(*wxTRANSPARENT_BRUSH);
292 dc.DrawLines(pointList.size(), &pointList[0]);
293
294 dc.SetPen(*wxTRANSPARENT_PEN);
295 dc.SetBrush(wxBrush(guiColour->selection));
296 //DrawDCCircle(m_rect.GetPosition() + wxPoint2DDouble(20.0, 20.0), 20 + (m_borderSize + 1.5) / scale, dc);
297 //DrawDCCircle(m_rect.GetPosition() + wxPoint2DDouble(50.0, 20.0), 20 + (m_borderSize + 1.5) / scale, dc);
298 DrawDCCircle(m_position + RotateLocal(wxPoint2DDouble(15.0, 0.0), m_angle), 20 + (m_borderSize + 1.5) / scale, dc);
299 DrawDCCircle(m_position + RotateLocal(wxPoint2DDouble(-15.0, 0.0), m_angle), 20 + (m_borderSize + 1.5) / scale, dc);
300
301 // Draw nodes selection.
302 dc.SetPen(*wxTRANSPARENT_PEN);
303 dc.SetBrush(wxBrush(guiColour->selection));
304 if (pointList.size() > 0) {
305 DrawDCCircle(pointList[0], 5.0 + m_borderSize / scale, dc);
306 if (m_inserted) { DrawDCCircle(pointList[pointList.size() - 1], 5.0 + m_borderSize / scale, dc); }
307 }
308 }
309
310 // Draw transformer (layer 2).
311 // Transformer line
312 dc.SetPen(wxPen(elementColour, 2));
313 dc.SetBrush(*wxTRANSPARENT_BRUSH);
314 dc.DrawLines(pointList.size(), &pointList[0]);
315
316 // Draw nodes.
317 dc.SetPen(*wxTRANSPARENT_PEN);
318 dc.SetBrush(wxBrush(elementColour));
319 if (pointList.size() > 0) {
320 DrawDCCircle(pointList[0], 5.0, dc);
321 if (m_inserted) { DrawDCCircle(pointList[pointList.size() - 1], 5.0, dc); }
322 }
323
324 DrawDCSwitches(guiColour, dc);
325 DrawDCPowerFlowPts(guiColour, dc);
326
327 dc.SetPen(*wxTRANSPARENT_PEN);
328 dc.SetBrush(wxBrush(guiColour->background));
329 DrawDCCircle(m_position + RotateLocal(wxPoint2DDouble(15.0, 0.0), m_angle), 20, dc);
330 DrawDCCircle(m_position + RotateLocal(wxPoint2DDouble(-15.0, 0.0), m_angle), 20, dc);
331
332 dc.SetPen(wxPen(elementColour, 2));
333 dc.SetBrush(*wxTRANSPARENT_BRUSH);
334 DrawDCCircle(m_position + RotateLocal(wxPoint2DDouble(15.0, 0.0), m_angle), 20, dc);
335 DrawDCCircle(m_position + RotateLocal(wxPoint2DDouble(-15.0, 0.0), m_angle), 20, dc);
336
337 // Point
338 dc.SetPen(*wxTRANSPARENT_PEN);
339 dc.SetBrush(wxBrush(elementColour));
340 DrawDCCircle(m_position + RotateLocal(wxPoint2DDouble(-35, -20), m_angle), 4, dc);
341 }
342}
virtual void DrawDCCircle(wxPoint2DDouble position, double radius, int numSegments, wxGraphicsContext *gc) const
Draw a circle using device context.
Definition Element.cpp:173
virtual void DrawDCPowerFlowPts(GUIColour *guiColour, wxGraphicsContext *gc) const
Draw power flow arrows.
virtual void DrawDCSwitches(GUIColour *guiColour, wxGraphicsContext *gc) const
Draw switch.
Here is the call graph for this function:

◆ DrawDC() [2/2]

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

Draw the element using GDI+.

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

Reimplemented from Element.

Definition at line 186 of file Transformer.cpp.

187{
188 wxColour elementColour;
189 if (m_online) {
190 if (m_dynEvent)
191 elementColour = guiColour->eventElement;
192 else
193 elementColour = guiColour->enabled;
194 }
195 else
196 elementColour = guiColour->disable;
197
198 if (m_inserted) {
199 // Draw selection (layer 1).
200 if (m_selected) {
201 gc->SetPen(wxPen(guiColour->selection, 2 + m_borderSize * 2.0));
202 gc->SetBrush(*wxTRANSPARENT_BRUSH);
203 gc->StrokeLines(m_pointList.size(), &m_pointList[0]);
204
205 // Push the current matrix on stack.
206 gc->PushState();
207 // Rotate the matrix around the object position.
208 gc->Translate(m_position.m_x, m_position.m_y);
209 gc->Rotate(wxDegToRad(m_angle));
210 gc->Translate(-m_position.m_x, -m_position.m_y);
211
212 gc->SetPen(*wxTRANSPARENT_PEN);
213 gc->SetBrush(wxBrush(guiColour->selection));
214 DrawDCCircle(m_rect.GetPosition() + wxPoint2DDouble(20.0, 20.0), 20 + (m_borderSize + 1.5) / scale, 20, gc);
215 DrawDCCircle(m_rect.GetPosition() + wxPoint2DDouble(50.0, 20.0), 20 + (m_borderSize + 1.5) / scale, 20, gc);
216
217 gc->PopState();
218
219 // Draw nodes selection.
220 gc->SetPen(*wxTRANSPARENT_PEN);
221 gc->SetBrush(wxBrush(guiColour->selection));
222 if (m_pointList.size() > 0) {
223 DrawDCCircle(m_pointList[0], 5.0 + m_borderSize / scale, 10, gc);
224 if (m_inserted) { DrawDCCircle(m_pointList[m_pointList.size() - 1], 5.0 + m_borderSize / scale, 10, gc); }
225 }
226 }
227
228 // Draw transformer (layer 2).
229 // Transformer line
230 gc->SetPen(wxPen(elementColour, 2));
231 gc->SetBrush(*wxTRANSPARENT_BRUSH);
232 gc->StrokeLines(m_pointList.size(), &m_pointList[0]);
233
234 // Draw nodes.
235 gc->SetPen(*wxTRANSPARENT_PEN);
236 gc->SetBrush(wxBrush(elementColour));
237 if (m_pointList.size() > 0) {
238 DrawDCCircle(m_pointList[0], 5.0, 10, gc);
239 if (m_inserted) { DrawDCCircle(m_pointList[m_pointList.size() - 1], 5.0, 10, gc); }
240 }
241
242 DrawDCSwitches(guiColour, gc);
243 DrawDCPowerFlowPts(guiColour, gc);
244
245 // Push the current matrix on stack.
246 gc->PushState();
247 // Rotate the matrix around the object position.
248 gc->Translate(m_position.m_x, m_position.m_y);
249 gc->Rotate(wxDegToRad(m_angle));
250 gc->Translate(-m_position.m_x, -m_position.m_y);
251
252 //glColor4d(1.0, 1.0, 1.0, 1.0);
253 gc->SetPen(*wxTRANSPARENT_PEN);
254 gc->SetBrush(wxBrush(guiColour->background));
255 DrawDCCircle(m_rect.GetPosition() + wxPoint2DDouble(20.0, 20.0), 20, 20, gc);
256 DrawDCCircle(m_rect.GetPosition() + wxPoint2DDouble(50.0, 20.0), 20, 20, gc);
257
258 gc->SetPen(wxPen(elementColour, 2));
259 gc->SetBrush(*wxTRANSPARENT_BRUSH);
260 DrawDCCircle(m_rect.GetPosition() + wxPoint2DDouble(20.0, 20.0), 20, 20, gc);
261 DrawDCCircle(m_rect.GetPosition() + wxPoint2DDouble(50.0, 20.0), 20, 20, gc);
262
263 // Point
264 gc->SetPen(*wxTRANSPARENT_PEN);
265 gc->SetBrush(wxBrush(elementColour));
266 DrawDCCircle(m_rect.GetPosition(), 4, 10, gc);
267
268 gc->PopState();
269 }
270}
Here is the call graph for this function:

◆ GetContextMenu()

bool Transformer::GetContextMenu ( wxMenu &  menu)
virtual

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 from Branch.

Definition at line 425 of file Transformer.cpp.

426{
427 menu.Append(ID_EDIT_ELEMENT, _("Edit tranformer"));
428
429 wxString busName[2] = { "?", "?" };
430 if (m_parentList.size() == 2) {
431 int i = 0;
432 for (Element* element : m_parentList) {
433 if (element) {
434 Bus* bus = static_cast<Bus*>(element);
435 busName[i] = bus->GetElectricalData().name;
436 }
437 i++;
438 }
439 }
440
441 wxMenu* textMenu = new wxMenu();
442
443 textMenu->Append(ID_TXT_NAME, _("Name"));
444 textMenu->Append(ID_TXT_BRANCH_ACTIVE_POWER_1_2, _("Active power (") + busName[0] + _(" to ") + busName[1] + wxT(")"));
445 textMenu->Append(ID_TXT_BRANCH_ACTIVE_POWER_2_1, _("Active power (") + busName[1] + _(" to ") + busName[0] + wxT(")"));
446 textMenu->Append(ID_TXT_BRANCH_REACTIVE_POWER_1_2, _("Reactive power (") + busName[0] + _(" to ") + busName[1] + wxT(")"));
447 textMenu->Append(ID_TXT_BRANCH_REACTIVE_POWER_2_1, _("Reactive power (") + busName[1] + _(" to ") + busName[0] + wxT(")"));
448 textMenu->Append(ID_TXT_BRANCH_LOSSES, _("Losses"));
449 textMenu->Append(ID_TXT_BRANCH_CURRENT_1_2, _("Current (") + busName[0] + _(" to ") + busName[1] + wxT(")"));
450 textMenu->Append(ID_TXT_BRANCH_CURRENT_2_1, _("Current (") + busName[1] + _(" to ") + busName[0] + wxT(")"));
451 textMenu->Append(ID_TXT_BRANCH_FAULT_CURRENT_1_2, _("Fault current (") + busName[0] + _(" to ") + busName[1] + wxT(")"));
452 textMenu->Append(ID_TXT_BRANCH_FAULT_CURRENT_2_1, _("Fault current (") + busName[1] + _(" to ") + busName[0] + wxT(")"));
453 textMenu->SetClientData(menu.GetClientData());
454 menu.AppendSubMenu(textMenu, _("Add text"));
455
456 GeneralMenuItens(menu);
457 return true;
458}
@ ID_EDIT_ELEMENT
Definition Element.h:77
Node for power elements. All others power elements are connected through this.
Definition Bus.h:86
Base class of all elements of the program. This class is responsible for manage graphical and his dat...
Definition Element.h:114
virtual void GeneralMenuItens(wxMenu &menu)
Insert general itens to context menu.
Definition Element.cpp:393
Here is the call graph for this function:

◆ GetCopy()

Element * Transformer::GetCopy ( )
virtual

Get a the element copy.

Returns
Copy of the element.

Reimplemented from Element.

Definition at line 589 of file Transformer.cpp.

590{
591 Transformer* copy = new Transformer();
592 *copy = *this;
593 return copy;
594}
Two-winding transformer power element.
Definition Transformer.h:84

◆ GetElectricalData()

virtual TransformerElectricalData Transformer::GetElectricalData ( ) const
inlinevirtual

Definition at line 107 of file Transformer.h.

107{ return m_electricalData; }

◆ GetElectricalDataRef()

virtual TransformerElectricalData & Transformer::GetElectricalDataRef ( )
inlinevirtual

Definition at line 108 of file Transformer.h.

108{ return m_electricalData; }

◆ GetPUElectricalData()

TransformerElectricalData Transformer::GetPUElectricalData ( double  systemBasePower) const
virtual

Definition at line 657 of file Transformer.cpp.

658{
660
661 data.name = m_electricalData.name;
662
663 data.nominalPower = m_electricalData.nominalPower;
664 data.nominalPowerUnit = m_electricalData.nominalPowerUnit;
665
666 data.primaryNominalVoltage = m_electricalData.primaryNominalVoltage;
667 data.primaryNominalVoltageUnit = m_electricalData.primaryNominalVoltageUnit;
668
669 data.secondaryNominalVoltage = m_electricalData.secondaryNominalVoltage;
670 data.secondaryNominalVoltageUnit = m_electricalData.secondaryNominalVoltageUnit;
671
672 data.useTransformerPower = m_electricalData.useTransformerPower;
673
674 data.baseVoltage = m_electricalData.baseVoltage;
675
676 data.resistance = m_electricalData.resistance;
677 data.resistanceUnit = m_electricalData.resistanceUnit;
678
679 data.indReactance = m_electricalData.indReactance;
680 data.indReactanceUnit = m_electricalData.indReactanceUnit;
681
682 data.connection = m_electricalData.connection;
683 data.turnsRatio = m_electricalData.turnsRatio;
684 data.phaseShift = m_electricalData.phaseShift;
685
686 data.zeroResistance = m_electricalData.zeroResistance;
687 data.zeroIndReactance = m_electricalData.zeroIndReactance;
688
689 data.primaryGrndResistance = m_electricalData.primaryGrndResistance;
690 data.primaryGrndReactance = m_electricalData.primaryGrndReactance;
691
692 data.secondaryGrndResistance = m_electricalData.secondaryGrndResistance;
693 data.secondaryGrndReactance = m_electricalData.secondaryGrndReactance;
694
695 data.powerFlow[0] = m_electricalData.powerFlow[0];
696 data.powerFlow[1] = m_electricalData.powerFlow[1];
697
698 data.harmonicOrder = m_electricalData.harmonicOrder;
699 data.harmonicCurrent[0] = m_electricalData.harmonicCurrent[0];
700 data.harmonicCurrent[1] = m_electricalData.harmonicCurrent[1];
701
702 double transformerBasePower = GetValueFromUnit(data.nominalPower, data.nominalPowerUnit);
703 double baseVoltage = 0.0;
704 if (data.baseVoltage == 0) {
705 baseVoltage = GetValueFromUnit(data.primaryNominalVoltage, data.primaryNominalVoltageUnit);
706 }
707 else {
708 baseVoltage = GetValueFromUnit(data.secondaryNominalVoltage, data.secondaryNominalVoltageUnit);
709 }
710 double systemBaseImpedance = (baseVoltage * baseVoltage) / systemBasePower;
711 double transformerBaseImpedance = (baseVoltage * baseVoltage) / transformerBasePower;
712
713 // Resistance
714 double r = data.resistance;
715 if (data.resistanceUnit == ElectricalUnit::UNIT_PU) {
716 if (data.useTransformerPower) data.resistance = (r * transformerBaseImpedance) / systemBaseImpedance;
717 }
718 else {
719 data.resistance = r / systemBaseImpedance;
720 }
721 data.resistanceUnit = ElectricalUnit::UNIT_PU;
722
723 // Indutive reactance
724 double x = data.indReactance;
725 if (data.indReactanceUnit == ElectricalUnit::UNIT_PU) {
726 if (data.useTransformerPower) data.indReactance = (x * transformerBaseImpedance) / systemBaseImpedance;
727 }
728 else {
729 data.indReactance = x / systemBaseImpedance;
730 }
731 data.indReactanceUnit = ElectricalUnit::UNIT_PU;
732
733 // Fault
734
735 // Zero seq. resistance
736 double r0 = data.zeroResistance;
737 if (data.useTransformerPower) data.zeroResistance = (r0 * transformerBaseImpedance) / systemBaseImpedance;
738
739 // Zero seq. ind. reactance
740 double x0 = data.zeroIndReactance;
741 if (data.useTransformerPower) data.zeroIndReactance = (x0 * transformerBaseImpedance) / systemBaseImpedance;
742
743 // Primary ground resistance
744 double rgp = data.primaryGrndResistance;
745 if (data.useTransformerPower) data.primaryGrndResistance = (rgp * transformerBaseImpedance) / systemBaseImpedance;
746
747 // Primary ground ind reactance
748 double xgp = data.primaryGrndReactance;
749 if (data.useTransformerPower) data.primaryGrndReactance = (xgp * transformerBaseImpedance) / systemBaseImpedance;
750
751 // Secondary ground resistance
752 double rgs = data.secondaryGrndResistance;
753 if (data.useTransformerPower) data.secondaryGrndResistance = (rgs * transformerBaseImpedance) / systemBaseImpedance;
754
755 // Secondary ground ind reactance
756 double xgs = data.secondaryGrndReactance;
757 if (data.useTransformerPower) data.secondaryGrndReactance = (xgs * transformerBaseImpedance) / systemBaseImpedance;
758
759 if (!m_online) {
760 data.powerFlow[0] = std::complex<double>(0, 0);
761 data.powerFlow[1] = std::complex<double>(0, 0);
762 data.faultCurrent[0][0] = std::complex<double>(0, 0);
763 data.faultCurrent[0][1] = std::complex<double>(0, 0);
764 data.faultCurrent[0][2] = std::complex<double>(0, 0);
765 data.faultCurrent[1][0] = std::complex<double>(0, 0);
766 data.faultCurrent[1][1] = std::complex<double>(0, 0);
767 data.faultCurrent[1][2] = std::complex<double>(0, 0);
768 }
769
770 return data;
771}

◆ GetTipText()

wxString Transformer::GetTipText ( ) const
virtual

Get the tip text.

Returns
Tip text.

Reimplemented from Element.

Definition at line 596 of file Transformer.cpp.

597{
598 wxString tipText = m_electricalData.name;
599 wxString primVoltage = StringFromDouble(m_electricalData.primaryNominalVoltage);
600 switch (m_electricalData.primaryNominalVoltageUnit) {
601 case ElectricalUnit::UNIT_V: {
602 primVoltage += _(" V");
603 } break;
604 case ElectricalUnit::UNIT_kV: {
605 primVoltage += _(" kV");
606 } break;
607 default:
608 break;
609 }
610 wxString secVoltage = StringFromDouble(m_electricalData.secondaryNominalVoltage);
611 switch (m_electricalData.secondaryNominalVoltageUnit) {
612 case ElectricalUnit::UNIT_V: {
613 secVoltage += _(" V");
614 } break;
615 case ElectricalUnit::UNIT_kV: {
616 secVoltage += _(" kV");
617 } break;
618 default:
619 break;
620 }
621
622 tipText += "\n" + primVoltage + " / " + secVoltage;
623
624 if (m_online) {
625 tipText += "\n";
626 int busNumber[2];
627 busNumber[0] = static_cast<Bus*>(m_parentList[0])->GetElectricalData().number + 1;
628 busNumber[1] = static_cast<Bus*>(m_parentList[1])->GetElectricalData().number + 1;
629
630 tipText += _("\nP") + wxString::Format("(%d-%d) = ", busNumber[0], busNumber[1]) +
631 wxString::FromDouble(m_electricalData.powerFlow[0].real(), 5) + _(" p.u.");
632 tipText += _("\nQ") + wxString::Format("(%d-%d) = ", busNumber[0], busNumber[1]) +
633 wxString::FromDouble(m_electricalData.powerFlow[0].imag(), 5) + _(" p.u.");
634 tipText += _("\nP") + wxString::Format("(%d-%d) = ", busNumber[1], busNumber[0]) +
635 wxString::FromDouble(m_electricalData.powerFlow[1].real(), 5) + _(" p.u.");
636 tipText += _("\nQ") + wxString::Format("(%d-%d) = ", busNumber[1], busNumber[0]) +
637 wxString::FromDouble(m_electricalData.powerFlow[1].imag(), 5) + _(" p.u.");
638
639 if (!m_electricalData.harmonicOrder.empty()) {
640 tipText += _("\n\nHarmonic currents:");
641 int i = 0;
642 for (auto& hCurrent1 : m_electricalData.harmonicCurrent[0]) {
643 auto& hCurrent2 = m_electricalData.harmonicCurrent[1][i];
644 wxString i1, i2;
645 i1.Printf(_("\nIh(%d)(%d-%d) = %.5e%s%.2f%s p.u."), m_electricalData.harmonicOrder[i], busNumber[0], busNumber[1], std::abs(hCurrent1), wxString(L'\u2220'), wxRadToDeg(std::arg(hCurrent1)), wxString(L'\u00B0'));
646 i2.Printf(_("\nIh(%d)(%d-%d) = %.5e%s%.2f%s p.u."), m_electricalData.harmonicOrder[i], busNumber[1], busNumber[0], std::abs(hCurrent2), wxString(L'\u2220'), wxRadToDeg(std::arg(hCurrent2)), wxString(L'\u00B0'));
647
648 tipText += i1 + i2;
649 i++;
650 }
651 }
652 }
653
654 return tipText;
655}
static wxString StringFromDouble(double value, int minDecimal=1, int maxDecimals=13)
Convert a double value to string.
Definition Element.cpp:466
Here is the call graph for this function:

◆ Intersects()

bool Transformer::Intersects ( wxRect2DDouble  rect) const
virtual

Check if the element's rect intersects other rect.

Parameters
rectRect to check intersection.

Reimplemented from Branch.

Definition at line 344 of file Transformer.cpp.

345{
346 if (m_angle == 0.0 || m_angle == 180.0) return m_rect.Intersects(rect);
347 return RotatedRectanglesIntersects(m_rect, rect, m_angle, 0.0);
348}
virtual bool RotatedRectanglesIntersects(wxRect2DDouble rect1, wxRect2DDouble rect2, double angle1, double angle2) const
Check if two roteted rectangles intersect.
Definition Element.cpp:295
Here is the call graph for this function:

◆ Move()

void Transformer::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 Branch.

Definition at line 366 of file Transformer.cpp.

367{
368 SetPosition(m_movePos + position - m_moveStartPt);
369
370 // Move all the points, except the switches and buses points.
371 for (int i = 2; i < (int)m_pointList.size() - 2; i++) { m_pointList[i] = m_movePts[i] + position - m_moveStartPt; }
372
373 if (!m_parentList[0]) { m_pointList[0] = m_movePts[0] + position - m_moveStartPt; }
374 if (!m_parentList[1]) {
375 m_pointList[m_pointList.size() - 1] = m_movePts[m_pointList.size() - 1] + position - m_moveStartPt;
376 }
377
378 UpdateSwitchesPosition();
379 UpdatePowerFlowArrowsPosition();
380}
Here is the call graph for this function:

◆ MoveNode()

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

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

Parameters
parentNode's parent.
positionNew node position.

Reimplemented from Branch.

Definition at line 382 of file Transformer.cpp.

383{
384 if (parent) {
385 // First bus.
386 if (parent == m_parentList[0]) {
387 m_pointList[0] = m_movePts[0] + position - m_moveStartPt;
388 }
389 // Second bus.
390 else if (parent == m_parentList[1]) {
391 m_pointList[m_pointList.size() - 1] = m_movePts[m_pointList.size() - 1] + position - m_moveStartPt;
392 }
393 }
394 else {
395 if (m_activeNodeID == 1) {
396 m_pointList[0] = m_movePts[0] + position - m_moveStartPt;
397 if (m_parentList[0]) {
398 m_parentList[0]->RemoveChild(this);
399 m_parentList[0] = nullptr;
400 m_online = false;
401 }
402 }
403 else if (m_activeNodeID == 2) {
404 m_pointList[m_pointList.size() - 1] = m_movePts[m_pointList.size() - 1] + position - m_moveStartPt;
405 if (m_parentList[1]) {
406 m_parentList[1]->RemoveChild(this);
407 m_parentList[1] = nullptr;
408 m_online = false;
409 }
410 }
411 }
412
413 // Recalculate switches positions
414 UpdateSwitchesPosition();
415 UpdatePowerFlowArrowsPosition();
416}

◆ OpenElement()

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

Reimplemented from PowerElement.

Definition at line 862 of file Transformer.cpp.

863{
864 auto cadPropNode = elementNode->first_node("CADProperties");
865 if (!cadPropNode) return false;
866
867 auto position = cadPropNode->first_node("Position");
868 double posX = XMLParser::GetNodeValueDouble(position, "X");
869 double posY = XMLParser::GetNodeValueDouble(position, "Y");
870 auto size = cadPropNode->first_node("Size");
871 m_width = XMLParser::GetNodeValueDouble(size, "Width");
872 m_height = XMLParser::GetNodeValueDouble(size, "Height");
873 double angle = XMLParser::GetNodeValueDouble(cadPropNode, "Angle");
874
875 // Get nodes points
876 std::vector<wxPoint2DDouble> ptsList;
877 auto nodePosList = cadPropNode->first_node("NodeList");
878 if (!nodePosList) return false;
879 auto nodePos = nodePosList->first_node("Node");
880 while (nodePos) {
881 double nodePosX = XMLParser::GetNodeValueDouble(nodePos, "X");
882 double nodePosY = XMLParser::GetNodeValueDouble(nodePos, "Y");
883 ptsList.push_back(wxPoint2DDouble(nodePosX, nodePosY));
884 nodePos = nodePos->next_sibling("Node");
885 }
886
887 // Get parents IDs
888 auto parentIDList = cadPropNode->first_node("ParentIDList");
889 if (!parentIDList) return false;
890 auto parentNode = parentIDList->first_node("ParentID");
891 long parentID[2] = { -1, -1 };
892 while (parentNode) {
893 long index = 0;
894 wxString(parentNode->first_attribute("ID")->value()).ToLong(&index);
895 wxString(parentNode->value()).ToCLong(&parentID[index]);
896 parentNode = parentNode->next_sibling("ParentID");
897 }
898
899 std::vector<wxPoint2DDouble> nodePtsList; // List of node points
900 nodePtsList.push_back(ptsList[0]); // First point on the list
901 nodePtsList.push_back(ptsList[ptsList.size() - 1]); // Last point on the list
902
903 // List of dummy buses to set not connected nodes properly
904 std::vector<Bus*> dummyBusList;
905 // Set parents (if have)
906 for (unsigned int i = 0; i < 2; ++i) {
907 if (parentID[i] == -1) // No parent connected
908 {
909 Bus* dummyBus = new Bus(nodePtsList[i]);
910 dummyBusList.push_back(dummyBus);
911 AddParent(dummyBus, nodePtsList[i]);
912 }
913 else { // Parent connected (necessarily a bus, get from bus list)
914 AddParent(parentList[parentID[i]], nodePtsList[i]);
915 }
916 }
917
918 StartMove(m_position);
919 Move(wxPoint2DDouble(posX, posY));
920
921 // Remove dummy buses
922 for (auto it = dummyBusList.begin(), itEnd = dummyBusList.end(); it != itEnd; ++it) {
923 RemoveParent(*it);
924 delete* it;
925 }
926 dummyBusList.clear();
927
928 // Set rotation properly.
929 int numRot = angle / GetRotationAngle();
930 bool clockwise = true;
931 if (numRot < 0) {
932 numRot = std::abs(numRot);
933 clockwise = false;
934 }
935 for (int i = 0; i < numRot; i++) Rotate(clockwise);
936
937 auto electricalProp = elementNode->first_node("ElectricalProperties");
938 if (!electricalProp) return false;
939
940 SetOnline(XMLParser::GetNodeValueInt(electricalProp, "IsOnline"));
941 m_electricalData.name = electricalProp->first_node("Name")->value();
942 m_electricalData.primaryNominalVoltage = XMLParser::GetNodeValueDouble(electricalProp, "PrimaryNominalVoltage");
943 m_electricalData.primaryNominalVoltageUnit =
944 static_cast<ElectricalUnit>(XMLParser::GetAttributeValueInt(electricalProp, "PrimaryNominalVoltage", "UnitID"));
945 m_electricalData.secondaryNominalVoltage = XMLParser::GetNodeValueDouble(electricalProp, "SecondaryNominalVoltage");
946 m_electricalData.secondaryNominalVoltageUnit = static_cast<ElectricalUnit>(
947 XMLParser::GetAttributeValueInt(electricalProp, "SecondaryNominalVoltage", "UnitID"));
948 m_electricalData.nominalPower = XMLParser::GetNodeValueDouble(electricalProp, "NominalPower");
949 m_electricalData.nominalPowerUnit =
950 static_cast<ElectricalUnit>(XMLParser::GetAttributeValueInt(electricalProp, "NominalPower", "UnitID"));
951 m_electricalData.resistance = XMLParser::GetNodeValueDouble(electricalProp, "Resistance");
952 m_electricalData.resistanceUnit =
953 static_cast<ElectricalUnit>(XMLParser::GetAttributeValueInt(electricalProp, "Resistance", "UnitID"));
954 m_electricalData.indReactance = XMLParser::GetNodeValueDouble(electricalProp, "IndReactance");
955 m_electricalData.indReactanceUnit =
956 static_cast<ElectricalUnit>(XMLParser::GetAttributeValueInt(electricalProp, "IndReactance", "UnitID"));
957 m_electricalData.connection = (TransformerConnection)XMLParser::GetNodeValueInt(electricalProp, "Connection");
958 m_electricalData.turnsRatio = XMLParser::GetNodeValueDouble(electricalProp, "TurnsRatio");
959 m_electricalData.phaseShift = XMLParser::GetNodeValueDouble(electricalProp, "PhaseShift");
960 m_electricalData.useTransformerPower = XMLParser::GetNodeValueInt(electricalProp, "UseTransfomerPower");
961
962 auto fault = electricalProp->first_node("Fault");
963 m_electricalData.zeroResistance = XMLParser::GetNodeValueDouble(fault, "ZeroResistance");
964 m_electricalData.zeroIndReactance = XMLParser::GetNodeValueDouble(fault, "ZeroIndReactance");
965 m_electricalData.primaryGrndResistance = XMLParser::GetNodeValueDouble(fault, "PrimaryGrndResistance");
966 m_electricalData.primaryGrndReactance = XMLParser::GetNodeValueDouble(fault, "PrimaryGrndReactance");
967 m_electricalData.secondaryGrndResistance = XMLParser::GetNodeValueDouble(fault, "SecondaryGrndResistance");
968 m_electricalData.secondaryGrndReactance = XMLParser::GetNodeValueDouble(fault, "SecondaryGrndReactance");
969
970 if (!OpenSwitchingData(electricalProp)) return false;
971 if (m_swData.swTime.size() != 0) SetDynamicEvent(true);
972
973 return true;
974}
virtual void RemoveParent(Element *parent)
Remove a parent.
Definition Branch.cpp:105
double GetRotationAngle() const
Get the angle of rotation.
Definition Element.h:218
bool SetOnline(bool online=true)
Set if the element is online or offline.
Definition Element.cpp:383
virtual void SetDynamicEvent(bool dynEvent=true)
Set if the power element have dynamic event.
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 Rotate(bool clockwise=true)
Rotate the element.
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,...
std::vector< double > swTime

◆ Rotate()

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

Rotate the element.

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

Reimplemented from Element.

Definition at line 350 of file Transformer.cpp.

351{
352 double rotAngle = m_rotationAngle;
353 if (!clockwise) rotAngle = -m_rotationAngle;
354
355 m_angle += rotAngle;
356 if (m_angle >= 360 || m_angle <= -360) m_angle = 0.0;
357
358 // Rotate all the points, except the switches and buses points.
359 for (int i = 2; i < (int)m_pointList.size() - 2; i++) {
360 m_pointList[i] = RotateAtPosition(m_pointList[i], rotAngle);
361 }
362 UpdateSwitchesPosition();
363 UpdatePowerFlowArrowsPosition();
364}
Here is the call graph for this function:

◆ RotateNode()

void Transformer::RotateNode ( Element parent,
bool  clockwise 
)
virtual

Rotate a node.

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

Reimplemented from Branch.

Definition at line 503 of file Transformer.cpp.

504{
505 double rotAngle = m_rotationAngle;
506 if (!clockwise) rotAngle = -m_rotationAngle;
507
508 if (parent == m_parentList[0]) {
509 m_pointList[0] = parent->RotateAtPosition(m_pointList[0], rotAngle);
510 }
511 else if (parent == m_parentList[1]) {
512 m_pointList[m_pointList.size() - 1] = parent->RotateAtPosition(m_pointList[m_pointList.size() - 1], rotAngle);
513 }
514 UpdateSwitchesPosition();
515 UpdatePowerFlowArrowsPosition();
516}
Here is the call graph for this function:

◆ SaveElement()

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

Reimplemented from Element.

Definition at line 773 of file Transformer.cpp.

774{
775 auto elementNode = XMLParser::AppendNode(doc, elementListNode, "Transfomer");
776 XMLParser::SetNodeAttribute(doc, elementNode, "ID", m_elementID);
777 auto cadProp = XMLParser::AppendNode(doc, elementNode, "CADProperties");
778 auto position = XMLParser::AppendNode(doc, cadProp, "Position");
779 auto posX = XMLParser::AppendNode(doc, position, "X");
780 XMLParser::SetNodeValue(doc, posX, m_position.m_x);
781 auto posY = XMLParser::AppendNode(doc, position, "Y");
782 XMLParser::SetNodeValue(doc, posY, m_position.m_y);
783 auto size = XMLParser::AppendNode(doc, cadProp, "Size");
784 auto width = XMLParser::AppendNode(doc, size, "Width");
785 XMLParser::SetNodeValue(doc, width, m_width);
786 auto height = XMLParser::AppendNode(doc, size, "Height");
787 XMLParser::SetNodeValue(doc, height, m_height);
788 auto angle = XMLParser::AppendNode(doc, cadProp, "Angle");
789 XMLParser::SetNodeValue(doc, angle, m_angle);
790 auto nodeList = XMLParser::AppendNode(doc, cadProp, "NodeList");
791 auto nodePos1 = XMLParser::AppendNode(doc, nodeList, "Node");
792 XMLParser::SetNodeAttribute(doc, nodePos1, "ID", 0);
793 auto nodePosX1 = XMLParser::AppendNode(doc, nodePos1, "X");
794 XMLParser::SetNodeValue(doc, nodePosX1, m_pointList[0].m_x);
795 auto nodePosY1 = XMLParser::AppendNode(doc, nodePos1, "Y");
796 XMLParser::SetNodeValue(doc, nodePosY1, m_pointList[0].m_y);
797 auto nodePos2 = XMLParser::AppendNode(doc, nodeList, "Node");
798 XMLParser::SetNodeAttribute(doc, nodePos2, "ID", 1);
799 auto nodePosX2 = XMLParser::AppendNode(doc, nodePos2, "X");
800 XMLParser::SetNodeValue(doc, nodePosX2, m_pointList[m_pointList.size() - 1].m_x);
801 auto nodePosY2 = XMLParser::AppendNode(doc, nodePos2, "Y");
802 XMLParser::SetNodeValue(doc, nodePosY2, m_pointList[m_pointList.size() - 1].m_y);
803
804 auto parentIDList = XMLParser::AppendNode(doc, cadProp, "ParentIDList");
805 for (unsigned int i = 0; i < m_parentList.size(); i++) {
806 Element* parent = m_parentList[i];
807 if (parent) {
808 auto parentID = XMLParser::AppendNode(doc, parentIDList, "ParentID");
809 XMLParser::SetNodeAttribute(doc, parentID, "ID", static_cast<int>(i));
810 XMLParser::SetNodeValue(doc, parentID, parent->GetID());
811 }
812 }
813
814 auto electricalProp = XMLParser::AppendNode(doc, elementNode, "ElectricalProperties");
815 auto isOnline = XMLParser::AppendNode(doc, electricalProp, "IsOnline");
816 XMLParser::SetNodeValue(doc, isOnline, m_online);
817 auto name = XMLParser::AppendNode(doc, electricalProp, "Name");
818 XMLParser::SetNodeValue(doc, name, m_electricalData.name);
819 auto primaryNominalVoltage = XMLParser::AppendNode(doc, electricalProp, "PrimaryNominalVoltage");
820 XMLParser::SetNodeValue(doc, primaryNominalVoltage, m_electricalData.primaryNominalVoltage);
821 XMLParser::SetNodeAttribute(doc, primaryNominalVoltage, "UnitID", static_cast<int>(m_electricalData.primaryNominalVoltageUnit));
822 auto secondaryNominalVoltage = XMLParser::AppendNode(doc, electricalProp, "SecondaryNominalVoltage");
823 XMLParser::SetNodeValue(doc, secondaryNominalVoltage, m_electricalData.secondaryNominalVoltage);
824 XMLParser::SetNodeAttribute(doc, secondaryNominalVoltage, "UnitID", static_cast<int>(m_electricalData.secondaryNominalVoltageUnit));
825 auto nominalPower = XMLParser::AppendNode(doc, electricalProp, "NominalPower");
826 XMLParser::SetNodeValue(doc, nominalPower, m_electricalData.nominalPower);
827 XMLParser::SetNodeAttribute(doc, nominalPower, "UnitID", static_cast<int>(m_electricalData.nominalPowerUnit));
828 auto resistance = XMLParser::AppendNode(doc, electricalProp, "Resistance");
829 XMLParser::SetNodeValue(doc, resistance, m_electricalData.resistance);
830 XMLParser::SetNodeAttribute(doc, resistance, "UnitID", static_cast<int>(m_electricalData.resistanceUnit));
831 auto indReactance = XMLParser::AppendNode(doc, electricalProp, "IndReactance");
832 XMLParser::SetNodeValue(doc, indReactance, m_electricalData.indReactance);
833 XMLParser::SetNodeAttribute(doc, indReactance, "UnitID", static_cast<int>(m_electricalData.indReactanceUnit));
834 auto connection = XMLParser::AppendNode(doc, electricalProp, "Connection");
835 XMLParser::SetNodeValue(doc, connection, m_electricalData.connection);
836 auto turnsRatio = XMLParser::AppendNode(doc, electricalProp, "TurnsRatio");
837 XMLParser::SetNodeValue(doc, turnsRatio, m_electricalData.turnsRatio);
838 auto phaseShift = XMLParser::AppendNode(doc, electricalProp, "PhaseShift");
839 XMLParser::SetNodeValue(doc, phaseShift, m_electricalData.phaseShift);
840 auto useTransformerPower = XMLParser::AppendNode(doc, electricalProp, "UseTransfomerPower");
841 XMLParser::SetNodeValue(doc, useTransformerPower, m_electricalData.useTransformerPower);
842
843 auto fault = XMLParser::AppendNode(doc, electricalProp, "Fault");
844 auto zeroResistance = XMLParser::AppendNode(doc, fault, "ZeroResistance");
845 XMLParser::SetNodeValue(doc, zeroResistance, m_electricalData.zeroResistance);
846 auto zeroIndReactance = XMLParser::AppendNode(doc, fault, "ZeroIndReactance");
847 XMLParser::SetNodeValue(doc, zeroIndReactance, m_electricalData.zeroIndReactance);
848 auto primaryGrndResistance = XMLParser::AppendNode(doc, fault, "PrimaryGrndResistance");
849 XMLParser::SetNodeValue(doc, primaryGrndResistance, m_electricalData.primaryGrndResistance);
850 auto primaryGrndReactance = XMLParser::AppendNode(doc, fault, "PrimaryGrndReactance");
851 XMLParser::SetNodeValue(doc, primaryGrndReactance, m_electricalData.primaryGrndReactance);
852 auto secondaryGrndResistance = XMLParser::AppendNode(doc, fault, "SecondaryGrndResistance");
853 XMLParser::SetNodeValue(doc, secondaryGrndResistance, m_electricalData.secondaryGrndResistance);
854 auto secondaryGrndReactance = XMLParser::AppendNode(doc, fault, "SecondaryGrndReactance");
855 XMLParser::SetNodeValue(doc, secondaryGrndReactance, m_electricalData.secondaryGrndReactance);
856
857 SaveSwitchingData(doc, electricalProp);
858
859 return elementNode;
860}
virtual int GetID() const
Get the element ID.
Definition Element.h:273

◆ SetBestPositionAndRotation()

void Transformer::SetBestPositionAndRotation ( )
virtual

Definition at line 976 of file Transformer.cpp.

977{
978 wxPoint2DDouble p1 = m_pointList[0];
979 wxPoint2DDouble p2 = m_pointList[m_pointList.size() - 1];
980 wxPoint2DDouble mid = (p1 + p2) / 2.0;
981 StartMove(m_position);
982 Move(mid);
983 double bestAngle = wxRadToDeg(std::atan2(p2.m_y - p1.m_y, p2.m_x - p1.m_x));
984 bool clockwise = bestAngle > 0 ? true : false;
985 while (std::abs(m_angle) < std::abs(bestAngle)) { Rotate(clockwise); }
986}

◆ SetElectricaData()

virtual void Transformer::SetElectricaData ( TransformerElectricalData  electricalData)
inlinevirtual

Definition at line 110 of file Transformer.h.

110{ m_electricalData = electricalData; }

◆ SetNodeParent()

bool Transformer::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 Branch.

Definition at line 518 of file Transformer.cpp.

519{
520 if (m_activeNodeID == 1 && parent == m_parentList[0]) return false;
521 if (m_activeNodeID == 2 && parent == m_parentList[1]) return false;
522
523 if (parent && m_activeNodeID != 0) {
524 wxRect2DDouble nodeRect(0, 0, 0, 0);
525 if (m_activeNodeID == 1) {
526 nodeRect = wxRect2DDouble(m_pointList[0].m_x - 5.0 - m_borderSize, m_pointList[0].m_y - 5.0 - m_borderSize,
527 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize);
528 }
529 if (m_activeNodeID == 2) {
530 nodeRect = wxRect2DDouble(m_pointList[m_pointList.size() - 1].m_x - 5.0 - m_borderSize,
531 m_pointList[m_pointList.size() - 1].m_y - 5.0 - m_borderSize,
532 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize);
533 }
534
535 if (parent->Intersects(nodeRect)) {
536 if (m_activeNodeID == 1) {
537 // Check if the user is trying to connect the same bus.
538 if (m_parentList[1] == parent) {
539 m_activeNodeID = 0;
540 return false;
541 }
542
543 m_parentList[0] = parent;
544
545 // Centralize the node on bus.
546 wxPoint2DDouble parentPt = parent->RotateAtPosition(
547 m_pointList[0], -parent->GetAngle()); // Rotate click to horizontal position.
548 parentPt.m_y = parent->GetPosition().m_y; // Centralize on bus.
549 parentPt = parent->RotateAtPosition(parentPt, parent->GetAngle());
550 m_pointList[0] = parentPt;
551
552 UpdateSwitchesPosition();
553 UpdatePowerFlowArrowsPosition();
554 return true;
555 }
556 if (m_activeNodeID == 2) {
557 if (m_parentList[0] == parent) {
558 m_activeNodeID = 0;
559 return false;
560 }
561
562 m_parentList[1] = parent;
563
564 wxPoint2DDouble parentPt =
565 parent->RotateAtPosition(m_pointList[m_pointList.size() - 1], -parent->GetAngle());
566 parentPt.m_y = parent->GetPosition().m_y;
567 parentPt = parent->RotateAtPosition(parentPt, parent->GetAngle());
568 m_pointList[m_pointList.size() - 1] = parentPt;
569
570 UpdateSwitchesPosition();
571 UpdatePowerFlowArrowsPosition();
572 return true;
573 }
574 }
575 else {
576 if (m_activeNodeID == 1) m_parentList[0] = nullptr;
577 if (m_activeNodeID == 2) m_parentList[1] = nullptr;
578 }
579 }
580 return false;
581}
virtual bool Intersects(wxRect2DDouble rect) const =0
Check if the element's rect intersects other rect.
Here is the call graph for this function:

◆ SetNominalVoltage()

void Transformer::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 from PowerElement.

Definition at line 470 of file Transformer.cpp.

471{
472 if (nominalVoltage.size() == 1) {
473 m_electricalData.primaryNominalVoltage = nominalVoltage[0];
474 m_electricalData.primaryNominalVoltageUnit = nominalVoltageUnit[0];
475 }
476 else if (nominalVoltage.size() == 2) {
477 m_electricalData.primaryNominalVoltage = nominalVoltage[0];
478 m_electricalData.primaryNominalVoltageUnit = nominalVoltageUnit[0];
479 m_electricalData.secondaryNominalVoltage = nominalVoltage[1];
480 m_electricalData.secondaryNominalVoltageUnit = nominalVoltageUnit[1];
481 }
482}

◆ SetPowerFlowDirection()

void Transformer::SetPowerFlowDirection ( PowerFlowDirection  pfDirection)
virtual

Set the direction of the power flow.

Parameters
pfDirectionPower flow direction.

Reimplemented from PowerElement.

Definition at line 583 of file Transformer.cpp.

584{
585 m_pfDirection = pfDirection;
586 UpdatePowerFlowArrowsPosition();
587}
Here is the caller graph for this function:

◆ ShowForm()

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

Show element data form.

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

Reimplemented from Element.

Definition at line 460 of file Transformer.cpp.

461{
462 TransformerForm transfForm(parent, this);
463 transfForm.CenterOnParent();
464 if (transfForm.ShowModal() == wxID_OK) {
465 return true;
466 }
467 return false;
468}
Form to edit the transformer power data.

◆ StartMove()

void Transformer::StartMove ( wxPoint2DDouble  position)
virtual

Update the element attributes related to the movement.

Parameters
positionStart move position.

Reimplemented from Branch.

Definition at line 418 of file Transformer.cpp.

419{
420 m_moveStartPt = position;
421 m_movePts = m_pointList;
422 m_movePos = m_position;
423}

◆ UpdatePowerFlowArrowsPosition()

void Transformer::UpdatePowerFlowArrowsPosition ( )
protected

Definition at line 484 of file Transformer.cpp.

485{
486 std::vector<wxPoint2DDouble> edges;
487 switch (m_pfDirection) {
489 m_powerFlowArrow.clear();
490 } break;
492 for (int i = 1; i < (int)m_pointList.size() - 1; i++) { edges.push_back(m_pointList[i]); }
493 } break;
495 for (int i = (int)m_pointList.size() - 2; i > 0; i--) { edges.push_back(m_pointList[i]); }
496 } break;
497 default:
498 break;
499 }
501}
virtual void CalculatePowerFlowPts(std::vector< wxPoint2DDouble > edges)
Calculate the points of the power flow arrows.

Member Data Documentation

◆ m_electricalData

TransformerElectricalData Transformer::m_electricalData
protected

Definition at line 119 of file Transformer.h.


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