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