From c03c509869a05b161f01aee3cfcbe7a731f9c4bd Mon Sep 17 00:00:00 2001 From: Julien Malik <julien.malik@c-s.fr> Date: Wed, 28 Sep 2011 15:36:15 +0200 Subject: [PATCH] ENH: finalize output vector data support --- .../otbWrapperApplication.cxx | 14 ++- .../ApplicationEngine/otbWrapperApplication.h | 1 - .../otbWrapperOutputVectorDataParameter.h | 42 ++++++++- Code/Wrappers/QtWidget/CMakeLists.txt | 1 + ...apperQtWidgetOutputVectorDataParameter.cxx | 91 +++++++++++++++++++ ...WrapperQtWidgetOutputVectorDataParameter.h | 71 +++++++++++++++ .../otbWrapperQtWidgetParameterFactory.cxx | 2 + 7 files changed, 215 insertions(+), 7 deletions(-) create mode 100644 Code/Wrappers/QtWidget/otbWrapperQtWidgetOutputVectorDataParameter.cxx create mode 100644 Code/Wrappers/QtWidget/otbWrapperQtWidgetOutputVectorDataParameter.h diff --git a/Code/ApplicationEngine/otbWrapperApplication.cxx b/Code/ApplicationEngine/otbWrapperApplication.cxx index 6343a27253..12c572f58a 100644 --- a/Code/ApplicationEngine/otbWrapperApplication.cxx +++ b/Code/ApplicationEngine/otbWrapperApplication.cxx @@ -45,7 +45,6 @@ namespace Wrapper Application::Application() : m_Name(""), m_Description(""), - m_WroteOutput(0), m_Logger(itk::Logger::New()) { // Don't call Init from the constructor, since it calls a virtual method ! @@ -112,7 +111,6 @@ void Application::Execute() void Application::ExecuteAndWriteOutput() { this->Execute(); - m_WroteOutput = 0; std::vector<std::string> paramList = GetParametersKeys(true); for (std::vector<std::string>::const_iterator it = paramList.begin(); it != paramList.end(); @@ -124,9 +122,17 @@ void Application::ExecuteAndWriteOutput() Parameter* param = GetParameterByKey(*it); OutputImageParameter* outputParam = dynamic_cast<OutputImageParameter*>(param); outputParam->InitializeWriters(); - AddProcess(outputParam->GetWriter(),"Writer "); + AddProcess(outputParam->GetWriter(),"Writer"); + outputParam->Write(); + } + else if (GetParameterType(*it) == ParameterType_OutputVectorData + && IsParameterEnabled(*it) ) + { + Parameter* param = GetParameterByKey(*it); + OutputVectorDataParameter* outputParam = dynamic_cast<OutputVectorDataParameter*>(param); + outputParam->InitializeWriters(); + AddProcess(outputParam->GetWriter(),"Writer"); outputParam->Write(); - m_WroteOutput++; } } } diff --git a/Code/ApplicationEngine/otbWrapperApplication.h b/Code/ApplicationEngine/otbWrapperApplication.h index b9de197113..b81f193d1e 100644 --- a/Code/ApplicationEngine/otbWrapperApplication.h +++ b/Code/ApplicationEngine/otbWrapperApplication.h @@ -368,7 +368,6 @@ private: std::string m_Name; std::string m_Description; ParameterGroup::Pointer m_ParameterList; - unsigned int m_WroteOutput; itk::Logger::Pointer m_Logger; diff --git a/Code/ApplicationEngine/otbWrapperOutputVectorDataParameter.h b/Code/ApplicationEngine/otbWrapperOutputVectorDataParameter.h index e8d31f23ea..987c7de284 100644 --- a/Code/ApplicationEngine/otbWrapperOutputVectorDataParameter.h +++ b/Code/ApplicationEngine/otbWrapperOutputVectorDataParameter.h @@ -18,9 +18,11 @@ #ifndef __otbWrapperOutputVectorDataParameter_h #define __otbWrapperOutputVectorDataParameter_h -#include "otbVectorData.h" #include "otbWrapperParameter.h" +#include "otbVectorData.h" +#include "otbVectorDataFileWriter.h" + namespace otb { namespace Wrapper @@ -51,6 +53,13 @@ public: /** Get the value */ itkGetObjectMacro(VectorData, VectorDataType); + /** Return true if a filename is set */ + bool HasValue() const + { + std::string filename(this->GetFileName()); + return !filename.empty(); + } + /** Return any value */ void SetValue(VectorDataType* vd) { @@ -64,9 +73,35 @@ public: return m_VectorData; } - itkSetStringMacro(FileName); + void SetFileName (const char* filename) + { + m_FileName = filename; + SetActive(true); + } + void SetFileName (const std::string& filename) + { + this->SetFileName(filename.c_str()); + } + itkGetStringMacro(FileName); + void Write() + { + m_Writer->SetFileName(m_FileName); + m_Writer->SetInput(m_VectorData); + m_Writer->Update(); + } + + itk::ProcessObject* GetWriter() + { + return m_Writer; + } + + void InitializeWriters() + { + m_Writer = otb::VectorDataFileWriter<VectorDataType>::New(); + } + protected: /** Constructor */ OutputVectorDataParameter() @@ -79,9 +114,12 @@ protected: virtual ~OutputVectorDataParameter() {} + VectorDataType::Pointer m_VectorData; std::string m_FileName; + otb::VectorDataFileWriter<VectorDataType>::Pointer m_Writer; + private: OutputVectorDataParameter(const Parameter &); //purposely not implemented void operator =(const Parameter&); //purposely not implemented diff --git a/Code/Wrappers/QtWidget/CMakeLists.txt b/Code/Wrappers/QtWidget/CMakeLists.txt index e5d8b49c97..0f151fdd57 100644 --- a/Code/Wrappers/QtWidget/CMakeLists.txt +++ b/Code/Wrappers/QtWidget/CMakeLists.txt @@ -10,6 +10,7 @@ set( WrappersQtWidget_MOC_HDR otbWrapperQtWidgetInputImageParameter.h otbWrapperQtWidgetInputImageListParameter.h otbWrapperQtWidgetOutputImageParameter.h + otbWrapperQtWidgetOutputVectorDataParameter.h otbWrapperQtWidgetParameterGroup.h otbWrapperQtWidgetParameterLabel.h otbWrapperQtWidgetParameterBase.h diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetOutputVectorDataParameter.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetOutputVectorDataParameter.cxx new file mode 100644 index 0000000000..21af7a65a7 --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetOutputVectorDataParameter.cxx @@ -0,0 +1,91 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "otbWrapperQtWidgetOutputVectorDataParameter.h" +#include "otbWrapperTypes.h" + +namespace otb +{ +namespace Wrapper +{ + +QtWidgetOutputVectorDataParameter::QtWidgetOutputVectorDataParameter(OutputVectorDataParameter* param, QtWidgetModel* m) +: QtWidgetParameterBase(param, m), + m_OutputVectorDataParam(param) +{ +} + +QtWidgetOutputVectorDataParameter::~QtWidgetOutputVectorDataParameter() +{ +} + +void QtWidgetOutputVectorDataParameter::DoUpdateGUI() +{ + +} + +void QtWidgetOutputVectorDataParameter::DoCreateWidget() +{ + m_HLayout = new QHBoxLayout; + m_HLayout->setSpacing(0); + m_HLayout->setContentsMargins(0, 0, 0, 0); + + m_Input = new QLineEdit; + m_Input->setToolTip( m_OutputVectorDataParam->GetDescription() ); + connect( m_Input, SIGNAL(textChanged(const QString&)), this, SLOT(SetFileName(const QString&)) ); + connect( m_Input, SIGNAL(textChanged(const QString&)), GetModel(), SLOT(NotifyUpdate()) ); + m_HLayout->addWidget(m_Input); + + m_Button = new QPushButton; + m_Button->setText("..."); + m_Button->setToolTip("Select output filename..."); + m_Button->setMaximumWidth(m_Button->width()); + connect( m_Button, SIGNAL(clicked()), this, SLOT(SelectFile()) ); + m_HLayout->addWidget(m_Button); + + this->setLayout(m_HLayout); +} + +void QtWidgetOutputVectorDataParameter::SelectFile() +{ + QFileDialog fileDialog; + fileDialog.setConfirmOverwrite(true); + fileDialog.setFileMode(QFileDialog::AnyFile); + fileDialog.setNameFilter("Raster files (*)"); + + if (fileDialog.exec()) + { + //this->SetFileName(fileDialog.selectedFiles().at(0)); + m_Input->setText(fileDialog.selectedFiles().at(0)); + } +} + +void QtWidgetOutputVectorDataParameter::SetFileName(const QString& value) +{ + // save value + m_FileName = value.toStdString(); + + m_OutputVectorDataParam->SetFileName(m_FileName); + + // notify of value change + QString key( QString::fromStdString(m_OutputVectorDataParam->GetKey()) ); + emit ParameterChanged(key); +} + + +} +} diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetOutputVectorDataParameter.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetOutputVectorDataParameter.h new file mode 100644 index 0000000000..9ced01d2cf --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetOutputVectorDataParameter.h @@ -0,0 +1,71 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __otbWrapperQtWidgetOutputVectorDataParameter_h +#define __otbWrapperQtWidgetOutputVectorDataParameter_h + +#include <QtGui> +#include "otbWrapperOutputVectorDataParameter.h" +#include "otbWrapperQtWidgetParameterBase.h" + + +namespace otb +{ +namespace Wrapper +{ + +/** \class + * \brief + */ +class QtWidgetOutputVectorDataParameter : public QtWidgetParameterBase +{ + Q_OBJECT +public: + QtWidgetOutputVectorDataParameter(OutputVectorDataParameter*, QtWidgetModel*); + virtual ~QtWidgetOutputVectorDataParameter(); + + /** Get the PixelType*/ + //itkGetMacro(PixelType, int); + +protected slots: + void SetFileName( const QString& value ); + void SelectFile(); + +private: + QtWidgetOutputVectorDataParameter(const QtWidgetOutputVectorDataParameter&); //purposely not implemented + void operator=(const QtWidgetOutputVectorDataParameter&); //purposely not implemented + + virtual void DoCreateWidget(); + + virtual void DoUpdateGUI(); + + std::string m_FileName; + OutputVectorDataParameter::Pointer m_OutputVectorDataParam; + + QHBoxLayout * m_HLayout; + QLineEdit* m_Input; + QPushButton * m_Button; + QComboBox* m_ComboBox; + int m_PixelType; + +}; + + +} +} + +#endif diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterFactory.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterFactory.cxx index 45b6a38811..f68322052d 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterFactory.cxx +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterFactory.cxx @@ -31,6 +31,7 @@ #include "otbWrapperQtWidgetInputImageParameter.h" #include "otbWrapperQtWidgetInputImageListParameter.h" #include "otbWrapperQtWidgetOutputImageParameter.h" +#include "otbWrapperQtWidgetOutputVectorDataParameter.h" #include "otbWrapperQtWidgetParameterGroup.h" namespace otb @@ -90,6 +91,7 @@ QtWidgetParameterFactory::CreateQtWidget( Parameter* param, QtWidgetModel* model CREATEWIDGET(InputImageParameter, QtWidgetInputImageParameter) CREATEWIDGET(InputImageListParameter, QtWidgetInputImageListParameter) CREATEWIDGET(OutputImageParameter, QtWidgetOutputImageParameter) + CREATEWIDGET(OutputVectorDataParameter, QtWidgetOutputVectorDataParameter) CREATEWIDGET(EmptyParameter, QtWidgetEmptyParameter) CREATEWIDGET(ParameterGroup, QtWidgetParameterGroup) -- GitLab