]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Tue, 28 Jun 2016 23:30:10 +0000 (18:30 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Tue, 28 Jun 2016 23:30:10 +0000 (18:30 -0500)
lib/cpBaseQtApplication/Editor.cxx
lib/cpBaseQtApplication/Editor.h
lib/cpBaseQtApplication/MainWindow.cxx
lib/cpExtensions/DataStructures/Graph.hxx
lib/cpPlugins/ProcessObject.h
lib/cpPlugins/ProcessObject.hxx
lib/cpPlugins/Workspace.cxx
lib/cpPlugins/Workspace.h

index 35b8a61ceb7f52dac45909f0d22d0c26057a51c7..fb911c3862875e65ea093aa8e087e759b65095f3 100644 (file)
@@ -68,9 +68,18 @@ void cpBaseQtApplication::Editor::
 setWorkspace( TWorkspace* ws )\r
 {\r
   this->m_Workspace = ws;\r
-  this->m_Graph = TGraph::New( );\r
+  this->redrawWorkspace( );\r
+}\r
 \r
+// -------------------------------------------------------------------------\r
+void cpBaseQtApplication::Editor::\r
+redrawWorkspace( )\r
+{\r
+  if( this->m_Workspace == NULL )\r
+    return;\r
+  \r
   // Create blocks\r
+  std::map< std::string, Block* > blocks;\r
   auto vIt = this->m_Workspace->GetGraph( )->BeginVertices( );\r
   auto vIt_end = this->m_Workspace->GetGraph( )->EndVertices( );\r
   for( ; vIt != vIt_end; ++vIt )\r
@@ -80,8 +89,7 @@ setWorkspace( TWorkspace* ws )
       vIt->first.c_str( ),\r
       QPointF( vIt->second->GetViewX( ), vIt->second->GetViewY( ) )\r
       );\r
-    if( b != NULL )\r
-      this->m_Graph->SetVertex( vIt->first, b );\r
+    blocks[ vIt->first ] = b;\r
 \r
   } // rof\r
 \r
