]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Interaction/SeedWidget.cxx
b6e348f5bce6d28484d517e1429a224fb04f4ad0
[cpPlugins.git] / lib / cpExtensions / Interaction / SeedWidget.cxx
1 #include <cpExtensions/Interaction/SeedWidget.h>
2
3 #include <vtkEvent.h>
4 #include <vtkWidgetCallbackMapper.h>
5 #include <vtkWidgetEvent.h>
6
7 // -------------------------------------------------------------------------
8 cpExtensions::Interaction::SeedWidget::
9 Self* cpExtensions::Interaction::SeedWidget::
10 New( )
11 {
12   return( new Self );
13 }
14
15 // -------------------------------------------------------------------------
16 void cpExtensions::Interaction::SeedWidget::
17 SetInteractor( vtkRenderWindowInteractor* rwi )
18 {
19   this->Superclass::SetInteractor( rwi );
20   /* TODO
21      if( rwi != NULL )
22      {
23      TBaseStyle* s =
24      dynamic_cast< TBaseStyle* >( rwi->GetInteractorStyle( ) );
25      if( s != NULL )
26      {
27      s->AddMouseClickCommand( Self::_Click, this );
28      s->AddMouseDoubleClickCommand( Self::_DoubleClick, this );
29
30      } // fi
31
32      } // fi
33   */
34 }
35
36 // -------------------------------------------------------------------------
37 cpExtensions::Interaction::SeedWidget::
38 SeedWidget( )
39   : Superclass( )
40 {
41   // These are the event callbacks supported by this widget
42   this->CallbackMapper->SetCallbackMethod(
43     vtkCommand::LeftButtonPressEvent,
44     vtkWidgetEvent::AddPoint,
45     this, Self::_AddPointAction
46     );
47   this->CallbackMapper->SetCallbackMethod(
48     vtkCommand::RightButtonPressEvent,
49     vtkWidgetEvent::Completed,
50     this, Self::_CompletedAction
51     );
52   this->CallbackMapper->SetCallbackMethod(
53     vtkCommand::MouseMoveEvent,
54     vtkWidgetEvent::Move,
55     this, Self::_MoveAction
56     );
57   this->CallbackMapper->SetCallbackMethod(
58     vtkCommand::LeftButtonReleaseEvent,
59     vtkWidgetEvent::EndSelect,
60     this, Self::_EndSelectAction
61     );
62   this->CallbackMapper->SetCallbackMethod(
63     vtkCommand::KeyPressEvent,
64     vtkEvent::NoModifier, 127, 1, "Delete",
65     vtkWidgetEvent::Delete,
66     this, Self::_DeleteAction
67     );
68 }
69
70 // -------------------------------------------------------------------------
71 cpExtensions::Interaction::SeedWidget::
72 ~SeedWidget( )
73 {
74 }
75
76 // -------------------------------------------------------------------------
77 void cpExtensions::Interaction::SeedWidget::
78 _AddPointAction( vtkAbstractWidget* wdg )
79 {
80   Self* self = dynamic_cast< Self* >( wdg );
81   if( self == NULL )
82     return;
83   auto iren = self->GetInteractor( );
84   if( iren == NULL )
85     return;
86   int shift = iren->GetShiftKey( );
87   if( shift == 1 )
88     Self::AddPointAction( wdg );
89 }
90
91 // -------------------------------------------------------------------------
92 void cpExtensions::Interaction::SeedWidget::
93 _CompletedAction( vtkAbstractWidget* wdg )
94 {
95   // Do nothing
96   Self::CompletedAction( wdg );
97 }
98
99 // -------------------------------------------------------------------------
100 void cpExtensions::Interaction::SeedWidget::
101 _MoveAction( vtkAbstractWidget* wdg )
102 {
103   // Do nothing
104   Self::MoveAction( wdg );
105 }
106
107 // -------------------------------------------------------------------------
108 void cpExtensions::Interaction::SeedWidget::
109 _EndSelectAction( vtkAbstractWidget* wdg )
110 {
111   // Do nothing
112   Self::EndSelectAction( wdg );
113 }
114
115 // -------------------------------------------------------------------------
116 void cpExtensions::Interaction::SeedWidget::
117 _DeleteAction( vtkAbstractWidget* wdg )
118 {
119   // Do nothing
120   Self::DeleteAction( wdg );
121 }
122
123 // -------------------------------------------------------------------------
124 /* TODO
125    void cpExtensions::Interaction::SeedWidget::
126    _Click(
127    void* data, const TBaseStyle::ButtonID& button,
128    int* idx, double* pos, bool alt, bool ctr, bool sft
129    )
130    {
131    SeedWidget* self = reinterpret_cast< SeedWidget* >( data );
132    if( self == NULL )
133    return;
134    if( self->WidgetState == vtkSeedWidget::MovingSeed )
135    return;
136
137    int st = self->WidgetRep->ComputeInteractionState( idx[ 0 ], idx[ 1 ] );
138    if( st == vtkSeedRepresentation::NearSeed )
139    {
140    self->WidgetState = vtkSeedWidget::MovingSeed;
141
142    // Invoke an event on ourself for the handles
143    self->InvokeEvent( vtkCommand::LeftButtonPressEvent, NULL );
144    self->Superclass::StartInteraction( );
145    self->InvokeEvent( vtkCommand::StartInteractionEvent, NULL );
146    self->EventCallbackCommand->SetAbortFlag( 1 );
147    self->Render( );
148
149    } // fi
150    }
151
152    // -------------------------------------------------------------------------
153    void cpExtensions::Interaction::SeedWidget::
154    _DoubleClick(
155    void* data, const TBaseStyle::ButtonID& button,
156    int* idx, double* pos, bool alt, bool ctr, bool sft
157    )
158    {
159    Self::AddPointAction( reinterpret_cast< vtkAbstractWidget* >( data ) );
160    }
161 */
162
163 // eof - $RCSfile$