From 20a44cd04ae40bb9a21e798db4d895876f79601a Mon Sep 17 00:00:00 2001
From: Julien Malik <julien.malik@c-s.fr>
Date: Sun, 12 Jun 2011 12:16:02 +0200
Subject: [PATCH] ENH: wrap more Application method, remove Parameter and
 ParameterGroup, rename ApplicationRegistry to Registry

---
 Code/Wrappers/SWIG/otbApplication.i         | 70 ++++++++++++++++-----
 Code/Wrappers/SWIG/otbWrapperSWIGIncludes.h | 16 ++---
 Example/otbSmoothing.cxx                    |  1 -
 Testing/Python/PythonSmoothingTest.py       |  9 ++-
 4 files changed, 70 insertions(+), 26 deletions(-)

diff --git a/Code/Wrappers/SWIG/otbApplication.i b/Code/Wrappers/SWIG/otbApplication.i
index 415f17bf8d..dde9e6f7e8 100644
--- a/Code/Wrappers/SWIG/otbApplication.i
+++ b/Code/Wrappers/SWIG/otbApplication.i
@@ -15,22 +15,42 @@ namespace otb
 namespace Wrapper
 {
 
-enum DefaultValueMode
+  enum DefaultValueMode
   {
     UNKNOWN,
     RELATIVE,
     ABSOLUTE
   };
-
+  
+  typedef enum
+  {
+    ParameterType_Empty,
+    ParameterType_Int,
+    ParameterType_Float,
+    ParameterType_String,
+    ParameterType_Filename,
+    ParameterType_Directory,
+    ParameterType_Choice,
+    ParameterType_InputImage,
+    ParameterType_InputComplexImage,
+    ParameterType_InputVectorData,
+    ParameterType_OutputImage,
+    ParameterType_OutputVectorData,
+    ParameterType_Radius,
+    ParameterType_Group,
+  } ParameterType;
+  
+  typedef enum
+  {
+    UserLevel_Basic,
+    UserLevel_Advanced
+  } UserLevel;
 }
 }
 
