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