Power System Platform  2026w10a-beta
Loading...
Searching...
No Matches
ControlElement Class Reference

#include <ControlElement.h>

Inheritance diagram for ControlElement:
Collaboration diagram for ControlElement:

Public Member Functions

 ControlElement (int id)
 
virtual void StartMove (wxPoint2DDouble position)
 Update the element attributes related to the movement.
 
virtual void Move (wxPoint2DDouble position)
 Move the element other position.
 
void SetNodeList (std::vector< Node * > nodeList)
 
std::vector< Node * > GetNodeList () const
 
virtual void DrawDCNodes (wxGraphicsContext *gc) const
 
virtual void ReplaceNode (Node *oldNode, Node *newNode)
 
virtual bool UpdateText ()
 Update the OpenGL text in the element (if present).
 
virtual bool IsSolved () const
 
virtual void SetSolved (bool solved=true)
 
virtual bool Solve (double *input, double timeStep)
 
virtual bool Initialize ()
 
virtual double GetOutput () const
 
virtual void SetOutput (double output)
 
- Public Member Functions inherited from Element
 Element ()
 Constructor.
 
virtual ~Element ()
 Destructor.
 
void SetDragging (bool dragging=true)
 Set if the element are being dragged.
 
void SetHeight (double height)
 Set element height.
 
void SetPosition (const wxPoint2DDouble position)
 Set the element position and update the rectangle.
 
void SetSelected (bool selected=true)
 Set element selection.
 
void SetWidth (double width)
 Set element width.
 
void SetAngle (double angle)
 Set element angle.
 
void ShowPickbox (bool showPickbox=true)
 Set if the pickbox is shown.
 
void SetBorderSize (double borderSize)
 Set the size of the border (shown in selected elements).
 
bool SetOnline (bool online=true)
 Set if the element is online or offline.
 
virtual void SetPointList (std::vector< wxPoint2DDouble > pointList)
 Set the list of points that connect the element to the bus.
 
ElementType GetElementType ()
 
wxRect2DDouble GetRect () const
 Get the element rectangle.
 
wxPoint2DDouble GetPosition () const
 Get the element position.
 
bool IsDragging () const
 Checks if the element is being dragged.
 
double GetHeight () const
 Get the element height.
 
bool IsSelected () const
 Checks if the element is selected.
 
double GetWidth () const
 Get the element width.
 
double GetAngle () const
 Get the element angle.
 
double GetRotationAngle () const
 Get the angle of rotation.
 
bool IsPickboxShown () const
 Checks if the pickbox is shown.
 
bool IsOnline () const
 Checks if the element is online or offline.
 
virtual std::vector< wxPoint2DDouble > GetPointList () const
 Get the list of points that connect the element to bus.
 
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, so the parent must be a bus. The element basic points are calculated in this method, so apply this when the element is being inserted.
 
virtual void AddParent (Element *parent)
 Add a parent to the element.
 
virtual bool Contains (wxPoint2DDouble position) const =0
 Checks if the element contains a position.
 
virtual bool Intersects (wxRect2DDouble rect) const =0
 Check if the element's rect intersects other rect.
 
virtual ElementGetCopy ()
 Get a the element copy.
 
virtual void SetID (int id)
 Set the element ID.
 
virtual int GetID () const
 Get the element ID.
 
virtual void AddChild (Element *child)
 Add a child to the child list.
 
virtual void RemoveChild (Element *child)
 Remove a child from the list.
 
virtual void ReplaceChild (Element *oldChild, Element *newChild)
 Replace a child from the list.
 
virtual wxString GetTipText () const
 Get the tip text.
 
virtual void DrawDC (wxPoint2DDouble translation, double scale, wxGraphicsContext *gc) const
 Draw the element using GDI+.
 
virtual void DrawDC (wxPoint2DDouble translation, double scale, wxDC &dc) const
 Draw the element using wxDC.
 
virtual void Rotate (bool clockwise=true)
 Rotate the element.
 
