]> Creatis software - cpPlugins.git/blobdiff - appli/cpPipelineEditor/QNEBlock.cxx
...
[cpPlugins.git] / appli / cpPipelineEditor / QNEBlock.cxx
index 5d6f16c4e6b1e674ae0c49e8ab7c6608de89cbe2..2b7ed51f6bc52f5580e4f9d6145f5086d0af1773 100644 (file)
@@ -55,6 +55,22 @@ QNEBlock( TFilter* filter, QGraphicsItem* parent, QGraphicsScene* scene )
 \r
   this->m_Width = this->m_HorzMargin;\r
   this->m_Height = this->m_VertMargin;\r
+\r
+  // Configure names\r
+  this->setNamePort( this->m_Filter->GetName( ) );\r
+  this->_setTypePort( this->m_Filter->GetClassName( ) );\r
+\r
+  // Add input ports\r
+  std::set< std::string > inputs;\r
+  this->m_Filter->GetInputsNames( inputs );\r
+  for( auto iIt = inputs.begin( ); iIt != inputs.end( ); ++iIt )\r
+    this->addInputPort( iIt->c_str( ) );\r
+\r
+  // Add output ports\r
+  std::set< std::string > outputs;\r
+  this->m_Filter->GetOutputsNames( outputs );\r
+  for( auto oIt = outputs.begin( ); oIt != outputs.end( ); ++oIt )\r
+    this->addOutputPort( oIt->c_str( ) );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
@@ -75,75 +91,76 @@ setNamePort( const QString& txt )
 }\r
 \r
 // -------------------------------------------------------------------------\r
-void PipelineEditor::QNEBlock::\r
-setTypePort( const QString& txt )\r
-{\r
-  if( this->m_TypePort == NULL )\r
-    this->m_TypePort = new QNETypePort( this );\r
-  this->m_TypePort->setName( txt );\r
-  this->_configPort( this->m_TypePort );\r
-}\r
-\r
-// -------------------------------------------------------------------------\r
-void PipelineEditor::QNEBlock::\r
+PipelineEditor::QNEInputPort* PipelineEditor::QNEBlock::\r
 addInputPort( const QString& txt )\r
 {\r
   QNEInputPort* ip = new QNEInputPort( this );\r
   ip->setName( txt );\r
-  this->m_InputPorts.push_back( ip );\r
+  this->m_InputPorts[ txt.toStdString( ) ] = ip;\r
   this->_configPort( ip );\r
+  return( ip );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-void PipelineEditor::QNEBlock::\r
+PipelineEditor::QNEOutputPort* PipelineEditor::QNEBlock::\r
 addOutputPort( const QString& txt )\r
 {\r
   QNEOutputPort* op = new QNEOutputPort( this );\r
   op->setName( txt );\r
-  this->m_OutputPorts.push_back( op );\r
+  this->m_OutputPorts[ txt.toStdString( ) ] = op;\r
   this->_configPort( op );\r
+  return( op );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-QVector< PipelineEditor::QNEPort* > PipelineEditor::QNEBlock::\r
-ports( )\r
+PipelineEditor::QNEInputPort* PipelineEditor::QNEBlock::\r
+inputPort( const QString& txt )\r
 {\r
-  QVector< QNEPort* > res;\r
-  foreach( QGraphicsItem* i, this->childItems( ) )\r
-  {\r
-    QNEPort* p = dynamic_cast< QNEPort* >( i );\r
-    if( p != NULL )\r
-      res.append( p );\r
-\r
-  } // rof\r
-  return( res );\r
+  auto i = this->m_InputPorts.find( txt.toStdString( ) );\r
+  if( i != this->m_InputPorts.end( ) )\r
+    return( i->second );\r
+  else\r
+    return( NULL );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
-PipelineEditor::QNEBlock* PipelineEditor::QNEBlock::\r
-clone( )\r
+PipelineEditor::QNEOutputPort* PipelineEditor::QNEBlock::\r
+outputPort( const QString& txt )\r
 {\r
-  QNEBlock* b = new QNEBlock( this->m_Filter, 0, this->scene( ) );\r
-  foreach( QGraphicsItem* i, this->childItems( ) )\r
-  {\r
-    QNENamePort* np = dynamic_cast< QNENamePort* >( i );\r
-    if( np != NULL )\r
-      b->setNamePort( np->name( ) );\r
-\r
-    QNETypePort* tp = dynamic_cast< QNETypePort* >( i );\r
-    if( tp != NULL )\r
-      b->setTypePort( tp->name( ) );\r
+  auto o = this->m_OutputPorts.find( txt.toStdString( ) );\r
+  if( o != this->m_OutputPorts.end( ) )\r
+    return( o->second );\r
+  else\r
+    return( NULL );\r
+}\r
 \r
-    QNEInputPort* ip = dynamic_cast< QNEInputPort* >( i );\r
-    if( ip != NULL )\r
-      b->addInputPort( ip->name( ) );\r
+// -------------------------------------------------------------------------\r
+const PipelineEditor::QNEInputPort* PipelineEditor::QNEBlock::\r
+inputPort( const QString& txt ) const\r
+{\r
+  auto i = this->m_InputPorts.find( txt.toStdString( ) );\r
+  if( i != this->m_InputPorts.end( ) )\r
+    return( i->second );\r
+  else\r
+    return( NULL );\r
+}\r
 \r
-    QNEOutputPort* op = dynamic_cast< QNEOutputPort* >( i );\r
-    if( op != NULL )\r
-      b->addOutputPort( op->name( ) );\r
+// -------------------------------------------------------------------------\r
+const PipelineEditor::QNEOutputPort* PipelineEditor::QNEBlock::\r
+outputPort( const QString& txt ) const\r
+{\r
+  auto o = this->m_OutputPorts.find( txt.toStdString( ) );\r
+  if( o != this->m_OutputPorts.end( ) )\r
+    return( o->second );\r
+  else\r
+    return( NULL );\r
+}\r
 \r
-  } // rof\r
-  return( b );\r
+// -------------------------------------------------------------------------\r
+const QString& PipelineEditor::QNEBlock::\r
+namePort( ) const\r
+{\r
+  return( this->m_NamePort->name( ) );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
@@ -176,6 +193,16 @@ itemChange( GraphicsItemChange change, const QVariant& value )
   return( value );\r
 }\r
 \r
+// -------------------------------------------------------------------------\r
+void PipelineEditor::QNEBlock::\r
+_setTypePort( const QString& txt )\r
+{\r
+  if( this->m_TypePort == NULL )\r
+    this->m_TypePort = new QNETypePort( this );\r
+  this->m_TypePort->setName( txt );\r
+  this->_configPort( this->m_TypePort );\r
+}\r
+\r
 // -------------------------------------------------------------------------\r
 void PipelineEditor::QNEBlock::\r
 _configPort( QNEPort* port )\r
@@ -214,4 +241,15 @@ _configPort( QNEPort* port )
   } // rof\r
 }\r
 \r
+// -------------------------------------------------------------------------\r
+void PipelineEditor::QNEBlock::\r
+mouseReleaseEvent( QGraphicsSceneMouseEvent* evt )\r
+{\r
+  if( this->m_Filter.IsNotNull( ) )\r
+    this->m_Filter->SetViewCoords(\r
+      this->scenePos( ).x( ), this->scenePos( ).y( )\r
+      );\r
+  this->Superclass::mouseReleaseEvent( evt );\r
+}\r
+\r
 // eof - $RCSfile$\r