diff options
author | Thales Lima Oliveira <thaleslima.ufu@gmail.com> | 2020-07-07 23:12:04 -0300 |
---|---|---|
committer | Thales Lima Oliveira <thaleslima.ufu@gmail.com> | 2020-07-07 23:12:04 -0300 |
commit | ab30228b1a57053323363674fa7f137c0329a180 (patch) | |
tree | 50849a3680d61a2428665cc1035f1f4215870acb /Project/MainFrame.cpp | |
parent | 6c0e98a2727d07e1fbb38b78c27d68e98ad09465 (diff) | |
download | PSP.git-ab30228b1a57053323363674fa7f137c0329a180.tar.gz PSP.git-ab30228b1a57053323363674fa7f137c0329a180.tar.xz PSP.git-ab30228b1a57053323363674fa7f137c0329a180.zip |
Voltage heat map implemented
Voltage heat map implemented using modern OpenGL =)
New external library required:
-GLEW
-GLFW
-GLM (incorporeted at the source)
Old memory leaks fixed =)
Diffstat (limited to 'Project/MainFrame.cpp')
-rw-r--r-- | Project/MainFrame.cpp | 439 |
1 files changed, 257 insertions, 182 deletions
diff --git a/Project/MainFrame.cpp b/Project/MainFrame.cpp index 345d10b..d695ad7 100644 --- a/Project/MainFrame.cpp +++ b/Project/MainFrame.cpp @@ -29,6 +29,8 @@ #include "Line.h" #include "Load.h" #include "MainFrame.h" + +#include "ProjectPropertiesForm.h" #include "PropertiesData.h" #include "SimulationsSettingsForm.h" #include "StabilityEventList.h" @@ -48,13 +50,13 @@ MainFrame::MainFrame(wxWindow* parent, wxLocale* locale, PropertiesData* initPro Init(); - if(openPath != "") { + if (openPath != "") { EnableCurrentProjectRibbon(); Workspace* newWorkspace = new Workspace(this, _("Open project"), this->GetStatusBar(), m_sharedGLContext); - if(!m_sharedGLContext) m_sharedGLContext = newWorkspace->GetSharedGLContext(); + if (!m_sharedGLContext) m_sharedGLContext = newWorkspace->GetSharedGLContext(); FileHanding fileHandling(newWorkspace); - if(fileHandling.OpenProject(openPath)) { + if (fileHandling.OpenProject(openPath)) { newWorkspace->SetSavedPath(openPath); m_workspaceList.push_back(newWorkspace); @@ -74,19 +76,21 @@ MainFrame::MainFrame(wxWindow* parent, wxLocale* locale, PropertiesData* initPro MainFrame::~MainFrame() { - // if(m_artMetro) delete m_artMetro; - if(m_addElementsMenu) { + if (!m_sharedGLContext && m_workspaceList.size() != 0) { + m_sharedGLContext = m_workspaceList[0]->GetSharedGLContext(); + } + if (m_addElementsMenu) { m_addElementsMenu->Disconnect(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OnAddElementsClick), - nullptr, this); + nullptr, this); delete m_addElementsMenu; } - if(m_stabilityMenu) { + if (m_stabilityMenu) { m_stabilityMenu->Disconnect(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OnStabilityMenuClick), - nullptr, this); + nullptr, this); delete m_stabilityMenu; } - if(m_locale) delete m_locale; - if(m_generalProperties) delete m_generalProperties; + if (m_locale) delete m_locale; + if (m_generalProperties) delete m_generalProperties; } void MainFrame::Init() @@ -134,6 +138,11 @@ void MainFrame::EnableCurrentProjectRibbon(bool enable) m_ribbonButtonBarCircuit->EnableButton(ID_RIBBON_ROTATECC, enable); m_ribbonButtonBarSimulations->EnableButton(ID_RIBBON_HARMDIST, enable); m_ribbonButtonBarSimulations->EnableButton(ID_RIBBON_FREQRESP, enable); + + if (m_generalProperties->GetGeneralPropertiesData().useOpenGL) + m_ribbonButtonBarReports->EnableButton(ID_RIBBON_HEATMAP, enable); + else + m_ribbonButtonBarReports->EnableButton(ID_RIBBON_HEATMAP, false); } void MainFrame::CreateDropdownMenus() @@ -146,23 +155,23 @@ void MainFrame::CreateDropdownMenus() wxMenuItem* lineElement = new wxMenuItem(m_addElementsMenu, ID_ADDMENU_LINE, _("&Line\tL"), _("Adds a power line at the circuit")); wxMenuItem* transformerElement = new wxMenuItem(m_addElementsMenu, ID_ADDMENU_TRANSFORMER, _("&Transformer\tT"), - _("Adds a transformer at the circuit")); + _("Adds a transformer at the circuit")); wxMenuItem* generatorElement = new wxMenuItem(m_addElementsMenu, ID_ADDMENU_GENERATOR, _("&Generator\tG"), - _("Adds a generator at the circuit")); + _("Adds a generator at the circuit")); wxMenuItem* indMotorElement = new wxMenuItem(m_addElementsMenu, ID_ADDMENU_INDMOTOR, _("&Induction motor\tI"), - _("Adds an induction motor at the circuit")); + _("Adds an induction motor at the circuit")); wxMenuItem* syncCompElement = new wxMenuItem(m_addElementsMenu, ID_ADDMENU_SYNCCOMP, _("&Synchronous compensator \tK"), - _("Adds an induction motor at the circuit")); + _("Adds an induction motor at the circuit")); wxMenuItem* loadElement = new wxMenuItem(m_addElementsMenu, ID_ADDMENU_LOAD, _("&Load\tShift-L"), _("Adds a load at the circuit")); wxMenuItem* capacitorElement = new wxMenuItem(m_addElementsMenu, ID_ADDMENU_CAPACITOR, _("&Capacitor\tShift-C"), - _("Adds a shunt capacitor at the circuit")); + _("Adds a shunt capacitor at the circuit")); wxMenuItem* inductorElement = new wxMenuItem(m_addElementsMenu, ID_ADDMENU_INDUCTOR, _("&Inductor\tShift-I"), - _("Adds a shunt inductor at the circuit")); + _("Adds a shunt inductor at the circuit")); wxMenuItem* harmCurrentElement = new wxMenuItem(m_addElementsMenu, ID_ADDMENU_HARMCURRENT, _("&Harmonic current\tShift-H"), - _("Adds a harmonic current source at the circuit")); + _("Adds a harmonic current source at the circuit")); wxMenuItem* textElement = new wxMenuItem(m_addElementsMenu, ID_ADDMENU_TEXT, _("&Text\tA"), _("Adds a linked text element")); @@ -183,7 +192,7 @@ void MainFrame::CreateDropdownMenus() m_stabilityMenu = new wxMenu(); wxMenuItem* stabilityList = new wxMenuItem(m_stabilityMenu, ID_STABMENU_LIST, _("&Stability event list"), - _("Show the stability event list")); + _("Show the stability event list")); m_stabilityMenu->Append(stabilityList); m_stabilityMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnStabilityMenuClick, this); @@ -200,12 +209,12 @@ void MainFrame::OnNewClick(wxRibbonButtonBarEvent& event) if (!m_sharedGLContext) m_sharedGLContext = newWorkspace->GetSharedGLContext(); } else { - newWorkspace = new WorkspaceDC(this, wxString::Format(_("New project %d"), m_projectNumber), - this->GetStatusBar()); + newWorkspace = new WorkspaceDC(this, wxString::Format(_("New project %d"), m_projectNumber), + this->GetStatusBar()); } // Set general properties in new Workspace newWorkspace->GetProperties()->SetGeneralPropertiesData(m_generalProperties->GetGeneralPropertiesData()); - + m_workspaceList.push_back(newWorkspace); m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_DISABLESOL, true); @@ -213,6 +222,7 @@ void MainFrame::OnNewClick(wxRibbonButtonBarEvent& event) m_auiNotebook->AddPage(newWorkspace, newWorkspace->GetName(), true); newWorkspace->Redraw(); + newWorkspace->SetJustOpened(true); m_projectNumber++; } @@ -225,13 +235,13 @@ void MainFrame::OnAboutClick(wxRibbonButtonBarEvent& event) void MainFrame::OnAddElementDropdown(wxRibbonButtonBarEvent& event) { event.PopupMenu(m_addElementsMenu); } void MainFrame::OnChartsClick(wxRibbonButtonBarEvent& event) { - if(Workspace* workspace = dynamic_cast<Workspace*>(m_auiNotebook->GetCurrentPage())) { + if (Workspace* workspace = dynamic_cast<Workspace*>(m_auiNotebook->GetCurrentPage())) { std::vector<ElementPlotData> plotDataList; auto elementList = workspace->GetElementList(); - for(auto it = elementList.begin(), itEnd = elementList.end(); it != itEnd; ++it) { - if(PowerElement* powerElement = dynamic_cast<PowerElement*>(*it)) { + for (auto it = elementList.begin(), itEnd = elementList.end(); it != itEnd; ++it) { + if (PowerElement* powerElement = dynamic_cast<PowerElement*>(*it)) { ElementPlotData plotData; - if(powerElement->GetPlotData(plotData)) plotDataList.push_back(plotData); + if (powerElement->GetPlotData(plotData)) plotDataList.push_back(plotData); } } ChartView* cView = new ChartView(workspace, plotDataList, workspace->GetStabilityTimeVector()); @@ -243,7 +253,7 @@ void MainFrame::OnCloseClick(wxRibbonButtonBarEvent& event) {} void MainFrame::OnCopyClick(wxRibbonButtonBarEvent& event) {} void MainFrame::OnDataReportClick(wxRibbonButtonBarEvent& event) { - if(Workspace* workspace = dynamic_cast<Workspace*>(m_auiNotebook->GetCurrentPage())) { + if (Workspace* workspace = dynamic_cast<Workspace*>(m_auiNotebook->GetCurrentPage())) { DataReport* dataReport = new DataReport(workspace, workspace); dataReport->Show(); } @@ -251,11 +261,11 @@ void MainFrame::OnDataReportClick(wxRibbonButtonBarEvent& event) void MainFrame::OnDeleteClick(wxRibbonButtonBarEvent& event) { Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage()); - if(workspace) { workspace->DeleteSelectedElements(); } + if (workspace) { workspace->DeleteSelectedElements(); } } void MainFrame::OnDisableSolutionClick(wxRibbonButtonBarEvent& event) { - if(Workspace* workspace = dynamic_cast<Workspace*>(m_auiNotebook->GetCurrentPage())) { + if (Workspace* workspace = dynamic_cast<Workspace*>(m_auiNotebook->GetCurrentPage())) { workspace->SetContinuousCalculationActive(false); } m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_DISABLESOL, true); @@ -265,7 +275,7 @@ void MainFrame::OnDisableSolutionClick(wxRibbonButtonBarEvent& event) void MainFrame::OnDragClick(wxRibbonButtonBarEvent& event) {} void MainFrame::OnEnableSolutionClick(wxRibbonButtonBarEvent& event) { - if(Workspace* workspace = dynamic_cast<Workspace*>(m_auiNotebook->GetCurrentPage())) { + if (Workspace* workspace = dynamic_cast<Workspace*>(m_auiNotebook->GetCurrentPage())) { workspace->SetContinuousCalculationActive(true); workspace->RunStaticStudies(); } @@ -276,35 +286,35 @@ void MainFrame::OnEnableSolutionClick(wxRibbonButtonBarEvent& event) // void MainFrame::OnExpImpClick(wxRibbonButtonBarEvent& event) {} void MainFrame::OnFaultClick(wxRibbonButtonBarEvent& event) { - if(Workspace* workspace = dynamic_cast<Workspace*>(m_auiNotebook->GetCurrentPage())) { workspace->RunFault(); } + if (Workspace* workspace = dynamic_cast<Workspace*>(m_auiNotebook->GetCurrentPage())) { workspace->RunFault(); } } void MainFrame::OnFitClick(wxRibbonButtonBarEvent& event) { Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage()); - if(workspace) { workspace->Fit(); } + if (workspace) { workspace->Fit(); } } void MainFrame::OnMoveClick(wxRibbonButtonBarEvent& event) { Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage()); - if(workspace) { + if (workspace) { auto elementList = workspace->GetAllElements(); // Calculate the average position of selected elements. wxPoint2DDouble averagePos(0, 0); int numSelElements = 0; - for(auto it = elementList.begin(), itEnd = elementList.end(); it != itEnd; ++it) { + for (auto it = elementList.begin(), itEnd = elementList.end(); it != itEnd; ++it) { Element* element = *it; - if(element->IsSelected()) { + if (element->IsSelected()) { averagePos += element->GetPosition(); numSelElements++; } } averagePos = wxPoint2DDouble(averagePos.m_x / double(numSelElements), averagePos.m_y / double(numSelElements)); // Set the move position to the average of selected elements. - for(auto it = elementList.begin(), itEnd = elementList.end(); it != itEnd; ++it) { + for (auto it = elementList.begin(), itEnd = elementList.end(); it != itEnd; ++it) { Element* element = *it; - if(element->IsSelected()) { element->StartMove(averagePos); } + if (element->IsSelected()) { element->StartMove(averagePos); } } workspace->SetWorkspaceMode(Workspace::WorkspaceMode::MODE_MOVE_ELEMENT); } @@ -313,30 +323,30 @@ void MainFrame::OnMoveClick(wxRibbonButtonBarEvent& event) void MainFrame::OnOpenClick(wxRibbonButtonBarEvent& event) { wxFileDialog openFileDialog(this, _("Open PSP file"), "", "", "PSP files (*.psp)|*.psp", - wxFD_OPEN | wxFD_FILE_MUST_EXIST); - if(openFileDialog.ShowModal() == wxID_CANCEL) return; + wxFD_OPEN | wxFD_FILE_MUST_EXIST); + if (openFileDialog.ShowModal() == wxID_CANCEL) return; wxFileName fileName(openFileDialog.GetPath()); EnableCurrentProjectRibbon(); - Workspace* newWorkspace; - if (m_generalProperties->GetGeneralPropertiesData().useOpenGL) { - newWorkspace = new Workspace(this, wxString::Format(_("New project %d"), m_projectNumber), - this->GetStatusBar(), m_sharedGLContext); - // If none shared OpenGL context is loaded, get from this workspace. - if (!m_sharedGLContext) m_sharedGLContext = newWorkspace->GetSharedGLContext(); - } - else { - newWorkspace = new WorkspaceDC(this, wxString::Format(_("New project %d"), m_projectNumber), - this->GetStatusBar()); - } - - // Set general properties in new workspace. - newWorkspace->GetProperties()->SetGeneralPropertiesData(m_generalProperties->GetGeneralPropertiesData()); - + Workspace* newWorkspace; + if (m_generalProperties->GetGeneralPropertiesData().useOpenGL) { + newWorkspace = new Workspace(this, wxString::Format(_("New project %d"), m_projectNumber), + this->GetStatusBar(), m_sharedGLContext); + // If none shared OpenGL context is loaded, get from this workspace. + if (!m_sharedGLContext) m_sharedGLContext = newWorkspace->GetSharedGLContext(); + } + else { + newWorkspace = new WorkspaceDC(this, wxString::Format(_("New project %d"), m_projectNumber), + this->GetStatusBar()); + } + + // Set general properties in new workspace. + newWorkspace->GetProperties()->SetGeneralPropertiesData(m_generalProperties->GetGeneralPropertiesData()); + FileHanding fileHandling(newWorkspace); - if(fileHandling.OpenProject(fileName)) { + if (fileHandling.OpenProject(fileName)) { newWorkspace->SetSavedPath(fileName); m_workspaceList.push_back(newWorkspace); @@ -350,9 +360,10 @@ void MainFrame::OnOpenClick(wxRibbonButtonBarEvent& event) newWorkspace->SetJustOpened(true); newWorkspace->Fit(); m_projectNumber++; - } else { + } + else { wxMessageDialog msgDialog(this, _("It was not possible to open the selected file."), _("Error"), - wxOK | wxCENTRE | wxICON_ERROR); + wxOK | wxCENTRE | wxICON_ERROR); msgDialog.ShowModal(); delete newWorkspace; } @@ -363,7 +374,7 @@ void MainFrame::OnPasteClick(wxRibbonButtonBarEvent& event) {} void MainFrame::OnPowerFlowClick(wxRibbonButtonBarEvent& event) { Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage()); - if(workspace) { workspace->RunPowerFlow(); } + if (workspace) { workspace->RunPowerFlow(); } } void MainFrame::OnRedoClick(wxRibbonButtonBarEvent& event) {} @@ -371,24 +382,24 @@ void MainFrame::OnResetVoltagesClick(wxRibbonButtonBarEvent& event) {} void MainFrame::OnRunStabilityClick(wxRibbonButtonBarEvent& event) { Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage()); - if(workspace) { workspace->RunStability(); } + if (workspace) { workspace->RunStability(); } } void MainFrame::OnSCPowerClick(wxRibbonButtonBarEvent& event) { Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage()); - if(workspace) { workspace->RunSCPower(); } + if (workspace) { workspace->RunSCPower(); } } void MainFrame::OnSaveAsClick(wxRibbonButtonBarEvent& event) { Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage()); - if(workspace) { + if (workspace) { FileHanding fileHandling(workspace); wxFileDialog saveFileDialog(this, _("Save PSP file"), "", "", "PSP files (*.psp)|*.psp", - wxFD_SAVE | wxFD_OVERWRITE_PROMPT); - if(saveFileDialog.ShowModal() == wxID_CANCEL) return; + wxFD_SAVE | wxFD_OVERWRITE_PROMPT); + if (saveFileDialog.ShowModal() == wxID_CANCEL) return; fileHandling.SaveProject(saveFileDialog.GetPath()); wxFileName fileName(saveFileDialog.GetPath()); @@ -401,15 +412,16 @@ void MainFrame::OnSaveAsClick(wxRibbonButtonBarEvent& event) void MainFrame::OnSaveClick(wxRibbonButtonBarEvent& event) { Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage()); - if(workspace) { + if (workspace) { FileHanding fileHandling(workspace); - if(workspace->GetSavedPath().IsOk()) { + if (workspace->GetSavedPath().IsOk()) { fileHandling.SaveProject(workspace->GetSavedPath()); - } else { + } + else { wxFileDialog saveFileDialog(this, _("Save PSP file"), "", "", "PSP files (*.psp)|*.psp", - wxFD_SAVE | wxFD_OVERWRITE_PROMPT); - if(saveFileDialog.ShowModal() == wxID_CANCEL) return; + wxFD_SAVE | wxFD_OVERWRITE_PROMPT); + if (saveFileDialog.ShowModal() == wxID_CANCEL) return; fileHandling.SaveProject(saveFileDialog.GetPath()); wxFileName fileName(saveFileDialog.GetPath()); @@ -426,93 +438,93 @@ void MainFrame::OnAddElementsClick(wxCommandEvent& event) { Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage()); - if(workspace) { - if(workspace->GetWorkspaceMode() != Workspace::WorkspaceMode::MODE_INSERT) { + if (workspace) { + if (workspace->GetWorkspaceMode() != Workspace::WorkspaceMode::MODE_INSERT) { auto elementList = workspace->GetElementList(); wxString statusBarText = ""; bool newElement = false; - switch(event.GetId()) { - case ID_ADDMENU_BUS: { - Bus* newBus = new Bus(wxPoint2DDouble(0, 0), - wxString::Format(_("Bus %d"), workspace->GetElementNumber(ID_BUS))); - workspace->IncrementElementNumber(ID_BUS); - elementList.push_back(newBus); - statusBarText = _("Insert Bus: Click to insert, ESC to cancel."); - newElement = true; - } break; - case ID_ADDMENU_LINE: { - Line* newLine = new Line(wxString::Format(_("Line %d"), workspace->GetElementNumber(ID_LINE))); - elementList.push_back(newLine); - workspace->IncrementElementNumber(ID_LINE); - statusBarText = _("Insert Line: Click on two buses, ESC to cancel."); - newElement = true; - } break; - case ID_ADDMENU_TRANSFORMER: { - Transformer* newTransformer = new Transformer( - wxString::Format(_("Transformer %d"), workspace->GetElementNumber(ID_TRANSFORMER))); - workspace->IncrementElementNumber(ID_TRANSFORMER); - elementList.push_back(newTransformer); - statusBarText = _("Insert Transformer: Click on two buses, ESC to cancel."); - newElement = true; - } break; - case ID_ADDMENU_GENERATOR: { - SyncGenerator* newGenerator = new SyncGenerator( - wxString::Format(_("Generator %d"), workspace->GetElementNumber(ID_SYNCGENERATOR))); - workspace->IncrementElementNumber(ID_SYNCGENERATOR); - elementList.push_back(newGenerator); - statusBarText = _("Insert Generator: Click on a buses, ESC to cancel."); - newElement = true; - } break; - case ID_ADDMENU_LOAD: { - Load* newLoad = new Load(wxString::Format(_("Load %d"), workspace->GetElementNumber(ID_LOAD))); - workspace->IncrementElementNumber(ID_LOAD); - elementList.push_back(newLoad); - statusBarText = _("Insert Load: Click on a buses, ESC to cancel."); - newElement = true; - } break; - case ID_ADDMENU_CAPACITOR: { - Capacitor* newCapacitor = - new Capacitor(wxString::Format(_("Capacitor %d"), workspace->GetElementNumber(ID_CAPACITOR))); - workspace->IncrementElementNumber(ID_CAPACITOR); - elementList.push_back(newCapacitor); - statusBarText = _("Insert Capacitor: Click on a buses, ESC to cancel."); - newElement = true; - } break; - case ID_ADDMENU_INDUCTOR: { - Inductor* newInductor = - new Inductor(wxString::Format(_("Inductor %d"), workspace->GetElementNumber(ID_INDUCTOR))); - workspace->IncrementElementNumber(ID_INDUCTOR); - elementList.push_back(newInductor); - statusBarText = _("Insert Inductor: Click on a buses, ESC to cancel."); - newElement = true; - } break; - case ID_ADDMENU_HARMCURRENT: { - HarmCurrent* newHarmCurrent = new HarmCurrent( - wxString::Format(_("Harmonic Current %d"), workspace->GetElementNumber(ID_INDUCTOR))); - workspace->IncrementElementNumber(ID_HARMCURRENT); - elementList.push_back(newHarmCurrent); - statusBarText = _("Insert Harmonic Current Source: Click on a buses, ESC to cancel."); - newElement = true; - } break; - case ID_ADDMENU_INDMOTOR: { - IndMotor* newIndMotor = new IndMotor( - wxString::Format(_("Induction motor %d"), workspace->GetElementNumber(ID_INDMOTOR))); - workspace->IncrementElementNumber(ID_INDMOTOR); - elementList.push_back(newIndMotor); - statusBarText = _("Insert Induction Motor: Click on a buses, ESC to cancel."); - newElement = true; - } break; - case ID_ADDMENU_SYNCCOMP: { - SyncMotor* newSyncCondenser = new SyncMotor( - wxString::Format(_("Synchronous condenser %d"), workspace->GetElementNumber(ID_SYNCMOTOR))); - workspace->IncrementElementNumber(ID_SYNCMOTOR); - elementList.push_back(newSyncCondenser); - statusBarText = _("Insert Synchronous Condenser: Click on a buses, ESC to cancel."); - newElement = true; - } break; + switch (event.GetId()) { + case ID_ADDMENU_BUS: { + Bus* newBus = new Bus(wxPoint2DDouble(0, 0), + wxString::Format(_("Bus %d"), workspace->GetElementNumber(ID_BUS))); + workspace->IncrementElementNumber(ID_BUS); + elementList.push_back(newBus); + statusBarText = _("Insert Bus: Click to insert, ESC to cancel."); + newElement = true; + } break; + case ID_ADDMENU_LINE: { + Line* newLine = new Line(wxString::Format(_("Line %d"), workspace->GetElementNumber(ID_LINE))); + elementList.push_back(newLine); + workspace->IncrementElementNumber(ID_LINE); + statusBarText = _("Insert Line: Click on two buses, ESC to cancel."); + newElement = true; + } break; + case ID_ADDMENU_TRANSFORMER: { + Transformer* newTransformer = new Transformer( + wxString::Format(_("Transformer %d"), workspace->GetElementNumber(ID_TRANSFORMER))); + workspace->IncrementElementNumber(ID_TRANSFORMER); + elementList.push_back(newTransformer); + statusBarText = _("Insert Transformer: Click on two buses, ESC to cancel."); + newElement = true; + } break; + case ID_ADDMENU_GENERATOR: { + SyncGenerator* newGenerator = new SyncGenerator( + wxString::Format(_("Generator %d"), workspace->GetElementNumber(ID_SYNCGENERATOR))); + workspace->IncrementElementNumber(ID_SYNCGENERATOR); + elementList.push_back(newGenerator); + statusBarText = _("Insert Generator: Click on a buses, ESC to cancel."); + newElement = true; + } break; + case ID_ADDMENU_LOAD: { + Load* newLoad = new Load(wxString::Format(_("Load %d"), workspace->GetElementNumber(ID_LOAD))); + workspace->IncrementElementNumber(ID_LOAD); + elementList.push_back(newLoad); + statusBarText = _("Insert Load: Click on a buses, ESC to cancel."); + newElement = true; + } break; + case ID_ADDMENU_CAPACITOR: { + Capacitor* newCapacitor = + new Capacitor(wxString::Format(_("Capacitor %d"), workspace->GetElementNumber(ID_CAPACITOR))); + workspace->IncrementElementNumber(ID_CAPACITOR); + elementList.push_back(newCapacitor); + statusBarText = _("Insert Capacitor: Click on a buses, ESC to cancel."); + newElement = true; + } break; + case ID_ADDMENU_INDUCTOR: { + Inductor* newInductor = + new Inductor(wxString::Format(_("Inductor %d"), workspace->GetElementNumber(ID_INDUCTOR))); + workspace->IncrementElementNumber(ID_INDUCTOR); + elementList.push_back(newInductor); + statusBarText = _("Insert Inductor: Click on a buses, ESC to cancel."); + newElement = true; + } break; + case ID_ADDMENU_HARMCURRENT: { + HarmCurrent* newHarmCurrent = new HarmCurrent( + wxString::Format(_("Harmonic Current %d"), workspace->GetElementNumber(ID_INDUCTOR))); + workspace->IncrementElementNumber(ID_HARMCURRENT); + elementList.push_back(newHarmCurrent); + statusBarText = _("Insert Harmonic Current Source: Click on a buses, ESC to cancel."); + newElement = true; + } break; + case ID_ADDMENU_INDMOTOR: { + IndMotor* newIndMotor = new IndMotor( + wxString::Format(_("Induction motor %d"), workspace->GetElementNumber(ID_INDMOTOR))); + workspace->IncrementElementNumber(ID_INDMOTOR); + elementList.push_back(newIndMotor); + statusBarText = _("Insert Induction Motor: Click on a buses, ESC to cancel."); + newElement = true; + } break; + case ID_ADDMENU_SYNCCOMP: { + SyncMotor* newSyncCondenser = new SyncMotor( + wxString::Format(_("Synchronous condenser %d"), workspace->GetElementNumber(ID_SYNCMOTOR))); + workspace->IncrementElementNumber(ID_SYNCMOTOR); + elementList.push_back(newSyncCondenser); + statusBarText = _("Insert Synchronous Condenser: Click on a buses, ESC to cancel."); + newElement = true; + } break; } - if(newElement) { + if (newElement) { workspace->SetElementList(elementList); workspace->SetWorkspaceMode(Workspace::WorkspaceMode::MODE_INSERT); workspace->SetStatusBarText(statusBarText); @@ -525,44 +537,61 @@ void MainFrame::OnAddElementsClick(wxCommandEvent& event) void MainFrame::OnImportClick(wxRibbonButtonBarEvent& event) { // Create a new workspace to import - Workspace* impWorkspace = new Workspace(this, _("Imported project"), this->GetStatusBar(), m_sharedGLContext); - ImportForm importForm(this, impWorkspace); - if(importForm.ShowModal() == wxID_OK) { - // Import file(s) - EnableCurrentProjectRibbon(); + //Workspace* impWorkspace = new Workspace(this, _("Imported project"), this->GetStatusBar(), m_sharedGLContext); - if(!m_sharedGLContext) m_sharedGLContext = impWorkspace->GetSharedGLContext(); - m_workspaceList.push_back(impWorkspace); - m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_DISABLESOL, true); - m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_ENABLESOL, false); + EnableCurrentProjectRibbon(); + + Workspace* newWorkspace; + if (m_generalProperties->GetGeneralPropertiesData().useOpenGL) { + newWorkspace = new Workspace(this, wxString::Format(_("New project %d"), m_projectNumber), + this->GetStatusBar(), m_sharedGLContext); + if (!m_sharedGLContext) m_sharedGLContext = newWorkspace->GetSharedGLContext(); + } + else { + newWorkspace = new WorkspaceDC(this, wxString::Format(_("New project %d"), m_projectNumber), + this->GetStatusBar()); + } + // Set general properties in new Workspace + newWorkspace->GetProperties()->SetGeneralPropertiesData(m_generalProperties->GetGeneralPropertiesData()); + + m_workspaceList.push_back(newWorkspace); + + m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_DISABLESOL, true); + m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_ENABLESOL, false); - m_auiNotebook->AddPage(impWorkspace, impWorkspace->GetName(), true); + m_auiNotebook->AddPage(newWorkspace, newWorkspace->GetName(), true); + newWorkspace->Redraw(); + m_projectNumber++; + + + ImportForm importForm(this, newWorkspace); + if (importForm.ShowModal() == wxID_OK) { m_auiNotebook->Layout(); - impWorkspace->Redraw(); - impWorkspace->SetJustOpened(true); - impWorkspace->Fit(); - m_projectNumber++; + newWorkspace->Redraw(); + newWorkspace->SetJustOpened(true); + newWorkspace->Fit(); } } void MainFrame::NotebookPageClosed(wxAuiNotebookEvent& event) { - if(m_auiNotebook->GetPageCount() == 0) EnableCurrentProjectRibbon(false); + if (m_auiNotebook->GetPageCount() == 0) EnableCurrentProjectRibbon(false); + event.Skip(); } void MainFrame::NotebookPageClosing(wxAuiNotebookEvent& event) { auto it = m_workspaceList.begin(); - while(it != m_workspaceList.end()) { - if(*it == m_auiNotebook->GetCurrentPage()) { - if((*it)->GetSharedGLContext() == m_sharedGLContext) m_sharedGLContext = nullptr; + while (it != m_workspaceList.end()) { + if (*it == m_auiNotebook->GetCurrentPage()) { + if ((*it)->GetSharedGLContext() == m_sharedGLContext) m_sharedGLContext = nullptr; m_workspaceList.erase(it); break; } - it++; + ++it; } - if(!m_sharedGLContext && m_workspaceList.size() != 0) { + if (!m_sharedGLContext && m_workspaceList.size() != 0) { m_sharedGLContext = m_workspaceList[0]->GetSharedGLContext(); } event.Skip(); @@ -571,13 +600,13 @@ void MainFrame::NotebookPageClosing(wxAuiNotebookEvent& event) void MainFrame::OnRotClockClick(wxRibbonButtonBarEvent& event) { Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage()); - if(workspace) { workspace->RotateSelectedElements(); } + if (workspace) { workspace->RotateSelectedElements(); } } void MainFrame::OnRotCounterClockClick(wxRibbonButtonBarEvent& event) { Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage()); - if(workspace) { workspace->RotateSelectedElements(false); } + if (workspace) { workspace->RotateSelectedElements(false); } } void MainFrame::OnGeneralSettingsClick(wxRibbonButtonBarEvent& event) @@ -590,7 +619,7 @@ void MainFrame::OnGeneralSettingsClick(wxRibbonButtonBarEvent& event) void MainFrame::OnSimulationSettingsClick(wxRibbonButtonBarEvent& event) { Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage()); - if(workspace) { + if (workspace) { SimulationsSettingsForm simulSettingsForm(this, workspace->GetProperties()); simulSettingsForm.SetInitialSize(); simulSettingsForm.ShowModal(); @@ -599,12 +628,12 @@ void MainFrame::OnSimulationSettingsClick(wxRibbonButtonBarEvent& event) void MainFrame::OnFreqResponseClick(wxRibbonButtonBarEvent& event) { Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage()); - if(workspace) { workspace->RunFrequencyResponse(); } + if (workspace) { workspace->RunFrequencyResponse(); } } void MainFrame::OnHarmDistortionsClick(wxRibbonButtonBarEvent& event) { Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage()); - if(workspace) { workspace->RunHarmonicDistortion(); } + if (workspace) { workspace->RunHarmonicDistortion(); } } void MainFrame::OnStabilityDropdown(wxRibbonButtonBarEvent& event) { event.PopupMenu(m_stabilityMenu); } @@ -613,14 +642,14 @@ void MainFrame::OnStabilityMenuClick(wxCommandEvent& event) { Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage()); - if(workspace) { + if (workspace) { auto elementList = workspace->GetElementList(); - switch(event.GetId()) { - case ID_STABMENU_LIST: { - StabilityEventList stabEventList(this, elementList); - stabEventList.ShowModal(); - } break; + switch (event.GetId()) { + case ID_STABMENU_LIST: { + StabilityEventList stabEventList(this, elementList); + stabEventList.ShowModal(); + } break; } } } @@ -633,8 +662,10 @@ int MainFrame::RunPSPTest() EnableCurrentProjectRibbon(); Workspace* newWorkspace = new Workspace(this, wxString::Format(_("New project %d"), m_projectNumber), - this->GetStatusBar(), m_sharedGLContext); - if(!m_sharedGLContext) m_sharedGLContext = newWorkspace->GetSharedGLContext(); + this->GetStatusBar(), m_sharedGLContext); + if (!m_sharedGLContext) { + m_sharedGLContext = newWorkspace->GetSharedGLContext(); + } m_workspaceList.push_back(newWorkspace); m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_DISABLESOL, true); @@ -648,3 +679,47 @@ int MainFrame::RunPSPTest() return 0; } +void MainFrame::OnClose(wxCloseEvent& event) +{ + // Setup the workspace closing correctly + + wxMessageDialog dialog(this, + _("Are you sure you want to close the program?\nAny unsaved changes will be lost."), + _("Closing PSP-UFU..."), + wxYES_NO | wxICON_EXCLAMATION); + + if (dialog.ShowModal() == wxID_YES) { + if (!m_workspaceList.empty()) + m_workspaceList[m_workspaceList.size() - 1]->Show(); + event.Skip(); + } + else event.Skip(false); +} +void MainFrame::OnHeatmapClick(wxRibbonButtonBarEvent& event) +{ + Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage()); + if (workspace) { + const bool enabled = workspace->IsHeatMapEnable(); + m_ribbonButtonBarReports->ToggleButton(ID_RIBBON_HEATMAP, !enabled); + workspace->EnableHeatMap(!enabled); + } +} +void MainFrame::OnNotebookPageChanged(wxAuiNotebookEvent& event) +{ + Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage()); + if (workspace) { + m_ribbonButtonBarReports->ToggleButton(ID_RIBBON_HEATMAP, workspace->IsHeatMapEnable()); + m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_ENABLESOL, workspace->IsContinuousCalculationActive()); + m_ribbonButtonBarContinuous->ToggleButton(ID_RIBBON_DISABLESOL, !workspace->IsContinuousCalculationActive()); + } +} +void MainFrame::OnProjectSettingsClick(wxRibbonButtonBarEvent& event) +{ + Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage()); + if(workspace) { + ProjectPropertiesForm ppf(this, workspace); + ppf.ShowModal(); + workspace->UpdateHeatMap(); + workspace->Redraw(); + } +} |