virtual bool GetContextMenu (wxMenu &menu)
 Get the element contex menu.
 
virtual void AddPoint (wxPoint2DDouble point)
 Add point to the list of points that connect the element to the bus.
 
virtual void MoveNode (Element *parent, wxPoint2DDouble position)
 Move a node. StartMove(wxPoint2DDouble position) before start moving.
 
virtual bool NodeContains (wxPoint2DDouble position)
 Check if a node contains a point. If contains, set the attributes related to node movement.
 
virtual void UpdateNodes ()
 Update the nodes according to the parents. If a parent is removed, use this method.
 
void SetParent (Element *parent, int num)
 
void SetChild (Element *child, int num)
 
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 points related to the nodes will be calculated.
 
virtual void RemoveParent (Element *parent)
 Remove a parent.
 
virtual void ReplaceParent (Element *oldParent, Element *newParent)
 Replace a parent.
 
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 calculated.
 
virtual void MovePickbox (wxPoint2DDouble position)
 Move the pickbox.
 
virtual wxCursor GetBestPickboxCursor () const
 Get the best cursor to shown to the user when the mouse is above a pickbox.
 
virtual void ResetPickboxes ()
 Remove the pickboxes.
 
virtual void ResetNodes ()
 Remove the active nodes.
 
virtual wxPoint2DDouble WorldToScreen (wxPoint2DDouble translation, double scale, double offsetX=0.0, double offsetY=0.0) const
 Convert the element position to screen position.
 
virtual wxPoint2DDouble WorldToScreen (wxPoint2DDouble position, wxPoint2DDouble translation, double scale, double offsetX=0.0, double offsetY=0.0) const
 Convert a generic position to screen position.
 
virtual bool RotatedRectanglesIntersects (wxRect2DDouble rect1, wxRect2DDouble rect2, double angle1, double angle2) const
 Check if two roteted rectangles intersect.
 
virtual void DrawDCRectangle (wxPoint2DDouble position, double width, double height, double angle, wxDC &dc) const
 Draw a circle.
 
virtual void DrawDCRoundedRectRotated (wxDC &dc, const wxPoint2DDouble &center, double width, double height, double radius, double angleDeg, int arcSegments=8) const
 
virtual void DrawDCCircle (wxPoint2DDouble position, double radius, int numSegments, wxGraphicsContext *gc) const
 Draw a circle using device context.
 
virtual void DrawDCCircle (wxPoint2DDouble position, double radius, wxDC &dc) const
 
virtual void DrawDCArc (wxPoint2DDouble position, double radius, double initAngle, double finalAngle, int numSegments, wxGraphicsContext *gc) const
 
virtual void DrawDCArc (wxPoint2DDouble position, double radius, double initAngle, double finalAngle, wxDC &dc) const
 
virtual void DrawDCTriangle (std::vector< wxPoint2DDouble > points, wxGraphicsContext *gc) const
 Draw rectangle.
 
virtual void DrawDCTriangle (std::vector< wxPoint > points, wxDC &dc) const
 
virtual void DrawDCPickbox (wxPoint2DDouble position, wxGraphicsContext *gc) const
 Draw a point.
 
virtual wxPoint2DDouble RotateAtPosition (wxPoint2DDouble pointToRotate, double angle, bool degrees=true) const
 Rotate a point as element position being the origin.
 
virtual wxPoint2DDouble RotateLocal (wxPoint2DDouble local, double angleDeg) const
 
virtual wxPoint RotateAround (const wxPoint2DDouble &p, const wxPoint2DDouble &center, double angleDeg) const
 
virtual std::vector< Element * > GetParentList () const
 Get the parent list.
 
virtual std::vector< Element * > GetChildList () const
 Get the Child list.
 
virtual void CalculateBoundaries (wxPoint2DDouble &leftUp, wxPoint2DDouble &rightBottom) const
 Calculate the element boundaries.
 
