Power System Platform  2026w23a-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 bool InsertTextElement(int textID, Element* parentElement, ElectricalUnit unit = ElectricalUnit::UNIT_NONE, int precision = 2);
170 Element* FindTextElement(Element* parentElement, int dataType);
171 void RemoveAllTextElements();
172
173 void CheckSlackBusDuplication(Element* newSlackBus);
174
175 void ValidateBusesVoltages(Element* initialBus);
176 void ValidateElementsVoltages();
177
178 void UpdateElementsID();
179 bool UpdateTextElements();
180 void UpdateHeatMap();
181
182 int GetElementNumber(ElementID elementID) { return m_elementNumber[elementID]; }
183 void IncrementElementNumber(ElementID elementID) { m_elementNumber[elementID]++; }
184 PropertiesData* GetProperties() const { return m_properties; }
185 std::vector<double> GetStabilityTimeVector() const { return m_stabilityTimeVector; }
186 bool IsContinuousCalculationActive() const { return m_continuousCalc; }
187 void SetContinuousCalculationActive(bool value = true) { m_continuousCalc = value; }
188 void ResetAllVoltages();
189 bool RunPowerFlow(bool resetVoltages = false, bool showBusyInfo = true);
190 bool RunFault();
191 bool RunSCPower();
192 bool RunStaticStudies();
193 bool RunStability();
194 bool RunHarmonicDistortion(bool runPowerFlowBefore = true);
195 bool RunFrequencyResponse();
196
197 virtual void OnMiddleDoubleClick(wxMouseEvent& event);
198 virtual void OnIdle(wxIdleEvent& event);
199 virtual void OnTimer(wxTimerEvent& event);
200 virtual void OnLeftDoubleClick(wxMouseEvent& event);
201 virtual void OnRightClickDown(wxMouseEvent& event);
202 virtual void OnLeftClickUp(wxMouseEvent& event);
203 virtual void OnScroll(wxMouseEvent& event);
204 virtual void OnMiddleDown(wxMouseEvent& event);
205 virtual void OnMiddleUp(wxMouseEvent& event);
206 virtual void OnMouseMotion(wxMouseEvent& event);
207 virtual void OnKeyDown(wxKeyEvent& event);
208 virtual void OnLeftClickDown(wxMouseEvent& event);
209 virtual void OnPaint(wxPaintEvent& event);
210 virtual void OnPopupClick(wxCommandEvent& event);
211 virtual void OnResize(wxSizeEvent& event);
212
213protected:
214 virtual void OnHeatMapTime(wxTimerEvent& event);
215
216 //void SetViewport();
217 void UpdateStatusBar();
218 int GetElementNumberFromList(Element* element);
219 void GetStateListsCopy(const std::vector< std::shared_ptr<PowerElement> >& elementsList,
220 const std::vector< std::shared_ptr<Text> >& textList,
221 std::vector< std::shared_ptr<PowerElement> >& elementsListCopy,
222 std::vector< std::shared_ptr<Text> >& textListCopy);
223
224 void DrawScene(wxGraphicsContext* gc);
225 void DrawScene(wxDC& dc);
226
227 //wxGLContext* m_glContext = nullptr;
228 wxStatusBar* m_statusBar = nullptr;
229 wxAuiNotebook* m_auiNotebook = nullptr;
230 Camera* m_camera = nullptr;
231 wxTipWindow::Ref m_tipWindow;
232 wxString m_name;
233
234 WorkspaceMode m_mode = WorkspaceMode::MODE_EDIT;
235 WorkspaceMode m_oldStatusMode = WorkspaceMode::MODE_EDIT;
236
237 //std::vector<PowerElement*> m_elementList;
238 std::vector< std::shared_ptr<PowerElement> > m_elementList;
239 int m_elementNumber[NUM_ELEMENTS];
240
241 //std::vector<Text*> m_textList;
242 std::vector< std::shared_ptr<Text> > m_textList;
243
244 //std::vector< std::vector<PowerElement*> > m_elementListState;
245 std::vector< std::vector< std::shared_ptr<PowerElement> > > m_elementListState;
246 //std::vector< std::vector<Text*> > m_textListState;
247 std::vector< std::vector< std::shared_ptr<Text> > > m_textListState;
248 int m_currenteState = -1;
249 int m_maxStates = 100;
250
251 wxFileName m_savedPath;
252
253 wxRect2DDouble m_selectionRect;
254 wxPoint2DDouble m_startSelRect;
255
256 PropertiesData* m_properties = nullptr;
257
258 std::vector<double> m_stabilityTimeVector;
259
260 bool m_continuousCalc = false;
261 bool m_disconnectedElement = false;
262 bool m_justOpened = false;
263
264 float m_width = 0.0;
265 float m_height = 0.0;
266
267 // Modern OpenGL
268 HMPlane* m_hmPlane = nullptr;
269
270 //glm::mat4 m_projMatrix;
271
272 bool m_showHM = false;
273 bool m_showHMTimer = false;
274 bool m_hmAutomaticLabel = false;
275
276 std::unique_ptr<ControlEditorManager> m_CEMngr;
277 std::unique_ptr<ChartWindowManager> m_CWMngr;
278
279
280#ifdef _DEBUG
281 DebugMainFrame* m_debugFrame = nullptr;
282#endif
283};
284
285#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:114
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.
Definition PowerFlow.h:36
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:70
Two-winding transformer power element.
Definition Transformer.h:84
This class manages the graphical and power elements. It is responsible for handling the user's intera...
Definition Workspace.h:105