]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GObjectController.cxx
0dffa0ec1a4d4d929ca092bde21663c4445e8e50
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsVtkGUIEditorGraphic / GObjectController.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::GObjectController 
34 */
35
36
37 #include "GObjectController.h"
38
39 namespace bbtk
40 {
41
42
43         //=========================================================================
44         GObjectController::GObjectController()
45         {
46                 
47         }
48
49         //=========================================================================
50         
51         GObjectController::~GObjectController()
52         {
53         }
54
55         //=========================================================================
56
57         void GObjectController::setModelAndView(GObjectModel* model, vtkGObjectView* view)
58         {
59                 _model = model;
60                 _view = view;
61         }
62
63         //=========================================================================
64
65         bool GObjectController::OnMouseMove()
66         {
67                 
68                 /**********************   VIRTUAL *************************/
69
70                 if ( _vtkInteractorStyleBaseView!=NULL)
71                 {
72                         int X,Y;
73                         wxVTKRenderWindowInteractor *_wxVTKiren;
74                         _wxVTKiren= _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
75                         _wxVTKiren->GetEventPosition( X , Y );
76
77                         int state  = _view->getState();
78                         
79                         //Evaluate new state
80                         if(!_model->hasChanged() && state == DRAG)
81                         {
82                                 moveObject(X,Y);
83                                 _model->setChanged();
84                         }
85
86                         if(!_model->hasChanged() && state == NOTHING_HAPPENS)
87                         {
88                                 if(_view->isPointInside(X,Y))
89                                 {
90                                         _view->setState(HIGHLIGHTED);
91                                         _model->setChanged();                           
92                                 }                       
93                         }
94                         if(!_model->hasChanged() && state==HIGHLIGHTED)
95                         {
96                                 if(!_view->isPointInside(X,Y))
97                                 {
98                                         _view->setState(NOTHING_HAPPENS);
99                                         _model->setChanged();
100                                 }
101                         }
102                         
103                         _model->notifyObservers(_id);
104                         
105                 }
106
107                 /**/
108
109                 return true;
110         }
111
112         //=========================================================================
113         
114         bool GObjectController::OnLeftButtonDown()
115         {
116                 /**********************   VIRTUAL *************************
117                 
118                 if ( _vtkInteractorStyleBaseView!=NULL )
119                 {
120                         int X,Y;
121                         wxVTKRenderWindowInteractor *wxVTKiren;
122                         wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
123                         wxVTKiren->GetEventPosition(X,Y);
124
125                         int state  = _model->getState();
126                         
127                         //Evaluate new state
128                         if(!_model->hasChanged() && state==HIGHLIGHTED)
129                         {
130                                 _view->isStartDragging(true);
131                                 _model->setState(DRAG);
132                                 _model->setChanged();
133                         }
134
135                         if( !_model->hasChanged() && state == SELECTED)
136                         {
137                                 if(_view->isPointInside(X,Y))
138                                 {
139                                         _view->isStartDragging(true);
140                                         _model->setState(DRAG);
141                                         _model->setChanged();
142                                 }       
143                         }
144                         
145                         _model->notifyObservers();
146                 }
147
148                 */
149
150                 return true;
151         }
152
153         //=========================================================================
154         
155         bool GObjectController::OnLeftButtonUp()
156         {
157
158                 /**********************   VIRTUAL *************************
159
160                 if ( _vtkInteractorStyleBaseView!=NULL )
161                 {
162                         int X,Y;
163                         wxVTKRenderWindowInteractor *wxVTKiren;
164                         wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
165                         wxVTKiren->GetEventPosition(X,Y);
166
167                         int state  = _model->getState();
168                         
169                         //Evaluate new state
170                         if(!_model->hasChanged() && state==CLICKED)
171                         {
172                                 _model->setState(SELECTED);
173                                 _model->setChanged();
174                         }
175
176                         if( !_model->hasChanged() && state == DRAG)
177                         {
178                                 _model->setState(SELECTED);
179                                 _model->setChanged();
180                         }
181
182                         _model->notifyObservers();
183
184                 }
185
186                 */
187                 return true;
188         }
189
190         //=========================================================================
191         
192         bool GObjectController::OnLeftDClick()
193         {
194                 /**********************   VIRTUAL *************************
195
196                 if ( _vtkInteractorStyleBaseView!=NULL )
197                 {
198                         int X,Y;
199                         wxVTKRenderWindowInteractor *wxVTKiren;
200                         wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
201                         wxVTKiren->GetEventPosition(X,Y);
202
203                         _model->notifyObservers();
204                 }
205
206                 */
207                 return true;
208         }
209
210         //=========================================================================
211
212         bool GObjectController::OnRightButtonDown()
213         {
214                 /**********************   VIRTUAL *************************/
215
216                 if( _vtkInteractorStyleBaseView!= NULL )
217                 {
218                         int X,Y;
219                         wxVTKRenderWindowInteractor *wxVTKiren;
220                         wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
221                         wxVTKiren->GetEventPosition(X, Y);
222                         
223                         int state  = _view->getState();
224                         
225                         //Evaluate new state
226                         if( !_model->hasChanged() && state == SELECTED)
227                         {
228                                 _view->setState(NOTHING_HAPPENS);
229                                 _model->setChanged();                   
230                         }
231
232                         _model->notifyObservers(_id);
233                 }
234                 
235                 /**/
236
237                 return true;
238
239         }
240
241         //=========================================================================
242
243         void GObjectController::moveObject(int X,int Y)
244         {
245                 _view->moveObject(X,Y); 
246         }
247
248         //=========================================================================
249
250         int GObjectController::getGObjectType()
251         {
252                 return _model->getGObjectType();
253         }
254
255         //=========================================================================
256         
257         GObjectModel* GObjectController::getModel()
258         {
259                 return _model;
260         }
261
262         //=========================================================================
263
264         vtkGObjectView* GObjectController::getView()
265         {
266                 return _view;
267         }
268
269         //=========================================================================
270
271         int GObjectController::getId()
272         {
273                 return _id;
274         }
275
276         //=========================================================================
277         
278         void GObjectController::setId(int id)
279         {
280                 _id = id;
281         }
282
283         //=========================================================================
284
285 }  // EO namespace bbtk
286
287 // EOF
288