]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Mon, 11 Jan 2016 23:15:34 +0000 (18:15 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Mon, 11 Jan 2016 23:15:34 +0000 (18:15 -0500)
appli/cpPipelineEditor/QNodesEditor.cxx
appli/cpPipelineEditor/QNodesEditor.h
appli/cpPipelineEditor/cpPipelineEditor.cxx
lib/cpExtensions/DataStructures/Graph.hxx
lib/cpPlugins/Interface/Workspace.cxx
lib/cpPlugins/Interface/Workspace.h

index 6417636e44ff256c6d30cbee0ce3786b5814e228..e026dda9d12f683e1cf9c495dbe9662ace367fd6 100644 (file)
@@ -36,6 +36,7 @@
 #include <QGraphicsSceneMoveEvent>\r
 #include <QGraphicsSceneResizeEvent>\r
 #include <QGraphicsSceneWheelEvent>\r
+#include <QInputDialog>\r
 \r
 #include "QNEPort.h"\r
 #include "QNEConnection.h"\r
@@ -86,7 +87,7 @@ setWorkspace( TWorkspace* ws )
   {\r
     this->_CreateBlock(\r
       dynamic_cast< TFilter* >( vIt->second.GetPointer( ) ),\r
-      QPointF( )\r
+      QPointF( vIt->second->GetViewX( ), vIt->second->GetViewY( ) )\r
       );\r
 \r
   } // rof\r
@@ -161,6 +162,25 @@ createFilter( const std::string& filter, const QPointF& pnt )
     return( "" );\r
 }\r
 \r
+// -------------------------------------------------------------------------\r
+void PipelineEditor::QNodesEditor::\r
+synchronizeBlockPositions( )\r
+{\r
+  auto bIt = this->m_Graph->BeginVertices( );\r
+  auto fIt = this->m_Workspace->GetGraph( )->BeginVertices( );\r
+  while(\r
+    bIt != this->m_Graph->EndVertices( ) &&\r
+    fIt != this->m_Workspace->GetGraph( )->EndVertices( )\r
+    )\r
+  {\r
+    auto pos = bIt->second->scenePos( );\r
+    fIt->second->SetViewCoords( pos.x( ), pos.y( ) );\r
+    bIt++;\r
+    fIt++;\r
+\r
+  } // elihw\r
+}\r
+\r
 // -------------------------------------------------------------------------\r
 void PipelineEditor::QNodesEditor::\r
 install( QGraphicsScene* s )\r
@@ -193,7 +213,7 @@ _CreateBlock( TFilter* f, const QPointF& pnt )
   QNEBlock* b = new QNEBlock( 0, this->m_Scene );\r
   b->setNamePort( f->GetName( ) );\r
   b->setTypePort( f->GetClassName( ) );\r
-  // TODO: b->setScenePos( pnt );\r
+  b->setPos( pnt );\r
 \r
   // Add input ports\r
   std::set< std::string > inputs;\r
