]> Creatis software - cpPlugins.git/blob - appli/PipelineEditor/PipelineEditor.cxx
d14d0cfafa44f4d59b2f11be32662f21a5ea07cb
[cpPlugins.git] / appli / PipelineEditor / PipelineEditor.cxx
1 #include <PipelineEditor.h>
2 #include <ui_PipelineEditor.h>
3
4 /* TODO
5    #include <cpExtensions/QT/SimpleMPRWidget.h>
6    #include <cpExtensions/QT/ImageWidget.h>
7    #include <cpExtensions/QT/ConfigurationChooser.h>
8 */
9 #include <cpPlugins/Utility.h>
10 #include <cpExtensions/QT/ActorsWidgetInterface.h>
11 #include <vtkImageData.h>
12 #include <vtkPolyData.h>
13
14 // -------------------------------------------------------------------------
15 PipelineEditor::
16 PipelineEditor( int argc, char* argv[], QWidget* parent )
17   : Superclass( argc, argv, parent ),
18     m_UI( new Ui::PipelineEditor )
19 {
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( );
27
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 );
34
35   // Load command-line given workspace (if any)
36   this->m_ActiveWS = "empty";
37   if( argc > 1 )
38   {
39     this->_loadWorkspace( argv[ 1 ] );
40     this->m_ActiveWS = argv[ 1 ];
41   }
42   else
43     this->_addWorkspace( this->m_ActiveWS );
44
45   /* TODO
46      this->connect(
47      this->m_UI->actionOpenWorkspace, SIGNAL( triggered( ) ),
48      this, SLOT( _slotOpenWorkspace( ) )
49      );
50      this->connect(
51      this->m_UI->actionSaveWorkspace, SIGNAL( triggered( ) ),
52      this, SLOT( _slotSaveWorkspace( ) )
53      );
54      this->connect(
55      this->m_UI->actionSaveWorkspaceAs, SIGNAL( triggered( ) ),
56      this, SLOT( _slotSaveWorkspaceAs( ) )
57      );
58      this->connect(
59      this->m_UI->actionActorsProperties, SIGNAL( triggered( ) ),
60      this, SLOT( _slotActorsProperties( ) )
61      );
62      this->m_UI->Canvas->connectOutputPortSlot(
63      this, SLOT( _slotView( const std::string&, bool ) )
64      );
65   */
66
67
68   // Associate qt-based objects
69 }
70
71 // -------------------------------------------------------------------------
72 PipelineEditor::
73 ~PipelineEditor( )
74 {
75   delete this->m_UI;
76 }
77
78 // -------------------------------------------------------------------------
79 template< class _TWidget >
80 std::pair< _TWidget*, bool > PipelineEditor::
81 _configureViewer( )
82 {
83   /* TODO
84      auto new_viewer = dynamic_cast< _TWidget* >( this->m_UI->Viewer );
85      bool ok = false;
86      if( new_viewer == NULL )
87      {
88      new_viewer = new _TWidget( );
89      delete this->m_UI->Viewer;
90      this->m_UI->Viewer = new_viewer;
91      ok = true;
92
93      auto interactors = new_viewer->GetInteractors( );
94      for( auto w : this->m_Workspaces )
95      for( auto i : interactors )
96      w.second->AddInteractor( i );
97
98      } // fi
99      this->m_UI->MainSplitter->insertWidget( 0, this->m_UI->Viewer );
100      return( std::pair< _TWidget*, bool >( new_viewer, ok ) );
101   */
102   return( std::pair< _TWidget*, bool >( NULL, false ) );
103 }
104
105 // -------------------------------------------------------------------------
106 void PipelineEditor::
107 _slotView( const std::string& name, bool show )
108 {
109   typedef cpExtensions::QT::ActorsWidgetInterface _TViewer;
110
111   // Get filter parameters
112   std::vector< std::string > tokens;
113   cpPlugins::Tokenize( tokens, name, "@" );
114   if( tokens.size( ) != 2 )
115     return;
116   auto filter_name = tokens[ 1 ];
117   auto output_name = tokens[ 0 ];
118
119   // Process data
120   try
121   {
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;
128     if( image != NULL )
129     {
130       int dim = image->GetDataDimension( );
131       if( dim == 2 )
132         viewer =
133           this->_configureViewer< cpExtensions::QT::ImageWidget >(
134             this->m_UI->Viewer
135             );
136       else if( dim == 3 )
137         viewer =
138           this->_configureViewer< cpExtensions::QT::SimpleMPRWidget >(
139             this->m_UI->Viewer
140             );
141     }
142     else if( mesh != NULL )
143       viewer =
144         this->_configureViewer< cpExtensions::QT::SimpleMPRWidget >(
145           this->m_UI->Viewer
146           );
147     if( ( QWidget* )( viewer ) != ( QWidget* )( this->m_UI->Viewer ) )
148     {
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 );
153
154     } // fi
155   }
156   catch( std::exception& err )
157   {
158     QMessageBox::critical(
159       NULL,
160       QMessageBox::tr( "Error showing data" ),
161       QMessageBox::tr( err.what( ) )
162       );
163
164   } // yrt
165
166   /* TODO
167      try
168      {
169      if( filter != NULL )
170      {
171      if( image != NULL )
172      {
173      int dim = image->GetDataDimension( );
174      if( dim == 2 )
175      {
176      auto viewer =
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( );
183      }
184      else if( dim == 3 )
185      {
186      auto viewer =
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( );
193
194      } // fi
195      }
196      else if( mesh != NULL )
197      {
198      auto viewer =
199      dynamic_cast< cpExtensions::QT::SimpleMPRWidget* >(
200      this->m_UI->Viewer
201      );
202      if( viewer != NULL )
203      {
204      this->m_Blocker.block( );
205      viewer->Add( mesh, name );
206      viewer->Render( );
207      this->m_Blocker.unblock( );
208
209      } // fi
210
211      } // fi
212
213      } // fi
214      }
215      catch( std::exception& err )
216      {
217      } // yrt
218   */
219 }
220
221 // -------------------------------------------------------------------------
222 void PipelineEditor::
223 _slotActorsProperties( )
224 {
225   /* TODO
226      auto data =
227      dynamic_cast< cpExtensions::QT::ActorsWidgetInterface* >(
228      this->m_UI->Viewer
229      );
230      if( data != NULL )
231      {
232      auto dlg = new cpExtensions::QT::ConfigurationChooser( this );
233      dlg->setData( data );
234      dlg->exec( );
235
236      } // fi
237   */
238 }
239
240 // -------------------------------------------------------------------------
241 #include <cpBaseQtApplication/MainHelper.h>
242 cpBaseQtApplication_Main( PipelineEditor );
243 cpBaseQtApplication_MainComplement;
244
245 // eof - $RCSfile$