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