1 #include <PipelineEditor.h>
2 #include <ui_PipelineEditor.h>
4 #include <cpPlugins/Utility.h>
5 #include <cpExtensions/QT/SimpleMPRWidget.h>
6 #include <cpExtensions/QT/ImageWidget.h>
7 #include <cpExtensions/QT/ConfigurationChooser.h>
8 #include <cpExtensions/QT/ActorsWidgetInterface.h>
9 #include <vtkImageData.h>
10 #include <vtkPolyData.h>
12 // -------------------------------------------------------------------------
14 PipelineEditor( int argc, char* argv[], QWidget* parent )
15 : Superclass( argc, argv, parent ),
16 m_UI( new Ui::PipelineEditor ),
19 this->m_UI->setupUi( this );
20 this->m_UI->Navigator->Update( );
22 cpBaseQtApplication_ConnectAction(
23 actionLoadDirectory, _loadPluginsFromPath
25 cpBaseQtApplication_ConnectAction(
26 actionLoadLibrary, _loadPlugins
30 this->m_UI->actionOpenWorkspace, SIGNAL( triggered( ) ),
31 this, SLOT( _slotOpenWorkspace( ) )
34 this->m_UI->actionSaveWorkspace, SIGNAL( triggered( ) ),
35 this, SLOT( _slotSaveWorkspace( ) )
38 this->m_UI->actionSaveWorkspaceAs, SIGNAL( triggered( ) ),
39 this, SLOT( _slotSaveWorkspaceAs( ) )
42 this->m_UI->actionActorsProperties, SIGNAL( triggered( ) ),
43 this, SLOT( _slotActorsProperties( ) )
45 this->m_UI->Canvas->connectOutputPortSlot(
46 this, SLOT( _slotView( const std::string&, bool ) )
49 // Load command-line given workspace
52 this->_loadWorkspace( argv[ 1 ] );
53 this->m_ActiveWS = argv[ 1 ];
56 this->_addWorkspace( this->m_ActiveWS );
57 this->m_UI->Canvas->setWorkspace( this->workspace( this->m_ActiveWS ) );
60 std::string( "PipelineEditor - " ) +
65 this->setCanvas( this->m_UI->Canvas );
66 this->setNavigator( this->m_UI->Navigator );
69 // -------------------------------------------------------------------------
76 // -------------------------------------------------------------------------
77 template< class _TWidget >
78 std::pair< _TWidget*, bool > PipelineEditor::
81 auto new_viewer = dynamic_cast< _TWidget* >( this->m_UI->Viewer );
83 if( new_viewer == NULL )
85 new_viewer = new _TWidget( );
86 delete this->m_UI->Viewer;
87 this->m_UI->Viewer = new_viewer;
90 auto interactors = new_viewer->GetInteractors( );
91 for( auto w : this->m_Workspaces )
92 for( auto i : interactors )
93 w.second->AddInteractor( i );
96 this->m_UI->MainSplitter->insertWidget( 0, this->m_UI->Viewer );
97 return( std::pair< _TWidget*, bool >( new_viewer, ok ) );
100 // -------------------------------------------------------------------------
101 void PipelineEditor::
102 _addWorkspace( const std::string& name )
104 typedef cpExtensions::QT::ActorsWidgetInterface _TInterface;
106 this->Superclass::_addWorkspace( name );
107 auto ws = this->m_Workspaces.find( name );
108 if( ws != this->m_Workspaces.end( ) )
110 ws->second->PrintExecutionOn( );
111 auto wdg = dynamic_cast< _TInterface* >( this->m_UI->Viewer );
114 auto interactors = wdg->GetInteractors( );
115 for( auto i : interactors )
116 ws->second->AddInteractor( i );
121 // -------------------------------------------------------------------------
122 void PipelineEditor::
123 _slotOpenWorkspace( )
125 this->m_LastSaveFileName = "";
126 this->_loadWorkspace( );
127 if( this->m_Workspaces.size( ) == 2 )
129 auto wIt = this->m_Workspaces.find( this->m_ActiveWS );
130 this->m_Workspaces.erase( wIt );
131 this->m_ActiveWS = this->m_Workspaces.begin( )->first;
133 else if( this->m_Workspaces.size( ) == 1 )
135 this->m_ActiveWS = this->m_Workspaces.begin( )->first;
139 this->m_ActiveWS = "ws";
140 this->_addWorkspace( this->m_ActiveWS );
143 this->m_UI->Canvas->setWorkspace( this->workspace( this->m_ActiveWS ) );
144 this->setWindowTitle(
146 std::string( "PipelineEditor - " ) +
152 // -------------------------------------------------------------------------
153 void PipelineEditor::
154 _slotSaveWorkspace( )
156 this->_saveWorkspace( this->m_ActiveWS, false );
157 this->setWindowTitle(
159 std::string( "PipelineEditor - " ) +
160 this->m_LastSaveFileName
165 // -------------------------------------------------------------------------
166 void PipelineEditor::
167 _slotSaveWorkspaceAs( )
169 this->_saveWorkspace( this->m_ActiveWS, true );
170 this->setWindowTitle(
172 std::string( "PipelineEditor - " ) +
173 this->m_LastSaveFileName
178 // -------------------------------------------------------------------------
179 void PipelineEditor::
180 _slotView( const std::string& name, bool show )
182 std::vector< std::string > tokens;
183 cpPlugins::Tokenize( tokens, name, "@" );
184 if( tokens.size( ) != 2 )
188 auto ws = this->workspace( this->m_ActiveWS );
189 auto filter = ws->GetFilter( tokens[ 1 ] );
192 cpBaseQtApplication_Execute( filter->Update( ) );
193 auto image = filter->GetOutputData< vtkImageData >( tokens[ 0 ] );
194 auto mesh = filter->GetOutputData< vtkPolyData >( tokens[ 0 ] );
197 int dim = image->GetDataDimension( );
201 this->_configureViewer< cpExtensions::QT::ImageWidget >( );
202 this->m_Blocker.block( );
203 viewer.first->SetImage( image, 2, name );
204 viewer.first->ResetCamera( );
205 viewer.first->Render( );
206 this->m_Blocker.unblock( );
211 this->_configureViewer< cpExtensions::QT::SimpleMPRWidget >( );
212 this->m_Blocker.block( );
213 viewer.first->SetImage( image, name );
214 viewer.first->ResetCameras( );
215 viewer.first->Render( );
216 this->m_Blocker.unblock( );
220 else if( mesh != NULL )
223 dynamic_cast< cpExtensions::QT::SimpleMPRWidget* >(
228 this->m_Blocker.block( );
229 viewer->Add( mesh, name );
231 this->m_Blocker.unblock( );
239 catch( std::exception& err )
241 QMessageBox::critical(
243 QMessageBox::tr( "Error showing data" ),
244 QMessageBox::tr( err.what( ) )
250 // -------------------------------------------------------------------------
251 void PipelineEditor::
252 _slotActorsProperties( )
255 dynamic_cast< cpExtensions::QT::ActorsWidgetInterface* >(
260 auto dlg = new cpExtensions::QT::ConfigurationChooser( this );
261 dlg->setData( data );
267 // -------------------------------------------------------------------------
268 #include <cpBaseQtApplication/MainHelper.h>
269 cpBaseQtApplication_Main( PipelineEditor );
270 cpBaseQtApplication_MainComplement;