]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GBlackBoxController.cxx
99c7d07bef0bc8fb3a6a7387d35b5aaf8e3cff19
[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                 if(state == SELECTED)
125                 {
126                         _view->setState(NOTHING_HAPPENS);
127                         _model->notifyObservers(getId(),REMOVE_FROM_SELECTED);
128                 } else {
129                     ok=false;
130                         _view->setState(SELECTED);
131                         _model->notifyObservers(getId(),ADD_TO_SELECTED);
132                 }
133                 
134                 
135                 int shiftkey            = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
136                 int ctrlkey             = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
137                 ctrlkey = ctrlkey + shiftkey;
138                 
139                 
140                 if ( (state==DRAG) && (ctrlkey==1) &&  (_view->isPointInside(X,Y)==true) )
141                 {
142                         _view->setState(NOTHING_HAPPENS);
143                         _model->notifyObservers(getId(),REMOVE_FROM_SELECTED);
144                 }
145
146                 return ok;
147         }
148
149         //=========================================================================
150
151         bool GBlackBoxController::OnLeftButtonUp()
152         {
153         _isLeftClickDown    = false;
154                 int state           = _view->getState();
155
156                 //Evaluate new state
157
158 //EED Borrame
159 //              int X,Y;
160 //              wxVTKRenderWindowInteractor *wxVTKiren;
161 //              wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
162 //              wxVTKiren->GetEventPosition(X,Y);
163 //              if(_isLeftClickDown)
164 //              {
165 //                      _isLeftClickDown=false;
166 //                      if(_view->isPointInside(X,Y))
167 //                      {
168                                 // It is supposed that I'm always inside even if the box is in drag
169 //                              _view->setState(SELECTED);
170 //                              _model->notifyObservers(getId());
171 //                      }
172 //              }
173
174
175
176                 int shiftkey            = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
177                 int ctrlkey             = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
178                 ctrlkey = ctrlkey + shiftkey;
179                 
180                 
181 //EED 12/07/2012                
182 //              if ( (state==SELECTED) && (ctrlkey==0) && (_objHasBeenMoved==false))
183 //              {
184 //                      _view->setState(NOTHING_HAPPENS);
185 //                      _model->notifyObservers(getId(),REMOVE_FROM_SELECTED);
186 //              }
187
188
189
190                 return true;
191
192         }
193
194         //=========================================================================
195
196         bool GBlackBoxController::OnRightButtonUp()
197         {
198                 return true;
199         }
200
201         //=========================================================================
202
203         bool GBlackBoxController::OnMiddleButtonDown()
204         {
205                 int X,Y;
206                 wxVTKRenderWindowInteractor *wxVTKiren;
207                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
208                 wxVTKiren->GetEventPosition(X,Y);
209
210 //              int state  = _view->getState();
211
212                 //Evaluate new state
213                 if(_view->isPointInside(X,Y))
214                 {
215                         GBlackBoxModel *bbmodel = (GBlackBoxModel*)_model;
216                         _view->setState(HIGHLIGHTED);
217                         if(bbmodel->isExecutable())
218                         {
219                                 bbmodel->setExecutable(false);
220                         }
221                         else
222                         {
223                                 bbmodel->setExecutable(true);
224                         }
225                         bbmodel->notifyObservers(getId());
226                 }
227
228                 return true;
229         }
230
231         //=========================================================================
232
233 }  // EO namespace bbtk
234
235 // EOF
236