]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkInteractorStyleSphere.cxx
e57cb6537789f955948137da8bb5835e127c04ca
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / vtkInteractorStyleSphere.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26
27 #include "vtkInteractorStyleSphere.h"
28
29 #include "wxSphereView.h"
30
31 vtkInteractorStyleSphere::vtkInteractorStyleSphere()
32 {
33         _stateRadio  = false;
34         _stateRotate = false;
35 }
36
37 //---------------------------------------------------------------------------
38
39 vtkInteractorStyleSphere::~vtkInteractorStyleSphere()
40 {
41 }
42
43
44 //---------------------------------------------------------------------------
45
46 bool  vtkInteractorStyleSphere::OnRightButtonDown()
47 {
48         if ((_vtkInteractorStyleBaseView->GetInteractor()->GetControlKey()==0) && (_vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey()==0) )
49         {
50                 _stateRadio     = true;
51                 //_fordwareX    = this->Interactor->GetEventPosition()[0];
52                 _fordwareY      = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[1];
53
54                 wxSphereView *wxsphereview = (wxSphereView*)(_vtkInteractorStyleBaseView->GetWxVtk2DBaseView());
55
56                 _radio = wxsphereview->GetRadio();
57         }
58
59         return true;
60 }
61
62 //---------------------------------------------------------------------------
63
64 bool  vtkInteractorStyleSphere::OnRightButtonUp() 
65 {
66         if (_stateRadio==true)
67         {
68                 wxSphereView *wxsphereview = (wxSphereView*)(_vtkInteractorStyleBaseView->GetWxVtk2DBaseView());
69                 wxsphereview->SetDeltaVoxel(1);
70                 double radio=wxsphereview->GetRadio();
71                 wxsphereview->GetIdOfImage(radio+0.1);
72                 wxsphereview->GetIdOfImage(radio+0.2);
73                 wxsphereview->GetIdOfImage(radio-0.1);
74                 wxsphereview->GetIdOfImage(radio-0.2);
75
76                 wxsphereview->RefreshView();
77                 _stateRadio = false;
78         }
79
80         return true;
81 }
82 //---------------------------------------------------------------------------
83
84 bool vtkInteractorStyleSphere::OnLeftButtonDown()
85 {
86         _stateRotate    = true;
87         _fordwareX              = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[0];
88         _fordwareY              = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[1];
89         return true;
90 }
91
92
93 //---------------------------------------------------------------------------
94
95 bool  vtkInteractorStyleSphere::OnLeftButtonUp() 
96 {
97         wxSphereView *wxsphereview = (wxSphereView*)(_vtkInteractorStyleBaseView->GetWxVtk2DBaseView());
98         if (_stateRotate==true){
99                 int fx  = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[0];
100                 int fy  = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[1];
101
102                 if ((_fordwareX==fx)&&(_fordwareY==fy)){
103                         double x=fx,y=fy,z=1;
104                         _vtkInteractorStyleBaseView->TransformCoordinate(x,y,z);            
105                         wxsphereview->SetXYZtoParent(x,y);
106                         wxCommandEvent newevent(wxEVT_COMMAND_MENU_SELECTED,12121);
107                         wxsphereview->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent);
108                 } else {
109                         wxsphereview->RotationEnd();
110                 }
111                 wxsphereview->RefreshView();
112                 _stateRotate = false;
113         }
114
115         return true;
116 }
117
118
119 //---------------------------------------------------------------------------
120
121 bool  vtkInteractorStyleSphere::OnMouseMove () 
122 {
123         wxSphereView *wxsphereview = (wxSphereView*)(_vtkInteractorStyleBaseView->GetWxVtk2DBaseView());
124         if (_stateRotate==true)
125         {
126                 bool ok_v, ok_ang;
127                 ok_v=false;
128                 ok_ang=false;
129                 if (_vtkInteractorStyleBaseView->GetInteractor()->GetControlKey()==1)
130                 {
131                         ok_v = true;
132                 }
133                 if (_vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey()==1)
134                 {
135                         ok_ang = true;
136                 }
137             int fx = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[0];
138         int fy = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[1];
139                 wxsphereview->RotationStart( fx - _fordwareX , -(fy - _fordwareY) , ok_v, ok_ang);
140                 wxsphereview->RefreshView();
141         } 
142         if (_stateRadio==true)
143         {           
144                 //int fx = this->Interactor->GetEventPosition()[0];
145         int fy = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[1];
146                 double dif=(fy-_fordwareY) / 10.0;
147                 wxsphereview->SetRadio( _radio + dif );
148                 wxsphereview->SetDeltaVoxel(3);
149                 wxsphereview->RefreshView();
150         }
151
152         return true;
153 }