Skip to content

Commit

Permalink
Fix wrong number of cores + code de-duplication (#793)
Browse files Browse the repository at this point in the history
* Fix wrong number of cores + code de-duplication

* PR remarks + small refactor (template)
  • Loading branch information
flomnes authored Aug 23, 2022
1 parent ac4f7f4 commit 5a9ee2f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 67 deletions.
76 changes: 14 additions & 62 deletions src/ui/simulator/windows/options/advanced/advanced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Data::ncMin>),
nullptr,
this);

Expand All @@ -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<Data::ncLow>),
nullptr,
this);

Expand All @@ -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<Data::ncAvg>),
nullptr,
this);

Expand All @@ -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<Data::ncHigh>),
nullptr,
this);

Expand All @@ -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<Data::ncMax>),
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<Data::NumberOfCoresMode level>
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*)
Expand Down
11 changes: 6 additions & 5 deletions src/ui/simulator/windows/options/advanced/advanced.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Antares::Data::NumberOfCoresMode>
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);
Expand Down

0 comments on commit 5a9ee2f

Please sign in to comment.