]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GBlackBoxController.cxx
Organizing code, the state now is in the view and the general render was simplified...
[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 namespace bbtk
40 {
41
42
43         //=========================================================================
44         GBlackBoxController::GBlackBoxController()
45         {
46                 
47         }
48
49         //=========================================================================
50         GBlackBoxController::~GBlackBoxController()
51         {
52         }
53         //=========================================================================
54
55         bool GBlackBoxController::OnMouseMove()
56         {
57                 
58                 if ( _vtkInteractorStyleBaseView!=NULL)
59                 {
60                         int X,Y;
61                         wxVTKRenderWindowInteractor *_wxVTKiren;
62                         _wxVTKiren= _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
63                         _wxVTKiren->GetEventPosition( X , Y );
64
65                         int state  = _view->getState();
66                         
67                         //Evaluate new state
68                         if(!_model->hasChanged() && state == DRAG)
69                         {
70                                 moveObject(X,Y);
71                                 _model->setChanged();
72                         }
73
74                         if(!_model->hasChanged() && state == NOTHING_HAPPENS)
75                         {
76                                 if(_view->isPointInside(X,Y))
77                                 {
78                                         _view->setState(HIGHLIGHTED);
79                                         _model->setChanged();                           
80                                 }                       
81                         }
82                         if(!_model->hasChanged() && state==HIGHLIGHTED)
83                         {
84                                 if(!_view->isPointInside(X,Y))
85                                 {
86                                         _view->setState(NOTHING_HAPPENS);
87                                         _model->setChanged();
88                                 }
89                         }
90                         
91                         _model->notifyObservers(_id);
92                         
93                 }
94                 return true;
95         }
96
97         //=========================================================================
98         
99         bool GBlackBoxController::OnLeftButtonDown()
100         {
101                 
102                 if ( _vtkInteractorStyleBaseView!=NULL )
103                 {
104                         int X,Y;
105                         wxVTKRenderWindowInteractor *wxVTKiren;
106                         wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
107                         wxVTKiren->GetEventPosition(X,Y);
108
109                         int state  = _view->getState();
110                         
111                         //Evaluate new state
112                         if(!_model->hasChanged() && state==HIGHLIGHTED)
113                         {
114                                 _view->isStartDragging(true);
115                                 _view->setState(DRAG);
116                                 _model->setChanged();
117                         }
118
119                         if( !_model->hasChanged() && state == SELECTED)
120                         {
121                                 if(_view->isPointInside(X,Y))
122                                 {
123                                         _view->isStartDragging(true);
124                                         _view->setState(DRAG);
125                                         _model->setChanged();
126                                 }       
127                         }
128                         
129                         _model->notifyObservers(_id);
130                 }
131                 return true;
132         }
133
134         //=========================================================================
135         
136         bool GBlackBoxController::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  = _view->getState();
146                         
147                         //Evaluate new state
148                         if(!_model->hasChanged() && state==CLICKED)
149                         {
150                                 _view->setState(SELECTED);
151                                 _model->setChanged();
152                         }
153
154                         if( !_model->hasChanged() && state == DRAG)
155                         {
156                                 _view->setState(SELECTED);
157                                 _model->setChanged();
158                         }
159
160                         _model->notifyObservers(_id);
161
162                 }
163                 return true;
164         }
165         
166         //=========================================================================
167         
168         bool GBlackBoxController::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(_id);
178                 }
179                 return true;
180         }
181         
182         //=========================================================================
183         
184         bool GBlackBoxController::OnRightButtonDown()
185         {
186                 if( _vtkInteractorStyleBaseView!= NULL )
187                 {
188                         int X,Y;
189                         wxVTKRenderWindowInteractor *wxVTKiren;
190                         wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
191                         wxVTKiren->GetEventPosition(X, Y);
192                         
193                         int state  = _view->getState();
194                         
195                         //Evaluate new state
196                         if( !_model->hasChanged() && state == SELECTED)
197                         {
198                                 _view->setState(NOTHING_HAPPENS);
199                                 _model->setChanged();                   
200                         }
201
202                         _model->notifyObservers(_id);
203                 }
204                 return true;
205         }
206
207         //=========================================================================
208
209 }  // EO namespace bbtk
210
211 // EOF
212