Power System Platform  2026w11a-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 (wxPoint2DDouble translation, double scale, wxGraphicsContext *gc) const
 Draw the element using GDI+.
 
virtual void DrawDC (wxPoint2DDouble translation, double scale, wxDC &dc) const
 Draw the element using wxDC.
 
virtual bool Intersects (wxRect2DDouble rect) const
 Check if the element's rect intersects other rect.
 
virtual void 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)
 
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 void Draw (wxPoint2DDouble translation, double scale) const
 
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 (wxGraphicsContext *gc) const
 Draw switch.
 
virtual void DrawDCSwitches (wxDC &dc) const
 
virtual void CalculatePowerFlowPts (std::vector< wxPoint2DDouble > edges)
 Calculate the points of the power flow arrows.
 
virtual void DrawDCPowerFlowPts (wxGraphicsContext *gc) const
 Draw power flow arrows.
 
virtual void DrawDCPowerFlowPts (wxDC &dc) const
 
virtual void SetSwitchingData (SwitchingData data)
 Set the switching data of the element.
 
virtual SwitchingData GetSwitchingData ()
 Returns the switching data of the element.
 
virtual PowerFlowDirection GetPowerFlowDirection () const
 Return the direction of the power flow.
 
virtual bool GetPlotData (ElementPlotData &plotData, PlotStudy study=PlotStudy::STABILITY)
 Fill the plot data.
 
virtual bool HaveDynamicEvent () const
 Check if the power element have dynamic event.
 
virtual void SetDynamicEvent (bool dynEvent=true)
 Set if the power element have dynamic event.
 
virtual double GetValueFromUnit (double value, ElectricalUnit valueUnit)
 
virtual void SaveCADProperties (rapidxml::xml_document<> &doc, rapidxml::xml_node<> *elementNode)
 
virtual void SaveSwitchingData (rapidxml::xml_document<> &doc, rapidxml::xml_node<> *electricalNode)
 
virtual bool 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
 
wxColour m_selectionColour
 

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:186
double GetAngle() const
Get the element angle.
Definition Element.h:211
void SetPosition(const wxPoint2DDouble position)
Set the element position and update the rectangle.
Definition Element.cpp:28
virtual wxPoint2DDouble RotateAtPosition(wxPoint2DDouble pointToRotate, double angle, bool degrees=true) const
Rotate a point as element position being the origin.
Definition Element.cpp:223
virtual void AddChild(Element *child)
Add a child to the child list.
Definition Element.cpp:494
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 ( wxPoint2DDouble  translation,
double  scale,
wxDC &  dc 
) const
virtual

Draw the element using wxDC.

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

Reimplemented from Element.

Definition at line 272 of file Transformer.cpp.

273{
274 wxColour elementColour;
275 if (m_online) {
276 if (m_dynEvent)
277 elementColour = m_dynamicEventColour;
278 else
279 elementColour = m_onlineElementColour;
280 }
281 else
282 elementColour = m_offlineElementColour;
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(m_selectionColour), 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(m_selectionColour));
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(m_selectionColour));
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(dc);
326
327 dc.SetPen(*wxTRANSPARENT_PEN);
328 dc.SetBrush(*wxWHITE_BRUSH);
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:168
virtual void DrawDCSwitches(wxGraphicsContext *gc) const
Draw switch.
virtual void DrawDCPowerFlowPts(wxGraphicsContext *gc) const
Draw power flow arrows.
Here is the call graph for this function:

◆ DrawDC() [2/2]

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

Draw the element using GDI+.

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

Reimplemented from Element.

Definition at line 186 of file Transformer.cpp.

187{
188 wxColour elementColour;
189 if (m_online) {
190 if (m_dynEvent)
191 elementColour = m_dynamicEventColour;
192 else
193 elementColour = m_onlineElementColour;
194 }
195 else
196 elementColour = m_offlineElementColour;
197
198 if (m_inserted) {
199 // Draw selection (layer 1).
200 if (m_selected) {
201 gc->SetPen(wxPen(wxColour(m_selectionColour), 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(m_selectionColour));
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(m_selectionColour));
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(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(*wxWHITE_BRUSH);
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:75
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:112
virtual void GeneralMenuItens(wxMenu &menu)
Insert general itens to context menu.
Definition Element.cpp:388
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)
virtual

Definition at line 657 of file Transformer.cpp.

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

◆ 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) {
602 primVoltage += _(" V");
603 } break;
605 primVoltage += _(" kV");
606 } break;
607 default:
608 break;
609 }
610 wxString secVoltage = StringFromDouble(m_electricalData.secondaryNominalVoltage);
611 switch (m_electricalData.secondaryNominalVoltageUnit) {
613 secVoltage += _(" V");
614 } break;
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:461
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:290
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 860 of file Transformer.cpp.

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

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

◆ SetBestPositionAndRotation()

void Transformer::SetBestPositionAndRotation ( )
virtual

Definition at line 974 of file Transformer.cpp.

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

◆ 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: