1 #include <PipelineEditor.h>
2 #include <ui_PipelineEditor.h>
4 #include <cpPlugins/OS/String.h>
5 #include <cpExtensions/QT/SimpleMPRWidget.h>
6 #include <cpExtensions/QT/ImageWidget.h>
7 #include <cpExtensions/QT/ActorsWidgetInterface.h>
8 #include <vtkImageData.h>
9 #include <vtkPolyData.h>
11 // -------------------------------------------------------------------------
13 PipelineEditor( int argc, char* argv[], QWidget* parent )
14 : Superclass( argc, argv, parent ),
15 m_UI( new Ui::PipelineEditor )
17 // Basic configuration
18 this->m_BaseWindowTitle = "PipelineEditor - ";
19 this->m_UI->setupUi( this );
20 this->setCanvas( this->m_UI->Canvas );
21 this->setNavigator( this->m_UI->Navigator );
22 this->m_UI->Navigator->Update( );
24 // Connect slots <-> signals
25 cpBaseQtApplication_ConnectAction( actionLoadDirectory, _loadPluginsFromPath );
26 cpBaseQtApplication_ConnectAction( actionLoadLibrary, _loadPlugins );
27 cpBaseQtApplication_ConnectAction( actionOpenWorkspace, _loadWorkspace );
28 cpBaseQtApplication_ConnectAction( actionSaveWorkspace, _saveWorkspace );
29 cpBaseQtApplication_ConnectAction( actionSaveWorkspaceAs, _saveWorkspace );
30 cpBaseQtApplication_ConnectAction( actionActorsProperties, _actorsProperties );
31 this->m_UI->Canvas->connectOutputPortSlot(
32 this, SLOT( _slotView( const std::string&, bool ) )
35 this->m_UI->actionPrintExecutionInformation, SIGNAL( triggered( bool ) ),
36 this, SLOT( _slotPrintExecutionInformation( bool ) )
39 // Load command-line given workspace (if any)
41 this->_loadWorkspace( argv[ 1 ] );
44 // -------------------------------------------------------------------------
51 // -------------------------------------------------------------------------
53 _slotView( const std::string& name, bool show )
55 typedef cpExtensions::QT::ActorsWidgetInterface _TViewer;
57 // Get filter parameters
58 std::vector< std::string > tokens =
59 cpPlugins::OS::String::Tokenize( name, "@" );
60 if( tokens.size( ) != 2 )
62 auto filter_name = tokens[ 1 ];
63 auto output_name = tokens[ 0 ];
70 auto ws = this->workspace( );
71 auto filter = ws->GetFilter( filter_name );
72 cpBaseQtApplication_Execute( filter->Update( ) );
73 auto image = filter->GetOutputData< vtkImageData >( output_name );
74 auto mesh = filter->GetOutputData< vtkPolyData >( output_name );
75 _TViewer* viewer = NULL;
78 int dim = image->GetDataDimension( );
81 this->_configureViewer< cpExtensions::QT::ImageWidget >(
86 this->_configureViewer< cpExtensions::QT::SimpleMPRWidget >(
90 else if( mesh != NULL )
93 this->_configureViewer< cpExtensions::QT::SimpleMPRWidget >(
99 dynamic_cast< QWidget* >( viewer ) !=
100 dynamic_cast< QWidget* >( this->m_UI->Viewer ) &&
104 delete this->m_UI->Viewer;
105 this->m_UI->Viewer = dynamic_cast< QWidget* >( viewer );
106 this->m_UI->MainSplitter->insertWidget( 0, this->m_UI->Viewer );
107 this->setViewer( viewer );
112 this->m_Blocker.block( );
113 auto mpr = dynamic_cast< cpExtensions::QT::SimpleMPRWidget* >( viewer );
114 auto imv = dynamic_cast< cpExtensions::QT::ImageWidget* >( viewer );
116 mpr->SetImage( image, name );
117 else if( imv != NULL )
118 imv->SetImage( image, name );
119 this->m_Blocker.unblock( );
121 else if( mesh != NULL )
123 this->m_Blocker.block( );
124 auto mpr = dynamic_cast< cpExtensions::QT::SimpleMPRWidget* >( viewer );
126 mpr->Add( mesh, name );
127 this->m_Blocker.unblock( );
131 catch( std::exception& err )
133 QMessageBox::critical(
135 QMessageBox::tr( "Error showing data" ),
136 QMessageBox::tr( err.what( ) )
144 // -------------------------------------------------------------------------
145 void PipelineEditor::
146 _slotPrintExecutionInformation( bool show )
148 if( this->m_Workspace.IsNotNull( ) )
149 this->m_Workspace->SetPrintExecution( show );
152 // -------------------------------------------------------------------------
153 #include <cpBaseQtApplication/MainHelper.h>
154 cpBaseQtApplication_Main( PipelineEditor );
155 cpBaseQtApplication_MainComplement;