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
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
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
c->setPort2( ip );\r
c->updatePosFromPorts( );\r
c->updatePath( );\r
- this->m_Graph->AddEdge( rIt->first, cIt->first, c );\r
\r
} // rof\r
\r
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
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
// -------------------------------------------------------------------------\r
cpBaseQtApplication_Editor_Callback_CODE( MouseDoubleClick )\r
{\r
+ /* TODO\r
QGraphicsItem* item = this->itemAt( evt->scenePos( ) );\r
if( item == NULL )\r
return;\r
} // fi\r
}\r
break;\r
- /* TODO:\r
case Qt::RightButton:\r
{\r
}\r
{\r
}\r
break;\r
- */\r
default:\r
break;\r
} // hctiws\r
+ */\r
}\r
\r
// -------------------------------------------------------------------------\r
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
#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
\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
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
Connection* m_ActualConnection;\r
\r
TWorkspace* m_Workspace;\r
- TGraph::Pointer m_Graph;\r
};\r
\r
} // ecapseman\r
}
else
{
- /* TODO
- if( this->m_Editor != NULL )
- this->m_Editor->setWorkspace( this->m_Workspace );
- */
+ if( this->m_Editor != NULL )
+ this->m_Editor->redrawWorkspace( );
} // fi
}
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 );
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( );
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::
}
// -------------------------------------------------------------------------
-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 );
}
// -------------------------------------------------------------------------
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 )
ProcessObject* f = this->GetFilter( name );
if( f == NULL )
{
- itkGenericExceptionMacro(
+ itkGenericExceptionMacro(
"cpPlugins::Workspace: Vertex \"" << name << "\" is not a filter."
);
{
namespace QT
{
-// TODO: #ifdef cpPlugins_QT4
class SimpleMPRWidget;
-// TODO: #else // cpPlugins_QT4
-// TODO: typedef char SimpleMPRWidget;
-// TODO: #endif // cpPlugins_QT4
}
}
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 );
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 );