-/** \class Parameter
- *  \brief This class represent a parameter for the wrapper framework
- *  This class is a high level class representing a parameter for the
- *  wrapper framework. It should be subclassed to represent different
- *  kinds of parameters 
- */
+
+
+/*
 class Parameter : public itkObject
 {
 public:
@@ -84,6 +104,7 @@ private:
   void operator =(const ParameterGroup&);
 };
 DECLARE_REF_COUNT_CLASS( ParameterGroup )
+*/
 
 class Application: public itkObject
 {
@@ -97,7 +118,22 @@ public:
   void Init();
   void UpdateParameters();
   void Execute();
-  ParameterGroup* GetParameterList();
+  void ExecuteAndWriteOutput();
+  
+//  ParameterGroup* GetParameterList();
+//  Parameter* GetParameterByKey(std::string parameter);
+//  const Parameter* GetParameterByKey(std::string parameter) const;
+  std::list<std::string> GetParametersKeys();
+  
+  void EnableParameter(std::string paramKey);
+  void DisableParameter(std::string paramKey);
+  bool IsParameterEnabled(std::string paramKey) const;
+  bool IsMandatory(std::string paramKey) const;
+  bool HasUserValue(std::string paramKey) const;
+  void ClearValue(std::string paramKey);
+  bool HasValue(std::string paramKey) const;
+  otb::Wrapper::UserLevel GetParameterUserLevel(std::string paramKey) const;
+  otb::Wrapper::ParameterType GetParameterType(std::string paramKey) const;
   
   void SetParameterInt(std::string parameter, int value);
   void SetParameterFloat(std::string parameter, float value);
@@ -110,7 +146,13 @@ public:
 protected:
   Application();
   virtual ~Application();
-
+  
+  void AddChoice(std::string paramKey, std::string paramName);
+  void AddParameter(otb::Wrapper::ParameterType type, std::string paramKey, std::string paramName);
+  void MandatoryOn(std::string paramKey);
+  void MandatoryOff(std::string paramKey);
+  void SetParameterUserLevel(std::string paramKey, otb::Wrapper::UserLevel level);
+  
 private:
   virtual void DoCreateParameters() = 0;
   virtual void DoUpdateParameters() = 0;
@@ -122,18 +164,18 @@ private:
 DECLARE_REF_COUNT_CLASS( Application )
 
 
-class ApplicationRegistry : public itkObject
+class Registry : public itkObject
 {
 public:
   static std::list<std::string> GetAvailableApplications();
   static Application_Pointer CreateApplication(const std::string& name);
 
 protected:
-  ApplicationRegistry();
-  virtual ~ApplicationRegistry();
+  Registry();
+  virtual ~Registry();
 
 private:
-  ApplicationRegistry(const Self&);
+  Registry(const Self&);
   void operator=(const Self&);
 };
 
diff --git a/Code/Wrappers/SWIG/otbWrapperSWIGIncludes.h b/Code/Wrappers/SWIG/otbWrapperSWIGIncludes.h
index 7d73314479..b37a7440e7 100644
--- a/Code/Wrappers/SWIG/otbWrapperSWIGIncludes.h
+++ b/Code/Wrappers/SWIG/otbWrapperSWIGIncludes.h
@@ -18,22 +18,22 @@
 #ifndef __otbWrapperSWIGIncludes_h
 #define __otbWrapperSWIGIncludes_h
 
-#include "otbWrapperParameter.h"
-#include "otbWrapperParameterGroup.h"
+//#include "otbWrapperParameter.h"
+//#include "otbWrapperParameterGroup.h"
 #include "otbWrapperApplication.h"
 #include "otbWrapperApplicationRegistry.h"
 
 
-typedef otb::Wrapper::Parameter                        Parameter;
-typedef otb::Wrapper::Parameter::Pointer::SmartPointer Parameter_Pointer;
+//typedef otb::Wrapper::Parameter                        Parameter;
+//typedef otb::Wrapper::Parameter::Pointer::SmartPointer Parameter_Pointer;
 
-typedef otb::Wrapper::ParameterGroup                        ParameterGroup;
-typedef otb::Wrapper::ParameterGroup::Pointer::SmartPointer ParameterGroup_Pointer;
+//typedef otb::Wrapper::ParameterGroup                        ParameterGroup;
+//typedef otb::Wrapper::ParameterGroup::Pointer::SmartPointer ParameterGroup_Pointer;
 
 typedef otb::Wrapper::Application                        Application;
 typedef otb::Wrapper::Application::Pointer::SmartPointer Application_Pointer;
 
-typedef otb::Wrapper::ApplicationRegistry                        ApplicationRegistry;
-typedef otb::Wrapper::ApplicationRegistry::Pointer::SmartPointer ApplicationRegistry_Pointer;
+typedef otb::Wrapper::ApplicationRegistry                        Registry;
+typedef otb::Wrapper::ApplicationRegistry::Pointer::SmartPointer Registry_Pointer;
 
 #endif
diff --git a/Example/otbSmoothing.cxx b/Example/otbSmoothing.cxx
index e100da3a7c..2a5786f54c 100644
--- a/Example/otbSmoothing.cxx
+++ b/Example/otbSmoothing.cxx
@@ -64,7 +64,6 @@ private:
     std::cout << "~Smoothing" << std::endl;
   }
 
-
   void DoCreateParameters()
   {
     AddParameter(ParameterType_InputImage,  "in",   "Input Image");
diff --git a/Testing/Python/PythonSmoothingTest.py b/Testing/Python/PythonSmoothingTest.py
index 521b7c6a12..8f65613ca3 100644
--- a/Testing/Python/PythonSmoothingTest.py
+++ b/Testing/Python/PythonSmoothingTest.py
@@ -2,14 +2,17 @@
 #  Example on the use of the Smoothing 
 #
 from sys import argv
-import otbApplication
+import otbApplication as otb
 
-print otbApplication.ApplicationRegistry.GetAvailableApplications()
+print otb.Registry.GetAvailableApplications()
+
+app = otb.Registry.CreateApplication("Smoothing")
+print app.GetParametersKeys()
 
-app = otbApplication.ApplicationRegistry.CreateApplication("Smoothing")
 app.SetParameterString("in", argv[1])
 
 for type in ['mean', 'gaussian', 'anidif']:
+  print 'Testing ' + type
   app.SetParameterString("type", type)
   app.SetParameterString("out", argv[2] + type + ".tif")
   app.Execute()
-- 
GitLab