Power System Platform  2026w10a-beta
Loading...
Searching...
No Matches
ControlElement.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 CONTROLELEMENT_H
19#define CONTROLELEMENT_H
20
21#include "../Element.h"
22
30class Node
31{
32 public:
33 enum class NodeType { NODE_IN = 0, NODE_OUT };
34
35 Node(wxPoint2DDouble position = wxPoint2DDouble(0, 0), NodeType nodeType = NodeType::NODE_IN, double borderSize = 0.0);
36 ~Node();
37
38 wxRect2DDouble GetRect() const { return m_rect; }
39 void SetRect(wxRect2DDouble rect) { m_rect = rect; }
40 wxPoint2DDouble GetPosition() const;
41 void SetPosition(wxPoint2DDouble position);
42
43 NodeType GetNodeType() const { return m_nodeType; }
44 void SetNodeType(NodeType nodeType) { m_nodeType = nodeType; }
45 double GetRadius() const { return m_radius; }
46 std::vector<wxPoint2DDouble> GetInTrianglePts() const { return m_triPts; }
47 double GetAngle() const { return m_angle; }
48 void SetAngle(double angle) { m_angle = angle; }
49 void Rotate(bool clockwise = true);
50
51 void RotateTriPt(double angle);
52
53 void StartMove(wxPoint2DDouble position);
54 void Move(wxPoint2DDouble position);
55 bool Contains(wxPoint2DDouble position) const;
56
57 bool IsConnected() const { return m_connected; }
58 void SetConnected(bool connected = true) { m_connected = connected; }
59 int GetID() const { return m_id; }
60 void SetID(int id) { m_id = id; }
61 Node* GetCopy() const;
62
63 protected:
64 int m_id = -1;
65
66 wxRect2DDouble m_rect;
67 NodeType m_nodeType;
68
69 bool m_connected = false;
70
71 wxPoint2DDouble m_moveStartPt;
72 wxPoint2DDouble m_movePos;
73
74 double m_radius = 3.0;
75 std::vector<wxPoint2DDouble> m_triPts;
76 double m_angle = 0.0;
77};
78
86class ControlElement : public Element
87{
88 public:
89 ControlElement(int id);
90 virtual ~ControlElement();
91
92 virtual void StartMove(wxPoint2DDouble position);
93 virtual void Move(wxPoint2DDouble position);
94
95 void SetNodeList(std::vector<Node*> nodeList) { m_nodeList = nodeList; }
96 std::vector<Node*> GetNodeList() const { return m_nodeList; }
97 //virtual void DrawNodes() const;
98 virtual void DrawDCNodes(wxGraphicsContext* gc) const;
99 virtual void ReplaceNode(Node* oldNode, Node* newNode);
100
105 virtual bool UpdateText() { return true; }
106 virtual bool IsSolved() const { return m_solved; }
107 virtual void SetSolved(bool solved = true) { m_solved = solved; }
108 virtual bool Solve(double* input, double timeStep);
109 virtual bool Initialize();
110 virtual double GetOutput() const { return m_output; }
111 virtual void SetOutput(double output) { m_output = output; }
112
113 static ControlElement* GetControlElementFromID(std::vector< std::shared_ptr<ControlElement> > elementList, int id);
114
115 protected:
116 std::vector<Node*> m_nodeList;
117 bool m_solved = false;
118 double m_output = 0.0;
119
120 void SaveControlNodes(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementNode);
121 bool OpenControlNodes(rapidxml::xml_node<>* elementNode);
122};
123
124#endif // CONTROLELEMENT_H
virtual void StartMove(wxPoint2DDouble position)
Update the element attributes related to the movement.
virtual void Move(wxPoint2DDouble position)
Move the element other position.
virtual bool UpdateText()
Update the OpenGL text in the element (if present).
Base class of all elements of the program. This class is responsible for manage graphical and his dat...
Definition Element.h:112
Node of a control element. This class manages the user interaction with the connection and control el...