@@ -225,6 +245,35 @@ _DoubleClick( QGraphicsSceneMouseEvent* evt, QGraphicsItem* item )
 \r
     if( block != NULL )\r
     {\r
+      QString old_name = block->namePort( )->name( );\r
+      bool ok;\r
+      QString new_name =\r
+        QInputDialog::getText(\r
+          dynamic_cast< QWidget* >( this->parent( ) ),\r
+          "Change filter name",\r
+          "Filter name:",\r
+          QLineEdit::Normal,\r
+          old_name,\r
+          &ok\r
+          );\r
+      if( ok && !new_name.isEmpty( ) && old_name != new_name )\r
+      {\r
+        ok = this->m_Graph->RenameVertex(\r
+          old_name.toStdString( ),\r
+          new_name.toStdString( )\r
+          );\r
+        if( ok )\r
+        {\r
+          block->namePort( )->setName( new_name );\r
+          this->m_Workspace->GetGraph( )->RenameVertex(\r
+            old_name.toStdString( ),\r
+            new_name.toStdString( )\r
+            );\r
+\r
+        } // fi\r
+\r
+      } // fi\r
+\r
       /* TODO\r
          auto ports = block->ports( );\r
          std::string name = "";\r
index e2dc37c7f7fc6718234a15ee455c3350a45ed955..a47b6bf738b666d4a40f290bf6d6dc8c00f31f6e 100644 (file)
@@ -70,6 +70,7 @@ namespace PipelineEditor
       const std::string& filter,\r
       const QPointF& pnt = QPointF( )\r
       );\r
+    void synchronizeBlockPositions( );\r
 \r
     void install( QGraphicsScene* s );\r
     bool eventFilter( QObject* o, QEvent* e );\r
index 6bda2a75087139d916155dfd18612aca04a1ffc7..088edbcf999652ec976ddf31bf81b20aa88f3920 100644 (file)
@@ -243,6 +243,7 @@ _ActionSaveWorkspace( )
     return;
   std::string fname = dlg.selectedFiles( ).at( 0 ).toStdString( );
 
+  this->m_UI->Canvas->editor( )->synchronizeBlockPositions( );
   std::string err = this->m_Workspace->SaveWorkspace( fname );
   if( err != "" )
     QMessageBox::critical(
index d89be75d279fed8105849d18a16913f4d5d195eb..c9c67cf4d709a77be4cfb264d56acc356715003b 100644 (file)
@@ -124,9 +124,9 @@ RenameVertex( const I& old_index, const I& new_index )
       for( ; rIt != mIt->second.end( ); ++rIt )
       {
         if( mIt->first == old_index )
-          this->m_Matrix[ new_index ][ rIt->first ].push_back( rIt->second );
+          this->m_Matrix[ new_index ][ rIt->first ] = rIt->second;
         else if( rIt->first == old_index )
-          this->m_Matrix[ mIt->first ][ new_index ].push_back( rIt->second );
+          this->m_Matrix[ mIt->first ][ new_index ] = rIt->second;
 
       } // rof
 
index 8a588afc4377279f49712bcf47aa3649ce004d85..a722908f168a0cafb535d40eb44e3437617efa5b 100644 (file)
@@ -199,6 +199,25 @@ Connect(
   return( false );
 }
 
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::Workspace::
+Connect( const std::string& i, const std::string& o )
+{
+  auto ii = this->m_InputPorts.find( i );
+  auto oi = this->m_OutputPorts.find( o );
+  if( ii != this->m_InputPorts.end( ) && oi != this->m_OutputPorts.end( ) )
+    return(
+      this->Connect(
+        oi->second.first,
+        ii->second.first,
+        oi->second.second,
+        ii->second.second
+        )
+      );
+  else
+    return( false );
+}
+
 // -------------------------------------------------------------------------
 cpPlugins::Interface::Workspace::
 TParameters* cpPlugins::Interface::Workspace::
@@ -270,6 +289,40 @@ Reduce( const std::string& name )
   return( false );
 }
 
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::Workspace::
+AddInputPort(
+  const std::string& name,
+  const std::string& filter, const std::string& filter_input
+  )
+{
+  this->m_InputPorts[ name ] = TGlobalPort( filter, filter_input );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::Workspace::
+AddOutputPort(
+  const std::string& name,
+  const std::string& filter, const std::string& filter_output
+  )
+{
+  this->m_OutputPorts[ name ] = TGlobalPort( filter, filter_output );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::Workspace::
+ClearInputPorts( )
+{
+  this->m_InputPorts.clear( );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::Workspace::
+ClearOutputPorts( )
+{
+  this->m_OutputPorts.clear( );
+}
+
 // -------------------------------------------------------------------------
 std::string cpPlugins::Interface::Workspace::
 Execute( )
index 9a79d29ae15a3023b9b84eb26666cb7ce6c8c475..c11d1554b5071939cf37dd2fcac61b522483f579 100644 (file)
@@ -28,7 +28,9 @@ namespace cpPlugins
       typedef TFilter::TParameters                TParameters;
 
       // Various types
-      typedef std::set< std::string > TStringContainer;
+      typedef std::set< std::string >               TStringContainer;
+      typedef std::pair< std::string, std::string > TGlobalPort;
+      typedef std::map< std::string, TGlobalPort >  TGlobalPorts;
 
       // Graph type
       typedef std::pair< std::string, std::string > TConnection;
@@ -58,6 +60,7 @@ namespace cpPlugins
         const std::string& output_name,
         const std::string& input_name
         );
+      bool Connect( const std::string& i, const std::string& o );
       TParameters* GetParameters( const std::string& name );
       const TParameters* GetParameters( const std::string& name ) const;
       TFilter* GetFilter( const std::string& name );
@@ -66,6 +69,16 @@ namespace cpPlugins
 
       // Graph reduction
       bool Reduce( const std::string& name );
+      void AddInputPort(
+        const std::string& name,
+        const std::string& filter, const std::string& filter_input
+        );
+      void AddOutputPort(
+        const std::string& name,
+        const std::string& filter, const std::string& filter_output
+        );
+      void ClearInputPorts( );
+      void ClearOutputPorts( );
 
       // Pipeline execution
       std::string Execute( );
@@ -80,6 +93,8 @@ namespace cpPlugins
 
       // Processing graph
       typename TGraph::Pointer m_Graph;
+      TGlobalPorts m_InputPorts;
+      TGlobalPorts m_OutputPorts;
     };
 
   } // ecapseman