1 // Copyright (C) 2007-2022 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 );
1407 if (myModel->viewCubeActivated()) {
1408 aAction = new QtxAction(tr("MNU_SHOW_VIEWCUBE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_VIEWCUBE" ) ),
1409 tr( "MNU_SHOW_VIEWCUBE" ), 0, this);
1410 aAction->setCheckable( true );
1411 aAction->setChecked( aResMgr->booleanValue( "OCCViewer", "viewcube_show", true ) );
1412 aAction->setStatusTip(tr("DSC_SHOW_VIEWCUBE"));
1413 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onViewCubeShow(bool)));
1414 toolMgr()->registerAction( aAction, ViewCubeShowId );
1418 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1419 tr( "MNU_SCALING" ), 0, this);
1420 aAction->setStatusTip(tr("DSC_SCALING"));
1421 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1422 toolMgr()->registerAction( aAction, AxialScaleId );
1424 // Enable/disable preselection
1425 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1426 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1427 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1428 aAction->setCheckable(true);
1429 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1430 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1432 // Enable/disable selection
1433 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1434 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1435 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1436 aAction->setCheckable(true);
1437 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1438 toolMgr()->registerAction( aAction, SwitchSelectionId );
1441 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1442 tr( "MNU_GRADUATED_AXES" ), 0, this);
1443 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1444 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1445 toolMgr()->registerAction( aAction, GraduatedAxesId );
1447 // Active only ambient light or not
1448 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1449 tr( "MNU_AMBIENT" ), 0, this);
1450 aAction->setStatusTip(tr("DSC_AMBIENT"));
1451 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1452 toolMgr()->registerAction( aAction, AmbientId );
1454 // Switch between interaction styles
1455 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1456 tr( "MNU_STYLE_SWITCH" ), 0, this);
1457 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1458 aAction->setCheckable(true);
1459 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1460 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1462 // Switch between zooming styles
1463 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1464 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1465 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1466 aAction->setCheckable(true);
1467 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1468 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1470 // Switch advanced selection style (poligone/circle)
1471 aAction = new QtxAction(tr("MNU_RECTANGLE_SELECTION_STYLE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RECT_STYLE" ) ),
1472 tr( "MNU_RECTANGLE_SELECTION_STYLE" ), 0, this);
1473 aAction->setStatusTip(tr("DSC_RECTANGLE_SELECTION_STYLE"));
1474 aAction->setCheckable(true);
1475 toolMgr()->registerAction( aAction, RectangleSelectionStyleId);
1477 aAction = new QtxAction(tr("MNU_POLYGON_SELECTION_STYLE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_POLY_STYLE" ) ),
1478 tr( "MNU_POLYGON_SELECTION_STYLE" ), 0, this);
1479 aAction->setStatusTip(tr("DSC_POLYGON_SELECTION_STYLE"));
1480 aAction->setCheckable(true);
1481 toolMgr()->registerAction( aAction, PolygonSelectionStyleId);
1483 aAction = new QtxAction(tr("MNU_CIRCLE_SELECTION_STYLE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CIRCLE_STYLE" ) ),
1484 tr( "MNU_CIRCLE_SELECTION_STYLE" ), 0, this);
1485 aAction->setStatusTip(tr("DSC_CIRCLE_SELECTION_STYLE"));
1486 aAction->setCheckable(true);
1487 toolMgr()->registerAction( aAction, CircleSelectionStyleId);
1489 // - add exclusive action group
1490 QActionGroup* aSelectionGroup = new QActionGroup(this);
1491 aSelectionGroup->addAction(toolMgr()->action(RectangleSelectionStyleId));
1492 aSelectionGroup->addAction(toolMgr()->action(PolygonSelectionStyleId));
1493 aSelectionGroup->addAction(toolMgr()->action(CircleSelectionStyleId));
1494 connect(aSelectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onSwitchSelectionStyle(QAction*)));
1497 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1498 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1499 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1500 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1501 toolMgr()->registerAction( aAction, MaximizedId );
1503 // Return to 3d view
1504 if (my2dMode!=No2dMode){
1505 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1506 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1507 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1508 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1509 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1513 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1514 #ifdef ENABLE_RAY_TRACING
1516 aAction = new QtxAction( tr("MNU_RAY_TRACING"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_RAY_TRACING") ),
1517 tr("MNU_RAY_TRACING"), 0, this );
1518 aAction->setStatusTip( tr("DSC_RAY_TRACING") );
1519 connect( aAction, SIGNAL( triggered() ), this, SLOT( onRayTracing() ) );
1520 toolMgr()->registerAction( aAction, RayTracingId );
1522 // Environment texture
1523 aAction = new QtxAction( tr("MNU_ENV_TEXTURE"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_ENV_TEXTURE") ),
1524 tr("MNU_ENV_TEXTURE"), 0, this );
1525 aAction->setStatusTip( tr("DSC_ENV_TEXTURE") );
1526 connect( aAction, SIGNAL( triggered() ), this, SLOT( onEnvTexture() ) );
1527 toolMgr()->registerAction( aAction, EnvTextureId );
1530 aAction = new QtxAction( tr("MNU_LIGHT_SOURCE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_LIGHT_SOURCE" ) ),
1531 tr( "MNU_LIGHT_SOURCE" ), 0, this );
1532 aAction->setStatusTip( tr("DSC_LIGHT_SOURCE") );
1533 connect( aAction, SIGNAL( triggered() ), this, SLOT( onLightSource() ) );
1534 toolMgr()->registerAction( aAction, LightSourceId );
1539 \brief Create toolbar.
1541 void OCCViewer_ViewWindow::createToolBar()
1543 static const char* titles[] = {
1544 "LBL_3DTOOLBAR_LABEL",
1545 "LBL_XYTOOLBAR_LABEL",
1546 "LBL_XZTOOLBAR_LABEL",
1547 "LBL_YZTOOLBAR_LABEL",
1549 static const char* names[] = {
1550 "OCCViewer3DViewOperations",
1551 "OCCViewerXYViewOperations",
1552 "OCCViewerXZViewOperations",
1553 "OCCViewerYZViewOperations",
1555 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1556 QString( names[my2dMode] ), // name (language-independant)
1557 false ); // disable floatable toolbar
1558 if ( my2dMode != No2dMode ){
1559 toolMgr()->append( ReturnTo3dViewId, tid );
1560 toolMgr()->append( toolMgr()->separator(), tid );
1562 toolMgr()->append( DumpId, tid );
1563 toolMgr()->append( SwitchInteractionStyleId, tid );
1564 toolMgr()->append( SwitchZoomingStyleId, tid );
1565 toolMgr()->append( SwitchPreselectionId, tid );
1566 toolMgr()->append( SwitchSelectionId, tid );
1568 QtxMultiAction* aSelectionAction = new QtxMultiAction(this);
1569 aSelectionAction->insertAction(toolMgr()->action(RectangleSelectionStyleId));
1570 aSelectionAction->insertAction(toolMgr()->action(PolygonSelectionStyleId));
1571 aSelectionAction->insertAction(toolMgr()->action(CircleSelectionStyleId));
1572 toolMgr()->append(aSelectionAction, tid );
1574 if( myModel->trihedronActivated() )
1575 toolMgr()->append( TrihedronShowId, tid );
1577 if( myModel->viewCubeActivated() )
1578 toolMgr()->append( ViewCubeShowId, tid );
1580 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1581 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1582 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1583 aScaleAction->insertAction( toolMgr()->action( FitSelectionId ) );
1584 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1585 toolMgr()->append( aScaleAction, tid );
1587 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1588 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1589 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1590 toolMgr()->append( aPanningAction, tid );
1592 if (my2dMode == No2dMode) {
1593 toolMgr()->append( ChangeRotationPointId, tid );
1594 toolMgr()->append( RotationId, tid );
1596 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1597 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1598 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1599 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1600 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1601 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1602 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1603 toolMgr()->append( aViewsAction, tid );
1605 toolMgr()->append( AntiClockWiseId, tid );
1606 toolMgr()->append( ClockWiseId, tid );
1608 toolMgr()->append( OrthographicId, tid );
1609 toolMgr()->append( PerspectiveId, tid );
1610 toolMgr()->append( StereoId, tid );
1612 toolMgr()->append( ResetId, tid );
1615 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1616 aMemAction->insertAction( toolMgr()->action( MemId ) );
1617 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1618 toolMgr()->append( aMemAction, tid );
1620 toolMgr()->append( toolMgr()->separator(), tid );
1621 toolMgr()->append( CloneId, tid );
1623 toolMgr()->append( toolMgr()->separator(), tid );
1624 toolMgr()->append( ClippingId, tid );
1625 toolMgr()->append( AxialScaleId, tid );
1626 toolMgr()->append( GraduatedAxesId, tid );
1627 toolMgr()->append( AmbientId, tid );
1629 toolMgr()->append( MaximizedId, tid );
1630 toolMgr()->append( SynchronizeId, tid );
1631 #ifdef ENABLE_RAY_TRACING
1632 toolMgr()->append( RayTracingId, tid );
1633 toolMgr()->append( EnvTextureId, tid );
1634 toolMgr()->append( LightSourceId, tid );
1639 \brief Perform 'fit all' operation.
1641 void OCCViewer_ViewWindow::onViewFitAll()
1643 myViewPort->fitAll();
1647 \brief Perform "front view" transformation.
1649 void OCCViewer_ViewWindow::onFrontView()
1651 emit vpTransformationStarted ( FRONTVIEW );
1652 Handle(V3d_View) aView3d = myViewPort->getView();
1653 if (myAutomaticZoom)
1655 if ( !aView3d.IsNull() )
1656 aView3d->SetProj (V3d_Xpos);
1660 projAndPanToGravity(V3d_Xpos);
1661 emit vpTransformationFinished ( FRONTVIEW );
1665 \brief Perform "back view" transformation.
1667 void OCCViewer_ViewWindow::onBackView()
1669 emit vpTransformationStarted ( BACKVIEW );
1670 Handle(V3d_View) aView3d = myViewPort->getView();
1671 if (myAutomaticZoom)
1673 if ( !aView3d.IsNull() )
1674 aView3d->SetProj (V3d_Xneg);
1678 projAndPanToGravity(V3d_Xneg);
1679 emit vpTransformationFinished ( BACKVIEW );
1683 \brief Perform "top view" transformation.
1685 void OCCViewer_ViewWindow::onTopView()
1687 emit vpTransformationStarted ( TOPVIEW );
1688 Handle(V3d_View) aView3d = myViewPort->getView();
1689 if (myAutomaticZoom)
1691 if ( !aView3d.IsNull() )
1692 aView3d->SetProj (V3d_Zpos);
1696 projAndPanToGravity(V3d_Zpos);
1697 emit vpTransformationFinished ( TOPVIEW );
1701 \brief Perform "bottom view" transformation.
1703 void OCCViewer_ViewWindow::onBottomView()
1705 emit vpTransformationStarted ( BOTTOMVIEW );
1706 Handle(V3d_View) aView3d = myViewPort->getView();
1707 if (myAutomaticZoom)
1709 if ( !aView3d.IsNull() )
1710 aView3d->SetProj (V3d_Zneg);
1714 projAndPanToGravity(V3d_Zneg);
1715 emit vpTransformationFinished ( BOTTOMVIEW );
1719 \brief Perform "left view" transformation.
1721 void OCCViewer_ViewWindow::onLeftView()
1723 emit vpTransformationStarted ( LEFTVIEW );
1724 Handle(V3d_View) aView3d = myViewPort->getView();
1725 if (myAutomaticZoom)
1727 if ( !aView3d.IsNull() )
1728 aView3d->SetProj (V3d_Yneg);
1732 projAndPanToGravity(V3d_Yneg);
1733 emit vpTransformationFinished ( LEFTVIEW );
1737 \brief Perform "right view" transformation.
1739 void OCCViewer_ViewWindow::onRightView()
1741 emit vpTransformationStarted ( RIGHTVIEW );
1742 Handle(V3d_View) aView3d = myViewPort->getView();
1743 if (myAutomaticZoom)
1745 if ( !aView3d.IsNull() )
1746 aView3d->SetProj (V3d_Ypos);
1750 projAndPanToGravity(V3d_Ypos);
1751 emit vpTransformationFinished ( RIGHTVIEW );
1755 \brief Rotate view 90 degrees clockwise
1757 void OCCViewer_ViewWindow::onClockWiseView()
1759 emit vpTransformationStarted ( CLOCKWISEVIEW );
1760 myViewPort->rotateXY( 90. );
1761 emit vpTransformationFinished ( CLOCKWISEVIEW );
1765 \brief Rotate view 90 degrees conterclockwise
1767 void OCCViewer_ViewWindow::onAntiClockWiseView()
1769 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1770 myViewPort->rotateXY( -90. );
1771 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1775 \brief Perform "reset view" transformation.
1777 Sets default orientation of the viewport camera.
1779 void OCCViewer_ViewWindow::onResetView()
1781 emit vpTransformationStarted( RESETVIEW );
1782 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1783 myViewPort->getView()->Reset( false );
1784 myViewPort->fitAll( false, true, false );
1785 myViewPort->getView()->SetImmediateUpdate( upd );
1786 onProjectionType(); // needed to apply projection type properly after reset
1787 myViewPort->getView()->Update();
1788 emit vpTransformationFinished( RESETVIEW );
1792 \brief Set the given projection mode.
1794 Set the given projection mode: Orthographic or Perspective.
1796 void OCCViewer_ViewWindow::onProjectionType( QAction* theAction )
1798 Handle(V3d_View) aView3d = myViewPort->getView();
1799 if ( !aView3d.IsNull() ) {
1800 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1801 if (theAction == toolMgr()->action( OrthographicId )) {
1802 myModel->setProjectionType(Orthographic);
1803 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Orthographic );
1804 aCamera->SetFOVy(45.0);
1806 else if (theAction == toolMgr()->action( PerspectiveId )) {
1807 myModel->setProjectionType(Perspective);
1808 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Perspective );
1809 aCamera->SetFOVy(30.0);
1811 if (toolMgr()->action( StereoId )->isChecked()) {
1812 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1813 aCamera->SetFOVy(30.0);
1821 \brief Sets Stereo projection mode.
1823 Sets Stereo projection mode.
1825 void OCCViewer_ViewWindow::onStereoType( bool activate )
1827 Handle(V3d_View) aView3d = myViewPort->getView();
1828 if ( !aView3d.IsNull() ) {
1829 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1831 toolMgr()->action( PerspectiveId )->setChecked(true);
1832 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1833 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(false);
1835 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1836 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1837 setStereoType( aResMgr->integerValue( "OCCViewer", "stereo_type", 0 ) );
1838 setAnaglyphFilter( aResMgr->integerValue( "OCCViewer", "anaglyph_filter", 0 ) );
1839 setReverseStereo( aResMgr->booleanValue( "OCCViewer", "reverse_stereo", false ) );
1840 setVSync( aResMgr->booleanValue( "OCCViewer", "enable_vsync", true ) );
1841 setQuadBufferSupport( aResMgr->booleanValue( "OCCViewer", "enable_quad_buffer_support", false ) );
1844 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(true);
1845 if (myModel->projectionType() == Orthographic) {
1846 toolMgr()->action( OrthographicId )->setChecked(true);
1847 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Orthographic);
1849 else if (myModel->projectionType() == Perspective) {
1850 toolMgr()->action( PerspectiveId )->setChecked(true);
1851 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1858 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1859 toolMgr()->action( StereoId )->isChecked() )
1860 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1864 \brief Restore the view.
1866 Restore the projection mode based on tool-buttons states.
1868 void OCCViewer_ViewWindow::onProjectionType()
1870 emit vpTransformationStarted( PROJECTION );
1871 if (toolMgr()->action( OrthographicId )->isChecked())
1872 setProjectionType( Orthographic );
1873 if (toolMgr()->action( PerspectiveId )->isChecked())
1874 setProjectionType( Perspective );
1875 if (toolMgr()->action( StereoId )->isChecked())
1876 setProjectionType( Stereo );
1877 emit vpTransformationFinished( PROJECTION );
1880 void OCCViewer_ViewWindow::setProjectionType( int mode )
1882 QtxAction* anOrthographicAction = dynamic_cast<QtxAction*>( toolMgr()->action( OrthographicId ) );
1883 QtxAction* aPerspectiveAction = dynamic_cast<QtxAction*>( toolMgr()->action( PerspectiveId ) );
1884 QtxAction* aStereoAction = dynamic_cast<QtxAction*>( toolMgr()->action( StereoId ) );
1887 onProjectionType( anOrthographicAction );
1890 onProjectionType( aPerspectiveAction );
1893 onStereoType( true );
1896 // update action state if method is called outside
1897 if ( mode == Orthographic && !anOrthographicAction->isChecked() ) {
1898 anOrthographicAction->setChecked( true );
1899 aStereoAction->setChecked( false );
1901 if ( mode == Perspective && !aPerspectiveAction->isChecked() ) {
1902 aPerspectiveAction->setChecked( true );
1903 aStereoAction->setChecked( false );
1905 if ( mode == Stereo ) {
1906 aStereoAction->setChecked( true );
1907 if ( anOrthographicAction->isEnabled() ) {
1908 anOrthographicAction->setEnabled( false );
1909 anOrthographicAction->setChecked( false );
1910 aStereoAction->setChecked( false );
1913 anOrthographicAction->setEnabled( true );
1914 aStereoAction->setChecked( false );
1915 anOrthographicAction->setChecked(myModel->projectionType() == Orthographic);
1917 if ( aPerspectiveAction->isEnabled() ) {
1918 aPerspectiveAction->setEnabled( false );
1919 aPerspectiveAction->setChecked( true );
1920 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1921 toolMgr()->action( StereoId )->isChecked() )
1922 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1925 aPerspectiveAction->setEnabled( true );
1926 aStereoAction->setChecked( false );
1927 aPerspectiveAction->setChecked(myModel->projectionType() == Perspective);
1932 if ( !anOrthographicAction->isEnabled() )
1933 anOrthographicAction->setEnabled( true );
1934 if ( !aPerspectiveAction->isEnabled() )
1935 aPerspectiveAction->setEnabled( true );
1940 \brief Perform "fit all" transformation.
1942 void OCCViewer_ViewWindow::onFitAll()
1944 emit vpTransformationStarted( FITALLVIEW );
1945 if (myModel->fitter())
1946 myModel->fitter()->fitAll(myViewPort->getView());
1948 myViewPort->fitAll();
1949 emit vpTransformationFinished( FITALLVIEW );
1953 \brief Perform "fit selection" transformation.
1955 void OCCViewer_ViewWindow::onFitSelection()
1957 emit vpTransformationStarted( FITSELECTION );
1958 myModel->getAISContext()->FitSelected( getViewPort()->getView() );
1959 emit vpTransformationFinished( FITSELECTION );
1963 \brief Called if 'change rotation point' operation is activated.
1964 \param on action state
1966 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1970 if (!mySetRotationPointDlg)
1972 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1973 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1976 if (!mySetRotationPointDlg->isVisible())
1978 //if (mySetRotationPointDlg->IsFirstShown())
1979 if (myCurrPointType == BBCENTER)
1981 Standard_Real Xcenter, Ycenter, Zcenter;
1982 if (OCCViewer_Utilities::computeVisibleBBCenter(myViewPort->getView(), Xcenter, Ycenter, Zcenter))
1983 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1985 mySetRotationPointDlg->show();
1990 if (mySetRotationPointDlg->isVisible())
1991 mySetRotationPointDlg->hide();
1996 \brief Create one more window with same content.
1998 void OCCViewer_ViewWindow::onCloneView()
2000 SUIT_ViewWindow* vw = myManager->createViewWindow();
2002 emit viewCloned( vw );
2003 OCCViewer_ViewWindow* occVw = dynamic_cast<OCCViewer_ViewWindow*> (vw);
2004 if(occVw && occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)) {
2005 occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)->synchronize(this);
2010 Creates one more window with same content
2012 void OCCViewer_ViewWindow::onAxialScale()
2014 if ( !myScalingDlg )
2015 myScalingDlg = new OCCViewer_AxialScaleDlg( this , myModel );
2017 if ( !myScalingDlg->isVisible() )
2019 myScalingDlg->Update();
2020 myScalingDlg->show();
2025 Shows Graduated Axes dialog
2027 void OCCViewer_ViewWindow::onGraduatedAxes()
2029 myCubeAxesDlg->Update();
2030 myCubeAxesDlg->show();
2033 void OCCViewer_ViewWindow::onAmbientToogle()
2035 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2036 viewer->InitDefinedLights();
2037 while(viewer->MoreDefinedLights())
2039 Handle(V3d_Light) light = viewer->DefinedLight();
2040 if(light->Type() != V3d_AMBIENT)
2042 Handle(V3d_View) aView3d = myViewPort->getView();
2043 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
2044 else viewer->SetLightOn(light);
2046 viewer->NextDefinedLights();
2052 \brief Store view parameters.
2054 void OCCViewer_ViewWindow::onMemorizeView()
2056 appendViewAspect( getViewParams() );
2060 \brief Restore view parameters.
2062 void OCCViewer_ViewWindow::onRestoreView()
2064 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
2065 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
2067 updateViewAspects( aDlg->parameters() );
2068 if( myRestoreFlag && aDlg->parameters().count() )
2069 performRestoring( aDlg->currentItem() );
2073 \brief Restore view parameters.
2074 \param anItem view parameters
2076 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
2078 Handle(V3d_View) aView3d = myViewPort->getView();
2080 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
2081 aView3d->SetScale( anItem.scale );
2082 aView3d->SetTwist( anItem.twist );
2083 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
2084 aView3d->SetImmediateUpdate( prev );
2085 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2086 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2087 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
2089 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
2091 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
2093 // "eye" and "at" require conversion to represent center panning
2094 // up direction is only available after setting angle of twist and
2095 // other view parameters
2096 aView3d->Up( anUpX, anUpY, anUpZ );
2098 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
2099 gp_Dir anUp( anUpX, anUpY, anUpZ );
2100 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
2101 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2102 gp_Dir aSide = aProj ^ anUp;
2104 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
2105 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
2107 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
2108 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2111 if ( !baseParamsOnly ) {
2113 myModel->setTrihedronShown( anItem.isVisible );
2114 myModel->setTrihedronSize( anItem.size );
2116 myModel->setViewCubeShown( anItem.vcIsVisible );
2118 // graduated trihedron
2119 bool anIsVisible = anItem.gtIsVisible;
2120 OCCViewer_AxisWidget::AxisData anAxisData[3];
2121 anAxisData[0].DrawName = anItem.gtDrawNameX;
2122 anAxisData[1].DrawName = anItem.gtDrawNameZ;
2123 anAxisData[2].DrawName = anItem.gtDrawNameZ;
2124 anAxisData[0].Name = anItem.gtNameX;
2125 anAxisData[1].Name = anItem.gtNameZ;
2126 anAxisData[2].Name = anItem.gtNameZ;
2127 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
2128 anItem.gtNameColorGX,
2129 anItem.gtNameColorBX );
2130 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
2131 anItem.gtNameColorGY,
2132 anItem.gtNameColorBY );
2133 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
2134 anItem.gtNameColorGZ,
2135 anItem.gtNameColorBZ );
2136 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
2137 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
2138 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
2139 anAxisData[0].NbValues = anItem.gtNbValuesX;
2140 anAxisData[1].NbValues = anItem.gtNbValuesY;
2141 anAxisData[2].NbValues = anItem.gtNbValuesZ;
2142 anAxisData[0].Offset = anItem.gtOffsetX;
2143 anAxisData[1].Offset = anItem.gtOffsetY;
2144 anAxisData[2].Offset = anItem.gtOffsetZ;
2145 anAxisData[0].Color = QColor( anItem.gtColorRX,
2148 anAxisData[1].Color = QColor( anItem.gtColorRY,
2151 anAxisData[2].Color = QColor( anItem.gtColorRZ,
2154 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
2155 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
2156 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
2157 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
2158 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
2159 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
2161 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
2162 myCubeAxesDlg->ApplyData( aView3d );
2164 } // if ( !baseParamsOnly )
2170 \brief Set restore flag.
2172 void OCCViewer_ViewWindow::setRestoreFlag()
2178 \brief Called when action "show/hide trihedron" is activated.
2180 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
2182 myModel->setTrihedronShown(show);
2186 \brief Called when action "show/hide view cube" is activated.
2188 void OCCViewer_ViewWindow::onViewCubeShow(bool show)
2190 myModel->setViewCubeShown(show);
2194 \brief Toggles preselection (highlighting) on/off
2196 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
2198 myPreselectionEnabled = on;
2199 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
2201 // unhighlight all highlighted objects
2203 myModel->unHighlightAll( true, false );
2206 // update action state if method is called outside
2207 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2208 if ( a && a->isChecked() != on ) {
2209 a->setChecked( on );
2214 \brief Toggles selection on/off
2216 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
2218 mySelectionEnabled = on;
2219 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
2221 // update action state if method is called outside
2224 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2226 a->setEnabled( on );
2230 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
2231 if ( a && a->isChecked() != on ) {
2232 a->setChecked( on );
2237 \brief Switches style of advanced multiple selection by Poligon/Circle
2239 void OCCViewer_ViewWindow::onSwitchSelectionStyle(QAction* theAction)
2242 OCCViewer_ViewSketcher* aSkecher = getSketcher(Polygon);
2244 if (theAction == toolMgr()->action(PolygonSelectionStyleId)) {
2245 aSkecher->setSketcherMode(OCCViewer_PolygonSketcher::Poligone);
2247 else if (theAction == toolMgr()->action(CircleSelectionStyleId)) {
2248 aSkecher->setSketcherMode(OCCViewer_PolygonSketcher::Circle);
2254 Returns currently selected selection style
2256 OCCViewer_ViewWindow::SelectionStyle OCCViewer_ViewWindow::selectionStyle() const
2258 if (toolMgr()->action(PolygonSelectionStyleId)->isChecked())
2259 return PolygonStyle;
2260 if (toolMgr()->action(CircleSelectionStyleId)->isChecked())
2265 void OCCViewer_ViewWindow::setSelectionStyle(SelectionStyle theMode)
2267 toolMgr()->action(RectangleSelectionStyleId)->setChecked(false);
2268 toolMgr()->action(PolygonSelectionStyleId)->setChecked(false);
2269 toolMgr()->action(CircleSelectionStyleId)->setChecked(false);
2272 toolMgr()->action(RectangleSelectionStyleId)->setChecked(true);
2275 toolMgr()->action(PolygonSelectionStyleId)->setChecked(true);
2278 toolMgr()->action(CircleSelectionStyleId)->setChecked(true);
2283 \brief Switches "keyboard free" interaction style on/off
2285 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
2287 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
2289 // update action state if method is called outside
2290 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
2291 if ( a && a->isChecked() != on )
2292 a->setChecked( on );
2296 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
2298 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
2300 myViewPort->setAdvancedZoomingEnabled( on );
2302 // update action state if method is called outside
2303 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
2304 if ( a && a->isChecked() != on )
2305 a->setChecked( on );
2309 \brief Get current interaction style
2310 \return interaction style
2312 int OCCViewer_ViewWindow::interactionStyle() const
2314 return myInteractionStyle;
2318 \brief Set current interaction style
2319 \param theStyle interaction style
2321 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
2323 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
2327 \brief Get current zooming style
2328 \return zooming style
2330 int OCCViewer_ViewWindow::zoomingStyle() const
2332 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
2336 \brief Set current zooming style
2337 \param theStyle zooming style
2339 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
2341 onSwitchZoomingStyle( theStyle == 1 );
2345 \brief Dump view window contents to the pixmap.
2346 \return pixmap containing all scene rendered in the window
2348 //#define USE_OLD_IMPLEMENTATION
2349 QImage OCCViewer_ViewWindow::dumpView()
2351 Handle(V3d_View) view = myViewPort->getView();
2352 if ( view.IsNull() )
2355 int aWidth = myViewPort->width();
2356 int aHeight = myViewPort->height();
2358 #ifdef USE_OLD_IMPLEMENTATION
2359 // rnv: Old approach to dump the OCCViewer content via Frame Buffer Object
2363 #ifndef DISABLE_GLVIEWER
2364 OpenGLUtils_FrameBuffer aFrameBuffer;
2365 if ( aFrameBuffer.init( aWidth, aHeight ) )
2367 glPushAttrib( GL_VIEWPORT_BIT );
2368 glViewport( 0, 0, aWidth, aHeight );
2369 aFrameBuffer.bind();
2374 aFrameBuffer.unbind();
2377 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
2379 aFrameBuffer.bind();
2380 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
2381 aFrameBuffer.unbind();
2383 anImage = anImage.rgbSwapped();
2384 anImage = anImage.mirrored();
2388 // if frame buffers are unsupported, use old approach
2390 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
2391 QPoint p = myViewPort->mapFromParent( myViewPort->geometry().topLeft() );
2392 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
2394 QImage anImage( data, aWidth, aHeight, QImage::Format_ARGB32 );
2395 anImage = anImage.mirrored();
2396 anImage = anImage.rgbSwapped();
2399 #else // DISABLE_GLVIEWER
2403 #endif // DISABLE_GLVIEWER
2405 #else // USE_OLD_IMPLEMENTATION
2406 // rnv: New approach is to use OCCT built-in procedure
2409 view->ToPixMap(aPix, aWidth, aHeight, Graphic3d_BT_RGB);
2411 QImage anImage( aWidth, aHeight, QImage::Format_ARGB32 );
2412 for ( int i = 0; i < aWidth; i++ ) {
2413 for ( int j = 0; j < aHeight; j++ ) {
2414 Quantity_Color pixel = aPix.PixelColor( i, j ).GetRGB();
2415 QColor color = QColor::fromRgbF( pixel.Red(), pixel.Green(), pixel.Blue() );
2416 anImage.setPixelColor( i, j, color );
2420 if ( aPix.IsTopDown() )
2421 anImage = anImage.mirrored();
2424 #endif // USE_OLD_IMPLEMENTATION
2427 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& /*img*/,
2428 const QString& fileName,
2429 const QString& /*format*/ )
2432 QApplication::setOverrideCursor( Qt::WaitCursor );
2434 res = myViewPort->getView()->Dump( fileName.toStdString().c_str() );
2436 QApplication::restoreOverrideCursor();
2441 QString OCCViewer_ViewWindow::filter() const
2443 // OCCT version > 7.3.0 is not support export to PS and EPS
2444 QString formats = tr( "OCC_IMAGE_FILES" );
2445 return formats.remove(" *.eps *.ps");
2450 \brief Set parameters of the cutting plane
2451 \param on if \c true, cutting plane is enabled
2452 \param x X position of plane point
2453 \param y Y position of plane point
2454 \param z Z position of plane point
2455 \param dx X coordinate of plane normal
2456 \param dy Y coordinate of plane normal
2457 \param dz Z coordinate of plane normal
2459 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2460 const double dx, const double dy, const double dz )
2462 Handle(V3d_View) view = myViewPort->getView();
2463 if ( view.IsNull() )
2467 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2469 // try to use already existing plane or create a new one
2470 Handle(V3d_Plane) clipPlane;
2472 // calculate new a,b,c,d values for the plane
2473 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2475 pln.Coefficients(a, b, c, d);
2476 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2477 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2478 if(aPlanes->Size() > 0 ) {
2479 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2480 aClipPlane->SetEquation(pln);
2481 aClipPlane->SetOn(Standard_True);
2483 view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2487 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2488 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2489 for( ;anIter.More();anIter.Next() ){
2490 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2491 aClipPlane->SetOn(Standard_False);
2499 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2501 gp_Dir aDir = pln.Axis().Direction();
2502 gp_Pnt aPnt = pln.Location();
2503 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2508 \brief Check if any cutting plane is enabled
2509 \return \c true if at least one cutting plane is enabled
2511 bool OCCViewer_ViewWindow::isCuttingPlane()
2513 Handle(V3d_View) view = myViewPort->getView();
2515 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2516 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2517 for( ;anIter.More();anIter.Next() ) {
2518 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2519 if(aClipPlane->IsOn()) {
2528 \brief Get the visual parameters of the view window.
2529 \return visual parameters of view window
2531 viewAspect OCCViewer_ViewWindow::getViewParams() const
2533 double projX, projY, projZ, twist;
2534 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2535 double aScaleX, aScaleY, aScaleZ;
2537 Handle(V3d_View) aView3d = myViewPort->getView();
2539 aView3d->Proj( projX, projY, projZ );
2540 aView3d->At( atX, atY, atZ );
2541 aView3d->Eye( eyeX, eyeY, eyeZ );
2542 twist = aView3d->Twist();
2544 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2546 bool isShown = myModel->isTrihedronVisible();
2547 double size = myModel->trihedronSize();
2549 bool isVCShown = myModel->isViewCubeVisible();
2551 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2554 params.scale = aView3d->Scale();
2555 params.projX = projX;
2556 params.projY = projY;
2557 params.projZ = projZ;
2558 params.twist = twist;
2565 params.scaleX = aScaleX;
2566 params.scaleY = aScaleY;
2567 params.scaleZ = aScaleZ;
2568 params.name = aName;
2571 params.isVisible= isShown;
2575 params.vcIsVisible= isVCShown;
2577 // graduated trihedron
2578 bool anIsVisible = false;
2579 OCCViewer_AxisWidget::AxisData anAxisData[3];
2580 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2582 params.gtIsVisible = anIsVisible;
2583 params.gtDrawNameX = anAxisData[0].DrawName;
2584 params.gtDrawNameY = anAxisData[1].DrawName;
2585 params.gtDrawNameZ = anAxisData[2].DrawName;
2586 params.gtNameX = anAxisData[0].Name;
2587 params.gtNameY = anAxisData[1].Name;
2588 params.gtNameZ = anAxisData[2].Name;
2589 params.gtNameColorRX = anAxisData[0].NameColor.red();
2590 params.gtNameColorGX = anAxisData[0].NameColor.green();
2591 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2592 params.gtNameColorRY = anAxisData[1].NameColor.red();
2593 params.gtNameColorGY = anAxisData[1].NameColor.green();
2594 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2595 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2596 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2597 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2598 params.gtDrawValuesX = anAxisData[0].DrawValues;
2599 params.gtDrawValuesY = anAxisData[1].DrawValues;
2600 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2601 params.gtNbValuesX = anAxisData[0].NbValues;
2602 params.gtNbValuesY = anAxisData[1].NbValues;
2603 params.gtNbValuesZ = anAxisData[2].NbValues;
2604 params.gtOffsetX = anAxisData[0].Offset;
2605 params.gtOffsetY = anAxisData[1].Offset;
2606 params.gtOffsetZ = anAxisData[2].Offset;
2607 params.gtColorRX = anAxisData[0].Color.red();
2608 params.gtColorGX = anAxisData[0].Color.green();
2609 params.gtColorBX = anAxisData[0].Color.blue();
2610 params.gtColorRY = anAxisData[1].Color.red();
2611 params.gtColorGY = anAxisData[1].Color.green();
2612 params.gtColorBY = anAxisData[1].Color.blue();
2613 params.gtColorRZ = anAxisData[2].Color.red();
2614 params.gtColorGZ = anAxisData[2].Color.green();
2615 params.gtColorBZ = anAxisData[2].Color.blue();
2616 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2617 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2618 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2619 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2620 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2621 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2627 \brief Get visual parameters of this view window.
2628 \return visual parameters of view window
2630 QString OCCViewer_ViewWindow::getVisualParameters()
2632 viewAspect params = getViewParams();
2636 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2637 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2638 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2639 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2640 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2641 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2642 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2643 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2644 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2645 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2646 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2647 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2648 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2649 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2650 data << QString( "isVisible=%1" ).arg( params.isVisible );
2651 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2653 ClipPlanesList aPlanes = myModel->getClipPlanes();
2654 for ( int i=0; i < (int)aPlanes.size(); i++ )
2656 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2657 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2658 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2659 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2660 switch ( aPlane.Mode )
2662 case OCCViewer_ClipPlane::Absolute :
2664 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2666 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2668 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2669 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2670 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2674 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2679 case OCCViewer_ClipPlane::Relative :
2681 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2682 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2683 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2688 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2689 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2690 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2691 data << ClippingPlane;
2694 // graduated trihedron
2695 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2696 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2697 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2698 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2699 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2700 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2701 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2702 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2703 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2704 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2705 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2706 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2707 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2708 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2709 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2710 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2711 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2712 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2713 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2714 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2715 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2716 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2717 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2718 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2719 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2720 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2721 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2722 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2723 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2724 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2725 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2726 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2727 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2728 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2729 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2730 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2731 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2732 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2733 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2734 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2736 // ray tracing parameters
2737 Graphic3d_RenderingParams rendParams = this->getViewPort()->getView()->RenderingParams();
2738 if ( rendParams.Method == Graphic3d_RM_RAYTRACING ) {
2739 QString RayTracing = "rayTracing=";
2740 RayTracing += QString( "rtDepth~%1;" ).arg( rendParams.RaytracingDepth );
2741 RayTracing += QString( "rtReflection~%1;" ).arg( rendParams.IsReflectionEnabled );
2742 RayTracing += QString( "rtAntialiasing~%1;" ).arg( rendParams.IsAntialiasingEnabled );
2743 RayTracing += QString( "rtShadow~%1;" ).arg( rendParams.IsShadowEnabled );
2744 RayTracing += QString( "rtTransShadow~%1;" ).arg( rendParams.IsTransparentShadowEnabled );
2748 // environment texture parameters
2749 Handle(Graphic3d_TextureEnv) aTexture = this->getViewPort()->getView()->TextureEnv();
2750 if ( !aTexture.IsNull() ) {
2751 QString EnvTexture = "envTexture=";
2752 if ( aTexture->Name() == Graphic3d_NOT_ENV_UNKNOWN ) {
2753 TCollection_AsciiString aFileName;
2754 aTexture->Path().SystemName( aFileName );
2755 EnvTexture += QString( "etFile~%1;" ).arg( aFileName.ToCString() );
2758 EnvTexture += QString( "etNumber~%1;" ).arg( aTexture->Name() );
2762 // light source parameters
2763 myModel->getViewer3d()->InitDefinedLights();
2764 while ( myModel->getViewer3d()->MoreDefinedLights() )
2766 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2767 if ( aLight->Type() != V3d_AMBIENT ) {
2768 QString LightSource = QString( "lightSource=" );
2769 LightSource += QString( "lightType~%1;" ).arg( aLight->Type() );
2771 if ( aLight->Type() == V3d_DIRECTIONAL )
2772 Handle(V3d_DirectionalLight)::DownCast( aLight )->Direction( aX, aY, aZ );
2773 else if ( aLight->Type() == V3d_POSITIONAL )
2774 Handle(V3d_PositionalLight)::DownCast( aLight )->Position( aX, aY, aZ );
2776 continue; // not supported type of light source
2777 LightSource += QString( "lightX~%1;" ).arg( aX );
2778 LightSource += QString( "lightY~%1;" ).arg( aY );
2779 LightSource += QString( "lightZ~%1;" ).arg( aZ );
2780 LightSource += QString( "lightColorR~%1;" ).arg( aLight->Color().Red() );
2781 LightSource += QString( "lightColorG~%1;" ).arg( aLight->Color().Green() );
2782 LightSource += QString( "lightColorB~%1;" ).arg( aLight->Color().Blue() );
2783 LightSource += QString( "lightHeadlight~%1;" ).arg( aLight->Headlight() );
2784 data << LightSource;
2786 myModel->getViewer3d()->NextDefinedLights();
2789 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2790 data << QString( "background=%1" ).arg( bg );
2792 return data.join("*");
2796 \brief Restore visual parameters of the view window.
2797 \param parameters visual parameters of view window
2799 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2802 ClipPlanesList aClipPlanes;
2803 QStringList data = parameters.split( '*' );
2804 Qtx::BackgroundData bgData;
2805 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2807 foreach( QString param, data ) {
2808 QString paramName = param.section( '=', 0, 0 ).trimmed();
2809 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2810 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2811 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2812 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2813 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2814 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2815 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2816 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2817 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2818 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2819 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2820 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2821 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2822 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2823 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2824 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2825 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2826 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2827 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2828 else if ( paramName.contains( "ClippingPlane" ) )
2830 QStringList ClipPlaneData = paramValue.split( ';' );
2831 OCCViewer_ClipPlane aPlane;
2832 foreach( QString ClipPlaneParam, ClipPlaneData )
2834 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2835 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2836 if ( ClipPlane_paramName == "Mode" )
2838 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2840 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2841 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2842 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2843 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2846 switch ( aPlane.Mode )
2848 case OCCViewer_ClipPlane::Absolute :
2849 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2850 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2851 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2852 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2853 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2856 case OCCViewer_ClipPlane::Relative :
2857 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2858 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2859 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2864 aClipPlanes.push_back(aPlane);
2866 // graduated trihedron
2867 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2868 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2869 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2870 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2871 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2872 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2873 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2874 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2875 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2876 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2877 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2878 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2879 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2880 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2881 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2882 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2883 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2884 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2885 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2886 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2887 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2888 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2889 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2890 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2891 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2892 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2893 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2894 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2895 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2896 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2897 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2898 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2899 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2900 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2901 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2902 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2903 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2904 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2905 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2906 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2907 else if ( paramName == "rayTracing" )
2909 Graphic3d_RenderingParams& rendParams = this->getViewPort()->getView()->ChangeRenderingParams();
2910 rendParams.Method = Graphic3d_RM_RAYTRACING;
2911 QStringList rtData = paramValue.split( ';' );
2912 foreach( QString rtParam, rtData )
2914 QString rt_paramName = rtParam.section( '~', 0, 0 ).trimmed();
2915 QString rt_paramValue = rtParam.section( '~', 1, 1 ).trimmed();
2916 if ( rt_paramName == "rtDepth" ) rendParams.RaytracingDepth = rt_paramValue.toInt();
2917 else if ( rt_paramName == "rtReflection" ) rendParams.IsReflectionEnabled = rt_paramValue.toInt();
2918 else if ( rt_paramName == "rtAntialiasing" ) rendParams.IsAntialiasingEnabled = rt_paramValue.toInt();
2919 else if ( rt_paramName == "rtShadow" ) rendParams.IsShadowEnabled = rt_paramValue.toInt();
2920 else if ( rt_paramName == "rtTransShadow" ) rendParams.IsTransparentShadowEnabled = rt_paramValue.toInt();
2923 else if ( paramName == "envTexture" )
2925 Handle(Graphic3d_TextureEnv) aTexture;
2926 QStringList etData = paramValue.split( ';' );
2927 foreach( QString etParam, etData )
2929 QString et_paramName = etParam.section( '~', 0, 0 ).trimmed();
2930 QString et_paramValue = etParam.section( '~', 1, 1 ).trimmed();
2931 if ( et_paramName == "etNumber" )
2932 aTexture = new Graphic3d_TextureEnv( Graphic3d_NameOfTextureEnv( et_paramValue.toInt() ) );
2933 else if ( et_paramName == "etFile" )
2934 aTexture = new Graphic3d_TextureEnv( TCollection_AsciiString( et_paramValue.toStdString().c_str() ) );
2935 Handle(V3d_View) aView = this->getViewPort()->getView();
2936 aView->SetTextureEnv( aTexture );
2939 else if ( paramName == "lightSource" )
2941 myModel->getViewer3d()->InitDefinedLights();
2942 while ( myModel->getViewer3d()->MoreDefinedLights() )
2944 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2945 if( aLight->Type() != V3d_AMBIENT ) {
2946 myModel->getViewer3d()->DelLight( aLight );
2947 myModel->getViewer3d()->InitDefinedLights();
2949 myModel->getViewer3d()->NextDefinedLights();
2952 double aX = 0., aY = 0., aZ = 0.;
2953 double cR = 0., cG = 0., cB = 0.;
2954 V3d_TypeOfLight aType = (V3d_TypeOfLight)-1; // not specified
2955 bool isHeadlight = false;
2956 QStringList lsData = paramValue.split( ';' );
2957 foreach( QString lsParam, lsData )
2959 QString ls_paramName = lsParam.section( '~', 0, 0 ).trimmed();
2960 QString ls_paramValue = lsParam.section( '~', 1, 1 ).trimmed();
2961 if ( ls_paramName == "lightType" ) aType = V3d_TypeOfLight( ls_paramValue.toInt() );
2962 else if ( ls_paramName == "lightX" ) aX = ls_paramValue.toDouble();
2963 else if ( ls_paramName == "lightY" ) aY = ls_paramValue.toDouble();
2964 else if ( ls_paramName == "lightZ" ) aZ = ls_paramValue.toDouble();
2965 else if ( ls_paramName == "lightColorR" ) cR = ls_paramValue.toDouble();
2966 else if ( ls_paramName == "lightColorG" ) cG = ls_paramValue.toDouble();
2967 else if ( ls_paramName == "lightColorB" ) cB = ls_paramValue.toDouble();
2968 else if ( ls_paramName == "lightHeadlight" ) isHeadlight = ls_paramValue.toInt();
2970 Quantity_Color aColor = Quantity_Color( cR, cG, cB, Quantity_TOC_RGB );
2971 if( aType == V3d_DIRECTIONAL ) {
2972 Handle(V3d_DirectionalLight) aLight = new V3d_DirectionalLight();
2973 myModel->getViewer3d()->AddLight( aLight );
2974 aLight->SetDirection( aX, aY, aZ );
2975 aLight->SetColor( aColor );
2976 aLight->SetHeadlight( isHeadlight );
2977 myModel->getViewer3d()->SetLightOn( aLight );
2979 else if( aType == V3d_POSITIONAL ) {
2980 Handle(V3d_PositionalLight) aLight = new V3d_PositionalLight( gp_Pnt(aX, aY, aZ), aColor.Name() );
2981 myModel->getViewer3d()->AddLight( aLight );
2982 aLight->SetHeadlight( isHeadlight );
2983 myModel->getViewer3d()->SetLightOn( aLight );
2986 else if ( paramName == "background" ) {
2987 QString bg = paramValue.replace( "$", "=" );
2988 bgData = Qtx::stringToBackground( bg );
2992 else // old format - "1.000e+00*0.000e+00..."
2995 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2996 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2997 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2998 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2999 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
3000 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
3001 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
3002 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
3003 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
3004 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
3005 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
3006 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
3007 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
3008 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
3009 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
3010 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
3011 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
3012 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
3014 performRestoring( params );
3015 setBackground( bgData );
3016 myModel->setClipPlanes(aClipPlanes);
3020 \brief Handle show event.
3022 Emits Show() signal.
3024 \param theEvent show event
3026 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
3028 emit Show( theEvent );
3032 \brief Handle hide event.
3034 Emits Hide() signal.
3036 \param theEvent hide event
3038 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
3040 emit Hide( theEvent );
3045 Save old cursor. [ protected ]
3047 void OCCViewer_ViewWindow::saveCursor()
3049 QCursor* aCursor = NULL;
3051 aCursor = myViewPort->getDefaultCursor();
3052 myCursor = ( aCursor ? *aCursor : cursor() );
3057 Creates default sketcher. [ virtual protected ]
3059 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
3062 return new OCCViewer_RectSketcher( this, type );
3063 if ( type == Polygon )
3064 return new OCCViewer_PolygonSketcher( this, type );
3068 void OCCViewer_ViewWindow::initSketchers()
3070 if ( mySketchers.isEmpty() )
3072 mySketchers.append( createSketcher( Rect ) );
3073 mySketchers.append( createSketcher( Polygon ) );
3077 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ ) const
3079 OCCViewer_ViewSketcher* sketcher = 0;
3080 QList<OCCViewer_ViewSketcher*>::ConstIterator it;
3081 for ( it = mySketchers.cbegin(); it != mySketchers.cend() && !sketcher; ++it )
3083 OCCViewer_ViewSketcher* sk = (*it);
3084 if ( sk->type() == typ )
3091 Handles requests for sketching in the active view. [ virtual public ]
3093 void OCCViewer_ViewWindow::activateSketching( int type )
3095 OCCViewer_ViewPort3d* vp = getViewPort();
3099 if ( !vp->isSketchingEnabled() )
3102 /* Finish current sketching */
3103 if ( type == NoSketching )
3107 onSketchingFinished();
3108 mypSketcher->deactivate();
3112 /* Activate new sketching */
3115 activateSketching( NoSketching ); /* concurrency not suported */
3116 mypSketcher = getSketcher( type );
3119 mypSketcher->activate();
3120 onSketchingStarted();
3126 Unhilights detected entities. [ virtual protected ]
3128 void OCCViewer_ViewWindow::onSketchingStarted()
3133 Selection by rectangle or polygon. [ virtual protected ]
3135 void OCCViewer_ViewWindow::onSketchingFinished()
3137 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()");
3138 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
3140 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
3141 bool append = mypSketcher->isHasShift();
3142 switch( mypSketcher->type() )
3146 QRect* aRect = (QRect*)mypSketcher->data();
3149 int aLeft = aRect->left();
3150 int aRight = aRect->right();
3151 int aTop = aRect->top();
3152 int aBottom = aRect->bottom();
3156 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False);
3158 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False);
3164 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
3165 if( aPolygon && (aPolygon->size() > 2))
3167 int size = aPolygon->size();
3168 TColgp_Array1OfPnt2d anArray(1, size);
3170 QPolygon::Iterator it = aPolygon->begin();
3171 QPolygon::Iterator itEnd = aPolygon->end();
3172 for (int index = 1; it != itEnd; ++it, index++)
3174 QPoint aPoint = *it;
3175 anArray.SetValue(index, gp_Pnt2d(aPoint.x(), aPoint.y()));
3179 ic->ShiftSelect(anArray, getViewPort()->getView(), Standard_False);
3181 ic->Select(anArray, getViewPort()->getView(), Standard_False);
3189 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
3190 aViewMgr->getOCCViewer()->performSelectionChanged();
3194 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
3199 bool OCCViewer_ViewWindow::transformRequested() const
3201 return ( myOperation != NOVIEWOP );
3204 bool OCCViewer_ViewWindow::transformInProcess() const
3206 return myEventStarted;
3209 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
3211 myEventStarted = bOn;
3215 Set enabled state of transformation (rotate, zoom, etc)
3217 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
3219 if ( id != NOVIEWOP ) myStatus.insert( id, on );
3223 \return enabled state of transformation (rotate, zoom, etc)
3225 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
3227 return myStatus.contains( id ) ? myStatus[ id ] : true;
3230 void OCCViewer_ViewWindow::onMaximizedView()
3232 setMaximized(!isMaximized());
3235 void OCCViewer_ViewWindow::returnTo3dView()
3237 setReturnedTo3dView( true );
3240 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
3242 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
3243 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
3244 if ( !isVisible3dView )
3245 toolMgr()->show( ReturnTo3dViewId );
3247 toolMgr()->hide( ReturnTo3dViewId );
3248 if ( isVisible3dView ) emit returnedTo3d( );
3252 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
3254 QAction* anAction = toolMgr()->action( MaximizedId );
3255 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
3256 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
3258 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
3259 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
3260 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
3261 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
3262 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
3264 emit maximized( this, true );
3268 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
3269 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
3270 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
3271 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
3272 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
3274 emit maximized( this, false );
3279 bool OCCViewer_ViewWindow::isMaximized() const
3281 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
3284 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
3286 IsSketcherStyle = enable;
3289 bool OCCViewer_ViewWindow::isSketcherStyle() const
3291 return IsSketcherStyle;
3295 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
3300 int OCCViewer_ViewWindow::projectionType() const
3302 int mode = Orthographic;
3303 Handle(V3d_View) aView3d = myViewPort->getView();
3304 if ( !aView3d.IsNull() ) {
3305 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3306 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Perspective)
3308 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Orthographic)
3309 mode = Orthographic;
3310 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
3316 void OCCViewer_ViewWindow::setStereoType( int type )
3318 Handle(V3d_View) aView3d = myViewPort->getView();
3319 if ( !aView3d.IsNull() ) {
3320 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3321 aParams->StereoMode = (Graphic3d_StereoMode)type;
3325 int OCCViewer_ViewWindow::stereoType() const
3327 int type = QuadBuffer;
3328 Handle(V3d_View) aView3d = myViewPort->getView();
3329 if ( !aView3d.IsNull() ) {
3330 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3331 type = (OCCViewer_ViewWindow::StereoType)aParams->StereoMode;
3336 void OCCViewer_ViewWindow::setAnaglyphFilter( int type )
3338 Handle(V3d_View) aView3d = myViewPort->getView();
3339 if ( !aView3d.IsNull() ) {
3340 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3341 if (type == RedCyan)
3342 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
3343 if (type == YellowBlue)
3344 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
3345 if (type == GreenMagenta)
3346 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
3350 int OCCViewer_ViewWindow::anaglyphFilter() const
3353 Handle(V3d_View) aView3d = myViewPort->getView();
3354 if ( !aView3d.IsNull() ) {
3355 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3356 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized)
3358 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized)
3360 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple)
3361 type = GreenMagenta;
3366 void OCCViewer_ViewWindow::setStereographicFocus( int type, double value )
3368 Handle(V3d_View) aView3d = myViewPort->getView();
3369 if ( !aView3d.IsNull() ) {
3370 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3371 aCamera->SetZFocus( (Graphic3d_Camera::FocusType) type, value );
3375 int OCCViewer_ViewWindow::stereographicFocusType() const
3377 int type = Relative;
3378 Handle(V3d_View) aView3d = myViewPort->getView();
3379 if ( !aView3d.IsNull() ) {
3380 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3381 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->ZFocusType();
3386 double OCCViewer_ViewWindow::stereographicFocusValue() const
3389 Handle(V3d_View) aView3d = myViewPort->getView();
3390 if ( !aView3d.IsNull() ) {
3391 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3392 value = aCamera->ZFocus();
3397 void OCCViewer_ViewWindow::setInterocularDistance( int type, double value )
3399 Handle(V3d_View) aView3d = myViewPort->getView();
3400 if ( !aView3d.IsNull() ) {
3401 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3402 aCamera->SetIOD( (Graphic3d_Camera::IODType) type, value );
3406 int OCCViewer_ViewWindow::interocularDistanceType() const
3408 int type = Relative;
3409 Handle(V3d_View) aView3d = myViewPort->getView();
3410 if ( !aView3d.IsNull() ) {
3411 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3412 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->GetIODType();
3417 double OCCViewer_ViewWindow::interocularDistanceValue() const
3419 double value = 0.05;
3420 Handle(V3d_View) aView3d = myViewPort->getView();
3421 if ( !aView3d.IsNull() ) {
3422 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3423 value = aCamera->IOD();
3428 void OCCViewer_ViewWindow::setReverseStereo( bool reverse )
3430 Handle(V3d_View) aView3d = myViewPort->getView();
3431 if ( !aView3d.IsNull() ) {
3432 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3433 aParams->ToReverseStereo = reverse;
3437 bool OCCViewer_ViewWindow::isReverseStereo() const
3439 int reverse = false;
3440 Handle(V3d_View) aView3d = myViewPort->getView();
3441 if ( !aView3d.IsNull() ) {
3442 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3443 reverse = aParams->ToReverseStereo;
3448 void OCCViewer_ViewWindow::setVSync( bool enable )
3450 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3451 if ( !anIntCont.IsNull() ) {
3452 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3453 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3454 aCaps->swapInterval = enable;
3458 bool OCCViewer_ViewWindow::isVSync() const
3461 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3462 if ( !anIntCont.IsNull() ) {
3463 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3464 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3465 enable = aCaps->swapInterval;
3470 void OCCViewer_ViewWindow::setQuadBufferSupport( bool enable )
3472 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3473 if ( !anIntCont.IsNull() ) {
3474 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3475 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3476 aCaps->contextStereo = enable;
3480 bool OCCViewer_ViewWindow::isQuadBufferSupport() const
3483 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3484 if ( !anIntCont.IsNull() ) {
3485 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3486 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3487 enable = aCaps->contextStereo;
3492 bool OCCViewer_ViewWindow::isOpenGlStereoSupport() const
3494 GLboolean support[1];
3495 glGetBooleanv (GL_STEREO, support);
3502 QColor OCCViewer_ViewWindow::backgroundColor() const
3504 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
3508 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
3510 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
3513 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
3515 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
3518 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
3520 if ( myViewPort ) myViewPort->setBackground( theBackground );
3523 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
3525 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
3531 void OCCViewer_ViewWindow::clearViewAspects()
3533 myViewAspects.clear();
3537 \return const reference to list of view aspects
3539 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
3541 return myViewAspects;
3545 Appends new view aspect
3546 \param aParams - new view aspects
3548 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
3550 myViewAspects.append( aParams );
3554 Replaces old view aspects by new ones
3555 \param aViewList - list of new view aspects
3557 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
3559 myViewAspects = aViewList;
3563 Get camera properties for the OCC view window.
3564 \return shared pointer on camera properties.
3566 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
3568 SUIT_CameraProperties aProps;
3570 Handle(V3d_View) aSourceView = getViewPort()->getView();
3571 if ( aSourceView.IsNull() )
3574 if ( get2dMode() == No2dMode ) {
3575 aProps.setDimension( SUIT_CameraProperties::Dim3D );
3578 aProps.setDimension( SUIT_CameraProperties::Dim2D );
3579 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
3582 // read common properites of the view
3583 Standard_Real anUp[3];
3584 Standard_Real anAt[3];
3585 Standard_Real anEye[3];
3586 Standard_Real aProj[3];
3587 Standard_Real anAxialScale[3];
3589 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
3590 aSourceView->At( anAt[0], anAt[1], anAt[2] );
3591 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
3592 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3594 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3595 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
3597 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
3599 // store camera properties "as is": it is up to synchronized
3600 // view classes to provide necessary property conversion.
3601 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
3602 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
3604 if ( aSourceView->Camera()->IsOrthographic() )
3606 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
3607 aProps.setViewAngle( 0.0 );
3611 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
3612 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
3614 aProps.setMappingScale( aSourceView->Camera()->Scale() );
3621 This implementation synchronizes OCC view's camera propreties.
3623 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
3625 bool blocked = blockSignals( true );
3627 SUIT_CameraProperties aProps = theView->cameraProperties();
3628 if ( !cameraProperties().isCompatible( aProps ) ) {
3629 // other view, this one is being currently synchronized to, seems has become incompatible
3630 // we have to break synchronization
3635 Handle(V3d_View) aDestView = getViewPort()->getView();
3637 aDestView->SetImmediateUpdate( Standard_False );
3640 double aPosition[3];
3641 double aFocalPoint[3];
3642 double anAxialScale[3];
3644 // get common properties
3645 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3646 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
3647 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3648 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3651 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3652 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
3653 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3654 aDestView->Camera()->SetScale( aProps.getMappingScale() );
3656 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3657 aDestView->SetImmediateUpdate( Standard_True );
3658 aDestView->Redraw();
3660 catch (Standard_Failure&) {
3663 blockSignals( blocked );
3667 \brief Indicates whether preselection is enabled
3668 \return true if preselection is enabled
3670 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
3672 return myPreselectionEnabled;
3676 \brief Enables/disables preselection
3677 \param theIsToEnable if true - preselection will be enabled
3679 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
3681 onSwitchPreselection( theIsToEnable );
3685 \brief Indicates whether selection is enabled
3686 \return true if selection is enabled
3688 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3690 return mySelectionEnabled;
3694 \brief Enables/disables selection
3695 \param theIsToEnable if true - selection will be enabled
3697 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3699 onSwitchSelection( theIsToEnable );
3704 \brief called if clipping operation is activated / deactivated.
3706 Enables/disables clipping plane displaying.
3708 \parma on action state
3710 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3712 if(!myModel) return;
3713 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3716 if (!aClippingDlg) {
3717 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3718 myModel->setClippingDlg(aClippingDlg);
3720 if (!aClippingDlg->isVisible())
3721 aClippingDlg->show();
3723 if ( aClippingDlg ) {
3724 aClippingDlg->close();
3725 myModel->setClippingDlg(0);
3729 SUIT_ViewManager* mgr = getViewManager();
3731 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3732 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3733 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3734 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3736 QAction* a = toolMgr()->action( ClippingId );
3738 if(theIsOn != a->isChecked()){
3739 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3740 a->setChecked(theIsOn);
3741 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3748 void OCCViewer_ViewWindow::onRayTracing()
3750 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_RayTracingDlg::getName() ) ) {
3751 QDialog* aDlg = new OCCViewer_RayTracingDlg( this );
3757 void OCCViewer_ViewWindow::onEnvTexture()
3759 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_EnvTextureDlg::getName() ) ) {
3760 QDialog* aDlg = new OCCViewer_EnvTextureDlg( this );
3766 void OCCViewer_ViewWindow::onLightSource()
3768 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_LightSourceDlg::getName() ) ) {
3769 QDialog* aDlg = new OCCViewer_LightSourceDlg( this, myModel );
3775 bool OCCViewer_ViewWindow::isActionVisible( ActionId theId ) const
3777 QAction* a = toolMgr()->action( theId );
3778 return a && a->isVisible();
3781 void OCCViewer_ViewWindow::setActionVisible( ActionId theId, bool isVisible )
3783 QAction* a = toolMgr()->action( theId );
3785 a->setVisible( isVisible );
3788 void OCCViewer_ViewWindow::projAndPanToGravity(V3d_TypeOfOrientation CamOri)
3790 const bool USE_XY = true;
3792 Handle(V3d_View) aView3d = myViewPort->getView();
3793 if (aView3d.IsNull())
3797 double X = 0, Y = 0, Z = 0;
3800 const double EPS = 1E-6;
3801 int xp = myViewPort->width()/2, yp = myViewPort->height()/2;
3802 aView3d->Convert( xp, yp, X, Y, Z );
3804 gp_Dir d = aView3d->Camera()->Direction();
3805 if( fabs( d.Z() ) > EPS )
3807 double t = -Z/d.Z();
3814 // It is really necessary to compute gravity center even if it is not used in part of code below.
3815 // Without this calculation the SetProj() method and other methods are not correct.
3817 IsGr = computeGravityCenter(X2, Y2, Z2);
3819 IsGr = OCCViewer_Utilities::computeSceneBBCenter(aView3d, X2, Y2, Z2);
3821 aView3d->SetProj(CamOri);
3824 //aView3d->Update();
3825 Handle(Graphic3d_Camera) Cam = aView3d->Camera();
3827 gp_Vec dir (Cam->Direction());
3828 gp_Pnt eye = Cam->Eye();
3830 Standard_Real D = dir.Dot(V1);
3831 gp_Pnt ppdir = eye.Translated(D*dir);
3832 gp_Vec V2(ppdir, gp);
3833 gp_XYZ trEye = eye.XYZ() + V2.XYZ();
3835 double xat, yat, zat;
3836 aView3d->At(xat, yat, zat);
3837 gp_Pnt At(xat, yat, zat);
3838 gp_XYZ trAt = At.XYZ() + V2.XYZ();
3839 aView3d->SetEye(trEye.X(), trEye.Y(), trEye.Z());
3840 aView3d->SetAt(trAt.X(), trAt.Y(), trAt.Z());
3845 bool OCCViewer_ViewWindow::isAutomaticZoom() const
3847 return myAutomaticZoom;
3850 void OCCViewer_ViewWindow::setAutomaticZoom(const bool isOn)
3852 myAutomaticZoom = isOn;