@@ -90,11 +98,11 @@ setWorkspace( TWorkspace* ws )
   auto rIt_end = this->m_Workspace->GetGraph( )->EndEdgesRows( );\r
   for( ; rIt != rIt_end; ++rIt )\r
   {\r
-    Block* orig = this->m_Graph->GetVertex( rIt->first );\r
+    Block* orig = blocks[ rIt->first ];\r
     auto cIt = rIt->second.begin( );\r
     for( ; cIt != rIt->second.end( ); ++cIt )\r
     {\r
-      Block* dest = this->m_Graph->GetVertex( cIt->first );\r
+      Block* dest = blocks[ cIt->first ];\r
       auto eIt = cIt->second.begin( );\r
       for( ; eIt != cIt->second.end( ); ++eIt )\r
       {\r
@@ -108,7 +116,6 @@ setWorkspace( TWorkspace* ws )
         c->setPort2( ip );\r
         c->updatePosFromPorts( );\r
         c->updatePath( );\r
-        this->m_Graph->AddEdge( rIt->first, cIt->first, c );\r
 \r
       } // rof\r
 \r
@@ -145,8 +152,10 @@ createFilter(
 bool cpBaseQtApplication::Editor::\r
 deleteFilter( const std::string& name )\r
 {\r
-  std::cout << name << std::endl;\r
-  return( false );\r
+  if( this->m_Workspace != NULL )\r
+    return( this->m_Workspace->RemoveFilter( name ) );\r
+  else\r
+    return( false );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
@@ -156,19 +165,23 @@ deleteConnection(
   const std::string& in, const std::string& out\r
   )\r
 {\r
-  std::cout\r
-    << src << " "\r
-    << des << " "\r
-    << in << " "\r
-    << out << std::endl;\r
-  return( false );\r
+  if( this->m_Workspace != NULL )\r
+    return( this->m_Workspace->Disconnect( src, des, in, out ) );\r
+  else\r
+    return( false );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
 void cpBaseQtApplication::Editor::\r
 clear( )\r
 {\r
-  std::cout << "Editor::clear" << std::endl;\r
+  std::cout << "Editor: clear" << std::endl;\r
+  /* TODO\r
+     auto vIt = this->m_Graph.BeginVertices( );\r
+     for( ; vIt != this->m_Graph.EndVertices( ); ++vIt )\r
+     {\r
+     } // rof\r
+  */\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
@@ -356,6 +369,7 @@ cpBaseQtApplication_Editor_Callback_CODE( HoverMove )
 // -------------------------------------------------------------------------\r
 cpBaseQtApplication_Editor_Callback_CODE( MouseDoubleClick )\r
 {\r
+  /* TODO\r
   QGraphicsItem* item = this->itemAt( evt->scenePos( ) );\r
   if( item == NULL )\r
     return;\r
@@ -481,7 +495,6 @@ cpBaseQtApplication_Editor_Callback_CODE( MouseDoubleClick )
     } // fi\r
   }\r
   break;\r
-  /* TODO:\r
      case Qt::RightButton:\r
      {\r
      }\r
@@ -490,10 +503,10 @@ cpBaseQtApplication_Editor_Callback_CODE( MouseDoubleClick )
      {\r
      }\r
      break;\r
-  */\r
   default:\r
     break;\r
   } // hctiws\r
+  */\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
@@ -583,11 +596,6 @@ cpBaseQtApplication_Editor_Callback_CODE( MouseRelease )
             port1->name( ).toStdString( ),\r
             port2->name( ).toStdString( )\r
             );\r
-          this->m_Graph->AddEdge(\r
-            port1->block( )->namePort( ).toStdString( ),\r
-            port2->block( )->namePort( ).toStdString( ),\r
-            this->m_ActualConnection\r
-            );\r
         }\r
         else\r
           delete this->m_ActualConnection;\r
index 073de08f415e79a3c9ad332bf3f8710dcb16c11d..5eab4bfc8b97b121e93e206f757b97ff0a8fa666 100644 (file)
@@ -2,7 +2,6 @@
 #define __CPBASEQTAPPLICATION__EDITOR__H__\r
 \r
 #include <cpBaseQtApplication_Export.h>\r
-#include <cpExtensions/DataStructures/Graph.h>\r
 #include <cpPlugins/Workspace.h>\r
 #include <QObject>\r
 #include <QPointF>\r
@@ -41,9 +40,6 @@ namespace cpBaseQtApplication
 \r
     typedef cpPlugins::Workspace     TWorkspace;\r
     typedef cpPlugins::ProcessObject TFilter;\r
-    typedef\r
-      cpExtensions::DataStructures::\r
-      Graph< Block*, Connection*, std::string > TGraph;\r
 \r
   public:\r
     explicit Editor( QObject* parent = 0 );\r
@@ -52,6 +48,7 @@ namespace cpBaseQtApplication
     TWorkspace* workspace( );\r
     const TWorkspace* workspace( ) const;\r
     void setWorkspace( TWorkspace* ws );\r
+    void redrawWorkspace( );\r
 \r
     std::string createFilter(\r
       const std::string& category, const std::string& filter,\r
@@ -138,7 +135,6 @@ namespace cpBaseQtApplication
     Connection* m_ActualConnection;\r
 \r
     TWorkspace* m_Workspace;\r
-    TGraph::Pointer m_Graph;\r
   };\r
 \r
 } // ecapseman\r
index 830508fb18d58a60ef0f14106d746735ff2314e0..41f2df5248725e9ecebc71977d2b3880dd973969 100644 (file)
@@ -297,10 +297,8 @@ _LoadWorkspace( const std::string& filename )
   }
   else
   {
-    /* TODO
-       if( this->m_Editor != NULL )
-       this->m_Editor->setWorkspace( this->m_Workspace );
-    */
+    if( this->m_Editor != NULL )
+      this->m_Editor->redrawWorkspace( );
 
   } // fi
 }
index d2d2d23b8382ee6847eb7028386b7f66adb9c4a7..8470099faf483a9e063a1795e1b667b2e2c811bd 100644 (file)
@@ -131,7 +131,14 @@ RemoveEdge( const I& orig, const I& dest, const C& cost )
     auto r = m->second.find( dest );
     if( r != m->second.end( ) )
     {
-      auto e = std::find( r->second.begin( ), r->second.end( ), cost );
+      auto e = r->second.end( );
+      for(
+        auto i = r->second.begin( );
+        i != r->second.end( ) && e == r->second.end( );
+        ++i
+        )
+        if( *i == cost )
+          e = i;
       if( e != r->second.end( ) )
       {
         r->second.erase( e );
index d161e7782241280d7d7766e2f6cf86f01e9236b7..ca5700abd857897cf23ffbf5cd49e97fc1c5872f 100644 (file)
@@ -78,6 +78,9 @@ namespace cpPlugins
 
     bool SetInputPort( const std::string& id, const OutputPort& port );
 
+    template< class _TType >
+      inline bool SetInput( const std::string& id, _TType* obj );
+
     void DisconnectInputs( );
     void DisconnectOutputs( );
     void Disconnect( );
index 9be267531b9609ea78d08137dd516981f6cae717..99954d49560a4a74e7c8eeb15219dfdcb4355173 100644 (file)
@@ -85,6 +85,22 @@ GetOutputData( const std::string& name )
     return( NULL );
 }
 
+// -------------------------------------------------------------------------
+template< class _TType >
+bool cpPlugins::ProcessObject::
+SetInput( const std::string& id, _TType* obj )
+{
+  auto i = this->m_Inputs.find( id );
+  if( i != this->m_Inputs.end( ) )
+  {
+    i->second = obj;
+    this->Modified( );
+    return( true );
+  }
+  else
+    return( false );
+}
+
 // -------------------------------------------------------------------------
 template< class O >
 void cpPlugins::ProcessObject::
index dd4ade8e7237fb4e3ad6482808a46ba27d66c29e..b3f6af70a41e280e55d49211b6499563748e120d 100644 (file)
@@ -172,9 +172,42 @@ RenameFilter( const std::string& old_name, const std::string& new_name )
 }
 
 // -------------------------------------------------------------------------
-void cpPlugins::Workspace::
+bool cpPlugins::Workspace::
 RemoveFilter( const std::string& name )
 {
+  auto filter = this->GetFilter( name );
+  if( filter != NULL )
+  {
+    auto vIt = this->m_Graph->BeginVertices( );
+    for( ; vIt != this->m_Graph->EndVertices( ); ++vIt )
+    {
+      if( vIt->first != name )
+      {
+        if( this->m_Graph->HasEdge( name, vIt->first ) )
+        {
+          auto edges = this->m_Graph->GetEdges( name, vIt->first );
+          auto other = this->GetFilter( vIt->first );
+          for( auto eIt = edges.begin( ); eIt != edges.end( ); ++eIt )
+            other->SetInput( eIt->first, ( DataObject* )( NULL ) );
+
+        } // fi
+
+        if( this->m_Graph->HasEdge( vIt->first, name ) )
+        {
+          auto edges = this->m_Graph->GetEdges( vIt->first, name );
+          for( auto eIt = edges.begin( ); eIt != edges.end( ); ++eIt )
+            filter->SetInput( eIt->first, ( DataObject* )( NULL ) );
+
+        } // fi
+
+      } // fi
+
+    } // rof
+    this->m_Graph->RemoveVertex( name );
+    return( true );
+  }
+  else
+    return( false );
 }
 
 // -------------------------------------------------------------------------
@@ -306,6 +339,32 @@ Connect( const OutputPort& port, const std::string& exposed_port )
     return( false );
 }
 
