1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SALOME VTKViewer : build VTK viewer into Salome desktop
24 // File : VTKViewer_InteractorStyle.cxx
25 // Author : Christophe ATTANASIO
27 #include "VTKViewer_InteractorStyle.h"
29 #include "VTKViewer_Actor.h"
30 #include "VTKViewer_Utilities.h"
31 #include "VTKViewer_Trihedron.h"
32 #include "VTKViewer_ViewWindow.h"
33 #include "VTKViewer_RenderWindow.h"
34 #include "VTKViewer_RenderWindowInteractor.h"
36 #include <vtkObjectFactory.h>
38 #include <vtkCommand.h>
39 #include <vtkCamera.h>
40 #include <vtkRenderer.h>
41 #include <vtkPicker.h>
42 #include <vtkPointPicker.h>
43 #include <vtkCellPicker.h>
45 #include <vtkMapper.h>
46 #include <vtkDataSet.h>
47 #include <vtkSmartPointer.h>
48 #include <vtkProperty.h>
50 #include <QApplication>
51 #include <QRubberBand>
56 static int GetEdgeId(vtkPicker *thePicker, SALOME_Actor *theActor, int theObjId){
58 if (vtkCell* aPickedCell = theActor->GetElemCell(theObjId)) {
59 float aPickPosition[3];
60 thePicker->GetPickPosition(aPickPosition);
61 float aMinDist = 1000000.0, aDist = 0;
62 for (int i = 0, iEnd = aPickedCell->GetNumberOfEdges(); i < iEnd; i++){
63 if(vtkLine* aLine = vtkLine::SafeDownCast(aPickedCell->GetEdge(i))){
64 int subId; float pcoords[3], closestPoint[3], weights[3];
65 aLine->EvaluatePosition(aPickPosition,closestPoint,subId,pcoords,aDist,weights);
66 if (aDist < aMinDist) {
77 vtkStandardNewMacro(VTKViewer_InteractorStyle);
81 VTKViewer_InteractorStyle::VTKViewer_InteractorStyle()
84 this->MotionFactor = 10.0;
85 this->State = VTK_INTERACTOR_STYLE_CAMERA_NONE;
86 this->RadianToDegree = 180.0 / vtkMath::Pi();
87 this->ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
90 myPreSelectionActor = VTKViewer_Actor::New();
91 myPreSelectionActor->GetProperty()->SetColor(0,1,1);
92 myPreSelectionActor->GetProperty()->SetLineWidth(5);
93 myPreSelectionActor->GetProperty()->SetPointSize(5);
97 OnSelectionModeChanged();
102 VTKViewer_InteractorStyle::~VTKViewer_InteractorStyle()
104 m_ViewWnd->RemoveActor(myPreSelectionActor);
109 /*!Set preselection properties.
110 *\param theRed - red color.
111 *\param theGreen - green color.
112 *\param theBlue - blue color.
113 *\param theWidth - width..
115 void VTKViewer_InteractorStyle::setPreselectionProp(const double& theRed, const double& theGreen,
116 const double& theBlue, const int& theWidth)
118 if ( myPreSelectionActor->GetProperty() == 0 )
120 myPreSelectionActor->GetProperty()->SetColor(theRed, theGreen, theBlue);
121 myPreSelectionActor->GetProperty()->SetLineWidth(theWidth);
122 myPreSelectionActor->GetProperty()->SetPointSize(theWidth);
126 /*!Set render window interactor
127 *\param theInteractor - interactor.
129 void VTKViewer_InteractorStyle::SetInteractor(vtkRenderWindowInteractor *theInteractor){
130 m_Interactor = dynamic_cast<VTKViewer_RenderWindowInteractor*>(theInteractor);
131 Superclass::SetInteractor(theInteractor);
136 *\param theViewWnd - SALOME VTKViewer_ViewWindow
138 void VTKViewer_InteractorStyle::setViewWnd(VTKViewer_ViewWindow* theViewWnd ){
139 m_ViewWnd = theViewWnd;
140 m_ViewWnd->AddActor(myPreSelectionActor);
141 myPreSelectionActor->Delete();
146 *\param theWindow - QWidget window.
148 void VTKViewer_InteractorStyle::setGUIWindow(QWidget* theWindow){
149 myGUIWindow = theWindow;
154 *\param theTrihedron - SALOME VTKViewer_Trihedron
156 void VTKViewer_InteractorStyle::setTriedron(VTKViewer_Trihedron* theTrihedron){
157 m_Trihedron = theTrihedron;
164 void VTKViewer_InteractorStyle::RotateXY(int dx, int dy)
170 if (this->CurrentRenderer == NULL)
175 int *size = this->CurrentRenderer->GetRenderWindow()->GetSize();
176 this->DeltaElevation = -20.0 / size[1];
177 this->DeltaAzimuth = -20.0 / size[0];
179 rxf = (double)dx * this->DeltaAzimuth * this->MotionFactor;
180 ryf = (double)dy * this->DeltaElevation * this->MotionFactor;
182 cam = this->CurrentRenderer->GetActiveCamera();
185 cam->OrthogonalizeViewUp();
186 ::ResetCameraClippingRange(this->CurrentRenderer);
187 //this->Interactor->Render();
188 myGUIWindow->update();
191 void VTKViewer_InteractorStyle::PanXY(int x, int y, int oldX, int oldY)
193 TranslateView(x, y, oldX, oldY);
194 //this->Interactor->Render();
195 myGUIWindow->update();
199 /*! Move the position of the camera along the direction of projection. (dx,dy)*/
200 void VTKViewer_InteractorStyle::DollyXY(int dx, int dy)
202 if (this->CurrentRenderer == NULL) return;
204 double dxf = this->MotionFactor * (double)(dx) / (double)(this->CurrentRenderer->GetCenter()[1]);
205 double dyf = this->MotionFactor * (double)(dy) / (double)(this->CurrentRenderer->GetCenter()[1]);
207 double zoomFactor = pow((double)1.1, dxf + dyf);
209 vtkCamera *aCam = this->CurrentRenderer->GetActiveCamera();
210 if (aCam->GetParallelProjection())
211 aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
213 aCam->Dolly(zoomFactor);
214 ::ResetCameraClippingRange(this->CurrentRenderer);
217 //this->Interactor->Render();
218 myGUIWindow->update();
221 void VTKViewer_InteractorStyle::SpinXY(int x, int y, int oldX, int oldY)
225 if (this->CurrentRenderer == NULL)
230 double newAngle = atan2((double)(y - this->CurrentRenderer->GetCenter()[1]),
231 (double)(x - this->CurrentRenderer->GetCenter()[0]));
232 double oldAngle = atan2((double)(oldY -this->CurrentRenderer->GetCenter()[1]),
233 (double)(oldX - this->CurrentRenderer->GetCenter()[0]));
235 newAngle *= this->RadianToDegree;
236 oldAngle *= this->RadianToDegree;
238 cam = this->CurrentRenderer->GetActiveCamera();
239 cam->Roll(newAngle - oldAngle);
240 cam->OrthogonalizeViewUp();
242 //this->Interactor->Render();
243 myGUIWindow->update();
247 /*!On mouse move event.
248 *\param ctrl - CTRL (not used)
249 *\param shift - SHIFT (on/off - integer 0/1)
250 *\param x - x coordinate
251 *\param y - y coordinate
253 void VTKViewer_InteractorStyle::OnMouseMove(int vtkNotUsed(ctrl),
257 myShiftState = shift;
258 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
259 onOperation(QPoint(x, y));
260 else if (ForcedState == VTK_INTERACTOR_STYLE_CAMERA_NONE)
261 onCursorMove(QPoint(x, y));
265 /*!On Left button down event.
266 *\param ctrl - CTRL (on/off - integer 0/1)
267 *\param shift - SHIFT (on/off - integer 0/1)
268 *\param x - x coordinate
269 *\param y - y coordinate
271 void VTKViewer_InteractorStyle::OnLeftButtonDown(int ctrl, int shift,
274 if (this->HasObserver(vtkCommand::LeftButtonPressEvent)) {
275 this->InvokeEvent(vtkCommand::LeftButtonPressEvent,NULL);
278 this->FindPokedRenderer(x, y);
279 if (this->CurrentRenderer == NULL) {
282 myShiftState = shift;
283 // finishing current viewer operation
284 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
286 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
288 myOtherPoint = myPoint = QPoint(x, y);
289 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
290 startOperation(ForcedState);
293 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
295 startOperation(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
301 /*!On left button up event.
302 *\param ctrl - CTRL (not used)
303 *\param shift - SHIFT (on/off - integer 0/1)
304 *\param x - x coordinate (not used)
305 *\param y - y coordinate (not used)
307 void VTKViewer_InteractorStyle::OnLeftButtonUp(int vtkNotUsed(ctrl),
312 myShiftState = shift;
313 // finishing current viewer operation
314 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
316 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
321 /*!On left button up event.
322 *\param ctrl - CTRL (on/off - integer 0/1)
323 *\param shift - SHIFT (on/off - integer 0/1)
324 *\param x - x coordinate
325 *\param y - y coordinate
327 void VTKViewer_InteractorStyle::OnMiddleButtonDown(int ctrl,
331 if (this->HasObserver(vtkCommand::MiddleButtonPressEvent))
333 this->InvokeEvent(vtkCommand::MiddleButtonPressEvent,NULL);
336 this->FindPokedRenderer(x, y);
337 if (this->CurrentRenderer == NULL)
341 myShiftState = shift;
342 // finishing current viewer operation
343 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
345 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
347 myOtherPoint = myPoint = QPoint(x, y);
348 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
349 startOperation(ForcedState);
353 startOperation(VTK_INTERACTOR_STYLE_CAMERA_PAN);
358 /*!On middle button up event.
359 *\param ctrl - CTRL (not used)
360 *\param shift - SHIFT (on/off - integer 0/1)
361 *\param x - x coordinate (not used)
362 *\param y - y coordinate (not used)
364 void VTKViewer_InteractorStyle::OnMiddleButtonUp(int vtkNotUsed(ctrl),
369 myShiftState = shift;
370 // finishing current viewer operation
371 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
373 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
378 /*!On right button down event.
379 *\param ctrl - CTRL (on/off - integer 0/1)
380 *\param shift - SHIFT (on/off - integer 0/1)
381 *\param x - x coordinate
382 *\param y - y coordinate
384 void VTKViewer_InteractorStyle::OnRightButtonDown(int ctrl,
388 if (this->HasObserver(vtkCommand::RightButtonPressEvent))
390 this->InvokeEvent(vtkCommand::RightButtonPressEvent,NULL);
393 this->FindPokedRenderer(x, y);
394 if (this->CurrentRenderer == NULL)
398 myShiftState = shift;
399 // finishing current viewer operation
400 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
402 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
404 myOtherPoint = myPoint = QPoint(x, y);
405 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
406 startOperation(ForcedState);
410 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
414 /*!On right button up event.
415 *\param ctrl - CTRL (not used)
416 *\param shift - SHIFT (on/off - integer 0/1)
417 *\param x - x coordinate (not used)
418 *\param y - y coordinate (not used)
420 void VTKViewer_InteractorStyle::OnRightButtonUp(int vtkNotUsed(ctrl),
425 myShiftState = shift;
426 // finishing current viewer operation
427 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
429 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
433 /*! @name XPM - x pixmaps. */
435 /*!Image Zoom cursor*/
436 const char* imageZoomCursor[] = {
441 "................................",
442 "................................",
443 ".#######........................",
444 "..aaaaaaa.......................",
445 "................................",
446 ".............#####..............",
447 "...........##.aaaa##............",
448 "..........#.aa.....a#...........",
449 ".........#.a.........#..........",
450 ".........#a..........#a.........",
451 "........#.a...........#.........",
452 "........#a............#a........",
453 "........#a............#a........",
454 "........#a............#a........",
455 "........#a............#a........",
456 ".........#...........#.a........",
457 ".........#a..........#a.........",
458 ".........##.........#.a.........",
459 "........#####.....##.a..........",
460 ".......###aaa#####.aa...........",
461 "......###aa...aaaaa.......#.....",
462 ".....###aa................#a....",
463 "....###aa.................#a....",
464 "...###aa...............#######..",
465 "....#aa.................aa#aaaa.",
466 ".....a....................#a....",
467 "..........................#a....",
468 "...........................a....",
469 "................................",
470 "................................",
471 "................................",
472 "................................"};
474 /*!Image rotate cursor*/
475 const char* imageRotateCursor[] = {
480 "................................",
481 "................................",
482 "................................",
483 "................................",
484 "........#.......................",
485 ".......#.a......................",
486 "......#######...................",
487 ".......#aaaaa#####..............",
488 "........#..##.a#aa##........##..",
489 ".........a#.aa..#..a#.....##.aa.",
490 ".........#.a.....#...#..##.aa...",
491 ".........#a.......#..###.aa.....",
492 "........#.a.......#a..#aa.......",
493 "........#a.........#..#a........",
494 "........#a.........#a.#a........",
495 "........#a.........#a.#a........",
496 "........#a.........#a.#a........",
497 ".........#.........#a#.a........",
498 "........##a........#a#a.........",
499 "......##.a#.......#.#.a.........",
500 "....##.aa..##.....##.a..........",
501 "..##.aa.....a#####.aa...........",
502 "...aa.........aaa#a.............",
503 "................#.a.............",
504 "...............#.a..............",
505 "..............#.a...............",
506 "...............a................",
507 "................................",
508 "................................",
509 "................................",
510 "................................",
511 "................................"};
514 /*! Loads cursors for viewer operations - zoom, pan, etc...*/
515 void VTKViewer_InteractorStyle::loadCursors()
517 myDefCursor = QCursor(Qt::ArrowCursor);
518 myHandCursor = QCursor(Qt::PointingHandCursor);
519 myPanCursor = QCursor(Qt::SizeAllCursor);
520 myZoomCursor = QCursor(QPixmap(imageZoomCursor));
521 myRotateCursor = QCursor(QPixmap(imageRotateCursor));
522 mySpinCursor = QCursor(QPixmap(imageRotateCursor)); // temporarly !!!!!!
523 myGlobalPanCursor = QCursor(Qt::CrossCursor);
524 myCursorState = false;
528 /*! event filter - controls mouse and keyboard events during viewer operations*/
529 bool VTKViewer_InteractorStyle::eventFilter(QObject* object, QEvent* event)
531 if (!myGUIWindow) return false;
532 if ( (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::KeyPress) && object != myGUIWindow)
534 qApp->removeEventFilter(this);
535 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
537 return QObject::eventFilter(object, event);
541 /*! starts Zoom operation (e.g. through menu command)*/
542 void VTKViewer_InteractorStyle::startZoom()
544 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
547 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
549 setCursor(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
550 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ZOOM;
551 qApp->installEventFilter(this);
555 /*! starts Pan operation (e.g. through menu command)*/
556 void VTKViewer_InteractorStyle::startPan()
558 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
561 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
563 setCursor(VTK_INTERACTOR_STYLE_CAMERA_PAN);
564 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_PAN;
565 qApp->installEventFilter(this);
568 /*! starts Rotate operation (e.g. through menu command)*/
569 void VTKViewer_InteractorStyle::startRotate()
571 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
574 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
576 setCursor(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
577 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ROTATE;
578 qApp->installEventFilter(this);
582 /*! starts Spin operation (e.g. through menu command)*/
583 void VTKViewer_InteractorStyle::startSpin()
585 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
588 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
590 setCursor(VTK_INTERACTOR_STYLE_CAMERA_SPIN);
591 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_SPIN;
592 qApp->installEventFilter(this);
597 /*! starts Fit Area operation (e.g. through menu command)*/
598 void VTKViewer_InteractorStyle::startFitArea()
600 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
603 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
605 setCursor(VTK_INTERACTOR_STYLE_CAMERA_FIT);
606 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_FIT;
607 qApp->installEventFilter(this);
612 void VTKViewer_InteractorStyle::ViewFitAll() {
613 int aTriedronWasVisible = false;
615 aTriedronWasVisible = m_Trihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
616 if(aTriedronWasVisible) m_Trihedron->VisibilityOff();
619 if(m_Trihedron->GetVisibleActorCount(CurrentRenderer)){
620 m_Trihedron->VisibilityOff();
621 ::ResetCamera(CurrentRenderer);
623 m_Trihedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
624 ::ResetCamera(CurrentRenderer,true);
626 if(aTriedronWasVisible) m_Trihedron->VisibilityOn();
627 else m_Trihedron->VisibilityOff();
628 ::ResetCameraClippingRange(CurrentRenderer);
631 /*!View fit selection.*/
632 void VTKViewer_InteractorStyle::ViewFitSelection() {
634 vtkActorCollection* aSelectedCollection = vtkActorCollection::New();
636 VTK::ActorCollectionCopy aCopy( CurrentRenderer->GetActors() );
637 vtkActorCollection* aCollection = aCopy.GetActors();
638 aCollection->InitTraversal();
639 while ( vtkActor* aProp = aCollection->GetNextActor() )
640 if ( VTKViewer_Actor* anActor = VTKViewer_Actor::SafeDownCast( aProp ) )
641 if ( anActor->isPreselected() )
642 aSelectedCollection->AddItem( aProp );
645 ::ComputeBounds( aSelectedCollection, bounds );
647 if ( aSelectedCollection->GetNumberOfItems() && ::isBoundValid( bounds ) ) {
648 CurrentRenderer->ResetCamera( bounds );
649 CurrentRenderer->ResetCameraClippingRange( bounds );
654 /*! starts Global Panning operation (e.g. through menu command)*/
655 void VTKViewer_InteractorStyle::startGlobalPan()
657 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
660 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
662 setCursor(VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN);
663 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN;
665 // store current zoom scale
666 vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
667 myScale = cam->GetParallelScale();
671 if (myGUIWindow) myGUIWindow->update();
673 qApp->installEventFilter(this);
677 /*!\retval \c true if needs redrawing*/
678 bool VTKViewer_InteractorStyle::needsRedrawing()
680 return State == VTK_INTERACTOR_STYLE_CAMERA_ZOOM ||
681 State == VTK_INTERACTOR_STYLE_CAMERA_PAN ||
682 State == VTK_INTERACTOR_STYLE_CAMERA_ROTATE ||
683 State == VTK_INTERACTOR_STYLE_CAMERA_SPIN ||
684 State == VTK_INTERACTOR_STYLE_CAMERA_NONE;
688 /*! fits viewer contents to rectangle
689 *\param left - left side
690 *\param top - top side
691 *\param right - right side
692 *\param bottom - bottom side
694 void VTKViewer_InteractorStyle::fitRect(const int left,
699 if (this->CurrentRenderer == NULL) return;
702 int x = (left + right)/2;
703 int y = (top + bottom)/2;
704 int *aSize = this->CurrentRenderer->GetRenderWindow()->GetSize();
705 int oldX = aSize[0]/2;
706 int oldY = aSize[1]/2;
707 TranslateView(oldX, oldY, x, y);
710 double dxf = (double)(aSize[0]) / (double)(abs(right - left));
711 double dyf = (double)(aSize[1]) / (double)(abs(bottom - top));
712 double zoomFactor = (dxf + dyf)/2 ;
714 vtkCamera *aCam = this->CurrentRenderer->GetActiveCamera();
715 if(aCam->GetParallelProjection())
716 aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
718 aCam->Dolly(zoomFactor);
719 ::ResetCameraClippingRange(this->CurrentRenderer);
722 myGUIWindow->update();
726 /*! starts viewer operation (!internal usage!)*/
727 void VTKViewer_InteractorStyle::startOperation(int operation)
731 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
732 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
733 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
734 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
735 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
736 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
737 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
738 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
739 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
741 if (State != VTK_INTERACTOR_STYLE_CAMERA_SELECT)
742 setCursor(operation);
745 case VTK_INTERACTOR_STYLE_CAMERA_NONE:
747 setCursor(VTK_INTERACTOR_STYLE_CAMERA_NONE);
748 State = ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
754 /*! sets proper cursor for window when viewer operation is activated*/
755 void VTKViewer_InteractorStyle::setCursor(const int operation)
757 if (!myGUIWindow) return;
760 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
761 myGUIWindow->setCursor(myZoomCursor);
762 myCursorState = true;
764 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
765 myGUIWindow->setCursor(myPanCursor);
766 myCursorState = true;
768 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
769 myGUIWindow->setCursor(myRotateCursor);
770 myCursorState = true;
772 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
773 myGUIWindow->setCursor(mySpinCursor);
774 myCursorState = true;
776 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
777 myGUIWindow->setCursor(myGlobalPanCursor);
778 myCursorState = true;
780 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
781 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
782 myGUIWindow->setCursor(myHandCursor);
783 myCursorState = true;
785 case VTK_INTERACTOR_STYLE_CAMERA_NONE:
787 myGUIWindow->setCursor(myDefCursor);
788 myCursorState = false;
794 Draws rectangle by starting and current points
796 void VTKViewer_InteractorStyle::drawRect()
799 myRectBand = new QRubberBand( QRubberBand::Rectangle, myGUIWindow );
801 palette.setColor(myRectBand->foregroundRole(), Qt::white);
802 myRectBand->setPalette(palette);
806 QRect aRect(myPoint, myOtherPoint);
807 myRectBand->setGeometry( aRect );
808 myRectBand->setVisible( aRect.isValid() );
812 \brief Delete rubber band on the end on the dragging operation.
814 void VTKViewer_InteractorStyle::endDrawRect()
820 /*! called when viewer operation started (!put necessary initialization here!)*/
821 void VTKViewer_InteractorStyle::onStartOperation()
823 if (!myGUIWindow) return;
824 // VSV: LOD actor activisation
825 // this->Interactor->GetRenderWindow()->SetDesiredUpdateRate(this->Interactor->GetDesiredUpdateRate());
827 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
828 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
833 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
834 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
835 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
836 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
837 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
843 /*! called when viewer operation finished (!put necessary post-processing here!)*/
844 void VTKViewer_InteractorStyle::onFinishOperation()
846 if (!myGUIWindow) return;
849 // SUIT_Study* aActiveStudy = SUIT_Application::getDesktop()->getActiveStudy();
850 // SALOME_Selection* aSel = SALOME_Selection::Selection( aActiveStudy->getSelection() );
852 // VSV: LOD actor activisation
853 // rwi->GetRenderWindow()->SetDesiredUpdateRate(rwi->GetStillUpdateRate());
855 // Selection_Mode aSelectionMode = aSel->SelectionMode();
856 // bool aSelActiveCompOnly = aSel->IsSelectActiveCompOnly();
859 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
860 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
862 QPainter p(myGUIWindow);
863 p.setPen(Qt::lightGray);
864 p.setRasterOp(Qt::XorROP);
865 QRect rect(myPoint, myOtherPoint);
867 rect = rect.normalize();
868 if (State == VTK_INTERACTOR_STYLE_CAMERA_FIT) {
869 // making fit rect opeation
871 m_Interactor->GetSize(w, h);
874 y1 = h - rect.top() - 1;
876 y2 = h - rect.bottom() - 1;
877 fitRect(x1, y1, x2, y2);
880 if (myPoint == myOtherPoint) {
881 // process point selection
883 m_Interactor->GetSize(w, h);
885 y = h - myPoint.y() - 1;
887 this->FindPokedRenderer(x, y);
888 m_Interactor->StartPickCallback();
890 vtkPicker* aPicker = vtkPicker::SafeDownCast(m_Interactor->GetPicker());
891 aPicker->Pick(x, y, 0.0, this->CurrentRenderer);
893 SALOME_Actor* SActor = SALOME_Actor::SafeDownCast(aPicker->GetActor());
895 if (vtkCellPicker* picker = vtkCellPicker::SafeDownCast(aPicker)) {
896 int aVtkId = picker->GetCellId();
897 if ( aVtkId >= 0 && SActor && SActor->hasIO() && IsValid( SActor, aVtkId ) ) {
898 int anObjId = SActor->GetElemObjId(aVtkId);
900 Handle(SALOME_InteractiveObject) IO = SActor->getIO();
901 if(aSelectionMode != EdgeOfCellSelection) {
902 if(CheckDimensionId(aSelectionMode,SActor,anObjId)){
903 if (IsSelected(IO,aSel)) {
904 // This IO is already in the selection
905 aSel->AddOrRemoveIndex( IO, anObjId, myShiftState, false );
908 this->HighlightProp( NULL );
909 aSel->ClearIObjects();
911 aSel->AddOrRemoveIndex( IO, anObjId, myShiftState, false );
912 aSel->AddIObject( IO, false );
917 this->HighlightProp( NULL );
918 aSel->ClearIObjects();
920 int anEdgeId = GetEdgeId(picker,SActor,anObjId);
922 aSel->AddOrRemoveIndex( IO, anObjId, true, false);
923 aSel->AddOrRemoveIndex( IO, -anEdgeId-1, true, true );
924 aSel->AddIObject( IO, false );
929 this->HighlightProp( NULL );
930 aSel->ClearIObjects();
932 } else if ( vtkPointPicker* picker = vtkPointPicker::SafeDownCast(aPicker) ) {
933 int aVtkId = picker->GetPointId();
934 if ( aVtkId >= 0 && IsValid( SActor, aVtkId, true ) ) {
935 if ( SActor && SActor->hasIO() ) {
936 int anObjId = SActor->GetNodeObjId(aVtkId);
938 Handle(SALOME_InteractiveObject) IO = SActor->getIO();
939 if(IsSelected(IO,aSel)) {
940 // This IO is already in the selection
941 aSel->AddOrRemoveIndex( IO, anObjId, myShiftState, false );
944 this->HighlightProp( NULL );
945 aSel->ClearIObjects();
947 aSel->AddOrRemoveIndex( IO, anObjId, myShiftState, false );
948 aSel->AddIObject( IO, false );
953 this->HighlightProp( NULL );
954 aSel->ClearIObjects();
957 if ( SActor && SActor->hasIO() ) {
959 Handle(SALOME_InteractiveObject) IO = SActor->getIO();
960 if(IsSelected(IO,aSel)) {
961 // This IO is already in the selection
963 aSel->RemoveIObject(IO);
968 this->HighlightProp( NULL );
969 aSel->ClearIObjects();
971 aSel->AddIObject( IO, false );
974 // No selection clear all
975 this->PropPicked = 0;
976 this->HighlightProp( NULL );
977 aSel->ClearIObjects();
980 m_Interactor->EndPickCallback();
982 //processing rectangle selection
983 QString aComponentDataType = SUIT_Application::getDesktop()->getComponentDataType();
984 if(aSelActiveCompOnly && aComponentDataType.isEmpty()) return;
985 m_Interactor->StartPickCallback();
988 this->PropPicked = 0;
989 this->HighlightProp( NULL );
990 aSel->ClearIObjects();
994 // vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
995 QRect rect(myPoint, myOtherPoint);
996 rect = rect.normalize();
998 m_Interactor->GetSize(w, h);
1001 y1 = h - rect.top() - 1;
1003 y2 = h - rect.bottom() - 1;
1005 switch (aSelectionMode) {
1006 case NodeSelection: {
1007 if ( vtkPointPicker* aPointPicker = vtkPointPicker::SafeDownCast(m_Interactor->GetPicker()) ) {
1008 vtkActorCollection* aListActors = this->CurrentRenderer->GetActors();
1009 aListActors->InitTraversal();
1010 while (vtkActor* aActor = aListActors->GetNextActor()) {
1011 if (!aActor->GetVisibility())
1013 if(SALOME_Actor* SActor = SALOME_Actor::SafeDownCast(aActor)) {
1014 if (SActor->hasIO()) {
1015 Handle(SALOME_InteractiveObject) IO = SActor->getIO();
1018 if (aSelActiveCompOnly && aComponentDataType != IO->getComponentDataType())
1020 if (vtkDataSet* aDataSet = SActor->GetInput()) {
1021 SALOME_Selection::TContainerOfId anIndices;
1022 for(int i = 0; i < aDataSet->GetNumberOfPoints(); i++) {
1024 aDataSet->GetPoint(i,aPoint);
1025 if (IsInRect(aPoint,x1,y1,x2,y2)){
1027 ComputeWorldToDisplay(aPoint[0],aPoint[1],aPoint[2],aDisp);
1028 if(aPointPicker->Pick(aDisp[0],aDisp[1],0.0,CurrentRenderer)){
1029 if(vtkActorCollection *anActorCollection = aPointPicker->GetActors()){
1030 if(anActorCollection->IsItemPresent(SActor)){
1031 float aPickedPoint[3];
1032 aPointPicker->GetMapperPosition(aPickedPoint);
1033 vtkIdType aVtkId = aDataSet->FindPoint(aPickedPoint);
1034 if ( aVtkId >= 0 && IsValid( SActor, aVtkId, true ) ){
1035 int anObjId = SActor->GetNodeObjId(aVtkId);
1036 anIndices.insert(anObjId);
1043 if (!anIndices.empty()) {
1044 aSel->AddOrRemoveIndex(IO, anIndices, true, false);
1045 aSel->AddIObject(IO, false);
1048 aSel->RemoveIObject(IO, false);
1058 case EdgeOfCellSelection:
1061 case VolumeSelection:
1063 vtkSmartPointer<VTKViewer_CellAreaPicker> picker = VTKViewer_CellRectPicker::New();
1064 picker->SetTolerance(0.001);
1065 picker->Pick(x1, y1, 0.0, x2, y2, 0.0, this->CurrentRenderer);
1067 vtkActorCollection* aListActors = picker->GetActors();
1068 aListActors->InitTraversal();
1069 while(vtkActor* aActor = aListActors->GetNextActor()) {
1070 if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)) {
1071 if (aSActor->hasIO()) {
1072 Handle(SALOME_InteractiveObject) aIO = aSActor->getIO();
1073 if (aSelActiveCompOnly && aComponentDataType != aIO->getComponentDataType())
1075 VTKViewer_CellDataSet cellList = picker->GetCellData(aActor);
1076 if ( !cellList.empty() ) {
1077 SALOME_Selection::TContainerOfId anIndexes;
1078 VTKViewer_CellDataSet::iterator it;
1079 for ( it = cellList.begin(); it != cellList.end(); ++it ) {
1080 int aCellId = (*it).cellId;
1082 if ( !IsValid( aSActor, aCellId ) )
1085 int anObjId = aSActor->GetElemObjId(aCellId);
1087 if ( CheckDimensionId(aSelectionMode,aSActor,anObjId) ) {
1088 anIndexes.insert(anObjId);
1092 aSel->AddOrRemoveIndex(aIO, anIndexes, true, false);
1093 aSel->AddIObject(aIO, false);
1100 case ActorSelection: // objects selection
1102 vtkSmartPointer<VTKViewer_AreaPicker> picker = VTKViewer_AreaPicker::New();
1103 picker->SetTolerance(0.001);
1104 picker->Pick(x1, y1, 0.0, x2, y2, 0.0, this->CurrentRenderer);
1106 vtkActorCollection* aListActors = picker->GetActors();
1107 SALOME_ListIO aListIO;
1108 aListActors->InitTraversal();
1109 while(vtkActor* aActor = aListActors->GetNextActor()) {
1110 if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)) {
1111 if (aSActor->hasIO()) {
1112 Handle(SALOME_InteractiveObject) aIO = aSActor->getIO();
1113 if (!IsStored(aIO,aListIO))
1114 aListIO.Append(aIO);
1118 if (!aListIO.IsEmpty()) {
1119 SALOME_ListIteratorOfListIO It(aListIO);
1120 for(;It.More();It.Next()) {
1121 Handle(SALOME_InteractiveObject) IOS = It.Value();
1123 aSel->AddIObject( IOS, false );
1128 m_Interactor->EndPickCallback();
1130 aActiveStudy->update3dViewers();
1134 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
1135 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
1136 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
1137 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
1139 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
1142 m_Interactor->GetSize(w, h);
1144 y = h - myPoint.y() - 1;
1149 if (myGUIWindow) myGUIWindow->update();
1153 /*! called during viewer operation when user moves mouse (!put necessary processing here!)*/
1154 void VTKViewer_InteractorStyle::onOperation(QPoint mousePos)
1156 if (!myGUIWindow) return;
1158 GetInteractor()->GetSize(w, h);
1160 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
1162 // processing panning
1163 //this->FindPokedCamera(mousePos.x(), mousePos.y());
1164 this->PanXY(mousePos.x(), myPoint.y(), myPoint.x(), mousePos.y());
1168 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
1170 // processing zooming
1171 //this->FindPokedCamera(mousePos.x(), mousePos.y());
1172 this->DollyXY(mousePos.x() - myPoint.x(), mousePos.y() - myPoint.y());
1176 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
1178 // processing rotation
1179 //this->FindPokedCamera(mousePos.x(), mousePos.y());
1180 this->RotateXY(mousePos.x() - myPoint.x(), myPoint.y() - mousePos.y());
1184 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
1186 // processing spinning
1187 //this->FindPokedCamera(mousePos.x(), mousePos.y());
1188 this->SpinXY(mousePos.x(), mousePos.y(), myPoint.x(), myPoint.y());
1192 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
1196 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
1199 setCursor(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
1201 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
1203 myOtherPoint = mousePos;
1208 this->LastPos[0] = mousePos.x();
1209 this->LastPos[1] = h - mousePos.y() - 1;
1212 /*! called when selection mode changed (!put necessary initialization here!)*/
1213 void VTKViewer_InteractorStyle::OnSelectionModeChanged()
1216 myPreSelectionActor->SetVisibility(false);
1217 myElemId = myEdgeId = myNodeId = -1;
1218 mySelectedActor = NULL;
1221 /*! called when user moves mouse inside viewer window and there is no active viewer operation \n
1222 * (!put necessary processing here!)
1224 void VTKViewer_InteractorStyle::onCursorMove(QPoint mousePos) {
1225 // processing highlighting
1226 // SUIT_Study* anActiveStudy = SUIT_Application::getDesktop()->getActiveStudy();
1227 // SALOME_Selection* Sel = SALOME_Selection::Selection( anActiveStudy->getSelection() );
1228 // Selection_Mode aSelectionMode = Sel->SelectionMode();
1231 m_Interactor->GetSize(w, h);
1232 x = mousePos.x(); y = h - mousePos.y() - 1;
1234 this->FindPokedRenderer(x,y);
1235 m_Interactor->StartPickCallback();
1236 myPreSelectionActor->SetVisibility(false);
1238 vtkPicker* aPicker = vtkPicker::SafeDownCast(m_Interactor->GetPicker());
1239 aPicker->Pick(x, y, 0.0, this->CurrentRenderer);
1241 SALOME_Actor* SActor = SALOME_Actor::SafeDownCast(aPicker->GetActor());
1243 if (vtkCellPicker* picker = vtkCellPicker::SafeDownCast(aPicker)) {
1244 int aVtkId = picker->GetCellId();
1245 if ( aVtkId >= 0 ) {
1246 int anObjId = SActor->GetElemObjId(aVtkId);
1247 if ( SActor && SActor->hasIO() && IsValid( SActor, aVtkId ) ) {
1248 bool anIsSameObjId = (mySelectedActor == SActor && myElemId == anObjId);
1249 bool aResult = anIsSameObjId;
1250 if(!anIsSameObjId) {
1251 if(aSelectionMode != EdgeOfCellSelection) {
1252 aResult = CheckDimensionId(aSelectionMode,SActor,anObjId);
1254 mySelectedActor = SActor;
1256 m_Interactor->setCellData(anObjId,SActor,myPreSelectionActor);
1260 if(aSelectionMode == EdgeOfCellSelection){
1261 int anEdgeId = GetEdgeId(picker,SActor,anObjId);
1262 bool anIsSameEdgeId = (myEdgeId != anEdgeId) && anIsSameObjId;
1263 aResult = anIsSameEdgeId;
1264 if(!anIsSameEdgeId) {
1265 aResult = (anEdgeId >= 0);
1267 mySelectedActor = SActor;
1268 myEdgeId = anEdgeId;
1270 m_Interactor->setEdgeData(anObjId,SActor,-anEdgeId-1,myPreSelectionActor);
1275 myPreSelectionActor->GetProperty()->SetRepresentationToSurface();
1276 myPreSelectionActor->SetVisibility(true);
1281 else if (vtkPointPicker* picker = vtkPointPicker::SafeDownCast(aPicker)) {
1282 int aVtkId = picker->GetPointId();
1283 if ( aVtkId >= 0 && IsValid( SActor, aVtkId, true ) ) {
1284 if ( SActor && SActor->hasIO() ) {
1285 int anObjId = SActor->GetNodeObjId(aVtkId);
1286 bool anIsSameObjId = (mySelectedActor == SActor && myNodeId == anObjId);
1287 if(!anIsSameObjId) {
1288 mySelectedActor = SActor;
1290 m_Interactor->setPointData(anObjId,SActor,myPreSelectionActor);
1292 myPreSelectionActor->GetProperty()->SetRepresentationToSurface();
1293 myPreSelectionActor->SetVisibility(true);
1297 else if ( vtkPicker::SafeDownCast(aPicker) ) {
1299 if ( myPreViewActor != SActor ) {
1300 if ( myPreViewActor != NULL ) {
1301 myPreViewActor->SetPreSelected( false );
1303 myPreViewActor = SActor;
1305 if ( SActor->hasIO() ) {
1306 Handle( SALOME_InteractiveObject) IO = SActor->getIO();
1307 if ( !IsSelected(IO,Sel) ) {
1308 // Find All actors with same IO
1309 vtkActorCollection* theActors = this->CurrentRenderer->GetActors();
1310 theActors->InitTraversal();
1311 while( vtkActor *ac = theActors->GetNextActor() ) {
1312 if ( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) ) {
1313 if ( anActor->hasIO() ) {
1314 Handle(SALOME_InteractiveObject) IOS = anActor->getIO();
1315 if(IO->isSame(IOS)) {
1316 anActor->SetPreSelected( true );
1325 myPreViewActor = NULL;
1326 vtkActorCollection* theActors = this->CurrentRenderer->GetActors();
1327 theActors->InitTraversal();
1328 while( vtkActor *ac = theActors->GetNextActor() ) {
1329 if ( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) ) {
1330 anActor->SetPreSelected( false );
1335 m_Interactor->EndPickCallback();
1336 //m_Interactor->Render();
1337 myGUIWindow->update();
1339 this->LastPos[0] = x;
1340 this->LastPos[1] = y;*/
1343 /*! called on finsh GlobalPan operation */
1344 void VTKViewer_InteractorStyle::Place(const int theX, const int theY)
1346 if (this->CurrentRenderer == NULL) {
1351 int *aSize = this->CurrentRenderer->GetRenderWindow()->GetSize();
1352 int centerX = aSize[0]/2;
1353 int centerY = aSize[1]/2;
1355 TranslateView(centerX, centerY, theX, theY);
1357 // restore zoom scale
1358 vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
1359 cam->SetParallelScale(myScale);
1360 ::ResetCameraClippingRange(this->CurrentRenderer);
1362 if (myGUIWindow) myGUIWindow->update();
1368 /*! Translates view from Point to Point*/
1369 void VTKViewer_InteractorStyle::TranslateView(int toX, int toY, int fromX, int fromY)
1371 vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
1372 double viewFocus[4], focalDepth, viewPoint[3];
1373 double newPickPoint[4], oldPickPoint[4], motionVector[3];
1374 cam->GetFocalPoint(viewFocus);
1376 this->ComputeWorldToDisplay(viewFocus[0], viewFocus[1],
1377 viewFocus[2], viewFocus);
1378 focalDepth = viewFocus[2];
1380 this->ComputeDisplayToWorld(double(toX), double(toY),
1381 focalDepth, newPickPoint);
1382 this->ComputeDisplayToWorld(double(fromX),double(fromY),
1383 focalDepth, oldPickPoint);
1385 // camera motion is reversed
1386 motionVector[0] = oldPickPoint[0] - newPickPoint[0];
1387 motionVector[1] = oldPickPoint[1] - newPickPoint[1];
1388 motionVector[2] = oldPickPoint[2] - newPickPoint[2];
1390 cam->GetFocalPoint(viewFocus);
1391 cam->GetPosition(viewPoint);
1392 cam->SetFocalPoint(motionVector[0] + viewFocus[0],
1393 motionVector[1] + viewFocus[1],
1394 motionVector[2] + viewFocus[2]);
1395 cam->SetPosition(motionVector[0] + viewPoint[0],
1396 motionVector[1] + viewPoint[1],
1397 motionVector[2] + viewPoint[2]);
1401 /*! Checks: is the given Actor within display coordinates?*/
1402 bool VTKViewer_InteractorStyle::IsInRect(vtkActor* theActor,
1403 const int left, const int top,
1404 const int right, const int bottom)
1406 double* aBounds = theActor->GetBounds();
1407 double aMin[3], aMax[3];
1408 ComputeWorldToDisplay(aBounds[0], aBounds[2], aBounds[4], aMin);
1409 ComputeWorldToDisplay(aBounds[1], aBounds[3], aBounds[5], aMax);
1410 if (aMin[0] > aMax[0]) {
1411 double aBuf = aMin[0];
1415 if (aMin[1] > aMax[1]) {
1416 double aBuf = aMin[1];
1421 return ((aMin[0]>left) && (aMax[0]<right) && (aMin[1]>bottom) && (aMax[1]<top));
1425 /*! Checks: is the given Cell within display coordinates?*/
1426 bool VTKViewer_InteractorStyle::IsInRect(vtkCell* theCell,
1427 const int left, const int top,
1428 const int right, const int bottom)
1430 double* aBounds = theCell->GetBounds();
1431 double aMin[3], aMax[3];
1432 ComputeWorldToDisplay(aBounds[0], aBounds[2], aBounds[4], aMin);
1433 ComputeWorldToDisplay(aBounds[1], aBounds[3], aBounds[5], aMax);
1434 if (aMin[0] > aMax[0]) {
1435 double aBuf = aMin[0];
1439 if (aMin[1] > aMax[1]) {
1440 double aBuf = aMin[1];
1445 return ((aMin[0]>left) && (aMax[0]<right) && (aMin[1]>bottom) && (aMax[1]<top));
1448 /*!Checks: is given point \a thePoint in rectangle*/
1449 bool VTKViewer_InteractorStyle::IsInRect(double* thePoint,
1450 const int left, const int top,
1451 const int right, const int bottom)
1454 ComputeWorldToDisplay(thePoint[0], thePoint[1], thePoint[2], aPnt);
1456 return ((aPnt[0]>left) && (aPnt[0]<right) && (aPnt[1]>bottom) && (aPnt[1]<top));
1459 /*!Set filter \a theFilter*/
1460 void VTKViewer_InteractorStyle::SetFilter( const Handle(VTKViewer_Filter)& theFilter )
1462 myFilters[ theFilter->GetId() ] = theFilter;
1465 /*!Checks: is filter present (with id \a theId)
1466 *\param theId - filter id.
1468 bool VTKViewer_InteractorStyle::IsFilterPresent( const int theId )
1470 return myFilters.find( theId ) != myFilters.end();
1473 /*!Remove filter with id \a theId.
1474 *\param theId - filter id.
1476 void VTKViewer_InteractorStyle::RemoveFilter( const int theId )
1478 if ( IsFilterPresent( theId ) )
1479 myFilters.erase( theId );
1482 /*!Checks: is valid cell(node) with id \a theId in actor \a theActor.
1483 *\param theActor - VTKViewer_Actor pointer.
1484 *\param theId - cell id.
1485 *\param theIsNode - boolean flag, if \c true - node, else - cell.
1487 bool VTKViewer_InteractorStyle::IsValid( VTKViewer_Actor* theActor,
1489 const bool theIsNode )
1491 std::map<int, Handle(VTKViewer_Filter)>::const_iterator anIter;
1492 for ( anIter = myFilters.begin(); anIter != myFilters.end(); ++anIter )
1494 const Handle(VTKViewer_Filter)& aFilter = anIter->second;
1495 if ( theIsNode == aFilter->IsNodeFilter() &&
1496 !aFilter->IsValid( theActor, theId ) )
1502 /*!Gets filter handle by filter id \a theId.*/
1503 Handle(VTKViewer_Filter) VTKViewer_InteractorStyle::GetFilter( const int theId )
1505 return IsFilterPresent( theId ) ? myFilters[ theId ] : Handle(VTKViewer_Filter)();
1509 *\param incrX - X coordinate increment.
1510 *\param incrY - Y coordinate increment.
1512 void VTKViewer_InteractorStyle::IncrementalPan( const int incrX, const int incrY )
1514 this->PanXY( incrX, incrY, 0, 0 );
1518 *\param incr - zoom increment.
1520 void VTKViewer_InteractorStyle::IncrementalZoom( const int incr )
1522 this->DollyXY( incr, incr );
1525 /*!Increment rotate.
1526 *\param incrX - X coordinate increment.
1527 *\param incrY - Y coordinate increment.
1529 void VTKViewer_InteractorStyle::IncrementalRotate( const int incrX, const int incrY )
1531 this->RotateXY( incrX, -incrY );