]> Creatis software - cpPlugins.git/blob - appli/PipelineEditor/PipelineEditor.cxx
...
[cpPlugins.git] / appli / PipelineEditor / PipelineEditor.cxx
1 #include <PipelineEditor.h>
2 #include <ui_PipelineEditor.h>
3
4 /* TODO
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>
12 */
13
14 // -------------------------------------------------------------------------
15 PipelineEditor::
16 PipelineEditor( int argc, char* argv[], QWidget* parent )
17   : Superclass( argc, argv, parent ),
18     m_UI( new Ui::PipelineEditor ),
19     m_ActiveWS( "ws" )
20 {
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( );
26
27   // Connect slots <-> signals
28   cpBaseQtApplication_ConnectAction( actionLoadDirectory, _loadPluginsFromPath );
29   cpBaseQtApplication_ConnectAction( actionLoadLibrary, _loadPlugins );
30
31   // Load command-line given workspace (if any)
32   if( argc > 1 )
33   {
34     this->_loadWorkspace( argv[ 1 ] );
35     this->m_ActiveWS = argv[ 1 ];
36   }
37   else
38     this->_addWorkspace( this->m_ActiveWS );
39   /* TODO
40      this->m_UI->Canvas->setWorkspace( this->workspace( this->m_ActiveWS ) );
41      this->setWindowTitle(
42      (
43      std::string( "PipelineEditor - " ) +
44      this->m_ActiveWS
45      ).c_str( )
46      );
47   */
48
49   /* TODO
50      this->connect(
51      this->m_UI->actionOpenWorkspace, SIGNAL( triggered( ) ),
52      this, SLOT( _slotOpenWorkspace( ) )
53      );
54      this->connect(
55      this->m_UI->actionSaveWorkspace, SIGNAL( triggered( ) ),
56      this, SLOT( _slotSaveWorkspace( ) )
57      );
58      this->connect(
59      this->m_UI->actionSaveWorkspaceAs, SIGNAL( triggered( ) ),
60      this, SLOT( _slotSaveWorkspaceAs( ) )
61      );
62      this->connect(
63      this->m_UI->actionActorsProperties, SIGNAL( triggered( ) ),
64      this, SLOT( _slotActorsProperties( ) )
65      );
66      this->m_UI->Canvas->connectOutputPortSlot(
67      this, SLOT( _slotView( const std::string&, bool ) )
68      );
69   */
70
71
72   // Associate qt-based objects
73 }
74
75 // -------------------------------------------------------------------------
76 PipelineEditor::
77 ~PipelineEditor( )
78 {
79   delete this->m_UI;
80 }
81
82 // -------------------------------------------------------------------------
83 template< class _TWidget >
84 std::pair< _TWidget*, bool > PipelineEditor::
85 _configureViewer( )
86 {
87   /* TODO
88      auto new_viewer = dynamic_cast< _TWidget* >( this->m_UI->Viewer );
89      bool ok = false;
90      if( new_viewer == NULL )
91      {
92      new_viewer = new _TWidget( );
93      delete this->m_UI->Viewer;
94      this->m_UI->Viewer = new_viewer;
95      ok = true;
96
97      auto interactors = new_viewer->GetInteractors( );
98      for( auto w : this->m_Workspaces )
99      for( auto i : interactors )
100      w.second->AddInteractor( i );
101
102      } // fi
103      this->m_UI->MainSplitter->insertWidget( 0, this->m_UI->Viewer );
104      return( std::pair< _TWidget*, bool >( new_viewer, ok ) );
105   */
106   return( std::pair< _TWidget*, bool >( NULL, false ) );
107 }
108
109 // -------------------------------------------------------------------------
110 void PipelineEditor::
111 _addWorkspace( const std::string& name )
112 {
113   /* TODO
114      typedef cpExtensions::QT::ActorsWidgetInterface _TInterface;
115
116      this->Superclass::_addWorkspace( name );
117      auto ws = this->m_Workspaces.find( name );
118      if( ws != this->m_Workspaces.end( ) )
119      {
120      ws->second->PrintExecutionOn( );
121      auto wdg = dynamic_cast< _TInterface* >( this->m_UI->Viewer );
122      if( wdg == NULL )
123      return;
124      auto interactors = wdg->GetInteractors( );
125      for( auto i : interactors )
126      ws->second->AddInteractor( i );
127
128      } // fi
129   */
130 }
131
132 // -------------------------------------------------------------------------
133 void PipelineEditor::
134 _slotOpenWorkspace( )
135 {
136   /* TODO
137      this->m_LastSaveFileName = "";
138      this->_loadWorkspace( );
139      if( this->m_Workspaces.size( ) == 2 )
140      {
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;
144      }
145      else if( this->m_Workspaces.size( ) == 1 )
146      {
147      this->m_ActiveWS = this->m_Workspaces.begin( )->first;
148      }
149      else
150      {
151      this->m_ActiveWS = "ws";
152      this->_addWorkspace( this->m_ActiveWS );
153
154      } // fi
155      this->m_UI->Canvas->setWorkspace( this->workspace( this->m_ActiveWS ) );
156      this->setWindowTitle(
157      (
158      std::string( "PipelineEditor - " ) +
159      this->m_ActiveWS
160      ).c_str( )
161      );
162   */
163 }
164
165 // -------------------------------------------------------------------------
166 void PipelineEditor::
167 _slotSaveWorkspace( )
168 {
169   /* TODO
170      this->_saveWorkspace( this->m_ActiveWS, false );
171      this->setWindowTitle(
172      (
173      std::string( "PipelineEditor - " ) +
174      this->m_LastSaveFileName
175      ).c_str( )
176      );
177   */
178 }
179
180 // -------------------------------------------------------------------------
181 void PipelineEditor::
182 _slotSaveWorkspaceAs( )
183 {
184   /* TODO
185      this->_saveWorkspace( this->m_ActiveWS, true );
186      this->setWindowTitle(
187      (
188      std::string( "PipelineEditor - " ) +
189      this->m_LastSaveFileName
190      ).c_str( )
191      );
192   */
193 }
194
195 // -------------------------------------------------------------------------
196 void PipelineEditor::
197 _slotView( const std::string& name, bool show )
198 {
199   /* TODO
200      std::vector< std::string > tokens;
201      cpPlugins::Tokenize( tokens, name, "@" );
202      if( tokens.size( ) != 2 )
203      return;
204      try
205      {
206      auto ws = this->workspace( this->m_ActiveWS );
207      auto filter = ws->GetFilter( tokens[ 1 ] );
208      if( filter != NULL )
209      {
210      cpBaseQtApplication_Execute( filter->Update( ) );
211      auto image = filter->GetOutputData< vtkImageData >( tokens[ 0 ] );
212      auto mesh = filter->GetOutputData< vtkPolyData >( tokens[ 0 ] );
213      if( image != NULL )
214      {
215      int dim = image->GetDataDimension( );
216      if( dim == 2 )
217      {
218      auto viewer =
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( );
225      }
226      else if( dim == 3 )
227      {
228      auto viewer =
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( );
235
236      } // fi
237      }
238      else if( mesh != NULL )
239      {
240      auto viewer =
241      dynamic_cast< cpExtensions::QT::SimpleMPRWidget* >(
242      this->m_UI->Viewer
243      );
244      if( viewer != NULL )
245      {
246      this->m_Blocker.block( );
247      viewer->Add( mesh, name );
248      viewer->Render( );
249      this->m_Blocker.unblock( );
250
251      } // fi
252
253      } // fi
254
255      } // fi
256      }
257      catch( std::exception& err )
258      {
259      QMessageBox::critical(
260      NULL,
261      QMessageBox::tr( "Error showing data" ),
262      QMessageBox::tr( err.what( ) )
263      );
264
265      } // yrt
266   */
267 }
268
269 // -------------------------------------------------------------------------
270 void PipelineEditor::
271 _slotActorsProperties( )
272 {
273   /* TODO
274      auto data =
275      dynamic_cast< cpExtensions::QT::ActorsWidgetInterface* >(
276      this->m_UI->Viewer
277      );
278      if( data != NULL )
279      {
280      auto dlg = new cpExtensions::QT::ConfigurationChooser( this );
281      dlg->setData( data );
282      dlg->exec( );
283
284      } // fi
285   */
286 }
287
288 // -------------------------------------------------------------------------
289 #include <cpBaseQtApplication/MainHelper.h>
290 cpBaseQtApplication_Main( PipelineEditor );
291 cpBaseQtApplication_MainComplement;
292
293 // eof - $RCSfile$