From 17151d06727adaa67feff8de8d0251b294bf8f03 Mon Sep 17 00:00:00 2001
From: Julien Michel <julien.michel@orfeo-toolbox.org>
Date: Thu, 3 Nov 2011 18:33:20 +0100
Subject: [PATCH] ENH: Enhancing documentation generation

---
 .../QtWidget/otbWrapperQtWidgetView.cxx       | 123 +++++++++++++-----
 .../QtWidget/otbWrapperQtWidgetView.h         |   3 +
 2 files changed, 95 insertions(+), 31 deletions(-)

diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.cxx
index 6e7fd7bfb4..a4c4b3f01c 100644
--- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.cxx
+++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.cxx
@@ -22,6 +22,7 @@
 #include "otbWrapperQtWidgetProgressReport.h"
 #include "otbWrapperOutputImageParameter.h"
 #include "otbWrapperParameterGroup.h"
+#include "otbWrapperChoiceParameter.h"
 #include "otbWrapperQtWidgetSimpleProgressReport.h"
 
 #include "itksys/SystemTools.hxx"
@@ -193,19 +194,20 @@ void QtWidgetView::SetDocParameters( std::string & val )
   //const unsigned int nbOfParam = appKeyList.size();
     
   itk::OStringStream oss;
-  oss << "<h3>Parameters</h3>";
   
   // Mandatory parameters
-  oss << "<h4>Mandatory parameters</h4>";
+  oss << "<h3>Mandatory parameters</h3>";
+  oss<<"<ul>";
   std::string paramDocs("");
 
   this->GetDocParameters( paramDocs, true );
   oss<<paramDocs;
+  oss<<"</ul>";
 
   paramDocs  ="";
 
   // Optional parameters
-  oss << "<h4>Optional parameters</h4>";
+  oss << "<h3>Optional parameters</h3>";
   oss << "<body><li>";
 
   this->GetDocParameters( paramDocs, false );
@@ -228,18 +230,34 @@ void QtWidgetView::GetDocParameters( std::string & val, bool mandatory)
      Parameter::Pointer param =  m_Application->GetParameterByKey( key );
      if( param->GetMandatory() == mandatory )
        {
-       if( m_Application->GetParameterType(key) !=  ParameterType_Group )
+       if( m_Application->GetParameterType(key) ==  ParameterType_Group)
          {
-         oss << "<i>" << param->GetName() << ":</i><br />";
-         oss << param->GetDescription()<< "<br />";
-         oss << "<br />";
+         oss << "<li><b>[group] "<<param->GetName()<<": </b>";
+         if(std::string(param->GetDescription()).size()!=0)
+           {
+           oss<<param->GetDescription();
+           }
+         std::string grDoc;
+         GetDocParameterGroup( grDoc, key, 1);
+         oss<<grDoc;
+         oss<<"</li><br />";
          }
-       else
+       else if( m_Application->GetParameterType(key) ==  ParameterType_Choice )
          {
-         oss << "<b><i>=== "<<param->GetName()<<"</i></b> ("<<param->GetDescription()<<"):<br />";
+        oss << "<li><b> [choice] "<<param->GetName()<<": </b>";
+         if(std::string(param->GetDescription()).size()!=0)
+           {
+           oss<<param->GetDescription();
+           }
          std::string grDoc;
-         GetDocParameterGroup( grDoc, key, 1);
+         GetDocParameterChoice(grDoc, key, 1);
          oss<<grDoc;
+         oss<<"</li><br />";
+         }
+       else
+         {
+         oss << "<li><code>[param] " << param->GetName() << ": </code> ";
+         oss << param->GetDescription()<< "</li>";
          }
        }
      }
