Power System Platform  2026w23a-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};
114{
115public:
119 Element();
120
124 virtual ~Element() {}
125
130 void SetDragging(bool dragging = true) { m_dragging = dragging; }
135 void SetHeight(double height) { m_height = height; }
140 void SetPosition(const wxPoint2DDouble position);
141
146 void SetSelected(bool selected = true) { m_selected = selected; }
151 void SetWidth(double width) { m_width = width; }
156 void SetAngle(double angle) { m_angle = angle; }
161 void ShowPickbox(bool showPickbox = true) { m_showPickbox = showPickbox; }
166 void SetBorderSize(double borderSize) { m_borderSize = borderSize; }
171 bool SetOnline(bool online = true);
172
177 virtual void SetPointList(std::vector<wxPoint2DDouble> pointList) { m_pointList = pointList; }
178 ElementType GetElementType() { return m_elementType; }
183 wxRect2DDouble GetRect() const { return m_rect; }
188 wxPoint2DDouble GetPosition() const { return m_position; }
193 bool IsDragging() const { return m_dragging; }
198 double GetHeight() const { return m_height; }
203 bool IsSelected() const { return m_selected; }
208 double GetWidth() const { return m_width; }
213 double GetAngle() const { return m_angle; }
218 double GetRotationAngle() const { return m_rotationAngle; }
223 bool IsPickboxShown() const { return m_showPickbox; }
228 bool IsOnline() const { return m_online; }
233 virtual std::vector<wxPoint2DDouble> GetPointList() const { return m_pointList; }
241 virtual bool AddParent(Element* parent, wxPoint2DDouble position) { return false; }
246 virtual void AddParent(Element* parent) { m_parentList.push_back(parent); }
251 virtual bool Contains(wxPoint2DDouble position) const = 0;
252
257 virtual bool Intersects(wxRect2DDouble rect) const = 0;
258
263 virtual Element* GetCopy() { return nullptr; }
268 virtual void SetID(int id) { m_elementID = id; }
273 virtual int GetID() const { return m_elementID; }
278 virtual void AddChild(Element* child);
279
284 virtual void RemoveChild(Element* child);
285
291 virtual void ReplaceChild(Element* oldChild, Element* newChild);
292
297 virtual wxString GetTipText() const { return wxEmptyString; }
298
306 virtual void DrawDC(GUIColour* guiColour, wxPoint2DDouble translation, double scale, wxGraphicsContext* gc) const {}
314 virtual void DrawDC(GUIColour* guiColour, wxPoint2DDouble translation, double scale, wxDC& dc) const {}
319 virtual void Rotate(bool clockwise = true) {}
325 virtual bool GetContextMenu(wxMenu& menu) { return false; }
330 virtual void AddPoint(wxPoint2DDouble point) {}
335 virtual void StartMove(wxPoint2DDouble position);
336
342 virtual void Move(wxPoint2DDouble position);
343
349 virtual void MoveNode(Element* parent, wxPoint2DDouble position) {}
355 virtual bool NodeContains(wxPoint2DDouble position) { return false; }
359 virtual void UpdateNodes() {}
360
361 void SetParent(Element* parent, int num) { m_parentList[num] = parent; }
362 void SetChild(Element* child, int num) { m_childList[num] = child; }
369 virtual bool SetNodeParent(Element* parent) { return false; }
374 virtual void RemoveParent(Element* parent) {}
380 virtual void ReplaceParent(Element* oldParent, Element* newParent);
381
387 virtual void RotateNode(Element* parent, bool clockwise = true) {}
394 virtual bool PickboxContains(wxPoint2DDouble position) { return false; }
399 virtual void MovePickbox(wxPoint2DDouble position) {}
404 virtual wxCursor GetBestPickboxCursor() const { return wxCURSOR_ARROW; }
408 virtual void ResetPickboxes() { m_activePickboxID = ID_PB_NONE; }
412 virtual void ResetNodes() { m_activeNodeID = 0; }
420 virtual wxPoint2DDouble WorldToScreen(wxPoint2DDouble translation,
421 double scale,
422 double offsetX = 0.0,
423 double offsetY = 0.0) const;
424
433 virtual wxPoint2DDouble WorldToScreen(wxPoint2DDouble position,
434 wxPoint2DDouble translation,
435 double scale,
436 double offsetX = 0.0,
437 double offsetY = 0.0) const;
438
446 virtual bool RotatedRectanglesIntersects(wxRect2DDouble rect1,
447 wxRect2DDouble rect2,
448 double angle1,
449 double angle2) const;
450
458 //virtual void DrawCircle(wxPoint2DDouble position, double radius, int numSegments, GLenum mode = GL_LINE_LOOP) const;
459
460 virtual void DrawDCRectangle(wxPoint2DDouble position, double width, double height, double angle, wxDC& dc) const;
461
462 virtual void DrawDCRoundedRectRotated(wxDC& dc, const wxPoint2DDouble& center, double width, double height, double radius, double angleDeg, int arcSegments = 8) const;
463
471 virtual void DrawDCCircle(wxPoint2DDouble position, double radius, int numSegments, wxGraphicsContext* gc) const;
472
473 virtual void DrawDCCircle(wxPoint2DDouble position, double radius, wxDC& dc) const;
474
475 //virtual void DrawArc(wxPoint2DDouble position,
476 // double radius,
477 // double initAngle,
478 // double finalAngle,
479 // int numSegments,
480 // GLenum mode = GL_LINE_LOOP) const;
481
482 virtual void DrawDCArc(wxPoint2DDouble position, double radius, double initAngle, double finalAngle, int numSegments, wxGraphicsContext* gc) const;
483
484 virtual void DrawDCArc(wxPoint2DDouble position, double radius, double initAngle, double finalAngle, wxDC& dc) const;
485
493 //virtual void DrawRectangle(wxPoint2DDouble position, double width, double height, GLenum mode = GL_QUADS) const;
494 //virtual void DrawRectangle(wxPoint2DDouble position, double width, double height) const;
495
501 //virtual void DrawRectangle(wxPoint2DDouble* points, GLenum mode = GL_QUADS) const;
502
508 //virtual void DrawTriangle(std::vector<wxPoint2DDouble> points, GLenum mode = GL_TRIANGLES) const;
509
515 virtual void DrawDCTriangle(std::vector<wxPoint2DDouble> points, wxGraphicsContext* gc) const;
516
517 virtual void DrawDCTriangle(std::vector<wxPoint> points, wxDC& dc) const;
518
524 //virtual void DrawPoint(wxPoint2DDouble position, double size) const;
525
531 //virtual void DrawLine(std::vector<wxPoint2DDouble> points, GLenum mode = GL_LINE_STRIP) const;
532
537 //virtual void DrawPickbox(wxPoint2DDouble position) const;
538
544 virtual void DrawDCPickbox(wxPoint2DDouble position, wxGraphicsContext* gc) const;
545
552 virtual wxPoint2DDouble RotateAtPosition(wxPoint2DDouble pointToRotate, double angle, bool degrees = true) const;
553
554 virtual wxPoint2DDouble RotateLocal(wxPoint2DDouble local, double angleDeg) const;
555
556 virtual wxPoint RotateAround(const wxPoint2DDouble& p, const wxPoint2DDouble& center, double angleDeg) const;
557
562 virtual std::vector<Element*> GetParentList() const { return m_parentList; }
567 virtual std::vector<Element*> GetChildList() const { return m_childList; }
568 // virtual wxPoint2DDouble GetMoveStartPosition() const { return m_moveStartPt; }
569 // virtual wxPoint2DDouble GetMovePosition() const { return m_movePos; }
570
576 virtual void CalculateBoundaries(wxPoint2DDouble& leftUp, wxPoint2DDouble& rightBottom) const;
577
582 virtual void GeneralMenuItens(wxMenu& menu);
583
590 virtual bool ShowForm(wxWindow* parent, Element* element, wxWindow* workspace = nullptr) { return false; }
598 static bool DoubleFromString(wxWindow* parent, wxString strValue, double& value, wxString errorMsg);
599
607 static bool IntFromString(wxWindow* parent, wxString strValue, int& value, wxString errorMsg);
608
614 static wxString StringFromDouble(double value, int minDecimal = 1, int maxDecimals = 13);
615
622 virtual double PointToLineDistance(wxPoint2DDouble point, int* segmentNumber = nullptr) const;
623
628 bool IsInserted() const { return m_inserted; }
629
634 void SetInserted(bool inserted = true) { m_inserted = inserted; }
635
636 virtual rapidxml::xml_node<>* SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode) { return nullptr; }
637 virtual bool OpenElement(rapidxml::xml_node<>* elementNode) { return true; }
638 void SaveCADProperties(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementNode);
639 bool OpenCADProperties(rapidxml::xml_node<>* elementNode);
640
641protected:
642 ElementType m_elementType = ElementType::TYPE_NONE;
643 int m_elementID = 0;
644 std::vector<Element*> m_parentList;
645 std::vector<Element*> m_childList;
646
647 wxRect2DDouble m_rect;
648 wxPoint2DDouble m_position;
649 double m_width = 0.0;
650 double m_height = 0.0;
651 double m_angle = 0.0;
652 double m_borderSize = 2.0;
653 double m_rotationAngle = 45.0;
654 double m_switchSize = 10.0;
655
656 std::vector<wxRect2DDouble> m_switchRect;
657
658 bool m_selected = false;
659 bool m_dragging = false;
660 bool m_showPickbox = false;
661 bool m_inserted = false;
662
663 int m_activePickboxID = ID_PB_NONE;
664 int m_activeNodeID = 0;
665
666 std::vector<wxPoint2DDouble> m_pointList;
667 std::vector<wxPoint2DDouble> m_movePts;
668
669 wxPoint2DDouble m_moveStartPt;
670 wxPoint2DDouble m_movePos;
671
672 bool m_online = true;
673
674 //OpenGLColour m_selectionColour;
675 //wxColour m_selectionColour;
676};
677
678#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:114
virtual bool RotatedRectanglesIntersects(wxRect2DDouble rect1, wxRect2DDouble rect2, double angle1, double angle2) const
Check if two roteted rectangles intersect.
Definition Element.cpp:295
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:263
virtual std::vector< Element * > GetParentList() const
Get the parent list.
Definition Element.h:562
virtual int GetID() const
Get the element ID.
Definition Element.h:273
double GetWidth() const
Get the element width.
Definition Element.h:208
virtual wxCursor GetBestPickboxCursor() const
Get the best cursor to shown to the user when the mouse is above a pickbox.
Definition Element.h:404
virtual bool GetContextMenu(wxMenu &menu)
Get the element contex menu.
Definition Element.h:325
bool IsDragging() const
Checks if the element is being dragged.
Definition Element.h:193
virtual void GeneralMenuItens(wxMenu &menu)
Insert general itens to context menu.
Definition Element.cpp:393
double GetRotationAngle() const
Get the angle of rotation.
Definition Element.h:218
virtual void ResetPickboxes()
Remove the pickboxes.
Definition Element.h:408
virtual void UpdateNodes()
Update the nodes according to the parents. If a parent is removed, use this method.
Definition Element.h:359
virtual std::vector< wxPoint2DDouble > GetPointList() const
Get the list of points that connect the element to bus.
Definition Element.h:233
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:452
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:534
void SetSelected(bool selected=true)
Set element selection.
Definition Element.h:146
wxPoint2DDouble GetPosition() const
Get the element position.
Definition Element.h:188
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,...
Definition Element.h:241
bool IsOnline() const
Checks if the element is online or offline.
Definition Element.h:228
virtual void CalculateBoundaries(wxPoint2DDouble &leftUp, wxPoint2DDouble &rightBottom) const
Calculate the element boundaries.
Definition Element.cpp:411
virtual void DrawDC(GUIColour *guiColour, wxPoint2DDouble translation, double scale, wxGraphicsContext *gc) const
Draw the element using GDI+.
Definition Element.h:306
virtual std::vector< Element * > GetChildList() const
Get the Child list.
Definition Element.h:567
double GetAngle() const
Get the element angle.
Definition Element.h:213
void SetWidth(double width)
Set element width.
Definition Element.h:151
double GetHeight() const
Get the element height.
Definition Element.h:198
virtual void RemoveChild(Element *child)
Remove a child from the list.
Definition Element.cpp:500
virtual void MovePickbox(wxPoint2DDouble position)
Move the pickbox.
Definition Element.h:399
virtual bool ShowForm(wxWindow *parent, Element *element, wxWindow *workspace=nullptr)
Show element data form.
Definition Element.h:590
virtual void ReplaceParent(Element *oldParent, Element *newParent)
Replace a parent.
Definition Element.cpp:492
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:265
virtual void MoveNode(Element *parent, wxPoint2DDouble position)
Move a node. StartMove(wxPoint2DDouble position) before start moving.
Definition Element.h:349
virtual void DrawDC(GUIColour *guiColour, wxPoint2DDouble translation, double scale, wxDC &dc) const
Draw the element using wxDC.
Definition Element.h:314
void SetHeight(double height)
Set element height.
Definition Element.h:135
virtual void SetPointList(std::vector< wxPoint2DDouble > pointList)
Set the list of points that connect the element to the bus.
Definition Element.h:177
virtual void ResetNodes()
Remove the active nodes.
Definition Element.h:412
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:374
virtual bool NodeContains(wxPoint2DDouble position)
Check if a node contains a point. If contains, set the attributes related to node movement.
Definition Element.h:355
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 SetID(int id)
Set the element ID.
Definition Element.h:268
virtual void DrawDCPickbox(wxPoint2DDouble position, wxGraphicsContext *gc) const
Draw a point.
Definition Element.cpp:221
virtual void AddPoint(wxPoint2DDouble point)
Add point to the list of points that connect the element to the bus.
Definition Element.h:330
void SetAngle(double angle)
Set element angle.
Definition Element.h:156
virtual wxString GetTipText() const
Get the tip text.
Definition Element.h:297
Element()
Constructor.
Definition Element.cpp:28
wxRect2DDouble GetRect() const
Get the element rectangle.
Definition Element.h:183
virtual ~Element()
Destructor.
Definition Element.h:124
void ShowPickbox(bool showPickbox=true)
Set if the pickbox is shown.
Definition Element.h:161
bool IsPickboxShown() const
Checks if the pickbox is shown.
Definition Element.h:223
virtual void Move(wxPoint2DDouble position)
Move the element other position.
Definition Element.cpp:271
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:272
virtual void AddChild(Element *child)
Add a child to the child list.
Definition Element.cpp:499
bool IsSelected() const
Checks if the element is selected.
Definition Element.h:203
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:369
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:438
virtual void AddParent(Element *parent)
Add a parent to the element.
Definition Element.h:246
static wxString StringFromDouble(double value, int minDecimal=1, int maxDecimals=13)
Convert a double value to string.
Definition Element.cpp:466
virtual void ReplaceChild(Element *oldChild, Element *newChild)
Replace a child from the list.
Definition Element.cpp:508
void SetDragging(bool dragging=true)
Set if the element are being dragged.
Definition Element.h:130
bool SetOnline(bool online=true)
Set if the element is online or offline.
Definition Element.cpp:383
bool IsInserted() const
Check if the element is properly inserted in the workspace.
Definition Element.h:628
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:387
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:394
virtual void Rotate(bool clockwise=true)
Rotate the element.
Definition Element.h:319
void SetInserted(bool inserted=true)
Set if the element is properly inserted in the workspace.
Definition Element.h:634
void SetBorderSize(double borderSize)
Set the size of the border (shown in selected elements).
Definition Element.h:166