From 0839b9100c79508e4c5784dd1c380a0b22b8bf00 Mon Sep 17 00:00:00 2001
From: Antoine Regimbeau <antoine.regimbeau@c-s.fr>
Date: Tue, 3 Apr 2018 11:35:59 +0200
Subject: [PATCH] ENH: add getters for default float and int value

---
 .../include/otbWrapperApplication.h           | 21 ++++++++-
 .../src/otbWrapperApplication.cxx             | 43 +++++++++++++++++++
 2 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h
index 4748ab0c5d..421ef9a4a7 100644
--- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h
+++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h
@@ -307,7 +307,7 @@ public:
    */
   bool IsParameterMissing(const std::string &key) const;
 
-  /* Set an default integer value, must used in the
+  /* Set a default integer value, must be used in the
    * DoInit when setting a value by default
    * for the parameter
    *
@@ -319,7 +319,17 @@ public:
    */
   void SetDefaultParameterInt(std::string parameter, int value);
 
-  /* Set a default floating value, must used in the
+  /* Get the default integer value of a parameter
+   *
+   * Can be called for types :
+   * \li ParameterType_Int
+   * \li ParameterType_Float
+   * \li ParameterType_Radius
+   * \li ParameterType_Choice
+   */
+  int GetDefaultParameterInt(std::string parameter);
+
+  /* Set a default floating value, must be used in the
    * DoInit when setting a value by default
    * for the parameter
    *
@@ -328,6 +338,13 @@ public:
    */
   void SetDefaultParameterFloat(std::string parameter, float value);
 
+  /* Get the default floating value of a parameter
+   *
+   * Can be called for types :
+   * \li ParameterType_Float
+   */
+  float GetDefaultParameterFloat(std::string parameter);
+
   /** Set a default pixel type for an output image parameter
    *
    * \param[in] parameter Name of the output image parameter
diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx
index 7aec4f8762..7dbba9892d 100644
--- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx
+++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx
@@ -1040,6 +1040,37 @@ void Application::SetDefaultParameterInt(std::string parameter, int value)
     }
 }
 
+int Application::GetDefaultParameterInt(std::string parameter)
+{
+  Parameter* param = GetParameterByKey(parameter);
+  int ret = 0 ;
+  if (dynamic_cast<RadiusParameter*>(param))
+    {
+    RadiusParameter* paramRadius = dynamic_cast<RadiusParameter*>(param);
+    ret = paramRadius->GetDefaultValue();
+    }
+   else if (dynamic_cast<IntParameter*>(param))
+    {
+    IntParameter* paramInt = dynamic_cast<IntParameter*>(param);
+    ret = paramInt->GetDefaultValue();
+    }
+  else if (dynamic_cast<FloatParameter*>(param))
+    {
+    FloatParameter* paramFloat = dynamic_cast<FloatParameter*>(param);
+    ret = paramFloat->GetDefaultValue();
+    }
+  else if (dynamic_cast<RAMParameter*>(param))
+    {
+    RAMParameter* paramRAM = dynamic_cast<RAMParameter*>(param);
+    ret = paramRAM->GetDefaultValue();
+    }
+  else
+    {
+    // log
+    }
+  return ret;
+}
+
 void Application::SetDefaultParameterFloat(std::string parameter, float value)
 {
   Parameter* param = GetParameterByKey(parameter);
@@ -1052,6 +1083,18 @@ void Application::SetDefaultParameterFloat(std::string parameter, float value)
     }
 }
 
+float Application::GetDefaultParameterFloat(std::string parameter)
+{
+  Parameter* param = GetParameterByKey(parameter);
+
+  if (dynamic_cast<FloatParameter*>(param))
+    {
+    FloatParameter* paramFloat = dynamic_cast<FloatParameter*>(param);
+    return paramFloat->GetDefaultValue();
+    }
+  return 0;
+}
+
 void Application::SetDefaultOutputPixelType(std::string parameter, ImagePixelType type)
 {
   Parameter* param = GetParameterByKey(parameter);
-- 
GitLab