1 #include <cpPlugins/ActorAxesProperties.h>
5 #include <cpPlugins/ui_ActorAxesProperties.h>
7 #include <QColorDialog>
9 #include <vtkAxesActor.h>
10 #include <vtkCaptionActor2D.h>
11 #include <vtkMatrix4x4.h>
12 #include <vtkTextProperty.h>
14 // -------------------------------------------------------------------------
15 cpPlugins::ActorAxesProperties::
16 ActorAxesProperties( QWidget* parent )
17 : cpPlugins::ActorProperties( parent ),
18 m_UI( new Ui::ActorAxesProperties )
20 this->m_UI->setupUi( this );
23 // -------------------------------------------------------------------------
24 cpPlugins::ActorAxesProperties::
25 ~ActorAxesProperties( )
30 // -------------------------------------------------------------------------
31 bool cpPlugins::ActorAxesProperties::
32 addActor( vtkProp* obj )
34 auto actor = dynamic_cast< vtkAxesActor* >( obj );
37 this->m_Actors.insert( obj );
38 if( this->m_Actors.size( ) == 1 )
39 this->_updateWidgets( );
46 // -------------------------------------------------------------------------
47 void cpPlugins::ActorAxesProperties::
51 dynamic_cast< vtkAxesActor* >( this->m_Actors.begin( )->GetPointer( ) );
56 std::string xtext( actor->GetXAxisLabelText( ) );
57 std::string ytext( actor->GetYAxisLabelText( ) );
58 std::string ztext( actor->GetZAxisLabelText( ) );
59 double scale = actor->GetScale( )[ 0 ];
60 auto prop = actor->GetXAxisCaptionActor2D( )->GetCaptionTextProperty( );
62 prop->GetColor( rgb );
63 rgb[ 0 ] *= double( 255 );
64 rgb[ 1 ] *= double( 255 );
65 rgb[ 2 ] *= double( 255 );
68 auto palette = this->m_UI->TextColor->palette( );
70 QPalette::Button, QColor( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ] )
72 this->m_UI->TextColor->setAutoFillBackground( true );
73 this->m_UI->TextColor->setPalette( palette );
75 this->m_UI->XText->setText( xtext.c_str( ) );
76 this->m_UI->YText->setText( ytext.c_str( ) );
77 this->m_UI->ZText->setText( ztext.c_str( ) );
78 this->m_UI->Scale->setValue( scale );
82 this->m_UI->Scale, SIGNAL( valueChanged( double ) ),
83 this, SLOT( _Scale( double ) )
86 this->m_UI->XText, SIGNAL( textChanged( const QString& ) ),
87 this, SLOT( _TextChanged( const QString& ) )
90 this->m_UI->YText, SIGNAL( textChanged( const QString& ) ),
91 this, SLOT( _TextChanged( const QString& ) )
94 this->m_UI->ZText, SIGNAL( textChanged( const QString& ) ),
95 this, SLOT( _TextChanged( const QString& ) )
98 this->m_UI->TextColor, SIGNAL( clicked( ) ),
99 this, SLOT( _TextColor( ) )
103 // -------------------------------------------------------------------------
104 void cpPlugins::ActorAxesProperties::
107 itk::Vector< double, 3 > x, y, z;
108 auto aIt = this->m_Actors.begin( );
109 for( ; aIt != this->m_Actors.end( ); ++aIt )
111 auto ma = dynamic_cast< vtkAxesActor* >( aIt->GetPointer( ) );
112 auto matrix = ma->GetUserMatrix( );
113 for( unsigned int d = 0; d < 3; ++d )
115 x[ d ] = matrix->GetElement( d, 0 );
116 y[ d ] = matrix->GetElement( d, 1 );
117 z[ d ] = matrix->GetElement( d, 2 );
120 auto nx = x.GetNorm( );
121 auto ny = y.GetNorm( );
122 auto nz = z.GetNorm( );
123 if( nx > double( 0 ) ) x /= nx;
124 if( ny > double( 0 ) ) y /= ny;
125 if( nz > double( 0 ) ) z /= nz;
129 for( unsigned int d = 0; d < 3; ++d )
131 matrix->SetElement( d, 0, x[ d ] );
132 matrix->SetElement( d, 1, y[ d ] );
133 matrix->SetElement( d, 2, z[ d ] );
142 // -------------------------------------------------------------------------
143 void cpPlugins::ActorAxesProperties::
144 _TextChanged( const QString& text )
146 auto obj = this->sender( );
147 auto aIt = this->m_Actors.begin( );
148 auto str = text.toStdString( );
149 for( ; aIt != this->m_Actors.end( ); ++aIt )
151 auto ma = dynamic_cast< vtkAxesActor* >( aIt->GetPointer( ) );
152 if( obj == this->m_UI->XText )
153 ma->SetXAxisLabelText( str.c_str( ) );
154 else if( obj == this->m_UI->YText )
155 ma->SetYAxisLabelText( str.c_str( ) );
156 else if( obj == this->m_UI->ZText )
157 ma->SetZAxisLabelText( str.c_str( ) );
164 // -------------------------------------------------------------------------
165 void cpPlugins::ActorAxesProperties::
168 if( this->m_Actors.size( ) == 0 )
170 QPalette pal = this->m_UI->TextColor->palette( );
172 QColorDialog::getColor(
173 pal.color( QPalette::Button ),
176 QColorDialog::DontUseNativeDialog
178 if( color.isValid( ) )
180 pal.setColor( QPalette::Button, color );
181 this->m_UI->TextColor->setAutoFillBackground( true );
182 this->m_UI->TextColor->setPalette( pal );
183 this->m_UI->TextColor->update( );
186 rgb[ 0 ] = double( color.red( ) ) / double( 255 );
187 rgb[ 1 ] = double( color.green( ) ) / double( 255 );
188 rgb[ 2 ] = double( color.blue( ) ) / double( 255 );
189 auto aIt = this->m_Actors.begin( );
190 for( ; aIt != this->m_Actors.end( ); ++aIt )
192 auto ma = dynamic_cast< vtkAxesActor* >( aIt->GetPointer( ) );
193 ma->GetXAxisCaptionActor2D( )->GetCaptionTextProperty( )->SetColor( rgb );
194 ma->GetYAxisCaptionActor2D( )->GetCaptionTextProperty( )->SetColor( rgb );
195 ma->GetZAxisCaptionActor2D( )->GetCaptionTextProperty( )->SetColor( rgb );
196 ma->GetXAxisCaptionActor2D( )->Modified( );
197 ma->GetYAxisCaptionActor2D( )->Modified( );
198 ma->GetZAxisCaptionActor2D( )->Modified( );
207 #endif // cpPlugins_QT4