]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GObjectController.cxx
First prototype works. Basic boxes construction, evenct handling and colors represent...
[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                         
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                         _model->setState(DRAG);
119                         _model->setChanged();
120                 }
121
122                 if( !_model->hasChanged() && state == SELECTED)
123                 {
124                         if(_view->isPointInside(X,Y))
125                         {
126                                 _model->setState(DRAG);
127                                 _model->setChanged();
128                         }       
129                 }
130                 
131                 _model->notifyObservers();
132         }
133         return true;
134 }
135 //=========================================================================
136 bool GObjectController::OnLeftButtonUp()
137 {
138         if ( _vtkInteractorStyleBaseView!=NULL )
139         {
140                 int X,Y;
141                 wxVTKRenderWindowInteractor *wxVTKiren;
142                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
143                 wxVTKiren->GetEventPosition(X,Y);
144
145                 int state  = _model->getState();
146                 
147                 //Evaluate new state
148                 if(!_model->hasChanged() && state==CLICKED)
149                 {
150                         _model->setState(SELECTED);
151                         _model->setChanged();
152                 }
153
154                 if( !_model->hasChanged() && state == DRAG)
155                 {
156                         _model->setState(SELECTED);
157                         _model->setChanged();
158                 }
159
160                 _model->notifyObservers();
161
162         }
163         return true;
164 }
165 //=========================================================================
166 bool GObjectController::OnLeftDClick()
167 {
168         if ( _vtkInteractorStyleBaseView!=NULL )
169         {
170                 int X,Y;
171                 wxVTKRenderWindowInteractor *wxVTKiren;
172                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
173                 wxVTKiren->GetEventPosition(X,Y);
174
175                 _model->notifyObservers();
176         }
177         return true;
178 }
179 //=========================================================================
180 bool GObjectController::OnRightButtonDown()
181 {
182         if( _vtkInteractorStyleBaseView!= NULL )
183         {
184                 int X,Y;
185                 wxVTKRenderWindowInteractor *wxVTKiren;
186                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
187                 wxVTKiren->GetEventPosition(X, Y);
188                 
189                 int state  = _model->getState();
190                 
191                 //Evaluate new state
192                 if( !_model->hasChanged() && state == SELECTED)
193                 {
194                         _model->setState(NOTHING_HAPPENS);
195                         _model->setChanged();                   
196                 }
197
198                 _model->notifyObservers();
199         }
200         return true;
201 }
202 //=========================================================================
203
204
205 }  // EO namespace bbtk
206
207 // EOF
208