From 01053601584552bd55dd871a8a2eae419c454c12 Mon Sep 17 00:00:00 2001
From: Cyrille Valladeau <cyrille.valladeau@c-s.fr>
Date: Mon, 19 Sep 2011 12:09:13 +0200
Subject: [PATCH] ENH: add progress report in command line + add parameter type
 in commend line helper

---
 Applications/Util/otbRescale.cxx              |  1 +
 .../otbWrapperOutputImageParameter.cxx        |  3 +-
 .../otbWrapperCommandLineLauncher.cxx         | 42 +++++++++----------
 .../otbWrapperCommandLineLauncher.h           | 11 +++--
 4 files changed, 28 insertions(+), 29 deletions(-)

diff --git a/Applications/Util/otbRescale.cxx b/Applications/Util/otbRescale.cxx
index 10ca7afbe6..a0998585b9 100644
--- a/Applications/Util/otbRescale.cxx
+++ b/Applications/Util/otbRescale.cxx
@@ -73,6 +73,7 @@ private:
     SetParameterDescription( "outmax", "Maximum value of the output image." );
 
     MandatoryOff("outmin");
+    MandatoryOff("outmax");
   }
 
   void DoUpdateParameters()
diff --git a/Code/ApplicationEngine/otbWrapperOutputImageParameter.cxx b/Code/ApplicationEngine/otbWrapperOutputImageParameter.cxx
index 95873b7418..2f025c2bf5 100644
--- a/Code/ApplicationEngine/otbWrapperOutputImageParameter.cxx
+++ b/Code/ApplicationEngine/otbWrapperOutputImageParameter.cxx
@@ -17,7 +17,7 @@
 =========================================================================*/
 #include "otbWrapperOutputImageParameter.h"
 #include "itkCastImageFilter.h"
