]> 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 #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   typedef cpExtensions::QT::ActorsWidgetInterface _TViewer;
52
53   // Get filter parameters
54   std::vector< std::string > tokens;
55   cpPlugins::Tokenize( tokens, name, "@" );
56   if( tokens.size( ) != 2 )
57     return;
58   auto filter_name = tokens[ 1 ];
59   auto output_name = tokens[ 0 ];
60
61   // Process data
62   if( show )
63   {
64     try
65     {
66       auto ws = this->workspace( );
67       auto filter = ws->GetFilter( filter_name );
68       cpBaseQtApplication_Execute( filter->Update( ) );
69       auto image = filter->GetOutputData< vtkImageData >( output_name );
70       auto mesh = filter->GetOutputData< vtkPolyData >( output_name );
71       _TViewer* viewer = NULL;
72       if( image != NULL )
73       {
74         int dim = image->GetDataDimension( );
75         if( dim == 2 )
76           viewer =
77             this->_configureViewer< cpExtensions::QT::ImageWidget >(
78               this->m_UI->Viewer
79               );
80         else if( dim == 3 )
81           viewer =
82             this->_configureViewer< cpExtensions::QT::SimpleMPRWidget >(
83               this->m_UI->Viewer
84               );
85       }
86       else if( mesh != NULL )
87       {
88         viewer =
89           this->_configureViewer< cpExtensions::QT::SimpleMPRWidget >(
90             this->m_UI->Viewer
91             );
92
93       } // fi
94       if(
95         dynamic_cast< QWidget* >( viewer ) !=
96         dynamic_cast< QWidget* >( this->m_UI->Viewer )
97         )
98       {
99         delete this->m_UI->Viewer;
100         this->m_UI->Viewer = dynamic_cast< QWidget* >( viewer );
101         this->m_UI->MainSplitter->insertWidget( 0, this->m_UI->Viewer );
102         this->setViewer( viewer );
103
104       } // fi
105       if( image != NULL )
106       {
107         this->m_Blocker.block( );
108         auto mpr = dynamic_cast< cpExtensions::QT::SimpleMPRWidget* >( viewer );
109         auto imv = dynamic_cast< cpExtensions::QT::ImageWidget* >( viewer );
110         if( mpr != NULL )
111           mpr->SetImage( image, name );
112         else if( imv != NULL )
113           imv->SetImage( image, name );
114         this->m_Blocker.unblock( );
115       }
116       else if( mesh != NULL )
117       {
118         this->m_Blocker.block( );
119         auto mpr = dynamic_cast< cpExtensions::QT::SimpleMPRWidget* >( viewer );
120         if( mpr != NULL )
121           mpr->Add( mesh, name );
122         this->m_Blocker.unblock( );
123
124       } // fi
125     }
126     catch( std::exception& err )
127     {
128       QMessageBox::critical(
129         NULL,
130         QMessageBox::tr( "Error showing data" ),
131         QMessageBox::tr( err.what( ) )
132         );
133
134     } // yrt
135
136   } // fi
137 }
138
139 // -------------------------------------------------------------------------
140 #include <cpBaseQtApplication/MainHelper.h>
141 cpBaseQtApplication_Main( PipelineEditor );
142 cpBaseQtApplication_MainComplement;
143
144 // eof - $RCSfile$