]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualContourBaseControler.cpp
creaButtonContainer & creaPanelButtonContainer: Updates in doxygen documentation...
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / manualContour / manualContourBaseControler.cpp
1 #include "manualContourBaseControler.h"
2
3
4 // ----------------------------------------------------------------------------
5 // ----------------------------------------------------------------------------
6 // ----------------------------------------------------------------------------
7
8 manualContourBaseControler::manualContourBaseControler()
9 {
10         _manViewBaseCont        = NULL;
11         _manContModel           = NULL;
12         _state                          = 0;
13         _z                                      = 900;
14         _editable                       = true;
15         _posibleToMove          = true;
16         _moving                         = false;
17         _created                        = false;
18         _keyBoardMoving         = false;
19 }
20 // ----------------------------------------------------------------------------
21 manualContourBaseControler::~manualContourBaseControler()
22 {
23 }
24
25 // ----------------------------------------------------------------------------
26 manualContourBaseControler * manualContourBaseControler :: Clone()  // virtual
27 {
28         manualContourBaseControler * clone = new manualContourBaseControler();
29         CopyAttributesTo(clone);
30         return clone;
31 }
32
33 // ---------------------------------------------------------------------------
34
35 void manualContourBaseControler::CopyAttributesTo( manualContourBaseControler * cloneObject)
36 {
37         // Fathers object
38         InteractorStyleMaracas::CopyAttributesTo(cloneObject);
39         cloneObject->SetZ( this->GetZ() );
40         cloneObject->SetState( this->GetState() );
41         cloneObject->SetEditable( this->IsEditable() );
42         cloneObject->SetPosibleToMove( this->GetPosibleToMove() );
43         cloneObject->SetMoving( this->IsMoving() );
44         cloneObject->SetCompleteCreation( this->GetIfCompleteCreation() );
45         cloneObject->SetKeyBoardMoving( this->GetKeyBoardMoving() );
46 }
47
48 // ----------------------------------------------------------------------------
49 void manualContourBaseControler::Configure() //virtual
50 {
51 }
52
53 // ----------------------------------------------------------------------------
54 bool manualContourBaseControler::OnChar()
55 {
56         if ( _vtkInteractorStyleBaseView!=NULL )
57         {
58                 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
59
60                 int X,Y;
61                 wxVTKRenderWindowInteractor *_wxVTKiren;
62                 _wxVTKiren= _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
63                 _wxVTKiren->GetEventPosition(X, Y);
64                 //int Z = GetZ(); // JPRx
65                 // Delete Point
66                 if ((keyCode==8) || (keyCode==127))
67                 {
68
69                         if (!GetManualViewBaseContour()->GetPosibleSelected()==true)
70                         {
71                                 DeleteActualMousePoint(X,Y);
72                         }
73                         GetManualViewBaseContour()->Refresh();
74                         this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
75                 }
76                 else
77                 {
78                         // Magnet
79                         if (keyCode==32)
80                         {
81                                 Magnet(X,Y);
82                                 GetManualViewBaseContour()->Refresh();
83                                 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
84                         }
85                         else if( !IsEditable() )
86                         {
87                                 if ( keyCode == 'L' )
88                                 {
89                                         GetManualViewBaseContour()->MoveContour( -1, 0 );
90                                         SetKeyBoardMoving( true );
91                                 }
92                                 else if ( keyCode == 'R' )
93                                 {
94                                         GetManualViewBaseContour()->MoveContour( 1, 0 );
95                                         SetKeyBoardMoving( true );
96                                 }
97                                 else if ( keyCode == 'U' )
98                                 {
99                                         GetManualViewBaseContour()->MoveContour( 0, -1 );
100                                         SetKeyBoardMoving( true );
101                                 }
102                                 else if ( keyCode == 'D' )
103                                 {
104                                         GetManualViewBaseContour()->MoveContour( 0, 1 );
105                                         SetKeyBoardMoving( true );
106                                 }
107                                 else if ( keyCode == 'W' )//Diagonal left down
108                                 {
109                                         GetManualViewBaseContour()->MoveContour( -1, 1 );
110                                         SetKeyBoardMoving( true );
111                                 }
112                                 else if ( keyCode == 'Q' )//Diagonal left up
113                                 {
114                                         GetManualViewBaseContour()->MoveContour( -1, -1 );
115                                         SetKeyBoardMoving( true );
116                                 }
117                                 else if( keyCode == 'P' )//Diagonal right up
118                                 {
119                                         GetManualViewBaseContour()->MoveContour( 1, -1 );
120                                         SetKeyBoardMoving( true );
121                                 }
122                                 else if( keyCode == 'M' )//Diagonal right down
123                                 {
124                                         GetManualViewBaseContour()->MoveContour( 1, 1 );
125                                         SetKeyBoardMoving( true );
126                                 }
127                                 if( GetKeyBoardMoving() )
128                                 {
129                                         GetManualViewBaseContour()->Refresh();
130                                         this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
131                                 }
132                         }
133                 }
134         }
135         return true;
136 }
137 // ----------------------------------------------------------------------------
138 bool manualContourBaseControler::OnMouseMove()
139 {
140         if ( _vtkInteractorStyleBaseView!=NULL)
141         {
142                 int X,Y;
143                 wxVTKRenderWindowInteractor *_wxVTKiren;
144                 _wxVTKiren= _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
145                 _wxVTKiren->GetEventPosition( X , Y );
146
147                 if ( (_vtkInteractorStyleBaseView->GetInteractor()->GetControlKey()==0) &&
148                         (_vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey()==0) ) {
149                         MouseMove(X,Y);
150                 }
151         }
152         return true;
153 }
154 // ----------------------------------------------------------------------------
155 bool manualContourBaseControler::OnLeftButtonDown()
156 {
157         SetKeyBoardMoving( false );
158         if ( _vtkInteractorStyleBaseView!=NULL )
159         {
160                 int X,Y;
161                 wxVTKRenderWindowInteractor *wxVTKiren;
162                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
163                 wxVTKiren->GetEventPosition(X,Y);
164
165                 MouseClickLeft(X,Y);
166         }
167         return true;
168 }
169 // ----------------------------------------------------------------------------
170 bool manualContourBaseControler::OnLeftButtonUp()
171 {
172         if ( _vtkInteractorStyleBaseView!=NULL )
173         {
174                 int X,Y;
175                 wxVTKRenderWindowInteractor *wxVTKiren;
176                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
177                 wxVTKiren->GetEventPosition(X,Y);
178                 MouseReleaseLeft(X,Y);
179         }
180         return true;
181 }
182 // ----------------------------------------------------------------------------
183 bool manualContourBaseControler::OnLeftDClick()
184 {
185         if ( _vtkInteractorStyleBaseView!=NULL )
186         {
187                 int X,Y;
188                 wxVTKRenderWindowInteractor *wxVTKiren;
189                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
190                 wxVTKiren->GetEventPosition(X,Y);
191
192                 this->MouseDLeft(X,Y);
193         }
194         return true;
195 }
196 // ----------------------------------------------------------------------------
197 bool manualContourBaseControler::OnMiddleButtonDown()
198 {
199 //      SetKeyBoardMoving( false );
200         if ( _vtkInteractorStyleBaseView!=NULL )
201         {
202                 int X,Y;
203                 wxVTKRenderWindowInteractor *wxVTKiren;
204                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
205                 wxVTKiren->GetEventPosition(X,Y);
206                 GetManualViewBaseContour()->InitMove( X, Y,GetZ());
207         }
208         return true;
209 }
210 // ----------------------------------------------------------------------------
211 bool manualContourBaseControler::OnMiddleButtonUp()
212 {
213         return true;
214 }
215 // ----------------------------------------------------------------------------
216 bool manualContourBaseControler::OnRightButtonDown()
217 {
218         if( _vtkInteractorStyleBaseView!= NULL )
219         {
220                 int X,Y;
221                 wxVTKRenderWindowInteractor *wxVTKiren;
222                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
223                 wxVTKiren->GetEventPosition(X, Y);
224
225                 MouseClickRight(X,Y);
226         }
227         return true;
228 }
229 // ----------------------------------------------------------------------------
230 bool manualContourBaseControler::OnRightButtonUp()
231 {
232         return true;
233 }
234 // ----------------------------------------------------------------------------
235 void manualContourBaseControler::SetModelView(manualBaseModel *manContModel, manualViewBaseContour *manViewBaseCont){
236         _manContModel           =       manContModel;
237         _manViewBaseCont        =       manViewBaseCont;
238         _manViewBaseCont->SetEditable( &_editable );
239 }
240 // ----------------------------------------------------------------------------
241 manualBaseModel* manualContourBaseControler::GetManualContourModel()
242 {
243         return _manContModel;
244 }
245 // ----------------------------------------------------------------------------
246 manualViewBaseContour* manualContourBaseControler::GetManualViewBaseContour()
247 {
248         return _manViewBaseCont;
249 }
250 // ----------------------------------------------------------------------------
251 void manualContourBaseControler::MouseClickLeft(int x, int y) // virtual
252 {
253
254 }
255 // ----------------------------------------------------------------------------
256 void manualContourBaseControler::MouseClickRight(int x, int y)
257 {
258         SetCompleteCreation( true );
259         SetKeyBoardMoving( false );
260         this->GetManualContourModel()->SetCloseContour(true);
261
262 //      if (_state==1)
263 //      {
264 //              _state=0;
265 //      }
266         SetEditable( false );
267         SetPosibleToMove( false );
268         _state = 0;
269
270 //EED 24Avril2009       _state=7;
271 }
272 // ----------------------------------------------------------------------------
273 void manualContourBaseControler::MouseReleaseLeft(int x, int y)
274 {
275         if (_state==5){ _state = 0; }
276         if (_state==6){ _state = 0; }
277         if (_state==7){ _state = 0; }
278         SetMoving( false );
279         GetManualViewBaseContour()->SelectPosibleContour(x,y,GetZ());
280         if( GetIfCompleteCreation() && IsEditable() && !GetManualViewBaseContour()->GetPosibleSelected() && (GetManualViewBaseContour()->GetIdPoint(x,y,GetZ())==-1)  )
281         {
282                 SetEditable( false );
283                 SetPosibleToMove( false );
284         }
285 }
286 // ----------------------------------------------------------------------------
287 void manualContourBaseControler::MouseDLeft(int x, int y )
288 {
289         if (_state==0)
290         {
291
292                 int z=GetZ();
293                 /*bool temp = */ _manViewBaseCont->SelectPosibleContour(x,y,z);
294
295                 _manViewBaseCont->SelectPosiblePoint(x,y,z);
296
297                 if ( _manViewBaseCont->GetPosibleSelected() )
298                 {
299                         _editable = true;
300                 }
301         }
302 }
303 // ----------------------------------------------------------------------------
304 void manualContourBaseControler::MouseMove(int x, int y) // virtual
305 {
306 }
307 // ----------------------------------------------------------------------------
308 void manualContourBaseControler::SetState(int state)
309 {
310         _state=state;
311 }
312 // ----------------------------------------------------------------------------
313 int manualContourBaseControler::GetState()
314 {
315         return _state;
316 }
317 // ----------------------------------------------------------------------------
318 bool manualContourBaseControler::IsEditable( )
319 {
320         return _editable;
321 }
322 // ----------------------------------------------------------------------------
323 void manualContourBaseControler::SetEditable(  bool condition  )
324 {
325         if (GetManualViewBaseContour()!=NULL) {
326                 if( !condition )
327                 {
328                         GetManualViewBaseContour()->RemoveControlPoints();
329                 }
330                 GetManualViewBaseContour()->SetSelected( condition );
331         }
332         _editable = condition;
333 }
334
335 // ----------------------------------------------------------------------------
336 bool manualContourBaseControler::GetPosibleToMove()
337 {
338         return _posibleToMove;
339 }
340 // ----------------------------------------------------------------------------
341 void manualContourBaseControler::SetPosibleToMove( bool condition )
342 {
343         _posibleToMove = condition;
344 }
345 // ----------------------------------------------------------------------------
346 bool manualContourBaseControler::IsMoving()
347 {
348         return _moving;
349 }
350 // ----------------------------------------------------------------------------
351 void manualContourBaseControler::SetMoving( bool condition )
352 {
353         _moving = condition;
354 }
355 // ----------------------------------------------------------------------------
356 void manualContourBaseControler::SetCompleteCreation( bool condition )
357 {
358         _created = condition;
359 }
360 // ----------------------------------------------------------------------------
361 bool manualContourBaseControler::GetIfCompleteCreation ( )
362 {
363         return _created;
364 }
365 // ----------------------------------------------------------------------------
366 void manualContourBaseControler::SetKeyBoardMoving( bool condition )
367 {
368         _keyBoardMoving = condition;
369 }
370 // ----------------------------------------------------------------------------
371 bool manualContourBaseControler::GetKeyBoardMoving(  )
372 {
373         return _keyBoardMoving;
374 }
375 // ----------------------------------------------------------------------------
376 void manualContourBaseControler::CreateNewManualContour(){
377         _manViewBaseCont->CreateNewContour();
378 }
379 // ----------------------------------------------------------------------------
380 int     manualContourBaseControler::GetNumberOfPointsManualContour(){
381         return _manViewBaseCont->GetNumberOfPoints();
382 }
383 // ----------------------------------------------------------------------------
384
385 //JSTG - 25-02-08 -------------------------------------------------------------
386 int     manualContourBaseControler::GetNumberOfPointsSplineManualContour(){
387         //return _manViewBaseCont->GetNumberOfPointsSpline();
388         return _manContModel->GetNumberOfPointsSpline();
389 }
390 // ----------------------------------------------------------------------------
391
392 double* manualContourBaseControler::GetVectorPointsXManualContour(){
393         return _manViewBaseCont->GetVectorPointsXManualContour();
394 }
395 // ----------------------------------------------------------------------------
396 double* manualContourBaseControler::GetVectorPointsYManualContour(){
397         return _manViewBaseCont->GetVectorPointsYManualContour();
398 }
399 // ----------------------------------------------------------------------------
400 void manualContourBaseControler::DeleteContour(){
401         _manViewBaseCont->DeleteContour();
402         _manContModel->DeleteAllPoints();
403 }
404 // ----------------------------------------------------------------------------
405 void manualContourBaseControler::DeleteActualMousePoint(int x, int y)// virtual
406 {
407         if ((_manContModel!=NULL) && (_manViewBaseCont!=NULL) )
408         {
409                 int id=_manViewBaseCont->GetIdPoint(x,y,GetZ());
410                 if ((id!=-1) && (_manContModel->GetSizeLstPoints()>2) ){
411                         _manContModel->DeletePoint(id);
412                         _manViewBaseCont->DeletePoint(id);
413                 }
414         }
415         _state = 0;
416 }
417
418 // ----------------------------------------------------------------------------
419 void manualContourBaseControler::Magnet(int x, int y)
420 {
421         if( IsEditable())
422         {
423                 /*int id= */ _manViewBaseCont->GetIdPoint(x,y,GetZ()); // JPRx
424                 if (GetManualContourModel()!=NULL){
425                         double  xx      = x;
426                         double  yy      = y;
427                         double  zz      = GetZ();
428                         GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
429                         int                     id      = GetManualContourModel()->GetIdPoint(xx,yy,zz,32000,-1);
430                         if (id!=-1)
431                         {
432                                 manualPoint     *mp     = GetManualContourModel()->GetManualPoint(id);
433                                 mp->SetPoint(xx,yy,zz);
434                         }
435         //              GetManualViewBaseContour()->UpdateViewPoint(id);
436                 }
437                 _state = 0;
438         }
439 }
440
441 // ----------------------------------------------------------------------------
442 void manualContourBaseControler::SetZ(int z)
443 {
444         _z=z;
445 }
446 // ----------------------------------------------------------------------------
447 int manualContourBaseControler::GetZ()
448 {
449         return _z;
450 }
451 // ----------------------------------------------------------------------------
452 void manualContourBaseControler::AddPoint(int x, int y, int z) // virtual
453 {
454         if (GetManualContourModel()!=NULL){
455                 double  xx      = x;
456                 double  yy      = y;
457                 double  zz      = z;
458
459                 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
460                 GetManualContourModel()->AddPoint(xx,yy,zz);
461                 GetManualViewBaseContour()->AddPoint();
462 //              GetManualViewBaseContour()->UpdateViewPoint(id);
463         }
464 }
465 // ----------------------------------------------------------------------------
466 void manualContourBaseControler::InsertPoint(int x,int y,int z)  // virtual
467 {
468 //EEDzz
469         int id=-1;
470         if (GetManualContourModel()!=NULL){
471                 double                          xx              = x;
472                 double                          yy              = y;
473                 double                          zz              = z;
474                 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
475                 if (GetManualContourModel()->GetSizeLstPoints()>1){
476                         id = GetManualContourModel()->InsertPoint(xx,yy,zz);
477                         GetManualViewBaseContour()->InsertPoint(id);
478 //                      GetManualViewBaseContour()->UpdateViewPoint(id);
479                 } else {
480                         GetManualContourModel()->AddPoint(xx,yy,zz);
481                         GetManualViewBaseContour()->AddPoint();
482 //                      AddPoint(x,y,z);
483 //                      GetManualViewBaseContour()->UpdateViewPoint(id);
484                 }
485         }
486 }
487
488 // ----------------------------------------------------------------------------
489 void manualContourBaseControler::SetPoint( int id ,int x , int y , int z){ // virtual
490         if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
491                 double xx = x;
492                 double yy = y;
493                 double zz = z;
494
495                 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
496                 manualPoint             *mp             = _manContModel->GetManualPoint(id);
497                 mp->SetPoint(xx,yy,zz);
498                 GetManualViewBaseContour()->UpdateViewPoint(id);
499         }
500 }
501 // ----------------------------------------------------------------------------
502 void manualContourBaseControler::SetPointX( int id ,int x  ){
503         if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
504                 double xx = x;
505                 double yy = 0;
506                 double zz = 0;
507                 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
508                 manualPoint             *mp             = _manContModel->GetManualPoint(id);
509                 mp->SetPointX(xx);
510                 GetManualViewBaseContour()->UpdateViewPoint(id);
511         }
512 }
513 // ----------------------------------------------------------------------------
514 void manualContourBaseControler::SetPointY( int id ,int y  ){
515         if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
516                 double xx = 0;
517                 double yy = y;
518                 double zz = 0;
519                 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
520                 manualPoint             *mp             = _manContModel->GetManualPoint(id);
521                 mp->SetPointY(yy);
522                 GetManualViewBaseContour()->UpdateViewPoint(id);
523         }
524 }
525 // ----------------------------------------------------------------------------
526 void manualContourBaseControler::SetPointZ( int id ,int z  ){
527         if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
528                 double xx = 0;
529                 double yy = 0;
530                 double zz = z;
531                 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
532                 manualPoint             *mp             = _manContModel->GetManualPoint(id);
533                 mp->SetPointZ(zz);
534                 GetManualViewBaseContour()->UpdateViewPoint(id);
535         }
536 }
537 // ----------------------------------------------------------------------------
538 void manualContourBaseControler::ResetContour() // virtual
539 {
540         this->DeleteContour();
541         GetManualViewBaseContour()->CreateNewContour();
542         this->SetState(0);
543 }
544