]> Creatis software - cpPlugins.git/blob - appli/PipelineEditor/PipelineEditor.cxx
f49c2a43ad05d1f542d7da7e357c017944687740
[cpPlugins.git] / appli / PipelineEditor / PipelineEditor.cxx
1 #include <PipelineEditor.h>
2 #include <ui_PipelineEditor.h>
3
4 #include <cpPlugins/Utility.h>
5 #include <cpExtensions/QT/SimpleMPRWidget.h>
6 #include <cpExtensions/QT/ImageWidget.h>
7 #include <cpExtensions/QT/ActorsWidgetInterface.h>
8 #include <vtkImageData.h>
9 #include <vtkPolyData.h>
10
11 // -------------------------------------------------------------------------
12 PipelineEditor::
13 PipelineEditor( int argc, char* argv[], QWidget* parent )
14   : Superclass( argc, argv, parent ),
15     m_UI( new Ui::PipelineEditor )
16 {
17   // Basic configuration
18   this->m_BaseWindowTitle = "PipelineEditor - ";
19   this->m_UI->setupUi( this );
20   this->setCanvas( this->m_UI->Canvas );
21   this->setNavigator( this->m_UI->Navigator );
22   this->m_UI->Navigator->Update( );
23
24   // Connect slots <-> signals
25   cpBaseQtApplication_ConnectAction( actionLoadDirectory, _loadPluginsFromPath );
26   cpBaseQtApplication_ConnectAction( actionLoadLibrary, _loadPlugins );
27   cpBaseQtApplication_ConnectAction( actionOpenWorkspace, _loadWorkspace );
28   cpBaseQtApplication_ConnectAction( actionSaveWorkspace, _saveWorkspace );
29   cpBaseQtApplication_ConnectAction( actionSaveWorkspaceAs, _saveWorkspace );
30   cpBaseQtApplication_ConnectAction( actionActorsProperties, _actorsProperties );
31   this->m_UI->Canvas->connectOutputPortSlot(
32     this, SLOT( _slotView( const std::string&, bool ) )
33     );
34
35   // Load command-line given workspace (if any)
36   if( argc > 1 )
37     this->_loadWorkspace( argv[ 1 ] );
38 }
39
40 // -------------------------------------------------------------------------
41 PipelineEditor::
42 ~PipelineEditor( )
43 {
44   delete this->m_UI;
45 }
46
47 // -------------------------------------------------------------------------
48 void PipelineEditor::
49 _slotView( const std::string& name, bool show )
50 {
51   /* TODO
52      typedef cpExtensions::QT::ActorsWidgetInterface _TViewer;
53
54      // Get filter parameters
55      std::vector< std::string > tokens;
56      cpPlugins::Tokenize( tokens, name, "@" );
57      if( tokens.size( ) != 2 )
58      return;
59      auto filter_name = tokens[ 1 ];
60      auto output_name = tokens[ 0 ];
61
62      // Process data
63      if( show )
64      {
65      try
66      {
67      auto ws = this->workspace( this->m_ActiveWS );
68      auto filter = ws->GetFilter( filter_name );
69      cpBaseQtApplication_Execute( filter->Update( ) );
70      auto image = filter->GetOutputData< vtkImageData >( output_name );
71      auto mesh = filter->GetOutputData< vtkPolyData >( output_name );
72      _TViewer* viewer = NULL;
73      if( image != NULL )
74      {
75      int dim = image->GetDataDimension( );
76      if( dim == 2 )
77      viewer =
78      this->_configureViewer< cpExtensions::QT::ImageWidget >(
79      this->m_UI->Viewer
80      );
81      else if( dim == 3 )
82      viewer =
83      this->_configureViewer< cpExtensions::QT::SimpleMPRWidget >(
84      this->m_UI->Viewer
85      );
86      }
87      else if( mesh != NULL )
88      {
89      viewer =
90      this->_configureViewer< cpExtensions::QT::SimpleMPRWidget >(
91      this->m_UI->Viewer
92      );
93
94      } // fi
95      if(
96      dynamic_cast< QWidget* >( viewer ) !=
97      dynamic_cast< QWidget* >( this->m_UI->Viewer )
98      )
99      {
100      delete this->m_UI->Viewer;
101      this->m_UI->Viewer = dynamic_cast< QWidget* >( viewer );
102      this->m_UI->MainSplitter->insertWidget( 0, this->m_UI->Viewer );
103      this->setViewer( viewer );
104
105      } // fi
106      if( image != NULL )
107      {
108      this->m_Blocker.block( );
109      auto mpr = dynamic_cast< cpExtensions::QT::SimpleMPRWidget* >( viewer );
110      auto imv = dynamic_cast< cpExtensions::QT::ImageWidget* >( viewer );
111      if( mpr != NULL )
112      mpr->SetImage( image, name );
113      else if( imv != NULL )
114      imv->SetImage( image, name );
115      this->m_Blocker.unblock( );
116      }
117      else if( mesh != NULL )
118      {
119      this->m_Blocker.block( );
120      auto mpr = dynamic_cast< cpExtensions::QT::SimpleMPRWidget* >( viewer );
121      if( mpr != NULL )
122      mpr->Add( mesh, name );
123      this->m_Blocker.unblock( );
124
125      } // fi
126      }
127      catch( std::exception& err )
128      {
129      QMessageBox::critical(
130      NULL,
131      QMessageBox::tr( "Error showing data" ),
132      QMessageBox::tr( err.what( ) )
133      );
134
135      } // yrt
136
137      } // fi
138   */
139 }
140
141 // -------------------------------------------------------------------------
142 #include <cpBaseQtApplication/MainHelper.h>
143 cpBaseQtApplication_Main( PipelineEditor );
144 cpBaseQtApplication_MainComplement;
145
146 // eof - $RCSfile$