1 #include <PipelineEditor.h>
2 #include <ui_PipelineEditor.h>
5 #include <cpPlugins/Utility.h>
6 #include <cpExtensions/QT/SimpleMPRWidget.h>
7 #include <cpExtensions/QT/ImageWidget.h>
8 #include <cpExtensions/QT/ConfigurationChooser.h>
9 #include <cpExtensions/QT/ActorsWidgetInterface.h>
10 #include <vtkImageData.h>
11 #include <vtkPolyData.h>
14 // -------------------------------------------------------------------------
16 PipelineEditor( int argc, char* argv[], QWidget* parent )
17 : Superclass( argc, argv, parent ),
18 m_UI( new Ui::PipelineEditor ),
21 // Basic configuration
22 this->m_UI->setupUi( this );
23 this->setCanvas( this->m_UI->Canvas );
24 this->setNavigator( this->m_UI->Navigator );
25 this->m_UI->Navigator->Update( );
27 // Connect slots <-> signals
28 cpBaseQtApplication_ConnectAction( actionLoadDirectory, _loadPluginsFromPath );
29 cpBaseQtApplication_ConnectAction( actionLoadLibrary, _loadPlugins );
31 // Load command-line given workspace (if any)
34 this->_loadWorkspace( argv[ 1 ] );
35 this->m_ActiveWS = argv[ 1 ];
38 this->_addWorkspace( this->m_ActiveWS );
40 this->m_UI->Canvas->setWorkspace( this->workspace( this->m_ActiveWS ) );
43 std::string( "PipelineEditor - " ) +
51 this->m_UI->actionOpenWorkspace, SIGNAL( triggered( ) ),
52 this, SLOT( _slotOpenWorkspace( ) )
55 this->m_UI->actionSaveWorkspace, SIGNAL( triggered( ) ),
56 this, SLOT( _slotSaveWorkspace( ) )
59 this->m_UI->actionSaveWorkspaceAs, SIGNAL( triggered( ) ),
60 this, SLOT( _slotSaveWorkspaceAs( ) )
63 this->m_UI->actionActorsProperties, SIGNAL( triggered( ) ),
64 this, SLOT( _slotActorsProperties( ) )
66 this->m_UI->Canvas->connectOutputPortSlot(
67 this, SLOT( _slotView( const std::string&, bool ) )
72 // Associate qt-based objects
75 // -------------------------------------------------------------------------
82 // -------------------------------------------------------------------------
83 template< class _TWidget >
84 std::pair< _TWidget*, bool > PipelineEditor::
88 auto new_viewer = dynamic_cast< _TWidget* >( this->m_UI->Viewer );
90 if( new_viewer == NULL )
92 new_viewer = new _TWidget( );
93 delete this->m_UI->Viewer;
94 this->m_UI->Viewer = new_viewer;
97 auto interactors = new_viewer->GetInteractors( );
98 for( auto w : this->m_Workspaces )
99 for( auto i : interactors )
100 w.second->AddInteractor( i );
103 this->m_UI->MainSplitter->insertWidget( 0, this->m_UI->Viewer );
104 return( std::pair< _TWidget*, bool >( new_viewer, ok ) );
106 return( std::pair< _TWidget*, bool >( NULL, false ) );
109 // -------------------------------------------------------------------------
110 void PipelineEditor::
111 _addWorkspace( const std::string& name )
114 typedef cpExtensions::QT::ActorsWidgetInterface _TInterface;
116 this->Superclass::_addWorkspace( name );
117 auto ws = this->m_Workspaces.find( name );
118 if( ws != this->m_Workspaces.end( ) )
120 ws->second->PrintExecutionOn( );
121 auto wdg = dynamic_cast< _TInterface* >( this->m_UI->Viewer );
124 auto interactors = wdg->GetInteractors( );
125 for( auto i : interactors )
126 ws->second->AddInteractor( i );
132 // -------------------------------------------------------------------------
133 void PipelineEditor::
134 _slotOpenWorkspace( )
137 this->m_LastSaveFileName = "";
138 this->_loadWorkspace( );
139 if( this->m_Workspaces.size( ) == 2 )
141 auto wIt = this->m_Workspaces.find( this->m_ActiveWS );
142 this->m_Workspaces.erase( wIt );
143 this->m_ActiveWS = this->m_Workspaces.begin( )->first;
145 else if( this->m_Workspaces.size( ) == 1 )
147 this->m_ActiveWS = this->m_Workspaces.begin( )->first;
151 this->m_ActiveWS = "ws";
152 this->_addWorkspace( this->m_ActiveWS );
155 this->m_UI->Canvas->setWorkspace( this->workspace( this->m_ActiveWS ) );
156 this->setWindowTitle(
158 std::string( "PipelineEditor - " ) +
165 // -------------------------------------------------------------------------
166 void PipelineEditor::
167 _slotSaveWorkspace( )
170 this->_saveWorkspace( this->m_ActiveWS, false );
171 this->setWindowTitle(
173 std::string( "PipelineEditor - " ) +
174 this->m_LastSaveFileName
180 // -------------------------------------------------------------------------
181 void PipelineEditor::
182 _slotSaveWorkspaceAs( )
185 this->_saveWorkspace( this->m_ActiveWS, true );
186 this->setWindowTitle(
188 std::string( "PipelineEditor - " ) +
189 this->m_LastSaveFileName
195 // -------------------------------------------------------------------------
196 void PipelineEditor::
197 _slotView( const std::string& name, bool show )
200 std::vector< std::string > tokens;
201 cpPlugins::Tokenize( tokens, name, "@" );
202 if( tokens.size( ) != 2 )
206 auto ws = this->workspace( this->m_ActiveWS );
207 auto filter = ws->GetFilter( tokens[ 1 ] );
210 cpBaseQtApplication_Execute( filter->Update( ) );
211 auto image = filter->GetOutputData< vtkImageData >( tokens[ 0 ] );
212 auto mesh = filter->GetOutputData< vtkPolyData >( tokens[ 0 ] );
215 int dim = image->GetDataDimension( );
219 this->_configureViewer< cpExtensions::QT::ImageWidget >( );
220 this->m_Blocker.block( );
221 viewer.first->SetImage( image, 2, name );
222 viewer.first->ResetCamera( );
223 viewer.first->Render( );
224 this->m_Blocker.unblock( );
229 this->_configureViewer< cpExtensions::QT::SimpleMPRWidget >( );
230 this->m_Blocker.block( );
231 viewer.first->SetImage( image, name );
232 viewer.first->ResetCameras( );
233 viewer.first->Render( );
234 this->m_Blocker.unblock( );
238 else if( mesh != NULL )
241 dynamic_cast< cpExtensions::QT::SimpleMPRWidget* >(
246 this->m_Blocker.block( );
247 viewer->Add( mesh, name );
249 this->m_Blocker.unblock( );
257 catch( std::exception& err )
259 QMessageBox::critical(
261 QMessageBox::tr( "Error showing data" ),
262 QMessageBox::tr( err.what( ) )
269 // -------------------------------------------------------------------------
270 void PipelineEditor::
271 _slotActorsProperties( )
275 dynamic_cast< cpExtensions::QT::ActorsWidgetInterface* >(
280 auto dlg = new cpExtensions::QT::ConfigurationChooser( this );
281 dlg->setData( data );
288 // -------------------------------------------------------------------------
289 #include <cpBaseQtApplication/MainHelper.h>
290 cpBaseQtApplication_Main( PipelineEditor );
291 cpBaseQtApplication_MainComplement;