]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GObjectController.cxx
Stable version ... The connection is correctly painted :)
[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( state == DRAG)
81                         {
82                                 moveObject(X,Y);
83                         }
84
85                         if( state == NOTHING_HAPPENS)
86                         {
87                                 if(_view->isPointInside(X,Y))
88                                 {
89                                         _view->setState(HIGHLIGHTED);   
90                                 }                       
91                         }
92                         if( state==HIGHLIGHTED)
93                         {
94                                 if(!_view->isPointInside(X,Y))
95                                 {
96                                         _view->setState(NOTHING_HAPPENS);
97                                 }
98                         }
99                         
100                         _model->notifyObservers(_id);
101                         
102                 }
103
104                 /**/
105
106                 return true;
107         }
108
109         //=========================================================================
110         
111         bool GObjectController::OnLeftButtonDown()
112         {
113                 /**********************   VIRTUAL *************************
114                 
115                 if ( _vtkInteractorStyleBaseView!=NULL )
116                 {
117                         int X,Y;
118                         wxVTKRenderWindowInteractor *wxVTKiren;
119                         wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
120                         wxVTKiren->GetEventPosition(X,Y);
121
122                         int state  = _model->getState();
123                         
124                         //Evaluate new state
125                         if(!_model->hasChanged() && state==HIGHLIGHTED)
126                         {
127                                 _view->isStartDragging(true);
128                                 _model->setState(DRAG);
129                         }
130
131                         if( !_model->hasChanged() && state == SELECTED)
132                         {
133                                 if(_view->isPointInside(X,Y))
134                                 {
135                                         _view->isStartDragging(true);
136                                         _model->setState(DRAG);
137                                 }       
138                         }
139                         
140                         _model->notifyObservers();
141                 }
142
143                 */
144
145                 return true;
146         }
147
148         //=========================================================================
149         
150         bool GObjectController::OnLeftButtonUp()
151         {
152
153                 /**********************   VIRTUAL *************************
154
155                 if ( _vtkInteractorStyleBaseView!=NULL )
156                 {
157                         int X,Y;
158                         wxVTKRenderWindowInteractor *wxVTKiren;
159                         wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
160                         wxVTKiren->GetEventPosition(X,Y);
161
162                         int state  = _model->getState();
163                         
164                         //Evaluate new state
165                         if(!_model->hasChanged() && state==CLICKED)
166                         {
167                                 _model->setState(SELECTED);
168                         }
169
170                         if( !_model->hasChanged() && state == DRAG)
171                         {
172                                 _model->setState(SELECTED);
173                         }
174
175                         _model->notifyObservers();
176
177                 }
178
179                 */
180                 return true;
181         }
182
183         //=========================================================================
184         
185         bool GObjectController::OnLeftDClick()
186         {
187                 /**********************   VIRTUAL *************************
188
189                 if ( _vtkInteractorStyleBaseView!=NULL )
190                 {
191                         int X,Y;
192                         wxVTKRenderWindowInteractor *wxVTKiren;
193                         wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
194                         wxVTKiren->GetEventPosition(X,Y);
195
196                         _model->notifyObservers();
197                 }
198
199                 */
200                 return true;
201         }
202
203         //=========================================================================
204
205         bool GObjectController::OnRightButtonDown()
206         {
207                 /**********************   VIRTUAL *************************/
208
209                 if( _vtkInteractorStyleBaseView!= NULL )
210                 {
211                         int X,Y;
212                         wxVTKRenderWindowInteractor *wxVTKiren;
213                         wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
214                         wxVTKiren->GetEventPosition(X, Y);
215                         
216                         int state  = _view->getState();
217                         
218                         //Evaluate new state
219                         if( state == SELECTED)
220                         {
221                                 _view->setState(NOTHING_HAPPENS);
222                         }
223
224                         _model->notifyObservers(_id);
225                 }
226                 
227                 /**/
228
229                 return true;
230
231         }
232
233         //=========================================================================
234
235         void GObjectController::moveObject(int X,int Y)
236         {
237                 _view->moveObject(X,Y); 
238         }
239
240         //=========================================================================
241
242         int GObjectController::getGObjectType()
243         {
244                 return _model->getGObjectType();
245         }
246
247         //=========================================================================
248         
249         GObjectModel* GObjectController::getModel()
250         {
251                 return _model;
252         }
253
254         //=========================================================================
255
256         vtkGObjectView* GObjectController::getView()
257         {
258                 return _view;
259         }
260
261         //=========================================================================
262
263         int GObjectController::getId()
264         {
265                 return _id;
266         }
267
268         //=========================================================================
269         
270         void GObjectController::setId(int id)
271         {
272                 _id = id;
273         }
274
275         //=========================================================================
276
277 }  // EO namespace bbtk
278
279 // EOF
280