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