@@ -253,46 +271,89 @@ void QtWidgetView::GetDocParameters( std::string & val, bool mandatory)
 
 void QtWidgetView::GetDocParameterGroup( std::string & val, const std::string & key, int level )
 {
-  std::string spaces, equals;
-  for(int i=0; i<level; i++)
-    {
-    spaces.append("&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;");
-    equals.append("===");
-    }
-  equals.append("===");
-
   Parameter * paramGr  = m_Application->GetParameterByKey( key );
-  if( !dynamic_cast<ParameterGroup *>(paramGr) )
+  if( !dynamic_cast<ParameterGroup *>(paramGr))
     {
-    itkGenericExceptionMacro("Invlaid parameter type for key "<<key<<", wait for ParameterGroup...");
+    itkGenericExceptionMacro("Invalid parameter type for key "<<key<<", wait for ParameterGroup...");
     }
-
-  ParameterGroup * group = dynamic_cast<ParameterGroup *>(paramGr);
-  const std::vector<std::string> appKeyList = group->GetParametersKeys( false );
-  unsigned int nbOfParam = appKeyList.size();
+    ParameterGroup * group = dynamic_cast<ParameterGroup *>(paramGr);
+    const std::vector<std::string> appKeyList = group->GetParametersKeys( false );
+    unsigned int nbOfParam = appKeyList.size();
   itk::OStringStream oss;
+  oss<<"<ul>";
   for( unsigned int i=0; i<nbOfParam; i++ )
     {
     const std::string fullKey(std::string(key).append(".").append(appKeyList[i]));
     Parameter::Pointer param =  m_Application->GetParameterByKey( fullKey );
-    if( m_Application->GetParameterType(fullKey) !=  ParameterType_Group )
+    if( m_Application->GetParameterType(fullKey) ==  ParameterType_Group)
       {
-      oss << "<i>" << spaces << param->GetName()<< ":</i><br />";
-      oss  << spaces << param->GetDescription()<<"<br>";
-      oss << "<br />";
+      oss << "<li><code>[group] "<< param->GetName()<<": </code>";
+      if(std::string(param->GetDescription()).size()!=0)
+        {
+        oss<<param->GetDescription();
+        }
+      std::string grDoc;
+      GetDocParameterGroup( grDoc, fullKey, level+1);
+      oss<<grDoc;
+      oss<<"</li>";
       }
-    else
+    else if( m_Application->GetParameterType(fullKey) ==  ParameterType_Choice )
       {
-      oss << "<b><i>" << equals << param->GetName()<<"</i></b> ("<<param->GetDescription()<<")<br />";
+      oss << "<li><code>[choice] "<<param->GetName()<<": </code>";
+      if(std::string(param->GetDescription()).size()!=0)
+        {
+        oss<<param->GetDescription();
+        }
       std::string grDoc;
-      GetDocParameterGroup( grDoc, fullKey, level+1);
+      GetDocParameterChoice(grDoc, fullKey, level+1);
       oss<<grDoc;
+      oss<<"</li>";
       }
+    else
+      {
+      oss << "<li><code>[param] "<< param->GetName()<< ": </code>";
+      oss  << param->GetDescription()<<"</li>";
+      }
+    }
+  oss<<"</ul>";
+  val.append(oss.str());
+}
+
+
+void QtWidgetView::GetDocParameterChoice( std::string & val, const std::string & key, int level )
+{
+  Parameter * paramCh  = m_Application->GetParameterByKey( key );
+  if( !dynamic_cast<ChoiceParameter *>(paramCh))
+    {
+    itkGenericExceptionMacro("Invalid parameter type for key "<<key<<", wait for ChoiceParameter...");
+    }
+    ChoiceParameter * choice = dynamic_cast<ChoiceParameter *>(paramCh);
+    const std::vector<std::string> appKeyList = choice->GetChoiceKeys();
+    unsigned int nbOfParam = choice->GetNbChoices();
+    itk::OStringStream oss;
+    oss<<"<ul>";
+  
+  for( unsigned int i=0; i<nbOfParam; i++ )
+    {
+    const std::string fullKey(std::string(key).append(".").append(appKeyList[i]));
+    ParameterGroup * group = choice->GetChoiceParameterGroupByIndex(i);
+    std::string grDoc;
+    oss << "<li><code>[group] "<< group->GetName()<<": </code>";
+      if(std::string(group->GetDescription()).size()!=0)
+        {
+        oss<<group->GetDescription();
+        }
+
+    GetDocParameterGroup( grDoc, fullKey, level+1);
+    oss<<grDoc;
+    oss<<"</li>";
     }
+  oss<<"</ul>";
   val.append(oss.str());
 }
 
 
+
 void QtWidgetView::CloseSlot()
 {
   // Close the widget
diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.h
index af03f7d658..9729b43a79 100644
--- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.h
+++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.h
@@ -75,6 +75,9 @@ private:
   /** generate the documentation associated to a group.*/
   void GetDocParameterGroup( std::string & val, const std::string & key, int level);
 
+  /** generate the documentation associated to a choice.*/
+  void GetDocParameterChoice( std::string & val, const std::string & key, int level);
+
   Application::Pointer m_Application;
 
   QtWidgetModel* m_Model;
-- 
GitLab