virtual void GeneralMenuItens (wxMenu &menu)
 Insert general itens to context menu.
 
virtual bool ShowForm (wxWindow *parent, Element *element)
 Show element data form.
 
virtual double PointToLineDistance (wxPoint2DDouble point, int *segmentNumber=nullptr) const
 Calculate the distance between a line (formed by point list) and a point.
 
bool IsInserted () const
 Check if the element is properly inserted in the workspace.
 
void SetInserted (bool inserted=true)
 Set if the element is properly inserted in the workspace.
 
virtual rapidxml::xml_node * SaveElement (rapidxml::xml_document<> &doc, rapidxml::xml_node<> *elementListNode)
 
virtual bool OpenElement (rapidxml::xml_node<> *elementNode)
 
void SaveCADProperties (rapidxml::xml_document<> &doc, rapidxml::xml_node<> *elementNode)
 
bool OpenCADProperties (rapidxml::xml_node<> *elementNode)
 

Static Public Member Functions

static ControlElementGetControlElementFromID (std::vector< std::shared_ptr< ControlElement > > elementList, int id)
 
- Static Public Member Functions inherited from Element
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.
 
static bool IntFromString (wxWindow *parent, wxString strValue, int &value, wxString errorMsg)
 Convert a string to int. Show a error message if the conversion fail.
 
static wxString StringFromDouble (double value, int minDecimal=1, int maxDecimals=13)
 Convert a double value to string.
 

Protected Member Functions

void SaveControlNodes (rapidxml::xml_document<> &doc, rapidxml::xml_node<> *elementNode)
 
bool OpenControlNodes (rapidxml::xml_node<> *elementNode)
 

Protected Attributes

std::vector< Node * > m_nodeList
 
bool m_solved = false
 
double m_output = 0.0
 
- Protected Attributes inherited from Element
ElementType m_elementType = ElementType::TYPE_NONE
 
int m_elementID = 0
 
std::vector< Element * > m_parentList
 
std::vector< Element * > m_childList
 
wxRect2DDouble m_rect
 
wxPoint2DDouble m_position
 
double m_width = 0.0
 
double m_height = 0.0
 
double m_angle = 0.0
 
double m_borderSize = 2.0
 
double m_rotationAngle = 45.0
 
double m_switchSize = 10.0
 
std::vector< wxRect2DDouble > m_switchRect
 
bool m_selected = false
 
bool m_dragging = false
 
bool m_showPickbox = false
 
bool m_inserted = false
 
int m_activePickboxID = ID_PB_NONE
 
int m_activeNodeID = 0
 
std::vector< wxPoint2DDouble > m_pointList
 
std::vector< wxPoint2DDouble > m_movePts
 
wxPoint2DDouble m_moveStartPt
 
wxPoint2DDouble m_movePos
 
bool m_online = true
 
wxColour m_selectionColour
 

Detailed Description

Author
Thales Lima Oliveira thale.nosp@m.s@uf.nosp@m.u.br
Date
05/10/2017

Definition at line 86 of file ControlElement.h.

Constructor & Destructor Documentation

◆ ControlElement()

ControlElement::ControlElement ( int  id)

Definition at line 111 of file ControlElement.cpp.

111: Element() { m_elementID = id; }
Element()
Constructor.
Definition Element.cpp:26

◆ ~ControlElement()

ControlElement::~ControlElement ( )
virtual

Definition at line 113 of file ControlElement.cpp.

114{
115}

Member Function Documentation

◆ DrawDCNodes()

void ControlElement::DrawDCNodes ( wxGraphicsContext *  gc) const
virtual

Definition at line 126 of file ControlElement.cpp.

