Salome HOME
Fix for bug 10502. It was uninitialized pointer fields in SVTK_InteractorStyle.
[modules/gui.git] / src / SVTK / SVTK_InteractorStyle.cxx
1 //  SALOME VTKViewer : build VTK viewer into Salome desktop
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SVTK_InteractorStyle.cxx
25 //  Author : Christophe ATTANASIO
26 //  Module : SALOME
27 //  $Header$
28
29
30 #include "SVTK_InteractorStyle.h"
31
32 #include "VTKViewer_CellRectPicker.h"
33 #include "VTKViewer_Utilities.h"
34 #include "VTKViewer_RectPicker.h"
35
36 #include "SVTK_RenderWindowInteractor.h"
37 #include "SVTK_RenderWindow.h"
38 #include "SVTK_ViewWindow.h"
39
40 #include "SALOME_Actor.h"
41 #include "SVTK_Actor.h"
42 #include "SVTK_Selector.h"
43
44 #include "SALOME_ListIteratorOfListIO.hxx"
45 #include "SALOME_ListIO.hxx"
46
47 #include "SUIT_Session.h"
48 #include "CAM_Application.h"
49
50 #include <vtkObjectFactory.h>
51 #include <vtkMath.h>
52 #include <vtkCommand.h>
53 #include <vtkCamera.h>
54 #include <vtkRenderer.h>
55 #include <vtkPicker.h>
56 #include <vtkPointPicker.h>
57 #include <vtkCellPicker.h>
58 #include <vtkLine.h> 
59 #include <vtkMapper.h>
60 #include <vtkDataSet.h>
61 #include <vtkSmartPointer.h>
62 #include <vtkRenderWindow.h>
63
64 #include <qapplication.h>
65 //VRV: porting on Qt 3.0.5
66 #if QT_VERSION >= 0x030005
67 #include <qpainter.h>
68 #endif
69 //VRV: porting on Qt 3.0.5
70 #include <algorithm>
71
72 using namespace std;
73
74
75 namespace
76 {
77   int
78   GetEdgeId(vtkPicker *thePicker, SALOME_Actor *theActor, int theObjId)
79   {
80     int anEdgeId = -1;
81     if (vtkCell* aPickedCell = theActor->GetElemCell(theObjId)) {
82       float aPickPosition[3];
83       thePicker->GetPickPosition(aPickPosition);
84       float aMinDist = 1000000.0, aDist = 0;
85       for (int i = 0, iEnd = aPickedCell->GetNumberOfEdges(); i < iEnd; i++){
86         if(vtkLine* aLine = vtkLine::SafeDownCast(aPickedCell->GetEdge(i))){
87           int subId;  float pcoords[3], closestPoint[3], weights[3];
88           aLine->EvaluatePosition(aPickPosition,closestPoint,subId,pcoords,aDist,weights);
89           if (aDist < aMinDist) {
90             aMinDist = aDist;
91             anEdgeId = i;
92           }
93         }
94       }
95     }
96     return anEdgeId;
97   }
98   
99
100   
101   bool CheckDimensionId(Selection_Mode theMode, SALOME_Actor *theActor, vtkIdType theObjId){
102     switch(theMode){
103     case CellSelection:
104       return true;
105     case EdgeSelection:
106       return ( theActor->GetObjDimension( theObjId ) == 1 );
107     case FaceSelection:
108       return ( theActor->GetObjDimension( theObjId ) == 2 );
109     case VolumeSelection:
110       return ( theActor->GetObjDimension( theObjId ) == 3 );
111     };
112     return false;
113   }
114 }  
115   
116 //----------------------------------------------------------------------------
117 vtkStandardNewMacro(SVTK_InteractorStyle);
118 //----------------------------------------------------------------------------
119
120 SVTK_InteractorStyle
121 ::SVTK_InteractorStyle() 
122 {
123   myPreViewActor = NULL;
124   myInteractor = NULL;
125   myViewWindow = NULL;
126   myGUIWindow = NULL;
127   this->MotionFactor = 10.0;
128   this->State = VTK_INTERACTOR_STYLE_CAMERA_NONE;
129   this->RadianToDegree = 180.0 / vtkMath::Pi();
130   this->ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
131   loadCursors();
132
133   myPreSelectionActor = SVTK_Actor::New();
134   myPreSelectionActor->GetProperty()->SetColor(0,1,1);
135   myPreSelectionActor->GetProperty()->SetLineWidth(5);
136   myPreSelectionActor->GetProperty()->SetPointSize(5);
137
138   OnSelectionModeChanged();
139 }
140
141 //----------------------------------------------------------------------------
142 SVTK_InteractorStyle
143 ::~SVTK_InteractorStyle() 
144 {
145   myViewWindow->RemoveActor(myPreSelectionActor);
146 }
147
148 //----------------------------------------------------------------------------
149 SVTK_Selector*
150 SVTK_InteractorStyle
151 ::GetSelector() 
152 {
153   return myViewWindow->GetSelector();
154 }
155
156 //----------------------------------------------------------------------------
157 void
158 SVTK_InteractorStyle
159 ::setPreselectionProp(const double& theRed, 
160                       const double& theGreen, 
161                       const double& theBlue, 
162                       const int& theWidth) 
163 {
164   if ( myPreSelectionActor->GetProperty() == 0 )
165     return;
166   myPreSelectionActor->GetProperty()->SetColor(theRed, theGreen, theBlue);
167   myPreSelectionActor->GetProperty()->SetLineWidth(theWidth);
168   myPreSelectionActor->GetProperty()->SetPointSize(theWidth);
169 }
170
171 //----------------------------------------------------------------------------
172 void
173 SVTK_InteractorStyle
174 ::SetInteractor(vtkRenderWindowInteractor *theInteractor)
175 {
176   myInteractor = dynamic_cast<SVTK_RenderWindowInteractor*>(theInteractor);
177   Superclass::SetInteractor(theInteractor);
178 }
179
180 //----------------------------------------------------------------------------
181 int
182 SVTK_InteractorStyle
183 ::GetState()
184 {
185   return State | ForcedState;
186 }
187
188 //----------------------------------------------------------------------------
189 void 
190 SVTK_InteractorStyle
191 ::setViewWindow(SVTK_ViewWindow* theViewWindow)
192 {
193   myViewWindow = theViewWindow;
194   myViewWindow->AddActor(myPreSelectionActor);
195   myPreSelectionActor->Delete();
196 }
197
198 //----------------------------------------------------------------------------
199 void
200 SVTK_InteractorStyle
201 ::setGUIWindow(QWidget* theWindow)
202 {
203   myGUIWindow = theWindow;
204 }
205
206 //----------------------------------------------------------------------------
207 void
208 SVTK_InteractorStyle
209 ::RotateXY(int dx, int dy)
210 {
211   double rxf;
212   double ryf;
213   vtkCamera *cam;
214   
215   if (this->CurrentRenderer == NULL)
216     {
217       return;
218     }
219   
220   int *size = this->CurrentRenderer->GetRenderWindow()->GetSize();
221   this->DeltaElevation = -20.0 / size[1];
222   this->DeltaAzimuth = -20.0 / size[0];
223   
224   rxf = (double)dx * this->DeltaAzimuth *  this->MotionFactor;
225   ryf = (double)dy * this->DeltaElevation * this->MotionFactor;
226   
227   cam = this->CurrentRenderer->GetActiveCamera();
228   cam->Azimuth(rxf);
229   cam->Elevation(ryf);
230   cam->OrthogonalizeViewUp();
231   ::ResetCameraClippingRange(this->CurrentRenderer); 
232   //this->Interactor->Render();
233   myGUIWindow->update();
234 }
235
236 //----------------------------------------------------------------------------
237 void
238 SVTK_InteractorStyle
239 ::PanXY(int x, int y, int oldX, int oldY)
240 {
241   TranslateView(x, y, oldX, oldY);   
242   //this->Interactor->Render();
243   myGUIWindow->update();
244 }
245
246
247 //----------------------------------------------------------------------------
248 void 
249 SVTK_InteractorStyle
250 ::DollyXY(int dx, int dy)
251 {
252   if (this->CurrentRenderer == NULL) return;
253
254   double dxf = this->MotionFactor * (double)(dx) / (double)(this->CurrentRenderer->GetCenter()[1]);
255   double dyf = this->MotionFactor * (double)(dy) / (double)(this->CurrentRenderer->GetCenter()[1]);
256
257   double zoomFactor = pow((double)1.1, dxf + dyf);
258   
259   vtkCamera *aCam = this->CurrentRenderer->GetActiveCamera();
260   if (aCam->GetParallelProjection())
261     aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
262   else{
263     aCam->Dolly(zoomFactor);
264     ::ResetCameraClippingRange(this->CurrentRenderer);
265   }
266
267   //this->Interactor->Render();
268   myGUIWindow->update();
269 }
270
271 //----------------------------------------------------------------------------
272 void 
273 SVTK_InteractorStyle
274 ::SpinXY(int x, int y, int oldX, int oldY)
275 {
276   vtkCamera *cam;
277
278   if (this->CurrentRenderer == NULL)
279     {
280       return;
281     }
282
283   double newAngle = atan2((double)(y - this->CurrentRenderer->GetCenter()[1]),
284                           (double)(x - this->CurrentRenderer->GetCenter()[0]));
285   double oldAngle = atan2((double)(oldY -this->CurrentRenderer->GetCenter()[1]),
286                           (double)(oldX - this->CurrentRenderer->GetCenter()[0]));
287   
288   newAngle *= this->RadianToDegree;
289   oldAngle *= this->RadianToDegree;
290
291   cam = this->CurrentRenderer->GetActiveCamera();
292   cam->Roll(newAngle - oldAngle);
293   cam->OrthogonalizeViewUp();
294       
295   //this->Interactor->Render();
296   myGUIWindow->update();
297 }
298
299
300 //----------------------------------------------------------------------------
301 void
302 SVTK_InteractorStyle
303 ::OnMouseMove(int vtkNotUsed(ctrl), 
304               int shift,
305               int x, int y) 
306 {
307   myShiftState = shift;
308   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
309     onOperation(QPoint(x, y));
310   else if (ForcedState == VTK_INTERACTOR_STYLE_CAMERA_NONE)
311     onCursorMove(QPoint(x, y));
312 }
313
314
315 //----------------------------------------------------------------------------
316 void
317 SVTK_InteractorStyle
318 ::OnLeftButtonDown(int ctrl, int shift, 
319                    int x, int y) 
320 {
321   if (this->HasObserver(vtkCommand::LeftButtonPressEvent)) {
322     this->InvokeEvent(vtkCommand::LeftButtonPressEvent,NULL);
323     return;
324   }
325   this->FindPokedRenderer(x, y);
326   if (this->CurrentRenderer == NULL) {
327     return;
328   }
329   myShiftState = shift;
330   // finishing current viewer operation
331   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
332     onFinishOperation();
333     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
334   }
335   myOtherPoint = myPoint = QPoint(x, y);
336   if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
337     startOperation(ForcedState);
338   } else {
339     if (ctrl)
340       startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
341     else
342       startOperation(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
343   }
344   return;
345 }
346
347
348 //----------------------------------------------------------------------------
349 void
350 SVTK_InteractorStyle
351 ::OnLeftButtonUp(int vtkNotUsed(ctrl),
352                  int shift, 
353                  int vtkNotUsed(x),
354                  int vtkNotUsed(y))
355 {
356   myShiftState = shift;
357   // finishing current viewer operation
358   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
359     onFinishOperation();
360     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
361   }
362 }
363
364
365 //----------------------------------------------------------------------------
366 void
367 SVTK_InteractorStyle
368 ::OnMiddleButtonDown(int ctrl,
369                      int shift, 
370                      int x, int y) 
371 {
372   if (this->HasObserver(vtkCommand::MiddleButtonPressEvent)) 
373     {
374       this->InvokeEvent(vtkCommand::MiddleButtonPressEvent,NULL);
375       return;
376     }
377   this->FindPokedRenderer(x, y);
378   if (this->CurrentRenderer == NULL)
379     {
380       return;
381     }
382   myShiftState = shift;
383   // finishing current viewer operation
384   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
385     onFinishOperation();
386     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
387   }
388   myOtherPoint = myPoint = QPoint(x, y);
389   if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
390     startOperation(ForcedState);
391   }
392   else {
393     if (ctrl)
394       startOperation(VTK_INTERACTOR_STYLE_CAMERA_PAN);
395   }
396 }
397
398
399 //----------------------------------------------------------------------------
400 void
401 SVTK_InteractorStyle
402 ::OnMiddleButtonUp(int vtkNotUsed(ctrl),
403                    int shift, 
404                    int vtkNotUsed(x),
405                    int vtkNotUsed(y))
406 {
407   myShiftState = shift;
408   // finishing current viewer operation
409   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
410     onFinishOperation();
411     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
412   }
413 }
414
415
416 //----------------------------------------------------------------------------
417 void
418 SVTK_InteractorStyle
419 ::OnRightButtonDown(int ctrl,
420                     int shift, 
421                     int x, int y) 
422 {
423   if (this->HasObserver(vtkCommand::RightButtonPressEvent)) 
424     {
425       this->InvokeEvent(vtkCommand::RightButtonPressEvent,NULL);
426       return;
427     }
428   this->FindPokedRenderer(x, y);
429   if (this->CurrentRenderer == NULL)
430     {
431       return;
432     }
433   myShiftState = shift;
434   // finishing current viewer operation
435   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
436     onFinishOperation();
437     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
438   }
439   myOtherPoint = myPoint = QPoint(x, y);
440   if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
441     startOperation(ForcedState);
442   }
443   else {
444     if (ctrl)
445       startOperation(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);  
446   }
447 }
448
449 //----------------------------------------------------------------------------
450 void
451 SVTK_InteractorStyle
452 ::OnRightButtonUp(int vtkNotUsed(ctrl),
453                   int shift, 
454                   int vtkNotUsed(x),
455                   int vtkNotUsed(y))
456 {
457   myShiftState = shift;
458   // finishing current viewer operation
459   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
460     onFinishOperation();
461     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
462   }
463 }
464
465 //----------------------------------------------------------------------------
466 /* XPM */
467 const char* imageZoomCursor[] = { 
468 "32 32 3 1",
469 ". c None",
470 "a c #000000",
471 "# c #ffffff",
472 "................................",
473 "................................",
474 ".#######........................",
475 "..aaaaaaa.......................",
476 "................................",
477 ".............#####..............",
478 "...........##.aaaa##............",
479 "..........#.aa.....a#...........",
480 ".........#.a.........#..........",
481 ".........#a..........#a.........",
482 "........#.a...........#.........",
483 "........#a............#a........",
484 "........#a............#a........",
485 "........#a............#a........",
486 "........#a............#a........",
487 ".........#...........#.a........",
488 ".........#a..........#a.........",
489 ".........##.........#.a.........",
490 "........#####.....##.a..........",
491 ".......###aaa#####.aa...........",
492 "......###aa...aaaaa.......#.....",
493 ".....###aa................#a....",
494 "....###aa.................#a....",
495 "...###aa...............#######..",
496 "....#aa.................aa#aaaa.",
497 ".....a....................#a....",
498 "..........................#a....",
499 "...........................a....",
500 "................................",
501 "................................",
502 "................................",
503 "................................"};
504
505 const char* imageRotateCursor[] = { 
506 "32 32 3 1",
507 ". c None",
508 "a c #000000",
509 "# c #ffffff",
510 "................................",
511 "................................",
512 "................................",
513 "................................",
514 "........#.......................",
515 ".......#.a......................",
516 "......#######...................",
517 ".......#aaaaa#####..............",
518 "........#..##.a#aa##........##..",
519 ".........a#.aa..#..a#.....##.aa.",
520 ".........#.a.....#...#..##.aa...",
521 ".........#a.......#..###.aa.....",
522 "........#.a.......#a..#aa.......",
523 "........#a.........#..#a........",
524 "........#a.........#a.#a........",
525 "........#a.........#a.#a........",
526 "........#a.........#a.#a........",
527 ".........#.........#a#.a........",
528 "........##a........#a#a.........",
529 "......##.a#.......#.#.a.........",
530 "....##.aa..##.....##.a..........",
531 "..##.aa.....a#####.aa...........",
532 "...aa.........aaa#a.............",
533 "................#.a.............",
534 "...............#.a..............",
535 "..............#.a...............",
536 "...............a................",
537 "................................",
538 "................................",
539 "................................",
540 "................................",
541 "................................"};
542
543
544 //----------------------------------------------------------------------------
545 // loads cursors for viewer operations - zoom, pan, etc...
546 void
547 SVTK_InteractorStyle
548 ::loadCursors()
549 {
550   myDefCursor       = QCursor(ArrowCursor);
551   myHandCursor      = QCursor(PointingHandCursor);
552   myPanCursor       = QCursor(SizeAllCursor);
553   myZoomCursor      = QCursor(QPixmap(imageZoomCursor));
554   myRotateCursor    = QCursor(QPixmap(imageRotateCursor));
555   mySpinCursor      = QCursor(QPixmap(imageRotateCursor)); // temporarly !!!!!!
556   myGlobalPanCursor = QCursor(CrossCursor);
557   myCursorState     = false;
558 }
559
560
561 //----------------------------------------------------------------------------
562 // event filter - controls mouse and keyboard events during viewer operations
563 bool
564 SVTK_InteractorStyle
565 ::eventFilter(QObject* object, QEvent* event)
566 {
567   if (!myGUIWindow) return false;
568   if ( (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::KeyPress) && object != myGUIWindow)
569   {
570     qApp->removeEventFilter(this);
571     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
572   }
573   return QObject::eventFilter(object, event);
574 }
575
576
577 //----------------------------------------------------------------------------
578 // starts Zoom operation (e.g. through menu command)
579 void
580 SVTK_InteractorStyle
581 ::startZoom()
582 {
583   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
584   {
585     onFinishOperation();
586     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
587   }
588   setCursor(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
589   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ZOOM;
590   qApp->installEventFilter(this);
591 }
592
593
594 //----------------------------------------------------------------------------
595 // starts Pan operation (e.g. through menu command)
596 void
597 SVTK_InteractorStyle
598 ::startPan()
599 {
600   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
601   {
602     onFinishOperation();
603     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
604   }
605   setCursor(VTK_INTERACTOR_STYLE_CAMERA_PAN);
606   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_PAN;
607   qApp->installEventFilter(this);
608 }
609
610 //----------------------------------------------------------------------------
611 // starts Rotate operation (e.g. through menu command)
612 void 
613 SVTK_InteractorStyle
614 ::startRotate()
615 {
616   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
617   {
618     onFinishOperation();
619     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
620   }
621   setCursor(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
622   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ROTATE;
623   qApp->installEventFilter(this);
624 }
625
626
627 //----------------------------------------------------------------------------
628 // starts Spin operation (e.g. through menu command)
629 void
630 SVTK_InteractorStyle
631 ::startSpin()
632 {
633   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
634   {
635     onFinishOperation();
636     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
637   }
638   setCursor(VTK_INTERACTOR_STYLE_CAMERA_SPIN);
639   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_SPIN;
640   qApp->installEventFilter(this);
641 }
642
643
644
645 //----------------------------------------------------------------------------
646 // starts Fit Area operation (e.g. through menu command)
647 void
648 SVTK_InteractorStyle
649 ::startFitArea()
650 {
651   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
652   {
653     onFinishOperation();
654     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
655   }
656   setCursor(VTK_INTERACTOR_STYLE_CAMERA_FIT);
657   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_FIT;
658   qApp->installEventFilter(this);
659 }
660
661
662 //----------------------------------------------------------------------------
663 // starts Global Panning operation (e.g. through menu command)
664 void
665 SVTK_InteractorStyle
666 ::startGlobalPan()
667 {
668   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
669   {
670     onFinishOperation();
671     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
672   }
673   setCursor(VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN);
674   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN;
675
676   // store current zoom scale
677   vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
678   myScale = cam->GetParallelScale();
679
680   if (myViewWindow) myViewWindow->onFitAll();
681
682   if (myGUIWindow) myGUIWindow->update();
683   
684   qApp->installEventFilter(this);
685 }
686
687
688 //----------------------------------------------------------------------------
689 // returns TRUE if needs redrawing
690 bool
691 SVTK_InteractorStyle
692 ::needsRedrawing()
693 {
694   return State == VTK_INTERACTOR_STYLE_CAMERA_ZOOM   ||
695          State == VTK_INTERACTOR_STYLE_CAMERA_PAN    ||
696          State == VTK_INTERACTOR_STYLE_CAMERA_ROTATE ||
697          State == VTK_INTERACTOR_STYLE_CAMERA_SPIN   ||
698          State == VTK_INTERACTOR_STYLE_CAMERA_NONE;
699 }
700
701
702 //----------------------------------------------------------------------------
703 // fits viewer contents to rect
704 void
705 SVTK_InteractorStyle
706 ::fitRect(const int left, 
707           const int top, 
708           const int right, 
709           const int bottom)
710 {
711   if (this->CurrentRenderer == NULL) return;
712  
713   // move camera
714   int x = (left + right)/2;
715   int y = (top + bottom)/2;
716   int *aSize = this->CurrentRenderer->GetRenderWindow()->GetSize();
717   int oldX = aSize[0]/2;
718   int oldY = aSize[1]/2;
719   TranslateView(oldX, oldY, x, y);
720
721   // zoom camera
722   double dxf = (double)(aSize[0]) / (double)(abs(right - left));
723   double dyf = (double)(aSize[1]) / (double)(abs(bottom - top));
724   double zoomFactor = (dxf + dyf)/2 ;
725
726   vtkCamera *aCam = this->CurrentRenderer->GetActiveCamera();
727   if(aCam->GetParallelProjection())
728     aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
729   else{
730     aCam->Dolly(zoomFactor);
731     ::ResetCameraClippingRange(this->CurrentRenderer);
732   }
733   
734   myGUIWindow->update();
735 }
736
737
738 //----------------------------------------------------------------------------
739 // starts viewer operation (!internal usage!)
740 void
741 SVTK_InteractorStyle
742 ::startOperation(int operation)
743 {
744   switch(operation)
745   { 
746   case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
747   case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
748   case VTK_INTERACTOR_STYLE_CAMERA_PAN:
749   case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
750   case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
751   case VTK_INTERACTOR_STYLE_CAMERA_FIT:
752   case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
753     if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
754       startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
755     State = operation;
756     if (State != VTK_INTERACTOR_STYLE_CAMERA_SELECT)
757       setCursor(operation);
758     onStartOperation();
759     break;
760   case VTK_INTERACTOR_STYLE_CAMERA_NONE:
761   default:
762     setCursor(VTK_INTERACTOR_STYLE_CAMERA_NONE);
763     State = ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
764     break;
765   }
766 }
767
768
769 //----------------------------------------------------------------------------
770 // sets proper cursor for window when viewer operation is activated
771 void
772 SVTK_InteractorStyle
773 ::setCursor(const int operation)
774 {
775   if (!myGUIWindow) return;
776   switch (operation)
777   {
778     case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
779       myGUIWindow->setCursor(myZoomCursor); 
780       myCursorState = true;
781       break;
782     case VTK_INTERACTOR_STYLE_CAMERA_PAN:
783       myGUIWindow->setCursor(myPanCursor); 
784       myCursorState = true;
785       break;
786     case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
787       myGUIWindow->setCursor(myRotateCursor); 
788       myCursorState = true;
789       break;
790     case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
791       myGUIWindow->setCursor(mySpinCursor); 
792       myCursorState = true;
793       break;
794     case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
795       myGUIWindow->setCursor(myGlobalPanCursor); 
796       myCursorState = true;
797       break;
798     case VTK_INTERACTOR_STYLE_CAMERA_FIT:
799     case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
800       myGUIWindow->setCursor(myHandCursor); 
801       myCursorState = true;
802       break;
803     case VTK_INTERACTOR_STYLE_CAMERA_NONE:
804     default:
805       myGUIWindow->setCursor(myDefCursor); 
806       myCursorState = false;
807       break;
808   }
809 }
810
811
812 //----------------------------------------------------------------------------
813 // called when viewer operation started (!put necessary initialization here!)
814 void
815 SVTK_InteractorStyle
816 ::onStartOperation()
817 {
818   if (!myGUIWindow) return;
819   // VSV: LOD actor activisation
820   //  this->Interactor->GetRenderWindow()->SetDesiredUpdateRate(this->Interactor->GetDesiredUpdateRate());
821   switch (State) {
822     case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
823     case VTK_INTERACTOR_STYLE_CAMERA_FIT:
824     {
825       QPainter p(myGUIWindow);
826       p.setPen(Qt::lightGray);
827       p.setRasterOp(Qt::XorROP);
828       p.drawRect(QRect(myPoint, myOtherPoint));
829       break;
830     }
831     case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
832     case VTK_INTERACTOR_STYLE_CAMERA_PAN:
833     case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
834     case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
835     case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
836       break;
837   }
838 }
839
840
841 //----------------------------------------------------------------------------
842 // called when viewer operation finished (!put necessary post-processing here!)
843 void
844 SVTK_InteractorStyle
845 ::onFinishOperation() 
846 {
847   if (!myGUIWindow) 
848     return;
849
850   // VSV: LOD actor activisation
851   //  rwi->GetRenderWindow()->SetDesiredUpdateRate(rwi->GetStillUpdateRate());
852
853   Selection_Mode aSelectionMode = myViewWindow->SelectionMode();
854   bool aSelActiveCompOnly = false;
855
856   QString aComponentDataType;
857   if(SUIT_Session* aSession = SUIT_Session::session())
858     if(SUIT_Application* aSUITApp = aSession->activeApplication())
859       if(CAM_Application* aCAMApp = dynamic_cast<CAM_Application*>(aSUITApp))
860         if(CAM_Module* aModule = aCAMApp->activeModule())
861           aComponentDataType = aModule->name();
862
863   switch (State) {
864     case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
865     case VTK_INTERACTOR_STYLE_CAMERA_FIT:
866     {
867       QPainter p(myGUIWindow);
868       p.setPen(Qt::lightGray);
869       p.setRasterOp(Qt::XorROP);
870       QRect rect(myPoint, myOtherPoint);
871       p.drawRect(rect);
872       rect = rect.normalize();
873       if (State == VTK_INTERACTOR_STYLE_CAMERA_FIT) {
874         // making fit rect opeation 
875         int w, h;
876         myInteractor->GetSize(w, h);
877         int x1, y1, x2, y2;
878         x1 = rect.left(); 
879         y1 = h - rect.top() - 1;
880         x2 = rect.right(); 
881         y2 = h - rect.bottom() - 1;
882         fitRect(x1, y1, x2, y2);
883       }
884       else {
885         if (myPoint == myOtherPoint) {
886           // process point selection
887           int w, h, x, y;
888           myInteractor->GetSize(w, h);
889           x = myPoint.x(); 
890           y = h - myPoint.y() - 1;
891
892           this->FindPokedRenderer(x, y);
893           myInteractor->StartPickCallback();
894
895           vtkPicker* aPicker = vtkPicker::SafeDownCast(myInteractor->GetPicker());
896           aPicker->Pick(x, y, 0.0, this->CurrentRenderer);
897     
898           SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aPicker->GetActor());
899
900           if (vtkCellPicker* picker = vtkCellPicker::SafeDownCast(aPicker)) {
901             int aVtkId = picker->GetCellId();
902             if ( aVtkId >= 0 && aSActor && aSActor->hasIO() && IsValid( aSActor, aVtkId ) ) {
903               int anObjId = aSActor->GetElemObjId(aVtkId);
904               if(anObjId >= 0){
905                 Handle(SALOME_InteractiveObject) anIO = aSActor->getIO();
906                 if(aSelectionMode != EdgeOfCellSelection) {
907                   if(CheckDimensionId(aSelectionMode,aSActor,anObjId)){
908                     if (GetSelector()->IsSelected(anIO)) {
909                       // This IO is already in the selection
910                       GetSelector()->AddOrRemoveIndex(anIO,anObjId,myShiftState);
911                     } else {
912                       if (!myShiftState) {
913                         this->HighlightProp( NULL );
914                         GetSelector()->ClearIObjects();
915                       }
916                       GetSelector()->AddOrRemoveIndex(anIO,anObjId,myShiftState);
917                       GetSelector()->AddIObject(aSActor);
918                     }
919                   }
920                 }else{
921                   if (!myShiftState) {
922                     this->HighlightProp( NULL );
923                     GetSelector()->ClearIObjects();
924                   }
925                   int anEdgeId = GetEdgeId(picker,aSActor,anObjId);
926                   if (anEdgeId >= 0) {
927                     GetSelector()->AddOrRemoveIndex(anIO,anObjId,false);
928                     GetSelector()->AddOrRemoveIndex(anIO,-anEdgeId-1,true);
929                     GetSelector()->AddIObject(aSActor);
930                   } 
931                 }
932               }
933             } else {
934               this->HighlightProp( NULL );
935               GetSelector()->ClearIObjects();
936             }
937           } else if ( vtkPointPicker* picker = vtkPointPicker::SafeDownCast(aPicker) ) {
938             int aVtkId = picker->GetPointId();
939             if ( aVtkId >= 0 && IsValid( aSActor, aVtkId, true ) ) {
940               if ( aSActor && aSActor->hasIO() ) {
941                 int anObjId = aSActor->GetNodeObjId(aVtkId);
942                 if(anObjId >= 0){
943                   Handle(SALOME_InteractiveObject) anIO = aSActor->getIO();
944                   if(GetSelector()->IsSelected(anIO)) {
945                     // This IO is already in the selection
946                     GetSelector()->AddOrRemoveIndex(anIO,anObjId,myShiftState);
947                   } else {
948                     if(!myShiftState) {
949                       this->HighlightProp( NULL );
950                       GetSelector()->ClearIObjects();
951                     }
952                     GetSelector()->AddOrRemoveIndex(anIO,anObjId,myShiftState);
953                     GetSelector()->AddIObject(aSActor);
954                   }
955                 }
956               }
957             } else {
958               this->HighlightProp( NULL );
959               GetSelector()->ClearIObjects();
960             } 
961           } else {
962             if ( aSActor && aSActor->hasIO() ) {
963               this->PropPicked++;
964               Handle(SALOME_InteractiveObject) anIO = aSActor->getIO();
965               if(GetSelector()->IsSelected(anIO)) {
966                 // This IO is already in the selection
967                 if(myShiftState) {
968                   GetSelector()->RemoveIObject(aSActor);
969                 }
970               }
971               else {
972                 if(!myShiftState) {
973                   this->HighlightProp( NULL );
974                   GetSelector()->ClearIObjects();
975                 }
976                 GetSelector()->AddIObject(aSActor);
977               }
978             }else{
979               // No selection clear all
980               this->PropPicked = 0;
981               this->HighlightProp( NULL );
982               GetSelector()->ClearIObjects();
983             }
984           }
985           myInteractor->EndPickCallback();
986         } else {
987           //processing rectangle selection
988           if(aSelActiveCompOnly && aComponentDataType.isEmpty()) return;
989           myInteractor->StartPickCallback();
990
991           if (!myShiftState) {
992             this->PropPicked = 0;
993             this->HighlightProp( NULL );
994             GetSelector()->ClearIObjects();
995           }
996
997           // Compute bounds
998           //      vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
999           QRect rect(myPoint, myOtherPoint);
1000           rect = rect.normalize();
1001           int w, h;
1002           myInteractor->GetSize(w, h);
1003           int x1, y1, x2, y2;
1004           x1 = rect.left(); 
1005           y1 = h - rect.top() - 1;
1006           x2 = rect.right(); 
1007           y2 = h - rect.bottom() - 1;
1008
1009           switch (aSelectionMode) {
1010           case NodeSelection: {
1011             if ( vtkPointPicker* aPointPicker = vtkPointPicker::SafeDownCast(myInteractor->GetPicker()) ) {
1012               vtkActorCollection* aListActors = this->CurrentRenderer->GetActors();
1013               aListActors->InitTraversal();
1014               while (vtkActor* aActor = aListActors->GetNextActor()) {
1015                 if (!aActor->GetVisibility()) 
1016                   continue;
1017                 if(SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)) {
1018                   if (aSActor->hasIO()) {
1019                     Handle(SALOME_InteractiveObject) anIO = aSActor->getIO();
1020                     if (anIO.IsNull()) 
1021                       continue;
1022                     if (aSelActiveCompOnly && aComponentDataType != anIO->getComponentDataType())
1023                       continue;
1024                     if (vtkDataSet* aDataSet = aSActor->GetInput()) {
1025                       TColStd_MapOfInteger anIndices;
1026                       for(int i = 0; i < aDataSet->GetNumberOfPoints(); i++) {
1027                         float aPoint[3];
1028                         aDataSet->GetPoint(i,aPoint);
1029                         if (IsInRect(aPoint,x1,y1,x2,y2)){
1030                           float aDisp[3];
1031                           ComputeWorldToDisplay(aPoint[0],aPoint[1],aPoint[2],aDisp);
1032                           if(aPointPicker->Pick(aDisp[0],aDisp[1],0.0,CurrentRenderer)){
1033                             if(vtkActorCollection *anActorCollection = aPointPicker->GetActors()){
1034                               if(anActorCollection->IsItemPresent(aSActor)){
1035                                 float aPickedPoint[3];
1036                                 aPointPicker->GetMapperPosition(aPickedPoint);
1037                                 vtkIdType aVtkId = aDataSet->FindPoint(aPickedPoint);
1038                                 if ( aVtkId >= 0 && IsValid( aSActor, aVtkId, true ) ){
1039                                   int anObjId = aSActor->GetNodeObjId(aVtkId);
1040                                   anIndices.Add(anObjId);
1041                                 }
1042                               }
1043                             }
1044                           }
1045                         }
1046                       }
1047                       if (!anIndices.IsEmpty()) {
1048                         GetSelector()->AddOrRemoveIndex(anIO,anIndices,true); // ENK false to true
1049                         GetSelector()->AddIObject(aSActor);
1050                         anIndices.Clear();
1051                       }else{
1052                         GetSelector()->RemoveIObject(aSActor);
1053                       }
1054                     }
1055                   }
1056                 }
1057               }
1058             }
1059             break;
1060           }
1061           case CellSelection:
1062           case EdgeOfCellSelection:
1063           case EdgeSelection:
1064           case FaceSelection:
1065           case VolumeSelection: 
1066             {
1067               vtkSmartPointer<VTKViewer_CellRectPicker> picker = VTKViewer_CellRectPicker::New();
1068               picker->SetTolerance(0.001);
1069               picker->Pick(x1, y1, 0.0, x2, y2, 0.0, this->CurrentRenderer);
1070               
1071               vtkActorCollection* aListActors = picker->GetActors();
1072               aListActors->InitTraversal();
1073               while(vtkActor* aActor = aListActors->GetNextActor()) {
1074                 if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)) {
1075                   if (aSActor->hasIO()) {
1076                     Handle(SALOME_InteractiveObject) anIO = aSActor->getIO();
1077                     if (aSelActiveCompOnly && aComponentDataType != anIO->getComponentDataType())
1078                       continue;
1079                     VTKViewer_CellDataSet cellList = picker->GetCellData(aActor);
1080                     if ( !cellList.empty() ) {
1081                       TColStd_MapOfInteger anIndexes;
1082                       VTKViewer_CellDataSet::iterator it;
1083                       for ( it = cellList.begin(); it != cellList.end(); ++it ) {
1084                         int aCellId = (*it).cellId;
1085                         
1086                         if ( !IsValid( aSActor, aCellId ) )
1087                           continue;
1088                         
1089                         int anObjId = aSActor->GetElemObjId(aCellId);
1090                         if (anObjId != -1){
1091                           if ( CheckDimensionId(aSelectionMode,aSActor,anObjId) ) {
1092                             anIndexes.Add(anObjId);
1093                           }
1094                         }
1095                       }
1096                       GetSelector()->AddOrRemoveIndex(anIO,anIndexes,true);
1097                       GetSelector()->AddIObject(aSActor);
1098                     }
1099                   }
1100                 }
1101               }
1102             }
1103             break;          
1104           case ActorSelection: // objects selection
1105             {
1106               vtkSmartPointer<VTKViewer_RectPicker> picker = VTKViewer_RectPicker::New();
1107               picker->SetTolerance(0.001);
1108               picker->Pick(x1, y1, 0.0, x2, y2, 0.0, this->CurrentRenderer);
1109
1110               vtkActorCollection* aListActors = picker->GetActors();
1111               aListActors->InitTraversal();
1112               while(vtkActor* aActor = aListActors->GetNextActor()) {
1113                 if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)) {
1114                   if (aSActor->hasIO()) {
1115                     Handle(SALOME_InteractiveObject) anIO = aSActor->getIO();
1116                     GetSelector()->AddIObject(aSActor);
1117                     this->PropPicked++;
1118                   }
1119                 }
1120               }
1121             } // end case 4
1122           } //end switch
1123           myInteractor->EndPickCallback();
1124         }
1125         myViewWindow->onSelectionChanged();
1126       } 
1127     } 
1128     break;
1129   case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
1130   case VTK_INTERACTOR_STYLE_CAMERA_PAN:
1131   case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
1132   case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
1133     break;
1134   case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN: 
1135     {
1136       int w, h, x, y;
1137       myInteractor->GetSize(w, h);
1138       x = myPoint.x(); 
1139       y = h - myPoint.y() - 1;
1140       Place(x, y);
1141     }
1142     break;
1143   }
1144   if (myGUIWindow) myGUIWindow->update();
1145
1146 }
1147
1148
1149 // called during viewer operation when user moves mouse (!put necessary processing here!)
1150 void
1151 SVTK_InteractorStyle
1152 ::onOperation(QPoint mousePos) 
1153 {
1154   if (!myGUIWindow) return;
1155   int w, h;
1156   GetInteractor()->GetSize(w, h);
1157   switch (State) {
1158   case VTK_INTERACTOR_STYLE_CAMERA_PAN: 
1159     {
1160       // processing panning
1161       //this->FindPokedCamera(mousePos.x(), mousePos.y());
1162       this->PanXY(mousePos.x(), myPoint.y(), myPoint.x(), mousePos.y());
1163       myPoint = mousePos;
1164       break;
1165     }
1166   case VTK_INTERACTOR_STYLE_CAMERA_ZOOM: 
1167     {    
1168       // processing zooming
1169       //this->FindPokedCamera(mousePos.x(), mousePos.y());
1170       this->DollyXY(mousePos.x() - myPoint.x(), mousePos.y() - myPoint.y());
1171       myPoint = mousePos;
1172       break;
1173     }
1174   case VTK_INTERACTOR_STYLE_CAMERA_ROTATE: 
1175     {
1176       // processing rotation
1177       //this->FindPokedCamera(mousePos.x(), mousePos.y());
1178       this->RotateXY(mousePos.x() - myPoint.x(), myPoint.y() - mousePos.y());
1179       myPoint = mousePos;
1180       break;
1181     }
1182   case VTK_INTERACTOR_STYLE_CAMERA_SPIN: 
1183     {
1184       // processing spinning
1185       //this->FindPokedCamera(mousePos.x(), mousePos.y());
1186       this->SpinXY(mousePos.x(), mousePos.y(), myPoint.x(), myPoint.y());
1187       myPoint = mousePos;
1188       break;
1189     }
1190   case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN: 
1191     {    
1192       break;
1193     }
1194   case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
1195     {
1196       if (!myCursorState)
1197         setCursor(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
1198     }
1199   case VTK_INTERACTOR_STYLE_CAMERA_FIT:
1200     {
1201       QPainter p(myGUIWindow);
1202       p.setPen(Qt::lightGray);
1203       p.setRasterOp(Qt::XorROP);
1204       p.drawRect(QRect(myPoint, myOtherPoint));
1205       myOtherPoint = mousePos;
1206       p.drawRect(QRect(myPoint, myOtherPoint));
1207       break;
1208     }
1209   }
1210   this->LastPos[0] = mousePos.x();
1211   this->LastPos[1] = h - mousePos.y() - 1;
1212 }
1213
1214 // called when selection mode changed (!put necessary initialization here!)
1215 void
1216 SVTK_InteractorStyle
1217 ::OnSelectionModeChanged()
1218 {
1219   
1220   myPreSelectionActor->SetVisibility(false);
1221   myElemId = myEdgeId = myNodeId = -1;
1222   mySelectedActor = NULL;
1223 }
1224
1225 // called when user moves mouse inside viewer window and there is no active viewer operation 
1226 // (!put necessary processing here!)
1227 void
1228 SVTK_InteractorStyle
1229 ::onCursorMove(QPoint mousePos) 
1230 {
1231   // processing highlighting
1232   Selection_Mode aSelectionMode = myViewWindow->SelectionMode();
1233
1234   int w, h, x, y;
1235   myInteractor->GetSize(w, h);
1236   x = mousePos.x(); y = h - mousePos.y() - 1;
1237
1238   this->FindPokedRenderer(x,y);
1239   myInteractor->StartPickCallback();
1240   myPreSelectionActor->SetVisibility(false);
1241
1242   vtkPicker* aPicker = vtkPicker::SafeDownCast(myInteractor->GetPicker());
1243   aPicker->Pick(x, y, 0.0, this->CurrentRenderer);
1244
1245   SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aPicker->GetActor());
1246
1247   if (aSActor && myPreSelectionActor){
1248     float aPos[3];
1249     aSActor->GetPosition(aPos);
1250     myPreSelectionActor->SetPosition(aPos);
1251   }
1252
1253   if (vtkCellPicker* picker = vtkCellPicker::SafeDownCast(aPicker)) {
1254     int aVtkId = picker->GetCellId();
1255     if ( aVtkId >= 0 ) {
1256       int anObjId = aSActor->GetElemObjId(aVtkId);
1257       if ( aSActor && aSActor->hasIO() && IsValid( aSActor, aVtkId ) ) {
1258         bool anIsSameObjId = (mySelectedActor == aSActor && myElemId == anObjId);
1259         bool aResult = anIsSameObjId;
1260         if(!anIsSameObjId) {
1261           if(aSelectionMode != EdgeOfCellSelection) {
1262             aResult = CheckDimensionId(aSelectionMode,aSActor,anObjId);
1263             if(aResult){
1264               mySelectedActor = aSActor;
1265               myElemId = anObjId;
1266               myInteractor->setCellData(anObjId,aSActor,myPreSelectionActor);
1267             }
1268           }
1269         }
1270         if(aSelectionMode == EdgeOfCellSelection){
1271           int anEdgeId = GetEdgeId(picker,aSActor,anObjId);
1272           bool anIsSameEdgeId = (myEdgeId != anEdgeId) && anIsSameObjId;
1273           aResult = anIsSameEdgeId;
1274           if(!anIsSameEdgeId) {
1275             aResult = (anEdgeId >= 0);
1276             if (aResult) {
1277               mySelectedActor = aSActor;
1278               myEdgeId = anEdgeId;
1279               myElemId = anObjId;
1280               myInteractor->setEdgeData(anObjId,aSActor,-anEdgeId-1,myPreSelectionActor);
1281             } 
1282           }
1283         }
1284         if(aResult) {
1285           myPreSelectionActor->GetProperty()->SetRepresentationToSurface();
1286           myPreSelectionActor->SetVisibility(true);
1287         }
1288       }
1289     }
1290   }
1291   else if (vtkPointPicker* picker = vtkPointPicker::SafeDownCast(aPicker)) {
1292     int aVtkId = picker->GetPointId();
1293     if ( aVtkId >= 0 && IsValid( aSActor, aVtkId, true ) ) {
1294       if ( aSActor && aSActor->hasIO() ) {
1295         int anObjId = aSActor->GetNodeObjId(aVtkId);
1296         bool anIsSameObjId = (mySelectedActor == aSActor && myNodeId == anObjId);
1297         if(!anIsSameObjId) {
1298           mySelectedActor = aSActor;
1299           myNodeId = anObjId;
1300           myInteractor->setPointData(anObjId,aSActor,myPreSelectionActor);
1301         }
1302         myPreSelectionActor->GetProperty()->SetRepresentationToSurface();
1303         myPreSelectionActor->SetVisibility(true);
1304       }
1305     }
1306   }
1307   else if ( vtkPicker::SafeDownCast(aPicker) ) {
1308     if ( aSActor ) {
1309       if ( myPreViewActor != aSActor ) {
1310         if ( myPreViewActor != NULL ) {
1311           myPreViewActor->SetPreSelected( false );
1312         }
1313         myPreViewActor = aSActor;
1314               
1315         if ( aSActor->hasIO() ) {
1316           Handle( SALOME_InteractiveObject) IO = aSActor->getIO();
1317           if ( !GetSelector()->IsSelected(IO) ) {
1318             // Find All actors with same IO
1319             vtkActorCollection* theActors = this->CurrentRenderer->GetActors();
1320             theActors->InitTraversal();
1321             while( vtkActor *ac = theActors->GetNextActor() ) {
1322               if ( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) ) {
1323                 if ( anActor->hasIO() ) {
1324                   Handle(SALOME_InteractiveObject) IOS = anActor->getIO();
1325                   if(IO->isSame(IOS)) {
1326                     anActor->SetPreSelected( true );
1327                   }
1328                 }
1329               }
1330             }
1331           }
1332         }
1333       }
1334     } else {
1335       myPreViewActor = NULL;
1336       vtkActorCollection* theActors = this->CurrentRenderer->GetActors();
1337       theActors->InitTraversal();
1338       while( vtkActor *ac = theActors->GetNextActor() ) {
1339         if ( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) ) {
1340           anActor->SetPreSelected( false );
1341         }
1342       }
1343     }
1344   }
1345   myInteractor->EndPickCallback();
1346   //myInteractor->Render();
1347   myGUIWindow->update();
1348   
1349   this->LastPos[0] = x;
1350   this->LastPos[1] = y;
1351 }
1352
1353 // called on finsh GlobalPan operation 
1354 void
1355 SVTK_InteractorStyle
1356 ::Place(const int theX, const int theY) 
1357 {
1358   if (this->CurrentRenderer == NULL) {
1359     return;
1360   }
1361
1362   //translate view
1363   int *aSize = this->CurrentRenderer->GetRenderWindow()->GetSize();
1364   int centerX = aSize[0]/2;
1365   int centerY = aSize[1]/2;
1366
1367   TranslateView(centerX, centerY, theX, theY);
1368
1369   // restore zoom scale
1370   vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
1371   cam->SetParallelScale(myScale);
1372   ::ResetCameraClippingRange(this->CurrentRenderer);
1373
1374   if (myGUIWindow) myGUIWindow->update();
1375
1376 }
1377
1378
1379
1380 // Translates view from Point to Point
1381 void
1382 SVTK_InteractorStyle
1383 ::TranslateView(int toX, int toY, int fromX, int fromY)
1384 {
1385   vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
1386   double viewFocus[4], focalDepth, viewPoint[3];
1387   float newPickPoint[4], oldPickPoint[4], motionVector[3];
1388   cam->GetFocalPoint(viewFocus);
1389
1390   this->ComputeWorldToDisplay(viewFocus[0], viewFocus[1],
1391                               viewFocus[2], viewFocus);
1392   focalDepth = viewFocus[2];
1393
1394   this->ComputeDisplayToWorld(double(toX), double(toY),
1395                               focalDepth, newPickPoint);
1396   this->ComputeDisplayToWorld(double(fromX),double(fromY),
1397                               focalDepth, oldPickPoint);
1398   
1399   // camera motion is reversed
1400   motionVector[0] = oldPickPoint[0] - newPickPoint[0];
1401   motionVector[1] = oldPickPoint[1] - newPickPoint[1];
1402   motionVector[2] = oldPickPoint[2] - newPickPoint[2];
1403   
1404   cam->GetFocalPoint(viewFocus);
1405   cam->GetPosition(viewPoint);
1406   cam->SetFocalPoint(motionVector[0] + viewFocus[0],
1407                      motionVector[1] + viewFocus[1],
1408                      motionVector[2] + viewFocus[2]);
1409   cam->SetPosition(motionVector[0] + viewPoint[0],
1410                    motionVector[1] + viewPoint[1],
1411                    motionVector[2] + viewPoint[2]);
1412 }
1413
1414
1415 /// Checks: is the given Actor within display coordinates?
1416 bool
1417 SVTK_InteractorStyle
1418 ::IsInRect(vtkActor* theActor, 
1419            const int left, const int top, 
1420            const int right, const int bottom)
1421 {
1422   float* aBounds = theActor->GetBounds();
1423   float aMin[3], aMax[3];
1424   ComputeWorldToDisplay(aBounds[0], aBounds[2], aBounds[4], aMin);
1425   ComputeWorldToDisplay(aBounds[1], aBounds[3], aBounds[5], aMax);
1426   if (aMin[0] > aMax[0]) {
1427     float aBuf = aMin[0];
1428     aMin[0] = aMax[0];
1429     aMax[0] = aBuf;
1430   }
1431   if (aMin[1] > aMax[1]) {
1432     float aBuf = aMin[1];
1433     aMin[1] = aMax[1];
1434     aMax[1] = aBuf;    
1435   }
1436
1437   return ((aMin[0]>left) && (aMax[0]<right) && (aMin[1]>bottom) && (aMax[1]<top));
1438 }
1439
1440
1441 /// Checks: is the given Cell within display coordinates?
1442 bool
1443 SVTK_InteractorStyle
1444 ::IsInRect(vtkCell* theCell, 
1445            const int left, const int top, 
1446            const int right, const int bottom)
1447 {
1448   float* aBounds = theCell->GetBounds();
1449   float aMin[3], aMax[3];
1450   ComputeWorldToDisplay(aBounds[0], aBounds[2], aBounds[4], aMin);
1451   ComputeWorldToDisplay(aBounds[1], aBounds[3], aBounds[5], aMax);
1452   if (aMin[0] > aMax[0]) {
1453     float aBuf = aMin[0];
1454     aMin[0] = aMax[0];
1455     aMax[0] = aBuf;
1456   }
1457   if (aMin[1] > aMax[1]) {
1458     float aBuf = aMin[1];
1459     aMin[1] = aMax[1];
1460     aMax[1] = aBuf;    
1461   }
1462
1463   return ((aMin[0]>left) && (aMax[0]<right) && (aMin[1]>bottom) && (aMax[1]<top));
1464 }
1465
1466
1467 bool
1468 SVTK_InteractorStyle
1469 ::IsInRect(float* thePoint, 
1470            const int left, const int top, 
1471            const int right, const int bottom)
1472 {
1473   float aPnt[3];
1474   ComputeWorldToDisplay(thePoint[0], thePoint[1], thePoint[2], aPnt);
1475
1476   return ((aPnt[0]>left) && (aPnt[0]<right) && (aPnt[1]>bottom) && (aPnt[1]<top));
1477 }
1478
1479 void
1480 SVTK_InteractorStyle
1481 ::SetFilter( const Handle(VTKViewer_Filter)& theFilter )
1482 {
1483   myFilters[ theFilter->GetId() ] = theFilter;
1484 }
1485
1486 bool
1487 SVTK_InteractorStyle
1488 ::IsFilterPresent( const int theId )
1489 {
1490   return myFilters.find( theId ) != myFilters.end();
1491 }
1492
1493 void  
1494 SVTK_InteractorStyle
1495 ::RemoveFilter( const int theId )
1496 {
1497   if ( IsFilterPresent( theId ) )
1498     myFilters.erase( theId );
1499 }
1500
1501
1502 bool
1503 SVTK_InteractorStyle
1504 ::IsValid( SALOME_Actor* theActor,
1505            const int     theId,
1506            const bool    theIsNode )
1507 {
1508   std::map<int, Handle(VTKViewer_Filter)>::const_iterator anIter;
1509   for ( anIter = myFilters.begin(); anIter != myFilters.end(); ++anIter )
1510   {
1511     const Handle(VTKViewer_Filter)& aFilter = anIter->second;
1512     if ( theIsNode == aFilter->IsNodeFilter() &&
1513          !aFilter->IsValid( theActor, theId ) )
1514       return false;
1515   }
1516   return true;
1517 }
1518
1519 Handle(VTKViewer_Filter) 
1520 SVTK_InteractorStyle
1521 ::GetFilter( const int theId )
1522 {
1523   return IsFilterPresent( theId ) ? myFilters[ theId ] : Handle(VTKViewer_Filter)();
1524 }
1525
1526 void
1527 SVTK_InteractorStyle
1528 ::IncrementalPan( const int incrX, const int incrY )
1529 {
1530   this->PanXY( incrX, incrY, 0, 0 );
1531 }
1532
1533 void
1534 SVTK_InteractorStyle
1535 ::IncrementalZoom( const int incr )
1536 {
1537   this->DollyXY( incr, incr );
1538 }
1539
1540 void
1541 SVTK_InteractorStyle
1542 ::IncrementalRotate( const int incrX, const int incrY )
1543 {
1544   this->RotateXY( incrX, -incrY );
1545 }