Power System Platform  2026w34a-beta
Loading...
Searching...
No Matches
Workspace.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 WORKSPACE_H
19#define WORKSPACE_H
20
21
22#ifdef _MSC_VER
23 //#include <windows.h>
24#endif // _MSC_VER
25
26#include <wx/dcclient.h>
27#include <wx/msgdlg.h>
28#include <wx/statusbr.h>
29#include <wx/aui/auibook.h>
30#include <wx/clipbrd.h>
31#include <wx/tipwin.h>
32#include <wx/stopwatch.h>
33#include <wx/graphics.h>
34#include <wx/dcbuffer.h>
35#include <map>
36
37#include "WorkspaceBase.h"
38#include "../elements/powerElement/Bus.h"
39
40#include "ControlEditor.h"
42#include "ChartWindowManager.h"
43
44#ifdef _DEBUG
45#include "../utils/DebugMainFrame.hpp"
46#endif
47
48class Camera;
49class Element;
50// class Bus;
51class Line;
52class Transformer;
53class SyncGenerator;
54class IndMotor;
55class SyncMotor;
56class Load;
57class Inductor;
58class Capacitor;
59class HarmCurrent;
61
62class Text;
63
64class PowerFlow;
65class Fault;
67class PowerQuality;
68
69class ElementPlotData;
70class ChartView;
72
73class PropertiesData;
74
75class HMPlane;
76class Shader;
77class Renderer;
78
79enum ElementID {
80 ID_BUS = 0,
81 ID_LINE,
82 ID_TRANSFORMER,
83 ID_SYNCGENERATOR,
84 ID_INDMOTOR,
85 ID_SYNCMOTOR,
86 ID_LOAD,
87 ID_CAPACITOR,
88 ID_INDUCTOR,
89 ID_HARMCURRENT,
90 ID_EMTELEMENT,
91 ID_TEXT,
92
93 NUM_ELEMENTS
94};
95
104class Workspace : public WorkspaceBase
105{
106public:
107 enum class WorkspaceMode : int {
108 MODE_EDIT = 0,
109 MODE_MOVE_ELEMENT,
110 MODE_MOVE_PICKBOX,
111 MODE_MOVE_NODE,
112 MODE_DRAG,
113 MODE_DRAG_INSERT,
114 MODE_DRAG_INSERT_TEXT,
115 MODE_INSERT,
116 MODE_INSERT_TEXT,
117 MODE_SELECTION_RECT,
118 MODE_PASTE,
119 MODE_DRAG_PASTE
120 };
121
122 Workspace();
123 Workspace(wxWindow* parent, wxString name = wxEmptyString, wxStatusBar* statusBar = nullptr, wxAuiNotebook* auiNotebook = nullptr);
124 virtual ~Workspace();
125
126 void SetColourTheme();
127 wxString GetName() const { return m_name; }
128 std::vector<Element*> GetElementList() const;
129 std::vector< std::shared_ptr<PowerElement> > GetElementSharedList() const { return m_elementList; }
130 std::vector< std::shared_ptr<Text> > GetTextList() const { return m_textList; }
131 std::vector<Element*> GetAllElements() const;
132 WorkspaceMode GetWorkspaceMode() const { return m_mode; }
133 Camera* GetCamera() const { return m_camera; }
134 void CopySelection();
135 bool Paste();
136 void SaveCurrentState();
137 void SetNextState();
138 void SetPreviousState();
139 void CopyToClipboard();
140 void ExportAsSVG(wxString path);
141
142 wxFileName GetSavedPath() const { return m_savedPath; }
143 void SetName(wxString name);
144 void SetElementList(std::vector< std::shared_ptr<PowerElement> > elementList);
145 void SetElementList(std::vector<Element*> elementList);
146 void SetTextList(const std::vector< std::shared_ptr<Text> >& textList);
147 void SetStatusBarText(wxString text) { m_statusBar->SetStatusText(text); }
148 void SetWorkspaceMode(WorkspaceMode mode) { m_mode = mode; }
149 void SetSavedPath(wxFileName savedPath) { m_savedPath = savedPath; }
150 void SetJustOpened(bool justOpened) { m_justOpened = justOpened; }
151 //virtual void Redraw() { m_glCanvas->Refresh(); }
152 virtual void Redraw() { m_workspacePanel->Refresh(); }
153 //wxGLContext* GetSharedGLContext() { return m_glContext; }
154 void RotateSelectedElements(bool clockwise = true);
155 void DeleteSelectedElements();
156 bool GetElementsCorners(wxPoint2DDouble& leftUpCorner,
157 wxPoint2DDouble& rightDownCorner,
158 std::vector<Element*> elementList);
159 void Fit();
160 void UnselectAll();
161 void EnableHeatMap(const bool& enable = true);
162 bool IsHeatMapEnable() const { return m_showHM; }
163 HMPlane* GetHeatMap() const { return m_hmPlane; }
164 void EnableAutoHeatMapLabel(const bool& enable = true) { m_hmAutomaticLabel = enable; }
165 bool IsHeatMapAutoLabelEnable() const { return m_hmAutomaticLabel; }
166 ControlEditorManager& GetControlEditorManager() const { return *m_CEMngr; }
167 ChartWindowManager& GetChartWindowManager() const { return *m_CWMngr; }
168
169 void EnableGrid(bool enable = true) { m_showGrid = enable; }
170 bool IsGridEnabled() const { return m_showGrid; }
171 void SetGridSize(double size) { m_gridSize = size; }
172 double GetGridSize() const { return m_gridSize; }
173 wxPoint2DDouble SnapToGrid(const wxPoint2DDouble& pt) const;
174 void AlignSelectedToGrid();
175
176 bool InsertTextElement(int textID, Element* parentElement, ElectricalUnit unit = ElectricalUnit::UNIT_NONE, int precision = 2);
177 Element* FindTextElement(Element* parentElement, int dataType);
178 void RemoveAllTextElements();
179
180 void CheckSlackBusDuplication(Element* newSlackBus);
181
182 void ValidateBusesVoltages(Element* initialBus);
183 void ValidateElementsVoltages();
184
185 void UpdateElementsID();
186 bool UpdateTextElements();
187 void UpdateHeatMap();
188
189 int GetElementNumber(ElementID elementID) { return m_elementNumber[elementID]; }
190 void IncrementElementNumber(ElementID elementID) { m_elementNumber[elementID]++; }
191 PropertiesData* GetProperties() const { return m_properties; }
192 std::vector<double> GetStabilityTimeVector() const { return m_stabilityTimeVector; }
193 bool IsContinuousCalculationActive() const { return m_continuousCalc; }
194 void SetContinuousCalculationActive(bool value = true) { m_continuousCalc = value; }
195 void ResetAllVoltages();
196 bool RunPowerFlow(bool resetVoltages = false, bool showBusyInfo = true);
197 bool RunFault();
198 bool RunSCPower();
199 bool RunStaticStudies();
200 bool RunStability();
201 bool RunHarmonicDistortion(bool runPowerFlowBefore = true);
202 bool RunFrequencyResponse();
203
204 virtual void OnMiddleDoubleClick(wxMouseEvent& event);
205 virtual void OnIdle(wxIdleEvent& event);
206 virtual void OnTimer(wxTimerEvent& event);
207 virtual void OnLeftDoubleClick(wxMouseEvent& event);
208 virtual void OnRightClickDown(wxMouseEvent& event);
209 virtual void OnLeftClickUp(wxMouseEvent& event);
210 virtual void OnScroll(wxMouseEvent& event);
211 virtual void OnMiddleDown(wxMouseEvent& event);
212 virtual void OnMiddleUp(wxMouseEvent& event);
213 virtual void OnMouseMotion(wxMouseEvent& event);
214 virtual void OnKeyDown(wxKeyEvent& event);
215 virtual void OnLeftClickDown(wxMouseEvent& event);
216 virtual void OnPaint(wxPaintEvent& event);
217 virtual void OnPopupClick(wxCommandEvent& event);
218 virtual void OnResize(wxSizeEvent& event);
219
220protected:
221 virtual void OnHeatMapTime(wxTimerEvent& event);
222
223 //void SetViewport();
224 void UpdateStatusBar();
225 int GetElementNumberFromList(Element* element);
226 void GetStateListsCopy(const std::vector< std::shared_ptr<PowerElement> >& elementsList,
227 const std::vector< std::shared_ptr<Text> >& textList,
228 std::vector< std::shared_ptr<PowerElement> >& elementsListCopy,
229 std::vector< std::shared_ptr<Text> >& textListCopy);
230
231 void DrawScene(wxGraphicsContext* gc);
232 void DrawScene(wxDC& dc);
233 void DrawGrid(wxGraphicsContext* gc);
234 void DrawGrid(wxDC& dc);
235
236 //wxGLContext* m_glContext = nullptr;
237 wxStatusBar* m_statusBar = nullptr;
238 wxAuiNotebook* m_auiNotebook = nullptr;
239 Camera* m_camera = nullptr;
240 wxTipWindow::Ref m_tipWindow;
241 wxString m_name;
242
243 WorkspaceMode m_mode = WorkspaceMode::MODE_EDIT;
244 WorkspaceMode m_oldStatusMode = WorkspaceMode::MODE_EDIT;
245
246 //std::vector<PowerElement*> m_elementList;
247 std::vector< std::shared_ptr<PowerElement> > m_elementList;
248 int m_elementNumber[NUM_ELEMENTS];
249
250 //std::vector<Text*> m_textList;
251 std::vector< std::shared_ptr<Text> > m_textList;
252
253 //std::vector< std::vector<PowerElement*> > m_elementListState;
254 std::vector< std::vector< std::shared_ptr<PowerElement> > > m_elementListState;
255 //std::vector< std::vector<Text*> > m_textListState;
256 std::vector< std::vector< std::shared_ptr<Text> > > m_textListState;
257 int m_currenteState = -1;
258 int m_maxStates = 100;
259
260 wxFileName m_savedPath;
261
262 wxRect2DDouble m_selectionRect;
263 wxPoint2DDouble m_startSelRect;
264
265 PropertiesData* m_properties = nullptr;
266
267 std::vector<double> m_stabilityTimeVector;
268
269 bool m_continuousCalc = false;
270 bool m_disconnectedElement = false;
271 bool m_justOpened = false;
272
273 float m_width = 0.0;
274 float m_height = 0.0;
275
276 // Modern OpenGL
277 HMPlane* m_hmPlane = nullptr;
278
279 //glm::mat4 m_projMatrix;
280
281 bool m_showHM = false;
282 bool m_showHMTimer = false;
283 bool m_hmAutomaticLabel = false;
284 bool m_showGrid = false;
285 double m_gridSize = 20.0;
286
287 std::unique_ptr<ControlEditorManager> m_CEMngr;
288 std::unique_ptr<ChartWindowManager> m_CWMngr;
289
290
291#ifdef _DEBUG
292 DebugMainFrame* m_debugFrame = nullptr;
293#endif
294};
295
296#endif // WORKSPACE_H
Class responsible for the correct visualization of the elements on screen.
Definition Camera.h:31
Shunt capactior power element.
Definition Capacitor.h:39
This class is responsible to manage the charts generated in the transient electromechanical studies.
Definition ChartView.h:49
This class is responsible to manage the ControlEditor instances in the application.
Calculates the electromechanical transient based on disturbances (e.g. system fault).
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:115
Calculate the fault of the system and update the elements data.
Definition Fault.h:31
Shunt Harmonic Corrent Source.
Definition HarmCurrent.h:24
Induction motor power element.
Definition IndMotor.h:119
Inductor shunt power element.
Definition Inductor.h:39
Power line element.
Definition Line.h:64
Loas shunt power element.
Definition Load.h:74
Calculate the power flow (including OLTC tap adjustment).
Definition PowerFlow.h:37
Responsible for the power quality calculations.
General and simulation data manager.
Synchronous generator power element.
Synchronous motor (synchronous compensator) power element.
Definition SyncMotor.h:135
Element that shows power element informations in workspace.
Definition Text.h:71
Two-winding transformer power element with OLTC support.
Definition Transformer.h:96
This class manages the graphical and power elements. It is responsible for handling the user's intera...
Definition Workspace.h:105