Power System Platform  2026w23a-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{
32public:
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
63protected:
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{
88public:
89 ControlElement(int id);
90 virtual ~ControlElement();
91
92 virtual void StartMove(wxPoint2DDouble position);
93 virtual void Move(wxPoint2DDouble position);
94
95 virtual void SetFont(wxFont& font) {}
96
97 void SetNodeList(std::vector<Node*> nodeList) { m_nodeList = nodeList; }
98 std::vector<Node*> GetNodeList() const { return m_nodeList; }
99 //virtual void DrawNodes() const;
100 virtual void DrawDCNodes(wxGraphicsContext* gc) const;
101 virtual void ReplaceNode(Node* oldNode, Node* newNode);
102
107 virtual bool UpdateText() { return true; }
108 virtual bool IsSolved() const { return m_solved; }
109 virtual void SetSolved(bool solved = true) { m_solved = solved; }
110 virtual bool Solve(double* input, double timeStep);
111 virtual bool Initialize();
112 virtual double GetOutput() const { return m_output; }
113 virtual void SetOutput(double output) { m_output = output; }
114
115 static ControlElement* GetControlElementFromID(std::vector< std::shared_ptr<ControlElement> > elementList, int id);
116
117protected:
118 std::vector<Node*> m_nodeList;
119 bool m_solved = false;
120 double m_output = 0.0;
121
122 void SaveControlNodes(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementNode);
123 bool OpenControlNodes(rapidxml::xml_node<>* elementNode);
124};
125
126#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:114
Node of a control element. This class manages the user interaction with the connection and control el...