diff --git a/Code/ApplicationEngine/otbWrapperInputVectorDataParameter.cxx b/Code/ApplicationEngine/otbWrapperInputVectorDataParameter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..0aa0f7a53afa537c7bd7e6cb48f4ec0c611d41fc --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperInputVectorDataParameter.cxx @@ -0,0 +1,101 @@ +/*========================================================================= + + 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 "otbWrapperInputVectorDataParameter.h" + +namespace otb +{ +namespace Wrapper +{ + +InputVectorDataParameter::InputVectorDataParameter() +{ + this->SetName("Input VectorData"); + this->SetKey("in"); + this->ClearValue(); +} + +InputVectorDataParameter::~InputVectorDataParameter() +{ +} + +bool +InputVectorDataParameter::SetFromFileName(const std::string& filename) +{ + // First clear previous file choosen + this->ClearValue(); + + // TODO : when the logger will be available, redirect the exception + // in the logger (like what is done in MsgReporter) + if (!filename.empty() + && itksys::SystemTools::FileExists(filename.c_str())) + { + VectorDataFileReaderType::Pointer reader = VectorDataFileReaderType::New(); + reader->SetFileName(filename); + try + { + reader->UpdateOutputInformation(); + } + catch(itk::ExceptionObject & err) + { + return true; + } + + // the specified filename is valid => store the value + m_FileName = filename; + SetActive(true); + } + return false; +} + + +VectorDataType* +InputVectorDataParameter::GetVectorData() const +{ + return m_VectorData; +} + +void +InputVectorDataParameter::SetVectorData(VectorDataType* vectorData) +{ + m_VectorData = vectorData; +} + + +bool +InputVectorDataParameter::HasValue() const +{ + if( m_FileName.empty() && m_VectorData.IsNull() ) + return false; + else + return true; +} + +void +InputVectorDataParameter::ClearValue() +{ + m_VectorData = NULL; + m_Reader = NULL; + m_FileName = ""; +} + + +} +} + + diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetInputImageListParameter.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetInputImageListParameter.cxx index 67fadae127da032a10ad793f49ee6b6b229bfc1e..246f72a7504decafc12ea352b9f96893b781b9d4 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetInputImageListParameter.cxx +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetInputImageListParameter.cxx @@ -345,16 +345,26 @@ void QtWidgetInputImageListParameter::RecreateImageList() { // save value m_InputImageListParam->ClearValue(); + const unsigned int initSize = m_FileSelectionList.size(); for(unsigned int j=0; j<m_FileSelectionList.size(); j++ ) { - m_InputImageListParam->AddFromFileName(m_FileSelectionList[j]->GetFilename()); - connect( m_FileSelectionList[j]->GetInput(), SIGNAL(textChanged(const QString&)), this, SLOT(UpdateImageList()) ); + if(m_InputImageListParam->AddFromFileName(m_FileSelectionList[j]->GetFilename()) == true ) + connect( m_FileSelectionList[j]->GetInput(), SIGNAL(textChanged(const QString&)), this, SLOT(UpdateImageList()) ); + else + { + m_FileSelectionList[j]->SetChecked(true); + } } - - emit Change(); - // notify of value change - QString key( QString::fromStdString(m_InputImageListParam->GetKey()) ); - emit ParameterChanged(key); + + if( initSize == m_FileSelectionList.size() ) + { + emit Change(); + // notify of value change + QString key( QString::fromStdString(m_InputImageListParam->GetKey()) ); + emit ParameterChanged(key); + } + else + this->SupressFile(); } diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetInputImageParameter.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetInputImageParameter.cxx index 849688f9bc53982ee2febe93ece2f98f3fc49991..c724beea65b717e77ec84f233f57b56285e2db12 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetInputImageParameter.cxx +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetInputImageParameter.cxx @@ -78,11 +78,12 @@ void QtWidgetInputImageParameter::SelectFile() void QtWidgetInputImageParameter::SetFileName(const QString& value) { // save value - m_InputImageParam->SetFromFileName(value.toStdString()); - - // notify of value change - QString key( QString::fromStdString(m_InputImageParam->GetKey()) ); - emit ParameterChanged(key); + if(m_InputImageParam->SetFromFileName(value.toStdString()) == false ) + { + // notify of value change + QString key( QString::fromStdString(m_InputImageParam->GetKey()) ); + emit ParameterChanged(key); + } } } diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetInputVectorDataListParameter.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetInputVectorDataListParameter.cxx index 768baa36efd93bd9ec14bebc1100f7134b7bee6a..c7bf9c314cec9ec5f5c151aaf155013247f987f1 100644 --- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetInputVectorDataListParameter.cxx +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetInputVectorDataListParameter.cxx @@ -137,13 +137,38 @@ void QtWidgetInputVectorDataListParameter::DoCreateWidget() void QtWidgetInputVectorDataListParameter::UpdateVectorDataList() { +std::cout<<"UpdateVectorDataList"<<std::endl; // save value + bool update = false; + + std::cout<<m_FileSelectionList.size()<<std::endl; + std::cout<<m_InputVectorDataListParam<<std::endl; + std::cout<<"m_InputVectorDataListParam->GetFileNameList().size()"<<std::endl; + std::cout<<m_InputVectorDataListParam->GetFileNameList().size()<<std::endl; + std::cout<<m_InputVectorDataListParam->GetVectorDataList()->Size()<<std::endl; + + for(unsigned int j=0; j<m_InputVectorDataListParam->GetVectorDataList()->Size(); j++ ) { - m_InputVectorDataListParam->SetNthFileName(j, m_FileSelectionList[j]->GetFilename()); + std::cout<<"UpdateVectorDataList,loop "<<j<<std::endl; + if( m_InputVectorDataListParam->SetNthFileName(j, m_FileSelectionList[j]->GetFilename()) == true ) + { + std::cout<<"UpdateVectorDataList, can't create vd"<<std::endl; + m_FileSelectionList[j]->SetChecked(true); + m_InputVectorDataListParam->AddNullElement(); + update = true; + } } - emit Change(); + std::cout<<m_FileSelectionList.size()<<std::endl; + std::cout<<m_InputVectorDataListParam->GetFileNameList().size()<<std::endl; + std::cout<<m_InputVectorDataListParam->GetVectorDataList()->Size()<<std::endl; + + if(update) + this->SupressFile(); + else + emit Change(); + } @@ -291,16 +316,22 @@ QtWidgetInputVectorDataListParameter::AddFile() void QtWidgetInputVectorDataListParameter::SupressFile() { + std::cout<<"QtWidgetInputVectorDataListParameter::SupressFile "<<m_FileSelectionList.size()<<std::endl; m_FileLayout = new QVBoxLayout(); - m_FileLayout->setSpacing(0); + m_FileLayout->setSpacing(0 ); std::vector<QtFileSelectionWidget *> tmpList; for (unsigned int i = 0; i < m_FileSelectionList.size(); i++) { + std::cout<<"QtWidgetInputVectorDataListParameter::SupressFile "<<i<<std::endl; if (!m_FileSelectionList[i]->IsChecked()) { m_FileLayout->addWidget(m_FileSelectionList[i]); tmpList.push_back(m_FileSelectionList[i]); } + else + { + //m_InputVectorDataListParam->GetVectorDataList()->Erase(i-count); + } } m_FileSelectionList = tmpList; @@ -339,19 +370,33 @@ QtWidgetInputVectorDataListParameter::EraseFile() void QtWidgetInputVectorDataListParameter::RecreateVectorDataList() { + std::cout<<"QtWidgetInputVectorDataListParameter::RecreateVectorDataList"<<std::endl; // save value m_InputVectorDataListParam->ClearValue(); - for (unsigned int j = 0; j < m_FileSelectionList.size(); j++) + + if( m_FileSelectionList.size() == 0) { - m_InputVectorDataListParam->AddFromFileName(m_FileSelectionList[j]->GetFilename()); - connect(m_FileSelectionList[j]->GetInput(), SIGNAL(textChanged(const QString&)), this, SLOT(UpdateVectorDataList())); +std::cout<<"QtWidgetInputVectorDataListParameter::RecreateVectorDataList:: Addfile"<<std::endl; + this->AddFile(); } + else + { + std::cout<<"QtWidgetInputVectorDataListParameter::RecreateVectorDataList else "<<m_FileSelectionList.size()<<std::endl; + for (unsigned int j = 0; j < m_FileSelectionList.size(); j++) + { + std::cout<<j<<std::endl; + m_InputVectorDataListParam->AddFromFileName(m_FileSelectionList[j]->GetFilename()); + connect(m_FileSelectionList[j]->GetInput(), SIGNAL(textChanged(const QString&)), this, SLOT(UpdateVectorDataList())); + } + + emit Change(); + // notify of value change + QString key(QString::fromStdString(m_InputVectorDataListParam->GetKey())); + emit ParameterChanged(key); + + } + std::cout<<"QtWidgetInputVectorDataListParameter::RecreateVectorDataList done"<<std::endl; - emit - Change(); - // notify of value change - QString key(QString::fromStdString(m_InputVectorDataListParam->GetKey())); - emit ParameterChanged(key); }