diff --git a/Modules/Adapters/QtAdapters/src/otbQtAdapters.cxx b/Modules/Adapters/QtAdapters/src/otbQtAdapters.cxx index e34a2f1ee8cc3ee30647bc37b6079407b15b140b..89f457dc9ca5bd5fae76a1798f7e4a8b994d368c 100644 --- a/Modules/Adapters/QtAdapters/src/otbQtAdapters.cxx +++ b/Modules/Adapters/QtAdapters/src/otbQtAdapters.cxx @@ -211,11 +211,13 @@ SetWorkingDir( const QString & filepath ) QFileInfo finfo( filepath ); #if 0 - return QDir::setCurrent( - finfo.isDir() - ? filepath - : finfo.path() - ); + return + QDir::setCurrent( + finfo.isDir() + ? filepath + : finfo.path() + ); + #else // TODO : add mutex if needed QString dir = finfo.isDir() ? filepath : finfo.path(); @@ -223,6 +225,7 @@ SetWorkingDir( const QString & filepath ) return false; RecentDirectory = finfo.isDir() ? filepath : finfo.path(); return true; + #endif } diff --git a/Modules/Applications/AppTest/app/otbTestApplication.cxx b/Modules/Applications/AppTest/app/otbTestApplication.cxx index 662529c4ca81f854c1b9482fef5dcc133fdb7f8e..a2e9ee940da3b473f8e69fbd152eda675c66256d 100644 --- a/Modules/Applications/AppTest/app/otbTestApplication.cxx +++ b/Modules/Applications/AppTest/app/otbTestApplication.cxx @@ -20,6 +20,7 @@ #include "otbWrapperApplication.h" #include "otbWrapperApplicationFactory.h" +#include "otbWrapperInputFilenameListParameter.h" namespace otb { @@ -46,7 +47,6 @@ private: SetName("TestApplication"); SetDescription("This application helps developers to test parameters types"); - SetDocName("Test"); SetDocLongDescription("The purpose of this application is to test parameters types."); SetDocLimitations("None"); @@ -76,7 +76,6 @@ private: AddParameter(ParameterType_Float, "choice.choice3.floatchoice3", "Float of choice3"); SetDefaultParameterFloat("choice.choice3.floatchoice3", 5.0); - AddParameter(ParameterType_Group, "ingroup", "Input Group"); MandatoryOff("ingroup"); AddParameter(ParameterType_Float, "ingroup.integer", "Integer of Group"); @@ -89,6 +88,15 @@ private: AddParameter(ParameterType_InputImageList, "il", "Input image list"); MandatoryOff("il"); + AddParameter( ParameterType_InputFilenameList, "fl", "Input filename list" ); + MandatoryOff( "fl" ); + + AddParameter( ParameterType_InputVectorDataList, "vdl", "Input vector-data list" ); + MandatoryOff( "vdl" ); + + AddParameter( ParameterType_StringList, "sl", "Input string list" ); + MandatoryOff( "sl" ); + AddParameter(ParameterType_ListView, "cl", "Output Image channels"); AddChoice("cl.choice1", "Choice1"); AddChoice("cl.choice2", "Choice2"); @@ -105,19 +113,62 @@ private: } void DoUpdateParameters() ITK_OVERRIDE + {} + + void DoExecute() ITK_OVERRIDE { - //std::cout << "TestApplication::DoUpdateParameters" << std::endl; + if( HasValue("il") && IsParameterEnabled("il") ) + { + FloatVectorImageListType * imgList = GetParameterImageList( "il" ); + SetParameterOutputImage( + "outgroup.outputimage", + imgList->GetNthElement( 0 ) + ); + } + else if (HasValue("ingroup.images.inputimage") && IsParameterEnabled("ingroup") ) + { + SetParameterOutputImage("outgroup.outputimage", + GetParameterImage("ingroup.images.inputimage")); + } + else + { + otbAppLogFATAL("Waiting at least one input image"); + } + + SetParameterComplexOutputImage( + "cout", + GetParameterComplexImage( "cin" ) + ); + + PrintStrings( "fl" ); } - void DoExecute() ITK_OVERRIDE +private: + void PrintStrings( const std::string & key ) const { - FloatVectorImageListType* imgList = GetParameterImageList("il"); - SetParameterOutputImage("outgroup.outputimage", imgList->GetNthElement(0)); - SetParameterComplexOutputImage("cout", GetParameterComplexImage("cin")); - //std::cout << "TestApplication::DoExecute" << std::endl; + if( !IsParameterEnabled(key) ) + return; + + const Parameter * p = GetParameterByKey( key ); + assert( p!=nullptr ); + const StringListInterface * sli = + dynamic_cast< const StringListInterface * >(p); + assert( sli!=nullptr ); + + StringListInterface::StringVector strings; + + sli->GetStrings( strings ); + + std::cout << "{" << std::endl; + { + for( auto s : strings ) + std::cout << "'" << s << "'" << std::endl; + } + std::cout << "}"<< std::endl; } }; -} -} -OTB_APPLICATION_EXPORT(otb::Wrapper::TestApplication) +} // end of namespace Wrapper +} // end of namespace otb + +OTB_APPLICATION_EXPORT( otb::Wrapper::TestApplication ) diff --git a/Modules/Core/ObjectList/include/otbObjectList.h b/Modules/Core/ObjectList/include/otbObjectList.h index 9d6babaef3980cf72eef00df15380c0e1b5afccc..b9db494becf30b3c3bf956c318f28c0d9a1cbc9a 100644 --- a/Modules/Core/ObjectList/include/otbObjectList.h +++ b/Modules/Core/ObjectList/include/otbObjectList.h @@ -200,7 +200,6 @@ public: Iterator lIter(m_Iter + i); return lIter; } - /** * Remove */ @@ -209,6 +208,20 @@ public: Iterator lIter(m_Iter - i); return lIter; } + /** + */ + Iterator + operator += ( int i ) + { + return m_Iter + i; + } + /** + */ + Iterator + operator -= ( int i ) + { + return m_Iter - i; + } /** * Difference comparison operator. */ diff --git a/Modules/Visualization/MonteverdiCore/src/mvdVectorImageModel.cxx b/Modules/Visualization/MonteverdiCore/src/mvdVectorImageModel.cxx index 378763d26e561bbc8bae2c0c51ac923dd80a3e58..c5ff7f064c2a12b6316b891faade0c831878c225 100644 --- a/Modules/Visualization/MonteverdiCore/src/mvdVectorImageModel.cxx +++ b/Modules/Visualization/MonteverdiCore/src/mvdVectorImageModel.cxx @@ -112,7 +112,7 @@ VectorImageModel m_ImageFileReader->SetFileName( QFile::encodeName( GetFilename() ) ); m_ImageFileReader->GetOutput()->UpdateOutputInformation(); - + // Retrieve the list of Lod from file m_LodCount = m_ImageFileReader->GetOverviewsCount(); @@ -130,7 +130,7 @@ VectorImageModel // << m_ImageFileReader->GetOutput()->GetOrigin()[ 1 ] // << "\nspacing:" << m_NativeSpacing[ 0 ] << m_NativeSpacing[ 1 ]; - + // Setup GenericRSTransform m_ToWgs84 = otb::GenericRSTransform<>::New(); m_ToWgs84->SetInputDictionary(m_ImageFileReader->GetOutput()->GetMetaDataDictionary()); @@ -140,11 +140,11 @@ VectorImageModel //Compute estimated spacing here //m_EstimatedGroundSpacing m_EstimatedGroundSpacing = m_NativeSpacing; - + typedef otb::GroundSpacingImageFunction<VectorImageType> GroundSpacingImageType; GroundSpacingImageType::Pointer GroundSpacing = GroundSpacingImageType::New(); GroundSpacing->SetInputImage(m_ImageFileReader->GetOutput()); - + if (m_ToWgs84->IsUpToDate()) { if (m_ToWgs84->GetTransformAccuracy() != otb::Projection::UNKNOWN) @@ -301,7 +301,7 @@ VectorImageModel static_cast< VectorImageSettings * const >( buildContext->m_Settings ); -// Fetch the no data flags if any + // Fetch the no data flags if any otb::ImageMetadataInterfaceBase::ConstPointer metaData( GetMetaDataInterface() ); @@ -316,7 +316,7 @@ VectorImageModel GetProperties()->SetNoDataEnabled(true); GetProperties()->SetNoData(values[0]); } - + // // Step #1: Perform pre-process of AbstractModel::BuildModel() // pattern. @@ -348,7 +348,7 @@ VectorImageModel // Remember image properties. if( buildContext->m_Properties!=NULL ) SetProperties( *buildContext->m_Properties ); - + // Apply settings to child QuicklookModel. ApplySettings(); } @@ -479,7 +479,7 @@ VectorImageModel::ComputeBestLod( double zoomFactor ) const } /*****************************************************************************/ -unsigned int +unsigned int VectorImageModel::Closest( double invZoomfactor, unsigned int lodCount ) { @@ -554,7 +554,7 @@ VectorImageModel // Update m_ImageFileReader m_ImageFileReader->SetFileName( QFile::encodeName( lodFilename ).constData() ); m_ImageFileReader->GetOutput()->UpdateOutputInformation(); - + // (Always) Update m_Image reference. m_Image = m_ImageFileReader->GetOutput(); } @@ -594,17 +594,17 @@ VectorImageModel IndexType centerIndex; centerIndex[0] = GetNativeLargestRegion().GetIndex()[0] + GetNativeLargestRegion().GetSize(0)/2; centerIndex[1] = GetNativeLargestRegion().GetIndex()[1] + GetNativeLargestRegion().GetSize(1)/2; - + // - // Compute the physical coordinates of the center pixel + // Compute the physical coordinates of the center pixel PointType centerPoint; centerPoint[0] = (centerIndex[0] * GetNativeSpacing()[0] ) + GetOrigin()[0]; centerPoint[1] = (centerIndex[1] * GetNativeSpacing()[1] ) + GetOrigin()[1]; - + // lat / long PointType wgs84; wgs84 = GetGenericRSTransform()->TransformPoint(centerPoint); - + // get placename otb::CoordinateToName::Pointer coordinateToName = otb::CoordinateToName::New(); coordinateToName->SetLonLat(wgs84); @@ -612,13 +612,13 @@ VectorImageModel // get the placename - Country (if any) std::ostringstream oss; - + std::string placeName = coordinateToName->GetPlaceName(); std::string countryName = coordinateToName->GetCountryName(); - + if (placeName != "") oss << placeName; - + if (countryName != "") oss << " - "<< countryName; @@ -792,7 +792,7 @@ VectorImageModel // show the current pixel description only if the mouse cursor is // under the image if( isInsideNativeLargestRegion || 1 ) - { + { // // get the physical coordinates if (!ToImage()->GetProjectionRef().empty()) @@ -815,11 +815,11 @@ VectorImageModel IndexType currentLodIndex; currentLodIndex[0] = (point[ 0 ] - ToImage()->GetOrigin()[0]) / ToImage()->GetSpacing()[0]; currentLodIndex[1] = (point[ 1 ] - ToImage()->GetOrigin()[1]) / ToImage()->GetSpacing()[1]; - + // // get the LatLong - - if (!ToImage()->GetProjectionRef().empty()) + + if (!ToImage()->GetProjectionRef().empty()) { geoVector.push_back(ToStdString(tr("Geographic(exact)"))); } @@ -835,23 +835,23 @@ VectorImageModel if( ToImage()->GetLargestPossibleRegion().IsInside(currentLodIndex) || 1 ) { // TODO : Is there a better method to detect no geoinfo available ? - if (!ToImage()->GetProjectionRef().empty() || ToImage()->GetImageKeywordlist().GetSize() != 0) + if (!ToImage()->GetProjectionRef().empty() || ToImage()->GetImageKeywordlist().GetSize() != 0) { assert( !m_ToWgs84.IsNull() ); PointType wgs84; wgs84 = m_ToWgs84->TransformPoint( point ); - + ossGeographicLong.precision(6); ossGeographicLat.precision(6); - + ossGeographicLong << std::fixed << wgs84[0]; ossGeographicLat << std::fixed << wgs84[1]; geoVector.push_back(ossGeographicLong.str()); geoVector.push_back(ossGeographicLat.str()); - + double elev = otb::DEMHandler::Instance()->GetHeightAboveEllipsoid(wgs84[0],wgs84[1]); if(elev > -32768) @@ -873,33 +873,33 @@ VectorImageModel /* else { - //handle here the case of QL information display. It + //handle here the case of QL information display. It //displays geographic info when the user is scrolling over the QL // // compute the current ql index - if (!ToImage()->GetProjectionRef().empty() || ToImage()->GetImageKeywordlist().GetSize() != 0) + if (!ToImage()->GetProjectionRef().empty() || ToImage()->GetImageKeywordlist().GetSize() != 0) { - currentLodIndex[0] = (Xpc - GetQuicklookModel()->ToImage()->GetOrigin()[0]) + currentLodIndex[0] = (Xpc - GetQuicklookModel()->ToImage()->GetOrigin()[0]) / GetQuicklookModel()->ToImage()->GetSpacing()[0]; - currentLodIndex[1] = (Ypc - GetQuicklookModel()->ToImage()->GetOrigin()[1]) + currentLodIndex[1] = (Ypc - GetQuicklookModel()->ToImage()->GetOrigin()[1]) / GetQuicklookModel()->ToImage()->GetSpacing()[1]; PointType wgs84; PointType currentLodPoint; GetQuicklookModel()->ToImage()->TransformIndexToPhysicalPoint(currentLodIndex, currentLodPoint); wgs84 = GetGenericRSTransform()->TransformPoint(currentLodPoint); - + ossGeographicLong.precision(6); ossGeographicLat.precision(6); - + ossGeographicLong << std::fixed << wgs84[0]; ossGeographicLat << std::fixed << wgs84[1]; //Update geovector with location over QL index geoVector.push_back(ossGeographicLong.str()); geoVector.push_back(ossGeographicLat.str()); - + double elev = otb::DEMHandler::Instance()->GetHeightAboveEllipsoid(wgs84[0],wgs84[1]); if(elev > -32768) @@ -950,16 +950,16 @@ VectorImageModel { // // compute the current ql index - currentLodIndex[0] = (Xpc - GetQuicklookModel()->ToImage()->GetOrigin()[0]) + currentLodIndex[0] = (Xpc - GetQuicklookModel()->ToImage()->GetOrigin()[0]) / GetQuicklookModel()->ToImage()->GetSpacing()[0]; - currentLodIndex[1] = (Ypc - GetQuicklookModel()->ToImage()->GetOrigin()[1]) + currentLodIndex[1] = (Ypc - GetQuicklookModel()->ToImage()->GetOrigin()[1]) / GetQuicklookModel()->ToImage()->GetSpacing()[1]; - + // // Get the radiometry form the Ql if ( GetQuicklookModel()->ToImage()->GetBufferedRegion().IsInside(currentLodIndex) ) { - currentPixel = + currentPixel = GetQuicklookModel()->ToImage()->GetPixel(currentLodIndex); ossRadio <<"Ql [ "; @@ -973,7 +973,7 @@ VectorImageModel */ } - // update band name for the current position + // update band name for the current position bandNames = GetBandNames( true ); // qDebug() << bandNames; diff --git a/Modules/Visualization/MonteverdiGui/include/mvdLayerStackItemModel.h b/Modules/Visualization/MonteverdiGui/include/mvdLayerStackItemModel.h index 3a3fc21ddc09bfdb277e18b2aab6b2a1e2018ab4..97f096ad9f43ff41d8f2e26a77a0980dce7af9b8 100644 --- a/Modules/Visualization/MonteverdiGui/include/mvdLayerStackItemModel.h +++ b/Modules/Visualization/MonteverdiGui/include/mvdLayerStackItemModel.h @@ -157,15 +157,13 @@ public: /** * \see http://qt-project.org/doc/qt-4.8/qabstractitemmodel.html#data */ - - QVariant + QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const ITK_OVERRIDE; /** * \see http://qt-project.org/doc/qt-4.8/qabstractitemmodel.html#dropMimeData */ - - bool + bool dropMimeData( const QMimeData * data, Qt::DropAction action, int row, @@ -188,11 +186,11 @@ public: QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const ITK_OVERRIDE; + /** * \see http://qt-project.org/doc/qt-4.8/qabstractitemmodel.html#index */ - - QModelIndex + QModelIndex index( int row, int column, const QModelIndex & p = QModelIndex() ) const ITK_OVERRIDE; @@ -200,8 +198,7 @@ public: /** * \see http://qt-project.org/doc/qt-4.8/qabstractitemmodel.html#insertRows */ - - bool + bool insertRows( int row, int count, const QModelIndex & p = QModelIndex() ) ITK_OVERRIDE; @@ -224,8 +221,7 @@ public: /** * \see http://qt-project.org/doc/qt-4.8/qabstractitemmodel.html#removeRows */ - - bool + bool removeRows( int row, int count, const QModelIndex & p = QModelIndex() ) ITK_OVERRIDE; @@ -238,8 +234,7 @@ public: /** * \see http://qt-project.org/doc/qt-4.8/qabstractitemmodel.html#setData */ - - bool + bool setData( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ) ITK_OVERRIDE; diff --git a/Modules/Visualization/MonteverdiGui/include/mvdQtWidgetParameterInitializers.h b/Modules/Visualization/MonteverdiGui/include/mvdQtWidgetParameterInitializers.h index 61d425e75d7597f248933b7c80b066f1bda3aaf8..8ad2bfc76d0f4b08239b8c0524ec1c59cb6607a3 100644 --- a/Modules/Visualization/MonteverdiGui/include/mvdQtWidgetParameterInitializers.h +++ b/Modules/Visualization/MonteverdiGui/include/mvdQtWidgetParameterInitializers.h @@ -62,6 +62,7 @@ #include "otbWrapperQtWidgetComplexInputImageParameter.h" #include "otbWrapperQtWidgetComplexOutputImageParameter.h" #include "otbWrapperQtWidgetParameterFactory.h" +#include "otbWrapperQtWidgetListEditWidget.h" #endif //tag=QT4-boost-compatibility #include "OTBMonteverdiGUIExport.h" @@ -135,7 +136,6 @@ class FileSelectionInitializer : public std::unary_function< > { public: - inline FileSelectionInitializer(); inline result_type operator () ( argument_type widget ) const; }; @@ -152,7 +152,6 @@ class InputImageInitializer : public std::unary_function< > { public: - inline InputImageInitializer(); inline result_type operator () ( argument_type widget ) const; }; @@ -169,12 +168,7 @@ class InputImageListInitializer : public std::unary_function< > { public: - inline InputImageListInitializer( QWidget * view ); - inline result_type operator () ( argument_type widget ) const; - -private: - QWidget * m_View; }; /** @@ -190,7 +184,6 @@ class ComplexInputImageInitializer : public std::unary_function< > { public: - inline ComplexInputImageInitializer(); inline result_type operator () ( argument_type widget ) const; }; @@ -221,12 +214,7 @@ class InputVectorDataListInitializer : public std::unary_function< void > { public: - inline InputVectorDataListInitializer( QWidget * view ); - inline result_type operator () ( argument_type widget ) const; - -private: - QWidget * m_View; }; /** @@ -256,12 +244,7 @@ class InputFilenameListInitializer : public std::unary_function< void > { public: - inline InputFilenameListInitializer( QWidget * view ); - inline result_type operator () ( argument_type widget ) const; - -private: - QWidget * m_View; }; /** @@ -334,8 +317,6 @@ class OutputVectorDataInitializer : public std::unary_function< { public: inline result_type operator () ( argument_type widget ) const; - -private: }; /** @@ -352,8 +333,6 @@ class OutputFilenameInitializer : public std::unary_function< { public: inline result_type operator () ( argument_type widget ) const; - -private: }; /** @@ -370,8 +349,6 @@ class OutputProcessXMLInitializer : public std::unary_function< { public: inline result_type operator () ( argument_type widget ) const; - -private: }; /** @@ -387,6 +364,21 @@ public: inline result_type operator () ( argument_type widget ) const; }; +/** + * \class ParameterListInitializer + * + * \ingroup OTBMonteverdiGUI + * + * \brief WIP. + */ +class ParameterListInitializer : public std::unary_function< + otb::Wrapper::QtWidgetParameterList *, + void > +{ +public: + inline result_type operator () ( argument_type widget ) const; +}; + } // end namespace 'Wrapper'. } // end namespace 'mvd'. @@ -420,13 +412,6 @@ namespace mvd namespace Wrapper { -/*****************************************************************************/ -inline -FileSelectionInitializer -::FileSelectionInitializer() -{ -} - /*****************************************************************************/ inline FileSelectionInitializer::result_type @@ -438,13 +423,6 @@ FileSelectionInitializer SetupForFilenameDrop( widget, "You can drop filename here." ); } -/*****************************************************************************/ -inline -InputImageInitializer -::InputImageInitializer() -{ -} - /*****************************************************************************/ inline InputImageInitializer::result_type @@ -456,35 +434,15 @@ InputImageInitializer SetupForFilenameDrop( widget, "You can drop filename here." ); } -/*****************************************************************************/ -inline -InputImageListInitializer -::InputImageListInitializer( QWidget * view ) : - m_View( view ) -{ -} - /*****************************************************************************/ inline InputImageListInitializer::result_type InputImageListInitializer -::operator () ( argument_type widget ) const +::operator () ( argument_type /* widget */ ) const { - assert( widget!=NULL ); - - QObject::connect( - widget, SIGNAL( FileSelectionWidgetAdded( QWidget * ) ), - m_View, SLOT( OnFileSelectionWidgetAdded0( QWidget * ) ) - ); - - SetupWidget( widget, FileSelectionInitializer() ); -} + // assert( widget!=NULL ); -/*****************************************************************************/ -inline -ComplexInputImageInitializer -::ComplexInputImageInitializer() -{ + // Drop support is done by ParameterListInitializer } /*****************************************************************************/ @@ -509,28 +467,15 @@ InputFilenameInitializer SetupForFilenameDrop( widget, "You can drop filename here." ); } -/*****************************************************************************/ -inline -InputFilenameListInitializer -::InputFilenameListInitializer( QWidget * view ) : - m_View( view ) -{ -} - /*****************************************************************************/ inline InputFilenameListInitializer::result_type InputFilenameListInitializer -::operator () ( argument_type widget ) const +::operator () ( argument_type /* widget */) const { - assert( widget!=NULL ); + // assert( widget!=NULL ); - QObject::connect( - widget, SIGNAL( FileSelectionWidgetAdded( QWidget * ) ), - m_View, SLOT( OnFileSelectionWidgetAdded0( QWidget * ) ) - ); - - SetupWidget( widget, FileSelectionInitializer() ); + // Drop support is done by ParameterListInitializer } /*****************************************************************************/ @@ -544,28 +489,15 @@ InputVectorDataInitializer SetupForFilenameDrop( widget, "You can drop filename here." ); } -/*****************************************************************************/ -inline -InputVectorDataListInitializer -::InputVectorDataListInitializer( QWidget * view ) : - m_View( view ) -{ -} - /*****************************************************************************/ inline InputVectorDataListInitializer::result_type InputVectorDataListInitializer -::operator () ( argument_type widget ) const +::operator () ( argument_type /* widget */) const { - assert( widget!=NULL ); + // assert( widget!=NULL ); - QObject::connect( - widget, SIGNAL( FileSelectionWidgetAdded( QWidget * ) ), - m_View, SLOT( OnFileSelectionWidgetAdded0( QWidget * ) ) - ); - - SetupWidget( widget, FileSelectionInitializer() ); + // Drop support is done by ParameterListInitializer } /*****************************************************************************/ @@ -719,6 +651,34 @@ OutputProcessXMLInitializer // } } +/*****************************************************************************/ +inline +ParameterListInitializer::result_type +ParameterListInitializer +::operator () ( argument_type widget ) const +{ + assert( widget!=nullptr ); + + QWidget *listWidget = widget->layout()->itemAt(0)->widget(); + + assert( listWidget ); + + otb::Wrapper::ListEditWidget *castListEdit = + dynamic_cast<otb::Wrapper::ListEditWidget *>(listWidget); + + assert(castListEdit); + + QObject* eventFilter = new FilenameDragAndDropEventFilter( castListEdit ); + castListEdit->installEventFilter(eventFilter); + QObject::connect( + eventFilter, + SIGNAL( FilenameDropped( const QString& ) ), + // to: + castListEdit, + SLOT( OnFilenameDropped( const QString& ) ) + ); +} + /*****************************************************************************/ template< typename W > void diff --git a/Modules/Visualization/MonteverdiGui/src/mvdQtWidgetView.cxx b/Modules/Visualization/MonteverdiGui/src/mvdQtWidgetView.cxx index ff6d14ecc26aa84d14d8f6418160b2d80adb9595..b11becb03201e8a5714c86285a706d1a364fdd0f 100644 --- a/Modules/Visualization/MonteverdiGui/src/mvdQtWidgetView.cxx +++ b/Modules/Visualization/MonteverdiGui/src/mvdQtWidgetView.cxx @@ -345,13 +345,14 @@ QtWidgetView assert( widget!=NULL ); SetupWidget( widget, InputFilenameInitializer() ); - SetupWidget( widget, InputFilenameListInitializer( this ) ); + //SetupWidget( widget, InputFilenameListInitializer() ); SetupWidget( widget, InputImageInitializer() ); - SetupWidget( widget, InputImageListInitializer( this ) ); + //SetupWidget( widget, InputImageListInitializer() ); SetupWidget( widget, ComplexInputImageInitializer() ); SetupWidget( widget, InputProcessXMLInitializer() ); SetupWidget( widget, InputVectorDataInitializer() ); - SetupWidget( widget, InputVectorDataListInitializer( this ) ); + //SetupWidget( widget, InputVectorDataListInitializer() ); + SetupWidget( widget, ParameterListInitializer() ); #if defined( OTB_DEBUG ) SetupWidget( widget, ToolTipInitializer() ); #endif diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperAbstractParameterList.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperAbstractParameterList.h new file mode 100644 index 0000000000000000000000000000000000000000..94a0c2896e008acf2bb62c807c06f4d959bd4f6f --- /dev/null +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperAbstractParameterList.h @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2005-2017 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 otbWrapperAbstractParameterList_h +#define otbWrapperAbstractParameterList_h + + +#include "otbWrapperParameter.h" +#include "otbWrapperStringListInterface.h" + + +namespace otb +{ + +namespace Wrapper +{ + + +/** \class AbstractParameterList + * \brief This class is a base class for list-type parameters + * + * \ingroup OTBApplicationEngine + */ +class OTBApplicationEngine_EXPORT AbstractParameterList : + public Parameter, + public StringListInterface +{ +// +// Public types. +public: + /** Standard class typedef */ + typedef AbstractParameterList Self; + typedef Parameter Superclass; + +// +// Public methods. +public: + + /** RTTI support */ + itkTypeMacro( AbstractParameterList, Parameter ); + +// +// Protected methods. +protected: + /** Constructor */ + AbstractParameterList(); + + /** Destructor */ + ~AbstractParameterList() override; + +// +// Private methods. +private: + AbstractParameterList( const Parameter & ) = delete; // purposely not implemented + void operator = ( const Parameter & ) = delete; // purposely not implemented + +// +// Protected methods. +protected: + +// +// Private attributes. +private: + +}; // End class InputImage Parameter + +} // End namespace Wrapper + +} // End namespace otb + +#endif diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h index cbc0f7f2736f9ffecb4933b6616032067acdd8bb..cec459dc965019f1d42396b995b89837138213a8 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h @@ -375,7 +375,7 @@ public: /** * Enable single selection mode for list view if status in true * (default is false). - * + * * Can be called for types: * \li ParameterType_ListView */ @@ -455,10 +455,18 @@ public: * \li ParameterType_InputImageList * \li ParameterType_InputFilenameList */ - std::vector<std::string> GetParameterStringList(std::string parameter); + // TODO: Should be rewritten: + // + // std::size_t + // GetParameterStringList( const std::vector< String > & v, + // const std::string & parameter ) const; + // + // to avoid useless memory allocations. + std::vector< std::string > + GetParameterStringList( const std::string & parameter ); - /** + /** * Set the input image parameter as an ImageBase * instead * of filename. Useful to connect pipelines between different * application instances. @@ -480,7 +488,7 @@ public: */ OutputImageParameter::ImageBaseType * GetParameterOutputImage(std::string parameter); - /** + /** * Set the input complex image parameter as an ImageBase * instead * of filename. Useful to connect pipelines between different * application instances. @@ -510,7 +518,7 @@ public: * \in img The ImageBase * of the image to add * \throw itk::Exception if parameter is not found or not an * InputImageList parameter - */ + */ void AddImageToParameterInputImageList(std::string parameter, InputImageListParameter::ImageBaseType * img); /** @@ -522,7 +530,7 @@ public: * \in img The ImageBase * of the image to add * \throw itk::Exception if parameter is not found or not an * InputImageList parameter or if id is out of bounds - */ + */ void SetNthParameterInputImageList(std::string parameter, const unsigned int &id, InputImageListParameter::ImageBaseType * img); /** @@ -530,12 +538,12 @@ public: * * Can be called for parameter types: * \li ParameterType_InputImageList - * + * * \in parameter The parameter key * \in str The string * \throw itk::Exception if parameter is not found or not an * InputImageList parameter - */ + */ void AddParameterStringList(std::string parameter, const std::string & str); /** @@ -543,15 +551,15 @@ public: * * Can be called for parameter types: * \li ParameterType_InputImageList - * + * * \in parameter The parameter key * \in id Position at which to set the ImageBase pointer * \in str The string * \throw itk::Exception if parameter is not found or not an * InputImageList parameter or if id is out of bounds - */ + */ void SetNthParameterStringList(std::string parameter, const unsigned int &id, const std::string& str); - + /** * Clear all images from an InputImageList parameter. @@ -559,7 +567,7 @@ public: * \in parameter The parameter key * \throw itk::Exception if parameter is not found or not an * InputImageList parameter - */ + */ void ClearParameterInputImageList(std::string parameter); /** @@ -568,10 +576,10 @@ public: * \return The number of images * \throw itk::Exception if parameter is not found or not an * InputImageList parameter - */ + */ unsigned int GetNumberOfElementsInParameterInputImageList(std::string parameter); - + /* Get an image value * * Can be called for types : diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperComplexInputImageParameter.txx b/Modules/Wrappers/ApplicationEngine/include/otbWrapperComplexInputImageParameter.txx index 47320646f9948127877d1a084e7b951e630bc26b..774dfdbf789b8cdb48252f76e7aad13bba90399c 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperComplexInputImageParameter.txx +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperComplexInputImageParameter.txx @@ -49,21 +49,14 @@ ComplexInputImageParameter::GetImage() { //////////////////////// Filename case: // A new valid filename has been given : a reader is created - m_PreviousFileName = m_FileName; typedef otb::ImageFileReader<TOutputImage> ReaderType; typename ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(m_FileName); - try - { - reader->UpdateOutputInformation(); - } - catch(itk::ExceptionObject &) - { - this->ClearValue(); - } + reader->UpdateOutputInformation(); m_Image = reader->GetOutput(); m_Reader = reader; + m_PreviousFileName = m_FileName; // Pay attention, don't return m_Image because it is a ImageBase... return reader->GetOutput(); diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperComplexOutputImageParameter.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperComplexOutputImageParameter.h index 37dc1434376dd6afe5806bb16367f9b59cecb644..371c4d416691d36e3e07ffe50ea69c1580c20284 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperComplexOutputImageParameter.h +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperComplexOutputImageParameter.h @@ -85,6 +85,10 @@ public: /** Static method to convert pixel type into string */ static std::string ConvertPixelTypeToString(ComplexImagePixelType type); + /** Convert a string into a ComplexImagePixelType (returns false if the + * conversion fails) */ + static bool ConvertStringToPixelType(const std::string &value, ComplexImagePixelType &type); + /** Return true if a filename is set */ bool HasValue() const ITK_OVERRIDE; diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputFilenameListParameter.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputFilenameListParameter.h index b5ef343dcdf7880a7131501423b10d3311f413e5..61e1dd605d0acc9f23fabb270094b3a5c8d9e778 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputFilenameListParameter.h +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputFilenameListParameter.h @@ -21,88 +21,85 @@ #ifndef otbWrapperInputFilenameListParameter_h #define otbWrapperInputFilenameListParameter_h -#include <string> + +#include "otbWrapperParameterList.h" #include "otbWrapperStringParameter.h" -#include "otbObjectList.h" namespace otb { + namespace Wrapper { + /** \class InputFilenameListParameter * \brief This class represents a list of InputFilename parameter * * \ingroup OTBApplicationEngine */ - -class OTBApplicationEngine_EXPORT InputFilenameListParameter : public Parameter +class OTBApplicationEngine_EXPORT InputFilenameListParameter : + public ParameterList< StringParameter > { +// +// Public types. public: /** Standard class typedef */ - typedef InputFilenameListParameter Self; - typedef Parameter Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - - typedef otb::ObjectList<StringParameter> StringParameterListType; - typedef StringParameterListType* StringParameterListPointerType; + typedef InputFilenameListParameter Self; + typedef ParameterList< StringParameter > Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; +// +// Public methods. +public: /** Defining ::New() static method */ - itkNewMacro(Self); + itkNewMacro( Self ); /** RTTI support */ - itkTypeMacro(InputFilenameListParameter, Parameter); - - /** Set file form a list of filenames */ - bool SetListFromFileName(const std::vector<std::string> & filenames); + itkTypeMacro( InputFilenameListParameter, Superclass ); - /** Add null element to lists. */ - void AddNullElement(); + /** */ + Role GetDirection( std::size_t ) const override; - /** Add a filename from a filename */ - bool AddFromFileName(const std::string & filename); + /** */ + Role GetDirection() const override; - /** Set one specific stored filename. */ - bool SetNthFileName( const unsigned int id, const std::string & filename ); + /** */ + const std::string & GetFilenameFilter( std::size_t ) const override; - /** Get the stored filename list */ - std::vector<std::string> GetFileNameList() const; - - /** Get one specific stored filename. */ - std::string GetNthFileName( unsigned int i ) const; - - /** Get one list of the stored files. */ - StringParameterListPointerType GetFileList() const; - - bool HasValue() const ITK_OVERRIDE; - - - /** Erase one element of the list. */ - void Erase( unsigned int id ); - - /** Clear all the list. */ - void ClearValue() ITK_OVERRIDE; + /** */ + const std::string & GetFilenameFilter() const override; +// +// Protected methods. protected: /** Constructor */ InputFilenameListParameter(); /** Destructor */ - ~InputFilenameListParameter() ITK_OVERRIDE; + ~InputFilenameListParameter() override; + /** */ + const std::string & ToString( const ParameterType::Pointer & ) const override; - StringParameterListType::Pointer m_FilenameList; + /** */ + using Superclass::FromString; + const ParameterType::Pointer & + FromString( const ParameterType::Pointer &, + const std::string & ) const override; +// +// Private methods. private: - InputFilenameListParameter(const Parameter &); //purposely not implemented - void operator =(const Parameter&); //purposely not implemented + InputFilenameListParameter( const Parameter & ); //purposely not implemented + void operator = ( const Parameter & ); //purposely not implemented }; // End class InputFilenameList Parameter } // End namespace Wrapper + } // End namespace otb #endif diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputImageListParameter.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputImageListParameter.h index 6b4bf70c7d66869098aa17dc42aa2a7f12fc5d4f..889e6d8df2bd02d831a1c26a571475407e6b6f86 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputImageListParameter.h +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputImageListParameter.h @@ -21,104 +21,113 @@ #ifndef otbWrapperInputImageListParameter_h #define otbWrapperInputImageListParameter_h -#include "otbWrapperParameter.h" + #include "otbWrapperInputImageParameter.h" +#include "otbWrapperParameterList.h" + namespace otb { + + namespace Wrapper { + /** \class InputImageListParameter * \brief This class represents a list of InputImage parameter * * \ingroup OTBApplicationEngine */ - -class OTBApplicationEngine_EXPORT InputImageListParameter : public Parameter +class OTBApplicationEngine_EXPORT InputImageListParameter : + public ParameterList< InputImageParameter > { public: /** Standard class typedef */ - typedef InputImageListParameter Self; - typedef Parameter Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; + typedef InputImageListParameter Self; + typedef ParameterList< InputImageParameter > Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; - typedef std::vector<InputImageParameter::Pointer> InputImageParameterVectorType; + typedef itk::ImageBase< 2 > ImageBaseType; - typedef itk::ImageBase<2> ImageBaseType; - /** Defining ::New() static method */ - itkNewMacro(Self); + itkNewMacro( Self ); /** RTTI support */ - itkTypeMacro(InputImageListParameter, Parameter); - - /** Set image form a list of filename */ - bool SetListFromFileName(const std::vector<std::string> & filenames); - - /** Add null element to lists. */ - void AddNullElement(); - - /** Add an image from a filename */ - bool AddFromFileName(const std::string & filename); - - /** Set one specific stored image filename. */ - bool SetNthFileName( const unsigned int id, const std::string & filename ); - - /** Get the stored image filename list */ - std::vector<std::string> GetFileNameList() const; - - /** Get one specific stored image filename. */ - std::string GetNthFileName( unsigned int i ) const; + itkTypeMacro( InputImageListParameter, ParameterList ); /** Get one list of the stored image. WARNING : if the parameter list changes, * the returned image list may become obsolete. You should call * GetImageList() again to make sure your image list is up-to-date. */ - FloatVectorImageListType* GetImageList() const; + const FloatVectorImageListType * GetImageList() const; + FloatVectorImageListType * GetImageList(); /** Get one specific stored image. */ - FloatVectorImageType* GetNthImage(unsigned int i) const; + const FloatVectorImageType * GetNthImage( std::size_t ) const; + FloatVectorImageType * GetNthImage( std::size_t ); /** Set one specific image. */ - void SetNthImage(unsigned int i, ImageBaseType * img); - + void SetNthImage( std::size_t, ImageBaseType * ); + /** Set the list of image. */ - void SetImageList(FloatVectorImageListType* imList); + void SetImageList( FloatVectorImageListType * ); /** Add an image to the list. */ - void AddImage(ImageBaseType* image); - - bool HasValue() const ITK_OVERRIDE; + void AddImage( ImageBaseType * ); + /** Clear all the list. */ + void ClearValue() override; - /** Erase one element of the list. */ - void Erase( unsigned int id ); + /** */ + using StringListInterface::GetDirection; + Role GetDirection() const override; - /** Clear all the list. */ - void ClearValue() ITK_OVERRIDE; + /** */ + using StringListInterface::GetFilenameFilter; + const std::string & GetFilenameFilter() const override; - /** Retrieve number of elements */ - unsigned int Size() const; - protected: /** Constructor */ InputImageListParameter(); /** Destructor */ - ~InputImageListParameter() ITK_OVERRIDE; + ~InputImageListParameter() override; + +// +// Protected methods. +protected: + + /** */ + const std::string & ToString( const ParameterType::Pointer & ) const override; + /** */ + using Superclass::FromString; + const ParameterType::Pointer & + FromString( const ParameterType::Pointer &, + const std::string & ) const override; +// +// Private methods. private: - InputImageListParameter(const Parameter &); //purposely not implemented - void operator =(const Parameter&); //purposely not implemented + InputImageListParameter( const Parameter & ); //purposely not implemented + void operator = ( const Parameter & ); //purposely not implemented + + InputImageParameter::Pointer + FromImage( ImageBaseType * ); - InputImageParameterVectorType m_InputImageParameterVector; + InputImageParameter::Pointer & + FromImage( InputImageParameter::Pointer &, ImageBaseType * ); + +// +// Private attributes +private: FloatVectorImageListType::Pointer m_ImageList; - - + + }; // End class InputImage Parameter } // End namespace Wrapper + } // End namespace otb #endif diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputImageParameter.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputImageParameter.h index 0cf771abccd2717c56ebeee8a8d7bc06b48e0a0e..6ff36eedeed7f32c1382aa06be580d2904741967 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputImageParameter.h +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputImageParameter.h @@ -53,8 +53,8 @@ public: itkTypeMacro(InputImageParameter, Parameter); /** Set value from filename */ - bool SetFromFileName(const std::string& filename); - itkGetConstMacro(FileName, std::string); + bool SetFromFileName( const std::string & filename ); + itkGetConstReferenceMacro( FileName, std::string ); /** Get the input image as FloatVectorImageType. */ @@ -96,7 +96,7 @@ public: /** Generic cast method that will be specified for each image type. */ template <class TInputImage, class TOutputImage> TOutputImage* CastImage(); - + /** Cast an image to an image of the same type * Image to Image, VectorImage to VectorImage, RGBAImage to RGBAImage. */ template <class TInputImage, class TOutputImage> @@ -177,7 +177,7 @@ private: otbDeclareCastImageMacro(InputImageType, Float##prefix##ImageType) \ otbDeclareCastImageMacro(InputImageType, Double##prefix##ImageType) - + /********************************************************************* ********************** Image -> Image **********************************************************************/ diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputImageParameter.txx b/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputImageParameter.txx index 64a620f70610e941fc293f1ada0704d904fbc22b..9db0e6140868eb635b115f0b46627f956615d178 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputImageParameter.txx +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputImageParameter.txx @@ -33,6 +33,8 @@ namespace Wrapper { +#define INPUT_IMAGE_PARAMETER_GET_IMAGE_EXCEPTION 0 + template <class TImageType> TImageType* InputImageParameter::GetImage() @@ -45,27 +47,35 @@ InputImageParameter::GetImage() // Only one image type can be used // 2 cases : the user set a filename vs. the user set an image - if (m_UseFilename) + if( m_UseFilename ) { - if( m_PreviousFileName!=m_FileName && !m_FileName.empty() ) + if( m_PreviousFileName!=m_FileName && + !m_FileName.empty() ) { //////////////////////// Filename case: // A new valid filename has been given : a reader is created - m_PreviousFileName = m_FileName; typedef otb::ImageFileReader<TImageType> ReaderType; + typename ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(m_FileName); + + reader->SetFileName( m_FileName ); reader->UpdateOutputInformation(); m_Image = reader->GetOutput(); m_Reader = reader; + m_PreviousFileName = m_FileName; + // Pay attention, don't return m_Image because it is a ImageBase... return reader->GetOutput(); } else { +#if INPUT_IMAGE_PARAMETER_GET_IMAGE_EXCEPTION + return dynamic_cast< TImageType* >( m_Image.GetPointer() ); + +#else // INPUT_IMAGE_PARAMETER_GET_IMAGE_EXCEPTION // In this case, the reader and the image should already be there if (m_Image.IsNull()) { @@ -83,14 +93,20 @@ InputImageParameter::GetImage() itkExceptionMacro("Cannot ask a different image type"); } } +#endif // INPUT_IMAGE_PARAMETER_GET_IMAGE_EXCEPTION } } + else { //////////////////////// Image case: if (m_Image.IsNull()) { +#if INPUT_IMAGE_PARAMETER_GET_IMAGE_EXCEPTION itkExceptionMacro("No input image or filename detected..."); +#else + return nullptr; +#endif } else { @@ -160,7 +176,11 @@ InputImageParameter::GetImage() } else { +#if INPUT_IMAGE_PARAMETER_GET_IMAGE_EXCEPTION itkExceptionMacro("Unknown image type"); +#else + return nullptr; +#endif } } } diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputVectorDataListParameter.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputVectorDataListParameter.h index 423d2ca0f9953c601c2122b6f9a004dcfbb61173..52d4ac37ea4c5aa116e211a203f1b2bca3860bbd 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputVectorDataListParameter.h +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputVectorDataListParameter.h @@ -21,78 +21,65 @@ #ifndef otbWrapperInputVectorDataListParameter_h #define otbWrapperInputVectorDataListParameter_h -#include "otbVectorDataFileReader.h" -#include "otbWrapperParameter.h" -#include "otbObjectList.h" +#include "otbWrapperInputVectorDataParameter.h" +#include "otbWrapperParameterList.h" + namespace otb { + + namespace Wrapper { + /** \class InputVectorDataListParameter * \brief This class represents a list of VectorData parameter * * \ingroup OTBApplicationEngine */ - -class OTBApplicationEngine_EXPORT InputVectorDataListParameter : public Parameter +class OTBApplicationEngine_EXPORT InputVectorDataListParameter : + public ParameterList< InputVectorDataParameter > { public: /** Standard class typedef */ - typedef InputVectorDataListParameter Self; - typedef Parameter Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - - typedef otb::VectorDataFileReader<VectorDataType> VectorDataFileReaderType; - typedef otb::ObjectList<VectorDataFileReaderType> VectorDataFileReaderListType; + typedef InputVectorDataListParameter Self; + typedef ParameterList< InputVectorDataParameter > Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; /** Defining ::New() static method */ - itkNewMacro(Self); + itkNewMacro( Self ); /** RTTI support */ - itkTypeMacro(InputVectorDataListParameter, Parameter); - - /** Set image form a list of filename */ - bool SetListFromFileName(const std::vector<std::string> & filenames); - - /** Add null element to lists. */ - void AddNullElement(); - - /** Add an image from a filename */ - bool AddFromFileName(const std::string & filename); - - /** Set one specific stored image filename. */ - bool SetNthFileName( const unsigned int id, const std::string & filename ); - - - /** Get the stored image filename list */ - std::vector<std::string> GetFileNameList() const; - - /** Get one specific stored image filename. */ - std::string GetNthFileName( unsigned int i ) const; + itkTypeMacro( InputVectorDataListParameter, ParameterList ); /** Get one list of the stored image. */ - VectorDataListType* GetVectorDataList() const; + const VectorDataListType * GetVectorDataList() const; + VectorDataListType * GetVectorDataList(); /** Get one specific stored image. */ - VectorDataType* GetNthVectorData(unsigned int i) const; + // + // FIXME: Definition is not const-correct because + // InputVectorDataParameter::GetVectorData() is not const-correct! + const VectorDataType * GetNthVectorData( std::size_t ); /** Set the list of image. */ - void SetVectorDataList(VectorDataListType* vdList); + void SetVectorDataList( VectorDataListType * ); /** Add an image to the list. */ - void AddVectorData(VectorDataType* image); - - bool HasValue() const ITK_OVERRIDE; + void AddVectorData( VectorDataType * ); + /** Clear all the list. */ + void ClearValue() override; - /** Erase one element of the list. */ - void Erase( unsigned int id ); + /** */ + using StringListInterface::GetDirection; + virtual Role GetDirection() const override; - /** Clear all the list. */ - void ClearValue() ITK_OVERRIDE; + /** */ + using StringListInterface::GetFilenameFilter; + const std::string & GetFilenameFilter() const override; protected: @@ -100,18 +87,39 @@ protected: InputVectorDataListParameter(); /** Destructor */ - ~InputVectorDataListParameter() ITK_OVERRIDE; + ~InputVectorDataListParameter() override; - VectorDataListType::Pointer m_VectorDataList; - VectorDataFileReaderListType::Pointer m_ReaderList; + /** */ + const std::string & ToString( const ParameterType::Pointer & ) const override; + + /** */ + using Superclass::FromString; + const ParameterType::Pointer & + FromString( const ParameterType::Pointer &, + const std::string & ) const override; + +private: + // Purposely not implemented + InputVectorDataListParameter( const Parameter & ); + + // Purposely not implemented + void operator = ( const Parameter & ); + + InputVectorDataParameter::Pointer + FromVectorData( VectorDataType * ); + InputVectorDataParameter::Pointer & + FromVectorData( InputVectorDataParameter::Pointer &, VectorDataType * ); + +// +// Private attributes private: - InputVectorDataListParameter(const Parameter &); //purposely not implemented - void operator =(const Parameter&); //purposely not implemented + VectorDataListType::Pointer m_VectorDataList; }; // End class InputVectorDataList Parameter } // End namespace Wrapper + } // End namespace otb #endif diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputVectorDataParameter.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputVectorDataParameter.h index dded12d42bc14e4d751c511ee7eb534aaf71e85a..f84a3834ebb28767374455d8d48035ffac275dbf 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputVectorDataParameter.h +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputVectorDataParameter.h @@ -55,9 +55,10 @@ public: /** Set value from filename */ bool SetFromFileName(const std::string& filename); - itkGetConstMacro(FileName, std::string); + itkGetConstReferenceMacro( FileName, std::string ); - VectorDataType* GetVectorData(); + const VectorDataType * GetVectorData() const; + VectorDataType * GetVectorData(); void SetVectorData(VectorDataType* vectorData); @@ -78,6 +79,8 @@ protected: std::string m_FileName; + std::string m_PreviousFileName; + private: InputVectorDataParameter(const Parameter &); //purposely not implemented void operator =(const Parameter&); //purposely not implemented diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperOutputImageParameter.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperOutputImageParameter.h index adbf9d12ee1628d5d1dd5e5f02e1b8a7ac8569c1..b420299ff6b707f8ccbed39577b488684e527fae 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperOutputImageParameter.h +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperOutputImageParameter.h @@ -86,6 +86,10 @@ public: /** Static method to convert pixel type into string */ static std::string ConvertPixelTypeToString(ImagePixelType type); + /** Converts a string into a pixel type (returns false if the conversion + * fails) */ + static bool ConvertStringToPixelType(const std::string &value, ImagePixelType &type); + /** Return true if a filename is set */ bool HasValue() const ITK_OVERRIDE; diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperParameter.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperParameter.h index 772ee60902a878ef883b8fc568e138b47ea44c1c..236411f8f21e8b185bed7aa514770bb19ca00b14 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperParameter.h +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperParameter.h @@ -70,9 +70,6 @@ public: typedef itk::SmartPointer<Self> Pointer; typedef itk::SmartPointer<const Self> ConstPointer; - /** Defining ::New() static method */ - itkNewMacro(Self); - /** RTTI support */ itkTypeMacro(Parameter, itk::Object); @@ -86,7 +83,7 @@ public: itkSetStringMacro(Description); /** Get the parameter description */ - itkGetStringMacro(Description); + itkGetConstReferenceMacro( Description, std::string ); /** Set the parameter key */ itkSetStringMacro(Key); @@ -151,14 +148,11 @@ public: { } - virtual bool HasValue() const - { - itkExceptionMacro(<<"HasValue() method must be re-implemented by sub-classes."); - } + virtual bool HasValue() const = 0; virtual bool HasUserValue() const { - return HasValue() && m_UserValue; + return this->HasValue() && m_UserValue; } virtual void SetUserValue(bool isUserValue) @@ -168,7 +162,8 @@ public: virtual void ClearValue() { - itkExceptionMacro(<<"ClearValue() method must be re-implemented by sub-classes."); + SetActive( false ); + Modified(); } /** Set/Get the root of the current parameter (direct parent) */ @@ -207,7 +202,7 @@ public: /** Store the state of the check box relative to this parameter (TO * BE MOVED to QtWrapper Model ) */ - virtual bool IsChecked() + virtual bool IsChecked() const { return m_IsChecked; } @@ -220,23 +215,23 @@ public: protected: /** Constructor */ - Parameter() : m_Name(""), - m_Description(""), - m_Key(""), - m_Mandatory(true), - m_Active(false), - m_UserValue(false), - m_AutomaticValue(false), - m_DefaultValueMode(DefaultValueMode_UNKNOWN), - m_UserLevel(UserLevel_Basic), - m_Role(Role_Input), - m_Root(this), - m_IsChecked(false) + Parameter() : + m_Name( "" ), + m_Description( "" ), + m_Key( "" ), + m_Mandatory( true ), + m_Active( false ), + m_UserValue( false ), + m_AutomaticValue( false ), + m_DefaultValueMode( DefaultValueMode_UNKNOWN ), + m_UserLevel( UserLevel_Basic ), + m_Role( Role_Input ), + m_Root( this ), + m_IsChecked( false ) {} /** Destructor */ - ~Parameter() ITK_OVERRIDE - {} + ~Parameter() ITK_OVERRIDE {} /** Name of the parameter */ std::string m_Name; diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperParameterList.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperParameterList.h new file mode 100644 index 0000000000000000000000000000000000000000..2c9c699fbe3c540a62d9cc4b39c39bfa052508b6 --- /dev/null +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperParameterList.h @@ -0,0 +1,205 @@ +/* + * Copyright (C) 2005-2017 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 otbWrapperParameterList_h +#define otbWrapperParameterList_h + + +#include "otbWrapperAbstractParameterList.h" +#include "otbWrapperStringListInterface.h" + + +namespace otb +{ + +namespace Wrapper +{ + + +/** \class ParameterList + * \brief This class represents a InputImage parameter + * + * \ingroup OTBApplicationEngine + */ +template< typename T > +class ParameterList : + public AbstractParameterList +{ +// +// Public types. +public: + /** Standard class typedef */ + typedef ParameterList Self; + typedef AbstractParameterList Superclass; + + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + /** Custom types */ + typedef T ParameterType; + typedef std::vector< typename T::Pointer > ParameterVector; + +// +// Public methods. +public: + + /** RTTI support */ + itkTypeMacro( ParameterList, AbstractParameterList ); + + /** */ + typename ParameterVector::const_iterator begin() const; + + /** */ + typename ParameterVector::const_iterator end() const; + + /** */ + void ClearValue() override; + + /** */ + bool HasValue() const override; + + /** Set file form a list of filenames */ + void SetListFromFileName( const StringVector & ) override; + + /** */ + void InsertNullElement( std::size_t = -1 ) override; + + /** Add a filename from a filename */ + void AddFromFileName( const std::string & ) override; + + /** */ + void Insert( const std::string &, std::size_t = -1 ) override; + + /** Set one specific stored filename. */ + void SetNthFileName( std::size_t, const std::string & ) override; + + /** */ + std::size_t SetStrings( const StringVector & ); + + /** */ + std::size_t GetStrings( StringVector & ) const override; + + /** Get the stored image filename list */ + StringVector GetFileNameList() const override; + + /** Get one specific stored image filename. */ + const std::string & GetNthFileName( std::size_t ) const override; + + /** */ + const std::string & GetToolTip( std::size_t ) const override; + + /** */ + using StringListInterface::Erase; + void Erase( std::size_t start, std::size_t count ) override; + + /** Retrieve number of elements */ + std::size_t Size() const override; + + /** */ + bool IsActive( size_t ) const override; + + /** */ + void Swap( std::size_t, std::size_t ) override; + +// +// Protected methods. +protected: + /** Constructor */ + ParameterList(); + + /** Destructor */ + ~ParameterList() override; + +// +// Private methods. +private: + // ParameterList( const Parameter & ); // purposely not implemented + // void operator = ( const Parameter & ); // purposely not implemented + +// +// Protected methods. +protected: + /** Utility method to factorize some code */ + template< typename L, typename From, typename Get > + void + SetObjectList( L &, const L &, From, Get ); + + /** Utility method to factorize some code */ + template< typename L, typename Get > + typename L::ObjectType * + GetObjectList( L &, Get ); + + /** */ + template< typename L, typename Get > + const typename L::ObjectType * + GetObjectList( L &, Get ) const; + + /** */ + template< typename D, typename From > + void AddData( D *, From ); + + /** */ + template< typename D, typename Set > + typename T::Pointer + FromData( D *, + Set, + const std::string & description = std::string() ); + + /** */ + template< typename D, typename Set > + typename T::Pointer & + FromData( typename T::Pointer &, + D *, + Set, + const std::string & description = std::string() ); + + /** ParameterType::ValueType -> std::string protocol */ + virtual + const std::string & + ToString( const typename ParameterType::Pointer & ) const = 0; + + /** std::string -> ParameterType::ValueType protocol */ + virtual + const typename ParameterType::Pointer & + FromString( const typename ParameterType::Pointer &, + const std::string & ) const = 0; + + /** Utility method to use std::string -> conversion in lambdas. */ + virtual + typename ParameterType::Pointer + FromString( const std::string & ) const; + +// +// Protected attributes. +protected: + /** */ + ParameterVector m_Parameters; + +}; // End class InputImage Parameter + +} // End namespace Wrapper + +} // End namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +# include "otbWrapperParameterList.txx" +#endif + +#endif diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperParameterList.txx b/Modules/Wrappers/ApplicationEngine/include/otbWrapperParameterList.txx new file mode 100644 index 0000000000000000000000000000000000000000..da857bcbf8bff3e78b988e2044f8f14cb4c144b6 --- /dev/null +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperParameterList.txx @@ -0,0 +1,487 @@ +/* + * Copyright (C) 2005-2017 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 otbWrapperParameterList_txx +#define otbWrapperParameterList_txx + + +#include <algorithm> +#include <iterator> + +#include "otbCast.h" +#include "otbWrapperParameterList.h" + + +namespace otb +{ + +namespace Wrapper +{ + + +/*****************************************************************************/ +template< typename T > +ParameterList< T > +::ParameterList() : + AbstractParameterList(), + m_Parameters() +{ +} + +/*****************************************************************************/ +template< typename T > +ParameterList< T > +::~ParameterList() +{ +} + +/*****************************************************************************/ +template< typename T > +typename ParameterList< T >::ParameterVector::const_iterator +ParameterList< T > +::begin() const +{ + return m_Parameters.begin(); +} + +/*****************************************************************************/ +template< typename T > +typename ParameterList< T >::ParameterVector::const_iterator +ParameterList< T > +::end() const +{ + return m_Parameters.end(); +} + +/*****************************************************************************/ +template< typename T > +bool +ParameterList< T > +::HasValue() const +{ + return + Size()>0 + && + std::all_of( + begin(), + end(), + []( auto p ) -> bool + { + assert( p!=nullptr ); + return p && p->HasValue(); + } + ); +} + +/*****************************************************************************/ +template< typename T > +void +ParameterList< T > +::ClearValue() +{ + m_Parameters.clear(); + + Superclass::ClearValue(); +} + +/*****************************************************************************/ +template< typename T > +void +ParameterList< T > +::SetListFromFileName( const StringVector & strings ) +{ + this->SetStrings(strings); +} + +/*****************************************************************************/ +template< typename T > +void +ParameterList< T > +::InsertNullElement( std::size_t index ) +{ + m_Parameters.insert( + index>=m_Parameters.size() + ? m_Parameters.end() + : m_Parameters.begin() + index, + typename T::Pointer() + ); + + SetActive( false ); + + Modified(); +} + +/*****************************************************************************/ +template< typename T > +void +ParameterList< T > +::AddFromFileName( const std::string & filename ) +{ + assert( !filename.empty() ); + + typename T::Pointer p( T::New() ); + + FromString( p, filename ); + + m_Parameters.push_back( p ); + + assert( !m_Parameters.back().IsNull() ); + + SetActive( true ); + + Modified(); +} + +/*****************************************************************************/ +template< typename T > +void +ParameterList< T > +::Insert( const std::string & filename, std::size_t index ) +{ + typename T::Pointer p( T::New() ); + + FromString( p, filename ); + + m_Parameters.insert( m_Parameters.begin() + index, p ); + + assert( !m_Parameters.back().IsNull() ); + + SetActive( true ); + + Modified(); +} + +/*****************************************************************************/ +template< typename T > +void +ParameterList< T > +::SetNthFileName( std::size_t i, + const std::string & filename ) +{ + assert( i<m_Parameters.size() ); + assert( !m_Parameters[ i ].IsNull() ); + + // Should throw exception when failed. + FromString( m_Parameters[ i ], filename ); + + SetActive( true ); + + Modified(); +} + +/*****************************************************************************/ +template< typename T > +std::size_t +ParameterList< T > +::SetStrings( const StringVector & strings ) +{ + // First clear previous file chosen + ClearValue(); + + if ( !strings.empty() ) + { + std::transform( + strings.begin(), + strings.end(), + std::back_inserter( m_Parameters ), + [ this ]( auto s ) -> auto + { + return this->FromString( s ); + } + ); + + SetActive( true ); + Modified(); + } + return strings.size(); +} + +/*****************************************************************************/ +template< typename T > +std::size_t +ParameterList< T > +::GetStrings( StringVector & strings ) const +{ + std::transform( + begin(), + end(), + std::back_inserter( strings ), + [ this ]( auto p ) -> auto + { + return this->ToString( p ); + } + ); + + return m_Parameters.size(); +} + +/*****************************************************************************/ +template< typename T > +StringListInterface::StringVector +ParameterList< T > +::GetFileNameList() const +{ + StringVector filenames; + + GetStrings( filenames ); + + return filenames; +} + +/*****************************************************************************/ +template< typename T > +const std::string & +ParameterList< T > +::GetNthFileName( std::size_t i ) const +{ + assert( i<m_Parameters.size() ); + + return ToString( m_Parameters[ i ] ); +} + +/*****************************************************************************/ +template< typename T > +const std::string & +ParameterList< T > +::GetToolTip( std::size_t i ) const +{ + assert( i<m_Parameters.size() ); + assert( !m_Parameters[ i ].IsNull() ); + + return m_Parameters[ i ]->GetDescription(); +} + +/*****************************************************************************/ +template< typename T > +void +ParameterList< T > +::Erase( std::size_t start, std::size_t count ) +{ + assert( start<m_Parameters.size() ); + assert( start+count<=m_Parameters.size() ); + + m_Parameters.erase( + m_Parameters.begin() + start, + m_Parameters.begin() + start + count + ); + + Modified(); +} + +/*****************************************************************************/ +template< typename T > +std::size_t +ParameterList< T > +::Size() const +{ + return m_Parameters.size(); +} + +/*****************************************************************************/ +template< typename T > +bool +ParameterList< T > +::IsActive( std::size_t i ) const +{ + assert( i<m_Parameters.size() ); + assert( !m_Parameters[ i ].IsNull() ); + + return m_Parameters[ i ]->GetActive(); +} + +/*****************************************************************************/ +template< typename T > +void +ParameterList< T > +::Swap( std::size_t i1, std::size_t i2 ) +{ + assert( !m_Parameters.empty() ); + + auto clamp = [ this ]( std::size_t i ) -> std::size_t + { + return + i>=m_Parameters.size() + ? m_Parameters.size() - 1 + : i; + }; + + std::swap( + m_Parameters[ clamp( i1 ) ], + m_Parameters[ clamp( i2 ) ] + ); +} + +/*****************************************************************************/ +template< typename T > +template< typename L, typename From, typename Get > +void +ParameterList< T > +::SetObjectList( L & this_list, + const L & list, + From from, + Get get ) +{ + // Force update of input-list elements. + for( std::size_t i=0; i<list.Size(); i++ ) + { + assert( list.GetNthElement( i )!=nullptr ); + + list.GetNthElement( i )->UpdateOutputInformation(); + } + + // Clear previous target list. + ClearValue(); + + for( std::size_t i=0; i<list.Size(); i++ ) + { + assert( list.GetNthElement( i )!=nullptr ); + + typename T::Pointer parameter; + + from( parameter, list.GetNthElement( i ) ); + + m_Parameters.push_back( parameter ); + + assert( get( parameter )!=nullptr ); + + this_list.PushBack( get( parameter ) ); + } + + SetActive( true ); + + Modified(); +} + +/*****************************************************************************/ +template< typename T > +template< typename L, typename Get > +typename L::ObjectType * +ParameterList< T > +::GetObjectList( L & this_list, Get get ) +{ + assert( this_list ); + + this_list->Clear(); + + std::for_each( + begin(), + end(), + [ this_list, get ]( auto parameter ) -> void + { + assert( parameter ); + assert( parameter==otb::DynamicCast< T >( parameter ) ); + + assert( get( DynamicCast< T >( parameter ) ) ); + + this_list->PushBack( + get( + DynamicCast< T >( parameter ) + ) + ); + } + ); + + return this_list; +} + +/*****************************************************************************/ +template< typename T > +template< typename L, typename Get > +const typename L::ObjectType * +ParameterList< T > +::GetObjectList( L & this_list, Get get ) const +{ + return + const_cast< ParameterList< T > * >( this ) + ->GetObjectList( this_list, get ); +} + +/*****************************************************************************/ +template< typename T > +template< typename D, typename From > +void +ParameterList< T > +::AddData( D * data, From from ) +{ + assert( data!=nullptr ); + + // Check input availability + data->UpdateOutputInformation(); + + // Build & add parameter. + m_Parameters.push_back( from( data ) ); + + Modified(); +} + +/*****************************************************************************/ +template< typename T > +template< typename D, typename Set > +typename T::Pointer +ParameterList< T > +::FromData( D * data, + Set set, + const std::string & description ) +{ + assert( data!=nullptr ); + + typename T::Pointer p; + + return From( p, data, set, description ); +} + +/*****************************************************************************/ +template< typename T > +template< typename D, typename Set > +typename T::Pointer & +ParameterList< T > +::FromData( typename T::Pointer & parameter, + D * data, + Set set, + const std::string & description ) +{ + assert( data!=nullptr ); + + parameter = T::New(); + + set( parameter, data ); + parameter->SetDescription( description ); + + return parameter; +} + +/*****************************************************************************/ +template< typename T > +typename T::Pointer +ParameterList< T > +::FromString( const std::string & s ) const +{ + typename T::Pointer parameter( T::New() ); + + return FromString( parameter, s ); +} + +} // End namespace Wrapper + + +} // End namespace otb + + +#endif diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperProxyParameter.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperProxyParameter.h index 1a93c2445479aaadc84e3303f01722181bdb4505..c7594f8c5dd625f96f144105513944e4c7fd39b1 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperProxyParameter.h +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperProxyParameter.h @@ -70,6 +70,11 @@ public: return m_Target; } + bool HasValue() const override + { + return m_Target.first.IsNotNull(); + } + protected: ProxyParameter() {} ~ProxyParameter() ITK_OVERRIDE {} diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperStringListInterface.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperStringListInterface.h new file mode 100644 index 0000000000000000000000000000000000000000..dd84632d2312d9ed3ecc7d60bedbb806232f9f3e --- /dev/null +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperStringListInterface.h @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2005-2017 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 otbWrapperStringListInterface_h +#define otbWrapperStringListInterface_h + + +#include <string> +#include <vector> + +#include "OTBApplicationEngineExport.h" + +#include "otbWrapperTypes.h" + + +namespace otb +{ + +namespace Wrapper +{ + +/** \class StringListInterface + * \brief This class represents a list of InputFilename parameter + * + * \ingroup OTBApplicationEngine + */ +class OTBApplicationEngine_EXPORT StringListInterface +{ +public: + /** */ + typedef std::vector< std::string > StringVector; + + /** Set file form a list of filenames */ + virtual void SetListFromFileName( const StringVector & ) = 0; + + /** Add null element to lists. */ + virtual void AddNullElement(); + + /** */ + virtual void InsertNullElement( std::size_t = -1 ) = 0; + + /** Add a filename from a filename */ + virtual void AddFromFileName( const std::string & ) = 0; + + /** */ + virtual void Insert( const std::string & filename, std::size_t = -1 ) = 0; + + /** Set one specific stored filename. */ + virtual void SetNthFileName( std::size_t, const std::string & ) = 0; + + /** */ + virtual std::size_t SetStrings( const StringVector & ); + + /** */ + virtual std::size_t GetStrings( StringVector & ) const; + + /** Get the stored filename list */ + virtual StringVector GetFileNameList() const = 0; + + /** Get one specific stored filename. */ + virtual const std::string & GetNthFileName( std::size_t i ) const = 0; + + /** Erase one element of the list. */ + virtual void Erase( std::size_t id ); + + /** */ + virtual void Erase( std::size_t start, std::size_t count ) = 0; + + /** Retrieve number of elements */ + virtual std::size_t Size() const = 0; + + /** */ + virtual bool IsActive( std::size_t ) const = 0; + + /** */ + virtual const std::string & GetToolTip( std::size_t ) const = 0; + + /** */ + virtual void Swap( std::size_t, std::size_t ) = 0; + + /** */ + virtual Role GetDirection( std::size_t ) const; + + /** */ + virtual Role GetDirection() const = 0; + + /** */ + virtual const std::string & GetFilenameFilter( std::size_t ) const; + + /** */ + virtual const std::string & GetFilenameFilter() const; + + /** */ + virtual bool IsFilename() const; + +protected: + /** Constructor */ + StringListInterface() {}; + +private: + +}; + +} // End namespace Wrapper + +} // End namespace otb + + +#endif // otbWrapperStringListInterface_h diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperStringListParameter.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperStringListParameter.h index c0368288448ff268bde9308a64b227bf3665b7c1..a01a11db2f44e056e9fd9cfa691548bf3eefad2a 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperStringListParameter.h +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperStringListParameter.h @@ -21,11 +21,15 @@ #ifndef otbWrapperStringListParameter_h #define otbWrapperStringListParameter_h -#include <string> -#include "otbWrapperParameter.h" + +#include "otbWrapperParameterList.h" +#include "otbWrapperStringParameter.h" + namespace otb { + + namespace Wrapper { @@ -34,114 +38,79 @@ namespace Wrapper * * \ingroup OTBApplicationEngine */ -class OTBApplicationEngine_EXPORT StringListParameter - : public Parameter +class OTBApplicationEngine_EXPORT StringListParameter : + public ParameterList< StringParameter > { +// +// Public methods. public: /** Standard class typedef */ typedef StringListParameter Self; - typedef Parameter Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; + typedef ParameterList< StringParameter > Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; - typedef std::vector<std::string> StringListType; + typedef StringListInterface::StringVector StringListType; /** Defining ::New() static method */ - itkNewMacro(Self) -; + itkNewMacro( Self ); /** RTTI support */ - itkTypeMacro(StringListParameter, Parameter) -; + itkTypeMacro( StringListParameter, ParameterList ); /** Set the value */ - void SetValue(StringListType sList) - { - m_Value.clear(); - for(unsigned int i=0; i<sList.size(); i++) - { - this->AddString(sList[i]); - } - } - - void AddString(std::string value) - { - if(!value.empty()) - { - m_Value.push_back(value); - if(!this->GetActive()) - { - this->SetActive(true); - } - } - } + void SetValue( const StringListInterface::StringVector & ); - /** Get the value */ - StringListType GetValue() const - { - return m_Value; - } + /** */ + void AddString( const std::string & value ); /** Get the value */ - std::string GetNthElement(unsigned int i) const - { - if (m_Value.size() < i) - { - itkExceptionMacro( "Invalid index "<<i<<" the string list has only "<<m_Value.size()<<" elements...") - } + StringListInterface::StringVector GetValue() const; - return m_Value[i]; - } + /** Get the value */ + const std::string & GetNthElement( std::size_t ) const; /** Get the value */ - void SetNthElement(unsigned int i, std::string value) - { - if (m_Value.size() < i) - { - itkExceptionMacro( "Invalid index "<<i<<" the string list has only "<<m_Value.size()<<" elements...") - } - m_Value[i] = value; - } - - bool HasValue() const ITK_OVERRIDE - { - return !m_Value.empty(); - } - - void ClearValue() ITK_OVERRIDE - { - m_Value.clear(); - } - - void AddNullElement() - { - m_Value.push_back(""); - SetActive(false); - this->Modified(); - } + void SetNthElement( std::size_t, const std::string & ); + /** */ + using StringListInterface::GetDirection; + Role GetDirection() const override; + + /** */ + bool IsFilename() const override; + +// +// Protected methods. protected: /** Constructor */ - StringListParameter() - { - this->SetName("String List"); - this->SetKey("strList"); - } + StringListParameter(); /** Destructor */ - ~StringListParameter() ITK_OVERRIDE - { - } + ~StringListParameter() override; + + /** */ + const std::string & ToString( const ParameterType::Pointer & ) const override; - StringListType m_Value; + /** */ + using Superclass::FromString; + const ParameterType::Pointer & + FromString( const ParameterType::Pointer &, + const std::string & ) const override; +// +// Private methods. private: - StringListParameter(const StringListParameter &); //purposely not implemented - void operator =(const StringListParameter&); //purposely not implemented + // Purposely not implemented + StringListParameter ( const StringListParameter & ); + + // Purposely not implemented + void operator = ( const StringListParameter & ); }; // End class Parameter } // End namespace Wrapper + } // End namespace otb #endif diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperStringParameter.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperStringParameter.h index a8f7943dbc2bd565e660ba7ed9cbaae653063e5c..9c8b1e88a976707a3da0d29842775f138777cd2b 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperStringParameter.h +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperStringParameter.h @@ -51,14 +51,14 @@ public: itkTypeMacro(StringParameter, Parameter); /** Set the value */ - void SetValue( std::string value) + void SetValue( const std::string & value ) { m_Value = value; - SetActive(true); + SetActive( true ); } /** Get the value */ - std::string GetValue() const + const std::string & GetValue() const { return m_Value; } diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperTypes.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperTypes.h index f00cb08571c9834067dadb996004bac9efa2f39e..63dafb639b432a1e3508084cdcc860b7c9efc7ae 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperTypes.h +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperTypes.h @@ -87,7 +87,7 @@ typedef enum typedef enum { - Role_Input, + Role_Input = 0, Role_Output } Role; diff --git a/Modules/Wrappers/ApplicationEngine/src/CMakeLists.txt b/Modules/Wrappers/ApplicationEngine/src/CMakeLists.txt index 3251a05d8e7f250abf1aae901438544cd7ae13eb..343f9db8354ca588189b10f7fcf625413225f1e4 100644 --- a/Modules/Wrappers/ApplicationEngine/src/CMakeLists.txt +++ b/Modules/Wrappers/ApplicationEngine/src/CMakeLists.txt @@ -18,7 +18,7 @@ # limitations under the License. # -set(OTBApplicationEngine_SRC +set( OTBApplicationEngine_SRC otbWrapperApplicationHtmlDocGenerator.cxx otbWrapperComplexOutputImageParameter.cxx otbWrapperInputVectorDataListParameter.cxx @@ -48,11 +48,15 @@ set(OTBApplicationEngine_SRC otbWrapperApplicationRegistry.cxx otbWrapperApplicationFactoryBase.cxx otbWrapperCompositeApplication.cxx + otbWrapperStringListInterface.cxx + otbWrapperStringListParameter.cxx + otbWrapperAbstractParameterList.cxx + otbWrapperParameterList.cxx otbLogger.cxx ) add_library(OTBApplicationEngine ${OTBApplicationEngine_SRC}) -target_link_libraries(OTBApplicationEngine +target_link_libraries(OTBApplicationEngine ${OTBVectorDataBase_LIBRARIES} ${OTBImageManipulation_LIBRARIES} ${OTBImageIO_LIBRARIES} diff --git a/Modules/Wrappers/ApplicationEngine/test/otbWrapperParameterTest.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperAbstractParameterList.cxx similarity index 50% rename from Modules/Wrappers/ApplicationEngine/test/otbWrapperParameterTest.cxx rename to Modules/Wrappers/ApplicationEngine/src/otbWrapperAbstractParameterList.cxx index e4104cdc6560c6b391b094b372b841b0fb376799..06b3cef29cbb21c783f3ed4c99b8b7df89662496 100644 --- a/Modules/Wrappers/ApplicationEngine/test/otbWrapperParameterTest.cxx +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperAbstractParameterList.cxx @@ -18,37 +18,31 @@ * limitations under the License. */ -#if defined(_MSC_VER) -#pragma warning ( disable : 4786 ) -#endif +#include "otbWrapperAbstractParameterList.h" -#include "otbWrapperParameter.h" -int otbWrapperParameterNew(int itkNotUsed(argc), char * itkNotUsed(argv)[]) +namespace otb { - typedef otb::Wrapper::Parameter ParameterBaseType; - ParameterBaseType::Pointer parameter = ParameterBaseType::New(); - //std::cout << parameter << std::endl; - return EXIT_SUCCESS; +namespace Wrapper +{ + + +/*****************************************************************************/ +AbstractParameterList +::AbstractParameterList() +{ } -int otbWrapperParameterTest1(int itkNotUsed(argc), char* argv[]) +/*****************************************************************************/ +AbstractParameterList +::~AbstractParameterList() { - typedef otb::Wrapper::Parameter ParameterBaseType; - ParameterBaseType::Pointer parameter = ParameterBaseType::New(); +} - const std::string name = argv[1]; - parameter->SetName(name); +} // End of namespace 'Wrapper' - if (name == parameter->GetName()) - { - return EXIT_SUCCESS; - } - else - { - return EXIT_FAILURE; - } -} + +} // End of namespace 'otb' diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx index 47c4e85d5fef4371e1454c0c65f35166ffea32a9..776b09fa45e894afe8efe0feb2980410de48b3bd 100644 --- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx @@ -265,20 +265,17 @@ void Application::SetParameterStringList(std::string parameter, std::vector<std: if (dynamic_cast<InputImageListParameter*>(param)) { InputImageListParameter* paramDown = dynamic_cast<InputImageListParameter*>(param); - if( !paramDown->SetListFromFileName(values) ) - otbAppLogCRITICAL( <<"At least one image filename is invalid."); + paramDown->SetListFromFileName( values ); } else if (dynamic_cast<InputVectorDataListParameter*>(param)) { InputVectorDataListParameter* paramDown = dynamic_cast<InputVectorDataListParameter*>(param); - if( !paramDown->SetListFromFileName(values) ) - otbAppLogCRITICAL( <<"At least one vector data filename is invalid.."); + paramDown->SetListFromFileName( values ); } else if (dynamic_cast<InputFilenameListParameter*>(param)) { InputFilenameListParameter* paramDown = dynamic_cast<InputFilenameListParameter*>(param); - if( !paramDown->SetListFromFileName(values) ) - otbAppLogCRITICAL( <<"At least one filename is invalid.."); + paramDown->SetListFromFileName( values ); } else if (dynamic_cast<StringListParameter*>(param)) { @@ -476,7 +473,7 @@ int Application::ExecuteAndWriteOutput() { Parameter* param = GetParameterByKey(key); ComplexOutputImageParameter* outputParam = dynamic_cast<ComplexOutputImageParameter*>(param); - + if(outputParam!=ITK_NULLPTR) { outputParam->InitializeWriters(); @@ -884,7 +881,7 @@ void Application::SetListViewSingleSelectionMode(std::string parameter, bool sta } else itkExceptionMacro(<<parameter << "parameter can't be casted to ListView"); - + } @@ -1124,14 +1121,16 @@ std::string Application::GetParameterString(std::string parameter) return ret; } -std::vector<std::string> Application::GetParameterStringList(std::string parameter) +std::vector< std::string > +Application +::GetParameterStringList( const std::string & parameter ) { std::vector<std::string> ret; - Parameter* param = GetParameterByKey(parameter); + Parameter * param = GetParameterByKey(parameter); if (dynamic_cast<InputImageListParameter*> (param)) { - InputImageListParameter* paramDown = dynamic_cast<InputImageListParameter*> (param); + InputImageListParameter * paramDown = dynamic_cast<InputImageListParameter*> (param); ret = paramDown->GetFileNameList(); } else @@ -1143,13 +1142,13 @@ std::vector<std::string> Application::GetParameterStringList(std::string paramet else if (dynamic_cast<InputFilenameListParameter*> (param)) { - InputFilenameListParameter* paramDown = dynamic_cast<InputFilenameListParameter*> (param); + InputFilenameListParameter* paramDown = dynamic_cast<InputFilenameListParameter*> (param); ret = paramDown->GetFileNameList(); } else if (dynamic_cast<StringListParameter*> (param)) { - StringListParameter* paramDown = dynamic_cast<StringListParameter*> (param); + StringListParameter* paramDown = dynamic_cast<StringListParameter*> (param); ret = paramDown->GetValue(); } else @@ -1171,7 +1170,7 @@ void Application::SetParameterInputImage(std::string parameter, InputImageParame Parameter* param = GetParameterByKey(parameter); InputImageParameter* paramDown = dynamic_cast<InputImageParameter*> (param); - + if (paramDown) { paramDown->SetImage(inputImage); @@ -1185,11 +1184,11 @@ void Application::SetParameterInputImage(std::string parameter, InputImageParame OutputImageParameter::ImageBaseType * Application::GetParameterOutputImage(std::string parameter) { Parameter* param = GetParameterByKey(parameter); - + OutputImageParameter* paramDown = dynamic_cast<OutputImageParameter*> (param); - + if (paramDown) - { + { return paramDown->GetValue(); } else @@ -1204,7 +1203,7 @@ void Application::SetParameterComplexInputImage(std::string parameter, ComplexIn Parameter* param = GetParameterByKey(parameter); ComplexInputImageParameter* paramDown = dynamic_cast<ComplexInputImageParameter*> (param); - + if (paramDown) { paramDown->SetImage(inputImage); @@ -1218,11 +1217,11 @@ void Application::SetParameterComplexInputImage(std::string parameter, ComplexIn ComplexOutputImageParameter::ImageBaseType * Application::GetParameterComplexOutputImage(std::string parameter) { Parameter* param = GetParameterByKey(parameter); - + ComplexOutputImageParameter* paramDown = dynamic_cast<ComplexOutputImageParameter*> (param); - + if (paramDown) - { + { return paramDown->GetValue(); } else @@ -1234,9 +1233,9 @@ ComplexOutputImageParameter::ImageBaseType * Application::GetParameterComplexOut void Application::AddImageToParameterInputImageList(std::string parameter, InputImageListParameter::ImageBaseType * img) { Parameter* param = GetParameterByKey(parameter); - + InputImageListParameter * paramDown = dynamic_cast<InputImageListParameter *>(param); - + if(paramDown) { paramDown->AddImage(img); @@ -1245,7 +1244,7 @@ void Application::AddImageToParameterInputImageList(std::string parameter, Input { itkExceptionMacro(<<parameter << "parameter can't be casted to InputImageListParameter"); } - + } void Application::SetNthParameterInputImageList(std::string parameter, const unsigned int &id, InputImageListParameter::ImageBaseType * img) @@ -1268,9 +1267,9 @@ void Application::SetNthParameterInputImageList(std::string parameter, const uns void Application::AddParameterStringList(std::string parameter, const std::string & str) { Parameter* param = GetParameterByKey(parameter); - + InputImageListParameter * paramDown = dynamic_cast<InputImageListParameter *>(param); - + if(paramDown) { paramDown->AddFromFileName(str); @@ -1279,7 +1278,7 @@ void Application::AddParameterStringList(std::string parameter, const std::strin { itkExceptionMacro(<<parameter << "parameter can't be casted to InputImageListParameter"); } - + } void Application::SetNthParameterStringList(std::string parameter, const unsigned int &id, const std::string & str) @@ -1454,7 +1453,10 @@ std::string Application::GetParameterAsString(std::string paramKey) oss << this->GetParameterFloat( paramKey ); ret = oss.str(); } - else if( type == ParameterType_StringList ) + else if( type == ParameterType_StringList || + type == ParameterType_InputImageList || + type == ParameterType_InputVectorDataList || + type == ParameterType_InputFilenameList) { std::ostringstream oss; oss << std::setprecision(10); diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperComplexInputImageParameter.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperComplexInputImageParameter.cxx index df0ed51e820e95e9dc3cf19f87b6528d5dc2a1ff..6c59ad4c83753feeacf012655642eba680586279 100644 --- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperComplexInputImageParameter.cxx +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperComplexInputImageParameter.cxx @@ -52,27 +52,10 @@ ComplexInputImageParameter::SetFromFileName(const std::string& filename) // - Done in the reader // - allow appending additional information to the filename // myfile.tif:2 for example, or myfile.tif:nocarto - if (!filename.empty()) - { - ComplexFloatVectorReaderType::Pointer reader = ComplexFloatVectorReaderType::New(); - - try - { - reader->SetFileName(filename); - reader->UpdateOutputInformation(); - } - catch(itk::ExceptionObject & /*err*/) - { - return false; - } - - // the specified filename is valid => store the value - m_FileName = filename; - m_UseFilename = true; - SetActive(true); - return true; - } - return false; + m_FileName = filename; + m_UseFilename = true; + SetActive(true); + return true; } diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperComplexOutputImageParameter.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperComplexOutputImageParameter.cxx index ce11263ccd7cab428275ce32d374264afc12f85c..64ef3657181d767341ce804d642374d6ed7b6a27 100644 --- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperComplexOutputImageParameter.cxx +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperComplexOutputImageParameter.cxx @@ -73,6 +73,18 @@ ComplexOutputImageParameter::ConvertPixelTypeToString(ComplexImagePixelType type return ret; } +bool +ComplexOutputImageParameter::ConvertStringToPixelType(const std::string &value, ComplexImagePixelType &type) +{ + if (value == "cfloat") + type = ComplexImagePixelType_float; + else if (value == "cdouble") + type = ComplexImagePixelType_double; + else + return false; + return true; +} + void ComplexOutputImageParameter::InitializeWriters() { m_ComplexFloatWriter = ComplexFloatWriterType::New(); diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputFilenameListParameter.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputFilenameListParameter.cxx index e65e22078177f51cf6d8f85a188d68f4ac9f1416..72b5aa13caf22c3827c30c52722f46d7bffd733d 100644 --- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputFilenameListParameter.cxx +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputFilenameListParameter.cxx @@ -19,189 +19,110 @@ */ #include "otbWrapperInputFilenameListParameter.h" -#include "itksys/SystemTools.hxx" + namespace otb { + + namespace Wrapper { -InputFilenameListParameter::InputFilenameListParameter() -{ - this->SetName("Input Filename List"); - this->SetKey("inList"); - m_FilenameList = StringParameterListType::New(); -} -InputFilenameListParameter::~InputFilenameListParameter() -{ -} +const std::string FILENAME_FILTER( + "All files (*);;" + "CSV files (.csv);;" + "Text files (.txt);;" + "XML files (.xml)" +); + -bool -InputFilenameListParameter::SetListFromFileName(const std::vector<std::string> & filenames) +/*****************************************************************************/ +InputFilenameListParameter +::InputFilenameListParameter() { - // First clear previous file chosen - this->ClearValue(); - - for(unsigned int i=0; i<filenames.size(); i++) - { - std::string filename = filenames[i]; - // File existence checked by the reader - if (!filename.empty()) - { - StringParameter::Pointer strParameter = StringParameter::New(); - strParameter->SetValue(filename); - strParameter->HasValue(); - - // everything went fine, store the object reference - m_FilenameList->PushBack(strParameter); - } - } - - SetActive(true); - this->Modified(); - return true; + SetName( "Input Filename List" ); + SetKey( "inList" ); } -void -InputFilenameListParameter::AddNullElement() +/*****************************************************************************/ +InputFilenameListParameter +::~InputFilenameListParameter() { - m_FilenameList->PushBack(ITK_NULLPTR); - SetActive(false); - this->Modified(); } -bool -InputFilenameListParameter::AddFromFileName(const std::string & filename) -{ - // File existence checked by the reader - if (!filename.empty()) - { - StringParameter::Pointer strParameter = StringParameter::New(); - strParameter->SetValue(filename); - strParameter->HasValue(); - - // everything went fine, store the object references - m_FilenameList->PushBack(strParameter); - SetActive(true); - this->Modified(); - return true; - } - - return false; -} -bool -InputFilenameListParameter::SetNthFileName( const unsigned int id, const std::string & filename ) +/*****************************************************************************/ +Role +InputFilenameListParameter +::GetDirection( std::size_t ) const { - if( m_FilenameList->Size()<id ) - { - itkExceptionMacro(<< "No file "<<id<<". Only "<<m_FilenameList->Size()<<" filenames available."); - } - - // File existence checked by the reader - if (!filename.empty()) - { - StringParameter::Pointer strParameter = StringParameter::New(); - strParameter->SetValue(filename); - strParameter->HasValue(); - - m_FilenameList->SetNthElement(id, strParameter); - SetActive(true); - this->Modified(); - return true; - } - - return false; -} +#if 0 + assert( i<m_FilenameList->Size() ); + assert( !m_FilenameList->GetNthElement( i ).IsNull() ); + return m_FilenameList->GetNthElement( i )->GetRole(); -std::vector<std::string> -InputFilenameListParameter::GetFileNameList() const -{ - if (m_FilenameList) - { - std::vector<std::string> filenames; - for(unsigned int i=0; i<m_FilenameList->Size(); i++) - { - if( m_FilenameList->GetNthElement(i) ) - filenames.push_back( m_FilenameList->GetNthElement(i)->GetValue() ); - } - - return filenames; - } - - itkExceptionMacro(<< "No filename value"); +#else + // otb::Parameter::GetRole() does not necessarily stand for + // direction of parameter. + return GetDirection(); + +#endif } -std::string -InputFilenameListParameter::GetNthFileName( unsigned int i ) const +/*****************************************************************************/ +Role +InputFilenameListParameter +::GetDirection() const { - if (m_FilenameList) - { - if(m_FilenameList->Size()<i) - { - itkExceptionMacro(<< "No file "<<i<<". Only "<<m_FilenameList->Size()<<" filenames available."); - } - - return m_FilenameList->GetNthElement(i)->GetValue(); - } - - itkExceptionMacro(<< "No filename value"); + return Role_Input; } -InputFilenameListParameter::StringParameterListPointerType -InputFilenameListParameter::GetFileList() const +/*****************************************************************************/ +const std::string & +InputFilenameListParameter +::GetFilenameFilter( std::size_t ) const { - return m_FilenameList; + return GetFilenameFilter(); } -bool -InputFilenameListParameter::HasValue() const + +/*****************************************************************************/ +const std::string & +InputFilenameListParameter +::GetFilenameFilter() const { - if(m_FilenameList->Size() == 0) - { - return false; - } - - bool res(true); - unsigned int i(0); - while(i < m_FilenameList->Size() && res == true) - { - res = m_FilenameList->GetNthElement(i).IsNotNull(); - i++; - } - - return res; + return FILENAME_FILTER; } -void -InputFilenameListParameter::Erase( unsigned int id ) +/*****************************************************************************/ +const std::string & +InputFilenameListParameter +::ToString( const ParameterType::Pointer & p ) const { - if(m_FilenameList->Size()<id) - { - itkExceptionMacro(<< "No file "<<id<<". Only "<<m_FilenameList->Size()<<" filenames available."); - } + assert( !p.IsNull() ); - m_FilenameList->Erase( id ); - - this->Modified(); + return p->GetValue(); } -void -InputFilenameListParameter::ClearValue() +/*****************************************************************************/ +const InputFilenameListParameter::ParameterType::Pointer & +InputFilenameListParameter +::FromString( const ParameterType::Pointer & p, + const std::string & s ) const { - m_FilenameList->Clear(); - - SetActive(false); - this->Modified(); -} + assert( !p.IsNull() ); + p->SetValue( s ); + return p; } + } +} diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputImageListParameter.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputImageListParameter.cxx index 01c31e196abfc40267f0291f703fe4db20ed0c52..4bb5f6159a6af26f09040a54d0ecfe0d604fa7c0 100644 --- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputImageListParameter.cxx +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputImageListParameter.cxx @@ -19,280 +19,235 @@ */ #include "otbWrapperInputImageListParameter.h" -#include "itksys/SystemTools.hxx" + + +#include "otbCast.h" + namespace otb { + namespace Wrapper { -InputImageListParameter::InputImageListParameter() - : m_InputImageParameterVector(), - m_ImageList(FloatVectorImageListType::New()) -{ - this->SetName("Input Image List"); - this->SetKey("inList"); -} -InputImageListParameter::~InputImageListParameter() -{ -} +const std::string +IMAGES_FILTER( + "All files (*);;" + "TIFF file (*tif);;" + "PNG File (*.png);;" + "JPEG File (*.jpg)" +); + -bool -InputImageListParameter::SetListFromFileName(const std::vector<std::string> & filenames) +/*****************************************************************************/ +InputImageParameter::Pointer +InputImageListParameter +::FromImage( ImageBaseType * image ) { - // First clear previous file chosen - this->ClearValue(); + assert( image!=nullptr ); - for(unsigned int i=0; i<filenames.size(); i++) - { - const std::string filename = filenames[i]; + InputImageParameter::Pointer p; - // File existence checked by the reader - if (!filename.empty()) - { - // Try to build a new ParameterInputImage - InputImageParameter::Pointer tmpInputImageParameter = InputImageParameter::New(); - tmpInputImageParameter->SetFromFileName(filename); + return FromImage( p, image ); +} - m_InputImageParameterVector.push_back(tmpInputImageParameter); - } - } +/*****************************************************************************/ +InputImageParameter::Pointer & +InputImageListParameter +::FromImage( InputImageParameter::Pointer & parameter, + ImageBaseType * image ) +{ + return + FromData( + parameter, + image, + []( auto p, auto i ) -> void + { + assert( p ); - this->Modified(); - SetActive(true); - return true; + p->SetImage( i ); + }, + "Image filename" + ); } -void -InputImageListParameter::AddNullElement() +/*****************************************************************************/ +InputImageListParameter +::InputImageListParameter() : + m_ImageList( FloatVectorImageListType::New() ) { - m_InputImageParameterVector.push_back(ITK_NULLPTR); - SetActive(false); - this->Modified(); + SetName( "Input Image List" ); + SetKey( "inList" ); } -bool -InputImageListParameter::AddFromFileName(const std::string & filename) -{ - // File existence checked by the reader - if (!filename.empty()) - { - InputImageParameter::Pointer tmpInputImageParameter = InputImageParameter::New(); - tmpInputImageParameter->SetFromFileName(filename); - - m_InputImageParameterVector.push_back(tmpInputImageParameter); - - this->Modified(); - SetActive(true); - return true; - } - return false; +/*****************************************************************************/ +InputImageListParameter +::~InputImageListParameter() +{ } -bool -InputImageListParameter::SetNthFileName( const unsigned int id, const std::string & filename ) +/*****************************************************************************/ +const FloatVectorImageListType * +InputImageListParameter +::GetImageList() const { - if( m_InputImageParameterVector.size()<id ) - { - itkExceptionMacro(<< "No image "<<id<<". Only "<<m_InputImageParameterVector.size()<<" images available."); - } - - // File existence checked by the reader - if (!filename.empty()) - { - InputImageParameter::Pointer tmpInputImageParameter = InputImageParameter::New(); - tmpInputImageParameter->SetFromFileName(filename); - - m_InputImageParameterVector[id] = tmpInputImageParameter; - - this->Modified(); - SetActive(true); - return true; - } - - return false; + return const_cast< InputImageListParameter * >( this )->GetImageList(); } -std::vector<std::string> -InputImageListParameter::GetFileNameList() const +/*****************************************************************************/ +FloatVectorImageListType * +InputImageListParameter +::GetImageList() { - std::vector<std::string> filenames; - - for(InputImageParameterVectorType::const_iterator it = m_InputImageParameterVector.begin(); - it!=m_InputImageParameterVector.end();++it) - { - if(it->IsNull()) + return + GetObjectList( + m_ImageList, + []( auto param ) -> auto { - itkExceptionMacro(<< "Empty image in InputImageListParameter."); - } - filenames.push_back( (*it)->GetFileName() ); - } + assert( param ); - return filenames; + return param->GetFloatVectorImage(); + } + ); } -std::string -InputImageListParameter::GetNthFileName( unsigned int i ) const +/*****************************************************************************/ +const FloatVectorImageType * +InputImageListParameter +::GetNthImage( std::size_t i ) const { - if(m_InputImageParameterVector.size()<i) - { - itkExceptionMacro(<< "No image "<<i<<". Only "<<m_InputImageParameterVector.size()<<" images available."); - } - if(m_InputImageParameterVector[i].IsNull()) - { - itkExceptionMacro(<< "Requested image "<<i<<" has no filename"); - } - return m_InputImageParameterVector[i]->GetFileName(); + return const_cast< InputImageListParameter * >( this )->GetNthImage( i ); } -FloatVectorImageListType* -InputImageListParameter::GetImageList() const -{ - m_ImageList->Clear(); - for (unsigned int i=0 ; i < this->Size() ; ++i) - { - if(m_InputImageParameterVector[i].IsNull()) - { - itkExceptionMacro(<< "Image "<<i<<" is empty."); - } - m_ImageList->PushBack(m_InputImageParameterVector[i]->GetFloatVectorImage()); - } - return m_ImageList; -} -FloatVectorImageType* -InputImageListParameter::GetNthImage(unsigned int i) const +/*****************************************************************************/ +FloatVectorImageType * +InputImageListParameter::GetNthImage( std::size_t i ) { - if(this->Size()<=i) - { - itkExceptionMacro(<< "No image "<<i<<". Only "<<this->Size()<<" images available."); - } - if(m_InputImageParameterVector[i].IsNull()) - { - itkExceptionMacro(<< "Image "<<i<<" is empty."); - } - return m_InputImageParameterVector[i]->GetFloatVectorImage(); + assert( i<Size() ); + assert( !m_Parameters[ i ].IsNull() ); + assert( m_Parameters[ i ]->GetFloatVectorImage()!=nullptr ); + + return m_Parameters[ i ]->GetFloatVectorImage(); } +/*****************************************************************************/ void -InputImageListParameter::SetImageList(FloatVectorImageListType* imList) +InputImageListParameter +::SetImageList( FloatVectorImageListType * imList ) { - // Check input availability - for(unsigned int i = 0; i < imList->Size(); i++) - { - imList->GetNthElement(i)->UpdateOutputInformation(); - } + assert( imList!=nullptr ); + assert( !m_ImageList.IsNull() ); - // Clear previous values - this->ClearValue(); - - for(unsigned int i = 0; i<imList->Size(); i++) + SetObjectList( + *m_ImageList, + *imList, + [ this ]( auto p, auto image ) -> auto { - // Try to build a new ParameterInputImage - InputImageParameter::Pointer tmpInputImageParameter = InputImageParameter::New(); - - tmpInputImageParameter->SetImage(imList->GetNthElement(i)); + this->FromImage( p, image ); + }, + // + []( auto p ) -> auto + { + assert( p ); - m_InputImageParameterVector.push_back(tmpInputImageParameter); - m_ImageList->PushBack(tmpInputImageParameter->GetFloatVectorImage()); + return p->GetFloatVectorImage(); } - - SetActive(true); - this->Modified(); + ); } -void InputImageListParameter::SetNthImage(unsigned int i, ImageBaseType * img) + +/*****************************************************************************/ +void +InputImageListParameter +::SetNthImage( std::size_t i, ImageBaseType * image ) { - if(this->Size()<i) - { - itkExceptionMacro(<< "No image "<<i<<". Only "<<this->Size()<<" images available."); - } + assert( i<Size() ); + assert( image!=nullptr ); // Check input availability - img->UpdateOutputInformation(); - - // Try to build a new ParameterInputImage - InputImageParameter::Pointer tmpInputImageParameter = InputImageParameter::New(); - - tmpInputImageParameter->SetImage(img); + image->UpdateOutputInformation(); - m_InputImageParameterVector[i] = tmpInputImageParameter; + // Build parameter. + FromImage( m_Parameters[ i ], image ); } +/*****************************************************************************/ void -InputImageListParameter::AddImage(ImageBaseType* image) +InputImageListParameter +::AddImage( ImageBaseType * image ) { - // Check input availability - image->UpdateOutputInformation(); + AddData( + image, + [ this ]( auto i ) -> auto + { + return this->FromImage( i ); + } + ); +} - InputImageParameter::Pointer tmpInputImageParameter = InputImageParameter::New(); - tmpInputImageParameter->SetImage(image); +/*****************************************************************************/ +void +InputImageListParameter +::ClearValue() +{ + Superclass::ClearValue(); - m_InputImageParameterVector.push_back(tmpInputImageParameter); + assert( m_ImageList ); - this->Modified(); + m_ImageList->Clear(); } -bool -InputImageListParameter::HasValue() const + +/*****************************************************************************/ +Role +InputImageListParameter +::GetDirection() const { - if(this->Size() == 0) - { - return false; - } + return Role_Input; +} - bool res(true); - unsigned int i(0); - while(i < this->Size() && res == true) - { - res = (m_InputImageParameterVector[i] ? - m_InputImageParameterVector[i]->HasValue() : - false); - i++; - } - return res; +/*****************************************************************************/ +const std::string & +InputImageListParameter +::GetFilenameFilter() const +{ + return IMAGES_FILTER; } -void -InputImageListParameter::Erase( unsigned int id ) +/*****************************************************************************/ +const std::string & +InputImageListParameter +::ToString( const ParameterType::Pointer & p ) const { - if(this->Size()<id) - { - itkExceptionMacro(<< "No image "<<id<<". Only "<<this->Size()<<" images available."); - } + assert( !p.IsNull() ); - m_InputImageParameterVector.erase(m_InputImageParameterVector.begin()+id); - - this->Modified(); + return p->GetFileName(); } -unsigned int -InputImageListParameter::Size() const +/*****************************************************************************/ +const InputImageListParameter::ParameterType::Pointer & +InputImageListParameter +::FromString( const ParameterType::Pointer & p, + const std::string & s ) const { - return m_InputImageParameterVector.size(); -} + assert( !p.IsNull() ); + p->SetFromFileName( s ); -void -InputImageListParameter::ClearValue() -{ - m_ImageList->Clear(); - m_InputImageParameterVector.clear(); - - SetActive(false); - this->Modified(); + return p; } } -} +} diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputImageParameter.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputImageParameter.cxx index 08c0e1c36249954b7a18c58fd253f7df9d0d1b67..166ab2956ad5fc46a6bd1df6a1298e3066b4f23f 100644 --- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputImageParameter.cxx +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputImageParameter.cxx @@ -26,6 +26,7 @@ namespace otb { + namespace Wrapper { @@ -55,7 +56,8 @@ InputImageParameter::SetFromFileName(const std::string& filename) // myfile.tif:2 for example, or myfile.tif:nocarto m_FileName = filename; m_UseFilename = true; - SetActive(true); + SetActive( true ); + return true; } @@ -88,14 +90,15 @@ InputImageParameter::HasValue() const } void -InputImageParameter::ClearValue() +InputImageParameter +::ClearValue() { - m_Image = ITK_NULLPTR; - m_Reader = ITK_NULLPTR; - m_Caster = ITK_NULLPTR; - m_FileName = ""; - m_PreviousFileName=""; - m_UseFilename = true; + m_Image = ITK_NULLPTR; + m_Reader = ITK_NULLPTR; + m_Caster = ITK_NULLPTR; + m_FileName = ""; + m_PreviousFileName=""; + m_UseFilename = true; } } diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputProcessXMLParameter.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputProcessXMLParameter.cxx index 8bfd04bbf50c86e349b732c8ec624774a1e79551..938936ebf64784d0287e9d5e4be25701e2c2c738 100644 --- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputProcessXMLParameter.cxx +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputProcessXMLParameter.cxx @@ -384,7 +384,6 @@ InputProcessXMLParameter::Read(Application::Pointer this_) if(itksys::SystemTools::FileExists(value.c_str())) { InputVectorDataParameter* paramDown = dynamic_cast<InputVectorDataParameter*>(param); - paramDown->SetFromFileName(value); if ( !paramDown->SetFromFileName(value) ) { ret = -1; @@ -395,28 +394,16 @@ InputProcessXMLParameter::Read(Application::Pointer this_) { InputImageListParameter* paramDown = dynamic_cast<InputImageListParameter*>(param); paramDown->SetListFromFileName(values); - if ( !paramDown->SetListFromFileName(values) ) - { - ret = -1; - } } else if (dynamic_cast<InputVectorDataListParameter*>(param)) { InputVectorDataListParameter* paramDown = dynamic_cast<InputVectorDataListParameter*>(param); - paramDown->SetListFromFileName(values); - if ( !paramDown->SetListFromFileName(values) ) - { - ret = -1; - } + paramDown->SetListFromFileName( values ); } else if (dynamic_cast<InputFilenameListParameter*>(param)) { InputFilenameListParameter* paramDown = dynamic_cast<InputFilenameListParameter*>(param); - paramDown->SetListFromFileName(values); - if ( !paramDown->SetListFromFileName(values) ) - { - ret= -1; - } + paramDown->SetListFromFileName( values ); } else if (type == ParameterType_Radius || type == ParameterType_Int || typeAsString == "rand" ) diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputVectorDataListParameter.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputVectorDataListParameter.cxx index 8b40c1e13ae77c4974542986b65f51bb2bac2fe6..3b21c919327b2b75ae04c2d9073fab0b0c595125 100644 --- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputVectorDataListParameter.cxx +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputVectorDataListParameter.cxx @@ -19,291 +19,201 @@ */ #include "otbWrapperInputVectorDataListParameter.h" -#include "itksys/SystemTools.hxx" -#include "otbWrapperMacros.h" namespace otb { -namespace Wrapper -{ -InputVectorDataListParameter::InputVectorDataListParameter() -{ - this->SetName("Input VectorData List"); - this->SetKey("vdList"); - m_VectorDataList = VectorDataListType::New(); - m_ReaderList = VectorDataFileReaderListType::New(); -} -InputVectorDataListParameter::~InputVectorDataListParameter() +namespace Wrapper { -} -bool -InputVectorDataListParameter::SetListFromFileName(const std::vector<std::string> & filenames) -{ - // First clear previous file chosen - this->ClearValue(); - bool isOk = true; - for(unsigned int i=0; i<filenames.size(); i++) - { - const std::string filename = filenames[i]; - // TODO : when the logger will be available, redirect the exception - // in the logger (like what is done in MsgReporter) - if (!filename.empty()) - { - VectorDataFileReaderType::Pointer reader = VectorDataFileReaderType::New(); - try - { - reader->SetFileName(filename); - reader->UpdateOutputInformation(); - } - catch(itk::ExceptionObject & /*err*/) - { - this->ClearValue(); - isOk = false; - break; - } - - // everything went fine, store the object references - m_ReaderList->PushBack(reader); - m_VectorDataList->PushBack(reader->GetOutput()); - } - } +const std::string +VECTOR_DATA_FILTER( + "All files (*);;" + "Shape file (*shp)" +); - if( !isOk ) - { - return false; - } - SetActive(true); - this->Modified(); - return true; -} +/*****************************************************************************/ +InputVectorDataParameter::Pointer +InputVectorDataListParameter +::FromVectorData( VectorDataType * data ) +{ + assert( data!=nullptr ); + InputVectorDataParameter::Pointer p; -void -InputVectorDataListParameter::AddNullElement() -{ - m_ReaderList->PushBack(ITK_NULLPTR); - m_VectorDataList->PushBack(ITK_NULLPTR); - SetActive(false); - this->Modified(); + return FromVectorData( p, data ); } -bool -InputVectorDataListParameter::AddFromFileName(const std::string & filename) +/*****************************************************************************/ +InputVectorDataParameter::Pointer & +InputVectorDataListParameter +::FromVectorData( InputVectorDataParameter::Pointer & parameter, + VectorDataType * data ) { - // TODO : when the logger will be available, redirect the exception - // in the logger (like what is done in MsgReporter) - if (!filename.empty()) - { - VectorDataFileReaderType::Pointer reader = VectorDataFileReaderType::New(); - reader->SetFileName(filename); - try + return + FromData( + parameter, + data, + []( auto p, auto d ) -> void { - reader->UpdateOutputInformation(); - } - catch(itk::ExceptionObject & /*err*/) - { - this->ClearValue(); - return false; - } + assert( p ); - // everything went fine, store the object references - m_ReaderList->PushBack(reader); - m_VectorDataList->PushBack(reader->GetOutput()); - SetActive(true); - this->Modified(); - return true; - } - - return false; + p->SetVectorData( d ); + }, + "Vector-data filename" + ); } -bool -InputVectorDataListParameter::SetNthFileName( const unsigned int id, const std::string & filename ) +/*****************************************************************************/ +InputVectorDataListParameter +::InputVectorDataListParameter() : + m_VectorDataList( VectorDataListType::New() ) { - if( m_ReaderList->Size()<id ) - { - itkExceptionMacro(<< "No vectordata "<<id<<". Only "<<m_ReaderList->Size()<<" vector data available."); - } - - // TODO : when the logger will be available, redirect the exception - // in the logger (like what is done in MsgReporter) - if (!filename.empty()) - { - VectorDataFileReaderType::Pointer reader = VectorDataFileReaderType::New(); - reader->SetFileName(filename); - try - { - reader->UpdateOutputInformation(); - } - catch(itk::ExceptionObject &) - { - this->ClearValue(); - return false; - } - - m_ReaderList->SetNthElement(id, reader); - m_VectorDataList->SetNthElement(id, reader->GetOutput()); - - this->Modified(); - return true; - } - - return false; + SetName( "Input VectorData List" ); + SetKey( "vdList" ); } - -std::vector<std::string> -InputVectorDataListParameter::GetFileNameList() const +/*****************************************************************************/ +InputVectorDataListParameter +::~InputVectorDataListParameter() { - if (m_ReaderList) - { - std::vector<std::string> filenames; - for(unsigned int i=0; i<m_ReaderList->Size(); i++) - { - if( m_ReaderList->GetNthElement(i) ) - filenames.push_back( m_ReaderList->GetNthElement(i)->GetFileName() ); - } - - return filenames; - } - - itkExceptionMacro(<< "No filename value"); } +/*****************************************************************************/ +const VectorDataListType * +InputVectorDataListParameter +::GetVectorDataList() const +{ + return + const_cast< InputVectorDataListParameter * >( this ) + ->GetVectorDataList(); +} -std::string -InputVectorDataListParameter::GetNthFileName( unsigned int i ) const +/*****************************************************************************/ +VectorDataListType * +InputVectorDataListParameter +::GetVectorDataList() { - if (m_ReaderList) - { - if(m_ReaderList->Size()<i) + return + GetObjectList( + m_VectorDataList, + []( auto param ) -> auto { - itkExceptionMacro(<< "No vector data "<<i<<". Only "<<m_ReaderList->Size()<<" vector data available."); - } + assert( param ); - return m_ReaderList->GetNthElement(i)->GetFileName(); - } - - itkExceptionMacro(<< "No filename value"); + return param->GetVectorData(); + } + ); } -VectorDataListType* -InputVectorDataListParameter::GetVectorDataList() const +/*****************************************************************************/ +const VectorDataType * +InputVectorDataListParameter +::GetNthVectorData( std::size_t i ) { - return m_VectorDataList; -} + assert( i<m_Parameters.size() ); + assert( !m_Parameters[ i ].IsNull() ); + assert( m_Parameters[ i ]->GetVectorData()!=nullptr ); -VectorDataType* -InputVectorDataListParameter::GetNthVectorData(unsigned int i) const -{ - if(m_VectorDataList->Size()<i) - { - itkExceptionMacro(<< "No vector data "<<i<<". Only "<<m_VectorDataList->Size()<<" vector data available."); - } - return m_VectorDataList->GetNthElement(i); + return m_Parameters[ i ]->GetVectorData(); } +/*****************************************************************************/ void -InputVectorDataListParameter::SetVectorDataList(VectorDataListType* vdList) +InputVectorDataListParameter +::SetVectorDataList( VectorDataListType * vdList ) { - // Check input availability - // TODO : when the logger will be available, redirect the exception - // in the logger (like what is done in MsgReporter) - try + assert( vdList!=nullptr ); + assert( !m_VectorDataList.IsNull() ); + + SetObjectList( + *m_VectorDataList, + *vdList, + // + [ this ]( auto p, auto vd ) -> auto { - for(unsigned int i=0; i<vdList->Size(); i++) - { - vdList->GetNthElement( i )->UpdateOutputInformation(); - } - } - catch(itk::ExceptionObject &) + this->FromVectorData( p, vd ); + }, + // + []( auto p ) -> auto { - return; - } + assert( p ); - m_VectorDataList = vdList; - m_ReaderList = VectorDataFileReaderListType::Pointer(); - for(unsigned int i=0; i<m_VectorDataList->Size(); i++) - { - m_ReaderList->PushBack( VectorDataFileReaderType::Pointer() ); + return p->GetVectorData(); } - - SetActive(true); - this->Modified(); + ); } +/*****************************************************************************/ void -InputVectorDataListParameter::AddVectorData(VectorDataType* vectorData) +InputVectorDataListParameter +::AddVectorData( VectorDataType * vectorData ) { - // Check input availability - // TODO : when the logger will be available, redirect the exception - // in the logger (like what is done in MsgReporter) - try - { - vectorData->UpdateOutputInformation(); - } - catch(itk::ExceptionObject &) + AddData( + vectorData, + [ this ]( auto d ) -> auto { - return; + return this->FromVectorData( d ); } - - m_VectorDataList->PushBack( vectorData ); - m_ReaderList->PushBack( VectorDataFileReaderType::Pointer() ); - - this->Modified(); + ); } -bool -InputVectorDataListParameter::HasValue() const +/*****************************************************************************/ +void +InputVectorDataListParameter +::ClearValue() { - if (m_VectorDataList->Size() == 0) - { - return false; - } + Superclass::ClearValue(); - bool res(true); - unsigned int i(0); - while (i < m_VectorDataList->Size() && res == true) - { - res = m_VectorDataList->GetNthElement(i).IsNotNull(); - i++; - } + assert( m_VectorDataList ); - return res; + m_VectorDataList->Clear(); } +/*****************************************************************************/ +Role +InputVectorDataListParameter +::GetDirection() const +{ + return Role_Input; +} -void -InputVectorDataListParameter::Erase( unsigned int id ) +/*****************************************************************************/ +const std::string & +InputVectorDataListParameter +::GetFilenameFilter() const { - if(m_VectorDataList->Size()<id) - { - itkExceptionMacro(<< "No vector data "<<id<<". Only "<<m_VectorDataList->Size()<<" vector data available."); - } + return VECTOR_DATA_FILTER; +} - m_VectorDataList->Erase( id ); - m_ReaderList->Erase( id ); +/*****************************************************************************/ +const std::string & +InputVectorDataListParameter +::ToString( const ParameterType::Pointer & p ) const +{ + assert( !p.IsNull() ); - this->Modified(); + return p->GetFileName(); } -void -InputVectorDataListParameter::ClearValue() +/*****************************************************************************/ +const InputVectorDataListParameter::ParameterType::Pointer & +InputVectorDataListParameter +::FromString( const ParameterType::Pointer & p, + const std::string & s ) const { - m_VectorDataList->Clear(); - m_ReaderList->Clear(); + assert( !p.IsNull() ); + + p->SetFromFileName( s ); - SetActive(false); - this->Modified(); + return p; } } -} +} diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputVectorDataParameter.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputVectorDataParameter.cxx index ee3b2559136860c5a35acd8ce28d2e370b9b49a5..f60cf29078bf0c487c35b90ed0c94f9fcee1800d 100644 --- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputVectorDataParameter.cxx +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputVectorDataParameter.cxx @@ -43,53 +43,37 @@ InputVectorDataParameter::SetFromFileName(const std::string& filename) // First clear previous file chosen 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(); - try - { - reader->SetFileName(filename); - reader->UpdateOutputInformation(); - } - catch(itk::ExceptionObject & /*err*/) - { - return false; - } + // No file existence is done here : + m_FileName = filename; + SetActive( true ); - // the specified filename is valid => store the value - m_FileName = filename; - SetActive(true); - return true; - } - return false; + return true; } -VectorDataType* +const VectorDataType * +InputVectorDataParameter +::GetVectorData() const +{ + return const_cast< InputVectorDataParameter * >( this )->GetVectorData(); +} + +VectorDataType * InputVectorDataParameter::GetVectorData() { // 2 cases : the user sets a filename vs. the user sets a vector data //////////////////////// Filename case: - if (!m_FileName.empty()) + if (!m_FileName.empty() && m_PreviousFileName!=m_FileName) { - //typedef otb::ImageFileReader<TOutputImage> ReaderType; - //typename ReaderType::Pointer reader = ReaderType::New(); - m_Reader = VectorDataFileReaderType::New(); - m_Reader->SetFileName(m_FileName); - try - { - // Update the viewer here to load the file => no streaming for VectorData - m_Reader->Update(); - } - catch (itk::ExceptionObject &) - { - this->ClearValue(); - } + VectorDataFileReaderType::Pointer reader = VectorDataFileReaderType::New(); + reader->SetFileName(m_FileName); + // Update the viewer here to load the file => no streaming for VectorData + reader->Update(); + + m_VectorData = reader->GetOutput(); + m_Reader = reader; - m_VectorData = m_Reader->GetOutput(); + m_PreviousFileName = m_FileName; } //////////////////////// VectorData case: else @@ -97,7 +81,7 @@ InputVectorDataParameter::GetVectorData() if (m_VectorData.IsNull()) { // Else : error - itkExceptionMacro("No input vector data or filename detected..."); + itkExceptionMacro("No input vector data detected..."); } } @@ -131,5 +115,3 @@ InputVectorDataParameter::ClearValue() } } - - diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperOutputImageParameter.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperOutputImageParameter.cxx index b2f2d8d5523d00adb29e556c0ca4d811b5902d43..2790bdce255aa5d0e8a3f92ab625e274ce48bf10 100644 --- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperOutputImageParameter.cxx +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperOutputImageParameter.cxx @@ -98,6 +98,28 @@ std::string OutputImageParameter::ConvertPixelTypeToString(ImagePixelType type) return ret; } +bool +OutputImageParameter::ConvertStringToPixelType(const std::string &value, ImagePixelType &type) +{ + if (value == "uint8") + type = ImagePixelType_uint8; + else if (value == "int16") + type = ImagePixelType_int16; + else if (value == "uint16") + type = ImagePixelType_uint16; + else if (value == "int32") + type = ImagePixelType_int32; + else if (value == "uint32") + type = ImagePixelType_uint32; + else if (value == "float") + type = ImagePixelType_float; + else if (value == "double") + type = ImagePixelType_double; + else + return false; + return true; +} + void OutputImageParameter::InitializeWriters() { m_UInt8Writer = UInt8WriterType::New(); diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperParameterList.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperParameterList.cxx new file mode 100644 index 0000000000000000000000000000000000000000..272f1faed2932f63b79ed56628ecba0b9ceb3552 --- /dev/null +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperParameterList.cxx @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2005-2017 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 "otbWrapperParameterList.h" + + +namespace otb +{ + + +namespace Wrapper +{ + + +} // End of namespace 'Wrapper' + + +} // End of namespace 'otb' diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperStringListInterface.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperStringListInterface.cxx new file mode 100644 index 0000000000000000000000000000000000000000..3f8175ef55aa7aec9aa5a3fb521a1495df337748 --- /dev/null +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperStringListInterface.cxx @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2005-2017 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 "otbWrapperStringListInterface.h" + + +namespace otb +{ + + +namespace Wrapper +{ + +const std::string +NULL_STRING; + + +/*****************************************************************************/ +void +StringListInterface +::AddNullElement() +{ + InsertNullElement(); +} + + +/*****************************************************************************/ +Role +StringListInterface +::GetDirection( std::size_t ) const +{ + return GetDirection(); +} + + +/*****************************************************************************/ +const std::string & +StringListInterface +::GetFilenameFilter( std::size_t ) const +{ + return GetFilenameFilter(); +} + + +/*****************************************************************************/ +const std::string & +StringListInterface +::GetFilenameFilter() const +{ + return NULL_STRING; +} + +/*****************************************************************************/ +bool +StringListInterface +::IsFilename() const +{ + return true; +} + +/*****************************************************************************/ +void +StringListInterface +::Erase( std::size_t id ) +{ + Erase( id, 1 ); +} + +/*****************************************************************************/ +std::size_t +StringListInterface +::SetStrings( const StringVector & ) +{ + return 0; +} + +/*****************************************************************************/ +std::size_t +StringListInterface +::GetStrings( StringVector & ) const +{ + return 0; +} + +} // End of Namespace 'Wrapper' + +} // End of Namespace 'otb' diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperStringListParameter.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperStringListParameter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..c880f2fa3ec094f7d9e1317a6d8fc26727162a15 --- /dev/null +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperStringListParameter.cxx @@ -0,0 +1,133 @@ +/* + * Copyright (C) 2005-2017 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 "otbWrapperStringListParameter.h" + + +#include "otbCast.h" + + +namespace otb +{ + +namespace Wrapper +{ + + +/*****************************************************************************/ +StringListParameter +::StringListParameter() +{ + SetName( "String List" ); + SetKey( "strList" ); +} + + +/*****************************************************************************/ +StringListParameter +::~StringListParameter() +{ +} + + +/*****************************************************************************/ +void +StringListParameter +::SetValue( const StringListInterface::StringVector & strings ) +{ + SetStrings( strings ); +} + +/*****************************************************************************/ +StringListInterface::StringVector +StringListParameter +::GetValue() const +{ + // Should get benefit of C++11 move constructor. + return GetFileNameList(); +} + +/*****************************************************************************/ +void +StringListParameter +::AddString( const std::string & s ) +{ + AddFromFileName( s ); +} + +/*****************************************************************************/ +const std::string & +StringListParameter +::GetNthElement( std::size_t i ) const +{ + return GetNthFileName( i ); +} + +/*****************************************************************************/ +void +StringListParameter +::SetNthElement( std::size_t i, const std::string & string ) +{ + SetNthFileName( i, string ); +} + +/*****************************************************************************/ +Role +StringListParameter +::GetDirection() const +{ + return GetRole(); +} + +/*****************************************************************************/ +bool +StringListParameter +::IsFilename() const +{ + return false; +} + +/*****************************************************************************/ +const std::string & +StringListParameter +::ToString( const ParameterType::Pointer & p ) const +{ + assert( !p.IsNull() ); + + return p->GetValue(); +} + +/*****************************************************************************/ +const StringListParameter::ParameterType::Pointer & +StringListParameter +::FromString( const ParameterType::Pointer & p, + const std::string & s ) const +{ + assert( !p.IsNull() ); + + p->SetValue( s ); + + return p; +} + + +} + +} diff --git a/Modules/Wrappers/ApplicationEngine/test/CMakeLists.txt b/Modules/Wrappers/ApplicationEngine/test/CMakeLists.txt index 0a5bd88dca87fd13c7adcc9c79c64d45b389eae0..860c8673636aff84ee7d5ae5f26c9c5ab0bc733d 100644 --- a/Modules/Wrappers/ApplicationEngine/test/CMakeLists.txt +++ b/Modules/Wrappers/ApplicationEngine/test/CMakeLists.txt @@ -23,7 +23,6 @@ otb_module_test() set(OTBApplicationEngineTests otbApplicationEngineTestDriver.cxx otbWrapperApplicationTest.cxx -otbWrapperParameterTest.cxx otbWrapperInputImageParameterTest.cxx otbWrapperNumericalParameterTest.cxx otbWrapperStringParameterTest.cxx @@ -54,15 +53,6 @@ otb_add_test(NAME owTuApplication COMMAND otbApplicationEngineTestDriver otbWrapperApplicationNew ) -otb_add_test(NAME owTvParameter COMMAND otbApplicationEngineTestDriver - otbWrapperParameterTest1 - "param1" - ) - -otb_add_test(NAME owTuParameterNew COMMAND otbApplicationEngineTestDriver - otbWrapperParameterNew - ) - otb_add_test(NAME owTvInputImageParameter COMMAND otbApplicationEngineTestDriver otbWrapperInputImageParameterTest1 ${INPUTDATA}/poupees.tif diff --git a/Modules/Wrappers/ApplicationEngine/test/otbApplicationEngineTestDriver.cxx b/Modules/Wrappers/ApplicationEngine/test/otbApplicationEngineTestDriver.cxx index f5db2967c0e9df41d8c910d8ff553962a07f7131..f5b3aabf3d5b4642044293927422883c491198f1 100644 --- a/Modules/Wrappers/ApplicationEngine/test/otbApplicationEngineTestDriver.cxx +++ b/Modules/Wrappers/ApplicationEngine/test/otbApplicationEngineTestDriver.cxx @@ -23,8 +23,6 @@ void RegisterTests() { REGISTER_TEST(otbWrapperApplicationNew); - REGISTER_TEST(otbWrapperParameterNew); - REGISTER_TEST(otbWrapperParameterTest1); REGISTER_TEST(otbWrapperInputImageParameterNew); REGISTER_TEST(otbWrapperInputImageParameterTest1); REGISTER_TEST(otbWrapperNumericalParameterNew); diff --git a/Modules/Wrappers/CommandLine/src/otbWrapperCommandLineLauncher.cxx b/Modules/Wrappers/CommandLine/src/otbWrapperCommandLineLauncher.cxx index 5d57a8337e73ee2298f313f08c13dc9f2ec5258f..fc529ef9e1bd713d380c9766ba1189ace1af51f5 100644 --- a/Modules/Wrappers/CommandLine/src/otbWrapperCommandLineLauncher.cxx +++ b/Modules/Wrappers/CommandLine/src/otbWrapperCommandLineLauncher.cxx @@ -390,7 +390,6 @@ CommandLineLauncher::ParamResultType CommandLineLauncher::LoadParameters() const std::string paramKey(appKeyList[i]); std::vector<std::string> values; - Parameter::Pointer param = m_Application->GetParameterByKey(paramKey); ParameterType type = m_Application->GetParameterType(paramKey); const bool paramExists(m_Parser->IsAttributExists(std::string("-").append(paramKey), m_VExpression)); @@ -412,166 +411,99 @@ CommandLineLauncher::ParamResultType CommandLineLauncher::LoadParameters() return INVALIDNUMBEROFVALUE; } - // Ensure that the parameter is enabled - m_Application->EnableParameter(paramKey); - - if (type == ParameterType_InputVectorDataList) + if (type == ParameterType_InputVectorDataList || + type == ParameterType_InputImageList || + type == ParameterType_InputFilenameList || + type == ParameterType_StringList || + type == ParameterType_ListView) { - dynamic_cast<InputVectorDataListParameter *> (param.GetPointer())->SetListFromFileName(values); + // Multiple values parameters + m_Application->SetParameterStringList(paramKey, values); } - else - if (type == ParameterType_InputImageList) - { - dynamic_cast<InputImageListParameter *> (param.GetPointer())->SetListFromFileName(values); - } - else - if (type == ParameterType_InputFilenameList) - { - dynamic_cast<InputFilenameListParameter *> (param.GetPointer())->SetListFromFileName(values); - } - else - if (type == ParameterType_StringList) - { - dynamic_cast<StringListParameter *> (param.GetPointer())->SetValue(values); - } - else - if (type == ParameterType_String) - { - dynamic_cast<StringParameter *> (param.GetPointer())->SetValue( - m_Parser->GetAttributAsString(std::string("-").append(paramKey), m_VExpression) ); - } - else - if (type == ParameterType_OutputImage) - { - m_Application->SetParameterString(paramKey, values[0]); - // Check if pixel type is given - if (values.size() == 2) - { - ImagePixelType outPixType = ImagePixelType_float; - if (values[1] == "uint8") - outPixType = ImagePixelType_uint8; - else if (values[1] == "int16") - outPixType = ImagePixelType_int16; - else if (values[1] == "uint16") - outPixType = ImagePixelType_uint16; - else if (values[1] == "int32") - outPixType = ImagePixelType_int32; - else if (values[1] == "uint32") - outPixType = ImagePixelType_uint32; - else if (values[1] == "float") - outPixType = ImagePixelType_float; - else if (values[1] == "double") - outPixType = ImagePixelType_double; - else - { - std::cerr << "ERROR: Invalid output type for parameter -" << paramKey << ": " << values[1] << "." << std::endl; - return WRONGPARAMETERVALUE; - } - dynamic_cast<OutputImageParameter *> (param.GetPointer())->SetPixelType(outPixType); - } - else - if (values.size() > 2) - { - std::cerr << "ERROR: Too many values for parameter -" << paramKey << " (expected 2 or less, got " << values.size() << ")." << std::endl; - return INVALIDNUMBEROFVALUE; - } - } - else if (type == ParameterType_ComplexOutputImage) - { - m_Application->SetParameterString(paramKey, values[0]); - // Check if pixel type is given - if (values.size() == 2) - { - ComplexImagePixelType outPixType = ComplexImagePixelType_float; - if (values[1] == "cfloat") - outPixType = ComplexImagePixelType_float; - else if (values[1] == "cdouble") - outPixType = ComplexImagePixelType_double; - else - { - std::cerr << "ERROR: Invalid output type for parameter -" << paramKey << ": " << values[1] << "." << std::endl; - return WRONGPARAMETERVALUE; - } - dynamic_cast<ComplexOutputImageParameter *> (param.GetPointer())->SetComplexPixelType(outPixType); - } - else - if (values.size() != 1 && values.size() != 2) - { - std::cerr << "ERROR: Invalid number of value for: \"" << paramKey - << "\", invalid number of values " << values.size() << std::endl; - return INVALIDNUMBEROFVALUE; - } - } - else - if (type == ParameterType_ListView) - { - - ListViewParameter * tmpLV = dynamic_cast<ListViewParameter *>(param.GetPointer()); - - if(tmpLV->GetSingleSelection() && values.size() > 1) - { - std::cerr << "ERROR: Invalid number of value for: \"" << paramKey - << "\", invalid number of values " << values.size() << std::endl; - return INVALIDNUMBEROFVALUE; - } - - tmpLV->SetSelectedNames(values); - } - else - if(values.size() != 1) - { - // Handle space in filename. Only for input - // files or directories - if (type == ParameterType_Directory || type == ParameterType_InputFilename || - type == ParameterType_ComplexInputImage || - type == ParameterType_InputImage || - type == ParameterType_InputVectorData || type == ParameterType_OutputVectorData ) - { - for(unsigned int j=1; j<values.size(); j++) - { - values[0].append(" "); - values[0].append(values[j]); - } - } - else if (!param->GetAutomaticValue()) - { - std::cerr << "ERROR: Invalid number of value for: \"" << paramKey << "\", must have 1 value, not " - << values.size() << std::endl; - return INVALIDNUMBEROFVALUE; - } - } - // Single value parameter - if (type == ParameterType_Choice || type == ParameterType_Float || type == ParameterType_Int || - type == ParameterType_Radius || type == ParameterType_Directory || type == ParameterType_InputFilename || + 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_ComplexInputImage || type == ParameterType_InputImage || + type == ParameterType_ComplexInputImage || + type == ParameterType_InputImage || + type == ParameterType_OutputImage || type == ParameterType_ComplexOutputImage || type == ParameterType_InputVectorData || - type == ParameterType_OutputVectorData || type == ParameterType_RAM || + type == ParameterType_OutputVectorData || + type == ParameterType_RAM || type == ParameterType_OutputProcessXML) // || type == ParameterType_InputProcessXML) { + // Single value parameter m_Application->SetParameterString(paramKey, values[0]); - } - else - if (type == ParameterType_Empty) + + if (type == ParameterType_OutputImage) { - if (values[0] == "1" || values[0] == "true") + // Check if pixel type is given + if (values.size() == 2) + { + ImagePixelType pixType = ImagePixelType_float; + if ( !OutputImageParameter::ConvertStringToPixelType(values[1],pixType) ) + { + std::cerr << "ERROR: Invalid output type for parameter -" << + paramKey << ": " << values[1] << "." << std::endl; + return WRONGPARAMETERVALUE; + } + m_Application->SetParameterOutputImagePixelType(paramKey, pixType); + } + else if (values.size() > 2) { - dynamic_cast<EmptyParameter *> (param.GetPointer())->SetActive(true); + std::cerr << "ERROR: Too many values for parameter -" << + paramKey << " (expected 2 or 1, got " << values.size() << ")." + << std::endl; + return INVALIDNUMBEROFVALUE; } - else - if (values[0] == "0" || values[0] == "false") + } + else if (type == ParameterType_ComplexOutputImage) + { + // Check if pixel type is given + if (values.size() == 2) + { + ComplexImagePixelType cpixType = ComplexImagePixelType_float; + if ( !ComplexOutputImageParameter::ConvertStringToPixelType(values[1],cpixType) ) { - dynamic_cast<EmptyParameter *> (param.GetPointer())->SetActive(false); + std::cerr << "ERROR: Invalid output type for parameter -" << + paramKey << ": " << values[1] << "." << std::endl; + return WRONGPARAMETERVALUE; } - else + m_Application->SetParameterComplexOutputImagePixelType(paramKey, cpixType); + } + else if (values.size() > 2) { - std::cerr << "ERROR: Wrong value for parameter -" << paramKey << "." << std::endl; - return WRONGPARAMETERVALUE; + std::cerr << "ERROR: Too many values for parameter: -" << paramKey + << " (expected 2 or 1, got " << values.size() << ")." <<std::endl; + return INVALIDNUMBEROFVALUE; } } - // Update the flag UserValue - param->SetUserValue(true); + } + else if (type == ParameterType_Empty) + { + // Set UserValue flag specific for EmptyParameter, beware that it + // should be done before Enable/Disable because SetParameterUserValue() + // may enable it by default + m_Application->SetParameterUserValue(paramKey,true); + if (values[0] == "1" || values[0] == "true") + { + m_Application->EnableParameter(paramKey); + } + else if (values[0] == "0" || values[0] == "false") + { + m_Application->DisableParameter(paramKey); + } + else + { + std::cerr << "ERROR: Wrong value for parameter -" << paramKey << "." << std::endl; + return WRONGPARAMETERVALUE; + } + } // Call the DoUpdateParameter to update dependent params m_Application->UpdateParameters(); } diff --git a/Modules/Wrappers/QtWidget/CMakeLists.txt b/Modules/Wrappers/QtWidget/CMakeLists.txt index 4162b8dd0192cd7dc25b157eee7d7773f2fd6941..7776d931eb8c30643bcf4f9066e7f66facdbb988 100644 --- a/Modules/Wrappers/QtWidget/CMakeLists.txt +++ b/Modules/Wrappers/QtWidget/CMakeLists.txt @@ -21,4 +21,10 @@ project(OTBQtWidget) set(OTBQtWidget_LIBRARIES OTBQtWidget) + +# folder where ui headers are generated +set( OTBQtWidget_INCLUDE_DIRS + ${OTBQtWidget_BINARY_DIR}/src + ) + otb_module_impl() diff --git a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetInputFilenameListParameter.h b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetInputFilenameListParameter.h index 0fd039933b71be32f1938331575b6d407605ebaf..9a64d46a516b26cde431b9c078fea5a9c01e5ca9 100644 --- a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetInputFilenameListParameter.h +++ b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetInputFilenameListParameter.h @@ -22,59 +22,43 @@ #define otbWrapperQtWidgetInputFilenameListParameter_h #include <QtGui> + #ifndef Q_MOC_RUN // See: https://bugreports.qt-project.org/browse/QTBUG-22829 //tag=QT4-boost-compatibility -#include "otbQtFileSelectionWidget.h" +# include "otbWrapperQtWidgetParameterList.h" #endif //tag=QT4-boost-compatibility namespace otb { + namespace Wrapper { +class InputFilenameListParameter; + /** \class QtWidgetInputFilenameListParameter * \brief * * \ingroup OTBQtWidget */ -class OTBQtWidget_EXPORT QtWidgetInputFilenameListParameter : public QtWidgetParameterBase +class OTBQtWidget_EXPORT QtWidgetInputFilenameListParameter : + public QtWidgetParameterList { Q_OBJECT -public: - QtWidgetInputFilenameListParameter(InputFilenameListParameter*, QtWidgetModel*); - ~QtWidgetInputFilenameListParameter() ITK_OVERRIDE; - - -signals: - void Change(); - void FileSelectionWidgetAdded( QWidget * ); -protected slots: - //void SetFileName( const QString& value ); - //virtual void SelectFile(); - virtual void UpFile(); - virtual void DownFile(); - virtual void AddFile(); - virtual void SuppressFile(); - virtual void EraseFile(); - virtual void UpdateFilenameList(); +// +// Public methods. +public: + QtWidgetInputFilenameListParameter( InputFilenameListParameter *, QtWidgetModel * ); + ~QtWidgetInputFilenameListParameter() override; +// +// Private methods. private: - QtWidgetInputFilenameListParameter(const QtWidgetInputFilenameListParameter&); //purposely not implemented - void operator=(const QtWidgetInputFilenameListParameter&); //purposely not implemented - - void DoCreateWidget() ITK_OVERRIDE; - - void DoUpdateGUI() ITK_OVERRIDE; - - void RecreateFilenameList(); - void UpdateFileList( std::map<unsigned int, unsigned int> idMap ); - - InputFilenameListParameter::Pointer m_InputFilenameListParam; + // purposely not implemented + QtWidgetInputFilenameListParameter( const QtWidgetInputFilenameListParameter & ); - QHBoxLayout * m_HLayout; - QVBoxLayout * m_FileLayout; - QScrollArea * m_Scroll; - std::vector<QtFileSelectionWidget *> m_FileSelectionList; + // purposely not implemented + void operator = ( const QtWidgetInputFilenameListParameter & ); }; diff --git a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetInputImageListParameter.h b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetInputImageListParameter.h index e4e5b0c3c134e42a9e3abb3361ef2f1e254ceeda..a975dedc454e3a329c040f53168fa14cdb16fef9 100644 --- a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetInputImageListParameter.h +++ b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetInputImageListParameter.h @@ -21,60 +21,49 @@ #ifndef otbWrapperQtWidgetInputImageListParameter_h #define otbWrapperQtWidgetInputImageListParameter_h + #include <QtGui> -#ifndef Q_MOC_RUN // See: https://bugreports.qt-project.org/browse/QTBUG-22829 //tag=QT4-boost-compatibility -#include "otbQtFileSelectionWidget.h" -#endif //tag=QT4-boost-compatibility + + +#include "OTBQtWidgetExport.h" +#include "otbWrapperQtWidgetParameterList.h" + namespace otb { + + namespace Wrapper { + +class InputImageListParameter; + + /** \class QtWidgetInputImageListParameter * \brief * * \ingroup OTBQtWidget */ -class OTBQtWidget_EXPORT QtWidgetInputImageListParameter : public QtWidgetParameterBase +class OTBQtWidget_EXPORT QtWidgetInputImageListParameter : + public QtWidgetParameterList { - Q_OBJECT -public: - QtWidgetInputImageListParameter(InputImageListParameter*, QtWidgetModel*); - ~QtWidgetInputImageListParameter() ITK_OVERRIDE; - + Q_OBJECT; -signals: - void Change(); - void FileSelectionWidgetAdded( QWidget * ); - -protected slots: - //void SetFileName( const QString& value ); - //virtual void SelectFile(); - virtual void UpFile(); - virtual void DownFile(); - virtual void AddFile(); - virtual void SuppressFile(); - virtual void EraseFile(); - virtual void UpdateImageList(); +// +// Public methods. +public: + QtWidgetInputImageListParameter( InputImageListParameter *, QtWidgetModel * ); + ~QtWidgetInputImageListParameter() override; +// +// Private methods. private: - QtWidgetInputImageListParameter(const QtWidgetInputImageListParameter&); //purposely not implemented - void operator=(const QtWidgetInputImageListParameter&); //purposely not implemented - - void DoCreateWidget() ITK_OVERRIDE; - - void DoUpdateGUI() ITK_OVERRIDE; - - void RecreateImageList(); - void UpdateFileList( std::map<unsigned int, unsigned int> idMap ); - - InputImageListParameter::Pointer m_InputImageListParam; + // Purposely not implemented + QtWidgetInputImageListParameter( const QtWidgetInputImageListParameter & ); - QHBoxLayout * m_HLayout; - QVBoxLayout * m_FileLayout; - QScrollArea * m_Scroll; - std::vector<QtFileSelectionWidget *> m_FileSelectionList; + // Purposely not implemented + void operator = ( const QtWidgetInputImageListParameter & ); }; diff --git a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetInputVectorDataListParameter.h b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetInputVectorDataListParameter.h index 4a43f7a00ebc1afa81d131a2eddc4c0dcd2a1770..7101cee908f87593f092471aa75d6b451be4e5f0 100644 --- a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetInputVectorDataListParameter.h +++ b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetInputVectorDataListParameter.h @@ -21,61 +21,52 @@ #ifndef otbWrapperQtWidgetInputVectorDataListParameter_h #define otbWrapperQtWidgetInputVectorDataListParameter_h + #include <QtGui> + + #ifndef Q_MOC_RUN // See: https://bugreports.qt-project.org/browse/QTBUG-22829 //tag=QT4-boost-compatibility -#include "otbWrapperInputVectorDataListParameter.h" -#include "otbQtFileSelectionWidget.h" +# include "otbWrapperQtWidgetParameterList.h" #endif //tag=QT4-boost-compatibility namespace otb { + + namespace Wrapper { + +class InputVectorDataListParameter; + + /** \class QtWidgetInputVectorDataListParameter * \brief * * \ingroup OTBQtWidget */ -class OTBQtWidget_EXPORT QtWidgetInputVectorDataListParameter : public QtWidgetParameterBase +class OTBQtWidget_EXPORT QtWidgetInputVectorDataListParameter + : public QtWidgetParameterList { - Q_OBJECT -public: - QtWidgetInputVectorDataListParameter(InputVectorDataListParameter*, QtWidgetModel*); - ~QtWidgetInputVectorDataListParameter() ITK_OVERRIDE; + Q_OBJECT; +// +// Public methods. +public: + QtWidgetInputVectorDataListParameter( InputVectorDataListParameter *, + QtWidgetModel * ); -signals: - void Change(); - void FileSelectionWidgetAdded( QWidget * ); + ~QtWidgetInputVectorDataListParameter() override; -protected slots: - //void SetFileName( const QString& value ); - //virtual void SelectFile(); - virtual void UpFile(); - virtual void DownFile(); - virtual void AddFile(); - virtual void SuppressFile(); - virtual void EraseFile(); - virtual void UpdateVectorDataList(); +// +// Private methods. private: - QtWidgetInputVectorDataListParameter(const QtWidgetInputVectorDataListParameter&); //purposely not implemented - void operator=(const QtWidgetInputVectorDataListParameter&); //purposely not implemented - - void DoCreateWidget() ITK_OVERRIDE; - - void DoUpdateGUI() ITK_OVERRIDE; - - void RecreateVectorDataList(); - void UpdateFileList( std::map<unsigned int, unsigned int> idMap ); - - InputVectorDataListParameter::Pointer m_InputVectorDataListParam; + // Purposely not implemented + QtWidgetInputVectorDataListParameter( const QtWidgetInputVectorDataListParameter & ); - QHBoxLayout * m_HLayout; - QVBoxLayout * m_FileLayout; - QScrollArea * m_Scroll; - std::vector<QtFileSelectionWidget *> m_FileSelectionList; + // Purposely not implemented + void operator = ( const QtWidgetInputVectorDataListParameter & ); }; diff --git a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetListEditItemModel.h b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetListEditItemModel.h new file mode 100644 index 0000000000000000000000000000000000000000..34000ebc980150843eabbbebc0b58302b0de3027 --- /dev/null +++ b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetListEditItemModel.h @@ -0,0 +1,288 @@ +/* + * Copyright (C) 2005-2017 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 otbListEditItemModel_h +#define otbListEditItemModel_h + +// +// Configuration include. +//// Included at first position before any other ones. +#ifndef Q_MOC_RUN // See: https://bugreports.qt-project.org/browse/QTBUG-22829 //tag=QT4-boost-compatibility +#include "otbMacro.h" +#endif //tag=QT4-boost-compatibility + +#include "OTBQtWidgetExport.h" + +/*****************************************************************************/ +/* INCLUDE SECTION */ + +// +// Qt includes (sorted by alphabetic order) +//// Must be included before system/custom includes. +#include <QtCore> + +// +// System includes (sorted by alphabetic order) + +// +// ITK includes (sorted by alphabetic order) + +// +// OTB includes (sorted by alphabetic order) + +// +// Monteverdi includes (sorted by alphabetic order) + + +/*****************************************************************************/ +/* PRE-DECLARATION SECTION */ + +// +// External classes pre-declaration. +namespace +{ + +} + +namespace otb +{ + +namespace Wrapper +{ + +// +// Internal classes pre-declaration. +class StringListInterface; + + +/*****************************************************************************/ +/* CLASS DEFINITION SECTION */ + +/** + * \class ListEditItemModel + * + * \ingroup OTBQtWidget + * + * \brief WIP. + */ +class OTBQtWidget_EXPORT ListEditItemModel : + public QAbstractItemModel +{ + + /*-[ QOBJECT SECTION ]-----------------------------------------------------*/ + + Q_OBJECT; + + /*-[ PUBLIC SECTION ]------------------------------------------------------*/ + +// +// Public types. +public: + + enum Columns + { + COLUMN_NONE = -1, + // + COLUMN_NAME = 0, + // COLUMN_BROWSE = 1, + // + COLUMN_COUNT, + }; + + enum UserRole + { + USER_ROLE_NONE = Qt::UserRole, + USER_ROLE_DIRECTION, + USER_ROLE_FILTER, + }; + +// +// Public methods. +public: + + /** \brief Constructor. */ + ListEditItemModel( StringListInterface *, + QObject * p = nullptr ); + + /** \brief Destructor. */ + ~ListEditItemModel() ITK_OVERRIDE; + + // + // QAbstractItemModel overloads. + + /** + * \see http://qt-project.org/doc/qt-4.8/qabstractitemmodel.html#columnCount + */ + int columnCount( const QModelIndex & p = QModelIndex() ) const ITK_OVERRIDE; + + /** + * \see http://qt-project.org/doc/qt-4.8/qabstractitemmodel.html#data + */ + QVariant + data( const QModelIndex & index, + int role = Qt::DisplayRole ) const ITK_OVERRIDE; + + /** + * \see http://qt-project.org/doc/qt-4.8/qabstractitemmodel.html#flags + */ + Qt::ItemFlags flags( const QModelIndex & index ) const ITK_OVERRIDE; + + /** + * \see http://qt-project.org/doc/qt-4.8/qabstractitemmodel.html#hasChildren + */ + bool hasChildren( const QModelIndex & p = QModelIndex() ) const ITK_OVERRIDE; + + /** + * \see http://qt-project.org/doc/qt-4.8/qabstractitemmodel.html#headerData + */ + QVariant headerData( int section, + Qt::Orientation orientation, + int role = Qt::DisplayRole ) const ITK_OVERRIDE; + + /** + * \see http://qt-project.org/doc/qt-4.8/qabstractitemmodel.html#index + */ + QModelIndex + index( int row, + int column, + const QModelIndex & p = QModelIndex() ) const ITK_OVERRIDE; + + /** + * \see http://doc.qt.io/qt-4.8/qabstractitemmodel.html#insertRow + */ + bool + insertRow( int row, const QModelIndex & parent = QModelIndex() ); + + /** + * \see http://qt-project.org/doc/qt-4.8/qabstractitemmodel.html#insertRows + */ + bool + insertRows( int row, + int count, + const QModelIndex & p = QModelIndex() ) ITK_OVERRIDE; + + /** + * \see http://qt-project.org/doc/qt-4.8/qabstractitemmodel.html#parent + */ + QModelIndex parent( const QModelIndex & index ) const ITK_OVERRIDE; + + /** + * \see http://qt-project.org/doc/qt-4.8/qabstractitemmodel.html#removeRows + */ + bool + removeRows( int row, + int count, + const QModelIndex & p = QModelIndex() ) ITK_OVERRIDE; + + /** + * \see http://qt-project.org/doc/qt-4.8/qabstractitemmodel.html#rowCount + */ + int rowCount( const QModelIndex & p = QModelIndex() ) const ITK_OVERRIDE; + + /** + * \see http://qt-project.org/doc/qt-4.8/qabstractitemmodel.html#setData + */ + bool + setData( const QModelIndex & index, + const QVariant & value, + int role = Qt::EditRole ) ITK_OVERRIDE; + + /** */ + virtual bool Swap( int, int ); + + /** */ + virtual bool IsInput() const; + + /** */ + virtual QString GetFilter() const; + + /** */ + virtual bool IsBrowsable() const; + + /*-[ PUBLIC SLOTS SECTION ]------------------------------------------------*/ + +// +// Public SLOTS. +public slots: + + /*-[ SIGNALS SECTION ]-----------------------------------------------------*/ + +// +// Signals. +signals: + + /*-[ PROTECTED SECTION ]---------------------------------------------------*/ + +// +// Protected methods. +protected: + +// +// Protected attributes. +protected: + + /*-[ PRIVATE SECTION ]-----------------------------------------------------*/ + +// +// Private methods. +private: + + +// +// Private attributes. +private: + /** */ + StringListInterface * m_StringList; + + /*-[ PRIVATE SLOTS SECTION ]-----------------------------------------------*/ + +// +// Slots. +private slots: +}; + +} // end namespace 'Wrapper'. + +} // end namespace 'otb'. + +/*****************************************************************************/ +/* INLINE SECTION */ + +// +// Qt includes (sorted by alphabetic order) +//// Must be included before system/custom includes. + +// +// System includes (sorted by alphabetic order) + +// +// ITK includes (sorted by alphabetic order) + +// +// OTB includes (sorted by alphabetic order) + +// +// Monteverdi includes (sorted by alphabetic order) + +namespace otb +{ +} // end namespace 'otb' + +#endif // otbListEditItemModel_h diff --git a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetListEditWidget.h b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetListEditWidget.h new file mode 100644 index 0000000000000000000000000000000000000000..a804dbe7bc8e5df5964abe581f528ce5ee6e2401 --- /dev/null +++ b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetListEditWidget.h @@ -0,0 +1,207 @@ +/* + * Copyright (C) 2005-2017 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 otbWrapperQtWidgetListEditWidget_h +#define otbWrapperQtWidgetListEditWidget_h + +// +// Configuration include. +//// Included at first position before any other ones. +#include "otbConfigure.h" + + +/*****************************************************************************/ +/* INCLUDE SECTION */ + +// +// Qt includes (sorted by alphabetic order) +//// Must be included before system/custom includes. +#include <QtGui> + +// +// System includes (sorted by alphabetic order) + +// +// ITK includes (sorted by alphabetic order) + +// +// OTB includes (sorted by alphabetic order) +#include "OTBQtWidgetExport.h" + + +/*****************************************************************************/ +/* PRE-DECLARATION SECTION */ + +// +// External classes pre-declaration. +namespace +{ +} + +namespace otb +{ + +namespace Wrapper +{ + +// +// Internal classes pre-declaration. +class ListEditItemModel; +class StringListInterface; + +namespace Ui +{ +class ListEditWidget; +}; + + +/*****************************************************************************/ +/* CLASS DEFINITION SECTION */ + +/** + * \class ListEditWidget + * + * \ingroup OTBQtWidget + * + * \brief + */ +class OTBQtWidget_EXPORT ListEditWidget : + public QWidget +{ + + /*-[ QOBJECT SECTION ]-----------------------------------------------------*/ + + Q_OBJECT; + + /*-[ PUBLIC SECTION ]------------------------------------------------------*/ + +// +// Public methods. +public: + + /** \brief Constructor. */ + ListEditWidget( StringListInterface *, + QWidget * p =NULL, + Qt::WindowFlags flags =0 ); + + /** \brief Destructor. */ + virtual ~ListEditWidget(); + + /** + */ + const ListEditItemModel * GetItemModel() const; + + /** + */ + ListEditItemModel * GetItemModel(); + +#if 0 + + /** */ + void SetBrowseEnabled( bool ); + + /** */ + bool IsBrowseEnabled() const; +#endif + + /*-[ PUBLIC SLOTS SECTION ]------------------------------------------------*/ + +// +// Public SLOTS. +public slots: + void OnFilenameDropped(const QString &); + /*-[ SIGNALS SECTION ]-----------------------------------------------------*/ + +// +// Signals. +signals: + /** */ + void Updated(); + + /*-[ PROTECTED SECTION ]---------------------------------------------------*/ + +// +// Protected methods. +protected: + + /*-[ PRIVATE SECTION ]-----------------------------------------------------*/ + +// +// Protected attributes. +protected: + +// +// Private types. +private: + enum SwapSelection + { + LEFT = -1, + NONE = 0, + RIGHT = +1, + }; + +// +// Private methods. +private: + void Swap( int, int, SwapSelection = NONE ); + + QStringList browseFilenames( bool multi = false, const QString & filename = QString()); + + QString browseFilename( const QModelIndex & ); + +// +// Private attributes. +private: + /** + * \brief uic generated. + */ + Ui::ListEditWidget * m_UI; + + /*-[ PRIVATE SLOTS SECTION ]-----------------------------------------------*/ + +// +// Slots. +private slots: + void on_addButton_clicked(); + void on_browseButton_clicked(); + void on_downButton_clicked(); + void on_removeButton_clicked(); + void on_removeAllButton_clicked(); + void on_upButton_clicked(); + + void OnDataChanged( const QModelIndex &, const QModelIndex & ); + void OnModelReset(); + void OnRowsInserted( const QModelIndex &, int, int ); + void OnRowsRemoved( const QModelIndex &, int, int ); + void OnSelectionChanged( const QItemSelection &, const QItemSelection & ); +}; + +} // end namespace 'Wrapper' + +} // end namespace 'otb' + +/*****************************************************************************/ +/* INLINE SECTION */ + +namespace Wrapper +{ +} // end namespace 'Wrapper' + +#endif // otbWrappersQtWidgetListEditWidget_h diff --git a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetParameterBase.h b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetParameterBase.h index 6edb46ea956dfd32b11bfb2426478fc5bb3319ff..db88ca9ace0243f4a10165b560e26dc2967b4869 100644 --- a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetParameterBase.h +++ b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetParameterBase.h @@ -42,7 +42,7 @@ class OTBQtWidget_EXPORT QtWidgetParameterBase : public QWidget { Q_OBJECT public: - QtWidgetParameterBase(Parameter *, QtWidgetModel*); + QtWidgetParameterBase( Parameter *, QtWidgetModel * ); ~QtWidgetParameterBase() ITK_OVERRIDE; void CreateWidget(); @@ -61,6 +61,9 @@ signals: protected: QtWidgetModel* GetModel(); + const Parameter * GetParam() const; + + Parameter * GetParam(); private: QtWidgetParameterBase(const QtWidgetParameterBase&); //purposely not implemented @@ -70,9 +73,10 @@ private: virtual void DoCreateWidget() = 0; - QtWidgetModel* m_Model; +private: + QtWidgetModel * m_Model; - Parameter* m_Param; + Parameter * m_Param; }; diff --git a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetParameterList.h b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetParameterList.h new file mode 100644 index 0000000000000000000000000000000000000000..61768297a1677ba29bd4ad8396890551a299d2e0 --- /dev/null +++ b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetParameterList.h @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2005-2017 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 otbWrapperQtWidgetParameterList_h +#define otbWrapperQtWidgetParameterList_h + +#include <QtGui> +#ifndef Q_MOC_RUN // See: https://bugreports.qt-project.org/browse/QTBUG-22829 //tag=QT4-boost-compatibility +# include "otbWrapperQtWidgetParameterBase.h" +#endif //tag=QT4-boost-compatibility + + +namespace otb +{ + + +namespace Wrapper +{ + +class AbstractParameterList; + +/** \class QtWidgetParameterList + * \brief + * + * \ingroup OTBQtWidget + */ +class OTBQtWidget_EXPORT QtWidgetParameterList : public QtWidgetParameterBase +{ + Q_OBJECT + +// +// Public methods. +public: + QtWidgetParameterList( AbstractParameterList *, QtWidgetModel * ); + ~QtWidgetParameterList() override; + +// +// Signals. +signals: + void NotifyUpdate(); + +// +// Private methods. +private: + QtWidgetParameterList( const QtWidgetParameterList & ); // purposely not implemented + void operator = (const QtWidgetParameterList & ); // purposely not implemented + + void DoCreateWidget() override; + + void DoUpdateGUI() override; + +// +// Private attributes. +private: + +// +// Private slots. +private slots: +}; + +} // Wrapper + +} // otb + +#endif diff --git a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetStringListParameter.h b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetStringListParameter.h index 8ae05e7551e57ec1e8ab239c1214c96468877d01..062e38ea6735f94c4dd2e841a33ae8135668df41 100644 --- a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetStringListParameter.h +++ b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetStringListParameter.h @@ -21,52 +21,47 @@ #ifndef otbWrapperQtWidgetStringListParameter_h #define otbWrapperQtWidgetStringListParameter_h -#include <QtGui> -#ifndef Q_MOC_RUN // See: https://bugreports.qt-project.org/browse/QTBUG-22829 //tag=QT4-boost-compatibility -#include "otbQtStringSelectionWidget.h" -#endif //tag=QT4-boost-compatibility + +#include "otbWrapperQtWidgetParameterList.h" + namespace otb { + + namespace Wrapper { + +class StringListParameter; + + /** \class QtWidgetStringListParameter * \brief * * \ingroup OTBQtWidget */ -class OTBQtWidget_EXPORT QtWidgetStringListParameter : public QtWidgetParameterBase +class OTBQtWidget_EXPORT QtWidgetStringListParameter : + public QtWidgetParameterList { - Q_OBJECT -public: - QtWidgetStringListParameter(StringListParameter*, QtWidgetModel*); - ~QtWidgetStringListParameter() ITK_OVERRIDE; - -signals: - void Change(); + Q_OBJECT; -protected slots: - void SetString( const QString& value ); - virtual void AddString(); - virtual void SuppressString(); - virtual void UpdateStringList(); - -private: - QtWidgetStringListParameter(const QtWidgetStringListParameter&); //purposely not implemented - void operator=(const QtWidgetStringListParameter&); //purposely not implemented - void DoCreateWidget() ITK_OVERRIDE; - - void DoUpdateGUI() ITK_OVERRIDE; +// +// Public methods. +public: + QtWidgetStringListParameter( StringListParameter *, QtWidgetModel * ); + ~QtWidgetStringListParameter() override; - StringListParameter::Pointer m_StringListParam; - QHBoxLayout * m_HLayout; - QVBoxLayout * m_StringLayout; - QScrollArea * m_Scroll; +// +// Private methods. +private: + // Purposely not implemented. + QtWidgetStringListParameter( const QtWidgetStringListParameter & ); - std::vector<QtStringSelectionWidget *> m_LineEditList; + // Purposely not implemented + void operator = ( const QtWidgetStringListParameter & ); }; diff --git a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetView.h b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetView.h index 761973da1dba385c8dc0bc64e863668818386da5..08857a242016ffb592d3005b209d6b2ffbb874fb 100644 --- a/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetView.h +++ b/Modules/Wrappers/QtWidget/include/otbWrapperQtWidgetView.h @@ -55,6 +55,7 @@ public: public slots: void CloseSlot(); void UnhandledException(QString message); + void OnExceptionRaised(QString message); private slots: void UpdateMessageAfterExecuteClicked(); diff --git a/Modules/Wrappers/QtWidget/src/CMakeLists.txt b/Modules/Wrappers/QtWidget/src/CMakeLists.txt index e567d8d7cadba6c047bc655a7de55d0e02bf8abb..28cb58c37691087555171daca7ab833814eed571 100644 --- a/Modules/Wrappers/QtWidget/src/CMakeLists.txt +++ b/Modules/Wrappers/QtWidget/src/CMakeLists.txt @@ -54,6 +54,9 @@ set(OTBQtWidget_SRC otbWrapperQtWidgetOutputVectorDataParameter.cxx otbWrapperQtWidgetInputFilenameParameter.cxx otbWrapperQtWidgetInputImageListParameter.cxx + otbWrapperQtWidgetListEditWidget.cxx + otbWrapperQtWidgetListEditItemModel.cxx + otbWrapperQtWidgetParameterList.cxx ) set(OTBQtWidget_MOC_HDR @@ -91,11 +94,23 @@ set(OTBQtWidget_MOC_HDR ../include/otbWrapperQtWidgetDirectoryParameter.h ../include/otbWrapperQtWidgetSimpleProgressReport.h ../include/otbWrapperQtWidgetRAMParameter.h + ../include/otbWrapperQtWidgetListEditWidget.h + ../include/otbWrapperQtWidgetListEditItemModel.h + ../include/otbWrapperQtWidgetParameterList.h ) -QT4_WRAP_CPP(OTBQtWidget_MOC_SRC ${OTBQtWidget_MOC_HDR}) +set( OTBQtWidget_FORMS + otbWrapperQtWidgetListEditWidget.ui + ) + +qt4_wrap_cpp( OTBQtWidget_MOC_SRC ${OTBQtWidget_MOC_HDR} ) +qt4_wrap_ui( OTBQtWidget_FORMS_HEADERS ${OTBQtWidget_FORMS} ) -add_library(OTBQtWidget ${OTBQtWidget_SRC} ${OTBQtWidget_MOC_SRC}) +add_library( OTBQtWidget + ${OTBQtWidget_SRC} + ${OTBQtWidget_FORMS_HEADERS} + ${OTBQtWidget_MOC_SRC} + ) target_link_libraries( OTBQtWidget ${OTBApplicationEngine_LIBRARIES} diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetChoiceParameter.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetChoiceParameter.cxx index e3321703b0793b6fe15b72897832035802165ad1..078064cba3623f721315bb0629babb77de0c89d5 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetChoiceParameter.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetChoiceParameter.cxx @@ -61,7 +61,9 @@ void QtWidgetChoiceParameter::DoUpdateGUI() void QtWidgetChoiceParameter::DoCreateWidget() { m_ComboBox = new QComboBox; - m_ComboBox->setToolTip(m_ChoiceParam->GetDescription()); + m_ComboBox->setToolTip( + QString::fromStdString( m_ChoiceParam->GetDescription() ) + ); m_StackWidget = new QStackedWidget; diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetComplexInputImageParameter.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetComplexInputImageParameter.cxx index 5334147cfa86ed0b117def49699468bebae9bb85..198b4a4929706fff9a83aeb9451bb644edcc5b96 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetComplexInputImageParameter.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetComplexInputImageParameter.cxx @@ -60,7 +60,9 @@ void QtWidgetComplexInputImageParameter::DoCreateWidget() m_HLayout->setSpacing(0); m_HLayout->setContentsMargins(0, 0, 0, 0); m_Input = new QLineEdit; - m_Input->setToolTip( m_ComplexInputImageParam->GetDescription() ); + m_Input->setToolTip( + QString::fromStdString( m_ComplexInputImageParam->GetDescription() ) + ); connect( m_Input, SIGNAL(textChanged(const QString&)), this, SLOT(SetFileName(const QString&)) ); connect( m_Input, SIGNAL(textChanged(const QString&)), GetModel(), SLOT(NotifyUpdate()) ); diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetComplexOutputImageParameter.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetComplexOutputImageParameter.cxx index 7432d261b9bcf07251c42df8b316b2cbe972d637..0cd5800dfa462ba05af6123a247ca48c15d29d78 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetComplexOutputImageParameter.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetComplexOutputImageParameter.cxx @@ -57,7 +57,9 @@ void QtWidgetComplexOutputImageParameter::DoCreateWidget() m_HLayout->setSpacing(0); m_HLayout->setContentsMargins(0, 0, 0, 0); m_Input = new QLineEdit; - m_Input->setToolTip( m_OutputImageParam->GetDescription() ); + m_Input->setToolTip( + QString::fromStdString( m_OutputImageParam->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); diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetDirectoryParameter.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetDirectoryParameter.cxx index 0c5aee0d58d9e986a5255e4370d4f07c0927dd05..6eb0189d11729838618eea498be3495b15c597e8 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetDirectoryParameter.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetDirectoryParameter.cxx @@ -56,7 +56,9 @@ void QtWidgetDirectoryParameter::DoCreateWidget() m_HLayout->setSpacing(0); m_HLayout->setContentsMargins(0, 0, 0, 0); m_Input = new QLineEdit; - m_Input->setToolTip( m_DirectoryParam->GetDescription() ); + m_Input->setToolTip( + QString::fromStdString( m_DirectoryParam->GetDescription() ) + ); connect( m_Input, SIGNAL(textChanged(const QString&)), this, SLOT(SetFileName(const QString&)) ); connect( m_Input, SIGNAL(textChanged(const QString&)), GetModel(), SLOT(NotifyUpdate()) ); diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetFloatParameter.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetFloatParameter.cxx index 2c7a2a99f109bb71b05a7bfacacadddcf97ad367..6c30dd23e88aad1c10252aa25c307b429601e97d 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetFloatParameter.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetFloatParameter.cxx @@ -72,7 +72,11 @@ void QtWidgetFloatParameter::DoCreateWidget() m_QDoubleSpinBox->setDecimals(5); m_QDoubleSpinBox->setSingleStep(0.1); m_QDoubleSpinBox->setRange(m_FloatParam->GetMinimumValue(), m_FloatParam->GetMaximumValue()); - m_QDoubleSpinBox->setToolTip(m_FloatParam->GetDescription()); + m_QDoubleSpinBox->setToolTip( + QString::fromStdString( + m_FloatParam->GetDescription() + ) + ); connect( m_QDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(SetValue(double)) ); connect( m_QDoubleSpinBox, SIGNAL(valueChanged(double)), GetModel(), SLOT(NotifyUpdate()) ); diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputFilenameListParameter.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputFilenameListParameter.cxx index da366b6308179702193e847846d918fc814ab1e8..8aeae849f6cf742c2ff857b4aa9e4bc5f060e04d 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputFilenameListParameter.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputFilenameListParameter.cxx @@ -18,382 +18,31 @@ * limitations under the License. */ +#include "otbWrapperInputFilenameListParameter.h" #include "otbWrapperQtWidgetInputFilenameListParameter.h" -namespace otb -{ -namespace Wrapper -{ - -QtWidgetInputFilenameListParameter::QtWidgetInputFilenameListParameter(InputFilenameListParameter* param, QtWidgetModel* m) -: QtWidgetParameterBase(param, m), - m_InputFilenameListParam(param) -{ - connect(this, SIGNAL(Change()), GetModel(), SLOT(NotifyUpdate())); -} - -QtWidgetInputFilenameListParameter::~QtWidgetInputFilenameListParameter() -{ -} - -void QtWidgetInputFilenameListParameter::DoUpdateGUI() -{ - if(!m_InputFilenameListParam) - return; - - std::vector<std::string> fileList = m_InputFilenameListParam->GetFileNameList(); - for( unsigned int i = m_FileSelectionList.size(); i < fileList.size(); i++ ) - { - this->AddFile(); - } - int i = 0; - std::vector<std::string>::iterator it; - for (it = fileList.begin(); it != fileList.end(); ++it) - { - m_FileSelectionList[i++]->GetInput()->setText( - QFile::decodeName( - it->c_str() - ) - ); - } -} - -void QtWidgetInputFilenameListParameter::DoCreateWidget() -{ - m_FileSelectionList.clear(); - const unsigned int sp(2); - const unsigned int buttonSize(30); - - // Global layout - QHBoxLayout * hLayout = new QHBoxLayout; - hLayout->setSpacing(sp); - hLayout->setContentsMargins(sp, sp, sp, sp); - - // Button layout - QVBoxLayout * buttonLayout = new QVBoxLayout; - buttonLayout->setSpacing(sp); - buttonLayout->setContentsMargins(sp, sp, sp, sp); - - QHBoxLayout * addSupLayout = new QHBoxLayout; - addSupLayout->setSpacing(sp); - addSupLayout->setContentsMargins(sp, sp, sp, sp); - - QHBoxLayout * upDownLayout = new QHBoxLayout; - upDownLayout->setSpacing(sp); - upDownLayout->setContentsMargins(sp, sp, sp, sp); - - // Add file button - QPushButton * addButton = new QPushButton; - addButton->setText("+"); - addButton->setFixedWidth(buttonSize); - addButton->setToolTip("Add a file selector..."); - connect(addButton, SIGNAL(clicked()), this, SLOT(AddFile())); - addSupLayout->addWidget(addButton); - - // Suppress file button - QPushButton * supButton = new QPushButton; - supButton->setText("-"); - supButton->setFixedWidth(buttonSize); - supButton->setToolTip("Suppress the selected file..."); - connect(supButton, SIGNAL(clicked()), this, SLOT(SuppressFile())); - addSupLayout->addWidget(supButton); - buttonLayout->addLayout(addSupLayout); - - // Up file edit - QPushButton * upButton = new QPushButton; - upButton->setText("Up"); - upButton->setFixedWidth(buttonSize); - upButton->setToolTip("Up the selected file in the list..."); - connect(upButton, SIGNAL(clicked()), this, SLOT(UpFile())); - upDownLayout->addWidget(upButton); - - // Down file edit - QPushButton * downButton = new QPushButton; - downButton->setText("Down"); - downButton->setFixedWidth(buttonSize); - downButton->setToolTip("Down the selected file in the list..."); - connect(downButton, SIGNAL(clicked()), this, SLOT(DownFile())); - upDownLayout->addWidget(downButton); - buttonLayout->addLayout(upDownLayout); - - // Erase file edit - QPushButton * eraseButton = new QPushButton; - eraseButton->setText("Erase"); - eraseButton->setFixedWidth(2*(buttonSize+sp)); - eraseButton->setToolTip("Erase the selected file of the list..."); - connect(eraseButton, SIGNAL(clicked()), this, SLOT(EraseFile())); - buttonLayout->addWidget(eraseButton); - - QVBoxLayout * fileLayout = new QVBoxLayout(); - fileLayout->setSpacing(0); - - QtFileSelectionWidget * fileSelection = new QtFileSelectionWidget(); - fileSelection->SetIOMode( QtFileSelectionWidget::IO_MODE_INPUT ); - fileSelection->setFixedHeight(30); - fileLayout->addWidget(fileSelection); - m_InputFilenameListParam->AddNullElement(); - connect(fileSelection->GetInput(), SIGNAL(textChanged(const QString&)), this, SLOT(UpdateFilenameList())); - - m_FileSelectionList.push_back(fileSelection); - - QGroupBox *mainGroup = new QGroupBox(); - mainGroup->setLayout(fileLayout); - QScrollArea * s = new QScrollArea(); - s->setWidget(mainGroup); - s->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - s->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - s->setWidgetResizable(true); - - hLayout->addWidget(s); - hLayout->addLayout(buttonLayout); - - this->setLayout(hLayout); - - m_FileLayout = fileLayout; - m_HLayout = hLayout; - m_Scroll = s; -} - -void -QtWidgetInputFilenameListParameter::UpdateFilenameList() -{ - for(unsigned int j = 0; j < m_InputFilenameListParam->GetFileList()->Size(); j++) - { - if(m_InputFilenameListParam->SetNthFileName(j, m_FileSelectionList[j]->GetFilename()) == false) - { - std::ostringstream oss; - oss << "The given file " << m_FileSelectionList[j]->GetFilename() << " is not valid."; - this->GetModel()->SendLogWARNING(oss.str()); - m_FileSelectionList[j]->ClearFilename(); - } - } - - emit Change(); - - // notify of value change - QString key(m_InputFilenameListParam->GetKey()); - emit ParameterChanged(key); -} - - -void -QtWidgetInputFilenameListParameter::UpFile() -{ - if(m_FileSelectionList.size() < 2) - return; - - m_FileLayout = new QVBoxLayout(); - m_FileLayout->setSpacing(2); - - // Map link between old and new index in the list - std::map<unsigned int, unsigned int> idMap; - - // Init map - for(unsigned int i = 0; i < m_FileSelectionList.size(); i++) - { - idMap[i] = i; - } - // If the first item is checked, uncheck it... - // It won't be moved - if(m_FileSelectionList[0]->IsChecked()) - { - m_FileSelectionList[0]->SetChecked(false); - } - - - // If other item are checked, up the index - // Starts at 1 because the first item mustn't move - for(unsigned int i = 1; i < m_FileSelectionList.size(); i++) - { - if(m_FileSelectionList[i]->IsChecked()) - { - unsigned int tmp = idMap[i]; - idMap[i] = i-1; - idMap[idMap[i-1]] = tmp; - } - } - - this->UpdateFileList(idMap); - - this->RecreateFilenameList(); -} - -void -QtWidgetInputFilenameListParameter::DownFile() -{ - if(m_FileSelectionList.size() < 2) return; - - m_FileLayout = new QVBoxLayout(); - m_FileLayout->setSpacing(0); - - // Map link between old and new index in the list - std::map<unsigned int, unsigned int> idMap; - - // Init map - for(unsigned int i = 0; i < m_FileSelectionList.size(); i++) - { - idMap[i] = i; - } - - // If the last item is checked, uncheck it... - // It won't be moved - if(m_FileSelectionList[m_FileSelectionList.size() - 1]->IsChecked()) - { - m_FileSelectionList[m_FileSelectionList.size() - 1]->SetChecked(false); - } - - // If other item are checked, up the index - // Stops at size-1 because the last item mustn't move - for(int i = m_FileSelectionList.size() - 2; i >= 0; i--) - { - if(m_FileSelectionList[i]->IsChecked()) - { - unsigned int tmp = idMap[i]; - idMap[i] = i + 1; - idMap[idMap[i + 1]] = tmp; - } - } - - this->UpdateFileList(idMap); - - this->RecreateFilenameList(); -} - - -void -QtWidgetInputFilenameListParameter::UpdateFileList(std::map<unsigned int, unsigned int> idMap) +namespace otb { - std::vector<QtFileSelectionWidget *> tmpList; - // Keys become values and inverse - std::map<unsigned int, unsigned int> idMapBis; - for(unsigned int i = 0; i < idMap.size(); i++) - { - idMapBis[idMap[i]] = i; - } - - // Create the new item list - for(unsigned int i = 0; i < m_FileSelectionList.size(); i++) - { - m_FileLayout->addWidget(m_FileSelectionList[idMapBis[i]]); - tmpList.push_back(m_FileSelectionList[idMapBis[i]]); - } - - m_FileSelectionList = tmpList; - QGroupBox *mainGroup = new QGroupBox(); - mainGroup->setLayout(m_FileLayout); - m_Scroll->setWidget(mainGroup); - - this->update(); - - // notify of value change - QString key(m_InputFilenameListParam->GetKey()); - emit ParameterChanged(key); -} - -void -QtWidgetInputFilenameListParameter::AddFile() +namespace Wrapper { - m_FileLayout = new QVBoxLayout(); - m_FileLayout->setSpacing(0); - - for(unsigned int i = 0; i < m_FileSelectionList.size(); i++) - { - m_FileLayout->addWidget(m_FileSelectionList[i]); - } - - QtFileSelectionWidget * fileSelection = new QtFileSelectionWidget(); - fileSelection->SetIOMode( QtFileSelectionWidget::IO_MODE_INPUT ); - fileSelection->setFixedHeight(30); - m_FileLayout->addWidget(fileSelection); - m_FileSelectionList.push_back(fileSelection); - m_InputFilenameListParam->AddNullElement(); - connect(fileSelection->GetInput(), SIGNAL(textChanged(const QString&)), this, SLOT(UpdateFilenameList())); - - QGroupBox *mainGroup = new QGroupBox(); - mainGroup->setLayout(m_FileLayout); - m_Scroll->setWidget(mainGroup); - this->update(); - - emit FileSelectionWidgetAdded( fileSelection ); -} - -void -QtWidgetInputFilenameListParameter::SuppressFile() +/*****************************************************************************/ +QtWidgetInputFilenameListParameter +::QtWidgetInputFilenameListParameter( InputFilenameListParameter * param, + QtWidgetModel * m ) : + QtWidgetParameterList( param, m ) { - m_FileLayout = new QVBoxLayout(); - m_FileLayout->setSpacing(0); - std::vector<QtFileSelectionWidget *> tmpList; - for(unsigned int i = 0; i < m_FileSelectionList.size(); i++) - { - if(!m_FileSelectionList[i]->IsChecked()) - { - m_FileLayout->addWidget(m_FileSelectionList[i]); - tmpList.push_back(m_FileSelectionList[i]); - } - } - - m_FileSelectionList = tmpList; - - QGroupBox *mainGroup = new QGroupBox(); - mainGroup->setLayout(m_FileLayout); - m_Scroll->setWidget(mainGroup); - - this->update(); - this->RecreateFilenameList(); } -void -QtWidgetInputFilenameListParameter::EraseFile() +/*****************************************************************************/ +QtWidgetInputFilenameListParameter +::~QtWidgetInputFilenameListParameter() { - m_FileSelectionList.clear(); - - m_FileLayout = new QVBoxLayout(); - - QtFileSelectionWidget * fileSelection = new QtFileSelectionWidget(); - fileSelection->SetIOMode( QtFileSelectionWidget::IO_MODE_INPUT ); - fileSelection->setFixedHeight(30); - m_FileLayout->addWidget(fileSelection); - m_FileSelectionList.push_back(fileSelection); - m_InputFilenameListParam->AddNullElement(); - connect(fileSelection->GetInput(), SIGNAL(textChanged(const QString&)), this, SLOT(UpdateFilenameList())); - - QGroupBox *mainGroup = new QGroupBox(); - mainGroup->setLayout(m_FileLayout); - m_Scroll->setWidget(mainGroup); - - this->update(); - this->RecreateFilenameList(); } - -void QtWidgetInputFilenameListParameter::RecreateFilenameList() -{ - // save value - m_InputFilenameListParam->ClearValue(); - - if(m_FileSelectionList.size() == 0) - { - this->AddFile(); - } - else - { - for(unsigned int j = 0; j < m_FileSelectionList.size(); j++) - { - m_InputFilenameListParam->AddFromFileName(m_FileSelectionList[j]->GetFilename()); - connect(m_FileSelectionList[j]->GetInput(), SIGNAL(textChanged(const QString&)), this, SLOT(UpdateFilenameList())); - } - - emit Change(); - // notify of value change - QString key(m_InputFilenameListParam->GetKey()); - emit ParameterChanged(key); - } } - -} } diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputFilenameParameter.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputFilenameParameter.cxx index 6db8cb82bbc1182e84dc99c6642a5e5ed3c91366..93011f37eb41736daf76cd063b5bdac4ff44fca5 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputFilenameParameter.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputFilenameParameter.cxx @@ -61,7 +61,9 @@ void QtWidgetInputFilenameParameter::DoCreateWidget() m_HLayout->setSpacing(0); m_HLayout->setContentsMargins(0, 0, 0, 0); m_Input = new QLineEdit; - m_Input->setToolTip( m_FilenameParam->GetDescription() ); + m_Input->setToolTip( + QString::fromStdString( m_FilenameParam->GetDescription() ) + ); connect( m_Input, SIGNAL(textChanged(const QString&)), this, SLOT(SetFileName(const QString&)) ); connect( m_Input, SIGNAL(textChanged(const QString&)), GetModel(), SLOT(NotifyUpdate()) ); diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputImageListParameter.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputImageListParameter.cxx index 8224946af0c073f5707a8ee268c2e4dfde1ebefa..218e6389d59ea9b0559dd9bc7950e73e839887a1 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputImageListParameter.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputImageListParameter.cxx @@ -20,393 +20,28 @@ #include "otbWrapperQtWidgetInputImageListParameter.h" -namespace otb -{ -namespace Wrapper -{ - -QtWidgetInputImageListParameter::QtWidgetInputImageListParameter(InputImageListParameter* param, QtWidgetModel* m) -: QtWidgetParameterBase(param, m), - m_InputImageListParam(param) -{ - connect(this, SIGNAL(Change()), GetModel(), SLOT(NotifyUpdate())); -} - -QtWidgetInputImageListParameter::~QtWidgetInputImageListParameter() -{ -} - -void QtWidgetInputImageListParameter::DoUpdateGUI() -{ - if(!m_InputImageListParam) - return; - - //update fileSelectionList only if HasUserValue flag is set(from xml) - if(m_InputImageListParam->HasUserValue()) - { - std::vector<std::string> fileList = m_InputImageListParam->GetFileNameList(); - - for( unsigned int i = m_FileSelectionList.size(); i < fileList.size(); i++ ) - { - this->AddFile(); - } - unsigned int i = 0; - std::vector<std::string>::iterator it; - for (it = fileList.begin(); it != fileList.end(); ++it) - { - m_FileSelectionList[i++]->GetInput()->setText( - QFile::decodeName( it->c_str() ) - ); - } - } -} -void QtWidgetInputImageListParameter::DoCreateWidget() -{ - m_FileSelectionList.clear(); - const unsigned int sp(2); - const unsigned int buttonSize(30); - - // Global layout - QHBoxLayout * hLayout = new QHBoxLayout; - hLayout->setSpacing(sp); - hLayout->setContentsMargins(sp, sp, sp, sp); - - // Button layout - QVBoxLayout * buttonLayout = new QVBoxLayout; - buttonLayout->setSpacing(sp); - buttonLayout->setContentsMargins(sp, sp, sp, sp); - - QHBoxLayout * addSupLayout = new QHBoxLayout; - addSupLayout->setSpacing(sp); - addSupLayout->setContentsMargins(sp, sp, sp, sp); - - QHBoxLayout * upDownLayout = new QHBoxLayout; - upDownLayout->setSpacing(sp); - upDownLayout->setContentsMargins(sp, sp, sp, sp); - - // Add file button - QPushButton * addButton = new QPushButton; - addButton->setText("+"); - addButton->setFixedWidth(buttonSize); - addButton->setToolTip("Add a file selector..."); - connect(addButton, SIGNAL(clicked()), this, SLOT(AddFile())); - addSupLayout->addWidget(addButton); - - // Suppress file button - QPushButton * supButton = new QPushButton; - supButton->setText("-"); - supButton->setFixedWidth(buttonSize); - supButton->setToolTip("Suppress the selected file..."); - connect(supButton, SIGNAL(clicked()), this, SLOT(SuppressFile())); - addSupLayout->addWidget(supButton); - buttonLayout->addLayout(addSupLayout); - - // Up file edit - QPushButton * upButton = new QPushButton; - upButton->setText("Up"); - upButton->setFixedWidth(buttonSize); - upButton->setToolTip("Up the selected file in the list..."); - connect(upButton, SIGNAL(clicked()), this, SLOT(UpFile())); - upDownLayout->addWidget(upButton); - - // Down file edit - QPushButton * downButton = new QPushButton; - downButton->setText("Down"); - downButton->setFixedWidth(buttonSize); - downButton->setToolTip("Down the selected file in the list..."); - connect(downButton, SIGNAL(clicked()), this, SLOT(DownFile())); - upDownLayout->addWidget(downButton); - buttonLayout->addLayout(upDownLayout); - - // Erase file edit - QPushButton * eraseButton = new QPushButton; - eraseButton->setText("Erase"); - eraseButton->setFixedWidth(2*(buttonSize+sp)); - eraseButton->setToolTip("Erase the selected file of the list..."); - connect(eraseButton, SIGNAL(clicked()), this, SLOT(EraseFile())); - buttonLayout->addWidget(eraseButton); - - QVBoxLayout * fileLayout = new QVBoxLayout(); - fileLayout->setSpacing(0); - - QtFileSelectionWidget * fileSelection = new QtFileSelectionWidget(); - fileSelection->SetIOMode( QtFileSelectionWidget::IO_MODE_INPUT ); - fileSelection->setFixedHeight(30); - fileLayout->addWidget(fileSelection); - m_InputImageListParam->AddNullElement(); - connect(fileSelection, SIGNAL(FilenameChanged()), this, SLOT(UpdateImageList())); - - m_FileSelectionList.push_back(fileSelection); - - QGroupBox *mainGroup = new QGroupBox(); - mainGroup->setLayout(fileLayout); - QScrollArea * s = new QScrollArea(); - s->setWidget(mainGroup); - s->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - s->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - s->setWidgetResizable(true); - - hLayout->addWidget(s); - hLayout->addLayout(buttonLayout); - - this->setLayout(hLayout); - - m_FileLayout = fileLayout; - m_HLayout = hLayout; - m_Scroll = s; - -} - -void -QtWidgetInputImageListParameter::UpdateImageList() -{ - // Adding a NullElement so to make the m_FileSelectionList and - // m_InputImageList's ImageList are of same size. - for(unsigned int i = m_InputImageListParam->Size(); i < m_FileSelectionList.size(); i++) - { - m_InputImageListParam->AddNullElement(); - } - - for(unsigned int j = 0; j < m_InputImageListParam->Size(); j++) - { - if(m_InputImageListParam->SetNthFileName(j, m_FileSelectionList[j]->GetFilename()) == false) - { - std::ostringstream oss; - oss << "The given file " << m_FileSelectionList[j]->GetFilename() << " is not valid."; - this->GetModel()->SendLogWARNING(oss.str()); - } - } - - emit Change(); - - // notify of value change - QString key(m_InputImageListParam->GetKey()); - emit ParameterChanged(key); -} - -void -QtWidgetInputImageListParameter::UpFile() -{ - if(m_FileSelectionList.size() < 2) - return; - - m_FileLayout = new QVBoxLayout(); - m_FileLayout->setSpacing(2); - - // Map link between old and new index in the list - std::map<unsigned int, unsigned int> idMap; - // Init map - for(unsigned int i = 0; i < m_FileSelectionList.size(); i++) - { - idMap[i] = i; - } - - // If the first item is checked, uncheck it... - // It won't be moved - if(m_FileSelectionList[0]->IsChecked()) - { - m_FileSelectionList[0]->SetChecked(false); - } - - - // If other item are checked, up the index - // Starts at 1 because the first item mustn't move - for(unsigned int i = 1; i < m_FileSelectionList.size(); i++) - { - if(m_FileSelectionList[i]->IsChecked()) - { - unsigned int tmp = idMap[i]; - idMap[i] = i-1; - idMap[idMap[i-1]] = tmp; - } - } - - this->UpdateFileList(idMap); - - this->RecreateImageList(); -} - -void -QtWidgetInputImageListParameter::DownFile() -{ - if(m_FileSelectionList.size() < 2) return; - - m_FileLayout = new QVBoxLayout(); - m_FileLayout->setSpacing(0); - - // Map link between old and new index in the list - std::map<unsigned int, unsigned int> idMap; - - // Init map - for(unsigned int i = 0; i < m_FileSelectionList.size(); i++) - { - idMap[i] = i; - } - - // If the last item is checked, uncheck it... - // It won't be moved - if(m_FileSelectionList[m_FileSelectionList.size() - 1]->IsChecked()) - { - m_FileSelectionList[m_FileSelectionList.size() - 1]->SetChecked(false); - } - - // If other item are checked, up the index - // Stops at size-1 because the last item mustn't move - for(int i = m_FileSelectionList.size() - 2; i >= 0; i--) - { - if(m_FileSelectionList[i]->IsChecked()) - { - unsigned int tmp = idMap[i]; - idMap[i] = i + 1; - idMap[idMap[i + 1]] = tmp; - } - } - - this->UpdateFileList(idMap); - - this->RecreateImageList(); -} - - -void -QtWidgetInputImageListParameter::UpdateFileList(std::map<unsigned int, unsigned int> idMap) +namespace otb { - std::vector<QtFileSelectionWidget *> tmpList; - // Keys become values and inverse - std::map<unsigned int, unsigned int> idMapBis; - for(unsigned int i = 0; i < idMap.size(); i++) - { - idMapBis[idMap[i]] = i; - } - - // Create the new item list - for(unsigned int i = 0; i < m_FileSelectionList.size(); i++) - { - m_FileLayout->addWidget(m_FileSelectionList[idMapBis[i]]); - tmpList.push_back(m_FileSelectionList[idMapBis[i]]); - } - - m_FileSelectionList = tmpList; - QGroupBox *mainGroup = new QGroupBox(); - mainGroup->setLayout(m_FileLayout); - m_Scroll->setWidget(mainGroup); - - this->update(); - // notify of value change - QString key(m_InputImageListParam->GetKey()); - emit ParameterChanged(key); -} - - -void -QtWidgetInputImageListParameter::AddFile() +namespace Wrapper { - m_FileLayout = new QVBoxLayout(); - m_FileLayout->setSpacing(0); - - for(unsigned int i = 0; i < m_FileSelectionList.size(); i++) - { - m_FileLayout->addWidget(m_FileSelectionList[i]); - } - - QtFileSelectionWidget * fileSelection = new QtFileSelectionWidget(); - fileSelection->SetIOMode( QtFileSelectionWidget::IO_MODE_INPUT ); - fileSelection->setFixedHeight(30); - m_FileLayout->addWidget(fileSelection); - m_FileSelectionList.push_back(fileSelection); - /* No need of AddNullElement() here. Moved adding NullElement when updating the list */ - //m_InputImageListParam->AddNullElement(); - connect( - fileSelection, - SIGNAL( FilenameChanged() ), - this, - SLOT( UpdateImageList() ) - ); - QGroupBox *mainGroup = new QGroupBox(); - mainGroup->setLayout(m_FileLayout); - m_Scroll->setWidget(mainGroup); - - this->update(); - - emit FileSelectionWidgetAdded( fileSelection ); -} - -void -QtWidgetInputImageListParameter::SuppressFile() +/*****************************************************************************/ +QtWidgetInputImageListParameter +::QtWidgetInputImageListParameter( InputImageListParameter * param, + QtWidgetModel * m ) : + QtWidgetParameterList( param, m ) { - m_FileLayout = new QVBoxLayout(); - m_FileLayout->setSpacing(0); - std::vector<QtFileSelectionWidget *> tmpList; - for(unsigned int i = 0; i < m_FileSelectionList.size(); i++) - { - if(!m_FileSelectionList[i]->IsChecked()) - { - m_FileLayout->addWidget(m_FileSelectionList[i]); - tmpList.push_back(m_FileSelectionList[i]); - } - } - - m_FileSelectionList = tmpList; - - QGroupBox *mainGroup = new QGroupBox(); - mainGroup->setLayout(m_FileLayout); - m_Scroll->setWidget(mainGroup); - - this->update(); - this->RecreateImageList(); } -void -QtWidgetInputImageListParameter::EraseFile() +/*****************************************************************************/ +QtWidgetInputImageListParameter +::~QtWidgetInputImageListParameter() { - m_FileSelectionList.clear(); - - m_FileLayout = new QVBoxLayout(); - - QtFileSelectionWidget * fileSelection = new QtFileSelectionWidget(); - fileSelection->SetIOMode( QtFileSelectionWidget::IO_MODE_INPUT ); - fileSelection->setFixedHeight(30); - m_FileLayout->addWidget(fileSelection); - m_FileSelectionList.push_back(fileSelection); - m_InputImageListParam->AddNullElement(); - connect(fileSelection, SIGNAL(FilenameChanged()), this, SLOT(UpdateImageList())); - - QGroupBox *mainGroup = new QGroupBox(); - mainGroup->setLayout(m_FileLayout); - m_Scroll->setWidget(mainGroup); - - this->update(); - this->RecreateImageList(); } -void QtWidgetInputImageListParameter::RecreateImageList() -{ - // save value - m_InputImageListParam->ClearValue(); - - if(m_FileSelectionList.size() == 0) - { - this->AddFile(); - } - else - { - for(unsigned int j = 0; j < m_FileSelectionList.size(); j++) - { - m_InputImageListParam->AddFromFileName(m_FileSelectionList[j]->GetFilename()); - connect(m_FileSelectionList[j], SIGNAL(FilenameChanged()), this, SLOT(UpdateImageList())); - } - - emit Change(); - // notify of value change - QString key(m_InputImageListParam->GetKey()); - emit ParameterChanged(key); - } } - -} } diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputImageParameter.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputImageParameter.cxx index e41c35dc01c1ede50efab19452972e0970abd9ce..8f9873bbbd81fcc3023d54899d0ec5e92cf32229 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputImageParameter.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputImageParameter.cxx @@ -68,7 +68,11 @@ void QtWidgetInputImageParameter::DoCreateWidget() m_HLayout->setSpacing(0); m_HLayout->setContentsMargins(0, 0, 0, 0); m_Input = new QLineEdit; - m_Input->setToolTip( m_InputImageParam->GetDescription() ); + + m_Input->setToolTip( + QString::fromStdString( m_InputImageParam->GetDescription() ) + ); + connect( m_Input, SIGNAL(editingFinished()), this, SLOT(OnEditingFinished()) ); connect( this, SIGNAL(FileNameIsSet()), GetModel(), SLOT(NotifyUpdate()) ); diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputProcessXMLParameter.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputProcessXMLParameter.cxx index bd72303cccda39728fe3843acfc64a7c68a1e431..9229d584f77997a4764941f5a4cccbcc54d6810a 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputProcessXMLParameter.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputProcessXMLParameter.cxx @@ -60,7 +60,9 @@ void QtWidgetInputProcessXMLParameter::DoCreateWidget() m_HLayout->setSpacing(0); m_HLayout->setContentsMargins(0, 0, 0, 0); m_Input = new QLineEdit; - m_Input->setToolTip( m_XMLParam->GetDescription() ); + m_Input->setToolTip( + QString::fromStdString( m_XMLParam->GetDescription() ) + ); connect( m_Input, SIGNAL(textChanged(const QString&)), this, SLOT(SetFileName(const QString&)) ); connect( m_Input, SIGNAL(textChanged(const QString&)), GetModel(), SLOT(NotifyUpdate()) ); diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputVectorDataListParameter.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputVectorDataListParameter.cxx index fd8cdad935c4ceaea5cac3572e01ae82210deddb..e4184c55351b546ef977bc453176679d5bc0fc97 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputVectorDataListParameter.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputVectorDataListParameter.cxx @@ -20,380 +20,32 @@ #include "otbWrapperQtWidgetInputVectorDataListParameter.h" -namespace otb -{ -namespace Wrapper -{ - -QtWidgetInputVectorDataListParameter::QtWidgetInputVectorDataListParameter(InputVectorDataListParameter* param, - QtWidgetModel* m) -: QtWidgetParameterBase(param, m), - m_InputVectorDataListParam(param) -{ - connect(this, SIGNAL(Change()), GetModel(), SLOT(NotifyUpdate())); -} - -QtWidgetInputVectorDataListParameter::~QtWidgetInputVectorDataListParameter() -{ -} - -void QtWidgetInputVectorDataListParameter::DoUpdateGUI() -{ - if(!m_InputVectorDataListParam) - return; - - std::vector<std::string> fileList = m_InputVectorDataListParam->GetFileNameList(); - for( unsigned int i = m_FileSelectionList.size(); i < fileList.size(); i++ ) - { - this->AddFile(); - } - int i = 0; - std::vector<std::string>::iterator it; - for (it = fileList.begin(); it != fileList.end(); ++it) - { - m_FileSelectionList[i++]->GetInput()->setText( - QFile::decodeName( it->c_str() ) - ); - } -} - -void QtWidgetInputVectorDataListParameter::DoCreateWidget() -{ - m_FileSelectionList.clear(); - const unsigned int sp(2); - const unsigned int buttonSize(30); - - // Global layout - QHBoxLayout * hLayout = new QHBoxLayout; - hLayout->setSpacing(sp); - hLayout->setContentsMargins(sp, sp, sp, sp); - - // Button layout - QVBoxLayout * buttonLayout = new QVBoxLayout; - buttonLayout->setSpacing(sp); - buttonLayout->setContentsMargins(sp, sp, sp, sp); - - QHBoxLayout * addSupLayout = new QHBoxLayout; - addSupLayout->setSpacing(sp); - addSupLayout->setContentsMargins(sp, sp, sp, sp); - - QHBoxLayout * upDownLayout = new QHBoxLayout; - upDownLayout->setSpacing(sp); - upDownLayout->setContentsMargins(sp, sp, sp, sp); - - // Add file button - QPushButton * addButton = new QPushButton; - addButton->setText("+"); - addButton->setFixedWidth(buttonSize); - addButton->setToolTip("Add a file selector..."); - connect(addButton, SIGNAL(clicked()), this, SLOT(AddFile())); - addSupLayout->addWidget(addButton); - - // Suppress file button - QPushButton * supButton = new QPushButton; - supButton->setText("-"); - supButton->setFixedWidth(buttonSize); - supButton->setToolTip("Suppress the selected file..."); - connect(supButton, SIGNAL(clicked()), this, SLOT(SuppressFile())); - addSupLayout->addWidget(supButton); - buttonLayout->addLayout(addSupLayout); - - // Up file edit - QPushButton * upButton = new QPushButton; - upButton->setText("Up"); - upButton->setFixedWidth(buttonSize); - upButton->setToolTip("Up the selected file in the list..."); - connect(upButton, SIGNAL(clicked()), this, SLOT(UpFile())); - upDownLayout->addWidget(upButton); - - // Down file edit - QPushButton * downButton = new QPushButton; - downButton->setText("Down"); - downButton->setFixedWidth(buttonSize); - downButton->setToolTip("Down the selected file in the list..."); - connect(downButton, SIGNAL(clicked()), this, SLOT(DownFile())); - upDownLayout->addWidget(downButton); - buttonLayout->addLayout(upDownLayout); - - // Erase file edit - QPushButton * eraseButton = new QPushButton; - eraseButton->setText("Erase"); - eraseButton->setFixedWidth(2*(buttonSize+sp)); - eraseButton->setToolTip("Erase the selected file of the list..."); - connect(eraseButton, SIGNAL(clicked()), this, SLOT(EraseFile())); - buttonLayout->addWidget(eraseButton); - - QVBoxLayout * fileLayout = new QVBoxLayout(); - fileLayout->setSpacing(0); - - QtFileSelectionWidget * fileSelection = new QtFileSelectionWidget(); - fileSelection->SetIOMode( QtFileSelectionWidget::IO_MODE_INPUT ); - fileSelection->setFixedHeight(30); - fileLayout->addWidget(fileSelection); - m_InputVectorDataListParam->AddNullElement(); - connect(fileSelection->GetInput(), SIGNAL(textChanged(const QString&)), this, SLOT(UpdateVectorDataList())); - - m_FileSelectionList.push_back(fileSelection); - - QGroupBox *mainGroup = new QGroupBox(); - mainGroup->setLayout(fileLayout); - QScrollArea * scroll2 = new QScrollArea(); - scroll2->setWidget(mainGroup); - scroll2->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - scroll2->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - scroll2->setWidgetResizable(true); - - hLayout->addWidget(scroll2); - hLayout->addLayout(buttonLayout); - - this->setLayout(hLayout); - - m_FileLayout = fileLayout; - m_HLayout = hLayout; - m_Scroll = scroll2; - -} - -void -QtWidgetInputVectorDataListParameter::UpdateVectorDataList() -{ - for(unsigned int j = 0; j < m_InputVectorDataListParam->GetVectorDataList()->Size(); j++) - { - if(m_InputVectorDataListParam->SetNthFileName(j, m_FileSelectionList[j]->GetFilename()) == false) - { - std::ostringstream oss; - oss << "The given file " << m_FileSelectionList[j]->GetFilename() << " is not valid."; - this->GetModel()->SendLogWARNING(oss.str()); - } - } - - emit Change(); - - // notify of value change - QString key(m_InputVectorDataListParam->GetKey()); - emit ParameterChanged(key); -} - - -void -QtWidgetInputVectorDataListParameter::UpFile() -{ - if(m_FileSelectionList.size() < 2) - return; - - m_FileLayout = new QVBoxLayout(); - m_FileLayout->setSpacing(2); - // Map link between old and new index in the list - std::map<unsigned int, unsigned int> idMap; +#include "otbWrapperInputVectorDataListParameter.h" - // Init map - for(unsigned int i = 0; i < m_FileSelectionList.size(); i++) - { - idMap[i] = i; - } - - // If the first item is checked, uncheck it... - // It won't be moved - if(m_FileSelectionList[0]->IsChecked()) - { - m_FileSelectionList[0]->SetChecked(false); - } - - - // If other item are checked, up the index - // Starts at 1 because the first item mustn't move - for(unsigned int i = 1; i < m_FileSelectionList.size(); i++) - { - if(m_FileSelectionList[i]->IsChecked()) - { - unsigned int tmp = idMap[i]; - idMap[i] = i-1; - idMap[idMap[i-1]] = tmp; - } - } - - this->UpdateFileList(idMap); - - this->RecreateVectorDataList(); -} - -void -QtWidgetInputVectorDataListParameter::DownFile() -{ - if(m_FileSelectionList.size() < 2) return; - - m_FileLayout = new QVBoxLayout(); - m_FileLayout->setSpacing(0); - - // Map link between old and new index in the list - std::map<unsigned int, unsigned int> idMap; - - // Init map - for(unsigned int i = 0; i < m_FileSelectionList.size(); i++) - { - idMap[i] = i; - } - - // If the last item is checked, uncheck it... - // It won't be moved - if(m_FileSelectionList[m_FileSelectionList.size() - 1]->IsChecked()) - { - m_FileSelectionList[m_FileSelectionList.size() - 1]->SetChecked(false); - } - - // If other item are checked, up the index - // Stops at size-1 because the last item mustn't move - for(int i = m_FileSelectionList.size() - 2; i >= 0; i--) - { - if(m_FileSelectionList[i]->IsChecked()) - { - unsigned int tmp = idMap[i]; - idMap[i] = i + 1; - idMap[idMap[i + 1]] = tmp; - } - } - - this->UpdateFileList(idMap); - - this->RecreateVectorDataList(); -} - - -void -QtWidgetInputVectorDataListParameter::UpdateFileList(std::map<unsigned int, unsigned int> idMap) +namespace otb { - std::vector<QtFileSelectionWidget *> tmpList; - // Keys become values and inverse - std::map<unsigned int, unsigned int> idMapBis; - for(unsigned int i = 0; i < idMap.size(); i++) - { - idMapBis[idMap[i]] = i; - } - - // Create the new item list - for(unsigned int i = 0; i < m_FileSelectionList.size(); i++) - { - m_FileLayout->addWidget(m_FileSelectionList[idMapBis[i]]); - tmpList.push_back(m_FileSelectionList[idMapBis[i]]); - } - m_FileSelectionList = tmpList; - QGroupBox *mainGroup = new QGroupBox(); - mainGroup->setLayout(m_FileLayout); - m_Scroll->setWidget(mainGroup); - this->update(); - - // notify of value change - QString key(m_InputVectorDataListParam->GetKey()); - emit ParameterChanged(key); -} - - -void -QtWidgetInputVectorDataListParameter::AddFile() +namespace Wrapper { - m_FileLayout = new QVBoxLayout(); - m_FileLayout->setSpacing(0); - - for(unsigned int i = 0; i < m_FileSelectionList.size(); i++) - { - m_FileLayout->addWidget(m_FileSelectionList[i]); - } - - QtFileSelectionWidget * fileSelection = new QtFileSelectionWidget(); - fileSelection->SetIOMode( QtFileSelectionWidget::IO_MODE_INPUT ); - fileSelection->setFixedHeight(30); - m_FileLayout->addWidget(fileSelection); - m_FileSelectionList.push_back(fileSelection); - m_InputVectorDataListParam->AddNullElement(); - connect(fileSelection->GetInput(), SIGNAL(textChanged(const QString&)), this, SLOT(UpdateVectorDataList())); - - QGroupBox *mainGroup = new QGroupBox(); - mainGroup->setLayout(m_FileLayout); - m_Scroll->setWidget(mainGroup); - this->update(); - emit FileSelectionWidgetAdded( fileSelection ); -} - -void -QtWidgetInputVectorDataListParameter::SuppressFile() +/*****************************************************************************/ +QtWidgetInputVectorDataListParameter +::QtWidgetInputVectorDataListParameter( InputVectorDataListParameter * param, + QtWidgetModel* m ) : + QtWidgetParameterList( param, m ) { - m_FileLayout = new QVBoxLayout(); - m_FileLayout->setSpacing(0); - std::vector<QtFileSelectionWidget *> tmpList; - for(unsigned int i = 0; i < m_FileSelectionList.size(); i++) - { - if(!m_FileSelectionList[i]->IsChecked()) - { - m_FileLayout->addWidget(m_FileSelectionList[i]); - tmpList.push_back(m_FileSelectionList[i]); - } - } - - m_FileSelectionList = tmpList; - - QGroupBox *mainGroup = new QGroupBox(); - mainGroup->setLayout(m_FileLayout); - m_Scroll->setWidget(mainGroup); - - this->update(); - this->RecreateVectorDataList(); } - -void -QtWidgetInputVectorDataListParameter::EraseFile() +/*****************************************************************************/ +QtWidgetInputVectorDataListParameter +::~QtWidgetInputVectorDataListParameter() { - m_FileSelectionList.clear(); - - m_FileLayout = new QVBoxLayout(); - - QtFileSelectionWidget * fileSelection = new QtFileSelectionWidget(); - fileSelection->SetIOMode( QtFileSelectionWidget::IO_MODE_INPUT ); - fileSelection->setFixedHeight(30); - m_FileLayout->addWidget(fileSelection); - m_FileSelectionList.push_back(fileSelection); - m_InputVectorDataListParam->AddNullElement(); - connect(fileSelection->GetInput(), SIGNAL(textChanged(const QString&)), this, SLOT(UpdateVectorDataList())); - - QGroupBox *mainGroup = new QGroupBox(); - mainGroup->setLayout(m_FileLayout); - m_Scroll->setWidget(mainGroup); - - this->update(); - this->RecreateVectorDataList(); } -void QtWidgetInputVectorDataListParameter::RecreateVectorDataList() -{ - // save value - m_InputVectorDataListParam->ClearValue(); - - if(m_FileSelectionList.size() == 0) - { - this->AddFile(); - } - else - { - for(unsigned int j = 0; j < m_FileSelectionList.size(); j++) - { - 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(m_InputVectorDataListParam->GetKey()); - emit ParameterChanged(key); - } } - -} } diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputVectorDataParameter.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputVectorDataParameter.cxx index 3fd1a551120fc3c38d4a1f23b019bccac9b762cd..26c6e54af87acfacc9f65b531cd6b10b703de3f9 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputVectorDataParameter.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetInputVectorDataParameter.cxx @@ -61,7 +61,9 @@ void QtWidgetInputVectorDataParameter::DoCreateWidget() m_HLayout->setSpacing(0); m_HLayout->setContentsMargins(0, 0, 0, 0); m_Input = new QLineEdit; - m_Input->setToolTip( m_InputVectorDataParam->GetDescription() ); + m_Input->setToolTip( + QString::fromStdString( m_InputVectorDataParam->GetDescription() ) + ); connect( m_Input, SIGNAL(textChanged(const QString&)), this, SLOT(SetFileName(const QString&)) ); connect( m_Input, SIGNAL(textChanged(const QString&)), GetModel(), SLOT(NotifyUpdate()) ); diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetIntParameter.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetIntParameter.cxx index 2d4e7b1e02a0eee668934f83ab65e8c2ff50ed68..052c919a63ea9e33b37eaf2ce9627ccdf68ed80e 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetIntParameter.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetIntParameter.cxx @@ -44,7 +44,9 @@ void QtWidgetIntParameter::DoCreateWidget() m_QSpinBox = new QSpinBox; m_QSpinBox->setRange(m_IntParam->GetMinimumValue(), m_IntParam->GetMaximumValue()); - m_QSpinBox->setToolTip(m_IntParam->GetDescription()); + m_QSpinBox->setToolTip( + QString::fromStdString( m_IntParam->GetDescription() ) + ); connect( m_QSpinBox, SIGNAL(valueChanged(int)), this, SLOT(SetValue(int)) ); connect( m_QSpinBox, SIGNAL(valueChanged(int)), GetModel(), SLOT(NotifyUpdate()) ); diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetListEditItemModel.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetListEditItemModel.cxx new file mode 100644 index 0000000000000000000000000000000000000000..b0ec1d5a917f34631be67042048eae6edd1b4cee --- /dev/null +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetListEditItemModel.cxx @@ -0,0 +1,483 @@ +/* + * Copyright (C) 2005-2017 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 "otbWrapperQtWidgetListEditItemModel.h" + + +/*****************************************************************************/ +/* INCLUDE SECTION */ + +// +// Qt includes (sorted by alphabetic order) +//// Must be included before system/custom includes. + +// +// System includes (sorted by alphabetic order) + +// +// ITK includes (sorted by alphabetic order) + +// +// OTB includes (sorted by alphabetic order) + +#include "otbWrapperStringListInterface.h" + + +namespace otb +{ + +namespace Wrapper +{ + +/* + TRANSLATOR otb::Wapper::ListEditItemModel + + Necessary for lupdate to be aware of C++ namespaces. + + Context comment for translator. +*/ + + +/*****************************************************************************/ +/* CONSTANTS */ + +namespace +{ + +const char * const +HEADERS[ ListEditItemModel::COLUMN_COUNT ] = +{ + QT_TRANSLATE_NOOP( "otb::Wrapper::ListEditItemModel", "Name" ), + // QT_TRANSLATE_NOOP( "otb::Wrapper::ListEditItemModel", "Browse" ), +}; + +} // end of anonymous namespace. + + +/*****************************************************************************/ +/* STATIC IMPLEMENTATION SECTION */ + + +/*****************************************************************************/ +/* CLASS IMPLEMENTATION SECTION */ + +/*******************************************************************************/ +ListEditItemModel +::ListEditItemModel( StringListInterface * sli, + QObject * p ) : + QAbstractItemModel( p ), + m_StringList( sli ) +{ + assert( sli!=nullptr ); +} + +/*******************************************************************************/ +ListEditItemModel +::~ListEditItemModel() +{ +} + +/*****************************************************************************/ +/* QAbstractItemModel overloads */ +/*****************************************************************************/ +int +ListEditItemModel +::columnCount( const QModelIndex & ) const +{ + // qDebug() << this << "::columnCount(" << parent << ")"; + + return COLUMN_COUNT; +} + +/*****************************************************************************/ +QVariant +ListEditItemModel +::data( const QModelIndex & idx, int role ) const +{ + // qDebug() << this << "::data(" << idx << "," << role << ")"; + + // Get layer. + assert( m_StringList!=NULL ); + + assert( idx.isValid() ); + assert( !idx.parent().isValid() ); + assert( idx.internalPointer()!=NULL ); + + const StringListInterface * stringList = + static_cast< const StringListInterface * >( idx.internalPointer() ); + + assert( stringList!=nullptr ); + + // Return data given role. + switch( role ) + { + case Qt::CheckStateRole: +#if 0 + if( idx.column()!=COLUMN_NAME ) + return QVariant(); + else + { + assert( idx.row() >= 0 ); + return stringList->IsActive( idx.row() ); + } +#endif + break; + + case Qt::EditRole: + case Qt::DisplayRole: + switch( idx.column() ) + { + case COLUMN_NAME: + { + assert( idx.row() >= 0 ); + + std::string filename( + stringList->GetNthFileName( idx.row() ) + ); + + // qDebug() << "Filename:" << QString( "%1" ).arg( filename.c_str() ); + + return + filename.empty() + ? ( role==Qt::EditRole ? QString() : "EMPTY" ) + : QFile::decodeName( filename.c_str() + ); + } + break; + + default: + break; + } + break; + + case Qt::FontRole: + break; + + case Qt::ToolTipRole: + switch( idx.column() ) + { + case COLUMN_NAME: + assert( idx.row() >= 0 ); + return QString::fromStdString( stringList->GetToolTip( idx.row() ) ); + break; + } + break; + + case USER_ROLE_DIRECTION: + assert( idx.row()>=0 ); + return stringList->GetDirection( idx.row() ); + break; + + case USER_ROLE_FILTER: + assert( idx.row()>=0 ); + return QString::fromStdString( stringList->GetFilenameFilter( idx.row() ) ); + break; + + default: + break; + } + + return QVariant(); +} + +/*****************************************************************************/ +Qt::ItemFlags +ListEditItemModel +::flags( const QModelIndex & idx ) const +{ + if( !idx.isValid() ) + return QAbstractItemModel::flags( idx ); + + Qt::ItemFlags iflags = + QAbstractItemModel::flags( idx ) + // | Qt::ItemIsDragEnabled + // | Qt::ItemIsDropEnabled + ; + + if( idx.column()==COLUMN_NAME ) + iflags |= + Qt::ItemIsEditable + // | Qt::ItemIsUserCheckable + // | Qt::ItemIsDragEnabled + ; + + return iflags; +} + +/*****************************************************************************/ +bool +ListEditItemModel +::hasChildren( const QModelIndex & idx ) const +{ + return !idx.isValid(); +} + +/*****************************************************************************/ +QVariant +ListEditItemModel +::headerData( int section, + Qt::Orientation /**orientation*/, + int role ) const +{ + // qDebug() + // << this << "::headerData(" + // << section << "," << orientation << "," << role + // << ")"; + + // assert( orientation==Qt::Horizontal ); + + switch( role ) + { + case Qt::DisplayRole: + assert( section>=0 && section<COLUMN_COUNT ); + return tr( HEADERS[ section ] ); + break; + + default: + break; + } + + return QVariant(); +} + +/*****************************************************************************/ +QModelIndex +ListEditItemModel +::index( int row, + int column, + const QModelIndex & p ) const +{ + // qDebug() + // << this << "::index(" << row << "," << column << "," << parent << ")"; + + if( m_StringList == nullptr ) + return QModelIndex(); + + // qDebug() + // << "index:" << row << "," << column << "," << m_StringList->At( row ); + + assert( row>=0 && column>=0 ); + +#if 0 + AbstractLayerModel * layer = m_StringList->At( row ); + + if( layer==NULL || p.isValid() ) + return QModelIndex(); +#endif + + return + createIndex( + row, + column, + p.isValid() + ? NULL + : m_StringList + ); +} + +/*****************************************************************************/ +bool +ListEditItemModel +::insertRow( int row, const QModelIndex & idxParent ) +{ + return insertRows( row, 1, idxParent ); +} + +/*****************************************************************************/ +bool +ListEditItemModel +::insertRows( int row, int count, const QModelIndex & idxParent ) +{ + // qDebug() << this << "::insertRows(" << row << "," << count << "," << idxParent << ")"; + + assert( m_StringList!=nullptr ); + + beginInsertRows( idxParent, row, count ); + { + for( int r=row; r<row+count; ++r ) + m_StringList->Insert( "", r ); + } + endInsertRows(); + + return true; +} + +/*****************************************************************************/ +QModelIndex +ListEditItemModel +::parent( const QModelIndex & ) const +{ + // qDebug() << this << "::parent(" << index << ")"; + + return QModelIndex(); +} + +/*****************************************************************************/ +bool +ListEditItemModel +::removeRows( int row, int count, const QModelIndex & p ) +{ + assert( !p.isValid() ); + assert( count>=1 ); + + if( p.isValid() || count<1 ) + return false; + + assert( m_StringList!=nullptr ); + + beginRemoveRows( p, row, row + count - 1 ); + { + m_StringList->Erase( row, count ); + } + endRemoveRows(); + + return true; +} + +/*****************************************************************************/ +int +ListEditItemModel +::rowCount( const QModelIndex & p ) const +{ + // qDebug() << this << "::rowCount(" << p << ")"; + + // qDebug() << "row-count:" << + // ( ( m_StringList==NULL || p.isValid() ) + // ? 0 + // : m_StringList->GetCount() + // ); + + return + ( m_StringList==nullptr || p.isValid() ) + ? 0 + : m_StringList->Size(); +} + +/*****************************************************************************/ +bool +ListEditItemModel +::setData( const QModelIndex & idx, + const QVariant & value, + int role ) +{ + // qDebug() + // << this << "::setData(" << idx << "," << value << "," << role + // << ");"; + + assert( !idx.parent().isValid() ); + assert( idx.row()>=0 ); + assert( idx.internalPointer()!=nullptr ); + + StringListInterface * stringList = + static_cast< StringListInterface * >( idx.internalPointer() ); + + switch( idx.column() ) + { + case COLUMN_NAME: + switch( role ) + { + case Qt::EditRole: + stringList->SetNthFileName( + idx.row(), + QFile::encodeName( value.toString() ).data() + ); + emit dataChanged( idx, idx ); + return true; + break; + + case Qt::CheckStateRole: + break; + + case USER_ROLE_DIRECTION: + break; + + default: + break; + } + break; + + default: + break; + } + + return false; +} + +/*******************************************************************************/ +bool +ListEditItemModel +::Swap( int row1, int row2 ) +{ + assert( m_StringList!=nullptr ); + + assert( row1>=0 ); + assert( static_cast< unsigned int >( row1 )<m_StringList->Size() ); + + assert( row2>=0 ); + assert( static_cast< unsigned int >( row2 )<m_StringList->Size() ); + + assert( row1!=row2 ); + + emit layoutAboutToBeChanged(); + + m_StringList->Swap( row1, row2 ); + + emit layoutChanged(); + + return true; +} + +/*******************************************************************************/ +bool +ListEditItemModel +::IsInput() const +{ + assert( m_StringList!=nullptr ); + + return m_StringList->GetDirection()==Role_Input; +} + +/*******************************************************************************/ +bool +ListEditItemModel +::IsBrowsable() const +{ + assert( m_StringList!=nullptr ); + + return m_StringList->IsFilename(); +} + +/*******************************************************************************/ +QString +ListEditItemModel +::GetFilter() const +{ + assert( m_StringList!=nullptr ); + + return QString::fromStdString( m_StringList->GetFilenameFilter() ); +} + +/*******************************************************************************/ +/* SLOTS */ +/*******************************************************************************/ + +} // end namespace 'Wrapper'. + +} // end namespace 'otb' diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetListEditWidget.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetListEditWidget.cxx new file mode 100644 index 0000000000000000000000000000000000000000..f2b1524dc9a3f080e8dfd18a02ada040db381ea7 --- /dev/null +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetListEditWidget.cxx @@ -0,0 +1,657 @@ +/* + * Copyright (C) 2005-2017 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 "otbWrapperQtWidgetListEditWidget.h" +#include "ui_otbWrapperQtWidgetListEditWidget.h" + + +/*****************************************************************************/ +/* INCLUDE SECTION */ + +// +// Qt includes (sorted by alphabetic order) +//// Must be included before system/custom includes. + +// +// System includes (sorted by alphabetic order) + +// +// ITK includes (sorted by alphabetic order) + +// +// OTB includes (sorted by alphabetic order) +#include "otbQtAdapters.h" +#include "otbWrapperQtWidgetListEditItemModel.h" +#include "otbWrapperTypes.h" + +namespace otb +{ + +namespace Wrapper +{ + +/* + TRANSLATOR otn::Wrappers + + Necessary for lupdate to be aware of C++ namespaces. + + Context comment for translator. +*/ + + +/*****************************************************************************/ +/* CONSTANTS */ + + +/*****************************************************************************/ +/* STATIC IMPLEMENTATION SECTION */ + + +/*****************************************************************************/ +/* CLASS IMPLEMENTATION SECTION */ +/*****************************************************************************/ +ListEditWidget +::ListEditWidget( StringListInterface * sli, + QWidget * p, + Qt::WindowFlags flags ) : + QWidget( p, flags ), + m_UI( new otb::Wrapper::Ui::ListEditWidget() ) +{ + m_UI->setupUi( this ); + + setAcceptDrops(true); + + assert( m_UI->treeView->selectionModel()==nullptr ); + + // + // Item-model. + ListEditItemModel * model = new ListEditItemModel( sli, m_UI->treeView ); + + m_UI->treeView->setModel( model ); + + QObject::connect( + model, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex & ) ), + this, SLOT( OnDataChanged( const QModelIndex &, const QModelIndex & ) ) + ); + + QObject::connect( + model, SIGNAL( modelReset() ), + this, SLOT( OnModelReset() ) + ); + + QObject::connect( + model, SIGNAL( rowsInserted( const QModelIndex &, int, int ) ), + this, SLOT( OnRowsInserted( const QModelIndex &, int, int ) ) + ); + + QObject::connect( + model, SIGNAL( rowsRemoved( const QModelIndex &, int, int ) ), + this, SLOT( OnRowsRemoved( const QModelIndex &, int, int ) ) + ); + + // + // Selection-model. + assert( m_UI->treeView->selectionModel()!=nullptr ); + + QObject::connect( + m_UI->treeView->selectionModel(), + SIGNAL( + selectionChanged( const QItemSelection & , const QItemSelection & ) + ), + // to: + this, + SLOT( + OnSelectionChanged( const QItemSelection & , const QItemSelection & ) + ) + ); + + // + // Browse-button. + assert( m_UI->browseButton!=nullptr ); + + m_UI->browseButton->setEnabled( model->IsBrowsable() ); +} + +/*******************************************************************************/ +ListEditWidget +::~ListEditWidget() +{ + delete m_UI; + m_UI = nullptr; +} + +#if 0 + +/*****************************************************************************/ +void +ListEditWidget +::SetBrowseEnabled( bool enabled ) +{ + assert( m_UI!=nullptr ); + assert( m_UI->browseButton ); + + m_UI->browseButton->setEnabled( enabled ); +} + +/*******************************************************************************/ +bool +ListEditWidget +::IsBrowseEnabled() const +{ + assert( m_UI!=nullptr ); + assert( m_UI->browseButton ); + + return m_UI->browseButton->isEnabled(); +} + +#endif + +/*******************************************************************************/ +const ListEditItemModel * +ListEditWidget +::GetItemModel() const +{ + return const_cast< ListEditWidget * >( this )->GetItemModel(); +} + +/*******************************************************************************/ +ListEditItemModel * +ListEditWidget +::GetItemModel() +{ + assert( + m_UI->treeView->model()== + qobject_cast< ListEditItemModel * >( m_UI->treeView->model() ) + ); + + return qobject_cast< ListEditItemModel * >( m_UI->treeView->model() ); +} + +/*******************************************************************************/ +void +ListEditWidget +::Swap( int row1, int row2, SwapSelection s ) +{ + assert( GetItemModel()!=nullptr ); + + assert( row1>=0 ); + assert( row1<GetItemModel()->rowCount() ); + + assert( row2>=0 ); + assert( row2<GetItemModel()->rowCount() ); + + + ListEditItemModel * itemModel = GetItemModel(); + + assert( itemModel!=nullptr ); + + + itemModel->Swap( row1, row2 ); + + + { + int row = + s==LEFT + ? row1 + : ( s==RIGHT + ? row2 + : -1 ); + + if( row<0 ) + return; + + assert( m_UI!=nullptr ); + assert( m_UI->treeView!=nullptr ); + assert( m_UI->treeView->selectionModel()!=nullptr ); + + QItemSelectionModel * ism = m_UI->treeView->selectionModel(); + + assert( ism!=nullptr ); + + ism->clear(); + + ism->setCurrentIndex( + itemModel->index( row, ListEditItemModel::COLUMN_NAME ), + QItemSelectionModel::Clear | + QItemSelectionModel::Select | + QItemSelectionModel::Current | + QItemSelectionModel::Rows + ); + } +} + +/*******************************************************************************/ +QStringList +ListEditWidget +::browseFilenames( bool multi , const QString & filename ) +{ + const ListEditItemModel * itemModel = GetItemModel(); + assert( itemModel!=nullptr ); + + QString filePath( + QDir::current().filePath( + filename + ) + ); + + QString selectedFilter; + QStringList output; + if(itemModel->IsInput()) + { + if (multi) + { + output = GetOpenFileNames( + this, + tr( "Select input filename..." ), + filePath, + itemModel->GetFilter(), + &selectedFilter + ); + } + else + { + output.push_back( + GetOpenFileName( + this, + tr( "Select input filename..." ), + filePath, + itemModel->GetFilter(), + &selectedFilter + ) + ); + } + } + else + { + output.push_back( + GetSaveFileName( + this, + tr( "Select output filename..." ), + filePath, + itemModel->GetFilter(), + &selectedFilter + ) + ); + } + return output; +} + +/*******************************************************************************/ +QString +ListEditWidget +::browseFilename( const QModelIndex & index ) +{ + assert( index.isValid() ); + assert( index.row()>=0 ); + assert( index.column()>=0 ); + + // + // Get item-model. + const ListEditItemModel * itemModel = GetItemModel(); + assert( itemModel!=nullptr ); + + // + // Pick-up filename. + assert( + itemModel->data( index, ListEditItemModel::USER_ROLE_DIRECTION ).isValid() + ); + + assert( + itemModel->data( index, ListEditItemModel::USER_ROLE_DIRECTION )==Role_Input + || + itemModel->data( index, ListEditItemModel::USER_ROLE_DIRECTION )==Role_Output + ); + + return + (browseFilenames( false, itemModel->data( index ).toString() )).front(); +} + + +/*******************************************************************************/ +/* SLOTS */ +/*******************************************************************************/ +void +ListEditWidget +::OnFilenameDropped(const QString & filename) +{ + ListEditItemModel * itemModel = GetItemModel(); + assert( itemModel!=nullptr ); + + if( filename.isEmpty() ) + return; + + int row = itemModel->rowCount(); + assert( row>=0 ); + + if( !itemModel->insertRow( row ) ) + return; + + itemModel->setData( + itemModel->index( row, ListEditItemModel::COLUMN_NAME ), + filename + ); +} + + +void +ListEditWidget +::on_addButton_clicked() +{ + // qDebug() << this << "::on_addButton_clicked()"; + + ListEditItemModel * itemModel = GetItemModel(); + assert( itemModel!=nullptr ); + + // + // When not browsable + if( !itemModel->IsBrowsable() ) + { + itemModel->insertRow( itemModel->rowCount() ); + + return; + } + + // + // When browsable. + QStringList filenames( browseFilenames(true) ); + + if( filenames.isEmpty() ) + return; + + int row = itemModel->rowCount(); + assert( row>=0 ); + + for (int i=0 ; i<filenames.size() ; i++) + { + if( !itemModel->insertRow( row ) ) + return; + + itemModel->setData( + itemModel->index( row, ListEditItemModel::COLUMN_NAME ), + filenames[i] + ); + row++; + } +} + +/*******************************************************************************/ +void +ListEditWidget +::on_removeButton_clicked() +{ + // qDebug() << this << "::on_removeButton_clicked()"; + + assert( m_UI->treeView->selectionModel()!=nullptr ); + + + QModelIndexList indexes( + m_UI->treeView->selectionModel()->selectedRows() + ); + + if( indexes.empty() ) + return; + + + ListEditItemModel * itemModel = GetItemModel(); + + assert( itemModel!=nullptr ); + + + for( const QModelIndex & i : indexes ) + { + assert( i.isValid() ); + + itemModel->removeRow( i.row() ); + } +} + +/*******************************************************************************/ +void +ListEditWidget +::on_removeAllButton_clicked() +{ + // qDebug() << this << "::on_removeAllButton_clicked()"; + + ListEditItemModel * model = GetItemModel(); + assert( model ); + + if( model->rowCount()<1 ) + return; + + assert( qApp ); + assert( !qApp->applicationName().isEmpty() ); + + if( QMessageBox::question( + this, + qApp->applicationName(), + tr("Are you sure you want to delete all (%1) item(s)?") + .arg( model->rowCount() ), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::No + ) + ==QMessageBox::No ) + return; + + model->removeRows( 0, model->rowCount() ); +} + +/*******************************************************************************/ +void +ListEditWidget +::on_upButton_clicked() +{ + // qDebug() << this << "::on_upButton_clicked()"; + + assert( m_UI!=nullptr ); + assert( m_UI->treeView!=nullptr ); + assert( m_UI->treeView->selectionModel()!=nullptr ); + + + QModelIndexList indexes( + m_UI->treeView->selectionModel()->selectedRows() + ); + + if( indexes.empty() ) + return; + + assert( indexes.size()==1 ); + + + const QModelIndex & front = indexes.front(); + + if( front.row()<1 ) + return; + + + Swap( + front.row(), + front.row() - 1, + RIGHT + ); +} + +/*******************************************************************************/ +void +ListEditWidget +::on_downButton_clicked() +{ + // qDebug() << this << "::on_downButton_clicked()"; + + assert( m_UI!=nullptr ); + assert( m_UI->treeView!=nullptr ); + assert( m_UI->treeView->selectionModel()!=nullptr ); + + + QModelIndexList indexes( + m_UI->treeView->selectionModel()->selectedRows() + ); + + if( indexes.empty() ) + return; + + assert( indexes.size()==1 ); + + + const QModelIndex & front = indexes.front(); + + if( front.row() >= GetItemModel()->rowCount() - 1 ) + return; + + + Swap( + front.row(), + front.row() + 1, + RIGHT + ); +} + +/*******************************************************************************/ +void +ListEditWidget +::on_browseButton_clicked() +{ + // qDebug() << this << "::on_browseButton_clicked()"; + + assert( m_UI!=nullptr ); + assert( m_UI->treeView!=nullptr ); + assert( m_UI->treeView->selectionModel()!=nullptr ); + + + // + // Pick-up first item of selection. + QModelIndexList indexes( + m_UI->treeView->selectionModel()->selectedRows() + ); + + if( indexes.isEmpty() ) + return; + + assert( indexes.size()==1 ); + + const QModelIndex & front = indexes.front(); + + // + // Get item-model. + ListEditItemModel * itemModel = GetItemModel(); + assert( itemModel!=nullptr ); + + // + // Pick-up filename. + QString selectedFilter; + + QString filename( browseFilename( front ) ); + + if( filename.isEmpty() ) + return; + + // + // Foo. + itemModel->setData( front, filename ); +} + +/*******************************************************************************/ +void +ListEditWidget +::OnSelectionChanged( const QItemSelection & /* selected */, + const QItemSelection & /* deselected */ ) +{ + // qDebug() + // << this + // << "::onSelectionChanged(" << selected << "," << deselected << ")"; + + // Experimental code. + // assert( selected.indexes().size()>=0 && selected.indexes().size()<=1 ); + + // assert( m_UI->upButton ); + // assert( m_UI->downButton ); + // assert( m_UI->browseButton ); + // assert( m_UI->removeButton ); + + // if( selected.empty() ) + // { + // m_UI->browseButton->setEnabled( false ); + // m_UI->removeButton->setEnabled( false ); + + // m_UI->upButton->setEnabled( false ); + // m_UI->downButton->setEnabled( false ); + + // return; + // } + + // assert( GetItemModel() ); + + // m_UI->browseButton->setEnabled( GetItemModel()->IsBrowsable() ); + // m_UI->removeButton->setEnabled( true ); + + // const QModelIndex & index = selected.indexes().front(); + + // m_UI->upButton->setEnabled( index.isValid() && index.row()>0 ); + + // m_UI->downButton->setEnabled( + // index.isValid() && + // index.sibling( index.row() + 1, index.column() ).isValid() + // ); +} + +/*****************************************************************************/ +void +ListEditWidget +::OnDataChanged( const QModelIndex &, const QModelIndex & ) +{ + // qDebug() << this << "::OnDataChanged()"; + + assert( GetItemModel()!=nullptr ); + + emit Updated(); +} + +/*****************************************************************************/ +void +ListEditWidget +::OnModelReset() +{ + // qDebug() << this << "::OnModelReset()"; + + emit Updated(); +} + +/*****************************************************************************/ +void +ListEditWidget +::OnRowsInserted( const QModelIndex &, int, int ) +{ + // qDebug() << this << "::OnRowsInserted()"; + + emit Updated(); +} + +/*****************************************************************************/ +void +ListEditWidget +::OnRowsRemoved( const QModelIndex &, int, int ) +{ + // qDebug() << this << "::OnRowsRemoved()"; + + emit Updated(); +} + +} // end namespace 'Wrapper' + +} // end namespace 'otb' diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetListEditWidget.ui b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetListEditWidget.ui new file mode 100644 index 0000000000000000000000000000000000000000..58a773eeafb8924a9e7dbc5a2c40343445952998 --- /dev/null +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetListEditWidget.ui @@ -0,0 +1,143 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>otb::Wrapper::ListEditWidget</class> + <widget class="QWidget" name="otb::Wrapper::ListEditWidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>122</width> + <height>178</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <property name="locale"> + <locale language="C" country="AnyCountry"/> + </property> + <layout class="QGridLayout" name="gridLayout"> + <property name="margin"> + <number>3</number> + </property> + <property name="spacing"> + <number>3</number> + </property> + <item row="0" column="0"> + <widget class="QTreeView" name="treeView"/> + </item> + <item row="0" column="1"> + <layout class="QVBoxLayout" name="verticalLayout"> + <property name="spacing"> + <number>1</number> + </property> + <item> + <widget class="QToolButton" name="upButton"> + <property name="toolTip"> + <string>Move up</string> + </property> + <property name="text"> + <string>Up</string> + </property> + <property name="arrowType"> + <enum>Qt::UpArrow</enum> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="addButton"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="toolTip"> + <string>Add</string> + </property> + <property name="text"> + <string>+</string> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="browseButton"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="toolTip"> + <string>Browse filename</string> + </property> + <property name="text"> + <string>...</string> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="removeAllButton"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="toolTip"> + <string>Remove all items</string> + </property> + <property name="text"> + <string>✕</string> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="removeButton"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="toolTip"> + <string>Remove</string> + </property> + <property name="text"> + <string>-</string> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="downButton"> + <property name="toolTip"> + <string>Move down</string> + </property> + <property name="text"> + <string>Down</string> + </property> + <property name="arrowType"> + <enum>Qt::DownArrow</enum> + </property> + </widget> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetListViewParameter.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetListViewParameter.cxx index 7f7b3ab995b85f92afeee24954d29ee971c1c2ba..f4f31d45d7b2f41ee2cc9999dfbb46b992c04298 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetListViewParameter.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetListViewParameter.cxx @@ -102,7 +102,9 @@ void QtWidgetListViewParameter::DoUpdateGUI() void QtWidgetListViewParameter::DoCreateWidget() { m_ListView = new QListWidget(); - m_ListView->setToolTip(m_ListViewParam->GetDescription()); + m_ListView->setToolTip( + QString::fromStdString( m_ListViewParam->GetDescription() ) + ); if(m_ListViewParam->GetSingleSelection()) { diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetModel.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetModel.cxx index 1fa1e283efa1d6710096ba5c8dcb6512bf433da8..a0d61138d72e424fd282b89c1daeb9da67bb9fe6 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetModel.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetModel.cxx @@ -70,7 +70,42 @@ QtWidgetModel ::NotifyUpdate() { // Update the parameters - m_Application->UpdateParameters(); + try + { + m_Application->UpdateParameters(); + } + catch(otb::ApplicationException& err) + { + m_Application->GetLogger()->Debug("Caught otb::ApplicationException during application update:\n"); + m_Application->GetLogger()->Debug(string(err.what()) + "\n"); + emit ExceptionRaised( err.what() ); + } + catch(otb::ImageFileReaderException& err) + { + m_Application->GetLogger()->Debug("Caught otb::ImageFileReaderException during application update:\n"); + m_Application->GetLogger()->Debug(string(err.what()) + "\n"); + string message( string("Cannot open image ") + err.m_Filename + string(". ") + err.GetDescription() ); + m_Application->GetLogger()->Fatal( message + string("\n")); + emit ExceptionRaised( message.c_str() ); + } + catch(itk::ExceptionObject& err) + { + m_Application->GetLogger()->Debug("Caught itk::ExceptionObject during application update:\n"); + m_Application->GetLogger()->Debug(string(err.what()) + "\n"); + m_Application->GetLogger()->Fatal(string(err.GetDescription()) + "\n"); + emit ExceptionRaised( err.GetDescription() ); + } + catch(std::exception& err) + { + m_Application->GetLogger()->Fatal(string("Caught std::exception during application update: ") + err.what() + "\n"); + emit ExceptionRaised( err.what() ); + } + catch(...) + { + m_Application->GetLogger()->Fatal("Caught unknown exception during application update.\n"); + emit ExceptionRaised("Unknown exception"); + } + emit UpdateGui(); // Notify all diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetOutputFilenameParameter.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetOutputFilenameParameter.cxx index 78ea7f7c7c220fd810671c0c7d916fc2ec3302b7..4f395262c43dd1ab3dc85c1bcf5f4ccdd315b298 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetOutputFilenameParameter.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetOutputFilenameParameter.cxx @@ -57,7 +57,9 @@ void QtWidgetOutputFilenameParameter::DoCreateWidget() m_HLayout->setSpacing(0); m_HLayout->setContentsMargins(0, 0, 0, 0); m_Input = new QLineEdit; - m_Input->setToolTip( m_FilenameParam->GetDescription() ); + m_Input->setToolTip( + QString::fromStdString( m_FilenameParam->GetDescription() ) + ); connect( m_Input, SIGNAL(textChanged(const QString&)), this, SLOT(SetFileName(const QString&)) ); connect( m_Input, SIGNAL(textChanged(const QString&)), GetModel(), SLOT(NotifyUpdate()) ); diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetOutputImageParameter.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetOutputImageParameter.cxx index bd47efd4203cb2c59b027c0db5363771961e0730..140ff6534f8487f97bbda7d0a99fc49128401843 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetOutputImageParameter.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetOutputImageParameter.cxx @@ -58,7 +58,9 @@ void QtWidgetOutputImageParameter::DoCreateWidget() m_HLayout->setSpacing(0); m_HLayout->setContentsMargins(0, 0, 0, 0); m_Input = new QLineEdit(); - m_Input->setToolTip( m_OutputImageParam->GetDescription() ); + m_Input->setToolTip( + QString::fromStdString( m_OutputImageParam->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); diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetOutputProcessXMLParameter.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetOutputProcessXMLParameter.cxx index 3e67ad01c0f8827c51bb6cbd33ac046ab404db71..324fa4e10a57d6c9432ac4cf1a2e62d99e07f107 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetOutputProcessXMLParameter.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetOutputProcessXMLParameter.cxx @@ -55,7 +55,9 @@ void QtWidgetOutputProcessXMLParameter::DoCreateWidget() m_HLayout->setSpacing(0); m_HLayout->setContentsMargins(0, 0, 0, 0); m_Input = new QLineEdit; - m_Input->setToolTip( m_XMLParam->GetDescription() ); + m_Input->setToolTip( + QString::fromStdString( m_XMLParam->GetDescription() ) + ); connect( m_Input, SIGNAL(textChanged(const QString&)), this, SLOT(SetFileName(const QString&)) ); connect( m_Input, SIGNAL(textChanged(const QString&)), GetModel(), SLOT(NotifyUpdate()) ); diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetOutputVectorDataParameter.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetOutputVectorDataParameter.cxx index b605c9be4df59714cccb6836530621e63c62af75..62c06044a1decaa9f28b12a3af67b4a63f3b16b0 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetOutputVectorDataParameter.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetOutputVectorDataParameter.cxx @@ -53,7 +53,9 @@ void QtWidgetOutputVectorDataParameter::DoCreateWidget() m_HLayout->setContentsMargins(0, 0, 0, 0); m_Input = new QLineEdit; - m_Input->setToolTip( m_OutputVectorDataParam->GetDescription() ); + m_Input->setToolTip( + QString::fromStdString( 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); diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetParameterBase.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetParameterBase.cxx index 2efb31574dfc5e701a7e29ab6c996fa343618bb0..eb44e1a4ee8eca304b95e7e52f11a185c2560c0a 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetParameterBase.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetParameterBase.cxx @@ -103,6 +103,21 @@ void QtWidgetParameterBase::Reset( ) this->UpdateGUI(); } +const Parameter * +QtWidgetParameterBase +::GetParam() const +{ + return m_Param; +} + +Parameter * +QtWidgetParameterBase +::GetParam() +{ + return m_Param; +} + + } } diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetParameterFactory.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetParameterFactory.cxx index 5f57b483daaae46469844d900a53f23d16afa5a7..89763c423741832b3c1e21f21ef144ff85690a22 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetParameterFactory.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetParameterFactory.cxx @@ -21,39 +21,45 @@ #include "otbWrapperQtWidgetParameterFactory.h" #include "otbWrapperParameter.h" -#include "otbWrapperQtWidgetModel.h" - -#include "otbWrapperQtWidgetParameterBase.h" +#include "otbWrapperInputFilenameListParameter.h" +#include "otbWrapperInputVectorDataListParameter.h" +#include "otbWrapperStringListParameter.h" -#include "otbWrapperQtWidgetEmptyParameter.h" -#include "otbWrapperQtWidgetIntParameter.h" -#include "otbWrapperQtWidgetFloatParameter.h" -#include "otbWrapperQtWidgetStringParameter.h" -#include "otbWrapperQtWidgetStringListParameter.h" #include "otbWrapperQtWidgetChoiceParameter.h" -#include "otbWrapperQtWidgetListViewParameter.h" -#include "otbWrapperQtWidgetInputImageParameter.h" #include "otbWrapperQtWidgetComplexInputImageParameter.h" #include "otbWrapperQtWidgetComplexOutputImageParameter.h" -#include "otbWrapperQtWidgetInputImageListParameter.h" -#include "otbWrapperQtWidgetOutputImageParameter.h" -#include "otbWrapperQtWidgetOutputVectorDataParameter.h" +#include "otbWrapperQtWidgetDirectoryParameter.h" +#include "otbWrapperQtWidgetEmptyParameter.h" +#include "otbWrapperQtWidgetFloatParameter.h" +#include "otbWrapperQtWidgetIntParameter.h" #include "otbWrapperQtWidgetInputFilenameParameter.h" #include "otbWrapperQtWidgetInputFilenameListParameter.h" -#include "otbWrapperQtWidgetOutputFilenameParameter.h" -#include "otbWrapperQtWidgetDirectoryParameter.h" -#include "otbWrapperQtWidgetParameterGroup.h" +#include "otbWrapperQtWidgetInputImageParameter.h" +#include "otbWrapperQtWidgetInputImageListParameter.h" +#include "otbWrapperQtWidgetInputProcessXMLParameter.h" #include "otbWrapperQtWidgetInputVectorDataListParameter.h" #include "otbWrapperQtWidgetInputVectorDataParameter.h" -#include "otbWrapperQtWidgetRAMParameter.h" +#include "otbWrapperQtWidgetListViewParameter.h" +#include "otbWrapperQtWidgetModel.h" +#include "otbWrapperQtWidgetOutputFilenameParameter.h" +#include "otbWrapperQtWidgetOutputImageParameter.h" #include "otbWrapperQtWidgetOutputProcessXMLParameter.h" -#include "otbWrapperQtWidgetInputProcessXMLParameter.h" +#include "otbWrapperQtWidgetOutputVectorDataParameter.h" +#include "otbWrapperQtWidgetParameterBase.h" +#include "otbWrapperQtWidgetParameterGroup.h" +#include "otbWrapperQtWidgetRAMParameter.h" +#include "otbWrapperQtWidgetStringParameter.h" +#include "otbWrapperQtWidgetStringListParameter.h" + namespace otb { + + namespace Wrapper { + template <class TParameterType, class TQtWidget> class QtWidgetParameterGenericFactory { @@ -66,13 +72,14 @@ public: static QtWidgetParameterBase* Create( Parameter* param, QtWidgetModel* model ) { - QtWidgetParameterBase* widget = ITK_NULLPTR; - TParameterType* specificParam = dynamic_cast<TParameterType *>(param); + QtWidgetParameterBase * widget = ITK_NULLPTR; + TParameterType * specificParam = dynamic_cast< TParameterType * >( param ); + + // Code should break if param is not a TParameterType and not be silent! + assert( specificParam!=nullptr ); + + widget = new TQtWidget( specificParam, model ); - if (specificParam) - { - widget = new TQtWidget(specificParam, model); - } return widget; } }; diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetParameterList.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetParameterList.cxx new file mode 100644 index 0000000000000000000000000000000000000000..5770106eeeab68b8ed66602717e520fc4e787c7b --- /dev/null +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetParameterList.cxx @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2005-2017 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 "otbWrapperParameterList.h" +#include "otbWrapperQtWidgetListEditItemModel.h" +#include "otbWrapperQtWidgetListEditWidget.h" +#include "otbWrapperQtWidgetParameterList.h" + + +namespace otb +{ + +namespace Wrapper +{ + + +/*****************************************************************************/ +QtWidgetParameterList +::QtWidgetParameterList( AbstractParameterList * param, QtWidgetModel * m ) : + QtWidgetParameterBase( param, m ) +{ + assert( m!=nullptr ); + + QObject::connect( + this, SIGNAL( NotifyUpdate() ), + m, SLOT( NotifyUpdate() ) + ); +} + +/*****************************************************************************/ +QtWidgetParameterList +::~QtWidgetParameterList() +{ +} + +/*****************************************************************************/ +void +QtWidgetParameterList +::DoUpdateGUI() +{ +} + +/*****************************************************************************/ +void +QtWidgetParameterList +::DoCreateWidget() +{ + // + // List-edit widget. + assert( dynamic_cast< StringListInterface * >( GetParam() )!=nullptr ); + + ListEditWidget * widget = new ListEditWidget( + dynamic_cast< StringListInterface * >( GetParam() ) + ); + + // + // Global Layout + QGridLayout * gLayout = new QGridLayout(); + + gLayout->setSpacing( 1 ); + gLayout->setContentsMargins( 2, 2, 2, 2 ); + + gLayout->addWidget( widget ); + + setLayout( gLayout ); + + // + // Connections. + QObject::connect( + widget, SIGNAL( Updated() ), + this, SIGNAL( NotifyUpdate() ) + ); +} + +} + +} diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetRAMParameter.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetRAMParameter.cxx index ffe5336b35f7c33fe56c2b56e56482ae24b87cfb..be73e12d1ca020529528eaf8fb59b473ed874fa0 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetRAMParameter.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetRAMParameter.cxx @@ -43,7 +43,9 @@ void QtWidgetRAMParameter::DoCreateWidget() m_QHBoxLayout->setContentsMargins(0, 0, 0, 0); m_QSpinBox = new QSpinBox; - m_QSpinBox->setToolTip(m_RAMParam->GetDescription()); + m_QSpinBox->setToolTip( + QString::fromStdString( m_RAMParam->GetDescription() ) + ); connect( m_QSpinBox, SIGNAL(valueChanged(int)), this, SLOT(SetValue(int)) ); connect( m_QSpinBox, SIGNAL(valueChanged(int)), GetModel(), SLOT(NotifyUpdate()) ); diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetStringListParameter.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetStringListParameter.cxx index 04667ea5242400c04ba442c980d00f04a834b4e3..60a9073ae2d41215e8d3a387edb616c7994359cc 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetStringListParameter.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetStringListParameter.cxx @@ -20,110 +20,35 @@ #include "otbWrapperQtWidgetStringListParameter.h" -namespace otb -{ -namespace Wrapper -{ -QtWidgetStringListParameter::QtWidgetStringListParameter(StringListParameter* param, QtWidgetModel* m) -: QtWidgetParameterBase(param, m), - m_StringListParam(param) -{ - connect( this, - SIGNAL(Change()), - GetModel(), - SLOT(NotifyUpdate()) ); -} +#include "otbWrapperStringListParameter.h" -QtWidgetStringListParameter::~QtWidgetStringListParameter() -{ -} -void QtWidgetStringListParameter::DoUpdateGUI() +namespace otb { - if(!m_StringListParam) - return; - std::vector<std::string> strList = m_StringListParam->GetValue(); - for( unsigned int i = m_LineEditList.size(); i < strList.size(); i++ ) - { - this->AddString(); - } - int i = 0; - std::vector<std::string>::iterator it; - for (it = strList.begin(); it != strList.end(); ++it) - { - m_LineEditList[i++]->SetText(QString( (*it).c_str() )); - } -} -void QtWidgetStringListParameter::DoCreateWidget() +namespace Wrapper { - m_LineEditList.clear(); - const unsigned int sp(2); - const unsigned int buttonSize(30); - // Global layout - QHBoxLayout * hLayout = new QHBoxLayout; - hLayout->setSpacing(sp); - hLayout->setContentsMargins(sp, sp, sp, sp); - if( m_StringListParam->GetRole() != Role_Output ) - { - // Button layout - QVBoxLayout * buttonLayout = new QVBoxLayout; - buttonLayout->setSpacing(sp); - buttonLayout->setContentsMargins(sp, sp, sp, sp); - - QHBoxLayout * addSupLayout = new QHBoxLayout; - addSupLayout->setSpacing(sp); - addSupLayout->setContentsMargins(sp, sp, sp, sp); - - QHBoxLayout * upDownLayout = new QHBoxLayout; - upDownLayout->setSpacing(sp); - upDownLayout->setContentsMargins(sp, sp, sp, sp); - - // Add file button - QPushButton * addButton = new QPushButton; - addButton->setText("+"); - addButton->setFixedWidth(buttonSize); - addButton->setToolTip("Add a string selector..."); - connect( addButton, SIGNAL(clicked()), this, SLOT(AddString()) ); - addSupLayout->addWidget(addButton); - - // Suppress file button - QPushButton * supButton = new QPushButton; - supButton->setText("-"); - supButton->setFixedWidth(buttonSize); - supButton->setToolTip("Suppress the selected string..."); - connect( supButton, SIGNAL(clicked()), this, SLOT(SuppressString()) ); - addSupLayout->addWidget(supButton); - buttonLayout->addLayout(addSupLayout); - - hLayout->addLayout(buttonLayout); - } - - QVBoxLayout * fileLayout = new QVBoxLayout(); - fileLayout->setSpacing(0); - - QGroupBox *mainGroup = new QGroupBox(); - mainGroup->setLayout(fileLayout); - QScrollArea * s = new QScrollArea(); - s->setWidget(mainGroup); - s->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - s->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - s->setWidgetResizable(true); - - hLayout->addWidget(s); - - - this->setLayout(hLayout); +/*****************************************************************************/ +QtWidgetStringListParameter +::QtWidgetStringListParameter( StringListParameter * param, + QtWidgetModel * m ) : + QtWidgetParameterList( param, m ) +{ +} - m_HLayout = hLayout; - m_Scroll = s; +/*****************************************************************************/ +QtWidgetStringListParameter +::~QtWidgetStringListParameter() +{ } +#if 0 + void QtWidgetStringListParameter::UpdateStringList() { @@ -206,5 +131,8 @@ QtWidgetStringListParameter::SuppressString() this->update(); } +#endif + } + } diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetStringParameter.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetStringParameter.cxx index b48616d65f62868bdd9f088b6e226b552ce412ec..54ffc7f82f1b0c2281bc77008d5e10684ae20b46 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetStringParameter.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetStringParameter.cxx @@ -37,7 +37,9 @@ QtWidgetStringParameter::~QtWidgetStringParameter() void QtWidgetStringParameter::DoUpdateGUI() { - m_Input->setToolTip(m_StringParam->GetDescription()); + m_Input->setToolTip( + QString::fromStdString( m_StringParam->GetDescription() ) + ); // Update the lineEdit only if there is a change and that's not empty or whitespaces QString text( m_StringParam->GetValue().c_str() ); @@ -55,7 +57,9 @@ void QtWidgetStringParameter::DoCreateWidget() m_HLayout->setContentsMargins(0, 0, 0, 0); m_Input = new QLineEdit; - m_Input->setToolTip(m_StringParam->GetDescription()); + m_Input->setToolTip( + QString::fromStdString( m_StringParam->GetDescription() ) + ); m_HLayout->addWidget(m_Input); connect( m_Input, SIGNAL(textChanged(const QString&)), this, SLOT(SetValue(const QString&)) ); diff --git a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetView.cxx b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetView.cxx index ae64ff49e556c3f0a2431472dad49290eb9a480c..9cc7c4af44e33e7520c0034551b48b1805dd0762 100644 --- a/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetView.cxx +++ b/Modules/Wrappers/QtWidget/src/otbWrapperQtWidgetView.cxx @@ -82,6 +82,8 @@ void QtWidgetView::CreateGui() QVBoxLayout *finalLayout = new QVBoxLayout(); finalLayout->addWidget(mainGroup); + connect( m_Model, SIGNAL(ExceptionRaised(QString)), this, SLOT(OnExceptionRaised(QString)) ); + // Make the final layout to the widget this->setLayout(finalLayout); } @@ -188,9 +190,14 @@ void QtWidgetView::CloseSlot() void QtWidgetView::UnhandledException(QString message) { - m_TabWidget->setCurrentIndex(1); + this->OnExceptionRaised(message); m_LogText->append(message); } +void QtWidgetView::OnExceptionRaised(QString /*message*/) +{ + m_TabWidget->setCurrentIndex(1); +} + } } diff --git a/Modules/Wrappers/SWIG/src/otbApplication.i b/Modules/Wrappers/SWIG/src/otbApplication.i index 0d952b8fdf0820190b36ce7f80a352512e71913d..52d446f50e56646ce6648902840093f7e8d8461b 100644 --- a/Modules/Wrappers/SWIG/src/otbApplication.i +++ b/Modules/Wrappers/SWIG/src/otbApplication.i @@ -128,7 +128,7 @@ namespace Wrapper typedef enum { - Role_Input, + Role_Input = 0, Role_Output } Role; @@ -198,7 +198,7 @@ public: std::string GetParameterString(std::string parameter); std::vector<std::string> GetParameterStringList(std::string parameter); std::string GetParameterAsString(std::string paramKey); - + InputImageParameter::ImageBaseType * GetParameterOutputImage(std::string parameter); void SetParameterInputImage(std::string parameter, InputImageParameter::ImageBaseType * inputImage); ComplexInputImageParameter::ImageBaseType * GetParameterComplexOutputImage(std::string parameter); @@ -211,7 +211,7 @@ public: unsigned int GetNumberOfElementsInParameterInputImageList(std::string parameter); - + itkProcessObject* GetProgressSource() const; std::string GetProgressDescription() const;