From 5a9ee2fd28492e33794ae43806c26ace8658598d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Omn=C3=A8s?= Date: Tue, 23 Aug 2022 12:40:49 +0200 Subject: [PATCH] Fix wrong number of cores + code de-duplication (#793) * Fix wrong number of cores + code de-duplication * PR remarks + small refactor (template) --- .../windows/options/advanced/advanced.cpp | 76 ++++--------------- .../windows/options/advanced/advanced.h | 11 +-- 2 files changed, 20 insertions(+), 67 deletions(-) diff --git a/src/ui/simulator/windows/options/advanced/advanced.cpp b/src/ui/simulator/windows/options/advanced/advanced.cpp index 457a304da6..bb94630e9f 100644 --- a/src/ui/simulator/windows/options/advanced/advanced.cpp +++ b/src/ui/simulator/windows/options/advanced/advanced.cpp @@ -899,7 +899,7 @@ void AdvancedParameters::onNumberOfCores(Component::Button&, wxMenu& menu, void* it = Menu::CreateItem(&menu, wxID_ANY, text, "images/16x16/tag.png"); menu.Connect(it->GetId(), wxEVT_COMMAND_MENU_SELECTED, - wxCommandEventHandler(AdvancedParameters::onSelectNCmin), + wxCommandEventHandler(AdvancedParameters::onSelectNumberOfCoresLevel), nullptr, this); @@ -908,7 +908,7 @@ void AdvancedParameters::onNumberOfCores(Component::Button&, wxMenu& menu, void* it = Menu::CreateItem(&menu, wxID_ANY, text, "images/16x16/tag.png"); menu.Connect(it->GetId(), wxEVT_COMMAND_MENU_SELECTED, - wxCommandEventHandler(AdvancedParameters::onSelectNClow), + wxCommandEventHandler(AdvancedParameters::onSelectNumberOfCoresLevel), nullptr, this); @@ -918,7 +918,7 @@ void AdvancedParameters::onNumberOfCores(Component::Button&, wxMenu& menu, void* it = Menu::CreateItem(&menu, wxID_ANY, text, "images/16x16/tag.png"); menu.Connect(it->GetId(), wxEVT_COMMAND_MENU_SELECTED, - wxCommandEventHandler(AdvancedParameters::onSelectNCaverage), + wxCommandEventHandler(AdvancedParameters::onSelectNumberOfCoresLevel), nullptr, this); @@ -927,7 +927,7 @@ void AdvancedParameters::onNumberOfCores(Component::Button&, wxMenu& menu, void* it = Menu::CreateItem(&menu, wxID_ANY, text, "images/16x16/tag.png"); menu.Connect(it->GetId(), wxEVT_COMMAND_MENU_SELECTED, - wxCommandEventHandler(AdvancedParameters::onSelectNChigh), + wxCommandEventHandler(AdvancedParameters::onSelectNumberOfCoresLevel), nullptr, this); @@ -936,79 +936,31 @@ void AdvancedParameters::onNumberOfCores(Component::Button&, wxMenu& menu, void* it = Menu::CreateItem(&menu, wxID_ANY, text, "images/16x16/tag.png"); menu.Connect(it->GetId(), wxEVT_COMMAND_MENU_SELECTED, - wxCommandEventHandler(AdvancedParameters::onSelectNCmax), + wxCommandEventHandler(AdvancedParameters::onSelectNumberOfCoresLevel), nullptr, this); } -void AdvancedParameters::onSelectNCmin(wxCommandEvent& /* evt */) +void AdvancedParameters::onSelectNumberOfCoresLevel(Data::NumberOfCoresMode ncMode) { if (not Data::Study::Current::Valid()) return; - auto& study = *Data::Study::Current::Get(); - - if (study.parameters.nbCores.ncMode != Data::ncMin) - { - study.parameters.nbCores.ncMode = Data::ncMin; - MarkTheStudyAsModified(); - refresh(); - } -} - -void AdvancedParameters::onSelectNClow(wxCommandEvent& /* evt */) -{ - if (not Data::Study::Current::Valid()) - return; - auto& study = *Data::Study::Current::Get(); - - if (study.parameters.nbCores.ncMode != Data::ncLow) - { - study.parameters.nbCores.ncMode = Data::ncLow; - MarkTheStudyAsModified(); - refresh(); - } -} - -void AdvancedParameters::onSelectNCaverage(wxCommandEvent& /* evt */) -{ - if (not Data::Study::Current::Valid()) - return; - auto& study = *Data::Study::Current::Get(); + auto study = Data::Study::Current::Get(); - if (study.parameters.nbCores.ncMode != Data::ncAvg) + if (study->parameters.nbCores.ncMode != ncMode) { - study.parameters.nbCores.ncMode = Data::ncAvg; + study->parameters.nbCores.ncMode = ncMode; + // Force refresh for study->nbYearsParallelRaw + study->getNumberOfCores(false, 1 /* ignored */); MarkTheStudyAsModified(); refresh(); } } -void AdvancedParameters::onSelectNChigh(wxCommandEvent& /* evt */) +template +void AdvancedParameters::onSelectNumberOfCoresLevel(wxCommandEvent& /* evt */) { - if (not Data::Study::Current::Valid()) - return; - auto& study = *Data::Study::Current::Get(); - - if (study.parameters.nbCores.ncMode != Data::ncHigh) - { - study.parameters.nbCores.ncMode = Data::ncHigh; - MarkTheStudyAsModified(); - refresh(); - } -} - -void AdvancedParameters::onSelectNCmax(wxCommandEvent& /* evt */) -{ - if (not Data::Study::Current::Valid()) - return; - auto& study = *Data::Study::Current::Get(); - - if (study.parameters.nbCores.ncMode != Data::ncMax) - { - study.parameters.nbCores.ncMode = Data::ncMax; - MarkTheStudyAsModified(); - refresh(); - } + onSelectNumberOfCoresLevel(level); } void AdvancedParameters::onRenewableGenerationModelling(Component::Button&, wxMenu& menu, void*) diff --git a/src/ui/simulator/windows/options/advanced/advanced.h b/src/ui/simulator/windows/options/advanced/advanced.h index 156cf997af..a39d502abc 100644 --- a/src/ui/simulator/windows/options/advanced/advanced.h +++ b/src/ui/simulator/windows/options/advanced/advanced.h @@ -103,12 +103,13 @@ class AdvancedParameters final : public wxDialog void onSelectUCMixedIntegerLinearProblem(wxCommandEvent& evt); void onNumberOfCores(Component::Button&, wxMenu& menu, void*); - void onSelectNCmin(wxCommandEvent& evt); - void onSelectNClow(wxCommandEvent& evt); - void onSelectNCaverage(wxCommandEvent& evt); - void onSelectNChigh(wxCommandEvent& evt); - void onSelectNCmax(wxCommandEvent& evt); + template + void onSelectNumberOfCoresLevel(wxCommandEvent& evt); +private: + void onSelectNumberOfCoresLevel(Data::NumberOfCoresMode ncMode); + +public: void onRenewableGenerationModelling(Component::Button&, wxMenu& menu, void*); void onSelectRGMaggregated(wxCommandEvent& evt); void onSelectRGMrenewableClusters(wxCommandEvent& evt);