]> Creatis software - cpPlugins.git/blob - appli/PipelineEditor/PipelineEditor.cxx
7c06aac5af584e0432a6264c967e55e090fab3bc
[cpPlugins.git] / appli / PipelineEditor / PipelineEditor.cxx
1 #include "PipelineEditor.h"
2 #include "ui_PipelineEditor.h"
3
4 #include <cpPipelineEditor/Editor.h>
5 #include <cpExtensions/QT/PropertyWidget.h>
6 #include <QMessageBox>
7 #include <vtkRenderWindowInteractor.h>
8
9 // -------------------------------------------------------------------------
10 PipelineEditor::
11 PipelineEditor( int argc, char* argv[], QApplication* app, QWidget* parent )
12   : Superclass( argc, argv, app, parent ),
13     m_UI( new Ui::PipelineEditor )
14 {
15   // Basic configuration
16   this->m_UI->setupUi( this );
17   this->_Configure(
18     this->m_UI->LoadedPlugins,
19     this->m_UI->Viewer,
20     this->m_UI->Canvas->editor( )
21     );
22
23   // Connect actions to slots
24   this->connect(
25     this->m_UI->ButtonLoadPluginsFile, SIGNAL( clicked( ) ),
26     this, SLOT( _InteractiveLoadPlugins( ) )
27     );
28   this->connect(
29     this->m_UI->ButtonLoadPluginsPath, SIGNAL( clicked( ) ),
30     this, SLOT( _InteractiveLoadPluginsFromPath( ) )
31     );
32   this->connect(
33     this->m_UI->ActionOpenWorkspace, SIGNAL( triggered( ) ),
34     this, SLOT( _InteractiveLoadWorkspace( ) )
35     );
36   this->connect(
37     this->m_UI->ActionSaveWorkspace, SIGNAL( triggered( ) ),
38     this, SLOT( _InteractiveSaveWorkspace( ) )
39     );
40   this->connect(
41     this->m_UI->Canvas->editor( ),
42     SIGNAL( execFilter( const std::string& ) ),
43     this,
44     SLOT( _ExecFilter( const std::string& ) )
45     );
46   this->connect(
47     this->m_UI->Canvas->editor( ),
48     SIGNAL( showFilterOutput( const std::string&, const std::string& ) ),
49     this,
50     SLOT( _ShowFilterOutput( const std::string&, const std::string& ) )
51     );
52   this->connect(
53     this->m_UI->Canvas->editor( ),
54     SIGNAL( hideFilterOutput( const std::string&, const std::string& ) ),
55     this,
56     SLOT( _HideFilterOutput( const std::string&, const std::string& ) )
57     );
58   this->connect(
59     this->m_UI->Canvas->editor( ),
60     SIGNAL( visualPropertiesFilterOutput( const std::string&, const std::string& ) ),
61     this,
62     SLOT( _PropertiesFilterOutput( const std::string&, const std::string& ) )
63     );
64 }
65
66 // -------------------------------------------------------------------------
67 PipelineEditor::
68 ~PipelineEditor( )
69 {
70   delete this->m_UI;
71 }
72
73 // -------------------------------------------------------------------------
74 void PipelineEditor::
75 _ShowFilterOutput(
76   const std::string& filter_name, const std::string& output_name
77   )
78 {
79   typedef cpPlugins::DataObject _TDataObject;
80
81   // Update filter, if needed
82   this->_ExecFilter( filter_name );
83
84   // Get output
85   auto filter = this->m_Workspace.GetFilter( filter_name );
86   if( filter != NULL )
87   {
88     auto output = filter->GetOutputData( output_name );
89     if( output != NULL )
90     {
91       std::string data_name = output_name + "@" + filter_name;
92       auto idata = output->GetVTK< vtkImageData >( );
93       auto mdata = output->GetVTK< vtkPolyData >( );
94       if( idata != NULL )
95       {
96         if( this->m_UI->Viewer->AddData( idata, data_name, "" ) )
97         {
98           if( this->m_UI->Viewer->GetNumberOfData( ) > 1 )
99             this->m_UI->Viewer->SetDataColor( data_name, 1, 0, 0 );
100           else
101             this->m_UI->Viewer->SetMainImage( data_name );
102           this->_Block( );
103           this->m_UI->Viewer->ShowData( data_name );
104           this->_UnBlock( );
105
106         } // fi
107       }
108       else if( mdata != NULL )
109       {
110         if( this->m_UI->Viewer->AddData( mdata, data_name ) )
111         {
112           this->m_UI->Viewer->SetDataColor( data_name, 1, 0, 0 );
113           this->_Block( );
114           this->m_UI->Viewer->ShowData( data_name );
115           this->_UnBlock( );
116
117         } // fi
118       }
119       else
120         QMessageBox::critical(
121           this,
122           QMessageBox::tr( "Error showing data" ),
123           QMessageBox::tr( "No known VTK conversion!" )
124           );
125
126     } // fi
127
128   } // fi
129 }
130
131 // -------------------------------------------------------------------------
132 void PipelineEditor::
133 _HideFilterOutput(
134   const std::string& filter_name, const std::string& output_name
135   )
136 {
137   // Get output
138   auto filter = this->m_Workspace.GetFilter( filter_name );
139   if( filter != NULL )
140   {
141     auto output = filter->GetOutputData( output_name );
142     if( output != NULL )
143     {
144       std::string data_name = output_name + "@" + filter_name;
145       this->m_UI->Viewer->HideData( data_name );
146
147     } // fi
148
149   } // fi
150 }
151
152 // -------------------------------------------------------------------------
153 void PipelineEditor::
154 _PropertiesFilterOutput(
155   const std::string& filter_name, const std::string& output_name
156   )
157 {
158   // Get output
159   auto filter = this->m_Workspace.GetFilter( filter_name );
160   if( filter != NULL )
161   {
162     auto output = filter->GetOutputData( output_name );
163     if( output != NULL )
164     {
165       std::string data_name = output_name + "@" + filter_name;
166       auto prop = this->m_UI->Viewer->GetProp( data_name );
167
168       cpExtensions::QT::PropertyWidget* wdg =
169         new cpExtensions::QT::PropertyWidget( NULL );
170       wdg->SetProp( prop );
171       wdg->SetRenderWindow( this->m_UI->Viewer->GetInteractor( 3 )->GetRenderWindow( ) );
172       wdg->show( );
173     }
174     else
175       QMessageBox::critical(
176         this,
177         QMessageBox::tr( "Error showing data" ),
178         QMessageBox::tr( "No known VTK conversion!" )
179         );
180
181   } // fi
182 }
183
184 // eof - $RCSfile$