]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GBlackBoxController.cxx
1497 BUG
[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 #ifdef _DEBUG
40 #define new DEBUG_NEW
41 #endif
42 namespace bbtk
43 {
44
45
46         //=========================================================================
47         GBlackBoxController::GBlackBoxController()
48         {
49
50         }
51
52         //=========================================================================
53         GBlackBoxController::~GBlackBoxController()
54         {
55         }
56         //=========================================================================
57
58         bool GBlackBoxController::OnMouseMove()
59         {
60
61                 if ( _vtkInteractorStyleBaseView!=NULL)
62                 {
63                         int X,Y;
64                         wxVTKRenderWindowInteractor *_wxVTKiren;
65                         _wxVTKiren= _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
66                         _wxVTKiren->GetEventPosition( X , Y );
67
68                         int state  = _view->getState();
69
70                         //Evaluate new state
71
72                         if(state == NOTHING_HAPPENS)
73                         {
74                                 if(_view->isPointInside(X,Y))
75                                 {
76                                         _view->setState(HIGHLIGHTED);
77                                 }
78                                                 return true; // to avoid to redraw all if nothing
79                         } // state
80
81                         if( state==HIGHLIGHTED)
82                         {
83                                 if(!_view->isPointInside(X,Y))
84                                 {
85                                         _view->setState(NOTHING_HAPPENS);
86                                 }
87                         } // state
88
89
90                         if ((state==DRAG) && (_isLeftClickDown==true) )
91                         {
92                             _objHasBeenMoved=true;
93                         } // state
94
95                         _model->notifyObservers(getId());
96
97                 }
98                 return true;
99         }
100
101         //=========================================================================
102
103         bool GBlackBoxController::OnLeftButtonDown()
104         {
105                 _objHasBeenMoved = false;
106                 _isLeftClickDown = true;
107         bool ok=true;
108                 
109                 int X,Y;
110                 wxVTKRenderWindowInteractor *_wxVTKiren;
111                 _wxVTKiren= _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
112                 _wxVTKiren->GetEventPosition( X , Y );
113                 
114                 
115                 
116                 int state  = _view->getState();
117                 //Evaluate new state
118                 
119                 if(_view->isPointInside(X,Y))
120                 
121 //              if(state == HIGHLIGHTED)
122 //EED3oct2010           if ( (state == HIGHLIGHTED) && (ctrlkey==1  ) )
123                 {
124                     ok=false;
125                         _view->setState(SELECTED);
126                         _model->notifyObservers(getId(),ADD_TO_SELECTED);
127                 }
128                 
129       
130                 int shiftkey            = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
131                 int ctrlkey             = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
132                 ctrlkey = ctrlkey + shiftkey;
133                 
134                 
135                 if ( (state==DRAG) && (ctrlkey==1) &&  (_view->isPointInside(X,Y)==true) )
136                 {
137                         _view->setState(NOTHING_HAPPENS);
138                         _model->notifyObservers(getId(),REMOVE_FROM_SELECTED);
139                 }
140
141                 return ok;
142         }
143
144         //=========================================================================
145
146         bool GBlackBoxController::OnLeftButtonUp()
147         {
148         _isLeftClickDown    = false;
149                 int state           = _view->getState();
150
151                 //Evaluate new state
152
153 //EED Borrame
154 //              int X,Y;
155 //              wxVTKRenderWindowInteractor *wxVTKiren;
156 //              wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
157 //              wxVTKiren->GetEventPosition(X,Y);
158 //              if(_isLeftClickDown)
159 //              {
160 //                      _isLeftClickDown=false;
161 //                      if(_view->isPointInside(X,Y))
162 //                      {
163                                 // It is supposed that I'm always inside even if the box is in drag
164 //                              _view->setState(SELECTED);
165 //                              _model->notifyObservers(getId());
166 //                      }
167 //              }
168
169
170
171                 int shiftkey            = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
172                 int ctrlkey             = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
173                 ctrlkey = ctrlkey + shiftkey;
174                 
175                 
176                 if ( (state==SELECTED) && (ctrlkey==0) && (_objHasBeenMoved==false))
177                 {
178                         _view->setState(NOTHING_HAPPENS);
179                         _model->notifyObservers(getId(),REMOVE_FROM_SELECTED);
180                 }
181
182
183
184                 return true;
185
186         }
187
188         //=========================================================================
189
190         bool GBlackBoxController::OnRightButtonUp()
191         {
192                 return true;
193         }
194
195         //=========================================================================
196
197         bool GBlackBoxController::OnMiddleButtonDown()
198         {
199                 int X,Y;
200                 wxVTKRenderWindowInteractor *wxVTKiren;
201                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
202                 wxVTKiren->GetEventPosition(X,Y);
203
204 //              int state  = _view->getState();
205
206                 //Evaluate new state
207                 if(_view->isPointInside(X,Y))
208                 {
209                         GBlackBoxModel *bbmodel = (GBlackBoxModel*)_model;
210                         _view->setState(HIGHLIGHTED);
211                         if(bbmodel->isExecutable())
212                         {
213                                 bbmodel->setExecutable(false);
214                         }
215                         else
216                         {
217                                 bbmodel->setExecutable(true);
218                         }
219                         bbmodel->notifyObservers(getId());
220                 }
221
222                 return true;
223         }
224
225         //=========================================================================
226
227 }  // EO namespace bbtk
228
229 // EOF
230