From 3d9e0a5bb0880393e0ca6ff1b1654330f28809b4 Mon Sep 17 00:00:00 2001 From: Guillaume Pasero <guillaume.pasero@c-s.fr> Date: Wed, 4 Nov 2015 15:50:10 +0100 Subject: [PATCH] BUG: Mantis-1098: fix interactive edition of InputProcessXMLParameter in QtWidget --- .../otbWrapperInputProcessXMLParameter.h | 13 +----- .../src/otbWrapperApplication.cxx | 3 +- .../otbWrapperInputProcessXMLParameter.cxx | 40 +++++++++++++------ ...rapperQtWidgetInputProcessXMLParameter.cxx | 27 +++++++------ 4 files changed, 46 insertions(+), 37 deletions(-) diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputProcessXMLParameter.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputProcessXMLParameter.h index be5f9dc215..1db4f6ecc2 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputProcessXMLParameter.h +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputProcessXMLParameter.h @@ -43,19 +43,10 @@ public: // Get Value //TODO otbGetObjectMemberMacro(StringParam, Value , std::string); - void SetFileName(std::string value) - { - this->SetValue(value); - } + bool SetFileName(std::string 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(); - } + virtual void SetValue(const std::string value); ImagePixelType GetPixelTypeFromString(std::string pixTypeAsString); diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx index 8176e2f7ff..5f0075229d 100644 --- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx @@ -807,7 +807,8 @@ void Application::SetParameterString(std::string parameter, std::string value) else if (dynamic_cast<InputProcessXMLParameter*>(param)) { InputProcessXMLParameter* paramDown = dynamic_cast<InputProcessXMLParameter*>(param); - paramDown->SetValue(value); + if ( !paramDown->SetFileName(value) ) + otbAppLogCRITICAL( <<"Invalid XML parameter filename " << value <<"."); } } diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputProcessXMLParameter.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputProcessXMLParameter.cxx index 87b94e868d..be17bb948f 100644 --- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputProcessXMLParameter.cxx +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputProcessXMLParameter.cxx @@ -41,6 +41,34 @@ 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.c_str(),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) { @@ -134,18 +162,6 @@ InputProcessXMLParameter::GetChildNodeTextOf(TiXmlElement *parentElement, std::s int InputProcessXMLParameter::Read(Application::Pointer this_) { - - // Check if the filename is not empty - if(m_FileName.empty()) - itkExceptionMacro(<<"The XML input 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) << " " << m_FileName << " " - <<" is a wrong Extension FileName : Expected .xml"); - } - // Open the xml file TiXmlDocument doc; diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputProcessXMLParameter.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputProcessXMLParameter.cxx index fbd32e34e9..d7b768675a 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputProcessXMLParameter.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputProcessXMLParameter.cxx @@ -34,10 +34,13 @@ QtWidgetInputProcessXMLParameter::~QtWidgetInputProcessXMLParameter() void QtWidgetInputProcessXMLParameter::DoUpdateGUI() { - // Update the lineEdit - QString text( m_XMLParam->GetFileName() ); - if (text != m_Input->text()) - m_Input->setText(text); + if (m_XMLParam->HasUserValue()) + { + // Update the lineEdit + QString text( m_XMLParam->GetFileName() ); + if (text != m_Input->text()) + m_Input->setText(text); + } } void QtWidgetInputProcessXMLParameter::DoCreateWidget() @@ -85,15 +88,13 @@ void QtWidgetInputProcessXMLParameter::SelectFile() void QtWidgetInputProcessXMLParameter::SetFileName(const QString& value) { // load xml file name - m_XMLParam->SetValue(value.toAscii().constData()); - - // notify of value change - QString key( m_XMLParam->GetKey() ); - - emit ParameterChanged(key); - - GetModel()->UpdateAllWidgets(); - + if (m_XMLParam->SetFileName(value.toAscii().constData())) + { + // notify of value change + QString key( m_XMLParam->GetKey() ); + emit ParameterChanged(key); + GetModel()->UpdateAllWidgets(); + } } } -- GitLab