22#include <wx/geometry.h>
25#include <wx/stdpaths.h>
26#include <wx/filename.h>
32#include <wx/graphics.h>
37#include "../utils/XMLParser.h"
39#include "../utils/CommomTypes.h"
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,
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,
162 void ShowPickbox(
bool showPickbox =
true) { m_showPickbox = showPickbox; }
178 virtual void SetPointList(std::vector<wxPoint2DDouble> pointList) { m_pointList = pointList; }
179 ElementType GetElementType() {
return m_elementType; }
184 wxRect2DDouble
GetRect()
const {
return m_rect; }
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; }
253 virtual bool Contains(wxPoint2DDouble position)
const = 0;
270 virtual void SetID(
int id) { m_elementID = id; }
275 virtual int GetID()
const {
return m_elementID; }
299 virtual wxString
GetTipText()
const {
return wxEmptyString; }
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) {}
337 virtual void StartMove(wxPoint2DDouble position);
344 virtual void Move(wxPoint2DDouble position);
345 virtual void AlignToGrid(
double gridSize = 20.0);
364 void SetParent(
Element* parent,
int num) { m_parentList[num] = parent; }
365 void SetChild(
Element* child,
int num) { m_childList[num] = child; }
423 virtual wxPoint2DDouble
WorldToScreen(wxPoint2DDouble translation,
425 double offsetX = 0.0,
426 double offsetY = 0.0)
const;
436 virtual wxPoint2DDouble
WorldToScreen(wxPoint2DDouble position,
437 wxPoint2DDouble translation,
439 double offsetX = 0.0,
440 double offsetY = 0.0)
const;
450 wxRect2DDouble rect2,
452 double angle2)
const;
463 virtual void DrawDCRectangle(wxPoint2DDouble position,
double width,
double height,
double angle, wxDC& dc)
const;
465 virtual void DrawDCRoundedRectRotated(wxDC& dc,
const wxPoint2DDouble& center,
double width,
double height,
double radius,
double angleDeg,
int arcSegments = 8)
const;
474 virtual void DrawDCCircle(wxPoint2DDouble position,
double radius,
int numSegments, wxGraphicsContext* gc)
const;
476 virtual void DrawDCCircle(wxPoint2DDouble position,
double radius, wxDC& dc)
const;
485 virtual void DrawDCArc(wxPoint2DDouble position,
double radius,
double initAngle,
double finalAngle,
int numSegments, wxGraphicsContext* gc)
const;
487 virtual void DrawDCArc(wxPoint2DDouble position,
double radius,
double initAngle,
double finalAngle, wxDC& dc)
const;
518 virtual void DrawDCTriangle(std::vector<wxPoint2DDouble> points, wxGraphicsContext* gc)
const;
520 virtual void DrawDCTriangle(std::vector<wxPoint> points, wxDC& dc)
const;
522 virtual void DrawStabilityEventGC(wxGraphicsContext* gc, wxPoint2DDouble translation,
double scale,
GUIColour* guiColour,
bool rotateAnchor =
false, wxPoint2DDouble iconPosition = wxPoint2DDouble(-1, -1))
const;
549 virtual void DrawDCPickbox(wxPoint2DDouble position, wxGraphicsContext* gc)
const;
557 virtual wxPoint2DDouble
RotateAtPosition(wxPoint2DDouble pointToRotate,
double angle,
bool degrees =
true)
const;
559 virtual wxPoint2DDouble RotateLocal(wxPoint2DDouble local,
double angleDeg)
const;
561 virtual wxPoint RotateAround(
const wxPoint2DDouble& p,
const wxPoint2DDouble& center,
double angleDeg)
const;
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; }
581 virtual void CalculateBoundaries(wxPoint2DDouble& leftUp, wxPoint2DDouble& rightBottom)
const;
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);
612 static bool IntFromString(wxWindow* parent, wxString strValue,
int& value, wxString errorMsg);
619 static wxString
StringFromDouble(
double value,
int minDecimal = 1,
int maxDecimals = 13);
627 virtual double PointToLineDistance(wxPoint2DDouble point,
int* segmentNumber =
nullptr)
const;
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);
647 ElementType m_elementType = ElementType::TYPE_NONE;
649 std::vector<Element*> m_parentList;
650 std::vector<Element*> m_childList;
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;
661 std::vector<wxRect2DDouble> m_switchRect;
663 bool m_selected =
false;
664 bool m_dragging =
false;
665 bool m_showPickbox =
false;
666 bool m_inserted =
false;
669 int m_activeNodeID = 0;
671 std::vector<wxPoint2DDouble> m_pointList;
672 std::vector<wxPoint2DDouble> m_movePts;
674 wxPoint2DDouble m_moveStartPt;
675 wxPoint2DDouble m_movePos;
677 bool m_online =
true;
ContextMenuID
ID of contex menu itens.
PickboxID
ID of the pickbox.
Base class of all elements of the program. This class is responsible for manage graphical and his dat...
virtual bool RotatedRectanglesIntersects(wxRect2DDouble rect1, wxRect2DDouble rect2, double angle1, double angle2) const
Check if two roteted rectangles intersect.
virtual bool Intersects(wxRect2DDouble rect) const =0
Check if the element's rect intersects other rect.
virtual Element * GetCopy()
Get a the element copy.
virtual std::vector< Element * > GetParentList() const
Get the parent list.
virtual int GetID() const
Get the element ID.
double GetWidth() const
Get the element width.
virtual wxCursor GetBestPickboxCursor() const
Get the best cursor to shown to the user when the mouse is above a pickbox.
virtual bool GetContextMenu(wxMenu &menu)
Get the element contex menu.
bool IsDragging() const
Checks if the element is being dragged.
virtual void GeneralMenuItens(wxMenu &menu)
Insert general itens to context menu.
double GetRotationAngle() const
Get the angle of rotation.
virtual void ResetPickboxes()
Remove the pickboxes.
virtual void UpdateNodes()
Update the nodes according to the parents. If a parent is removed, use this method.
virtual std::vector< wxPoint2DDouble > GetPointList() const
Get the list of points that connect the element to bus.
static bool IntFromString(wxWindow *parent, wxString strValue, int &value, wxString errorMsg)
Convert a string to int. Show a error message if the conversion fail.
virtual double PointToLineDistance(wxPoint2DDouble point, int *segmentNumber=nullptr) const
Calculate the distance between a line (formed by point list) and a point.
void SetSelected(bool selected=true)
Set element selection.
wxPoint2DDouble GetPosition() const
Get the element position.
bool IsOnline() const
Checks if the element is online or offline.
virtual void CalculateBoundaries(wxPoint2DDouble &leftUp, wxPoint2DDouble &rightBottom) const
Calculate the element boundaries.
virtual void DrawDC(GUIColour *guiColour, wxPoint2DDouble translation, double scale, wxGraphicsContext *gc) const
Draw the element using GDI+.
virtual std::vector< Element * > GetChildList() const
Get the Child list.
double GetAngle() const
Get the element angle.
void SetWidth(double width)
Set element width.
double GetHeight() const
Get the element height.
virtual void RemoveChild(Element *child)
Remove a child from the list.
virtual void MovePickbox(wxPoint2DDouble position)
Move the pickbox.
virtual bool ShowForm(wxWindow *parent, Element *element, wxWindow *workspace=nullptr)
Show element data form.
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,...
virtual void ReplaceParent(Element *oldParent, Element *newParent)
Replace a parent.
virtual void DrawDCRectangle(wxPoint2DDouble position, double width, double height, double angle, wxDC &dc) const
Draw a circle.
virtual void StartMove(wxPoint2DDouble position)
Update the element attributes related to the movement.
virtual void MoveNode(Element *parent, wxPoint2DDouble position)
Move a node. StartMove(wxPoint2DDouble position) before start moving.
virtual void DrawDC(GUIColour *guiColour, wxPoint2DDouble translation, double scale, wxDC &dc) const
Draw the element using wxDC.
void SetHeight(double height)
Set element height.
virtual void SetPointList(std::vector< wxPoint2DDouble > pointList)
Set the list of points that connect the element to the bus.
virtual void ResetNodes()
Remove the active nodes.
void SetPosition(const wxPoint2DDouble position)
Set the element position and update the rectangle.
virtual void DrawDCTriangle(std::vector< wxPoint2DDouble > points, wxGraphicsContext *gc) const
Draw rectangle.
virtual void RemoveParent(Element *parent)
Remove a parent.
virtual bool NodeContains(wxPoint2DDouble position)
Check if a node contains a point. If contains, set the attributes related to node movement.
virtual wxPoint2DDouble RotateAtPosition(wxPoint2DDouble pointToRotate, double angle, bool degrees=true) const
Rotate a point as element position being the origin.
virtual void SetID(int id)
Set the element ID.
virtual void DrawDCPickbox(wxPoint2DDouble position, wxGraphicsContext *gc) const
Draw a point.
virtual void AddPoint(wxPoint2DDouble point)
Add point to the list of points that connect the element to the bus.
void SetAngle(double angle)
Set element angle.
virtual wxString GetTipText() const
Get the tip text.
wxRect2DDouble GetRect() const
Get the element rectangle.
virtual ~Element()
Destructor.
void ShowPickbox(bool showPickbox=true)
Set if the pickbox is shown.
bool IsPickboxShown() const
Checks if the pickbox is shown.
virtual void Move(wxPoint2DDouble position)
Move the element other position.
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.
virtual void AddChild(Element *child)
Add a child to the child list.
bool IsSelected() const
Checks if the element is selected.
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...
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.
virtual void AddParent(Element *parent)
Add a parent to the element.
static wxString StringFromDouble(double value, int minDecimal=1, int maxDecimals=13)
Convert a double value to string.
virtual void ReplaceChild(Element *oldChild, Element *newChild)
Replace a child from the list.
void SetDragging(bool dragging=true)
Set if the element are being dragged.
bool SetOnline(bool online=true)
Set if the element is online or offline.
bool IsInserted() const
Check if the element is properly inserted in the workspace.
virtual void DrawDCCircle(wxPoint2DDouble position, double radius, int numSegments, wxGraphicsContext *gc) const
Draw a circle using device context.
virtual void RotateNode(Element *parent, bool clockwise=true)
Rotate a node.
virtual bool PickboxContains(wxPoint2DDouble position)
Check if a pickbox contains a point. If contains the attributes related to pickbox movement will be c...
virtual void Rotate(bool clockwise=true)
Rotate the element.
void SetInserted(bool inserted=true)
Set if the element is properly inserted in the workspace.
void SetBorderSize(double borderSize)
Set the size of the border (shown in selected elements).