diff --git a/Documentation/Cookbook/Scripts/otbGenerateWrappersRstDoc.py b/Documentation/Cookbook/Scripts/otbGenerateWrappersRstDoc.py index 8cd9ab8ed70e204d915e32c25ebb4944f52b4a9b..ce5e5d1b1c788a8b3fc8050c47045cac3f7898bf 100755 --- a/Documentation/Cookbook/Scripts/otbGenerateWrappersRstDoc.py +++ b/Documentation/Cookbook/Scripts/otbGenerateWrappersRstDoc.py @@ -25,7 +25,7 @@ import argparse import re import otbApplication -from otbApplication import ParameterType_Bool, ParameterType_Int, ParameterType_Radius, ParameterType_RAM, ParameterType_Float, ParameterType_String, ParameterType_StringList, ParameterType_InputFilename, ParameterType_OutputFilename, ParameterType_InputImage, ParameterType_OutputImage, ParameterType_InputVectorData, ParameterType_OutputVectorData, ParameterType_Directory, ParameterType_Choice, ParameterType_InputImageList, ParameterType_InputVectorDataList, ParameterType_InputFilenameList, ParameterType_InputProcessXML, ParameterType_OutputProcessXML, ParameterType_ListView, ParameterType_Group +from otbApplication import ParameterType_Bool, ParameterType_Int, ParameterType_Radius, ParameterType_RAM, ParameterType_Float, ParameterType_String, ParameterType_StringList, ParameterType_InputFilename, ParameterType_OutputFilename, ParameterType_InputImage, ParameterType_OutputImage, ParameterType_InputVectorData, ParameterType_OutputVectorData, ParameterType_Directory, ParameterType_Choice, ParameterType_InputImageList, ParameterType_InputVectorDataList, ParameterType_InputFilenameList, ParameterType_ListView, ParameterType_Group from otb_warnings import application_documentation_warnings @@ -202,7 +202,6 @@ def rst_parameter_value(app, key): values.update({ParameterType_InputImageList: "image1 image2..."}) values.update({ParameterType_InputVectorDataList: "vectorfile1 vectorfile2..."}) values.update({ParameterType_InputFilenameList: "filename1 filename2..."}) - values.update(dict.fromkeys([ParameterType_InputProcessXML, ParameterType_OutputProcessXML], "filename.xml")) if type in values: return values[type] diff --git a/Documentation/Cookbook/rst/C++/WriteAnApplication.rst b/Documentation/Cookbook/rst/C++/WriteAnApplication.rst index 412a789d70bf9190b51272653ff0458ae1b4e7c4..a1497c8d6e7af1b39a43c28081fb62ab9240ab7c 100644 --- a/Documentation/Cookbook/rst/C++/WriteAnApplication.rst +++ b/Documentation/Cookbook/rst/C++/WriteAnApplication.rst @@ -158,9 +158,6 @@ parameters: - ``ParameterType_InputVectorDataList`` : parameter storing a list of input vector data. -- ``ParameterType_InputProcessXML`` : parameter storing an input XML - file name. - - ``ParameterType_OutputFilename`` : parameter storing an output file name. @@ -169,9 +166,6 @@ parameters: - ``ParameterType_OutputVectorData`` : parameter storing an output vector data. -- ``ParameterType_OutputProcessXML`` : parameter storing an output XML - file name. - - ``ParameterType_RAM`` : parameter storing the maximum amount of RAM to be used. diff --git a/Documentation/Cookbook/rst/CliInterface.rst b/Documentation/Cookbook/rst/CliInterface.rst index eebd130fe3f08995be54e36ddf4c822fc247b3de..6717fd10ee5c21f79ec48996d5d2ef3ef0ddd940 100644 --- a/Documentation/Cookbook/rst/CliInterface.rst +++ b/Documentation/Cookbook/rst/CliInterface.rst @@ -123,7 +123,6 @@ example based on the OrthoRectification application: -opt.rpc <int32> RPC modeling (points per axis) (optional, off by default, default value is 10) -opt.ram <int32> Available RAM (MB) (optional, off by default, default value is 128) -opt.gridspacing <float> Resampling grid spacing (optional, off by default, default value is 4) - -inxml <string> Load parameters from XML (optional, off by default) -progress <boolean> Report progress -help <string list> Display long help (empty list), or help for given parameters keys @@ -145,11 +144,10 @@ Command-line examples are provided in the chapter :ref:`apprefdoc`. Load and save parameters to XML ------------------------------- -Since OTB 3.20, OTB applications parameters can be export/import to/from -an XML file using inxml/outxml parameters. Those parameters are -available in all applications. - -An example is worth a thousand words +OTB application parameters can be saved and loaded to +an XML file using the special ``-inxml`` and ``-outxml`` parameters. +Those parameters are available in all applications. +For example: :: @@ -177,17 +175,6 @@ time In this case it will use as mathematical expression “(im1b1 - im2b1)†instead of “abs(im1b1 - im2b1)â€. -Finally, you can also launch applications directly from the command-line -launcher executable using the inxml parameter without having to declare -the application name. Use in this case: - -:: - - otbApplicationLauncherCommandLine -inxml saved_applications_parameters.xml - -It will retrieve the application name and related parameters from the -input XML file and launch in this case the BandMath applications. - Parallel execution with MPI --------------------------- diff --git a/Documentation/Cookbook/rst/PythonAPI.rst b/Documentation/Cookbook/rst/PythonAPI.rst index 4fa3ca24b0ed1317373a4abe6354ecec25d9e091..6f61f1b4084faebb6cc1f94b459c82c34567b148 100644 --- a/Documentation/Cookbook/rst/PythonAPI.rst +++ b/Documentation/Cookbook/rst/PythonAPI.rst @@ -218,11 +218,34 @@ implementation does not break it, for instance by using an internal writer to write intermediate data. In this case, execution should still be correct, but some intermediate data will be read or written. +Load and save parameters to XML +------------------------------- + +As with a the `command line interface` you can save application parameters +to an xml file: + +.. code-block:: python + + # Save application parameters to XML + app = otb.Registry.CreateApplication('BandMath') + app.SetParameterStringList("il", ["image1.tif", "image2.tif"], True) + app.SetParameterString("out", out, True) + app.SetParameterString("exp", "cos(im1b1)+im2b1*im1b1", True) + app.SaveParametersToXML("parameters.xml") + +And load them later for execution: + +.. code-block:: python + + # Load application parameters from XML + app = otb.Registry.CreateApplication("BandMath") + app.LoadParametersFromXML("parameters.xml") + app.ExecuteAndWriteOutput() + + Interactions with OTB pipeline ------------------------------ -[Since OTB 6.6] - The application framework has been extended in order to provide ways to interact with the pipelines inside each application. It applies only to applications that use input or output images. Let's check which diff --git a/Modules/Visualization/MonteverdiGui/include/mvdQtWidgetParameterInitializers.h b/Modules/Visualization/MonteverdiGui/include/mvdQtWidgetParameterInitializers.h index 1be6f7514f2db902f0194de47ce26f78e8ac99a2..c7143258d95e0c5b4f2e8e95c59c6ff9edfbaef8 100644 --- a/Modules/Visualization/MonteverdiGui/include/mvdQtWidgetParameterInitializers.h +++ b/Modules/Visualization/MonteverdiGui/include/mvdQtWidgetParameterInitializers.h @@ -49,12 +49,10 @@ #include "otbWrapperQtWidgetInputFilenameListParameter.h" #include "otbWrapperQtWidgetInputImageParameter.h" #include "otbWrapperQtWidgetInputImageListParameter.h" -#include "otbWrapperQtWidgetInputProcessXMLParameter.h" #include "otbWrapperQtWidgetInputVectorDataParameter.h" #include "otbWrapperQtWidgetInputVectorDataListParameter.h" #include "otbWrapperQtWidgetOutputFilenameParameter.h" #include "otbWrapperQtWidgetOutputImageParameter.h" -#include "otbWrapperQtWidgetOutputProcessXMLParameter.h" #include "otbWrapperQtWidgetOutputVectorDataParameter.h" #include "otbWrapperQtWidgetParameterFactory.h" #include "otbWrapperQtWidgetListEditWidget.h" @@ -225,21 +223,6 @@ public: inline result_type operator () ( argument_type widget ) const; }; -/** - * \class InputProcessXMLInitializer - * - * \ingroup OTBMonteverdiGUI - * - * \brief WIP. - */ -class InputProcessXMLInitializer : public std::unary_function< - otb::Wrapper::QtWidgetInputProcessXMLParameter *, - void > -{ -public: - inline result_type operator () ( argument_type widget ) const; -}; - /** * \class OutputImageInitializer * @@ -293,22 +276,6 @@ public: inline result_type operator () ( argument_type widget ) const; }; -/** - * \class OutputProcessXMLInitializer - * - * \ingroup OTBMonteverdiGUI - * - * \brief WIP. - */ -class OutputProcessXMLInitializer : public std::unary_function< - otb::Wrapper::QtWidgetOutputProcessXMLParameter *, - void - > -{ -public: - inline result_type operator () ( argument_type widget ) const; -}; - /** * \class ToolTipInitializer * @@ -445,17 +412,6 @@ InputVectorDataListInitializer // Drop support is done by ParameterListInitializer } -/*****************************************************************************/ -inline -InputProcessXMLInitializer::result_type -InputProcessXMLInitializer -::operator () ( argument_type widget ) const -{ - assert( widget!=NULL ); - - SetupForFilenameDrop( widget ); -} - /*****************************************************************************/ inline ToolTipInitializer::result_type @@ -542,25 +498,6 @@ OutputFilenameInitializer SetupOutputFilename( widget ); } -/*****************************************************************************/ -inline -OutputProcessXMLInitializer::result_type -OutputProcessXMLInitializer -::operator () ( argument_type widget ) const -{ - assert( widget!=NULL ); - - SetupForFilenameDrop( widget ); - - assert( qApp!=NULL ); - assert( !qApp->arguments().empty() ); - - // MANTIS-1103 - // { - // SetupOutputFilename( widget ); - // } -} - /*****************************************************************************/ inline ParameterListInitializer::result_type diff --git a/Modules/Visualization/MonteverdiGui/src/mvdQtWidgetView.cxx b/Modules/Visualization/MonteverdiGui/src/mvdQtWidgetView.cxx index d074c1aae4c92205f06daacdc0420222233930dc..77bdbd9dc6c5c519f1c85d06778739abdb555964 100644 --- a/Modules/Visualization/MonteverdiGui/src/mvdQtWidgetView.cxx +++ b/Modules/Visualization/MonteverdiGui/src/mvdQtWidgetView.cxx @@ -163,7 +163,6 @@ QtWidgetView //SetupWidget( widget, InputFilenameListInitializer() ); SetupWidget( widget, InputImageInitializer() ); //SetupWidget( widget, InputImageListInitializer() ); - SetupWidget( widget, InputProcessXMLInitializer() ); SetupWidget( widget, InputVectorDataInitializer() ); //SetupWidget( widget, InputVectorDataListInitializer() ); SetupWidget( widget, ParameterListInitializer() ); @@ -172,7 +171,6 @@ QtWidgetView #endif SetupWidget( widget, OutputFilenameInitializer() ); - SetupWidget( widget, OutputProcessXMLInitializer() ); SetupWidget( widget, diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h index 3baadd6f0f747b5f640b284fd3bd6a7aeab79254..b2a11017541f6a774be6f8a1a5befb55a2575c41 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h @@ -102,11 +102,8 @@ public: /** Check if the application has been initialized */ bool IsInitialized() const; - virtual void SetHaveInXML(bool); - virtual bool GetHaveInXML() const; - - virtual void SetHaveOutXML(bool); - virtual bool GetHaveOutXML() const; + void LoadParametersFromXML(const std::string& filename); + void SaveParametersToXML(const std::string& filename); /** Update the value of parameters for which no user value has been provided */ void UpdateParameters(); @@ -210,12 +207,6 @@ public: /* Returns the description of a parameter */ std::vector<std::string> GetChoiceNames(std::string paramKey); - /* Is the application ready to be executed : All the mandatory - * parameters have to be set - */ - /* Set the Parameter value and Update the UserFlag. used by xml parameter - */ - /* Set an integer value * * Can be called for types : @@ -690,9 +681,6 @@ public: */ std::vector< std::pair<std::string, std::string> > GetOutputParametersSumUp(); - /** If need to force readxml more than once in application */ - void ForceInXMLParseFlag(); - double GetLastExecutionTiming() const; virtual void SetDocLink(const std::string & link); @@ -816,16 +804,6 @@ protected: * by default seed initialization is based on time value*/ void AddRANDParameter(std::string paramKey, std::string paramName, unsigned int defaultValue); - void AddInXMLParameter() - { - GetParameterList()->AddInXMLParameter(); - } - - void AddOutXMLParameter() - { - GetParameterList()->AddOutXMLParameter(); - } - /** Remove the items added to the ListWidget */ void ClearChoices(std::string key); @@ -916,11 +894,6 @@ private: /** Chrono to measure execution time */ otb::Stopwatch m_Chrono; - //rashad:: controls adding of -xml parameter. set to true by default - bool m_HaveInXML; - bool m_HaveOutXML; - bool m_IsInXMLParsed; - /** Flag is true when executing DoInit, DoUpdateParameters or DoExecute */ bool m_IsInPrivateDo; diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputProcessXMLParameter.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputProcessXMLParameter.h deleted file mode 100644 index d4db58283c9294ef3b7dc1de2d841134f539823a..0000000000000000000000000000000000000000 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputProcessXMLParameter.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef otbWrapperInputProcessXMLParameter_h -#define otbWrapperInputProcessXMLParameter_h -#include "otbWrapperApplication.h" -#include "otb_tinyxml.h" -#include <sstream> -#include <string> - -namespace otb -{ -namespace Wrapper -{ - -/** \class InputProcessXMLParameter - * \brief This class represent a xml filename parameter for the wrapper framework to load otb application. - * - * \ingroup OTBApplicationEngine - */ -class OTBApplicationEngine_EXPORT InputProcessXMLParameter - : public Parameter -{ -public: - /** Standard class typedef */ - typedef InputProcessXMLParameter Self; - typedef Parameter Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - - /** Defining ::New() static method */ - itkNewMacro(Self); - - /** RTTI support */ - itkTypeMacro(InputProcessXMLParameter, Parameter); - - itkGetStringMacro(FileName); - - bool HasValue() const override - { - if(m_FileName.empty()) - return false; - else - return true; - } - - virtual ParameterType GetType() const override - { - return ParameterType_InputProcessXML; - } - - std::string ToString() const override - { - return GetFileName(); - } - - void FromString(const std::string& value) override - { - SetFileName(value); - } - - // Get Value - //TODO otbGetObjectMemberMacro(StringParam, Value , std::string); - - bool SetFileName(std::string value); - - // Set Value - virtual void SetValue(const std::string value); - - ImagePixelType GetPixelTypeFromString(std::string pixTypeAsString); - - ParameterType GetParameterType(const Parameter* param) const; - - const std::string GetChildNodeTextOf(TiXmlElement *parentElement, std::string key); - - int Read(Application::Pointer application); - - void otbAppLogInfo(Application::Pointer app, std::string info); - -/* copied from Utilities/tinyXMLlib/tinyxml.cpp. Must have a FIX inside tinyxml.cpp */ - FILE* TiXmlFOpen( const char* filename, const char* mode ); - -protected: - - InputProcessXMLParameter(); - - /** Destructor */ - ~InputProcessXMLParameter() override; - -private: - - std::string m_FileName; - - InputProcessXMLParameter(const InputProcessXMLParameter &) = delete; - void operator =(const InputProcessXMLParameter&) = delete; - - -}; // End class Parameter - -} // End namespace Wrapper -} // End namespace otb - -#endif diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputXML.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputXML.h new file mode 100644 index 0000000000000000000000000000000000000000..181169784da960e525caf1335b080510ef250558 --- /dev/null +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputXML.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) + * + * This file is part of Orfeo Toolbox + * + * https://www.orfeo-toolbox.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef otbWrapperInputXML_h +#define otbWrapperInputXML_h + +#include "otbWrapperApplication.h" +#include "otb_tinyxml.h" +#include <sstream> +#include <string> + +namespace otb +{ +namespace Wrapper +{ +namespace XML +{ + +const std::string GetChildNodeTextOf(TiXmlElement* parentElement, std::string key); + +int Read(const std::string& filename, Application::Pointer application); + +/* copied from Utilities/tinyXMLlib/tinyxml.cpp. Must have a FIX inside tinyxml.cpp */ +FILE* TiXmlFOpen(const char* filename, const char* mode); + +} // namespace XML +} // End namespace Wrapper +} // End namespace otb + +#endif diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperOutputProcessXMLParameter.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperOutputProcessXMLParameter.h deleted file mode 100644 index 136489e96ba1cfc9acfff1d4a29f89ed9083d471..0000000000000000000000000000000000000000 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperOutputProcessXMLParameter.h +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef otbWrapperOutputProcessXMLParameter_h -#define otbWrapperOutputProcessXMLParameter_h -#include "otbWrapperApplication.h" -#include "otb_tinyxml.h" -#include <string> - -namespace otb -{ -namespace Wrapper -{ - -/** \class OutputProcessXMLParameter - * \brief This class represent a xml filename parameter for the wrapper framework to save otb application. - * - * \ingroup OTBApplicationEngine - */ -class OTBApplicationEngine_EXPORT OutputProcessXMLParameter - : public Parameter -{ -public: - /** Standard class typedef */ - typedef OutputProcessXMLParameter Self; - typedef Parameter Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - - /** Defining ::New() static method */ - itkNewMacro(Self); - - /** RTTI support */ - itkTypeMacro(OutputProcessXMLParameter, Parameter); - - itkGetStringMacro(FileName); - - // Set FileName - void SetFileName(std::string value) - { - this->SetValue(value); - } - - // Set Value - virtual void SetValue(const std::string value) - { - itkDebugMacro("setting member m_FileName to " << value); - this->m_FileName = value; - SetActive(true); - this->Modified(); - } - - bool HasValue() const override - { - if(m_FileName.empty()) - return false; - else - return true; - } - - void ClearValue() override - { - m_FileName = ""; - } - - virtual ParameterType GetType() const override - { - return ParameterType_OutputProcessXML; - } - - std::string ToString() const override - { - return GetFileName(); - } - - void FromString(const std::string& value) override - { - SetValue(value); - } - - TiXmlElement* AddChildNodeTo(TiXmlElement* parent, std::string name, std::string value=""); - - std::string pixelTypeToString(ImagePixelType pixType); - - ParameterType GetParameterType(const Parameter* param) const; - - void Write(Application::Pointer application); - - TiXmlElement* ParseApplication(Application::Pointer app); - - static std::string MakeCommandLine(otb::Wrapper::Application::Pointer application); - -protected: - - OutputProcessXMLParameter(); - - /** Destructor */ - ~OutputProcessXMLParameter() override; - -private: - - /** Recursive function to parse a group parameter */ - void ParseGroup(const std::string& group); - - std::string m_FileName; - - /** Temporary storage of the XML node to fill (internal) */ - TiXmlElement* m_Node; - - /** Temporary pointer to the application to parse (internal) */ - Application::Pointer m_Appli; - - OutputProcessXMLParameter(const OutputProcessXMLParameter &) = delete; - void operator =(const OutputProcessXMLParameter&) = delete; - - -}; // End class Parameter - -} // End namespace Wrapper -} // End namespace otb - -#endif diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperOutputXML.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperOutputXML.h new file mode 100644 index 0000000000000000000000000000000000000000..6d02238812aa26c5c4ac3b9f8bf84cade71ba8c5 --- /dev/null +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperOutputXML.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) + * + * This file is part of Orfeo Toolbox + * + * https://www.orfeo-toolbox.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef otbWrapperOutputXML_h +#define otbWrapperOutputXML_h + +#include "otbWrapperApplication.h" +#include "otb_tinyxml.h" +#include <string> + +namespace otb +{ +namespace Wrapper +{ +namespace XML +{ + +TiXmlElement* AddChildNodeTo(TiXmlElement* parent, std::string name, std::string value = ""); + +std::string pixelTypeToString(ImagePixelType pixType); + +void Write(const std::string& filename, Application::Pointer application); + +TiXmlElement* ParseApplication(Application::Pointer app); + +std::string MakeCommandLine(otb::Wrapper::Application::Pointer application); + +/** Recursive function to parse a group parameter */ +void ParseGroup(Application::Pointer app, TiXmlElement* n_App, const std::string& group); + +} // namespace XML +} // End namespace Wrapper +} // End namespace otb + +#endif diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperParameterGroup.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperParameterGroup.h index 5883ea352d279f495da859f7d40968df3d6f6f5c..53f4b5fac1784bd2a1bec6f9f046b0cbec0e5812 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperParameterGroup.h +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperParameterGroup.h @@ -73,11 +73,6 @@ public: Parameter::Pointer GetParameterByKey(std::string name, bool follow=true); - /** rashad: Add xml parameters eg: -inxml -outxml */ - void AddInXMLParameter(); - - void AddOutXMLParameter(); - void Clear() { m_ParameterList.clear(); diff --git a/Modules/Wrappers/ApplicationEngine/src/CMakeLists.txt b/Modules/Wrappers/ApplicationEngine/src/CMakeLists.txt index fb220c564fbe628d9e9469f6f3f438352caa6454..a3f78c16fe606361e4fe0005840d65d320ce2a89 100644 --- a/Modules/Wrappers/ApplicationEngine/src/CMakeLists.txt +++ b/Modules/Wrappers/ApplicationEngine/src/CMakeLists.txt @@ -23,7 +23,8 @@ set( OTBApplicationEngine_SRC otbWrapperInputVectorDataListParameter.cxx otbWrapperListViewParameter.cxx otbWrapperParameterGroup.cxx - otbWrapperOutputProcessXMLParameter.cxx + otbWrapperInputXML.cxx + otbWrapperOutputXML.cxx otbWrapperInputImageListParameter.cxx otbWrapperElevationParametersHandler.cxx otbWrapperInputFilenameListParameter.cxx @@ -44,7 +45,6 @@ set( OTBApplicationEngine_SRC otbWrapperDocExampleStructure.cxx otbWrapperInputVectorDataParameter.cxx otbWrapperOutputVectorDataParameter.cxx - otbWrapperInputProcessXMLParameter.cxx otbWrapperMapProjectionParametersHandler.cxx otbWrapperApplication.cxx otbWrapperChoiceParameter.cxx diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx index 4297ae946d62476a88847a9974cd5aff72526fb3..42893b1273ada5f98ce9f154e51e0359abce125a 100644 --- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx @@ -25,14 +25,14 @@ #include "otbWrapperInputFilenameParameter.h" #include "otbWrapperInputFilenameListParameter.h" #include "otbWrapperOutputFilenameParameter.h" -#include "otbWrapperOutputProcessXMLParameter.h" #include "otbWrapperInputVectorDataParameter.h" #include "otbWrapperInputVectorDataListParameter.h" #include "otbWrapperOutputVectorDataParameter.h" #include "otbWrapperNumericalParameter.h" #include "otbWrapperStringListParameter.h" #include "otbWrapperInputImageListParameter.h" -#include "otbWrapperInputProcessXMLParameter.h" +#include "otbWrapperInputXML.h" +#include "otbWrapperOutputXML.h" #include "otbWrapperProxyParameter.h" #include "otbWrapperParameterKey.h" #include "otbWrapperBoolParameter.h" @@ -169,28 +169,6 @@ const char* Application::GetDescription() const return m_Description.c_str(); } -void Application::SetHaveInXML(bool haveInXML) -{ - m_HaveInXML = haveInXML; - this->Modified(); -} - -bool Application::GetHaveInXML() const -{ - return m_HaveInXML; -} - -void Application::SetHaveOutXML(bool haveOutXML) -{ - m_HaveOutXML = haveOutXML; - this->Modified(); -} - -bool Application::GetHaveOutXML() const -{ - return m_HaveOutXML; -} - void Application::SetDocName(const std::string& value) { m_DocName = value; @@ -331,11 +309,6 @@ std::string Application::GetHtmlExample() return GetDocExample()->GenerateHtmlExample(); } -void Application::ForceInXMLParseFlag() -{ - m_IsInXMLParsed = false; -} - void Application::SetDocLink(const std::string & link) { if (m_Doclink.compare(link) != 0) @@ -368,9 +341,6 @@ Application::Application() m_DocSeeAlso(""), m_DocTags(), m_Doclink(""), - m_HaveInXML(true), - m_HaveOutXML(true), - m_IsInXMLParsed(false), m_IsInPrivateDo(false) { // Don't call Init from the constructor, since it calls a virtual method ! @@ -473,21 +443,9 @@ void Application::Init() { m_DocExample = DocExampleStructure::New(); m_ParameterList = ParameterGroup::New(); - //reset inXML parse checker in case if reinit-ing - m_IsInXMLParsed = false; m_IsInPrivateDo = true; this->DoInit(); m_IsInPrivateDo = false; - - //rashad: global parameters. now used only for inxml and outxml - if(this->GetHaveInXML()) - { - AddInXMLParameter(); - } - if(this->GetHaveOutXML()) - { - AddOutXMLParameter(); - } } template <typename T> @@ -501,25 +459,18 @@ T* downcast_check(Parameter* param) return down; } +void Application::LoadParametersFromXML(const std::string& filename) +{ + otb::Wrapper::XML::Read(filename, this); +} + +void Application::SaveParametersToXML(const std::string& filename) +{ + otb::Wrapper::XML::Write(filename, this); +} + void Application::UpdateParameters() { - //read application from xml only once m_IsInXMLParsed is in charge of it. - std::string inXMLKey = "inxml"; - if (m_HaveInXML && !m_IsInXMLParsed) - { - if ( GetParameterType(inXMLKey) == ParameterType_InputProcessXML && - IsParameterEnabled(inXMLKey) && HasValue(inXMLKey) ) - { - Parameter* param = GetParameterByKey(inXMLKey); - InputProcessXMLParameter* inXMLParam = dynamic_cast<InputProcessXMLParameter*>(param); - if(inXMLParam!=nullptr) - { - // switch on 'm_IsInXMLParsed' before Read() to avoid cyclic calls - m_IsInXMLParsed = true; - inXMLParam->Read(this); - } - } - } m_IsInPrivateDo = true; this->DoUpdateParameters(); m_IsInPrivateDo = false; @@ -858,17 +809,6 @@ int Application::ExecuteAndWriteOutput() outputParam->Write(); } } - //xml writer parameter - else if (m_HaveOutXML && GetParameterType(key) == ParameterType_OutputProcessXML - && IsParameterEnabled(key) && HasValue(key) ) - { - Parameter* param = GetParameterByKey(key); - OutputProcessXMLParameter* outXMLParam = dynamic_cast<OutputProcessXMLParameter*>(param); - if(outXMLParam!=nullptr) - { - outXMLParam->Write(this); - } - } } } diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputProcessXMLParameter.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputXML.cxx similarity index 64% rename from Modules/Wrappers/ApplicationEngine/src/otbWrapperInputProcessXMLParameter.cxx rename to Modules/Wrappers/ApplicationEngine/src/otbWrapperInputXML.cxx index 44b76c6540c673a1680f9612973cd028a8220aef..47da2827ba952865020038f75873b5a0e1b8dae2 100644 --- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputProcessXMLParameter.cxx +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputXML.cxx @@ -18,7 +18,7 @@ * limitations under the License. */ -#include "otbWrapperInputProcessXMLParameter.h" +#include "otbWrapperInputXML.h" #include "otbWrapperChoiceParameter.h" #include "otbWrapperListViewParameter.h" @@ -41,51 +41,10 @@ namespace otb { namespace Wrapper { -InputProcessXMLParameter::InputProcessXMLParameter() +namespace XML { - this->SetKey("inxml"); - this->SetName("Load parameters from XML"); - this->SetDescription("Load application parameters from an XML file."); - this->SetMandatory(false); - this->SetActive(false); - this->SetRole(Role_Input); -} - -InputProcessXMLParameter::~InputProcessXMLParameter() -{ - -} - -bool -InputProcessXMLParameter::SetFileName(std::string value) -{ - // Check if the filename is not empty - if(!value.empty()) - { - // Check that the right extension is given : expected .xml - if (itksys::SystemTools::GetFilenameLastExtension(value) == ".xml") - { - if (itksys::SystemTools::FileExists(value,true)) - { - this->SetValue(value); - return true; - } - } - } - return false; -} - -void -InputProcessXMLParameter::SetValue(const std::string value) -{ - itkDebugMacro("setting member m_FileName to " << value); - this->m_FileName = value; - SetActive(true); - this->Modified(); -} -ImagePixelType -InputProcessXMLParameter::GetPixelTypeFromString(std::string strType) +ImagePixelType GetPixelTypeFromString(std::string strType) { if(strType == "uint8") { @@ -124,29 +83,7 @@ InputProcessXMLParameter::GetPixelTypeFromString(std::string strType) } } -void -InputProcessXMLParameter::otbAppLogInfo(Application::Pointer app, std::string info) -{ - app->GetLogger()->Write(itk::LoggerBase::INFO, info ); -} - -/* copied from Utilities/tinyXMLlib/tinyxml.cpp. Must have a FIX inside tinyxml.cpp */ -FILE* -InputProcessXMLParameter::TiXmlFOpen( const char* filename, const char* mode ) -{ -#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) - FILE* fp = 0; - errno_t err = fopen_s( &fp, filename, mode ); - if ( !err && fp ) - return fp; - return 0; - #else - return fopen( filename, mode ); - #endif -} - -const std::string -InputProcessXMLParameter::GetChildNodeTextOf(TiXmlElement *parentElement, std::string key) +const std::string GetChildNodeTextOf(TiXmlElement* parentElement, std::string key) { std::string value=""; @@ -174,22 +111,15 @@ InputProcessXMLParameter::GetChildNodeTextOf(TiXmlElement *parentElement, std::s return value; } -int -InputProcessXMLParameter::Read(Application::Pointer this_) +int Read(const std::string& filename, Application::Pointer this_) { // Open the xml file TiXmlDocument doc; - //Use itksys::SystemTools::FOpen() and close it below because - //TiXmlDocument::TiXmlFileOpen( ) is not exposed from tinyXML library. Even - //though its available in the TiXmlDocument::SaveFile(). - FILE* fp = itksys::SystemTools::Fopen(m_FileName, "rb"); - - if (!doc.LoadFile(fp , TIXML_ENCODING_UTF8)) - { - fclose(fp); - itkExceptionMacro(<< "Can't open file " << m_FileName); - } + if (!doc.LoadFile(filename , TIXML_ENCODING_UTF8)) + { + itkGenericExceptionMacro(<< "Can't open file " << filename); + } TiXmlHandle handle(&doc); @@ -198,23 +128,15 @@ InputProcessXMLParameter::Read(Application::Pointer this_) if(!n_OTB) { - std::string info = "Input XML file " + std::string(this->GetFileName()) + " is invalid."; - //this->otbAppLogInfo(app,info); + std::string info = "Input XML file " + filename + " is invalid."; } std::string otb_Version; otb_Version = GetChildNodeTextOf(n_OTB,"version"); if(otb_Version != OTB_VERSION_STRING) - otbMsgDebugMacro( << "Input XML was generated with a different version of OTB (" << - otb_Version << ") and current version is OTB (" << OTB_VERSION_STRING << ")" ); - - /* - std::string otb_Version, otb_Build, otb_Platform; - otb_Version = this_->GetChildNodeTextOf(n_OTB,"version"); - otb_Build = GetChildNodeTextOf(n_OTB, "build"); - otb_Platform = this_->GetChildNodeTextOf(n_OTB, "platform"); - */ + otbGenericMsgDebugMacro(<< "Input XML was generated with a different version of OTB (" << otb_Version << ") and current version is OTB (" + << OTB_VERSION_STRING << ")"); int ret = 0; @@ -222,46 +144,11 @@ InputProcessXMLParameter::Read(Application::Pointer this_) std::string app_Name; app_Name = GetChildNodeTextOf(n_AppNode, "name"); - /* - AddMetaData("appname", app_Name); - - app_Descr = this_->GetChildNodeTextOf(n_AppNode, "descr"); - AddMetaData("appdescr", app_Descr); - - TiXmlElement* n_Doc = n_AppNode->FirstChildElement("doc"); - - std::string doc_Name, doc_Descr, doc_Author, doc_Limitation, doc_SeeAlso; - - doc_Name = this_->GetChildNodeTextOf(n_Doc, "name"); - AddMetaData("docname", doc_Name); - - doc_Descr = this_->GetChildNodeTextOf(n_Doc, "longdescr"); - AddMetaData("doclongdescr", doc_Descr); - - doc_Author = this_->GetChildNodeTextOf(n_Doc, "authors"); - AddMetaData("docauthors", doc_Author); - - doc_Limitation = this_->GetChildNodeTextOf(n_Doc, "limitations"); - AddMetaData("doclimitations", doc_Limitation); - - doc_SeeAlso = this_->GetChildNodeTextOf(n_Doc, "seealso"); - AddMetaData("docseealso", doc_SeeAlso); - */ - if(this_->GetName() != app_Name) - { - //hopefully shouldn't reach here ... - /* - std::string message = "Input XML was generated for a different application( " - + app_Name + ") while application loaded is:" + this_->GetName(); - */ - itkWarningMacro( << "Input XML was generated for a different application( " << - app_Name << ") while application loaded is:" <<this_->GetName()); - - fclose(fp); - return -1; - } + { + itkGenericExceptionMacro(<< "Input XML was generated for a different application( " << app_Name << ") while application loaded is:" << this_->GetName()); + } ParameterGroup::Pointer paramGroup = this_->GetParameterList(); @@ -279,15 +166,6 @@ InputProcessXMLParameter::Read(Application::Pointer this_) Parameter* param = this_->GetParameterByKey(key); - // std::cout - // << "'" << paramName << "'\t" - // << key << "\t" - // << typeAsString << "\t" - // << type << "\t" - // << ParameterType_OutputImage << "\t" - // << param->HasUserValue() << "\t" - // << value << std::endl; - param->SetUserValue(true); param->SetActive(true); @@ -402,9 +280,6 @@ InputProcessXMLParameter::Read(Application::Pointer this_) } else if (type == ParameterType_StringList || type == ParameterType_ListView) { - if(values.empty()) - itkWarningMacro(<< key << " has null values"); - this_->SetParameterStringList(key, values); } @@ -415,12 +290,11 @@ InputProcessXMLParameter::Read(Application::Pointer this_) ret = 0; //resetting return to zero, we don't use it anyway for now. - fclose(fp); - return ret; } +} // namespace XML } //end namespace wrapper } //end namespace otb diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperOutputProcessXMLParameter.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperOutputXML.cxx similarity index 79% rename from Modules/Wrappers/ApplicationEngine/src/otbWrapperOutputProcessXMLParameter.cxx rename to Modules/Wrappers/ApplicationEngine/src/otbWrapperOutputXML.cxx index 3b020d798980c922f491e80c263fd7590a93743c..d32e501713ecd213fca3d9261415888cd1b03e9f 100644 --- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperOutputProcessXMLParameter.cxx +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperOutputXML.cxx @@ -18,7 +18,7 @@ * limitations under the License. */ -#include "otbWrapperOutputProcessXMLParameter.h" +#include "otbWrapperOutputXML.h" #include "otbWrapperChoiceParameter.h" #include "otbWrapperListViewParameter.h" @@ -40,25 +40,10 @@ namespace otb { namespace Wrapper { -OutputProcessXMLParameter::OutputProcessXMLParameter() - : m_Node(nullptr) - , m_Appli() +namespace XML { - this->SetKey("outxml"); - this->SetName("Save parameters to XML"); - this->SetDescription("Save application parameters to an XML file."); - this->SetMandatory(false); - this->SetActive(false); - this->SetRole(Role_Output); -} - -OutputProcessXMLParameter::~OutputProcessXMLParameter() -{ - -} -std::string -OutputProcessXMLParameter::pixelTypeToString(ImagePixelType pixType) +std::string pixelTypeToString(ImagePixelType pixType) { std::string type; @@ -108,7 +93,7 @@ OutputProcessXMLParameter::pixelTypeToString(ImagePixelType pixType) return type; } -TiXmlElement* OutputProcessXMLParameter::AddChildNodeTo(TiXmlElement *parent, std::string name, std::string value) +TiXmlElement* AddChildNodeTo(TiXmlElement* parent, std::string name, std::string value) { TiXmlElement * n_Node = new TiXmlElement( name.c_str() ); parent->LinkEndChild( n_Node ); @@ -120,18 +105,16 @@ TiXmlElement* OutputProcessXMLParameter::AddChildNodeTo(TiXmlElement *parent, st return n_Node; } -void -OutputProcessXMLParameter::Write(Application::Pointer app) +void Write(const std::string& filename, Application::Pointer app) { // Check if the filename is not empty - if(m_FileName.empty()) - itkExceptionMacro("The XML output FileName is empty, please set the filename via the method SetFileName"); + if (filename.empty()) + itkGenericExceptionMacro("The XML output FileName is empty, please set the filename via the method SetFileName"); // Check that the right extension is given : expected .xml */ - if (itksys::SystemTools::GetFilenameLastExtension(m_FileName) != ".xml") - { - itkExceptionMacro(<<itksys::SystemTools::GetFilenameLastExtension(m_FileName) - <<" is a wrong Extension FileName : Expected .xml"); + if (itksys::SystemTools::GetFilenameLastExtension(filename) != ".xml") + { + itkGenericExceptionMacro(<< itksys::SystemTools::GetFilenameLastExtension(filename) << " is a wrong Extension FileName : Expected .xml"); } // start creating XML file @@ -152,15 +135,12 @@ OutputProcessXMLParameter::Write(Application::Pointer app) n_OTB->LinkEndChild(n_App); // Finally, write xml contents to file - doc.SaveFile( m_FileName.c_str() ); + doc.SaveFile(filename.c_str()); } -TiXmlElement* -OutputProcessXMLParameter::ParseApplication(Application::Pointer app) +TiXmlElement* ParseApplication(Application::Pointer app) { - m_Appli = app; - TiXmlElement * n_App = new TiXmlElement("application"); - m_Node = n_App; + TiXmlElement* n_App = new TiXmlElement("application"); AddChildNodeTo(n_App, "name", app->GetName()); AddChildNodeTo(n_App, "descr", app->GetDescription()); @@ -185,19 +165,14 @@ OutputProcessXMLParameter::ParseApplication(Application::Pointer app) } // recursive call to ParseGroup(), starting with "" (i.e. GetParameterList()) - this->ParseGroup(std::string("")); - - // reset temporary members - m_Appli = nullptr; - m_Node = nullptr; - return n_App; + ParseGroup(app, n_App, std::string("")); + return n_App; } -void -OutputProcessXMLParameter::ParseGroup(const std::string& group) +void ParseGroup(Application::Pointer app, TiXmlElement* n_App, const std::string& group) { std::string prefix(group); - ParameterGroup::Pointer paramGroup = m_Appli->GetParameterList(); + ParameterGroup::Pointer paramGroup = app->GetParameterList(); if (!group.empty()) { prefix += '.'; @@ -209,7 +184,7 @@ OutputProcessXMLParameter::ParseGroup(const std::string& group) } else { - itkExceptionMacro("Function ParseGroup() expected a group parameter for key "<<group); + itkGenericExceptionMacro("Function ParseGroup() expected a group parameter for key " << group); } } @@ -221,20 +196,18 @@ OutputProcessXMLParameter::ParseGroup(const std::string& group) std::string key = prefix + *it; Parameter *param = paramGroup->GetParameterByKey(*it); std::string paramName = param->GetName(); - ParameterType type = m_Appli->GetParameterType(key); + ParameterType type = app->GetParameterType(key); std::string typeAsString = paramGroup->GetParameterTypeAsString(type); // if param is a Group, inspect this group with a recursive call if (type == ParameterType_Group) { - this->ParseGroup(key); + ParseGroup(app, n_App, key); } else { - bool paramExists = m_Appli->HasUserValue(key) && - m_Appli->IsParameterEnabled(key) && - m_Appli->GetParameterRole(key) == Role_Input; - if ( type == ParameterType_OutputProcessXML ) + bool paramExists = app->HasUserValue(key) && app->IsParameterEnabled(key) && app->GetParameterRole(key) == Role_Input; + if (type == ParameterType_OutputProcessXML) { paramExists = false; } @@ -265,18 +238,18 @@ OutputProcessXMLParameter::ParseGroup(const std::string& group) type == ParameterType_InputVectorDataList || type == ParameterType_StringList || type == ParameterType_ListView ) { - values = m_Appli->GetParameterStringList(key); - hasValueList = true; + values = app->GetParameterStringList(key); + hasValueList = true; } else if (type == ParameterType_Int || type == ParameterType_Radius || type == ParameterType_RAM ) { - value = m_Appli->GetParameterAsString(key); + value = app->GetParameterAsString(key); } else if(type == ParameterType_Float) { std::ostringstream oss; oss << std::setprecision(std::numeric_limits<float>::digits10+1); - oss << m_Appli->GetParameterFloat( key ); + oss << app->GetParameterFloat(key); value = oss.str(); } else if ( type == ParameterType_String || type == ParameterType_InputFilename || @@ -285,12 +258,12 @@ OutputProcessXMLParameter::ParseGroup(const std::string& group) type == ParameterType_OutputVectorData || type == ParameterType_OutputFilename || type == ParameterType_Bool) { - value = m_Appli->GetParameterString(key); + value = app->GetParameterString(key); } else if(key == "rand") { std::ostringstream strm; - strm << m_Appli->GetParameterInt("rand"); + strm << app->GetParameterInt("rand"); value = strm.str(); } else if (type == ParameterType_InputProcessXML) @@ -352,24 +325,23 @@ OutputProcessXMLParameter::ParseGroup(const std::string& group) AddChildNodeTo(n_Values, "value",*strIt); } } - m_Node->LinkEndChild(n_Parameter); + n_App->LinkEndChild(n_Parameter); } // dig into Choice parameter if (type == ParameterType_Choice) { std::string choiceGroup(key); choiceGroup += '.'; - choiceGroup += m_Appli->GetParameterString(key); - this->ParseGroup(choiceGroup); + choiceGroup += app->GetParameterString(key); + ParseGroup(app, n_App, choiceGroup); } } } } -std::string OutputProcessXMLParameter::MakeCommandLine(Application::Pointer application) +std::string MakeCommandLine(Application::Pointer application) { - OutputProcessXMLParameter::Pointer outXMLParam = OutputProcessXMLParameter::New(); - TiXmlElement* XMLAppElement = outXMLParam->ParseApplication(application); + TiXmlElement* XMLAppElement = ParseApplication(application); // Create command line from the XML document TiXmlElement * pName, *pParam; @@ -437,6 +409,6 @@ std::string OutputProcessXMLParameter::MakeCommandLine(Application::Pointer appl } -} //end namespace wrapper - +} // namespace XML +} // namespace Wrapper } //end namespace otb diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperParameterGroup.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperParameterGroup.cxx index 3a8ec354b5328750e5dfaa7381002ddabe23cab6..5cb7932941d31e8c22b699c3cde7aee3254e1656 100644 --- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperParameterGroup.cxx +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperParameterGroup.cxx @@ -25,7 +25,6 @@ #include "otbWrapperInputFilenameParameter.h" #include "otbWrapperInputFilenameListParameter.h" #include "otbWrapperOutputFilenameParameter.h" -#include "otbWrapperOutputProcessXMLParameter.h" #include "otbWrapperInputImageParameter.h" #include "otbWrapperInputVectorDataParameter.h" #include "otbWrapperOutputImageParameter.h" @@ -34,7 +33,6 @@ #include "otbWrapperStringListParameter.h" #include "otbWrapperInputImageListParameter.h" #include "otbWrapperInputVectorDataListParameter.h" -#include "otbWrapperInputProcessXMLParameter.h" #include "otbWrapperParameterKey.h" #include "otbWrapperProxyParameter.h" #include "otbWrapperBoolParameter.h" @@ -163,46 +161,6 @@ ParameterGroup::ClearChoices(std::string paramKey) } } -void ParameterGroup::AddOutXMLParameter() -{ - Parameter::Pointer tmpParam; - tmpParam = OutputProcessXMLParameter::New(); -// const std::string key = tmpParam->GetKey(); -// const std::string descr = tmpParam->GetDescription(); -const std::string defaultXMLFileName = std::string(GetName()) + ".xml"; - tmpParam->SetActive(false); - AddParameter(tmpParam); - - tmpParam = nullptr; - /* - AddParameter(ParameterType_OutputProcessXML, key, descr); - SetParameterDescription(key, descr); - MandatoryOff(key); - //SetParameterString(key, defaultXMLFileName); - DisableParameter(key); - */ -} - -void ParameterGroup::AddInXMLParameter() -{ - Parameter::Pointer tmpParam; - tmpParam = InputProcessXMLParameter::New(); -// const std::string key = tmpParam->GetKey(); -// const std::string descr = tmpParam->GetDescription(); - const std::string defaultXMLFileName = std::string(GetName()) + ".xml"; - tmpParam->SetActive(false); - AddParameter(tmpParam); - - tmpParam = nullptr; - /* - AddParameter(ParameterType_InputProcessXML, key, descr); - SetParameterDescription(key, descr); - MandatoryOff(key); - //SetParameterString(key, defaultXMLFileName); - DisableParameter(key); -*/ -} - /** Get the choices made in the QListWidget */ std::vector<int> ParameterGroup::GetSelectedItems(std::string paramKey) @@ -369,16 +327,6 @@ ParameterGroup::AddParameter(ParameterType type, std::string paramKey, std::stri newParam = RAMParameter::New(); } break; - case ParameterType_OutputProcessXML: - { - newParam = OutputProcessXMLParameter::New(); - } - break; - case ParameterType_InputProcessXML: - { - newParam = InputProcessXMLParameter::New(); - } - break; case ParameterType_Bool: { newParam = BoolParameter::New(); diff --git a/Modules/Wrappers/CommandLine/src/otbApplicationLauncherCommandLine.cxx b/Modules/Wrappers/CommandLine/src/otbApplicationLauncherCommandLine.cxx index 816e56d81fc7ea3f9c9f178198cc999eea1e6cb7..e456eabf88b97b5a3f03217358983eef9c1b394d 100644 --- a/Modules/Wrappers/CommandLine/src/otbApplicationLauncherCommandLine.cxx +++ b/Modules/Wrappers/CommandLine/src/otbApplicationLauncherCommandLine.cxx @@ -28,221 +28,6 @@ #include "otbMPIConfig.h" #endif -const std::string GetChildNodeTextOf(TiXmlElement *parentElement, std::string key); -std::string PrepareExpressionFromXML(std::string filename); -std::vector<std::string> PrepareVectorExpressionFromXML(std::string filename); -std::string CleanWord(const std::string & word); - - -std::string PrepareExpressionFromXML(std::string filename) -{ - std::string expression; - - if(filename.empty()) - { - std::cerr <<"Input XML Filename is empty" << std::endl; - return expression; - } - std::string ext = filename.substr(filename.size()-4,filename.size()); - if(ext != ".xml" ) - std::cerr << ext << " is a wrong extension: Expected .xml " << __FILE__ << std::endl; - - // Open the xml file - TiXmlDocument doc; - - //Use itksys::SystemTools::FOpen() and close it below because - //TiXmlDocument::TiXmlFileOpen( ) is not exposed from tinyXML library. Even - //though its available in the TiXmlDocument::SaveFile(). - FILE* fp = itksys::SystemTools::Fopen(filename, "rb"); - - if (!doc.LoadFile(fp , TIXML_ENCODING_UTF8)) - { - std::cerr << "Can't open file " << filename << std::endl; - fclose(fp); - exit(1); - - } - - TiXmlHandle handle(&doc); - - TiXmlElement *n_OTB; - n_OTB = handle.FirstChild("OTB").Element(); - - if(!n_OTB) - { - std::string info = "Input XML file " + filename + " is invalid."; - std::cerr << info << std::endl; - fclose(fp); - exit(1); - } - - TiXmlElement *n_AppNode = n_OTB->FirstChildElement("application"); - - std::string moduleName; - moduleName = GetChildNodeTextOf(n_AppNode, "name"); - /* - AddMetaData("appname", app_Name); - - app_Descr = this_->GetChildNodeTextOf(n_AppNode, "descr"); - AddMetaData("appdescr", app_Descr); - - TiXmlElement* n_Doc = n_AppNode->FirstChildElement("doc"); - - std::string doc_Name, doc_Descr, doc_Author, doc_Limitation, doc_SeeAlso; - - doc_Name = this_->GetChildNodeTextOf(n_Doc, "name"); - AddMetaData("docname", doc_Name); - - doc_Descr = this_->GetChildNodeTextOf(n_Doc, "longdescr"); - AddMetaData("doclongdescr", doc_Descr); - - doc_Author = this_->GetChildNodeTextOf(n_Doc, "authors"); - AddMetaData("docauthors", doc_Author); - - doc_Limitation = this_->GetChildNodeTextOf(n_Doc, "limitations"); - AddMetaData("doclimitations", doc_Limitation); - - doc_SeeAlso = this_->GetChildNodeTextOf(n_Doc, "seealso"); - AddMetaData("docseealso", doc_SeeAlso); - */ - - expression.append(moduleName); - - for( TiXmlElement* n_Parameter = n_AppNode->FirstChildElement("parameter"); n_Parameter != nullptr; - n_Parameter = n_Parameter->NextSiblingElement() ) - { - std::string key="-"; - key.append(GetChildNodeTextOf(n_Parameter, "key")); - - TiXmlElement* n_Values = nullptr; - n_Values = n_Parameter->FirstChildElement("values"); - if(n_Values) - { - std::string values; - for(TiXmlElement* n_Value = n_Values->FirstChildElement("value"); n_Value != nullptr; - n_Value = n_Value->NextSiblingElement()) - { - values.append(n_Value->GetText()); - values.append(" "); - } - values = values.substr(0,values.size()-1); - expression.append(" "); - expression.append(key); - expression.append(" "); - expression.append(values); - } - else - { - std::string value; - value = GetChildNodeTextOf(n_Parameter, "value"); - - expression.append(" "); - expression.append(key); - expression.append(" "); - expression.append(value); - - std::string type = GetChildNodeTextOf(n_Parameter, "type"); - if (type == "OutputImage") - { - std::string t = GetChildNodeTextOf(n_Parameter, "pixtype"); - expression.append(" "); - expression.append(t); - } - } - } - - fclose(fp); - - return expression; -} - -std::vector<std::string> PrepareVectorExpressionFromXML(std::string filename) -{ - std::vector<std::string> expression; - - if(filename.empty()) - { - std::cerr <<"Input XML Filename is empty" << std::endl; - return expression; - } - std::string ext = filename.substr(filename.size()-4,filename.size()); - if(ext != ".xml" ) - std::cerr << ext << " is a wrong extension: Expected .xml " << __FILE__ << std::endl; - - // Open the xml file - TiXmlDocument doc; - - //Use itksys::SystemTools::FOpen() and close it below because - //TiXmlDocument::TiXmlFileOpen( ) is not exposed from tinyXML library. Even - //though its available in the TiXmlDocument::SaveFile(). - FILE* fp = itksys::SystemTools::Fopen(filename, "rb"); - - if (!doc.LoadFile(fp , TIXML_ENCODING_UTF8)) - { - std::cerr << "Can't open file " << filename << std::endl; - fclose(fp); - exit(1); - - } - - TiXmlHandle handle(&doc); - - TiXmlElement *n_OTB; - n_OTB = handle.FirstChild("OTB").Element(); - - if(!n_OTB) - { - std::string info = "Input XML file " + filename + " is invalid."; - std::cerr << info << std::endl; - fclose(fp); - exit(1); - } - - TiXmlElement *n_AppNode = n_OTB->FirstChildElement("application"); - - std::string moduleName; - moduleName = GetChildNodeTextOf(n_AppNode, "name"); - - expression.push_back(CleanWord(moduleName)); - - for( TiXmlElement* n_Parameter = n_AppNode->FirstChildElement("parameter"); n_Parameter != nullptr; - n_Parameter = n_Parameter->NextSiblingElement() ) - { - std::string key="-"; - key.append(GetChildNodeTextOf(n_Parameter, "key")); - expression.push_back(CleanWord(key)); - - TiXmlElement* n_Values = nullptr; - n_Values = n_Parameter->FirstChildElement("values"); - if(n_Values) - { - std::string values; - for(TiXmlElement* n_Value = n_Values->FirstChildElement("value"); n_Value != nullptr; - n_Value = n_Value->NextSiblingElement()) - { - expression.push_back(CleanWord(n_Value->GetText())); - } - } - else - { - std::string value; - value = GetChildNodeTextOf(n_Parameter, "value"); - expression.push_back(CleanWord(value)); - - std::string type = GetChildNodeTextOf(n_Parameter, "type"); - if (type == "OutputImage") - { - std::string t = GetChildNodeTextOf(n_Parameter, "pixtype"); - expression.push_back(CleanWord(t)); - } - } - } - - fclose(fp); - - return expression; -} - std::string CleanWord(const std::string & word) { std::string res(""); @@ -272,26 +57,18 @@ int main(int argc, char* argv[]) std::vector<std::string> vexp; - std::string exp; - if (strcmp(argv[1], "-inxml") == 0) - { - vexp = PrepareVectorExpressionFromXML(argv[2]); - } - else + // Construct the string expression + for (int i = 1; i < argc; i++) + { + std::string strarg(argv[i]); + std::string cleanArg = CleanWord(strarg); + if (cleanArg.empty()) { - // Construct the string expression - for (int i = 1; i < argc; i++) - { - std::string strarg(argv[i]); - std::string cleanArg = CleanWord(strarg); - if (cleanArg.empty()) - { - // Empty argument ! - continue; - } - vexp.push_back(cleanArg); - } + // Empty argument! + continue; } + vexp.push_back(cleanArg); + } if (vexp.empty()) { @@ -317,31 +94,3 @@ int main(int argc, char* argv[]) #endif return success ? EXIT_SUCCESS : EXIT_FAILURE; } - -const std::string GetChildNodeTextOf(TiXmlElement *parentElement, std::string key) -{ - std::string value=""; - - if(parentElement) - { - TiXmlElement* childElement = nullptr; - childElement = parentElement->FirstChildElement(key.c_str()); - - //same as childElement->GetText() does but that call is failing if there is - //no such node. - //but the below code works and is a replacement for GetText() - if(childElement) - { - const TiXmlNode* child = childElement->FirstChild(); - if ( child ) - { - const TiXmlText* childText = child->ToText(); - if ( childText ) - { - value = childText->Value(); - } - } - } - } - return value; -} diff --git a/Modules/Wrappers/CommandLine/src/otbWrapperCommandLineLauncher.cxx b/Modules/Wrappers/CommandLine/src/otbWrapperCommandLineLauncher.cxx index b5ef08d6acaf9814579046f6a50a0db917dac063..01a1f6810581bcc47f84ca6d9c17959564c329ae 100644 --- a/Modules/Wrappers/CommandLine/src/otbWrapperCommandLineLauncher.cxx +++ b/Modules/Wrappers/CommandLine/src/otbWrapperCommandLineLauncher.cxx @@ -31,7 +31,6 @@ #include "otbWrapperOutputVectorDataParameter.h" #include "otbWrapperNumericalParameter.h" #include "otbWrapperListViewParameter.h" -#include "otbWrapperOutputProcessXMLParameter.h" #include "otbWrapperAddProcessToWatchEvent.h" // List value parameter @@ -137,19 +136,27 @@ bool CommandLineLauncher::Execute() bool CommandLineLauncher::ExecuteAndWriteOutputNoCatch() { - if (this->BeforeExecute() == false) - { - return false; - } - if( m_Application->ExecuteAndWriteOutput() == 0 ) - { - this->DisplayOutputParameters(); - } - else - { - return false; - } - return true; + if (this->BeforeExecute() == false) + { + return false; + } + + if (m_Application->ExecuteAndWriteOutput() != 0) + { + return false; + } + + this->DisplayOutputParameters(); + + // After execution, write parameters to the xml file if requested + const char* attrib = "-outxml"; + if (m_Parser->IsAttributExists(attrib, m_VExpression)) + { + std::vector<std::string> outXMLValues = m_Parser->GetAttribut(attrib, m_VExpression); + m_Application->SaveParametersToXML(outXMLValues[0]); + } + + return true; } bool CommandLineLauncher::ExecuteAndWriteOutput() @@ -358,22 +365,16 @@ CommandLineLauncher::ParamResultType CommandLineLauncher::LoadParameters() itkExceptionMacro("No application loaded"); } - /* Check for inxml parameter. If exists Update all Parameters from xml and - * check for user defined parameters for overriding those from XML - */ - const char *inXMLKey = "inxml"; - const char *attrib = "-inxml"; - const bool paramInXMLExists(m_Parser->IsAttributExists(attrib, m_VExpression)); - if(paramInXMLExists) + // Read parameters from xml file if provided + const char* attrib = "-inxml"; + if (m_Parser->IsAttributExists(attrib, m_VExpression)) { - std::vector<std::string> inXMLValues; - inXMLValues = m_Parser->GetAttribut(attrib, m_VExpression); - m_Application->SetParameterString(inXMLKey, inXMLValues[0]); - m_Application->UpdateParameters(); + std::vector<std::string> inXMLValues = m_Parser->GetAttribut(attrib, m_VExpression); + m_Application->LoadParametersFromXML(inXMLValues[0]); } - // Check for the progress report parameter - if (m_Parser->IsAttributExists("-progress", m_VExpression) == true) + // Check for the progress report parameter + if (m_Parser->IsAttributExists("-progress", m_VExpression) == true) { std::vector<std::string> val = m_Parser->GetAttribut("-progress", m_VExpression); if (val.size() == 1 && (val[0] == "1" || val[0] == "true")) @@ -429,21 +430,10 @@ CommandLineLauncher::ParamResultType CommandLineLauncher::LoadParameters() // Multiple values parameters m_Application->SetParameterStringList(paramKey, values); } - else if (type == ParameterType_Choice || - type == ParameterType_Float || - type == ParameterType_Int || - type == ParameterType_Radius || - type == ParameterType_Directory || - type == ParameterType_String || - type == ParameterType_InputFilename || - type == ParameterType_OutputFilename || - type == ParameterType_InputImage || - type == ParameterType_OutputImage || - type == ParameterType_InputVectorData || - type == ParameterType_OutputVectorData || - type == ParameterType_RAM || - type == ParameterType_OutputProcessXML || - type == ParameterType_Bool) // || type == ParameterType_InputProcessXML) + else if (type == ParameterType_Choice || type == ParameterType_Float || type == ParameterType_Int || type == ParameterType_Radius || + type == ParameterType_Directory || type == ParameterType_String || type == ParameterType_InputFilename || + type == ParameterType_OutputFilename || type == ParameterType_InputImage || type == ParameterType_OutputImage || + type == ParameterType_InputVectorData || type == ParameterType_OutputVectorData || type == ParameterType_RAM || type == ParameterType_Bool) { // Single value parameter m_Application->SetParameterString(paramKey, values[0]); @@ -718,9 +708,9 @@ std::string CommandLineLauncher::DisplayParameterHelp(const Parameter::Pointer & { oss << "<float> "; } - else if (type == ParameterType_InputFilename || type == ParameterType_OutputFilename ||type == ParameterType_Directory || type == ParameterType_InputImage || type == ParameterType_OutputProcessXML || type == ParameterType_InputProcessXML || - type == ParameterType_InputVectorData || type == ParameterType_OutputVectorData || type == ParameterType_String || - type == ParameterType_Choice || (type == ParameterType_ListView && singleSelectionForListView)) + else if (type == ParameterType_InputFilename || type == ParameterType_OutputFilename || type == ParameterType_Directory || + type == ParameterType_InputImage || type == ParameterType_InputVectorData || type == ParameterType_OutputVectorData || + type == ParameterType_String || type == ParameterType_Choice || (type == ParameterType_ListView && singleSelectionForListView)) { oss << "<string> "; } @@ -894,6 +884,8 @@ bool CommandLineLauncher::CheckKeyValidity(std::string& refKey) appKeyList.push_back("progress"); appKeyList.push_back("testenv"); appKeyList.push_back("version"); + appKeyList.push_back("inxml"); + appKeyList.push_back("outxml"); // Check if each key in the expression exists in the application for (unsigned int i = 0; i < expKeyList.size(); i++) diff --git a/Modules/Wrappers/QGIS/src/otbQgisDescriptor.cxx b/Modules/Wrappers/QGIS/src/otbQgisDescriptor.cxx index 6d757472971fe66922b22cc70c550dc4f6bc764a..609a8e658750f459382830d6c818eee13315ab2f 100644 --- a/Modules/Wrappers/QGIS/src/otbQgisDescriptor.cxx +++ b/Modules/Wrappers/QGIS/src/otbQgisDescriptor.cxx @@ -131,13 +131,10 @@ int main(int argc, char* argv[]) const ParameterType type = appli->GetParameterType(name); const std::string description = appli->GetParameterName(name); if ( type == ParameterType_Group || - type == ParameterType_OutputProcessXML || - type == ParameterType_InputProcessXML || type == ParameterType_RAM || param->GetRole() == Role_Output ) { // group parameter cannot have any value. - // outxml and inxml parameters are not relevant for QGIS and is considered a bit noisy // ram is added by qgis-otb processing provider plugin as an advanced parameter for all apps // parameter role cannot be of type Role_Output continue; diff --git a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetInputProcessXMLParameter.h b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetInputProcessXMLParameter.h deleted file mode 100644 index dbd5e4a45b737abfc47564fd951623c03f2e628b..0000000000000000000000000000000000000000 --- a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetInputProcessXMLParameter.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef otbWrapperQtWidgetInputProcessXMLParameter_h -#define otbWrapperQtWidgetInputProcessXMLParameter_h - -#include <QtWidgets> -#include "otbWrapperInputProcessXMLParameter.h" -#include "otbWrapperQtWidgetParameterBase.h" - - -namespace otb -{ -namespace Wrapper -{ - -/** \class QtWidgetInputProcessXMLParameter - * \brief - * - * \ingroup OTBQtWidget - */ -class OTBQtWidget_EXPORT QtWidgetInputProcessXMLParameter : public QtWidgetParameterBase -{ - Q_OBJECT -public: - QtWidgetInputProcessXMLParameter(InputProcessXMLParameter*, QtWidgetModel*, QWidget*); - ~QtWidgetInputProcessXMLParameter() override; - - const QLineEdit* GetInput() const; - QLineEdit* GetInput(); - -protected slots: - void SetFileName( const QString& value ); - void SelectFile(); - -private: - QtWidgetInputProcessXMLParameter(const QtWidgetInputProcessXMLParameter&) = delete; - void operator=(const QtWidgetInputProcessXMLParameter&) = delete; - - void DoCreateWidget() override; - - void DoUpdateGUI() override; - - - InputProcessXMLParameter::Pointer m_XMLParam; - - QHBoxLayout * m_HLayout; - QLineEdit* m_Input; - QPushButton * m_Button; -}; - - -} -} - -#endif diff --git a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetMainWindow.h b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetMainWindow.h index 70d922b8116411a6201c0cb9569d74534153ee34..0bd6704b59175cf80e237f95503d4b5a463781ad 100644 --- a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetMainWindow.h +++ b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetMainWindow.h @@ -65,6 +65,8 @@ public slots: void UpdateMessageAfterExecution(int status); void on_executeButton_clicked(); void CopyCommandLine(); + void LoadFromXML(); + void SaveToXML(); private: ::Ui::AppMainWindow* ui; diff --git a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetModel.h b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetModel.h index 13dffe9fe1078859117eb80c4ae90bdb1be445e4..dc6ec0b88dc32a476caf52a7781b9ce32d5bb418 100644 --- a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetModel.h +++ b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetModel.h @@ -110,13 +110,6 @@ public: /** Logger debug message sender */ void SendLogDEBUG( const std::string & mes ); - /** Used by inxml when forcing xml parse flag to update widget data via UpdateGui */ - void UpdateAllWidgets() - { - GetApplication()->ForceInXMLParseFlag(); - emit UpdateGui(); - } - signals: void SetApplicationReady(bool); diff --git a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetOutputProcessXMLParameter.h b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetOutputProcessXMLParameter.h deleted file mode 100644 index 5896481a4d4fe39cf9bfd96c5cd26c147cf36ef7..0000000000000000000000000000000000000000 --- a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetOutputProcessXMLParameter.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef otbWrapperQtWidgetOutputProcessXMLParameter_h -#define otbWrapperQtWidgetOutputProcessXMLParameter_h - -#include <QtWidgets> -#include "otbWrapperOutputProcessXMLParameter.h" -#include "otbWrapperQtWidgetParameterBase.h" - - -namespace otb -{ -namespace Wrapper -{ - -/** \class QtWidgetOutputProcessXMLParameter - * \brief - * - * \ingroup OTBQtWidget - */ -class OTBQtWidget_EXPORT QtWidgetOutputProcessXMLParameter : public QtWidgetParameterBase -{ - Q_OBJECT -public: - QtWidgetOutputProcessXMLParameter(OutputProcessXMLParameter*, QtWidgetModel*, QWidget*); - ~QtWidgetOutputProcessXMLParameter() override; - - const QLineEdit* GetInput() const; - QLineEdit* GetInput(); - -public slots: - void SetFileName( const QString& value ); - -protected slots: - void SelectFile(); - -private: - QtWidgetOutputProcessXMLParameter(const QtWidgetOutputProcessXMLParameter&) = delete; - void operator=(const QtWidgetOutputProcessXMLParameter&) = delete; - - void DoCreateWidget() override; - - void DoUpdateGUI() override; - - - OutputProcessXMLParameter::Pointer m_XMLParam; - - QHBoxLayout * m_HLayout; - QLineEdit* m_Input; - QPushButton * m_Button; -}; - - -} -} - -#endif diff --git a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetParameterGroup.h b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetParameterGroup.h index a84acb452ddb484f934f8c7d4f6275f312a36f95..3eb77f9f800174904918eb1cc00473d216c60abf 100644 --- a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetParameterGroup.h +++ b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetParameterGroup.h @@ -24,8 +24,8 @@ #include <QtWidgets> #include "otbWrapperParameterGroup.h" #include "otbWrapperQtWidgetParameterBase.h" -#include "otbWrapperInputProcessXMLParameter.h" -#include "otbWrapperOutputProcessXMLParameter.h" +#include "otbWrapperInputXML.h" +#include "otbWrapperOutputXML.h" namespace otb { diff --git a/Modules/Wrappers/QtWidget/src/CMakeLists.txt b/Modules/Wrappers/QtWidget/src/CMakeLists.txt index 41fc9f1b190b29da9d7272d41f245b0c06d1a863..461bd06209a5bc418ae79972b7e221efe0c55bc1 100644 --- a/Modules/Wrappers/QtWidget/src/CMakeLists.txt +++ b/Modules/Wrappers/QtWidget/src/CMakeLists.txt @@ -24,7 +24,6 @@ set(OTBQtWidget_SRC otbWrapperQtWidgetParameterLabel.cxx otbWrapperQtWidgetView.cxx otbWrapperQtWidgetMainWindow.cxx - otbWrapperQtWidgetInputProcessXMLParameter.cxx otbWrapperQtWidgetIntParameter.cxx otbWrapperQtWidgetInputVectorDataListParameter.cxx otbWrapperQtWidgetSimpleProgressReport.cxx @@ -44,7 +43,6 @@ set(OTBQtWidget_SRC otbWrapperQtWidgetParameterGroup.cxx otbWrapperQtWidgetInputFilenameListParameter.cxx otbWrapperQtWidgetRAMParameter.cxx - otbWrapperQtWidgetOutputProcessXMLParameter.cxx otbWrapperQtWidgetParameterBase.cxx otbWrapperQtWidgetInputImageParameter.cxx otbWrapperQtWidgetStringListParameter.cxx @@ -70,8 +68,6 @@ set(OTBQtWidget_MOC_HDR ../include/otbWrapperQtWidgetInputVectorDataParameter.h ../include/otbWrapperQtWidgetOutputImageParameter.h ../include/otbWrapperQtWidgetOutputVectorDataParameter.h - ../include/otbWrapperQtWidgetOutputProcessXMLParameter.h - ../include/otbWrapperQtWidgetInputProcessXMLParameter.h ../include/otbWrapperQtWidgetParameterGroup.h ../include/otbWrapperQtWidgetParameterLabel.h ../include/otbWrapperQtWidgetParameterBase.h diff --git a/Modules/Wrappers/QtWidget/src/appmainwindow.ui b/Modules/Wrappers/QtWidget/src/appmainwindow.ui index c376f1984f3cec0518739bf1dd22fe3b6fb4f4be..da67595ad265bef7a54f74b1f2e151265e104dca 100644 --- a/Modules/Wrappers/QtWidget/src/appmainwindow.ui +++ b/Modules/Wrappers/QtWidget/src/appmainwindow.ui @@ -171,6 +171,9 @@ </property> <addaction name="separator"/> <addaction name="actionCopy_command_line"/> + <addaction name="actionLoad_from_XML"/> + <addaction name="actionSave_to_XML"/> + <addaction name="separator"/> <addaction name="actionQuit"/> </widget> <widget class="QMenu" name="menuHelp"> @@ -195,31 +198,6 @@ <string>F1</string> </property> </action> - <action name="actionAboutOTB"> - <property name="text"> - <string>About</string> - </property> - </action> - <action name="actionAbout"> - <property name="text"> - <string>About</string> - </property> - </action> - <action name="actionView_log"> - <property name="text"> - <string>View log</string> - </property> - </action> - <action name="actionLoad_parameters"> - <property name="text"> - <string>Load parameters</string> - </property> - </action> - <action name="actionSave_parameters"> - <property name="text"> - <string>Save parameters</string> - </property> - </action> <action name="actionQuit"> <property name="text"> <string>Quit</string> @@ -228,14 +206,9 @@ <string>Ctrl+Q</string> </property> </action> - <action name="actionReset_parameters"> - <property name="text"> - <string>Reset parameters</string> - </property> - </action> - <action name="actionReset"> + <action name="actionCopy_command_line"> <property name="text"> - <string>Reset All</string> + <string>Copy command line to clipboard</string> </property> </action> <action name="actionLoad_from_XML"> @@ -248,11 +221,6 @@ <string>Save to XML</string> </property> </action> - <action name="actionCopy_command_line"> - <property name="text"> - <string>Copy command line to clipboard</string> - </property> - </action> </widget> <customwidgets> <customwidget> diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputProcessXMLParameter.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputProcessXMLParameter.cxx deleted file mode 100644 index fdd95d1135ec9ebe62d2ccfe179a963dd28ab488..0000000000000000000000000000000000000000 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputProcessXMLParameter.cxx +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "otbWrapperQtWidgetInputProcessXMLParameter.h" - - -#include <otbQtAdapters.h> - - -namespace otb -{ -namespace Wrapper -{ - -QtWidgetInputProcessXMLParameter::QtWidgetInputProcessXMLParameter(InputProcessXMLParameter* param, QtWidgetModel* m, QWidget * parent) -: QtWidgetParameterBase(param, m, parent), - m_XMLParam(param) -{ -} - -QtWidgetInputProcessXMLParameter::~QtWidgetInputProcessXMLParameter() -{ -} - -const QLineEdit* -QtWidgetInputProcessXMLParameter -::GetInput() const -{ - return m_Input; -} - -QLineEdit* -QtWidgetInputProcessXMLParameter -::GetInput() -{ - return m_Input; -} - -void QtWidgetInputProcessXMLParameter::DoUpdateGUI() -{ - if (m_XMLParam->HasUserValue()) - { - // Update the lineEdit - QString text( - QFile::decodeName( m_XMLParam->GetFileName() ) - ); - - if (text != m_Input->text()) - m_Input->setText(text); - } -} - -void QtWidgetInputProcessXMLParameter::DoCreateWidget() -{ - // Set up input text edit - m_HLayout = new QHBoxLayout; - m_HLayout->setSpacing(0); - m_HLayout->setContentsMargins(0, 0, 0, 0); - m_Input = new QLineEdit(this); - m_Input->setToolTip( - QString::fromStdString( m_XMLParam->GetDescription() ) - ); - connect( m_Input, &QLineEdit::textChanged, this, &QtWidgetInputProcessXMLParameter::SetFileName ); - connect( m_Input, &QLineEdit::textChanged, GetModel(), &QtWidgetModel::NotifyUpdate ); - - m_HLayout->addWidget(m_Input); - - // Set up input text edit - m_Button = new QPushButton(this); - m_Button->setText("..."); - m_Button->setToolTip("Select file..."); - m_Button->setMaximumWidth(m_Button->width()); - connect( m_Button, &QPushButton::clicked, this, &QtWidgetInputProcessXMLParameter::SelectFile ); - m_HLayout->addWidget(m_Button); - - this->setLayout(m_HLayout); -} - - -void -QtWidgetInputProcessXMLParameter -::SelectFile() -{ - assert( m_Input!=NULL ); - - QString filename( - otb::GetOpenFilename( - this, - QString(), - m_Input->text(), - tr( "XML File (*.xml)" ), - NULL, - QFileDialog::ReadOnly - ) - ); - - if( filename.isEmpty() ) - return; - - m_Input->setText( filename ); -} - - -void QtWidgetInputProcessXMLParameter::SetFileName(const QString& value) -{ - // load xml file name - if( m_XMLParam->SetFileName( - QFile::encodeName( value ).constData() ) ) - { - // notify of value change - QString key( m_XMLParam->GetKey() ); - emit ParameterChanged(key); - GetModel()->GetApplication()->ForceInXMLParseFlag(); - } -} - -} - -} diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetMainWindow.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetMainWindow.cxx index 93c3f459e2e43b49d43e879a84e3f83ccfa30345..539cad7cef40a7f5d80b8d71d4644f8e47255d57 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetMainWindow.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetMainWindow.cxx @@ -19,11 +19,11 @@ */ #include "otbWrapperQtWidgetMainWindow.h" +#include "otbWrapperOutputXML.h" #include <QtWidgets> #include "otbWrapperQtWidgetView.h" -#include "otbWrapperQtWidgetOutputProcessXMLParameter.h" #include "ui_appmainwindow.h" @@ -44,11 +44,13 @@ QtMainWindow::QtMainWindow(Application::Pointer app, QtWidgetView* gui, QWidget* ui->scrollArea->setWidget(gui); // Connect menu buttons - connect(ui->actionQuit, &QAction::triggered, this, &QMainWindow::close); const auto url = std::string("https://www.orfeo-toolbox.org/CookBook/Applications/app_") + app->GetName() + std::string(".html"); connect(ui->actionDocumentation, &QAction::triggered, this, [=] { QDesktopServices::openUrl(QUrl(QString::fromStdString(url))); }); connect(ui->actionCopy_command_line, &QAction::triggered, this, &QtMainWindow::CopyCommandLine); + connect(ui->actionLoad_from_XML, &QAction::triggered, this, &QtMainWindow::LoadFromXML); + connect(ui->actionSave_to_XML, &QAction::triggered, this, &QtMainWindow::SaveToXML); + connect(ui->actionQuit, &QAction::triggered, this, &QMainWindow::close); // Setup execute / cancel button ui->executeButton->setDefault(true); @@ -128,7 +130,7 @@ void QtMainWindow::on_executeButton_clicked() void QtMainWindow::CopyCommandLine() { // Get command line - std::string cmdLine = OutputProcessXMLParameter::MakeCommandLine(gui->GetModel()->m_Application); + std::string cmdLine = otb::Wrapper::XML::MakeCommandLine(gui->GetModel()->m_Application); // Copy it to clipboard QClipboard* clipboard = QGuiApplication::clipboard(); @@ -138,6 +140,27 @@ void QtMainWindow::CopyCommandLine() gui->GetModel()->SendLogINFO(cmdLine); } +void QtMainWindow::LoadFromXML() +{ + QString filename = QFileDialog::getOpenFileName(this, tr("Load from XML"), "", tr("XML files (*.xml);;All files (*)")); + + if (!filename.isNull()) + { + gui->GetModel()->m_Application->LoadParametersFromXML(filename.toStdString()); + gui->GetModel()->UpdateGui(); + } +} + +void QtMainWindow::SaveToXML() +{ + QString filename = QFileDialog::getSaveFileName(this, tr("Save to XML"), "", tr("XML files (*.xml);;All files (*)")); + + if (!filename.isNull()) + { + gui->GetModel()->m_Application->SaveParametersToXML(filename.toStdString()); + } +} + QtMainWindow::~QtMainWindow() { delete ui; diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetModel.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetModel.cxx index dc0e9278dd532fed974eb1c8adc900e9fc5fd32b..9047819d649166b1e25ba2f0e6ca9953dd8c7e7f 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetModel.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetModel.cxx @@ -21,7 +21,7 @@ #include "otbWrapperQtWidgetModel.h" //Use to create command line from the application parameters -#include "otbWrapperOutputProcessXMLParameter.h" +#include "otbWrapperOutputXML.h" using std::string; diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetOutputProcessXMLParameter.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetOutputProcessXMLParameter.cxx deleted file mode 100644 index 42418fb5f174fabaf7aaeb4f4142581b67eafbc3..0000000000000000000000000000000000000000 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetOutputProcessXMLParameter.cxx +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "otbWrapperQtWidgetOutputProcessXMLParameter.h" - -#include <otbQtAdapters.h> - -namespace otb -{ -namespace Wrapper -{ - -QtWidgetOutputProcessXMLParameter::QtWidgetOutputProcessXMLParameter(OutputProcessXMLParameter* param, QtWidgetModel* m, QWidget * parent) -: QtWidgetParameterBase(param, m, parent), - m_XMLParam(param) -{ -} - -QtWidgetOutputProcessXMLParameter::~QtWidgetOutputProcessXMLParameter() -{ -} - -const QLineEdit* -QtWidgetOutputProcessXMLParameter -::GetInput() const -{ - return m_Input; -} - -QLineEdit* -QtWidgetOutputProcessXMLParameter -::GetInput() -{ - return m_Input; -} - -void QtWidgetOutputProcessXMLParameter::DoUpdateGUI() -{ - // Update the lineEdit - QString text( - QFile::decodeName( m_XMLParam->GetFileName() ) - ); -; - if (text != m_Input->text()) - m_Input->setText(text); -} - -void QtWidgetOutputProcessXMLParameter::DoCreateWidget() -{ - // Set up input text edit - m_HLayout = new QHBoxLayout; - m_HLayout->setSpacing(0); - m_HLayout->setContentsMargins(0, 0, 0, 0); - m_Input = new QLineEdit(this); - m_Input->setToolTip( - QString::fromStdString( m_XMLParam->GetDescription() ) - ); - connect( m_Input, &QLineEdit::textChanged, this, &QtWidgetOutputProcessXMLParameter::SetFileName ); - connect( m_Input, &QLineEdit::textChanged, GetModel(), &QtWidgetModel::NotifyUpdate ); - - m_HLayout->addWidget(m_Input); - - // Set up input text edit - m_Button = new QPushButton(this); - m_Button->setText("..."); - m_Button->setToolTip("Select file..."); - m_Button->setMaximumWidth(m_Button->width()); - connect( m_Button, &QPushButton::clicked, this, &QtWidgetOutputProcessXMLParameter::SelectFile ); - m_HLayout->addWidget(m_Button); - - this->setLayout(m_HLayout); -} - - -void -QtWidgetOutputProcessXMLParameter -::SelectFile() -{ - assert( m_Input!=NULL ); - - QString filename( - otb::GetSaveFilename( - this, - QString(), - m_Input->text(), - tr( "XML File (*.xml)" ), - NULL ) - ); - - if( filename.isEmpty() ) - return; - - m_Input->setText( filename ); -} - - -void QtWidgetOutputProcessXMLParameter::SetFileName(const QString& value) -{ - // save xml file name - m_XMLParam->SetValue( - QFile::encodeName( value ).constData() - ); - - // notify of value change - QString key( m_XMLParam->GetKey() ); - emit ParameterChanged(key); - - -} - -} -} diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetParameterFactory.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetParameterFactory.cxx index 2f382da98d8ba177b763b3264fae37c5a239f378..2b2ae79bd1add2aee3f4f376ff7d22168626ca09 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetParameterFactory.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetParameterFactory.cxx @@ -33,14 +33,12 @@ #include "otbWrapperQtWidgetInputFilenameListParameter.h" #include "otbWrapperQtWidgetInputImageParameter.h" #include "otbWrapperQtWidgetInputImageListParameter.h" -#include "otbWrapperQtWidgetInputProcessXMLParameter.h" #include "otbWrapperQtWidgetInputVectorDataListParameter.h" #include "otbWrapperQtWidgetInputVectorDataParameter.h" #include "otbWrapperQtWidgetListViewParameter.h" #include "otbWrapperQtWidgetModel.h" #include "otbWrapperQtWidgetOutputFilenameParameter.h" #include "otbWrapperQtWidgetOutputImageParameter.h" -#include "otbWrapperQtWidgetOutputProcessXMLParameter.h" #include "otbWrapperQtWidgetOutputVectorDataParameter.h" #include "otbWrapperQtWidgetParameterBase.h" #include "otbWrapperQtWidgetParameterGroup.h" @@ -121,8 +119,6 @@ QtWidgetParameterFactory::CreateQtWidget( Parameter* param, QtWidgetModel* model CREATEWIDGET(BoolParameter, QtWidgetBoolParameter) CREATEWIDGET(ParameterGroup, QtWidgetParameterGroup) CREATEWIDGET(RAMParameter, QtWidgetRAMParameter) - CREATEWIDGET(OutputProcessXMLParameter, QtWidgetOutputProcessXMLParameter) - CREATEWIDGET(InputProcessXMLParameter, QtWidgetInputProcessXMLParameter) #undef CREATEWIDGET if (widget) diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetParameterGroup.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetParameterGroup.cxx index 5aadbca9ef2e90ef9261442586dc71882302a225..7faea2ce2294065ac3a3b9d331891c9585e4451e 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetParameterGroup.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetParameterGroup.cxx @@ -62,15 +62,9 @@ void QtWidgetParameterGroup::DoCreateWidget() { ParameterGroup* paramAsGroup = dynamic_cast<ParameterGroup*>(param); ChoiceParameter* paramAsChoice = dynamic_cast<ChoiceParameter*>(param); - OutputProcessXMLParameter* paramAsInXML = dynamic_cast<OutputProcessXMLParameter*>(param); - InputProcessXMLParameter* paramAsOutXML = dynamic_cast<InputProcessXMLParameter*>(param); - bool paramIsXML = false; - if(paramAsInXML != nullptr || paramAsOutXML != nullptr) - paramIsXML = true; - - if (paramAsGroup == nullptr && paramAsChoice == nullptr && !paramIsXML) - { + if (paramAsGroup == nullptr && paramAsChoice == nullptr) + { // Label (col 1) QWidget* label = new QtWidgetParameterLabel( rawParam , this); gridLayout->addWidget(label, i, 1); diff --git a/Modules/Wrappers/SWIG/src/otbApplication.i b/Modules/Wrappers/SWIG/src/otbApplication.i index 896016f85cd3f57816980e21b683ee351abf3cc2..b4174a1141c050a20fb0ab6a43a93d1aa1600cbb 100644 --- a/Modules/Wrappers/SWIG/src/otbApplication.i +++ b/Modules/Wrappers/SWIG/src/otbApplication.i @@ -95,8 +95,6 @@ namespace Wrapper ParameterType_Group, ParameterType_ListView, ParameterType_RAM, - ParameterType_OutputProcessXML, - ParameterType_InputProcessXML, ParameterType_Bool } ParameterType; @@ -219,6 +217,9 @@ public: int Execute(); int ExecuteAndWriteOutput(); + void LoadParametersFromXML(const std::string& filename); + void SaveParametersToXML(const std::string& filename); + #if SWIGPYTHON Logger* GetLogger(); #endif @@ -579,12 +580,10 @@ class ApplicationProxy(object): def GetParameterTypeAsString(self, parameter_type): return { - ParameterType_InputProcessXML : 'ParameterType_InputProcessXML', ParameterType_String : 'ParameterType_String', ParameterType_InputFilename : 'ParameterType_InputFilename', ParameterType_OutputImage : 'ParameterType_OutputImage', ParameterType_OutputVectorData : 'ParameterType_OutputVectorData', - ParameterType_OutputProcessXML : 'ParameterType_OutputProcessXML', ParameterType_OutputFilename : 'ParameterType_OutputFilename', ParameterType_Directory : 'ParameterType_Directory', ParameterType_InputImage : 'ParameterType_InputImage', @@ -615,10 +614,10 @@ class ApplicationProxy(object): def SetParameterValue(self, paramKey, value): paramType = self.GetParameterType(paramKey) - if paramType in [ParameterType_InputProcessXML, ParameterType_RAM, + if paramType in [ParameterType_RAM, ParameterType_String, ParameterType_InputFilename, ParameterType_OutputImage, ParameterType_OutputVectorData, - ParameterType_OutputProcessXML, ParameterType_OutputFilename, + ParameterType_OutputFilename, ParameterType_Directory, ParameterType_InputImage, ParameterType_InputVectorData]: return self.SetParameterString(paramKey, value) @@ -649,10 +648,10 @@ class ApplicationProxy(object): def GetParameterValue(self, paramKey): paramType = self.GetParameterType(paramKey) - if paramType in [ParameterType_InputProcessXML, + if paramType in [ ParameterType_String, ParameterType_InputFilename, ParameterType_OutputImage, ParameterType_OutputVectorData, - ParameterType_OutputProcessXML, ParameterType_OutputFilename, + ParameterType_OutputFilename, ParameterType_Directory, ParameterType_InputImage, ParameterType_InputVectorData]: return self.GetParameterString(paramKey) diff --git a/Modules/Wrappers/SWIG/test/python/PythonInXMLTest.py b/Modules/Wrappers/SWIG/test/python/PythonInXMLTest.py index be223358df88ffa2f417a5c8c320f87b7120400f..70207aaf49acc0655e6213e8e3f3431a45a6944e 100644 --- a/Modules/Wrappers/SWIG/test/python/PythonInXMLTest.py +++ b/Modules/Wrappers/SWIG/test/python/PythonInXMLTest.py @@ -26,10 +26,10 @@ # def test(otb, argv): - app = otb.Registry.CreateApplication('BandMath') + app = otb.Registry.CreateApplication('BandMath') - app.SetParameterString("inxml", argv[1]) - app.UpdateParameters() + app.LoadParametersFromXML(argv[1]) + #app.UpdateParameters() - app.SetParameterString("out" , argv[-1]) - app.ExecuteAndWriteOutput() + app.SetParameterString("out" , argv[-1]) + app.ExecuteAndWriteOutput() diff --git a/Modules/Wrappers/SWIG/test/python/PythonNewStyleParametersTest.py b/Modules/Wrappers/SWIG/test/python/PythonNewStyleParametersTest.py index d1c0fa45a5e840fe3e1ff3482e39a35f99b29dd3..ea6203a0545a537a4f60bc7a556fd69d947b21d6 100644 --- a/Modules/Wrappers/SWIG/test/python/PythonNewStyleParametersTest.py +++ b/Modules/Wrappers/SWIG/test/python/PythonNewStyleParametersTest.py @@ -98,14 +98,6 @@ def test(otb, argv): app.SetParameterString('outputs.mode', 'orthofit') cm_assert(app.OUTPUTS.MODE, 'orthofit') - #14 - inputxml parameter set - app.INXML = argv[3] - cm_assert(app.GetParameterString('inxml'), argv[3]) - - #15 - outputxml parameter get - app.SetParameterString('outxml', 'output.xml') - cm_assert("output.xml", app.OUTXML) - #16 - parameter float get app.SetParameterFloat('elev.default', 5.0) cm_assert(5.0, app.ELEV.DEFAULT) diff --git a/Modules/Wrappers/SWIG/test/python/PythonOutXMLTest.py b/Modules/Wrappers/SWIG/test/python/PythonOutXMLTest.py index dcbe45c4a52514521ed50a4ae34df24a5c141e23..dca30937e29c676d209b719fd43750e1547824b3 100644 --- a/Modules/Wrappers/SWIG/test/python/PythonOutXMLTest.py +++ b/Modules/Wrappers/SWIG/test/python/PythonOutXMLTest.py @@ -26,17 +26,16 @@ # def test(otb, argv): - imagelist = argv[1:-2] - exp = "cos(im1b1)+im2b1*im3b1-im3b2+ndvi(im3b3, im3b4)" - out = argv[-2] - outxml = argv[-1] - app = otb.Registry.CreateApplication('BandMath') - app.SetParameterStringList("il", imagelist, True) - app.SetParameterString("out", out, True) - app.SetParameterString("exp", exp, True) - app.SetParameterString("outxml", outxml, True) - app.UpdateParameters() -#for paramKey in app.GetParametersKeys(): - #app.GetParameterValue(paramKey) - #print app.HasUserValue(paramKey) - app.ExecuteAndWriteOutput() + imagelist = argv[1:-2] + exp = "cos(im1b1)+im2b1*im3b1-im3b2+ndvi(im3b3, im3b4)" + out = argv[-2] + outxml = argv[-1] + + app = otb.Registry.CreateApplication('BandMath') + app.SetParameterStringList("il", imagelist, True) + app.SetParameterString("out", out, True) + app.SetParameterString("exp", exp, True) + + app.SaveParametersToXML(outxml) + + app.ExecuteAndWriteOutput()