Power System Platform  2026w10a-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"
41
42#ifdef _DEBUG
43#include "../utils/DebugMainFrame.hpp"
44#endif
45
46class Camera;
47class Element;
48// class Bus;
49class Line;
50class Transformer;
51class SyncGenerator;
52class IndMotor;
53class SyncMotor;
54class Load;
55class Inductor;
56class Capacitor;
57class HarmCurrent;
59
60class Text;
61
62class PowerFlow;
63class Fault;
65class PowerQuality;
66
67class ElementPlotData;
68class ChartView;
70
71class PropertiesData;
72
73class HMPlane;
74class Shader;
75class Renderer;
76
77enum ElementID {
78 ID_BUS = 0,
79 ID_LINE,
80 ID_TRANSFORMER,
81 ID_SYNCGENERATOR,
82 ID_INDMOTOR,
83 ID_SYNCMOTOR,
84 ID_LOAD,
85 ID_CAPACITOR,
86 ID_INDUCTOR,
87 ID_HARMCURRENT,
88 ID_EMTELEMENT,
89 ID_TEXT,
90
91 NUM_ELEMENTS
92};
93
102class Workspace : public WorkspaceBase
103{
104public:
105 enum class WorkspaceMode : int {
106 MODE_EDIT = 0,
107 MODE_MOVE_ELEMENT,
108 MODE_MOVE_PICKBOX,
109 MODE_MOVE_NODE,
110 MODE_DRAG,
111 MODE_DRAG_INSERT,
112 MODE_DRAG_INSERT_TEXT,
113 MODE_INSERT,
114 MODE_INSERT_TEXT,
115 MODE_SELECTION_RECT,
116 MODE_PASTE,
117 MODE_DRAG_PASTE
118 };
119
120 Workspace();
121 Workspace(wxWindow* parent, wxString name = wxEmptyString, wxStatusBar* statusBar = nullptr, wxAuiNotebook* auiNotebook = nullptr);
122 virtual ~Workspace();
123
124 wxString GetName() const { return m_name; }
125 std::vector<Element*> GetElementList() const;
126 std::vector< std::shared_ptr<PowerElement> > GetElementSharedList() const { return m_elementList; }
127 std::vector< std::shared_ptr<Text> > GetTextList() const { return m_textList; }
128 std::vector<Element*> GetAllElements() const;
129 WorkspaceMode GetWorkspaceMode() const { return m_mode; }
130 Camera* GetCamera() const { return m_camera; }
131 void CopySelection();
132 bool Paste();
133 void SaveCurrentState();
134 void SetNextState();
135 void SetPreviousState();
136 void CopyToClipboard();
137 void ExportAsSVG(wxString path);
138
139 wxFileName GetSavedPath() const { return m_savedPath; }
140 void SetName(wxString name);
141 void SetElementList(std::vector< std::shared_ptr<PowerElement> > elementList);
142 void SetElementList(std::vector<Element*> elementList);
143 void SetTextList(const std::vector< std::shared_ptr<Text> >& textList);
144 void SetStatusBarText(wxString text) { m_statusBar->SetStatusText(text); }
145 void SetWorkspaceMode(WorkspaceMode mode) { m_mode = mode; }
146 void SetSavedPath(wxFileName savedPath) { m_savedPath = savedPath; }
147 void SetJustOpened(bool justOpened) { m_justOpened = justOpened; }
148 //virtual void Redraw() { m_glCanvas->Refresh(); }
149 virtual void Redraw() { m_workspacePanel->Refresh(); }
150 //wxGLContext* GetSharedGLContext() { return m_glContext; }
151 void RotateSelectedElements(bool clockwise = true);
152 void DeleteSelectedElements();
153 bool GetElementsCorners(wxPoint2DDouble& leftUpCorner,
154 wxPoint2DDouble& rightDownCorner,
155 std::vector<Element*> elementList);
156 void Fit();
157 void UnselectAll();
158 void EnableHeatMap(const bool& enable = true);
159 bool IsHeatMapEnable() const { return m_showHM; }
160 HMPlane* GetHeatMap() const { return m_hmPlane; }
161 void EnableAutoHeatMapLabel(const bool& enable = true) { m_hmAutomaticLabel = enable; }
162 bool IsHeatMapAutoLabelEnable() const { return m_hmAutomaticLabel; }
163 bool InsertTextElement(int textID, Element* parentElement, ElectricalUnit unit = ElectricalUnit::UNIT_NONE, int precision = 2);
164 Element* FindTextElement(Element* parentElement, int dataType);
165 void RemoveAllTextElements();
166 void CheckSlackBusDuplication(Element* newSlackBus);
167
168 void ValidateBusesVoltages(Element* initialBus);
169 void ValidateElementsVoltages();
170
171 void UpdateElementsID();
172 bool UpdateTextElements();
173 void UpdateHeatMap();
174
175 int GetElementNumber(ElementID elementID) { return m_elementNumber[elementID]; }
176 void IncrementElementNumber(ElementID elementID) { m_elementNumber[elementID]++; }
177 PropertiesData* GetProperties() const { return m_properties; }
178 std::vector<double> GetStabilityTimeVector() const { return m_stabilityTimeVector; }
179 bool IsContinuousCalculationActive() const { return m_continuousCalc; }
180 void SetContinuousCalculationActive(bool value = true) { m_continuousCalc = value; }
181 void ResetAllVoltages();
182 bool RunPowerFlow(bool resetVoltages = false, bool showBusyInfo = true);
183 bool RunFault();
184 bool RunSCPower();
185 bool RunStaticStudies();
186 bool RunStability();
187 bool RunHarmonicDistortion(bool runPowerFlowBefore = true);
188 bool RunFrequencyResponse();
189
190 virtual void OnMiddleDoubleClick(wxMouseEvent& event);
191 virtual void OnIdle(wxIdleEvent& event);
192 virtual void OnTimer(wxTimerEvent& event);
193 virtual void OnLeftDoubleClick(wxMouseEvent& event);
194 virtual void OnRightClickDown(wxMouseEvent& event);
195 virtual void OnLeftClickUp(wxMouseEvent& event);
196 virtual void OnScroll(wxMouseEvent& event);
197 virtual void OnMiddleDown(wxMouseEvent& event);
198 virtual void OnMiddleUp(wxMouseEvent& event);
199 virtual void OnMouseMotion(wxMouseEvent& event);
200 virtual void OnKeyDown(wxKeyEvent& event);
201 virtual void OnLeftClickDown(wxMouseEvent& event);
202 virtual void OnPaint(wxPaintEvent& event);
203 virtual void OnPopupClick(wxCommandEvent& event);
204 virtual void OnResize(wxSizeEvent& event);
205
206protected:
207 virtual void OnHeatMapTime(wxTimerEvent& event);
208
209 //void SetViewport();
210 void UpdateStatusBar();
211 int GetElementNumberFromList(Element* element);
212 void GetStateListsCopy(const std::vector< std::shared_ptr<PowerElement> >& elementsList,
213 const std::vector< std::shared_ptr<Text> >& textList,
214 std::vector< std::shared_ptr<PowerElement> >& elementsListCopy,
215 std::vector< std::shared_ptr<Text> >& textListCopy);
216
217 void DrawScene(wxGraphicsContext* gc);
218 void DrawScene(wxDC& dc);
219
220 //wxGLContext* m_glContext = nullptr;
221 wxStatusBar* m_statusBar = nullptr;
222 wxAuiNotebook* m_auiNotebook = nullptr;
223 Camera* m_camera = nullptr;
224 wxTipWindow* m_tipWindow = nullptr;
225 wxString m_name;
226
227 WorkspaceMode m_mode = WorkspaceMode::MODE_EDIT;
228 WorkspaceMode m_oldStatusMode = WorkspaceMode::MODE_EDIT;
229
230 //std::vector<PowerElement*> m_elementList;
231 std::vector< std::shared_ptr<PowerElement> > m_elementList;
232 int m_elementNumber[NUM_ELEMENTS];
233
234 //std::vector<Text*> m_textList;
235 std::vector< std::shared_ptr<Text> > m_textList;
236
237 //std::vector< std::vector<PowerElement*> > m_elementListState;
238 std::vector< std::vector< std::shared_ptr<PowerElement> > > m_elementListState;
239 //std::vector< std::vector<Text*> > m_textListState;
240 std::vector< std::vector< std::shared_ptr<Text> > > m_textListState;
241 int m_currenteState = -1;
242 int m_maxStates = 100;
243
244 wxFileName m_savedPath;
245
246 wxRect2DDouble m_selectionRect;
247 wxPoint2DDouble m_startSelRect;
248
249 PropertiesData* m_properties = nullptr;
250
251 std::vector<double> m_stabilityTimeVector;
252
253 bool m_continuousCalc = false;
254 bool m_disconnectedElement = false;
255 bool m_justOpened = false;
256
257 float m_width = 0.0;
258 float m_height = 0.0;
259
260 // Modern OpenGL
261 HMPlane* m_hmPlane = nullptr;
262
263 //glm::mat4 m_projMatrix;
264
265 bool m_showHM = false;
266 bool m_showHMTimer = false;
267 bool m_hmAutomaticLabel = false;
268
269
270
271#ifdef _DEBUG
272 DebugMainFrame* m_debugFrame = nullptr;
273#endif
274};
275
276#endif // WORKSPACE_H
ElectricalUnit
Electrical units.
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
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:112
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:103