]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Interaction/SeedWidget.cxx
More widgets added
[cpPlugins.git] / lib / cpExtensions / Interaction / SeedWidget.cxx
1 #include <cpExtensions/Interaction/SeedWidget.h>
2
3 #include <vtkCallbackCommand.h>
4 #include <vtkCommand.h>
5 #include <vtkRenderWindowInteractor.h>
6 #include <vtkSeedRepresentation.h>
7 #include <vtkWidgetEventTranslator.h>
8 #include <vtkWidgetRepresentation.h>
9
10 // -------------------------------------------------------------------------
11 cpExtensions::Interaction::SeedWidget::
12 Self* cpExtensions::Interaction::SeedWidget::
13 New( )
14 {
15   return( new Self );
16 }
17
18 // -------------------------------------------------------------------------
19 void cpExtensions::Interaction::SeedWidget::
20 SetInteractor( vtkRenderWindowInteractor* rwi )
21 {
22   this->Superclass::SetInteractor( rwi );
23   TBaseStyle* s = dynamic_cast< TBaseStyle*>( rwi->GetInteractorStyle( ) );
24   if( s != NULL )
25   {
26     s->AddMouseClickCommand( Self::_Click, this );
27     s->AddMouseDoubleClickCommand( Self::_DoubleClick, this );
28
29   } // fi
30 }
31
32 // -------------------------------------------------------------------------
33 cpExtensions::Interaction::SeedWidget::
34 SeedWidget( )
35   : Superclass( )
36 {
37   // Remove default translations
38   vtkWidgetEventTranslator* t = this->GetEventTranslator( );
39   t->RemoveTranslation( vtkCommand::LeftButtonPressEvent );
40   t->RemoveTranslation( vtkCommand::MiddleButtonPressEvent );
41   t->RemoveTranslation( vtkCommand::RightButtonPressEvent );
42 }
43
44 // -------------------------------------------------------------------------
45 cpExtensions::Interaction::SeedWidget::
46 ~SeedWidget( )
47 {
48 }
49
50 // -------------------------------------------------------------------------
51 void cpExtensions::Interaction::SeedWidget::
52 _Click(
53   void* data, const TBaseStyle::ButtonID& button,
54   int* idx, double* pos, bool alt, bool ctr, bool sft
55   )
56 {
57   SeedWidget* self = reinterpret_cast< SeedWidget* >( data );
58   if( self->WidgetState == vtkSeedWidget::MovingSeed )
59     return;
60
61   int st = self->WidgetRep->ComputeInteractionState( idx[ 0 ], idx[ 1 ] );
62   if( st == vtkSeedRepresentation::NearSeed )
63   {
64     self->WidgetState = vtkSeedWidget::MovingSeed;
65
66     // Invoke an event on ourself for the handles
67     self->InvokeEvent( vtkCommand::LeftButtonPressEvent, NULL );
68     self->Superclass::StartInteraction( );
69     self->InvokeEvent( vtkCommand::StartInteractionEvent, NULL );
70     self->EventCallbackCommand->SetAbortFlag( 1 );
71     self->Render( );
72
73   } // fi
74 }
75
76 // -------------------------------------------------------------------------
77 void cpExtensions::Interaction::SeedWidget::
78 _DoubleClick(
79   void* data, const TBaseStyle::ButtonID& button,
80   int* idx, double* pos, bool alt, bool ctr, bool sft
81   )
82 {
83   Self::AddPointAction( reinterpret_cast< vtkAbstractWidget* >( data ) );
84 }
85
86 // eof - $RCSfile$