1 // SALOME VTKViewer : build VTK viewer into Salome desktop
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : VTKViewer_InteractorStyle.cxx
25 // Author : Christophe ATTANASIO
28 #include "VTKViewer_InteractorStyle.h"
30 #include "VTKViewer_Actor.h"
31 #include "VTKViewer_Utilities.h"
32 #include "VTKViewer_Trihedron.h"
33 #include "VTKViewer_ViewWindow.h"
34 #include "VTKViewer_RenderWindow.h"
35 #include "VTKViewer_RenderWindowInteractor.h"
37 //#include "SALOME_Actor.h"
39 #include <vtkObjectFactory.h>
41 #include <vtkCommand.h>
42 #include <vtkCamera.h>
43 #include <vtkRenderer.h>
44 #include <vtkPicker.h>
45 #include <vtkPointPicker.h>
46 #include <vtkCellPicker.h>
48 #include <vtkMapper.h>
49 #include <vtkDataSet.h>
50 #include <vtkSmartPointer.h>
51 #include <vtkProperty.h>
53 #include <qapplication.h>
54 //VRV: porting on Qt 3.0.5
55 #if QT_VERSION >= 0x030005
58 //VRV: porting on Qt 3.0.5
61 //#include "utilities.h"
67 static int GetEdgeId(vtkPicker *thePicker, SALOME_Actor *theActor, int theObjId){
69 if (vtkCell* aPickedCell = theActor->GetElemCell(theObjId)) {
70 float aPickPosition[3];
71 thePicker->GetPickPosition(aPickPosition);
72 float aMinDist = 1000000.0, aDist = 0;
73 for (int i = 0, iEnd = aPickedCell->GetNumberOfEdges(); i < iEnd; i++){
74 if(vtkLine* aLine = vtkLine::SafeDownCast(aPickedCell->GetEdge(i))){
75 int subId; float pcoords[3], closestPoint[3], weights[3];
76 aLine->EvaluatePosition(aPickPosition,closestPoint,subId,pcoords,aDist,weights);
77 if (aDist < aMinDist) {
88 vtkStandardNewMacro(VTKViewer_InteractorStyle);
92 VTKViewer_InteractorStyle::VTKViewer_InteractorStyle()
95 this->MotionFactor = 10.0;
96 this->State = VTK_INTERACTOR_STYLE_CAMERA_NONE;
97 this->RadianToDegree = 180.0 / vtkMath::Pi();
98 this->ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
101 myPreSelectionActor = VTKViewer_Actor::New();
102 myPreSelectionActor->GetProperty()->SetColor(0,1,1);
103 myPreSelectionActor->GetProperty()->SetLineWidth(5);
104 myPreSelectionActor->GetProperty()->SetPointSize(5);
106 OnSelectionModeChanged();
111 VTKViewer_InteractorStyle::~VTKViewer_InteractorStyle()
113 m_ViewWnd->RemoveActor(myPreSelectionActor);
117 /*!Set preselection properties.
118 *\param theRed - red color.
119 *\param theGreen - green color.
120 *\param theBlue - blue color.
121 *\param theWidth - width..
123 void VTKViewer_InteractorStyle::setPreselectionProp(const double& theRed, const double& theGreen,
124 const double& theBlue, const int& theWidth)
126 if ( myPreSelectionActor->GetProperty() == 0 )
128 myPreSelectionActor->GetProperty()->SetColor(theRed, theGreen, theBlue);
129 myPreSelectionActor->GetProperty()->SetLineWidth(theWidth);
130 myPreSelectionActor->GetProperty()->SetPointSize(theWidth);
134 /*!Set render window interactor
135 *\param theInteractor - interactor.
137 void VTKViewer_InteractorStyle::SetInteractor(vtkRenderWindowInteractor *theInteractor){
138 m_Interactor = dynamic_cast<VTKViewer_RenderWindowInteractor*>(theInteractor);
139 Superclass::SetInteractor(theInteractor);
144 *\param theViewWnd - SALOME VTKViewer_ViewWindow
146 void VTKViewer_InteractorStyle::setViewWnd(VTKViewer_ViewWindow* theViewWnd ){
147 m_ViewWnd = theViewWnd;
148 m_ViewWnd->AddActor(myPreSelectionActor);
149 myPreSelectionActor->Delete();
154 *\param theWindow - QWidget window.
156 void VTKViewer_InteractorStyle::setGUIWindow(QWidget* theWindow){
157 myGUIWindow = theWindow;
162 *\param theTrihedron - SALOME VTKViewer_Trihedron
164 void VTKViewer_InteractorStyle::setTriedron(VTKViewer_Trihedron* theTrihedron){
165 m_Trihedron = theTrihedron;
172 void VTKViewer_InteractorStyle::RotateXY(int dx, int dy)
178 if (this->CurrentRenderer == NULL)
183 int *size = this->CurrentRenderer->GetRenderWindow()->GetSize();
184 this->DeltaElevation = -20.0 / size[1];
185 this->DeltaAzimuth = -20.0 / size[0];
187 rxf = (double)dx * this->DeltaAzimuth * this->MotionFactor;
188 ryf = (double)dy * this->DeltaElevation * this->MotionFactor;
190 cam = this->CurrentRenderer->GetActiveCamera();
193 cam->OrthogonalizeViewUp();
194 ::ResetCameraClippingRange(this->CurrentRenderer);
195 //this->Interactor->Render();
196 myGUIWindow->update();
199 void VTKViewer_InteractorStyle::PanXY(int x, int y, int oldX, int oldY)
201 TranslateView(x, y, oldX, oldY);
202 //this->Interactor->Render();
203 myGUIWindow->update();
207 /*! Move the position of the camera along the direction of projection. (dx,dy)*/
208 void VTKViewer_InteractorStyle::DollyXY(int dx, int dy)
210 if (this->CurrentRenderer == NULL) return;
212 double dxf = this->MotionFactor * (double)(dx) / (double)(this->CurrentRenderer->GetCenter()[1]);
213 double dyf = this->MotionFactor * (double)(dy) / (double)(this->CurrentRenderer->GetCenter()[1]);
215 double zoomFactor = pow((double)1.1, dxf + dyf);
217 vtkCamera *aCam = this->CurrentRenderer->GetActiveCamera();
218 if (aCam->GetParallelProjection())
219 aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
221 aCam->Dolly(zoomFactor);
222 ::ResetCameraClippingRange(this->CurrentRenderer);
225 //this->Interactor->Render();
226 myGUIWindow->update();
229 void VTKViewer_InteractorStyle::SpinXY(int x, int y, int oldX, int oldY)
233 if (this->CurrentRenderer == NULL)
238 double newAngle = atan2((double)(y - this->CurrentRenderer->GetCenter()[1]),
239 (double)(x - this->CurrentRenderer->GetCenter()[0]));
240 double oldAngle = atan2((double)(oldY -this->CurrentRenderer->GetCenter()[1]),
241 (double)(oldX - this->CurrentRenderer->GetCenter()[0]));
243 newAngle *= this->RadianToDegree;
244 oldAngle *= this->RadianToDegree;
246 cam = this->CurrentRenderer->GetActiveCamera();
247 cam->Roll(newAngle - oldAngle);
248 cam->OrthogonalizeViewUp();
250 //this->Interactor->Render();
251 myGUIWindow->update();
255 /*!On mouse move event.
256 *\param ctrl - CTRL (not used)
257 *\param shift - SHIFT (on/off - integer 0/1)
258 *\param x - x coordinate
259 *\param y - y coordinate
261 void VTKViewer_InteractorStyle::OnMouseMove(int vtkNotUsed(ctrl),
265 myShiftState = shift;
266 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
267 onOperation(QPoint(x, y));
268 else if (ForcedState == VTK_INTERACTOR_STYLE_CAMERA_NONE)
269 onCursorMove(QPoint(x, y));
273 /*!On Left button down event.
274 *\param ctrl - CTRL (on/off - integer 0/1)
275 *\param shift - SHIFT (on/off - integer 0/1)
276 *\param x - x coordinate
277 *\param y - y coordinate
279 void VTKViewer_InteractorStyle::OnLeftButtonDown(int ctrl, int shift,
282 if (this->HasObserver(vtkCommand::LeftButtonPressEvent)) {
283 this->InvokeEvent(vtkCommand::LeftButtonPressEvent,NULL);
286 this->FindPokedRenderer(x, y);
287 if (this->CurrentRenderer == NULL) {
290 myShiftState = shift;
291 // finishing current viewer operation
292 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
294 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
296 myOtherPoint = myPoint = QPoint(x, y);
297 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
298 startOperation(ForcedState);
301 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
303 startOperation(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
309 /*!On left button up event.
310 *\param ctrl - CTRL (not used)
311 *\param shift - SHIFT (on/off - integer 0/1)
312 *\param x - x coordinate (not used)
313 *\param y - y coordinate (not used)
315 void VTKViewer_InteractorStyle::OnLeftButtonUp(int vtkNotUsed(ctrl),
320 myShiftState = shift;
321 // finishing current viewer operation
322 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
324 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
329 /*!On left button up event.
330 *\param ctrl - CTRL (on/off - integer 0/1)
331 *\param shift - SHIFT (on/off - integer 0/1)
332 *\param x - x coordinate
333 *\param y - y coordinate
335 void VTKViewer_InteractorStyle::OnMiddleButtonDown(int ctrl,
339 if (this->HasObserver(vtkCommand::MiddleButtonPressEvent))
341 this->InvokeEvent(vtkCommand::MiddleButtonPressEvent,NULL);
344 this->FindPokedRenderer(x, y);
345 if (this->CurrentRenderer == NULL)
349 myShiftState = shift;
350 // finishing current viewer operation
351 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
353 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
355 myOtherPoint = myPoint = QPoint(x, y);
356 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
357 startOperation(ForcedState);
361 startOperation(VTK_INTERACTOR_STYLE_CAMERA_PAN);
366 /*!On middle button up event.
367 *\param ctrl - CTRL (not used)
368 *\param shift - SHIFT (on/off - integer 0/1)
369 *\param x - x coordinate (not used)
370 *\param y - y coordinate (not used)
372 void VTKViewer_InteractorStyle::OnMiddleButtonUp(int vtkNotUsed(ctrl),
377 myShiftState = shift;
378 // finishing current viewer operation
379 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
381 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
386 /*!On right button down event.
387 *\param ctrl - CTRL (on/off - integer 0/1)
388 *\param shift - SHIFT (on/off - integer 0/1)
389 *\param x - x coordinate
390 *\param y - y coordinate
392 void VTKViewer_InteractorStyle::OnRightButtonDown(int ctrl,
396 if (this->HasObserver(vtkCommand::RightButtonPressEvent))
398 this->InvokeEvent(vtkCommand::RightButtonPressEvent,NULL);
401 this->FindPokedRenderer(x, y);
402 if (this->CurrentRenderer == NULL)
406 myShiftState = shift;
407 // finishing current viewer operation
408 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
410 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
412 myOtherPoint = myPoint = QPoint(x, y);
413 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
414 startOperation(ForcedState);
418 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
422 /*!On right button up event.
423 *\param ctrl - CTRL (not used)
424 *\param shift - SHIFT (on/off - integer 0/1)
425 *\param x - x coordinate (not used)
426 *\param y - y coordinate (not used)
428 void VTKViewer_InteractorStyle::OnRightButtonUp(int vtkNotUsed(ctrl),
433 myShiftState = shift;
434 // finishing current viewer operation
435 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
437 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
441 /*! @name XPM - x pixmaps. */
443 /*!Image Zoom cursor*/
444 const char* imageZoomCursor[] = {
449 "................................",
450 "................................",
451 ".#######........................",
452 "..aaaaaaa.......................",
453 "................................",
454 ".............#####..............",
455 "...........##.aaaa##............",
456 "..........#.aa.....a#...........",
457 ".........#.a.........#..........",
458 ".........#a..........#a.........",
459 "........#.a...........#.........",
460 "........#a............#a........",
461 "........#a............#a........",
462 "........#a............#a........",
463 "........#a............#a........",
464 ".........#...........#.a........",
465 ".........#a..........#a.........",
466 ".........##.........#.a.........",
467 "........#####.....##.a..........",
468 ".......###aaa#####.aa...........",
469 "......###aa...aaaaa.......#.....",
470 ".....###aa................#a....",
471 "....###aa.................#a....",
472 "...###aa...............#######..",
473 "....#aa.................aa#aaaa.",
474 ".....a....................#a....",
475 "..........................#a....",
476 "...........................a....",
477 "................................",
478 "................................",
479 "................................",
480 "................................"};
482 /*!Image rotate cursor*/
483 const char* imageRotateCursor[] = {
488 "................................",
489 "................................",
490 "................................",
491 "................................",
492 "........#.......................",
493 ".......#.a......................",
494 "......#######...................",
495 ".......#aaaaa#####..............",
496 "........#..##.a#aa##........##..",
497 ".........a#.aa..#..a#.....##.aa.",
498 ".........#.a.....#...#..##.aa...",
499 ".........#a.......#..###.aa.....",
500 "........#.a.......#a..#aa.......",
501 "........#a.........#..#a........",
502 "........#a.........#a.#a........",
503 "........#a.........#a.#a........",
504 "........#a.........#a.#a........",
505 ".........#.........#a#.a........",
506 "........##a........#a#a.........",
507 "......##.a#.......#.#.a.........",
508 "....##.aa..##.....##.a..........",
509 "..##.aa.....a#####.aa...........",
510 "...aa.........aaa#a.............",
511 "................#.a.............",
512 "...............#.a..............",
513 "..............#.a...............",
514 "...............a................",
515 "................................",
516 "................................",
517 "................................",
518 "................................",
519 "................................"};
522 /*! Loads cursors for viewer operations - zoom, pan, etc...*/
523 void VTKViewer_InteractorStyle::loadCursors()
525 myDefCursor = QCursor(ArrowCursor);
526 myHandCursor = QCursor(PointingHandCursor);
527 myPanCursor = QCursor(SizeAllCursor);
528 myZoomCursor = QCursor(QPixmap(imageZoomCursor));
529 myRotateCursor = QCursor(QPixmap(imageRotateCursor));
530 mySpinCursor = QCursor(QPixmap(imageRotateCursor)); // temporarly !!!!!!
531 myGlobalPanCursor = QCursor(CrossCursor);
532 myCursorState = false;
536 /*! event filter - controls mouse and keyboard events during viewer operations*/
537 bool VTKViewer_InteractorStyle::eventFilter(QObject* object, QEvent* event)
539 if (!myGUIWindow) return false;
540 if ( (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::KeyPress) && object != myGUIWindow)
542 qApp->removeEventFilter(this);
543 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
545 return QObject::eventFilter(object, event);
549 /*! starts Zoom operation (e.g. through menu command)*/
550 void VTKViewer_InteractorStyle::startZoom()
552 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
555 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
557 setCursor(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
558 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ZOOM;
559 qApp->installEventFilter(this);
563 /*! starts Pan operation (e.g. through menu command)*/
564 void VTKViewer_InteractorStyle::startPan()
566 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
569 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
571 setCursor(VTK_INTERACTOR_STYLE_CAMERA_PAN);
572 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_PAN;
573 qApp->installEventFilter(this);
576 /*! starts Rotate operation (e.g. through menu command)*/
577 void VTKViewer_InteractorStyle::startRotate()
579 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
582 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
584 setCursor(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
585 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ROTATE;
586 qApp->installEventFilter(this);
590 /*! starts Spin operation (e.g. through menu command)*/
591 void VTKViewer_InteractorStyle::startSpin()
593 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
596 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
598 setCursor(VTK_INTERACTOR_STYLE_CAMERA_SPIN);
599 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_SPIN;
600 qApp->installEventFilter(this);
605 /*! starts Fit Area operation (e.g. through menu command)*/
606 void VTKViewer_InteractorStyle::startFitArea()
608 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
611 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
613 setCursor(VTK_INTERACTOR_STYLE_CAMERA_FIT);
614 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_FIT;
615 qApp->installEventFilter(this);
620 void VTKViewer_InteractorStyle::ViewFitAll() {
621 int aTriedronWasVisible = false;
623 aTriedronWasVisible = m_Trihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
624 if(aTriedronWasVisible) m_Trihedron->VisibilityOff();
627 if(m_Trihedron->GetVisibleActorCount(CurrentRenderer)){
628 m_Trihedron->VisibilityOff();
629 ::ResetCamera(CurrentRenderer);
631 m_Trihedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
632 ::ResetCamera(CurrentRenderer,true);
634 if(aTriedronWasVisible) m_Trihedron->VisibilityOn();
635 else m_Trihedron->VisibilityOff();
636 ::ResetCameraClippingRange(CurrentRenderer);
640 /*! starts Global Panning operation (e.g. through menu command)*/
641 void VTKViewer_InteractorStyle::startGlobalPan()
643 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
646 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
648 setCursor(VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN);
649 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN;
651 // store current zoom scale
652 vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
653 myScale = cam->GetParallelScale();
657 if (myGUIWindow) myGUIWindow->update();
659 qApp->installEventFilter(this);
663 /*!\retval TRUE if needs redrawing*/
664 bool VTKViewer_InteractorStyle::needsRedrawing()
666 return State == VTK_INTERACTOR_STYLE_CAMERA_ZOOM ||
667 State == VTK_INTERACTOR_STYLE_CAMERA_PAN ||
668 State == VTK_INTERACTOR_STYLE_CAMERA_ROTATE ||
669 State == VTK_INTERACTOR_STYLE_CAMERA_SPIN ||
670 State == VTK_INTERACTOR_STYLE_CAMERA_NONE;
674 /*! fits viewer contents to rectangle
675 *\param left - left side
676 *\param top - top side
677 *\param right - right side
678 *\param bottom - bottom side
680 void VTKViewer_InteractorStyle::fitRect(const int left,
685 if (this->CurrentRenderer == NULL) return;
688 int x = (left + right)/2;
689 int y = (top + bottom)/2;
690 int *aSize = this->CurrentRenderer->GetRenderWindow()->GetSize();
691 int oldX = aSize[0]/2;
692 int oldY = aSize[1]/2;
693 TranslateView(oldX, oldY, x, y);
696 double dxf = (double)(aSize[0]) / (double)(abs(right - left));
697 double dyf = (double)(aSize[1]) / (double)(abs(bottom - top));
698 double zoomFactor = (dxf + dyf)/2 ;
700 vtkCamera *aCam = this->CurrentRenderer->GetActiveCamera();
701 if(aCam->GetParallelProjection())
702 aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
704 aCam->Dolly(zoomFactor);
705 ::ResetCameraClippingRange(this->CurrentRenderer);
708 myGUIWindow->update();
712 /*! starts viewer operation (!internal usage!)*/
713 void VTKViewer_InteractorStyle::startOperation(int operation)
717 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
718 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
719 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
720 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
721 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
722 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
723 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
724 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
725 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
727 if (State != VTK_INTERACTOR_STYLE_CAMERA_SELECT)
728 setCursor(operation);
731 case VTK_INTERACTOR_STYLE_CAMERA_NONE:
733 setCursor(VTK_INTERACTOR_STYLE_CAMERA_NONE);
734 State = ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
740 /*! sets proper cursor for window when viewer operation is activated*/
741 void VTKViewer_InteractorStyle::setCursor(const int operation)
743 if (!myGUIWindow) return;
746 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
747 myGUIWindow->setCursor(myZoomCursor);
748 myCursorState = true;
750 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
751 myGUIWindow->setCursor(myPanCursor);
752 myCursorState = true;
754 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
755 myGUIWindow->setCursor(myRotateCursor);
756 myCursorState = true;
758 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
759 myGUIWindow->setCursor(mySpinCursor);
760 myCursorState = true;
762 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
763 myGUIWindow->setCursor(myGlobalPanCursor);
764 myCursorState = true;
766 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
767 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
768 myGUIWindow->setCursor(myHandCursor);
769 myCursorState = true;
771 case VTK_INTERACTOR_STYLE_CAMERA_NONE:
773 myGUIWindow->setCursor(myDefCursor);
774 myCursorState = false;
780 /*! called when viewer operation started (!put necessary initialization here!)*/
781 void VTKViewer_InteractorStyle::onStartOperation()
783 if (!myGUIWindow) return;
784 // VSV: LOD actor activisation
785 // this->Interactor->GetRenderWindow()->SetDesiredUpdateRate(this->Interactor->GetDesiredUpdateRate());
787 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
788 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
790 QPainter p(myGUIWindow);
791 p.setPen(Qt::lightGray);
792 p.setRasterOp(Qt::XorROP);
793 p.drawRect(QRect(myPoint, myOtherPoint));
796 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
797 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
798 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
799 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
800 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
806 /*! called when viewer operation finished (!put necessary post-processing here!)*/
807 void VTKViewer_InteractorStyle::onFinishOperation()
809 if (!myGUIWindow) return;
812 // SUIT_Study* aActiveStudy = SUIT_Application::getDesktop()->getActiveStudy();
813 // SALOME_Selection* aSel = SALOME_Selection::Selection( aActiveStudy->getSelection() );
815 // VSV: LOD actor activisation
816 // rwi->GetRenderWindow()->SetDesiredUpdateRate(rwi->GetStillUpdateRate());
818 // Selection_Mode aSelectionMode = aSel->SelectionMode();
819 // bool aSelActiveCompOnly = aSel->IsSelectActiveCompOnly();
822 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
823 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
825 QPainter p(myGUIWindow);
826 p.setPen(Qt::lightGray);
827 p.setRasterOp(Qt::XorROP);
828 QRect rect(myPoint, myOtherPoint);
830 rect = rect.normalize();
831 if (State == VTK_INTERACTOR_STYLE_CAMERA_FIT) {
832 // making fit rect opeation
834 m_Interactor->GetSize(w, h);
837 y1 = h - rect.top() - 1;
839 y2 = h - rect.bottom() - 1;
840 fitRect(x1, y1, x2, y2);
843 if (myPoint == myOtherPoint) {
844 // process point selection
846 m_Interactor->GetSize(w, h);
848 y = h - myPoint.y() - 1;
850 this->FindPokedRenderer(x, y);
851 m_Interactor->StartPickCallback();
853 vtkPicker* aPicker = vtkPicker::SafeDownCast(m_Interactor->GetPicker());
854 aPicker->Pick(x, y, 0.0, this->CurrentRenderer);
856 SALOME_Actor* SActor = SALOME_Actor::SafeDownCast(aPicker->GetActor());
858 if (vtkCellPicker* picker = vtkCellPicker::SafeDownCast(aPicker)) {
859 int aVtkId = picker->GetCellId();
860 if ( aVtkId >= 0 && SActor && SActor->hasIO() && IsValid( SActor, aVtkId ) ) {
861 int anObjId = SActor->GetElemObjId(aVtkId);
863 Handle(SALOME_InteractiveObject) IO = SActor->getIO();
864 if(aSelectionMode != EdgeOfCellSelection) {
865 if(CheckDimensionId(aSelectionMode,SActor,anObjId)){
866 if (IsSelected(IO,aSel)) {
867 // This IO is already in the selection
868 aSel->AddOrRemoveIndex( IO, anObjId, myShiftState, false );
871 this->HighlightProp( NULL );
872 aSel->ClearIObjects();
874 aSel->AddOrRemoveIndex( IO, anObjId, myShiftState, false );
875 aSel->AddIObject( IO, false );
880 this->HighlightProp( NULL );
881 aSel->ClearIObjects();
883 int anEdgeId = GetEdgeId(picker,SActor,anObjId);
885 aSel->AddOrRemoveIndex( IO, anObjId, true, false);
886 aSel->AddOrRemoveIndex( IO, -anEdgeId-1, true, true );
887 aSel->AddIObject( IO, false );
892 this->HighlightProp( NULL );
893 aSel->ClearIObjects();
895 } else if ( vtkPointPicker* picker = vtkPointPicker::SafeDownCast(aPicker) ) {
896 int aVtkId = picker->GetPointId();
897 if ( aVtkId >= 0 && IsValid( SActor, aVtkId, true ) ) {
898 if ( SActor && SActor->hasIO() ) {
899 int anObjId = SActor->GetNodeObjId(aVtkId);
901 Handle(SALOME_InteractiveObject) IO = SActor->getIO();
902 if(IsSelected(IO,aSel)) {
903 // This IO is already in the selection
904 aSel->AddOrRemoveIndex( IO, anObjId, myShiftState, false );
907 this->HighlightProp( NULL );
908 aSel->ClearIObjects();
910 aSel->AddOrRemoveIndex( IO, anObjId, myShiftState, false );
911 aSel->AddIObject( IO, false );
916 this->HighlightProp( NULL );
917 aSel->ClearIObjects();
920 if ( SActor && SActor->hasIO() ) {
922 Handle(SALOME_InteractiveObject) IO = SActor->getIO();
923 if(IsSelected(IO,aSel)) {
924 // This IO is already in the selection
926 aSel->RemoveIObject(IO);
931 this->HighlightProp( NULL );
932 aSel->ClearIObjects();
934 aSel->AddIObject( IO, false );
937 // No selection clear all
938 this->PropPicked = 0;
939 this->HighlightProp( NULL );
940 aSel->ClearIObjects();
943 m_Interactor->EndPickCallback();
945 //processing rectangle selection
946 QString aComponentDataType = SUIT_Application::getDesktop()->getComponentDataType();
947 if(aSelActiveCompOnly && aComponentDataType.isEmpty()) return;
948 m_Interactor->StartPickCallback();
951 this->PropPicked = 0;
952 this->HighlightProp( NULL );
953 aSel->ClearIObjects();
957 // vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
958 QRect rect(myPoint, myOtherPoint);
959 rect = rect.normalize();
961 m_Interactor->GetSize(w, h);
964 y1 = h - rect.top() - 1;
966 y2 = h - rect.bottom() - 1;
968 switch (aSelectionMode) {
969 case NodeSelection: {
970 if ( vtkPointPicker* aPointPicker = vtkPointPicker::SafeDownCast(m_Interactor->GetPicker()) ) {
971 vtkActorCollection* aListActors = this->CurrentRenderer->GetActors();
972 aListActors->InitTraversal();
973 while (vtkActor* aActor = aListActors->GetNextActor()) {
974 if (!aActor->GetVisibility())
976 if(SALOME_Actor* SActor = SALOME_Actor::SafeDownCast(aActor)) {
977 if (SActor->hasIO()) {
978 Handle(SALOME_InteractiveObject) IO = SActor->getIO();
981 if (aSelActiveCompOnly && aComponentDataType != IO->getComponentDataType())
983 if (vtkDataSet* aDataSet = SActor->GetInput()) {
984 SALOME_Selection::TContainerOfId anIndices;
985 for(int i = 0; i < aDataSet->GetNumberOfPoints(); i++) {
987 aDataSet->GetPoint(i,aPoint);
988 if (IsInRect(aPoint,x1,y1,x2,y2)){
990 ComputeWorldToDisplay(aPoint[0],aPoint[1],aPoint[2],aDisp);
991 if(aPointPicker->Pick(aDisp[0],aDisp[1],0.0,CurrentRenderer)){
992 if(vtkActorCollection *anActorCollection = aPointPicker->GetActors()){
993 if(anActorCollection->IsItemPresent(SActor)){
994 float aPickedPoint[3];
995 aPointPicker->GetMapperPosition(aPickedPoint);
996 vtkIdType aVtkId = aDataSet->FindPoint(aPickedPoint);
997 if ( aVtkId >= 0 && IsValid( SActor, aVtkId, true ) ){
998 int anObjId = SActor->GetNodeObjId(aVtkId);
999 anIndices.insert(anObjId);
1006 if (!anIndices.empty()) {
1007 aSel->AddOrRemoveIndex(IO, anIndices, true, false);
1008 aSel->AddIObject(IO, false);
1011 aSel->RemoveIObject(IO, false);
1021 case EdgeOfCellSelection:
1024 case VolumeSelection:
1026 vtkSmartPointer<VTKViewer_CellRectPicker> picker = VTKViewer_CellRectPicker::New();
1027 picker->SetTolerance(0.001);
1028 picker->Pick(x1, y1, 0.0, x2, y2, 0.0, this->CurrentRenderer);
1030 vtkActorCollection* aListActors = picker->GetActors();
1031 aListActors->InitTraversal();
1032 while(vtkActor* aActor = aListActors->GetNextActor()) {
1033 if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)) {
1034 if (aSActor->hasIO()) {
1035 Handle(SALOME_InteractiveObject) aIO = aSActor->getIO();
1036 if (aSelActiveCompOnly && aComponentDataType != aIO->getComponentDataType())
1038 VTKViewer_CellDataSet cellList = picker->GetCellData(aActor);
1039 if ( !cellList.empty() ) {
1040 SALOME_Selection::TContainerOfId anIndexes;
1041 VTKViewer_CellDataSet::iterator it;
1042 for ( it = cellList.begin(); it != cellList.end(); ++it ) {
1043 int aCellId = (*it).cellId;
1045 if ( !IsValid( aSActor, aCellId ) )
1048 int anObjId = aSActor->GetElemObjId(aCellId);
1050 if ( CheckDimensionId(aSelectionMode,aSActor,anObjId) ) {
1051 anIndexes.insert(anObjId);
1055 aSel->AddOrRemoveIndex(aIO, anIndexes, true, false);
1056 aSel->AddIObject(aIO, false);
1063 case ActorSelection: // objects selection
1065 vtkSmartPointer<VTKViewer_RectPicker> picker = VTKViewer_RectPicker::New();
1066 picker->SetTolerance(0.001);
1067 picker->Pick(x1, y1, 0.0, x2, y2, 0.0, this->CurrentRenderer);
1069 vtkActorCollection* aListActors = picker->GetActors();
1070 SALOME_ListIO aListIO;
1071 aListActors->InitTraversal();
1072 while(vtkActor* aActor = aListActors->GetNextActor()) {
1073 if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)) {
1074 if (aSActor->hasIO()) {
1075 Handle(SALOME_InteractiveObject) aIO = aSActor->getIO();
1076 if (!IsStored(aIO,aListIO))
1077 aListIO.Append(aIO);
1081 if (!aListIO.IsEmpty()) {
1082 SALOME_ListIteratorOfListIO It(aListIO);
1083 for(;It.More();It.Next()) {
1084 Handle(SALOME_InteractiveObject) IOS = It.Value();
1086 aSel->AddIObject( IOS, false );
1091 m_Interactor->EndPickCallback();
1093 aActiveStudy->update3dViewers();
1097 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
1098 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
1099 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
1100 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
1102 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
1105 m_Interactor->GetSize(w, h);
1107 y = h - myPoint.y() - 1;
1112 if (myGUIWindow) myGUIWindow->update();
1116 /*! called during viewer operation when user moves mouse (!put necessary processing here!)*/
1117 void VTKViewer_InteractorStyle::onOperation(QPoint mousePos)
1119 if (!myGUIWindow) return;
1121 GetInteractor()->GetSize(w, h);
1123 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
1125 // processing panning
1126 //this->FindPokedCamera(mousePos.x(), mousePos.y());
1127 this->PanXY(mousePos.x(), myPoint.y(), myPoint.x(), mousePos.y());
1131 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
1133 // processing zooming
1134 //this->FindPokedCamera(mousePos.x(), mousePos.y());
1135 this->DollyXY(mousePos.x() - myPoint.x(), mousePos.y() - myPoint.y());
1139 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
1141 // processing rotation
1142 //this->FindPokedCamera(mousePos.x(), mousePos.y());
1143 this->RotateXY(mousePos.x() - myPoint.x(), myPoint.y() - mousePos.y());
1147 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
1149 // processing spinning
1150 //this->FindPokedCamera(mousePos.x(), mousePos.y());
1151 this->SpinXY(mousePos.x(), mousePos.y(), myPoint.x(), myPoint.y());
1155 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
1159 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
1162 setCursor(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
1164 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
1166 QPainter p(myGUIWindow);
1167 p.setPen(Qt::lightGray);
1168 p.setRasterOp(Qt::XorROP);
1169 p.drawRect(QRect(myPoint, myOtherPoint));
1170 myOtherPoint = mousePos;
1171 p.drawRect(QRect(myPoint, myOtherPoint));
1175 this->LastPos[0] = mousePos.x();
1176 this->LastPos[1] = h - mousePos.y() - 1;
1179 /*! called when selection mode changed (!put necessary initialization here!)*/
1180 void VTKViewer_InteractorStyle::OnSelectionModeChanged()
1183 myPreSelectionActor->SetVisibility(false);
1184 myElemId = myEdgeId = myNodeId = -1;
1185 mySelectedActor = NULL;
1188 /*! called when user moves mouse inside viewer window and there is no active viewer operation \n
1189 * (!put necessary processing here!)
1191 void VTKViewer_InteractorStyle::onCursorMove(QPoint mousePos) {
1192 // processing highlighting
1193 // SUIT_Study* anActiveStudy = SUIT_Application::getDesktop()->getActiveStudy();
1194 // SALOME_Selection* Sel = SALOME_Selection::Selection( anActiveStudy->getSelection() );
1195 // Selection_Mode aSelectionMode = Sel->SelectionMode();
1198 m_Interactor->GetSize(w, h);
1199 x = mousePos.x(); y = h - mousePos.y() - 1;
1201 this->FindPokedRenderer(x,y);
1202 m_Interactor->StartPickCallback();
1203 myPreSelectionActor->SetVisibility(false);
1205 vtkPicker* aPicker = vtkPicker::SafeDownCast(m_Interactor->GetPicker());
1206 aPicker->Pick(x, y, 0.0, this->CurrentRenderer);
1208 SALOME_Actor* SActor = SALOME_Actor::SafeDownCast(aPicker->GetActor());
1210 if (vtkCellPicker* picker = vtkCellPicker::SafeDownCast(aPicker)) {
1211 int aVtkId = picker->GetCellId();
1212 if ( aVtkId >= 0 ) {
1213 int anObjId = SActor->GetElemObjId(aVtkId);
1214 if ( SActor && SActor->hasIO() && IsValid( SActor, aVtkId ) ) {
1215 bool anIsSameObjId = (mySelectedActor == SActor && myElemId == anObjId);
1216 bool aResult = anIsSameObjId;
1217 if(!anIsSameObjId) {
1218 if(aSelectionMode != EdgeOfCellSelection) {
1219 aResult = CheckDimensionId(aSelectionMode,SActor,anObjId);
1221 mySelectedActor = SActor;
1223 m_Interactor->setCellData(anObjId,SActor,myPreSelectionActor);
1227 if(aSelectionMode == EdgeOfCellSelection){
1228 int anEdgeId = GetEdgeId(picker,SActor,anObjId);
1229 bool anIsSameEdgeId = (myEdgeId != anEdgeId) && anIsSameObjId;
1230 aResult = anIsSameEdgeId;
1231 if(!anIsSameEdgeId) {
1232 aResult = (anEdgeId >= 0);
1234 mySelectedActor = SActor;
1235 myEdgeId = anEdgeId;
1237 m_Interactor->setEdgeData(anObjId,SActor,-anEdgeId-1,myPreSelectionActor);
1242 myPreSelectionActor->GetProperty()->SetRepresentationToSurface();
1243 myPreSelectionActor->SetVisibility(true);
1248 else if (vtkPointPicker* picker = vtkPointPicker::SafeDownCast(aPicker)) {
1249 int aVtkId = picker->GetPointId();
1250 if ( aVtkId >= 0 && IsValid( SActor, aVtkId, true ) ) {
1251 if ( SActor && SActor->hasIO() ) {
1252 int anObjId = SActor->GetNodeObjId(aVtkId);
1253 bool anIsSameObjId = (mySelectedActor == SActor && myNodeId == anObjId);
1254 if(!anIsSameObjId) {
1255 mySelectedActor = SActor;
1257 m_Interactor->setPointData(anObjId,SActor,myPreSelectionActor);
1259 myPreSelectionActor->GetProperty()->SetRepresentationToSurface();
1260 myPreSelectionActor->SetVisibility(true);
1264 else if ( vtkPicker::SafeDownCast(aPicker) ) {
1266 if ( myPreViewActor != SActor ) {
1267 if ( myPreViewActor != NULL ) {
1268 myPreViewActor->SetPreSelected( false );
1270 myPreViewActor = SActor;
1272 if ( SActor->hasIO() ) {
1273 Handle( SALOME_InteractiveObject) IO = SActor->getIO();
1274 if ( !IsSelected(IO,Sel) ) {
1275 // Find All actors with same IO
1276 vtkActorCollection* theActors = this->CurrentRenderer->GetActors();
1277 theActors->InitTraversal();
1278 while( vtkActor *ac = theActors->GetNextActor() ) {
1279 if ( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) ) {
1280 if ( anActor->hasIO() ) {
1281 Handle(SALOME_InteractiveObject) IOS = anActor->getIO();
1282 if(IO->isSame(IOS)) {
1283 anActor->SetPreSelected( true );
1292 myPreViewActor = NULL;
1293 vtkActorCollection* theActors = this->CurrentRenderer->GetActors();
1294 theActors->InitTraversal();
1295 while( vtkActor *ac = theActors->GetNextActor() ) {
1296 if ( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) ) {
1297 anActor->SetPreSelected( false );
1302 m_Interactor->EndPickCallback();
1303 //m_Interactor->Render();
1304 myGUIWindow->update();
1306 this->LastPos[0] = x;
1307 this->LastPos[1] = y;*/
1310 /*! called on finsh GlobalPan operation */
1311 void VTKViewer_InteractorStyle::Place(const int theX, const int theY)
1313 if (this->CurrentRenderer == NULL) {
1318 int *aSize = this->CurrentRenderer->GetRenderWindow()->GetSize();
1319 int centerX = aSize[0]/2;
1320 int centerY = aSize[1]/2;
1322 TranslateView(centerX, centerY, theX, theY);
1324 // restore zoom scale
1325 vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
1326 cam->SetParallelScale(myScale);
1327 ::ResetCameraClippingRange(this->CurrentRenderer);
1329 if (myGUIWindow) myGUIWindow->update();
1335 /*! Translates view from Point to Point*/
1336 void VTKViewer_InteractorStyle::TranslateView(int toX, int toY, int fromX, int fromY)
1338 vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
1339 vtkFloatingPointType viewFocus[4], focalDepth, viewPoint[3];
1340 vtkFloatingPointType newPickPoint[4], oldPickPoint[4], motionVector[3];
1341 cam->GetFocalPoint(viewFocus);
1343 this->ComputeWorldToDisplay(viewFocus[0], viewFocus[1],
1344 viewFocus[2], viewFocus);
1345 focalDepth = viewFocus[2];
1347 this->ComputeDisplayToWorld(vtkFloatingPointType(toX), vtkFloatingPointType(toY),
1348 focalDepth, newPickPoint);
1349 this->ComputeDisplayToWorld(vtkFloatingPointType(fromX),vtkFloatingPointType(fromY),
1350 focalDepth, oldPickPoint);
1352 // camera motion is reversed
1353 motionVector[0] = oldPickPoint[0] - newPickPoint[0];
1354 motionVector[1] = oldPickPoint[1] - newPickPoint[1];
1355 motionVector[2] = oldPickPoint[2] - newPickPoint[2];
1357 cam->GetFocalPoint(viewFocus);
1358 cam->GetPosition(viewPoint);
1359 cam->SetFocalPoint(motionVector[0] + viewFocus[0],
1360 motionVector[1] + viewFocus[1],
1361 motionVector[2] + viewFocus[2]);
1362 cam->SetPosition(motionVector[0] + viewPoint[0],
1363 motionVector[1] + viewPoint[1],
1364 motionVector[2] + viewPoint[2]);
1368 /*! Checks: is the given Actor within display coordinates?*/
1369 bool VTKViewer_InteractorStyle::IsInRect(vtkActor* theActor,
1370 const int left, const int top,
1371 const int right, const int bottom)
1373 vtkFloatingPointType* aBounds = theActor->GetBounds();
1374 vtkFloatingPointType aMin[3], aMax[3];
1375 ComputeWorldToDisplay(aBounds[0], aBounds[2], aBounds[4], aMin);
1376 ComputeWorldToDisplay(aBounds[1], aBounds[3], aBounds[5], aMax);
1377 if (aMin[0] > aMax[0]) {
1378 vtkFloatingPointType aBuf = aMin[0];
1382 if (aMin[1] > aMax[1]) {
1383 vtkFloatingPointType aBuf = aMin[1];
1388 return ((aMin[0]>left) && (aMax[0]<right) && (aMin[1]>bottom) && (aMax[1]<top));
1392 /*! Checks: is the given Cell within display coordinates?*/
1393 bool VTKViewer_InteractorStyle::IsInRect(vtkCell* theCell,
1394 const int left, const int top,
1395 const int right, const int bottom)
1397 vtkFloatingPointType* aBounds = theCell->GetBounds();
1398 vtkFloatingPointType aMin[3], aMax[3];
1399 ComputeWorldToDisplay(aBounds[0], aBounds[2], aBounds[4], aMin);
1400 ComputeWorldToDisplay(aBounds[1], aBounds[3], aBounds[5], aMax);
1401 if (aMin[0] > aMax[0]) {
1402 vtkFloatingPointType aBuf = aMin[0];
1406 if (aMin[1] > aMax[1]) {
1407 vtkFloatingPointType aBuf = aMin[1];
1412 return ((aMin[0]>left) && (aMax[0]<right) && (aMin[1]>bottom) && (aMax[1]<top));
1415 /*!Checks: is given point \a thePoint in rectangle*/
1416 bool VTKViewer_InteractorStyle::IsInRect(vtkFloatingPointType* thePoint,
1417 const int left, const int top,
1418 const int right, const int bottom)
1420 vtkFloatingPointType aPnt[3];
1421 ComputeWorldToDisplay(thePoint[0], thePoint[1], thePoint[2], aPnt);
1423 return ((aPnt[0]>left) && (aPnt[0]<right) && (aPnt[1]>bottom) && (aPnt[1]<top));
1426 /*!Set filter \a theFilter*/
1427 void VTKViewer_InteractorStyle::SetFilter( const Handle(VTKViewer_Filter)& theFilter )
1429 myFilters[ theFilter->GetId() ] = theFilter;
1432 /*!Checks: is filter present (with id \a theId)
1433 *\param theId - filter id.
1435 bool VTKViewer_InteractorStyle::IsFilterPresent( const int theId )
1437 return myFilters.find( theId ) != myFilters.end();
1440 /*!Remove filter with id \a theId.
1441 *\param theId - filter id.
1443 void VTKViewer_InteractorStyle::RemoveFilter( const int theId )
1445 if ( IsFilterPresent( theId ) )
1446 myFilters.erase( theId );
1449 /*!Checks: is valid cell(node) with id \a theId in actor \a theActor.
1450 *\param theActor - VTKViewer_Actor pointer.
1451 *\param theId - cell id.
1452 *\param theIsNode - boolean flag, if true - node, else - cell.
1454 bool VTKViewer_InteractorStyle::IsValid( VTKViewer_Actor* theActor,
1456 const bool theIsNode )
1458 std::map<int, Handle(VTKViewer_Filter)>::const_iterator anIter;
1459 for ( anIter = myFilters.begin(); anIter != myFilters.end(); ++anIter )
1461 const Handle(VTKViewer_Filter)& aFilter = anIter->second;
1462 if ( theIsNode == aFilter->IsNodeFilter() &&
1463 !aFilter->IsValid( theActor, theId ) )
1469 /*!Gets filter handle by filter id \a theId.*/
1470 Handle(VTKViewer_Filter) VTKViewer_InteractorStyle::GetFilter( const int theId )
1472 return IsFilterPresent( theId ) ? myFilters[ theId ] : Handle(VTKViewer_Filter)();
1476 *\param incrX - X coordinate increment.
1477 *\param incrY - Y coordinate increment.
1479 void VTKViewer_InteractorStyle::IncrementalPan( const int incrX, const int incrY )
1481 this->PanXY( incrX, incrY, 0, 0 );
1485 *\param incr - zoom increment.
1487 void VTKViewer_InteractorStyle::IncrementalZoom( const int incr )
1489 this->DollyXY( incr, incr );
1492 /*!Increment rotate.
1493 *\param incrX - X coordinate increment.
1494 *\param incrY - Y coordinate increment.
1496 void VTKViewer_InteractorStyle::IncrementalRotate( const int incrX, const int incrY )
1498 this->RotateXY( incrX, -incrY );