+// -------------------------------------------------------------------------
+bool cpPlugins::Workspace::
+Disconnect(
+  const std::string& orig_filter, const std::string& dest_filter,
+  const std::string& output_name, const std::string& input_name
+  )
+{
+  // Get filters
+  ProcessObject* orig = this->GetFilter( orig_filter );
+  ProcessObject* dest = this->GetFilter( dest_filter );
+  if( orig == NULL || dest == NULL )
+    return( false );
+
+  // Real disconnection
+  if( dest->SetInput( input_name, ( DataObject* )( NULL ) ) )
+  {
+    this->m_Graph->RemoveEdge(
+      orig_filter, dest_filter,
+      TConnection( output_name, input_name )
+      );
+    return( true );
+  }
+  else
+    return( false );
+}
+
 // -------------------------------------------------------------------------
 bool cpPlugins::Workspace::
 Reduce( const std::string& name )
@@ -467,7 +526,7 @@ Execute( const std::string& name )
   ProcessObject* f = this->GetFilter( name );
   if( f == NULL )
   {
-    itkGenericExceptionMacro( 
+    itkGenericExceptionMacro(
       "cpPlugins::Workspace: Vertex \"" << name << "\" is not a filter."
       );
 
index eb146901c2862011b9f2fb1b3969e0b27fc5e96a..f22b2834e4d4ea9f70e9cae4b3c25e78eaa7e2d4 100644 (file)
@@ -16,11 +16,7 @@ namespace cpExtensions
 {
   namespace QT
   {
-// TODO: #ifdef cpPlugins_QT4
     class SimpleMPRWidget;
-// TODO: #else // cpPlugins_QT4
-// TODO:     typedef char SimpleMPRWidget;
-// TODO: #endif // cpPlugins_QT4
   }
 }
 
@@ -83,7 +79,7 @@ namespace cpPlugins
     bool RenameFilter(
       const std::string& old_name, const std::string& new_name
       );
-    void RemoveFilter( const std::string& name );
+    bool RemoveFilter( const std::string& name );
     void SetParameter( const std::string& name, const std::string& value );
 
     void SetPrintExecution( bool b );
@@ -105,11 +101,18 @@ namespace cpPlugins
       const std::string& output_name, const std::string& input_name
       );
     bool Connect( const OutputPort& port, const std::string& exposed_port );
-    void RemoveConnection(
-      const std::string& dest_filter, const std::string& input_name
+
+    bool Disconnect(
+      const std::string& orig_filter, const std::string& dest_filter,
+      const std::string& output_name, const std::string& input_name
       );
-    void RemoveConnection( const std::string& exposed_port );
-    void RemoveConnections( const std::string& dest_filter );
+    /* TODO
+       void RemoveConnection(
+       const std::string& dest_filter, const std::string& input_name
+       );
+       void RemoveConnection( const std::string& exposed_port );
+       void RemoveConnections( const std::string& dest_filter );
+    */
 
     // Graph reduction
     bool Reduce( const std::string& name );