]> Creatis software - cpPlugins.git/blobdiff - appli/cpPipelineEditor/QNEBlock.cxx
More on graph editor
[cpPlugins.git] / appli / cpPipelineEditor / QNEBlock.cxx
index 2b7ed51f6bc52f5580e4f9d6145f5086d0af1773..67f4a9bd477d873a924b5e357298233797170128 100644 (file)
@@ -33,6 +33,7 @@
 #include <QStyleOptionGraphicsItem>\r
 \r
 #include "QNEPort.h"\r
+#include "QNEConnection.h"\r
 \r
 // -------------------------------------------------------------------------\r
 PipelineEditor::QNEBlock::\r
@@ -95,6 +96,13 @@ PipelineEditor::QNEInputPort* PipelineEditor::QNEBlock::
 addInputPort( const QString& txt )\r
 {\r
   QNEInputPort* ip = new QNEInputPort( this );\r
+  ip->setExtendedName(\r
+    (\r
+      txt.toStdString( ) +\r
+      std::string( "@" ) +\r
+      this->namePort( ).toStdString( )\r
+      ).c_str( )\r
+    );\r
   ip->setName( txt );\r
   this->m_InputPorts[ txt.toStdString( ) ] = ip;\r
   this->_configPort( ip );\r
@@ -106,12 +114,49 @@ PipelineEditor::QNEOutputPort* PipelineEditor::QNEBlock::
 addOutputPort( const QString& txt )\r
 {\r
   QNEOutputPort* op = new QNEOutputPort( this );\r
+  op->setExtendedName(\r
+    (\r
+      txt.toStdString( ) +\r
+      std::string( "@" ) +\r
+      this->namePort( ).toStdString( )\r
+      ).c_str( )\r
+    );\r
   op->setName( txt );\r
   this->m_OutputPorts[ txt.toStdString( ) ] = op;\r
   this->_configPort( op );\r
   return( op );\r
 }\r
 \r
+// -------------------------------------------------------------------------\r
+bool PipelineEditor::QNEBlock::\r
+extendInputPort( const QString& txt, QNEConnection* conn )\r
+{\r
+  auto p = this->m_InputPorts.find( txt.toStdString( ) );\r
+  auto i = this->m_ExtInputPorts.find( txt.toStdString( ) );\r
+  if( p != this->m_InputPorts.end( ) && i == this->m_ExtInputPorts.end( ) )\r
+  {\r
+    this->m_ExtInputPorts[ txt.toStdString( ) ] = conn;\r
+    return( true );\r
+  }\r
+  else\r
+    return( false );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+bool PipelineEditor::QNEBlock::\r
+extendOutputPort( const QString& txt, QNEConnection* conn )\r
+{\r
+  auto p = this->m_OutputPorts.find( txt.toStdString( ) );\r
+  auto i = this->m_ExtOutputPorts.find( txt.toStdString( ) );\r
+  if( p != this->m_OutputPorts.end( ) && i == this->m_ExtOutputPorts.end( ) )\r
+  {\r
+    this->m_ExtOutputPorts[ txt.toStdString( ) ] = conn;\r
+    return( true );\r
+  }\r
+  else\r
+    return( false );\r
+}\r
+\r
 // -------------------------------------------------------------------------\r
 PipelineEditor::QNEInputPort* PipelineEditor::QNEBlock::\r
 inputPort( const QString& txt )\r
@@ -134,6 +179,13 @@ outputPort( const QString& txt )
     return( NULL );\r
 }\r
 \r
+// -------------------------------------------------------------------------\r
+QString PipelineEditor::QNEBlock::\r
+namePort( ) const\r
+{\r
+  return( this->m_NamePort->name( ) );\r
+}\r
+\r
 // -------------------------------------------------------------------------\r
 const PipelineEditor::QNEInputPort* PipelineEditor::QNEBlock::\r
 inputPort( const QString& txt ) const\r
@@ -157,10 +209,25 @@ outputPort( const QString& txt ) const
 }\r
 \r
 // -------------------------------------------------------------------------\r
-const QString& PipelineEditor::QNEBlock::\r
-namePort( ) const\r
+const PipelineEditor::QNEConnection* PipelineEditor::QNEBlock::\r
+extendedInputPort( const QString& txt ) const\r
 {\r
-  return( this->m_NamePort->name( ) );\r
+  auto i = this->m_ExtInputPorts.find( txt.toStdString( ) );\r
+  if( i != this->m_ExtInputPorts.end( ) )\r
+    return( i->second );\r
+  else\r
+    return( NULL );\r
+}\r
+\r
+// -------------------------------------------------------------------------\r
+const PipelineEditor::QNEConnection* PipelineEditor::QNEBlock::\r
+extendedOutputPort( const QString& txt ) const\r
+{\r
+  auto i = this->m_ExtOutputPorts.find( txt.toStdString( ) );\r
+  if( i != this->m_ExtOutputPorts.end( ) )\r
+    return( i->second );\r
+  else\r
+    return( NULL );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
@@ -210,11 +277,13 @@ _configPort( QNEPort* port )
   port->setBlock( this );\r
 \r
   QFontMetrics fm( this->scene( )->font( ) );\r
-  int w = fm.width( port->name( ) );\r
+  int w = fm.width( port->name( ) ) + ( 4 * port->radius( ) );\r
   int h = fm.height( );\r
   if( w > this->m_Width - this->m_HorzMargin )\r
     this->m_Width = w + this->m_HorzMargin;\r
-  this->m_Height += h;\r
+  this->m_Height = this->m_InputPorts.size( ) + this->m_OutputPorts.size( );\r
+  this->m_Height += 4;\r
+  this->m_Height *= h;\r
 \r
   QPainterPath pth;\r
   pth.addRoundedRect(\r
@@ -232,10 +301,28 @@ _configPort( QNEPort* port )
     if( p == NULL )\r
       continue;\r
 \r
-    if( dynamic_cast< QNEOutputPort* >( p ) != NULL )\r
-      p->setPos( this->m_Width / 2 + port->radius( ), y );\r
-    else\r
-      p->setPos( -this->m_Width / 2 - port->radius( ), y );\r
+    if( dynamic_cast< QNENamePort* >( i ) != NULL )\r
+      i->setPos( -this->m_Width / 2 + port->radius( ), y );\r
+    else if( dynamic_cast< QNETypePort* >( i ) != NULL )\r
+    {\r
+      i->setPos( -this->m_Width / 2 + port->radius( ), y );\r
+      y += h;\r
+    }\r
+    else if( dynamic_cast< QNEInputPort* >( i ) != NULL )\r
+      i->setPos( -this->m_Width / 2 - 2 * port->radius( ), y );\r
+    else if( dynamic_cast< QNEOutputPort* >( i ) != NULL )\r
+      i->setPos( this->m_Width / 2, y );\r
+\r
+    /* TODO\r
+       QNEPort* p = dynamic_cast< QNEPort* >( i );\r
+       if( p == NULL )\r
+       continue;\r
+\r
+       if( dynamic_cast< QNEOutputPort* >( p ) != NULL )\r
+       p->setPos( this->m_Width / 2 + port->radius( ), y );\r
+       else\r
+       p->setPos( -this->m_Width / 2 - port->radius( ), y );\r
+    */\r
     y += h;\r
 \r
   } // rof\r