1 #include <cpBaseQtApplication/ActorAxesProperties.h>
3 #include <cpBaseQtApplication/ui_ActorAxesProperties.h>
5 #include <QColorDialog>
7 #include <vtkAxesActor.h>
8 #include <vtkCaptionActor2D.h>
9 #include <vtkMatrix4x4.h>
10 #include <vtkTextProperty.h>
12 // -------------------------------------------------------------------------
13 cpBaseQtApplication::ActorAxesProperties::
14 ActorAxesProperties( QWidget* parent )
15 : cpBaseQtApplication::ActorProperties( parent ),
16 m_UI( new Ui::ActorAxesProperties )
18 this->m_UI->setupUi( this );
21 // -------------------------------------------------------------------------
22 cpBaseQtApplication::ActorAxesProperties::
23 ~ActorAxesProperties( )
28 // -------------------------------------------------------------------------
29 bool cpBaseQtApplication::ActorAxesProperties::
30 addActor( vtkProp* obj )
32 auto actor = dynamic_cast< vtkAxesActor* >( obj );
35 this->m_Actors.insert( obj );
36 if( this->m_Actors.size( ) == 1 )
37 this->_updateWidgets( );
44 // -------------------------------------------------------------------------
45 void cpBaseQtApplication::ActorAxesProperties::
49 dynamic_cast< vtkAxesActor* >( this->m_Actors.begin( )->GetPointer( ) );
54 std::string xtext( actor->GetXAxisLabelText( ) );
55 std::string ytext( actor->GetYAxisLabelText( ) );
56 std::string ztext( actor->GetZAxisLabelText( ) );
57 double scale = actor->GetScale( )[ 0 ];
58 auto prop = actor->GetXAxisCaptionActor2D( )->GetCaptionTextProperty( );
60 prop->GetColor( rgb );
61 rgb[ 0 ] *= double( 255 );
62 rgb[ 1 ] *= double( 255 );
63 rgb[ 2 ] *= double( 255 );
66 auto palette = this->m_UI->TextColor->palette( );
68 QPalette::Button, QColor( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ] )
70 this->m_UI->TextColor->setAutoFillBackground( true );
71 this->m_UI->TextColor->setPalette( palette );
73 this->m_UI->XText->setText( xtext.c_str( ) );
74 this->m_UI->YText->setText( ytext.c_str( ) );
75 this->m_UI->ZText->setText( ztext.c_str( ) );
76 this->m_UI->Scale->setValue( scale );
80 this->m_UI->Scale, SIGNAL( valueChanged( double ) ),
81 this, SLOT( _Scale( double ) )
84 this->m_UI->XText, SIGNAL( textChanged( const QString& ) ),
85 this, SLOT( _TextChanged( const QString& ) )
88 this->m_UI->YText, SIGNAL( textChanged( const QString& ) ),
89 this, SLOT( _TextChanged( const QString& ) )
92 this->m_UI->ZText, SIGNAL( textChanged( const QString& ) ),
93 this, SLOT( _TextChanged( const QString& ) )
96 this->m_UI->TextColor, SIGNAL( clicked( ) ),
97 this, SLOT( _TextColor( ) )
101 // -------------------------------------------------------------------------
102 void cpBaseQtApplication::ActorAxesProperties::
105 itk::Vector< double, 3 > x, y, z;
106 auto aIt = this->m_Actors.begin( );
107 for( ; aIt != this->m_Actors.end( ); ++aIt )
109 auto ma = dynamic_cast< vtkAxesActor* >( aIt->GetPointer( ) );
110 auto matrix = ma->GetUserMatrix( );
111 for( unsigned int d = 0; d < 3; ++d )
113 x[ d ] = matrix->GetElement( d, 0 );
114 y[ d ] = matrix->GetElement( d, 1 );
115 z[ d ] = matrix->GetElement( d, 2 );
118 auto nx = x.GetNorm( );
119 auto ny = y.GetNorm( );
120 auto nz = z.GetNorm( );
121 if( nx > double( 0 ) ) x /= nx;
122 if( ny > double( 0 ) ) y /= ny;
123 if( nz > double( 0 ) ) z /= nz;
127 for( unsigned int d = 0; d < 3; ++d )
129 matrix->SetElement( d, 0, x[ d ] );
130 matrix->SetElement( d, 1, y[ d ] );
131 matrix->SetElement( d, 2, z[ d ] );
140 // -------------------------------------------------------------------------
141 void cpBaseQtApplication::ActorAxesProperties::
142 _TextChanged( const QString& text )
144 auto obj = this->sender( );
145 auto aIt = this->m_Actors.begin( );
146 auto str = text.toStdString( );
147 for( ; aIt != this->m_Actors.end( ); ++aIt )
149 auto ma = dynamic_cast< vtkAxesActor* >( aIt->GetPointer( ) );
150 if( obj == this->m_UI->XText )
151 ma->SetXAxisLabelText( str.c_str( ) );
152 else if( obj == this->m_UI->YText )
153 ma->SetYAxisLabelText( str.c_str( ) );
154 else if( obj == this->m_UI->ZText )
155 ma->SetZAxisLabelText( str.c_str( ) );
162 // -------------------------------------------------------------------------
163 void cpBaseQtApplication::ActorAxesProperties::
166 if( this->m_Actors.size( ) == 0 )
168 QPalette pal = this->m_UI->TextColor->palette( );
170 QColorDialog::getColor(
171 pal.color( QPalette::Button ),
174 QColorDialog::DontUseNativeDialog
176 if( color.isValid( ) )
178 pal.setColor( QPalette::Button, color );
179 this->m_UI->TextColor->setAutoFillBackground( true );
180 this->m_UI->TextColor->setPalette( pal );
181 this->m_UI->TextColor->update( );
184 rgb[ 0 ] = double( color.red( ) ) / double( 255 );
185 rgb[ 1 ] = double( color.green( ) ) / double( 255 );
186 rgb[ 2 ] = double( color.blue( ) ) / double( 255 );
187 auto aIt = this->m_Actors.begin( );
188 for( ; aIt != this->m_Actors.end( ); ++aIt )
190 auto ma = dynamic_cast< vtkAxesActor* >( aIt->GetPointer( ) );
191 ma->GetXAxisCaptionActor2D( )->GetCaptionTextProperty( )->SetColor( rgb );
192 ma->GetYAxisCaptionActor2D( )->GetCaptionTextProperty( )->SetColor( rgb );
193 ma->GetZAxisCaptionActor2D( )->GetCaptionTextProperty( )->SetColor( rgb );
194 ma->GetXAxisCaptionActor2D( )->Modified( );
195 ma->GetYAxisCaptionActor2D( )->Modified( );
196 ma->GetZAxisCaptionActor2D( )->Modified( );