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_RectPicker.h"
34 #include "VTKViewer_ViewWindow.h"
35 #include "VTKViewer_RenderWindow.h"
36 #include "VTKViewer_CellRectPicker.h"
37 #include "VTKViewer_RenderWindowInteractor.h"
39 //#include "SALOME_Actor.h"
41 #include <vtkObjectFactory.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>
50 #include <vtkMapper.h>
51 #include <vtkDataSet.h>
52 #include <vtkSmartPointer.h>
54 #include <qapplication.h>
55 //VRV: porting on Qt 3.0.5
56 #if QT_VERSION >= 0x030005
59 //VRV: porting on Qt 3.0.5
62 //#include "utilities.h"
68 static int GetEdgeId(vtkPicker *thePicker, SALOME_Actor *theActor, int theObjId){
70 if (vtkCell* aPickedCell = theActor->GetElemCell(theObjId)) {
71 float aPickPosition[3];
72 thePicker->GetPickPosition(aPickPosition);
73 float aMinDist = 1000000.0, aDist = 0;
74 for (int i = 0, iEnd = aPickedCell->GetNumberOfEdges(); i < iEnd; i++){
75 if(vtkLine* aLine = vtkLine::SafeDownCast(aPickedCell->GetEdge(i))){
76 int subId; float pcoords[3], closestPoint[3], weights[3];
77 aLine->EvaluatePosition(aPickPosition,closestPoint,subId,pcoords,aDist,weights);
78 if (aDist < aMinDist) {
88 //----------------------------------------------------------------------------
89 vtkStandardNewMacro(VTKViewer_InteractorStyle);
91 //----------------------------------------------------------------------------
93 VTKViewer_InteractorStyle::VTKViewer_InteractorStyle()
96 this->MotionFactor = 10.0;
97 this->State = VTK_INTERACTOR_STYLE_CAMERA_NONE;
98 this->RadianToDegree = 180.0 / vtkMath::Pi();
99 this->ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
102 myPreSelectionActor = VTKViewer_Actor::New();
103 myPreSelectionActor->GetProperty()->SetColor(0,1,1);
104 myPreSelectionActor->GetProperty()->SetLineWidth(5);
105 myPreSelectionActor->GetProperty()->SetPointSize(5);
107 OnSelectionModeChanged();
110 //----------------------------------------------------------------------------
112 VTKViewer_InteractorStyle::~VTKViewer_InteractorStyle()
114 m_ViewWnd->RemoveActor(myPreSelectionActor);
117 //----------------------------------------------------------------------------
118 /*!Set preselection properties.
119 *\param theRed - red color.
120 *\param theGreen - green color.
121 *\param theBlue - blue color.
122 *\param theWidth - width..
124 void VTKViewer_InteractorStyle::setPreselectionProp(const double& theRed, const double& theGreen,
125 const double& theBlue, const int& theWidth)
127 if ( myPreSelectionActor->GetProperty() == 0 )
129 myPreSelectionActor->GetProperty()->SetColor(theRed, theGreen, theBlue);
130 myPreSelectionActor->GetProperty()->SetLineWidth(theWidth);
131 myPreSelectionActor->GetProperty()->SetPointSize(theWidth);
134 //----------------------------------------------------------------------------
135 /*!Set render window interactor
136 *\param theInteractor - interactor.
138 void VTKViewer_InteractorStyle::SetInteractor(vtkRenderWindowInteractor *theInteractor){
139 m_Interactor = dynamic_cast<VTKViewer_RenderWindowInteractor*>(theInteractor);
140 Superclass::SetInteractor(theInteractor);
143 //----------------------------------------------------------------------------
145 *\param theViewWnd - SALOME VTKViewer_ViewWindow
147 void VTKViewer_InteractorStyle::setViewWnd(VTKViewer_ViewWindow* theViewWnd ){
148 m_ViewWnd = theViewWnd;
149 m_ViewWnd->AddActor(myPreSelectionActor);
150 myPreSelectionActor->Delete();
153 //----------------------------------------------------------------------------
155 *\param theWindow - QWidget window.
157 void VTKViewer_InteractorStyle::setGUIWindow(QWidget* theWindow){
158 myGUIWindow = theWindow;
161 //----------------------------------------------------------------------------
163 *\param theTrihedron - SALOME VTKViewer_Trihedron
165 void VTKViewer_InteractorStyle::setTriedron(VTKViewer_Trihedron* theTrihedron){
166 m_Trihedron = theTrihedron;
169 //----------------------------------------------------------------------------
174 void VTKViewer_InteractorStyle::RotateXY(int dx, int dy)
180 if (this->CurrentRenderer == NULL)
185 int *size = this->CurrentRenderer->GetRenderWindow()->GetSize();
186 this->DeltaElevation = -20.0 / size[1];
187 this->DeltaAzimuth = -20.0 / size[0];
189 rxf = (double)dx * this->DeltaAzimuth * this->MotionFactor;
190 ryf = (double)dy * this->DeltaElevation * this->MotionFactor;
192 cam = this->CurrentRenderer->GetActiveCamera();
195 cam->OrthogonalizeViewUp();
196 ::ResetCameraClippingRange(this->CurrentRenderer);
197 //this->Interactor->Render();
198 myGUIWindow->update();
201 //----------------------------------------------------------------------------
202 void VTKViewer_InteractorStyle::PanXY(int x, int y, int oldX, int oldY)
204 TranslateView(x, y, oldX, oldY);
205 //this->Interactor->Render();
206 myGUIWindow->update();
210 //----------------------------------------------------------------------------
211 /*! Move the position of the camera along the direction of projection. (dx,dy)*/
212 void VTKViewer_InteractorStyle::DollyXY(int dx, int dy)
214 if (this->CurrentRenderer == NULL) return;
216 double dxf = this->MotionFactor * (double)(dx) / (double)(this->CurrentRenderer->GetCenter()[1]);
217 double dyf = this->MotionFactor * (double)(dy) / (double)(this->CurrentRenderer->GetCenter()[1]);
219 double zoomFactor = pow((double)1.1, dxf + dyf);
221 vtkCamera *aCam = this->CurrentRenderer->GetActiveCamera();
222 if (aCam->GetParallelProjection())
223 aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
225 aCam->Dolly(zoomFactor);
226 ::ResetCameraClippingRange(this->CurrentRenderer);
229 //this->Interactor->Render();
230 myGUIWindow->update();
233 //----------------------------------------------------------------------------
235 void VTKViewer_InteractorStyle::SpinXY(int x, int y, int oldX, int oldY)
239 if (this->CurrentRenderer == NULL)
244 double newAngle = atan2((double)(y - this->CurrentRenderer->GetCenter()[1]),
245 (double)(x - this->CurrentRenderer->GetCenter()[0]));
246 double oldAngle = atan2((double)(oldY -this->CurrentRenderer->GetCenter()[1]),
247 (double)(oldX - this->CurrentRenderer->GetCenter()[0]));
249 newAngle *= this->RadianToDegree;
250 oldAngle *= this->RadianToDegree;
252 cam = this->CurrentRenderer->GetActiveCamera();
253 cam->Roll(newAngle - oldAngle);
254 cam->OrthogonalizeViewUp();
256 //this->Interactor->Render();
257 myGUIWindow->update();
261 //----------------------------------------------------------------------------
262 /*!On mouse move event.
263 *\param ctrl - CTRL (not used)
264 *\param shift - SHIFT (on/off - integer 0/1)
265 *\param x - x coordinate
266 *\param y - y coordinate
268 void VTKViewer_InteractorStyle::OnMouseMove(int vtkNotUsed(ctrl),
272 myShiftState = shift;
273 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
274 onOperation(QPoint(x, y));
275 else if (ForcedState == VTK_INTERACTOR_STYLE_CAMERA_NONE)
276 onCursorMove(QPoint(x, y));
280 //----------------------------------------------------------------------------
281 /*!On Left button down event.
282 *\param ctrl - CTRL (on/off - integer 0/1)
283 *\param shift - SHIFT (on/off - integer 0/1)
284 *\param x - x coordinate
285 *\param y - y coordinate
287 void VTKViewer_InteractorStyle::OnLeftButtonDown(int ctrl, int shift,
290 if (this->HasObserver(vtkCommand::LeftButtonPressEvent)) {
291 this->InvokeEvent(vtkCommand::LeftButtonPressEvent,NULL);
294 this->FindPokedRenderer(x, y);
295 if (this->CurrentRenderer == NULL) {
298 myShiftState = shift;
299 // finishing current viewer operation
300 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
302 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
304 myOtherPoint = myPoint = QPoint(x, y);
305 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
306 startOperation(ForcedState);
309 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
311 startOperation(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
317 //----------------------------------------------------------------------------
318 /*!On left button up event.
319 *\param ctrl - CTRL (not used)
320 *\param shift - SHIFT (on/off - integer 0/1)
321 *\param x - x coordinate (not used)
322 *\param y - y coordinate (not used)
324 void VTKViewer_InteractorStyle::OnLeftButtonUp(int vtkNotUsed(ctrl),
329 myShiftState = shift;
330 // finishing current viewer operation
331 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
333 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
338 //----------------------------------------------------------------------------
339 /*!On left button up event.
340 *\param ctrl - CTRL (on/off - integer 0/1)
341 *\param shift - SHIFT (on/off - integer 0/1)
342 *\param x - x coordinate
343 *\param y - y coordinate
345 void VTKViewer_InteractorStyle::OnMiddleButtonDown(int ctrl,
349 if (this->HasObserver(vtkCommand::MiddleButtonPressEvent))
351 this->InvokeEvent(vtkCommand::MiddleButtonPressEvent,NULL);
354 this->FindPokedRenderer(x, y);
355 if (this->CurrentRenderer == NULL)
359 myShiftState = shift;
360 // finishing current viewer operation
361 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
363 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
365 myOtherPoint = myPoint = QPoint(x, y);
366 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
367 startOperation(ForcedState);
371 startOperation(VTK_INTERACTOR_STYLE_CAMERA_PAN);
376 //----------------------------------------------------------------------------
377 /*!On middle button up event.
378 *\param ctrl - CTRL (not used)
379 *\param shift - SHIFT (on/off - integer 0/1)
380 *\param x - x coordinate (not used)
381 *\param y - y coordinate (not used)
383 void VTKViewer_InteractorStyle::OnMiddleButtonUp(int vtkNotUsed(ctrl),
388 myShiftState = shift;
389 // finishing current viewer operation
390 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
392 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
397 //----------------------------------------------------------------------------
398 /*!On right button down event.
399 *\param ctrl - CTRL (on/off - integer 0/1)
400 *\param shift - SHIFT (on/off - integer 0/1)
401 *\param x - x coordinate
402 *\param y - y coordinate
404 void VTKViewer_InteractorStyle::OnRightButtonDown(int ctrl,
408 if (this->HasObserver(vtkCommand::RightButtonPressEvent))
410 this->InvokeEvent(vtkCommand::RightButtonPressEvent,NULL);
413 this->FindPokedRenderer(x, y);
414 if (this->CurrentRenderer == NULL)
418 myShiftState = shift;
419 // finishing current viewer operation
420 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
422 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
424 myOtherPoint = myPoint = QPoint(x, y);
425 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
426 startOperation(ForcedState);
430 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
434 //----------------------------------------------------------------------------
435 /*!On right button up event.
436 *\param ctrl - CTRL (not used)
437 *\param shift - SHIFT (on/off - integer 0/1)
438 *\param x - x coordinate (not used)
439 *\param y - y coordinate (not used)
441 void VTKViewer_InteractorStyle::OnRightButtonUp(int vtkNotUsed(ctrl),
446 myShiftState = shift;
447 // finishing current viewer operation
448 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
450 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
454 //----------------------------------------------------------------------------
455 /** @name XPM - x pixmaps. */
457 /*!Image Zoom cursor*/
458 const char* imageZoomCursor[] = {
463 "................................",
464 "................................",
465 ".#######........................",
466 "..aaaaaaa.......................",
467 "................................",
468 ".............#####..............",
469 "...........##.aaaa##............",
470 "..........#.aa.....a#...........",
471 ".........#.a.........#..........",
472 ".........#a..........#a.........",
473 "........#.a...........#.........",
474 "........#a............#a........",
475 "........#a............#a........",
476 "........#a............#a........",
477 "........#a............#a........",
478 ".........#...........#.a........",
479 ".........#a..........#a.........",
480 ".........##.........#.a.........",
481 "........#####.....##.a..........",
482 ".......###aaa#####.aa...........",
483 "......###aa...aaaaa.......#.....",
484 ".....###aa................#a....",
485 "....###aa.................#a....",
486 "...###aa...............#######..",
487 "....#aa.................aa#aaaa.",
488 ".....a....................#a....",
489 "..........................#a....",
490 "...........................a....",
491 "................................",
492 "................................",
493 "................................",
494 "................................"};
496 /*!Image rotate cursor*/
497 const char* imageRotateCursor[] = {
502 "................................",
503 "................................",
504 "................................",
505 "................................",
506 "........#.......................",
507 ".......#.a......................",
508 "......#######...................",
509 ".......#aaaaa#####..............",
510 "........#..##.a#aa##........##..",
511 ".........a#.aa..#..a#.....##.aa.",
512 ".........#.a.....#...#..##.aa...",
513 ".........#a.......#..###.aa.....",
514 "........#.a.......#a..#aa.......",
515 "........#a.........#..#a........",
516 "........#a.........#a.#a........",
517 "........#a.........#a.#a........",
518 "........#a.........#a.#a........",
519 ".........#.........#a#.a........",
520 "........##a........#a#a.........",
521 "......##.a#.......#.#.a.........",
522 "....##.aa..##.....##.a..........",
523 "..##.aa.....a#####.aa...........",
524 "...aa.........aaa#a.............",
525 "................#.a.............",
526 "...............#.a..............",
527 "..............#.a...............",
528 "...............a................",
529 "................................",
530 "................................",
531 "................................",
532 "................................",
533 "................................"};
536 //----------------------------------------------------------------------------
537 /*! Loads cursors for viewer operations - zoom, pan, etc...*/
538 void VTKViewer_InteractorStyle::loadCursors()
540 myDefCursor = QCursor(ArrowCursor);
541 myHandCursor = QCursor(PointingHandCursor);
542 myPanCursor = QCursor(SizeAllCursor);
543 myZoomCursor = QCursor(QPixmap(imageZoomCursor));
544 myRotateCursor = QCursor(QPixmap(imageRotateCursor));
545 mySpinCursor = QCursor(QPixmap(imageRotateCursor)); // temporarly !!!!!!
546 myGlobalPanCursor = QCursor(CrossCursor);
547 myCursorState = false;
551 //----------------------------------------------------------------------------
552 /*! event filter - controls mouse and keyboard events during viewer operations*/
553 bool VTKViewer_InteractorStyle::eventFilter(QObject* object, QEvent* event)
555 if (!myGUIWindow) return false;
556 if ( (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::KeyPress) && object != myGUIWindow)
558 qApp->removeEventFilter(this);
559 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
561 return QObject::eventFilter(object, event);
565 //----------------------------------------------------------------------------
566 /*! starts Zoom operation (e.g. through menu command)*/
567 void VTKViewer_InteractorStyle::startZoom()
569 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
572 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
574 setCursor(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
575 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ZOOM;
576 qApp->installEventFilter(this);
580 //----------------------------------------------------------------------------
581 /*! starts Pan operation (e.g. through menu command)*/
582 void VTKViewer_InteractorStyle::startPan()
584 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
587 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
589 setCursor(VTK_INTERACTOR_STYLE_CAMERA_PAN);
590 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_PAN;
591 qApp->installEventFilter(this);
594 //----------------------------------------------------------------------------
595 /*! starts Rotate operation (e.g. through menu command)*/
596 void VTKViewer_InteractorStyle::startRotate()
598 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
601 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
603 setCursor(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
604 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ROTATE;
605 qApp->installEventFilter(this);
609 //----------------------------------------------------------------------------
610 /*! starts Spin operation (e.g. through menu command)*/
611 void VTKViewer_InteractorStyle::startSpin()
613 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
616 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
618 setCursor(VTK_INTERACTOR_STYLE_CAMERA_SPIN);
619 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_SPIN;
620 qApp->installEventFilter(this);
625 //----------------------------------------------------------------------------
626 /*! starts Fit Area operation (e.g. through menu command)*/
627 void VTKViewer_InteractorStyle::startFitArea()
629 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
632 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
634 setCursor(VTK_INTERACTOR_STYLE_CAMERA_FIT);
635 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_FIT;
636 qApp->installEventFilter(this);
640 //----------------------------------------------------------------------------
642 void VTKViewer_InteractorStyle::ViewFitAll() {
643 int aTriedronWasVisible = false;
645 aTriedronWasVisible = m_Trihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
646 if(aTriedronWasVisible) m_Trihedron->VisibilityOff();
649 if(m_Trihedron->GetVisibleActorCount(CurrentRenderer)){
650 m_Trihedron->VisibilityOff();
651 ::ResetCamera(CurrentRenderer);
653 m_Trihedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
654 ::ResetCamera(CurrentRenderer,true);
656 if(aTriedronWasVisible) m_Trihedron->VisibilityOn();
657 else m_Trihedron->VisibilityOff();
658 ::ResetCameraClippingRange(CurrentRenderer);
662 //----------------------------------------------------------------------------
663 /*! starts Global Panning operation (e.g. through menu command)*/
664 void VTKViewer_InteractorStyle::startGlobalPan()
666 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
669 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
671 setCursor(VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN);
672 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN;
674 // store current zoom scale
675 vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
676 myScale = cam->GetParallelScale();
680 if (myGUIWindow) myGUIWindow->update();
682 qApp->installEventFilter(this);
686 //----------------------------------------------------------------------------
687 /*!\retval TRUE if needs redrawing*/
688 bool VTKViewer_InteractorStyle::needsRedrawing()
690 return State == VTK_INTERACTOR_STYLE_CAMERA_ZOOM ||
691 State == VTK_INTERACTOR_STYLE_CAMERA_PAN ||
692 State == VTK_INTERACTOR_STYLE_CAMERA_ROTATE ||
693 State == VTK_INTERACTOR_STYLE_CAMERA_SPIN ||
694 State == VTK_INTERACTOR_STYLE_CAMERA_NONE;
698 //----------------------------------------------------------------------------
699 /*! fits viewer contents to rectangle
700 *\param left - left side
701 *\param top - top side
702 *\param right - right side
703 *\param bottom - bottom side
705 void VTKViewer_InteractorStyle::fitRect(const int left,
710 if (this->CurrentRenderer == NULL) return;
713 int x = (left + right)/2;
714 int y = (top + bottom)/2;
715 int *aSize = this->CurrentRenderer->GetRenderWindow()->GetSize();
716 int oldX = aSize[0]/2;
717 int oldY = aSize[1]/2;
718 TranslateView(oldX, oldY, x, y);
721 double dxf = (double)(aSize[0]) / (double)(abs(right - left));
722 double dyf = (double)(aSize[1]) / (double)(abs(bottom - top));
723 double zoomFactor = (dxf + dyf)/2 ;
725 vtkCamera *aCam = this->CurrentRenderer->GetActiveCamera();
726 if(aCam->GetParallelProjection())
727 aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
729 aCam->Dolly(zoomFactor);
730 ::ResetCameraClippingRange(this->CurrentRenderer);
733 myGUIWindow->update();
737 //----------------------------------------------------------------------------
738 /*! starts viewer operation (!internal usage!)*/
739 void VTKViewer_InteractorStyle::startOperation(int operation)
743 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
744 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
745 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
746 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
747 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
748 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
749 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
750 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
751 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
753 if (State != VTK_INTERACTOR_STYLE_CAMERA_SELECT)
754 setCursor(operation);
757 case VTK_INTERACTOR_STYLE_CAMERA_NONE:
759 setCursor(VTK_INTERACTOR_STYLE_CAMERA_NONE);
760 State = ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
766 //----------------------------------------------------------------------------
767 /*! sets proper cursor for window when viewer operation is activated*/
768 void VTKViewer_InteractorStyle::setCursor(const int operation)
770 if (!myGUIWindow) return;
773 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
774 myGUIWindow->setCursor(myZoomCursor);
775 myCursorState = true;
777 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
778 myGUIWindow->setCursor(myPanCursor);
779 myCursorState = true;
781 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
782 myGUIWindow->setCursor(myRotateCursor);
783 myCursorState = true;
785 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
786 myGUIWindow->setCursor(mySpinCursor);
787 myCursorState = true;
789 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
790 myGUIWindow->setCursor(myGlobalPanCursor);
791 myCursorState = true;
793 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
794 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
795 myGUIWindow->setCursor(myHandCursor);
796 myCursorState = true;
798 case VTK_INTERACTOR_STYLE_CAMERA_NONE:
800 myGUIWindow->setCursor(myDefCursor);
801 myCursorState = false;
807 //----------------------------------------------------------------------------
808 /*! called when viewer operation started (!put necessary initialization here!)*/
809 void VTKViewer_InteractorStyle::onStartOperation()
811 if (!myGUIWindow) return;
812 // VSV: LOD actor activisation
813 // this->Interactor->GetRenderWindow()->SetDesiredUpdateRate(this->Interactor->GetDesiredUpdateRate());
815 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
816 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
818 QPainter p(myGUIWindow);
819 p.setPen(Qt::lightGray);
820 p.setRasterOp(Qt::XorROP);
821 p.drawRect(QRect(myPoint, myOtherPoint));
824 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
825 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
826 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
827 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
828 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
834 //----------------------------------------------------------------------------
835 /*! called when viewer operation finished (!put necessary post-processing here!)*/
836 void VTKViewer_InteractorStyle::onFinishOperation()
838 if (!myGUIWindow) return;
841 // SUIT_Study* aActiveStudy = SUIT_Application::getDesktop()->getActiveStudy();
842 // SALOME_Selection* aSel = SALOME_Selection::Selection( aActiveStudy->getSelection() );
844 // VSV: LOD actor activisation
845 // rwi->GetRenderWindow()->SetDesiredUpdateRate(rwi->GetStillUpdateRate());
847 // Selection_Mode aSelectionMode = aSel->SelectionMode();
848 // bool aSelActiveCompOnly = aSel->IsSelectActiveCompOnly();
851 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
852 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
854 QPainter p(myGUIWindow);
855 p.setPen(Qt::lightGray);
856 p.setRasterOp(Qt::XorROP);
857 QRect rect(myPoint, myOtherPoint);
859 rect = rect.normalize();
860 if (State == VTK_INTERACTOR_STYLE_CAMERA_FIT) {
861 // making fit rect opeation
863 m_Interactor->GetSize(w, h);
866 y1 = h - rect.top() - 1;
868 y2 = h - rect.bottom() - 1;
869 fitRect(x1, y1, x2, y2);
872 if (myPoint == myOtherPoint) {
873 // process point selection
875 m_Interactor->GetSize(w, h);
877 y = h - myPoint.y() - 1;
879 this->FindPokedRenderer(x, y);
880 m_Interactor->StartPickCallback();
882 vtkPicker* aPicker = vtkPicker::SafeDownCast(m_Interactor->GetPicker());
883 aPicker->Pick(x, y, 0.0, this->CurrentRenderer);
885 SALOME_Actor* SActor = SALOME_Actor::SafeDownCast(aPicker->GetActor());
887 if (vtkCellPicker* picker = vtkCellPicker::SafeDownCast(aPicker)) {
888 int aVtkId = picker->GetCellId();
889 if ( aVtkId >= 0 && SActor && SActor->hasIO() && IsValid( SActor, aVtkId ) ) {
890 int anObjId = SActor->GetElemObjId(aVtkId);
892 Handle(SALOME_InteractiveObject) IO = SActor->getIO();
893 if(aSelectionMode != EdgeOfCellSelection) {
894 if(CheckDimensionId(aSelectionMode,SActor,anObjId)){
895 if (IsSelected(IO,aSel)) {
896 // This IO is already in the selection
897 aSel->AddOrRemoveIndex( IO, anObjId, myShiftState, false );
900 this->HighlightProp( NULL );
901 aSel->ClearIObjects();
903 aSel->AddOrRemoveIndex( IO, anObjId, myShiftState, false );
904 aSel->AddIObject( IO, false );
909 this->HighlightProp( NULL );
910 aSel->ClearIObjects();
912 int anEdgeId = GetEdgeId(picker,SActor,anObjId);
914 aSel->AddOrRemoveIndex( IO, anObjId, true, false);
915 aSel->AddOrRemoveIndex( IO, -anEdgeId-1, true, true );
916 aSel->AddIObject( IO, false );
921 this->HighlightProp( NULL );
922 aSel->ClearIObjects();
924 } else if ( vtkPointPicker* picker = vtkPointPicker::SafeDownCast(aPicker) ) {
925 int aVtkId = picker->GetPointId();
926 if ( aVtkId >= 0 && IsValid( SActor, aVtkId, true ) ) {
927 if ( SActor && SActor->hasIO() ) {
928 int anObjId = SActor->GetNodeObjId(aVtkId);
930 Handle(SALOME_InteractiveObject) IO = SActor->getIO();
931 if(IsSelected(IO,aSel)) {
932 // This IO is already in the selection
933 aSel->AddOrRemoveIndex( IO, anObjId, myShiftState, false );
936 this->HighlightProp( NULL );
937 aSel->ClearIObjects();
939 aSel->AddOrRemoveIndex( IO, anObjId, myShiftState, false );
940 aSel->AddIObject( IO, false );
945 this->HighlightProp( NULL );
946 aSel->ClearIObjects();
949 if ( SActor && SActor->hasIO() ) {
951 Handle(SALOME_InteractiveObject) IO = SActor->getIO();
952 if(IsSelected(IO,aSel)) {
953 // This IO is already in the selection
955 aSel->RemoveIObject(IO);
960 this->HighlightProp( NULL );
961 aSel->ClearIObjects();
963 aSel->AddIObject( IO, false );
966 // No selection clear all
967 this->PropPicked = 0;
968 this->HighlightProp( NULL );
969 aSel->ClearIObjects();
972 m_Interactor->EndPickCallback();
974 //processing rectangle selection
975 QString aComponentDataType = SUIT_Application::getDesktop()->getComponentDataType();
976 if(aSelActiveCompOnly && aComponentDataType.isEmpty()) return;
977 m_Interactor->StartPickCallback();
980 this->PropPicked = 0;
981 this->HighlightProp( NULL );
982 aSel->ClearIObjects();
986 // vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
987 QRect rect(myPoint, myOtherPoint);
988 rect = rect.normalize();
990 m_Interactor->GetSize(w, h);
993 y1 = h - rect.top() - 1;
995 y2 = h - rect.bottom() - 1;
997 switch (aSelectionMode) {
998 case NodeSelection: {
999 if ( vtkPointPicker* aPointPicker = vtkPointPicker::SafeDownCast(m_Interactor->GetPicker()) ) {
1000 vtkActorCollection* aListActors = this->CurrentRenderer->GetActors();
1001 aListActors->InitTraversal();
1002 while (vtkActor* aActor = aListActors->GetNextActor()) {
1003 if (!aActor->GetVisibility())
1005 if(SALOME_Actor* SActor = SALOME_Actor::SafeDownCast(aActor)) {
1006 if (SActor->hasIO()) {
1007 Handle(SALOME_InteractiveObject) IO = SActor->getIO();
1010 if (aSelActiveCompOnly && aComponentDataType != IO->getComponentDataType())
1012 if (vtkDataSet* aDataSet = SActor->GetInput()) {
1013 SALOME_Selection::TContainerOfId anIndices;
1014 for(int i = 0; i < aDataSet->GetNumberOfPoints(); i++) {
1016 aDataSet->GetPoint(i,aPoint);
1017 if (IsInRect(aPoint,x1,y1,x2,y2)){
1019 ComputeWorldToDisplay(aPoint[0],aPoint[1],aPoint[2],aDisp);
1020 if(aPointPicker->Pick(aDisp[0],aDisp[1],0.0,CurrentRenderer)){
1021 if(vtkActorCollection *anActorCollection = aPointPicker->GetActors()){
1022 if(anActorCollection->IsItemPresent(SActor)){
1023 float aPickedPoint[3];
1024 aPointPicker->GetMapperPosition(aPickedPoint);
1025 vtkIdType aVtkId = aDataSet->FindPoint(aPickedPoint);
1026 if ( aVtkId >= 0 && IsValid( SActor, aVtkId, true ) ){
1027 int anObjId = SActor->GetNodeObjId(aVtkId);
1028 anIndices.insert(anObjId);
1035 if (!anIndices.empty()) {
1036 aSel->AddOrRemoveIndex(IO, anIndices, true, false);
1037 aSel->AddIObject(IO, false);
1040 aSel->RemoveIObject(IO, false);
1050 case EdgeOfCellSelection:
1053 case VolumeSelection:
1055 vtkSmartPointer<VTKViewer_CellRectPicker> picker = VTKViewer_CellRectPicker::New();
1056 picker->SetTolerance(0.001);
1057 picker->Pick(x1, y1, 0.0, x2, y2, 0.0, this->CurrentRenderer);
1059 vtkActorCollection* aListActors = picker->GetActors();
1060 aListActors->InitTraversal();
1061 while(vtkActor* aActor = aListActors->GetNextActor()) {
1062 if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)) {
1063 if (aSActor->hasIO()) {
1064 Handle(SALOME_InteractiveObject) aIO = aSActor->getIO();
1065 if (aSelActiveCompOnly && aComponentDataType != aIO->getComponentDataType())
1067 VTKViewer_CellDataSet cellList = picker->GetCellData(aActor);
1068 if ( !cellList.empty() ) {
1069 SALOME_Selection::TContainerOfId anIndexes;
1070 VTKViewer_CellDataSet::iterator it;
1071 for ( it = cellList.begin(); it != cellList.end(); ++it ) {
1072 int aCellId = (*it).cellId;
1074 if ( !IsValid( aSActor, aCellId ) )
1077 int anObjId = aSActor->GetElemObjId(aCellId);
1079 if ( CheckDimensionId(aSelectionMode,aSActor,anObjId) ) {
1080 anIndexes.insert(anObjId);
1084 aSel->AddOrRemoveIndex(aIO, anIndexes, true, false);
1085 aSel->AddIObject(aIO, false);
1092 case ActorSelection: // objects selection
1094 vtkSmartPointer<VTKViewer_RectPicker> picker = VTKViewer_RectPicker::New();
1095 picker->SetTolerance(0.001);
1096 picker->Pick(x1, y1, 0.0, x2, y2, 0.0, this->CurrentRenderer);
1098 vtkActorCollection* aListActors = picker->GetActors();
1099 SALOME_ListIO aListIO;
1100 aListActors->InitTraversal();
1101 while(vtkActor* aActor = aListActors->GetNextActor()) {
1102 if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)) {
1103 if (aSActor->hasIO()) {
1104 Handle(SALOME_InteractiveObject) aIO = aSActor->getIO();
1105 if (!IsStored(aIO,aListIO))
1106 aListIO.Append(aIO);
1110 if (!aListIO.IsEmpty()) {
1111 SALOME_ListIteratorOfListIO It(aListIO);
1112 for(;It.More();It.Next()) {
1113 Handle(SALOME_InteractiveObject) IOS = It.Value();
1115 aSel->AddIObject( IOS, false );
1120 m_Interactor->EndPickCallback();
1122 aActiveStudy->update3dViewers();
1126 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
1127 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
1128 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
1129 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
1131 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
1134 m_Interactor->GetSize(w, h);
1136 y = h - myPoint.y() - 1;
1141 if (myGUIWindow) myGUIWindow->update();
1145 /*! called during viewer operation when user moves mouse (!put necessary processing here!)*/
1146 void VTKViewer_InteractorStyle::onOperation(QPoint mousePos)
1148 if (!myGUIWindow) return;
1150 GetInteractor()->GetSize(w, h);
1152 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
1154 // processing panning
1155 //this->FindPokedCamera(mousePos.x(), mousePos.y());
1156 this->PanXY(mousePos.x(), myPoint.y(), myPoint.x(), mousePos.y());
1160 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
1162 // processing zooming
1163 //this->FindPokedCamera(mousePos.x(), mousePos.y());
1164 this->DollyXY(mousePos.x() - myPoint.x(), mousePos.y() - myPoint.y());
1168 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
1170 // processing rotation
1171 //this->FindPokedCamera(mousePos.x(), mousePos.y());
1172 this->RotateXY(mousePos.x() - myPoint.x(), myPoint.y() - mousePos.y());
1176 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
1178 // processing spinning
1179 //this->FindPokedCamera(mousePos.x(), mousePos.y());
1180 this->SpinXY(mousePos.x(), mousePos.y(), myPoint.x(), myPoint.y());
1184 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
1188 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
1191 setCursor(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
1193 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
1195 QPainter p(myGUIWindow);
1196 p.setPen(Qt::lightGray);
1197 p.setRasterOp(Qt::XorROP);
1198 p.drawRect(QRect(myPoint, myOtherPoint));
1199 myOtherPoint = mousePos;
1200 p.drawRect(QRect(myPoint, myOtherPoint));
1204 this->LastPos[0] = mousePos.x();
1205 this->LastPos[1] = h - mousePos.y() - 1;
1208 /*! called when selection mode changed (!put necessary initialization here!)*/
1209 void VTKViewer_InteractorStyle::OnSelectionModeChanged()
1212 myPreSelectionActor->SetVisibility(false);
1213 myElemId = myEdgeId = myNodeId = -1;
1214 mySelectedActor = NULL;
1217 /*! called when user moves mouse inside viewer window and there is no active viewer operation \n
1218 * (!put necessary processing here!)
1220 void VTKViewer_InteractorStyle::onCursorMove(QPoint mousePos) {
1221 // processing highlighting
1222 // SUIT_Study* anActiveStudy = SUIT_Application::getDesktop()->getActiveStudy();
1223 // SALOME_Selection* Sel = SALOME_Selection::Selection( anActiveStudy->getSelection() );
1224 // Selection_Mode aSelectionMode = Sel->SelectionMode();
1227 m_Interactor->GetSize(w, h);
1228 x = mousePos.x(); y = h - mousePos.y() - 1;
1230 this->FindPokedRenderer(x,y);
1231 m_Interactor->StartPickCallback();
1232 myPreSelectionActor->SetVisibility(false);
1234 vtkPicker* aPicker = vtkPicker::SafeDownCast(m_Interactor->GetPicker());
1235 aPicker->Pick(x, y, 0.0, this->CurrentRenderer);
1237 SALOME_Actor* SActor = SALOME_Actor::SafeDownCast(aPicker->GetActor());
1239 if (vtkCellPicker* picker = vtkCellPicker::SafeDownCast(aPicker)) {
1240 int aVtkId = picker->GetCellId();
1241 if ( aVtkId >= 0 ) {
1242 int anObjId = SActor->GetElemObjId(aVtkId);
1243 if ( SActor && SActor->hasIO() && IsValid( SActor, aVtkId ) ) {
1244 bool anIsSameObjId = (mySelectedActor == SActor && myElemId == anObjId);
1245 bool aResult = anIsSameObjId;
1246 if(!anIsSameObjId) {
1247 if(aSelectionMode != EdgeOfCellSelection) {
1248 aResult = CheckDimensionId(aSelectionMode,SActor,anObjId);
1250 mySelectedActor = SActor;
1252 m_Interactor->setCellData(anObjId,SActor,myPreSelectionActor);
1256 if(aSelectionMode == EdgeOfCellSelection){
1257 int anEdgeId = GetEdgeId(picker,SActor,anObjId);
1258 bool anIsSameEdgeId = (myEdgeId != anEdgeId) && anIsSameObjId;
1259 aResult = anIsSameEdgeId;
1260 if(!anIsSameEdgeId) {
1261 aResult = (anEdgeId >= 0);
1263 mySelectedActor = SActor;
1264 myEdgeId = anEdgeId;
1266 m_Interactor->setEdgeData(anObjId,SActor,-anEdgeId-1,myPreSelectionActor);
1271 myPreSelectionActor->GetProperty()->SetRepresentationToSurface();
1272 myPreSelectionActor->SetVisibility(true);
1277 else if (vtkPointPicker* picker = vtkPointPicker::SafeDownCast(aPicker)) {
1278 int aVtkId = picker->GetPointId();
1279 if ( aVtkId >= 0 && IsValid( SActor, aVtkId, true ) ) {
1280 if ( SActor && SActor->hasIO() ) {
1281 int anObjId = SActor->GetNodeObjId(aVtkId);
1282 bool anIsSameObjId = (mySelectedActor == SActor && myNodeId == anObjId);
1283 if(!anIsSameObjId) {
1284 mySelectedActor = SActor;
1286 m_Interactor->setPointData(anObjId,SActor,myPreSelectionActor);
1288 myPreSelectionActor->GetProperty()->SetRepresentationToSurface();
1289 myPreSelectionActor->SetVisibility(true);
1293 else if ( vtkPicker::SafeDownCast(aPicker) ) {
1295 if ( myPreViewActor != SActor ) {
1296 if ( myPreViewActor != NULL ) {
1297 myPreViewActor->SetPreSelected( false );
1299 myPreViewActor = SActor;
1301 if ( SActor->hasIO() ) {
1302 Handle( SALOME_InteractiveObject) IO = SActor->getIO();
1303 if ( !IsSelected(IO,Sel) ) {
1304 // Find All actors with same IO
1305 vtkActorCollection* theActors = this->CurrentRenderer->GetActors();
1306 theActors->InitTraversal();
1307 while( vtkActor *ac = theActors->GetNextActor() ) {
1308 if ( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) ) {
1309 if ( anActor->hasIO() ) {
1310 Handle(SALOME_InteractiveObject) IOS = anActor->getIO();
1311 if(IO->isSame(IOS)) {
1312 anActor->SetPreSelected( true );
1321 myPreViewActor = NULL;
1322 vtkActorCollection* theActors = this->CurrentRenderer->GetActors();
1323 theActors->InitTraversal();
1324 while( vtkActor *ac = theActors->GetNextActor() ) {
1325 if ( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) ) {
1326 anActor->SetPreSelected( false );
1331 m_Interactor->EndPickCallback();
1332 //m_Interactor->Render();
1333 myGUIWindow->update();
1335 this->LastPos[0] = x;
1336 this->LastPos[1] = y;*/
1339 /*! called on finsh GlobalPan operation */
1340 void VTKViewer_InteractorStyle::Place(const int theX, const int theY)
1342 if (this->CurrentRenderer == NULL) {
1347 int *aSize = this->CurrentRenderer->GetRenderWindow()->GetSize();
1348 int centerX = aSize[0]/2;
1349 int centerY = aSize[1]/2;
1351 TranslateView(centerX, centerY, theX, theY);
1353 // restore zoom scale
1354 vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
1355 cam->SetParallelScale(myScale);
1356 ::ResetCameraClippingRange(this->CurrentRenderer);
1358 if (myGUIWindow) myGUIWindow->update();
1364 /*! Translates view from Point to Point*/
1365 void VTKViewer_InteractorStyle::TranslateView(int toX, int toY, int fromX, int fromY)
1367 vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
1368 double viewFocus[4], focalDepth, viewPoint[3];
1369 float newPickPoint[4], oldPickPoint[4], motionVector[3];
1370 cam->GetFocalPoint(viewFocus);
1372 this->ComputeWorldToDisplay(viewFocus[0], viewFocus[1],
1373 viewFocus[2], viewFocus);
1374 focalDepth = viewFocus[2];
1376 this->ComputeDisplayToWorld(double(toX), double(toY),
1377 focalDepth, newPickPoint);
1378 this->ComputeDisplayToWorld(double(fromX),double(fromY),
1379 focalDepth, oldPickPoint);
1381 // camera motion is reversed
1382 motionVector[0] = oldPickPoint[0] - newPickPoint[0];
1383 motionVector[1] = oldPickPoint[1] - newPickPoint[1];
1384 motionVector[2] = oldPickPoint[2] - newPickPoint[2];
1386 cam->GetFocalPoint(viewFocus);
1387 cam->GetPosition(viewPoint);
1388 cam->SetFocalPoint(motionVector[0] + viewFocus[0],
1389 motionVector[1] + viewFocus[1],
1390 motionVector[2] + viewFocus[2]);
1391 cam->SetPosition(motionVector[0] + viewPoint[0],
1392 motionVector[1] + viewPoint[1],
1393 motionVector[2] + viewPoint[2]);
1397 /*! Checks: is the given Actor within display coordinates?*/
1398 bool VTKViewer_InteractorStyle::IsInRect(vtkActor* theActor,
1399 const int left, const int top,
1400 const int right, const int bottom)
1402 float* aBounds = theActor->GetBounds();
1403 float aMin[3], aMax[3];
1404 ComputeWorldToDisplay(aBounds[0], aBounds[2], aBounds[4], aMin);
1405 ComputeWorldToDisplay(aBounds[1], aBounds[3], aBounds[5], aMax);
1406 if (aMin[0] > aMax[0]) {
1407 float aBuf = aMin[0];
1411 if (aMin[1] > aMax[1]) {
1412 float aBuf = aMin[1];
1417 return ((aMin[0]>left) && (aMax[0]<right) && (aMin[1]>bottom) && (aMax[1]<top));
1421 /*! Checks: is the given Cell within display coordinates?*/
1422 bool VTKViewer_InteractorStyle::IsInRect(vtkCell* theCell,
1423 const int left, const int top,
1424 const int right, const int bottom)
1426 float* aBounds = theCell->GetBounds();
1427 float aMin[3], aMax[3];
1428 ComputeWorldToDisplay(aBounds[0], aBounds[2], aBounds[4], aMin);
1429 ComputeWorldToDisplay(aBounds[1], aBounds[3], aBounds[5], aMax);
1430 if (aMin[0] > aMax[0]) {
1431 float aBuf = aMin[0];
1435 if (aMin[1] > aMax[1]) {
1436 float aBuf = aMin[1];
1441 return ((aMin[0]>left) && (aMax[0]<right) && (aMin[1]>bottom) && (aMax[1]<top));
1444 /*!Checks: is given point \a thePoint in rectangle*/
1445 bool VTKViewer_InteractorStyle::IsInRect(float* thePoint,
1446 const int left, const int top,
1447 const int right, const int bottom)
1450 ComputeWorldToDisplay(thePoint[0], thePoint[1], thePoint[2], aPnt);
1452 return ((aPnt[0]>left) && (aPnt[0]<right) && (aPnt[1]>bottom) && (aPnt[1]<top));
1455 /*!Set filter \a theFilter*/
1456 void VTKViewer_InteractorStyle::SetFilter( const Handle(VTKViewer_Filter)& theFilter )
1458 myFilters[ theFilter->GetId() ] = theFilter;
1461 /*!Checks: is filter present (with id \a theId)
1462 *\param theId - filter id.
1464 bool VTKViewer_InteractorStyle::IsFilterPresent( const int theId )
1466 return myFilters.find( theId ) != myFilters.end();
1469 /*!Remove filter with id \a theId.
1470 *\param theId - filter id.
1472 void VTKViewer_InteractorStyle::RemoveFilter( const int theId )
1474 if ( IsFilterPresent( theId ) )
1475 myFilters.erase( theId );
1478 /*!Checks: is valid cell(node) with id \a theId in actor \a theActor.
1479 *\param theActor - VTKViewer_Actor pointer.
1480 *\param theId - cell id.
1481 *\param theIsNode - boolean flag, if true - node, else - cell.
1483 bool VTKViewer_InteractorStyle::IsValid( VTKViewer_Actor* theActor,
1485 const bool theIsNode )
1487 std::map<int, Handle(VTKViewer_Filter)>::const_iterator anIter;
1488 for ( anIter = myFilters.begin(); anIter != myFilters.end(); ++anIter )
1490 const Handle(VTKViewer_Filter)& aFilter = anIter->second;
1491 if ( theIsNode == aFilter->IsNodeFilter() &&
1492 !aFilter->IsValid( theActor, theId ) )
1498 /*!Gets filter handle by filter id \a theId.*/
1499 Handle(VTKViewer_Filter) VTKViewer_InteractorStyle::GetFilter( const int theId )
1501 return IsFilterPresent( theId ) ? myFilters[ theId ] : Handle(VTKViewer_Filter)();
1505 *\param incrX - X coordinate increment.
1506 *\param incrY - Y coordinate increment.
1508 void VTKViewer_InteractorStyle::IncrementalPan( const int incrX, const int incrY )
1510 this->PanXY( incrX, incrY, 0, 0 );
1514 *\param incr - zoom increment.
1516 void VTKViewer_InteractorStyle::IncrementalZoom( const int incr )
1518 this->DollyXY( incr, incr );
1521 /*!Increment rotate.
1522 *\param incrX - X coordinate increment.
1523 *\param incrY - Y coordinate increment.
1525 void VTKViewer_InteractorStyle::IncrementalRotate( const int incrX, const int incrY )
1527 this->RotateXY( incrX, -incrY );