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
161 void ShowPickbox(
bool showPickbox =
true) { m_showPickbox = showPickbox; }
177 virtual void SetPointList(std::vector<wxPoint2DDouble> pointList) { m_pointList = pointList; }
178 ElementType GetElementType() {
return m_elementType; }
183 wxRect2DDouble
GetRect()
const {
return m_rect; }
233 virtual std::vector<wxPoint2DDouble>
GetPointList()
const {
return m_pointList; }
251 virtual bool Contains(wxPoint2DDouble position)
const = 0;
268 virtual void SetID(
int id) { m_elementID = id; }
273 virtual int GetID()
const {
return m_elementID; }
297 virtual wxString
GetTipText()
const {
return wxEmptyString; }
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) {}
335 virtual void StartMove(wxPoint2DDouble position);
342 virtual void Move(wxPoint2DDouble position);
361 void SetParent(
Element* parent,
int num) { m_parentList[num] = parent; }
362 void SetChild(
Element* child,
int num) { m_childList[num] = child; }
420 virtual wxPoint2DDouble
WorldToScreen(wxPoint2DDouble translation,
422 double offsetX = 0.0,
423 double offsetY = 0.0)
const;
433 virtual wxPoint2DDouble
WorldToScreen(wxPoint2DDouble position,
434 wxPoint2DDouble translation,
436 double offsetX = 0.0,
437 double offsetY = 0.0)
const;
447 wxRect2DDouble rect2,
449 double angle2)
const;
460 virtual void DrawDCRectangle(wxPoint2DDouble position,
double width,
double height,
double angle, wxDC& dc)
const;
462 virtual void DrawDCRoundedRectRotated(wxDC& dc,
const wxPoint2DDouble& center,
double width,
double height,
double radius,
double angleDeg,
int arcSegments = 8)
const;
471 virtual void DrawDCCircle(wxPoint2DDouble position,
double radius,
int numSegments, wxGraphicsContext* gc)
const;
473 virtual void DrawDCCircle(wxPoint2DDouble position,
double radius, wxDC& dc)
const;
482 virtual void DrawDCArc(wxPoint2DDouble position,
double radius,
double initAngle,
double finalAngle,
int numSegments, wxGraphicsContext* gc)
const;
484 virtual void DrawDCArc(wxPoint2DDouble position,
double radius,
double initAngle,
double finalAngle, wxDC& dc)
const;
515 virtual void DrawDCTriangle(std::vector<wxPoint2DDouble> points, wxGraphicsContext* gc)
const;
517 virtual void DrawDCTriangle(std::vector<wxPoint> points, wxDC& dc)
const;
544 virtual void DrawDCPickbox(wxPoint2DDouble position, wxGraphicsContext* gc)
const;
552 virtual wxPoint2DDouble
RotateAtPosition(wxPoint2DDouble pointToRotate,
double angle,
bool degrees =
true)
const;
554 virtual wxPoint2DDouble RotateLocal(wxPoint2DDouble local,
double angleDeg)
const;
556 virtual wxPoint RotateAround(
const wxPoint2DDouble& p,
const wxPoint2DDouble& center,
double angleDeg)
const;
562 virtual std::vector<Element*>
GetParentList()
const {
return m_parentList; }
567 virtual std::vector<Element*>
GetChildList()
const {
return m_childList; }
576 virtual void CalculateBoundaries(wxPoint2DDouble& leftUp, wxPoint2DDouble& rightBottom)
const;
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);
607 static bool IntFromString(wxWindow* parent, wxString strValue,
int& value, wxString errorMsg);
614 static wxString
StringFromDouble(
double value,
int minDecimal = 1,
int maxDecimals = 13);
622 virtual double PointToLineDistance(wxPoint2DDouble point,
int* segmentNumber =
nullptr)
const;
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);
642 ElementType m_elementType = ElementType::TYPE_NONE;
644 std::vector<Element*> m_parentList;
645 std::vector<Element*> m_childList;
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;
656 std::vector<wxRect2DDouble> m_switchRect;
658 bool m_selected =
false;
659 bool m_dragging =
false;
660 bool m_showPickbox =
false;
661 bool m_inserted =
false;
664 int m_activeNodeID = 0;
666 std::vector<wxPoint2DDouble> m_pointList;
667 std::vector<wxPoint2DDouble> m_movePts;
669 wxPoint2DDouble m_moveStartPt;
670 wxPoint2DDouble m_movePos;
672 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.
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,...
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 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).