Commit 983e1f8a authored by Rashad Kanavath's avatar Rashad Kanavath
Browse files

Backed out changeset ba7f2d5bb10c

No related merge requests found
Showing with 176 additions and 194 deletions
+176 -194
...@@ -17,32 +17,153 @@ ...@@ -17,32 +17,153 @@
=========================================================================*/ =========================================================================*/
#include "otbWrapperCommandLineLauncher.h" #include "otbWrapperCommandLineLauncher.h"
#include "otbTinyXML.h"
int main(int argc, char* argv[]) const std::string GetChildNodeTextOf(TiXmlElement *parentElement, std::string key);
std::string PrepareExpressionFromXML(std::string filename);
std::string PrepareExpressionFromXML(std::string filename)
{ {
std::string exp; std::string expression;
int start = 1;
if (argc < 2) if(filename.empty())
{ {
std::cerr << "Usage 1: " << argv[0] << " module_name [MODULEPATH] [arguments]" << std::endl; std::cerr <<"Input XML Filename is empty" << std::endl;
std::cerr << "Usage 2: " << argv[0] << " [MODULEPATH] -inxml otbApplicationOutput.xml" << std::endl; return expression;
return EXIT_FAILURE;
} }
// Construct the string expression std::string ext = filename.substr(filename.size()-4,filename.size());
for (int i = start; i < argc; i++) if(ext != ".xml" )
std::cerr << ext << " is a wrong extension: Expected .xml " << __FILE__ << std::endl;
// Open the xml file
TiXmlDocument doc;
FILE* fp = fopen( filename.c_str (), "rb" ); //must be changed TiXmlFileOpen
//from tinyxml.cpp
if (!doc.LoadFile(fp , TIXML_ENCODING_UTF8))
{
std::cerr << "Can't open file " << filename << std::endl;
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;
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 != NULL;
n_Parameter = n_Parameter->NextSiblingElement() )
{
std::string key="-";
key.append(GetChildNodeTextOf(n_Parameter, "key"));
TiXmlElement* n_Values = NULL;
n_Values = n_Parameter->FirstChildElement("values");
if(n_Values)
{ {
if (i != argc - 1) std::string values;
{ for(TiXmlElement* n_Value = n_Values->FirstChildElement("value"); n_Value != NULL;
exp.append(argv[i]); n_Value = n_Value->NextSiblingElement())
exp.append(" ");
}
else
{ {
exp.append(argv[i]); 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);
} }
}
return expression;
}
int main(int argc, char* argv[])
{
if (argc < 2)
{
std::cerr << "Usage : " << argv[0] << " module_name [MODULEPATH] [arguments]" << std::endl;
return EXIT_FAILURE;
}
std::string exp;
if( strcmp(argv[1], "-inxml") == 0 )
{
exp = PrepareExpressionFromXML(argv[2]);
}
else
{
// Construct the string expression
for (int i = 1; i < argc; i++)
{
if (i != argc - 1)
{
exp.append(argv[i]);
exp.append(" ");
}
else
{
exp.append(argv[i]);
}
}
}
// std::cerr << exp << ":\n";
typedef otb::Wrapper::CommandLineLauncher LauncherType; typedef otb::Wrapper::CommandLineLauncher LauncherType;
LauncherType::Pointer launcher = LauncherType::New(); LauncherType::Pointer launcher = LauncherType::New();
...@@ -61,3 +182,31 @@ int main(int argc, char* argv[]) ...@@ -61,3 +182,31 @@ int main(int argc, char* argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
const std::string GetChildNodeTextOf(TiXmlElement *parentElement, std::string key)
{
std::string value="";
if(parentElement)
{
TiXmlElement* childElement = 0;
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;
}
...@@ -98,143 +98,6 @@ bool CommandLineLauncher::Load(const std::string & exp) ...@@ -98,143 +98,6 @@ bool CommandLineLauncher::Load(const std::string & exp)
return this->Load(); return this->Load();
} }
const std::string CommandLineLauncher::GetChildNodeTextOf(TiXmlElement *parentElement, std::string key)
{
std::string value="";
if(parentElement)
{
TiXmlElement* childElement = 0;
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;
}
std::string CommandLineLauncher::PrepareExpressionFromXML(std::string filename, std::string modulePath,
std::string cmdExpression)
{
std::string expression;
if(filename.empty())
{
itkExceptionMacro( <<"Input XML Filename is empty" );
}
std::string ext = filename.substr(filename.size()-4,filename.size());
if(ext != ".xml" )
{
itkExceptionMacro( << ext << " is a wrong extension: Expected .xml");
}
// Open the xml file
TiXmlDocument doc;
FILE* fp = fopen( filename.c_str (), "rb" ); //must be changed TiXmlFileOpen
//from tinyxml.cpp
if (!doc.LoadFile(fp , TIXML_ENCODING_UTF8))
{
itkExceptionMacro( << "Can't open file " << filename );
}
TiXmlHandle handle(&doc);
TiXmlElement *n_OTB;
n_OTB = handle.FirstChild("OTB").Element();
if(!n_OTB)
{
itkExceptionMacro( << "Input XML file " << filename << " doesn't contain a valid otb application.");
return expression;
}
TiXmlElement *n_AppNode = n_OTB->FirstChildElement("application");
std::string moduleName;
moduleName = GetChildNodeTextOf(n_AppNode, "name");
expression.append(moduleName);
if(!modulePath.empty())
{
expression.append(" ");
expression.append(modulePath);
}
for( TiXmlElement* n_Parameter = n_AppNode->FirstChildElement("parameter"); n_Parameter != NULL;
n_Parameter = n_Parameter->NextSiblingElement() )
{
std::string key="-";
std::string value;
key.append(GetChildNodeTextOf(n_Parameter, "key"));
/** check if the user has an values to be overridden from xml
TODO check if the extra key name is correct
**/
if (m_Parser->IsAttributExists(key, cmdExpression) == true)
{
std::vector<std::string> cmdValues;
cmdValues = m_Parser->GetAttribut(key, cmdExpression);
std::string values = "";
for(std::vector<std::string>::iterator vit = cmdValues.begin(); vit !=cmdValues.end(); ++vit)
{
values.append(*vit);
values.append(" ");
}
value = values.substr(0, values.size()-1);
}
else //take value from xml
{
TiXmlElement* n_Values = NULL;
n_Values = n_Parameter->FirstChildElement("values");
if(n_Values)
{
std::string values;
for(TiXmlElement* n_Value = n_Values->FirstChildElement("value"); n_Value != NULL;
n_Value = n_Value->NextSiblingElement())
{
values.append(n_Value->GetText());
values.append(" ");
}
value = values.substr(0,values.size()-1);
}
else
{
value = GetChildNodeTextOf(n_Parameter, "value");
}
std::string pixtype = GetChildNodeTextOf(n_Parameter, "pixtype");
if(!pixtype.empty())
{
value.append(" ");
value.append(pixtype);
}
} //end else take value from xml
expression.append(" ");
expression.append(key);
expression.append(" ");
expression.append(value);
}
return expression;
}
bool CommandLineLauncher::Load() bool CommandLineLauncher::Load()
{ {
// Add a space to clarify output logs // Add a space to clarify output logs
...@@ -244,24 +107,6 @@ bool CommandLineLauncher::Load() ...@@ -244,24 +107,6 @@ bool CommandLineLauncher::Load()
itkExceptionMacro("No expression specified..."); itkExceptionMacro("No expression specified...");
} }
std::string tmp;
/*No Module given. check for -inxml and prepare the expression */
if (m_Parser->GetModuleName(tmp, m_Expression) != CommandLineParser::NOMODULENAME)
{
if (m_Parser->IsAttributExists("-inxml",m_Expression) == true)
{
std::vector<std::string> inXMLValue;
inXMLValue = m_Parser->GetAttribut("-inxml", m_Expression);
if (inXMLValue.size() == 0)
{
std::cerr << "ERROR: Missing parameter value for inxml" << std::endl;
return MISSINGPARAMETERVALUE;
}
std::string modulePath = m_Expression.substr( 0, m_Expression.find(" -inxml"));
m_Expression = this->PrepareExpressionFromXML(inXMLValue[0], modulePath, m_Expression);
}
}
if (this->CheckParametersPrefix() == false) if (this->CheckParametersPrefix() == false)
{ {
std::cerr << "ERROR: Parameter keys have to set using \"-\", not \"--\"" << std::endl; std::cerr << "ERROR: Parameter keys have to set using \"-\", not \"--\"" << std::endl;
...@@ -525,11 +370,6 @@ CommandLineLauncher::ParamResultType CommandLineLauncher::LoadParameters() ...@@ -525,11 +370,6 @@ CommandLineLauncher::ParamResultType CommandLineLauncher::LoadParameters()
{ {
std::vector<std::string> inXMLValues; std::vector<std::string> inXMLValues;
inXMLValues = m_Parser->GetAttribut(attrib, m_Expression); inXMLValues = m_Parser->GetAttribut(attrib, m_Expression);
if (inXMLValues.size() == 0)
{
std::cerr << "ERROR: Missing parameter value for " << inXMLKey << std::endl;
return MISSINGPARAMETERVALUE;
}
m_Application->SetParameterString(inXMLKey, inXMLValues[0]); m_Application->SetParameterString(inXMLKey, inXMLValues[0]);
m_Application->UpdateParameters(); m_Application->UpdateParameters();
} }
......
/*========================================================================= /*=========================================================================
Program: ORFEO Toolbox Program: ORFEO Toolbox
Language: C++ Language: C++
Date: $Date$ Date: $Date$
Version: $Revision$ Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details. See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information. PURPOSE. See the above copyright notices for more information.
=========================================================================*/ =========================================================================*/
#ifndef __otbWrapperCommandLineLauncher_h #ifndef __otbWrapperCommandLineLauncher_h
#define __otbWrapperCommandLineLauncher_h #define __otbWrapperCommandLineLauncher_h
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include "otbWrapperParameter.h" #include "otbWrapperParameter.h"
#include "itksys/SystemTools.hxx" #include "itksys/SystemTools.hxx"
#include "otbWrapperCommandLineParser.h" #include "otbWrapperCommandLineParser.h"
#include "otbTinyXML.h"
#include "itkStdStreamLogOutput.h" #include "itkStdStreamLogOutput.h"
...@@ -38,7 +37,7 @@ namespace otb ...@@ -38,7 +37,7 @@ namespace otb
{ {
namespace Wrapper namespace Wrapper
{ {
/** \class CommandLineLauncher /** \class CommandLineLauncher
* \brief This class check the validity of a command line application. * \brief This class check the validity of a command line application.
* *
...@@ -58,13 +57,13 @@ public: ...@@ -58,13 +57,13 @@ public:
typedef itk::Object Superclass; typedef itk::Object Superclass;
typedef itk::SmartPointer<Self> Pointer; typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer; typedef itk::SmartPointer<const Self> ConstPointer;
/** Defining ::New() static method */ /** Defining ::New() static method */
itkNewMacro(Self); itkNewMacro(Self);
/** RTTI support */ /** RTTI support */
itkTypeMacro(CommandLineLauncher, itk::Object); itkTypeMacro(CommandLineLauncher, itk::Object);
/** Parse result enum */ /** Parse result enum */
typedef CommandLineParser::ParseResultType ParseResultType; typedef CommandLineParser::ParseResultType ParseResultType;
typedef enum { OKPARAM, MISSINGMANDATORYPARAMETER, typedef enum { OKPARAM, MISSINGMANDATORYPARAMETER,
...@@ -111,12 +110,6 @@ public: ...@@ -111,12 +110,6 @@ public:
/** Performs specific action for testing environment */ /** Performs specific action for testing environment */
void LoadTestEnv(); void LoadTestEnv();
/*TODO: Code duplication with InputProcessXMLParameter. should be avoided */
const std::string GetChildNodeTextOf(TiXmlElement *parentElement, std::string key);
std::string PrepareExpressionFromXML(std::string filename, std::string modulePath,
std::string cmdExpression);
protected: protected:
/** Constructor */ /** Constructor */
CommandLineLauncher(); CommandLineLauncher();
...@@ -171,7 +164,7 @@ private: ...@@ -171,7 +164,7 @@ private:
CommandLineLauncher(const CommandLineLauncher &); //purposely not implemented CommandLineLauncher(const CommandLineLauncher &); //purposely not implemented
void operator =(const CommandLineLauncher&); //purposely not implemented void operator =(const CommandLineLauncher&); //purposely not implemented
std::string m_Path; std::string m_Path;
Application::Pointer m_Application; Application::Pointer m_Application;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment