]> Creatis software - cpPlugins.git/blob - lib/cpBaseQtApplication/ActorPropertiesQDialog.cxx
...
[cpPlugins.git] / lib / cpBaseQtApplication / ActorPropertiesQDialog.cxx
1 #include <cpBaseQtApplication/ActorPropertiesQDialog.h>
2
3 #include <cpBaseQtApplication/ActorAxesProperties.h>
4 #include <cpBaseQtApplication/ActorImageProperties.h>
5 #include <cpBaseQtApplication/ActorLUTImageProperties.h>
6 #include <cpBaseQtApplication/ActorPolyDataProperties.h>
7
8 #include <vtkActor.h>
9 #include <vtkPropCollection.h>
10
11 #include <map>
12 #include <set>
13 #include <sstream>
14
15 /*
16   #include <vtkImageData.h>
17   #include <vtkImageProperty.h>
18   #include <vtkMapper.h>
19   #include <vtkProperty.h>
20
21   #include <QCheckBox>
22   #include <QColorDialog>
23   #include <QDoubleSpinBox>
24   #include <QPushButton>
25   #include <QSlider>
26 */
27
28 // -------------------------------------------------------------------------
29 cpBaseQtApplication::ActorPropertiesQDialog::
30 ActorPropertiesQDialog( QWidget* parent, Qt::WindowFlags f )
31   : QDialog( parent, f ),
32     m_MainWidget( NULL )
33 {
34   this->m_Title = new QLabel( this );
35   this->m_Title->setText( "Visualization properties" );
36   this->m_MainLayout = new QGridLayout( this );
37   this->m_ToolsLayout = new QVBoxLayout( );
38   this->m_ToolsLayout->addWidget( this->m_Title );
39   this->m_MainLayout->addLayout( this->m_ToolsLayout, 0, 0, 1, 1 );
40 }
41
42 // -------------------------------------------------------------------------
43 cpBaseQtApplication::ActorPropertiesQDialog::
44 ~ActorPropertiesQDialog( )
45 {
46 }
47
48 // -------------------------------------------------------------------------
49 void cpBaseQtApplication::ActorPropertiesQDialog::
50 setProps( const TProps& props )
51 {
52   if( this->m_MainWidget == NULL )
53   {
54     std::map< std::string, std::set< vtkProp* > > all_props;
55     for( auto coll = props.begin( ); coll != props.end( ); ++coll )
56     {
57       ( *coll )->InitTraversal( );
58       while( auto p = ( *coll )->GetNextProp( ) )
59         all_props[ p->GetClassName( ) ].insert( p );
60
61     } // rof
62
63     std::stringstream title;
64     title << "Parameters for an object of class";
65     auto wl_actors = all_props.find( "WindowLevelImageActor" );
66     auto lt_actors = all_props.find( "LUTImageActor" );
67     auto actors = all_props.end( );
68     if( wl_actors != all_props.end( ) )
69     {
70       title << "\"Image\"";
71       this->m_MainWidget = new cpBaseQtApplication::ActorImageProperties( this );
72       actors = wl_actors;
73     }
74     else if( lt_actors != all_props.end( ) )
75     {
76       title << "\"LUT Image\"";
77       this->m_MainWidget = new cpBaseQtApplication::ActorLUTImageProperties( this );
78       actors = lt_actors;
79     }
80     else
81     {
82       if( all_props.size( ) == 1 )
83       {
84         auto mesh =
85           dynamic_cast< vtkActor* >( *( all_props.begin( )->second.begin( ) ) );
86         if( mesh != NULL )
87         {
88           title << "\"Mesh\"";
89           this->m_MainWidget =
90             new cpBaseQtApplication::ActorPolyDataProperties( this );
91           actors = all_props.begin( );
92
93         } // fi
94
95       } // fi
96
97     } // fi
98
99     if( actors != all_props.end( ) )
100     {
101       this->m_Title->setText( title.str( ).c_str( ) );
102       this->m_ToolsLayout->addWidget( this->m_MainWidget );
103       this->m_Buttons = new QDialogButtonBox( QDialogButtonBox::Ok );
104       this->connect(
105         this->m_Buttons, SIGNAL( accepted( ) ), this, SLOT( accept( ) )
106         );
107       this->connect(
108         this->m_Buttons, SIGNAL( rejected( ) ), this, SLOT( reject( ) )
109         );
110       this->m_ToolsLayout->addWidget( this->m_Buttons );
111
112       for( auto a = actors->second.begin( ); a != actors->second.end( ); ++a )
113         this->m_MainWidget->addActor( *a );
114
115     } // fi
116
117   } // fi
118 }
119
120 // -------------------------------------------------------------------------
121 bool cpBaseQtApplication::ActorPropertiesQDialog::
122 addRenderWindow( vtkRenderWindow* win )
123 {
124   if( this->m_MainWidget != NULL && win != NULL )
125     return( this->m_MainWidget->addRenderWindow( win ) );
126   else
127     return( false );
128 }
129
130 // eof - $RCSfile$