diff --git a/src/libs/antares/study/scenario-builder/hydroLevelsData.cpp b/src/libs/antares/study/scenario-builder/hydroLevelsData.cpp index 5aabfcec9d..40bfb1d019 100644 --- a/src/libs/antares/study/scenario-builder/hydroLevelsData.cpp +++ b/src/libs/antares/study/scenario-builder/hydroLevelsData.cpp @@ -36,8 +36,9 @@ namespace Data { namespace ScenarioBuilder { -hydroLevelsData::hydroLevelsData(std::string& iniFilePrefix) : -addToPrefix(iniFilePrefix) +hydroLevelsData::hydroLevelsData(std::string& iniFilePrefix, + std::function applyToTarget) : + addToPrefix(iniFilePrefix), applyToTarget_(applyToTarget) { } @@ -90,13 +91,7 @@ void hydroLevelsData::set_value(uint x, uint y, double value) bool hydroLevelsData::apply(Study& study) { - study.scenarioInitialHydroLevels.copyFrom(pHydroLevelsRules); - return true; -} - -bool hydroLevelsData::applyHydroLevels(Matrix& scenarioHydroLevels) const -{ - scenarioHydroLevels.copyFrom(pHydroLevelsRules); + applyToTarget_(study, pHydroLevelsRules); return true; } diff --git a/src/libs/antares/study/scenario-builder/hydroLevelsData.h b/src/libs/antares/study/scenario-builder/hydroLevelsData.h index f31b0d4643..70f615c632 100644 --- a/src/libs/antares/study/scenario-builder/hydroLevelsData.h +++ b/src/libs/antares/study/scenario-builder/hydroLevelsData.h @@ -28,6 +28,7 @@ #define __LIBS_STUDY_SCENARIO_BUILDER_DATA_HYDRO_LEVELS_H__ #include "scBuilderDataInterface.h" +#include namespace Antares { @@ -46,8 +47,9 @@ class hydroLevelsData final : public dataInterface public: // Constructor - - hydroLevelsData(std::string& iniFilePrefix); + + hydroLevelsData(std::string& iniFilePrefix, + std::function&)> applyToTarget); //! \name Data manupulation //@{ @@ -79,8 +81,7 @@ class hydroLevelsData final : public dataInterface void set_value(uint x, uint y, double value); - bool apply(Study& study); - bool applyHydroLevels(Matrix& scenarioHydroLevels) const; + bool apply(Study& study) override; private: //! Hydro levels overlay (0 if auto) @@ -88,6 +89,8 @@ class hydroLevelsData final : public dataInterface // prefix to be added when calling saveToINIFileHydroLevel std::string& addToPrefix; + std::function&)> applyToTarget_; + }; // class hydroLevelsData // class hydroLevelsData : inline functions @@ -114,6 +117,16 @@ inline double hydroLevelsData::get_value(uint x, uint y) const return pHydroLevelsRules.entry[y][x]; } +inline void initLevelApply(Study& study, Matrix& matrix) +{ + study.scenarioInitialHydroLevels.copyFrom(matrix); +} + +inline void finalLevelApply(Study& study, Matrix& matrix) +{ + study.scenarioFinalHydroLevels.copyFrom(matrix); +} + } // namespace ScenarioBuilder } // namespace Data } // namespace Antares diff --git a/src/libs/antares/study/scenario-builder/rules.cpp b/src/libs/antares/study/scenario-builder/rules.cpp index b455435bc9..0a673c6f28 100644 --- a/src/libs/antares/study/scenario-builder/rules.cpp +++ b/src/libs/antares/study/scenario-builder/rules.cpp @@ -379,8 +379,8 @@ bool Rules::apply() returned_status = renewable[i].apply(study_) && returned_status; returned_status = linksNTC[i].apply(study_) && returned_status; } - returned_status = hydroInitialLevels.applyHydroLevels(study_.scenarioInitialHydroLevels) && returned_status; - returned_status = hydroFinalLevels.applyHydroLevels(study_.scenarioFinalHydroLevels) && returned_status; + returned_status = hydroInitialLevels.apply(study_) && returned_status; + returned_status = hydroFinalLevels.apply(study_) && returned_status; returned_status = binding_constraints.apply(study_) && returned_status; } else diff --git a/src/libs/antares/study/scenario-builder/rules.h b/src/libs/antares/study/scenario-builder/rules.h index 1f97e01c46..2f90287b51 100644 --- a/src/libs/antares/study/scenario-builder/rules.h +++ b/src/libs/antares/study/scenario-builder/rules.h @@ -119,10 +119,10 @@ class Rules final : private Yuni::NonCopyable //! hydro initial levels std::string prefixInitial = "hl,"; - hydroLevelsData hydroInitialLevels = hydroLevelsData(prefixInitial); + hydroLevelsData hydroInitialLevels = hydroLevelsData(prefixInitial, initLevelApply); //! hydro final levels std::string prefixFinal = "hfl,"; - hydroLevelsData hydroFinalLevels = hydroLevelsData(prefixFinal); + hydroLevelsData hydroFinalLevels = hydroLevelsData(prefixFinal, finalLevelApply); // Links NTC std::vector linksNTC;