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