36#include "forms/ProjectPropertiesForm.h"
38#include "forms/StabilityEventList.h"
39#include "forms/LabelManager.h"
46#include "extLibs/artProvider/ArtMetro.h"
54 m_generalProperties = initProperties;
59 EnableCurrentProjectRibbon();
60 Workspace* newWorkspace =
new Workspace(
this, _(
"Open project"), this->GetStatusBar(), this->GetAuiNotebook());
64 if (fileHandling.OpenProject(openPath)) {
65 newWorkspace->SetSavedPath(openPath);
67 m_workspaceList.push_back(newWorkspace);
69 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_DISABLESOL,
true);
70 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_ENABLESOL,
false);
72 m_auiNotebook->AddPage(newWorkspace, newWorkspace->GetName(),
true);
73 m_auiNotebook->Layout();
74 newWorkspace->Redraw();
75 newWorkspace->SetJustOpened(
true);
87 if (m_addElementsMenu) {
88 m_addElementsMenu->Disconnect(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OnAddElementsClick),
90 delete m_addElementsMenu;
92 if (m_stabilityMenu) {
93 m_stabilityMenu->Disconnect(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OnStabilityMenuClick),
95 delete m_stabilityMenu;
98 m_snapshotMenu->Disconnect(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OnSnapshotMenuClick),
100 delete m_snapshotMenu;
103 if (m_locale)
delete m_locale;
104 if (m_generalProperties)
delete m_generalProperties;
107void MainFrame::Init()
109 this->SetSize(800, 600);
111 CreateDropdownMenus();
113 EnableCurrentProjectRibbon(
false);
115 m_artMetro =
new wxRibbonMetroArtProvider();
116 m_ribbonBar->SetArtProvider(m_artMetro);
117 m_ribbonBar->Realize();
122void MainFrame::EnableCurrentProjectRibbon(
bool enable)
124 m_ribbonButtonBarCircuit->EnableButton(ID_RIBBON_ADDELEMENT, enable);
125 m_ribbonButtonBarReports->EnableButton(ID_RIBBON_CHARTS, enable);
126 m_ribbonButtonBarCProject->EnableButton(ID_RIBBON_CLOSE, enable);
127 m_ribbonButtonBarClipboard->EnableButton(ID_RIBBON_COPY, enable);
128 m_ribbonButtonBarReports->EnableButton(ID_RIBBON_DATAREPORT, enable);
129 m_ribbonButtonBarCircuit->EnableButton(ID_RIBBON_DELETE, enable);
130 m_ribbonButtonBarContinuous->EnableButton(ID_RIBBON_DISABLESOL, enable);
131 m_ribbonButtonBarCircuit->EnableButton(ID_RIBBON_DRAG, enable);
132 m_ribbonButtonBarContinuous->EnableButton(ID_RIBBON_ENABLESOL, enable);
133 m_ribbonButtonBarSimulations->EnableButton(ID_RIBBON_FAULT, enable);
134 m_ribbonButtonBarCircuit->EnableButton(ID_RIBBON_FIT, enable);
135 m_ribbonButtonBarCircuit->EnableButton(ID_RIBBON_MOVE, enable);
136 m_ribbonButtonBarClipboard->EnableButton(ID_RIBBON_PASTE, enable);
137 m_ribbonButtonBarSimulations->EnableButton(ID_RIBBON_POWERFLOW, enable);
138 m_ribbonButtonBarClipboard->EnableButton(ID_RIBBON_REDO, enable);
139 m_ribbonButtonBarContinuous->EnableButton(ID_RIBBON_RESETVOLT, enable);
140 m_ribbonButtonBarSimulations->EnableButton(ID_RIBBON_RUNSTAB, enable);
141 m_ribbonButtonBarCProject->EnableButton(ID_RIBBON_SAVE, enable);
142 m_ribbonButtonBarCProject->EnableButton(ID_RIBBON_SAVEAS, enable);
143 m_ribbonButtonBarSimulations->EnableButton(ID_RIBBON_SCPOWER, enable);
144 m_ribbonButtonBarCircuit->EnableButton(ID_RIBBON_PROJSETTINGS, enable);
145 m_ribbonButtonBarReports->EnableButton(ID_RIBBON_SNAPSHOT, enable);
146 m_ribbonButtonBarSimulations->EnableButton(ID_RIBBON_SIMULSETTINGS, enable);
147 m_ribbonButtonBarClipboard->EnableButton(ID_RIBBON_UNDO, enable);
148 m_ribbonButtonBarCircuit->EnableButton(ID_RIBBON_ROTATEC, enable);
149 m_ribbonButtonBarCircuit->EnableButton(ID_RIBBON_ROTATECC, enable);
150 m_ribbonButtonBarSimulations->EnableButton(ID_RIBBON_HARMDIST, enable);
151 m_ribbonButtonBarSimulations->EnableButton(ID_RIBBON_FREQRESP, enable);
159void MainFrame::CreateDropdownMenus()
161 m_addElementsMenu =
new wxMenu();
163 wxMenuItem* busElement =
164 new wxMenuItem(m_addElementsMenu, ID_ADDMENU_BUS, _(
"&Bus\tB"), _(
"Adds a bus at the circuit"));
166 wxMenuItem* lineElement =
167 new wxMenuItem(m_addElementsMenu, ID_ADDMENU_LINE, _(
"&Line\tL"), _(
"Adds a power line at the circuit"));
168 wxMenuItem* transformerElement =
new wxMenuItem(m_addElementsMenu, ID_ADDMENU_TRANSFORMER, _(
"&Transformer\tT"),
169 _(
"Adds a transformer at the circuit"));
170 wxMenuItem* generatorElement =
new wxMenuItem(m_addElementsMenu, ID_ADDMENU_GENERATOR, _(
"&Generator\tG"),
171 _(
"Adds a generator at the circuit"));
172 wxMenuItem* indMotorElement =
new wxMenuItem(m_addElementsMenu, ID_ADDMENU_INDMOTOR, _(
"&Induction motor\tI"),
173 _(
"Adds an induction motor at the circuit"));
174 wxMenuItem* syncCompElement =
175 new wxMenuItem(m_addElementsMenu, ID_ADDMENU_SYNCCOMP, _(
"&Synchronous compensator \tK"),
176 _(
"Adds an induction motor at the circuit"));
177 wxMenuItem* loadElement =
178 new wxMenuItem(m_addElementsMenu, ID_ADDMENU_LOAD, _(
"&Load\tShift-L"), _(
"Adds a load at the circuit"));
179 wxMenuItem* capacitorElement =
new wxMenuItem(m_addElementsMenu, ID_ADDMENU_CAPACITOR, _(
"&Capacitor\tShift-C"),
180 _(
"Adds a shunt capacitor at the circuit"));
181 wxMenuItem* inductorElement =
new wxMenuItem(m_addElementsMenu, ID_ADDMENU_INDUCTOR, _(
"&Inductor\tShift-I"),
182 _(
"Adds a shunt inductor at the circuit"));
183 wxMenuItem* harmCurrentElement =
184 new wxMenuItem(m_addElementsMenu, ID_ADDMENU_HARMCURRENT, _(
"&Harmonic current\tShift-H"),
185 _(
"Adds a harmonic current source at the circuit"));
186 wxMenuItem* emtElement =
187 new wxMenuItem(m_addElementsMenu, ID_ADDMENU_EMTELEMENT, _(
"&Electromagnetic Transient Element\tShift-E"), _(
"Adds an electromagnetic transient element that connects with ATP"));
188 wxMenuItem* textElement =
189 new wxMenuItem(m_addElementsMenu, ID_ADDMENU_TEXT, _(
"&Label\tA"), _(
"Adds a linked element label"));
192 m_addElementsMenu->Append(busElement);
193 m_addElementsMenu->Append(lineElement);
194 m_addElementsMenu->Append(transformerElement);
195 m_addElementsMenu->Append(generatorElement);
196 m_addElementsMenu->Append(indMotorElement);
197 m_addElementsMenu->Append(syncCompElement);
198 m_addElementsMenu->Append(loadElement);
199 m_addElementsMenu->Append(capacitorElement);
200 m_addElementsMenu->Append(inductorElement);
201 m_addElementsMenu->Append(harmCurrentElement);
202 m_addElementsMenu->Append(emtElement);
203 m_addElementsMenu->Append(textElement);
205 m_addElementsMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnAddElementsClick,
this);
207 m_stabilityMenu =
new wxMenu();
209 wxMenuItem* stabilityList =
new wxMenuItem(m_stabilityMenu, ID_STABMENU_LIST, _(
"&Stability event list"),
210 _(
"Show the stability event list"));
211 m_stabilityMenu->Append(stabilityList);
213 m_stabilityMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnStabilityMenuClick,
this);
215 m_snapshotMenu =
new wxMenu();
217 wxMenuItem* snapshotList =
new wxMenuItem(m_stabilityMenu, ID_SNAPSHOTMENU_LIST, _(
"&Export as SVG"),
218 _(
"Export the diagram as SVG file."));
219 m_snapshotMenu->Append(snapshotList);
221 m_snapshotMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnSnapshotMenuClick,
this);
224void MainFrame::OnNewClick(wxRibbonButtonBarEvent& event)
226 EnableCurrentProjectRibbon();
230 newWorkspace =
new Workspace(
this, wxString::Format(_(
"New project %d"), m_projectNumber),
231 this->GetStatusBar(), this->GetAuiNotebook());
239 newWorkspace->GetProperties()->SetGeneralPropertiesData(m_generalProperties->GetGeneralPropertiesData());
241 m_workspaceList.push_back(newWorkspace);
243 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_DISABLESOL,
true);
244 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_ENABLESOL,
false);
246 m_auiNotebook->AddPage(newWorkspace, newWorkspace->GetName(),
true);
247 newWorkspace->Redraw();
248 newWorkspace->SetJustOpened(
true);
252void MainFrame::OnAboutClick(wxRibbonButtonBarEvent& event)
258void MainFrame::OnAddElementDropdown(wxRibbonButtonBarEvent& event) {
event.PopupMenu(m_addElementsMenu); }
259void MainFrame::OnChartsClick(wxRibbonButtonBarEvent& event)
261 if (
Workspace* workspace =
dynamic_cast<Workspace*
>(m_auiNotebook->GetCurrentPage())) {
262 std::vector<ElementPlotData> plotDataList;
263 auto elementList = workspace->GetElementList();
264 for (
auto it = elementList.begin(), itEnd = elementList.end(); it != itEnd; ++it) {
267 if (powerElement->GetPlotData(plotData)) plotDataList.push_back(plotData);
270 ChartView* cView =
new ChartView(workspace, plotDataList, workspace->GetStabilityTimeVector(), m_generalProperties->GetGeneralPropertiesData().plotLib);
275void MainFrame::OnCloseClick(wxRibbonButtonBarEvent& event)
277 auto it = m_workspaceList.begin();
278 while (it != m_workspaceList.end()) {
279 if (*it == m_auiNotebook->GetCurrentPage()) {
281 m_workspaceList.erase(it);
282 m_auiNotebook->DeletePage(m_auiNotebook->GetPageIndex(m_auiNotebook->GetCurrentPage()));
290 if (m_workspaceList.empty()) {
291 EnableCurrentProjectRibbon(
false);
294void MainFrame::OnCopyClick(wxRibbonButtonBarEvent& event)
297 if (workspace) { workspace->CopySelection(); }
300void MainFrame::OnDataReportClick(wxRibbonButtonBarEvent& event)
302 if (
Workspace* workspace =
dynamic_cast<Workspace*
>(m_auiNotebook->GetCurrentPage())) {
307void MainFrame::OnDeleteClick(wxRibbonButtonBarEvent& event)
310 if (workspace) { workspace->DeleteSelectedElements(); }
312void MainFrame::OnDisableSolutionClick(wxRibbonButtonBarEvent& event)
314 if (
Workspace* workspace =
dynamic_cast<Workspace*
>(m_auiNotebook->GetCurrentPage())) {
315 workspace->SetContinuousCalculationActive(
false);
317 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_DISABLESOL,
true);
318 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_ENABLESOL,
false);
321void MainFrame::OnDragClick(wxRibbonButtonBarEvent& event)
325 workspace->SetWorkspaceMode(Workspace::WorkspaceMode::MODE_DRAG);
329void MainFrame::OnEnableSolutionClick(wxRibbonButtonBarEvent& event)
331 if (
Workspace* workspace =
dynamic_cast<Workspace*
>(m_auiNotebook->GetCurrentPage())) {
332 workspace->SetContinuousCalculationActive(
true);
333 workspace->RunStaticStudies();
335 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_ENABLESOL,
true);
336 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_DISABLESOL,
false);
340void MainFrame::OnFaultClick(wxRibbonButtonBarEvent& event)
342 if (
Workspace* workspace =
dynamic_cast<Workspace*
>(m_auiNotebook->GetCurrentPage())) { workspace->RunFault(); }
345void MainFrame::OnFitClick(wxRibbonButtonBarEvent& event)
348 if (workspace) { workspace->Fit(); }
351void MainFrame::OnMoveClick(wxRibbonButtonBarEvent& event)
355 auto elementList = workspace->GetAllElements();
357 wxPoint2DDouble averagePos(0, 0);
358 int numSelElements = 0;
359 for (
auto it = elementList.begin(), itEnd = elementList.end(); it != itEnd; ++it) {
366 averagePos = wxPoint2DDouble(averagePos.m_x /
double(numSelElements), averagePos.m_y /
double(numSelElements));
368 for (
auto it = elementList.begin(), itEnd = elementList.end(); it != itEnd; ++it) {
372 workspace->SetWorkspaceMode(Workspace::WorkspaceMode::MODE_MOVE_ELEMENT);
376void MainFrame::OnOpenClick(wxRibbonButtonBarEvent& event)
378 wxFileDialog openFileDialog(
this, _(
"Open PSP file"),
"",
"",
"PSP files (*.psp)|*.psp",
379 wxFD_OPEN | wxFD_FILE_MUST_EXIST);
380 if (openFileDialog.ShowModal() == wxID_CANCEL)
return;
382 wxFileName fileName(openFileDialog.GetPath());
384 EnableCurrentProjectRibbon();
388 newWorkspace =
new Workspace(
this, wxString::Format(_(
"New project %d"), m_projectNumber),
389 this->GetStatusBar(), this->GetAuiNotebook());
399 newWorkspace->GetProperties()->SetGeneralPropertiesData(m_generalProperties->GetGeneralPropertiesData());
402 if (fileHandling.OpenProject(fileName)) {
403 newWorkspace->SetSavedPath(fileName);
405 m_workspaceList.push_back(newWorkspace);
407 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_DISABLESOL,
true);
408 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_ENABLESOL,
false);
410 m_auiNotebook->AddPage(newWorkspace, newWorkspace->GetName(),
true);
411 m_auiNotebook->Layout();
412 newWorkspace->Redraw();
413 newWorkspace->SetJustOpened(
true);
414 newWorkspace->SaveCurrentState();
419 wxMessageDialog msgDialog(
this, _(
"It was not possible to open the selected file."), _(
"Error"),
420 wxOK | wxCENTRE | wxICON_ERROR);
421 msgDialog.ShowModal();
426void MainFrame::OnPSPGuideClick(wxRibbonButtonBarEvent& event)
428 wxLaunchDefaultBrowser(
"https://thales1330.github.io/PSP/docs/");
430void MainFrame::OnPasteClick(wxRibbonButtonBarEvent& event)
433 if (workspace) { workspace->Paste(); }
436void MainFrame::OnPowerFlowClick(wxRibbonButtonBarEvent& event)
439 if (workspace) { workspace->RunPowerFlow(); }
442void MainFrame::OnRedoClick(wxRibbonButtonBarEvent& event)
446 workspace->SetNextState();
449void MainFrame::OnResetVoltagesClick(wxRibbonButtonBarEvent& event)
452 if (workspace) { workspace->ResetAllVoltages(); }
455void MainFrame::OnRunStabilityClick(wxRibbonButtonBarEvent& event)
458 if (workspace) { workspace->RunStability(); }
461void MainFrame::OnSCPowerClick(wxRibbonButtonBarEvent& event)
464 if (workspace) { workspace->RunSCPower(); }
467void MainFrame::OnSaveAsClick(wxRibbonButtonBarEvent& event)
473 wxFileDialog saveFileDialog(
this, _(
"Save PSP file"),
"",
"",
"PSP files (*.psp)|*.psp",
474 wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
475 if (saveFileDialog.ShowModal() == wxID_CANCEL)
return;
477 fileHandling.SaveProject(saveFileDialog.GetPath());
478 wxFileName fileName(saveFileDialog.GetPath());
479 workspace->SetName(fileName.GetName());
480 m_auiNotebook->SetPageText(m_auiNotebook->GetPageIndex(workspace), workspace->GetName());
481 workspace->SetSavedPath(fileName);
485void MainFrame::OnSaveClick(wxRibbonButtonBarEvent& event)
491 if (workspace->GetSavedPath().IsOk()) {
492 fileHandling.SaveProject(workspace->GetSavedPath());
495 wxFileDialog saveFileDialog(
this, _(
"Save PSP file"),
"",
"",
"PSP files (*.psp)|*.psp",
496 wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
497 if (saveFileDialog.ShowModal() == wxID_CANCEL)
return;
499 fileHandling.SaveProject(saveFileDialog.GetPath());
500 wxFileName fileName(saveFileDialog.GetPath());
501 workspace->SetName(fileName.GetName());
502 m_auiNotebook->SetPageText(m_auiNotebook->GetPageIndex(workspace), workspace->GetName());
503 workspace->SetSavedPath(fileName);
508void MainFrame::OnSnapshotClick(wxRibbonButtonBarEvent& event)
512 workspace->CopyToClipboard();
516void MainFrame::OnUndoClick(wxRibbonButtonBarEvent& event)
520 workspace->SetPreviousState();
524void MainFrame::OnAddElementsClick(wxCommandEvent& event)
529 if (workspace->GetWorkspaceMode() != Workspace::WorkspaceMode::MODE_INSERT) {
530 auto elementList = workspace->GetElementSharedList();
531 auto textList = workspace->GetTextList();
532 wxString statusBarText =
"";
533 bool newElement =
false;
536 switch (event.GetId()) {
537 case ID_ADDMENU_BUS: {
538 auto newBus = std::make_shared<Bus>(wxPoint2DDouble(0, 0),
539 wxString::Format(_(
"Bus %d"), workspace->GetElementNumber(ID_BUS)));
540 workspace->IncrementElementNumber(ID_BUS);
541 elementList.push_back(newBus);
542 statusBarText = _(
"Insert Bus: Click to insert, ESC to cancel.");
545 case ID_ADDMENU_LINE: {
546 auto newLine = std::make_shared<Line>(wxString::Format(_(
"Line %d"), workspace->GetElementNumber(ID_LINE)));
547 elementList.push_back(newLine);
548 workspace->IncrementElementNumber(ID_LINE);
549 statusBarText = _(
"Insert Line: Click on two buses, ESC to cancel.");
552 case ID_ADDMENU_TRANSFORMER: {
553 auto newTransformer = std::make_shared <Transformer>(
554 wxString::Format(_(
"Transformer %d"), workspace->GetElementNumber(ID_TRANSFORMER)));
555 workspace->IncrementElementNumber(ID_TRANSFORMER);
556 elementList.push_back(newTransformer);
557 statusBarText = _(
"Insert Transformer: Click on two buses, ESC to cancel.");
560 case ID_ADDMENU_GENERATOR: {
561 auto newGenerator = std::make_shared<SyncGenerator>(
562 wxString::Format(_(
"Generator %d"), workspace->GetElementNumber(ID_SYNCGENERATOR)));
563 workspace->IncrementElementNumber(ID_SYNCGENERATOR);
564 elementList.push_back(newGenerator);
565 statusBarText = _(
"Insert Generator: Click on a bus, ESC to cancel.");
568 case ID_ADDMENU_LOAD: {
569 auto newLoad = std::make_shared<Load>(wxString::Format(_(
"Load %d"), workspace->GetElementNumber(ID_LOAD)));
570 workspace->IncrementElementNumber(ID_LOAD);
571 elementList.push_back(newLoad);
572 statusBarText = _(
"Insert Load: Click on a bus, ESC to cancel.");
575 case ID_ADDMENU_CAPACITOR: {
576 auto newCapacitor = std::make_shared<Capacitor>(wxString::Format(_(
"Capacitor %d"), workspace->GetElementNumber(ID_CAPACITOR)));
577 workspace->IncrementElementNumber(ID_CAPACITOR);
578 elementList.push_back(newCapacitor);
579 statusBarText = _(
"Insert Capacitor: Click on a bus, ESC to cancel.");
582 case ID_ADDMENU_INDUCTOR: {
583 auto newInductor = std::make_shared<Inductor>(wxString::Format(_(
"Inductor %d"), workspace->GetElementNumber(ID_INDUCTOR)));
584 workspace->IncrementElementNumber(ID_INDUCTOR);
585 elementList.push_back(newInductor);
586 statusBarText = _(
"Insert Inductor: Click on a bus, ESC to cancel.");
589 case ID_ADDMENU_HARMCURRENT: {
590 auto newHarmCurrent = std::make_shared<HarmCurrent>(
591 wxString::Format(_(
"Harmonic Current %d"), workspace->GetElementNumber(ID_INDUCTOR)));
592 workspace->IncrementElementNumber(ID_HARMCURRENT);
593 elementList.push_back(newHarmCurrent);
594 statusBarText = _(
"Insert Harmonic Current Source: Click on a bus, ESC to cancel.");
597 case ID_ADDMENU_INDMOTOR: {
598 auto newIndMotor = std::make_shared<IndMotor>(
599 wxString::Format(_(
"Induction motor %d"), workspace->GetElementNumber(ID_INDMOTOR)));
600 workspace->IncrementElementNumber(ID_INDMOTOR);
601 elementList.push_back(newIndMotor);
602 statusBarText = _(
"Insert Induction Motor: Click on a bus, ESC to cancel.");
605 case ID_ADDMENU_SYNCCOMP: {
606 auto newSyncCondenser = std::make_shared<SyncMotor>(
607 wxString::Format(_(
"Synchronous condenser %d"), workspace->GetElementNumber(ID_SYNCMOTOR)));
608 workspace->IncrementElementNumber(ID_SYNCMOTOR);
609 elementList.push_back(newSyncCondenser);
610 statusBarText = _(
"Insert Synchronous Condenser: Click on a bus, ESC to cancel.");
613 case ID_ADDMENU_EMTELEMENT: {
614 auto newEMTElement = std::make_shared<EMTElement>(wxString::Format(_(
"Electromagnetic Transient %d"), workspace->GetElementNumber(ID_EMTELEMENT)));
615 workspace->IncrementElementNumber(ID_EMTELEMENT);
616 elementList.push_back(newEMTElement);
617 statusBarText = _(
"Insert Electromagnetic Transient Element: Click on a bus, ESC to cancel.");
620 case ID_ADDMENU_TEXT: {
622 auto newText = std::make_shared<Text>();
623 textList.push_back(newText);
624 statusBarText = _(
"Insert Label: Click to insert, ESC to cancel.");
630 workspace->SetElementList(elementList);
631 workspace->SetTextList(textList);
633 workspace->SetWorkspaceMode(Workspace::WorkspaceMode::MODE_INSERT);
635 workspace->SetWorkspaceMode(Workspace::WorkspaceMode::MODE_INSERT_TEXT);
636 workspace->SetStatusBarText(statusBarText);
643void MainFrame::OnImportClick(wxRibbonButtonBarEvent& event)
649 EnableCurrentProjectRibbon();
653 newWorkspace =
new Workspace(
this, wxString::Format(_(
"New project %d"), m_projectNumber),
654 this->GetStatusBar(), this->GetAuiNotebook());
662 newWorkspace->GetProperties()->SetGeneralPropertiesData(m_generalProperties->GetGeneralPropertiesData());
664 m_workspaceList.push_back(newWorkspace);
666 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_DISABLESOL,
true);
667 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_ENABLESOL,
false);
669 m_auiNotebook->AddPage(newWorkspace, newWorkspace->GetName(),
true);
670 newWorkspace->Redraw();
675 if (importForm.ShowModal() == wxID_OK) {
676 m_auiNotebook->Layout();
677 newWorkspace->Redraw();
678 newWorkspace->SetJustOpened(
true);
683void MainFrame::NotebookPageClosed(wxAuiNotebookEvent& event)
685 if (m_auiNotebook->GetPageCount() == 0) EnableCurrentProjectRibbon(
false);
689void MainFrame::NotebookPageClosing(wxAuiNotebookEvent& event)
691 auto it = m_workspaceList.begin();
692 while (it != m_workspaceList.end()) {
693 if (*it == m_auiNotebook->GetCurrentPage()) {
695 m_workspaceList.erase(it);
706void MainFrame::OnRotClockClick(wxRibbonButtonBarEvent& event)
709 if (workspace) { workspace->RotateSelectedElements(); }
712void MainFrame::OnRotCounterClockClick(wxRibbonButtonBarEvent& event)
715 if (workspace) { workspace->RotateSelectedElements(
false); }
718void MainFrame::OnGeneralSettingsClick(wxRibbonButtonBarEvent& event)
721 genPropForm.SetInitialSize();
722 genPropForm.ShowModal();
723 for (
auto& workspace : m_workspaceList) {
724 workspace->GetProperties()->SetGeneralPropertiesData(m_generalProperties->GetGeneralPropertiesData());
725 workspace->UpdateTextElements();
730void MainFrame::OnSimulationSettingsClick(wxRibbonButtonBarEvent& event)
735 simulSettingsForm.SetInitialSize();
736 simulSettingsForm.ShowModal();
739void MainFrame::OnFreqResponseClick(wxRibbonButtonBarEvent& event)
742 if (workspace) { workspace->RunFrequencyResponse(); }
744void MainFrame::OnHarmDistortionsClick(wxRibbonButtonBarEvent& event)
747 if (workspace) { workspace->RunHarmonicDistortion(); }
750void MainFrame::OnStabilityDropdown(wxRibbonButtonBarEvent& event) {
event.PopupMenu(m_stabilityMenu); }
752void MainFrame::OnStabilityMenuClick(wxCommandEvent& event)
757 auto elementList = workspace->GetElementList();
759 switch (event.GetId()) {
760 case ID_STABMENU_LIST: {
762 stabEventList.ShowModal();
768void MainFrame::OnSnapshotMenuClick(wxCommandEvent& event)
773 auto elementList = workspace->GetElementList();
775 switch (event.GetId()) {
776 case ID_SNAPSHOTMENU_LIST: {
778 wxFileDialog saveFileDialog(
this, _(
"Save diagram as SVG"),
"",
"",
"SVG files (*.svg)|*.svg",
779 wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
780 if (saveFileDialog.ShowModal() == wxID_CANCEL)
return;
781 workspace->ExportAsSVG(saveFileDialog.GetPath());
787int MainFrame::RunPSPTest()
789 wxMessageOutput::Get()->Printf(
"Main frame setup OK!\n");
792 EnableCurrentProjectRibbon();
794 Workspace* newWorkspace =
new Workspace(
this, wxString::Format(_(
"New project %d"), m_projectNumber),
795 this->GetStatusBar(), this->GetAuiNotebook());
799 m_workspaceList.push_back(newWorkspace);
801 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_DISABLESOL,
true);
802 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_ENABLESOL,
false);
804 m_auiNotebook->AddPage(newWorkspace, newWorkspace->GetName(),
true);
805 newWorkspace->Redraw();
807 wxMessageOutput::Get()->Printf(
"Project creation OK!\n");
808 wxMessageOutput::Get()->Printf(
"Test done!\n");
812void MainFrame::OnClose(wxCloseEvent& event)
816 wxMessageDialog dialog(
this,
817 _(
"Are you sure you want to close the program?\nAny unsaved changes will be lost."),
818 _(
"Closing PSP-UFU..."),
819 wxYES_NO | wxICON_EXCLAMATION);
821 if (dialog.ShowModal() == wxID_YES) {
822 if (!m_workspaceList.empty())
823 m_workspaceList[m_workspaceList.size() - 1]->Show();
826 else event.Skip(
false);
828void MainFrame::OnHeatmapClick(wxRibbonButtonBarEvent& event)
832 const bool enabled = workspace->IsHeatMapEnable();
833 m_ribbonButtonBarReports->ToggleButton(ID_RIBBON_HEATMAP, !enabled);
834 workspace->EnableHeatMap(!enabled);
837void MainFrame::OnNotebookPageChanged(wxAuiNotebookEvent& event)
841 m_ribbonButtonBarReports->ToggleButton(ID_RIBBON_HEATMAP, workspace->IsHeatMapEnable());
842 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_ENABLESOL, workspace->IsContinuousCalculationActive());
843 m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_DISABLESOL, !workspace->IsContinuousCalculationActive());
846void MainFrame::OnProjectSettingsClick(wxRibbonButtonBarEvent& event)
852 workspace->UpdateHeatMap();
856void MainFrame::OnSnapshotDropdown(wxRibbonButtonBarEvent& event)
858 event.PopupMenu(m_snapshotMenu);
860void MainFrame::OnLabelMngrClick(wxRibbonButtonBarEvent& event)
866 if (labelMngr.ShowModal() == wxID_OK) {
867 workspace->UpdateTextElements();
This class is responsible to manage the charts generated in the transient electromechanical studies.
Form that shows the results of power flow and fault calculations.
Base class of all elements of the program. This class is responsible for manage graphical and his dat...
wxPoint2DDouble GetPosition() const
Get the element position.
virtual void StartMove(wxPoint2DDouble position)
Update the element attributes related to the movement.
bool IsSelected() const
Checks if the element is selected.
Save and opens the projects created on disk.
~MainFrame()
Default destructor.
MainFrame()
Default constructor.
Abstract class of power elements.
General and simulation data manager.
This class manages the graphical and power elements. It is responsible for handling the user's intera...