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 MYDEBUG = 0;
70 static int MYDEBUG = 0;
74 static int GetEdgeId(vtkPicker *thePicker, SALOME_Actor *theActor, int theObjId){
76 if (vtkCell* aPickedCell = theActor->GetElemCell(theObjId)) {
77 float aPickPosition[3];
78 thePicker->GetPickPosition(aPickPosition);
79 float aMinDist = 1000000.0, aDist = 0;
80 for (int i = 0, iEnd = aPickedCell->GetNumberOfEdges(); i < iEnd; i++){
81 if(vtkLine* aLine = vtkLine::SafeDownCast(aPickedCell->GetEdge(i))){
82 int subId; float pcoords[3], closestPoint[3], weights[3];
83 aLine->EvaluatePosition(aPickPosition,closestPoint,subId,pcoords,aDist,weights);
84 if (aDist < aMinDist) {
94 //----------------------------------------------------------------------------
95 vtkStandardNewMacro(VTKViewer_InteractorStyle);
97 //----------------------------------------------------------------------------
99 VTKViewer_InteractorStyle::VTKViewer_InteractorStyle()
102 this->MotionFactor = 10.0;
103 this->State = VTK_INTERACTOR_STYLE_CAMERA_NONE;
104 this->RadianToDegree = 180.0 / vtkMath::Pi();
105 this->ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
108 myPreSelectionActor = VTKViewer_Actor::New();
109 myPreSelectionActor->GetProperty()->SetColor(0,1,1);
110 myPreSelectionActor->GetProperty()->SetLineWidth(5);
111 myPreSelectionActor->GetProperty()->SetPointSize(5);
113 OnSelectionModeChanged();
116 //----------------------------------------------------------------------------
118 VTKViewer_InteractorStyle::~VTKViewer_InteractorStyle()
120 // if(MYDEBUG) INFOS("VTKViewer_InteractorStyle::~VTKViewer_InteractorStyle()");
121 m_ViewWnd->RemoveActor(myPreSelectionActor);
124 //----------------------------------------------------------------------------
125 /*!Set preselection properties.
126 *\param theRed - red color.
127 *\param theGreen - green color.
128 *\param theBlue - blue color.
129 *\param theWidth - width..
131 void VTKViewer_InteractorStyle::setPreselectionProp(const double& theRed, const double& theGreen,
132 const double& theBlue, const int& theWidth)
134 if ( myPreSelectionActor->GetProperty() == 0 )
136 myPreSelectionActor->GetProperty()->SetColor(theRed, theGreen, theBlue);
137 myPreSelectionActor->GetProperty()->SetLineWidth(theWidth);
138 myPreSelectionActor->GetProperty()->SetPointSize(theWidth);
141 //----------------------------------------------------------------------------
142 /*!Set render window interactor
143 *\param theInteractor - interactor.
145 void VTKViewer_InteractorStyle::SetInteractor(vtkRenderWindowInteractor *theInteractor){
146 m_Interactor = dynamic_cast<VTKViewer_RenderWindowInteractor*>(theInteractor);
147 Superclass::SetInteractor(theInteractor);
150 //----------------------------------------------------------------------------
152 *\param theViewWnd - SALOME VTKViewer_ViewWindow
154 void VTKViewer_InteractorStyle::setViewWnd(VTKViewer_ViewWindow* theViewWnd ){
155 m_ViewWnd = theViewWnd;
156 m_ViewWnd->AddActor(myPreSelectionActor);
157 myPreSelectionActor->Delete();
160 //----------------------------------------------------------------------------
162 *\param theWindow - QWidget window.
164 void VTKViewer_InteractorStyle::setGUIWindow(QWidget* theWindow){
165 myGUIWindow = theWindow;
168 //----------------------------------------------------------------------------
170 *\param theTrihedron - SALOME VTKViewer_Trihedron
172 void VTKViewer_InteractorStyle::setTriedron(VTKViewer_Trihedron* theTrihedron){
173 m_Trihedron = theTrihedron;
176 //----------------------------------------------------------------------------
181 void VTKViewer_InteractorStyle::RotateXY(int dx, int dy)
187 if (this->CurrentRenderer == NULL)
192 int *size = this->CurrentRenderer->GetRenderWindow()->GetSize();
193 this->DeltaElevation = -20.0 / size[1];
194 this->DeltaAzimuth = -20.0 / size[0];
196 rxf = (double)dx * this->DeltaAzimuth * this->MotionFactor;
197 ryf = (double)dy * this->DeltaElevation * this->MotionFactor;
199 cam = this->CurrentRenderer->GetActiveCamera();
202 cam->OrthogonalizeViewUp();
203 ::ResetCameraClippingRange(this->CurrentRenderer);
204 //this->Interactor->Render();
205 myGUIWindow->update();
208 //----------------------------------------------------------------------------
209 void VTKViewer_InteractorStyle::PanXY(int x, int y, int oldX, int oldY)
211 TranslateView(x, y, oldX, oldY);
212 //this->Interactor->Render();
213 myGUIWindow->update();
217 //----------------------------------------------------------------------------
218 /*! Move the position of the camera along the direction of projection. (dx,dy)*/
219 void VTKViewer_InteractorStyle::DollyXY(int dx, int dy)
221 if (this->CurrentRenderer == NULL) return;
223 double dxf = this->MotionFactor * (double)(dx) / (double)(this->CurrentRenderer->GetCenter()[1]);
224 double dyf = this->MotionFactor * (double)(dy) / (double)(this->CurrentRenderer->GetCenter()[1]);
226 double zoomFactor = pow((double)1.1, dxf + dyf);
228 vtkCamera *aCam = this->CurrentRenderer->GetActiveCamera();
229 if (aCam->GetParallelProjection())
230 aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
232 aCam->Dolly(zoomFactor);
233 ::ResetCameraClippingRange(this->CurrentRenderer);
236 //this->Interactor->Render();
237 myGUIWindow->update();
240 //----------------------------------------------------------------------------
242 void VTKViewer_InteractorStyle::SpinXY(int x, int y, int oldX, int oldY)
246 if (this->CurrentRenderer == NULL)
251 double newAngle = atan2((double)(y - this->CurrentRenderer->GetCenter()[1]),
252 (double)(x - this->CurrentRenderer->GetCenter()[0]));
253 double oldAngle = atan2((double)(oldY -this->CurrentRenderer->GetCenter()[1]),
254 (double)(oldX - this->CurrentRenderer->GetCenter()[0]));
256 newAngle *= this->RadianToDegree;
257 oldAngle *= this->RadianToDegree;
259 cam = this->CurrentRenderer->GetActiveCamera();
260 cam->Roll(newAngle - oldAngle);
261 cam->OrthogonalizeViewUp();
263 //this->Interactor->Render();
264 myGUIWindow->update();
268 //----------------------------------------------------------------------------
269 /*!On mouse move event.
270 *\param ctrl - CTRL (not used)
271 *\param shift - SHIFT (on/off - integer 0/1)
272 *\param x - x coordinate
273 *\param y - y coordinate
275 void VTKViewer_InteractorStyle::OnMouseMove(int vtkNotUsed(ctrl),
279 myShiftState = shift;
280 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
281 onOperation(QPoint(x, y));
282 else if (ForcedState == VTK_INTERACTOR_STYLE_CAMERA_NONE)
283 onCursorMove(QPoint(x, y));
287 //----------------------------------------------------------------------------
288 /*!On Left button down event.
289 *\param ctrl - CTRL (on/off - integer 0/1)
290 *\param shift - SHIFT (on/off - integer 0/1)
291 *\param x - x coordinate
292 *\param y - y coordinate
294 void VTKViewer_InteractorStyle::OnLeftButtonDown(int ctrl, int shift,
297 if (this->HasObserver(vtkCommand::LeftButtonPressEvent)) {
298 this->InvokeEvent(vtkCommand::LeftButtonPressEvent,NULL);
301 this->FindPokedRenderer(x, y);
302 if (this->CurrentRenderer == NULL) {
305 myShiftState = shift;
306 // finishing current viewer operation
307 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
309 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
311 myOtherPoint = myPoint = QPoint(x, y);
312 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
313 startOperation(ForcedState);
316 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
318 startOperation(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
324 //----------------------------------------------------------------------------
325 /*!On left button up event.
326 *\param ctrl - CTRL (not used)
327 *\param shift - SHIFT (on/off - integer 0/1)
328 *\param x - x coordinate (not used)
329 *\param y - y coordinate (not used)
331 void VTKViewer_InteractorStyle::OnLeftButtonUp(int vtkNotUsed(ctrl),
336 myShiftState = shift;
337 // finishing current viewer operation
338 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
340 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
345 //----------------------------------------------------------------------------
346 /*!On left button up event.
347 *\param ctrl - CTRL (on/off - integer 0/1)
348 *\param shift - SHIFT (on/off - integer 0/1)
349 *\param x - x coordinate
350 *\param y - y coordinate
352 void VTKViewer_InteractorStyle::OnMiddleButtonDown(int ctrl,
356 if (this->HasObserver(vtkCommand::MiddleButtonPressEvent))
358 this->InvokeEvent(vtkCommand::MiddleButtonPressEvent,NULL);
361 this->FindPokedRenderer(x, y);
362 if (this->CurrentRenderer == NULL)
366 myShiftState = shift;
367 // finishing current viewer operation
368 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
370 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
372 myOtherPoint = myPoint = QPoint(x, y);
373 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
374 startOperation(ForcedState);
378 startOperation(VTK_INTERACTOR_STYLE_CAMERA_PAN);
383 //----------------------------------------------------------------------------
384 /*!On middle button up event.
385 *\param ctrl - CTRL (not used)
386 *\param shift - SHIFT (on/off - integer 0/1)
387 *\param x - x coordinate (not used)
388 *\param y - y coordinate (not used)
390 void VTKViewer_InteractorStyle::OnMiddleButtonUp(int vtkNotUsed(ctrl),
395 myShiftState = shift;
396 // finishing current viewer operation
397 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
399 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
404 //----------------------------------------------------------------------------
405 /*!On right button down event.
406 *\param ctrl - CTRL (on/off - integer 0/1)
407 *\param shift - SHIFT (on/off - integer 0/1)
408 *\param x - x coordinate
409 *\param y - y coordinate
411 void VTKViewer_InteractorStyle::OnRightButtonDown(int ctrl,
415 if (this->HasObserver(vtkCommand::RightButtonPressEvent))
417 this->InvokeEvent(vtkCommand::RightButtonPressEvent,NULL);
420 this->FindPokedRenderer(x, y);
421 if (this->CurrentRenderer == NULL)
425 myShiftState = shift;
426 // finishing current viewer operation
427 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
429 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
431 myOtherPoint = myPoint = QPoint(x, y);
432 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
433 startOperation(ForcedState);
437 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
441 //----------------------------------------------------------------------------
442 /*!On right button up event.
443 *\param ctrl - CTRL (not used)
444 *\param shift - SHIFT (on/off - integer 0/1)
445 *\param x - x coordinate (not used)
446 *\param y - y coordinate (not used)
448 void VTKViewer_InteractorStyle::OnRightButtonUp(int vtkNotUsed(ctrl),
453 myShiftState = shift;
454 // finishing current viewer operation
455 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
457 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
461 //----------------------------------------------------------------------------
462 /** @name XPM - x pixmaps. */
464 /*!Image Zoom cursor*/
465 const char* imageZoomCursor[] = {
470 "................................",
471 "................................",
472 ".#######........................",
473 "..aaaaaaa.......................",
474 "................................",
475 ".............#####..............",
476 "...........##.aaaa##............",
477 "..........#.aa.....a#...........",
478 ".........#.a.........#..........",
479 ".........#a..........#a.........",
480 "........#.a...........#.........",
481 "........#a............#a........",
482 "........#a............#a........",
483 "........#a............#a........",
484 "........#a............#a........",
485 ".........#...........#.a........",
486 ".........#a..........#a.........",
487 ".........##.........#.a.........",
488 "........#####.....##.a..........",
489 ".......###aaa#####.aa...........",
490 "......###aa...aaaaa.......#.....",
491 ".....###aa................#a....",
492 "....###aa.................#a....",
493 "...###aa...............#######..",
494 "....#aa.................aa#aaaa.",
495 ".....a....................#a....",
496 "..........................#a....",
497 "...........................a....",
498 "................................",
499 "................................",
500 "................................",
501 "................................"};
503 /*!Image rotate cursor*/
504 const char* imageRotateCursor[] = {
509 "................................",
510 "................................",
511 "................................",
512 "................................",
513 "........#.......................",
514 ".......#.a......................",
515 "......#######...................",
516 ".......#aaaaa#####..............",
517 "........#..##.a#aa##........##..",
518 ".........a#.aa..#..a#.....##.aa.",
519 ".........#.a.....#...#..##.aa...",
520 ".........#a.......#..###.aa.....",
521 "........#.a.......#a..#aa.......",
522 "........#a.........#..#a........",
523 "........#a.........#a.#a........",
524 "........#a.........#a.#a........",
525 "........#a.........#a.#a........",
526 ".........#.........#a#.a........",
527 "........##a........#a#a.........",
528 "......##.a#.......#.#.a.........",
529 "....##.aa..##.....##.a..........",
530 "..##.aa.....a#####.aa...........",
531 "...aa.........aaa#a.............",
532 "................#.a.............",
533 "...............#.a..............",
534 "..............#.a...............",
535 "...............a................",
536 "................................",
537 "................................",
538 "................................",
539 "................................",
540 "................................"};
543 //----------------------------------------------------------------------------
544 /*! Loads cursors for viewer operations - zoom, pan, etc...*/
545 void VTKViewer_InteractorStyle::loadCursors()
547 myDefCursor = QCursor(ArrowCursor);
548 myHandCursor = QCursor(PointingHandCursor);
549 myPanCursor = QCursor(SizeAllCursor);
550 myZoomCursor = QCursor(QPixmap(imageZoomCursor));
551 myRotateCursor = QCursor(QPixmap(imageRotateCursor));
552 mySpinCursor = QCursor(QPixmap(imageRotateCursor)); // temporarly !!!!!!
553 myGlobalPanCursor = QCursor(CrossCursor);
554 myCursorState = false;
558 //----------------------------------------------------------------------------
559 /*! event filter - controls mouse and keyboard events during viewer operations*/
560 bool VTKViewer_InteractorStyle::eventFilter(QObject* object, QEvent* event)
562 if (!myGUIWindow) return false;
563 if ( (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::KeyPress) && object != myGUIWindow)
565 qApp->removeEventFilter(this);
566 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
568 return QObject::eventFilter(object, event);
572 //----------------------------------------------------------------------------
573 /*! starts Zoom operation (e.g. through menu command)*/
574 void VTKViewer_InteractorStyle::startZoom()
576 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
579 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
581 setCursor(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
582 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ZOOM;
583 qApp->installEventFilter(this);
587 //----------------------------------------------------------------------------
588 /*! starts Pan operation (e.g. through menu command)*/
589 void VTKViewer_InteractorStyle::startPan()
591 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
594 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
596 setCursor(VTK_INTERACTOR_STYLE_CAMERA_PAN);
597 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_PAN;
598 qApp->installEventFilter(this);
601 //----------------------------------------------------------------------------
602 /*! starts Rotate operation (e.g. through menu command)*/
603 void VTKViewer_InteractorStyle::startRotate()
605 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
608 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
610 setCursor(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
611 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ROTATE;
612 qApp->installEventFilter(this);
616 //----------------------------------------------------------------------------
617 /*! starts Spin operation (e.g. through menu command)*/
618 void VTKViewer_InteractorStyle::startSpin()
620 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
623 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
625 setCursor(VTK_INTERACTOR_STYLE_CAMERA_SPIN);
626 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_SPIN;
627 qApp->installEventFilter(this);
632 //----------------------------------------------------------------------------
633 /*! starts Fit Area operation (e.g. through menu command)*/
634 void VTKViewer_InteractorStyle::startFitArea()
636 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
639 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
641 setCursor(VTK_INTERACTOR_STYLE_CAMERA_FIT);
642 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_FIT;
643 qApp->installEventFilter(this);
647 //----------------------------------------------------------------------------
649 void VTKViewer_InteractorStyle::ViewFitAll() {
650 int aTriedronWasVisible = false;
652 aTriedronWasVisible = m_Trihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
653 if(aTriedronWasVisible) m_Trihedron->VisibilityOff();
656 if(m_Trihedron->GetVisibleActorCount(CurrentRenderer)){
657 m_Trihedron->VisibilityOff();
658 ::ResetCamera(CurrentRenderer);
660 m_Trihedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
661 ::ResetCamera(CurrentRenderer,true);
663 if(aTriedronWasVisible) m_Trihedron->VisibilityOn();
664 else m_Trihedron->VisibilityOff();
665 ::ResetCameraClippingRange(CurrentRenderer);
669 //----------------------------------------------------------------------------
670 /*! starts Global Panning operation (e.g. through menu command)*/
671 void VTKViewer_InteractorStyle::startGlobalPan()
673 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
676 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
678 setCursor(VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN);
679 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN;
681 // store current zoom scale
682 vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
683 myScale = cam->GetParallelScale();
687 if (myGUIWindow) myGUIWindow->update();
689 qApp->installEventFilter(this);
693 //----------------------------------------------------------------------------
694 /*!\retval TRUE if needs redrawing*/
695 bool VTKViewer_InteractorStyle::needsRedrawing()
697 return State == VTK_INTERACTOR_STYLE_CAMERA_ZOOM ||
698 State == VTK_INTERACTOR_STYLE_CAMERA_PAN ||
699 State == VTK_INTERACTOR_STYLE_CAMERA_ROTATE ||
700 State == VTK_INTERACTOR_STYLE_CAMERA_SPIN ||
701 State == VTK_INTERACTOR_STYLE_CAMERA_NONE;
705 //----------------------------------------------------------------------------
706 /*! fits viewer contents to rectangle
707 *\param left - left side
708 *\param top - top side
709 *\param right - right side
710 *\param bottom - bottom side
712 void VTKViewer_InteractorStyle::fitRect(const int left,
717 if (this->CurrentRenderer == NULL) return;
720 int x = (left + right)/2;
721 int y = (top + bottom)/2;
722 int *aSize = this->CurrentRenderer->GetRenderWindow()->GetSize();
723 int oldX = aSize[0]/2;
724 int oldY = aSize[1]/2;
725 TranslateView(oldX, oldY, x, y);
728 double dxf = (double)(aSize[0]) / (double)(abs(right - left));
729 double dyf = (double)(aSize[1]) / (double)(abs(bottom - top));
730 double zoomFactor = (dxf + dyf)/2 ;
732 vtkCamera *aCam = this->CurrentRenderer->GetActiveCamera();
733 if(aCam->GetParallelProjection())
734 aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
736 aCam->Dolly(zoomFactor);
737 ::ResetCameraClippingRange(this->CurrentRenderer);
740 myGUIWindow->update();
744 //----------------------------------------------------------------------------
745 /*! starts viewer operation (!internal usage!)*/
746 void VTKViewer_InteractorStyle::startOperation(int operation)
750 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
751 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
752 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
753 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
754 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
755 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
756 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
757 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
758 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
760 if (State != VTK_INTERACTOR_STYLE_CAMERA_SELECT)
761 setCursor(operation);
764 case VTK_INTERACTOR_STYLE_CAMERA_NONE:
766 setCursor(VTK_INTERACTOR_STYLE_CAMERA_NONE);
767 State = ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
773 //----------------------------------------------------------------------------
774 /*! sets proper cursor for window when viewer operation is activated*/
775 void VTKViewer_InteractorStyle::setCursor(const int operation)
777 if (!myGUIWindow) return;
780 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
781 myGUIWindow->setCursor(myZoomCursor);
782 myCursorState = true;
784 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
785 myGUIWindow->setCursor(myPanCursor);
786 myCursorState = true;
788 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
789 myGUIWindow->setCursor(myRotateCursor);
790 myCursorState = true;
792 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
793 myGUIWindow->setCursor(mySpinCursor);
794 myCursorState = true;
796 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
797 myGUIWindow->setCursor(myGlobalPanCursor);
798 myCursorState = true;
800 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
801 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
802 myGUIWindow->setCursor(myHandCursor);
803 myCursorState = true;
805 case VTK_INTERACTOR_STYLE_CAMERA_NONE:
807 myGUIWindow->setCursor(myDefCursor);
808 myCursorState = false;
814 //----------------------------------------------------------------------------
815 /*! called when viewer operation started (!put necessary initialization here!)*/
816 void VTKViewer_InteractorStyle::onStartOperation()
818 if (!myGUIWindow) return;
819 // VSV: LOD actor activisation
820 // this->Interactor->GetRenderWindow()->SetDesiredUpdateRate(this->Interactor->GetDesiredUpdateRate());
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 p.drawRect(QRect(myPoint, myOtherPoint));
831 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
832 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
833 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
834 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
835 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
841 //----------------------------------------------------------------------------
842 /*! called when viewer operation finished (!put necessary post-processing here!)*/
843 void VTKViewer_InteractorStyle::onFinishOperation()
845 if (!myGUIWindow) return;
848 // SUIT_Study* aActiveStudy = SUIT_Application::getDesktop()->getActiveStudy();
849 // SALOME_Selection* aSel = SALOME_Selection::Selection( aActiveStudy->getSelection() );
851 // VSV: LOD actor activisation
852 // rwi->GetRenderWindow()->SetDesiredUpdateRate(rwi->GetStillUpdateRate());
854 // Selection_Mode aSelectionMode = aSel->SelectionMode();
855 // bool aSelActiveCompOnly = aSel->IsSelectActiveCompOnly();
858 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
859 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
861 QPainter p(myGUIWindow);
862 p.setPen(Qt::lightGray);
863 p.setRasterOp(Qt::XorROP);
864 QRect rect(myPoint, myOtherPoint);
866 rect = rect.normalize();
867 if (State == VTK_INTERACTOR_STYLE_CAMERA_FIT) {
868 // making fit rect opeation
870 m_Interactor->GetSize(w, h);
873 y1 = h - rect.top() - 1;
875 y2 = h - rect.bottom() - 1;
876 fitRect(x1, y1, x2, y2);
879 if (myPoint == myOtherPoint) {
880 // process point selection
882 m_Interactor->GetSize(w, h);
884 y = h - myPoint.y() - 1;
886 this->FindPokedRenderer(x, y);
887 m_Interactor->StartPickCallback();
889 vtkPicker* aPicker = vtkPicker::SafeDownCast(m_Interactor->GetPicker());
890 aPicker->Pick(x, y, 0.0, this->CurrentRenderer);
892 SALOME_Actor* SActor = SALOME_Actor::SafeDownCast(aPicker->GetActor());
894 if (vtkCellPicker* picker = vtkCellPicker::SafeDownCast(aPicker)) {
895 int aVtkId = picker->GetCellId();
896 if ( aVtkId >= 0 && SActor && SActor->hasIO() && IsValid( SActor, aVtkId ) ) {
897 int anObjId = SActor->GetElemObjId(aVtkId);
899 Handle(SALOME_InteractiveObject) IO = SActor->getIO();
900 if(aSelectionMode != EdgeOfCellSelection) {
901 if(CheckDimensionId(aSelectionMode,SActor,anObjId)){
902 if(MYDEBUG) INFOS(" CellId : "<<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 if(MYDEBUG) INFOS(" CellId : "<<anObjId<<"; EdgeId : "<<anEdgeId);
923 aSel->AddOrRemoveIndex( IO, anObjId, true, false);
924 aSel->AddOrRemoveIndex( IO, -anEdgeId-1, true, true );
925 aSel->AddIObject( IO, false );
930 this->HighlightProp( NULL );
931 aSel->ClearIObjects();
933 } else if ( vtkPointPicker* picker = vtkPointPicker::SafeDownCast(aPicker) ) {
934 int aVtkId = picker->GetPointId();
935 if ( aVtkId >= 0 && IsValid( SActor, aVtkId, true ) ) {
936 if ( SActor && SActor->hasIO() ) {
937 int anObjId = SActor->GetNodeObjId(aVtkId);
939 Handle(SALOME_InteractiveObject) IO = SActor->getIO();
940 if(IsSelected(IO,aSel)) {
941 // This IO is already in the selection
942 aSel->AddOrRemoveIndex( IO, anObjId, myShiftState, false );
945 this->HighlightProp( NULL );
946 aSel->ClearIObjects();
948 if(MYDEBUG) INFOS(" PointId : "<<anObjId);
949 aSel->AddOrRemoveIndex( IO, anObjId, myShiftState, false );
950 aSel->AddIObject( IO, false );
955 this->HighlightProp( NULL );
956 aSel->ClearIObjects();
959 if ( SActor && SActor->hasIO() ) {
961 Handle(SALOME_InteractiveObject) IO = SActor->getIO();
962 if(IsSelected(IO,aSel)) {
963 // This IO is already in the selection
965 aSel->RemoveIObject(IO);
970 this->HighlightProp( NULL );
971 aSel->ClearIObjects();
973 aSel->AddIObject( IO, false );
976 // No selection clear all
977 this->PropPicked = 0;
978 this->HighlightProp( NULL );
979 aSel->ClearIObjects();
982 m_Interactor->EndPickCallback();
984 //processing rectangle selection
985 QString aComponentDataType = SUIT_Application::getDesktop()->getComponentDataType();
986 if(aSelActiveCompOnly && aComponentDataType.isEmpty()) return;
987 m_Interactor->StartPickCallback();
990 this->PropPicked = 0;
991 this->HighlightProp( NULL );
992 aSel->ClearIObjects();
996 // vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
997 QRect rect(myPoint, myOtherPoint);
998 rect = rect.normalize();
1000 m_Interactor->GetSize(w, h);
1003 y1 = h - rect.top() - 1;
1005 y2 = h - rect.bottom() - 1;
1007 switch (aSelectionMode) {
1008 case NodeSelection: {
1009 if ( vtkPointPicker* aPointPicker = vtkPointPicker::SafeDownCast(m_Interactor->GetPicker()) ) {
1010 vtkActorCollection* aListActors = this->CurrentRenderer->GetActors();
1011 aListActors->InitTraversal();
1012 while (vtkActor* aActor = aListActors->GetNextActor()) {
1013 if (!aActor->GetVisibility())
1015 if(SALOME_Actor* SActor = SALOME_Actor::SafeDownCast(aActor)) {
1016 if (SActor->hasIO()) {
1017 Handle(SALOME_InteractiveObject) IO = SActor->getIO();
1020 if (aSelActiveCompOnly && aComponentDataType != IO->getComponentDataType())
1022 if (vtkDataSet* aDataSet = SActor->GetInput()) {
1023 SALOME_Selection::TContainerOfId anIndices;
1024 for(int i = 0; i < aDataSet->GetNumberOfPoints(); i++) {
1026 aDataSet->GetPoint(i,aPoint);
1027 if (IsInRect(aPoint,x1,y1,x2,y2)){
1029 ComputeWorldToDisplay(aPoint[0],aPoint[1],aPoint[2],aDisp);
1030 if(aPointPicker->Pick(aDisp[0],aDisp[1],0.0,CurrentRenderer)){
1031 if(vtkActorCollection *anActorCollection = aPointPicker->GetActors()){
1032 if(anActorCollection->IsItemPresent(SActor)){
1033 float aPickedPoint[3];
1034 aPointPicker->GetMapperPosition(aPickedPoint);
1035 vtkIdType aVtkId = aDataSet->FindPoint(aPickedPoint);
1036 if ( aVtkId >= 0 && IsValid( SActor, aVtkId, true ) ){
1037 int anObjId = SActor->GetNodeObjId(aVtkId);
1038 anIndices.insert(anObjId);
1045 if (!anIndices.empty()) {
1046 aSel->AddOrRemoveIndex(IO, anIndices, true, false);
1047 aSel->AddIObject(IO, false);
1050 aSel->RemoveIObject(IO, false);
1060 case EdgeOfCellSelection:
1063 case VolumeSelection:
1065 vtkSmartPointer<VTKViewer_CellRectPicker> picker = VTKViewer_CellRectPicker::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 aListActors->InitTraversal();
1071 while(vtkActor* aActor = aListActors->GetNextActor()) {
1072 if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)) {
1073 if (aSActor->hasIO()) {
1074 Handle(SALOME_InteractiveObject) aIO = aSActor->getIO();
1075 if (aSelActiveCompOnly && aComponentDataType != aIO->getComponentDataType())
1077 VTKViewer_CellDataSet cellList = picker->GetCellData(aActor);
1078 if ( !cellList.empty() ) {
1079 if(MYDEBUG) INFOS ( " NAME Actor : " << aSActor->getName() );
1080 SALOME_Selection::TContainerOfId anIndexes;
1081 VTKViewer_CellDataSet::iterator it;
1082 for ( it = cellList.begin(); it != cellList.end(); ++it ) {
1083 int aCellId = (*it).cellId;
1085 if ( !IsValid( aSActor, aCellId ) )
1088 int anObjId = aSActor->GetElemObjId(aCellId);
1090 if ( CheckDimensionId(aSelectionMode,aSActor,anObjId) ) {
1091 anIndexes.insert(anObjId);
1095 aSel->AddOrRemoveIndex(aIO, anIndexes, true, false);
1096 aSel->AddIObject(aIO, false);
1103 case ActorSelection: // objects selection
1105 vtkSmartPointer<VTKViewer_RectPicker> picker = VTKViewer_RectPicker::New();
1106 picker->SetTolerance(0.001);
1107 picker->Pick(x1, y1, 0.0, x2, y2, 0.0, this->CurrentRenderer);
1109 vtkActorCollection* aListActors = picker->GetActors();
1110 SALOME_ListIO aListIO;
1111 aListActors->InitTraversal();
1112 while(vtkActor* aActor = aListActors->GetNextActor()) {
1113 if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)) {
1114 if (aSActor->hasIO()) {
1115 Handle(SALOME_InteractiveObject) aIO = aSActor->getIO();
1116 if (!IsStored(aIO,aListIO))
1117 aListIO.Append(aIO);
1121 if (!aListIO.IsEmpty()) {
1122 SALOME_ListIteratorOfListIO It(aListIO);
1123 for(;It.More();It.Next()) {
1124 Handle(SALOME_InteractiveObject) IOS = It.Value();
1126 aSel->AddIObject( IOS, false );
1131 m_Interactor->EndPickCallback();
1133 aActiveStudy->update3dViewers();
1137 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
1138 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
1139 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
1140 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
1142 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
1145 m_Interactor->GetSize(w, h);
1147 y = h - myPoint.y() - 1;
1152 if (myGUIWindow) myGUIWindow->update();
1156 /*! called during viewer operation when user moves mouse (!put necessary processing here!)*/
1157 void VTKViewer_InteractorStyle::onOperation(QPoint mousePos)
1159 if (!myGUIWindow) return;
1161 GetInteractor()->GetSize(w, h);
1163 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
1165 // processing panning
1166 //this->FindPokedCamera(mousePos.x(), mousePos.y());
1167 this->PanXY(mousePos.x(), myPoint.y(), myPoint.x(), mousePos.y());
1171 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
1173 // processing zooming
1174 //this->FindPokedCamera(mousePos.x(), mousePos.y());
1175 this->DollyXY(mousePos.x() - myPoint.x(), mousePos.y() - myPoint.y());
1179 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
1181 // processing rotation
1182 //this->FindPokedCamera(mousePos.x(), mousePos.y());
1183 this->RotateXY(mousePos.x() - myPoint.x(), myPoint.y() - mousePos.y());
1187 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
1189 // processing spinning
1190 //this->FindPokedCamera(mousePos.x(), mousePos.y());
1191 this->SpinXY(mousePos.x(), mousePos.y(), myPoint.x(), myPoint.y());
1195 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
1199 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
1202 setCursor(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
1204 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
1206 QPainter p(myGUIWindow);
1207 p.setPen(Qt::lightGray);
1208 p.setRasterOp(Qt::XorROP);
1209 p.drawRect(QRect(myPoint, myOtherPoint));
1210 myOtherPoint = mousePos;
1211 p.drawRect(QRect(myPoint, myOtherPoint));
1215 this->LastPos[0] = mousePos.x();
1216 this->LastPos[1] = h - mousePos.y() - 1;
1219 /*! called when selection mode changed (!put necessary initialization here!)*/
1220 void VTKViewer_InteractorStyle::OnSelectionModeChanged()
1223 myPreSelectionActor->SetVisibility(false);
1224 myElemId = myEdgeId = myNodeId = -1;
1225 mySelectedActor = NULL;
1228 /*! called when user moves mouse inside viewer window and there is no active viewer operation \n
1229 * (!put necessary processing here!)
1231 void VTKViewer_InteractorStyle::onCursorMove(QPoint mousePos) {
1232 // processing highlighting
1233 // SUIT_Study* anActiveStudy = SUIT_Application::getDesktop()->getActiveStudy();
1234 // SALOME_Selection* Sel = SALOME_Selection::Selection( anActiveStudy->getSelection() );
1235 // Selection_Mode aSelectionMode = Sel->SelectionMode();
1238 m_Interactor->GetSize(w, h);
1239 x = mousePos.x(); y = h - mousePos.y() - 1;
1241 this->FindPokedRenderer(x,y);
1242 m_Interactor->StartPickCallback();
1243 myPreSelectionActor->SetVisibility(false);
1245 vtkPicker* aPicker = vtkPicker::SafeDownCast(m_Interactor->GetPicker());
1246 aPicker->Pick(x, y, 0.0, this->CurrentRenderer);
1248 SALOME_Actor* SActor = SALOME_Actor::SafeDownCast(aPicker->GetActor());
1250 if (vtkCellPicker* picker = vtkCellPicker::SafeDownCast(aPicker)) {
1251 int aVtkId = picker->GetCellId();
1252 if ( aVtkId >= 0 ) {
1253 int anObjId = SActor->GetElemObjId(aVtkId);
1254 if ( SActor && SActor->hasIO() && IsValid( SActor, aVtkId ) ) {
1255 bool anIsSameObjId = (mySelectedActor == SActor && myElemId == anObjId);
1256 bool aResult = anIsSameObjId;
1257 if(!anIsSameObjId) {
1258 if(aSelectionMode != EdgeOfCellSelection) {
1259 aResult = CheckDimensionId(aSelectionMode,SActor,anObjId);
1261 mySelectedActor = SActor;
1263 if(MYDEBUG) INFOS(" CellId : "<<anObjId);
1264 m_Interactor->setCellData(anObjId,SActor,myPreSelectionActor);
1268 if(aSelectionMode == EdgeOfCellSelection){
1269 int anEdgeId = GetEdgeId(picker,SActor,anObjId);
1270 bool anIsSameEdgeId = (myEdgeId != anEdgeId) && anIsSameObjId;
1271 aResult = anIsSameEdgeId;
1272 if(!anIsSameEdgeId) {
1273 aResult = (anEdgeId >= 0);
1275 mySelectedActor = SActor;
1276 myEdgeId = anEdgeId;
1278 if(MYDEBUG) INFOS(" CellId : "<<anObjId<<"; EdgeId : "<<anEdgeId);
1279 m_Interactor->setEdgeData(anObjId,SActor,-anEdgeId-1,myPreSelectionActor);
1284 myPreSelectionActor->GetProperty()->SetRepresentationToSurface();
1285 myPreSelectionActor->SetVisibility(true);
1290 else if (vtkPointPicker* picker = vtkPointPicker::SafeDownCast(aPicker)) {
1291 int aVtkId = picker->GetPointId();
1292 if ( aVtkId >= 0 && IsValid( SActor, aVtkId, true ) ) {
1293 if ( SActor && SActor->hasIO() ) {
1294 int anObjId = SActor->GetNodeObjId(aVtkId);
1295 bool anIsSameObjId = (mySelectedActor == SActor && myNodeId == anObjId);
1296 if(!anIsSameObjId) {
1297 mySelectedActor = SActor;
1299 if(MYDEBUG) INFOS(" PointId : "<<anObjId);
1300 m_Interactor->setPointData(anObjId,SActor,myPreSelectionActor);
1302 myPreSelectionActor->GetProperty()->SetRepresentationToSurface();
1303 myPreSelectionActor->SetVisibility(true);
1307 else if ( vtkPicker::SafeDownCast(aPicker) ) {
1309 if ( myPreViewActor != SActor ) {
1310 if ( myPreViewActor != NULL ) {
1311 myPreViewActor->SetPreSelected( false );
1313 myPreViewActor = SActor;
1315 if ( SActor->hasIO() ) {
1316 Handle( SALOME_InteractiveObject) IO = SActor->getIO();
1317 if ( !IsSelected(IO,Sel) ) {
1318 // Find All actors with same IO
1319 vtkActorCollection* theActors = this->CurrentRenderer->GetActors();
1320 theActors->InitTraversal();
1321 while( vtkActor *ac = theActors->GetNextActor() ) {
1322 if ( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) ) {
1323 if ( anActor->hasIO() ) {
1324 Handle(SALOME_InteractiveObject) IOS = anActor->getIO();
1325 if(IO->isSame(IOS)) {
1326 anActor->SetPreSelected( true );
1331 //if(MYDEBUG) INFOS ( " NAME PREVIEW " << SActor->getName() );
1336 myPreViewActor = NULL;
1337 vtkActorCollection* theActors = this->CurrentRenderer->GetActors();
1338 theActors->InitTraversal();
1339 while( vtkActor *ac = theActors->GetNextActor() ) {
1340 if ( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) ) {
1341 anActor->SetPreSelected( false );
1346 m_Interactor->EndPickCallback();
1347 //m_Interactor->Render();
1348 myGUIWindow->update();
1350 this->LastPos[0] = x;
1351 this->LastPos[1] = y;*/
1354 /*! called on finsh GlobalPan operation */
1355 void VTKViewer_InteractorStyle::Place(const int theX, const int theY)
1357 if (this->CurrentRenderer == NULL) {
1362 int *aSize = this->CurrentRenderer->GetRenderWindow()->GetSize();
1363 int centerX = aSize[0]/2;
1364 int centerY = aSize[1]/2;
1366 TranslateView(centerX, centerY, theX, theY);
1368 // restore zoom scale
1369 vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
1370 cam->SetParallelScale(myScale);
1371 ::ResetCameraClippingRange(this->CurrentRenderer);
1373 if (myGUIWindow) myGUIWindow->update();
1379 /*! Translates view from Point to Point*/
1380 void VTKViewer_InteractorStyle::TranslateView(int toX, int toY, int fromX, int fromY)
1382 vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
1383 double viewFocus[4], focalDepth, viewPoint[3];
1384 float newPickPoint[4], oldPickPoint[4], motionVector[3];
1385 cam->GetFocalPoint(viewFocus);
1387 this->ComputeWorldToDisplay(viewFocus[0], viewFocus[1],
1388 viewFocus[2], viewFocus);
1389 focalDepth = viewFocus[2];
1391 this->ComputeDisplayToWorld(double(toX), double(toY),
1392 focalDepth, newPickPoint);
1393 this->ComputeDisplayToWorld(double(fromX),double(fromY),
1394 focalDepth, oldPickPoint);
1396 // camera motion is reversed
1397 motionVector[0] = oldPickPoint[0] - newPickPoint[0];
1398 motionVector[1] = oldPickPoint[1] - newPickPoint[1];
1399 motionVector[2] = oldPickPoint[2] - newPickPoint[2];
1401 cam->GetFocalPoint(viewFocus);
1402 cam->GetPosition(viewPoint);
1403 cam->SetFocalPoint(motionVector[0] + viewFocus[0],
1404 motionVector[1] + viewFocus[1],
1405 motionVector[2] + viewFocus[2]);
1406 cam->SetPosition(motionVector[0] + viewPoint[0],
1407 motionVector[1] + viewPoint[1],
1408 motionVector[2] + viewPoint[2]);
1412 /*! Checks: is the given Actor within display coordinates?*/
1413 bool VTKViewer_InteractorStyle::IsInRect(vtkActor* theActor,
1414 const int left, const int top,
1415 const int right, const int bottom)
1417 float* aBounds = theActor->GetBounds();
1418 float aMin[3], aMax[3];
1419 ComputeWorldToDisplay(aBounds[0], aBounds[2], aBounds[4], aMin);
1420 ComputeWorldToDisplay(aBounds[1], aBounds[3], aBounds[5], aMax);
1421 if (aMin[0] > aMax[0]) {
1422 float aBuf = aMin[0];
1426 if (aMin[1] > aMax[1]) {
1427 float aBuf = aMin[1];
1432 return ((aMin[0]>left) && (aMax[0]<right) && (aMin[1]>bottom) && (aMax[1]<top));
1436 /*! Checks: is the given Cell within display coordinates?*/
1437 bool VTKViewer_InteractorStyle::IsInRect(vtkCell* theCell,
1438 const int left, const int top,
1439 const int right, const int bottom)
1441 float* aBounds = theCell->GetBounds();
1442 float aMin[3], aMax[3];
1443 ComputeWorldToDisplay(aBounds[0], aBounds[2], aBounds[4], aMin);
1444 ComputeWorldToDisplay(aBounds[1], aBounds[3], aBounds[5], aMax);
1445 if (aMin[0] > aMax[0]) {
1446 float aBuf = aMin[0];
1450 if (aMin[1] > aMax[1]) {
1451 float aBuf = aMin[1];
1456 return ((aMin[0]>left) && (aMax[0]<right) && (aMin[1]>bottom) && (aMax[1]<top));
1459 /*!Checks: is given point \a thePoint in rectangle*/
1460 bool VTKViewer_InteractorStyle::IsInRect(float* thePoint,
1461 const int left, const int top,
1462 const int right, const int bottom)
1465 ComputeWorldToDisplay(thePoint[0], thePoint[1], thePoint[2], aPnt);
1467 return ((aPnt[0]>left) && (aPnt[0]<right) && (aPnt[1]>bottom) && (aPnt[1]<top));
1470 /*!Set filter \a theFilter*/
1471 void VTKViewer_InteractorStyle::SetFilter( const Handle(VTKViewer_Filter)& theFilter )
1473 myFilters[ theFilter->GetId() ] = theFilter;
1476 /*!Checks: is filter present (with id \a theId)
1477 *\param theId - filter id.
1479 bool VTKViewer_InteractorStyle::IsFilterPresent( const int theId )
1481 return myFilters.find( theId ) != myFilters.end();
1484 /*!Remove filter with id \a theId.
1485 *\param theId - filter id.
1487 void VTKViewer_InteractorStyle::RemoveFilter( const int theId )
1489 if ( IsFilterPresent( theId ) )
1490 myFilters.erase( theId );
1493 /*!Checks: is valid cell(node) with id \a theId in actor \a theActor.
1494 *\param theActor - VTKViewer_Actor pointer.
1495 *\param theId - cell id.
1496 *\param theIsNode - boolean flag, if true - node, else - cell.
1498 bool VTKViewer_InteractorStyle::IsValid( VTKViewer_Actor* theActor,
1500 const bool theIsNode )
1502 std::map<int, Handle(VTKViewer_Filter)>::const_iterator anIter;
1503 for ( anIter = myFilters.begin(); anIter != myFilters.end(); ++anIter )
1505 const Handle(VTKViewer_Filter)& aFilter = anIter->second;
1506 if ( theIsNode == aFilter->IsNodeFilter() &&
1507 !aFilter->IsValid( theActor, theId ) )
1513 /*!Gets filter handle by filter id \a theId.*/
1514 Handle(VTKViewer_Filter) VTKViewer_InteractorStyle::GetFilter( const int theId )
1516 return IsFilterPresent( theId ) ? myFilters[ theId ] : Handle(VTKViewer_Filter)();
1520 *\param incrX - X coordinate increment.
1521 *\param incrY - Y coordinate increment.
1523 void VTKViewer_InteractorStyle::IncrementalPan( const int incrX, const int incrY )
1525 this->PanXY( incrX, incrY, 0, 0 );
1529 *\param incr - zoom increment.
1531 void VTKViewer_InteractorStyle::IncrementalZoom( const int incr )
1533 this->DollyXY( incr, incr );
1536 /*!Increment rotate.
1537 *\param incrX - X coordinate increment.
1538 *\param incrY - Y coordinate increment.
1540 void VTKViewer_InteractorStyle::IncrementalRotate( const int incrX, const int incrY )
1542 this->RotateXY( incrX, -incrY );