1 #include <cpExtensions/Interaction/SeedWidget.h>
4 #include <vtkWidgetCallbackMapper.h>
5 #include <vtkWidgetEvent.h>
7 // -------------------------------------------------------------------------
8 cpExtensions::Interaction::SeedWidget::
9 Self* cpExtensions::Interaction::SeedWidget::
15 // -------------------------------------------------------------------------
16 void cpExtensions::Interaction::SeedWidget::
17 SetInteractor( vtkRenderWindowInteractor* rwi )
19 this->Superclass::SetInteractor( rwi );
24 dynamic_cast< TBaseStyle* >( rwi->GetInteractorStyle( ) );
27 s->AddMouseClickCommand( Self::_Click, this );
28 s->AddMouseDoubleClickCommand( Self::_DoubleClick, this );
36 // -------------------------------------------------------------------------
37 cpExtensions::Interaction::SeedWidget::
41 // These are the event callbacks supported by this widget
42 this->CallbackMapper->SetCallbackMethod(
43 vtkCommand::LeftButtonPressEvent,
44 vtkWidgetEvent::AddPoint,
45 this, Self::_AddPointAction
47 this->CallbackMapper->SetCallbackMethod(
48 vtkCommand::RightButtonPressEvent,
49 vtkWidgetEvent::Completed,
50 this, Self::_CompletedAction
52 this->CallbackMapper->SetCallbackMethod(
53 vtkCommand::MouseMoveEvent,
55 this, Self::_MoveAction
57 this->CallbackMapper->SetCallbackMethod(
58 vtkCommand::LeftButtonReleaseEvent,
59 vtkWidgetEvent::EndSelect,
60 this, Self::_EndSelectAction
62 this->CallbackMapper->SetCallbackMethod(
63 vtkCommand::KeyPressEvent,
64 vtkEvent::NoModifier, 127, 1, "Delete",
65 vtkWidgetEvent::Delete,
66 this, Self::_DeleteAction
70 // -------------------------------------------------------------------------
71 cpExtensions::Interaction::SeedWidget::
76 // -------------------------------------------------------------------------
77 void cpExtensions::Interaction::SeedWidget::
78 _AddPointAction( vtkAbstractWidget* wdg )
80 Self* self = dynamic_cast< Self* >( wdg );
83 auto iren = self->GetInteractor( );
86 int shift = iren->GetShiftKey( );
88 Self::AddPointAction( wdg );
91 // -------------------------------------------------------------------------
92 void cpExtensions::Interaction::SeedWidget::
93 _CompletedAction( vtkAbstractWidget* wdg )
96 Self::CompletedAction( wdg );
99 // -------------------------------------------------------------------------
100 void cpExtensions::Interaction::SeedWidget::
101 _MoveAction( vtkAbstractWidget* wdg )
104 Self::MoveAction( wdg );
107 // -------------------------------------------------------------------------
108 void cpExtensions::Interaction::SeedWidget::
109 _EndSelectAction( vtkAbstractWidget* wdg )
112 Self::EndSelectAction( wdg );
115 // -------------------------------------------------------------------------
116 void cpExtensions::Interaction::SeedWidget::
117 _DeleteAction( vtkAbstractWidget* wdg )
120 Self::DeleteAction( wdg );
123 // -------------------------------------------------------------------------
125 void cpExtensions::Interaction::SeedWidget::
127 void* data, const TBaseStyle::ButtonID& button,
128 int* idx, double* pos, bool alt, bool ctr, bool sft
131 SeedWidget* self = reinterpret_cast< SeedWidget* >( data );
134 if( self->WidgetState == vtkSeedWidget::MovingSeed )
137 int st = self->WidgetRep->ComputeInteractionState( idx[ 0 ], idx[ 1 ] );
138 if( st == vtkSeedRepresentation::NearSeed )
140 self->WidgetState = vtkSeedWidget::MovingSeed;
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 );
152 // -------------------------------------------------------------------------
153 void cpExtensions::Interaction::SeedWidget::
155 void* data, const TBaseStyle::ButtonID& button,
156 int* idx, double* pos, bool alt, bool ctr, bool sft
159 Self::AddPointAction( reinterpret_cast< vtkAbstractWidget* >( data ) );