]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualContourBaseControler.cpp
Changements dans la class CutModuleMainPanel et CutModuleManager pour ajouter la...
[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                 this->GetManualContourModel()->SetCloseContour(true);
230                 MouseClickRight(X,Y);
231         }
232         return true;
233 }
234 // ----------------------------------------------------------------------------
235 bool manualContourBaseControler::OnRightButtonUp()
236 {
237         return true;
238 }
239 // ----------------------------------------------------------------------------
240 void manualContourBaseControler::SetModelView(manualBaseModel *manContModel, manualViewBaseContour *manViewBaseCont){
241         _manContModel           =       manContModel;
242         _manViewBaseCont        =       manViewBaseCont;
243         _manViewBaseCont->SetEditable( &_editable );
244 }
245 // ----------------------------------------------------------------------------
246 manualBaseModel* manualContourBaseControler::GetManualContourModel()
247 {
248         return _manContModel;
249 }
250 // ----------------------------------------------------------------------------
251 manualViewBaseContour* manualContourBaseControler::GetManualViewBaseContour()
252 {
253         return _manViewBaseCont;
254 }
255 // ----------------------------------------------------------------------------
256 void manualContourBaseControler::MouseClickLeft(int x, int y) // virtual
257 {
258
259 }
260 // ----------------------------------------------------------------------------
261 void manualContourBaseControler::MouseClickRight(int x, int y)
262 {
263 //      if (_state==1)
264 //      {
265 //              _state=0;
266 //      }
267         SetEditable( false );
268         SetPosibleToMove( false );
269         _state = 0;
270
271 //EED 24Avril2009       _state=7;
272 }
273 // ----------------------------------------------------------------------------
274 void manualContourBaseControler::MouseReleaseLeft(int x, int y)
275 {
276         if (_state==5){ _state = 0; }
277         if (_state==6){ _state = 0; }
278         if (_state==7){ _state = 0; }
279         SetMoving( false );
280         GetManualViewBaseContour()->SelectPosibleContour(x,y,GetZ());
281         if( GetIfCompleteCreation() && IsEditable() && !GetManualViewBaseContour()->GetPosibleSelected() && (GetManualViewBaseContour()->GetIdPoint(x,y,GetZ())==-1)  )
282         {
283                 SetEditable( false );
284                 SetPosibleToMove( false );
285         }
286 }
287 // ----------------------------------------------------------------------------
288 void manualContourBaseControler::MouseDLeft(int x, int y )
289 {
290         if (_state==0)
291         {
292                 
293                 int z=GetZ();
294                 bool temp = _manViewBaseCont->SelectPosibleContour(x,y,z);
295
296                 _manViewBaseCont->SelectPosiblePoint(x,y,z);
297
298                 if ( _manViewBaseCont->GetPosibleSelected() )
299                 {
300                         _editable = true;
301                 }
302         }
303 }
304 // ----------------------------------------------------------------------------
305 void manualContourBaseControler::MouseMove(int x, int y) // virtual
306 {
307 }
308 // ----------------------------------------------------------------------------
309 void manualContourBaseControler::SetState(int state)
310 {
311         _state=state;
312 }
313 // ----------------------------------------------------------------------------
314 int manualContourBaseControler::GetState()
315 {
316         return _state;
317 }
318 // ----------------------------------------------------------------------------
319 bool manualContourBaseControler::IsEditable( )
320 {
321         return _editable;
322 }
323 // ----------------------------------------------------------------------------
324 void manualContourBaseControler::SetEditable(  bool condition  )
325 {
326         if (GetManualViewBaseContour()!=NULL) {
327                 if( !condition )
328                 {
329                         GetManualViewBaseContour()->RemoveControlPoints();
330                 }
331                 GetManualViewBaseContour()->SetSelected( condition );
332         }
333         _editable = condition;
334 }
335
336 // ----------------------------------------------------------------------------
337 bool manualContourBaseControler::GetPosibleToMove()
338 {
339         return _posibleToMove;
340 }
341 // ----------------------------------------------------------------------------
342 void manualContourBaseControler::SetPosibleToMove( bool condition )
343 {
344         _posibleToMove = condition;
345 }
346 // ----------------------------------------------------------------------------
347 bool manualContourBaseControler::IsMoving()
348 {
349         return _moving;
350 }
351 // ----------------------------------------------------------------------------
352 void manualContourBaseControler::SetMoving( bool condition )
353 {
354         _moving = condition;
355 }
356 // ----------------------------------------------------------------------------
357 void manualContourBaseControler::SetCompleteCreation( bool condition )
358 {
359         _created = condition;
360 }
361 // ----------------------------------------------------------------------------
362 bool manualContourBaseControler::GetIfCompleteCreation ( )
363 {
364         return _created;
365 }
366 // ----------------------------------------------------------------------------
367 void manualContourBaseControler::SetKeyBoardMoving( bool condition )
368 {
369         _keyBoardMoving = condition;
370 }
371 // ----------------------------------------------------------------------------
372 bool manualContourBaseControler::GetKeyBoardMoving(  )
373 {
374         return _keyBoardMoving;
375 }
376 // ----------------------------------------------------------------------------
377 void manualContourBaseControler::CreateNewManualContour(){
378         _manViewBaseCont->CreateNewContour();
379 }
380 // ----------------------------------------------------------------------------
381 int     manualContourBaseControler::GetNumberOfPointsManualContour(){
382         return _manViewBaseCont->GetNumberOfPoints();
383 }
384 // ----------------------------------------------------------------------------
385
386 //JSTG - 25-02-08 -------------------------------------------------------------
387 int     manualContourBaseControler::GetNumberOfPointsSplineManualContour(){
388         //return _manViewBaseCont->GetNumberOfPointsSpline();
389         return _manContModel->GetNumberOfPointsSpline();
390 }
391 // ----------------------------------------------------------------------------
392
393 double* manualContourBaseControler::GetVectorPointsXManualContour(){
394         return _manViewBaseCont->GetVectorPointsXManualContour();
395 }
396 // ----------------------------------------------------------------------------
397 double* manualContourBaseControler::GetVectorPointsYManualContour(){
398         return _manViewBaseCont->GetVectorPointsYManualContour();
399 }
400 // ----------------------------------------------------------------------------
401 void manualContourBaseControler::DeleteContour(){
402         _manViewBaseCont->DeleteContour();
403         _manContModel->DeleteAllPoints();
404 }
405 // ----------------------------------------------------------------------------
406 void manualContourBaseControler::DeleteActualMousePoint(int x, int y)// virtual
407 {
408         if ((_manContModel!=NULL) && (_manViewBaseCont!=NULL) )
409         {
410                 int id=_manViewBaseCont->GetIdPoint(x,y,GetZ());
411                 if ((id!=-1) && (_manContModel->GetSizeLstPoints()>2) ){
412                         _manContModel->DeletePoint(id);
413                         _manViewBaseCont->DeletePoint(id);
414                 }
415         }
416         _state = 0;
417 }
418
419 // ----------------------------------------------------------------------------
420 void manualContourBaseControler::Magnet(int x, int y)
421 {
422         if( IsEditable())
423         {
424                 /*int id= */ _manViewBaseCont->GetIdPoint(x,y,GetZ()); // JPRx
425                 if (GetManualContourModel()!=NULL){
426                         double  xx      = x;
427                         double  yy      = y;
428                         double  zz      = GetZ();
429                         GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
430                         int                     id      = GetManualContourModel()->GetIdPoint(xx,yy,zz,32000,-1);
431                         if (id!=-1)
432                         {
433                                 manualPoint     *mp     = GetManualContourModel()->GetManualPoint(id);
434                                 mp->SetPoint(xx,yy,zz);
435                         }
436         //              GetManualViewBaseContour()->UpdateViewPoint(id);
437                 }
438                 _state = 0;
439         }
440 }
441
442 // ----------------------------------------------------------------------------
443 void manualContourBaseControler::SetZ(int z)
444 {
445         _z=z;
446 }
447 // ----------------------------------------------------------------------------
448 int manualContourBaseControler::GetZ()
449 {
450         return _z;
451 }
452 // ----------------------------------------------------------------------------
453 void manualContourBaseControler::AddPoint(int x, int y, int z) // virtual
454 {
455         if (GetManualContourModel()!=NULL){
456                 double  xx      = x;
457                 double  yy      = y;
458                 double  zz      = z;
459                 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
460                 /*int   id              =*/  GetManualContourModel()->AddPoint(xx,yy,zz);  // JPRx
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                 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
495                 manualPoint             *mp             = _manContModel->GetManualPoint(id);
496                 mp->SetPoint(xx,yy,zz);
497                 GetManualViewBaseContour()->UpdateViewPoint(id);
498         }
499 }
500 // ----------------------------------------------------------------------------
501 void manualContourBaseControler::SetPointX( int id ,int x  ){
502         if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
503                 double xx = x;
504                 double yy = 0;
505                 double zz = 0;
506                 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
507                 manualPoint             *mp             = _manContModel->GetManualPoint(id);
508                 mp->SetPointX(xx);
509                 GetManualViewBaseContour()->UpdateViewPoint(id);
510         }
511 }
512 // ----------------------------------------------------------------------------
513 void manualContourBaseControler::SetPointY( int id ,int y  ){
514         if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
515                 double xx = 0;
516                 double yy = y;
517                 double zz = 0;
518                 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
519                 manualPoint             *mp             = _manContModel->GetManualPoint(id);
520                 mp->SetPointY(yy);
521                 GetManualViewBaseContour()->UpdateViewPoint(id);
522         }
523 }
524 // ----------------------------------------------------------------------------
525 void manualContourBaseControler::SetPointZ( int id ,int z  ){
526         if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
527                 double xx = 0;
528                 double yy = 0;
529                 double zz = z;
530                 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
531                 manualPoint             *mp             = _manContModel->GetManualPoint(id);
532                 mp->SetPointZ(zz);
533                 GetManualViewBaseContour()->UpdateViewPoint(id);
534         }
535 }
536 // ----------------------------------------------------------------------------
537 void manualContourBaseControler::ResetContour() // virtual
538 {
539         this->DeleteContour();
540         GetManualViewBaseContour()->CreateNewContour();
541         this->SetState(0);
542 }
543