127{
128 for (auto node : m_nodeList) {
129 DrawDCCircle(node->GetPosition(), node->GetRadius(), 10, gc);
130 if (node->GetNodeType() == Node::NodeType::NODE_IN) { DrawDCTriangle(node->GetInTrianglePts(), gc); }
131 }
132}
virtual void DrawDCTriangle(std::vector< wxPoint2DDouble > points, wxGraphicsContext *gc) const
Draw rectangle.
Definition Element.cpp:237
virtual void DrawDCCircle(wxPoint2DDouble position, double radius, int numSegments, wxGraphicsContext *gc) const
Draw a circle using device context.
Definition Element.cpp:177

◆ GetControlElementFromID()

ControlElement * ControlElement::GetControlElementFromID ( std::vector< std::shared_ptr< ControlElement > >  elementList,
int  id 
)
static

Definition at line 163 of file ControlElement.cpp.

164{
165 for (auto it = elementList.begin(), itEnd = elementList.end(); it != itEnd; ++it) {
166 ControlElement* element = it->get();
167 if (element->GetID() == id) return element;
168 }
169 return nullptr;
170}
virtual int GetID() const
Get the element ID.
Definition Element.h:271

◆ GetNodeList()

std::vector< Node * > ControlElement::GetNodeList ( ) const
inline

Definition at line 96 of file ControlElement.h.

96{ return m_nodeList; }

◆ GetOutput()

virtual double ControlElement::GetOutput ( ) const
inlinevirtual

Definition at line 110 of file ControlElement.h.

110{ return m_output; }

◆ Initialize()

bool ControlElement::Initialize ( )
virtual

Definition at line 217 of file ControlElement.cpp.

218{
219 m_solved = false;
220 m_output = 0.0;
221 return true;
222}

◆ IsSolved()

virtual bool ControlElement::IsSolved ( ) const
inlinevirtual

Definition at line 106 of file ControlElement.h.

106{ return m_solved; }

◆ Move()

void ControlElement::Move ( wxPoint2DDouble  position)
virtual

Move the element other position.

Parameters
positionPosition that the element will be moved. Use StartMove(wxPoint2DDouble position) before start moving.

Reimplemented from Element.

Reimplemented in ConnectionLine, and Gain.

Definition at line 141 of file ControlElement.cpp.

142{
143 SetPosition(m_movePos + position - m_moveStartPt);
144 for (int i = 0; i < (int)m_nodeList.size(); ++i) { m_nodeList[i]->Move(position); }
145}
void SetPosition(const wxPoint2DDouble position)
Set the element position and update the rectangle.
Definition Element.cpp:27
Here is the call graph for this function:

◆ OpenControlNodes()

bool ControlElement::OpenControlNodes ( rapidxml::xml_node<> *  elementNode)
protected

Definition at line 194 of file ControlElement.cpp.

195{
196 // Clear old nodes
197 for (auto it = m_nodeList.begin(), itEnd = m_nodeList.end(); it != itEnd; ++it) delete* it;
198 m_nodeList.clear();
199
200 auto nodeList = elementNode->first_node("NodeList");
201 if (!nodeList) return false;
202 auto nodeN = nodeList->first_node("Node");
203 while (nodeN) {
204 auto nodePosition = nodeN->first_node("Position");
205 double nodePosX = XMLParser::GetNodeValueDouble(nodePosition, "X");
206 double nodePosY = XMLParser::GetNodeValueDouble(nodePosition, "Y");
207 double nodeAngle = XMLParser::GetNodeValueDouble(nodeN, "Angle");
208 Node::NodeType nodeType = static_cast<Node::NodeType>(XMLParser::GetNodeValueInt(nodeN, "Type"));
209 Node* node = new Node(wxPoint2DDouble(nodePosX, nodePosY), nodeType, 2.0);
210 node->SetAngle(nodeAngle);
211 m_nodeList.push_back(node);
212 nodeN = nodeN->next_sibling("Node");
213 }
214 return true;
215}
Node of a control element. This class manages the user interaction with the connection and control el...

◆ ReplaceNode()

void ControlElement::ReplaceNode ( Node oldNode,
Node newNode 
)
virtual

Definition at line 156 of file ControlElement.cpp.

