]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Object.cxx
054321c22888628d7d702a71543a9599575ade82
[cpPlugins.git] / lib / cpPlugins / Object.cxx
1 #include <cpPlugins/Object.h>
2
3 #include <itkObject.h>
4 #include <vtkObject.h>
5
6 // -------------------------------------------------------------------------
7 const float& cpPlugins::Object::
8 GetViewX( ) const
9 {
10   return( this->m_ViewX );
11 }
12
13 // -------------------------------------------------------------------------
14 const float& cpPlugins::Object::
15 GetViewY( ) const
16 {
17   return( this->m_ViewY );
18 }
19
20 // -------------------------------------------------------------------------
21 void cpPlugins::Object::
22 SetViewCoords( float x, float y )
23 {
24   this->m_ViewX = x;
25   this->m_ViewY = y;
26   // WARNING: do not call "this->Modified( )" -> It could lead to a
27   //          re-execution of all pipeline
28 }
29
30 #ifdef cpPlugins_QT4
31 // -------------------------------------------------------------------------
32 void cpPlugins::Object::
33 SetViewCoords( const QPointF& coords )
34 {
35   this->SetViewCoords( coords.x( ), coords.y( ) );
36 }
37
38 // -------------------------------------------------------------------------
39 QPointF cpPlugins::Object::
40 GetViewCoords( ) const
41 {
42   return( QPointF( this->m_ViewX, this->m_ViewY ) );
43 }
44 #endif // cpPlugins_QT4
45
46 // -------------------------------------------------------------------------
47 void cpPlugins::Object::
48 Modified( ) const
49 {
50   const itk::Object* i = this->GetITK< itk::Object >( );
51   vtkObject* v = const_cast< vtkObject* >( this->GetVTK< vtkObject >( ) );
52   if( i != NULL ) i->Modified( );
53   if( v != NULL ) v->Modified( );
54   this->Superclass::Modified( );
55 }
56
57 // -------------------------------------------------------------------------
58 itk::ModifiedTimeType cpPlugins::Object::
59 GetMTime( ) const
60 {
61   const itk::Object* i = this->GetITK< itk::Object >( );
62   vtkObject* v = const_cast< vtkObject* >( this->GetVTK< vtkObject >( ) );
63   if( i != NULL && v == NULL )
64     return( i->GetMTime( ) );
65   else if( i == NULL && v != NULL )
66     return( v->GetMTime( ) );
67   else if( i != NULL && v != NULL )
68   {
69     auto iTime = i->GetMTime( );
70     auto vTime = i->GetMTime( );
71     return( itk::ModifiedTimeType( ( iTime > vTime )? iTime: vTime ) );
72   }
73   else
74     return( this->Superclass::GetMTime( ) );
75 }
76
77 // -------------------------------------------------------------------------
78 void cpPlugins::Object::
79 SetITK( itk::LightObject* o )
80 {
81   if( this->m_ITKObject.GetPointer( ) != o )
82   {
83     this->m_ITKObject = o;
84     this->Modified( );
85
86   } // fi
87 }
88
89 // -------------------------------------------------------------------------
90 void cpPlugins::Object::
91 SetVTK( vtkObjectBase* o )
92 {
93   if( this->m_VTKObject.GetPointer( ) != o )
94   {
95     this->m_VTKObject = o;
96     this->Modified( );
97
98   } // fi
99 }
100
101 // -------------------------------------------------------------------------
102 cpPlugins::Object::
103 Object( )
104   : m_ITKObject( NULL ),
105     m_VTKObject( NULL ),
106     m_ViewX( float( 0 ) ),
107     m_ViewY( float( 0 ) )
108 {
109 }
110
111 // -------------------------------------------------------------------------
112 cpPlugins::Object::
113 ~Object( )
114 {
115 }
116
117 // eof - $RCSfile$