]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GBlackBoxController.cxx
0480ece566d47accda9b61f7b89d4adfdac314e5
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsVtkGUIEditorGraphic / GBlackBoxController.cxx
1 /*=========================================================================
2 Program:   bbtk
3 Module:    $RCSfile$
4 Language:  C++
5 Date:      $Date$
6 Version:   $Revision$
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and
15 *  abiding by the rules of distribution of free software. You can  use,
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B
17 *  license as circulated by CEA, CNRS and INRIA at the following URL
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability.
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
30
31 /**
32 *  \file
33 *  \brief Class bbtk::GBlackBoxController
34 */
35
36
37 #include "GBlackBoxController.h"
38
39 namespace bbtk
40 {
41
42
43         //=========================================================================
44         GBlackBoxController::GBlackBoxController()
45         {
46
47         }
48
49         //=========================================================================
50         GBlackBoxController::~GBlackBoxController()
51         {
52         }
53         //=========================================================================
54
55         bool GBlackBoxController::OnMouseMove()
56         {
57
58                 if ( _vtkInteractorStyleBaseView!=NULL)
59                 {
60                         int X,Y;
61                         wxVTKRenderWindowInteractor *_wxVTKiren;
62                         _wxVTKiren= _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
63                         _wxVTKiren->GetEventPosition( X , Y );
64
65                         int state  = _view->getState();
66
67                         //Evaluate new state
68
69                         if(state == NOTHING_HAPPENS)
70                         {
71                                 if(_view->isPointInside(X,Y))
72                                 {
73                                         _view->setState(HIGHLIGHTED);
74                                 }
75                         } // state
76
77                         if( state==HIGHLIGHTED)
78                         {
79                                 if(!_view->isPointInside(X,Y))
80                                 {
81                                         _view->setState(NOTHING_HAPPENS);
82                                 }
83                         } // state
84
85
86                         if ((state==DRAG) && (_isLeftClickDown==true) )
87                         {
88                             _objHasBeenMoved=true;
89                         } // state
90
91                         _model->notifyObservers(getId());
92
93                 }
94                 return true;
95         }
96
97         //=========================================================================
98
99         bool GBlackBoxController::OnLeftButtonDown()
100         {
101                 _objHasBeenMoved = false;
102                 _isLeftClickDown = true;
103         bool ok=true;
104                 
105                 int X,Y;
106                 wxVTKRenderWindowInteractor *_wxVTKiren;
107                 _wxVTKiren= _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
108                 _wxVTKiren->GetEventPosition( X , Y );
109                 
110                 
111                 
112                 int state  = _view->getState();
113                 //Evaluate new state
114                 
115                 if(_view->isPointInside(X,Y))
116                 
117 //              if(state == HIGHLIGHTED)
118 //EED3oct2010           if ( (state == HIGHLIGHTED) && (ctrlkey==1  ) )
119                 {
120                     ok=false;
121                         _view->setState(SELECTED);
122                         _model->notifyObservers(getId(),ADD_TO_SELECTED);
123                 }
124                 
125       
126                 int shiftkey            = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
127                 int ctrlkey             = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
128                 ctrlkey = ctrlkey + shiftkey;
129                 
130                 
131                 if ( (state==DRAG) && (ctrlkey==1) &&  (_view->isPointInside(X,Y)==true) )
132                 {
133                         _view->setState(NOTHING_HAPPENS);
134                         _model->notifyObservers(getId(),REMOVE_FROM_SELECTED);
135                 }
136
137                 return ok;
138         }
139
140         //=========================================================================
141
142         bool GBlackBoxController::OnLeftButtonUp()
143         {
144         _isLeftClickDown    = false;
145                 int state           = _view->getState();
146
147                 //Evaluate new state
148
149 //EED Borrame
150 //              int X,Y;
151 //              wxVTKRenderWindowInteractor *wxVTKiren;
152 //              wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
153 //              wxVTKiren->GetEventPosition(X,Y);
154 //              if(_isLeftClickDown)
155 //              {
156 //                      _isLeftClickDown=false;
157 //                      if(_view->isPointInside(X,Y))
158 //                      {
159                                 // It is supposed that I'm always inside even if the box is in drag
160 //                              _view->setState(SELECTED);
161 //                              _model->notifyObservers(getId());
162 //                      }
163 //              }
164
165
166
167                 int shiftkey            = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
168                 int ctrlkey             = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
169                 ctrlkey = ctrlkey + shiftkey;
170                 
171                 
172                 if ( (state==SELECTED) && (ctrlkey==0) && (_objHasBeenMoved==false))
173                 {
174                         _view->setState(NOTHING_HAPPENS);
175                         _model->notifyObservers(getId(),REMOVE_FROM_SELECTED);
176                 }
177
178
179
180                 return true;
181
182         }
183
184         //=========================================================================
185
186         bool GBlackBoxController::OnRightButtonUp()
187         {
188                 return true;
189         }
190
191         //=========================================================================
192
193         bool GBlackBoxController::OnMiddleButtonDown()
194         {
195                 int X,Y;
196                 wxVTKRenderWindowInteractor *wxVTKiren;
197                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
198                 wxVTKiren->GetEventPosition(X,Y);
199
200 //              int state  = _view->getState();
201
202                 //Evaluate new state
203                 if(_view->isPointInside(X,Y))
204                 {
205                         GBlackBoxModel *bbmodel = (GBlackBoxModel*)_model;
206                         _view->setState(HIGHLIGHTED);
207                         if(bbmodel->isExecutable())
208                         {
209                                 bbmodel->setExecutable(false);
210                         }
211                         else
212                         {
213                                 bbmodel->setExecutable(true);
214                         }
215                         bbmodel->notifyObservers(getId());
216                 }
217
218                 return true;
219         }
220
221         //=========================================================================
222
223 }  // EO namespace bbtk
224
225 // EOF
226