1 // Copyright (C) 2007-2023 CEA, EDF, 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_AutoRotate.h"
36 #include "OCCViewer_AxialScaleDlg.h"
37 #include "OCCViewer_CubeAxesDlg.h"
38 #include "OCCViewer_ClippingDlg.h"
39 #include "OCCViewer_RayTracingDlg.h"
40 #include "OCCViewer_EnvTextureDlg.h"
41 #include "OCCViewer_LightSourceDlg.h"
42 #include "OCCViewer_Utilities.h"
44 #include <SUIT_Desktop.h>
45 #include <SUIT_Session.h>
46 #include <SUIT_ViewManager.h>
47 #include <SUIT_Tools.h>
48 #include <SUIT_ResourceMgr.h>
49 #include <SUIT_MessageBox.h>
50 #include <SUIT_Application.h>
52 #include <QtxActionToolMgr.h>
53 #include <QtxMultiAction.h>
54 #include <QtxRubberBand.h>
60 #include <QMouseEvent>
61 #include <QApplication>
62 #include <QActionGroup>
65 #include <AIS_ListOfInteractive.hxx>
66 #include <AIS_ListIteratorOfListOfInteractive.hxx>
67 #include <AIS_Shape.hxx>
69 #include <BRep_Tool.hxx>
70 #include <BRepBndLib.hxx>
71 #include <BRepGProp.hxx>
72 #include <GProp_GProps.hxx>
75 #include <Graphic3d_SequenceOfHClipPlane.hxx>
76 #include <Graphic3d_ClipPlane.hxx>
77 #include <OpenGl_GraphicDriver.hxx>
78 #include <OpenGLUtils_FrameBuffer.h>
79 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
80 #include <Graphic3d_MapOfStructure.hxx>
81 #include <Graphic3d_Structure.hxx>
82 #include <Graphic3d_StereoMode.hxx>
83 #include <Graphic3d_RenderingParams.hxx>
84 #include <Graphic3d_BndBox3d.hxx>
86 #include <V3d_Plane.hxx>
87 #include <V3d_Light.hxx>
91 #include <gp_GTrsf.hxx>
92 #include <TColgp_Array1OfPnt2d.hxx>
94 #include <Image_PixMap.hxx>
96 #include <Standard_Version.hxx>
97 #include <Standard_Failure.hxx>
99 #include "utilities.h"
101 // // OpenCV includes
103 // #include <highgui.h>
105 static QEvent* l_mbPressEvent = 0;
108 //# include <QWindowsStyle>
112 #include <OpenGL/gl.h>
117 // To avoid conflict between KeyPress from the X.h (define KeyPress 2)
118 // and QEvent::KeyPress (qevent.h)
128 // Enable ray tracing features
129 #define ENABLE_RAY_TRACING
131 const char* imageZoomCursor[] = {
136 "................................",
137 "................................",
138 ".#######........................",
139 "..aaaaaaa.......................",
140 "................................",
141 ".............#####..............",
142 "...........##.aaaa##............",
143 "..........#.aa.....a#...........",
144 ".........#.a.........#..........",
145 ".........#a..........#a.........",
146 "........#.a...........#.........",
147 "........#a............#a........",
148 "........#a............#a........",
149 "........#a............#a........",
150 "........#a............#a........",
151 ".........#...........#.a........",
152 ".........#a..........#a.........",
153 ".........##.........#.a.........",
154 "........#####.....##.a..........",
155 ".......###aaa#####.aa...........",
156 "......###aa...aaaaa.......#.....",
157 ".....###aa................#a....",
158 "....###aa.................#a....",
159 "...###aa...............#######..",
160 "....#aa.................aa#aaaa.",
161 ".....a....................#a....",
162 "..........................#a....",
163 "...........................a....",
164 "................................",
165 "................................",
166 "................................",
167 "................................"};
169 const char* imageRotateCursor[] = {
174 "................................",
175 "................................",
176 "................................",
177 "................................",
178 "........#.......................",
179 ".......#.a......................",
180 "......#######...................",
181 ".......#aaaaa#####..............",
182 "........#..##.a#aa##........##..",
183 ".........a#.aa..#..a#.....##.aa.",
184 ".........#.a.....#...#..##.aa...",
185 ".........#a.......#..###.aa.....",
186 "........#.a.......#a..#aa.......",
187 "........#a.........#..#a........",
188 "........#a.........#a.#a........",
189 "........#a.........#a.#a........",
190 "........#a.........#a.#a........",
191 ".........#.........#a#.a........",
192 "........##a........#a#a.........",
193 "......##.a#.......#.#.a.........",
194 "....##.aa..##.....##.a..........",
195 "..##.aa.....a#####.aa...........",
196 "...aa.........aaa#a.............",
197 "................#.a.............",
198 "...............#.a..............",
199 "..............#.a...............",
200 "...............a................",
201 "................................",
202 "................................",
203 "................................",
204 "................................",
205 "................................"};
207 const char* imageCrossCursor[] = {
212 "................................",
213 "................................",
214 "................................",
215 "................................",
216 "................................",
217 "................................",
218 "................................",
219 "...............#................",
220 "...............#a...............",
221 "...............#a...............",
222 "...............#a...............",
223 "...............#a...............",
224 "...............#a...............",
225 "...............#a...............",
226 "...............#a...............",
227 ".......#################........",
228 "........aaaaaaa#aaaaaaaaa.......",
229 "...............#a...............",
230 "...............#a...............",
231 "...............#a...............",
232 "...............#a...............",
233 "...............#a...............",
234 "...............#a...............",
235 "...............#a...............",
236 "................a...............",
237 "................................",
238 "................................",
239 "................................",
240 "................................",
241 "................................",
242 "................................",
243 "................................"};
248 \param theDesktop main window of application
249 \param theModel OCC 3D viewer
251 OCCViewer_ViewWindow::OCCViewer_ViewWindow( SUIT_Desktop* theDesktop,
252 OCCViewer_Viewer* theModel )
253 : SUIT_ViewWindow( theDesktop )
258 myEnableDrawMode = false;
259 myDrawRectEnabled = true;
261 updateEnabledDrawMode();
263 mySetRotationPointDlg = 0;
266 IsSketcherStyle = false;
273 myInteractionStyle = SUIT_ViewModel::STANDARD;
274 myPreselectionEnabled = true;
275 mySelectionEnabled = true;
277 myCursorIsHand = false;
278 myPanningByBtn = false;
279 myAutomaticZoom = true;
287 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
289 if (myAutoRotate) delete myAutoRotate;
291 qDeleteAll( mySketchers );
295 \brief Internal initialization.
297 void OCCViewer_ViewWindow::initLayout()
299 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
300 myViewPort->installEventFilter(this);
301 setCentralWidget(myViewPort);
302 myOperation = NOVIEWOP;
304 myCurrPointType = BBCENTER;
305 myPrevPointType = BBCENTER;
306 mySelectedPoint = gp_Pnt(0.,0.,0.);
307 myRotationPointSelection = false;
309 setTransformRequested ( NOVIEWOP );
310 setTransformInProcess ( false );
329 // Graduated axes dialog
330 QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
331 myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
332 myCubeAxesDlg->initialize();
334 connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
337 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
339 return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
343 \brief Detect viewer operation according the the mouse button pressed
344 and key modifiers used.
345 \param theEvent mouse event
346 \return type of the operation
348 OCCViewer_ViewWindow::OperationType
349 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
351 OperationType aOp = NOVIEWOP;
352 SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
353 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
354 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
356 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
357 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
359 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
360 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
361 (my2dMode == No2dMode))
368 \brief Customize event handling
369 \param watched event receiver object
371 \return \c true if the event processing should be stopped
373 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
375 if ( watched == myViewPort ) {
376 int aType = e->type();
378 case QEvent::MouseButtonPress:
379 vpMousePressEvent((QMouseEvent*) e);
382 case QEvent::MouseButtonRelease:
383 vpMouseReleaseEvent((QMouseEvent*) e);
386 case QEvent::MouseMove:
387 vpMouseMoveEvent((QMouseEvent*) e);
390 case QEvent::MouseButtonDblClick:
391 emit mouseDoubleClicked(this, (QMouseEvent*)e);
396 QWheelEvent* aEvent = (QWheelEvent*) e;
398 if ( aEvent->modifiers().testFlag(Qt::ControlModifier) ) {
399 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
400 if ( isPreselectionEnabled() ) {
401 if ( aEvent->delta() > 0 ) {
402 ic->HilightNextDetected( myViewPort->getView() );
404 ic->HilightPreviousDetected( myViewPort->getView() );
409 emit vpTransformationStarted ( ZOOMVIEW );
410 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
411 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
414 int x1 = (int)( aEvent->x() + width()*delta/100 );
415 int y1 = (int)( aEvent->y() + height()*delta/100 );
416 myViewPort->zoom( x, y, x1, y1 );
417 emit vpTransformationFinished ( ZOOMVIEW );
422 case QEvent::ContextMenu:
424 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
425 if ( aEvent->reason() != QContextMenuEvent::Mouse )
426 emit contextMenuRequested( aEvent );
430 case QEvent::KeyPress:
431 emit keyPressed(this, (QKeyEvent*) e);
434 case QEvent::KeyRelease:
435 emit keyReleased(this, (QKeyEvent*) e);
442 return SUIT_ViewWindow::eventFilter(watched, e);
446 \brief Enable / disable draw rect (rubber band) mode
448 bool OCCViewer_ViewWindow::enableDrawMode( bool on )
450 bool prev = myDrawRectEnabled;
451 myDrawRectEnabled = on;
452 updateEnabledDrawMode();
457 \brief Update state of enable draw mode state.
459 void OCCViewer_ViewWindow::updateEnabledDrawMode()
461 myEnableDrawMode = myDrawRectEnabled;
463 myEnableDrawMode = myEnableDrawMode && myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
467 \brief Handle mouse press event
468 \param theEvent mouse event
470 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
472 myStartX = theEvent->x();
473 myStartY = theEvent->y();
474 myStartTime = QDateTime::currentMSecsSinceEpoch();
475 int anInteractionStyle = interactionStyle();
477 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
478 // which are assigned for pan and rotate - these operations are activated immediately after pressing
479 // of the first button, so it is necessary to switch to zoom when the second button is pressed
480 bool aSwitchToZoom = false;
481 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
482 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
483 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
486 switch ( myOperation ) {
488 if ( theEvent->button() == Qt::LeftButton )
489 emit vpTransformationStarted ( WINDOWFIT );
493 if ( theEvent->button() == Qt::LeftButton )
494 emit vpTransformationStarted ( PANGLOBAL );
498 if ( theEvent->button() == Qt::LeftButton ) {
499 myViewPort->startZoomAtPoint( myStartX, myStartY );
500 emit vpTransformationStarted ( ZOOMVIEW );
505 if ( aSwitchToZoom ) {
506 myViewPort->startZoomAtPoint( myStartX, myStartY );
509 else if ( theEvent->button() == Qt::LeftButton )
510 emit vpTransformationStarted ( PANVIEW );
514 if ( aSwitchToZoom ) {
515 myViewPort->startZoomAtPoint( myStartX, myStartY );
518 else if ( theEvent->button() == Qt::LeftButton ) {
519 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
520 emit vpTransformationStarted ( ROTATE );
521 emit vpStartRotate(myStartX, myStartY, myStartTime);
526 /* Try to activate a transformation */
527 OperationType aState;
528 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
529 aState = getButtonState(theEvent, anInteractionStyle);
531 aState = OCCViewer_ViewWindow::NOVIEWOP;
536 myViewPort->startZoomAtPoint( myStartX, myStartY );
544 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
545 emit vpStartRotate(myStartX, myStartY, myStartTime);
548 if ( myRotationPointSelection )
550 if ( theEvent->button() == Qt::LeftButton )
552 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
553 ic->Select( Standard_True );
554 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
556 TopoDS_Shape aShape = ic->SelectedShape();
557 GProp_GProps aSystem;
559 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
561 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
563 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE )
565 BRepGProp::LinearProperties( aShape, aSystem );
566 aPnt = aSystem.CentreOfMass();
568 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE )
570 BRepGProp::SurfaceProperties( aShape, aSystem );
571 aPnt = aSystem.CentreOfMass();
573 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID )
575 BRepGProp::VolumeProperties( aShape, aSystem );
576 aPnt = aSystem.CentreOfMass();
580 myCurrPointType = myPrevPointType;
584 if ( mySetRotationPointDlg )
586 myRotationPointSelection = false;
587 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
590 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
591 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
594 myOperation = NOVIEWOP;
595 myViewPort->setCursor( myCursor );
596 myCursorIsHand = false;
597 myRotationPointSelection = false;
601 emit mousePressed(this, theEvent);
604 /* notify that we start a transformation */
605 if ( transformRequested() )
606 emit vpTransformationStarted ( myOperation );
608 if ( transformRequested() )
609 setTransformInProcess( true );
611 /* we may need it for sketching... */
612 if ( l_mbPressEvent )
613 delete l_mbPressEvent;
614 l_mbPressEvent = new QMouseEvent( *theEvent );
619 \brief Start zooming operation.
621 Sets the corresponding cursor for the widget.
623 void OCCViewer_ViewWindow::activateZoom()
625 if ( !transformRequested() && !myCursorIsHand )
626 saveCursor(); /* save old cursor */
628 if ( myOperation != ZOOMVIEW ) {
629 QPixmap zoomPixmap (imageZoomCursor);
630 QCursor zoomCursor (zoomPixmap);
631 if( setTransformRequested ( ZOOMVIEW ) )
632 myViewPort->setCursor( zoomCursor );
637 void OCCViewer_ViewWindow::onPanning()
639 OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( getViewManager() );
640 bool isChained = aMgr->isChainedOperations();
641 bool isReset = ( myPanningByBtn && isChained );
648 myPanningByBtn = true;
654 \brief Start panning operation.
656 Sets the corresponding cursor for the widget.
658 void OCCViewer_ViewWindow::activatePanning()
660 if ( !transformRequested() && !myCursorIsHand )
661 saveCursor(); // save old cursor
663 if ( myOperation != PANVIEW ) {
664 QCursor panCursor (Qt::SizeAllCursor);
665 if( setTransformRequested ( PANVIEW ) )
666 myViewPort->setCursor( panCursor );
671 \brief Start rotation operation
673 Sets the corresponding cursor for the widget.
675 void OCCViewer_ViewWindow::activateRotation()
677 if ( !transformRequested() && !myCursorIsHand )
678 saveCursor(); // save old cursor
680 if ( myOperation != ROTATE ) {
681 QPixmap rotatePixmap (imageRotateCursor);
682 QCursor rotCursor (rotatePixmap);
683 if( setTransformRequested ( ROTATE ) )
684 myViewPort->setCursor( rotCursor );
689 \brief Compute the gravity center.
690 \param theX used to return X coordinate of the gravity center
691 \param theY used to return Y coordinate of the gravity center
692 \param theZ used to return Z coordinate of the gravity center
693 \return \c true if the gravity center is computed
695 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
697 Handle(V3d_View) aView3d = myViewPort->getView();
699 // Project boundaries points and add to avergae gravity
700 // the ones which lie within the screen limits
701 Standard_Real aScreenLimits[4] = { 0.0, 0.0, 0.0, 0.0 };
703 // NDC space screen limits
704 aScreenLimits[0] = -1.0;
705 aScreenLimits[1] = 1.0;
706 aScreenLimits[2] = -1.0;
707 aScreenLimits[3] = 1.0;
709 Standard_Integer aPointsNb = 0;
711 Standard_Real aXmin = 0.0;
712 Standard_Real aYmin = 0.0;
713 Standard_Real aZmin = 0.0;
714 Standard_Real aXmax = 0.0;
715 Standard_Real aYmax = 0.0;
716 Standard_Real aZmax = 0.0;
718 Graphic3d_MapOfStructure aSetOfStructures;
719 aView3d->View()->DisplayedStructures( aSetOfStructures );
720 Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures );
722 for( ; aStructureIt.More(); aStructureIt.Next() ) {
723 const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key();
724 if ( aStructure->IsEmpty() || !aStructure->IsVisible() || aStructure->CStructure()->IsForHighlight )
727 const Graphic3d_BndBox3d& aBox = aStructure->CStructure()->BoundingBox();
730 aXmin = /*aBox.IsVoid() ? RealFirst() : */aBox.CornerMin().x();
731 aYmin = /*aBox.IsVoid() ? RealFirst() : */aBox.CornerMin().y();
732 aZmin = /*aBox.IsVoid() ? RealFirst() : */aBox.CornerMin().z();
733 aXmax = /*aBox.IsVoid() ? RealLast() : */aBox.CornerMax().x();
734 aYmax = /*aBox.IsVoid() ? RealLast() : */aBox.CornerMax().y();
735 aZmax = /*aBox.IsVoid() ? RealLast() : */aBox.CornerMax().z();
737 // Infinite structures are skipped
738 Standard_Real aLIM = ShortRealLast() - 1.0;
739 if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
740 || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
744 gp_Pnt aPoints[8] = {
745 gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
746 gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
747 gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
748 gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
751 for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
752 const gp_Pnt& aBBPoint = aPoints[aPointIt];
754 gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
755 const Standard_Real& U = aProjected.X();
756 const Standard_Real& V = aProjected.Y();
758 if (U >= aScreenLimits[0]
759 && U <= aScreenLimits[1]
760 && V >= aScreenLimits[2]
761 && V <= aScreenLimits[3])
764 theX += aBBPoint.X();
765 theY += aBBPoint.Y();
766 theZ += aBBPoint.Z();
783 \brief Set the gravity center as a rotation point.
785 void OCCViewer_ViewWindow::activateSetRotationGravity()
787 if ( myRotationPointSelection )
789 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
792 myOperation = NOVIEWOP;
793 myViewPort->setCursor( myCursor );
794 myCursorIsHand = false;
795 myRotationPointSelection = false;
798 myPrevPointType = myCurrPointType;
799 myCurrPointType = BBCENTER;
801 Standard_Real Xcenter, Ycenter, Zcenter;
802 if ( OCCViewer_Utilities::computeVisibleBBCenter( myViewPort->getView(), Xcenter, Ycenter, Zcenter ) )
803 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
807 \brief Update gravity center in the "Set Rotation Point" dialog box.
808 \sa OCCViewer_SetRotationPointDlg class
810 void OCCViewer_ViewWindow::updateGravityCoords()
812 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == BBCENTER )
814 Standard_Real Xcenter, Ycenter, Zcenter;
815 if ( OCCViewer_Utilities::computeVisibleBBCenter( myViewPort->getView(), Xcenter, Ycenter, Zcenter ) )
816 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
821 \brief Set the point selected by the user as a rotation point.
822 \param theX X coordinate of the rotation point
823 \param theY Y coordinate of the rotation point
824 \param theZ Z coordinate of the rotation point
826 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
828 if ( myRotationPointSelection )
830 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
833 myOperation = NOVIEWOP;
834 myViewPort->setCursor( myCursor );
835 myCursorIsHand = false;
836 myRotationPointSelection = false;
839 myPrevPointType = myCurrPointType;
840 myCurrPointType = SELECTED;
841 mySelectedPoint.SetCoord(theX,theY,theZ);
845 \brief Start the shape selection process.
847 void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
849 myPrevPointType = myCurrPointType;
850 myCurrPointType = SELECTED;
852 // activate selection ------>
853 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
856 AIS_ListOfInteractive aList;
857 ic->DisplayedObjects( aList );
858 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
860 Handle(AIS_InteractiveObject) anObj = it.Value();
861 if ( !anObj.IsNull() && anObj->HasPresentation() &&
862 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
865 ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
868 // activate selection <------
870 if ( !myCursorIsHand )
872 QCursor handCursor (Qt::PointingHandCursor);
873 myCursorIsHand = true;
875 myViewPort->setCursor( handCursor );
877 myRotationPointSelection = true;
881 \brief Start global panning operation
883 Sets the corresponding cursor for the widget.
885 void OCCViewer_ViewWindow::activateGlobalPanning()
887 Handle(V3d_View) aView3d = myViewPort->getView();
888 if ( !aView3d.IsNull() ) {
889 QPixmap globalPanPixmap (imageCrossCursor);
890 QCursor glPanCursor (globalPanPixmap);
891 myCurScale = aView3d->Scale();
892 aView3d->FitAll(0.01, false);
893 saveCursor(); // save old cursor
894 myViewPort->fitAll(); // fits view before selecting a new scene center
895 if( setTransformRequested( PANGLOBAL ) )
896 myViewPort->setCursor( glPanCursor );
901 \brief Starts fit operation.
903 Sets the corresponding cursor for the widget.
905 void OCCViewer_ViewWindow::activateWindowFit()
907 if ( !transformRequested() && !myCursorIsHand )
908 saveCursor(); /* save old cursor */
910 if ( myOperation != WINDOWFIT ) {
911 QCursor handCursor (Qt::PointingHandCursor);
912 if( setTransformRequested ( WINDOWFIT ) )
914 myViewPort->setCursor ( handCursor );
915 myCursorIsHand = true;
921 \brief Start delayed viewer operation.
923 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
925 bool ok = transformEnabled( op );
926 myOperation = ok ? op : NOVIEWOP;
927 myViewPort->setMouseTracking( myOperation == NOVIEWOP );
932 \brief Handle mouse move event.
933 \param theEvent mouse event
935 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
937 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
939 switch ( getButtonState( theEvent, interactionStyle() ) ) {
941 myViewPort->startZoomAtPoint( myStartX, myStartY );
949 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
950 emit vpStartRotate(myStartX, myStartY, myStartTime);
957 myCurrX = theEvent->x();
958 myCurrY = theEvent->y();
959 myCurrTime = QDateTime::currentMSecsSinceEpoch();
960 switch (myOperation) {
962 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
963 emit vpRotate(myCurrX, myCurrY, myCurrTime);
967 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
973 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
987 if ( myRotationPointSelection || isSketcherStyle() )
989 emit mouseMoving( this, theEvent );
993 int aState = theEvent->modifiers();
994 int aButton = theEvent->buttons();
995 int anInteractionStyle = interactionStyle();
996 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
997 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || aState == Qt::ShiftModifier ) ) ||
998 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
999 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
1000 myDrawRect = myEnableDrawMode;
1003 //if ( !myCursorIsHand ) { // we are going to sketch a rectangle
1004 // QCursor handCursor (Qt::PointingHandCursor);
1005 // myCursorIsHand = true;
1007 // myViewPort->setCursor( handCursor );
1010 SelectionStyle aStyle = selectionStyle();
1011 activateSketching(aStyle == RectStyle ? Rect : Polygon);
1014 if (l_mbPressEvent) {
1015 QApplication::sendEvent(getViewPort(), l_mbPressEvent);
1016 delete l_mbPressEvent;
1019 QApplication::sendEvent(getViewPort(), theEvent);
1022 emit mouseMoving( this, theEvent );
1024 //else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
1025 // aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
1026 // ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
1027 // aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
1028 // OCCViewer_ViewSketcher* sketcher = 0;
1029 // QList<OCCViewer_ViewSketcher*>::Iterator it;
1030 // for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
1032 // OCCViewer_ViewSketcher* sk = (*it);
1033 // if( sk->isDefault() && sk->sketchButton() == aButton )
1036 // if ( sketcher && myCurSketch == -1 )
1038 // activateSketching( sketcher->type() );
1039 // if ( mypSketcher )
1041 // myCurSketch = mypSketcher->sketchButton();
1043 // if ( l_mbPressEvent )
1045 // QApplication::sendEvent( getViewPort(), l_mbPressEvent );
1046 // delete l_mbPressEvent;
1047 // l_mbPressEvent = 0;
1049 // QApplication::sendEvent( getViewPort(), theEvent );
1054 emit mouseMoving( this, theEvent );
1060 \brief Handle mouse release event.
1061 \param theEvent mouse event
1063 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
1065 switch ( myOperation ) {
1068 int prevState = myCurSketch;
1069 if(theEvent->button() == Qt::RightButton)
1071 QList<OCCViewer_ViewSketcher*>::Iterator it;
1072 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
1074 OCCViewer_ViewSketcher* sk = (*it);
1075 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
1080 emit mouseReleased(this, theEvent);
1081 if(theEvent->button() == Qt::RightButton && prevState == -1)
1083 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1084 theEvent->pos(), theEvent->globalPos() );
1085 emit contextMenuRequested( &aEvent );
1090 myCurrX = theEvent->x();
1091 myCurrY = theEvent->y(),
1092 myCurrTime = QDateTime::currentMSecsSinceEpoch();
1093 myViewPort->endRotation();
1094 emit vpEndRotate(myCurrX, myCurrY, myCurrTime);
1101 OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( getViewManager() );
1102 bool isChained = aMgr->isChainedOperations();
1103 bool isReset = !( myOperation==PANVIEW && myPanningByBtn && isChained ) || theEvent->button() == Qt::RightButton;
1110 if ( theEvent->button() == Qt::LeftButton ) {
1111 myViewPort->setCenter( theEvent->x(), theEvent->y() );
1112 myViewPort->getView()->SetScale(myCurScale);
1118 if ( theEvent->button() == Qt::LeftButton ) {
1119 myCurrX = theEvent->x();
1120 myCurrY = theEvent->y();
1122 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1123 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1132 // NOTE: viewer 3D detects a rectangle of selection using this event
1133 // so we must emit it BEFORE resetting the selection rectangle
1135 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1139 myViewPort->update();
1142 if ( l_mbPressEvent ) {
1143 delete l_mbPressEvent;
1149 \brief Reset the viewport to its initial state
1150 ( no transformations in process etc. )
1152 void OCCViewer_ViewWindow::resetState()
1156 if ( myRotationPointSelection )
1158 QCursor handCursor (Qt::PointingHandCursor);
1159 myViewPort->setCursor( handCursor );
1163 if ( transformRequested() || myCursorIsHand )
1164 myViewPort->setCursor( myCursor );
1165 myCursorIsHand = false;
1168 if ( transformRequested() )
1169 emit vpTransformationFinished (myOperation);
1171 setTransformInProcess( false );
1172 setTransformRequested( NOVIEWOP );
1174 myPanningByBtn = false;
1179 \brief Draw rubber band rectangle.
1181 void OCCViewer_ViewWindow::drawRect()
1183 if ( !myRectBand ) {
1184 myRectBand = new QtxRectRubberBand( myViewPort );
1187 myRectBand->setUpdatesEnabled ( false );
1188 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1189 myRectBand->initGeometry( aRect );
1191 if ( !myRectBand->isVisible() )
1194 myRectBand->setUpdatesEnabled ( true );
1198 \brief Clear rubber band rectangle on the end on the dragging operation.
1200 void OCCViewer_ViewWindow::endDrawRect()
1203 myRectBand->clearGeometry();
1209 \brief Create actions.
1211 void OCCViewer_ViewWindow::createActions()
1213 if( !toolMgr()->isEmpty() )
1216 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1223 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1224 tr( "MNU_DUMP_VIEW" ), 0, this);
1225 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1226 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1227 toolMgr()->registerAction( aAction, DumpId );
1230 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1231 tr( "MNU_FITALL" ), 0, this);
1232 aAction->setStatusTip(tr("DSC_FITALL"));
1233 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1234 toolMgr()->registerAction( aAction, FitAllId );
1237 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1238 tr( "MNU_FITRECT" ), 0, this);
1239 aAction->setStatusTip(tr("DSC_FITRECT"));
1240 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1241 toolMgr()->registerAction( aAction, FitRectId );
1244 aAction = new QtxAction(tr("MNU_FITSELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITSELECTION" ) ),
1245 tr( "MNU_FITSELECTION" ), 0, this);
1246 aAction->setStatusTip(tr("DSC_FITSELECTION"));
1247 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
1248 toolMgr()->registerAction( aAction, FitSelectionId );
1251 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1252 tr( "MNU_ZOOM_VIEW" ), 0, this);
1253 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1254 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1255 toolMgr()->registerAction( aAction, ZoomId );
1258 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1259 tr( "MNU_PAN_VIEW" ), 0, this);
1260 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1261 connect(aAction, SIGNAL(triggered()), this, SLOT(onPanning()));
1262 toolMgr()->registerAction( aAction, PanId );
1265 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1266 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1267 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1268 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1269 toolMgr()->registerAction( aAction, GlobalPanId );
1272 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1273 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1274 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1275 mySetRotationPointAction->setCheckable( true );
1276 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1277 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1280 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1281 tr( "MNU_ROTATE_VIEW" ), 0, this);
1282 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1283 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1284 toolMgr()->registerAction( aAction, RotationId );
1287 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1288 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1289 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1290 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1291 this->addAction(aAction);
1292 toolMgr()->registerAction( aAction, FrontId );
1294 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1295 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1296 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1297 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1298 this->addAction(aAction);
1299 toolMgr()->registerAction( aAction, BackId );
1301 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1302 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1303 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1304 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1305 this->addAction(aAction);
1306 toolMgr()->registerAction( aAction, TopId );
1308 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1309 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1310 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1311 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1312 this->addAction(aAction);
1313 toolMgr()->registerAction( aAction, BottomId );
1315 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1316 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1317 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1318 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1319 this->addAction(aAction);
1320 toolMgr()->registerAction( aAction, LeftId );
1322 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1323 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1324 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1325 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1326 this->addAction(aAction);
1327 toolMgr()->registerAction( aAction, RightId );
1329 // rotate anticlockwise
1330 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1331 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1332 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1333 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1334 this->addAction(aAction);
1335 toolMgr()->registerAction( aAction, AntiClockWiseId );
1338 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1339 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1340 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1341 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1342 this->addAction(aAction);
1343 toolMgr()->registerAction( aAction, ClockWiseId );
1345 // Projection mode group
1347 // - orthographic projection
1348 aAction = new QtxAction(tr("MNU_ORTHOGRAPHIC_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ORTHOGRAPHIC" ) ),
1349 tr( "MNU_ORTHOGRAPHIC_MODE" ), 0, this);
1350 aAction->setStatusTip(tr("DSC_ORTHOGRAPHIC_MODE"));
1351 aAction->setCheckable(true);
1352 toolMgr()->registerAction( aAction, OrthographicId );
1354 // - perspective projection
1355 aAction = new QtxAction(tr("MNU_PERSPECTIVE_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PERSPECTIVE" ) ),
1356 tr( "MNU_PERSPECTIVE_MODE" ), 0, this);
1357 aAction->setStatusTip(tr("DSC_PERSPECTIVE_MODE"));
1358 aAction->setCheckable(true);
1359 toolMgr()->registerAction( aAction, PerspectiveId );
1361 // - stereo projection
1362 aAction = new QtxAction(tr("MNU_STEREO_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STEREO" ) ),
1363 tr( "MNU_STEREO_MODE" ), 0, this);
1364 aAction->setStatusTip(tr("DSC_STEREO_MODE"));
1365 aAction->setCheckable(true);
1366 toolMgr()->registerAction( aAction, StereoId );
1367 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onStereoType(bool)));
1369 // - add exclusive action group
1370 QActionGroup* aProjectionGroup = new QActionGroup( this );
1371 aProjectionGroup->addAction( toolMgr()->action( OrthographicId ) );
1372 aProjectionGroup->addAction( toolMgr()->action( PerspectiveId ) );
1373 connect(aProjectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProjectionType(QAction*)));
1376 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1377 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1378 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1379 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1380 this->addAction(aAction);
1381 toolMgr()->registerAction( aAction, ResetId );
1384 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1385 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1386 tr("MNU_CLONE_VIEW"), 0, this);
1387 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1388 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1389 toolMgr()->registerAction( aAction, CloneId );
1391 aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
1392 tr("MNU_CLIPPING"), 0, this);
1393 aAction->setStatusTip (tr("DSC_CLIPPING"));
1394 aAction->setCheckable (true);
1395 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1396 toolMgr()->registerAction (aAction, ClippingId);
1398 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1399 tr( "MNU_SHOOT_VIEW" ), 0, this);
1400 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1401 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1402 toolMgr()->registerAction( aAction, MemId );
1404 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1405 tr( "MNU_PRESETS_VIEW" ), 0, this);
1406 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1407 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1408 toolMgr()->registerAction( aAction, RestoreId );
1410 if (myModel->trihedronActivated()) {
1411 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1412 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1413 aAction->setCheckable( true );
1414 aAction->setChecked( true );
1415 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1416 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1417 toolMgr()->registerAction( aAction, TrihedronShowId );
1420 if (myModel->viewCubeActivated()) {
1421 aAction = new QtxAction(tr("MNU_SHOW_VIEWCUBE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_VIEWCUBE" ) ),
1422 tr( "MNU_SHOW_VIEWCUBE" ), 0, this);
1423 aAction->setCheckable( true );
1424 aAction->setChecked( aResMgr->booleanValue( "OCCViewer", "viewcube_show", true ) );
1425 aAction->setStatusTip(tr("DSC_SHOW_VIEWCUBE"));
1426 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onViewCubeShow(bool)));
1427 toolMgr()->registerAction( aAction, ViewCubeShowId );
1431 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1432 tr( "MNU_SCALING" ), 0, this);
1433 aAction->setStatusTip(tr("DSC_SCALING"));
1434 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1435 toolMgr()->registerAction( aAction, AxialScaleId );
1437 // Enable/disable preselection
1438 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1439 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1440 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1441 aAction->setCheckable(true);
1442 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1443 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1445 // Enable/disable selection
1446 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1447 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1448 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1449 aAction->setCheckable(true);
1450 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1451 toolMgr()->registerAction( aAction, SwitchSelectionId );
1454 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1455 tr( "MNU_GRADUATED_AXES" ), 0, this);
1456 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1457 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1458 toolMgr()->registerAction( aAction, GraduatedAxesId );
1460 // Active only ambient light or not
1461 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1462 tr( "MNU_AMBIENT" ), 0, this);
1463 aAction->setStatusTip(tr("DSC_AMBIENT"));
1464 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1465 toolMgr()->registerAction( aAction, AmbientId );
1467 // Switch between interaction styles
1468 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1469 tr( "MNU_STYLE_SWITCH" ), 0, this);
1470 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1471 aAction->setCheckable(true);
1472 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1473 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1475 // Switch between zooming styles
1476 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1477 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1478 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1479 aAction->setCheckable(true);
1480 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1481 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1483 // Switch advanced selection style (poligone/circle)
1484 aAction = new QtxAction(tr("MNU_RECTANGLE_SELECTION_STYLE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RECT_STYLE" ) ),
1485 tr( "MNU_RECTANGLE_SELECTION_STYLE" ), 0, this);
1486 aAction->setStatusTip(tr("DSC_RECTANGLE_SELECTION_STYLE"));
1487 aAction->setCheckable(true);
1488 toolMgr()->registerAction( aAction, RectangleSelectionStyleId);
1490 aAction = new QtxAction(tr("MNU_POLYGON_SELECTION_STYLE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_POLY_STYLE" ) ),
1491 tr( "MNU_POLYGON_SELECTION_STYLE" ), 0, this);
1492 aAction->setStatusTip(tr("DSC_POLYGON_SELECTION_STYLE"));
1493 aAction->setCheckable(true);
1494 toolMgr()->registerAction( aAction, PolygonSelectionStyleId);
1496 aAction = new QtxAction(tr("MNU_CIRCLE_SELECTION_STYLE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CIRCLE_STYLE" ) ),
1497 tr( "MNU_CIRCLE_SELECTION_STYLE" ), 0, this);
1498 aAction->setStatusTip(tr("DSC_CIRCLE_SELECTION_STYLE"));
1499 aAction->setCheckable(true);
1500 toolMgr()->registerAction( aAction, CircleSelectionStyleId);
1502 // - add exclusive action group
1503 QActionGroup* aSelectionGroup = new QActionGroup(this);
1504 aSelectionGroup->addAction(toolMgr()->action(RectangleSelectionStyleId));
1505 aSelectionGroup->addAction(toolMgr()->action(PolygonSelectionStyleId));
1506 aSelectionGroup->addAction(toolMgr()->action(CircleSelectionStyleId));
1507 connect(aSelectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onSwitchSelectionStyle(QAction*)));
1510 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1511 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1512 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1513 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1514 toolMgr()->registerAction( aAction, MaximizedId );
1516 // Return to 3d view
1517 if (my2dMode!=No2dMode){
1518 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1519 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1520 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1521 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1522 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1526 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1527 #ifdef ENABLE_RAY_TRACING
1529 aAction = new QtxAction( tr("MNU_RAY_TRACING"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_RAY_TRACING") ),
1530 tr("MNU_RAY_TRACING"), 0, this );
1531 aAction->setStatusTip( tr("DSC_RAY_TRACING") );
1532 connect( aAction, SIGNAL( triggered() ), this, SLOT( onRayTracing() ) );
1533 toolMgr()->registerAction( aAction, RayTracingId );
1535 // Environment texture
1536 aAction = new QtxAction( tr("MNU_ENV_TEXTURE"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_ENV_TEXTURE") ),
1537 tr("MNU_ENV_TEXTURE"), 0, this );
1538 aAction->setStatusTip( tr("DSC_ENV_TEXTURE") );
1539 connect( aAction, SIGNAL( triggered() ), this, SLOT( onEnvTexture() ) );
1540 toolMgr()->registerAction( aAction, EnvTextureId );
1543 aAction = new QtxAction( tr("MNU_LIGHT_SOURCE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_LIGHT_SOURCE" ) ),
1544 tr( "MNU_LIGHT_SOURCE" ), 0, this );
1545 aAction->setStatusTip( tr("DSC_LIGHT_SOURCE") );
1546 connect( aAction, SIGNAL( triggered() ), this, SLOT( onLightSource() ) );
1547 toolMgr()->registerAction( aAction, LightSourceId );
1552 \brief Create toolbar.
1554 void OCCViewer_ViewWindow::createToolBar()
1556 static const char* titles[] = {
1557 "LBL_3DTOOLBAR_LABEL",
1558 "LBL_XYTOOLBAR_LABEL",
1559 "LBL_XZTOOLBAR_LABEL",
1560 "LBL_YZTOOLBAR_LABEL",
1562 static const char* names[] = {
1563 "OCCViewer3DViewOperations",
1564 "OCCViewerXYViewOperations",
1565 "OCCViewerXZViewOperations",
1566 "OCCViewerYZViewOperations",
1568 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1569 QString( names[my2dMode] ), // name (language-independant)
1570 false ); // disable floatable toolbar
1571 if ( my2dMode != No2dMode ){
1572 toolMgr()->append( ReturnTo3dViewId, tid );
1573 toolMgr()->append( toolMgr()->separator(), tid );
1575 toolMgr()->append( DumpId, tid );
1576 toolMgr()->append( SwitchInteractionStyleId, tid );
1577 toolMgr()->append( SwitchZoomingStyleId, tid );
1578 toolMgr()->append( SwitchPreselectionId, tid );
1579 toolMgr()->append( SwitchSelectionId, tid );
1581 QtxMultiAction* aSelectionAction = new QtxMultiAction(this);
1582 aSelectionAction->insertAction(toolMgr()->action(RectangleSelectionStyleId));
1583 aSelectionAction->insertAction(toolMgr()->action(PolygonSelectionStyleId));
1584 aSelectionAction->insertAction(toolMgr()->action(CircleSelectionStyleId));
1585 toolMgr()->append(aSelectionAction, tid );
1587 if( myModel->trihedronActivated() )
1588 toolMgr()->append( TrihedronShowId, tid );
1590 if( myModel->viewCubeActivated() )
1591 toolMgr()->append( ViewCubeShowId, tid );
1593 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1594 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1595 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1596 aScaleAction->insertAction( toolMgr()->action( FitSelectionId ) );
1597 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1598 toolMgr()->append( aScaleAction, tid );
1600 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1601 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1602 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1603 toolMgr()->append( aPanningAction, tid );
1605 if (my2dMode == No2dMode) {
1606 toolMgr()->append( ChangeRotationPointId, tid );
1607 toolMgr()->append( RotationId, tid );
1609 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1610 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1611 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1612 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1613 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1614 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1615 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1616 toolMgr()->append( aViewsAction, tid );
1618 toolMgr()->append( AntiClockWiseId, tid );
1619 toolMgr()->append( ClockWiseId, tid );
1621 toolMgr()->append( OrthographicId, tid );
1622 toolMgr()->append( PerspectiveId, tid );
1623 toolMgr()->append( StereoId, tid );
1625 toolMgr()->append( ResetId, tid );
1628 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1629 aMemAction->insertAction( toolMgr()->action( MemId ) );
1630 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1631 toolMgr()->append( aMemAction, tid );
1633 toolMgr()->append( toolMgr()->separator(), tid );
1634 toolMgr()->append( CloneId, tid );
1636 toolMgr()->append( toolMgr()->separator(), tid );
1637 toolMgr()->append( ClippingId, tid );
1638 toolMgr()->append( AxialScaleId, tid );
1639 toolMgr()->append( GraduatedAxesId, tid );
1640 toolMgr()->append( AmbientId, tid );
1642 toolMgr()->append( MaximizedId, tid );
1643 toolMgr()->append( SynchronizeId, tid );
1644 #ifdef ENABLE_RAY_TRACING
1645 toolMgr()->append( RayTracingId, tid );
1646 toolMgr()->append( EnvTextureId, tid );
1647 toolMgr()->append( LightSourceId, tid );
1652 \brief Perform 'fit all' operation.
1654 void OCCViewer_ViewWindow::onViewFitAll()
1656 myViewPort->fitAll();
1660 \brief Perform "front view" transformation.
1662 void OCCViewer_ViewWindow::onFrontView()
1664 emit vpTransformationStarted ( FRONTVIEW );
1665 Handle(V3d_View) aView3d = myViewPort->getView();
1666 if (myAutomaticZoom)
1668 if ( !aView3d.IsNull() )
1669 aView3d->SetProj (V3d_Xpos);
1673 projAndPanToGravity(V3d_Xpos);
1674 emit vpTransformationFinished ( FRONTVIEW );
1678 \brief Perform "back view" transformation.
1680 void OCCViewer_ViewWindow::onBackView()
1682 emit vpTransformationStarted ( BACKVIEW );
1683 Handle(V3d_View) aView3d = myViewPort->getView();
1684 if (myAutomaticZoom)
1686 if ( !aView3d.IsNull() )
1687 aView3d->SetProj (V3d_Xneg);
1691 projAndPanToGravity(V3d_Xneg);
1692 emit vpTransformationFinished ( BACKVIEW );
1696 \brief Perform "top view" transformation.
1698 void OCCViewer_ViewWindow::onTopView()
1700 emit vpTransformationStarted ( TOPVIEW );
1701 Handle(V3d_View) aView3d = myViewPort->getView();
1702 if (myAutomaticZoom)
1704 if ( !aView3d.IsNull() )
1705 aView3d->SetProj (V3d_Zpos);
1709 projAndPanToGravity(V3d_Zpos);
1710 emit vpTransformationFinished ( TOPVIEW );
1714 \brief Perform "bottom view" transformation.
1716 void OCCViewer_ViewWindow::onBottomView()
1718 emit vpTransformationStarted ( BOTTOMVIEW );
1719 Handle(V3d_View) aView3d = myViewPort->getView();
1720 if (myAutomaticZoom)
1722 if ( !aView3d.IsNull() )
1723 aView3d->SetProj (V3d_Zneg);
1727 projAndPanToGravity(V3d_Zneg);
1728 emit vpTransformationFinished ( BOTTOMVIEW );
1732 \brief Perform "left view" transformation.
1734 void OCCViewer_ViewWindow::onLeftView()
1736 emit vpTransformationStarted ( LEFTVIEW );
1737 Handle(V3d_View) aView3d = myViewPort->getView();
1738 if (myAutomaticZoom)
1740 if ( !aView3d.IsNull() )
1741 aView3d->SetProj (V3d_Yneg);
1745 projAndPanToGravity(V3d_Yneg);
1746 emit vpTransformationFinished ( LEFTVIEW );
1750 \brief Perform "right view" transformation.
1752 void OCCViewer_ViewWindow::onRightView()
1754 emit vpTransformationStarted ( RIGHTVIEW );
1755 Handle(V3d_View) aView3d = myViewPort->getView();
1756 if (myAutomaticZoom)
1758 if ( !aView3d.IsNull() )
1759 aView3d->SetProj (V3d_Ypos);
1763 projAndPanToGravity(V3d_Ypos);
1764 emit vpTransformationFinished ( RIGHTVIEW );
1768 \brief Rotate view 90 degrees clockwise
1770 void OCCViewer_ViewWindow::onClockWiseView()
1772 emit vpTransformationStarted ( CLOCKWISEVIEW );
1773 myViewPort->rotateXY( 90. );
1774 emit vpTransformationFinished ( CLOCKWISEVIEW );
1778 \brief Rotate view 90 degrees conterclockwise
1780 void OCCViewer_ViewWindow::onAntiClockWiseView()
1782 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1783 myViewPort->rotateXY( -90. );
1784 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1788 \brief Perform "reset view" transformation.
1790 Sets default orientation of the viewport camera.
1792 void OCCViewer_ViewWindow::onResetView()
1794 emit vpTransformationStarted( RESETVIEW );
1795 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1796 myViewPort->getView()->Reset( false );
1797 myViewPort->fitAll( false, true, false );
1798 myViewPort->getView()->SetImmediateUpdate( upd );
1799 onProjectionType(); // needed to apply projection type properly after reset
1800 myViewPort->getView()->Update();
1801 emit vpTransformationFinished( RESETVIEW );
1805 \brief Set the given projection mode.
1807 Set the given projection mode: Orthographic or Perspective.
1809 void OCCViewer_ViewWindow::onProjectionType( QAction* theAction )
1811 Handle(V3d_View) aView3d = myViewPort->getView();
1812 if ( !aView3d.IsNull() ) {
1813 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1814 if (theAction == toolMgr()->action( OrthographicId )) {
1815 myModel->setProjectionType(Orthographic);
1816 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Orthographic );
1817 aCamera->SetFOVy(45.0);
1819 else if (theAction == toolMgr()->action( PerspectiveId )) {
1820 myModel->setProjectionType(Perspective);
1821 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Perspective );
1822 aCamera->SetFOVy(30.0);
1824 if (toolMgr()->action( StereoId )->isChecked()) {
1825 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1826 aCamera->SetFOVy(30.0);
1834 \brief Sets Stereo projection mode.
1836 Sets Stereo projection mode.
1838 void OCCViewer_ViewWindow::onStereoType( bool activate )
1840 Handle(V3d_View) aView3d = myViewPort->getView();
1841 if ( !aView3d.IsNull() ) {
1842 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1844 toolMgr()->action( PerspectiveId )->setChecked(true);
1845 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1846 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(false);
1848 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1849 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1850 setStereoType( aResMgr->integerValue( "OCCViewer", "stereo_type", 0 ) );
1851 setAnaglyphFilter( aResMgr->integerValue( "OCCViewer", "anaglyph_filter", 0 ) );
1852 setReverseStereo( aResMgr->booleanValue( "OCCViewer", "reverse_stereo", false ) );
1853 setVSync( aResMgr->booleanValue( "OCCViewer", "enable_vsync", true ) );
1854 setQuadBufferSupport( aResMgr->booleanValue( "OCCViewer", "enable_quad_buffer_support", false ) );
1857 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(true);
1858 if (myModel->projectionType() == Orthographic) {
1859 toolMgr()->action( OrthographicId )->setChecked(true);
1860 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Orthographic);
1862 else if (myModel->projectionType() == Perspective) {
1863 toolMgr()->action( PerspectiveId )->setChecked(true);
1864 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1871 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1872 toolMgr()->action( StereoId )->isChecked() )
1873 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1877 \brief Restore the view.
1879 Restore the projection mode based on tool-buttons states.
1881 void OCCViewer_ViewWindow::onProjectionType()
1883 emit vpTransformationStarted( PROJECTION );
1884 if (toolMgr()->action( OrthographicId )->isChecked())
1885 setProjectionType( Orthographic );
1886 if (toolMgr()->action( PerspectiveId )->isChecked())
1887 setProjectionType( Perspective );
1888 if (toolMgr()->action( StereoId )->isChecked())
1889 setProjectionType( Stereo );
1890 emit vpTransformationFinished( PROJECTION );
1893 void OCCViewer_ViewWindow::setProjectionType( int mode )
1895 QtxAction* anOrthographicAction = dynamic_cast<QtxAction*>( toolMgr()->action( OrthographicId ) );
1896 QtxAction* aPerspectiveAction = dynamic_cast<QtxAction*>( toolMgr()->action( PerspectiveId ) );
1897 QtxAction* aStereoAction = dynamic_cast<QtxAction*>( toolMgr()->action( StereoId ) );
1900 onProjectionType( anOrthographicAction );
1903 onProjectionType( aPerspectiveAction );
1906 onStereoType( true );
1909 // update action state if method is called outside
1910 if ( mode == Orthographic && !anOrthographicAction->isChecked() ) {
1911 anOrthographicAction->setChecked( true );
1912 aStereoAction->setChecked( false );
1914 if ( mode == Perspective && !aPerspectiveAction->isChecked() ) {
1915 aPerspectiveAction->setChecked( true );
1916 aStereoAction->setChecked( false );
1918 if ( mode == Stereo ) {
1919 aStereoAction->setChecked( true );
1920 if ( anOrthographicAction->isEnabled() ) {
1921 anOrthographicAction->setEnabled( false );
1922 anOrthographicAction->setChecked( false );
1923 aStereoAction->setChecked( false );
1926 anOrthographicAction->setEnabled( true );
1927 aStereoAction->setChecked( false );
1928 anOrthographicAction->setChecked(myModel->projectionType() == Orthographic);
1930 if ( aPerspectiveAction->isEnabled() ) {
1931 aPerspectiveAction->setEnabled( false );
1932 aPerspectiveAction->setChecked( true );
1933 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1934 toolMgr()->action( StereoId )->isChecked() )
1935 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1938 aPerspectiveAction->setEnabled( true );
1939 aStereoAction->setChecked( false );
1940 aPerspectiveAction->setChecked(myModel->projectionType() == Perspective);
1945 if ( !anOrthographicAction->isEnabled() )
1946 anOrthographicAction->setEnabled( true );
1947 if ( !aPerspectiveAction->isEnabled() )
1948 aPerspectiveAction->setEnabled( true );
1953 \brief Perform "fit all" transformation.
1955 void OCCViewer_ViewWindow::onFitAll()
1957 emit vpTransformationStarted( FITALLVIEW );
1958 if (myModel->fitter())
1959 myModel->fitter()->fitAll(myViewPort->getView());
1961 myViewPort->fitAll();
1962 emit vpTransformationFinished( FITALLVIEW );
1966 \brief Perform "fit selection" transformation.
1968 void OCCViewer_ViewWindow::onFitSelection()
1970 emit vpTransformationStarted( FITSELECTION );
1971 myModel->getAISContext()->FitSelected( getViewPort()->getView() );
1972 emit vpTransformationFinished( FITSELECTION );
1976 \brief Called if 'change rotation point' operation is activated.
1977 \param on action state
1979 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1983 if (!mySetRotationPointDlg)
1985 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1986 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1989 if (!mySetRotationPointDlg->isVisible())
1991 //if (mySetRotationPointDlg->IsFirstShown())
1992 if (myCurrPointType == BBCENTER)
1994 Standard_Real Xcenter, Ycenter, Zcenter;
1995 if (OCCViewer_Utilities::computeVisibleBBCenter(myViewPort->getView(), Xcenter, Ycenter, Zcenter))
1996 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1998 mySetRotationPointDlg->show();
2003 if (mySetRotationPointDlg->isVisible())
2004 mySetRotationPointDlg->hide();
2009 \brief Create one more window with same content.
2011 void OCCViewer_ViewWindow::onCloneView()
2013 SUIT_ViewWindow* vw = myManager->createViewWindow();
2015 emit viewCloned( vw );
2016 OCCViewer_ViewWindow* occVw = dynamic_cast<OCCViewer_ViewWindow*> (vw);
2017 if(occVw && occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)) {
2018 occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)->synchronize(this);
2023 Creates one more window with same content
2025 void OCCViewer_ViewWindow::onAxialScale()
2027 if ( !myScalingDlg )
2028 myScalingDlg = new OCCViewer_AxialScaleDlg( this , myModel );
2030 if ( !myScalingDlg->isVisible() )
2032 myScalingDlg->Update();
2033 myScalingDlg->show();
2038 Shows Graduated Axes dialog
2040 void OCCViewer_ViewWindow::onGraduatedAxes()
2042 myCubeAxesDlg->Update();
2043 myCubeAxesDlg->show();
2046 void OCCViewer_ViewWindow::onAmbientToogle()
2048 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2049 viewer->InitDefinedLights();
2050 while(viewer->MoreDefinedLights())
2052 Handle(V3d_Light) light = viewer->DefinedLight();
2053 if(light->Type() != V3d_AMBIENT)
2055 Handle(V3d_View) aView3d = myViewPort->getView();
2056 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
2057 else viewer->SetLightOn(light);
2059 viewer->NextDefinedLights();
2065 \brief Store view parameters.
2067 void OCCViewer_ViewWindow::onMemorizeView()
2069 appendViewAspect( getViewParams() );
2073 \brief Restore view parameters.
2075 void OCCViewer_ViewWindow::onRestoreView()
2077 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
2078 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
2080 updateViewAspects( aDlg->parameters() );
2081 if( myRestoreFlag && aDlg->parameters().count() )
2082 performRestoring( aDlg->currentItem() );
2086 \brief Restore view parameters.
2087 \param anItem view parameters
2089 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
2091 Handle(V3d_View) aView3d = myViewPort->getView();
2093 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
2094 aView3d->SetScale( anItem.scale );
2095 aView3d->SetTwist( anItem.twist );
2096 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
2097 aView3d->SetImmediateUpdate( prev );
2098 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2099 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2100 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
2102 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
2104 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
2106 // "eye" and "at" require conversion to represent center panning
2107 // up direction is only available after setting angle of twist and
2108 // other view parameters
2109 aView3d->Up( anUpX, anUpY, anUpZ );
2111 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
2112 gp_Dir anUp( anUpX, anUpY, anUpZ );
2113 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
2114 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2115 gp_Dir aSide = aProj ^ anUp;
2117 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
2118 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
2120 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
2121 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2124 if ( !baseParamsOnly ) {
2126 myModel->setTrihedronShown( anItem.isVisible );
2127 myModel->setTrihedronSize( anItem.size );
2129 myModel->setViewCubeShown( anItem.vcIsVisible );
2131 // graduated trihedron
2132 bool anIsVisible = anItem.gtIsVisible;
2133 OCCViewer_AxisWidget::AxisData anAxisData[3];
2134 anAxisData[0].DrawName = anItem.gtDrawNameX;
2135 anAxisData[1].DrawName = anItem.gtDrawNameZ;
2136 anAxisData[2].DrawName = anItem.gtDrawNameZ;
2137 anAxisData[0].Name = anItem.gtNameX;
2138 anAxisData[1].Name = anItem.gtNameZ;
2139 anAxisData[2].Name = anItem.gtNameZ;
2140 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
2141 anItem.gtNameColorGX,
2142 anItem.gtNameColorBX );
2143 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
2144 anItem.gtNameColorGY,
2145 anItem.gtNameColorBY );
2146 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
2147 anItem.gtNameColorGZ,
2148 anItem.gtNameColorBZ );
2149 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
2150 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
2151 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
2152 anAxisData[0].NbValues = anItem.gtNbValuesX;
2153 anAxisData[1].NbValues = anItem.gtNbValuesY;
2154 anAxisData[2].NbValues = anItem.gtNbValuesZ;
2155 anAxisData[0].Offset = anItem.gtOffsetX;
2156 anAxisData[1].Offset = anItem.gtOffsetY;
2157 anAxisData[2].Offset = anItem.gtOffsetZ;
2158 anAxisData[0].Color = QColor( anItem.gtColorRX,
2161 anAxisData[1].Color = QColor( anItem.gtColorRY,
2164 anAxisData[2].Color = QColor( anItem.gtColorRZ,
2167 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
2168 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
2169 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
2170 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
2171 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
2172 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
2174 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
2175 myCubeAxesDlg->ApplyData( aView3d );
2177 } // if ( !baseParamsOnly )
2183 \brief Set restore flag.
2185 void OCCViewer_ViewWindow::setRestoreFlag()
2191 \brief Called when action "show/hide trihedron" is activated.
2193 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
2195 myModel->setTrihedronShown(show);
2199 \brief Called when action "show/hide view cube" is activated.
2201 void OCCViewer_ViewWindow::onViewCubeShow(bool show)
2203 myModel->setViewCubeShown(show);
2207 \brief Toggles preselection (highlighting) on/off
2209 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
2211 myPreselectionEnabled = on;
2212 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
2214 // unhighlight all highlighted objects
2216 myModel->unHighlightAll( true, false );
2219 // update action state if method is called outside
2220 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2221 if ( a && a->isChecked() != on ) {
2222 a->setChecked( on );
2227 \brief Toggles selection on/off
2229 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
2231 mySelectionEnabled = on;
2232 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
2234 // update action state if method is called outside
2237 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2239 a->setEnabled( on );
2243 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
2244 if ( a && a->isChecked() != on ) {
2245 a->setChecked( on );
2250 \brief Switches style of advanced multiple selection by Poligon/Circle
2252 void OCCViewer_ViewWindow::onSwitchSelectionStyle(QAction* theAction)
2255 OCCViewer_ViewSketcher* aSkecher = getSketcher(Polygon);
2257 if (theAction == toolMgr()->action(PolygonSelectionStyleId)) {
2258 aSkecher->setSketcherMode(OCCViewer_PolygonSketcher::Poligone);
2260 else if (theAction == toolMgr()->action(CircleSelectionStyleId)) {
2261 aSkecher->setSketcherMode(OCCViewer_PolygonSketcher::Circle);
2267 Returns currently selected selection style
2269 OCCViewer_ViewWindow::SelectionStyle OCCViewer_ViewWindow::selectionStyle() const
2271 if (toolMgr()->action(PolygonSelectionStyleId)->isChecked())
2272 return PolygonStyle;
2273 if (toolMgr()->action(CircleSelectionStyleId)->isChecked())
2278 void OCCViewer_ViewWindow::setSelectionStyle(SelectionStyle theMode)
2280 toolMgr()->action(RectangleSelectionStyleId)->setChecked(false);
2281 toolMgr()->action(PolygonSelectionStyleId)->setChecked(false);
2282 toolMgr()->action(CircleSelectionStyleId)->setChecked(false);
2285 toolMgr()->action(RectangleSelectionStyleId)->setChecked(true);
2288 toolMgr()->action(PolygonSelectionStyleId)->setChecked(true);
2291 toolMgr()->action(CircleSelectionStyleId)->setChecked(true);
2296 \brief Switches "keyboard free" interaction style on/off
2298 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
2300 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
2302 // update action state if method is called outside
2303 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
2304 if ( a && a->isChecked() != on )
2305 a->setChecked( on );
2309 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
2311 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
2313 myViewPort->setAdvancedZoomingEnabled( on );
2315 // update action state if method is called outside
2316 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
2317 if ( a && a->isChecked() != on )
2318 a->setChecked( on );
2322 \brief Get current interaction style
2323 \return interaction style
2325 int OCCViewer_ViewWindow::interactionStyle() const
2327 return myInteractionStyle;
2331 \brief Set current interaction style
2332 \param theStyle interaction style
2334 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
2336 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
2340 \brief Get current zooming style
2341 \return zooming style
2343 int OCCViewer_ViewWindow::zoomingStyle() const
2345 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
2349 \brief Set current zooming style
2350 \param theStyle zooming style
2352 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
2354 onSwitchZoomingStyle( theStyle == 1 );
2358 \brief Dump view window contents to the pixmap.
2359 \return pixmap containing all scene rendered in the window
2361 //#define USE_OLD_IMPLEMENTATION
2362 QImage OCCViewer_ViewWindow::dumpView()
2364 Handle(V3d_View) view = myViewPort->getView();
2365 if ( view.IsNull() )
2368 int aWidth = myViewPort->width();
2369 int aHeight = myViewPort->height();
2371 #ifdef USE_OLD_IMPLEMENTATION
2372 // rnv: Old approach to dump the OCCViewer content via Frame Buffer Object
2376 #ifndef DISABLE_GLVIEWER
2377 OpenGLUtils_FrameBuffer aFrameBuffer;
2378 if ( aFrameBuffer.init( aWidth, aHeight ) )
2380 glPushAttrib( GL_VIEWPORT_BIT );
2381 glViewport( 0, 0, aWidth, aHeight );
2382 aFrameBuffer.bind();
2387 aFrameBuffer.unbind();
2390 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
2392 aFrameBuffer.bind();
2393 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
2394 aFrameBuffer.unbind();
2396 anImage = anImage.rgbSwapped();
2397 anImage = anImage.mirrored();
2401 // if frame buffers are unsupported, use old approach
2403 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
2404 QPoint p = myViewPort->mapFromParent( myViewPort->geometry().topLeft() );
2405 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
2407 QImage anImage( data, aWidth, aHeight, QImage::Format_ARGB32 );
2408 anImage = anImage.mirrored();
2409 anImage = anImage.rgbSwapped();
2412 #else // DISABLE_GLVIEWER
2416 #endif // DISABLE_GLVIEWER
2418 #else // USE_OLD_IMPLEMENTATION
2419 // rnv: New approach is to use OCCT built-in procedure
2422 view->ToPixMap(aPix, aWidth, aHeight, Graphic3d_BT_RGB);
2424 QImage anImage( aWidth, aHeight, QImage::Format_ARGB32 );
2425 for ( int i = 0; i < aWidth; i++ ) {
2426 for ( int j = 0; j < aHeight; j++ ) {
2427 Quantity_Color pixel = aPix.PixelColor( i, j ).GetRGB();
2428 QColor color = QColor::fromRgbF( pixel.Red(), pixel.Green(), pixel.Blue() );
2429 anImage.setPixelColor( i, j, color );
2433 if ( aPix.IsTopDown() )
2434 anImage = anImage.mirrored();
2437 #endif // USE_OLD_IMPLEMENTATION
2440 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& /*img*/,
2441 const QString& fileName,
2442 const QString& /*format*/ )
2445 QApplication::setOverrideCursor( Qt::WaitCursor );
2447 res = myViewPort->getView()->Dump( fileName.toStdString().c_str() );
2449 QApplication::restoreOverrideCursor();
2454 QString OCCViewer_ViewWindow::filter() const
2456 // OCCT version > 7.3.0 is not support export to PS and EPS
2457 QString formats = tr( "OCC_IMAGE_FILES" );
2458 return formats.remove(" *.eps *.ps");
2463 \brief Set parameters of the cutting plane
2464 \param on if \c true, cutting plane is enabled
2465 \param x X position of plane point
2466 \param y Y position of plane point
2467 \param z Z position of plane point
2468 \param dx X coordinate of plane normal
2469 \param dy Y coordinate of plane normal
2470 \param dz Z coordinate of plane normal
2472 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2473 const double dx, const double dy, const double dz )
2475 Handle(V3d_View) view = myViewPort->getView();
2476 if ( view.IsNull() )
2480 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2482 // try to use already existing plane or create a new one
2483 Handle(V3d_Plane) clipPlane;
2485 // calculate new a,b,c,d values for the plane
2486 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2488 pln.Coefficients(a, b, c, d);
2489 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2490 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2491 if(aPlanes->Size() > 0 ) {
2492 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2493 aClipPlane->SetEquation(pln);
2494 aClipPlane->SetOn(Standard_True);
2496 view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2500 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2501 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2502 for( ;anIter.More();anIter.Next() ){
2503 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2504 aClipPlane->SetOn(Standard_False);
2512 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2514 gp_Dir aDir = pln.Axis().Direction();
2515 gp_Pnt aPnt = pln.Location();
2516 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2521 \brief Check if any cutting plane is enabled
2522 \return \c true if at least one cutting plane is enabled
2524 bool OCCViewer_ViewWindow::isCuttingPlane()
2526 Handle(V3d_View) view = myViewPort->getView();
2528 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2529 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2530 for( ;anIter.More();anIter.Next() ) {
2531 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2532 if(aClipPlane->IsOn()) {
2541 \brief Get the visual parameters of the view window.
2542 \return visual parameters of view window
2544 viewAspect OCCViewer_ViewWindow::getViewParams() const
2546 double projX, projY, projZ, twist;
2547 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2548 double aScaleX, aScaleY, aScaleZ;
2550 Handle(V3d_View) aView3d = myViewPort->getView();
2552 aView3d->Proj( projX, projY, projZ );
2553 aView3d->At( atX, atY, atZ );
2554 aView3d->Eye( eyeX, eyeY, eyeZ );
2555 twist = aView3d->Twist();
2557 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2559 bool isShown = myModel->isTrihedronVisible();
2560 double size = myModel->trihedronSize();
2562 bool isVCShown = myModel->isViewCubeVisible();
2564 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2567 params.scale = aView3d->Scale();
2568 params.projX = projX;
2569 params.projY = projY;
2570 params.projZ = projZ;
2571 params.twist = twist;
2578 params.scaleX = aScaleX;
2579 params.scaleY = aScaleY;
2580 params.scaleZ = aScaleZ;
2581 params.name = aName;
2584 params.isVisible= isShown;
2588 params.vcIsVisible= isVCShown;
2590 // graduated trihedron
2591 bool anIsVisible = false;
2592 OCCViewer_AxisWidget::AxisData anAxisData[3];
2593 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2595 params.gtIsVisible = anIsVisible;
2596 params.gtDrawNameX = anAxisData[0].DrawName;
2597 params.gtDrawNameY = anAxisData[1].DrawName;
2598 params.gtDrawNameZ = anAxisData[2].DrawName;
2599 params.gtNameX = anAxisData[0].Name;
2600 params.gtNameY = anAxisData[1].Name;
2601 params.gtNameZ = anAxisData[2].Name;
2602 params.gtNameColorRX = anAxisData[0].NameColor.red();
2603 params.gtNameColorGX = anAxisData[0].NameColor.green();
2604 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2605 params.gtNameColorRY = anAxisData[1].NameColor.red();
2606 params.gtNameColorGY = anAxisData[1].NameColor.green();
2607 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2608 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2609 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2610 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2611 params.gtDrawValuesX = anAxisData[0].DrawValues;
2612 params.gtDrawValuesY = anAxisData[1].DrawValues;
2613 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2614 params.gtNbValuesX = anAxisData[0].NbValues;
2615 params.gtNbValuesY = anAxisData[1].NbValues;
2616 params.gtNbValuesZ = anAxisData[2].NbValues;
2617 params.gtOffsetX = anAxisData[0].Offset;
2618 params.gtOffsetY = anAxisData[1].Offset;
2619 params.gtOffsetZ = anAxisData[2].Offset;
2620 params.gtColorRX = anAxisData[0].Color.red();
2621 params.gtColorGX = anAxisData[0].Color.green();
2622 params.gtColorBX = anAxisData[0].Color.blue();
2623 params.gtColorRY = anAxisData[1].Color.red();
2624 params.gtColorGY = anAxisData[1].Color.green();
2625 params.gtColorBY = anAxisData[1].Color.blue();
2626 params.gtColorRZ = anAxisData[2].Color.red();
2627 params.gtColorGZ = anAxisData[2].Color.green();
2628 params.gtColorBZ = anAxisData[2].Color.blue();
2629 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2630 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2631 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2632 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2633 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2634 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2640 \brief Get visual parameters of this view window.
2641 \return visual parameters of view window
2643 QString OCCViewer_ViewWindow::getVisualParameters()
2645 viewAspect params = getViewParams();
2649 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2650 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2651 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2652 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2653 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2654 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2655 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2656 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2657 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2658 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2659 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2660 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2661 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2662 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2663 data << QString( "isVisible=%1" ).arg( params.isVisible );
2664 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2666 ClipPlanesList aPlanes = myModel->getClipPlanes();
2667 for ( int i=0; i < (int)aPlanes.size(); i++ )
2669 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2670 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2671 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2672 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2673 switch ( aPlane.Mode )
2675 case OCCViewer_ClipPlane::Absolute :
2677 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2679 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2681 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2682 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2683 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2687 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2692 case OCCViewer_ClipPlane::Relative :
2694 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2695 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2696 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2701 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2702 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2703 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2704 data << ClippingPlane;
2707 // graduated trihedron
2708 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2709 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2710 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2711 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2712 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2713 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2714 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2715 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2716 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2717 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2718 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2719 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2720 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2721 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2722 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2723 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2724 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2725 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2726 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2727 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2728 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2729 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2730 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2731 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2732 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2733 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2734 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2735 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2736 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2737 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2738 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2739 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2740 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2741 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2742 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2743 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2744 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2745 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2746 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2747 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2749 // ray tracing parameters
2750 Graphic3d_RenderingParams rendParams = this->getViewPort()->getView()->RenderingParams();
2751 if ( rendParams.Method == Graphic3d_RM_RAYTRACING ) {
2752 QString RayTracing = "rayTracing=";
2753 RayTracing += QString( "rtDepth~%1;" ).arg( rendParams.RaytracingDepth );
2754 RayTracing += QString( "rtReflection~%1;" ).arg( rendParams.IsReflectionEnabled );
2755 RayTracing += QString( "rtAntialiasing~%1;" ).arg( rendParams.IsAntialiasingEnabled );
2756 RayTracing += QString( "rtShadow~%1;" ).arg( rendParams.IsShadowEnabled );
2757 RayTracing += QString( "rtTransShadow~%1;" ).arg( rendParams.IsTransparentShadowEnabled );
2761 // environment texture parameters
2762 Handle(Graphic3d_TextureEnv) aTexture = this->getViewPort()->getView()->TextureEnv();
2763 if ( !aTexture.IsNull() ) {
2764 QString EnvTexture = "envTexture=";
2765 if ( aTexture->Name() == Graphic3d_NOT_ENV_UNKNOWN ) {
2766 TCollection_AsciiString aFileName;
2767 aTexture->Path().SystemName( aFileName );
2768 EnvTexture += QString( "etFile~%1;" ).arg( aFileName.ToCString() );
2771 EnvTexture += QString( "etNumber~%1;" ).arg( aTexture->Name() );
2775 // light source parameters
2776 myModel->getViewer3d()->InitDefinedLights();
2777 while ( myModel->getViewer3d()->MoreDefinedLights() )
2779 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2780 if ( aLight->Type() != V3d_AMBIENT ) {
2781 QString LightSource = QString( "lightSource=" );
2782 LightSource += QString( "lightType~%1;" ).arg( aLight->Type() );
2784 if ( aLight->Type() == V3d_DIRECTIONAL )
2785 Handle(V3d_DirectionalLight)::DownCast( aLight )->Direction( aX, aY, aZ );
2786 else if ( aLight->Type() == V3d_POSITIONAL )
2787 Handle(V3d_PositionalLight)::DownCast( aLight )->Position( aX, aY, aZ );
2789 continue; // not supported type of light source
2790 LightSource += QString( "lightX~%1;" ).arg( aX );
2791 LightSource += QString( "lightY~%1;" ).arg( aY );
2792 LightSource += QString( "lightZ~%1;" ).arg( aZ );
2793 LightSource += QString( "lightColorR~%1;" ).arg( aLight->Color().Red() );
2794 LightSource += QString( "lightColorG~%1;" ).arg( aLight->Color().Green() );
2795 LightSource += QString( "lightColorB~%1;" ).arg( aLight->Color().Blue() );
2796 LightSource += QString( "lightHeadlight~%1;" ).arg( aLight->Headlight() );
2797 data << LightSource;
2799 myModel->getViewer3d()->NextDefinedLights();
2802 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2803 data << QString( "background=%1" ).arg( bg );
2805 return data.join("*");
2809 \brief Restore visual parameters of the view window.
2810 \param parameters visual parameters of view window
2812 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2815 ClipPlanesList aClipPlanes;
2816 QStringList data = parameters.split( '*' );
2817 Qtx::BackgroundData bgData;
2818 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2820 foreach( QString param, data ) {
2821 QString paramName = param.section( '=', 0, 0 ).trimmed();
2822 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2823 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2824 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2825 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2826 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2827 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2828 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2829 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2830 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2831 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2832 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2833 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2834 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2835 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2836 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2837 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2838 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2839 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2840 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2841 else if ( paramName.contains( "ClippingPlane" ) )
2843 QStringList ClipPlaneData = paramValue.split( ';' );
2844 OCCViewer_ClipPlane aPlane;
2845 foreach( QString ClipPlaneParam, ClipPlaneData )
2847 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2848 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2849 if ( ClipPlane_paramName == "Mode" )
2851 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2853 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2854 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2855 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2856 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2859 switch ( aPlane.Mode )
2861 case OCCViewer_ClipPlane::Absolute :
2862 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2863 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2864 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2865 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2866 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2869 case OCCViewer_ClipPlane::Relative :
2870 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2871 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2872 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2877 aClipPlanes.push_back(aPlane);
2879 // graduated trihedron
2880 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2881 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2882 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2883 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2884 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2885 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2886 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2887 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2888 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2889 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2890 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2891 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2892 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2893 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2894 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2895 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2896 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2897 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2898 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2899 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2900 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2901 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2902 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2903 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2904 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2905 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2906 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2907 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2908 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2909 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2910 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2911 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2912 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2913 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2914 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2915 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2916 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2917 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2918 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2919 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2920 else if ( paramName == "rayTracing" )
2922 Graphic3d_RenderingParams& rendParams = this->getViewPort()->getView()->ChangeRenderingParams();
2923 rendParams.Method = Graphic3d_RM_RAYTRACING;
2924 QStringList rtData = paramValue.split( ';' );
2925 foreach( QString rtParam, rtData )
2927 QString rt_paramName = rtParam.section( '~', 0, 0 ).trimmed();
2928 QString rt_paramValue = rtParam.section( '~', 1, 1 ).trimmed();
2929 if ( rt_paramName == "rtDepth" ) rendParams.RaytracingDepth = rt_paramValue.toInt();
2930 else if ( rt_paramName == "rtReflection" ) rendParams.IsReflectionEnabled = rt_paramValue.toInt();
2931 else if ( rt_paramName == "rtAntialiasing" ) rendParams.IsAntialiasingEnabled = rt_paramValue.toInt();
2932 else if ( rt_paramName == "rtShadow" ) rendParams.IsShadowEnabled = rt_paramValue.toInt();
2933 else if ( rt_paramName == "rtTransShadow" ) rendParams.IsTransparentShadowEnabled = rt_paramValue.toInt();
2936 else if ( paramName == "envTexture" )
2938 Handle(Graphic3d_TextureEnv) aTexture;
2939 QStringList etData = paramValue.split( ';' );
2940 foreach( QString etParam, etData )
2942 QString et_paramName = etParam.section( '~', 0, 0 ).trimmed();
2943 QString et_paramValue = etParam.section( '~', 1, 1 ).trimmed();
2944 if ( et_paramName == "etNumber" )
2945 aTexture = new Graphic3d_TextureEnv( Graphic3d_NameOfTextureEnv( et_paramValue.toInt() ) );
2946 else if ( et_paramName == "etFile" )
2947 aTexture = new Graphic3d_TextureEnv( TCollection_AsciiString( et_paramValue.toStdString().c_str() ) );
2948 Handle(V3d_View) aView = this->getViewPort()->getView();
2949 aView->SetTextureEnv( aTexture );
2952 else if ( paramName == "lightSource" )
2954 myModel->getViewer3d()->InitDefinedLights();
2955 while ( myModel->getViewer3d()->MoreDefinedLights() )
2957 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2958 if( aLight->Type() != V3d_AMBIENT ) {
2959 myModel->getViewer3d()->DelLight( aLight );
2960 myModel->getViewer3d()->InitDefinedLights();
2962 myModel->getViewer3d()->NextDefinedLights();
2965 double aX = 0., aY = 0., aZ = 0.;
2966 double cR = 0., cG = 0., cB = 0.;
2967 V3d_TypeOfLight aType = (V3d_TypeOfLight)-1; // not specified
2968 bool isHeadlight = false;
2969 QStringList lsData = paramValue.split( ';' );
2970 foreach( QString lsParam, lsData )
2972 QString ls_paramName = lsParam.section( '~', 0, 0 ).trimmed();
2973 QString ls_paramValue = lsParam.section( '~', 1, 1 ).trimmed();
2974 if ( ls_paramName == "lightType" ) aType = V3d_TypeOfLight( ls_paramValue.toInt() );
2975 else if ( ls_paramName == "lightX" ) aX = ls_paramValue.toDouble();
2976 else if ( ls_paramName == "lightY" ) aY = ls_paramValue.toDouble();
2977 else if ( ls_paramName == "lightZ" ) aZ = ls_paramValue.toDouble();
2978 else if ( ls_paramName == "lightColorR" ) cR = ls_paramValue.toDouble();
2979 else if ( ls_paramName == "lightColorG" ) cG = ls_paramValue.toDouble();
2980 else if ( ls_paramName == "lightColorB" ) cB = ls_paramValue.toDouble();
2981 else if ( ls_paramName == "lightHeadlight" ) isHeadlight = ls_paramValue.toInt();
2983 Quantity_Color aColor = Quantity_Color( cR, cG, cB, Quantity_TOC_RGB );
2984 if( aType == V3d_DIRECTIONAL ) {
2985 Handle(V3d_DirectionalLight) aLight = new V3d_DirectionalLight();
2986 myModel->getViewer3d()->AddLight( aLight );
2987 aLight->SetDirection( aX, aY, aZ );
2988 aLight->SetColor( aColor );
2989 aLight->SetHeadlight( isHeadlight );
2990 myModel->getViewer3d()->SetLightOn( aLight );
2992 else if( aType == V3d_POSITIONAL ) {
2993 Handle(V3d_PositionalLight) aLight = new V3d_PositionalLight( gp_Pnt(aX, aY, aZ), aColor.Name() );
2994 myModel->getViewer3d()->AddLight( aLight );
2995 aLight->SetHeadlight( isHeadlight );
2996 myModel->getViewer3d()->SetLightOn( aLight );
2999 else if ( paramName == "background" ) {
3000 QString bg = paramValue.replace( "$", "=" );
3001 bgData = Qtx::stringToBackground( bg );
3005 else // old format - "1.000e+00*0.000e+00..."
3008 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
3009 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
3010 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
3011 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
3012 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
3013 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
3014 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
3015 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
3016 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
3017 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
3018 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
3019 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
3020 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
3021 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
3022 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
3023 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
3024 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
3025 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
3027 performRestoring( params );
3028 setBackground( bgData );
3029 myModel->setClipPlanes(aClipPlanes);
3033 \brief Handle show event.
3035 Emits Show() signal.
3037 \param theEvent show event
3039 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
3041 emit Show( theEvent );
3045 \brief Handle hide event.
3047 Emits Hide() signal.
3049 \param theEvent hide event
3051 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
3053 emit Hide( theEvent );
3058 Save old cursor. [ protected ]
3060 void OCCViewer_ViewWindow::saveCursor()
3062 QCursor* aCursor = NULL;
3064 aCursor = myViewPort->getDefaultCursor();
3065 myCursor = ( aCursor ? *aCursor : cursor() );
3070 Creates default sketcher. [ virtual protected ]
3072 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
3075 return new OCCViewer_RectSketcher( this, type );
3076 if ( type == Polygon )
3077 return new OCCViewer_PolygonSketcher( this, type );
3081 void OCCViewer_ViewWindow::initSketchers()
3083 if ( mySketchers.isEmpty() )
3085 mySketchers.append( createSketcher( Rect ) );
3086 mySketchers.append( createSketcher( Polygon ) );
3090 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ ) const
3092 OCCViewer_ViewSketcher* sketcher = 0;
3093 QList<OCCViewer_ViewSketcher*>::ConstIterator it;
3094 for ( it = mySketchers.cbegin(); it != mySketchers.cend() && !sketcher; ++it )
3096 OCCViewer_ViewSketcher* sk = (*it);
3097 if ( sk->type() == typ )
3104 Handles requests for sketching in the active view. [ virtual public ]
3106 void OCCViewer_ViewWindow::activateSketching( int type )
3108 OCCViewer_ViewPort3d* vp = getViewPort();
3112 if ( !vp->isSketchingEnabled() )
3115 /* Finish current sketching */
3116 if ( type == NoSketching )
3120 onSketchingFinished();
3121 mypSketcher->deactivate();
3125 /* Activate new sketching */
3128 activateSketching( NoSketching ); /* concurrency not suported */
3129 mypSketcher = getSketcher( type );
3132 mypSketcher->activate();
3133 onSketchingStarted();
3139 Unhilights detected entities. [ virtual protected ]
3141 void OCCViewer_ViewWindow::onSketchingStarted()
3146 Selection by rectangle or polygon. [ virtual protected ]
3148 void OCCViewer_ViewWindow::onSketchingFinished()
3150 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()");
3151 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
3153 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
3154 bool append = mypSketcher->isHasShift();
3155 switch( mypSketcher->type() )
3159 QRect* aRect = (QRect*)mypSketcher->data();
3162 int aLeft = aRect->left();
3163 int aRight = aRect->right();
3164 int aTop = aRect->top();
3165 int aBottom = aRect->bottom();
3169 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False);
3171 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False);
3177 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
3178 if( aPolygon && (aPolygon->size() > 2))
3180 int size = aPolygon->size();
3181 TColgp_Array1OfPnt2d anArray(1, size);
3183 QPolygon::Iterator it = aPolygon->begin();
3184 QPolygon::Iterator itEnd = aPolygon->end();
3185 for (int index = 1; it != itEnd; ++it, index++)
3187 QPoint aPoint = *it;
3188 anArray.SetValue(index, gp_Pnt2d(aPoint.x(), aPoint.y()));
3192 ic->ShiftSelect(anArray, getViewPort()->getView(), Standard_False);
3194 ic->Select(anArray, getViewPort()->getView(), Standard_False);
3202 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
3203 aViewMgr->getOCCViewer()->performSelectionChanged();
3207 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
3212 bool OCCViewer_ViewWindow::transformRequested() const
3214 return ( myOperation != NOVIEWOP );
3217 bool OCCViewer_ViewWindow::transformInProcess() const
3219 return myEventStarted;
3222 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
3224 myEventStarted = bOn;
3228 Set enabled state of transformation (rotate, zoom, etc)
3230 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
3232 if ( id != NOVIEWOP ) myStatus.insert( id, on );
3236 \return enabled state of transformation (rotate, zoom, etc)
3238 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
3240 return myStatus.contains( id ) ? myStatus[ id ] : true;
3243 void OCCViewer_ViewWindow::onMaximizedView()
3245 setMaximized(!isMaximized());
3248 void OCCViewer_ViewWindow::returnTo3dView()
3250 setReturnedTo3dView( true );
3253 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
3255 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
3256 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
3257 if ( !isVisible3dView )
3258 toolMgr()->show( ReturnTo3dViewId );
3260 toolMgr()->hide( ReturnTo3dViewId );
3261 if ( isVisible3dView ) emit returnedTo3d( );
3265 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
3267 QAction* anAction = toolMgr()->action( MaximizedId );
3268 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
3269 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
3271 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
3272 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
3273 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
3274 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
3275 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
3277 emit maximized( this, true );
3281 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
3282 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
3283 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
3284 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
3285 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
3287 emit maximized( this, false );
3292 bool OCCViewer_ViewWindow::isMaximized() const
3294 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
3297 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
3299 IsSketcherStyle = enable;
3302 bool OCCViewer_ViewWindow::isSketcherStyle() const
3304 return IsSketcherStyle;
3308 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
3313 int OCCViewer_ViewWindow::projectionType() const
3315 int mode = Orthographic;
3316 Handle(V3d_View) aView3d = myViewPort->getView();
3317 if ( !aView3d.IsNull() ) {
3318 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3319 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Perspective)
3321 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Orthographic)
3322 mode = Orthographic;
3323 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
3329 void OCCViewer_ViewWindow::setStereoType( int type )
3331 Handle(V3d_View) aView3d = myViewPort->getView();
3332 if ( !aView3d.IsNull() ) {
3333 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3334 aParams->StereoMode = (Graphic3d_StereoMode)type;
3338 int OCCViewer_ViewWindow::stereoType() const
3340 int type = QuadBuffer;
3341 Handle(V3d_View) aView3d = myViewPort->getView();
3342 if ( !aView3d.IsNull() ) {
3343 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3344 type = (OCCViewer_ViewWindow::StereoType)aParams->StereoMode;
3349 void OCCViewer_ViewWindow::setAnaglyphFilter( int type )
3351 Handle(V3d_View) aView3d = myViewPort->getView();
3352 if ( !aView3d.IsNull() ) {
3353 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3354 if (type == RedCyan)
3355 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
3356 if (type == YellowBlue)
3357 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
3358 if (type == GreenMagenta)
3359 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
3363 int OCCViewer_ViewWindow::anaglyphFilter() const
3366 Handle(V3d_View) aView3d = myViewPort->getView();
3367 if ( !aView3d.IsNull() ) {
3368 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3369 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized)
3371 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized)
3373 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple)
3374 type = GreenMagenta;
3379 void OCCViewer_ViewWindow::setStereographicFocus( int type, double value )
3381 Handle(V3d_View) aView3d = myViewPort->getView();
3382 if ( !aView3d.IsNull() ) {
3383 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3384 aCamera->SetZFocus( (Graphic3d_Camera::FocusType) type, value );
3388 int OCCViewer_ViewWindow::stereographicFocusType() const
3390 int type = Relative;
3391 Handle(V3d_View) aView3d = myViewPort->getView();
3392 if ( !aView3d.IsNull() ) {
3393 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3394 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->ZFocusType();
3399 double OCCViewer_ViewWindow::stereographicFocusValue() const
3402 Handle(V3d_View) aView3d = myViewPort->getView();
3403 if ( !aView3d.IsNull() ) {
3404 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3405 value = aCamera->ZFocus();
3410 void OCCViewer_ViewWindow::setInterocularDistance( int type, double value )
3412 Handle(V3d_View) aView3d = myViewPort->getView();
3413 if ( !aView3d.IsNull() ) {
3414 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3415 aCamera->SetIOD( (Graphic3d_Camera::IODType) type, value );
3419 int OCCViewer_ViewWindow::interocularDistanceType() const
3421 int type = Relative;
3422 Handle(V3d_View) aView3d = myViewPort->getView();
3423 if ( !aView3d.IsNull() ) {
3424 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3425 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->GetIODType();
3430 double OCCViewer_ViewWindow::interocularDistanceValue() const
3432 double value = 0.05;
3433 Handle(V3d_View) aView3d = myViewPort->getView();
3434 if ( !aView3d.IsNull() ) {
3435 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3436 value = aCamera->IOD();
3441 void OCCViewer_ViewWindow::setReverseStereo( bool reverse )
3443 Handle(V3d_View) aView3d = myViewPort->getView();
3444 if ( !aView3d.IsNull() ) {
3445 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3446 aParams->ToReverseStereo = reverse;
3450 bool OCCViewer_ViewWindow::isReverseStereo() const
3452 int reverse = false;
3453 Handle(V3d_View) aView3d = myViewPort->getView();
3454 if ( !aView3d.IsNull() ) {
3455 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3456 reverse = aParams->ToReverseStereo;
3461 void OCCViewer_ViewWindow::setVSync( bool enable )
3463 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3464 if ( !anIntCont.IsNull() ) {
3465 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3466 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3467 aCaps->swapInterval = enable;
3471 bool OCCViewer_ViewWindow::isVSync() const
3474 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3475 if ( !anIntCont.IsNull() ) {
3476 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3477 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3478 enable = aCaps->swapInterval;
3483 void OCCViewer_ViewWindow::setQuadBufferSupport( bool enable )
3485 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3486 if ( !anIntCont.IsNull() ) {
3487 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3488 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3489 aCaps->contextStereo = enable;
3493 bool OCCViewer_ViewWindow::isQuadBufferSupport() const
3496 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3497 if ( !anIntCont.IsNull() ) {
3498 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3499 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3500 enable = aCaps->contextStereo;
3505 bool OCCViewer_ViewWindow::isOpenGlStereoSupport() const
3507 GLboolean support[1];
3508 glGetBooleanv (GL_STEREO, support);
3515 QColor OCCViewer_ViewWindow::backgroundColor() const
3517 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
3521 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
3523 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
3526 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
3528 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
3531 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
3533 if ( myViewPort ) myViewPort->setBackground( theBackground );
3536 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
3538 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
3544 void OCCViewer_ViewWindow::clearViewAspects()
3546 myViewAspects.clear();
3550 \return const reference to list of view aspects
3552 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
3554 return myViewAspects;
3558 Appends new view aspect
3559 \param aParams - new view aspects
3561 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
3563 myViewAspects.append( aParams );
3567 Replaces old view aspects by new ones
3568 \param aViewList - list of new view aspects
3570 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
3572 myViewAspects = aViewList;
3576 Get camera properties for the OCC view window.
3577 \return shared pointer on camera properties.
3579 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
3581 SUIT_CameraProperties aProps;
3583 Handle(V3d_View) aSourceView = getViewPort()->getView();
3584 if ( aSourceView.IsNull() )
3587 if ( get2dMode() == No2dMode ) {
3588 aProps.setDimension( SUIT_CameraProperties::Dim3D );
3591 aProps.setDimension( SUIT_CameraProperties::Dim2D );
3592 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
3595 // read common properites of the view
3596 Standard_Real anUp[3];
3597 Standard_Real anAt[3];
3598 Standard_Real anEye[3];
3599 Standard_Real aProj[3];
3600 Standard_Real anAxialScale[3];
3602 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
3603 aSourceView->At( anAt[0], anAt[1], anAt[2] );
3604 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
3605 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3607 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3608 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
3610 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
3612 // store camera properties "as is": it is up to synchronized
3613 // view classes to provide necessary property conversion.
3614 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
3615 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
3617 if ( aSourceView->Camera()->IsOrthographic() )
3619 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
3620 aProps.setViewAngle( 0.0 );
3624 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
3625 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
3627 aProps.setMappingScale( aSourceView->Camera()->Scale() );
3634 This implementation synchronizes OCC view's camera propreties.
3636 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
3638 bool blocked = blockSignals( true );
3640 SUIT_CameraProperties aProps = theView->cameraProperties();
3641 if ( !cameraProperties().isCompatible( aProps ) ) {
3642 // other view, this one is being currently synchronized to, seems has become incompatible
3643 // we have to break synchronization
3648 Handle(V3d_View) aDestView = getViewPort()->getView();
3650 aDestView->SetImmediateUpdate( Standard_False );
3653 double aPosition[3];
3654 double aFocalPoint[3];
3655 double anAxialScale[3];
3657 // get common properties
3658 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3659 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
3660 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3661 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3664 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3665 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
3666 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3667 aDestView->Camera()->SetScale( aProps.getMappingScale() );
3669 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3670 aDestView->SetImmediateUpdate( Standard_True );
3671 aDestView->Redraw();
3673 catch (Standard_Failure&) {
3676 blockSignals( blocked );
3680 \brief Indicates whether preselection is enabled
3681 \return true if preselection is enabled
3683 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
3685 return myPreselectionEnabled;
3689 \brief Enables/disables preselection
3690 \param theIsToEnable if true - preselection will be enabled
3692 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
3694 onSwitchPreselection( theIsToEnable );
3698 \brief Indicates whether selection is enabled
3699 \return true if selection is enabled
3701 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3703 return mySelectionEnabled;
3707 \brief Enables/disables selection
3708 \param theIsToEnable if true - selection will be enabled
3710 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3712 onSwitchSelection( theIsToEnable );
3717 \brief called if clipping operation is activated / deactivated.
3719 Enables/disables clipping plane displaying.
3721 \parma on action state
3723 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3725 if(!myModel) return;
3726 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3729 if (!aClippingDlg) {
3730 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3731 myModel->setClippingDlg(aClippingDlg);
3733 if (!aClippingDlg->isVisible())
3734 aClippingDlg->show();
3736 if ( aClippingDlg ) {
3737 aClippingDlg->close();
3738 myModel->setClippingDlg(0);
3742 SUIT_ViewManager* mgr = getViewManager();
3744 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3745 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3746 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3747 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3749 QAction* a = toolMgr()->action( ClippingId );
3751 if(theIsOn != a->isChecked()){
3752 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3753 a->setChecked(theIsOn);
3754 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3761 void OCCViewer_ViewWindow::onRayTracing()
3763 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_RayTracingDlg::getName() ) ) {
3764 QDialog* aDlg = new OCCViewer_RayTracingDlg( this );
3770 void OCCViewer_ViewWindow::onEnvTexture()
3772 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_EnvTextureDlg::getName() ) ) {
3773 QDialog* aDlg = new OCCViewer_EnvTextureDlg( this );
3779 void OCCViewer_ViewWindow::onLightSource()
3781 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_LightSourceDlg::getName() ) ) {
3782 QDialog* aDlg = new OCCViewer_LightSourceDlg( this, myModel );
3788 bool OCCViewer_ViewWindow::isActionVisible( ActionId theId ) const
3790 QAction* a = toolMgr()->action( theId );
3791 return a && a->isVisible();
3794 void OCCViewer_ViewWindow::setActionVisible( ActionId theId, bool isVisible )
3796 QAction* a = toolMgr()->action( theId );
3798 a->setVisible( isVisible );
3801 void OCCViewer_ViewWindow::projAndPanToGravity(V3d_TypeOfOrientation CamOri)
3803 const bool USE_XY = true;
3805 Handle(V3d_View) aView3d = myViewPort->getView();
3806 if (aView3d.IsNull())
3810 double X = 0, Y = 0, Z = 0;
3813 const double EPS = 1E-6;
3814 int xp = myViewPort->width()/2, yp = myViewPort->height()/2;
3815 aView3d->Convert( xp, yp, X, Y, Z );
3817 gp_Dir d = aView3d->Camera()->Direction();
3818 if( fabs( d.Z() ) > EPS )
3820 double t = -Z/d.Z();
3827 // It is really necessary to compute gravity center even if it is not used in part of code below.
3828 // Without this calculation the SetProj() method and other methods are not correct.
3830 IsGr = computeGravityCenter(X2, Y2, Z2);
3832 IsGr = OCCViewer_Utilities::computeSceneBBCenter(aView3d, X2, Y2, Z2);
3834 aView3d->SetProj(CamOri);
3837 //aView3d->Update();
3838 Handle(Graphic3d_Camera) Cam = aView3d->Camera();
3840 gp_Vec dir (Cam->Direction());
3841 gp_Pnt eye = Cam->Eye();
3843 Standard_Real D = dir.Dot(V1);
3844 gp_Pnt ppdir = eye.Translated(D*dir);
3845 gp_Vec V2(ppdir, gp);
3846 gp_XYZ trEye = eye.XYZ() + V2.XYZ();
3848 double xat, yat, zat;
3849 aView3d->At(xat, yat, zat);
3850 gp_Pnt At(xat, yat, zat);
3851 gp_XYZ trAt = At.XYZ() + V2.XYZ();
3852 aView3d->SetEye(trEye.X(), trEye.Y(), trEye.Z());
3853 aView3d->SetAt(trAt.X(), trAt.Y(), trAt.Z());
3858 bool OCCViewer_ViewWindow::isAutomaticZoom() const
3860 return myAutomaticZoom;
3863 void OCCViewer_ViewWindow::setAutomaticZoom(const bool isOn)
3865 myAutomaticZoom = isOn;
3869 void OCCViewer_ViewWindow::enableAutoRotation( const bool isEnable )
3871 SUIT_ViewWindow::enableAutoRotation(isEnable);
3873 delete myAutoRotate;
3874 myAutoRotate = nullptr;
3877 myAutoRotate = new OCCViewer_AutoRotate(this);