]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GObjectController.cxx
37b5de2d4ddf64067a6ed54e61cfe219614723e3
[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         GObjectController::~GObjectController()
51         {
52         }
53         //=========================================================================
54
55         void GObjectController::setModelAndView(GObjectModel* model, vtkGObjectView* view)
56         {
57                 _model = model;
58                 _view = view;
59         }
60         //=========================================================================
61
62 bool GObjectController::OnMouseMove()
63 {
64         
65         if ( _vtkInteractorStyleBaseView!=NULL)
66         {
67                 int X,Y;
68                 wxVTKRenderWindowInteractor *_wxVTKiren;
69                 _wxVTKiren= _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
70                 _wxVTKiren->GetEventPosition( X , Y );
71
72                 int state  = _model->getState();
73                 
74                 //Evaluate new state
75                 if(!_model->hasChanged() && state == DRAG)
76                 {
77                         moveObject(X,Y);
78                         _model->setChanged();
79                 }
80
81                 if(!_model->hasChanged() && state == NOTHING_HAPPENS)
82                 {
83                         if(_view->isPointInside(X,Y))
84                         {
85                                 _model->setState(HIGHLIGHTED);
86                                 _model->setChanged();                           
87                         }                       
88                 }
89                 if(!_model->hasChanged() && state==HIGHLIGHTED)
90                 {
91                         if(!_view->isPointInside(X,Y))
92                         {
93                                 _model->setState(NOTHING_HAPPENS);
94                                 _model->setChanged();
95                         }
96                 }
97                 
98                 _model->notifyObservers();
99         }
100         return true;
101 }
102 //=========================================================================
103 bool GObjectController::OnLeftButtonDown()
104 {
105         
106         if ( _vtkInteractorStyleBaseView!=NULL )
107         {
108                 int X,Y;
109                 wxVTKRenderWindowInteractor *wxVTKiren;
110                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
111                 wxVTKiren->GetEventPosition(X,Y);
112
113                 int state  = _model->getState();
114                 
115                 //Evaluate new state
116                 if(!_model->hasChanged() && state==HIGHLIGHTED)
117                 {
118                         _view->isFirstDragging(true);
119                         _model->setState(DRAG);
120                         _model->setChanged();
121                 }
122
123                 if( !_model->hasChanged() && state == SELECTED)
124                 {
125                         if(_view->isPointInside(X,Y))
126                         {
127                                 _view->isFirstDragging(true);
128                                 _model->setState(DRAG);
129                                 _model->setChanged();
130                         }       
131                 }
132                 
133                 _model->notifyObservers();
134         }
135         return true;
136 }
137 //=========================================================================
138 bool GObjectController::OnLeftButtonUp()
139 {
140         if ( _vtkInteractorStyleBaseView!=NULL )
141         {
142                 int X,Y;
143                 wxVTKRenderWindowInteractor *wxVTKiren;
144                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
145                 wxVTKiren->GetEventPosition(X,Y);
146
147                 int state  = _model->getState();
148                 
149                 //Evaluate new state
150                 if(!_model->hasChanged() && state==CLICKED)
151                 {
152                         _model->setState(SELECTED);
153                         _model->setChanged();
154                 }
155
156                 if( !_model->hasChanged() && state == DRAG)
157                 {
158                         _model->setState(SELECTED);
159                         _model->setChanged();
160                 }
161
162                 _model->notifyObservers();
163
164         }
165         return true;
166 }
167 //=========================================================================
168 bool GObjectController::OnLeftDClick()
169 {
170         if ( _vtkInteractorStyleBaseView!=NULL )
171         {
172                 int X,Y;
173                 wxVTKRenderWindowInteractor *wxVTKiren;
174                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
175                 wxVTKiren->GetEventPosition(X,Y);
176
177                 _model->notifyObservers();
178         }
179         return true;
180 }
181 //=========================================================================
182 bool GObjectController::OnRightButtonDown()
183 {
184         if( _vtkInteractorStyleBaseView!= NULL )
185         {
186                 int X,Y;
187                 wxVTKRenderWindowInteractor *wxVTKiren;
188                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
189                 wxVTKiren->GetEventPosition(X, Y);
190                 
191                 int state  = _model->getState();
192                 
193                 //Evaluate new state
194                 if( !_model->hasChanged() && state == SELECTED)
195                 {
196                         _model->setState(NOTHING_HAPPENS);
197                         _model->setChanged();                   
198                 }
199
200                 _model->notifyObservers();
201         }
202         return true;
203 }
204
205 //=========================================================================
206
207 void GObjectController::moveObject(int X,int Y)
208 {
209         _view->moveObject(X,Y); 
210 }
211
212 //=========================================================================
213
214 }  // EO namespace bbtk
215
216 // EOF
217