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