Power System Platform  2026w23a-beta
Loading...
Searching...
No Matches
ControlEditor.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 CONTROLEDITOR_H
19#define CONTROLEDITOR_H
20
21
22#include "ControlEditorBase.h"
23
24#include <wx/wrapsizer.h>
25#include <wx/dcclient.h>
26#include <wx/dcscreen.h>
27#include <wx/graphics.h>
28#include <wx/progdlg.h>
29
30#ifdef _MSC_VER
31 //#include <windows.h>
32#endif
33
34#include "../elements/controlElement/IOControl.h"
35#include "../utils/PropertiesData.h"
36#include "ControlSystemTest.h"
37
38#include <unordered_set>
39
40class FileHanding;
41class Camera;
42class Element;
43class ControlElement;
45class ConnectionLine;
46class Sum;
47class Multiplier;
48class Limiter;
49class RateLimiter;
50class Exponential;
51class Constant;
52class Gain;
53class MathOperation;
54class Divider;
55class MathExpression;
56
59
60class ChartView;
63
65
66enum class ControlElementButtonID : int {
67 ID_IO = 0,
68 ID_TF,
69 ID_SUM,
70 ID_CONST,
71 ID_LIMITER,
72 ID_GAIN,
73 ID_MULT,
74 ID_EXP,
75 ID_RATELIM,
76 ID_MATH_DIV,
77 ID_MATH_EXPR
78};
79
87class ControlElementButton : public wxWindow
88{
89public:
90 ControlElementButton(wxWindow* parent, wxString label, wxImage image, wxWindowID id, GUIColour* guiColour);
91 ControlElementButton(wxWindow* parent, wxString label, std::unique_ptr<ControlElement> iconElement, wxWindowID id, GUIColour* guiColour, double buttonScale = 1.0);
93
94protected:
95 virtual void OnPaint(wxPaintEvent& event);
96 virtual void OnMouseEnter(wxMouseEvent& event);
97 virtual void OnMouseLeave(wxMouseEvent& event);
98 virtual void OnLeftClickDown(wxMouseEvent& event);
99 virtual void OnLeftClickUp(wxMouseEvent& event);
100
101 GUIColour* m_guiColour = nullptr;
102
103 std::unique_ptr<ControlElement> m_iconElement;
104
105 wxString m_label;
106 wxFont m_buttonFont;
107 double m_buttonScale = 1.0;
108 wxPoint m_labelPosition;
109
110 wxImage m_image;
111 wxSize m_imageSize;
112 wxPoint m_imagePosition;
113
114 int m_borderSize = 2;
115 bool m_mouseAbove = false;
116 bool m_selected = false;
117
118 wxSize m_buttonSize;
119};
120
121class ControlEditor : public ControlEditorBase
122{
123public:
124 enum class ControlEditorMode : int {
125 MODE_EDIT = 0,
126 MODE_MOVE_ELEMENT,
127 MODE_MOVE_LINE,
128 MODE_DRAG,
129 MODE_DRAG_INSERT,
130 MODE_INSERT,
131 MODE_INSERT_LINE,
132 MODE_SELECTION_RECT,
133 MODE_PASTE,
134 MODE_DRAG_PASTE
135 };
136 ControlEditor(wxWindow* parent, PropertiesData* properties) : ControlEditorBase(parent), m_properties(properties) {}
137 ControlEditor(wxWindow* parent, PropertiesData* properties,
138 int ioflags = IOControl::IN_TERMINAL_VOLTAGE | IOControl::IN_VELOCITY | IOControl::OUT_FIELD_VOLTAGE |
139 IOControl::OUT_MEC_POWER);
140 virtual ~ControlEditor();
141
142 virtual void AddElement(ControlElementButtonID id);
143 //virtual void Redraw() { m_glCanvas->Refresh(); }
144 virtual void Redraw() { m_cePanel->Refresh(); }
145 virtual void SetJustOpened(bool justOpened) { m_justOpened = justOpened; }
146 virtual void RotateSelectedElements(bool clockwise);
147 virtual void DeleteSelectedElements();
148 virtual void CheckConnections();
149 virtual std::vector< std::shared_ptr<ConnectionLine> > GetConnectionLineList() const { return m_connectionList; }
150 virtual std::vector< std::shared_ptr<ControlElement> > GetControlElementList() const { return m_elementList; }
151 virtual void SetElementsList(const std::vector< std::shared_ptr<ControlElement> >& elementList);
152 virtual void SetConnectionsList(const std::vector< std::shared_ptr<ConnectionLine> >& connectionList) { m_connectionList = connectionList; }
153 virtual void SetControlContainer(ControlElementContainer* ctrlContainer) { m_ctrlContainer = ctrlContainer; }
154 virtual ControlElementContainer* GetControlContainer() { return m_ctrlContainer; }
155 virtual void SetPlotLib(int plotLib) { m_plotLib = plotLib; }
156 virtual void SetManager(ControlEditorManager* manager) { m_ctrlManager = manager; }
157 virtual std::vector<Element*> GetElementList() const;
158 virtual void Fit();
159
160 virtual void OnClose(wxCloseEvent& event);
161 virtual void OnTestClick(wxCommandEvent& event);
162 virtual void OnButtonOKClick(wxCommandEvent& event) { Close(); }
163 virtual void OnImportClick(wxCommandEvent& event);
164 virtual void OnExportClick(wxCommandEvent& event);
165 virtual void OnKeyDown(wxKeyEvent& event);
166 virtual void OnIdle(wxIdleEvent& event);
167 virtual void OnScroll(wxMouseEvent& event);
168 virtual void OnDoubleClick(wxMouseEvent& event);
169 virtual void OnLeftClickDown(wxMouseEvent& event);
170 virtual void OnLeftClickUp(wxMouseEvent& event);
171 virtual void OnMiddleDown(wxMouseEvent& event);
172 virtual void OnMiddleUp(wxMouseEvent& event);
173 virtual void OnMouseMotion(wxMouseEvent& event);
174 virtual void OnPaint(wxPaintEvent& event);
175 virtual void LeftClickDown(wxMouseEvent& event);
176
177 virtual void BuildColourList();
178 virtual wxColour GetNextColour();
179
180 void BuildControlElementPanel();
181
182protected:
183 virtual void OnMiddleDoubleClick(wxMouseEvent& event);
184 virtual void OnFitClick(wxCommandEvent& event);
185 virtual void OnCopyClick(wxCommandEvent& event);
186 virtual void OnDeleteClick(wxCommandEvent& event);
187 virtual void OnDragClick(wxCommandEvent& event);
188 virtual void OnMoveClick(wxCommandEvent& event);
189 virtual void OnNewClick(wxCommandEvent& event);
190 virtual void OnPasteClick(wxCommandEvent& event);
191 virtual void OnRedoClick(wxCommandEvent& event);
192 virtual void OnUndoClick(wxCommandEvent& event);
193 //void SetViewport();
194 int GetNextID();
195
196 std::vector< std::shared_ptr<ConnectionLine> >::iterator DeleteLineFromList(std::vector< std::shared_ptr<ConnectionLine> >::iterator& it);
197
198 // ---------------------------------------------------------------------
199 // Clipboard + Undo/Redo helpers (mirrors Workspace patterns)
200 // ---------------------------------------------------------------------
201 void UnselectAll();
202 void CopySelectionToClipboard();
203 bool PasteFromClipboard();
204
205 void SaveCurrentState();
206 void SetPreviousState();
207 void SetNextState();
208 void ClearStates();
209
210 bool GetElementsCorners(wxPoint2DDouble& leftUpCorner,
211 wxPoint2DDouble& rightDownCorner,
212 const std::vector<Element*>& elementList) const;
213
214 void ApplyFontToElements();
215 wxPoint GetEditorMouseClientPoint() const;
216 wxPoint2DDouble GetEditorMouseWorldPoint() const;
217
218 Camera* m_camera = nullptr;
219
220 PropertiesData* m_properties = nullptr;
221 wxFont m_font;
222
223 ControlEditorMode m_mode = ControlEditorMode::MODE_EDIT;
224
225 wxRect2DDouble m_selectionRect;
226 wxPoint2DDouble m_startSelRect;
227
228 //std::vector<ControlElement*> m_elementList;
229 std::vector< std::shared_ptr<ControlElement> > m_elementList;
230 //std::vector<ConnectionLine*> m_connectionList;
231 std::vector< std::shared_ptr<ConnectionLine> > m_connectionList;
232
233 ControlElementContainer* m_ctrlContainer = nullptr;
234 ControlEditorManager* m_ctrlManager = nullptr;
235
236 bool m_justOpened = false;
237 int m_ioFlags = 0;
238
239 int m_inputType = 0;
240 double m_startTime = 1.0;
241 double m_slope = 1.0;
242 double m_timeStep = 1e-4;
243 double m_simTime = 10.0;
244 int m_plotLib = 0;
245
246 std::vector<wxColour> m_colourList;
247 std::vector<wxColour>::iterator m_itColourList;
248
249 // Undo / Redo state (deep copies of the whole control system)
250 std::vector<std::vector<std::shared_ptr<ControlElement>>> m_elementListState;
251 std::vector<std::vector<std::shared_ptr<ConnectionLine>>> m_connectionListState;
252 int m_currentState = -1;
253 int m_maxStates = 100;
254};
255#endif // CONTROLEDITOR_H
Class responsible for the correct visualization of the elements on screen.
Definition Camera.h:31
This class is responsible to manage the charts generated in the transient electromechanical studies.
Definition ChartView.h:49
Connection between two control elements or other connection line and an element.
A control element that provides a constant value.
Definition Constant.h:37
This class is responsible to manage the ControlEditor instances in the application.
This class is responsible to handle the user interaction with control elements.
Class that can contain all control elements. Can identify (using RTTI) the elements from a generic li...
Clipboard payload for ControlEditor copy/paste (control elements + connection lines).
Solves in the time the control system. Can solve the control system directly from a ControlEditor or ...
Control element that divides two inputs.
Definition Divider.h:33
Class to store the elements in the clipboard.
Base class of all elements of the program. This class is responsible for manage graphical and his dat...
Definition Element.h:114
Generates an output following an exponential function.
Definition Exponential.h:33
Save and opens the projects created on disk.
Definition FileHanding.h:43
Provide an output multiplying the input by a constant.
Definition Gain.h:37
Limits the input value by superior and inferior values.
Definition Limiter.h:33
A generic math expression block that can perform math and conditional operations with the inputs.
Abstract class that define the general behavior of math operation control block.
Multiplies two inputs.
Definition Multiplier.h:33
General and simulation data manager.
Limits the rising and/or falling rate.
Definition RateLimiter.h:33
Sum the all inputs (can choose the input signal).
Definition Sum.h:34
Calculates the time response by a frequency domain transfer function.