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_InteractorStyleSALOME.cxx
25 // Author : Christophe ATTANASIO
29 #include "VTKViewer_InteractorStyleSALOME.h"
31 #include "VTKViewer_RenderWindowInteractor.h"
32 #include "VTKViewer_RenderWindow.h"
33 #include "VTKViewer_ViewFrame.h"
35 #include "VTKViewer_Utilities.h"
36 #include "VTKViewer_Trihedron.h"
37 #include "VTKViewer_RectPicker.h"
38 #include "VTKViewer_CellRectPicker.h"
40 #include "QAD_Config.h"
41 #include "QAD_Application.h"
42 #include "QAD_Desktop.h"
44 #include "SALOME_Actor.h"
45 #include "VTKViewer_Actor.h"
46 #include "SALOME_Selection.h"
47 #include "SALOME_ListIteratorOfListIO.hxx"
48 #include "SALOME_CubeAxesActor2D.h"
50 #include <vtkObjectFactory.h>
52 #include <vtkCommand.h>
53 #include <vtkCamera.h>
54 #include <vtkRenderer.h>
55 #include <vtkPicker.h>
56 #include <vtkPointPicker.h>
57 #include <vtkCellPicker.h>
59 #include <vtkMapper.h>
60 #include <vtkDataSet.h>
61 #include <vtkSmartPointer.h>
63 #include <qapplication.h>
64 //VRV: porting on Qt 3.0.5
65 #if QT_VERSION >= 0x030005
68 //VRV: porting on Qt 3.0.5
71 #include "utilities.h"
77 static int MYDEBUG = 0;
79 static int MYDEBUG = 0;
83 static bool IsStored(Handle(SALOME_InteractiveObject)& theIO,
84 const SALOME_ListIO& theListIO)
86 if (!theListIO.IsEmpty()){
87 SALOME_ListIteratorOfListIO anIter(theListIO);
88 for(; anIter.More(); anIter.Next()) {
89 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
90 if(theIO->isSame(anIO)) {
91 theIO = anIO; //Added by SRN, fix SAL1307
100 static bool IsSelected(Handle(SALOME_InteractiveObject)& theIO,
101 SALOME_Selection* theSel)
103 return IsStored(theIO,theSel->StoredIObjects());
107 static int GetEdgeId(vtkPicker *thePicker, SALOME_Actor *theActor, int theObjId){
109 if (vtkCell* aPickedCell = theActor->GetElemCell(theObjId)) {
110 float aPickPosition[3];
111 thePicker->GetPickPosition(aPickPosition);
112 float aMinDist = 1000000.0, aDist = 0;
113 for (int i = 0, iEnd = aPickedCell->GetNumberOfEdges(); i < iEnd; i++){
114 if(vtkLine* aLine = vtkLine::SafeDownCast(aPickedCell->GetEdge(i))){
115 int subId; float pcoords[3], closestPoint[3], weights[3];
116 aLine->EvaluatePosition(aPickPosition,closestPoint,subId,pcoords,aDist,weights);
117 if (aDist < aMinDist) {
128 static bool CheckDimensionId(Selection_Mode theMode, SALOME_Actor *theActor, vtkIdType theObjId){
133 return ( theActor->GetObjDimension( theObjId ) == 1 );
135 return ( theActor->GetObjDimension( theObjId ) == 2 );
136 case VolumeSelection:
137 return ( theActor->GetObjDimension( theObjId ) == 3 );
143 //----------------------------------------------------------------------------
144 vtkStandardNewMacro(VTKViewer_InteractorStyleSALOME);
145 //----------------------------------------------------------------------------
147 VTKViewer_InteractorStyleSALOME::VTKViewer_InteractorStyleSALOME()
151 this->MotionFactor = 10.0;
152 this->State = VTK_INTERACTOR_STYLE_CAMERA_NONE;
153 this->RadianToDegree = 180.0 / vtkMath::Pi();
154 this->ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
157 myPreSelectionActor = VTKViewer_Actor::New();
158 myPreSelectionActor->GetProperty()->SetColor(0,1,1);
159 myPreSelectionActor->GetProperty()->SetLineWidth(5);
160 myPreSelectionActor->GetProperty()->SetPointSize(5);
162 OnSelectionModeChanged();
165 //----------------------------------------------------------------------------
166 VTKViewer_InteractorStyleSALOME::~VTKViewer_InteractorStyleSALOME()
168 if(MYDEBUG) INFOS("VTKViewer_InteractorStyleSALOME::~VTKViewer_InteractorStyleSALOME()");
169 m_ViewFrame->RemoveActor(myPreSelectionActor);
172 //----------------------------------------------------------------------------
173 void VTKViewer_InteractorStyleSALOME::setPreselectionProp(const double& theRed, const double& theGreen,
174 const double& theBlue, const int& theWidth)
176 if ( myPreSelectionActor->GetProperty() == 0 )
178 myPreSelectionActor->GetProperty()->SetColor(theRed, theGreen, theBlue);
179 myPreSelectionActor->GetProperty()->SetLineWidth(theWidth);
180 myPreSelectionActor->GetProperty()->SetPointSize(theWidth);
183 //----------------------------------------------------------------------------
184 void VTKViewer_InteractorStyleSALOME::SetInteractor(vtkRenderWindowInteractor *theInteractor){
185 m_Interactor = dynamic_cast<VTKViewer_RenderWindowInteractor*>(theInteractor);
186 Superclass::SetInteractor(theInteractor);
189 //----------------------------------------------------------------------------
190 void VTKViewer_InteractorStyleSALOME::setViewFrame(VTKViewer_ViewFrame* theViewFrame){
191 m_ViewFrame = theViewFrame;
192 m_ViewFrame->AddActor(myPreSelectionActor);
193 myPreSelectionActor->Delete();
196 //----------------------------------------------------------------------------
197 void VTKViewer_InteractorStyleSALOME::setGUIWindow(QWidget* theWindow){
198 myGUIWindow = theWindow;
201 //----------------------------------------------------------------------------
202 void VTKViewer_InteractorStyleSALOME::setTriedron(VTKViewer_Trihedron* theTrihedron){
203 m_Trihedron = theTrihedron;
206 void VTKViewer_InteractorStyleSALOME::setCubeAxes(SALOME_CubeAxesActor2D* theCubeAxes){
207 m_CubeAxes = theCubeAxes;
210 //----------------------------------------------------------------------------
211 void VTKViewer_InteractorStyleSALOME::RotateXY(int dx, int dy)
217 if (this->CurrentRenderer == NULL)
222 int *size = this->CurrentRenderer->GetRenderWindow()->GetSize();
223 this->DeltaElevation = -20.0 / size[1];
224 this->DeltaAzimuth = -20.0 / size[0];
226 rxf = (double)dx * this->DeltaAzimuth * this->MotionFactor;
227 ryf = (double)dy * this->DeltaElevation * this->MotionFactor;
229 cam = this->CurrentRenderer->GetActiveCamera();
232 cam->OrthogonalizeViewUp();
233 ::ResetCameraClippingRange(this->CurrentRenderer);
234 //this->Interactor->Render();
235 myGUIWindow->update();
238 //----------------------------------------------------------------------------
239 void VTKViewer_InteractorStyleSALOME::PanXY(int x, int y, int oldX, int oldY)
241 TranslateView(x, y, oldX, oldY);
242 //this->Interactor->Render();
243 myGUIWindow->update();
247 //----------------------------------------------------------------------------
248 void VTKViewer_InteractorStyleSALOME::DollyXY(int dx, int dy)
250 if (this->CurrentRenderer == NULL) return;
252 double dxf = this->MotionFactor * (double)(dx) / (double)(this->CurrentRenderer->GetCenter()[1]);
253 double dyf = this->MotionFactor * (double)(dy) / (double)(this->CurrentRenderer->GetCenter()[1]);
255 double zoomFactor = pow((double)1.1, dxf + dyf);
257 vtkCamera *aCam = this->CurrentRenderer->GetActiveCamera();
258 if (aCam->GetParallelProjection())
259 aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
261 aCam->Dolly(zoomFactor);
262 ::ResetCameraClippingRange(this->CurrentRenderer);
265 //this->Interactor->Render();
266 myGUIWindow->update();
269 //----------------------------------------------------------------------------
270 void VTKViewer_InteractorStyleSALOME::SpinXY(int x, int y, int oldX, int oldY)
274 if (this->CurrentRenderer == NULL)
279 double newAngle = atan2((double)(y - this->CurrentRenderer->GetCenter()[1]),
280 (double)(x - this->CurrentRenderer->GetCenter()[0]));
281 double oldAngle = atan2((double)(oldY -this->CurrentRenderer->GetCenter()[1]),
282 (double)(oldX - this->CurrentRenderer->GetCenter()[0]));
284 newAngle *= this->RadianToDegree;
285 oldAngle *= this->RadianToDegree;
287 cam = this->CurrentRenderer->GetActiveCamera();
288 cam->Roll(newAngle - oldAngle);
289 cam->OrthogonalizeViewUp();
291 //this->Interactor->Render();
292 myGUIWindow->update();
296 //----------------------------------------------------------------------------
297 void VTKViewer_InteractorStyleSALOME::OnMouseMove(int vtkNotUsed(ctrl),
301 myShiftState = shift;
302 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
303 onOperation(QPoint(x, y));
304 else if (ForcedState == VTK_INTERACTOR_STYLE_CAMERA_NONE)
305 onCursorMove(QPoint(x, y));
309 //----------------------------------------------------------------------------
310 void VTKViewer_InteractorStyleSALOME::OnLeftButtonDown(int ctrl, int shift,
313 if (this->HasObserver(vtkCommand::LeftButtonPressEvent)) {
314 this->InvokeEvent(vtkCommand::LeftButtonPressEvent,NULL);
317 this->FindPokedRenderer(x, y);
318 if (this->CurrentRenderer == NULL) {
321 myShiftState = shift;
322 // finishing current viewer operation
323 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
325 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
327 myOtherPoint = myPoint = QPoint(x, y);
328 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
329 startOperation(ForcedState);
332 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
334 startOperation(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
340 //----------------------------------------------------------------------------
341 void VTKViewer_InteractorStyleSALOME::OnLeftButtonUp(int vtkNotUsed(ctrl),
346 myShiftState = shift;
347 // finishing current viewer operation
348 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
350 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
355 //----------------------------------------------------------------------------
356 void VTKViewer_InteractorStyleSALOME::OnMiddleButtonDown(int ctrl,
360 if (this->HasObserver(vtkCommand::MiddleButtonPressEvent))
362 this->InvokeEvent(vtkCommand::MiddleButtonPressEvent,NULL);
365 this->FindPokedRenderer(x, y);
366 if (this->CurrentRenderer == NULL)
370 myShiftState = shift;
371 // finishing current viewer operation
372 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
374 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
376 myOtherPoint = myPoint = QPoint(x, y);
377 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
378 startOperation(ForcedState);
382 startOperation(VTK_INTERACTOR_STYLE_CAMERA_PAN);
387 //----------------------------------------------------------------------------
388 void VTKViewer_InteractorStyleSALOME::OnMiddleButtonUp(int vtkNotUsed(ctrl),
393 myShiftState = shift;
394 // finishing current viewer operation
395 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
397 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
402 //----------------------------------------------------------------------------
403 void VTKViewer_InteractorStyleSALOME::OnRightButtonDown(int ctrl,
407 if (this->HasObserver(vtkCommand::RightButtonPressEvent))
409 this->InvokeEvent(vtkCommand::RightButtonPressEvent,NULL);
412 this->FindPokedRenderer(x, y);
413 if (this->CurrentRenderer == NULL)
417 myShiftState = shift;
418 // finishing current viewer operation
419 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
421 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
423 myOtherPoint = myPoint = QPoint(x, y);
424 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
425 startOperation(ForcedState);
429 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
433 //----------------------------------------------------------------------------
434 void VTKViewer_InteractorStyleSALOME::OnRightButtonUp(int vtkNotUsed(ctrl),
439 myShiftState = shift;
440 // finishing current viewer operation
441 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
443 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
447 //----------------------------------------------------------------------------
449 const char* imageZoomCursor[] = {
454 "................................",
455 "................................",
456 ".#######........................",
457 "..aaaaaaa.......................",
458 "................................",
459 ".............#####..............",
460 "...........##.aaaa##............",
461 "..........#.aa.....a#...........",
462 ".........#.a.........#..........",
463 ".........#a..........#a.........",
464 "........#.a...........#.........",
465 "........#a............#a........",
466 "........#a............#a........",
467 "........#a............#a........",
468 "........#a............#a........",
469 ".........#...........#.a........",
470 ".........#a..........#a.........",
471 ".........##.........#.a.........",
472 "........#####.....##.a..........",
473 ".......###aaa#####.aa...........",
474 "......###aa...aaaaa.......#.....",
475 ".....###aa................#a....",
476 "....###aa.................#a....",
477 "...###aa...............#######..",
478 "....#aa.................aa#aaaa.",
479 ".....a....................#a....",
480 "..........................#a....",
481 "...........................a....",
482 "................................",
483 "................................",
484 "................................",
485 "................................"};
487 const char* imageRotateCursor[] = {
492 "................................",
493 "................................",
494 "................................",
495 "................................",
496 "........#.......................",
497 ".......#.a......................",
498 "......#######...................",
499 ".......#aaaaa#####..............",
500 "........#..##.a#aa##........##..",
501 ".........a#.aa..#..a#.....##.aa.",
502 ".........#.a.....#...#..##.aa...",
503 ".........#a.......#..###.aa.....",
504 "........#.a.......#a..#aa.......",
505 "........#a.........#..#a........",
506 "........#a.........#a.#a........",
507 "........#a.........#a.#a........",
508 "........#a.........#a.#a........",
509 ".........#.........#a#.a........",
510 "........##a........#a#a.........",
511 "......##.a#.......#.#.a.........",
512 "....##.aa..##.....##.a..........",
513 "..##.aa.....a#####.aa...........",
514 "...aa.........aaa#a.............",
515 "................#.a.............",
516 "...............#.a..............",
517 "..............#.a...............",
518 "...............a................",
519 "................................",
520 "................................",
521 "................................",
522 "................................",
523 "................................"};
526 //----------------------------------------------------------------------------
527 // loads cursors for viewer operations - zoom, pan, etc...
528 void VTKViewer_InteractorStyleSALOME::loadCursors()
530 myDefCursor = QCursor(ArrowCursor);
531 myHandCursor = QCursor(PointingHandCursor);
532 myPanCursor = QCursor(SizeAllCursor);
533 myZoomCursor = QCursor(QPixmap(imageZoomCursor));
534 myRotateCursor = QCursor(QPixmap(imageRotateCursor));
535 mySpinCursor = QCursor(QPixmap(imageRotateCursor)); // temporarly !!!!!!
536 myGlobalPanCursor = QCursor(CrossCursor);
537 myCursorState = false;
541 //----------------------------------------------------------------------------
542 // event filter - controls mouse and keyboard events during viewer operations
543 bool VTKViewer_InteractorStyleSALOME::eventFilter(QObject* object, QEvent* event)
545 if (!myGUIWindow) return false;
546 if ( (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::KeyPress) && object != myGUIWindow)
548 qApp->removeEventFilter(this);
549 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
551 return QObject::eventFilter(object, event);
555 //----------------------------------------------------------------------------
556 // starts Zoom operation (e.g. through menu command)
557 void VTKViewer_InteractorStyleSALOME::startZoom()
559 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
562 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
564 setCursor(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
565 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ZOOM;
566 qApp->installEventFilter(this);
570 //----------------------------------------------------------------------------
571 // starts Pan operation (e.g. through menu command)
572 void VTKViewer_InteractorStyleSALOME::startPan()
574 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
577 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
579 setCursor(VTK_INTERACTOR_STYLE_CAMERA_PAN);
580 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_PAN;
581 qApp->installEventFilter(this);
584 //----------------------------------------------------------------------------
585 // starts Rotate operation (e.g. through menu command)
586 void VTKViewer_InteractorStyleSALOME::startRotate()
588 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
591 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
593 setCursor(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
594 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ROTATE;
595 qApp->installEventFilter(this);
599 //----------------------------------------------------------------------------
600 // starts Spin operation (e.g. through menu command)
601 void VTKViewer_InteractorStyleSALOME::startSpin()
603 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
606 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
608 setCursor(VTK_INTERACTOR_STYLE_CAMERA_SPIN);
609 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_SPIN;
610 qApp->installEventFilter(this);
615 //----------------------------------------------------------------------------
616 // starts Fit Area operation (e.g. through menu command)
617 void VTKViewer_InteractorStyleSALOME::startFitArea()
619 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
622 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
624 setCursor(VTK_INTERACTOR_STYLE_CAMERA_FIT);
625 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_FIT;
626 qApp->installEventFilter(this);
630 //----------------------------------------------------------------------------
631 void VTKViewer_InteractorStyleSALOME::ViewFitAll() {
632 int aTriedronWasVisible = false;
633 int aCubeAxesWasVisible = false;
635 aTriedronWasVisible = m_Trihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
636 if(aTriedronWasVisible) m_Trihedron->VisibilityOff();
639 aCubeAxesWasVisible = m_CubeAxes->GetVisibility();
640 if(aCubeAxesWasVisible) m_CubeAxes->VisibilityOff();
643 if(m_Trihedron->GetVisibleActorCount(CurrentRenderer)){
644 m_Trihedron->VisibilityOff();
645 m_CubeAxes->VisibilityOff();
646 ::ResetCamera(CurrentRenderer);
648 m_Trihedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
649 m_CubeAxes->SetVisibility(2);
650 ::ResetCamera(CurrentRenderer,true);
652 if(aTriedronWasVisible) m_Trihedron->VisibilityOn();
653 else m_Trihedron->VisibilityOff();
654 if(aCubeAxesWasVisible) m_CubeAxes->VisibilityOn();
655 else m_CubeAxes->VisibilityOff();
656 ::ResetCameraClippingRange(CurrentRenderer);
660 //----------------------------------------------------------------------------
661 // starts Global Panning operation (e.g. through menu command)
662 void VTKViewer_InteractorStyleSALOME::startGlobalPan()
664 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
667 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
669 setCursor(VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN);
670 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN;
672 // store current zoom scale
673 vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
674 myScale = cam->GetParallelScale();
678 if (myGUIWindow) myGUIWindow->update();
680 qApp->installEventFilter(this);
684 //----------------------------------------------------------------------------
685 // returns TRUE if needs redrawing
686 bool VTKViewer_InteractorStyleSALOME::needsRedrawing()
688 return State == VTK_INTERACTOR_STYLE_CAMERA_ZOOM ||
689 State == VTK_INTERACTOR_STYLE_CAMERA_PAN ||
690 State == VTK_INTERACTOR_STYLE_CAMERA_ROTATE ||
691 State == VTK_INTERACTOR_STYLE_CAMERA_SPIN ||
692 State == VTK_INTERACTOR_STYLE_CAMERA_NONE;
696 //----------------------------------------------------------------------------
697 // fits viewer contents to rect
698 void VTKViewer_InteractorStyleSALOME::fitRect(const int left,
703 if (this->CurrentRenderer == NULL) return;
706 int x = (left + right)/2;
707 int y = (top + bottom)/2;
708 int *aSize = this->CurrentRenderer->GetRenderWindow()->GetSize();
709 int oldX = aSize[0]/2;
710 int oldY = aSize[1]/2;
711 TranslateView(oldX, oldY, x, y);
714 double dxf = (double)(aSize[0]) / (double)(abs(right - left));
715 double dyf = (double)(aSize[1]) / (double)(abs(bottom - top));
716 double zoomFactor = (dxf + dyf)/2 ;
718 vtkCamera *aCam = this->CurrentRenderer->GetActiveCamera();
719 if(aCam->GetParallelProjection())
720 aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
722 aCam->Dolly(zoomFactor);
723 ::ResetCameraClippingRange(this->CurrentRenderer);
726 myGUIWindow->update();
730 //----------------------------------------------------------------------------
731 // starts viewer operation (!internal usage!)
732 void VTKViewer_InteractorStyleSALOME::startOperation(int operation)
736 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
737 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
738 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
739 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
740 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
741 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
742 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
743 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
744 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
746 if (State != VTK_INTERACTOR_STYLE_CAMERA_SELECT)
747 setCursor(operation);
750 case VTK_INTERACTOR_STYLE_CAMERA_NONE:
752 setCursor(VTK_INTERACTOR_STYLE_CAMERA_NONE);
753 State = ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
759 //----------------------------------------------------------------------------
760 // sets proper cursor for window when viewer operation is activated
761 void VTKViewer_InteractorStyleSALOME::setCursor(const int operation)
763 if (!myGUIWindow) return;
766 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
767 myGUIWindow->setCursor(myZoomCursor);
768 myCursorState = true;
770 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
771 myGUIWindow->setCursor(myPanCursor);
772 myCursorState = true;
774 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
775 myGUIWindow->setCursor(myRotateCursor);
776 myCursorState = true;
778 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
779 myGUIWindow->setCursor(mySpinCursor);
780 myCursorState = true;
782 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
783 myGUIWindow->setCursor(myGlobalPanCursor);
784 myCursorState = true;
786 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
787 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
788 myGUIWindow->setCursor(myHandCursor);
789 myCursorState = true;
791 case VTK_INTERACTOR_STYLE_CAMERA_NONE:
793 myGUIWindow->setCursor(myDefCursor);
794 myCursorState = false;
800 //----------------------------------------------------------------------------
801 // called when viewer operation started (!put necessary initialization here!)
802 void VTKViewer_InteractorStyleSALOME::onStartOperation()
804 if (!myGUIWindow) return;
805 // VSV: LOD actor activisation
806 // this->Interactor->GetRenderWindow()->SetDesiredUpdateRate(this->Interactor->GetDesiredUpdateRate());
808 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
809 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
811 QPainter p(myGUIWindow);
812 p.setPen(Qt::lightGray);
813 p.setRasterOp(Qt::XorROP);
814 p.drawRect(QRect(myPoint, myOtherPoint));
817 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
818 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
819 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
820 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
821 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
827 //----------------------------------------------------------------------------
828 // called when viewer operation finished (!put necessary post-processing here!)
829 void VTKViewer_InteractorStyleSALOME::onFinishOperation()
831 if (!myGUIWindow) return;
834 QAD_Study* aActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
835 SALOME_Selection* aSel = SALOME_Selection::Selection( aActiveStudy->getSelection() );
837 // VSV: LOD actor activisation
838 // rwi->GetRenderWindow()->SetDesiredUpdateRate(rwi->GetStillUpdateRate());
840 Selection_Mode aSelectionMode = aSel->SelectionMode();
841 bool aSelActiveCompOnly = aSel->IsSelectActiveCompOnly();
844 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
845 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
847 QPainter p(myGUIWindow);
848 p.setPen(Qt::lightGray);
849 p.setRasterOp(Qt::XorROP);
850 QRect rect(myPoint, myOtherPoint);
852 rect = rect.normalize();
853 if (State == VTK_INTERACTOR_STYLE_CAMERA_FIT) {
854 // making fit rect opeation
856 m_Interactor->GetSize(w, h);
859 y1 = h - rect.top() - 1;
861 y2 = h - rect.bottom() - 1;
862 fitRect(x1, y1, x2, y2);
865 if (myPoint == myOtherPoint) {
866 // process point selection
868 m_Interactor->GetSize(w, h);
870 y = h - myPoint.y() - 1;
872 this->FindPokedRenderer(x, y);
873 m_Interactor->StartPickCallback();
875 vtkPicker* aPicker = vtkPicker::SafeDownCast(m_Interactor->GetPicker());
876 aPicker->Pick(x, y, 0.0, this->CurrentRenderer);
878 SALOME_Actor* SActor = SALOME_Actor::SafeDownCast(aPicker->GetActor());
880 if (vtkCellPicker* picker = vtkCellPicker::SafeDownCast(aPicker)) {
881 int aVtkId = picker->GetCellId();
882 if ( aVtkId >= 0 && SActor && SActor->hasIO() && IsValid( SActor, aVtkId ) ) {
883 int anObjId = SActor->GetElemObjId(aVtkId);
885 Handle(SALOME_InteractiveObject) IO = SActor->getIO();
886 if(aSelectionMode != EdgeOfCellSelection) {
887 if(CheckDimensionId(aSelectionMode,SActor,anObjId)){
888 if(MYDEBUG) INFOS(" CellId : "<<anObjId);
889 if (IsSelected(IO,aSel)) {
890 // This IO is already in the selection
891 aSel->AddOrRemoveIndex( IO, anObjId, myShiftState, false );
894 this->HighlightProp( NULL );
895 aSel->ClearIObjects();
897 aSel->AddOrRemoveIndex( IO, anObjId, myShiftState, false );
898 aSel->AddIObject( IO, false );
903 this->HighlightProp( NULL );
904 aSel->ClearIObjects();
906 int anEdgeId = GetEdgeId(picker,SActor,anObjId);
908 if(MYDEBUG) INFOS(" CellId : "<<anObjId<<"; EdgeId : "<<anEdgeId);
909 aSel->AddOrRemoveIndex( IO, anObjId, true, false);
910 aSel->AddOrRemoveIndex( IO, -anEdgeId-1, true, true );
911 aSel->AddIObject( IO, false );
916 this->HighlightProp( NULL );
917 aSel->ClearIObjects();
919 } else if ( vtkPointPicker* picker = vtkPointPicker::SafeDownCast(aPicker) ) {
920 int aVtkId = picker->GetPointId();
921 if ( aVtkId >= 0 && IsValid( SActor, aVtkId, true ) ) {
922 if ( SActor && SActor->hasIO() ) {
923 int anObjId = SActor->GetNodeObjId(aVtkId);
925 Handle(SALOME_InteractiveObject) IO = SActor->getIO();
926 if(IsSelected(IO,aSel)) {
927 // This IO is already in the selection
928 aSel->AddOrRemoveIndex( IO, anObjId, myShiftState, false );
931 this->HighlightProp( NULL );
932 aSel->ClearIObjects();
934 if(MYDEBUG) INFOS(" PointId : "<<anObjId);
935 aSel->AddOrRemoveIndex( IO, anObjId, myShiftState, false );
936 aSel->AddIObject( IO, false );
941 this->HighlightProp( NULL );
942 aSel->ClearIObjects();
945 if ( SActor && SActor->hasIO() ) {
947 Handle(SALOME_InteractiveObject) IO = SActor->getIO();
948 if(IsSelected(IO,aSel)) {
949 // This IO is already in the selection
951 aSel->RemoveIObject(IO);
956 this->HighlightProp( NULL );
957 aSel->ClearIObjects();
959 aSel->AddIObject( IO, false );
962 // No selection clear all
963 this->PropPicked = 0;
964 this->HighlightProp( NULL );
965 aSel->ClearIObjects();
968 m_Interactor->EndPickCallback();
970 //processing rectangle selection
971 QString aComponentDataType = QAD_Application::getDesktop()->getComponentDataType();
972 if(aSelActiveCompOnly && aComponentDataType.isEmpty()) return;
973 m_Interactor->StartPickCallback();
976 this->PropPicked = 0;
977 this->HighlightProp( NULL );
978 aSel->ClearIObjects();
982 // vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
983 QRect rect(myPoint, myOtherPoint);
984 rect = rect.normalize();
986 m_Interactor->GetSize(w, h);
989 y1 = h - rect.top() - 1;
991 y2 = h - rect.bottom() - 1;
993 switch (aSelectionMode) {
994 case NodeSelection: {
995 if ( vtkPointPicker* aPointPicker = vtkPointPicker::SafeDownCast(m_Interactor->GetPicker()) ) {
996 vtkActorCollection* aListActors = this->CurrentRenderer->GetActors();
997 aListActors->InitTraversal();
998 while (vtkActor* aActor = aListActors->GetNextActor()) {
999 if (!aActor->GetVisibility())
1001 if(SALOME_Actor* SActor = SALOME_Actor::SafeDownCast(aActor)) {
1002 if (SActor->hasIO()) {
1003 Handle(SALOME_InteractiveObject) IO = SActor->getIO();
1006 if (aSelActiveCompOnly && aComponentDataType != IO->getComponentDataType())
1008 if (vtkDataSet* aDataSet = SActor->GetInput()) {
1009 SALOME_Selection::TContainerOfId anIndices;
1010 for(int i = 0; i < aDataSet->GetNumberOfPoints(); i++) {
1012 aDataSet->GetPoint(i,aPoint);
1013 if (IsInRect(aPoint,x1,y1,x2,y2)){
1015 ComputeWorldToDisplay(aPoint[0],aPoint[1],aPoint[2],aDisp);
1016 if(aPointPicker->Pick(aDisp[0],aDisp[1],0.0,CurrentRenderer)){
1017 if(vtkActorCollection *anActorCollection = aPointPicker->GetActors()){
1018 if(anActorCollection->IsItemPresent(SActor)){
1019 float aPickedPoint[3];
1020 aPointPicker->GetMapperPosition(aPickedPoint);
1021 vtkIdType aVtkId = aDataSet->FindPoint(aPickedPoint);
1022 if ( aVtkId >= 0 && IsValid( SActor, aVtkId, true ) ){
1023 int anObjId = SActor->GetNodeObjId(aVtkId);
1024 anIndices.insert(anObjId);
1031 if (!anIndices.empty()) {
1032 aSel->AddOrRemoveIndex(IO, anIndices, true, false);
1033 aSel->AddIObject(IO, false);
1036 aSel->RemoveIObject(IO, false);
1046 case EdgeOfCellSelection:
1049 case VolumeSelection:
1051 vtkSmartPointer<VTKViewer_CellRectPicker> picker = VTKViewer_CellRectPicker::New();
1052 picker->SetTolerance(0.001);
1053 picker->Pick(x1, y1, 0.0, x2, y2, 0.0, this->CurrentRenderer);
1055 vtkActorCollection* aListActors = picker->GetActors();
1056 aListActors->InitTraversal();
1057 while(vtkActor* aActor = aListActors->GetNextActor()) {
1058 if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)) {
1059 if (aSActor->hasIO()) {
1060 Handle(SALOME_InteractiveObject) aIO = aSActor->getIO();
1061 if (aSelActiveCompOnly && aComponentDataType != aIO->getComponentDataType())
1063 VTKViewer_CellDataSet cellList = picker->GetCellData(aActor);
1064 if ( !cellList.empty() ) {
1065 if(MYDEBUG) INFOS ( " NAME Actor : " << aSActor->getName() );
1066 SALOME_Selection::TContainerOfId anIndexes;
1067 VTKViewer_CellDataSet::iterator it;
1068 for ( it = cellList.begin(); it != cellList.end(); ++it ) {
1069 int aCellId = (*it).cellId;
1071 if ( !IsValid( aSActor, aCellId ) )
1074 int anObjId = aSActor->GetElemObjId(aCellId);
1076 if ( CheckDimensionId(aSelectionMode,aSActor,anObjId) ) {
1077 anIndexes.insert(anObjId);
1081 aSel->AddOrRemoveIndex(aIO, anIndexes, true, false);
1082 aSel->AddIObject(aIO, false);
1089 case ActorSelection: // objects selection
1091 vtkSmartPointer<VTKViewer_RectPicker> picker = VTKViewer_RectPicker::New();
1092 picker->SetTolerance(0.001);
1093 picker->Pick(x1, y1, 0.0, x2, y2, 0.0, this->CurrentRenderer);
1095 vtkActorCollection* aListActors = picker->GetActors();
1096 SALOME_ListIO aListIO;
1097 aListActors->InitTraversal();
1098 while(vtkActor* aActor = aListActors->GetNextActor()) {
1099 if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)) {
1100 if (aSActor->hasIO()) {
1101 Handle(SALOME_InteractiveObject) aIO = aSActor->getIO();
1102 if (!IsStored(aIO,aListIO))
1103 aListIO.Append(aIO);
1107 if (!aListIO.IsEmpty()) {
1108 SALOME_ListIteratorOfListIO It(aListIO);
1109 for(;It.More();It.Next()) {
1110 Handle(SALOME_InteractiveObject) IOS = It.Value();
1112 aSel->AddIObject( IOS, false );
1117 m_Interactor->EndPickCallback();
1119 aActiveStudy->update3dViewers();
1123 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
1124 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
1125 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
1126 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
1128 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
1131 m_Interactor->GetSize(w, h);
1133 y = h - myPoint.y() - 1;
1138 if (myGUIWindow) myGUIWindow->update();
1142 // called during viewer operation when user moves mouse (!put necessary processing here!)
1143 void VTKViewer_InteractorStyleSALOME::onOperation(QPoint mousePos)
1145 if (!myGUIWindow) return;
1147 GetInteractor()->GetSize(w, h);
1149 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
1151 // processing panning
1152 //this->FindPokedCamera(mousePos.x(), mousePos.y());
1153 this->PanXY(mousePos.x(), myPoint.y(), myPoint.x(), mousePos.y());
1157 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
1159 // processing zooming
1160 //this->FindPokedCamera(mousePos.x(), mousePos.y());
1161 this->DollyXY(mousePos.x() - myPoint.x(), mousePos.y() - myPoint.y());
1165 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
1167 // processing rotation
1168 //this->FindPokedCamera(mousePos.x(), mousePos.y());
1169 this->RotateXY(mousePos.x() - myPoint.x(), myPoint.y() - mousePos.y());
1173 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
1175 // processing spinning
1176 //this->FindPokedCamera(mousePos.x(), mousePos.y());
1177 this->SpinXY(mousePos.x(), mousePos.y(), myPoint.x(), myPoint.y());
1181 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
1185 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
1188 setCursor(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
1190 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
1192 QPainter p(myGUIWindow);
1193 p.setPen(Qt::lightGray);
1194 p.setRasterOp(Qt::XorROP);
1195 p.drawRect(QRect(myPoint, myOtherPoint));
1196 myOtherPoint = mousePos;
1197 p.drawRect(QRect(myPoint, myOtherPoint));
1201 this->LastPos[0] = mousePos.x();
1202 this->LastPos[1] = h - mousePos.y() - 1;
1205 // called when selection mode changed (!put necessary initialization here!)
1206 void VTKViewer_InteractorStyleSALOME::OnSelectionModeChanged()
1209 myPreSelectionActor->SetVisibility(false);
1210 myElemId = myEdgeId = myNodeId = -1;
1211 mySelectedActor = NULL;
1214 // called when user moves mouse inside viewer window and there is no active viewer operation
1215 // (!put necessary processing here!)
1216 void VTKViewer_InteractorStyleSALOME::onCursorMove(QPoint mousePos) {
1217 // processing highlighting
1218 QAD_Study* anActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
1219 SALOME_Selection* Sel = SALOME_Selection::Selection( anActiveStudy->getSelection() );
1220 Selection_Mode aSelectionMode = Sel->SelectionMode();
1223 m_Interactor->GetSize(w, h);
1224 x = mousePos.x(); y = h - mousePos.y() - 1;
1226 this->FindPokedRenderer(x,y);
1227 m_Interactor->StartPickCallback();
1228 myPreSelectionActor->SetVisibility(false);
1230 vtkPicker* aPicker = vtkPicker::SafeDownCast(m_Interactor->GetPicker());
1231 aPicker->Pick(x, y, 0.0, this->CurrentRenderer);
1233 SALOME_Actor* SActor = SALOME_Actor::SafeDownCast(aPicker->GetActor());
1235 if (SActor && myPreSelectionActor){
1237 SActor->GetPosition(aPos);
1238 myPreSelectionActor->SetPosition(aPos);
1241 if (vtkCellPicker* picker = vtkCellPicker::SafeDownCast(aPicker)) {
1242 int aVtkId = picker->GetCellId();
1243 if ( aVtkId >= 0 ) {
1244 int anObjId = SActor->GetElemObjId(aVtkId);
1245 if ( SActor && SActor->hasIO() && IsValid( SActor, aVtkId ) ) {
1246 bool anIsSameObjId = (mySelectedActor == SActor && myElemId == anObjId);
1247 bool aResult = anIsSameObjId;
1248 if(!anIsSameObjId) {
1249 if(aSelectionMode != EdgeOfCellSelection) {
1250 aResult = CheckDimensionId(aSelectionMode,SActor,anObjId);
1252 mySelectedActor = SActor;
1254 if(MYDEBUG) INFOS(" CellId : "<<anObjId);
1255 m_Interactor->setCellData(anObjId,SActor,myPreSelectionActor);
1259 if(aSelectionMode == EdgeOfCellSelection){
1260 int anEdgeId = GetEdgeId(picker,SActor,anObjId);
1261 bool anIsSameEdgeId = (myEdgeId != anEdgeId) && anIsSameObjId;
1262 aResult = anIsSameEdgeId;
1263 if(!anIsSameEdgeId) {
1264 aResult = (anEdgeId >= 0);
1266 mySelectedActor = SActor;
1267 myEdgeId = anEdgeId;
1269 if(MYDEBUG) INFOS(" CellId : "<<anObjId<<"; EdgeId : "<<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 if(MYDEBUG) INFOS(" PointId : "<<anObjId);
1291 m_Interactor->setPointData(anObjId,SActor,myPreSelectionActor);
1293 myPreSelectionActor->GetProperty()->SetRepresentationToSurface();
1294 myPreSelectionActor->SetVisibility(true);
1298 else if ( vtkPicker::SafeDownCast(aPicker) ) {
1300 if ( myPreViewActor != SActor ) {
1301 if ( myPreViewActor != NULL ) {
1302 myPreViewActor->SetPreSelected( false );
1304 myPreViewActor = SActor;
1306 if ( SActor->hasIO() ) {
1307 Handle( SALOME_InteractiveObject) IO = SActor->getIO();
1308 if ( !IsSelected(IO,Sel) ) {
1309 // Find All actors with same IO
1310 vtkActorCollection* theActors = this->CurrentRenderer->GetActors();
1311 theActors->InitTraversal();
1312 while( vtkActor *ac = theActors->GetNextActor() ) {
1313 if ( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) ) {
1314 if ( anActor->hasIO() ) {
1315 Handle(SALOME_InteractiveObject) IOS = anActor->getIO();
1316 if(IO->isSame(IOS)) {
1317 anActor->SetPreSelected( true );
1322 //if(MYDEBUG) INFOS ( " NAME PREVIEW " << SActor->getName() );
1327 myPreViewActor = NULL;
1328 vtkActorCollection* theActors = this->CurrentRenderer->GetActors();
1329 theActors->InitTraversal();
1330 while( vtkActor *ac = theActors->GetNextActor() ) {
1331 if ( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) ) {
1332 anActor->SetPreSelected( false );
1337 m_Interactor->EndPickCallback();
1338 //m_Interactor->Render();
1339 myGUIWindow->update();
1341 this->LastPos[0] = x;
1342 this->LastPos[1] = y;
1345 // called on finsh GlobalPan operation
1346 void VTKViewer_InteractorStyleSALOME::Place(const int theX, const int theY)
1348 if (this->CurrentRenderer == NULL) {
1353 int *aSize = this->CurrentRenderer->GetRenderWindow()->GetSize();
1354 int centerX = aSize[0]/2;
1355 int centerY = aSize[1]/2;
1357 TranslateView(centerX, centerY, theX, theY);
1359 // restore zoom scale
1360 vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
1361 cam->SetParallelScale(myScale);
1362 ::ResetCameraClippingRange(this->CurrentRenderer);
1364 if (myGUIWindow) myGUIWindow->update();
1370 // Translates view from Point to Point
1371 void VTKViewer_InteractorStyleSALOME::TranslateView(int toX, int toY, int fromX, int fromY)
1373 vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
1374 double viewFocus[4], focalDepth, viewPoint[3];
1375 float newPickPoint[4], oldPickPoint[4], motionVector[3];
1376 cam->GetFocalPoint(viewFocus);
1378 this->ComputeWorldToDisplay(viewFocus[0], viewFocus[1],
1379 viewFocus[2], viewFocus);
1380 focalDepth = viewFocus[2];
1382 this->ComputeDisplayToWorld(double(toX), double(toY),
1383 focalDepth, newPickPoint);
1384 this->ComputeDisplayToWorld(double(fromX),double(fromY),
1385 focalDepth, oldPickPoint);
1387 // camera motion is reversed
1388 motionVector[0] = oldPickPoint[0] - newPickPoint[0];
1389 motionVector[1] = oldPickPoint[1] - newPickPoint[1];
1390 motionVector[2] = oldPickPoint[2] - newPickPoint[2];
1392 cam->GetFocalPoint(viewFocus);
1393 cam->GetPosition(viewPoint);
1394 cam->SetFocalPoint(motionVector[0] + viewFocus[0],
1395 motionVector[1] + viewFocus[1],
1396 motionVector[2] + viewFocus[2]);
1397 cam->SetPosition(motionVector[0] + viewPoint[0],
1398 motionVector[1] + viewPoint[1],
1399 motionVector[2] + viewPoint[2]);
1403 /// Checks: is the given Actor within display coordinates?
1404 bool VTKViewer_InteractorStyleSALOME::IsInRect(vtkActor* theActor,
1405 const int left, const int top,
1406 const int right, const int bottom)
1408 float* aBounds = theActor->GetBounds();
1409 float aMin[3], aMax[3];
1410 ComputeWorldToDisplay(aBounds[0], aBounds[2], aBounds[4], aMin);
1411 ComputeWorldToDisplay(aBounds[1], aBounds[3], aBounds[5], aMax);
1412 if (aMin[0] > aMax[0]) {
1413 float aBuf = aMin[0];
1417 if (aMin[1] > aMax[1]) {
1418 float aBuf = aMin[1];
1423 return ((aMin[0]>left) && (aMax[0]<right) && (aMin[1]>bottom) && (aMax[1]<top));
1427 /// Checks: is the given Cell within display coordinates?
1428 bool VTKViewer_InteractorStyleSALOME::IsInRect(vtkCell* theCell,
1429 const int left, const int top,
1430 const int right, const int bottom)
1432 float* aBounds = theCell->GetBounds();
1433 float aMin[3], aMax[3];
1434 ComputeWorldToDisplay(aBounds[0], aBounds[2], aBounds[4], aMin);
1435 ComputeWorldToDisplay(aBounds[1], aBounds[3], aBounds[5], aMax);
1436 if (aMin[0] > aMax[0]) {
1437 float aBuf = aMin[0];
1441 if (aMin[1] > aMax[1]) {
1442 float aBuf = aMin[1];
1447 return ((aMin[0]>left) && (aMax[0]<right) && (aMin[1]>bottom) && (aMax[1]<top));
1451 bool VTKViewer_InteractorStyleSALOME::IsInRect(float* thePoint,
1452 const int left, const int top,
1453 const int right, const int bottom)
1456 ComputeWorldToDisplay(thePoint[0], thePoint[1], thePoint[2], aPnt);
1458 return ((aPnt[0]>left) && (aPnt[0]<right) && (aPnt[1]>bottom) && (aPnt[1]<top));
1461 void VTKViewer_InteractorStyleSALOME::SetFilter( const Handle(VTKViewer_Filter)& theFilter )
1463 myFilters[ theFilter->GetId() ] = theFilter;
1466 bool VTKViewer_InteractorStyleSALOME::IsFilterPresent( const int theId )
1468 return myFilters.find( theId ) != myFilters.end();
1471 void VTKViewer_InteractorStyleSALOME::RemoveFilter( const int theId )
1473 if ( IsFilterPresent( theId ) )
1474 myFilters.erase( theId );
1478 bool VTKViewer_InteractorStyleSALOME::IsValid( SALOME_Actor* theActor,
1480 const bool theIsNode )
1482 std::map<int, Handle(VTKViewer_Filter)>::const_iterator anIter;
1483 for ( anIter = myFilters.begin(); anIter != myFilters.end(); ++anIter )
1485 const Handle(VTKViewer_Filter)& aFilter = anIter->second;
1486 if ( theIsNode == aFilter->IsNodeFilter() &&
1487 !aFilter->IsValid( theActor, theId ) )
1493 Handle(VTKViewer_Filter) VTKViewer_InteractorStyleSALOME::GetFilter( const int theId )
1495 return IsFilterPresent( theId ) ? myFilters[ theId ] : Handle(VTKViewer_Filter)();
1498 void VTKViewer_InteractorStyleSALOME::IncrementalPan( const int incrX, const int incrY )
1500 this->PanXY( incrX, incrY, 0, 0 );
1503 void VTKViewer_InteractorStyleSALOME::IncrementalZoom( const int incr )
1505 this->DollyXY( incr, incr );
1508 void VTKViewer_InteractorStyleSALOME::IncrementalRotate( const int incrX, const int incrY )
1510 this->RotateXY( incrX, -incrY );