1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : OCCViewer_ViewWindow.cxx
26 #include "OCCViewer_ViewWindow.h"
27 #include "OCCViewer_ViewFrame.h"
28 #include "OCCViewer_ViewModel.h"
29 #include "OCCViewer_ViewPort3d.h"
30 #include "OCCViewer_ViewManager.h"
31 #include "OCCViewer_ViewSketcher.h"
32 #include "OCCViewer_CreateRestoreViewDlg.h"
33 #include "OCCViewer_ClipPlane.h"
34 #include "OCCViewer_SetRotationPointDlg.h"
35 #include "OCCViewer_AxialScaleDlg.h"
36 #include "OCCViewer_CubeAxesDlg.h"
37 #include "OCCViewer_ClippingDlg.h"
38 #include "OCCViewer_RayTracingDlg.h"
39 #include "OCCViewer_EnvTextureDlg.h"
40 #include "OCCViewer_LightSourceDlg.h"
41 #include "OCCViewer_Utilities.h"
43 #include <SUIT_Desktop.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_ViewManager.h>
46 #include <SUIT_Tools.h>
47 #include <SUIT_ResourceMgr.h>
48 #include <SUIT_MessageBox.h>
49 #include <SUIT_Application.h>
51 #include <QtxActionToolMgr.h>
52 #include <QtxMultiAction.h>
53 #include <QtxRubberBand.h>
59 #include <QMouseEvent>
60 #include <QApplication>
61 #include <QActionGroup>
64 #include <AIS_ListOfInteractive.hxx>
65 #include <AIS_ListIteratorOfListOfInteractive.hxx>
66 #include <AIS_Shape.hxx>
68 #include <BRep_Tool.hxx>
69 #include <BRepBndLib.hxx>
70 #include <BRepGProp.hxx>
71 #include <GProp_GProps.hxx>
74 #include <Graphic3d_SequenceOfHClipPlane.hxx>
75 #include <Graphic3d_ClipPlane.hxx>
76 #include <OpenGl_GraphicDriver.hxx>
77 #include <OpenGLUtils_FrameBuffer.h>
78 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
79 #include <Graphic3d_MapOfStructure.hxx>
80 #include <Graphic3d_Structure.hxx>
81 #include <Graphic3d_StereoMode.hxx>
82 #include <Graphic3d_RenderingParams.hxx>
83 #include <Graphic3d_BndBox3d.hxx>
85 #include <V3d_Plane.hxx>
86 #include <V3d_Light.hxx>
90 #include <gp_GTrsf.hxx>
91 #include <TColgp_Array1OfPnt2d.hxx>
93 #include <Image_PixMap.hxx>
95 #include <Standard_Version.hxx>
96 #include <Standard_Failure.hxx>
98 #include "utilities.h"
100 // // OpenCV includes
102 // #include <highgui.h>
104 static QEvent* l_mbPressEvent = 0;
107 //# include <QWindowsStyle>
111 #include <OpenGL/gl.h>
116 // To avoid conflict between KeyPress from the X.h (define KeyPress 2)
117 // and QEvent::KeyPress (qevent.h)
127 // Enable ray tracing features
128 #define ENABLE_RAY_TRACING
130 const char* imageZoomCursor[] = {
135 "................................",
136 "................................",
137 ".#######........................",
138 "..aaaaaaa.......................",
139 "................................",
140 ".............#####..............",
141 "...........##.aaaa##............",
142 "..........#.aa.....a#...........",
143 ".........#.a.........#..........",
144 ".........#a..........#a.........",
145 "........#.a...........#.........",
146 "........#a............#a........",
147 "........#a............#a........",
148 "........#a............#a........",
149 "........#a............#a........",
150 ".........#...........#.a........",
151 ".........#a..........#a.........",
152 ".........##.........#.a.........",
153 "........#####.....##.a..........",
154 ".......###aaa#####.aa...........",
155 "......###aa...aaaaa.......#.....",
156 ".....###aa................#a....",
157 "....###aa.................#a....",
158 "...###aa...............#######..",
159 "....#aa.................aa#aaaa.",
160 ".....a....................#a....",
161 "..........................#a....",
162 "...........................a....",
163 "................................",
164 "................................",
165 "................................",
166 "................................"};
168 const char* imageRotateCursor[] = {
173 "................................",
174 "................................",
175 "................................",
176 "................................",
177 "........#.......................",
178 ".......#.a......................",
179 "......#######...................",
180 ".......#aaaaa#####..............",
181 "........#..##.a#aa##........##..",
182 ".........a#.aa..#..a#.....##.aa.",
183 ".........#.a.....#...#..##.aa...",
184 ".........#a.......#..###.aa.....",
185 "........#.a.......#a..#aa.......",
186 "........#a.........#..#a........",
187 "........#a.........#a.#a........",
188 "........#a.........#a.#a........",
189 "........#a.........#a.#a........",
190 ".........#.........#a#.a........",
191 "........##a........#a#a.........",
192 "......##.a#.......#.#.a.........",
193 "....##.aa..##.....##.a..........",
194 "..##.aa.....a#####.aa...........",
195 "...aa.........aaa#a.............",
196 "................#.a.............",
197 "...............#.a..............",
198 "..............#.a...............",
199 "...............a................",
200 "................................",
201 "................................",
202 "................................",
203 "................................",
204 "................................"};
206 const char* imageCrossCursor[] = {
211 "................................",
212 "................................",
213 "................................",
214 "................................",
215 "................................",
216 "................................",
217 "................................",
218 "...............#................",
219 "...............#a...............",
220 "...............#a...............",
221 "...............#a...............",
222 "...............#a...............",
223 "...............#a...............",
224 "...............#a...............",
225 "...............#a...............",
226 ".......#################........",
227 "........aaaaaaa#aaaaaaaaa.......",
228 "...............#a...............",
229 "...............#a...............",
230 "...............#a...............",
231 "...............#a...............",
232 "...............#a...............",
233 "...............#a...............",
234 "...............#a...............",
235 "................a...............",
236 "................................",
237 "................................",
238 "................................",
239 "................................",
240 "................................",
241 "................................",
242 "................................"};
247 \param theDesktop main window of application
248 \param theModel OCC 3D viewer
250 OCCViewer_ViewWindow::OCCViewer_ViewWindow( SUIT_Desktop* theDesktop,
251 OCCViewer_Viewer* theModel )
252 : SUIT_ViewWindow( theDesktop )
256 myEnableDrawMode = false;
257 myDrawRectEnabled = true;
259 updateEnabledDrawMode();
261 mySetRotationPointDlg = 0;
264 IsSketcherStyle = false;
271 myInteractionStyle = SUIT_ViewModel::STANDARD;
272 myPreselectionEnabled = true;
273 mySelectionEnabled = true;
275 myCursorIsHand = false;
276 myPanningByBtn = false;
277 myAutomaticZoom = true;
285 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
288 qDeleteAll( mySketchers );
292 \brief Internal initialization.
294 void OCCViewer_ViewWindow::initLayout()
296 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
297 myViewPort->installEventFilter(this);
298 setCentralWidget(myViewPort);
299 myOperation = NOVIEWOP;
301 myCurrPointType = BBCENTER;
302 myPrevPointType = BBCENTER;
303 mySelectedPoint = gp_Pnt(0.,0.,0.);
304 myRotationPointSelection = false;
306 setTransformRequested ( NOVIEWOP );
307 setTransformInProcess ( false );
326 // Graduated axes dialog
327 QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
328 myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
329 myCubeAxesDlg->initialize();
331 connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
334 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
336 return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
340 \brief Detect viewer operation according the the mouse button pressed
341 and key modifiers used.
342 \param theEvent mouse event
343 \return type of the operation
345 OCCViewer_ViewWindow::OperationType
346 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
348 OperationType aOp = NOVIEWOP;
349 SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
350 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
351 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
353 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
354 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
356 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
357 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
358 (my2dMode == No2dMode))
365 \brief Customize event handling
366 \param watched event receiver object
368 \return \c true if the event processing should be stopped
370 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
372 if ( watched == myViewPort ) {
373 int aType = e->type();
375 case QEvent::MouseButtonPress:
376 vpMousePressEvent((QMouseEvent*) e);
379 case QEvent::MouseButtonRelease:
380 vpMouseReleaseEvent((QMouseEvent*) e);
383 case QEvent::MouseMove:
384 vpMouseMoveEvent((QMouseEvent*) e);
387 case QEvent::MouseButtonDblClick:
388 emit mouseDoubleClicked(this, (QMouseEvent*)e);
393 QWheelEvent* aEvent = (QWheelEvent*) e;
395 if ( aEvent->modifiers().testFlag(Qt::ControlModifier) ) {
396 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
397 if ( isPreselectionEnabled() ) {
398 if ( aEvent->delta() > 0 ) {
399 ic->HilightNextDetected( myViewPort->getView() );
401 ic->HilightPreviousDetected( myViewPort->getView() );
406 emit vpTransformationStarted ( ZOOMVIEW );
407 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
408 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
411 int x1 = (int)( aEvent->x() + width()*delta/100 );
412 int y1 = (int)( aEvent->y() + height()*delta/100 );
413 myViewPort->zoom( x, y, x1, y1 );
414 emit vpTransformationFinished ( ZOOMVIEW );
419 case QEvent::ContextMenu:
421 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
422 if ( aEvent->reason() != QContextMenuEvent::Mouse )
423 emit contextMenuRequested( aEvent );
427 case QEvent::KeyPress:
428 emit keyPressed(this, (QKeyEvent*) e);
431 case QEvent::KeyRelease:
432 emit keyReleased(this, (QKeyEvent*) e);
439 return SUIT_ViewWindow::eventFilter(watched, e);
443 \brief Enable / disable draw rect (rubber band) mode
445 bool OCCViewer_ViewWindow::enableDrawMode( bool on )
447 bool prev = myDrawRectEnabled;
448 myDrawRectEnabled = on;
449 updateEnabledDrawMode();
454 \brief Update state of enable draw mode state.
456 void OCCViewer_ViewWindow::updateEnabledDrawMode()
458 myEnableDrawMode = myDrawRectEnabled;
460 myEnableDrawMode = myEnableDrawMode && myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
464 \brief Handle mouse press event
465 \param theEvent mouse event
467 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
469 myStartX = theEvent->x();
470 myStartY = theEvent->y();
471 int anInteractionStyle = interactionStyle();
473 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
474 // which are assigned for pan and rotate - these operations are activated immediately after pressing
475 // of the first button, so it is necessary to switch to zoom when the second button is pressed
476 bool aSwitchToZoom = false;
477 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
478 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
479 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
482 switch ( myOperation ) {
484 if ( theEvent->button() == Qt::LeftButton )
485 emit vpTransformationStarted ( WINDOWFIT );
489 if ( theEvent->button() == Qt::LeftButton )
490 emit vpTransformationStarted ( PANGLOBAL );
494 if ( theEvent->button() == Qt::LeftButton ) {
495 myViewPort->startZoomAtPoint( myStartX, myStartY );
496 emit vpTransformationStarted ( ZOOMVIEW );
501 if ( aSwitchToZoom ) {
502 myViewPort->startZoomAtPoint( myStartX, myStartY );
505 else if ( theEvent->button() == Qt::LeftButton )
506 emit vpTransformationStarted ( PANVIEW );
510 if ( aSwitchToZoom ) {
511 myViewPort->startZoomAtPoint( myStartX, myStartY );
514 else if ( theEvent->button() == Qt::LeftButton ) {
515 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
516 emit vpTransformationStarted ( ROTATE );
521 /* Try to activate a transformation */
522 OperationType aState;
523 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
524 aState = getButtonState(theEvent, anInteractionStyle);
526 aState = OCCViewer_ViewWindow::NOVIEWOP;
531 myViewPort->startZoomAtPoint( myStartX, myStartY );
539 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
542 if ( myRotationPointSelection )
544 if ( theEvent->button() == Qt::LeftButton )
546 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
547 ic->Select( Standard_True );
548 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
550 TopoDS_Shape aShape = ic->SelectedShape();
551 GProp_GProps aSystem;
553 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
555 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
557 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE )
559 BRepGProp::LinearProperties( aShape, aSystem );
560 aPnt = aSystem.CentreOfMass();
562 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE )
564 BRepGProp::SurfaceProperties( aShape, aSystem );
565 aPnt = aSystem.CentreOfMass();
567 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID )
569 BRepGProp::VolumeProperties( aShape, aSystem );
570 aPnt = aSystem.CentreOfMass();
574 myCurrPointType = myPrevPointType;
578 if ( mySetRotationPointDlg )
580 myRotationPointSelection = false;
581 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
584 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
585 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
588 myOperation = NOVIEWOP;
589 myViewPort->setCursor( myCursor );
590 myCursorIsHand = false;
591 myRotationPointSelection = false;
595 emit mousePressed(this, theEvent);
598 /* notify that we start a transformation */
599 if ( transformRequested() )
600 emit vpTransformationStarted ( myOperation );
602 if ( transformRequested() )
603 setTransformInProcess( true );
605 /* we may need it for sketching... */
606 if ( l_mbPressEvent )
607 delete l_mbPressEvent;
608 l_mbPressEvent = new QMouseEvent( *theEvent );
613 \brief Start zooming operation.
615 Sets the corresponding cursor for the widget.
617 void OCCViewer_ViewWindow::activateZoom()
619 if ( !transformRequested() && !myCursorIsHand )
620 saveCursor(); /* save old cursor */
622 if ( myOperation != ZOOMVIEW ) {
623 QPixmap zoomPixmap (imageZoomCursor);
624 QCursor zoomCursor (zoomPixmap);
625 if( setTransformRequested ( ZOOMVIEW ) )
626 myViewPort->setCursor( zoomCursor );
631 void OCCViewer_ViewWindow::onPanning()
633 OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( getViewManager() );
634 bool isChained = aMgr->isChainedOperations();
635 bool isReset = ( myPanningByBtn && isChained );
642 myPanningByBtn = true;
648 \brief Start panning operation.
650 Sets the corresponding cursor for the widget.
652 void OCCViewer_ViewWindow::activatePanning()
654 if ( !transformRequested() && !myCursorIsHand )
655 saveCursor(); // save old cursor
657 if ( myOperation != PANVIEW ) {
658 QCursor panCursor (Qt::SizeAllCursor);
659 if( setTransformRequested ( PANVIEW ) )
660 myViewPort->setCursor( panCursor );
665 \brief Start rotation operation
667 Sets the corresponding cursor for the widget.
669 void OCCViewer_ViewWindow::activateRotation()
671 if ( !transformRequested() && !myCursorIsHand )
672 saveCursor(); // save old cursor
674 if ( myOperation != ROTATE ) {
675 QPixmap rotatePixmap (imageRotateCursor);
676 QCursor rotCursor (rotatePixmap);
677 if( setTransformRequested ( ROTATE ) )
678 myViewPort->setCursor( rotCursor );
683 \brief Compute the gravity center.
684 \param theX used to return X coordinate of the gravity center
685 \param theY used to return Y coordinate of the gravity center
686 \param theZ used to return Z coordinate of the gravity center
687 \return \c true if the gravity center is computed
689 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
691 Handle(V3d_View) aView3d = myViewPort->getView();
693 // Project boundaries points and add to avergae gravity
694 // the ones which lie within the screen limits
695 Standard_Real aScreenLimits[4] = { 0.0, 0.0, 0.0, 0.0 };
697 // NDC space screen limits
698 aScreenLimits[0] = -1.0;
699 aScreenLimits[1] = 1.0;
700 aScreenLimits[2] = -1.0;
701 aScreenLimits[3] = 1.0;
703 Standard_Integer aPointsNb = 0;
705 Standard_Real aXmin = 0.0;
706 Standard_Real aYmin = 0.0;
707 Standard_Real aZmin = 0.0;
708 Standard_Real aXmax = 0.0;
709 Standard_Real aYmax = 0.0;
710 Standard_Real aZmax = 0.0;
712 Graphic3d_MapOfStructure aSetOfStructures;
713 aView3d->View()->DisplayedStructures( aSetOfStructures );
714 Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures );
716 for( ; aStructureIt.More(); aStructureIt.Next() ) {
717 const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key();
718 if ( aStructure->IsEmpty() || !aStructure->IsVisible() || aStructure->CStructure()->IsForHighlight )
721 const Graphic3d_BndBox3d& aBox = aStructure->CStructure()->BoundingBox();
724 aXmin = /*aBox.IsVoid() ? RealFirst() : */aBox.CornerMin().x();
725 aYmin = /*aBox.IsVoid() ? RealFirst() : */aBox.CornerMin().y();
726 aZmin = /*aBox.IsVoid() ? RealFirst() : */aBox.CornerMin().z();
727 aXmax = /*aBox.IsVoid() ? RealLast() : */aBox.CornerMax().x();
728 aYmax = /*aBox.IsVoid() ? RealLast() : */aBox.CornerMax().y();
729 aZmax = /*aBox.IsVoid() ? RealLast() : */aBox.CornerMax().z();
731 // Infinite structures are skipped
732 Standard_Real aLIM = ShortRealLast() - 1.0;
733 if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
734 || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
738 gp_Pnt aPoints[8] = {
739 gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
740 gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
741 gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
742 gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
745 for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
746 const gp_Pnt& aBBPoint = aPoints[aPointIt];
748 gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
749 const Standard_Real& U = aProjected.X();
750 const Standard_Real& V = aProjected.Y();
752 if (U >= aScreenLimits[0]
753 && U <= aScreenLimits[1]
754 && V >= aScreenLimits[2]
755 && V <= aScreenLimits[3])
758 theX += aBBPoint.X();
759 theY += aBBPoint.Y();
760 theZ += aBBPoint.Z();
777 \brief Set the gravity center as a rotation point.
779 void OCCViewer_ViewWindow::activateSetRotationGravity()
781 if ( myRotationPointSelection )
783 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
786 myOperation = NOVIEWOP;
787 myViewPort->setCursor( myCursor );
788 myCursorIsHand = false;
789 myRotationPointSelection = false;
792 myPrevPointType = myCurrPointType;
793 myCurrPointType = BBCENTER;
795 Standard_Real Xcenter, Ycenter, Zcenter;
796 if ( OCCViewer_Utilities::computeVisibleBBCenter( myViewPort->getView(), Xcenter, Ycenter, Zcenter ) )
797 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
801 \brief Update gravity center in the "Set Rotation Point" dialog box.
802 \sa OCCViewer_SetRotationPointDlg class
804 void OCCViewer_ViewWindow::updateGravityCoords()
806 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == BBCENTER )
808 Standard_Real Xcenter, Ycenter, Zcenter;
809 if ( OCCViewer_Utilities::computeVisibleBBCenter( myViewPort->getView(), Xcenter, Ycenter, Zcenter ) )
810 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
815 \brief Set the point selected by the user as a rotation point.
816 \param theX X coordinate of the rotation point
817 \param theY Y coordinate of the rotation point
818 \param theZ Z coordinate of the rotation point
820 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
822 if ( myRotationPointSelection )
824 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
827 myOperation = NOVIEWOP;
828 myViewPort->setCursor( myCursor );
829 myCursorIsHand = false;
830 myRotationPointSelection = false;
833 myPrevPointType = myCurrPointType;
834 myCurrPointType = SELECTED;
835 mySelectedPoint.SetCoord(theX,theY,theZ);
839 \brief Start the shape selection process.
841 void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
843 myPrevPointType = myCurrPointType;
844 myCurrPointType = SELECTED;
846 // activate selection ------>
847 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
850 AIS_ListOfInteractive aList;
851 ic->DisplayedObjects( aList );
852 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
854 Handle(AIS_InteractiveObject) anObj = it.Value();
855 if ( !anObj.IsNull() && anObj->HasPresentation() &&
856 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
859 ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
862 // activate selection <------
864 if ( !myCursorIsHand )
866 QCursor handCursor (Qt::PointingHandCursor);
867 myCursorIsHand = true;
869 myViewPort->setCursor( handCursor );
871 myRotationPointSelection = true;
875 \brief Start global panning operation
877 Sets the corresponding cursor for the widget.
879 void OCCViewer_ViewWindow::activateGlobalPanning()
881 Handle(V3d_View) aView3d = myViewPort->getView();
882 if ( !aView3d.IsNull() ) {
883 QPixmap globalPanPixmap (imageCrossCursor);
884 QCursor glPanCursor (globalPanPixmap);
885 myCurScale = aView3d->Scale();
886 aView3d->FitAll(0.01, false);
887 saveCursor(); // save old cursor
888 myViewPort->fitAll(); // fits view before selecting a new scene center
889 if( setTransformRequested( PANGLOBAL ) )
890 myViewPort->setCursor( glPanCursor );
895 \brief Starts fit operation.
897 Sets the corresponding cursor for the widget.
899 void OCCViewer_ViewWindow::activateWindowFit()
901 if ( !transformRequested() && !myCursorIsHand )
902 saveCursor(); /* save old cursor */
904 if ( myOperation != WINDOWFIT ) {
905 QCursor handCursor (Qt::PointingHandCursor);
906 if( setTransformRequested ( WINDOWFIT ) )
908 myViewPort->setCursor ( handCursor );
909 myCursorIsHand = true;
915 \brief Start delayed viewer operation.
917 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
919 bool ok = transformEnabled( op );
920 myOperation = ok ? op : NOVIEWOP;
921 myViewPort->setMouseTracking( myOperation == NOVIEWOP );
926 \brief Handle mouse move event.
927 \param theEvent mouse event
929 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
931 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
933 switch ( getButtonState( theEvent, interactionStyle() ) ) {
935 myViewPort->startZoomAtPoint( myStartX, myStartY );
943 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
950 myCurrX = theEvent->x();
951 myCurrY = theEvent->y();
952 switch (myOperation) {
954 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
958 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
964 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
978 if ( myRotationPointSelection || isSketcherStyle() )
980 emit mouseMoving( this, theEvent );
984 int aState = theEvent->modifiers();
985 int aButton = theEvent->buttons();
986 int anInteractionStyle = interactionStyle();
987 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
988 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || aState == Qt::ShiftModifier ) ) ||
989 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
990 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
991 myDrawRect = myEnableDrawMode;
994 //if ( !myCursorIsHand ) { // we are going to sketch a rectangle
995 // QCursor handCursor (Qt::PointingHandCursor);
996 // myCursorIsHand = true;
998 // myViewPort->setCursor( handCursor );
1001 SelectionStyle aStyle = selectionStyle();
1002 activateSketching(aStyle == RectStyle ? Rect : Polygon);
1005 if (l_mbPressEvent) {
1006 QApplication::sendEvent(getViewPort(), l_mbPressEvent);
1007 delete l_mbPressEvent;
1010 QApplication::sendEvent(getViewPort(), theEvent);
1013 emit mouseMoving( this, theEvent );
1015 //else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
1016 // aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
1017 // ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
1018 // aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
1019 // OCCViewer_ViewSketcher* sketcher = 0;
1020 // QList<OCCViewer_ViewSketcher*>::Iterator it;
1021 // for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
1023 // OCCViewer_ViewSketcher* sk = (*it);
1024 // if( sk->isDefault() && sk->sketchButton() == aButton )
1027 // if ( sketcher && myCurSketch == -1 )
1029 // activateSketching( sketcher->type() );
1030 // if ( mypSketcher )
1032 // myCurSketch = mypSketcher->sketchButton();
1034 // if ( l_mbPressEvent )
1036 // QApplication::sendEvent( getViewPort(), l_mbPressEvent );
1037 // delete l_mbPressEvent;
1038 // l_mbPressEvent = 0;
1040 // QApplication::sendEvent( getViewPort(), theEvent );
1045 emit mouseMoving( this, theEvent );
1051 \brief Handle mouse release event.
1052 \param theEvent mouse event
1054 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
1056 switch ( myOperation ) {
1059 int prevState = myCurSketch;
1060 if(theEvent->button() == Qt::RightButton)
1062 QList<OCCViewer_ViewSketcher*>::Iterator it;
1063 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
1065 OCCViewer_ViewSketcher* sk = (*it);
1066 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
1071 emit mouseReleased(this, theEvent);
1072 if(theEvent->button() == Qt::RightButton && prevState == -1)
1074 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1075 theEvent->pos(), theEvent->globalPos() );
1076 emit contextMenuRequested( &aEvent );
1081 myViewPort->endRotation();
1088 OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( getViewManager() );
1089 bool isChained = aMgr->isChainedOperations();
1090 bool isReset = !( myOperation==PANVIEW && myPanningByBtn && isChained ) || theEvent->button() == Qt::RightButton;
1097 if ( theEvent->button() == Qt::LeftButton ) {
1098 myViewPort->setCenter( theEvent->x(), theEvent->y() );
1099 myViewPort->getView()->SetScale(myCurScale);
1105 if ( theEvent->button() == Qt::LeftButton ) {
1106 myCurrX = theEvent->x();
1107 myCurrY = theEvent->y();
1109 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1110 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1119 // NOTE: viewer 3D detects a rectangle of selection using this event
1120 // so we must emit it BEFORE resetting the selection rectangle
1122 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1126 myViewPort->update();
1129 if ( l_mbPressEvent ) {
1130 delete l_mbPressEvent;
1136 \brief Reset the viewport to its initial state
1137 ( no transformations in process etc. )
1139 void OCCViewer_ViewWindow::resetState()
1143 if ( myRotationPointSelection )
1145 QCursor handCursor (Qt::PointingHandCursor);
1146 myViewPort->setCursor( handCursor );
1150 if ( transformRequested() || myCursorIsHand )
1151 myViewPort->setCursor( myCursor );
1152 myCursorIsHand = false;
1155 if ( transformRequested() )
1156 emit vpTransformationFinished (myOperation);
1158 setTransformInProcess( false );
1159 setTransformRequested( NOVIEWOP );
1161 myPanningByBtn = false;
1166 \brief Draw rubber band rectangle.
1168 void OCCViewer_ViewWindow::drawRect()
1170 if ( !myRectBand ) {
1171 myRectBand = new QtxRectRubberBand( myViewPort );
1174 myRectBand->setUpdatesEnabled ( false );
1175 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1176 myRectBand->initGeometry( aRect );
1178 if ( !myRectBand->isVisible() )
1181 myRectBand->setUpdatesEnabled ( true );
1185 \brief Clear rubber band rectangle on the end on the dragging operation.
1187 void OCCViewer_ViewWindow::endDrawRect()
1190 myRectBand->clearGeometry();
1196 \brief Create actions.
1198 void OCCViewer_ViewWindow::createActions()
1200 if( !toolMgr()->isEmpty() )
1203 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1210 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1211 tr( "MNU_DUMP_VIEW" ), 0, this);
1212 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1213 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1214 toolMgr()->registerAction( aAction, DumpId );
1217 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1218 tr( "MNU_FITALL" ), 0, this);
1219 aAction->setStatusTip(tr("DSC_FITALL"));
1220 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1221 toolMgr()->registerAction( aAction, FitAllId );
1224 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1225 tr( "MNU_FITRECT" ), 0, this);
1226 aAction->setStatusTip(tr("DSC_FITRECT"));
1227 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1228 toolMgr()->registerAction( aAction, FitRectId );
1231 aAction = new QtxAction(tr("MNU_FITSELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITSELECTION" ) ),
1232 tr( "MNU_FITSELECTION" ), 0, this);
1233 aAction->setStatusTip(tr("DSC_FITSELECTION"));
1234 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
1235 toolMgr()->registerAction( aAction, FitSelectionId );
1238 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1239 tr( "MNU_ZOOM_VIEW" ), 0, this);
1240 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1241 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1242 toolMgr()->registerAction( aAction, ZoomId );
1245 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1246 tr( "MNU_PAN_VIEW" ), 0, this);
1247 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1248 connect(aAction, SIGNAL(triggered()), this, SLOT(onPanning()));
1249 toolMgr()->registerAction( aAction, PanId );
1252 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1253 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1254 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1255 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1256 toolMgr()->registerAction( aAction, GlobalPanId );
1259 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1260 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1261 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1262 mySetRotationPointAction->setCheckable( true );
1263 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1264 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1267 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1268 tr( "MNU_ROTATE_VIEW" ), 0, this);
1269 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1270 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1271 toolMgr()->registerAction( aAction, RotationId );
1274 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1275 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1276 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1277 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1278 this->addAction(aAction);
1279 toolMgr()->registerAction( aAction, FrontId );
1281 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1282 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1283 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1284 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1285 this->addAction(aAction);
1286 toolMgr()->registerAction( aAction, BackId );
1288 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1289 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1290 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1291 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1292 this->addAction(aAction);
1293 toolMgr()->registerAction( aAction, TopId );
1295 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1296 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1297 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1298 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1299 this->addAction(aAction);
1300 toolMgr()->registerAction( aAction, BottomId );
1302 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1303 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1304 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1305 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1306 this->addAction(aAction);
1307 toolMgr()->registerAction( aAction, LeftId );
1309 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1310 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1311 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1312 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1313 this->addAction(aAction);
1314 toolMgr()->registerAction( aAction, RightId );
1316 // rotate anticlockwise
1317 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1318 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1319 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1320 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1321 this->addAction(aAction);
1322 toolMgr()->registerAction( aAction, AntiClockWiseId );
1325 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1326 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1327 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1328 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1329 this->addAction(aAction);
1330 toolMgr()->registerAction( aAction, ClockWiseId );
1332 // Projection mode group
1334 // - orthographic projection
1335 aAction = new QtxAction(tr("MNU_ORTHOGRAPHIC_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ORTHOGRAPHIC" ) ),
1336 tr( "MNU_ORTHOGRAPHIC_MODE" ), 0, this);
1337 aAction->setStatusTip(tr("DSC_ORTHOGRAPHIC_MODE"));
1338 aAction->setCheckable(true);
1339 toolMgr()->registerAction( aAction, OrthographicId );
1341 // - perspective projection
1342 aAction = new QtxAction(tr("MNU_PERSPECTIVE_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PERSPECTIVE" ) ),
1343 tr( "MNU_PERSPECTIVE_MODE" ), 0, this);
1344 aAction->setStatusTip(tr("DSC_PERSPECTIVE_MODE"));
1345 aAction->setCheckable(true);
1346 toolMgr()->registerAction( aAction, PerspectiveId );
1348 // - stereo projection
1349 aAction = new QtxAction(tr("MNU_STEREO_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STEREO" ) ),
1350 tr( "MNU_STEREO_MODE" ), 0, this);
1351 aAction->setStatusTip(tr("DSC_STEREO_MODE"));
1352 aAction->setCheckable(true);
1353 toolMgr()->registerAction( aAction, StereoId );
1354 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onStereoType(bool)));
1356 // - add exclusive action group
1357 QActionGroup* aProjectionGroup = new QActionGroup( this );
1358 aProjectionGroup->addAction( toolMgr()->action( OrthographicId ) );
1359 aProjectionGroup->addAction( toolMgr()->action( PerspectiveId ) );
1360 connect(aProjectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProjectionType(QAction*)));
1363 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1364 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1365 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1366 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1367 this->addAction(aAction);
1368 toolMgr()->registerAction( aAction, ResetId );
1371 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1372 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1373 tr("MNU_CLONE_VIEW"), 0, this);
1374 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1375 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1376 toolMgr()->registerAction( aAction, CloneId );
1378 aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
1379 tr("MNU_CLIPPING"), 0, this);
1380 aAction->setStatusTip (tr("DSC_CLIPPING"));
1381 aAction->setCheckable (true);
1382 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1383 toolMgr()->registerAction (aAction, ClippingId);
1385 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1386 tr( "MNU_SHOOT_VIEW" ), 0, this);
1387 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1388 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1389 toolMgr()->registerAction( aAction, MemId );
1391 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1392 tr( "MNU_PRESETS_VIEW" ), 0, this);
1393 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1394 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1395 toolMgr()->registerAction( aAction, RestoreId );
1397 if (myModel->trihedronActivated()) {
1398 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1399 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1400 aAction->setCheckable( true );
1401 aAction->setChecked( true );
1402 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1403 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1404 toolMgr()->registerAction( aAction, TrihedronShowId );
1408 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1409 tr( "MNU_SCALING" ), 0, this);
1410 aAction->setStatusTip(tr("DSC_SCALING"));
1411 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1412 toolMgr()->registerAction( aAction, AxialScaleId );
1414 // Enable/disable preselection
1415 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1416 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1417 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1418 aAction->setCheckable(true);
1419 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1420 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1422 // Enable/disable selection
1423 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1424 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1425 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1426 aAction->setCheckable(true);
1427 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1428 toolMgr()->registerAction( aAction, SwitchSelectionId );
1431 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1432 tr( "MNU_GRADUATED_AXES" ), 0, this);
1433 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1434 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1435 toolMgr()->registerAction( aAction, GraduatedAxesId );
1437 // Active only ambient light or not
1438 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1439 tr( "MNU_AMBIENT" ), 0, this);
1440 aAction->setStatusTip(tr("DSC_AMBIENT"));
1441 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1442 toolMgr()->registerAction( aAction, AmbientId );
1444 // Switch between interaction styles
1445 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1446 tr( "MNU_STYLE_SWITCH" ), 0, this);
1447 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1448 aAction->setCheckable(true);
1449 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1450 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1452 // Switch between zooming styles
1453 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1454 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1455 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1456 aAction->setCheckable(true);
1457 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1458 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1460 // Switch advanced selection style (poligone/circle)
1461 aAction = new QtxAction(tr("MNU_RECTANGLE_SELECTION_STYLE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RECT_STYLE" ) ),
1462 tr( "MNU_RECTANGLE_SELECTION_STYLE" ), 0, this);
1463 aAction->setStatusTip(tr("DSC_RECTANGLE_SELECTION_STYLE"));
1464 aAction->setCheckable(true);
1465 toolMgr()->registerAction( aAction, RectangleSelectionStyleId);
1467 aAction = new QtxAction(tr("MNU_POLYGON_SELECTION_STYLE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_POLY_STYLE" ) ),
1468 tr( "MNU_POLYGON_SELECTION_STYLE" ), 0, this);
1469 aAction->setStatusTip(tr("DSC_POLYGON_SELECTION_STYLE"));
1470 aAction->setCheckable(true);
1471 toolMgr()->registerAction( aAction, PolygonSelectionStyleId);
1473 aAction = new QtxAction(tr("MNU_CIRCLE_SELECTION_STYLE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CIRCLE_STYLE" ) ),
1474 tr( "MNU_CIRCLE_SELECTION_STYLE" ), 0, this);
1475 aAction->setStatusTip(tr("DSC_CIRCLE_SELECTION_STYLE"));
1476 aAction->setCheckable(true);
1477 toolMgr()->registerAction( aAction, CircleSelectionStyleId);
1479 // - add exclusive action group
1480 QActionGroup* aSelectionGroup = new QActionGroup(this);
1481 aSelectionGroup->addAction(toolMgr()->action(RectangleSelectionStyleId));
1482 aSelectionGroup->addAction(toolMgr()->action(PolygonSelectionStyleId));
1483 aSelectionGroup->addAction(toolMgr()->action(CircleSelectionStyleId));
1484 connect(aSelectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onSwitchSelectionStyle(QAction*)));
1487 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1488 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1489 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1490 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1491 toolMgr()->registerAction( aAction, MaximizedId );
1493 // Return to 3d view
1494 if (my2dMode!=No2dMode){
1495 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1496 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1497 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1498 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1499 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1503 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1504 #ifdef ENABLE_RAY_TRACING
1506 aAction = new QtxAction( tr("MNU_RAY_TRACING"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_RAY_TRACING") ),
1507 tr("MNU_RAY_TRACING"), 0, this );
1508 aAction->setStatusTip( tr("DSC_RAY_TRACING") );
1509 connect( aAction, SIGNAL( triggered() ), this, SLOT( onRayTracing() ) );
1510 toolMgr()->registerAction( aAction, RayTracingId );
1512 // Environment texture
1513 aAction = new QtxAction( tr("MNU_ENV_TEXTURE"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_ENV_TEXTURE") ),
1514 tr("MNU_ENV_TEXTURE"), 0, this );
1515 aAction->setStatusTip( tr("DSC_ENV_TEXTURE") );
1516 connect( aAction, SIGNAL( triggered() ), this, SLOT( onEnvTexture() ) );
1517 toolMgr()->registerAction( aAction, EnvTextureId );
1520 aAction = new QtxAction( tr("MNU_LIGHT_SOURCE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_LIGHT_SOURCE" ) ),
1521 tr( "MNU_LIGHT_SOURCE" ), 0, this );
1522 aAction->setStatusTip( tr("DSC_LIGHT_SOURCE") );
1523 connect( aAction, SIGNAL( triggered() ), this, SLOT( onLightSource() ) );
1524 toolMgr()->registerAction( aAction, LightSourceId );
1529 \brief Create toolbar.
1531 void OCCViewer_ViewWindow::createToolBar()
1533 static const char* titles[] = {
1534 "LBL_3DTOOLBAR_LABEL",
1535 "LBL_XYTOOLBAR_LABEL",
1536 "LBL_XZTOOLBAR_LABEL",
1537 "LBL_YZTOOLBAR_LABEL",
1539 static const char* names[] = {
1540 "OCCViewer3DViewOperations",
1541 "OCCViewerXYViewOperations",
1542 "OCCViewerXZViewOperations",
1543 "OCCViewerYZViewOperations",
1545 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1546 QString( names[my2dMode] ), // name (language-independant)
1547 false ); // disable floatable toolbar
1548 if ( my2dMode != No2dMode ){
1549 toolMgr()->append( ReturnTo3dViewId, tid );
1550 toolMgr()->append( toolMgr()->separator(), tid );
1552 toolMgr()->append( DumpId, tid );
1553 toolMgr()->append( SwitchInteractionStyleId, tid );
1554 toolMgr()->append( SwitchZoomingStyleId, tid );
1555 toolMgr()->append( SwitchPreselectionId, tid );
1556 toolMgr()->append( SwitchSelectionId, tid );
1558 QtxMultiAction* aSelectionAction = new QtxMultiAction(this);
1559 aSelectionAction->insertAction(toolMgr()->action(RectangleSelectionStyleId));
1560 aSelectionAction->insertAction(toolMgr()->action(PolygonSelectionStyleId));
1561 aSelectionAction->insertAction(toolMgr()->action(CircleSelectionStyleId));
1562 toolMgr()->append(aSelectionAction, tid );
1564 if( myModel->trihedronActivated() )
1565 toolMgr()->append( TrihedronShowId, tid );
1567 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1568 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1569 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1570 aScaleAction->insertAction( toolMgr()->action( FitSelectionId ) );
1571 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1572 toolMgr()->append( aScaleAction, tid );
1574 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1575 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1576 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1577 toolMgr()->append( aPanningAction, tid );
1579 if (my2dMode == No2dMode) {
1580 toolMgr()->append( ChangeRotationPointId, tid );
1581 toolMgr()->append( RotationId, tid );
1583 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1584 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1585 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1586 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1587 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1588 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1589 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1590 toolMgr()->append( aViewsAction, tid );
1592 toolMgr()->append( AntiClockWiseId, tid );
1593 toolMgr()->append( ClockWiseId, tid );
1595 toolMgr()->append( OrthographicId, tid );
1596 toolMgr()->append( PerspectiveId, tid );
1597 toolMgr()->append( StereoId, tid );
1599 toolMgr()->append( ResetId, tid );
1602 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1603 aMemAction->insertAction( toolMgr()->action( MemId ) );
1604 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1605 toolMgr()->append( aMemAction, tid );
1607 toolMgr()->append( toolMgr()->separator(), tid );
1608 toolMgr()->append( CloneId, tid );
1610 toolMgr()->append( toolMgr()->separator(), tid );
1611 toolMgr()->append( ClippingId, tid );
1612 toolMgr()->append( AxialScaleId, tid );
1613 toolMgr()->append( GraduatedAxesId, tid );
1614 toolMgr()->append( AmbientId, tid );
1616 toolMgr()->append( MaximizedId, tid );
1617 toolMgr()->append( SynchronizeId, tid );
1618 #ifdef ENABLE_RAY_TRACING
1619 toolMgr()->append( RayTracingId, tid );
1620 toolMgr()->append( EnvTextureId, tid );
1621 toolMgr()->append( LightSourceId, tid );
1626 \brief Perform 'fit all' operation.
1628 void OCCViewer_ViewWindow::onViewFitAll()
1630 myViewPort->fitAll();
1634 \brief Perform "front view" transformation.
1636 void OCCViewer_ViewWindow::onFrontView()
1638 emit vpTransformationStarted ( FRONTVIEW );
1639 Handle(V3d_View) aView3d = myViewPort->getView();
1640 if (myAutomaticZoom)
1642 if ( !aView3d.IsNull() )
1643 aView3d->SetProj (V3d_Xpos);
1647 projAndPanToGravity(V3d_Xpos);
1648 emit vpTransformationFinished ( FRONTVIEW );
1652 \brief Perform "back view" transformation.
1654 void OCCViewer_ViewWindow::onBackView()
1656 emit vpTransformationStarted ( BACKVIEW );
1657 Handle(V3d_View) aView3d = myViewPort->getView();
1658 if (myAutomaticZoom)
1660 if ( !aView3d.IsNull() )
1661 aView3d->SetProj (V3d_Xneg);
1665 projAndPanToGravity(V3d_Xneg);
1666 emit vpTransformationFinished ( BACKVIEW );
1670 \brief Perform "top view" transformation.
1672 void OCCViewer_ViewWindow::onTopView()
1674 emit vpTransformationStarted ( TOPVIEW );
1675 Handle(V3d_View) aView3d = myViewPort->getView();
1676 if (myAutomaticZoom)
1678 if ( !aView3d.IsNull() )
1679 aView3d->SetProj (V3d_Zpos);
1683 projAndPanToGravity(V3d_Zpos);
1684 emit vpTransformationFinished ( TOPVIEW );
1688 \brief Perform "bottom view" transformation.
1690 void OCCViewer_ViewWindow::onBottomView()
1692 emit vpTransformationStarted ( BOTTOMVIEW );
1693 Handle(V3d_View) aView3d = myViewPort->getView();
1694 if (myAutomaticZoom)
1696 if ( !aView3d.IsNull() )
1697 aView3d->SetProj (V3d_Zneg);
1701 projAndPanToGravity(V3d_Zneg);
1702 emit vpTransformationFinished ( BOTTOMVIEW );
1706 \brief Perform "left view" transformation.
1708 void OCCViewer_ViewWindow::onLeftView()
1710 emit vpTransformationStarted ( LEFTVIEW );
1711 Handle(V3d_View) aView3d = myViewPort->getView();
1712 if (myAutomaticZoom)
1714 if ( !aView3d.IsNull() )
1715 aView3d->SetProj (V3d_Yneg);
1719 projAndPanToGravity(V3d_Yneg);
1720 emit vpTransformationFinished ( LEFTVIEW );
1724 \brief Perform "right view" transformation.
1726 void OCCViewer_ViewWindow::onRightView()
1728 emit vpTransformationStarted ( RIGHTVIEW );
1729 Handle(V3d_View) aView3d = myViewPort->getView();
1730 if (myAutomaticZoom)
1732 if ( !aView3d.IsNull() )
1733 aView3d->SetProj (V3d_Ypos);
1737 projAndPanToGravity(V3d_Ypos);
1738 emit vpTransformationFinished ( RIGHTVIEW );
1742 \brief Rotate view 90 degrees clockwise
1744 void OCCViewer_ViewWindow::onClockWiseView()
1746 emit vpTransformationStarted ( CLOCKWISEVIEW );
1747 myViewPort->rotateXY( 90. );
1748 emit vpTransformationFinished ( CLOCKWISEVIEW );
1752 \brief Rotate view 90 degrees conterclockwise
1754 void OCCViewer_ViewWindow::onAntiClockWiseView()
1756 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1757 myViewPort->rotateXY( -90. );
1758 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1762 \brief Perform "reset view" transformation.
1764 Sets default orientation of the viewport camera.
1766 void OCCViewer_ViewWindow::onResetView()
1768 emit vpTransformationStarted( RESETVIEW );
1769 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1770 myViewPort->getView()->Reset( false );
1771 myViewPort->fitAll( false, true, false );
1772 myViewPort->getView()->SetImmediateUpdate( upd );
1773 onProjectionType(); // needed to apply projection type properly after reset
1774 myViewPort->getView()->Update();
1775 emit vpTransformationFinished( RESETVIEW );
1779 \brief Set the given projection mode.
1781 Set the given projection mode: Orthographic or Perspective.
1783 void OCCViewer_ViewWindow::onProjectionType( QAction* theAction )
1785 Handle(V3d_View) aView3d = myViewPort->getView();
1786 if ( !aView3d.IsNull() ) {
1787 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1788 if (theAction == toolMgr()->action( OrthographicId )) {
1789 myModel->setProjectionType(Orthographic);
1790 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Orthographic );
1791 aCamera->SetFOVy(45.0);
1793 else if (theAction == toolMgr()->action( PerspectiveId )) {
1794 myModel->setProjectionType(Perspective);
1795 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Perspective );
1796 aCamera->SetFOVy(30.0);
1798 if (toolMgr()->action( StereoId )->isChecked()) {
1799 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1800 aCamera->SetFOVy(30.0);
1808 \brief Sets Stereo projection mode.
1810 Sets Stereo projection mode.
1812 void OCCViewer_ViewWindow::onStereoType( bool activate )
1814 Handle(V3d_View) aView3d = myViewPort->getView();
1815 if ( !aView3d.IsNull() ) {
1816 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1818 toolMgr()->action( PerspectiveId )->setChecked(true);
1819 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1820 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(false);
1822 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1823 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1824 setStereoType( aResMgr->integerValue( "OCCViewer", "stereo_type", 0 ) );
1825 setAnaglyphFilter( aResMgr->integerValue( "OCCViewer", "anaglyph_filter", 0 ) );
1826 setReverseStereo( aResMgr->booleanValue( "OCCViewer", "reverse_stereo", false ) );
1827 setVSync( aResMgr->booleanValue( "OCCViewer", "enable_vsync", true ) );
1828 setQuadBufferSupport( aResMgr->booleanValue( "OCCViewer", "enable_quad_buffer_support", false ) );
1831 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(true);
1832 if (myModel->projectionType() == Orthographic) {
1833 toolMgr()->action( OrthographicId )->setChecked(true);
1834 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Orthographic);
1836 else if (myModel->projectionType() == Perspective) {
1837 toolMgr()->action( PerspectiveId )->setChecked(true);
1838 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1845 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1846 toolMgr()->action( StereoId )->isChecked() )
1847 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1851 \brief Restore the view.
1853 Restore the projection mode based on tool-buttons states.
1855 void OCCViewer_ViewWindow::onProjectionType()
1857 emit vpTransformationStarted( PROJECTION );
1858 if (toolMgr()->action( OrthographicId )->isChecked())
1859 setProjectionType( Orthographic );
1860 if (toolMgr()->action( PerspectiveId )->isChecked())
1861 setProjectionType( Perspective );
1862 if (toolMgr()->action( StereoId )->isChecked())
1863 setProjectionType( Stereo );
1864 emit vpTransformationFinished( PROJECTION );
1867 void OCCViewer_ViewWindow::setProjectionType( int mode )
1869 QtxAction* anOrthographicAction = dynamic_cast<QtxAction*>( toolMgr()->action( OrthographicId ) );
1870 QtxAction* aPerspectiveAction = dynamic_cast<QtxAction*>( toolMgr()->action( PerspectiveId ) );
1871 QtxAction* aStereoAction = dynamic_cast<QtxAction*>( toolMgr()->action( StereoId ) );
1874 onProjectionType( anOrthographicAction );
1877 onProjectionType( aPerspectiveAction );
1880 onStereoType( true );
1883 // update action state if method is called outside
1884 if ( mode == Orthographic && !anOrthographicAction->isChecked() ) {
1885 anOrthographicAction->setChecked( true );
1886 aStereoAction->setChecked( false );
1888 if ( mode == Perspective && !aPerspectiveAction->isChecked() ) {
1889 aPerspectiveAction->setChecked( true );
1890 aStereoAction->setChecked( false );
1892 if ( mode == Stereo ) {
1893 aStereoAction->setChecked( true );
1894 if ( anOrthographicAction->isEnabled() ) {
1895 anOrthographicAction->setEnabled( false );
1896 anOrthographicAction->setChecked( false );
1897 aStereoAction->setChecked( false );
1900 anOrthographicAction->setEnabled( true );
1901 aStereoAction->setChecked( false );
1902 anOrthographicAction->setChecked(myModel->projectionType() == Orthographic);
1904 if ( aPerspectiveAction->isEnabled() ) {
1905 aPerspectiveAction->setEnabled( false );
1906 aPerspectiveAction->setChecked( true );
1907 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1908 toolMgr()->action( StereoId )->isChecked() )
1909 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1912 aPerspectiveAction->setEnabled( true );
1913 aStereoAction->setChecked( false );
1914 aPerspectiveAction->setChecked(myModel->projectionType() == Perspective);
1919 if ( !anOrthographicAction->isEnabled() )
1920 anOrthographicAction->setEnabled( true );
1921 if ( !aPerspectiveAction->isEnabled() )
1922 aPerspectiveAction->setEnabled( true );
1927 \brief Perform "fit all" transformation.
1929 void OCCViewer_ViewWindow::onFitAll()
1931 emit vpTransformationStarted( FITALLVIEW );
1932 if (myModel->fitter())
1933 myModel->fitter()->fitAll(myViewPort->getView());
1935 myViewPort->fitAll();
1936 emit vpTransformationFinished( FITALLVIEW );
1940 \brief Perform "fit selection" transformation.
1942 void OCCViewer_ViewWindow::onFitSelection()
1944 emit vpTransformationStarted( FITSELECTION );
1945 myModel->getAISContext()->FitSelected( getViewPort()->getView() );
1946 emit vpTransformationFinished( FITSELECTION );
1950 \brief Called if 'change rotation point' operation is activated.
1951 \param on action state
1953 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1957 if (!mySetRotationPointDlg)
1959 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1960 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1963 if (!mySetRotationPointDlg->isVisible())
1965 //if (mySetRotationPointDlg->IsFirstShown())
1966 if (myCurrPointType == BBCENTER)
1968 Standard_Real Xcenter, Ycenter, Zcenter;
1969 if (OCCViewer_Utilities::computeVisibleBBCenter(myViewPort->getView(), Xcenter, Ycenter, Zcenter))
1970 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1972 mySetRotationPointDlg->show();
1977 if (mySetRotationPointDlg->isVisible())
1978 mySetRotationPointDlg->hide();
1983 \brief Create one more window with same content.
1985 void OCCViewer_ViewWindow::onCloneView()
1987 SUIT_ViewWindow* vw = myManager->createViewWindow();
1989 emit viewCloned( vw );
1990 OCCViewer_ViewWindow* occVw = dynamic_cast<OCCViewer_ViewWindow*> (vw);
1991 if(occVw && occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)) {
1992 occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)->synchronize(this);
1997 Creates one more window with same content
1999 void OCCViewer_ViewWindow::onAxialScale()
2001 if ( !myScalingDlg )
2002 myScalingDlg = new OCCViewer_AxialScaleDlg( this , myModel );
2004 if ( !myScalingDlg->isVisible() )
2006 myScalingDlg->Update();
2007 myScalingDlg->show();
2012 Shows Graduated Axes dialog
2014 void OCCViewer_ViewWindow::onGraduatedAxes()
2016 myCubeAxesDlg->Update();
2017 myCubeAxesDlg->show();
2020 void OCCViewer_ViewWindow::onAmbientToogle()
2022 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2023 viewer->InitDefinedLights();
2024 while(viewer->MoreDefinedLights())
2026 Handle(V3d_Light) light = viewer->DefinedLight();
2027 if(light->Type() != V3d_AMBIENT)
2029 Handle(V3d_View) aView3d = myViewPort->getView();
2030 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
2031 else viewer->SetLightOn(light);
2033 viewer->NextDefinedLights();
2039 \brief Store view parameters.
2041 void OCCViewer_ViewWindow::onMemorizeView()
2043 appendViewAspect( getViewParams() );
2047 \brief Restore view parameters.
2049 void OCCViewer_ViewWindow::onRestoreView()
2051 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
2052 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
2054 updateViewAspects( aDlg->parameters() );
2055 if( myRestoreFlag && aDlg->parameters().count() )
2056 performRestoring( aDlg->currentItem() );
2060 \brief Restore view parameters.
2061 \param anItem view parameters
2063 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
2065 Handle(V3d_View) aView3d = myViewPort->getView();
2067 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
2068 aView3d->SetScale( anItem.scale );
2069 aView3d->SetTwist( anItem.twist );
2070 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
2071 aView3d->SetImmediateUpdate( prev );
2072 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2073 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2074 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
2076 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
2078 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
2080 // "eye" and "at" require conversion to represent center panning
2081 // up direction is only available after setting angle of twist and
2082 // other view parameters
2083 aView3d->Up( anUpX, anUpY, anUpZ );
2085 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
2086 gp_Dir anUp( anUpX, anUpY, anUpZ );
2087 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
2088 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2089 gp_Dir aSide = aProj ^ anUp;
2091 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
2092 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
2094 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
2095 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2098 if ( !baseParamsOnly ) {
2100 myModel->setTrihedronShown( anItem.isVisible );
2101 myModel->setTrihedronSize( anItem.size );
2103 // graduated trihedron
2104 bool anIsVisible = anItem.gtIsVisible;
2105 OCCViewer_AxisWidget::AxisData anAxisData[3];
2106 anAxisData[0].DrawName = anItem.gtDrawNameX;
2107 anAxisData[1].DrawName = anItem.gtDrawNameZ;
2108 anAxisData[2].DrawName = anItem.gtDrawNameZ;
2109 anAxisData[0].Name = anItem.gtNameX;
2110 anAxisData[1].Name = anItem.gtNameZ;
2111 anAxisData[2].Name = anItem.gtNameZ;
2112 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
2113 anItem.gtNameColorGX,
2114 anItem.gtNameColorBX );
2115 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
2116 anItem.gtNameColorGY,
2117 anItem.gtNameColorBY );
2118 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
2119 anItem.gtNameColorGZ,
2120 anItem.gtNameColorBZ );
2121 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
2122 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
2123 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
2124 anAxisData[0].NbValues = anItem.gtNbValuesX;
2125 anAxisData[1].NbValues = anItem.gtNbValuesY;
2126 anAxisData[2].NbValues = anItem.gtNbValuesZ;
2127 anAxisData[0].Offset = anItem.gtOffsetX;
2128 anAxisData[1].Offset = anItem.gtOffsetY;
2129 anAxisData[2].Offset = anItem.gtOffsetZ;
2130 anAxisData[0].Color = QColor( anItem.gtColorRX,
2133 anAxisData[1].Color = QColor( anItem.gtColorRY,
2136 anAxisData[2].Color = QColor( anItem.gtColorRZ,
2139 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
2140 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
2141 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
2142 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
2143 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
2144 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
2146 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
2147 myCubeAxesDlg->ApplyData( aView3d );
2149 } // if ( !baseParamsOnly )
2155 \brief Set restore flag.
2157 void OCCViewer_ViewWindow::setRestoreFlag()
2163 \brief Called when action "show/hide trihedron" is activated.
2165 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
2167 myModel->setTrihedronShown(show);
2171 \brief Toggles preselection (highlighting) on/off
2173 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
2175 myPreselectionEnabled = on;
2176 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
2178 // unhighlight all highlighted objects
2180 myModel->unHighlightAll( true, false );
2183 // update action state if method is called outside
2184 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2185 if ( a && a->isChecked() != on ) {
2186 a->setChecked( on );
2191 \brief Toggles selection on/off
2193 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
2195 mySelectionEnabled = on;
2196 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
2198 // update action state if method is called outside
2201 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2203 a->setEnabled( on );
2207 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
2208 if ( a && a->isChecked() != on ) {
2209 a->setChecked( on );
2214 \brief Switches style of advanced multiple selection by Poligon/Circle
2216 void OCCViewer_ViewWindow::onSwitchSelectionStyle(QAction* theAction)
2219 OCCViewer_ViewSketcher* aSkecher = getSketcher(Polygon);
2221 if (theAction == toolMgr()->action(PolygonSelectionStyleId)) {
2222 aSkecher->setSketcherMode(OCCViewer_PolygonSketcher::Poligone);
2224 else if (theAction == toolMgr()->action(CircleSelectionStyleId)) {
2225 aSkecher->setSketcherMode(OCCViewer_PolygonSketcher::Circle);
2231 Returns currently selected selection style
2233 OCCViewer_ViewWindow::SelectionStyle OCCViewer_ViewWindow::selectionStyle() const
2235 if (toolMgr()->action(PolygonSelectionStyleId)->isChecked())
2236 return PolygonStyle;
2237 if (toolMgr()->action(CircleSelectionStyleId)->isChecked())
2242 void OCCViewer_ViewWindow::setSelectionStyle(SelectionStyle theMode)
2244 toolMgr()->action(RectangleSelectionStyleId)->setChecked(false);
2245 toolMgr()->action(PolygonSelectionStyleId)->setChecked(false);
2246 toolMgr()->action(CircleSelectionStyleId)->setChecked(false);
2249 toolMgr()->action(RectangleSelectionStyleId)->setChecked(true);
2252 toolMgr()->action(PolygonSelectionStyleId)->setChecked(true);
2255 toolMgr()->action(CircleSelectionStyleId)->setChecked(true);
2260 \brief Switches "keyboard free" interaction style on/off
2262 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
2264 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
2266 // update action state if method is called outside
2267 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
2268 if ( a && a->isChecked() != on )
2269 a->setChecked( on );
2273 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
2275 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
2277 myViewPort->setAdvancedZoomingEnabled( on );
2279 // update action state if method is called outside
2280 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
2281 if ( a && a->isChecked() != on )
2282 a->setChecked( on );
2286 \brief Get current interaction style
2287 \return interaction style
2289 int OCCViewer_ViewWindow::interactionStyle() const
2291 return myInteractionStyle;
2295 \brief Set current interaction style
2296 \param theStyle interaction style
2298 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
2300 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
2304 \brief Get current zooming style
2305 \return zooming style
2307 int OCCViewer_ViewWindow::zoomingStyle() const
2309 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
2313 \brief Set current zooming style
2314 \param theStyle zooming style
2316 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
2318 onSwitchZoomingStyle( theStyle == 1 );
2322 \brief Dump view window contents to the pixmap.
2323 \return pixmap containing all scene rendered in the window
2325 //#define USE_OLD_IMPLEMENTATION
2326 QImage OCCViewer_ViewWindow::dumpView()
2328 Handle(V3d_View) view = myViewPort->getView();
2329 if ( view.IsNull() )
2332 int aWidth = myViewPort->width();
2333 int aHeight = myViewPort->height();
2335 #ifdef USE_OLD_IMPLEMENTATION
2336 // rnv: Old approach to dump the OCCViewer content via Frame Buffer Object
2340 #ifndef DISABLE_GLVIEWER
2341 OpenGLUtils_FrameBuffer aFrameBuffer;
2342 if ( aFrameBuffer.init( aWidth, aHeight ) )
2344 glPushAttrib( GL_VIEWPORT_BIT );
2345 glViewport( 0, 0, aWidth, aHeight );
2346 aFrameBuffer.bind();
2351 aFrameBuffer.unbind();
2354 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
2356 aFrameBuffer.bind();
2357 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
2358 aFrameBuffer.unbind();
2360 anImage = anImage.rgbSwapped();
2361 anImage = anImage.mirrored();
2365 // if frame buffers are unsupported, use old approach
2367 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
2368 QPoint p = myViewPort->mapFromParent( myViewPort->geometry().topLeft() );
2369 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
2371 QImage anImage( data, aWidth, aHeight, QImage::Format_ARGB32 );
2372 anImage = anImage.mirrored();
2373 anImage = anImage.rgbSwapped();
2376 #else // DISABLE_GLVIEWER
2380 #endif // DISABLE_GLVIEWER
2382 #else // USE_OLD_IMPLEMENTATION
2383 // rnv: New approach is to use OCCT built-in procedure
2386 view->ToPixMap(aPix, aWidth, aHeight, Graphic3d_BT_RGB);
2388 QImage anImage( aWidth, aHeight, QImage::Format_ARGB32 );
2389 for ( int i = 0; i < aWidth; i++ ) {
2390 for ( int j = 0; j < aHeight; j++ ) {
2391 Quantity_Color pixel = aPix.PixelColor( i, j ).GetRGB();
2392 QColor color = QColor::fromRgbF( pixel.Red(), pixel.Green(), pixel.Blue() );
2393 anImage.setPixelColor( i, j, color );
2397 if ( aPix.IsTopDown() )
2398 anImage = anImage.mirrored();
2401 #endif // USE_OLD_IMPLEMENTATION
2404 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& /*img*/,
2405 const QString& fileName,
2406 const QString& /*format*/ )
2409 QApplication::setOverrideCursor( Qt::WaitCursor );
2411 res = myViewPort->getView()->Dump( fileName.toStdString().c_str() );
2413 QApplication::restoreOverrideCursor();
2418 QString OCCViewer_ViewWindow::filter() const
2420 // OCCT version > 7.3.0 is not support export to PS and EPS
2421 QString formats = tr( "OCC_IMAGE_FILES" );
2422 return formats.remove(" *.eps *.ps");
2427 \brief Set parameters of the cutting plane
2428 \param on if \c true, cutting plane is enabled
2429 \param x X position of plane point
2430 \param y Y position of plane point
2431 \param z Z position of plane point
2432 \param dx X coordinate of plane normal
2433 \param dy Y coordinate of plane normal
2434 \param dz Z coordinate of plane normal
2436 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2437 const double dx, const double dy, const double dz )
2439 Handle(V3d_View) view = myViewPort->getView();
2440 if ( view.IsNull() )
2444 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2446 // try to use already existing plane or create a new one
2447 Handle(V3d_Plane) clipPlane;
2449 // calculate new a,b,c,d values for the plane
2450 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2452 pln.Coefficients(a, b, c, d);
2453 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2454 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2455 if(aPlanes->Size() > 0 ) {
2456 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2457 aClipPlane->SetEquation(pln);
2458 aClipPlane->SetOn(Standard_True);
2460 view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2464 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2465 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2466 for( ;anIter.More();anIter.Next() ){
2467 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2468 aClipPlane->SetOn(Standard_False);
2476 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2478 gp_Dir aDir = pln.Axis().Direction();
2479 gp_Pnt aPnt = pln.Location();
2480 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2485 \brief Check if any cutting plane is enabled
2486 \return \c true if at least one cutting plane is enabled
2488 bool OCCViewer_ViewWindow::isCuttingPlane()
2490 Handle(V3d_View) view = myViewPort->getView();
2492 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2493 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2494 for( ;anIter.More();anIter.Next() ) {
2495 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2496 if(aClipPlane->IsOn()) {
2505 \brief Get the visual parameters of the view window.
2506 \return visual parameters of view window
2508 viewAspect OCCViewer_ViewWindow::getViewParams() const
2510 double projX, projY, projZ, twist;
2511 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2512 double aScaleX, aScaleY, aScaleZ;
2514 Handle(V3d_View) aView3d = myViewPort->getView();
2516 aView3d->Proj( projX, projY, projZ );
2517 aView3d->At( atX, atY, atZ );
2518 aView3d->Eye( eyeX, eyeY, eyeZ );
2519 twist = aView3d->Twist();
2521 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2523 bool isShown = myModel->isTrihedronVisible();
2524 double size = myModel->trihedronSize();
2526 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2529 params.scale = aView3d->Scale();
2530 params.projX = projX;
2531 params.projY = projY;
2532 params.projZ = projZ;
2533 params.twist = twist;
2540 params.scaleX = aScaleX;
2541 params.scaleY = aScaleY;
2542 params.scaleZ = aScaleZ;
2543 params.name = aName;
2544 params.isVisible= isShown;
2547 // graduated trihedron
2548 bool anIsVisible = false;
2549 OCCViewer_AxisWidget::AxisData anAxisData[3];
2550 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2552 params.gtIsVisible = anIsVisible;
2553 params.gtDrawNameX = anAxisData[0].DrawName;
2554 params.gtDrawNameY = anAxisData[1].DrawName;
2555 params.gtDrawNameZ = anAxisData[2].DrawName;
2556 params.gtNameX = anAxisData[0].Name;
2557 params.gtNameY = anAxisData[1].Name;
2558 params.gtNameZ = anAxisData[2].Name;
2559 params.gtNameColorRX = anAxisData[0].NameColor.red();
2560 params.gtNameColorGX = anAxisData[0].NameColor.green();
2561 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2562 params.gtNameColorRY = anAxisData[1].NameColor.red();
2563 params.gtNameColorGY = anAxisData[1].NameColor.green();
2564 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2565 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2566 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2567 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2568 params.gtDrawValuesX = anAxisData[0].DrawValues;
2569 params.gtDrawValuesY = anAxisData[1].DrawValues;
2570 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2571 params.gtNbValuesX = anAxisData[0].NbValues;
2572 params.gtNbValuesY = anAxisData[1].NbValues;
2573 params.gtNbValuesZ = anAxisData[2].NbValues;
2574 params.gtOffsetX = anAxisData[0].Offset;
2575 params.gtOffsetY = anAxisData[1].Offset;
2576 params.gtOffsetZ = anAxisData[2].Offset;
2577 params.gtColorRX = anAxisData[0].Color.red();
2578 params.gtColorGX = anAxisData[0].Color.green();
2579 params.gtColorBX = anAxisData[0].Color.blue();
2580 params.gtColorRY = anAxisData[1].Color.red();
2581 params.gtColorGY = anAxisData[1].Color.green();
2582 params.gtColorBY = anAxisData[1].Color.blue();
2583 params.gtColorRZ = anAxisData[2].Color.red();
2584 params.gtColorGZ = anAxisData[2].Color.green();
2585 params.gtColorBZ = anAxisData[2].Color.blue();
2586 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2587 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2588 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2589 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2590 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2591 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2597 \brief Get visual parameters of this view window.
2598 \return visual parameters of view window
2600 QString OCCViewer_ViewWindow::getVisualParameters()
2602 viewAspect params = getViewParams();
2606 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2607 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2608 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2609 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2610 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2611 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2612 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2613 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2614 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2615 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2616 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2617 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2618 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2619 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2620 data << QString( "isVisible=%1" ).arg( params.isVisible );
2621 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2623 ClipPlanesList aPlanes = myModel->getClipPlanes();
2624 for ( int i=0; i < (int)aPlanes.size(); i++ )
2626 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2627 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2628 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2629 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2630 switch ( aPlane.Mode )
2632 case OCCViewer_ClipPlane::Absolute :
2634 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2636 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2638 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2639 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2640 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2644 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2649 case OCCViewer_ClipPlane::Relative :
2651 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2652 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2653 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2658 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2659 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2660 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2661 data << ClippingPlane;
2664 // graduated trihedron
2665 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2666 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2667 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2668 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2669 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2670 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2671 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2672 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2673 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2674 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2675 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2676 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2677 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2678 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2679 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2680 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2681 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2682 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2683 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2684 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2685 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2686 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2687 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2688 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2689 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2690 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2691 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2692 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2693 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2694 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2695 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2696 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2697 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2698 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2699 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2700 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2701 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2702 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2703 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2704 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2706 // ray tracing parameters
2707 Graphic3d_RenderingParams rendParams = this->getViewPort()->getView()->RenderingParams();
2708 if ( rendParams.Method == Graphic3d_RM_RAYTRACING ) {
2709 QString RayTracing = "rayTracing=";
2710 RayTracing += QString( "rtDepth~%1;" ).arg( rendParams.RaytracingDepth );
2711 RayTracing += QString( "rtReflection~%1;" ).arg( rendParams.IsReflectionEnabled );
2712 RayTracing += QString( "rtAntialiasing~%1;" ).arg( rendParams.IsAntialiasingEnabled );
2713 RayTracing += QString( "rtShadow~%1;" ).arg( rendParams.IsShadowEnabled );
2714 RayTracing += QString( "rtTransShadow~%1;" ).arg( rendParams.IsTransparentShadowEnabled );
2718 // environment texture parameters
2719 Handle(Graphic3d_TextureEnv) aTexture = this->getViewPort()->getView()->TextureEnv();
2720 if ( !aTexture.IsNull() ) {
2721 QString EnvTexture = "envTexture=";
2722 if ( aTexture->Name() == Graphic3d_NOT_ENV_UNKNOWN ) {
2723 TCollection_AsciiString aFileName;
2724 aTexture->Path().SystemName( aFileName );
2725 EnvTexture += QString( "etFile~%1;" ).arg( aFileName.ToCString() );
2728 EnvTexture += QString( "etNumber~%1;" ).arg( aTexture->Name() );
2732 // light source parameters
2733 myModel->getViewer3d()->InitDefinedLights();
2734 while ( myModel->getViewer3d()->MoreDefinedLights() )
2736 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2737 if ( aLight->Type() != V3d_AMBIENT ) {
2738 QString LightSource = QString( "lightSource=" );
2739 LightSource += QString( "lightType~%1;" ).arg( aLight->Type() );
2741 if ( aLight->Type() == V3d_DIRECTIONAL )
2742 Handle(V3d_DirectionalLight)::DownCast( aLight )->Direction( aX, aY, aZ );
2743 else if ( aLight->Type() == V3d_POSITIONAL )
2744 Handle(V3d_PositionalLight)::DownCast( aLight )->Position( aX, aY, aZ );
2746 continue; // not supported type of light source
2747 LightSource += QString( "lightX~%1;" ).arg( aX );
2748 LightSource += QString( "lightY~%1;" ).arg( aY );
2749 LightSource += QString( "lightZ~%1;" ).arg( aZ );
2750 LightSource += QString( "lightColorR~%1;" ).arg( aLight->Color().Red() );
2751 LightSource += QString( "lightColorG~%1;" ).arg( aLight->Color().Green() );
2752 LightSource += QString( "lightColorB~%1;" ).arg( aLight->Color().Blue() );
2753 LightSource += QString( "lightHeadlight~%1;" ).arg( aLight->Headlight() );
2754 data << LightSource;
2756 myModel->getViewer3d()->NextDefinedLights();
2759 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2760 data << QString( "background=%1" ).arg( bg );
2762 return data.join("*");
2766 \brief Restore visual parameters of the view window.
2767 \param parameters visual parameters of view window
2769 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2772 ClipPlanesList aClipPlanes;
2773 QStringList data = parameters.split( '*' );
2774 Qtx::BackgroundData bgData;
2775 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2777 foreach( QString param, data ) {
2778 QString paramName = param.section( '=', 0, 0 ).trimmed();
2779 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2780 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2781 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2782 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2783 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2784 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2785 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2786 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2787 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2788 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2789 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2790 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2791 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2792 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2793 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2794 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2795 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2796 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2797 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2798 else if ( paramName.contains( "ClippingPlane" ) )
2800 QStringList ClipPlaneData = paramValue.split( ';' );
2801 OCCViewer_ClipPlane aPlane;
2802 foreach( QString ClipPlaneParam, ClipPlaneData )
2804 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2805 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2806 if ( ClipPlane_paramName == "Mode" )
2808 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2810 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2811 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2812 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2813 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2816 switch ( aPlane.Mode )
2818 case OCCViewer_ClipPlane::Absolute :
2819 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2820 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2821 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2822 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2823 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2826 case OCCViewer_ClipPlane::Relative :
2827 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2828 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2829 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2834 aClipPlanes.push_back(aPlane);
2836 // graduated trihedron
2837 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2838 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2839 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2840 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2841 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2842 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2843 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2844 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2845 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2846 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2847 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2848 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2849 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2850 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2851 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2852 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2853 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2854 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2855 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2856 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2857 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2858 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2859 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2860 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2861 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2862 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2863 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2864 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2865 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2866 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2867 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2868 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2869 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2870 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2871 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2872 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2873 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2874 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2875 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2876 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2877 else if ( paramName == "rayTracing" )
2879 Graphic3d_RenderingParams& rendParams = this->getViewPort()->getView()->ChangeRenderingParams();
2880 rendParams.Method = Graphic3d_RM_RAYTRACING;
2881 QStringList rtData = paramValue.split( ';' );
2882 foreach( QString rtParam, rtData )
2884 QString rt_paramName = rtParam.section( '~', 0, 0 ).trimmed();
2885 QString rt_paramValue = rtParam.section( '~', 1, 1 ).trimmed();
2886 if ( rt_paramName == "rtDepth" ) rendParams.RaytracingDepth = rt_paramValue.toInt();
2887 else if ( rt_paramName == "rtReflection" ) rendParams.IsReflectionEnabled = rt_paramValue.toInt();
2888 else if ( rt_paramName == "rtAntialiasing" ) rendParams.IsAntialiasingEnabled = rt_paramValue.toInt();
2889 else if ( rt_paramName == "rtShadow" ) rendParams.IsShadowEnabled = rt_paramValue.toInt();
2890 else if ( rt_paramName == "rtTransShadow" ) rendParams.IsTransparentShadowEnabled = rt_paramValue.toInt();
2893 else if ( paramName == "envTexture" )
2895 Handle(Graphic3d_TextureEnv) aTexture;
2896 QStringList etData = paramValue.split( ';' );
2897 foreach( QString etParam, etData )
2899 QString et_paramName = etParam.section( '~', 0, 0 ).trimmed();
2900 QString et_paramValue = etParam.section( '~', 1, 1 ).trimmed();
2901 if ( et_paramName == "etNumber" )
2902 aTexture = new Graphic3d_TextureEnv( Graphic3d_NameOfTextureEnv( et_paramValue.toInt() ) );
2903 else if ( et_paramName == "etFile" )
2904 aTexture = new Graphic3d_TextureEnv( TCollection_AsciiString( et_paramValue.toStdString().c_str() ) );
2905 Handle(V3d_View) aView = this->getViewPort()->getView();
2906 aView->SetTextureEnv( aTexture );
2909 else if ( paramName == "lightSource" )
2911 myModel->getViewer3d()->InitDefinedLights();
2912 while ( myModel->getViewer3d()->MoreDefinedLights() )
2914 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2915 if( aLight->Type() != V3d_AMBIENT ) {
2916 myModel->getViewer3d()->DelLight( aLight );
2917 myModel->getViewer3d()->InitDefinedLights();
2919 myModel->getViewer3d()->NextDefinedLights();
2922 double aX = 0., aY = 0., aZ = 0.;
2923 double cR = 0., cG = 0., cB = 0.;
2924 V3d_TypeOfLight aType = (V3d_TypeOfLight)-1; // not specified
2925 bool isHeadlight = false;
2926 QStringList lsData = paramValue.split( ';' );
2927 foreach( QString lsParam, lsData )
2929 QString ls_paramName = lsParam.section( '~', 0, 0 ).trimmed();
2930 QString ls_paramValue = lsParam.section( '~', 1, 1 ).trimmed();
2931 if ( ls_paramName == "lightType" ) aType = V3d_TypeOfLight( ls_paramValue.toInt() );
2932 else if ( ls_paramName == "lightX" ) aX = ls_paramValue.toDouble();
2933 else if ( ls_paramName == "lightY" ) aY = ls_paramValue.toDouble();
2934 else if ( ls_paramName == "lightZ" ) aZ = ls_paramValue.toDouble();
2935 else if ( ls_paramName == "lightColorR" ) cR = ls_paramValue.toDouble();
2936 else if ( ls_paramName == "lightColorG" ) cG = ls_paramValue.toDouble();
2937 else if ( ls_paramName == "lightColorB" ) cB = ls_paramValue.toDouble();
2938 else if ( ls_paramName == "lightHeadlight" ) isHeadlight = ls_paramValue.toInt();
2940 Quantity_Color aColor = Quantity_Color( cR, cG, cB, Quantity_TOC_RGB );
2941 if( aType == V3d_DIRECTIONAL ) {
2942 Handle(V3d_DirectionalLight) aLight = new V3d_DirectionalLight();
2943 myModel->getViewer3d()->AddLight( aLight );
2944 aLight->SetDirection( aX, aY, aZ );
2945 aLight->SetColor( aColor );
2946 aLight->SetHeadlight( isHeadlight );
2947 myModel->getViewer3d()->SetLightOn( aLight );
2949 else if( aType == V3d_POSITIONAL ) {
2950 Handle(V3d_PositionalLight) aLight = new V3d_PositionalLight( gp_Pnt(aX, aY, aZ), aColor.Name() );
2951 myModel->getViewer3d()->AddLight( aLight );
2952 aLight->SetHeadlight( isHeadlight );
2953 myModel->getViewer3d()->SetLightOn( aLight );
2956 else if ( paramName == "background" ) {
2957 QString bg = paramValue.replace( "$", "=" );
2958 bgData = Qtx::stringToBackground( bg );
2962 else // old format - "1.000e+00*0.000e+00..."
2965 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2966 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2967 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2968 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2969 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2970 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2971 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
2972 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2973 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2974 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
2975 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2976 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2977 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2978 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
2979 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
2980 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
2981 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
2982 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
2984 performRestoring( params );
2985 setBackground( bgData );
2986 myModel->setClipPlanes(aClipPlanes);
2990 \brief Handle show event.
2992 Emits Show() signal.
2994 \param theEvent show event
2996 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2998 emit Show( theEvent );
3002 \brief Handle hide event.
3004 Emits Hide() signal.
3006 \param theEvent hide event
3008 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
3010 emit Hide( theEvent );
3015 Save old cursor. [ protected ]
3017 void OCCViewer_ViewWindow::saveCursor()
3019 QCursor* aCursor = NULL;
3021 aCursor = myViewPort->getDefaultCursor();
3022 myCursor = ( aCursor ? *aCursor : cursor() );
3027 Creates default sketcher. [ virtual protected ]
3029 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
3032 return new OCCViewer_RectSketcher( this, type );
3033 if ( type == Polygon )
3034 return new OCCViewer_PolygonSketcher( this, type );
3038 void OCCViewer_ViewWindow::initSketchers()
3040 if ( mySketchers.isEmpty() )
3042 mySketchers.append( createSketcher( Rect ) );
3043 mySketchers.append( createSketcher( Polygon ) );
3047 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ ) const
3049 OCCViewer_ViewSketcher* sketcher = 0;
3050 QList<OCCViewer_ViewSketcher*>::ConstIterator it;
3051 for ( it = mySketchers.cbegin(); it != mySketchers.cend() && !sketcher; ++it )
3053 OCCViewer_ViewSketcher* sk = (*it);
3054 if ( sk->type() == typ )
3061 Handles requests for sketching in the active view. [ virtual public ]
3063 void OCCViewer_ViewWindow::activateSketching( int type )
3065 OCCViewer_ViewPort3d* vp = getViewPort();
3069 if ( !vp->isSketchingEnabled() )
3072 /* Finish current sketching */
3073 if ( type == NoSketching )
3077 onSketchingFinished();
3078 mypSketcher->deactivate();
3082 /* Activate new sketching */
3085 activateSketching( NoSketching ); /* concurrency not suported */
3086 mypSketcher = getSketcher( type );
3089 mypSketcher->activate();
3090 onSketchingStarted();
3096 Unhilights detected entities. [ virtual protected ]
3098 void OCCViewer_ViewWindow::onSketchingStarted()
3103 Selection by rectangle or polygon. [ virtual protected ]
3105 void OCCViewer_ViewWindow::onSketchingFinished()
3107 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
3108 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
3110 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
3111 bool append = mypSketcher->isHasShift();
3112 switch( mypSketcher->type() )
3116 QRect* aRect = (QRect*)mypSketcher->data();
3119 int aLeft = aRect->left();
3120 int aRight = aRect->right();
3121 int aTop = aRect->top();
3122 int aBottom = aRect->bottom();
3126 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False);
3128 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False);
3134 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
3135 if( aPolygon && (aPolygon->size() > 2))
3137 int size = aPolygon->size();
3138 TColgp_Array1OfPnt2d anArray(1, size);
3140 QPolygon::Iterator it = aPolygon->begin();
3141 QPolygon::Iterator itEnd = aPolygon->end();
3142 for (int index = 1; it != itEnd; ++it, index++)
3144 QPoint aPoint = *it;
3145 anArray.SetValue(index, gp_Pnt2d(aPoint.x(), aPoint.y()));
3149 ic->ShiftSelect(anArray, getViewPort()->getView(), Standard_False);
3151 ic->Select(anArray, getViewPort()->getView(), Standard_False);
3159 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
3160 aViewMgr->getOCCViewer()->performSelectionChanged();
3164 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
3169 bool OCCViewer_ViewWindow::transformRequested() const
3171 return ( myOperation != NOVIEWOP );
3174 bool OCCViewer_ViewWindow::transformInProcess() const
3176 return myEventStarted;
3179 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
3181 myEventStarted = bOn;
3185 Set enabled state of transformation (rotate, zoom, etc)
3187 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
3189 if ( id != NOVIEWOP ) myStatus.insert( id, on );
3193 \return enabled state of transformation (rotate, zoom, etc)
3195 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
3197 return myStatus.contains( id ) ? myStatus[ id ] : true;
3200 void OCCViewer_ViewWindow::onMaximizedView()
3202 setMaximized(!isMaximized());
3205 void OCCViewer_ViewWindow::returnTo3dView()
3207 setReturnedTo3dView( true );
3210 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
3212 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
3213 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
3214 if ( !isVisible3dView )
3215 toolMgr()->show( ReturnTo3dViewId );
3217 toolMgr()->hide( ReturnTo3dViewId );
3218 if ( isVisible3dView ) emit returnedTo3d( );
3222 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
3224 QAction* anAction = toolMgr()->action( MaximizedId );
3225 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
3226 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
3228 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
3229 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
3230 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
3231 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
3232 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
3234 emit maximized( this, true );
3238 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
3239 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
3240 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
3241 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
3242 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
3244 emit maximized( this, false );
3249 bool OCCViewer_ViewWindow::isMaximized() const
3251 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
3254 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
3256 IsSketcherStyle = enable;
3259 bool OCCViewer_ViewWindow::isSketcherStyle() const
3261 return IsSketcherStyle;
3265 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
3270 int OCCViewer_ViewWindow::projectionType() const
3272 int mode = Orthographic;
3273 Handle(V3d_View) aView3d = myViewPort->getView();
3274 if ( !aView3d.IsNull() ) {
3275 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3276 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Perspective)
3278 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Orthographic)
3279 mode = Orthographic;
3280 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
3286 void OCCViewer_ViewWindow::setStereoType( int type )
3288 Handle(V3d_View) aView3d = myViewPort->getView();
3289 if ( !aView3d.IsNull() ) {
3290 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3291 aParams->StereoMode = (Graphic3d_StereoMode)type;
3295 int OCCViewer_ViewWindow::stereoType() const
3297 int type = QuadBuffer;
3298 Handle(V3d_View) aView3d = myViewPort->getView();
3299 if ( !aView3d.IsNull() ) {
3300 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3301 type = (OCCViewer_ViewWindow::StereoType)aParams->StereoMode;
3306 void OCCViewer_ViewWindow::setAnaglyphFilter( int type )
3308 Handle(V3d_View) aView3d = myViewPort->getView();
3309 if ( !aView3d.IsNull() ) {
3310 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3311 if (type == RedCyan)
3312 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
3313 if (type == YellowBlue)
3314 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
3315 if (type == GreenMagenta)
3316 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
3320 int OCCViewer_ViewWindow::anaglyphFilter() const
3323 Handle(V3d_View) aView3d = myViewPort->getView();
3324 if ( !aView3d.IsNull() ) {
3325 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3326 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized)
3328 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized)
3330 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple)
3331 type = GreenMagenta;
3336 void OCCViewer_ViewWindow::setStereographicFocus( int type, double value )
3338 Handle(V3d_View) aView3d = myViewPort->getView();
3339 if ( !aView3d.IsNull() ) {
3340 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3341 aCamera->SetZFocus( (Graphic3d_Camera::FocusType) type, value );
3345 int OCCViewer_ViewWindow::stereographicFocusType() const
3347 int type = Relative;
3348 Handle(V3d_View) aView3d = myViewPort->getView();
3349 if ( !aView3d.IsNull() ) {
3350 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3351 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->ZFocusType();
3356 double OCCViewer_ViewWindow::stereographicFocusValue() const
3359 Handle(V3d_View) aView3d = myViewPort->getView();
3360 if ( !aView3d.IsNull() ) {
3361 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3362 value = aCamera->ZFocus();
3367 void OCCViewer_ViewWindow::setInterocularDistance( int type, double value )
3369 Handle(V3d_View) aView3d = myViewPort->getView();
3370 if ( !aView3d.IsNull() ) {
3371 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3372 aCamera->SetIOD( (Graphic3d_Camera::IODType) type, value );
3376 int OCCViewer_ViewWindow::interocularDistanceType() const
3378 int type = Relative;
3379 Handle(V3d_View) aView3d = myViewPort->getView();
3380 if ( !aView3d.IsNull() ) {
3381 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3382 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->GetIODType();
3387 double OCCViewer_ViewWindow::interocularDistanceValue() const
3389 double value = 0.05;
3390 Handle(V3d_View) aView3d = myViewPort->getView();
3391 if ( !aView3d.IsNull() ) {
3392 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3393 value = aCamera->IOD();
3398 void OCCViewer_ViewWindow::setReverseStereo( bool reverse )
3400 Handle(V3d_View) aView3d = myViewPort->getView();
3401 if ( !aView3d.IsNull() ) {
3402 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3403 aParams->ToReverseStereo = reverse;
3407 bool OCCViewer_ViewWindow::isReverseStereo() const
3409 int reverse = false;
3410 Handle(V3d_View) aView3d = myViewPort->getView();
3411 if ( !aView3d.IsNull() ) {
3412 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3413 reverse = aParams->ToReverseStereo;
3418 void OCCViewer_ViewWindow::setVSync( bool enable )
3420 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3421 if ( !anIntCont.IsNull() ) {
3422 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3423 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3424 aCaps->swapInterval = enable;
3428 bool OCCViewer_ViewWindow::isVSync() const
3431 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3432 if ( !anIntCont.IsNull() ) {
3433 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3434 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3435 enable = aCaps->swapInterval;
3440 void OCCViewer_ViewWindow::setQuadBufferSupport( bool enable )
3442 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3443 if ( !anIntCont.IsNull() ) {
3444 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3445 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3446 aCaps->contextStereo = enable;
3450 bool OCCViewer_ViewWindow::isQuadBufferSupport() const
3453 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3454 if ( !anIntCont.IsNull() ) {
3455 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3456 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3457 enable = aCaps->contextStereo;
3462 bool OCCViewer_ViewWindow::isOpenGlStereoSupport() const
3464 GLboolean support[1];
3465 glGetBooleanv (GL_STEREO, support);
3472 QColor OCCViewer_ViewWindow::backgroundColor() const
3474 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
3478 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
3480 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
3483 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
3485 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
3488 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
3490 if ( myViewPort ) myViewPort->setBackground( theBackground );
3493 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
3495 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
3501 void OCCViewer_ViewWindow::clearViewAspects()
3503 myViewAspects.clear();
3507 \return const reference to list of view aspects
3509 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
3511 return myViewAspects;
3515 Appends new view aspect
3516 \param aParams - new view aspects
3518 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
3520 myViewAspects.append( aParams );
3524 Replaces old view aspects by new ones
3525 \param aViewList - list of new view aspects
3527 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
3529 myViewAspects = aViewList;
3533 Get camera properties for the OCC view window.
3534 \return shared pointer on camera properties.
3536 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
3538 SUIT_CameraProperties aProps;
3540 Handle(V3d_View) aSourceView = getViewPort()->getView();
3541 if ( aSourceView.IsNull() )
3544 if ( get2dMode() == No2dMode ) {
3545 aProps.setDimension( SUIT_CameraProperties::Dim3D );
3548 aProps.setDimension( SUIT_CameraProperties::Dim2D );
3549 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
3552 // read common properites of the view
3553 Standard_Real anUp[3];
3554 Standard_Real anAt[3];
3555 Standard_Real anEye[3];
3556 Standard_Real aProj[3];
3557 Standard_Real anAxialScale[3];
3559 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
3560 aSourceView->At( anAt[0], anAt[1], anAt[2] );
3561 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
3562 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3564 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3565 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
3567 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
3569 // store camera properties "as is": it is up to synchronized
3570 // view classes to provide necessary property conversion.
3571 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
3572 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
3574 if ( aSourceView->Camera()->IsOrthographic() )
3576 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
3577 aProps.setViewAngle( 0.0 );
3581 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
3582 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
3584 aProps.setMappingScale( aSourceView->Camera()->Scale() );
3591 This implementation synchronizes OCC view's camera propreties.
3593 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
3595 bool blocked = blockSignals( true );
3597 SUIT_CameraProperties aProps = theView->cameraProperties();
3598 if ( !cameraProperties().isCompatible( aProps ) ) {
3599 // other view, this one is being currently synchronized to, seems has become incompatible
3600 // we have to break synchronization
3605 Handle(V3d_View) aDestView = getViewPort()->getView();
3607 aDestView->SetImmediateUpdate( Standard_False );
3610 double aPosition[3];
3611 double aFocalPoint[3];
3612 double anAxialScale[3];
3614 // get common properties
3615 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3616 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
3617 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3618 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3621 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3622 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
3623 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3624 aDestView->Camera()->SetScale( aProps.getMappingScale() );
3626 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3627 aDestView->SetImmediateUpdate( Standard_True );
3628 aDestView->Redraw();
3630 catch (Standard_Failure&) {
3633 blockSignals( blocked );
3637 \brief Indicates whether preselection is enabled
3638 \return true if preselection is enabled
3640 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
3642 return myPreselectionEnabled;
3646 \brief Enables/disables preselection
3647 \param theIsToEnable if true - preselection will be enabled
3649 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
3651 onSwitchPreselection( theIsToEnable );
3655 \brief Indicates whether selection is enabled
3656 \return true if selection is enabled
3658 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3660 return mySelectionEnabled;
3664 \brief Enables/disables selection
3665 \param theIsToEnable if true - selection will be enabled
3667 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3669 onSwitchSelection( theIsToEnable );
3674 \brief called if clipping operation is activated / deactivated.
3676 Enables/disables clipping plane displaying.
3678 \parma on action state
3680 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3682 if(!myModel) return;
3683 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3686 if (!aClippingDlg) {
3687 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3688 myModel->setClippingDlg(aClippingDlg);
3690 if (!aClippingDlg->isVisible())
3691 aClippingDlg->show();
3693 if ( aClippingDlg ) {
3694 aClippingDlg->close();
3695 myModel->setClippingDlg(0);
3699 SUIT_ViewManager* mgr = getViewManager();
3701 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3702 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3703 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3704 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3706 QAction* a = toolMgr()->action( ClippingId );
3708 if(theIsOn != a->isChecked()){
3709 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3710 a->setChecked(theIsOn);
3711 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3718 void OCCViewer_ViewWindow::onRayTracing()
3720 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_RayTracingDlg::getName() ) ) {
3721 QDialog* aDlg = new OCCViewer_RayTracingDlg( this );
3727 void OCCViewer_ViewWindow::onEnvTexture()
3729 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_EnvTextureDlg::getName() ) ) {
3730 QDialog* aDlg = new OCCViewer_EnvTextureDlg( this );
3736 void OCCViewer_ViewWindow::onLightSource()
3738 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_LightSourceDlg::getName() ) ) {
3739 QDialog* aDlg = new OCCViewer_LightSourceDlg( this, myModel );
3745 bool OCCViewer_ViewWindow::isActionVisible( ActionId theId ) const
3747 QAction* a = toolMgr()->action( theId );
3748 return a && a->isVisible();
3751 void OCCViewer_ViewWindow::setActionVisible( ActionId theId, bool isVisible )
3753 QAction* a = toolMgr()->action( theId );
3755 a->setVisible( isVisible );
3758 void OCCViewer_ViewWindow::projAndPanToGravity(V3d_TypeOfOrientation CamOri)
3760 const bool USE_XY = true;
3762 Handle(V3d_View) aView3d = myViewPort->getView();
3763 if (aView3d.IsNull())
3767 double X = 0, Y = 0, Z = 0;
3770 const double EPS = 1E-6;
3771 int xp = myViewPort->width()/2, yp = myViewPort->height()/2;
3772 aView3d->Convert( xp, yp, X, Y, Z );
3774 gp_Dir d = aView3d->Camera()->Direction();
3775 if( fabs( d.Z() ) > EPS )
3777 double t = -Z/d.Z();
3784 // It is really necessary to compute gravity center even if it is not used in part of code below.
3785 // Without this calculation the SetProj() method and other methods are not correct.
3787 IsGr = computeGravityCenter(X2, Y2, Z2);
3789 IsGr = OCCViewer_Utilities::computeSceneBBCenter(aView3d, X2, Y2, Z2);
3791 aView3d->SetProj(CamOri);
3794 //aView3d->Update();
3795 Handle(Graphic3d_Camera) Cam = aView3d->Camera();
3797 gp_Vec dir (Cam->Direction());
3798 gp_Pnt eye = Cam->Eye();
3800 Standard_Real D = dir.Dot(V1);
3801 gp_Pnt ppdir = eye.Translated(D*dir);
3802 gp_Vec V2(ppdir, gp);
3803 gp_XYZ trEye = eye.XYZ() + V2.XYZ();
3805 double xat, yat, zat;
3806 aView3d->At(xat, yat, zat);
3807 gp_Pnt At(xat, yat, zat);
3808 gp_XYZ trAt = At.XYZ() + V2.XYZ();
3809 aView3d->SetEye(trEye.X(), trEye.Y(), trEye.Z());
3810 aView3d->SetAt(trAt.X(), trAt.Y(), trAt.Z());
3815 bool OCCViewer_ViewWindow::isAutomaticZoom() const
3817 return myAutomaticZoom;
3820 void OCCViewer_ViewWindow::setAutomaticZoom(const bool isOn)
3822 myAutomaticZoom = isOn;