1 #include <cpExtensions/Interaction/SeedWidget.h>
3 #include <vtkCommand.h>
5 #include <vtkRenderWindowInteractor.h>
6 #include <vtkWidgetCallbackMapper.h>
7 #include <vtkWidgetEvent.h>
9 // -------------------------------------------------------------------------
10 cpExtensions::Interaction::SeedWidget::
11 Self* cpExtensions::Interaction::SeedWidget::
17 // -------------------------------------------------------------------------
18 void cpExtensions::Interaction::SeedWidget::
19 SetInteractor( vtkRenderWindowInteractor* rwi )
21 this->Superclass::SetInteractor( rwi );
26 dynamic_cast< TBaseStyle* >( rwi->GetInteractorStyle( ) );
29 s->AddMouseClickCommand( Self::_Click, this );
30 s->AddMouseDoubleClickCommand( Self::_DoubleClick, this );
38 // -------------------------------------------------------------------------
39 cpExtensions::Interaction::SeedWidget::
43 // These are the event callbacks supported by this widget
44 this->CallbackMapper->SetCallbackMethod(
45 vtkCommand::LeftButtonPressEvent,
46 vtkWidgetEvent::AddPoint,
47 this, Self::_AddPointAction
49 this->CallbackMapper->SetCallbackMethod(
50 vtkCommand::RightButtonPressEvent,
51 vtkWidgetEvent::Completed,
52 this, Self::_CompletedAction
54 this->CallbackMapper->SetCallbackMethod(
55 vtkCommand::MouseMoveEvent,
57 this, Self::_MoveAction
59 this->CallbackMapper->SetCallbackMethod(
60 vtkCommand::LeftButtonReleaseEvent,
61 vtkWidgetEvent::EndSelect,
62 this, Self::_EndSelectAction
64 this->CallbackMapper->SetCallbackMethod(
65 vtkCommand::KeyPressEvent,
66 vtkEvent::NoModifier, 127, 1, "Delete",
67 vtkWidgetEvent::Delete,
68 this, Self::_DeleteAction
72 // -------------------------------------------------------------------------
73 cpExtensions::Interaction::SeedWidget::
78 // -------------------------------------------------------------------------
79 void cpExtensions::Interaction::SeedWidget::
80 _AddPointAction( vtkAbstractWidget* wdg )
82 Self* self = dynamic_cast< Self* >( wdg );
85 auto iren = self->GetInteractor( );
88 int shift = iren->GetShiftKey( );
90 Self::AddPointAction( wdg );
93 // -------------------------------------------------------------------------
94 void cpExtensions::Interaction::SeedWidget::
95 _CompletedAction( vtkAbstractWidget* wdg )
98 Self::CompletedAction( wdg );
101 // -------------------------------------------------------------------------
102 void cpExtensions::Interaction::SeedWidget::
103 _MoveAction( vtkAbstractWidget* wdg )
106 Self::MoveAction( wdg );
109 // -------------------------------------------------------------------------
110 void cpExtensions::Interaction::SeedWidget::
111 _EndSelectAction( vtkAbstractWidget* wdg )
114 Self::EndSelectAction( wdg );
117 // -------------------------------------------------------------------------
118 void cpExtensions::Interaction::SeedWidget::
119 _DeleteAction( vtkAbstractWidget* wdg )
122 Self::DeleteAction( wdg );
125 // -------------------------------------------------------------------------
127 void cpExtensions::Interaction::SeedWidget::
129 void* data, const TBaseStyle::ButtonID& button,
130 int* idx, double* pos, bool alt, bool ctr, bool sft
133 SeedWidget* self = reinterpret_cast< SeedWidget* >( data );
136 if( self->WidgetState == vtkSeedWidget::MovingSeed )
139 int st = self->WidgetRep->ComputeInteractionState( idx[ 0 ], idx[ 1 ] );
140 if( st == vtkSeedRepresentation::NearSeed )
142 self->WidgetState = vtkSeedWidget::MovingSeed;
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 );
154 // -------------------------------------------------------------------------
155 void cpExtensions::Interaction::SeedWidget::
157 void* data, const TBaseStyle::ButtonID& button,
158 int* idx, double* pos, bool alt, bool ctr, bool sft
161 Self::AddPointAction( reinterpret_cast< vtkAbstractWidget* >( data ) );