]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Thu, 24 Sep 2015 16:16:28 +0000 (18:16 +0200)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Thu, 24 Sep 2015 16:16:28 +0000 (18:16 +0200)
appli/ImageMPR/ImageMPR.cxx
lib/cpPlugins/Interface/CMakeLists.txt
lib/cpPlugins/Interface/Config.h.in [new file with mode: 0644]
lib/cpPlugins/Interface/ParametersListWidget.cxx [new file with mode: 0644]
lib/cpPlugins/Interface/ParametersListWidget.h [new file with mode: 0644]
lib/cpPlugins/Interface/ParametersListWidget.ui [new file with mode: 0644]
lib/cpPlugins/Interface/ParametersQtDialog.cxx
lib/cpPlugins/Interface/ProcessObject.cxx
lib/cpPlugins/Interface/ProcessObject.h

index f17e7195a9ced54f8117268ad5dc78ec2e511678..412b9ed48819c5a2974a21a2d3179e209a054c4b 100644 (file)
@@ -310,18 +310,13 @@ _triggered_actionImageToImage( )
   // Configure filter
   TPluginFilter::Pointer filter =
     this->m_Plugins.CreateProcessObject( name );
-  TParameters parameters = filter->GetDefaultParameters( );
-  bool dlg_ok =
-    cpPlugins::Interface::ParametersQtDialog(
-      parameters, filter->GetClassName( )
-      );
+  bool dlg_ok = filter->ExecConfigurationDialog( NULL );
   if( !dlg_ok )
     return;
 
   // Execute filter
   QApplication::setOverrideCursor( Qt::WaitCursor );
   this->setEnabled( false );
-  filter->SetParameters( parameters );
   filter->SetInput( 0, this->m_InputImage );
   std::string err = filter->Update( );
   QApplication::restoreOverrideCursor( );
@@ -360,18 +355,13 @@ _triggered_actionImageToMesh( )
   // Configure filter
   TPluginFilter::Pointer filter =
     this->m_Plugins.CreateProcessObject( name );
-  TParameters parameters = filter->GetDefaultParameters( );
-  bool dlg_ok =
-    cpPlugins::Interface::ParametersQtDialog(
-      parameters, filter->GetClassName( )
-      );
+  bool dlg_ok = filter->ExecConfigurationDialog( NULL );
   if( !dlg_ok )
     return;
 
   // Execute filter
   QApplication::setOverrideCursor( Qt::WaitCursor );
   this->setEnabled( false );
-  filter->SetParameters( parameters );
   filter->SetInput( 0, this->m_InputImage );
   std::string err = filter->Update( );
   QApplication::restoreOverrideCursor( );
index 36dc3f8ae3cabfcf1458b65d030ae0eadc00217f..6d73928e24f27ea70b172cc1029df327c70674f9 100644 (file)
@@ -1,5 +1,11 @@
 SET(LIBRARY_NAME cpPlugins_Interface)
 
+CONFIGURE_FILE(
+  Config.h.in
+  ${PROJECT_BINARY_DIR}/lib/cpPlugins/Interface/Config.h
+  @ONLY
+  )
+
 ## ===============
 ## = Source code =
 ## ===============
@@ -61,6 +67,42 @@ IF(USE_QT4)
     ${LIB_SOURCES_CXX}
     ParametersQtDialog.cxx
     )
+
+  SET(
+    LIB_QT_UI
+    ParametersListWidget.ui
+    )
+  SET(
+    LIB_QT_Headers
+    ParametersListWidget.h
+    )
+  SET(
+    LIB_QT_Sources
+    ParametersListWidget.cxx
+    )
+  SET(
+    LIB_QT_Resources
+    )
+
+  QT4_WRAP_UI(LIB_QT_Wrapped_Headers ${LIB_QT_UI})
+  QT4_WRAP_CPP(LIB_QT_Wrapped_MOC_Sources ${LIB_QT_Headers})
+  QT4_ADD_RESOURCES(LIB_QT_Wrapped_Resources_Sources ${LIB_QT_Resources})
+
+  SET(
+    LIB_HEADERS_H
+    ${LIB_HEADERS_H}
+    ${LIB_QT_Wrapped_Headers}
+    )
+
+  SET(
+    LIB_SOURCES_CXX
+    ${LIB_SOURCES_CXX}
+    ${LIB_QT_Sources}
+    ${LIB_QT_Wrapped_Headers}
+    ${LIB_QT_Wrapped_MOC_Sources}
+    ${LIB_QT_Wrapped_Resources_Sources}
+    )
+
 ENDIF(USE_QT4)
 
 ## =====================
