]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Interaction/SeedWidget.cxx
Architecture updated.
[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 }
97
98 // -------------------------------------------------------------------------
99 void cpExtensions::Interaction::SeedWidget::
100 _MoveAction( vtkAbstractWidget* wdg )
101 {
102   // Do nothing
103 }
104
105 // -------------------------------------------------------------------------
106 void cpExtensions::Interaction::SeedWidget::
107 _EndSelectAction( vtkAbstractWidget* wdg )
108 {
109   // Do nothing
110 }
111
112 // -------------------------------------------------------------------------
113 void cpExtensions::Interaction::SeedWidget::
114 _DeleteAction( vtkAbstractWidget* wdg )
115 {
116   // Do nothing
117 }
118
119 // -------------------------------------------------------------------------
120 /* TODO
121    void cpExtensions::Interaction::SeedWidget::
122    _Click(
123    void* data, const TBaseStyle::ButtonID& button,
124    int* idx, double* pos, bool alt, bool ctr, bool sft
125    )
126    {
127    SeedWidget* self = reinterpret_cast< SeedWidget* >( data );
128    if( self == NULL )
129    return;
130    if( self->WidgetState == vtkSeedWidget::MovingSeed )
131    return;
132
133    int st = self->WidgetRep->ComputeInteractionState( idx[ 0 ], idx[ 1 ] );
134    if( st == vtkSeedRepresentation::NearSeed )
135    {
136    self->WidgetState = vtkSeedWidget::MovingSeed;
137
138    // Invoke an event on ourself for the handles
139    self->InvokeEvent( vtkCommand::LeftButtonPressEvent, NULL );
140    self->Superclass::StartInteraction( );
141    self->InvokeEvent( vtkCommand::StartInteractionEvent, NULL );
142    self->EventCallbackCommand->SetAbortFlag( 1 );
143    self->Render( );
144
145    } // fi
146    }
147
148    // -------------------------------------------------------------------------
149    void cpExtensions::Interaction::SeedWidget::
150    _DoubleClick(
151    void* data, const TBaseStyle::ButtonID& button,
152    int* idx, double* pos, bool alt, bool ctr, bool sft
153    )
154    {
155    Self::AddPointAction( reinterpret_cast< vtkAbstractWidget* >( data ) );
156    }
157 */
158
159 // eof - $RCSfile$