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 )
98 // -------------------------------------------------------------------------
99 void cpExtensions::Interaction::SeedWidget::
100 _MoveAction( vtkAbstractWidget* wdg )
105 // -------------------------------------------------------------------------
106 void cpExtensions::Interaction::SeedWidget::
107 _EndSelectAction( vtkAbstractWidget* wdg )
112 // -------------------------------------------------------------------------
113 void cpExtensions::Interaction::SeedWidget::
114 _DeleteAction( vtkAbstractWidget* wdg )
119 // -------------------------------------------------------------------------
121 void cpExtensions::Interaction::SeedWidget::
123 void* data, const TBaseStyle::ButtonID& button,
124 int* idx, double* pos, bool alt, bool ctr, bool sft
127 SeedWidget* self = reinterpret_cast< SeedWidget* >( data );
130 if( self->WidgetState == vtkSeedWidget::MovingSeed )
133 int st = self->WidgetRep->ComputeInteractionState( idx[ 0 ], idx[ 1 ] );
134 if( st == vtkSeedRepresentation::NearSeed )
136 self->WidgetState = vtkSeedWidget::MovingSeed;
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 );
148 // -------------------------------------------------------------------------
149 void cpExtensions::Interaction::SeedWidget::
151 void* data, const TBaseStyle::ButtonID& button,
152 int* idx, double* pos, bool alt, bool ctr, bool sft
155 Self::AddPointAction( reinterpret_cast< vtkAbstractWidget* >( data ) );