1 #include <PipelineEditor.h>
2 #include <ui_PipelineEditor.h>
5 #include <cpExtensions/QT/SimpleMPRWidget.h>
6 #include <cpExtensions/QT/ImageWidget.h>
7 #include <cpExtensions/QT/ConfigurationChooser.h>
9 #include <cpPlugins/Utility.h>
10 #include <cpExtensions/QT/ActorsWidgetInterface.h>
11 #include <vtkImageData.h>
12 #include <vtkPolyData.h>
14 // -------------------------------------------------------------------------
16 PipelineEditor( int argc, char* argv[], QWidget* parent )
17 : Superclass( argc, argv, parent ),
18 m_UI( new Ui::PipelineEditor )
20 // Basic configuration
21 this->m_SingleWorkspace = true;
22 this->m_BaseWindowTitle = "PipelineEditor - ";
23 this->m_UI->setupUi( this );
24 this->setCanvas( this->m_UI->Canvas );
25 this->setNavigator( this->m_UI->Navigator );
26 this->m_UI->Navigator->Update( );
28 // Connect slots <-> signals
29 cpBaseQtApplication_ConnectAction( actionLoadDirectory, _loadPluginsFromPath );
30 cpBaseQtApplication_ConnectAction( actionLoadLibrary, _loadPlugins );
31 cpBaseQtApplication_ConnectAction( actionOpenWorkspace, _loadWorkspace );
32 cpBaseQtApplication_ConnectAction( actionSaveWorkspace, _saveWorkspace );
33 cpBaseQtApplication_ConnectAction( actionSaveWorkspaceAs, _saveWorkspace );
35 // Load command-line given workspace (if any)
36 this->m_ActiveWS = "empty";
39 this->_loadWorkspace( argv[ 1 ] );
40 this->m_ActiveWS = argv[ 1 ];
43 this->_addWorkspace( this->m_ActiveWS );
47 this->m_UI->actionOpenWorkspace, SIGNAL( triggered( ) ),
48 this, SLOT( _slotOpenWorkspace( ) )
51 this->m_UI->actionSaveWorkspace, SIGNAL( triggered( ) ),
52 this, SLOT( _slotSaveWorkspace( ) )
55 this->m_UI->actionSaveWorkspaceAs, SIGNAL( triggered( ) ),
56 this, SLOT( _slotSaveWorkspaceAs( ) )
59 this->m_UI->actionActorsProperties, SIGNAL( triggered( ) ),
60 this, SLOT( _slotActorsProperties( ) )
62 this->m_UI->Canvas->connectOutputPortSlot(
63 this, SLOT( _slotView( const std::string&, bool ) )
68 // Associate qt-based objects
71 // -------------------------------------------------------------------------
78 // -------------------------------------------------------------------------
79 template< class _TWidget >
80 std::pair< _TWidget*, bool > PipelineEditor::
84 auto new_viewer = dynamic_cast< _TWidget* >( this->m_UI->Viewer );
86 if( new_viewer == NULL )
88 new_viewer = new _TWidget( );
89 delete this->m_UI->Viewer;
90 this->m_UI->Viewer = new_viewer;
93 auto interactors = new_viewer->GetInteractors( );
94 for( auto w : this->m_Workspaces )
95 for( auto i : interactors )
96 w.second->AddInteractor( i );
99 this->m_UI->MainSplitter->insertWidget( 0, this->m_UI->Viewer );
100 return( std::pair< _TWidget*, bool >( new_viewer, ok ) );
102 return( std::pair< _TWidget*, bool >( NULL, false ) );
105 // -------------------------------------------------------------------------
106 void PipelineEditor::
107 _slotView( const std::string& name, bool show )
109 typedef cpExtensions::QT::ActorsWidgetInterface _TViewer;
111 // Get filter parameters
112 std::vector< std::string > tokens;
113 cpPlugins::Tokenize( tokens, name, "@" );
114 if( tokens.size( ) != 2 )
116 auto filter_name = tokens[ 1 ];
117 auto output_name = tokens[ 0 ];
122 auto ws = this->workspace( this->m_ActiveWS );
123 auto filter = ws->GetFilter( filter_name );
124 cpBaseQtApplication_Execute( filter->Update( ) );
125 auto image = filter->GetOutputData< vtkImageData >( output_name );
126 auto mesh = filter->GetOutputData< vtkPolyData >( output_name );
127 _TViewer* viewer = NULL;
130 int dim = image->GetDataDimension( );
133 this->_configureViewer< cpExtensions::QT::ImageWidget >(
138 this->_configureViewer< cpExtensions::QT::SimpleMPRWidget >(
142 else if( mesh != NULL )
144 this->_configureViewer< cpExtensions::QT::SimpleMPRWidget >(
147 if( ( QWidget* )( viewer ) != ( QWidget* )( this->m_UI->Viewer ) )
149 delete this->m_UI->Viewer;
150 this->m_UI->Viewer = viewer;
151 this->m_UI->MainSplitter->insertWidget( 0, this->m_UI->Viewer );
152 this->setViewer( viewer );
156 catch( std::exception& err )
158 QMessageBox::critical(
160 QMessageBox::tr( "Error showing data" ),
161 QMessageBox::tr( err.what( ) )
173 int dim = image->GetDataDimension( );
177 this->_configureViewer< cpExtensions::QT::ImageWidget >( );
178 this->m_Blocker.block( );
179 viewer.first->SetImage( image, 2, name );
180 viewer.first->ResetCamera( );
181 viewer.first->Render( );
182 this->m_Blocker.unblock( );
187 this->_configureViewer< cpExtensions::QT::SimpleMPRWidget >( );
188 this->m_Blocker.block( );
189 viewer.first->SetImage( image, name );
190 viewer.first->ResetCameras( );
191 viewer.first->Render( );
192 this->m_Blocker.unblock( );
196 else if( mesh != NULL )
199 dynamic_cast< cpExtensions::QT::SimpleMPRWidget* >(
204 this->m_Blocker.block( );
205 viewer->Add( mesh, name );
207 this->m_Blocker.unblock( );
215 catch( std::exception& err )
221 // -------------------------------------------------------------------------
222 void PipelineEditor::
223 _slotActorsProperties( )
227 dynamic_cast< cpExtensions::QT::ActorsWidgetInterface* >(
232 auto dlg = new cpExtensions::QT::ConfigurationChooser( this );
233 dlg->setData( data );
240 // -------------------------------------------------------------------------
241 #include <cpBaseQtApplication/MainHelper.h>
242 cpBaseQtApplication_Main( PipelineEditor );
243 cpBaseQtApplication_MainComplement;