]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualContourBaseControler.cpp
24c974bf7d91a7027627295cad099b41627d9559
[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         
141         if ( _vtkInteractorStyleBaseView!=NULL)
142         {
143                 int X,Y;
144                 wxVTKRenderWindowInteractor *_wxVTKiren;
145                 _wxVTKiren= _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
146                 _wxVTKiren->GetEventPosition( X , Y );
147
148
149                 if ( (_vtkInteractorStyleBaseView->GetInteractor()->GetControlKey()==0) &&
150                         (_vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey()==0) ) {
151                         MouseMove(X,Y);
152                 }
153         }
154         return true;
155 }
156 // ----------------------------------------------------------------------------
157 bool manualContourBaseControler::OnLeftButtonDown()
158 {
159         SetKeyBoardMoving( false );
160         if ( _vtkInteractorStyleBaseView!=NULL )
161         {
162                 int X,Y;
163                 wxVTKRenderWindowInteractor *wxVTKiren;
164                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
165                 wxVTKiren->GetEventPosition(X,Y);
166
167                 MouseClickLeft(X,Y);
168         }
169         return true;
170 }
171 // ----------------------------------------------------------------------------
172 bool manualContourBaseControler::OnLeftButtonUp()
173 {
174         if ( _vtkInteractorStyleBaseView!=NULL )
175         {
176                 int X,Y;
177                 wxVTKRenderWindowInteractor *wxVTKiren;
178                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
179                 wxVTKiren->GetEventPosition(X,Y);
180                 MouseReleaseLeft(X,Y);
181         }
182         return true;
183 }
184 // ----------------------------------------------------------------------------
185 bool manualContourBaseControler::OnLeftDClick()
186 {
187         if ( _vtkInteractorStyleBaseView!=NULL )
188         {
189                 int X,Y;
190                 wxVTKRenderWindowInteractor *wxVTKiren;
191                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
192                 wxVTKiren->GetEventPosition(X,Y);
193
194                 this->MouseDLeft(X,Y);
195         }
196         return true;
197 }
198 // ----------------------------------------------------------------------------
199 bool manualContourBaseControler::OnMiddleButtonDown()
200 {
201 //      SetKeyBoardMoving( false );
202         if ( _vtkInteractorStyleBaseView!=NULL )
203         {
204                 int X,Y;
205                 wxVTKRenderWindowInteractor *wxVTKiren;
206                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
207                 wxVTKiren->GetEventPosition(X,Y);
208                 GetManualViewBaseContour()->InitMove( X, Y,GetZ());
209         }
210         return true;
211 }
212 // ----------------------------------------------------------------------------
213 bool manualContourBaseControler::OnMiddleButtonUp()
214 {
215         return true;
216 }
217 // ----------------------------------------------------------------------------
218 bool manualContourBaseControler::OnRightButtonDown()
219 {
220         if( _vtkInteractorStyleBaseView!= NULL )
221         {
222                 int X,Y;
223                 wxVTKRenderWindowInteractor *wxVTKiren;
224                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
225                 wxVTKiren->GetEventPosition(X, Y);
226
227                 SetCompleteCreation( true );
228                 SetKeyBoardMoving( false );
229                 MouseClickRight(X,Y);
230         }
231         return true;
232 }
233 // ----------------------------------------------------------------------------
234 bool manualContourBaseControler::OnRightButtonUp()
235 {
236         return true;
237 }
238 // ----------------------------------------------------------------------------
239 void manualContourBaseControler::SetModelView(manualContourModel *manContModel, manualViewBaseContour *manViewBaseCont){
240         _manContModel           =       manContModel;
241         _manViewBaseCont        =       manViewBaseCont;
242         _manViewBaseCont->SetEditable( &_editable );
243 }
244 // ----------------------------------------------------------------------------
245 manualContourModel* manualContourBaseControler::GetManualContourModel()
246 {
247         return _manContModel;
248 }
249 // ----------------------------------------------------------------------------
250 manualViewBaseContour* manualContourBaseControler::GetManualViewBaseContour()
251 {
252         return _manViewBaseCont;
253 }
254 // ----------------------------------------------------------------------------
255 void manualContourBaseControler::MouseClickLeft(int x, int y) // virtual
256 {
257
258 }
259 // ----------------------------------------------------------------------------
260 void manualContourBaseControler::MouseClickRight(int x, int y)
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                 int z=GetZ();
292                 GetManualViewBaseContour()->SelectPosibleContour(x,y,z);
293                 GetManualViewBaseContour()->SelectPosiblePoint(x,y,z);
294                 if ( GetManualViewBaseContour()->GetPosibleSelected() )
295                 {
296                         _editable = true;
297                 }
298         }
299 }
300 // ----------------------------------------------------------------------------
301 void manualContourBaseControler::MouseMove(int x, int y) // virtual
302 {
303 }
304 // ----------------------------------------------------------------------------
305 void manualContourBaseControler::SetState(int state)
306 {
307         _state=state;
308 }
309 // ----------------------------------------------------------------------------
310 int manualContourBaseControler::GetState()
311 {
312         return _state;
313 }
314 // ----------------------------------------------------------------------------
315 bool manualContourBaseControler::IsEditable( )
316 {
317         return _editable;
318 }
319 // ----------------------------------------------------------------------------
320 void manualContourBaseControler::SetEditable(  bool condition  )
321 {
322         if (GetManualViewBaseContour()!=NULL) {
323                 if( !condition )
324                 {
325                         GetManualViewBaseContour()->RemoveControlPoints();
326                 }
327                 GetManualViewBaseContour()->SetSelected( condition );
328         }
329         _editable = condition;
330 }
331
332 // ----------------------------------------------------------------------------
333 bool manualContourBaseControler::GetPosibleToMove()
334 {
335         return _posibleToMove;
336 }
337 // ----------------------------------------------------------------------------
338 void manualContourBaseControler::SetPosibleToMove( bool condition )
339 {
340         _posibleToMove = condition;
341 }
342 // ----------------------------------------------------------------------------
343 bool manualContourBaseControler::IsMoving()
344 {
345         return _moving;
346 }
347 // ----------------------------------------------------------------------------
348 void manualContourBaseControler::SetMoving( bool condition )
349 {
350         _moving = condition;
351 }
352 // ----------------------------------------------------------------------------
353 void manualContourBaseControler::SetCompleteCreation( bool condition )
354 {
355         _created = condition;
356 }
357 // ----------------------------------------------------------------------------
358 bool manualContourBaseControler::GetIfCompleteCreation ( )
359 {
360         return _created;
361 }
362 // ----------------------------------------------------------------------------
363 void manualContourBaseControler::SetKeyBoardMoving( bool condition )
364 {
365         _keyBoardMoving = condition;
366 }
367 // ----------------------------------------------------------------------------
368 bool manualContourBaseControler::GetKeyBoardMoving(  )
369 {
370         return _keyBoardMoving;
371 }
372 // ----------------------------------------------------------------------------
373 void manualContourBaseControler::CreateNewManualContour(){
374         _manViewBaseCont->CreateNewContour();
375 }
376 // ----------------------------------------------------------------------------
377 int     manualContourBaseControler::GetNumberOfPointsManualContour(){
378         return _manViewBaseCont->GetNumberOfPoints();
379 }
380 // ----------------------------------------------------------------------------
381
382 //JSTG - 25-02-08 -------------------------------------------------------------
383 int     manualContourBaseControler::GetNumberOfPointsSplineManualContour(){
384         //return _manViewBaseCont->GetNumberOfPointsSpline();
385         return _manContModel->GetNumberOfPointsSpline();
386 }
387 // ----------------------------------------------------------------------------
388
389 double* manualContourBaseControler::GetVectorPointsXManualContour(){
390         return _manViewBaseCont->GetVectorPointsXManualContour();
391 }
392 // ----------------------------------------------------------------------------
393 double* manualContourBaseControler::GetVectorPointsYManualContour(){
394         return _manViewBaseCont->GetVectorPointsYManualContour();
395 }
396 // ----------------------------------------------------------------------------
397 void manualContourBaseControler::DeleteContour(){
398         _manViewBaseCont->DeleteContour();
399         _manContModel->DeleteAllPoints();
400 }
401 // ----------------------------------------------------------------------------
402 void manualContourBaseControler::DeleteActualMousePoint(int x, int y)// virtual
403 {
404         if ((_manContModel!=NULL) && (_manViewBaseCont!=NULL) )
405         {
406                 int id=_manViewBaseCont->GetIdPoint(x,y,GetZ());
407                 if ((id!=-1) && (_manContModel->GetSizeLstPoints()>2) ){
408                         _manContModel->DeletePoint(id);
409                         _manViewBaseCont->DeletePoint(id);
410                 }
411         }
412         _state = 0;
413 }
414
415 // ----------------------------------------------------------------------------
416 void manualContourBaseControler::Magnet(int x, int y)
417 {
418         if( IsEditable())
419         {
420                 /*int id= */ _manViewBaseCont->GetIdPoint(x,y,GetZ()); // JPRx
421                 if (GetManualContourModel()!=NULL){
422                         double  xx      = x;
423                         double  yy      = y;
424                         double  zz      = GetZ();
425                         GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
426                         int                     id      = GetManualContourModel()->GetIdPoint(xx,yy,zz,32000,-1);
427                         if (id!=-1)
428                         {
429                                 manualPoint     *mp     = GetManualContourModel()->GetManualPoint(id);
430                                 mp->SetPoint(xx,yy,zz);
431                         }
432         //              GetManualViewBaseContour()->UpdateViewPoint(id);
433                 }
434                 _state = 0;
435         }
436 }
437
438 // ----------------------------------------------------------------------------
439 void manualContourBaseControler::SetZ(int z)
440 {
441         _z=z;
442 }
443 // ----------------------------------------------------------------------------
444 int manualContourBaseControler::GetZ()
445 {
446         return _z;
447 }
448 // ----------------------------------------------------------------------------
449 void manualContourBaseControler::AddPoint(int x, int y, int z) // virtual
450 {
451         if (GetManualContourModel()!=NULL){
452                 double  xx      = x;
453                 double  yy      = y;
454                 double  zz      = z;
455                 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
456                 /*int   id              =*/  GetManualContourModel()->AddPoint(xx,yy,zz);  // JPRx
457                 GetManualViewBaseContour()->AddPoint();
458 //              GetManualViewBaseContour()->UpdateViewPoint(id);
459         }
460 }
461 // ----------------------------------------------------------------------------
462 void manualContourBaseControler::InsertPoint(int x,int y,int z)  // virtual
463 {
464 //EEDzz
465         int id=-1;
466         if (GetManualContourModel()!=NULL){
467                 double                          xx              = x;
468                 double                          yy              = y;
469                 double                          zz              = z;
470                 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
471                 if (GetManualContourModel()->GetSizeLstPoints()>1){
472                         id = GetManualContourModel()->InsertPoint(xx,yy,zz);
473                         GetManualViewBaseContour()->InsertPoint(id);
474 //                      GetManualViewBaseContour()->UpdateViewPoint(id);
475                 } else {
476                         GetManualContourModel()->AddPoint(xx,yy,zz);
477                         GetManualViewBaseContour()->AddPoint();
478 //                      AddPoint(x,y,z);
479 //                      GetManualViewBaseContour()->UpdateViewPoint(id);
480                 }
481         }
482 }
483
484 // ----------------------------------------------------------------------------
485 void manualContourBaseControler::SetPoint( int id ,int x , int y , int z){ // virtual
486         if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
487                 double xx = x;
488                 double yy = y;
489                 double zz = z;
490                 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
491                 manualPoint             *mp             = _manContModel->GetManualPoint(id);
492                 mp->SetPoint(xx,yy,zz);
493                 GetManualViewBaseContour()->UpdateViewPoint(id);
494         }
495 }
496 // ----------------------------------------------------------------------------
497 void manualContourBaseControler::SetPointX( int id ,int x  ){
498         if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
499                 double xx = x;
500                 double yy = 0;
501                 double zz = 0;
502                 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
503                 manualPoint             *mp             = _manContModel->GetManualPoint(id);
504                 mp->SetPointX(xx);
505                 GetManualViewBaseContour()->UpdateViewPoint(id);
506         }
507 }
508 // ----------------------------------------------------------------------------
509 void manualContourBaseControler::SetPointY( int id ,int y  ){
510         if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
511                 double xx = 0;
512                 double yy = y;
513                 double zz = 0;
514                 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
515                 manualPoint             *mp             = _manContModel->GetManualPoint(id);
516                 mp->SetPointY(yy);
517                 GetManualViewBaseContour()->UpdateViewPoint(id);
518         }
519 }
520 // ----------------------------------------------------------------------------
521 void manualContourBaseControler::SetPointZ( int id ,int z  ){
522         if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
523                 double xx = 0;
524                 double yy = 0;
525                 double zz = z;
526                 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
527                 manualPoint             *mp             = _manContModel->GetManualPoint(id);
528                 mp->SetPointZ(zz);
529                 GetManualViewBaseContour()->UpdateViewPoint(id);
530         }
531 }
532 // ----------------------------------------------------------------------------
533 void manualContourBaseControler::ResetContour() // virtual
534 {
535         this->DeleteContour();
536         GetManualViewBaseContour()->CreateNewContour();
537         this->SetState(0);
538 }
539