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