Power System Platform  2026w34a-beta
Loading...
Searching...
No Matches
Element.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017 Thales Lima Oliveira <thales@ufu.br>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#ifndef ELEMENT_H
19#define ELEMENT_H
20
21#include <wx/msgdlg.h>
22#include <wx/geometry.h>
23#include <wx/cursor.h>
24#include <wx/menu.h>
25#include <wx/stdpaths.h>
26#include <wx/filename.h>
27 //#include <GL/glew.h>
28#ifdef _MSC_VER
29 //#include <windows.h>
30#endif
31//#include <GL/gl.h>
32#include <wx/graphics.h>
33#include <wx/dc.h>
34
35#include <complex>
36
37#include "../utils/XMLParser.h"
38//#include "../utils/PropertiesData.h"
39#include "../utils/CommomTypes.h"
40
41//#include <wx/log.h>
42
43enum ElementType {
44 TYPE_NONE = 0,
45 TYPE_BUS,
46 TYPE_CAPACITOR,
47 TYPE_IND_MOTOR,
48 TYPE_INDUCTOR,
49 TYPE_LINE,
50 TYPE_LOAD,
51 TYPE_SYNC_GENERATOR,
52 TYPE_SYNC_MOTOR,
53 TYPE_TRANSFORMER,
54 TYPE_HARMCURRENT,
55 TYPE_TEXT
56};
57
71
84
85enum TextID {
86 ID_TXT_NAME = 1000,
87 ID_TXT_VOLTAGE,
88 ID_TXT_ANGLE,
89 ID_TXT_FAULTCURRENT,
90 ID_TXT_FAULTVOLTAGE,
91 ID_TXT_SCC,
92 ID_TXT_THD,
93 ID_TXT_ACTIVE_POWER,
94 ID_TXT_REACTIVE_POWER,
95 ID_TXT_BRANCH_ACTIVE_POWER_1_2,
96 ID_TXT_BRANCH_ACTIVE_POWER_2_1,
97 ID_TXT_BRANCH_REACTIVE_POWER_1_2,
98 ID_TXT_BRANCH_REACTIVE_POWER_2_1,
99 ID_TXT_BRANCH_LOSSES,
100 ID_TXT_BRANCH_CURRENT_1_2,
101 ID_TXT_BRANCH_CURRENT_2_1,
102 ID_TXT_BRANCH_FAULT_CURRENT_1_2,
103 ID_TXT_BRANCH_FAULT_CURRENT_2_1,
104 ID_TXT_TAP
105};
115{
116public:
120 Element();
121
125 virtual ~Element() {}
126
131 void SetDragging(bool dragging = true) { m_dragging = dragging; }
136 void SetHeight(double height) { m_height = height; }
141 void SetPosition(const wxPoint2DDouble position);
142
147 void SetSelected(bool selected = true) { m_selected = selected; }
152 void SetWidth(double width) { m_width = width; }
157 void SetAngle(double angle) { m_angle = angle; }
162 void ShowPickbox(bool showPickbox = true) { m_showPickbox = showPickbox; }
167 void SetBorderSize(double borderSize) { m_borderSize = borderSize; }
172 bool SetOnline(bool online = true);
173
178 virtual void SetPointList(std::vector<wxPoint2DDouble> pointList) { m_pointList = pointList; }
179 ElementType GetElementType() { return m_elementType; }
184 wxRect2DDouble GetRect() const { return m_rect; }
189 wxPoint2DDouble GetPosition() const { return m_position; }
194 bool IsDragging() const { return m_dragging; }
199 double GetHeight() const { return m_height; }
204 bool IsSelected() const { return m_selected; }
209 double GetWidth() const { return m_width; }
214 double GetAngle() const { return m_angle; }
219 double GetRotationAngle() const { return m_rotationAngle; }
224 bool IsPickboxShown() const { return m_showPickbox; }
229 bool IsOnline() const { return m_online; }
234 virtual std::vector<wxPoint2DDouble> GetPointList() const { return m_pointList; }
235 virtual std::vector<wxPoint2DDouble>& GetPointListRef() { return m_pointList; }
243 virtual bool AddParent(Element* parent, wxPoint2DDouble position, bool isOpening = false) { return false; }
248 virtual void AddParent(Element* parent) { m_parentList.push_back(parent); }
253 virtual bool Contains(wxPoint2DDouble position) const = 0;
254
259 virtual bool Intersects(wxRect2DDouble rect) const = 0;
260
265 virtual Element* GetCopy() { return nullptr; }
270 virtual void SetID(int id) { m_elementID = id; }
275 virtual int GetID() const { return m_elementID; }
280 virtual void AddChild(Element* child);
281
286 virtual void RemoveChild(Element* child);
287
293 virtual void ReplaceChild(Element* oldChild, Element* newChild);
294
299 virtual wxString GetTipText() const { return wxEmptyString; }
300
308 virtual void DrawDC(GUIColour* guiColour, wxPoint2DDouble translation, double scale, wxGraphicsContext* gc) const {}
316 virtual void DrawDC(GUIColour* guiColour, wxPoint2DDouble translation, double scale, wxDC& dc) const {}
321 virtual void Rotate(bool clockwise = true) {}
327 virtual bool GetContextMenu(wxMenu& menu) { return false; }
332 virtual void AddPoint(wxPoint2DDouble point) {}
337 virtual void StartMove(wxPoint2DDouble position);
338
344 virtual void Move(wxPoint2DDouble position);
345 virtual void AlignToGrid(double gridSize = 20.0);
346
352 virtual void MoveNode(Element* parent, wxPoint2DDouble position) {}
358 virtual bool NodeContains(wxPoint2DDouble position) { return false; }
362 virtual void UpdateNodes() {}
363
364 void SetParent(Element* parent, int num) { m_parentList[num] = parent; }
365 void SetChild(Element* child, int num) { m_childList[num] = child; }
372 virtual bool SetNodeParent(Element* parent) { return false; }
377 virtual void RemoveParent(Element* parent) {}
383 virtual void ReplaceParent(Element* oldParent, Element* newParent);
384
390 virtual void RotateNode(Element* parent, bool clockwise = true) {}
397 virtual bool PickboxContains(wxPoint2DDouble position) { return false; }
402 virtual void MovePickbox(wxPoint2DDouble position) {}
407 virtual wxCursor GetBestPickboxCursor() const { return wxCURSOR_ARROW; }
411 virtual void ResetPickboxes() { m_activePickboxID = ID_PB_NONE; }
415 virtual void ResetNodes() { m_activeNodeID = 0; }
423 virtual wxPoint2DDouble WorldToScreen(wxPoint2DDouble translation,
424 double scale,
425 double offsetX = 0.0,
426 double offsetY = 0.0) const;
427
436 virtual wxPoint2DDouble WorldToScreen(wxPoint2DDouble position,
437 wxPoint2DDouble translation,
438 double scale,
439 double offsetX = 0.0,
440 double offsetY = 0.0) const;
441
449 virtual bool RotatedRectanglesIntersects(wxRect2DDouble rect1,
450 wxRect2DDouble rect2,
451 double angle1,
452 double angle2) const;
453
461 //virtual void DrawCircle(wxPoint2DDouble position, double radius, int numSegments, GLenum mode = GL_LINE_LOOP) const;
462
463 virtual void DrawDCRectangle(wxPoint2DDouble position, double width, double height, double angle, wxDC& dc) const;
464
465 virtual void DrawDCRoundedRectRotated(wxDC& dc, const wxPoint2DDouble& center, double width, double height, double radius, double angleDeg, int arcSegments = 8) const;
466
474 virtual void DrawDCCircle(wxPoint2DDouble position, double radius, int numSegments, wxGraphicsContext* gc) const;
475
476 virtual void DrawDCCircle(wxPoint2DDouble position, double radius, wxDC& dc) const;
477
478 //virtual void DrawArc(wxPoint2DDouble position,
479 // double radius,
480 // double initAngle,
481 // double finalAngle,
482 // int numSegments,
483 // GLenum mode = GL_LINE_LOOP) const;
484
485 virtual void DrawDCArc(wxPoint2DDouble position, double radius, double initAngle, double finalAngle, int numSegments, wxGraphicsContext* gc) const;
486
487 virtual void DrawDCArc(wxPoint2DDouble position, double radius, double initAngle, double finalAngle, wxDC& dc) const;
488
496 //virtual void DrawRectangle(wxPoint2DDouble position, double width, double height, GLenum mode = GL_QUADS) const;
497 //virtual void DrawRectangle(wxPoint2DDouble position, double width, double height) const;
498
504 //virtual void DrawRectangle(wxPoint2DDouble* points, GLenum mode = GL_QUADS) const;
505
511 //virtual void DrawTriangle(std::vector<wxPoint2DDouble> points, GLenum mode = GL_TRIANGLES) const;
512
518 virtual void DrawDCTriangle(std::vector<wxPoint2DDouble> points, wxGraphicsContext* gc) const;
519
520 virtual void DrawDCTriangle(std::vector<wxPoint> points, wxDC& dc) const;
521
522 virtual void DrawStabilityEventGC(wxGraphicsContext* gc, wxPoint2DDouble translation, double scale, GUIColour* guiColour, bool rotateAnchor = false, wxPoint2DDouble iconPosition = wxPoint2DDouble(-1, -1)) const;
523
529 //virtual void DrawPoint(wxPoint2DDouble position, double size) const;
530
536 //virtual void DrawLine(std::vector<wxPoint2DDouble> points, GLenum mode = GL_LINE_STRIP) const;
537
542 //virtual void DrawPickbox(wxPoint2DDouble position) const;
543
549 virtual void DrawDCPickbox(wxPoint2DDouble position, wxGraphicsContext* gc) const;
550
557 virtual wxPoint2DDouble RotateAtPosition(wxPoint2DDouble pointToRotate, double angle, bool degrees = true) const;
558
559 virtual wxPoint2DDouble RotateLocal(wxPoint2DDouble local, double angleDeg) const;
560
561 virtual wxPoint RotateAround(const wxPoint2DDouble& p, const wxPoint2DDouble& center, double angleDeg) const;
562
567 virtual std::vector<Element*> GetParentList() const { return m_parentList; }
572 virtual std::vector<Element*> GetChildList() const { return m_childList; }
573 virtual wxPoint2DDouble GetMoveStartPosition() const { return m_moveStartPt; }
574 virtual wxPoint2DDouble GetMovePosition() const { return m_movePos; }
575
581 virtual void CalculateBoundaries(wxPoint2DDouble& leftUp, wxPoint2DDouble& rightBottom) const;
582
587 virtual void GeneralMenuItens(wxMenu& menu);
588
595 virtual bool ShowForm(wxWindow* parent, Element* element, wxWindow* workspace = nullptr) { return false; }
603 static bool DoubleFromString(wxWindow* parent, wxString strValue, double& value, wxString errorMsg);
604
612 static bool IntFromString(wxWindow* parent, wxString strValue, int& value, wxString errorMsg);
613
619 static wxString StringFromDouble(double value, int minDecimal = 1, int maxDecimals = 13);
620
627 virtual double PointToLineDistance(wxPoint2DDouble point, int* segmentNumber = nullptr) const;
628
633 bool IsInserted() const { return m_inserted; }
634
639 void SetInserted(bool inserted = true) { m_inserted = inserted; }
640
641 virtual rapidxml::xml_node<>* SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode) { return nullptr; }
642 virtual bool OpenElement(rapidxml::xml_node<>* elementNode) { return true; }
643 void SaveCADProperties(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementNode);
644 bool OpenCADProperties(rapidxml::xml_node<>* elementNode);
645
646protected:
647 ElementType m_elementType = ElementType::TYPE_NONE;
648 int m_elementID = 0;
649 std::vector<Element*> m_parentList;
650 std::vector<Element*> m_childList;
651
652 wxRect2DDouble m_rect;
653 wxPoint2DDouble m_position;
654 double m_width = 0.0;
655 double m_height = 0.0;
656 double m_angle = 0.0;
657 double m_borderSize = 2.0;
658 double m_rotationAngle = 45.0;
659 double m_switchSize = 10.0;
660
661 std::vector<wxRect2DDouble> m_switchRect;
662
663 bool m_selected = false;
664 bool m_dragging = false;
665 bool m_showPickbox = false;
666 bool m_inserted = false;
667
668 int m_activePickboxID = ID_PB_NONE;
669 int m_activeNodeID = 0;
670
671 std::vector<wxPoint2DDouble> m_pointList;
672 std::vector<wxPoint2DDouble> m_movePts;
673
674 wxPoint2DDouble m_moveStartPt;
675 wxPoint2DDouble m_movePos;
676
677 bool m_online = true;
678
679 //OpenGLColour m_selectionColour;
680 //wxColour m_selectionColour;
681};
682
683#endif // ELEMENT_H
ContextMenuID
ID of contex menu itens.
Definition Element.h:76
@ ID_LINE_REMOVE_NODE
Definition Element.h:79
@ ID_DELETE
Definition Element.h:82
@ ID_ROTATE_CLOCK
Definition Element.h:80
@ ID_EDIT_ELEMENT
Definition Element.h:77
@ ID_ROTATE_COUNTERCLOCK
Definition Element.h:81
@ ID_LINE_ADD_NODE
Definition Element.h:78
PickboxID
ID of the pickbox.
Definition Element.h:62
@ ID_PB_NONE
Definition Element.h:63
@ ID_PB_RIGHT_TOP
Definition Element.h:67
@ ID_PB_LEFT_TOP
Definition Element.h:69
@ ID_PB_RIGHT_BOTTOM
Definition Element.h:66
@ ID_PB_LEFT
Definition Element.h:65
@ ID_PB_LEFT_BOTTOM
Definition Element.h:68
@ ID_PB_RIGHT
Definition Element.h:64
Base class of all elements of the program. This class is responsible for manage graphical and his dat...
Definition Element.h:115
virtual bool RotatedRectanglesIntersects(wxRect2DDouble rect1, wxRect2DDouble rect2, double angle1, double angle2) const
Check if two roteted rectangles intersect.
Definition Element.cpp:377
virtual bool Intersects(wxRect2DDouble rect) const =0
Check if the element's rect intersects other rect.
virtual Element * GetCopy()
Get a the element copy.
Definition Element.h:265
virtual std::vector< Element * > GetParentList() const
Get the parent list.
Definition Element.h:567
virtual int GetID() const
Get the element ID.
Definition Element.h:275
double GetWidth() const
Get the element width.
Definition Element.h:209
virtual wxCursor GetBestPickboxCursor() const
Get the best cursor to shown to the user when the mouse is above a pickbox.
Definition Element.h:407
virtual bool GetContextMenu(wxMenu &menu)
Get the element contex menu.
Definition Element.h:327
bool IsDragging() const
Checks if the element is being dragged.
Definition Element.h:194
virtual void GeneralMenuItens(wxMenu &menu)
Insert general itens to context menu.
Definition Element.cpp:475
double GetRotationAngle() const
Get the angle of rotation.
Definition Element.h:219
virtual void ResetPickboxes()
Remove the pickboxes.
Definition Element.h:411
virtual void UpdateNodes()
Update the nodes according to the parents. If a parent is removed, use this method.
Definition Element.h:362
virtual std::vector< wxPoint2DDouble > GetPointList() const
Get the list of points that connect the element to bus.
Definition Element.h:234
static bool IntFromString(wxWindow *parent, wxString strValue, int &value, wxString errorMsg)
Convert a string to int. Show a error message if the conversion fail.
Definition Element.cpp:534
virtual double PointToLineDistance(wxPoint2DDouble point, int *segmentNumber=nullptr) const
Calculate the distance between a line (formed by point list) and a point.
Definition Element.cpp:616
void SetSelected(bool selected=true)
Set element selection.
Definition Element.h:147
wxPoint2DDouble GetPosition() const
Get the element position.
Definition Element.h:189
bool IsOnline() const
Checks if the element is online or offline.
Definition Element.h:229
virtual void CalculateBoundaries(wxPoint2DDouble &leftUp, wxPoint2DDouble &rightBottom) const
Calculate the element boundaries.
Definition Element.cpp:493
virtual void DrawDC(GUIColour *guiColour, wxPoint2DDouble translation, double scale, wxGraphicsContext *gc) const
Draw the element using GDI+.
Definition Element.h:308
virtual std::vector< Element * > GetChildList() const
Get the Child list.
Definition Element.h:572
double GetAngle() const
Get the element angle.
Definition Element.h:214
void SetWidth(double width)
Set element width.
Definition Element.h:152
double GetHeight() const
Get the element height.
Definition Element.h:199
virtual void RemoveChild(Element *child)
Remove a child from the list.
Definition Element.cpp:582
virtual void MovePickbox(wxPoint2DDouble position)
Move the pickbox.
Definition Element.h:402
virtual bool ShowForm(wxWindow *parent, Element *element, wxWindow *workspace=nullptr)
Show element data form.
Definition Element.h:595
virtual bool AddParent(Element *parent, wxPoint2DDouble position, bool isOpening=false)
Add a parent to the element. This method must be used on power elements that connect to a bus,...
Definition Element.h:243
virtual void ReplaceParent(Element *oldParent, Element *newParent)
Replace a parent.
Definition Element.cpp:574
virtual void DrawDCRectangle(wxPoint2DDouble position, double width, double height, double angle, wxDC &dc) const
Draw a circle.
Definition Element.cpp:41
virtual void StartMove(wxPoint2DDouble position)
Update the element attributes related to the movement.
Definition Element.cpp:335
virtual void MoveNode(Element *parent, wxPoint2DDouble position)
Move a node. StartMove(wxPoint2DDouble position) before start moving.
Definition Element.h:352
virtual void DrawDC(GUIColour *guiColour, wxPoint2DDouble translation, double scale, wxDC &dc) const
Draw the element using wxDC.
Definition Element.h:316
void SetHeight(double height)
Set element height.
Definition Element.h:136
virtual void SetPointList(std::vector< wxPoint2DDouble > pointList)
Set the list of points that connect the element to the bus.
Definition Element.h:178
virtual void ResetNodes()
Remove the active nodes.
Definition Element.h:415
void SetPosition(const wxPoint2DDouble position)
Set the element position and update the rectangle.
Definition Element.cpp:33
virtual void DrawDCTriangle(std::vector< wxPoint2DDouble > points, wxGraphicsContext *gc) const
Draw rectangle.
Definition Element.cpp:209
virtual void RemoveParent(Element *parent)
Remove a parent.
Definition Element.h:377
virtual bool NodeContains(wxPoint2DDouble position)
Check if a node contains a point. If contains, set the attributes related to node movement.
Definition Element.h:358
virtual wxPoint2DDouble RotateAtPosition(wxPoint2DDouble pointToRotate, double angle, bool degrees=true) const
Rotate a point as element position being the origin.
Definition Element.cpp:298
virtual void SetID(int id)
Set the element ID.
Definition Element.h:270
virtual void DrawDCPickbox(wxPoint2DDouble position, wxGraphicsContext *gc) const
Draw a point.
Definition Element.cpp:291
virtual void AddPoint(wxPoint2DDouble point)
Add point to the list of points that connect the element to the bus.
Definition Element.h:332
void SetAngle(double angle)
Set element angle.
Definition Element.h:157
virtual wxString GetTipText() const
Get the tip text.
Definition Element.h:299
Element()
Constructor.
Definition Element.cpp:28
wxRect2DDouble GetRect() const
Get the element rectangle.
Definition Element.h:184
virtual ~Element()
Destructor.
Definition Element.h:125
void ShowPickbox(bool showPickbox=true)
Set if the pickbox is shown.
Definition Element.h:162
bool IsPickboxShown() const
Checks if the pickbox is shown.
Definition Element.h:224
virtual void Move(wxPoint2DDouble position)
Move the element other position.
Definition Element.cpp:341
virtual bool Contains(wxPoint2DDouble position) const =0
Checks if the element contains a position.
virtual wxPoint2DDouble WorldToScreen(wxPoint2DDouble translation, double scale, double offsetX=0.0, double offsetY=0.0) const
Convert the element position to screen position.
Definition Element.cpp:354
virtual void AddChild(Element *child)
Add a child to the child list.
Definition Element.cpp:581
bool IsSelected() const
Checks if the element is selected.
Definition Element.h:204
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 po...
Definition Element.h:372
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.
Definition Element.cpp:520
virtual void AddParent(Element *parent)
Add a parent to the element.
Definition Element.h:248
static wxString StringFromDouble(double value, int minDecimal=1, int maxDecimals=13)
Convert a double value to string.
Definition Element.cpp:548
virtual void ReplaceChild(Element *oldChild, Element *newChild)
Replace a child from the list.
Definition Element.cpp:590
void SetDragging(bool dragging=true)
Set if the element are being dragged.
Definition Element.h:131
bool SetOnline(bool online=true)
Set if the element is online or offline.
Definition Element.cpp:465
bool IsInserted() const
Check if the element is properly inserted in the workspace.
Definition Element.h:633
virtual void DrawDCCircle(wxPoint2DDouble position, double radius, int numSegments, wxGraphicsContext *gc) const
Draw a circle using device context.
Definition Element.cpp:173
virtual void RotateNode(Element *parent, bool clockwise=true)
Rotate a node.
Definition Element.h:390
virtual bool PickboxContains(wxPoint2DDouble position)
Check if a pickbox contains a point. If contains the attributes related to pickbox movement will be c...
Definition Element.h:397
virtual void Rotate(bool clockwise=true)
Rotate the element.
Definition Element.h:321
void SetInserted(bool inserted=true)
Set if the element is properly inserted in the workspace.
Definition Element.h:639
void SetBorderSize(double borderSize)
Set the size of the border (shown in selected elements).
Definition Element.h:167