-#include "otbStandardFilterWatcher.h"
+
 namespace otb
 {
 namespace Wrapper
@@ -113,7 +113,6 @@ OutputImageParameter::Write( )
       {
       m_FloatWriter->SetFileName( this->GetFileName() );
       m_FloatWriter->SetInput(this->GetImage());
-      //StandardFilterWatcher watch(static_cast<itk::ProcessObject*>(m_FloatWriter), "oss.str()");
       m_FloatWriter->Update();
       }
       break;
diff --git a/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.cxx b/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.cxx
index ecf6aa5d98..a4038607ca 100644
--- a/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.cxx
+++ b/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.cxx
@@ -48,7 +48,7 @@ namespace otb
 namespace Wrapper
 {
 
-CommandLineLauncher::CommandLineLauncher() : m_Expression(""), m_FilterWatcherList(), m_WriterWatcherList()
+CommandLineLauncher::CommandLineLauncher() : m_Expression(""), m_WatcherList()
 {
   m_Application = NULL;
   m_Parser = CommandLineParser::New();
@@ -62,8 +62,21 @@ CommandLineLauncher::CommandLineLauncher(const char * exp) : m_Expression(exp)
 
 CommandLineLauncher::~CommandLineLauncher()
 {
+  this->DeleteWatcherList();
 }
 
+void
+CommandLineLauncher::DeleteWatcherList()
+{
+  for( unsigned int i= 0; i<m_WatcherList.size(); i++ )
+    {
+      delete m_WatcherList[i];
+      m_WatcherList[i] = NULL;
+    }
+  m_WatcherList.clear();
+}
+
+
 bool
 CommandLineLauncher::Load( const std::string & exp )
 {
@@ -348,43 +361,30 @@ CommandLineLauncher::LoadParameters()
 void
 CommandLineLauncher::LinkWatchers()
 {
-  m_FilterWatcherList.clear();
-  m_WriterWatcherList.clear();
+  this->DeleteWatcherList();
   // Link internall filters watcher
   for( unsigned int i=0; i<m_Application->GetInternalProcessList().size(); i++ )
     {
-      //std::cout<<"BRRRRRRRRRRRRRRR"<<std::endl;
-      //StandardFilterWatcher watch(m_Application->GetInternalProcessList()[i], m_Application->GetInternalProcessListName()[i]);
-      //m_FilterWatcherList.push_back( watch );
+      StandardFilterWatcher * watch = new StandardFilterWatcher(m_Application->GetInternalProcessList()[i], m_Application->GetInternalProcessListName()[i]);
+      m_WatcherList.push_back( watch );
     }
   
   // Link output image writers watchers
    std::vector<std::string> paramList = m_Application->GetParametersKeys(true);
    std::vector<std::string>::const_iterator it = paramList.begin();
-   std::cout<<"BRRRRRRRRRRRRRRR"<<std::endl;
    for (; it != paramList.end(); ++it)
      {
        if (m_Application->GetParameterType(*it) == ParameterType_OutputImage)
          {
-              std::cout<<"-------------------------------------------------------------t'en as?"<<std::endl;
            Parameter* param = m_Application->GetParameterByKey(*it);
            OutputImageParameter* outputParam = dynamic_cast<OutputImageParameter*>(param);
            itk::OStringStream oss;
-           oss<< "Wrinting "<< param->GetName()<<std::endl;
-
-           std::cout<<"----++++"<<std::endl;
-           std::cout<<"----++++: "<<outputParam->GetWriter()<<std::endl;
-           std::cout<<"----++++"<<std::endl;
-           //typedef otb::StreamingImageFileWriter<FloatVectorImageType>  FloatWriterType;
-           //StandardWriterWatcher watch(static_cast<FloatWriterType::Pointer>(static_cast<FloatWriterType *>(outputParam->GetWriter())), "write that");
-           //StandardWriterWatcher watch(outputParam->GetWriter(), "write that");
-           //m_WriterWatcherList.push_back( watch );
-           //StandardFilterWatcher watch(outputParam->GetWriter(), oss.str());
-           //m_FilterWatcherList.push_back( watch );
-           
+           oss<< "Wrinting "<< param->GetName()<<"...";
+
+           StandardFilterWatcher * watch = new StandardFilterWatcher(outputParam->GetWriter(), oss.str());
+           m_WatcherList.push_back( watch );          
         }
     }
-   std::cout<<"BRRRRRRRRRRRRRRR fin"<<std::endl;
 }
 
 void
diff --git a/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.h b/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.h
index 60bcfc07ba..470daeaa97 100644
--- a/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.h
+++ b/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.h
@@ -27,7 +27,6 @@
 #include "itksys/SystemTools.hxx"
 #include "otbWrapperCommandLineParser.h"
 
-#include "otbStandardWriterWatcher.h"
 #include "otbStandardFilterWatcher.h"
 
 
@@ -66,9 +65,7 @@ public:
   typedef enum { OKPARAM, MISSINGMANDATORYPARAMETER, MISSINGPARAMETERVALUE, WRONGPARAMETERVALUE,  INVALIDNUMBEROFVALUE, DEFAULT} ParamResultType;
   
   /** Filter watcher list type */
-  typedef std::vector<StandardFilterWatcher> FilterWatcherListType;
-  /** Writer watcher list type */
-  typedef std::vector<StandardWriterWatcher> WriterWatcherListType;
+  typedef std::vector<StandardFilterWatcher *> WatcherListType;
 
   /** Load the application in several steps :
    * - Load the paths
@@ -128,6 +125,9 @@ protected:
   /** Load the watchers for internal progress and writeing progress report. */
   void LinkWatchers();
 
+  /** Clear watcher list, deleting its pointers. */
+  void DeleteWatcherList();
+
 private:
 
   CommandLineLauncher(const CommandLineLauncher &); //purposely not implemented
@@ -139,8 +139,7 @@ private:
   std::string m_Expression;
   CommandLineParser::Pointer m_Parser;
 
-  FilterWatcherListType m_FilterWatcherList;
-  WriterWatcherListType m_WriterWatcherList;
+  WatcherListType m_WatcherList;
 
 }; //end class
 
-- 
GitLab