Power System Platform  2026w34a-beta
Loading...
Searching...
No Matches
MainFrame.cpp
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#include "MainFrame.h"
19
20#include <wx/settings.h>
21
33
34#include "forms/AboutForm.h"
35#include "forms/DataReport.h"
37#include "forms/ImportForm.h"
38#include "forms/ProjectPropertiesForm.h"
40#include "forms/StabilityEventList.h"
41#include "forms/LabelManager.h"
42#include "forms/ElementsToolBar.h"
43
44#include "utils/FileHanding.h"
46
47#include "editors/ChartView.h"
48#include "editors/Workspace.h"
49#include "extLibs/artProvider/ArtMetro.h"
50#include "utils/Path.h"
51 //#include "WorkspaceDC.h"
52
53MainFrame::MainFrame() : MainFrameBase(nullptr) {}
54MainFrame::MainFrame(wxWindow* parent, wxLocale* locale, PropertiesData* initProperties, wxString openPath)
55 : MainFrameBase(parent)
56{
57 m_locale = locale;
58 m_generalProperties = initProperties;
59
60 Init();
61
62 if (openPath != "") {
63 EnableCurrentProjectRibbon();
64 Workspace* newWorkspace = new Workspace(this, _("Open project"), this->GetStatusBar(), this->GetAuiNotebook());
65 //if (!m_sharedGLContext) m_sharedGLContext = newWorkspace->GetSharedGLContext();
66
67 FileHanding fileHandling(newWorkspace);
68 if (fileHandling.OpenProject(openPath)) {
69 newWorkspace->SetSavedPath(openPath);
70
71 m_workspaceList.push_back(newWorkspace);
72
73 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_DISABLESOL, true);
74 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_ENABLESOL, false);
75
76 m_auiNotebook->AddPage(newWorkspace, newWorkspace->GetName(), true);
77 m_auiNotebook->Layout();
78 newWorkspace->Redraw();
79 newWorkspace->SetJustOpened(true);
80 newWorkspace->Fit();
81 m_projectNumber++;
82 }
83 }
84}
85
87{
88 //if (!m_sharedGLContext && m_workspaceList.size() != 0) {
89 // m_sharedGLContext = m_workspaceList[0]->GetSharedGLContext();
90 //}
91 if (m_addElementsMenu) {
92 m_addElementsMenu->Disconnect(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OnAddElementsClick),
93 nullptr, this);
94 delete m_addElementsMenu;
95 }
96 if (m_stabilityMenu) {
97 m_stabilityMenu->Disconnect(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OnStabilityMenuClick),
98 nullptr, this);
99 delete m_stabilityMenu;
100 }
101 if (m_snapshotMenu) {
102 m_snapshotMenu->Disconnect(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OnSnapshotMenuClick),
103 nullptr, this);
104 delete m_snapshotMenu;
105 }
106
107 if (m_locale) delete m_locale;
108 if (m_generalProperties) delete m_generalProperties;
109}
110
111void MainFrame::Init()
112{
113 this->SetSize(800, 600);
114
115 m_generalProperties->SetGUIColourTheme();
116
117 CreateDropdownMenus();
118
119 EnableCurrentProjectRibbon(false);
120
121 if (wxSystemSettings::GetAppearance().IsDark())
122 {
123 auto* darkArt = m_ribbonBar->GetArtProvider();
124 wxColour stdBlue = wxColour(53, 132, 228);
125 wxColour darkBlue = wxColour(6, 68, 140);
126 wxColour stdGrey = wxColour(59, 59, 59);
127 wxColour darkGrey = wxColour(40, 40, 40);
128
129 darkArt->SetColor(wxRIBBON_ART_PAGE_BACKGROUND_TOP_COLOUR, stdGrey);
130 darkArt->SetColor(wxRIBBON_ART_PAGE_BACKGROUND_TOP_GRADIENT_COLOUR, stdGrey);
131 darkArt->SetColor(wxRIBBON_ART_PAGE_BACKGROUND_COLOUR, stdGrey);
132 darkArt->SetColor(wxRIBBON_ART_PAGE_BACKGROUND_GRADIENT_COLOUR, stdGrey);
133
134 darkArt->SetColor(wxRIBBON_ART_PAGE_HOVER_BACKGROUND_TOP_COLOUR, darkGrey);
135 darkArt->SetColor(wxRIBBON_ART_PAGE_HOVER_BACKGROUND_TOP_GRADIENT_COLOUR, darkGrey);
136 darkArt->SetColor(wxRIBBON_ART_PAGE_HOVER_BACKGROUND_COLOUR, darkGrey);
137 darkArt->SetColor(wxRIBBON_ART_PAGE_HOVER_BACKGROUND_GRADIENT_COLOUR, darkGrey);
138
139 darkArt->SetColor(wxRIBBON_ART_TAB_HOVER_BACKGROUND_TOP_COLOUR, stdBlue);
140 darkArt->SetColor(wxRIBBON_ART_TAB_HOVER_BACKGROUND_TOP_GRADIENT_COLOUR, stdBlue);
141 darkArt->SetColor(wxRIBBON_ART_TAB_HOVER_BACKGROUND_COLOUR, stdBlue);
142 darkArt->SetColor(wxRIBBON_ART_TAB_HOVER_BACKGROUND_GRADIENT_COLOUR, stdBlue);
143
144 darkArt->SetColor(wxRIBBON_ART_BUTTON_BAR_ACTIVE_BACKGROUND_TOP_COLOUR, stdBlue);
145 darkArt->SetColor(wxRIBBON_ART_BUTTON_BAR_ACTIVE_BACKGROUND_TOP_GRADIENT_COLOUR, stdBlue);
146 darkArt->SetColor(wxRIBBON_ART_BUTTON_BAR_ACTIVE_BACKGROUND_COLOUR, stdBlue);
147 darkArt->SetColor(wxRIBBON_ART_BUTTON_BAR_ACTIVE_BACKGROUND_GRADIENT_COLOUR, stdBlue);
148
149 darkArt->SetColor(wxRIBBON_ART_BUTTON_BAR_HOVER_BACKGROUND_TOP_COLOUR, darkBlue);
150 darkArt->SetColor(wxRIBBON_ART_BUTTON_BAR_HOVER_BACKGROUND_TOP_GRADIENT_COLOUR, darkBlue);
151 darkArt->SetColor(wxRIBBON_ART_BUTTON_BAR_HOVER_BACKGROUND_COLOUR, darkBlue);
152 darkArt->SetColor(wxRIBBON_ART_BUTTON_BAR_HOVER_BACKGROUND_GRADIENT_COLOUR, darkBlue);
153 m_ribbonBar->Realize();
154 }
155 else
156 {
157 m_artMetro = new wxRibbonMetroArtProvider();
158 m_ribbonBar->SetArtProvider(m_artMetro);
159 m_ribbonBar->Realize();
160 }
161
162 this->Layout();
163
164 if (!m_generalProperties) return;
165
166 //m_elementsToolBar = new ElementsToolBar(this, m_generalProperties->GetGeneralPropertiesData().elementsToolbar == VERTICAL);
167 //m_elementsToolBar->EnableTools(false);
168 if (m_generalProperties->GetGeneralPropertiesData().elementsToolbar != NONE) {
169 CallAfter([this]() {
170 BuildElementsToolBar(m_generalProperties->GetGeneralPropertiesData().elementsToolbar);
171 m_elementsToolBar->EnableTools(false);
172 });
173 }
174}
175
176void MainFrame::EnableCurrentProjectRibbon(bool enable)
177{
178 if (m_elementsToolBar) {
179 m_elementsToolBar->EnableTools(enable);
180 }
181 m_ribbonButtonBarCircuit->EnableButton(ID_RIBBON_ADDELEMENT, enable);
182 m_ribbonButtonBarReports->EnableButton(ID_RIBBON_CHARTS, enable);
183 m_ribbonButtonBarCProject->EnableButton(ID_RIBBON_CLOSE, enable);
184 m_ribbonButtonBarClipboard->EnableButton(ID_RIBBON_COPY, enable);
185 m_ribbonButtonBarReports->EnableButton(ID_RIBBON_DATAREPORT, enable);
186 m_ribbonButtonBarCircuit->EnableButton(ID_RIBBON_DELETE, enable);
187 m_ribbonButtonBarContinuous->EnableButton(ID_RIBBON_DISABLESOL, enable);
188 m_ribbonButtonBarCircuit->EnableButton(ID_RIBBON_DRAG, enable);
189 m_ribbonButtonBarContinuous->EnableButton(ID_RIBBON_ENABLESOL, enable);
190 m_ribbonButtonBarSimulations->EnableButton(ID_RIBBON_FAULT, enable);
191 m_ribbonButtonBarCircuit->EnableButton(ID_RIBBON_FIT, enable);
192 m_ribbonButtonBarCircuit->EnableButton(ID_RIBBON_MOVE, enable);
193 m_ribbonButtonBarClipboard->EnableButton(ID_RIBBON_PASTE, enable);
194 m_ribbonButtonBarSimulations->EnableButton(ID_RIBBON_POWERFLOW, enable);
195 m_ribbonButtonBarClipboard->EnableButton(ID_RIBBON_REDO, enable);
196 m_ribbonButtonBarContinuous->EnableButton(ID_RIBBON_RESETVOLT, enable);
197 m_ribbonButtonBarSimulations->EnableButton(ID_RIBBON_RUNSTAB, enable);
198 m_ribbonButtonBarCProject->EnableButton(ID_RIBBON_SAVE, enable);
199 m_ribbonButtonBarCProject->EnableButton(ID_RIBBON_SAVEAS, enable);
200 m_ribbonButtonBarSimulations->EnableButton(ID_RIBBON_SCPOWER, enable);
201 m_ribbonButtonBarCircuit->EnableButton(ID_RIBBON_PROJSETTINGS, enable);
202 m_ribbonButtonBarReports->EnableButton(ID_RIBBON_HEATMAP, enable);
203 m_ribbonButtonBarReports->EnableButton(ID_RIBBON_SNAPSHOT, enable);
204 m_ribbonButtonBarSimulations->EnableButton(ID_RIBBON_SIMULSETTINGS, enable);
205 m_ribbonButtonBarClipboard->EnableButton(ID_RIBBON_UNDO, enable);
206 m_ribbonButtonBarCircuit->EnableButton(ID_RIBBON_ROTATEC, enable);
207 m_ribbonButtonBarCircuit->EnableButton(ID_RIBBON_ROTATECC, enable);
208 m_ribbonButtonBarCircuit->EnableButton(ID_RIBBON_GRID, enable);
209 m_ribbonButtonBarCircuit->EnableButton(ID_RIBBON_ALIGN, enable);
210 m_ribbonButtonBarCircuit->EnableButton(ID_RIBBON_LABELMNGR, enable);
211 m_ribbonButtonBarSimulations->EnableButton(ID_RIBBON_HARMDIST, enable);
212 m_ribbonButtonBarSimulations->EnableButton(ID_RIBBON_FREQRESP, enable);
213}
214
215void MainFrame::CreateDropdownMenus()
216{
217 m_addElementsMenu = new wxMenu();
218
219 struct ElementIcon {
220 int id;
221 wxString file;
222 };
223
224 const std::vector<ElementIcon> elementIcons = {
225 { ID_ADDMENU_BUS, "bus.png" },
226 { ID_ADDMENU_CAPACITOR, "capacitor.png" },
227 { ID_ADDMENU_EMTELEMENT, "emtelement.png" },
228 { ID_ADDMENU_GENERATOR, "generator.png" },
229 { ID_ADDMENU_HARMCURRENT, "harmcurrent.png" },
230 { ID_ADDMENU_INDMOTOR, "indmotor.png" },
231 { ID_ADDMENU_INDUCTOR, "inductor.png" },
232 { ID_ADDMENU_LINE, "line.png" },
233 { ID_ADDMENU_LOAD, "load.png" },
234 { ID_ADDMENU_SYNCCOMP, "synccomp.png" },
235 { ID_ADDMENU_TEXT, "text.png" },
236 { ID_ADDMENU_TRANSFORMER, "transformer.png" }
237 };
238
239 std::map<int, wxBitmap> elementBitmaps;
240
241 const int iconSize = FromDIP(16);
242
243 for (const auto& icon : elementIcons) {
244 wxImage image(Paths::GetDataPath() + "/images/elements/" + icon.file, wxBITMAP_TYPE_PNG);
245
246 if (image.IsOk()) {
247 image.Rescale(iconSize, iconSize, wxIMAGE_QUALITY_HIGH);
248 elementBitmaps[icon.id] = wxBitmap(image);
249 }
250 }
251
252 wxMenuItem* busElement =
253 new wxMenuItem(m_addElementsMenu, ID_ADDMENU_BUS, _("&Bus\tB"), _("Adds a bus at the circuit"));
254 busElement->SetBitmap(elementBitmaps.at(ID_ADDMENU_BUS));
255
256 wxMenuItem* lineElement =
257 new wxMenuItem(m_addElementsMenu, ID_ADDMENU_LINE, _("&Line\tL"), _("Adds a power line at the circuit"));
258 lineElement->SetBitmap(elementBitmaps.at(ID_ADDMENU_LINE));
259
260 wxMenuItem* transformerElement = new wxMenuItem(m_addElementsMenu, ID_ADDMENU_TRANSFORMER, _("&Transformer\tT"),
261 _("Adds a transformer at the circuit"));
262 transformerElement->SetBitmap(elementBitmaps.at(ID_ADDMENU_TRANSFORMER));
263
264 wxMenuItem* generatorElement = new wxMenuItem(m_addElementsMenu, ID_ADDMENU_GENERATOR, _("&Generator\tG"),
265 _("Adds a generator at the circuit"));
266 generatorElement->SetBitmap(elementBitmaps.at(ID_ADDMENU_GENERATOR));
267
268 wxMenuItem* indMotorElement = new wxMenuItem(m_addElementsMenu, ID_ADDMENU_INDMOTOR, _("&Induction motor\tI"),
269 _("Adds an induction motor at the circuit"));
270 indMotorElement->SetBitmap(elementBitmaps.at(ID_ADDMENU_INDMOTOR));
271
272 wxMenuItem* syncCompElement =
273 new wxMenuItem(m_addElementsMenu, ID_ADDMENU_SYNCCOMP, _("&Synchronous compensator \tK"),
274 _("Adds an induction motor at the circuit"));
275 syncCompElement->SetBitmap(elementBitmaps.at(ID_ADDMENU_SYNCCOMP));
276
277 wxMenuItem* loadElement =
278 new wxMenuItem(m_addElementsMenu, ID_ADDMENU_LOAD, _("&Load\tShift-L"), _("Adds a load at the circuit"));
279 loadElement->SetBitmap(elementBitmaps.at(ID_ADDMENU_LOAD));
280
281 wxMenuItem* capacitorElement = new wxMenuItem(m_addElementsMenu, ID_ADDMENU_CAPACITOR, _("&Capacitor\tShift-C"),
282 _("Adds a shunt capacitor at the circuit"));
283 capacitorElement->SetBitmap(elementBitmaps.at(ID_ADDMENU_CAPACITOR));
284
285 wxMenuItem* inductorElement = new wxMenuItem(m_addElementsMenu, ID_ADDMENU_INDUCTOR, _("&Inductor\tShift-I"),
286 _("Adds a shunt inductor at the circuit"));
287 inductorElement->SetBitmap(elementBitmaps.at(ID_ADDMENU_INDUCTOR));
288
289 wxMenuItem* harmCurrentElement =
290 new wxMenuItem(m_addElementsMenu, ID_ADDMENU_HARMCURRENT, _("&Harmonic current\tShift-H"),
291 _("Adds a harmonic current source at the circuit"));
292 harmCurrentElement->SetBitmap(elementBitmaps.at(ID_ADDMENU_HARMCURRENT));
293
294 wxMenuItem* emtElement =
295 new wxMenuItem(m_addElementsMenu, ID_ADDMENU_EMTELEMENT, _("&Electromagnetic Transient Element\tShift-E"), _("Adds an electromagnetic transient element that connects with ATP"));
296 emtElement->SetBitmap(elementBitmaps.at(ID_ADDMENU_EMTELEMENT));
297
298 wxMenuItem* textElement =
299 new wxMenuItem(m_addElementsMenu, ID_ADDMENU_TEXT, _("&Label\tA"), _("Adds a linked element label"));
300 textElement->SetBitmap(elementBitmaps.at(ID_ADDMENU_TEXT));
301
302
303 m_addElementsMenu->Append(busElement);
304 m_addElementsMenu->Append(lineElement);
305 m_addElementsMenu->Append(transformerElement);
306 m_addElementsMenu->Append(generatorElement);
307 m_addElementsMenu->Append(indMotorElement);
308 m_addElementsMenu->Append(syncCompElement);
309 m_addElementsMenu->Append(loadElement);
310 m_addElementsMenu->Append(capacitorElement);
311 m_addElementsMenu->Append(inductorElement);
312 m_addElementsMenu->Append(harmCurrentElement);
313 m_addElementsMenu->Append(emtElement);
314 m_addElementsMenu->Append(textElement);
315
316 m_addElementsMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnAddElementsClick, this);
317
318 m_stabilityMenu = new wxMenu();
319
320 wxMenuItem* stabilityList = new wxMenuItem(m_stabilityMenu, ID_STABMENU_LIST, _("&Stability event list"),
321 _("Show the stability event list"));
322 m_stabilityMenu->Append(stabilityList);
323
324 m_stabilityMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnStabilityMenuClick, this);
325
326 m_snapshotMenu = new wxMenu();
327
328 wxMenuItem* snapshotList = new wxMenuItem(m_stabilityMenu, ID_SNAPSHOTMENU_LIST, _("&Export as SVG"),
329 _("Export the diagram as SVG file."));
330 m_snapshotMenu->Append(snapshotList);
331
332 m_snapshotMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnSnapshotMenuClick, this);
333}
334
335void MainFrame::OnNewClick(wxRibbonButtonBarEvent& event)
336{
337 EnableCurrentProjectRibbon();
338
339 Workspace* newWorkspace;
340 //newWorkspace = new Workspace(this, wxString::Format(_("New project %d"), m_projectNumber), this->GetStatusBar(), this->GetAuiNotebook());
341 newWorkspace = new Workspace(m_auiNotebook, wxString::Format(_("New project %d"), m_projectNumber), this->GetStatusBar(), this->GetAuiNotebook());
342 // Set general properties in new Workspace
343 newWorkspace->GetProperties()->SetGeneralPropertiesData(m_generalProperties->GetGeneralPropertiesData());
344 newWorkspace->SetColourTheme();
345
346 m_workspaceList.push_back(newWorkspace);
347
348 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_DISABLESOL, true);
349 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_ENABLESOL, false);
350
351 m_auiNotebook->AddPage(newWorkspace, newWorkspace->GetName(), true);
352 newWorkspace->Redraw();
353 newWorkspace->SetJustOpened(true);
354 m_projectNumber++;
355}
356
357void MainFrame::OnAboutClick(wxRibbonButtonBarEvent& event)
358{
359 AboutForm about(this);
360 about.ShowModal();
361}
362
363void MainFrame::OnAddElementDropdown(wxRibbonButtonBarEvent& event) { event.PopupMenu(m_addElementsMenu); }
364void MainFrame::OnChartsClick(wxRibbonButtonBarEvent& event)
365{
366 if (Workspace* workspace = dynamic_cast<Workspace*>(m_auiNotebook->GetCurrentPage())) {
367 std::vector<ElementPlotData> plotDataList;
368 auto elementList = workspace->GetElementList();
369 for (auto it = elementList.begin(), itEnd = elementList.end(); it != itEnd; ++it) {
370 if (PowerElement* powerElement = dynamic_cast<PowerElement*>(*it)) {
371 ElementPlotData plotData;
372 if (powerElement->GetPlotData(plotData)) plotDataList.push_back(plotData);
373 }
374 }
375 ChartView* cView = new ChartView(workspace, plotDataList, workspace->GetStabilityTimeVector(), m_generalProperties->GetGeneralPropertiesData().plotLib);
376 cView->Show();
377 }
378}
379
380void MainFrame::OnCloseClick(wxRibbonButtonBarEvent& event)
381{
382 auto it = m_workspaceList.begin();
383 while (it != m_workspaceList.end()) {
384 if (*it == m_auiNotebook->GetCurrentPage()) {
385 //if ((*it)->GetSharedGLContext() == m_sharedGLContext) m_sharedGLContext = nullptr;
386 m_workspaceList.erase(it);
387 m_auiNotebook->DeletePage(m_auiNotebook->GetPageIndex(m_auiNotebook->GetCurrentPage()));
388 break;
389 }
390 ++it;
391 }
392 //if (!m_sharedGLContext && !m_workspaceList.empty()) {
393 // m_sharedGLContext = m_workspaceList[0]->GetSharedGLContext();
394 //}
395 if (m_workspaceList.empty()) {
396 EnableCurrentProjectRibbon(false);
397 }
398}
399void MainFrame::OnCopyClick(wxRibbonButtonBarEvent& event)
400{
401 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
402 if (workspace) { workspace->CopySelection(); }
403}
404
405void MainFrame::OnDataReportClick(wxRibbonButtonBarEvent& event)
406{
407 if (Workspace* workspace = dynamic_cast<Workspace*>(m_auiNotebook->GetCurrentPage())) {
408 DataReport* dataReport = new DataReport(workspace, workspace);
409 dataReport->Show();
410 }
411}
412void MainFrame::OnDeleteClick(wxRibbonButtonBarEvent& event)
413{
414 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
415 if (workspace) { workspace->DeleteSelectedElements(); }
416}
417void MainFrame::OnDisableSolutionClick(wxRibbonButtonBarEvent& event)
418{
419 if (Workspace* workspace = dynamic_cast<Workspace*>(m_auiNotebook->GetCurrentPage())) {
420 workspace->SetContinuousCalculationActive(false);
421 }
422 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_DISABLESOL, true);
423 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_ENABLESOL, false);
424}
425
426void MainFrame::OnDragClick(wxRibbonButtonBarEvent& event)
427{
428 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
429 if (workspace) {
430 workspace->SetWorkspaceMode(Workspace::WorkspaceMode::MODE_DRAG);
431 }
432}
433
434void MainFrame::OnEnableSolutionClick(wxRibbonButtonBarEvent& event)
435{
436 if (Workspace* workspace = dynamic_cast<Workspace*>(m_auiNotebook->GetCurrentPage())) {
437 workspace->SetContinuousCalculationActive(true);
438 workspace->RunStaticStudies();
439 }
440 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_ENABLESOL, true);
441 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_DISABLESOL, false);
442}
443
444// void MainFrame::OnExpImpClick(wxRibbonButtonBarEvent& event) {}
445void MainFrame::OnFaultClick(wxRibbonButtonBarEvent& event)
446{
447 if (Workspace* workspace = dynamic_cast<Workspace*>(m_auiNotebook->GetCurrentPage())) { workspace->RunFault(); }
448}
449
450void MainFrame::OnFitClick(wxRibbonButtonBarEvent& event)
451{
452 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
453 if (workspace) { workspace->Fit(); }
454}
455
456void MainFrame::OnMoveClick(wxRibbonButtonBarEvent& event)
457{
458 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
459 if (workspace) {
460 auto elementList = workspace->GetAllElements();
461 // Calculate the average position of selected elements.
462 wxPoint2DDouble averagePos(0, 0);
463 int numSelElements = 0;
464 for (auto it = elementList.begin(), itEnd = elementList.end(); it != itEnd; ++it) {
465 Element* element = *it;
466 if (element->IsSelected()) {
467 averagePos += element->GetPosition();
468 numSelElements++;
469 }
470 }
471 averagePos = wxPoint2DDouble(averagePos.m_x / double(numSelElements), averagePos.m_y / double(numSelElements));
472 // Set the move position to the average of selected elements.
473 for (auto it = elementList.begin(), itEnd = elementList.end(); it != itEnd; ++it) {
474 Element* element = *it;
475 if (element->IsSelected()) { element->StartMove(averagePos); }
476 }
477 workspace->SetWorkspaceMode(Workspace::WorkspaceMode::MODE_MOVE_ELEMENT);
478 }
479}
480
481void MainFrame::OnOpenClick(wxRibbonButtonBarEvent& event)
482{
483 wxFileDialog openFileDialog(this, _("Open PSP file"), "", "", "PSP files (*.psp)|*.psp",
484 wxFD_OPEN | wxFD_FILE_MUST_EXIST);
485 if (openFileDialog.ShowModal() == wxID_CANCEL) return;
486
487 wxFileName fileName(openFileDialog.GetPath());
488
489 EnableCurrentProjectRibbon();
490
491 //Workspace* newWorkspace = new Workspace(this, wxString::Format(_("New project %d"), m_projectNumber), this->GetStatusBar(), this->GetAuiNotebook());
492 Workspace* newWorkspace = new Workspace(m_auiNotebook, wxString::Format(_("New project %d"), m_projectNumber), this->GetStatusBar(), this->GetAuiNotebook());
493
494 // Set general properties in new workspace.
495 newWorkspace->GetProperties()->SetGeneralPropertiesData(m_generalProperties->GetGeneralPropertiesData());
496 newWorkspace->SetColourTheme();
497
498 FileHanding fileHandling(newWorkspace);
499 if (fileHandling.OpenProject(fileName)) {
500 newWorkspace->SetSavedPath(fileName);
501
502 m_workspaceList.push_back(newWorkspace);
503
504 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_DISABLESOL, true);
505 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_ENABLESOL, false);
506
507 m_auiNotebook->AddPage(newWorkspace, newWorkspace->GetName(), true);
508 m_auiNotebook->Layout();
509 newWorkspace->Redraw();
510 newWorkspace->SetJustOpened(true);
511 newWorkspace->SaveCurrentState();
512 newWorkspace->Fit();
513 m_projectNumber++;
514 }
515 else {
516 wxMessageDialog msgDialog(this, _("It was not possible to open the selected file."), _("Error"),
517 wxOK | wxCENTRE | wxICON_ERROR);
518 msgDialog.ShowModal();
519 delete newWorkspace;
520 }
521}
522
523void MainFrame::OnPSPGuideClick(wxRibbonButtonBarEvent& event)
524{
525 wxLaunchDefaultBrowser("https://thales1330.github.io/PSP/docs/");
526}
527void MainFrame::OnPasteClick(wxRibbonButtonBarEvent& event)
528{
529 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
530 if (workspace) { workspace->Paste(); }
531}
532
533void MainFrame::OnPowerFlowClick(wxRibbonButtonBarEvent& event)
534{
535 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
536 if (workspace) { workspace->RunPowerFlow(); }
537}
538
539void MainFrame::OnRedoClick(wxRibbonButtonBarEvent& event)
540{
541 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
542 if (workspace) {
543 workspace->SetNextState();
544 }
545}
546void MainFrame::OnResetVoltagesClick(wxRibbonButtonBarEvent& event)
547{
548 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
549 if (workspace) { workspace->ResetAllVoltages(); }
550}
551
552void MainFrame::OnRunStabilityClick(wxRibbonButtonBarEvent& event)
553{
554 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
555 if (workspace) { workspace->RunStability(); }
556}
557
558void MainFrame::OnSCPowerClick(wxRibbonButtonBarEvent& event)
559{
560 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
561 if (workspace) { workspace->RunSCPower(); }
562}
563
564void MainFrame::OnSaveAsClick(wxRibbonButtonBarEvent& event)
565{
566 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
567 if (workspace) {
568 FileHanding fileHandling(workspace);
569
570 wxFileDialog saveFileDialog(this, _("Save PSP file"), "", "", "PSP files (*.psp)|*.psp",
571 wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
572 if (saveFileDialog.ShowModal() == wxID_CANCEL) return;
573
574 fileHandling.SaveProject(saveFileDialog.GetPath());
575 wxFileName fileName(saveFileDialog.GetPath());
576 workspace->SetName(fileName.GetName());
577 m_auiNotebook->SetPageText(m_auiNotebook->GetPageIndex(workspace), workspace->GetName());
578 workspace->SetSavedPath(fileName);
579 }
580}
581
582void MainFrame::OnSaveClick(wxRibbonButtonBarEvent& event)
583{
584 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
585 if (workspace) {
586 FileHanding fileHandling(workspace);
587
588 if (workspace->GetSavedPath().IsOk()) {
589 fileHandling.SaveProject(workspace->GetSavedPath());
590 }
591 else {
592 wxFileDialog saveFileDialog(this, _("Save PSP file"), "", "", "PSP files (*.psp)|*.psp",
593 wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
594 if (saveFileDialog.ShowModal() == wxID_CANCEL) return;
595
596 fileHandling.SaveProject(saveFileDialog.GetPath());
597 wxFileName fileName(saveFileDialog.GetPath());
598 workspace->SetName(fileName.GetName());
599 m_auiNotebook->SetPageText(m_auiNotebook->GetPageIndex(workspace), workspace->GetName());
600 workspace->SetSavedPath(fileName);
601 }
602 }
603}
604
605void MainFrame::OnSnapshotClick(wxRibbonButtonBarEvent& event)
606{
607 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
608 if (workspace) {
609 workspace->CopyToClipboard();
610 }
611}
612
613void MainFrame::OnUndoClick(wxRibbonButtonBarEvent& event)
614{
615 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
616 if (workspace) {
617 workspace->SetPreviousState();
618 }
619}
620
621void MainFrame::OnAddElementsClick(wxCommandEvent& event)
622{
623 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
624
625 if (workspace) {
626 if (workspace->GetWorkspaceMode() != Workspace::WorkspaceMode::MODE_INSERT) {
627 auto elementList = workspace->GetElementSharedList();
628 auto textList = workspace->GetTextList();
629 wxString statusBarText = "";
630 bool newElement = false;
631 bool isText = false;
632
633 switch (event.GetId()) {
634 case ID_ADDMENU_BUS: {
635 auto newBus = std::make_shared<Bus>(wxPoint2DDouble(0, 0),
636 wxString::Format(_("Bus %d"), workspace->GetElementNumber(ID_BUS)));
637 workspace->IncrementElementNumber(ID_BUS);
638 elementList.push_back(newBus);
639 statusBarText = _("Insert Bus: Click to insert, ESC to cancel.");
640 newElement = true;
641 } break;
642 case ID_ADDMENU_LINE: {
643 auto newLine = std::make_shared<Line>(wxString::Format(_("Line %d"), workspace->GetElementNumber(ID_LINE)));
644 elementList.push_back(newLine);
645 workspace->IncrementElementNumber(ID_LINE);
646 statusBarText = _("Insert Line: Click on two buses, ESC to cancel.");
647 newElement = true;
648 } break;
649 case ID_ADDMENU_TRANSFORMER: {
650 auto newTransformer = std::make_shared <Transformer>(
651 wxString::Format(_("Transformer %d"), workspace->GetElementNumber(ID_TRANSFORMER)));
652 workspace->IncrementElementNumber(ID_TRANSFORMER);
653 elementList.push_back(newTransformer);
654 statusBarText = _("Insert Transformer: Click on two buses, ESC to cancel.");
655 newElement = true;
656 } break;
657 case ID_ADDMENU_GENERATOR: {
658 auto newGenerator = std::make_shared<SyncGenerator>(
659 wxString::Format(_("Generator %d"), workspace->GetElementNumber(ID_SYNCGENERATOR)));
660 workspace->IncrementElementNumber(ID_SYNCGENERATOR);
661 elementList.push_back(newGenerator);
662 statusBarText = _("Insert Generator: Click on a bus, ESC to cancel.");
663 newElement = true;
664 } break;
665 case ID_ADDMENU_LOAD: {
666 auto newLoad = std::make_shared<Load>(wxString::Format(_("Load %d"), workspace->GetElementNumber(ID_LOAD)));
667 workspace->IncrementElementNumber(ID_LOAD);
668 elementList.push_back(newLoad);
669 statusBarText = _("Insert Load: Click on a bus, ESC to cancel.");
670 newElement = true;
671 } break;
672 case ID_ADDMENU_CAPACITOR: {
673 auto newCapacitor = std::make_shared<Capacitor>(wxString::Format(_("Capacitor %d"), workspace->GetElementNumber(ID_CAPACITOR)));
674 workspace->IncrementElementNumber(ID_CAPACITOR);
675 elementList.push_back(newCapacitor);
676 statusBarText = _("Insert Capacitor: Click on a bus, ESC to cancel.");
677 newElement = true;
678 } break;
679 case ID_ADDMENU_INDUCTOR: {
680 auto newInductor = std::make_shared<Inductor>(wxString::Format(_("Inductor %d"), workspace->GetElementNumber(ID_INDUCTOR)));
681 workspace->IncrementElementNumber(ID_INDUCTOR);
682 elementList.push_back(newInductor);
683 statusBarText = _("Insert Inductor: Click on a bus, ESC to cancel.");
684 newElement = true;
685 } break;
686 case ID_ADDMENU_HARMCURRENT: {
687 auto newHarmCurrent = std::make_shared<HarmCurrent>(
688 wxString::Format(_("Harmonic Current %d"), workspace->GetElementNumber(ID_INDUCTOR)));
689 workspace->IncrementElementNumber(ID_HARMCURRENT);
690 elementList.push_back(newHarmCurrent);
691 statusBarText = _("Insert Harmonic Current Source: Click on a bus, ESC to cancel.");
692 newElement = true;
693 } break;
694 case ID_ADDMENU_INDMOTOR: {
695 auto newIndMotor = std::make_shared<IndMotor>(
696 wxString::Format(_("Induction motor %d"), workspace->GetElementNumber(ID_INDMOTOR)));
697 workspace->IncrementElementNumber(ID_INDMOTOR);
698 elementList.push_back(newIndMotor);
699 statusBarText = _("Insert Induction Motor: Click on a bus, ESC to cancel.");
700 newElement = true;
701 } break;
702 case ID_ADDMENU_SYNCCOMP: {
703 auto newSyncCondenser = std::make_shared<SyncMotor>(
704 wxString::Format(_("Synchronous condenser %d"), workspace->GetElementNumber(ID_SYNCMOTOR)));
705 workspace->IncrementElementNumber(ID_SYNCMOTOR);
706 elementList.push_back(newSyncCondenser);
707 statusBarText = _("Insert Synchronous Condenser: Click on a bus, ESC to cancel.");
708 newElement = true;
709 } break;
710 case ID_ADDMENU_EMTELEMENT: {
711 auto newEMTElement = std::make_shared<EMTElement>(wxString::Format(_("Electromagnetic Transient %d"), workspace->GetElementNumber(ID_EMTELEMENT)));
712 workspace->IncrementElementNumber(ID_EMTELEMENT);
713 elementList.push_back(newEMTElement);
714 statusBarText = _("Insert Electromagnetic Transient Element: Click on a bus, ESC to cancel.");
715 newElement = true;
716 } break;
717 case ID_ADDMENU_TEXT: {
718 //Text* newText = new Text();
719 auto newText = std::make_shared<Text>();
720 textList.push_back(newText);
721 statusBarText = _("Insert Label: Click to insert, ESC to cancel.");
722 newElement = true;
723 isText = true;
724 } break;
725 }
726 if (newElement) {
727 workspace->SetElementList(elementList);
728 workspace->SetTextList(textList);
729 if (!isText)
730 workspace->SetWorkspaceMode(Workspace::WorkspaceMode::MODE_INSERT);
731 else
732 workspace->SetWorkspaceMode(Workspace::WorkspaceMode::MODE_INSERT_TEXT);
733 workspace->SetStatusBarText(statusBarText);
734 workspace->Redraw();
735 }
736 }
737 }
738}
739
740void MainFrame::OnImportClick(wxRibbonButtonBarEvent& event)
741{
742 // Create a new workspace to import
743 EnableCurrentProjectRibbon();
744
745 //Workspace* newWorkspace = new Workspace(this, wxString::Format(_("New project %d"), m_projectNumber), this->GetStatusBar(), this->GetAuiNotebook());
746 Workspace* newWorkspace = new Workspace(m_auiNotebook, wxString::Format(_("New project %d"), m_projectNumber), this->GetStatusBar(), this->GetAuiNotebook());
747 // Set general properties in new Workspace
748 newWorkspace->GetProperties()->SetGeneralPropertiesData(m_generalProperties->GetGeneralPropertiesData());
749 newWorkspace->SetColourTheme();
750
751 m_workspaceList.push_back(newWorkspace);
752
753 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_DISABLESOL, true);
754 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_ENABLESOL, false);
755
756 m_auiNotebook->AddPage(newWorkspace, newWorkspace->GetName(), true);
757 newWorkspace->Redraw();
758 m_projectNumber++;
759
760
761 ImportForm importForm(this, newWorkspace);
762 if (importForm.ShowModal() == wxID_OK) {
763 m_auiNotebook->Layout();
764 newWorkspace->Redraw();
765 newWorkspace->SetJustOpened(true);
766 newWorkspace->Fit();
767 }
768}
769
770void MainFrame::NotebookPageClosed(wxAuiNotebookEvent& event)
771{
772 if (m_auiNotebook->GetPageCount() == 0) EnableCurrentProjectRibbon(false);
773 event.Skip();
774}
775
776void MainFrame::NotebookPageClosing(wxAuiNotebookEvent& event)
777{
778 auto it = m_workspaceList.begin();
779 while (it != m_workspaceList.end()) {
780 if (*it == m_auiNotebook->GetCurrentPage()) {
781 //if ((*it)->GetSharedGLContext() == m_sharedGLContext) m_sharedGLContext = nullptr;
782 m_workspaceList.erase(it);
783 break;
784 }
785 ++it;
786 }
787 //if (!m_sharedGLContext && m_workspaceList.size() != 0) {
788 // m_sharedGLContext = m_workspaceList[0]->GetSharedGLContext();
789 //}
790 event.Skip();
791}
792
793void MainFrame::OnRotClockClick(wxRibbonButtonBarEvent& event)
794{
795 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
796 if (workspace) { workspace->RotateSelectedElements(); }
797}
798
799void MainFrame::OnRotCounterClockClick(wxRibbonButtonBarEvent& event)
800{
801 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
802 if (workspace) { workspace->RotateSelectedElements(false); }
803}
804
805void MainFrame::OnGeneralSettingsClick(wxRibbonButtonBarEvent& event)
806{
807 GeneralPropertiesForm genPropForm(this, m_generalProperties);
808 genPropForm.SetInitialSize();
809 if (genPropForm.ShowModal() == wxID_OK) {
810 BuildElementsToolBar(m_generalProperties->GetGeneralPropertiesData().elementsToolbar);
811 }
812 for (auto& workspace : m_workspaceList) {
813 workspace->GetProperties()->SetGeneralPropertiesData(m_generalProperties->GetGeneralPropertiesData());
814 workspace->GetProperties()->SetGUIColourTheme();
815 workspace->SetColourTheme();
816 workspace->UpdateTextElements();
817 workspace->Redraw();
818 }
819}
820
821void MainFrame::OnSimulationSettingsClick(wxRibbonButtonBarEvent& event)
822{
823 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
824 if (workspace) {
825 SimulationsSettingsForm simulSettingsForm(this, workspace->GetProperties(), m_locale);
826 simulSettingsForm.SetInitialSize();
827 simulSettingsForm.ShowModal();
828 }
829}
830void MainFrame::OnFreqResponseClick(wxRibbonButtonBarEvent& event)
831{
832 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
833 if (workspace) { workspace->RunFrequencyResponse(); }
834}
835void MainFrame::OnHarmDistortionsClick(wxRibbonButtonBarEvent& event)
836{
837 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
838 if (workspace) { workspace->RunHarmonicDistortion(); }
839}
840
841void MainFrame::OnStabilityDropdown(wxRibbonButtonBarEvent& event) { event.PopupMenu(m_stabilityMenu); }
842
843void MainFrame::OnStabilityMenuClick(wxCommandEvent& event)
844{
845 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
846
847 if (workspace) {
848 auto elementList = workspace->GetElementList();
849
850 switch (event.GetId()) {
851 case ID_STABMENU_LIST: {
852 StabilityEventList stabEventList(this, elementList);
853 stabEventList.ShowModal();
854 } break;
855 }
856 }
857}
858
859void MainFrame::OnSnapshotMenuClick(wxCommandEvent& event)
860{
861 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
862
863 if (workspace) {
864 auto elementList = workspace->GetElementList();
865
866 switch (event.GetId()) {
867 case ID_SNAPSHOTMENU_LIST: {
868 // Save SVG file
869 wxFileDialog saveFileDialog(this, _("Save diagram as SVG"), "", "", "SVG files (*.svg)|*.svg",
870 wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
871 if (saveFileDialog.ShowModal() == wxID_CANCEL) return;
872 workspace->ExportAsSVG(saveFileDialog.GetPath());
873 } break;
874 }
875 }
876}
877
878int MainFrame::RunPSPTest()
879{
880 wxMessageOutput::Get()->Printf("Main frame setup OK!\n");
881
882 // Emulate new project creation
883 EnableCurrentProjectRibbon();
884
885 Workspace* newWorkspace = new Workspace(this, wxString::Format(_("New project %d"), m_projectNumber),
886 this->GetStatusBar(), this->GetAuiNotebook());
887 //if (!m_sharedGLContext) {
888 // m_sharedGLContext = newWorkspace->GetSharedGLContext();
889 //}
890 m_workspaceList.push_back(newWorkspace);
891
892 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_DISABLESOL, true);
893 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_ENABLESOL, false);
894
895 m_auiNotebook->AddPage(newWorkspace, newWorkspace->GetName(), true);
896 newWorkspace->Redraw();
897
898 wxMessageOutput::Get()->Printf("Project creation OK!\n");
899 wxMessageOutput::Get()->Printf("Test done!\n");
900
901 return 0;
902}
903void MainFrame::OnClose(wxCloseEvent& event)
904{
905 // Setup the workspace closing correctly
906
907 wxMessageDialog dialog(this,
908 _("Are you sure you want to close the program?\nAny unsaved changes will be lost."),
909 _("Closing PSP-UFU..."),
910 wxYES_NO | wxICON_EXCLAMATION);
911
912 if (dialog.ShowModal() == wxID_YES) {
913 if (!m_workspaceList.empty())
914 m_workspaceList[m_workspaceList.size() - 1]->Show();
915 event.Skip();
916 }
917 else event.Skip(false);
918}
919void MainFrame::OnHeatmapClick(wxRibbonButtonBarEvent& event)
920{
921 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
922 if (workspace) {
923 const bool enabled = workspace->IsHeatMapEnable();
924 m_ribbonButtonBarReports->ToggleButton(ID_RIBBON_HEATMAP, !enabled);
925 workspace->EnableHeatMap(!enabled);
926 }
927}
928void MainFrame::OnGridClick(wxRibbonButtonBarEvent& event)
929{
930 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
931 if (workspace) {
932 const bool enabled = workspace->IsGridEnabled();
933 m_ribbonButtonBarCircuit->ToggleButton(ID_RIBBON_GRID, !enabled);
934 workspace->EnableGrid(!enabled);
935 workspace->Redraw();
936 }
937}
938void MainFrame::OnAlignClick(wxRibbonButtonBarEvent& event)
939{
940 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
941 if (workspace) {
942 workspace->AlignSelectedToGrid();
943 }
944}
945void MainFrame::OnNotebookPageChanged(wxAuiNotebookEvent& event)
946{
947 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
948 if (workspace) {
949 m_ribbonButtonBarCircuit->ToggleButton(ID_RIBBON_GRID, workspace->IsGridEnabled());
950 m_ribbonButtonBarReports->ToggleButton(ID_RIBBON_HEATMAP, workspace->IsHeatMapEnable());
951 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_ENABLESOL, workspace->IsContinuousCalculationActive());
952 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_DISABLESOL, !workspace->IsContinuousCalculationActive());
953 }
954}
955void MainFrame::OnProjectSettingsClick(wxRibbonButtonBarEvent& event)
956{
957 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
958 if (workspace) {
959 ProjectPropertiesForm ppf(this, workspace);
960 ppf.ShowModal();
961 workspace->UpdateHeatMap();
962 workspace->Redraw();
963 }
964}
965void MainFrame::OnSnapshotDropdown(wxRibbonButtonBarEvent& event)
966{
967 event.PopupMenu(m_snapshotMenu);
968}
969void MainFrame::OnLabelMngrClick(wxRibbonButtonBarEvent& event)
970{
971 Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
972 if (workspace) {
973 LabelManager labelMngr(this, workspace);
974
975 if (labelMngr.ShowModal() == wxID_OK) {
976 workspace->UpdateTextElements();
977 workspace->Redraw();
978 }
979 }
980}
981
982void MainFrame::PositionElementsToolBar()
983{
984 if (!m_elementsToolBar) return;
985 //wxRect frameRect = GetScreenRect();
986 //wxSize tbSize = m_elementsToolBar->GetSize();
987 //if (tbSize.GetWidth() <= 0 || tbSize.GetHeight() <= 0) {
988 // tbSize = m_elementsToolBar->GetBestSize();
989 //}
990 //int x = frameRect.GetRight() - tbSize.GetWidth() - 25;
991 //int y = frameRect.GetTop() + 165;
992 //if (x < frameRect.GetLeft()) x = frameRect.GetLeft() + 10;
993 //if (y < frameRect.GetTop()) y = frameRect.GetTop() + 10;
994 //m_elementsToolBar->SetPosition(wxPoint(x, y));
995 wxPoint pos = GetPosition() + wxPoint(20, m_ribbonBar->GetSize().GetHeight() + 70);
996 m_elementsToolBar->Move(pos);
997}
998
999void MainFrame::BuildElementsToolBar(ElementsToolbar style)
1000{
1001 if (style != NONE) {
1002 delete m_elementsToolBar;
1003 //if (!m_elementsToolBarPositioned) {
1004 m_elementsToolBar = new ElementsToolBar(this, style == VERTICAL);
1005 PositionElementsToolBar();
1006 m_elementsToolBarPositioned = true;
1007 //}
1008 m_elementsToolBar->Show();
1009 m_elementsToolBar->Raise();
1010 }
1011 else {
1012 if (!m_elementsToolBar) return;
1013 m_elementsToolBar->Hide();
1014 }
1015}
1016
1017void MainFrame::OnElementsToolBarClosed()
1018{
1019 if (m_generalProperties) {
1020 auto data = m_generalProperties->GetGeneralPropertiesData();
1021 data.elementsToolbar = NONE;
1022 m_generalProperties->SetGeneralPropertiesData(data);
1023 PropertiesData::SaveConfigFile(data);
1024 }
1025}
wxPoint2DDouble GetPosition() const
Get the element position.
Definition Element.h:189
virtual void StartMove(wxPoint2DDouble position)
Update the element attributes related to the movement.
Definition Element.cpp:335
bool IsSelected() const
Checks if the element is selected.
Definition Element.h:204
Save and opens the projects created on disk.
Definition FileHanding.h:43
~MainFrame()
Default destructor.
Definition MainFrame.cpp:86
MainFrame()
Default constructor.
Definition MainFrame.cpp:53
General and simulation data manager.
This class manages the graphical and power elements. It is responsible for handling the user's intera...
Definition Workspace.h:105