]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Interaction/BaseInteractorStyle.cxx
Minor refactoring and errors solved
[cpPlugins.git] / lib / cpExtensions / Interaction / BaseInteractorStyle.cxx
1 #include <cpExtensions/Interaction/BaseInteractorStyle.h>
2
3 #include <cmath>
4
5 #include <vtkCallbackCommand.h>
6 #include <vtkCamera.h>
7 #include <vtkRenderer.h>
8 #include <vtkRenderWindowInteractor.h>
9
10 // -------------------------------------------------------------------------
11 long cpExtensions::Interaction::BaseInteractorStyle::_TMouseButtonEvent::
12 MaxDoubleClick = 350; // ms
13
14 // -------------------------------------------------------------------------
15 void cpExtensions::Interaction::BaseInteractorStyle::
16 SetSetDoubleClickDelay( long delay )
17 {
18   Self::_TMouseButtonEvent::MaxDoubleClick = delay;
19 }
20
21 // -------------------------------------------------------------------------
22 void cpExtensions::Interaction::BaseInteractorStyle::
23 AddMouseMoveCommand( TMouseCommand command, void* data )
24 {
25   if( command != NULL )
26   {
27     this->m_MouseMoveCommands[ command ] = data;
28     this->Modified( );
29
30   } // fi
31 }
32
33 // -------------------------------------------------------------------------
34 void cpExtensions::Interaction::BaseInteractorStyle::
35 AddMouseClickCommand( TMouseCommand command, void* data )
36 {
37   if( command != NULL )
38   {
39     this->m_MouseClickCommands[ command ] = data;
40     this->Modified( );
41
42   } // fi
43 }
44
45 // -------------------------------------------------------------------------
46 void cpExtensions::Interaction::BaseInteractorStyle::
47 AddMouseDoubleClickCommand( TMouseCommand command, void* data )
48 {
49   if( command != NULL )
50   {
51     this->m_MouseDoubleClickCommands[ command ] = data;
52     this->Modified( );
53
54   } // fi
55 }
56
57 // -------------------------------------------------------------------------
58 void cpExtensions::Interaction::BaseInteractorStyle::
59 AddMouseWheelCommand( TMouseWheelCommand command, void* data )
60 {
61   if( command != NULL )
62   {
63     this->m_MouseWheelCommands[ command ] = data;
64     this->Modified( );
65
66   } // fi
67 }
68
69 // -------------------------------------------------------------------------
70 void cpExtensions::Interaction::BaseInteractorStyle::
71 AddKeyCommand( TKeyCommand command, void* data )
72 {
73   if( command != NULL )
74   {
75     this->m_KeyCommands[ command ] = data;
76     this->Modified( );
77
78   } // fi
79 }
80
81 // -------------------------------------------------------------------------
82 void cpExtensions::Interaction::BaseInteractorStyle::
83 AddExposeCommand( TVoidCommand command, void* data )
84 {
85   if( command != NULL )
86   {
87     this->m_ExposeCommands[ command ] = data;
88     this->Modified( );
89
90   } // fi
91 }
92
93 // -------------------------------------------------------------------------
94 void cpExtensions::Interaction::BaseInteractorStyle::
95 AddConfigureCommand( TVoidCommand command, void* data )
96 {
97   if( command != NULL )
98   {
99     this->m_ConfigureCommands[ command ] = data;
100     this->Modified( );
101
102   } // fi
103 }
104
105 // -------------------------------------------------------------------------
106 void cpExtensions::Interaction::BaseInteractorStyle::
107 AddEnterCommand( TVoidCommand command, void* data )
108 {
109   if( command != NULL )
110   {
111     this->m_EnterCommands[ command ] = data;
112     this->Modified( );
113
114   } // fi
115 }
116
117 // -------------------------------------------------------------------------
118 void cpExtensions::Interaction::BaseInteractorStyle::
119 AddLeaveCommand( TVoidCommand command, void* data )
120 {
121   if( command != NULL )
122   {
123     this->m_LeaveCommands[ command ] = data;
124     this->Modified( );
125
126   } // fi
127 }
128
129 // -------------------------------------------------------------------------
130 void cpExtensions::Interaction::BaseInteractorStyle::
131 RemoveMouseMoveCommand( TMouseCommand command )
132 {
133   auto i = this->m_MouseMoveCommands.find( command );
134   if( i != this->m_MouseMoveCommands.end( ) )
135   {
136     this->m_MouseMoveCommands.erase( i );
137     this->Modified( );
138
139   } // fi
140 }
141
142 // -------------------------------------------------------------------------
143 void cpExtensions::Interaction::BaseInteractorStyle::
144 RemoveMouseClickCommand( TMouseCommand command )
145 {
146   auto i = this->m_MouseClickCommands.find( command );
147   if( i != this->m_MouseClickCommands.end( ) )
148   {
149     this->m_MouseClickCommands.erase( i );
150     this->Modified( );
151
152   } // fi
153 }
154
155 // -------------------------------------------------------------------------
156 void cpExtensions::Interaction::BaseInteractorStyle::
157 RemoveMouseDoubleClickCommand( TMouseCommand command )
158 {
159   auto i = this->m_MouseDoubleClickCommands.find( command );
160   if( i != this->m_MouseDoubleClickCommands.end( ) )
161   {
162     this->m_MouseDoubleClickCommands.erase( i );
163     this->Modified( );
164
165   } // fi
166 }
167
168 // -------------------------------------------------------------------------
169 void cpExtensions::Interaction::BaseInteractorStyle::
170 RemoveMouseWheelCommand( TMouseWheelCommand command )
171 {
172   auto i = this->m_MouseWheelCommands.find( command );
173   if( i != this->m_MouseWheelCommands.end( ) )
174   {
175     this->m_MouseWheelCommands.erase( i );
176     this->Modified( );
177
178   } // fi
179 }
180
181 // -------------------------------------------------------------------------
182 void cpExtensions::Interaction::BaseInteractorStyle::
183 RemoveKeyCommand( TKeyCommand command )
184 {
185   auto i = this->m_KeyCommands.find( command );
186   if( i != this->m_KeyCommands.end( ) )
187   {
188     this->m_KeyCommands.erase( i );
189     this->Modified( );
190
191   } // fi
192 }
193
194 // -------------------------------------------------------------------------
195 void cpExtensions::Interaction::BaseInteractorStyle::
196 RemoveExposeCommand( TVoidCommand command )
197 {
198   auto i = this->m_ExposeCommands.find( command );
199   if( i != this->m_ExposeCommands.end( ) )
200   {
201     this->m_ExposeCommands.erase( i );
202     this->Modified( );
203
204   } // fi
205 }
206
207 // -------------------------------------------------------------------------
208 void cpExtensions::Interaction::BaseInteractorStyle::
209 RemoveConfigureCommand( TVoidCommand command )
210 {
211   auto i = this->m_ConfigureCommands.find( command );
212   if( i != this->m_ConfigureCommands.end( ) )
213   {
214     this->m_ConfigureCommands.erase( i );
215     this->Modified( );
216
217   } // fi
218 }
219
220 // -------------------------------------------------------------------------
221 void cpExtensions::Interaction::BaseInteractorStyle::
222 RemoveEnterCommand( TVoidCommand command )
223 {
224   auto i = this->m_EnterCommands.find( command );
225   if( i != this->m_EnterCommands.end( ) )
226   {
227     this->m_EnterCommands.erase( i );
228     this->Modified( );
229
230   } // fi
231 }
232
233 // -------------------------------------------------------------------------
234 void cpExtensions::Interaction::BaseInteractorStyle::
235 RemoveLeaveCommand( TVoidCommand command )
236 {
237   auto i = this->m_LeaveCommands.find( command );
238   if( i != this->m_LeaveCommands.end( ) )
239   {
240     this->m_LeaveCommands.erase( i );
241     this->Modified( );
242
243   } // fi
244 }
245
246 // -------------------------------------------------------------------------
247 void cpExtensions::Interaction::BaseInteractorStyle::
248 DelegateTDxEvent( unsigned long event, void* calldata )
249 {
250   // TODO
251   std::cerr << "No TDx support at this time!" << std::endl;
252   std::exit( 1 );
253 }
254
255 // -------------------------------------------------------------------------
256 void cpExtensions::Interaction::BaseInteractorStyle::
257 OnMouseMove( )
258 {
259   // Get current position on the associated actors
260   vtkRenderWindowInteractor* rwi = this->GetInteractor( );
261   if( rwi == NULL )
262     return;
263
264   // Get modifiers
265   bool alt = ( rwi->GetAltKey( ) == 1 );
266   bool ctr = ( rwi->GetControlKey( ) == 1 );
267   bool sft = ( rwi->GetShiftKey( ) == 1 );
268   ButtonID button = this->GetButtonID( );
269
270   // Invoke possible generic events
271   if( button == Self::ButtonID_Right )
272   {
273     if( !alt && !ctr && !sft )
274     {
275       this->FindPokedRenderer(
276         rwi->GetEventPosition( )[ 0 ],
277         rwi->GetEventPosition( )[ 1 ]
278         );
279       this->Dolly( );
280
281     } // fi
282   }
283   else if( button == Self::ButtonID_Middle )
284   {
285     if( !alt && !ctr && !sft )
286     {
287       this->FindPokedRenderer(
288         rwi->GetEventPosition( )[ 0 ],
289         rwi->GetEventPosition( )[ 1 ]
290         );
291       this->Pan( );
292
293     } // fi
294
295   } // fi
296
297   // Get mouse pointer position
298   static int idx[ 2 ];
299   static double pos[ 3 ];
300   if( !( this->_PickPosition( idx, pos ) ) )
301     return;
302
303   // Invoke possible specialized events
304   auto i = this->m_MouseMoveCommands.begin( );
305   for( ; i != this->m_MouseMoveCommands.end( ); ++i )
306     i->first( i->second, button, idx, pos, alt, ctr, sft );
307 }
308
309 // -------------------------------------------------------------------------
310 void cpExtensions::Interaction::BaseInteractorStyle::
311 OnMouseWheelForward( )
312 {
313   vtkRenderWindowInteractor* rwi = this->GetInteractor( );
314   if( rwi == NULL )
315     return;
316
317   // Invoke possible events
318   auto i = this->m_MouseWheelCommands.begin( );
319   for( ; i != this->m_MouseWheelCommands.end( ); ++i )
320     i->first(
321       i->second, 1,
322       rwi->GetAltKey( ) == 1,
323       rwi->GetControlKey( ) == 1,
324       rwi->GetShiftKey( ) == 1
325       );
326 }
327
328 // -------------------------------------------------------------------------
329 void cpExtensions::Interaction::BaseInteractorStyle::
330 OnMouseWheelBackward( )
331 {
332   vtkRenderWindowInteractor* rwi = this->GetInteractor( );
333   if( rwi == NULL )
334     return;
335
336   // Invoke possible events
337   auto i = this->m_MouseWheelCommands.begin( );
338   for( ; i != this->m_MouseWheelCommands.end( ); ++i )
339     i->first(
340       i->second, -1,
341       rwi->GetAltKey( ) == 1,
342       rwi->GetControlKey( ) == 1,
343       rwi->GetShiftKey( ) == 1
344       );
345 }
346
347 // -------------------------------------------------------------------------
348 void cpExtensions::Interaction::BaseInteractorStyle::
349 OnLeftButtonDown( )
350 {
351   this->m_ActiveButton = Self::ButtonID_Left;
352 }
353
354 // -------------------------------------------------------------------------
355 void cpExtensions::Interaction::BaseInteractorStyle::
356 OnLeftButtonUp( )
357 {
358   this->m_ActiveButton = Self::ButtonID_None;
359 }
360
361 // -------------------------------------------------------------------------
362 void cpExtensions::Interaction::BaseInteractorStyle::
363 OnMiddleButtonDown( )
364 {
365   this->m_ActiveButton = Self::ButtonID_Middle;
366
367   // Get current position on the associated actors
368   vtkRenderWindowInteractor* rwi = this->GetInteractor( );
369   if( rwi == NULL )
370     return;
371
372   // Get modifiers
373   bool alt = ( rwi->GetAltKey( ) == 1 );
374   bool ctr = ( rwi->GetControlKey( ) == 1 );
375   bool sft = ( rwi->GetShiftKey( ) == 1 );
376
377   if( !alt && !ctr && !sft )
378     this->StartPan( );
379 }
380
381 // -------------------------------------------------------------------------
382 void cpExtensions::Interaction::BaseInteractorStyle::
383 OnMiddleButtonUp( )
384 {
385   this->m_ActiveButton = Self::ButtonID_None;
386
387   // Get current position on the associated actors
388   vtkRenderWindowInteractor* rwi = this->GetInteractor( );
389   if( rwi == NULL )
390     return;
391
392   // Get modifiers
393   bool alt = ( rwi->GetAltKey( ) == 1 );
394   bool ctr = ( rwi->GetControlKey( ) == 1 );
395   bool sft = ( rwi->GetShiftKey( ) == 1 );
396
397   switch( this->State )
398   {
399   case VTKIS_PAN:
400     this->EndPan( );
401     break;
402   default:
403     break;
404   } // hctiws
405 }
406
407 // -------------------------------------------------------------------------
408 void cpExtensions::Interaction::BaseInteractorStyle::
409 OnRightButtonDown( )
410 {
411   this->m_ActiveButton = Self::ButtonID_Right;
412
413   // Get current position on the associated actors
414   vtkRenderWindowInteractor* rwi = this->GetInteractor( );
415   if( rwi == NULL )
416     return;
417
418   // Get modifiers
419   bool alt = ( rwi->GetAltKey( ) == 1 );
420   bool ctr = ( rwi->GetControlKey( ) == 1 );
421   bool sft = ( rwi->GetShiftKey( ) == 1 );
422
423   if( !alt && !ctr && !sft )
424     this->StartDolly( );
425 }
426
427 // -------------------------------------------------------------------------
428 void cpExtensions::Interaction::BaseInteractorStyle::
429 OnRightButtonUp( )
430 {
431   this->m_ActiveButton = Self::ButtonID_None;
432
433   // Get current position on the associated actors
434   vtkRenderWindowInteractor* rwi = this->GetInteractor( );
435   if( rwi == NULL )
436     return;
437
438   // Get modifiers
439   bool alt = ( rwi->GetAltKey( ) == 1 );
440   bool ctr = ( rwi->GetControlKey( ) == 1 );
441   bool sft = ( rwi->GetShiftKey( ) == 1 );
442
443   switch( this->State )
444   {
445   case VTKIS_DOLLY:
446     this->EndDolly( );
447     break;
448   default:
449     break;
450   } // hctiws
451 }
452
453 // -------------------------------------------------------------------------
454 void cpExtensions::Interaction::BaseInteractorStyle::
455 OnLeftClick( )
456 {
457   // Get current position on the associated actors
458   vtkRenderWindowInteractor* rwi = this->GetInteractor( );
459   if( rwi == NULL )
460     return;
461
462   // Get mouse pointer position
463   static int idx[ 2 ];
464   static double pos[ 3 ];
465   if( !( this->_PickPosition( idx, pos ) ) )
466     return;
467
468   // Invoke possible events
469   auto i = this->m_MouseClickCommands.begin( );
470   for( ; i != this->m_MouseClickCommands.end( ); ++i )
471     i->first(
472       i->second,
473       Self::ButtonID_Left,
474       idx, pos,
475       rwi->GetAltKey( ) == 1,
476       rwi->GetControlKey( ) == 1,
477       rwi->GetShiftKey( ) == 1
478       );
479 }
480
481 // -------------------------------------------------------------------------
482 void cpExtensions::Interaction::BaseInteractorStyle::
483 OnLeftDoubleClick( )
484 {
485   // Get current position on the associated actors
486   vtkRenderWindowInteractor* rwi = this->GetInteractor( );
487   if( rwi == NULL )
488     return;
489
490   // Get mouse pointer position
491   static int idx[ 2 ];
492   static double pos[ 3 ];
493   if( !( this->_PickPosition( idx, pos ) ) )
494     return;
495
496   // Invoke possible events
497   auto i = this->m_MouseDoubleClickCommands.begin( );
498   for( ; i != this->m_MouseDoubleClickCommands.end( ); ++i )
499     i->first(
500       i->second,
501       Self::ButtonID_Left,
502       idx, pos,
503       rwi->GetAltKey( ) == 1,
504       rwi->GetControlKey( ) == 1,
505       rwi->GetShiftKey( ) == 1
506       );
507 }
508
509 // -------------------------------------------------------------------------
510 void cpExtensions::Interaction::BaseInteractorStyle::
511 OnMiddleClick( )
512 {
513   // Get current position on the associated actors
514   vtkRenderWindowInteractor* rwi = this->GetInteractor( );
515   if( rwi == NULL )
516     return;
517
518   // Get mouse pointer position
519   static int idx[ 2 ];
520   static double pos[ 3 ];
521   if( !( this->_PickPosition( idx, pos ) ) )
522     return;
523
524   // Invoke possible events
525   auto i = this->m_MouseClickCommands.begin( );
526   for( ; i != this->m_MouseClickCommands.end( ); ++i )
527     i->first(
528       i->second,
529       Self::ButtonID_Middle,
530       idx, pos,
531       rwi->GetAltKey( ) == 1,
532       rwi->GetControlKey( ) == 1,
533       rwi->GetShiftKey( ) == 1
534       );
535 }
536
537 // -------------------------------------------------------------------------
538 void cpExtensions::Interaction::BaseInteractorStyle::
539 OnMiddleDoubleClick( )
540 {
541   // Get current position on the associated actors
542   vtkRenderWindowInteractor* rwi = this->GetInteractor( );
543   if( rwi == NULL )
544     return;
545
546   // Get mouse pointer position
547   static int idx[ 2 ];
548   static double pos[ 3 ];
549   if( !( this->_PickPosition( idx, pos ) ) )
550     return;
551
552   // Invoke possible events
553   auto i = this->m_MouseDoubleClickCommands.begin( );
554   for( ; i != this->m_MouseDoubleClickCommands.end( ); ++i )
555     i->first(
556       i->second,
557       Self::ButtonID_Middle,
558       idx, pos,
559       rwi->GetAltKey( ) == 1,
560       rwi->GetControlKey( ) == 1,
561       rwi->GetShiftKey( ) == 1
562       );
563 }
564
565 // -------------------------------------------------------------------------
566 void cpExtensions::Interaction::BaseInteractorStyle::
567 OnRightClick( )
568 {
569   // Get current position on the associated actors
570   vtkRenderWindowInteractor* rwi = this->GetInteractor( );
571   if( rwi == NULL )
572     return;
573
574   // Get mouse pointer position
575   static int idx[ 2 ];
576   static double pos[ 3 ];
577   if( !( this->_PickPosition( idx, pos ) ) )
578     return;
579
580   // Invoke possible events
581   auto i = this->m_MouseClickCommands.begin( );
582   for( ; i != this->m_MouseClickCommands.end( ); ++i )
583     i->first(
584       i->second,
585       Self::ButtonID_Right,
586       idx, pos,
587       rwi->GetAltKey( ) == 1,
588       rwi->GetControlKey( ) == 1,
589       rwi->GetShiftKey( ) == 1
590       );
591 }
592
593 // -------------------------------------------------------------------------
594 void cpExtensions::Interaction::BaseInteractorStyle::
595 OnRightDoubleClick( )
596 {
597   // Get current position on the associated actors
598   vtkRenderWindowInteractor* rwi = this->GetInteractor( );
599   if( rwi == NULL )
600     return;
601
602   // Get mouse pointer position
603   static int idx[ 2 ];
604   static double pos[ 3 ];
605   if( !( this->_PickPosition( idx, pos ) ) )
606     return;
607
608   // Invoke possible events
609   auto i = this->m_MouseDoubleClickCommands.begin( );
610   for( ; i != this->m_MouseDoubleClickCommands.end( ); ++i )
611     i->first(
612       i->second,
613       Self::ButtonID_Right,
614       idx, pos,
615       rwi->GetAltKey( ) == 1,
616       rwi->GetControlKey( ) == 1,
617       rwi->GetShiftKey( ) == 1
618       );
619 }
620
621 // -------------------------------------------------------------------------
622 void cpExtensions::Interaction::BaseInteractorStyle::
623 OnChar( )
624 {
625   vtkRenderWindowInteractor* rwi = this->GetInteractor( );
626   if( rwi == NULL )
627     return;
628
629   // Invoke possible events
630   auto i = this->m_KeyCommands.begin( );
631   for( ; i != this->m_KeyCommands.end( ); ++i )
632     i->first( i->second, rwi->GetKeyCode( ) );
633 }
634
635 // -------------------------------------------------------------------------
636 void cpExtensions::Interaction::BaseInteractorStyle::
637 OnKeyDown( )
638 {
639 }
640
641 // -------------------------------------------------------------------------
642 void cpExtensions::Interaction::BaseInteractorStyle::
643 OnKeyUp( )
644 {
645 }
646
647 // -------------------------------------------------------------------------
648 void cpExtensions::Interaction::BaseInteractorStyle::
649 OnKeyPress( )
650 {
651 }
652
653 // -------------------------------------------------------------------------
654 void cpExtensions::Interaction::BaseInteractorStyle::
655 OnKeyRelease( )
656 {
657 }
658
659 // -------------------------------------------------------------------------
660 void cpExtensions::Interaction::BaseInteractorStyle::
661 OnExpose( )
662 {
663   vtkRenderWindowInteractor* rwi = this->GetInteractor( );
664   if( rwi == NULL )
665     return;
666
667   // Invoke possible events
668   auto i = this->m_ExposeCommands.begin( );
669   for( ; i != this->m_ExposeCommands.end( ); ++i )
670     i->first( i->second );
671 }
672
673 // -------------------------------------------------------------------------
674 void cpExtensions::Interaction::BaseInteractorStyle::
675 OnConfigure( )
676 {
677   vtkRenderWindowInteractor* rwi = this->GetInteractor( );
678   if( rwi == NULL )
679     return;
680
681   // Invoke possible events
682   auto i = this->m_ConfigureCommands.begin( );
683   for( ; i != this->m_ConfigureCommands.end( ); ++i )
684     i->first( i->second );
685 }
686
687 // -------------------------------------------------------------------------
688 void cpExtensions::Interaction::BaseInteractorStyle::
689 OnEnter( )
690 {
691   vtkRenderWindowInteractor* rwi = this->GetInteractor( );
692   if( rwi == NULL )
693     return;
694
695   // Invoke possible events
696   auto i = this->m_EnterCommands.begin( );
697   for( ; i != this->m_EnterCommands.end( ); ++i )
698     i->first( i->second );
699 }
700
701 // -------------------------------------------------------------------------
702 void cpExtensions::Interaction::BaseInteractorStyle::
703 OnLeave( )
704 {
705   vtkRenderWindowInteractor* rwi = this->GetInteractor( );
706   if( rwi == NULL )
707     return;
708
709   // Invoke possible events
710   auto i = this->m_LeaveCommands.begin( );
711   for( ; i != this->m_LeaveCommands.end( ); ++i )
712     i->first( i->second );
713 }
714
715 // -------------------------------------------------------------------------
716 void cpExtensions::Interaction::BaseInteractorStyle::
717 Dolly( )
718 {
719   if( this->CurrentRenderer == NULL )
720     return;
721
722   vtkRenderWindowInteractor* rwi = this->GetInteractor( );
723   double *center = this->CurrentRenderer->GetCenter( );
724   int dy = rwi->GetEventPosition( )[ 1 ] - rwi->GetLastEventPosition( )[ 1 ];
725   double dyf = this->m_MotionFactor * dy / center[ 1 ];
726   this->_Dolly( std::pow( 1.1, dyf ) );
727 }
728
729 // -------------------------------------------------------------------------
730 void cpExtensions::Interaction::BaseInteractorStyle::
731 Pan( )
732 {
733   if( this->CurrentRenderer == NULL )
734     return;
735
736   vtkRenderWindowInteractor* rwi = this->Interactor;
737   double viewFocus[ 4 ], focalDepth, viewPoint[ 3 ];
738   double newPickPoint[ 4 ], oldPickPoint[ 4 ], motionVector[ 3 ];
739
740   // Calculate the focal depth since we'll be using it a lot
741   vtkCamera* camera = this->CurrentRenderer->GetActiveCamera( );
742   camera->GetFocalPoint( viewFocus );
743   this->ComputeWorldToDisplay(
744     viewFocus[ 0 ], viewFocus[ 1 ], viewFocus[ 2 ], viewFocus
745     );
746   focalDepth = viewFocus[ 2 ];
747   this->ComputeDisplayToWorld(
748     rwi->GetEventPosition( )[ 0 ],
749     rwi->GetEventPosition( )[ 1 ],
750     focalDepth,
751     newPickPoint
752     );
753
754   // Has to recalc old mouse point since the viewport has moved,
755   // so can't move it outside the loop
756   this->ComputeDisplayToWorld(
757     rwi->GetLastEventPosition( )[ 0 ],
758     rwi->GetLastEventPosition( )[ 1 ],
759     focalDepth,
760     oldPickPoint
761     );
762
763   // Camera motion is reversed
764   motionVector[ 0 ] = oldPickPoint[ 0 ] - newPickPoint[ 0 ];
765   motionVector[ 1 ] = oldPickPoint[ 1 ] - newPickPoint[ 1 ];
766   motionVector[ 2 ] = oldPickPoint[ 2 ] - newPickPoint[ 2 ];
767
768   camera->GetFocalPoint( viewFocus );
769   camera->GetPosition( viewPoint );
770   camera->SetFocalPoint(
771     motionVector[ 0 ] + viewFocus[ 0 ],
772     motionVector[ 1 ] + viewFocus[ 1 ],
773     motionVector[ 2 ] + viewFocus[ 2 ]
774     );
775   camera->SetPosition(
776     motionVector[ 0 ] + viewPoint[ 0 ],
777     motionVector[ 1 ] + viewPoint[ 1 ],
778     motionVector[ 2 ] + viewPoint[ 2 ]
779     );
780   if( rwi->GetLightFollowCamera( ) )
781     this->CurrentRenderer->UpdateLightsGeometryToFollowCamera( );
782   rwi->Render( );
783 }
784
785 // -------------------------------------------------------------------------
786 cpExtensions::Interaction::BaseInteractorStyle::
787 BaseInteractorStyle( )
788   : Superclass( ),
789     m_MotionFactor( double( 10 ) )
790 {
791   this->m_LeftButtonEvent.Reset( );
792   this->m_MiddleButtonEvent.Reset( );
793   this->m_RightButtonEvent.Reset( );
794   this->m_ActiveButton = Self::ButtonID_None;
795
796   this->EventCallbackCommand->SetCallback( Self::_ProcessEvents );
797 }
798
799 // -------------------------------------------------------------------------
800 cpExtensions::Interaction::BaseInteractorStyle::
801 ~BaseInteractorStyle( )
802 {
803 }
804
805 // -------------------------------------------------------------------------
806 void cpExtensions::Interaction::BaseInteractorStyle::
807 _Dolly( double factor )
808 {
809   if( this->CurrentRenderer == NULL )
810     return;
811
812   vtkCamera* camera = this->CurrentRenderer->GetActiveCamera( );
813   if( camera->GetParallelProjection( ) == 0 )
814   {
815     camera->Dolly( factor );
816     if( this->AutoAdjustCameraClippingRange )
817       this->CurrentRenderer->ResetCameraClippingRange( );
818   }
819   else
820     camera->SetParallelScale( camera->GetParallelScale( ) / factor );
821   if( this->Interactor->GetLightFollowCamera( ) )
822     this->CurrentRenderer->UpdateLightsGeometryToFollowCamera( );
823   this->Interactor->Render( );
824 }
825
826 // -------------------------------------------------------------------------
827 void cpExtensions::Interaction::BaseInteractorStyle::
828 _ProcessEvents(
829   vtkObject* object,
830   unsigned long event,
831   void* clientdata,
832   void* calldata
833   )
834 {
835   // Get active style and interactor
836   Self* s = reinterpret_cast< Self* >( clientdata );
837   if( s == NULL )
838     return;
839
840   // Process events
841   switch( event )
842   {
843   case vtkCommand::MouseMoveEvent:
844   {
845     s->OnMouseMove( );
846   }
847   break;
848   case vtkCommand::LeftButtonPressEvent:
849   {
850     unsigned char nc = s->m_LeftButtonEvent.Clicks( );
851     if( nc == 2 )
852       s->OnLeftDoubleClick( );
853     else if( nc == 1 )
854       s->OnLeftClick( );
855     s->OnLeftButtonDown( );
856   }
857   break;
858   case vtkCommand::LeftButtonReleaseEvent:
859   {
860     s->m_LeftButtonEvent.Release( );
861     s->OnLeftButtonUp( );
862   }
863   break;
864   case vtkCommand::MiddleButtonPressEvent:
865   {
866     unsigned char nc = s->m_MiddleButtonEvent.Clicks( );
867     if( nc == 2 )
868       s->OnMiddleDoubleClick( );
869     else if( nc == 1 )
870       s->OnMiddleClick( );
871     s->OnMiddleButtonDown( );
872   }
873   break;
874   case vtkCommand::MiddleButtonReleaseEvent:
875   {
876     s->m_MiddleButtonEvent.Release( );
877     s->OnMiddleButtonUp( );
878   }
879   break;
880   case vtkCommand::RightButtonPressEvent:
881   {
882     unsigned char nc = s->m_RightButtonEvent.Clicks( );
883     if( nc == 2 )
884       s->OnRightDoubleClick( );
885     else if( nc == 1 )
886       s->OnRightClick( );
887     s->OnRightButtonDown( );
888   }
889   break;
890   case vtkCommand::RightButtonReleaseEvent:
891   {
892     s->m_RightButtonEvent.Release( );
893     s->OnRightButtonUp( );
894   }
895   break;
896   case vtkCommand::MouseWheelForwardEvent:
897   {
898     s->OnMouseWheelForward( );
899   }
900   break;
901   case vtkCommand::MouseWheelBackwardEvent:
902   {
903     s->OnMouseWheelBackward( );
904   }
905   break;
906   case vtkCommand::KeyPressEvent:
907   {
908     s->OnKeyDown( );
909     s->OnKeyPress( );
910   }
911   break;
912   case vtkCommand::KeyReleaseEvent:
913   {
914     s->OnKeyUp( );
915     s->OnKeyRelease( );
916   }
917   break;
918   case vtkCommand::CharEvent:
919   {
920     s->OnChar( );
921   }
922   break;
923   case vtkCommand::ExposeEvent:
924   {
925     s->OnExpose( );
926   }
927   break;
928   case vtkCommand::ConfigureEvent:
929   {
930     s->OnConfigure( );
931   }
932   break;
933   case vtkCommand::EnterEvent:
934   {
935     s->OnEnter( );
936   }
937   break;
938   case vtkCommand::LeaveEvent:
939   {
940     s->OnLeave( );
941   }
942   break;
943   case vtkCommand::TimerEvent:
944   {
945     // Do nothing
946   }
947   break;
948   case vtkCommand::DeleteEvent:
949   {
950     s->SetInteractor( 0 );
951   }
952   break;
953   case vtkCommand::TDxMotionEvent:
954   case vtkCommand::TDxButtonPressEvent:
955   case vtkCommand::TDxButtonReleaseEvent:
956   {
957     s->DelegateTDxEvent( event, calldata );
958   }
959   break;
960   default:
961     break;
962   } // hctiws
963 }
964
965 // eof - $RCSfile$