157{
158 for (unsigned int i = 0; i < m_nodeList.size(); i++) {
159 if (m_nodeList[i] == oldNode) m_nodeList[i] = newNode;
160 }
161}

◆ SaveControlNodes()

void ControlElement::SaveControlNodes ( rapidxml::xml_document<> &  doc,
rapidxml::xml_node<> *  elementNode 
)
protected

Definition at line 172 of file ControlElement.cpp.

173{
174 auto nodeList = XMLParser::AppendNode(doc, elementNode, "NodeList");
175 int id = 0;
176 for (auto it = m_nodeList.begin(), itEnd = m_nodeList.end(); it != itEnd; ++it) {
177 Node* node = *it;
178 node->SetID(id);
179 auto nodeN = XMLParser::AppendNode(doc, nodeList, "Node");
180 XMLParser::SetNodeAttribute(doc, nodeN, "ID", id);
181 auto nodePosition = XMLParser::AppendNode(doc, nodeN, "Position");
182 auto posNodeX = XMLParser::AppendNode(doc, nodePosition, "X");
183 XMLParser::SetNodeValue(doc, posNodeX, node->GetPosition().m_x);
184 auto posNodeY = XMLParser::AppendNode(doc, nodePosition, "Y");
185 XMLParser::SetNodeValue(doc, posNodeY, node->GetPosition().m_y);
186 auto angle = XMLParser::AppendNode(doc, nodeN, "Angle");
187 XMLParser::SetNodeValue(doc, angle, node->GetAngle());
188 auto nodeType = XMLParser::AppendNode(doc, nodeN, "Type");
189 XMLParser::SetNodeValue(doc, nodeType, static_cast<int>(node->GetNodeType()));
190 id++;
191 }
192}

◆ SetNodeList()

void ControlElement::SetNodeList ( std::vector< Node * >  nodeList)
inline

Definition at line 95 of file ControlElement.h.

95{ m_nodeList = nodeList; }

◆ SetOutput()

virtual void ControlElement::SetOutput ( double  output)
inlinevirtual

Definition at line 111 of file ControlElement.h.

111{ m_output = output; }

◆ SetSolved()

virtual void ControlElement::SetSolved ( bool  solved = true)
inlinevirtual

Definition at line 107 of file ControlElement.h.

107{ m_solved = solved; }

◆ Solve()

bool ControlElement::Solve ( double *  input,
double  timeStep 
)
virtual

Reimplemented in Exponential, Gain, RateLimiter, and TransferFunction.

Definition at line 147 of file ControlElement.cpp.

148{
149 if (input)
150 m_output = input[0];
151 else
152 m_output = 0.0;
153 return true;
154}

◆ StartMove()

void ControlElement::StartMove ( wxPoint2DDouble  position)
virtual

Update the element attributes related to the movement.

Parameters
positionStart move position.

Reimplemented from Element.

Reimplemented in ConnectionLine.

Definition at line 134 of file ControlElement.cpp.

135{
136 m_moveStartPt = position;
137 m_movePos = m_position;
138 for (int i = 0; i < (int)m_nodeList.size(); ++i) { m_nodeList[i]->StartMove(position); }
139}

◆ UpdateText()

virtual bool ControlElement::UpdateText ( )
inlinevirtual

Update the OpenGL text in the element (if present).

Returns
true if OpenGLText is ok, false otherwise.

Reimplemented in Constant, Gain, IOControl, MathExpression, and TransferFunction.

Definition at line 105 of file ControlElement.h.

105{ return true; }

Member Data Documentation

◆ m_nodeList

std::vector<Node*> ControlElement::m_nodeList
protected

Definition at line 116 of file ControlElement.h.

◆ m_output

double ControlElement::m_output = 0.0
protected

Definition at line 118 of file ControlElement.h.

◆ m_solved

bool ControlElement::m_solved = false
protected

Definition at line 117 of file ControlElement.h.


The documentation for this class was generated from the following files: