From 3f6669acc6485e724c4ff79620e4de0f8c26734c Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Mon, 11 Jan 2016 18:15:34 -0500 Subject: [PATCH] ... --- appli/cpPipelineEditor/QNodesEditor.cxx | 53 ++++++++++++++++++++- appli/cpPipelineEditor/QNodesEditor.h | 1 + appli/cpPipelineEditor/cpPipelineEditor.cxx | 1 + lib/cpExtensions/DataStructures/Graph.hxx | 4 +- lib/cpPlugins/Interface/Workspace.cxx | 53 +++++++++++++++++++++ lib/cpPlugins/Interface/Workspace.h | 17 ++++++- 6 files changed, 124 insertions(+), 5 deletions(-) diff --git a/appli/cpPipelineEditor/QNodesEditor.cxx b/appli/cpPipelineEditor/QNodesEditor.cxx index 6417636..e026dda 100644 --- a/appli/cpPipelineEditor/QNodesEditor.cxx +++ b/appli/cpPipelineEditor/QNodesEditor.cxx @@ -36,6 +36,7 @@ #include #include #include +#include #include "QNEPort.h" #include "QNEConnection.h" @@ -86,7 +87,7 @@ setWorkspace( TWorkspace* ws ) { this->_CreateBlock( dynamic_cast< TFilter* >( vIt->second.GetPointer( ) ), - QPointF( ) + QPointF( vIt->second->GetViewX( ), vIt->second->GetViewY( ) ) ); } // rof @@ -161,6 +162,25 @@ createFilter( const std::string& filter, const QPointF& pnt ) return( "" ); } +// ------------------------------------------------------------------------- +void PipelineEditor::QNodesEditor:: +synchronizeBlockPositions( ) +{ + auto bIt = this->m_Graph->BeginVertices( ); + auto fIt = this->m_Workspace->GetGraph( )->BeginVertices( ); + while( + bIt != this->m_Graph->EndVertices( ) && + fIt != this->m_Workspace->GetGraph( )->EndVertices( ) + ) + { + auto pos = bIt->second->scenePos( ); + fIt->second->SetViewCoords( pos.x( ), pos.y( ) ); + bIt++; + fIt++; + + } // elihw +} + // ------------------------------------------------------------------------- void PipelineEditor::QNodesEditor:: install( QGraphicsScene* s ) @@ -193,7 +213,7 @@ _CreateBlock( TFilter* f, const QPointF& pnt ) QNEBlock* b = new QNEBlock( 0, this->m_Scene ); b->setNamePort( f->GetName( ) ); b->setTypePort( f->GetClassName( ) ); - // TODO: b->setScenePos( pnt ); + b->setPos( pnt ); // Add input ports std::set< std::string > inputs; @@ -225,6 +245,35 @@ _DoubleClick( QGraphicsSceneMouseEvent* evt, QGraphicsItem* item ) if( block != NULL ) { + QString old_name = block->namePort( )->name( ); + bool ok; + QString new_name = + QInputDialog::getText( + dynamic_cast< QWidget* >( this->parent( ) ), + "Change filter name", + "Filter name:", + QLineEdit::Normal, + old_name, + &ok + ); + if( ok && !new_name.isEmpty( ) && old_name != new_name ) + { + ok = this->m_Graph->RenameVertex( + old_name.toStdString( ), + new_name.toStdString( ) + ); + if( ok ) + { + block->namePort( )->setName( new_name ); + this->m_Workspace->GetGraph( )->RenameVertex( + old_name.toStdString( ), + new_name.toStdString( ) + ); + + } // fi + + } // fi + /* TODO auto ports = block->ports( ); std::string name = ""; diff --git a/appli/cpPipelineEditor/QNodesEditor.h b/appli/cpPipelineEditor/QNodesEditor.h index e2dc37c..a47b6bf 100644 --- a/appli/cpPipelineEditor/QNodesEditor.h +++ b/appli/cpPipelineEditor/QNodesEditor.h @@ -70,6 +70,7 @@ namespace PipelineEditor const std::string& filter, const QPointF& pnt = QPointF( ) ); + void synchronizeBlockPositions( ); void install( QGraphicsScene* s ); bool eventFilter( QObject* o, QEvent* e ); diff --git a/appli/cpPipelineEditor/cpPipelineEditor.cxx b/appli/cpPipelineEditor/cpPipelineEditor.cxx index 6bda2a7..088edbc 100644 --- a/appli/cpPipelineEditor/cpPipelineEditor.cxx +++ b/appli/cpPipelineEditor/cpPipelineEditor.cxx @@ -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( diff --git a/lib/cpExtensions/DataStructures/Graph.hxx b/lib/cpExtensions/DataStructures/Graph.hxx index d89be75..c9c67cf 100644 --- a/lib/cpExtensions/DataStructures/Graph.hxx +++ b/lib/cpExtensions/DataStructures/Graph.hxx @@ -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 diff --git a/lib/cpPlugins/Interface/Workspace.cxx b/lib/cpPlugins/Interface/Workspace.cxx index 8a588af..a722908 100644 --- a/lib/cpPlugins/Interface/Workspace.cxx +++ b/lib/cpPlugins/Interface/Workspace.cxx @@ -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( ) diff --git a/lib/cpPlugins/Interface/Workspace.h b/lib/cpPlugins/Interface/Workspace.h index 9a79d29..c11d155 100644 --- a/lib/cpPlugins/Interface/Workspace.h +++ b/lib/cpPlugins/Interface/Workspace.h @@ -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 -- 2.47.1