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"
92 ID_TXT_REACTIVE_POWER,
93 ID_TXT_BRANCH_ACTIVE_POWER_1_2,
94 ID_TXT_BRANCH_ACTIVE_POWER_2_1,
95 ID_TXT_BRANCH_REACTIVE_POWER_1_2,
96 ID_TXT_BRANCH_REACTIVE_POWER_2_1,
98 ID_TXT_BRANCH_CURRENT_1_2,
99 ID_TXT_BRANCH_CURRENT_2_1,
100 ID_TXT_BRANCH_FAULT_CURRENT_1_2,
101 ID_TXT_BRANCH_FAULT_CURRENT_2_1
159 void ShowPickbox(
bool showPickbox =
true) { m_showPickbox = showPickbox; }
175 virtual void SetPointList(std::vector<wxPoint2DDouble> pointList) { m_pointList = pointList; }
176 ElementType GetElementType() {
return m_elementType; }
181 wxRect2DDouble
GetRect()
const {
return m_rect; }
231 virtual std::vector<wxPoint2DDouble>
GetPointList()
const {
return m_pointList; }
249 virtual bool Contains(wxPoint2DDouble position)
const = 0;
266 virtual void SetID(
int id) { m_elementID = id; }
271 virtual int GetID()
const {
return m_elementID; }
295 virtual wxString
GetTipText()
const {
return wxEmptyString; }
304 virtual void DrawDC(wxPoint2DDouble translation,
double scale, wxGraphicsContext* gc)
const {}
311 virtual void DrawDC(wxPoint2DDouble translation,
double scale, wxDC& dc)
const {}
316 virtual void Rotate(
bool clockwise =
true) {}
332 virtual void StartMove(wxPoint2DDouble position);
339 virtual void Move(wxPoint2DDouble position);
358 void SetParent(
Element* parent,
int num) { m_parentList[num] = parent; }
359 void SetChild(
Element* child,
int num) { m_childList[num] = child; }
417 virtual wxPoint2DDouble
WorldToScreen(wxPoint2DDouble translation,
419 double offsetX = 0.0,
420 double offsetY = 0.0)
const;
430 virtual wxPoint2DDouble
WorldToScreen(wxPoint2DDouble position,
431 wxPoint2DDouble translation,
433 double offsetX = 0.0,
434 double offsetY = 0.0)
const;
444 wxRect2DDouble rect2,
446 double angle2)
const;
457 virtual void DrawDCRectangle(wxPoint2DDouble position,
double width,
double height,
double angle, wxDC& dc)
const;
459 virtual void DrawDCRoundedRectRotated(wxDC& dc,
const wxPoint2DDouble& center,
double width,
double height,
double radius,
double angleDeg,
int arcSegments = 8)
const;
468 virtual void DrawDCCircle(wxPoint2DDouble position,
double radius,
int numSegments, wxGraphicsContext* gc)
const;
470 virtual void DrawDCCircle(wxPoint2DDouble position,
double radius, wxDC& dc)
const;
479 virtual void DrawDCArc(wxPoint2DDouble position,
double radius,
double initAngle,
double finalAngle,
int numSegments, wxGraphicsContext* gc)
const;
481 virtual void DrawDCArc(wxPoint2DDouble position,
double radius,
double initAngle,
double finalAngle, wxDC& dc)
const;
512 virtual void DrawDCTriangle(std::vector<wxPoint2DDouble> points, wxGraphicsContext* gc)
const;
514 virtual void DrawDCTriangle(std::vector<wxPoint> points, wxDC& dc)
const;
541 virtual void DrawDCPickbox(wxPoint2DDouble position, wxGraphicsContext* gc)
const;
549 virtual wxPoint2DDouble
RotateAtPosition(wxPoint2DDouble pointToRotate,
double angle,
bool degrees =
true)
const;
551 virtual wxPoint2DDouble RotateLocal(wxPoint2DDouble local,
double angleDeg)
const;
553 virtual wxPoint RotateAround(
const wxPoint2DDouble& p,
const wxPoint2DDouble& center,
double angleDeg)
const;
559 virtual std::vector<Element*>
GetParentList()
const {
return m_parentList; }
564 virtual std::vector<Element*>
GetChildList()
const {
return m_childList; }
573 virtual void CalculateBoundaries(wxPoint2DDouble& leftUp, wxPoint2DDouble& rightBottom)
const;
595 static bool DoubleFromString(wxWindow* parent, wxString strValue,
double& value, wxString errorMsg);
604 static bool IntFromString(wxWindow* parent, wxString strValue,
int& value, wxString errorMsg);
611 static wxString
StringFromDouble(
double value,
int minDecimal = 1,
int maxDecimals = 13);
619 virtual double PointToLineDistance(wxPoint2DDouble point,
int* segmentNumber =
nullptr)
const;
633 virtual rapidxml::xml_node<>* SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode) {
return nullptr; }
634 virtual bool OpenElement(rapidxml::xml_node<>* elementNode) {
return true; }
635 void SaveCADProperties(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementNode);
636 bool OpenCADProperties(rapidxml::xml_node<>* elementNode);
639 ElementType m_elementType = ElementType::TYPE_NONE;
641 std::vector<Element*> m_parentList;
642 std::vector<Element*> m_childList;
644 wxRect2DDouble m_rect;
645 wxPoint2DDouble m_position;
646 double m_width = 0.0;
647 double m_height = 0.0;
648 double m_angle = 0.0;
649 double m_borderSize = 2.0;
650 double m_rotationAngle = 45.0;
651 double m_switchSize = 10.0;
653 std::vector<wxRect2DDouble> m_switchRect;
655 bool m_selected =
false;
656 bool m_dragging =
false;
657 bool m_showPickbox =
false;
658 bool m_inserted =
false;
661 int m_activeNodeID = 0;
663 std::vector<wxPoint2DDouble> m_pointList;
664 std::vector<wxPoint2DDouble> m_movePts;
666 wxPoint2DDouble m_moveStartPt;
667 wxPoint2DDouble m_movePos;
669 bool m_online =
true;
672 wxColour m_selectionColour;
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 DrawDC(wxPoint2DDouble translation, double scale, wxDC &dc) const
Draw the element using wxDC.
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 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 DrawDC(wxPoint2DDouble translation, double scale, wxGraphicsContext *gc) const
Draw the element using GDI+.
virtual void MovePickbox(wxPoint2DDouble position)
Move the pickbox.
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.
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.
virtual bool ShowForm(wxWindow *parent, Element *element)
Show element data form.
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).