diff --git a/Code/ApplicationEngine/otbWrapperApplicationHtmlDocGenerator.cxx b/Code/ApplicationEngine/otbWrapperApplicationHtmlDocGenerator.cxx new file mode 100644 index 0000000000000000000000000000000000000000..9aeab1784405cf86d3f7e2ae3c81f292a01b878b --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperApplicationHtmlDocGenerator.cxx @@ -0,0 +1,295 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "otbWrapperApplicationHtmlDocGenerator.h" + +#include <stdio.h> +#include "otbMacro.h" +#include "otbWrapperParameterGroup.h" +#include "otbWrapperChoiceParameter.h" + +namespace otb +{ +namespace Wrapper +{ + +#define otbDocHtmlTitleMacro( value ) \ + oss << "</style></head><body style=\" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;\"><p align=\"center\" style=\" margin-top:16px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:x-large; font-weight:600;\"><span style=\" font-size:x-large;\">"; \ + oss << value; \ + oss << "</span></p>"; + +#define otbDocHtmlTitle1Macro( value ) \ + oss << "<p style=\" margin-top:14px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:large; font-weight:600;\"><span style=\" font-size:large;\">"; \ + oss << value; \ + oss << "</span></p>"; + +#define otbDocHtmlTitle2Macro( value ) \ + oss << "<p style=\" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:medium; font-weight:600;\"><span style=\" font-size:medium;\">"; \ + oss << value; \ + oss << "</span></p>"; + +#define otbDocHtmlBodyMacro( value ) \ + oss << "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">"; \ + oss << value; \ + oss << "</p>"; + +#define otbDocHtmlBodyItalicMacro( value ) \ + oss << "<span style=\" font-style:italic;\">"; \ + oss << value; \ + oss << "</span>"; + + +#define otbDocHtmlBodyBoldMacro( value ) \ + oss << "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-weight:600;\">"; \ + oss << value; \ + oss << "</span></p>"; + + +#define otbDocHtmlBodyCodeMacro( value ) \ + oss << "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Courier New,courier';\">"; \ + oss << value; \ + oss << "</p>"; + +#define otbDocHtmlBodyBoldCodeMacro( value ) \ + oss << "<span style=\" font-weight:600;\"><p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Courier New,courier';\">"; \ + oss << value; \ + oss << "</p></span>"; + +ApplicationHtmlDocGenerator::ApplicationHtmlDocGenerator() +{ +} + +ApplicationHtmlDocGenerator::~ApplicationHtmlDocGenerator() +{ +} + + +void +ApplicationHtmlDocGenerator::GenerateDoc(const Application::Pointer app, const std::string& filename) +{ + itk::OStringStream oss; + + oss << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd\">"; + oss << "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">"; + oss << "p, li { white-space: pre-wrap; }"; + oss << "</style></head><body style=\" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;\">"; + + otbDocHtmlTitleMacro( app->GetDocName() ); + + otbDocHtmlTitle1Macro( "Brief Description" ); + otbDocHtmlBodyMacro( app->GetDescription() ); + + otbDocHtmlTitle1Macro( "Tags" ); + std::string tagList; + if ( app->GetDocTags().size() > 0 ) + { + for (unsigned int i = 0; i < app->GetDocTags().size() - 1; i++) + { + tagList.append( app->GetDocTags()[i] ).append(", "); + } + tagList.append( app->GetDocTags()[app->GetDocTags().size() - 1]); + otbDocHtmlBodyMacro( tagList ); + } + else + { + otbDocHtmlBodyMacro( "None" ); + } + + otbDocHtmlTitle1Macro("Long Description"); + otbDocHtmlBodyMacro( app->GetDocLongDescription() ); + + otbDocHtmlTitle1Macro("Parameters"); + oss << "<ul>"; + std::string paramDocs(""); + ApplicationHtmlDocGenerator::GetDocParameters( app, paramDocs ); + oss<<paramDocs; + oss<<"</ul>"; + + otbDocHtmlTitle1Macro( "Limitations"); + otbDocHtmlBodyMacro( app->GetDocLimitations() ); + + otbDocHtmlTitle1Macro( "Authors" ); + otbDocHtmlBodyMacro( app->GetDocAuthors() ); + + otbDocHtmlTitle1Macro( "See also" ); + otbDocHtmlBodyMacro( app->GetDocSeeAlso() ); + + otbDocHtmlTitle1Macro( "Command line example" ); + otbDocHtmlBodyCodeMacro( app->GetDocCLExample() ); + + oss << "</body></html>"; + + FILE *file = fopen(filename.c_str(), "w"); + if (file == NULL) + { + fprintf(stderr, "Error, can't open file"); + itkGenericExceptionMacro( << "Error, can't open file "<<filename<<"."); + } + fprintf(file, oss.str().c_str()); + fclose(file); + +} + +void ApplicationHtmlDocGenerator::GetDocParameters( const Application::Pointer app, std::string & val) +{ + itk::OStringStream oss; + const std::vector<std::string> appKeyList = app->GetParametersKeys( false ); + const unsigned int nbOfParam = appKeyList.size(); + + std::string paramDocs(""); + if( nbOfParam == 0) + { + val = "None"; + } + else + { + for( unsigned int i=0; i<nbOfParam; i++ ) + { + const std::string key(appKeyList[i]); + Parameter::Pointer param = app->GetParameterByKey( key ); + if( app->GetParameterType(key) == ParameterType_Group) + { + oss << "<li>"; + otbDocHtmlBodyBoldMacro( std::string("[group] ").append( param->GetName() ).append(":") ); + if(std::string(param->GetDescription()).size()!=0) + { + otbDocHtmlBodyMacro(oss<<param->GetDescription()); + } + std::string grDoc; + ApplicationHtmlDocGenerator::GetDocParameterGroup( app, grDoc, key ); + oss<<grDoc; + oss<<"</li><br />"; + } + else if( app->GetParameterType(key) == ParameterType_Choice ) + { + oss << "<li>"; + otbDocHtmlBodyBoldMacro( std::string("[choice] ").append( param->GetName() ).append(":")); + if(std::string(param->GetDescription()).size()!=0) + { + otbDocHtmlBodyMacro(param->GetDescription()); + } + std::string grDoc; + ApplicationHtmlDocGenerator::GetDocParameterChoice(app, grDoc, key); + oss<<grDoc; + oss<<"</li><br />"; + } + else + { + otbDocHtmlBodyBoldCodeMacro( std::string("[param] ").append( param->GetName() ).append(":")); + otbDocHtmlBodyMacro( param->GetDescription() ); + oss << "</li>"; + } + } + } + + val = oss.str(); +} + +void ApplicationHtmlDocGenerator::GetDocParameterGroup( const Application::Pointer app, std::string & val, const std::string & key ) +{ + Parameter * paramGr = app->GetParameterByKey( key ); + if( !dynamic_cast<ParameterGroup *>(paramGr)) + { + 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(); + 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 = app->GetParameterByKey( fullKey ); + if( app->GetParameterType(fullKey) == ParameterType_Group) + { + oss<<"<li>"; + otbDocHtmlBodyBoldCodeMacro( std::string("[group] ").append( param->GetName() ).append(":")); + if(std::string(param->GetDescription()).size()!=0) + { + otbDocHtmlBodyMacro( param->GetDescription() ); + } + std::string grDoc; + ApplicationHtmlDocGenerator::GetDocParameterGroup( app, grDoc, fullKey ); + oss<<grDoc; + oss<<"</li>"; + } + else if( app->GetParameterType(fullKey) == ParameterType_Choice ) + { + oss<<"<li>"; + otbDocHtmlBodyBoldCodeMacro( std::string("[choice] ").append( param->GetName() ).append(":")); + if(std::string(param->GetDescription()).size()!=0) + { + otbDocHtmlBodyMacro( param->GetDescription() ); + } + std::string grDoc; + ApplicationHtmlDocGenerator::GetDocParameterChoice(app, grDoc, fullKey ); + oss<<grDoc; + oss<<"</li>"; + } + else + { + oss << "<li>"; + otbDocHtmlBodyBoldCodeMacro( std::string("[param] ").append( param->GetName() ).append(":")); + otbDocHtmlBodyMacro( param->GetDescription() ); + oss <<"</li>"; + } + } + oss<<"</ul>"; + val.append(oss.str()); +} + + +void ApplicationHtmlDocGenerator::GetDocParameterChoice( const Application::Pointer app, std::string & val, const std::string & key ) +{ + Parameter * paramCh = app->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>"; + otbDocHtmlBodyBoldCodeMacro( std::string("[group] ").append( group->GetName() ).append(":")); + if(std::string(group->GetDescription()).size()!=0) + { + otbDocHtmlBodyMacro( group->GetDescription() ); + } + + ApplicationHtmlDocGenerator::GetDocParameterGroup( app, grDoc, fullKey ); + oss<<grDoc; + oss<<"</li>"; + } + oss<<"</ul>"; + val.append(oss.str()); +} + +} +} + diff --git a/Code/ApplicationEngine/otbWrapperApplicationHtmlDocGenerator.h b/Code/ApplicationEngine/otbWrapperApplicationHtmlDocGenerator.h new file mode 100644 index 0000000000000000000000000000000000000000..94c346e9ba928eb013ca3be40dec2ed5dd305eab --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperApplicationHtmlDocGenerator.h @@ -0,0 +1,67 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __otbWrapperApplicationHtmlDocGenerator_h +#define __otbWrapperApplicationHtmlDocGenerator_h + +#include "otbWrapperApplication.h" + +namespace otb +{ +namespace Wrapper +{ +/** \class ApplicationHtmlDocGenerator + * \brief This class genertaes the documentation of a class usung the + * class doc attributes. + */ + +class ITK_EXPORT ApplicationHtmlDocGenerator +{ +public: + /** Standard class typedef */ + typedef ApplicationHtmlDocGenerator Self; + + /** Constructor */ + ApplicationHtmlDocGenerator(); + + /** Destructor */ + virtual ~ApplicationHtmlDocGenerator(); + + static void GenerateDoc( const Application::Pointer app, const std::string & filename ); + +protected: + +/** Get the parameter description of one parameter. */ + static void GetDocParameters( const Application::Pointer app, std::string & val ); + + /** generate the documentation associated to a group.*/ + static void GetDocParameterGroup( const Application::Pointer app, std::string & val, const std::string & key ); + + /** generate the documentation associated to a choice.*/ + static void GetDocParameterChoice( const Application::Pointer app, std::string & val, const std::string & key ); + + +private: + ApplicationHtmlDocGenerator(const ApplicationHtmlDocGenerator &); //purposely not implemented + void operator =(const ApplicationHtmlDocGenerator&); //purposely not implemented + +}; // End class InputImage Parameter + +} // End namespace Wrapper +} // End namespace otb + +#endif diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.cxx index 016c2370913b19ada2bc66f201cf78ec7f7de8b9..032101fd6a939eabb3d43f3c40e4f02a42bbdcba 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.cxx +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetView.cxx @@ -183,7 +183,7 @@ QWidget* QtWidgetView::CreateDoc() text->setDocument(doc); - //std::cout<<text->toHtml().toStdString()<<std::endl; + std::cout<<text->toHtml().toStdString()<<std::endl; return text; } diff --git a/Testing/Code/ApplicationEngine/CMakeLists.txt b/Testing/Code/ApplicationEngine/CMakeLists.txt index 34698bb623c967e9b22f623c72bc461f1615ae28..6733aafc14ef35b2577d8fb3bcc2d607f7f5eac8 100644 --- a/Testing/Code/ApplicationEngine/CMakeLists.txt +++ b/Testing/Code/ApplicationEngine/CMakeLists.txt @@ -145,6 +145,18 @@ add_test(owTvParameterRAM ${OTB_WRAPPER_TESTS} otbWrapperRAMParameterNew ) +# ApplicationHtmlDocGenerator +add_test(owTvApplicationHtmlDocGeneratorNew ${OTB_WRAPPER_TESTS} + otbWrapperApplicationHtmlDocGeneratorNew + ) + +add_test(owTvApplicationHtmlDocGeneratorTest ${OTB_WRAPPER_TESTS} + otbWrapperApplicationHtmlDocGeneratorTest1 + ReadImageInfo + $<TARGET_FILE_DIR:otbapp_ReadImageInfo> + ${TEMP}/owTvOReadImageInfoDoc.html +) + # ----------------Source files CXX ----------------------------------- @@ -167,6 +179,7 @@ otbWrapperParameterKeyTest.cxx otbWrapperStringParameterTest.cxx otbWrapperRAMParameterTest.cxx otbWrapperStringListParameterTest.cxx +otbWrapperApplicationHtmlDocGeneratorTest.cxx ) include_directories(${CMAKE_SOURCE_DIR}/Code/Core) diff --git a/Testing/Code/ApplicationEngine/otbWrapperApplicationHtmlDocGeneratorTest.cxx b/Testing/Code/ApplicationEngine/otbWrapperApplicationHtmlDocGeneratorTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..0e93b9b98fe033bde22bcbdf6d4b1aac664f3ad7 --- /dev/null +++ b/Testing/Code/ApplicationEngine/otbWrapperApplicationHtmlDocGeneratorTest.cxx @@ -0,0 +1,60 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#include "otbWrapperApplicationHtmlDocGenerator.h" +#include "otbWrapperApplicationRegistry.h" +#include "otbWrapperApplication.h" + +int otbWrapperApplicationHtmlDocGeneratorNew(int argc, char* argv[]) +{ + typedef otb::Wrapper::ApplicationHtmlDocGenerator DocGeneratorType; + DocGeneratorType generator; + + return EXIT_SUCCESS; +} + +int otbWrapperApplicationHtmlDocGeneratorTest1(int argc, char* argv[]) +{ + if (argc != 4) + { + std::cerr << "Usage : " << argv[0] << " module_name module_path outputfilename" << std::endl; + return EXIT_FAILURE; + } + + typedef otb::Wrapper::ApplicationHtmlDocGenerator DocGeneratorType; + + // Add module path list + otb::Wrapper::ApplicationRegistry::AddApplicationPath( argv[2] ); + + // Create module + otb::Wrapper::Application::Pointer app = otb::Wrapper::ApplicationRegistry::CreateApplication(argv[1]); + + if (app.IsNull()) + { + std::cout << "Could not find application " << argv[1] << std::endl; + return EXIT_FAILURE; + } + + // Create the documentation output file + DocGeneratorType::GenerateDoc( app, std::string(argv[3]) ); + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/ApplicationEngine/otbWrapperCoreTests.cxx b/Testing/Code/ApplicationEngine/otbWrapperCoreTests.cxx index 0d665588e9c61991709380278df32f5ad1e569ad..daae9e75a4cf613cff7e2c2314401332b73ba84b 100644 --- a/Testing/Code/ApplicationEngine/otbWrapperCoreTests.cxx +++ b/Testing/Code/ApplicationEngine/otbWrapperCoreTests.cxx @@ -51,5 +51,7 @@ void RegisterTests() REGISTER_TEST(otbWrapperApplicationRegistry); REGISTER_TEST(otbWrapperParameterKey); REGISTER_TEST(otbWrapperRAMParameterNew); + REGISTER_TEST(otbWrapperApplicationHtmlDocGeneratorNew); + REGISTER_TEST(otbWrapperApplicationHtmlDocGeneratorTest1); }