diff --git a/lib/cpPlugins/Interface/Config.h.in b/lib/cpPlugins/Interface/Config.h.in
new file mode 100644 (file)
index 0000000..58a9286
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef __CPPLUGINS__INTERFACE__CONFIG__H__
+#define __CPPLUGINS__INTERFACE__CONFIG__H__
+
+
+#define cpPlugins_MAJOR_VERSION   @prj_MAJOR_VERSION@
+#define cpPlugins_MINOR_VERSION   @prj_MINOR_VERSION@
+#define cpPlugins_RELEASE_VERSION @prj_RELEASE_VERSION@
+#define cpPlugins_VERSION         "@prj_VERSION@"
+
+#define cpPlugins_Interface_QT4_USED @QT4_FOUND@
+#if cpPlugins_Interface_QT4_USED == 1
+#  define cpPlugins_Interface_QT4
+#else // cpPlugins_Interface_QT4_USED == 1
+#  undef cpPlugins_Interface_QT4
+#endif // cpPlugins_Interface_QT4_USED == 1
+
+#endif // __CPPLUGINS__INTERFACE__CONFIG__H__
+
+// eof - $RCSfile$
diff --git a/lib/cpPlugins/Interface/ParametersListWidget.cxx b/lib/cpPlugins/Interface/ParametersListWidget.cxx
new file mode 100644 (file)
index 0000000..752bb68
--- /dev/null
@@ -0,0 +1,137 @@
+#include <cpPlugins/Interface/ParametersListWidget.h>
+#include <cpPlugins/Interface/ui_ParametersListWidget.h>
+
+#include <set>
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::ParametersListWidget::
+ParametersListWidget( const std::string& list_name, QWidget* parent )
+  : QWidget( parent ),
+    m_UI( new Ui::ParametersListWidget )
+{
+  this->m_UI->setupUi( this );
+
+  // Configure table
+  QTableWidget* table = this->m_UI->ValuesTable;
+  table->setColumnCount( 1 );
+  table->setRowCount( 1 );
+
+  QStringList header;
+  header << list_name.c_str( );
+  table->setHorizontalHeaderLabels( header );
+  table->setShowGrid( true );
+  table->setSelectionBehavior( QAbstractItemView::SelectRows );
+
+  // Connect signals
+  QObject::connect(
+    this->m_UI->AddValueButton, SIGNAL( clicked( ) ),
+    this, SLOT( _changeValuesCount( ) )
+    );
+  QObject::connect(
+    this->m_UI->RemoveValueButton, SIGNAL( clicked( ) ),
+    this, SLOT( _changeValuesCount( ) )
+    );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::ParametersListWidget::
+~ParametersListWidget( )
+{
+  delete this->m_UI;
+}
+
+// -------------------------------------------------------------------------
+std::vector< std::string > cpPlugins::Interface::ParametersListWidget::
+GetStringValues( ) const
+{
+  std::vector< std::string > values;
+
+  QTableWidget* table = this->m_UI->ValuesTable;
+  for( int i = 0; i < table->rowCount( ); ++i )
+    values.push_back( table->item( i, 0 )->text( ).toStdString( ) );
+  return( values );
+}
+
+// -------------------------------------------------------------------------
+std::vector< int > cpPlugins::Interface::ParametersListWidget::
+GetIntValues( ) const
+{
+  std::vector< int > values;
+
+  QTableWidget* table = this->m_UI->ValuesTable;
+  for( int i = 0; i < table->rowCount( ); ++i )
+  {
+    const char* text = table->item( i, 0 )->text( ).toStdString( ).c_str( );
+    char* ptr = 0;
+    double v = std::strtod( text, &ptr );
+    if( *ptr == '\0' && ptr != text )
+      values.push_back( int( v ) );
+    
+  } // rof
+  return( values );
+}
+
+// -------------------------------------------------------------------------
+std::vector< unsigned int > cpPlugins::Interface::ParametersListWidget::
+GetUintValues( ) const
+{
+  std::vector< unsigned int > values;
+
+  QTableWidget* table = this->m_UI->ValuesTable;
+  for( int i = 0; i < table->rowCount( ); ++i )
+  {
+    const char* text = table->item( i, 0 )->text( ).toStdString( ).c_str( );
+    char* ptr = 0;
+    double v = std::strtod( text, &ptr );
+    if( *ptr == '\0' && ptr != text && v >= double( 0 ) )
+      values.push_back( ( unsigned int )( v ) );
+
+  } // rof
+  return( values );
+}
+
+// -------------------------------------------------------------------------
+std::vector< double > cpPlugins::Interface::ParametersListWidget::
+GetDoubleValues( ) const
+{
+  std::vector< double > values;
+
+  QTableWidget* table = this->m_UI->ValuesTable;
+  for( int i = 0; i < table->rowCount( ); ++i )
+  {
+    const char* text = table->item( i, 0 )->text( ).toStdString( ).c_str( );
+    char* ptr = 0;
+    double v = std::strtod( text, &ptr );
+    if( *ptr == '\0' && ptr != text )
+      values.push_back( v );
+    
+  } // rof
+  return( values );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::ParametersListWidget::
+_changeValuesCount( )
+{
+  QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
+  if( btn == NULL )
+    return;
+  QTableWidget* table = this->m_UI->ValuesTable;
+
+  if( btn == this->m_UI->RemoveValueButton )
+  {
+    std::set< int > to_delete;
+    QList< QTableWidgetItem* > lst = table->selectedItems( );
+    QList< QTableWidgetItem* >::iterator i = lst.begin( );
+    for( ; i != lst.end( ); ++i )
+      to_delete.insert( ( *i )->row( ) );
+
+    std::set< int >::const_reverse_iterator d = to_delete.rbegin( );
+    for( ; d != to_delete.rend( ); ++d )
+      table->removeRow( *d );
+  }
+  else
+    table->insertRow( table->rowCount( ) );
+}
+
+// eof - $RCSfile$
diff --git a/lib/cpPlugins/Interface/ParametersListWidget.h b/lib/cpPlugins/Interface/ParametersListWidget.h
new file mode 100644 (file)
index 0000000..eb186dd
--- /dev/null
@@ -0,0 +1,51 @@
+#ifndef __CPPLUGINS__INTERFACE__PARAMETERSLISTWIDGET__H__
+#define __CPPLUGINS__INTERFACE__PARAMETERSLISTWIDGET__H__
+
+#include <vector>
+#include <QWidget>
+
+// -------------------------------------------------------------------------
+namespace Ui
+{
+  class ParametersListWidget;
+}
+
+// -------------------------------------------------------------------------
+/**
+ */
+namespace cpPlugins
+{
+  namespace Interface
+  {
+    class ParametersListWidget
+      : public QWidget
+    {
+      Q_OBJECT;
+
+    public:
+
+    public:
+      explicit ParametersListWidget(
+        const std::string& list_name, QWidget* parent = 0
+        );
+      virtual ~ParametersListWidget( );
+
+      std::vector< std::string > GetStringValues( ) const;
+      std::vector< int > GetIntValues( ) const;
+      std::vector< unsigned int > GetUintValues( ) const;
+      std::vector< double > GetDoubleValues( ) const;
+
+    private slots:
+      void _changeValuesCount( );
+
+    private:
+      Ui::ParametersListWidget* m_UI;
+    };
+
+  } // ecapseman
+
+} // ecapseman
+
+#endif // __CPPLUGINS__INTERFACE__PARAMETERSLISTWIDGET__H__
+
+// eof - $RCSfile$
diff --git a/lib/cpPlugins/Interface/ParametersListWidget.ui b/lib/cpPlugins/Interface/ParametersListWidget.ui
new file mode 100644 (file)
index 0000000..688029c
--- /dev/null
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ParametersListWidget</class>
+ <widget class="QWidget" name="ParametersListWidget">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>230</width>
+    <height>310</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <widget class="QTableWidget" name="ValuesTable"/>
+   </item>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <widget class="QPushButton" name="RemoveValueButton">
+       <property name="text">
+        <string>-</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="AddValueButton">
+       <property name="text">
+        <string>+</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
index 1cc5820f30ee9561ba890cff5df75907133ea912..e6c5f5768030aae38f0c77ed827ce257301e0b63 100644 (file)
@@ -3,6 +3,7 @@
 #include <limits>
 #include <vector>
 
+#include <cpPlugins/Interface/ParametersListWidget.h>
 #include <QCheckBox>
 #include <QDialog>
 #include <QDialogButtonBox>
@@ -10,7 +11,6 @@
 #include <QHBoxLayout>
 #include <QLabel>
 #include <QLineEdit>
-#include <QTableWidget>
 #include <QWidget>
 
 // -------------------------------------------------------------------------
@@ -92,24 +92,15 @@ ParametersQtDialog(
       v_double->setValue( parameters.GetValueAsReal( *nIt ) );
       w_input = v_double;
     }
-    else if( pt == Parameters::RealList )
+    else if(
+      pt == Parameters::StringList ||
+      pt == Parameters::IntList ||
+      pt == Parameters::UintList ||
+      pt == Parameters::RealList
+      )
     {
-      QStringList header;
-      header << nIt->c_str( );
-
-      QTableWidget* l_double = new QTableWidget( dlg );
-      l_double->setColumnCount( 1 );
-      l_double->setRowCount( 1 );
-      l_double->setHorizontalHeaderLabels( header );
-      l_double->setShowGrid( true );
-      l_double->setSelectionBehavior( QAbstractItemView::SelectRows );
-      l_double->setSelectionMode( QAbstractItemView::SingleSelection );
-
-      QObject::connect(
-        l_double, SIGNAL( cellDoubleClicked( int, int ) ),
-        l_double, SLOT( insertRow( int ) )
-        );
-
+      cpPlugins::Interface::ParametersListWidget* l_double =
+        new cpPlugins::Interface::ParametersListWidget( *nIt, dlg );
       w_input = l_double;
 
     } // fi
@@ -180,21 +171,44 @@ ParametersQtDialog(
       if( v_double != NULL )
         parameters.SetValueAsReal( *nIt, v_double->value( ) );
     }
-    else if( pt == Parameters::RealList )
+    else if(
+      pt == Parameters::StringList ||
+      pt == Parameters::IntList ||
+      pt == Parameters::UintList ||
+      pt == Parameters::RealList
+      )
     {
-      QTableWidget* l_double =
-        dlg->findChild< QTableWidget* >( nIt->c_str( ) );
+      cpPlugins::Interface::ParametersListWidget* l_double =
+        dlg->findChild< cpPlugins::Interface::ParametersListWidget* >(
+          nIt->c_str( )
+          );
       if( l_double != NULL )
       {
-        for( int r = 0; r < l_double->rowCount( ); ++r )
+        if( pt == Parameters::StringList )
+        {
+          std::vector< std::string > values = l_double->GetStringValues( );
+          for( int r = 0; r < values.size( ); ++r )
+            parameters.AddValueToStringList( *nIt, values[ r ] );
+        }
+        else if( pt == Parameters::IntList )
+        {
+          std::vector< int > values = l_double->GetIntValues( );
+          for( int r = 0; r < values.size( ); ++r )
+            parameters.AddValueToIntList( *nIt, values[ r ] );
+        }
+        else if( pt == Parameters::UintList )
+        {
+          std::vector< unsigned int > values = l_double->GetUintValues( );
+          for( int r = 0; r < values.size( ); ++r )
+            parameters.AddValueToUintList( *nIt, values[ r ] );
+        }
+        else if( pt == Parameters::RealList )
         {
-          double v =
-            std::atof(
-              l_double->item( r, 0 )->text( ).toStdString( ).c_str( )
-              );
-          parameters.AddValueToRealList( *nIt, v );
+          std::vector< double > values = l_double->GetDoubleValues( );
+          for( int r = 0; r < values.size( ); ++r )
+            parameters.AddValueToRealList( *nIt, values[ r ] );
 
-        } // rof
+        } // fi
 
       } // fi
 
index 3630e491022a4813778201346aa45d65d2b3b0fd..a53476f894a8b30953fadfb84322a211fcebd6bf 100644 (file)
@@ -1,5 +1,9 @@
 #include <cpPlugins/Interface/ProcessObject.h>
 
+#ifdef cpPlugins_Interface_QT4
+#include <cpPlugins/Interface/ParametersQtDialog.h>
+#endif // cpPlugins_Interface_QT4
+
 // -------------------------------------------------------------------------
 const cpPlugins::Interface::Parameters&
 cpPlugins::Interface::ProcessObject::
@@ -92,6 +96,28 @@ DisconnectOutputs( )
       this->m_Outputs[ idx ]->DisconnectPipeline( );
 }
 
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::ProcessObject::
+ExecConfigurationDialog( QWidget* parent )
+{
+  bool r = false;
+
+#ifdef cpPlugins_Interface_QT4
+
+  Parameters parameters = this->m_DefaultParameters;
+  r = cpPlugins::Interface::ParametersQtDialog(
+    parameters,
+    this->m_ClassName + std::string( " basic configuration" ),
+    parent
+    );
+  if( r )
+    this->m_Parameters = parameters;
+
+#endif // cpPlugins_Interface_QT4
+
+  return( r );
+}
+
 // -------------------------------------------------------------------------
 cpPlugins::Interface::ProcessObject::
 ProcessObject( )
index d201a6c84c09ac57782062d14178420412d206e0..82492db180639484e977f5fae5659c371b90781c 100644 (file)
@@ -2,10 +2,17 @@
 #define __CPPLUGINS__INTERFACE__PROCESSOBJECT__H__
 
 #include <cpPlugins/Interface/cpPlugins_Interface_Export.h>
+#include <cpPlugins/Interface/Config.h>
 #include <cpPlugins/Interface/Object.h>
 #include <cpPlugins/Interface/DataObject.h>
 #include <cpPlugins/Interface/Parameters.h>
 
+#ifdef cpPlugins_Interface_QT4
+class QWidget;
+#else
+typedef char QWidget
+#endif // cpPlugins_Interface_QT4
+
 #include <itkProcessObject.h>
 
 namespace cpPlugins
@@ -41,6 +48,8 @@ namespace cpPlugins
       virtual std::string Update( );
       virtual void DisconnectOutputs( );
 
+      virtual bool ExecConfigurationDialog( QWidget* parent );
+
       template< class T >
         inline T* GetInput( unsigned int idx );