]> Creatis software - cpPlugins.git/blobdiff - appli/cpPipelineEditor/QNodesEditorCanvas.cxx
More on graph editor
[cpPlugins.git] / appli / cpPipelineEditor / QNodesEditorCanvas.cxx
index 6d970adb25a9fcd385f28a8ddf27269d4a7dcf7d..d253f78f8e9288cf7c7a14bf98c4ceec40d5f494 100644 (file)
@@ -11,8 +11,7 @@
 // -------------------------------------------------------------------------
 PipelineEditor::QNodesEditorCanvas::
 QNodesEditorCanvas( QWidget* parent )
-  : QGraphicsView( parent ),
-    m_Workspace( NULL )
+  : QGraphicsView( parent )
 {
   QGraphicsScene* scene = new QGraphicsScene( this );
   this->setScene( scene );
@@ -30,97 +29,19 @@ PipelineEditor::QNodesEditorCanvas::
 }
 
 // -------------------------------------------------------------------------
-PipelineEditor::QNodesEditorCanvas::
-TWorkspace* PipelineEditor::QNodesEditorCanvas::
-workspace( )
+PipelineEditor::
+QNodesEditor* PipelineEditor::QNodesEditorCanvas::
+editor( )
 {
-  return( this->m_Workspace );
+  return( this->m_Editor );
 }
 
 // -------------------------------------------------------------------------
-const PipelineEditor::QNodesEditorCanvas::
-TWorkspace* PipelineEditor::QNodesEditorCanvas::
-workspace( ) const
+const PipelineEditor::
+QNodesEditor* PipelineEditor::QNodesEditorCanvas::
+editor( ) const
 {
-  return( this->m_Workspace );
-}
-
-// -------------------------------------------------------------------------
-void PipelineEditor::QNodesEditorCanvas::
-setWorkspace( TWorkspace* ws )
-{
-  if( this->m_Workspace == ws )
-    return;
-  this->m_Workspace = ws;
-  QGraphicsScene* scene = this->scene( );
-
-  // Create graph
-  this->m_Graph = TGraph::New( );
-
-  // Add vertices and keep track of ports
-  std::map< std::string, std::map< std::string, QNEPort* > >
-    in_ports, out_ports;
-  auto vIt = this->m_Workspace->GetGraph( )->BeginVertices( );
-  auto vIt_end = this->m_Workspace->GetGraph( )->EndVertices( );
-  for( ; vIt != vIt_end; ++vIt )
-  {
-    this->_createBlock( dynamic_cast< TFilter* >( vIt->second.GetPointer( ) ) );
-#error ACA VOY
-    // Add block
-    QNEBlock* b = new QNEBlock( 0, scene );
-    b->addPort( vIt->second->GetName( ), 0, QNEPort::NamePort );
-    b->addPort( vIt->second->GetClassName( ).c_str( ), 0, QNEPort::TypePort );
-
-    // Get filter
-    if( f == NULL )
-      continue;
-
-    // Add input ports
-    std::set< std::string > inputs;
-    f->GetInputsNames( inputs );
-    for( auto iIt = inputs.begin( ); iIt != inputs.end( ); ++iIt )
-      in_ports[ vIt->first ][ *iIt ] = b->addInputPort( iIt->c_str( ) );
-
-    // Add output ports
-    std::set< std::string > outputs;
-    f->GetOutputsNames( outputs );
-    for( auto oIt = outputs.begin( ); oIt != outputs.end( ); ++oIt )
-      out_ports[ vIt->first ][ *oIt ] = b->addOutputPort( oIt->c_str( ) );
-
-    // Keep a trace of this visual graph
-    this->m_Graph->InsertVertex( vIt->first, b );
-
-  } // rof
-
-  // Add edges
-  /* TODO
-     auto rIt = this->m_Workspace->GetGraph( )->BeginEdgesRows( );
-     auto rIt_end = this->m_Workspace->GetGraph( )->EndEdgesRows( );
-     for( ; rIt != rIt_end; ++rIt )
-     {
-     auto cIt = rIt->second.begin( );
-     for( ; cIt != rIt->second.end( ); ++cIt )
-     {
-     auto eIt = cIt->second.begin( );
-     for( ; eIt != cIt->second.end( ); ++eIt )
-     {
-     QNEPort* p1 = out_ports[ rIt->first ][ eIt->first ];
-     QNEPort* p2 = in_ports[ cIt->first ][ eIt->second ];
-     if( p1 != NULL && p2 != NULL )
-     {
-     QNEConnection* conn = new QNEConnection( 0, scene );
-     conn->setPort1( p1 );
-     conn->setPort2( p2 );
-     this->m_Graph->AddConnection( rIt->first, cIt->first, conn );
-
-     } // fi
-
-     } // rof
-
-     } // rof
-
-     } // rof
-  */
+  return( this->m_Editor );
 }
 
 // -------------------------------------------------------------------------
@@ -171,8 +92,6 @@ dragMoveEvent( QDragMoveEvent* event )
 void PipelineEditor::QNodesEditorCanvas::
 dropEvent( QDropEvent* event )
 {
-  if( this->m_Workspace == NULL )
-    return;
   const QMimeData* mime = event->mimeData( );
   if( !( mime->hasFormat( "application/x-qabstractitemmodeldatalist" ) ) )
     return;
@@ -184,16 +103,9 @@ dropEvent( QDropEvent* event )
 
   QList< QTreeWidgetItem* > items = tree->selectedItems( );
   for( auto iIt = items.begin( ); iIt != items.end( ); ++iIt )
-  {
-    std::string filter = ( *iIt )->text( 0 ).toStdString( );
-    std::string name = filter;
-    if( this->m_Workspace->GetFilter( name ) != NULL )
-      name += std::string( "_" );
-    if( this->m_Workspace->CreateFilter( filter, name ) )
-    {
-    } // fi
-
-  } // rof
+    this->m_Editor->createFilter(
+      ( *iIt )->text( 0 ).toStdString( ), event->pos( )
+      );
 }
 
 // -------------------------------------------------------------------------
@@ -210,6 +122,7 @@ _scaleView( qreal scaleFactor )
 }
 
 // -------------------------------------------------------------------------
+  /*
 void PipelineEditor::QNodesEditorCanvas::
 _createBlock( TFilter* f )
 {
@@ -239,7 +152,6 @@ _createBlock( TFilter* f )
   this->m_Graph->InsertVertex( f->GetName( ), b );
 
   // Add vertices and keep track of ports
-  /*
     std::map< std::string, std::map< std::string, QNEPort* > >
     in_ports, out_ports;
     auto vIt = this->m_Workspace->GetGraph( )->BeginVertices( );
@@ -272,8 +184,8 @@ _createBlock( TFilter* f )
     this->m_Graph->InsertVertex( vIt->first, b );
 
     } // rof
-  */
 }
+  */
 
 // eof - $RCSfile$