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"
49 #include <vtkObjectFactory.h>
51 #include <vtkCommand.h>
52 #include <vtkCamera.h>
53 #include <vtkRenderer.h>
54 #include <vtkPicker.h>
55 #include <vtkPointPicker.h>
56 #include <vtkCellPicker.h>
58 #include <vtkMapper.h>
59 #include <vtkDataSet.h>
60 #include <vtkSmartPointer.h>
62 #include <qapplication.h>
63 //VRV: porting on Qt 3.0.5
64 #if QT_VERSION >= 0x030005
67 //VRV: porting on Qt 3.0.5
70 #include "utilities.h"
76 static int MYDEBUG = 0;
78 static int MYDEBUG = 0;
82 static bool IsStored(Handle(SALOME_InteractiveObject)& theIO,
83 const SALOME_ListIO& theListIO)
85 if (!theListIO.IsEmpty()){
86 SALOME_ListIteratorOfListIO anIter(theListIO);
87 for(; anIter.More(); anIter.Next()) {
88 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
89 if(theIO->isSame(anIO)) {
90 theIO = anIO; //Added by SRN, fix SAL1307
99 static bool IsSelected(Handle(SALOME_InteractiveObject)& theIO,
100 SALOME_Selection* theSel)
102 return IsStored(theIO,theSel->StoredIObjects());
106 static int GetEdgeId(vtkPicker *thePicker, SALOME_Actor *theActor, int theObjId){
108 if (vtkCell* aPickedCell = theActor->GetElemCell(theObjId)) {
109 float aPickPosition[3];
110 thePicker->GetPickPosition(aPickPosition);
111 float aMinDist = 1000000.0, aDist = 0;
112 for (int i = 0, iEnd = aPickedCell->GetNumberOfEdges(); i < iEnd; i++){
113 if(vtkLine* aLine = vtkLine::SafeDownCast(aPickedCell->GetEdge(i))){
114 int subId; float pcoords[3], closestPoint[3], weights[3];
115 aLine->EvaluatePosition(aPickPosition,closestPoint,subId,pcoords,aDist,weights);
116 if (aDist < aMinDist) {
127 static bool CheckDimensionId(Selection_Mode theMode, SALOME_Actor *theActor, vtkIdType theObjId){
132 return ( theActor->GetObjDimension( theObjId ) == 1 );
134 return ( theActor->GetObjDimension( theObjId ) == 2 );
135 case VolumeSelection:
136 return ( theActor->GetObjDimension( theObjId ) == 3 );
142 //----------------------------------------------------------------------------
143 vtkStandardNewMacro(VTKViewer_InteractorStyleSALOME);
144 //----------------------------------------------------------------------------
146 VTKViewer_InteractorStyleSALOME::VTKViewer_InteractorStyleSALOME()
149 this->MotionFactor = 10.0;
150 this->State = VTK_INTERACTOR_STYLE_CAMERA_NONE;
151 this->RadianToDegree = 180.0 / vtkMath::Pi();
152 this->ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
155 myPreSelectionActor = VTKViewer_Actor::New();
156 myPreSelectionActor->GetProperty()->SetColor(0,1,1);
157 myPreSelectionActor->GetProperty()->SetLineWidth(5);
158 myPreSelectionActor->GetProperty()->SetPointSize(5);
160 OnSelectionModeChanged();
163 //----------------------------------------------------------------------------
164 VTKViewer_InteractorStyleSALOME::~VTKViewer_InteractorStyleSALOME()
166 if(MYDEBUG) INFOS("VTKViewer_InteractorStyleSALOME::~VTKViewer_InteractorStyleSALOME()");
167 m_ViewFrame->RemoveActor(myPreSelectionActor);
170 //----------------------------------------------------------------------------
171 void VTKViewer_InteractorStyleSALOME::setPreselectionProp(const double& theRed, const double& theGreen,
172 const double& theBlue, const int& theWidth)
174 myPreSelectionActor->GetProperty()->SetColor(theRed, theGreen, theBlue);
175 myPreSelectionActor->GetProperty()->SetLineWidth(theWidth);
176 myPreSelectionActor->GetProperty()->SetPointSize(theWidth);
179 //----------------------------------------------------------------------------
180 void VTKViewer_InteractorStyleSALOME::SetInteractor(vtkRenderWindowInteractor *theInteractor){
181 m_Interactor = dynamic_cast<VTKViewer_RenderWindowInteractor*>(theInteractor);
182 Superclass::SetInteractor(theInteractor);
185 //----------------------------------------------------------------------------
186 void VTKViewer_InteractorStyleSALOME::setViewFrame(VTKViewer_ViewFrame* theViewFrame){
187 m_ViewFrame = theViewFrame;
188 m_ViewFrame->AddActor(myPreSelectionActor);
189 myPreSelectionActor->Delete();
192 //----------------------------------------------------------------------------
193 void VTKViewer_InteractorStyleSALOME::setGUIWindow(QWidget* theWindow){
194 myGUIWindow = theWindow;
197 //----------------------------------------------------------------------------
198 void VTKViewer_InteractorStyleSALOME::setTriedron(VTKViewer_Trihedron* theTrihedron){
199 m_Trihedron = theTrihedron;
202 //----------------------------------------------------------------------------
203 void VTKViewer_InteractorStyleSALOME::RotateXY(int dx, int dy)
209 if (this->CurrentRenderer == NULL)
214 int *size = this->CurrentRenderer->GetRenderWindow()->GetSize();
215 this->DeltaElevation = -20.0 / size[1];
216 this->DeltaAzimuth = -20.0 / size[0];
218 rxf = (double)dx * this->DeltaAzimuth * this->MotionFactor;
219 ryf = (double)dy * this->DeltaElevation * this->MotionFactor;
221 cam = this->CurrentRenderer->GetActiveCamera();
224 cam->OrthogonalizeViewUp();
225 ::ResetCameraClippingRange(this->CurrentRenderer);
226 //this->Interactor->Render();
227 myGUIWindow->update();
230 //----------------------------------------------------------------------------
231 void VTKViewer_InteractorStyleSALOME::PanXY(int x, int y, int oldX, int oldY)
233 TranslateView(x, y, oldX, oldY);
234 //this->Interactor->Render();
235 myGUIWindow->update();
239 //----------------------------------------------------------------------------
240 void VTKViewer_InteractorStyleSALOME::DollyXY(int dx, int dy)
242 if (this->CurrentRenderer == NULL) return;
244 double dxf = this->MotionFactor * (double)(dx) / (double)(this->CurrentRenderer->GetCenter()[1]);
245 double dyf = this->MotionFactor * (double)(dy) / (double)(this->CurrentRenderer->GetCenter()[1]);
247 double zoomFactor = pow((double)1.1, dxf + dyf);
249 vtkCamera *aCam = this->CurrentRenderer->GetActiveCamera();
250 if (aCam->GetParallelProjection())
251 aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
253 aCam->Dolly(zoomFactor);
254 ::ResetCameraClippingRange(this->CurrentRenderer);
257 //this->Interactor->Render();
258 myGUIWindow->update();
261 //----------------------------------------------------------------------------
262 void VTKViewer_InteractorStyleSALOME::SpinXY(int x, int y, int oldX, int oldY)
266 if (this->CurrentRenderer == NULL)
271 double newAngle = atan2((double)(y - this->CurrentRenderer->GetCenter()[1]),
272 (double)(x - this->CurrentRenderer->GetCenter()[0]));
273 double oldAngle = atan2((double)(oldY -this->CurrentRenderer->GetCenter()[1]),
274 (double)(oldX - this->CurrentRenderer->GetCenter()[0]));
276 newAngle *= this->RadianToDegree;
277 oldAngle *= this->RadianToDegree;
279 cam = this->CurrentRenderer->GetActiveCamera();
280 cam->Roll(newAngle - oldAngle);
281 cam->OrthogonalizeViewUp();
283 //this->Interactor->Render();
284 myGUIWindow->update();
288 //----------------------------------------------------------------------------
289 void VTKViewer_InteractorStyleSALOME::OnMouseMove(int vtkNotUsed(ctrl),
293 myShiftState = shift;
294 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
295 onOperation(QPoint(x, y));
296 else if (ForcedState == VTK_INTERACTOR_STYLE_CAMERA_NONE)
297 onCursorMove(QPoint(x, y));
301 //----------------------------------------------------------------------------
302 void VTKViewer_InteractorStyleSALOME::OnLeftButtonDown(int ctrl, int shift,
305 if (this->HasObserver(vtkCommand::LeftButtonPressEvent)) {
306 this->InvokeEvent(vtkCommand::LeftButtonPressEvent,NULL);
309 this->FindPokedRenderer(x, y);
310 if (this->CurrentRenderer == NULL) {
313 myShiftState = shift;
314 // finishing current viewer operation
315 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
317 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
319 myOtherPoint = myPoint = QPoint(x, y);
320 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
321 startOperation(ForcedState);
324 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
326 startOperation(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
332 //----------------------------------------------------------------------------
333 void VTKViewer_InteractorStyleSALOME::OnLeftButtonUp(int vtkNotUsed(ctrl),
338 myShiftState = shift;
339 // finishing current viewer operation
340 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
342 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
347 //----------------------------------------------------------------------------
348 void VTKViewer_InteractorStyleSALOME::OnMiddleButtonDown(int ctrl,
352 if (this->HasObserver(vtkCommand::MiddleButtonPressEvent))
354 this->InvokeEvent(vtkCommand::MiddleButtonPressEvent,NULL);
357 this->FindPokedRenderer(x, y);
358 if (this->CurrentRenderer == NULL)
362 myShiftState = shift;
363 // finishing current viewer operation
364 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
366 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
368 myOtherPoint = myPoint = QPoint(x, y);
369 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
370 startOperation(ForcedState);
374 startOperation(VTK_INTERACTOR_STYLE_CAMERA_PAN);
379 //----------------------------------------------------------------------------
380 void VTKViewer_InteractorStyleSALOME::OnMiddleButtonUp(int vtkNotUsed(ctrl),
385 myShiftState = shift;
386 // finishing current viewer operation
387 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
389 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
394 //----------------------------------------------------------------------------
395 void VTKViewer_InteractorStyleSALOME::OnRightButtonDown(int ctrl,
399 if (this->HasObserver(vtkCommand::RightButtonPressEvent))
401 this->InvokeEvent(vtkCommand::RightButtonPressEvent,NULL);
404 this->FindPokedRenderer(x, y);
405 if (this->CurrentRenderer == NULL)
409 myShiftState = shift;
410 // finishing current viewer operation
411 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
413 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
415 myOtherPoint = myPoint = QPoint(x, y);
416 if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
417 startOperation(ForcedState);
421 startOperation(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
425 //----------------------------------------------------------------------------
426 void VTKViewer_InteractorStyleSALOME::OnRightButtonUp(int vtkNotUsed(ctrl),
431 myShiftState = shift;
432 // finishing current viewer operation
433 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
435 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
439 //----------------------------------------------------------------------------
441 const char* imageZoomCursor[] = {
446 "................................",
447 "................................",
448 ".#######........................",
449 "..aaaaaaa.......................",
450 "................................",
451 ".............#####..............",
452 "...........##.aaaa##............",
453 "..........#.aa.....a#...........",
454 ".........#.a.........#..........",
455 ".........#a..........#a.........",
456 "........#.a...........#.........",
457 "........#a............#a........",
458 "........#a............#a........",
459 "........#a............#a........",
460 "........#a............#a........",
461 ".........#...........#.a........",
462 ".........#a..........#a.........",
463 ".........##.........#.a.........",
464 "........#####.....##.a..........",
465 ".......###aaa#####.aa...........",
466 "......###aa...aaaaa.......#.....",
467 ".....###aa................#a....",
468 "....###aa.................#a....",
469 "...###aa...............#######..",
470 "....#aa.................aa#aaaa.",
471 ".....a....................#a....",
472 "..........................#a....",
473 "...........................a....",
474 "................................",
475 "................................",
476 "................................",
477 "................................"};
479 const char* imageRotateCursor[] = {
484 "................................",
485 "................................",
486 "................................",
487 "................................",
488 "........#.......................",
489 ".......#.a......................",
490 "......#######...................",
491 ".......#aaaaa#####..............",
492 "........#..##.a#aa##........##..",
493 ".........a#.aa..#..a#.....##.aa.",
494 ".........#.a.....#...#..##.aa...",
495 ".........#a.......#..###.aa.....",
496 "........#.a.......#a..#aa.......",
497 "........#a.........#..#a........",
498 "........#a.........#a.#a........",
499 "........#a.........#a.#a........",
500 "........#a.........#a.#a........",
501 ".........#.........#a#.a........",
502 "........##a........#a#a.........",
503 "......##.a#.......#.#.a.........",
504 "....##.aa..##.....##.a..........",
505 "..##.aa.....a#####.aa...........",
506 "...aa.........aaa#a.............",
507 "................#.a.............",
508 "...............#.a..............",
509 "..............#.a...............",
510 "...............a................",
511 "................................",
512 "................................",
513 "................................",
514 "................................",
515 "................................"};
518 //----------------------------------------------------------------------------
519 // loads cursors for viewer operations - zoom, pan, etc...
520 void VTKViewer_InteractorStyleSALOME::loadCursors()
522 myDefCursor = QCursor(ArrowCursor);
523 myHandCursor = QCursor(PointingHandCursor);
524 myPanCursor = QCursor(SizeAllCursor);
525 myZoomCursor = QCursor(QPixmap(imageZoomCursor));
526 myRotateCursor = QCursor(QPixmap(imageRotateCursor));
527 mySpinCursor = QCursor(QPixmap(imageRotateCursor)); // temporarly !!!!!!
528 myGlobalPanCursor = QCursor(CrossCursor);
529 myCursorState = false;
533 //----------------------------------------------------------------------------
534 // event filter - controls mouse and keyboard events during viewer operations
535 bool VTKViewer_InteractorStyleSALOME::eventFilter(QObject* object, QEvent* event)
537 if (!myGUIWindow) return false;
538 if ( (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::KeyPress) && object != myGUIWindow)
540 qApp->removeEventFilter(this);
541 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
543 return QObject::eventFilter(object, event);
547 //----------------------------------------------------------------------------
548 // starts Zoom operation (e.g. through menu command)
549 void VTKViewer_InteractorStyleSALOME::startZoom()
551 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
554 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
556 setCursor(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
557 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ZOOM;
558 qApp->installEventFilter(this);
562 //----------------------------------------------------------------------------
563 // starts Pan operation (e.g. through menu command)
564 void VTKViewer_InteractorStyleSALOME::startPan()
566 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
569 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
571 setCursor(VTK_INTERACTOR_STYLE_CAMERA_PAN);
572 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_PAN;
573 qApp->installEventFilter(this);
576 //----------------------------------------------------------------------------
577 // starts Rotate operation (e.g. through menu command)
578 void VTKViewer_InteractorStyleSALOME::startRotate()
580 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
583 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
585 setCursor(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
586 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ROTATE;
587 qApp->installEventFilter(this);
591 //----------------------------------------------------------------------------
592 // starts Spin operation (e.g. through menu command)
593 void VTKViewer_InteractorStyleSALOME::startSpin()
595 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
598 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
600 setCursor(VTK_INTERACTOR_STYLE_CAMERA_SPIN);
601 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_SPIN;
602 qApp->installEventFilter(this);
607 //----------------------------------------------------------------------------
608 // starts Fit Area operation (e.g. through menu command)
609 void VTKViewer_InteractorStyleSALOME::startFitArea()
611 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
614 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
616 setCursor(VTK_INTERACTOR_STYLE_CAMERA_FIT);
617 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_FIT;
618 qApp->installEventFilter(this);
622 //----------------------------------------------------------------------------
623 void VTKViewer_InteractorStyleSALOME::ViewFitAll() {
624 int aTriedronWasVisible = false;
626 aTriedronWasVisible = m_Trihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
627 if(aTriedronWasVisible) m_Trihedron->VisibilityOff();
630 if(m_Trihedron->GetVisibleActorCount(CurrentRenderer)){
631 m_Trihedron->VisibilityOff();
632 ::ResetCamera(CurrentRenderer);
634 m_Trihedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
635 ::ResetCamera(CurrentRenderer,true);
637 if(aTriedronWasVisible) m_Trihedron->VisibilityOn();
638 else m_Trihedron->VisibilityOff();
639 ::ResetCameraClippingRange(CurrentRenderer);
643 //----------------------------------------------------------------------------
644 // starts Global Panning operation (e.g. through menu command)
645 void VTKViewer_InteractorStyleSALOME::startGlobalPan()
647 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
650 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
652 setCursor(VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN);
653 ForcedState = VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN;
655 // store current zoom scale
656 vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
657 myScale = cam->GetParallelScale();
661 if (myGUIWindow) myGUIWindow->update();
663 qApp->installEventFilter(this);
667 //----------------------------------------------------------------------------
668 // returns TRUE if needs redrawing
669 bool VTKViewer_InteractorStyleSALOME::needsRedrawing()
671 return State == VTK_INTERACTOR_STYLE_CAMERA_ZOOM ||
672 State == VTK_INTERACTOR_STYLE_CAMERA_PAN ||
673 State == VTK_INTERACTOR_STYLE_CAMERA_ROTATE ||
674 State == VTK_INTERACTOR_STYLE_CAMERA_SPIN ||
675 State == VTK_INTERACTOR_STYLE_CAMERA_NONE;
679 //----------------------------------------------------------------------------
680 // fits viewer contents to rect
681 void VTKViewer_InteractorStyleSALOME::fitRect(const int left,
686 if (this->CurrentRenderer == NULL) return;
689 int x = (left + right)/2;
690 int y = (top + bottom)/2;
691 int *aSize = this->CurrentRenderer->GetRenderWindow()->GetSize();
692 int oldX = aSize[0]/2;
693 int oldY = aSize[1]/2;
694 TranslateView(oldX, oldY, x, y);
697 double dxf = (double)(aSize[0]) / (double)(abs(right - left));
698 double dyf = (double)(aSize[1]) / (double)(abs(bottom - top));
699 double zoomFactor = (dxf + dyf)/2 ;
701 vtkCamera *aCam = this->CurrentRenderer->GetActiveCamera();
702 if(aCam->GetParallelProjection())
703 aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
705 aCam->Dolly(zoomFactor);
706 ::ResetCameraClippingRange(this->CurrentRenderer);
709 myGUIWindow->update();
713 //----------------------------------------------------------------------------
714 // starts viewer operation (!internal usage!)
715 void VTKViewer_InteractorStyleSALOME::startOperation(int operation)
719 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
720 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
721 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
722 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
723 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
724 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
725 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
726 if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
727 startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
729 if (State != VTK_INTERACTOR_STYLE_CAMERA_SELECT)
730 setCursor(operation);
733 case VTK_INTERACTOR_STYLE_CAMERA_NONE:
735 setCursor(VTK_INTERACTOR_STYLE_CAMERA_NONE);
736 State = ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
742 //----------------------------------------------------------------------------
743 // sets proper cursor for window when viewer operation is activated
744 void VTKViewer_InteractorStyleSALOME::setCursor(const int operation)
746 if (!myGUIWindow) return;
749 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
750 myGUIWindow->setCursor(myZoomCursor);
751 myCursorState = true;
753 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
754 myGUIWindow->setCursor(myPanCursor);
755 myCursorState = true;
757 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
758 myGUIWindow->setCursor(myRotateCursor);
759 myCursorState = true;
761 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
762 myGUIWindow->setCursor(mySpinCursor);
763 myCursorState = true;
765 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
766 myGUIWindow->setCursor(myGlobalPanCursor);
767 myCursorState = true;
769 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
770 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
771 myGUIWindow->setCursor(myHandCursor);
772 myCursorState = true;
774 case VTK_INTERACTOR_STYLE_CAMERA_NONE:
776 myGUIWindow->setCursor(myDefCursor);
777 myCursorState = false;
783 //----------------------------------------------------------------------------
784 // called when viewer operation started (!put necessary initialization here!)
785 void VTKViewer_InteractorStyleSALOME::onStartOperation()
787 if (!myGUIWindow) return;
788 // VSV: LOD actor activisation
789 // this->Interactor->GetRenderWindow()->SetDesiredUpdateRate(this->Interactor->GetDesiredUpdateRate());
791 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
792 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
794 QPainter p(myGUIWindow);
795 p.setPen(Qt::lightGray);
796 p.setRasterOp(Qt::XorROP);
797 p.drawRect(QRect(myPoint, myOtherPoint));
800 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
801 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
802 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
803 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
804 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
810 //----------------------------------------------------------------------------
811 // called when viewer operation finished (!put necessary post-processing here!)
812 void VTKViewer_InteractorStyleSALOME::onFinishOperation()
814 if (!myGUIWindow) return;
817 QAD_Study* aActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
818 SALOME_Selection* aSel = SALOME_Selection::Selection( aActiveStudy->getSelection() );
820 // VSV: LOD actor activisation
821 // rwi->GetRenderWindow()->SetDesiredUpdateRate(rwi->GetStillUpdateRate());
823 Selection_Mode aSelectionMode = aSel->SelectionMode();
824 bool aSelActiveCompOnly = aSel->IsSelectActiveCompOnly();
827 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
828 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
830 QPainter p(myGUIWindow);
831 p.setPen(Qt::lightGray);
832 p.setRasterOp(Qt::XorROP);
833 QRect rect(myPoint, myOtherPoint);
835 rect = rect.normalize();
836 if (State == VTK_INTERACTOR_STYLE_CAMERA_FIT) {
837 // making fit rect opeation
839 m_Interactor->GetSize(w, h);
842 y1 = h - rect.top() - 1;
844 y2 = h - rect.bottom() - 1;
845 fitRect(x1, y1, x2, y2);
848 if (myPoint == myOtherPoint) {
849 // process point selection
851 m_Interactor->GetSize(w, h);
853 y = h - myPoint.y() - 1;
855 this->FindPokedRenderer(x, y);
856 m_Interactor->StartPickCallback();
858 vtkPicker* aPicker = vtkPicker::SafeDownCast(m_Interactor->GetPicker());
859 aPicker->Pick(x, y, 0.0, this->CurrentRenderer);
861 SALOME_Actor* SActor = SALOME_Actor::SafeDownCast(aPicker->GetActor());
863 if (vtkCellPicker* picker = vtkCellPicker::SafeDownCast(aPicker)) {
864 int aVtkId = picker->GetCellId();
865 if ( aVtkId >= 0 && SActor && SActor->hasIO() && IsValid( SActor, aVtkId ) ) {
866 int anObjId = SActor->GetElemObjId(aVtkId);
868 Handle(SALOME_InteractiveObject) IO = SActor->getIO();
869 if(aSelectionMode != EdgeOfCellSelection) {
870 if(CheckDimensionId(aSelectionMode,SActor,anObjId)){
871 if(MYDEBUG) INFOS(" CellId : "<<anObjId);
872 if (IsSelected(IO,aSel)) {
873 // This IO is already in the selection
874 aSel->AddOrRemoveIndex( IO, anObjId, myShiftState, false );
877 this->HighlightProp( NULL );
878 aSel->ClearIObjects();
880 aSel->AddOrRemoveIndex( IO, anObjId, myShiftState, false );
881 aSel->AddIObject( IO, false );
886 this->HighlightProp( NULL );
887 aSel->ClearIObjects();
889 int anEdgeId = GetEdgeId(picker,SActor,anObjId);
891 if(MYDEBUG) INFOS(" CellId : "<<anObjId<<"; EdgeId : "<<anEdgeId);
892 aSel->AddOrRemoveIndex( IO, anObjId, true, false);
893 aSel->AddOrRemoveIndex( IO, -anEdgeId-1, true, true );
894 aSel->AddIObject( IO, false );
899 this->HighlightProp( NULL );
900 aSel->ClearIObjects();
902 } else if ( vtkPointPicker* picker = vtkPointPicker::SafeDownCast(aPicker) ) {
903 int aVtkId = picker->GetPointId();
904 if ( aVtkId >= 0 && IsValid( SActor, aVtkId, true ) ) {
905 if ( SActor && SActor->hasIO() ) {
906 int anObjId = SActor->GetNodeObjId(aVtkId);
908 Handle(SALOME_InteractiveObject) IO = SActor->getIO();
909 if(IsSelected(IO,aSel)) {
910 // This IO is already in the selection
911 aSel->AddOrRemoveIndex( IO, anObjId, myShiftState, false );
914 this->HighlightProp( NULL );
915 aSel->ClearIObjects();
917 if(MYDEBUG) INFOS(" PointId : "<<anObjId);
918 aSel->AddOrRemoveIndex( IO, anObjId, myShiftState, false );
919 aSel->AddIObject( IO, false );
924 this->HighlightProp( NULL );
925 aSel->ClearIObjects();
928 if ( SActor && SActor->hasIO() ) {
930 Handle(SALOME_InteractiveObject) IO = SActor->getIO();
931 if(IsSelected(IO,aSel)) {
932 // This IO is already in the selection
934 aSel->RemoveIObject(IO);
939 this->HighlightProp( NULL );
940 aSel->ClearIObjects();
942 aSel->AddIObject( IO, false );
945 // No selection clear all
946 this->PropPicked = 0;
947 this->HighlightProp( NULL );
948 aSel->ClearIObjects();
951 m_Interactor->EndPickCallback();
953 //processing rectangle selection
954 QString aComponentDataType = QAD_Application::getDesktop()->getComponentDataType();
955 if(aSelActiveCompOnly && aComponentDataType.isEmpty()) return;
956 m_Interactor->StartPickCallback();
959 this->PropPicked = 0;
960 this->HighlightProp( NULL );
961 aSel->ClearIObjects();
965 // vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
966 QRect rect(myPoint, myOtherPoint);
967 rect = rect.normalize();
969 m_Interactor->GetSize(w, h);
972 y1 = h - rect.top() - 1;
974 y2 = h - rect.bottom() - 1;
976 switch (aSelectionMode) {
977 case NodeSelection: {
978 if ( vtkPointPicker* aPointPicker = vtkPointPicker::SafeDownCast(m_Interactor->GetPicker()) ) {
979 vtkActorCollection* aListActors = this->CurrentRenderer->GetActors();
980 aListActors->InitTraversal();
981 while (vtkActor* aActor = aListActors->GetNextActor()) {
982 if (!aActor->GetVisibility())
984 if(SALOME_Actor* SActor = SALOME_Actor::SafeDownCast(aActor)) {
985 if (SActor->hasIO()) {
986 Handle(SALOME_InteractiveObject) IO = SActor->getIO();
989 if (aSelActiveCompOnly && aComponentDataType != IO->getComponentDataType())
991 if (vtkDataSet* aDataSet = SActor->GetInput()) {
992 SALOME_Selection::TContainerOfId anIndices;
993 for(int i = 0; i < aDataSet->GetNumberOfPoints(); i++) {
995 aDataSet->GetPoint(i,aPoint);
996 if (IsInRect(aPoint,x1,y1,x2,y2)){
998 ComputeWorldToDisplay(aPoint[0],aPoint[1],aPoint[2],aDisp);
999 if(aPointPicker->Pick(aDisp[0],aDisp[1],0.0,CurrentRenderer)){
1000 if(vtkActorCollection *anActorCollection = aPointPicker->GetActors()){
1001 if(anActorCollection->IsItemPresent(SActor)){
1002 float aPickedPoint[3];
1003 aPointPicker->GetMapperPosition(aPickedPoint);
1004 vtkIdType aVtkId = aDataSet->FindPoint(aPickedPoint);
1005 if ( aVtkId >= 0 && IsValid( SActor, aVtkId, true ) ){
1006 int anObjId = SActor->GetNodeObjId(aVtkId);
1007 anIndices.insert(anObjId);
1014 if (!anIndices.empty()) {
1015 aSel->AddOrRemoveIndex(IO, anIndices, true, false);
1016 aSel->AddIObject(IO, false);
1019 aSel->RemoveIObject(IO, false);
1029 case EdgeOfCellSelection:
1032 case VolumeSelection:
1034 vtkSmartPointer<VTKViewer_CellRectPicker> picker = VTKViewer_CellRectPicker::New();
1035 picker->SetTolerance(0.001);
1036 picker->Pick(x1, y1, 0.0, x2, y2, 0.0, this->CurrentRenderer);
1038 vtkActorCollection* aListActors = picker->GetActors();
1039 aListActors->InitTraversal();
1040 while(vtkActor* aActor = aListActors->GetNextActor()) {
1041 if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)) {
1042 if (aSActor->hasIO()) {
1043 Handle(SALOME_InteractiveObject) aIO = aSActor->getIO();
1044 if (aSelActiveCompOnly && aComponentDataType != aIO->getComponentDataType())
1046 VTKViewer_CellDataSet cellList = picker->GetCellData(aActor);
1047 if ( !cellList.empty() ) {
1048 if(MYDEBUG) INFOS ( " NAME Actor : " << aSActor->getName() );
1049 SALOME_Selection::TContainerOfId anIndexes;
1050 VTKViewer_CellDataSet::iterator it;
1051 for ( it = cellList.begin(); it != cellList.end(); ++it ) {
1052 int aCellId = (*it).cellId;
1054 if ( !IsValid( aSActor, aCellId ) )
1057 int anObjId = aSActor->GetElemObjId(aCellId);
1059 if ( CheckDimensionId(aSelectionMode,aSActor,anObjId) ) {
1060 anIndexes.insert(anObjId);
1064 aSel->AddOrRemoveIndex(aIO, anIndexes, true, false);
1065 aSel->AddIObject(aIO, false);
1072 case ActorSelection: // objects selection
1074 vtkSmartPointer<VTKViewer_RectPicker> picker = VTKViewer_RectPicker::New();
1075 picker->SetTolerance(0.001);
1076 picker->Pick(x1, y1, 0.0, x2, y2, 0.0, this->CurrentRenderer);
1078 vtkActorCollection* aListActors = picker->GetActors();
1079 SALOME_ListIO aListIO;
1080 aListActors->InitTraversal();
1081 while(vtkActor* aActor = aListActors->GetNextActor()) {
1082 if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)) {
1083 if (aSActor->hasIO()) {
1084 Handle(SALOME_InteractiveObject) aIO = aSActor->getIO();
1085 if (!IsStored(aIO,aListIO))
1086 aListIO.Append(aIO);
1090 if (!aListIO.IsEmpty()) {
1091 SALOME_ListIteratorOfListIO It(aListIO);
1092 for(;It.More();It.Next()) {
1093 Handle(SALOME_InteractiveObject) IOS = It.Value();
1095 aSel->AddIObject( IOS, false );
1100 m_Interactor->EndPickCallback();
1102 aActiveStudy->update3dViewers();
1106 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
1107 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
1108 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
1109 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
1111 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
1114 m_Interactor->GetSize(w, h);
1116 y = h - myPoint.y() - 1;
1121 if (myGUIWindow) myGUIWindow->update();
1125 // called during viewer operation when user moves mouse (!put necessary processing here!)
1126 void VTKViewer_InteractorStyleSALOME::onOperation(QPoint mousePos)
1128 if (!myGUIWindow) return;
1130 GetInteractor()->GetSize(w, h);
1132 case VTK_INTERACTOR_STYLE_CAMERA_PAN:
1134 // processing panning
1135 //this->FindPokedCamera(mousePos.x(), mousePos.y());
1136 this->PanXY(mousePos.x(), myPoint.y(), myPoint.x(), mousePos.y());
1140 case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
1142 // processing zooming
1143 //this->FindPokedCamera(mousePos.x(), mousePos.y());
1144 this->DollyXY(mousePos.x() - myPoint.x(), mousePos.y() - myPoint.y());
1148 case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
1150 // processing rotation
1151 //this->FindPokedCamera(mousePos.x(), mousePos.y());
1152 this->RotateXY(mousePos.x() - myPoint.x(), myPoint.y() - mousePos.y());
1156 case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
1158 // processing spinning
1159 //this->FindPokedCamera(mousePos.x(), mousePos.y());
1160 this->SpinXY(mousePos.x(), mousePos.y(), myPoint.x(), myPoint.y());
1164 case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
1168 case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
1171 setCursor(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
1173 case VTK_INTERACTOR_STYLE_CAMERA_FIT:
1175 QPainter p(myGUIWindow);
1176 p.setPen(Qt::lightGray);
1177 p.setRasterOp(Qt::XorROP);
1178 p.drawRect(QRect(myPoint, myOtherPoint));
1179 myOtherPoint = mousePos;
1180 p.drawRect(QRect(myPoint, myOtherPoint));
1184 this->LastPos[0] = mousePos.x();
1185 this->LastPos[1] = h - mousePos.y() - 1;
1188 // called when selection mode changed (!put necessary initialization here!)
1189 void VTKViewer_InteractorStyleSALOME::OnSelectionModeChanged()
1192 myPreSelectionActor->SetVisibility(false);
1193 myElemId = myEdgeId = myNodeId = -1;
1194 mySelectedActor = NULL;
1197 // called when user moves mouse inside viewer window and there is no active viewer operation
1198 // (!put necessary processing here!)
1199 void VTKViewer_InteractorStyleSALOME::onCursorMove(QPoint mousePos) {
1200 // processing highlighting
1201 QAD_Study* anActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
1202 SALOME_Selection* Sel = SALOME_Selection::Selection( anActiveStudy->getSelection() );
1203 Selection_Mode aSelectionMode = Sel->SelectionMode();
1206 m_Interactor->GetSize(w, h);
1207 x = mousePos.x(); y = h - mousePos.y() - 1;
1209 this->FindPokedRenderer(x,y);
1210 m_Interactor->StartPickCallback();
1211 myPreSelectionActor->SetVisibility(false);
1213 vtkPicker* aPicker = vtkPicker::SafeDownCast(m_Interactor->GetPicker());
1214 aPicker->Pick(x, y, 0.0, this->CurrentRenderer);
1216 SALOME_Actor* SActor = SALOME_Actor::SafeDownCast(aPicker->GetActor());
1218 if (vtkCellPicker* picker = vtkCellPicker::SafeDownCast(aPicker)) {
1219 int aVtkId = picker->GetCellId();
1220 if ( aVtkId >= 0 ) {
1221 int anObjId = SActor->GetElemObjId(aVtkId);
1222 if ( SActor && SActor->hasIO() && IsValid( SActor, aVtkId ) ) {
1223 bool anIsSameObjId = (mySelectedActor == SActor && myElemId == anObjId);
1224 bool aResult = anIsSameObjId;
1225 if(!anIsSameObjId) {
1226 if(aSelectionMode != EdgeOfCellSelection) {
1227 aResult = CheckDimensionId(aSelectionMode,SActor,anObjId);
1229 mySelectedActor = SActor;
1231 if(MYDEBUG) INFOS(" CellId : "<<anObjId);
1232 m_Interactor->setCellData(anObjId,SActor,myPreSelectionActor);
1236 if(aSelectionMode == EdgeOfCellSelection){
1237 int anEdgeId = GetEdgeId(picker,SActor,anObjId);
1238 bool anIsSameEdgeId = (myEdgeId != anEdgeId) && anIsSameObjId;
1239 aResult = anIsSameEdgeId;
1240 if(!anIsSameEdgeId) {
1241 aResult = (anEdgeId >= 0);
1243 mySelectedActor = SActor;
1244 myEdgeId = anEdgeId;
1246 if(MYDEBUG) INFOS(" CellId : "<<anObjId<<"; EdgeId : "<<anEdgeId);
1247 m_Interactor->setEdgeData(anObjId,SActor,-anEdgeId-1,myPreSelectionActor);
1252 myPreSelectionActor->GetProperty()->SetRepresentationToSurface();
1253 myPreSelectionActor->SetVisibility(true);
1258 else if (vtkPointPicker* picker = vtkPointPicker::SafeDownCast(aPicker)) {
1259 int aVtkId = picker->GetPointId();
1260 if ( aVtkId >= 0 && IsValid( SActor, aVtkId, true ) ) {
1261 if ( SActor && SActor->hasIO() ) {
1262 int anObjId = SActor->GetNodeObjId(aVtkId);
1263 bool anIsSameObjId = (mySelectedActor == SActor && myNodeId == anObjId);
1264 if(!anIsSameObjId) {
1265 mySelectedActor = SActor;
1267 if(MYDEBUG) INFOS(" PointId : "<<anObjId);
1268 m_Interactor->setPointData(anObjId,SActor,myPreSelectionActor);
1270 myPreSelectionActor->GetProperty()->SetRepresentationToSurface();
1271 myPreSelectionActor->SetVisibility(true);
1275 else if ( vtkPicker* picker = vtkPicker::SafeDownCast(aPicker) ) {
1277 if ( myPreViewActor != SActor ) {
1278 if ( myPreViewActor != NULL ) {
1279 myPreViewActor->SetPreSelected( false );
1281 myPreViewActor = SActor;
1283 if ( SActor->hasIO() ) {
1284 Handle( SALOME_InteractiveObject) IO = SActor->getIO();
1285 if ( !IsSelected(IO,Sel) ) {
1286 // Find All actors with same IO
1287 vtkActorCollection* theActors = this->CurrentRenderer->GetActors();
1288 theActors->InitTraversal();
1289 while( vtkActor *ac = theActors->GetNextActor() ) {
1290 if ( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) ) {
1291 if ( anActor->hasIO() ) {
1292 Handle(SALOME_InteractiveObject) IOS = anActor->getIO();
1293 if(IO->isSame(IOS)) {
1294 anActor->SetPreSelected( true );
1299 //if(MYDEBUG) INFOS ( " NAME PREVIEW " << SActor->getName() );
1304 myPreViewActor = NULL;
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 anActor->SetPreSelected( false );
1314 m_Interactor->EndPickCallback();
1315 //m_Interactor->Render();
1316 myGUIWindow->update();
1318 this->LastPos[0] = x;
1319 this->LastPos[1] = y;
1322 // called on finsh GlobalPan operation
1323 void VTKViewer_InteractorStyleSALOME::Place(const int theX, const int theY)
1325 if (this->CurrentRenderer == NULL) {
1330 int *aSize = this->CurrentRenderer->GetRenderWindow()->GetSize();
1331 int centerX = aSize[0]/2;
1332 int centerY = aSize[1]/2;
1334 TranslateView(centerX, centerY, theX, theY);
1336 // restore zoom scale
1337 vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
1338 cam->SetParallelScale(myScale);
1339 ::ResetCameraClippingRange(this->CurrentRenderer);
1341 if (myGUIWindow) myGUIWindow->update();
1347 // Translates view from Point to Point
1348 void VTKViewer_InteractorStyleSALOME::TranslateView(int toX, int toY, int fromX, int fromY)
1350 vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
1351 double viewFocus[4], focalDepth, viewPoint[3];
1352 float newPickPoint[4], oldPickPoint[4], motionVector[3];
1353 cam->GetFocalPoint(viewFocus);
1355 this->ComputeWorldToDisplay(viewFocus[0], viewFocus[1],
1356 viewFocus[2], viewFocus);
1357 focalDepth = viewFocus[2];
1359 this->ComputeDisplayToWorld(double(toX), double(toY),
1360 focalDepth, newPickPoint);
1361 this->ComputeDisplayToWorld(double(fromX),double(fromY),
1362 focalDepth, oldPickPoint);
1364 // camera motion is reversed
1365 motionVector[0] = oldPickPoint[0] - newPickPoint[0];
1366 motionVector[1] = oldPickPoint[1] - newPickPoint[1];
1367 motionVector[2] = oldPickPoint[2] - newPickPoint[2];
1369 cam->GetFocalPoint(viewFocus);
1370 cam->GetPosition(viewPoint);
1371 cam->SetFocalPoint(motionVector[0] + viewFocus[0],
1372 motionVector[1] + viewFocus[1],
1373 motionVector[2] + viewFocus[2]);
1374 cam->SetPosition(motionVector[0] + viewPoint[0],
1375 motionVector[1] + viewPoint[1],
1376 motionVector[2] + viewPoint[2]);
1380 /// Checks: is the given Actor within display coordinates?
1381 bool VTKViewer_InteractorStyleSALOME::IsInRect(vtkActor* theActor,
1382 const int left, const int top,
1383 const int right, const int bottom)
1385 float* aBounds = theActor->GetBounds();
1386 float aMin[3], aMax[3];
1387 ComputeWorldToDisplay(aBounds[0], aBounds[2], aBounds[4], aMin);
1388 ComputeWorldToDisplay(aBounds[1], aBounds[3], aBounds[5], aMax);
1389 if (aMin[0] > aMax[0]) {
1390 float aBuf = aMin[0];
1394 if (aMin[1] > aMax[1]) {
1395 float aBuf = aMin[1];
1400 return ((aMin[0]>left) && (aMax[0]<right) && (aMin[1]>bottom) && (aMax[1]<top));
1404 /// Checks: is the given Cell within display coordinates?
1405 bool VTKViewer_InteractorStyleSALOME::IsInRect(vtkCell* theCell,
1406 const int left, const int top,
1407 const int right, const int bottom)
1409 float* aBounds = theCell->GetBounds();
1410 float aMin[3], aMax[3];
1411 ComputeWorldToDisplay(aBounds[0], aBounds[2], aBounds[4], aMin);
1412 ComputeWorldToDisplay(aBounds[1], aBounds[3], aBounds[5], aMax);
1413 if (aMin[0] > aMax[0]) {
1414 float aBuf = aMin[0];
1418 if (aMin[1] > aMax[1]) {
1419 float aBuf = aMin[1];
1424 return ((aMin[0]>left) && (aMax[0]<right) && (aMin[1]>bottom) && (aMax[1]<top));
1428 bool VTKViewer_InteractorStyleSALOME::IsInRect(float* thePoint,
1429 const int left, const int top,
1430 const int right, const int bottom)
1433 ComputeWorldToDisplay(thePoint[0], thePoint[1], thePoint[2], aPnt);
1435 return ((aPnt[0]>left) && (aPnt[0]<right) && (aPnt[1]>bottom) && (aPnt[1]<top));
1438 void VTKViewer_InteractorStyleSALOME::SetFilter( const Handle(VTKViewer_Filter)& theFilter )
1440 myFilters[ theFilter->GetId() ] = theFilter;
1443 bool VTKViewer_InteractorStyleSALOME::IsFilterPresent( const int theId )
1445 return myFilters.find( theId ) != myFilters.end();
1448 void VTKViewer_InteractorStyleSALOME::RemoveFilter( const int theId )
1450 if ( IsFilterPresent( theId ) )
1451 myFilters.erase( theId );
1455 bool VTKViewer_InteractorStyleSALOME::IsValid( SALOME_Actor* theActor,
1457 const bool theIsNode )
1459 std::map<int, Handle(VTKViewer_Filter)>::const_iterator anIter;
1460 for ( anIter = myFilters.begin(); anIter != myFilters.end(); ++anIter )
1462 const Handle(VTKViewer_Filter)& aFilter = anIter->second;
1463 if ( theIsNode == aFilter->IsNodeFilter() &&
1464 !aFilter->IsValid( theActor, theId ) )
1470 Handle(VTKViewer_Filter) VTKViewer_InteractorStyleSALOME::GetFilter( const int theId )
1472 return IsFilterPresent( theId ) ? myFilters[ theId ] : Handle(VTKViewer_Filter)();