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