1 // Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : OCCViewer_ViewWindow.cxx
26 #include "OCCViewer_ViewWindow.h"
27 #include "OCCViewer_ViewFrame.h"
28 #include "OCCViewer_ViewModel.h"
29 #include "OCCViewer_ViewPort3d.h"
30 #include "OCCViewer_ViewManager.h"
31 #include "OCCViewer_ViewSketcher.h"
32 #include "OCCViewer_CreateRestoreViewDlg.h"
33 #include "OCCViewer_ClipPlane.h"
34 #include "OCCViewer_SetRotationPointDlg.h"
35 #include "OCCViewer_AxialScaleDlg.h"
36 #include "OCCViewer_CubeAxesDlg.h"
37 #include "OCCViewer_ClippingDlg.h"
38 #include "OCCViewer_RayTracingDlg.h"
39 #include "OCCViewer_EnvTextureDlg.h"
40 #include "OCCViewer_LightSourceDlg.h"
41 #include "OCCViewer_Utilities.h"
43 #include <SUIT_Desktop.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_ViewManager.h>
46 #include <SUIT_Tools.h>
47 #include <SUIT_ResourceMgr.h>
48 #include <SUIT_MessageBox.h>
49 #include <SUIT_Application.h>
51 #include <QtxActionToolMgr.h>
52 #include <QtxMultiAction.h>
53 #include <QtxRubberBand.h>
59 #include <QMouseEvent>
60 #include <QApplication>
61 #include <QActionGroup>
64 #include <AIS_ListOfInteractive.hxx>
65 #include <AIS_ListIteratorOfListOfInteractive.hxx>
66 #include <AIS_Shape.hxx>
68 #include <BRep_Tool.hxx>
69 #include <BRepBndLib.hxx>
70 #include <BRepGProp.hxx>
71 #include <GProp_GProps.hxx>
74 #include <Graphic3d_SequenceOfHClipPlane.hxx>
75 #include <Graphic3d_ClipPlane.hxx>
76 #include <OpenGl_GraphicDriver.hxx>
77 #include <OpenGLUtils_FrameBuffer.h>
78 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
79 #include <Graphic3d_MapOfStructure.hxx>
80 #include <Graphic3d_Structure.hxx>
81 #include <Graphic3d_StereoMode.hxx>
82 #include <Graphic3d_RenderingParams.hxx>
83 #include <Graphic3d_BndBox3d.hxx>
85 #include <V3d_Plane.hxx>
86 #include <V3d_Light.hxx>
90 #include <gp_GTrsf.hxx>
91 #include <TColgp_Array1OfPnt2d.hxx>
93 #include <Image_PixMap.hxx>
95 #include <Standard_Version.hxx>
96 #include <Standard_Failure.hxx>
98 #include "utilities.h"
100 // // OpenCV includes
102 // #include <highgui.h>
104 static QEvent* l_mbPressEvent = 0;
107 //# include <QWindowsStyle>
111 #include <OpenGL/gl.h>
116 // To avoid conflict between KeyPress from the X.h (define KeyPress 2)
117 // and QEvent::KeyPress (qevent.h)
127 // Enable ray tracing features
128 #define ENABLE_RAY_TRACING
130 const char* imageZoomCursor[] = {
135 "................................",
136 "................................",
137 ".#######........................",
138 "..aaaaaaa.......................",
139 "................................",
140 ".............#####..............",
141 "...........##.aaaa##............",
142 "..........#.aa.....a#...........",
143 ".........#.a.........#..........",
144 ".........#a..........#a.........",
145 "........#.a...........#.........",
146 "........#a............#a........",
147 "........#a............#a........",
148 "........#a............#a........",
149 "........#a............#a........",
150 ".........#...........#.a........",
151 ".........#a..........#a.........",
152 ".........##.........#.a.........",
153 "........#####.....##.a..........",
154 ".......###aaa#####.aa...........",
155 "......###aa...aaaaa.......#.....",
156 ".....###aa................#a....",
157 "....###aa.................#a....",
158 "...###aa...............#######..",
159 "....#aa.................aa#aaaa.",
160 ".....a....................#a....",
161 "..........................#a....",
162 "...........................a....",
163 "................................",
164 "................................",
165 "................................",
166 "................................"};
168 const char* imageRotateCursor[] = {
173 "................................",
174 "................................",
175 "................................",
176 "................................",
177 "........#.......................",
178 ".......#.a......................",
179 "......#######...................",
180 ".......#aaaaa#####..............",
181 "........#..##.a#aa##........##..",
182 ".........a#.aa..#..a#.....##.aa.",
183 ".........#.a.....#...#..##.aa...",
184 ".........#a.......#..###.aa.....",
185 "........#.a.......#a..#aa.......",
186 "........#a.........#..#a........",
187 "........#a.........#a.#a........",
188 "........#a.........#a.#a........",
189 "........#a.........#a.#a........",
190 ".........#.........#a#.a........",
191 "........##a........#a#a.........",
192 "......##.a#.......#.#.a.........",
193 "....##.aa..##.....##.a..........",
194 "..##.aa.....a#####.aa...........",
195 "...aa.........aaa#a.............",
196 "................#.a.............",
197 "...............#.a..............",
198 "..............#.a...............",
199 "...............a................",
200 "................................",
201 "................................",
202 "................................",
203 "................................",
204 "................................"};
206 const char* imageCrossCursor[] = {
211 "................................",
212 "................................",
213 "................................",
214 "................................",
215 "................................",
216 "................................",
217 "................................",
218 "...............#................",
219 "...............#a...............",
220 "...............#a...............",
221 "...............#a...............",
222 "...............#a...............",
223 "...............#a...............",
224 "...............#a...............",
225 "...............#a...............",
226 ".......#################........",
227 "........aaaaaaa#aaaaaaaaa.......",
228 "...............#a...............",
229 "...............#a...............",
230 "...............#a...............",
231 "...............#a...............",
232 "...............#a...............",
233 "...............#a...............",
234 "...............#a...............",
235 "................a...............",
236 "................................",
237 "................................",
238 "................................",
239 "................................",
240 "................................",
241 "................................",
242 "................................"};
247 \param theDesktop main window of application
248 \param theModel OCC 3D viewer
250 OCCViewer_ViewWindow::OCCViewer_ViewWindow( SUIT_Desktop* theDesktop,
251 OCCViewer_Viewer* theModel )
252 : SUIT_ViewWindow( theDesktop )
256 myEnableDrawMode = false;
257 myDrawRectEnabled = true;
259 updateEnabledDrawMode();
261 mySetRotationPointDlg = 0;
264 IsSketcherStyle = false;
271 myInteractionStyle = SUIT_ViewModel::STANDARD;
272 myPreselectionEnabled = true;
273 mySelectionEnabled = true;
275 myCursorIsHand = false;
276 myPanningByBtn = false;
277 myAutomaticZoom = true;
285 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
288 qDeleteAll( mySketchers );
292 \brief Internal initialization.
294 void OCCViewer_ViewWindow::initLayout()
296 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
297 myViewPort->installEventFilter(this);
298 setCentralWidget(myViewPort);
299 myOperation = NOVIEWOP;
301 myCurrPointType = BBCENTER;
302 myPrevPointType = BBCENTER;
303 mySelectedPoint = gp_Pnt(0.,0.,0.);
304 myRotationPointSelection = false;
306 setTransformRequested ( NOVIEWOP );
307 setTransformInProcess ( false );
324 // Graduated axes dialog
325 QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
326 myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
327 myCubeAxesDlg->initialize();
329 connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
332 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
334 return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
338 \brief Detect viewer operation according the the mouse button pressed
339 and key modifiers used.
340 \param theEvent mouse event
341 \return type of the operation
343 OCCViewer_ViewWindow::OperationType
344 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
346 OperationType aOp = NOVIEWOP;
347 SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
348 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
349 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
351 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
352 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
354 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
355 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
356 (my2dMode == No2dMode))
363 \brief Customize event handling
364 \param watched event receiver object
366 \return \c true if the event processing should be stopped
368 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
370 if ( watched == myViewPort ) {
371 int aType = e->type();
373 case QEvent::MouseButtonPress:
374 vpMousePressEvent((QMouseEvent*) e);
377 case QEvent::MouseButtonRelease:
378 vpMouseReleaseEvent((QMouseEvent*) e);
381 case QEvent::MouseMove:
382 vpMouseMoveEvent((QMouseEvent*) e);
385 case QEvent::MouseButtonDblClick:
386 emit mouseDoubleClicked(this, (QMouseEvent*)e);
391 QWheelEvent* aEvent = (QWheelEvent*) e;
393 if ( aEvent->modifiers().testFlag(Qt::ControlModifier) ) {
394 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
395 if ( isPreselectionEnabled() ) {
396 if ( aEvent->delta() > 0 ) {
397 ic->HilightNextDetected( myViewPort->getView() );
399 ic->HilightPreviousDetected( myViewPort->getView() );
404 emit vpTransformationStarted ( ZOOMVIEW );
405 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
406 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
409 int x1 = (int)( aEvent->x() + width()*delta/100 );
410 int y1 = (int)( aEvent->y() + height()*delta/100 );
411 myViewPort->zoom( x, y, x1, y1 );
412 emit vpTransformationFinished ( ZOOMVIEW );
417 case QEvent::ContextMenu:
419 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
420 if ( aEvent->reason() != QContextMenuEvent::Mouse )
421 emit contextMenuRequested( aEvent );
425 case QEvent::KeyPress:
426 emit keyPressed(this, (QKeyEvent*) e);
429 case QEvent::KeyRelease:
430 emit keyReleased(this, (QKeyEvent*) e);
437 return SUIT_ViewWindow::eventFilter(watched, e);
441 \brief Enable / disable draw rect (rubber band) mode
443 bool OCCViewer_ViewWindow::enableDrawMode( bool on )
445 bool prev = myDrawRectEnabled;
446 myDrawRectEnabled = on;
447 updateEnabledDrawMode();
452 \brief Update state of enable draw mode state.
454 void OCCViewer_ViewWindow::updateEnabledDrawMode()
456 myEnableDrawMode = myDrawRectEnabled;
458 myEnableDrawMode = myEnableDrawMode && myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
462 \brief Handle mouse press event
463 \param theEvent mouse event
465 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
467 myStartX = theEvent->x();
468 myStartY = theEvent->y();
469 int anInteractionStyle = interactionStyle();
471 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
472 // which are assigned for pan and rotate - these operations are activated immediately after pressing
473 // of the first button, so it is necessary to switch to zoom when the second button is pressed
474 bool aSwitchToZoom = false;
475 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
476 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
477 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
480 switch ( myOperation ) {
482 if ( theEvent->button() == Qt::LeftButton )
483 emit vpTransformationStarted ( WINDOWFIT );
487 if ( theEvent->button() == Qt::LeftButton )
488 emit vpTransformationStarted ( PANGLOBAL );
492 if ( theEvent->button() == Qt::LeftButton ) {
493 myViewPort->startZoomAtPoint( myStartX, myStartY );
494 emit vpTransformationStarted ( ZOOMVIEW );
499 if ( aSwitchToZoom ) {
500 myViewPort->startZoomAtPoint( myStartX, myStartY );
503 else if ( theEvent->button() == Qt::LeftButton )
504 emit vpTransformationStarted ( PANVIEW );
508 if ( aSwitchToZoom ) {
509 myViewPort->startZoomAtPoint( myStartX, myStartY );
512 else if ( theEvent->button() == Qt::LeftButton ) {
513 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
514 emit vpTransformationStarted ( ROTATE );
519 /* Try to activate a transformation */
520 OperationType aState;
521 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
522 aState = getButtonState(theEvent, anInteractionStyle);
524 aState = OCCViewer_ViewWindow::NOVIEWOP;
529 myViewPort->startZoomAtPoint( myStartX, myStartY );
537 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
540 if ( myRotationPointSelection )
542 if ( theEvent->button() == Qt::LeftButton )
544 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
545 ic->Select( Standard_True );
546 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
548 TopoDS_Shape aShape = ic->SelectedShape();
549 GProp_GProps aSystem;
551 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
553 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
555 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE )
557 BRepGProp::LinearProperties( aShape, aSystem );
558 aPnt = aSystem.CentreOfMass();
560 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE )
562 BRepGProp::SurfaceProperties( aShape, aSystem );
563 aPnt = aSystem.CentreOfMass();
565 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID )
567 BRepGProp::VolumeProperties( aShape, aSystem );
568 aPnt = aSystem.CentreOfMass();
572 myCurrPointType = myPrevPointType;
576 if ( mySetRotationPointDlg )
578 myRotationPointSelection = false;
579 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
582 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
583 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
586 myOperation = NOVIEWOP;
587 myViewPort->setCursor( myCursor );
588 myCursorIsHand = false;
589 myRotationPointSelection = false;
593 emit mousePressed(this, theEvent);
596 /* notify that we start a transformation */
597 if ( transformRequested() )
598 emit vpTransformationStarted ( myOperation );
600 if ( transformRequested() )
601 setTransformInProcess( true );
603 /* we may need it for sketching... */
604 if ( l_mbPressEvent )
605 delete l_mbPressEvent;
606 l_mbPressEvent = new QMouseEvent( *theEvent );
611 \brief Start zooming operation.
613 Sets the corresponding cursor for the widget.
615 void OCCViewer_ViewWindow::activateZoom()
617 if ( !transformRequested() && !myCursorIsHand )
618 saveCursor(); /* save old cursor */
620 if ( myOperation != ZOOMVIEW ) {
621 QPixmap zoomPixmap (imageZoomCursor);
622 QCursor zoomCursor (zoomPixmap);
623 if( setTransformRequested ( ZOOMVIEW ) )
624 myViewPort->setCursor( zoomCursor );
629 void OCCViewer_ViewWindow::onPanning()
631 OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( getViewManager() );
632 bool isChained = aMgr->isChainedOperations();
633 bool isReset = ( myPanningByBtn && isChained );
640 myPanningByBtn = true;
646 \brief Start panning operation.
648 Sets the corresponding cursor for the widget.
650 void OCCViewer_ViewWindow::activatePanning()
652 if ( !transformRequested() && !myCursorIsHand )
653 saveCursor(); // save old cursor
655 if ( myOperation != PANVIEW ) {
656 QCursor panCursor (Qt::SizeAllCursor);
657 if( setTransformRequested ( PANVIEW ) )
658 myViewPort->setCursor( panCursor );
663 \brief Start rotation operation
665 Sets the corresponding cursor for the widget.
667 void OCCViewer_ViewWindow::activateRotation()
669 if ( !transformRequested() && !myCursorIsHand )
670 saveCursor(); // save old cursor
672 if ( myOperation != ROTATE ) {
673 QPixmap rotatePixmap (imageRotateCursor);
674 QCursor rotCursor (rotatePixmap);
675 if( setTransformRequested ( ROTATE ) )
676 myViewPort->setCursor( rotCursor );
681 \brief Compute the gravity center.
682 \param theX used to return X coordinate of the gravity center
683 \param theY used to return Y coordinate of the gravity center
684 \param theZ used to return Z coordinate of the gravity center
685 \return \c true if the gravity center is computed
687 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
689 Handle(V3d_View) aView3d = myViewPort->getView();
691 // Project boundaries points and add to avergae gravity
692 // the ones which lie within the screen limits
693 Standard_Real aScreenLimits[4] = { 0.0, 0.0, 0.0, 0.0 };
695 // NDC space screen limits
696 aScreenLimits[0] = -1.0;
697 aScreenLimits[1] = 1.0;
698 aScreenLimits[2] = -1.0;
699 aScreenLimits[3] = 1.0;
701 Standard_Integer aPointsNb = 0;
703 Standard_Real aXmin = 0.0;
704 Standard_Real aYmin = 0.0;
705 Standard_Real aZmin = 0.0;
706 Standard_Real aXmax = 0.0;
707 Standard_Real aYmax = 0.0;
708 Standard_Real aZmax = 0.0;
710 Graphic3d_MapOfStructure aSetOfStructures;
711 aView3d->View()->DisplayedStructures( aSetOfStructures );
712 Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures );
714 for( ; aStructureIt.More(); aStructureIt.Next() ) {
715 const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key();
716 if ( aStructure->IsEmpty() || !aStructure->IsVisible() || aStructure->CStructure()->IsForHighlight )
719 Bnd_Box aBox1 = aStructure->MinMaxValues();
720 const Graphic3d_BndBox3d& aBox = aStructure->CStructure()->BoundingBox();
723 aXmin = /*aBox.IsVoid() ? RealFirst() :*/ aBox.CornerMin().x();
724 aYmin = /*aBox.IsVoid() ? RealFirst() : */aBox.CornerMin().y();
725 aZmin = /*aBox.IsVoid() ? RealFirst() : */aBox.CornerMin().z();
726 aXmax = /*aBox.IsVoid() ? RealLast() : */aBox.CornerMax().x();
727 aYmax = /*aBox.IsVoid() ? RealLast() : */aBox.CornerMax().y();
728 aZmax = /*aBox.IsVoid() ? RealLast() : */aBox.CornerMax().z();
730 // Infinite structures are skipped
731 Standard_Real aLIM = ShortRealLast() - 1.0;
732 if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
733 || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
737 gp_Pnt aPoints[8] = {
738 gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
739 gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
740 gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
741 gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
744 for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
745 const gp_Pnt& aBBPoint = aPoints[aPointIt];
747 gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
748 const Standard_Real& U = aProjected.X();
749 const Standard_Real& V = aProjected.Y();
751 if (U >= aScreenLimits[0]
752 && U <= aScreenLimits[1]
753 && V >= aScreenLimits[2]
754 && V <= aScreenLimits[3])
757 theX += aBBPoint.X();
758 theY += aBBPoint.Y();
759 theZ += aBBPoint.Z();
776 \brief Set the gravity center as a rotation point.
778 void OCCViewer_ViewWindow::activateSetRotationGravity()
780 if ( myRotationPointSelection )
782 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
785 myOperation = NOVIEWOP;
786 myViewPort->setCursor( myCursor );
787 myCursorIsHand = false;
788 myRotationPointSelection = false;
791 myPrevPointType = myCurrPointType;
792 myCurrPointType = BBCENTER;
794 Standard_Real Xcenter, Ycenter, Zcenter;
795 if ( OCCViewer_Utilities::computeVisibleBBCenter( myViewPort->getView(), Xcenter, Ycenter, Zcenter ) )
796 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
800 \brief Update gravity center in the "Set Rotation Point" dialog box.
801 \sa OCCViewer_SetRotationPointDlg class
803 void OCCViewer_ViewWindow::updateGravityCoords()
805 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == BBCENTER )
807 Standard_Real Xcenter, Ycenter, Zcenter;
808 if ( OCCViewer_Utilities::computeVisibleBBCenter( myViewPort->getView(), Xcenter, Ycenter, Zcenter ) )
809 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
814 \brief Set the point selected by the user as a rotation point.
815 \param theX X coordinate of the rotation point
816 \param theY Y coordinate of the rotation point
817 \param theZ Z coordinate of the rotation point
819 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
821 if ( myRotationPointSelection )
823 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
826 myOperation = NOVIEWOP;
827 myViewPort->setCursor( myCursor );
828 myCursorIsHand = false;
829 myRotationPointSelection = false;
832 myPrevPointType = myCurrPointType;
833 myCurrPointType = SELECTED;
834 mySelectedPoint.SetCoord(theX,theY,theZ);
838 \brief Start the shape selection process.
840 void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
842 myPrevPointType = myCurrPointType;
843 myCurrPointType = SELECTED;
845 // activate selection ------>
846 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
849 AIS_ListOfInteractive aList;
850 ic->DisplayedObjects( aList );
851 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
853 Handle(AIS_InteractiveObject) anObj = it.Value();
854 if ( !anObj.IsNull() && anObj->HasPresentation() &&
855 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
858 ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
861 // activate selection <------
863 if ( !myCursorIsHand )
865 QCursor handCursor (Qt::PointingHandCursor);
866 myCursorIsHand = true;
868 myViewPort->setCursor( handCursor );
870 myRotationPointSelection = true;
874 \brief Start global panning operation
876 Sets the corresponding cursor for the widget.
878 void OCCViewer_ViewWindow::activateGlobalPanning()
880 Handle(V3d_View) aView3d = myViewPort->getView();
881 if ( !aView3d.IsNull() ) {
882 QPixmap globalPanPixmap (imageCrossCursor);
883 QCursor glPanCursor (globalPanPixmap);
884 myCurScale = aView3d->Scale();
885 aView3d->FitAll(0.01, false);
886 saveCursor(); // save old cursor
887 myViewPort->fitAll(); // fits view before selecting a new scene center
888 if( setTransformRequested( PANGLOBAL ) )
889 myViewPort->setCursor( glPanCursor );
894 \brief Starts fit operation.
896 Sets the corresponding cursor for the widget.
898 void OCCViewer_ViewWindow::activateWindowFit()
900 if ( !transformRequested() && !myCursorIsHand )
901 saveCursor(); /* save old cursor */
903 if ( myOperation != WINDOWFIT ) {
904 QCursor handCursor (Qt::PointingHandCursor);
905 if( setTransformRequested ( WINDOWFIT ) )
907 myViewPort->setCursor ( handCursor );
908 myCursorIsHand = true;
914 \brief Start delayed viewer operation.
916 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
918 bool ok = transformEnabled( op );
919 myOperation = ok ? op : NOVIEWOP;
920 myViewPort->setMouseTracking( myOperation == NOVIEWOP );
925 \brief Handle mouse move event.
926 \param theEvent mouse event
928 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
930 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
932 switch ( getButtonState( theEvent, interactionStyle() ) ) {
934 myViewPort->startZoomAtPoint( myStartX, myStartY );
942 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
949 myCurrX = theEvent->x();
950 myCurrY = theEvent->y();
951 switch (myOperation) {
953 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
957 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
963 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
977 if ( myRotationPointSelection || isSketcherStyle() )
979 emit mouseMoving( this, theEvent );
983 int aState = theEvent->modifiers();
984 int aButton = theEvent->buttons();
985 int anInteractionStyle = interactionStyle();
986 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
987 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
988 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
989 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
990 myDrawRect = myEnableDrawMode;
993 //if ( !myCursorIsHand ) { // we are going to sketch a rectangle
994 // QCursor handCursor (Qt::PointingHandCursor);
995 // myCursorIsHand = true;
997 // myViewPort->setCursor( handCursor );
1000 SelectionStyle aStyle = selectionStyle();
1001 activateSketching(aStyle == RectStyle ? Rect : Polygon);
1004 if (l_mbPressEvent) {
1005 QApplication::sendEvent(getViewPort(), l_mbPressEvent);
1006 delete l_mbPressEvent;
1009 QApplication::sendEvent(getViewPort(), theEvent);
1012 emit mouseMoving( this, theEvent );
1014 //else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
1015 // aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
1016 // ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
1017 // aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
1018 // OCCViewer_ViewSketcher* sketcher = 0;
1019 // QList<OCCViewer_ViewSketcher*>::Iterator it;
1020 // for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
1022 // OCCViewer_ViewSketcher* sk = (*it);
1023 // if( sk->isDefault() && sk->sketchButton() == aButton )
1026 // if ( sketcher && myCurSketch == -1 )
1028 // activateSketching( sketcher->type() );
1029 // if ( mypSketcher )
1031 // myCurSketch = mypSketcher->sketchButton();
1033 // if ( l_mbPressEvent )
1035 // QApplication::sendEvent( getViewPort(), l_mbPressEvent );
1036 // delete l_mbPressEvent;
1037 // l_mbPressEvent = 0;
1039 // QApplication::sendEvent( getViewPort(), theEvent );
1044 emit mouseMoving( this, theEvent );
1050 \brief Handle mouse release event.
1051 \param theEvent mouse event
1053 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
1055 switch ( myOperation ) {
1058 int prevState = myCurSketch;
1059 if(theEvent->button() == Qt::RightButton)
1061 QList<OCCViewer_ViewSketcher*>::Iterator it;
1062 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
1064 OCCViewer_ViewSketcher* sk = (*it);
1065 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
1070 emit mouseReleased(this, theEvent);
1071 if(theEvent->button() == Qt::RightButton && prevState == -1)
1073 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1074 theEvent->pos(), theEvent->globalPos() );
1075 emit contextMenuRequested( &aEvent );
1080 myViewPort->endRotation();
1087 OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( getViewManager() );
1088 bool isChained = aMgr->isChainedOperations();
1089 bool isReset = !( myOperation==PANVIEW && myPanningByBtn && isChained ) || theEvent->button() == Qt::RightButton;
1096 if ( theEvent->button() == Qt::LeftButton ) {
1097 myViewPort->setCenter( theEvent->x(), theEvent->y() );
1098 myViewPort->getView()->SetScale(myCurScale);
1104 if ( theEvent->button() == Qt::LeftButton ) {
1105 myCurrX = theEvent->x();
1106 myCurrY = theEvent->y();
1108 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1109 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1116 // NOTE: viewer 3D detects a rectangle of selection using this event
1117 // so we must emit it BEFORE resetting the selection rectangle
1119 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1123 myViewPort->update();
1126 if ( l_mbPressEvent ) {
1127 delete l_mbPressEvent;
1133 \brief Reset the viewport to its initial state
1134 ( no transformations in process etc. )
1136 void OCCViewer_ViewWindow::resetState()
1140 if ( myRotationPointSelection )
1142 QCursor handCursor (Qt::PointingHandCursor);
1143 myViewPort->setCursor( handCursor );
1147 if ( transformRequested() || myCursorIsHand )
1148 myViewPort->setCursor( myCursor );
1149 myCursorIsHand = false;
1152 if ( transformRequested() )
1153 emit vpTransformationFinished (myOperation);
1155 setTransformInProcess( false );
1156 setTransformRequested( NOVIEWOP );
1158 myPanningByBtn = false;
1163 \brief Draw rubber band rectangle.
1165 void OCCViewer_ViewWindow::drawRect()
1167 if ( !myRectBand ) {
1168 myRectBand = new QtxRectRubberBand( myViewPort );
1171 myRectBand->setUpdatesEnabled ( false );
1172 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1173 myRectBand->initGeometry( aRect );
1175 if ( !myRectBand->isVisible() )
1178 myRectBand->setUpdatesEnabled ( true );
1182 \brief Clear rubber band rectangle on the end on the dragging operation.
1184 void OCCViewer_ViewWindow::endDrawRect()
1187 myRectBand->clearGeometry();
1193 \brief Create actions.
1195 void OCCViewer_ViewWindow::createActions()
1197 if( !toolMgr()->isEmpty() )
1200 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1207 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1208 tr( "MNU_DUMP_VIEW" ), 0, this);
1209 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1210 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1211 toolMgr()->registerAction( aAction, DumpId );
1214 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1215 tr( "MNU_FITALL" ), 0, this);
1216 aAction->setStatusTip(tr("DSC_FITALL"));
1217 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1218 toolMgr()->registerAction( aAction, FitAllId );
1221 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1222 tr( "MNU_FITRECT" ), 0, this);
1223 aAction->setStatusTip(tr("DSC_FITRECT"));
1224 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1225 toolMgr()->registerAction( aAction, FitRectId );
1228 aAction = new QtxAction(tr("MNU_FITSELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITSELECTION" ) ),
1229 tr( "MNU_FITSELECTION" ), 0, this);
1230 aAction->setStatusTip(tr("DSC_FITSELECTION"));
1231 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
1232 toolMgr()->registerAction( aAction, FitSelectionId );
1235 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1236 tr( "MNU_ZOOM_VIEW" ), 0, this);
1237 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1238 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1239 toolMgr()->registerAction( aAction, ZoomId );
1242 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1243 tr( "MNU_PAN_VIEW" ), 0, this);
1244 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1245 connect(aAction, SIGNAL(triggered()), this, SLOT(onPanning()));
1246 toolMgr()->registerAction( aAction, PanId );
1249 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1250 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1251 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1252 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1253 toolMgr()->registerAction( aAction, GlobalPanId );
1256 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1257 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1258 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1259 mySetRotationPointAction->setCheckable( true );
1260 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1261 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1264 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1265 tr( "MNU_ROTATE_VIEW" ), 0, this);
1266 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1267 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1268 toolMgr()->registerAction( aAction, RotationId );
1271 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1272 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1273 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1274 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1275 this->addAction(aAction);
1276 toolMgr()->registerAction( aAction, FrontId );
1278 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1279 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1280 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1281 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1282 this->addAction(aAction);
1283 toolMgr()->registerAction( aAction, BackId );
1285 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1286 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1287 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1288 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1289 this->addAction(aAction);
1290 toolMgr()->registerAction( aAction, TopId );
1292 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1293 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1294 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1295 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1296 this->addAction(aAction);
1297 toolMgr()->registerAction( aAction, BottomId );
1299 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1300 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1301 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1302 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1303 this->addAction(aAction);
1304 toolMgr()->registerAction( aAction, LeftId );
1306 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1307 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1308 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1309 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1310 this->addAction(aAction);
1311 toolMgr()->registerAction( aAction, RightId );
1313 // rotate anticlockwise
1314 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1315 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1316 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1317 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1318 this->addAction(aAction);
1319 toolMgr()->registerAction( aAction, AntiClockWiseId );
1322 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1323 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1324 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1325 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1326 this->addAction(aAction);
1327 toolMgr()->registerAction( aAction, ClockWiseId );
1329 // Projection mode group
1331 // - orthographic projection
1332 aAction = new QtxAction(tr("MNU_ORTHOGRAPHIC_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ORTHOGRAPHIC" ) ),
1333 tr( "MNU_ORTHOGRAPHIC_MODE" ), 0, this);
1334 aAction->setStatusTip(tr("DSC_ORTHOGRAPHIC_MODE"));
1335 aAction->setCheckable(true);
1336 toolMgr()->registerAction( aAction, OrthographicId );
1338 // - perspective projection
1339 aAction = new QtxAction(tr("MNU_PERSPECTIVE_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PERSPECTIVE" ) ),
1340 tr( "MNU_PERSPECTIVE_MODE" ), 0, this);
1341 aAction->setStatusTip(tr("DSC_PERSPECTIVE_MODE"));
1342 aAction->setCheckable(true);
1343 toolMgr()->registerAction( aAction, PerspectiveId );
1345 // - stereo projection
1346 aAction = new QtxAction(tr("MNU_STEREO_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STEREO" ) ),
1347 tr( "MNU_STEREO_MODE" ), 0, this);
1348 aAction->setStatusTip(tr("DSC_STEREO_MODE"));
1349 aAction->setCheckable(true);
1350 toolMgr()->registerAction( aAction, StereoId );
1351 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onStereoType(bool)));
1353 // - add exclusive action group
1354 QActionGroup* aProjectionGroup = new QActionGroup( this );
1355 aProjectionGroup->addAction( toolMgr()->action( OrthographicId ) );
1356 aProjectionGroup->addAction( toolMgr()->action( PerspectiveId ) );
1357 connect(aProjectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProjectionType(QAction*)));
1360 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1361 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1362 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1363 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1364 this->addAction(aAction);
1365 toolMgr()->registerAction( aAction, ResetId );
1368 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1369 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1370 tr("MNU_CLONE_VIEW"), 0, this);
1371 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1372 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1373 toolMgr()->registerAction( aAction, CloneId );
1375 aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
1376 tr("MNU_CLIPPING"), 0, this);
1377 aAction->setStatusTip (tr("DSC_CLIPPING"));
1378 aAction->setCheckable (true);
1379 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1380 toolMgr()->registerAction (aAction, ClippingId);
1382 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1383 tr( "MNU_SHOOT_VIEW" ), 0, this);
1384 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1385 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1386 toolMgr()->registerAction( aAction, MemId );
1388 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1389 tr( "MNU_PRESETS_VIEW" ), 0, this);
1390 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1391 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1392 toolMgr()->registerAction( aAction, RestoreId );
1394 if (myModel->trihedronActivated()) {
1395 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1396 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1397 aAction->setCheckable( true );
1398 aAction->setChecked( true );
1399 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1400 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1401 toolMgr()->registerAction( aAction, TrihedronShowId );
1405 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1406 tr( "MNU_SCALING" ), 0, this);
1407 aAction->setStatusTip(tr("DSC_SCALING"));
1408 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1409 toolMgr()->registerAction( aAction, AxialScaleId );
1411 // Enable/disable preselection
1412 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1413 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1414 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1415 aAction->setCheckable(true);
1416 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1417 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1419 // Enable/disable selection
1420 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1421 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1422 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1423 aAction->setCheckable(true);
1424 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1425 toolMgr()->registerAction( aAction, SwitchSelectionId );
1428 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1429 tr( "MNU_GRADUATED_AXES" ), 0, this);
1430 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1431 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1432 toolMgr()->registerAction( aAction, GraduatedAxesId );
1434 // Active only ambient light or not
1435 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1436 tr( "MNU_AMBIENT" ), 0, this);
1437 aAction->setStatusTip(tr("DSC_AMBIENT"));
1438 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1439 toolMgr()->registerAction( aAction, AmbientId );
1441 // Switch between interaction styles
1442 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1443 tr( "MNU_STYLE_SWITCH" ), 0, this);
1444 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1445 aAction->setCheckable(true);
1446 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1447 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1449 // Switch between zooming styles
1450 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1451 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1452 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1453 aAction->setCheckable(true);
1454 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1455 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1457 // Switch advanced selection style (poligone/circle)
1458 aAction = new QtxAction(tr("MNU_RECTANGLE_SELECTION_STYLE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RECT_STYLE" ) ),
1459 tr( "MNU_RECTANGLE_SELECTION_STYLE" ), 0, this);
1460 aAction->setStatusTip(tr("DSC_RECTANGLE_SELECTION_STYLE"));
1461 aAction->setCheckable(true);
1462 toolMgr()->registerAction( aAction, RectangleSelectionStyleId);
1464 aAction = new QtxAction(tr("MNU_POLYGON_SELECTION_STYLE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_POLY_STYLE" ) ),
1465 tr( "MNU_POLYGON_SELECTION_STYLE" ), 0, this);
1466 aAction->setStatusTip(tr("DSC_POLYGON_SELECTION_STYLE"));
1467 aAction->setCheckable(true);
1468 toolMgr()->registerAction( aAction, PolygonSelectionStyleId);
1470 aAction = new QtxAction(tr("MNU_CIRCLE_SELECTION_STYLE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CIRCLE_STYLE" ) ),
1471 tr( "MNU_CIRCLE_SELECTION_STYLE" ), 0, this);
1472 aAction->setStatusTip(tr("DSC_CIRCLE_SELECTION_STYLE"));
1473 aAction->setCheckable(true);
1474 toolMgr()->registerAction( aAction, CircleSelectionStyleId);
1476 // - add exclusive action group
1477 QActionGroup* aSelectionGroup = new QActionGroup(this);
1478 aSelectionGroup->addAction(toolMgr()->action(RectangleSelectionStyleId));
1479 aSelectionGroup->addAction(toolMgr()->action(PolygonSelectionStyleId));
1480 aSelectionGroup->addAction(toolMgr()->action(CircleSelectionStyleId));
1481 connect(aSelectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onSwitchSelectionStyle(QAction*)));
1484 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1485 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1486 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1487 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1488 toolMgr()->registerAction( aAction, MaximizedId );
1490 // Return to 3d view
1491 if (my2dMode!=No2dMode){
1492 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1493 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1494 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1495 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1496 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1500 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1501 #ifdef ENABLE_RAY_TRACING
1503 aAction = new QtxAction( tr("MNU_RAY_TRACING"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_RAY_TRACING") ),
1504 tr("MNU_RAY_TRACING"), 0, this );
1505 aAction->setStatusTip( tr("DSC_RAY_TRACING") );
1506 connect( aAction, SIGNAL( triggered() ), this, SLOT( onRayTracing() ) );
1507 toolMgr()->registerAction( aAction, RayTracingId );
1509 // Environment texture
1510 aAction = new QtxAction( tr("MNU_ENV_TEXTURE"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_ENV_TEXTURE") ),
1511 tr("MNU_ENV_TEXTURE"), 0, this );
1512 aAction->setStatusTip( tr("DSC_ENV_TEXTURE") );
1513 connect( aAction, SIGNAL( triggered() ), this, SLOT( onEnvTexture() ) );
1514 toolMgr()->registerAction( aAction, EnvTextureId );
1517 aAction = new QtxAction( tr("MNU_LIGHT_SOURCE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_LIGHT_SOURCE" ) ),
1518 tr( "MNU_LIGHT_SOURCE" ), 0, this );
1519 aAction->setStatusTip( tr("DSC_LIGHT_SOURCE") );
1520 connect( aAction, SIGNAL( triggered() ), this, SLOT( onLightSource() ) );
1521 toolMgr()->registerAction( aAction, LightSourceId );
1526 \brief Create toolbar.
1528 void OCCViewer_ViewWindow::createToolBar()
1530 static const char* titles[] = {
1531 "LBL_3DTOOLBAR_LABEL",
1532 "LBL_XYTOOLBAR_LABEL",
1533 "LBL_XZTOOLBAR_LABEL",
1534 "LBL_YZTOOLBAR_LABEL",
1536 static const char* names[] = {
1537 "OCCViewer3DViewOperations",
1538 "OCCViewerXYViewOperations",
1539 "OCCViewerXZViewOperations",
1540 "OCCViewerYZViewOperations",
1542 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1543 QString( names[my2dMode] ), // name (language-independant)
1544 false ); // disable floatable toolbar
1545 if ( my2dMode != No2dMode ){
1546 toolMgr()->append( ReturnTo3dViewId, tid );
1547 toolMgr()->append( toolMgr()->separator(), tid );
1549 toolMgr()->append( DumpId, tid );
1550 toolMgr()->append( SwitchInteractionStyleId, tid );
1551 toolMgr()->append( SwitchZoomingStyleId, tid );
1552 toolMgr()->append( SwitchPreselectionId, tid );
1553 toolMgr()->append( SwitchSelectionId, tid );
1555 QtxMultiAction* aSelectionAction = new QtxMultiAction(this);
1556 aSelectionAction->insertAction(toolMgr()->action(RectangleSelectionStyleId));
1557 aSelectionAction->insertAction(toolMgr()->action(PolygonSelectionStyleId));
1558 aSelectionAction->insertAction(toolMgr()->action(CircleSelectionStyleId));
1559 toolMgr()->append(aSelectionAction, tid );
1561 if( myModel->trihedronActivated() )
1562 toolMgr()->append( TrihedronShowId, tid );
1564 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1565 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1566 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1567 aScaleAction->insertAction( toolMgr()->action( FitSelectionId ) );
1568 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1569 toolMgr()->append( aScaleAction, tid );
1571 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1572 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1573 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1574 toolMgr()->append( aPanningAction, tid );
1576 if (my2dMode == No2dMode) {
1577 toolMgr()->append( ChangeRotationPointId, tid );
1578 toolMgr()->append( RotationId, tid );
1580 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1581 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1582 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1583 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1584 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1585 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1586 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1587 toolMgr()->append( aViewsAction, tid );
1589 toolMgr()->append( AntiClockWiseId, tid );
1590 toolMgr()->append( ClockWiseId, tid );
1592 toolMgr()->append( OrthographicId, tid );
1593 toolMgr()->append( PerspectiveId, tid );
1594 toolMgr()->append( StereoId, tid );
1596 toolMgr()->append( ResetId, tid );
1599 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1600 aMemAction->insertAction( toolMgr()->action( MemId ) );
1601 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1602 toolMgr()->append( aMemAction, tid );
1604 toolMgr()->append( toolMgr()->separator(), tid );
1605 toolMgr()->append( CloneId, tid );
1607 toolMgr()->append( toolMgr()->separator(), tid );
1608 toolMgr()->append( ClippingId, tid );
1609 toolMgr()->append( AxialScaleId, tid );
1610 toolMgr()->append( GraduatedAxesId, tid );
1611 toolMgr()->append( AmbientId, tid );
1613 toolMgr()->append( MaximizedId, tid );
1614 toolMgr()->append( SynchronizeId, tid );
1615 #ifdef ENABLE_RAY_TRACING
1616 toolMgr()->append( RayTracingId, tid );
1617 toolMgr()->append( EnvTextureId, tid );
1618 toolMgr()->append( LightSourceId, tid );
1623 \brief Perform 'fit all' operation.
1625 void OCCViewer_ViewWindow::onViewFitAll()
1627 myViewPort->fitAll();
1631 \brief Perform "front view" transformation.
1633 void OCCViewer_ViewWindow::onFrontView()
1635 emit vpTransformationStarted ( FRONTVIEW );
1636 Handle(V3d_View) aView3d = myViewPort->getView();
1637 if (myAutomaticZoom)
1639 if ( !aView3d.IsNull() )
1640 aView3d->SetProj (V3d_Xpos);
1644 projAndPanToGravity(V3d_Xpos);
1645 emit vpTransformationFinished ( FRONTVIEW );
1649 \brief Perform "back view" transformation.
1651 void OCCViewer_ViewWindow::onBackView()
1653 emit vpTransformationStarted ( BACKVIEW );
1654 Handle(V3d_View) aView3d = myViewPort->getView();
1655 if (myAutomaticZoom)
1657 if ( !aView3d.IsNull() )
1658 aView3d->SetProj (V3d_Xneg);
1662 projAndPanToGravity(V3d_Xneg);
1663 emit vpTransformationFinished ( BACKVIEW );
1667 \brief Perform "top view" transformation.
1669 void OCCViewer_ViewWindow::onTopView()
1671 emit vpTransformationStarted ( TOPVIEW );
1672 Handle(V3d_View) aView3d = myViewPort->getView();
1673 if (myAutomaticZoom)
1675 if ( !aView3d.IsNull() )
1676 aView3d->SetProj (V3d_Zpos);
1680 projAndPanToGravity(V3d_Zpos);
1681 emit vpTransformationFinished ( TOPVIEW );
1685 \brief Perform "bottom view" transformation.
1687 void OCCViewer_ViewWindow::onBottomView()
1689 emit vpTransformationStarted ( BOTTOMVIEW );
1690 Handle(V3d_View) aView3d = myViewPort->getView();
1691 if (myAutomaticZoom)
1693 if ( !aView3d.IsNull() )
1694 aView3d->SetProj (V3d_Zneg);
1698 projAndPanToGravity(V3d_Zneg);
1699 emit vpTransformationFinished ( BOTTOMVIEW );
1703 \brief Perform "left view" transformation.
1705 void OCCViewer_ViewWindow::onLeftView()
1707 emit vpTransformationStarted ( LEFTVIEW );
1708 Handle(V3d_View) aView3d = myViewPort->getView();
1709 if (myAutomaticZoom)
1711 if ( !aView3d.IsNull() )
1712 aView3d->SetProj (V3d_Yneg);
1716 projAndPanToGravity(V3d_Yneg);
1717 emit vpTransformationFinished ( LEFTVIEW );
1721 \brief Perform "right view" transformation.
1723 void OCCViewer_ViewWindow::onRightView()
1725 emit vpTransformationStarted ( RIGHTVIEW );
1726 Handle(V3d_View) aView3d = myViewPort->getView();
1727 if (myAutomaticZoom)
1729 if ( !aView3d.IsNull() )
1730 aView3d->SetProj (V3d_Ypos);
1734 projAndPanToGravity(V3d_Ypos);
1735 emit vpTransformationFinished ( RIGHTVIEW );
1739 \brief Rotate view 90 degrees clockwise
1741 void OCCViewer_ViewWindow::onClockWiseView()
1743 emit vpTransformationStarted ( CLOCKWISEVIEW );
1744 myViewPort->rotateXY( 90. );
1745 emit vpTransformationFinished ( CLOCKWISEVIEW );
1749 \brief Rotate view 90 degrees conterclockwise
1751 void OCCViewer_ViewWindow::onAntiClockWiseView()
1753 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1754 myViewPort->rotateXY( -90. );
1755 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1759 \brief Perform "reset view" transformation.
1761 Sets default orientation of the viewport camera.
1763 void OCCViewer_ViewWindow::onResetView()
1765 emit vpTransformationStarted( RESETVIEW );
1766 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1767 myViewPort->getView()->Reset( false );
1768 myViewPort->fitAll( false, true, false );
1769 myViewPort->getView()->SetImmediateUpdate( upd );
1770 onProjectionType(); // needed to apply projection type properly after reset
1771 myViewPort->getView()->Update();
1772 emit vpTransformationFinished( RESETVIEW );
1776 \brief Set the given projection mode.
1778 Set the given projection mode: Orthographic or Perspective.
1780 void OCCViewer_ViewWindow::onProjectionType( QAction* theAction )
1782 Handle(V3d_View) aView3d = myViewPort->getView();
1783 if ( !aView3d.IsNull() ) {
1784 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1785 if (theAction == toolMgr()->action( OrthographicId )) {
1786 myModel->setProjectionType(Orthographic);
1787 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Orthographic );
1788 aCamera->SetFOVy(45.0);
1790 else if (theAction == toolMgr()->action( PerspectiveId )) {
1791 myModel->setProjectionType(Perspective);
1792 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Perspective );
1793 aCamera->SetFOVy(30.0);
1795 if (toolMgr()->action( StereoId )->isChecked()) {
1796 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1797 aCamera->SetFOVy(30.0);
1805 \brief Sets Stereo projection mode.
1807 Sets Stereo projection mode.
1809 void OCCViewer_ViewWindow::onStereoType( bool activate )
1811 Handle(V3d_View) aView3d = myViewPort->getView();
1812 if ( !aView3d.IsNull() ) {
1813 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1815 toolMgr()->action( PerspectiveId )->setChecked(true);
1816 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1817 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(false);
1819 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1820 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1821 setStereoType( aResMgr->integerValue( "OCCViewer", "stereo_type", 0 ) );
1822 setAnaglyphFilter( aResMgr->integerValue( "OCCViewer", "anaglyph_filter", 0 ) );
1823 setReverseStereo( aResMgr->booleanValue( "OCCViewer", "reverse_stereo", false ) );
1824 setVSync( aResMgr->booleanValue( "OCCViewer", "enable_vsync", true ) );
1825 setQuadBufferSupport( aResMgr->booleanValue( "OCCViewer", "enable_quad_buffer_support", false ) );
1828 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(true);
1829 if (myModel->projectionType() == Orthographic) {
1830 toolMgr()->action( OrthographicId )->setChecked(true);
1831 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Orthographic);
1833 else if (myModel->projectionType() == Perspective) {
1834 toolMgr()->action( PerspectiveId )->setChecked(true);
1835 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1842 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1843 toolMgr()->action( StereoId )->isChecked() )
1844 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1848 \brief Restore the view.
1850 Restore the projection mode based on tool-buttons states.
1852 void OCCViewer_ViewWindow::onProjectionType()
1854 emit vpTransformationStarted( PROJECTION );
1855 if (toolMgr()->action( OrthographicId )->isChecked())
1856 setProjectionType( Orthographic );
1857 if (toolMgr()->action( PerspectiveId )->isChecked())
1858 setProjectionType( Perspective );
1859 if (toolMgr()->action( StereoId )->isChecked())
1860 setProjectionType( Stereo );
1861 emit vpTransformationFinished( PROJECTION );
1864 void OCCViewer_ViewWindow::setProjectionType( int mode )
1866 QtxAction* anOrthographicAction = dynamic_cast<QtxAction*>( toolMgr()->action( OrthographicId ) );
1867 QtxAction* aPerspectiveAction = dynamic_cast<QtxAction*>( toolMgr()->action( PerspectiveId ) );
1868 QtxAction* aStereoAction = dynamic_cast<QtxAction*>( toolMgr()->action( StereoId ) );
1871 onProjectionType( anOrthographicAction );
1874 onProjectionType( aPerspectiveAction );
1877 onStereoType( true );
1880 // update action state if method is called outside
1881 if ( mode == Orthographic && !anOrthographicAction->isChecked() ) {
1882 anOrthographicAction->setChecked( true );
1883 aStereoAction->setChecked( false );
1885 if ( mode == Perspective && !aPerspectiveAction->isChecked() ) {
1886 aPerspectiveAction->setChecked( true );
1887 aStereoAction->setChecked( false );
1889 if ( mode == Stereo ) {
1890 aStereoAction->setChecked( true );
1891 if ( anOrthographicAction->isEnabled() ) {
1892 anOrthographicAction->setEnabled( false );
1893 anOrthographicAction->setChecked( false );
1894 aStereoAction->setChecked( false );
1897 anOrthographicAction->setEnabled( true );
1898 aStereoAction->setChecked( false );
1899 anOrthographicAction->setChecked(myModel->projectionType() == Orthographic);
1901 if ( aPerspectiveAction->isEnabled() ) {
1902 aPerspectiveAction->setEnabled( false );
1903 aPerspectiveAction->setChecked( true );
1904 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1905 toolMgr()->action( StereoId )->isChecked() )
1906 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1909 aPerspectiveAction->setEnabled( true );
1910 aStereoAction->setChecked( false );
1911 aPerspectiveAction->setChecked(myModel->projectionType() == Perspective);
1916 if ( !anOrthographicAction->isEnabled() )
1917 anOrthographicAction->setEnabled( true );
1918 if ( !aPerspectiveAction->isEnabled() )
1919 aPerspectiveAction->setEnabled( true );
1924 \brief Perform "fit all" transformation.
1926 void OCCViewer_ViewWindow::onFitAll()
1928 emit vpTransformationStarted( FITALLVIEW );
1929 if (myModel->fitter())
1930 myModel->fitter()->fitAll(myViewPort->getView());
1932 myViewPort->fitAll();
1933 emit vpTransformationFinished( FITALLVIEW );
1937 \brief Perform "fit selection" transformation.
1939 void OCCViewer_ViewWindow::onFitSelection()
1941 emit vpTransformationStarted( FITSELECTION );
1942 myModel->getAISContext()->FitSelected( getViewPort()->getView() );
1943 emit vpTransformationFinished( FITSELECTION );
1947 \brief Called if 'change rotation point' operation is activated.
1948 \param on action state
1950 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1954 if (!mySetRotationPointDlg)
1956 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1957 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1960 if (!mySetRotationPointDlg->isVisible())
1962 //if (mySetRotationPointDlg->IsFirstShown())
1963 if (myCurrPointType == BBCENTER)
1965 Standard_Real Xcenter, Ycenter, Zcenter;
1966 if (OCCViewer_Utilities::computeVisibleBBCenter(myViewPort->getView(), Xcenter, Ycenter, Zcenter))
1967 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1969 mySetRotationPointDlg->show();
1974 if (mySetRotationPointDlg->isVisible())
1975 mySetRotationPointDlg->hide();
1980 \brief Create one more window with same content.
1982 void OCCViewer_ViewWindow::onCloneView()
1984 SUIT_ViewWindow* vw = myManager->createViewWindow();
1986 emit viewCloned( vw );
1987 OCCViewer_ViewWindow* occVw = dynamic_cast<OCCViewer_ViewWindow*> (vw);
1988 if(occVw && occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)) {
1989 occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)->synchronize(this);
1994 Creates one more window with same content
1996 void OCCViewer_ViewWindow::onAxialScale()
1998 if ( !myScalingDlg )
1999 myScalingDlg = new OCCViewer_AxialScaleDlg( this , myModel );
2001 if ( !myScalingDlg->isVisible() )
2003 myScalingDlg->Update();
2004 myScalingDlg->show();
2009 Shows Graduated Axes dialog
2011 void OCCViewer_ViewWindow::onGraduatedAxes()
2013 myCubeAxesDlg->Update();
2014 myCubeAxesDlg->show();
2017 void OCCViewer_ViewWindow::onAmbientToogle()
2019 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2020 viewer->InitDefinedLights();
2021 while(viewer->MoreDefinedLights())
2023 Handle(V3d_Light) light = viewer->DefinedLight();
2024 if(light->Type() != V3d_AMBIENT)
2026 Handle(V3d_View) aView3d = myViewPort->getView();
2027 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
2028 else viewer->SetLightOn(light);
2030 viewer->NextDefinedLights();
2036 \brief Store view parameters.
2038 void OCCViewer_ViewWindow::onMemorizeView()
2040 appendViewAspect( getViewParams() );
2044 \brief Restore view parameters.
2046 void OCCViewer_ViewWindow::onRestoreView()
2048 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
2049 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
2051 updateViewAspects( aDlg->parameters() );
2052 if( myRestoreFlag && aDlg->parameters().count() )
2053 performRestoring( aDlg->currentItem() );
2057 \brief Restore view parameters.
2058 \param anItem view parameters
2060 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
2062 Handle(V3d_View) aView3d = myViewPort->getView();
2064 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
2065 aView3d->SetScale( anItem.scale );
2066 aView3d->SetTwist( anItem.twist );
2067 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
2068 aView3d->SetImmediateUpdate( prev );
2069 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2070 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2071 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
2073 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
2075 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
2077 // "eye" and "at" require conversion to represent center panning
2078 // up direction is only available after setting angle of twist and
2079 // other view parameters
2080 aView3d->Up( anUpX, anUpY, anUpZ );
2082 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
2083 gp_Dir anUp( anUpX, anUpY, anUpZ );
2084 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
2085 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2086 gp_Dir aSide = aProj ^ anUp;
2088 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
2089 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
2091 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
2092 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2095 if ( !baseParamsOnly ) {
2097 myModel->setTrihedronShown( anItem.isVisible );
2098 myModel->setTrihedronSize( anItem.size );
2100 // graduated trihedron
2101 bool anIsVisible = anItem.gtIsVisible;
2102 OCCViewer_AxisWidget::AxisData anAxisData[3];
2103 anAxisData[0].DrawName = anItem.gtDrawNameX;
2104 anAxisData[1].DrawName = anItem.gtDrawNameZ;
2105 anAxisData[2].DrawName = anItem.gtDrawNameZ;
2106 anAxisData[0].Name = anItem.gtNameX;
2107 anAxisData[1].Name = anItem.gtNameZ;
2108 anAxisData[2].Name = anItem.gtNameZ;
2109 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
2110 anItem.gtNameColorGX,
2111 anItem.gtNameColorBX );
2112 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
2113 anItem.gtNameColorGY,
2114 anItem.gtNameColorBY );
2115 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
2116 anItem.gtNameColorGZ,
2117 anItem.gtNameColorBZ );
2118 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
2119 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
2120 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
2121 anAxisData[0].NbValues = anItem.gtNbValuesX;
2122 anAxisData[1].NbValues = anItem.gtNbValuesY;
2123 anAxisData[2].NbValues = anItem.gtNbValuesZ;
2124 anAxisData[0].Offset = anItem.gtOffsetX;
2125 anAxisData[1].Offset = anItem.gtOffsetY;
2126 anAxisData[2].Offset = anItem.gtOffsetZ;
2127 anAxisData[0].Color = QColor( anItem.gtColorRX,
2130 anAxisData[1].Color = QColor( anItem.gtColorRY,
2133 anAxisData[2].Color = QColor( anItem.gtColorRZ,
2136 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
2137 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
2138 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
2139 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
2140 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
2141 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
2143 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
2144 myCubeAxesDlg->ApplyData( aView3d );
2146 } // if ( !baseParamsOnly )
2152 \brief Set restore flag.
2154 void OCCViewer_ViewWindow::setRestoreFlag()
2160 \brief Called when action "show/hide trihedron" is activated.
2162 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
2164 myModel->setTrihedronShown(show);
2168 \brief Toggles preselection (highlighting) on/off
2170 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
2172 myPreselectionEnabled = on;
2173 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
2175 // unhighlight all highlighted objects
2177 myModel->unHighlightAll( true, false );
2180 // update action state if method is called outside
2181 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2182 if ( a && a->isChecked() != on ) {
2183 a->setChecked( on );
2188 \brief Toggles selection on/off
2190 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
2192 mySelectionEnabled = on;
2193 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
2195 // update action state if method is called outside
2198 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2200 a->setEnabled( on );
2204 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
2205 if ( a && a->isChecked() != on ) {
2206 a->setChecked( on );
2211 \brief Switches style of advanced multiple selection by Poligon/Circle
2213 void OCCViewer_ViewWindow::onSwitchSelectionStyle(QAction* theAction)
2216 OCCViewer_ViewSketcher* aSkecher = getSketcher(Polygon);
2218 if (theAction == toolMgr()->action(PolygonSelectionStyleId)) {
2219 aSkecher->setSketcherMode(OCCViewer_PolygonSketcher::Poligone);
2221 else if (theAction == toolMgr()->action(CircleSelectionStyleId)) {
2222 aSkecher->setSketcherMode(OCCViewer_PolygonSketcher::Circle);
2228 Returns currently selected selection style
2230 OCCViewer_ViewWindow::SelectionStyle OCCViewer_ViewWindow::selectionStyle() const
2232 if (toolMgr()->action(PolygonSelectionStyleId)->isChecked())
2233 return PolygonStyle;
2234 if (toolMgr()->action(CircleSelectionStyleId)->isChecked())
2239 void OCCViewer_ViewWindow::setSelectionStyle(SelectionStyle theMode)
2241 toolMgr()->action(RectangleSelectionStyleId)->setChecked(false);
2242 toolMgr()->action(PolygonSelectionStyleId)->setChecked(false);
2243 toolMgr()->action(CircleSelectionStyleId)->setChecked(false);
2246 toolMgr()->action(RectangleSelectionStyleId)->setChecked(true);
2249 toolMgr()->action(PolygonSelectionStyleId)->setChecked(true);
2252 toolMgr()->action(CircleSelectionStyleId)->setChecked(true);
2257 \brief Switches "keyboard free" interaction style on/off
2259 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
2261 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
2263 // update action state if method is called outside
2264 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
2265 if ( a && a->isChecked() != on )
2266 a->setChecked( on );
2270 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
2272 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
2274 myViewPort->setAdvancedZoomingEnabled( on );
2276 // update action state if method is called outside
2277 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
2278 if ( a && a->isChecked() != on )
2279 a->setChecked( on );
2283 \brief Get current interaction style
2284 \return interaction style
2286 int OCCViewer_ViewWindow::interactionStyle() const
2288 return myInteractionStyle;
2292 \brief Set current interaction style
2293 \param theStyle interaction style
2295 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
2297 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
2301 \brief Get current zooming style
2302 \return zooming style
2304 int OCCViewer_ViewWindow::zoomingStyle() const
2306 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
2310 \brief Set current zooming style
2311 \param theStyle zooming style
2313 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
2315 onSwitchZoomingStyle( theStyle == 1 );
2319 \brief Dump view window contents to the pixmap.
2320 \return pixmap containing all scene rendered in the window
2322 //#define USE_OLD_IMPLEMENTATION
2323 QImage OCCViewer_ViewWindow::dumpView()
2325 Handle(V3d_View) view = myViewPort->getView();
2326 if ( view.IsNull() )
2329 int aWidth = myViewPort->width();
2330 int aHeight = myViewPort->height();
2332 #ifdef USE_OLD_IMPLEMENTATION
2333 // rnv: Old approach to dump the OCCViewer content via Frame Buffer Object
2337 #ifndef DISABLE_GLVIEWER
2338 OpenGLUtils_FrameBuffer aFrameBuffer;
2339 if ( aFrameBuffer.init( aWidth, aHeight ) )
2341 glPushAttrib( GL_VIEWPORT_BIT );
2342 glViewport( 0, 0, aWidth, aHeight );
2343 aFrameBuffer.bind();
2348 aFrameBuffer.unbind();
2351 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
2353 aFrameBuffer.bind();
2354 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
2355 aFrameBuffer.unbind();
2357 anImage = anImage.rgbSwapped();
2358 anImage = anImage.mirrored();
2362 // if frame buffers are unsupported, use old approach
2364 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
2365 QPoint p = myViewPort->mapFromParent( myViewPort->geometry().topLeft() );
2366 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
2368 QImage anImage( data, aWidth, aHeight, QImage::Format_ARGB32 );
2369 anImage = anImage.mirrored();
2370 anImage = anImage.rgbSwapped();
2373 #else // DISABLE_GLVIEWER
2377 #endif // DISABLE_GLVIEWER
2379 #else // USE_OLD_IMPLEMENTATION
2380 // rnv: New approach is to use OCCT built-in procedure
2383 view->ToPixMap(aPix, aWidth, aHeight, Graphic3d_BT_RGB);
2385 QImage anImage( aWidth, aHeight, QImage::Format_ARGB32 );
2386 for ( int i = 0; i < aWidth; i++ ) {
2387 for ( int j = 0; j < aHeight; j++ ) {
2388 Quantity_Color pixel = aPix.PixelColor( i, j ).GetRGB();
2389 QColor color = QColor::fromRgbF( pixel.Red(), pixel.Green(), pixel.Blue() );
2390 anImage.setPixelColor( i, j, color );
2394 if ( aPix.IsTopDown() )
2395 anImage = anImage.mirrored();
2398 #endif // USE_OLD_IMPLEMENTATION
2401 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
2402 const QString& fileName,
2403 const QString& format )
2406 QApplication::setOverrideCursor( Qt::WaitCursor );
2408 res = myViewPort->getView()->Dump( fileName.toStdString().c_str() );
2410 QApplication::restoreOverrideCursor();
2415 QString OCCViewer_ViewWindow::filter() const
2417 // OCCT version > 7.3.0 is not support export to PS and EPS
2418 QString formats = tr( "OCC_IMAGE_FILES" );
2419 return formats.remove(" *.eps *.ps");
2424 \brief Set parameters of the cutting plane
2425 \param on if \c true, cutting plane is enabled
2426 \param x X position of plane point
2427 \param y Y position of plane point
2428 \param z Z position of plane point
2429 \param dx X coordinate of plane normal
2430 \param dy Y coordinate of plane normal
2431 \param dz Z coordinate of plane normal
2433 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2434 const double dx, const double dy, const double dz )
2436 Handle(V3d_View) view = myViewPort->getView();
2437 if ( view.IsNull() )
2441 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2443 // try to use already existing plane or create a new one
2444 Handle(V3d_Plane) clipPlane;
2446 // calculate new a,b,c,d values for the plane
2447 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2449 pln.Coefficients(a, b, c, d);
2450 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2451 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2452 if(aPlanes->Size() > 0 ) {
2453 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2454 aClipPlane->SetEquation(pln);
2455 aClipPlane->SetOn(Standard_True);
2457 view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2461 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2462 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2463 for( ;anIter.More();anIter.Next() ){
2464 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2465 aClipPlane->SetOn(Standard_False);
2473 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2475 gp_Dir aDir = pln.Axis().Direction();
2476 gp_Pnt aPnt = pln.Location();
2477 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2482 \brief Check if any cutting plane is enabled
2483 \return \c true if at least one cutting plane is enabled
2485 bool OCCViewer_ViewWindow::isCuttingPlane()
2487 Handle(V3d_View) view = myViewPort->getView();
2489 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2490 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2491 for( ;anIter.More();anIter.Next() ) {
2492 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2493 if(aClipPlane->IsOn()) {
2502 \brief Get the visual parameters of the view window.
2503 \return visual parameters of view window
2505 viewAspect OCCViewer_ViewWindow::getViewParams() const
2507 double projX, projY, projZ, twist;
2508 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2509 double aScaleX, aScaleY, aScaleZ;
2511 Handle(V3d_View) aView3d = myViewPort->getView();
2513 aView3d->Proj( projX, projY, projZ );
2514 aView3d->At( atX, atY, atZ );
2515 aView3d->Eye( eyeX, eyeY, eyeZ );
2516 twist = aView3d->Twist();
2518 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2520 bool isShown = myModel->isTrihedronVisible();
2521 double size = myModel->trihedronSize();
2523 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2526 params.scale = aView3d->Scale();
2527 params.projX = projX;
2528 params.projY = projY;
2529 params.projZ = projZ;
2530 params.twist = twist;
2537 params.scaleX = aScaleX;
2538 params.scaleY = aScaleY;
2539 params.scaleZ = aScaleZ;
2540 params.name = aName;
2541 params.isVisible= isShown;
2544 // graduated trihedron
2545 bool anIsVisible = false;
2546 OCCViewer_AxisWidget::AxisData anAxisData[3];
2547 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2549 params.gtIsVisible = anIsVisible;
2550 params.gtDrawNameX = anAxisData[0].DrawName;
2551 params.gtDrawNameY = anAxisData[1].DrawName;
2552 params.gtDrawNameZ = anAxisData[2].DrawName;
2553 params.gtNameX = anAxisData[0].Name;
2554 params.gtNameY = anAxisData[1].Name;
2555 params.gtNameZ = anAxisData[2].Name;
2556 params.gtNameColorRX = anAxisData[0].NameColor.red();
2557 params.gtNameColorGX = anAxisData[0].NameColor.green();
2558 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2559 params.gtNameColorRY = anAxisData[1].NameColor.red();
2560 params.gtNameColorGY = anAxisData[1].NameColor.green();
2561 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2562 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2563 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2564 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2565 params.gtDrawValuesX = anAxisData[0].DrawValues;
2566 params.gtDrawValuesY = anAxisData[1].DrawValues;
2567 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2568 params.gtNbValuesX = anAxisData[0].NbValues;
2569 params.gtNbValuesY = anAxisData[1].NbValues;
2570 params.gtNbValuesZ = anAxisData[2].NbValues;
2571 params.gtOffsetX = anAxisData[0].Offset;
2572 params.gtOffsetY = anAxisData[1].Offset;
2573 params.gtOffsetZ = anAxisData[2].Offset;
2574 params.gtColorRX = anAxisData[0].Color.red();
2575 params.gtColorGX = anAxisData[0].Color.green();
2576 params.gtColorBX = anAxisData[0].Color.blue();
2577 params.gtColorRY = anAxisData[1].Color.red();
2578 params.gtColorGY = anAxisData[1].Color.green();
2579 params.gtColorBY = anAxisData[1].Color.blue();
2580 params.gtColorRZ = anAxisData[2].Color.red();
2581 params.gtColorGZ = anAxisData[2].Color.green();
2582 params.gtColorBZ = anAxisData[2].Color.blue();
2583 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2584 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2585 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2586 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2587 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2588 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2594 \brief Get visual parameters of this view window.
2595 \return visual parameters of view window
2597 QString OCCViewer_ViewWindow::getVisualParameters()
2599 viewAspect params = getViewParams();
2603 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2604 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2605 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2606 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2607 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2608 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2609 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2610 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2611 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2612 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2613 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2614 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2615 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2616 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2617 data << QString( "isVisible=%1" ).arg( params.isVisible );
2618 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2620 ClipPlanesList aPlanes = myModel->getClipPlanes();
2621 for ( int i=0; i < aPlanes.size(); i++ )
2623 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2624 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2625 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2626 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2627 switch ( aPlane.Mode )
2629 case OCCViewer_ClipPlane::Absolute :
2631 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2633 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2635 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2636 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2637 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2641 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2646 case OCCViewer_ClipPlane::Relative :
2648 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2649 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2650 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2655 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2656 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2657 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2658 data << ClippingPlane;
2661 // graduated trihedron
2662 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2663 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2664 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2665 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2666 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2667 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2668 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2669 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2670 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2671 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2672 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2673 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2674 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2675 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2676 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2677 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2678 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2679 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2680 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2681 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2682 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2683 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2684 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2685 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2686 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2687 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2688 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2689 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2690 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2691 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2692 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2693 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2694 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2695 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2696 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2697 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2698 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2699 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2700 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2701 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2703 // ray tracing parameters
2704 Graphic3d_RenderingParams rendParams = this->getViewPort()->getView()->RenderingParams();
2705 if ( rendParams.Method == Graphic3d_RM_RAYTRACING ) {
2706 QString RayTracing = "rayTracing=";
2707 RayTracing += QString( "rtDepth~%1;" ).arg( rendParams.RaytracingDepth );
2708 RayTracing += QString( "rtReflection~%1;" ).arg( rendParams.IsReflectionEnabled );
2709 RayTracing += QString( "rtAntialiasing~%1;" ).arg( rendParams.IsAntialiasingEnabled );
2710 RayTracing += QString( "rtShadow~%1;" ).arg( rendParams.IsShadowEnabled );
2711 RayTracing += QString( "rtTransShadow~%1;" ).arg( rendParams.IsTransparentShadowEnabled );
2715 // environment texture parameters
2716 Handle(Graphic3d_TextureEnv) aTexture = this->getViewPort()->getView()->TextureEnv();
2717 if ( !aTexture.IsNull() ) {
2718 QString EnvTexture = "envTexture=";
2719 if ( aTexture->Name() == Graphic3d_NOT_ENV_UNKNOWN ) {
2720 TCollection_AsciiString aFileName;
2721 aTexture->Path().SystemName( aFileName );
2722 EnvTexture += QString( "etFile~%1;" ).arg( aFileName.ToCString() );
2725 EnvTexture += QString( "etNumber~%1;" ).arg( aTexture->Name() );
2729 // light source parameters
2730 myModel->getViewer3d()->InitDefinedLights();
2731 while ( myModel->getViewer3d()->MoreDefinedLights() )
2733 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2734 if ( aLight->Type() != V3d_AMBIENT ) {
2735 QString LightSource = QString( "lightSource=" );
2736 LightSource += QString( "lightType~%1;" ).arg( aLight->Type() );
2738 if ( aLight->Type() == V3d_DIRECTIONAL )
2739 Handle(V3d_DirectionalLight)::DownCast( aLight )->Direction( aX, aY, aZ );
2740 else if ( aLight->Type() == V3d_POSITIONAL )
2741 Handle(V3d_PositionalLight)::DownCast( aLight )->Position( aX, aY, aZ );
2742 LightSource += QString( "lightX~%1;" ).arg( aX );
2743 LightSource += QString( "lightY~%1;" ).arg( aY );
2744 LightSource += QString( "lightZ~%1;" ).arg( aZ );
2745 LightSource += QString( "lightColorR~%1;" ).arg( aLight->Color().Red() );
2746 LightSource += QString( "lightColorG~%1;" ).arg( aLight->Color().Green() );
2747 LightSource += QString( "lightColorB~%1;" ).arg( aLight->Color().Blue() );
2748 LightSource += QString( "lightHeadlight~%1;" ).arg( aLight->Headlight() );
2749 data << LightSource;
2751 myModel->getViewer3d()->NextDefinedLights();
2754 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2755 data << QString( "background=%1" ).arg( bg );
2757 return data.join("*");
2761 \brief Restore visual parameters of the view window.
2762 \param parameters visual parameters of view window
2764 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2767 ClipPlanesList aClipPlanes;
2768 QStringList data = parameters.split( '*' );
2769 Qtx::BackgroundData bgData;
2770 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2772 foreach( QString param, data ) {
2773 QString paramName = param.section( '=', 0, 0 ).trimmed();
2774 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2775 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2776 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2777 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2778 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2779 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2780 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2781 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2782 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2783 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2784 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2785 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2786 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2787 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2788 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2789 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2790 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2791 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2792 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2793 else if ( paramName.contains( "ClippingPlane" ) )
2795 QStringList ClipPlaneData = paramValue.split( ';' );
2796 OCCViewer_ClipPlane aPlane;
2797 foreach( QString ClipPlaneParam, ClipPlaneData )
2799 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2800 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2801 if ( ClipPlane_paramName == "Mode" )
2803 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2805 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2806 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2807 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2808 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2811 switch ( aPlane.Mode )
2813 case OCCViewer_ClipPlane::Absolute :
2814 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2815 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2816 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2817 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2818 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2821 case OCCViewer_ClipPlane::Relative :
2822 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2823 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2824 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2829 aClipPlanes.push_back(aPlane);
2831 // graduated trihedron
2832 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2833 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2834 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2835 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2836 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2837 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2838 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2839 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2840 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2841 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2842 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2843 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2844 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2845 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2846 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2847 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2848 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2849 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2850 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2851 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2852 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2853 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2854 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2855 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2856 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2857 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2858 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2859 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2860 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2861 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2862 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2863 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2864 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2865 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2866 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2867 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2868 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2869 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2870 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2871 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2872 else if ( paramName == "rayTracing" )
2874 Graphic3d_RenderingParams& rendParams = this->getViewPort()->getView()->ChangeRenderingParams();
2875 rendParams.Method = Graphic3d_RM_RAYTRACING;
2876 QStringList rtData = paramValue.split( ';' );
2877 foreach( QString rtParam, rtData )
2879 QString rt_paramName = rtParam.section( '~', 0, 0 ).trimmed();
2880 QString rt_paramValue = rtParam.section( '~', 1, 1 ).trimmed();
2881 if ( rt_paramName == "rtDepth" ) rendParams.RaytracingDepth = rt_paramValue.toInt();
2882 else if ( rt_paramName == "rtReflection" ) rendParams.IsReflectionEnabled = rt_paramValue.toInt();
2883 else if ( rt_paramName == "rtAntialiasing" ) rendParams.IsAntialiasingEnabled = rt_paramValue.toInt();
2884 else if ( rt_paramName == "rtShadow" ) rendParams.IsShadowEnabled = rt_paramValue.toInt();
2885 else if ( rt_paramName == "rtTransShadow" ) rendParams.IsTransparentShadowEnabled = rt_paramValue.toInt();
2888 else if ( paramName == "envTexture" )
2890 Handle(Graphic3d_TextureEnv) aTexture;
2891 QStringList etData = paramValue.split( ';' );
2892 foreach( QString etParam, etData )
2894 QString et_paramName = etParam.section( '~', 0, 0 ).trimmed();
2895 QString et_paramValue = etParam.section( '~', 1, 1 ).trimmed();
2896 if ( et_paramName == "etNumber" )
2897 aTexture = new Graphic3d_TextureEnv( Graphic3d_NameOfTextureEnv( et_paramValue.toInt() ) );
2898 else if ( et_paramName == "etFile" )
2899 aTexture = new Graphic3d_TextureEnv( TCollection_AsciiString( et_paramValue.toStdString().c_str() ) );
2900 Handle(V3d_View) aView = this->getViewPort()->getView();
2901 aView->SetTextureEnv( aTexture );
2904 else if ( paramName == "lightSource" )
2906 myModel->getViewer3d()->InitDefinedLights();
2907 while ( myModel->getViewer3d()->MoreDefinedLights() )
2909 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2910 if( aLight->Type() != V3d_AMBIENT ) {
2911 myModel->getViewer3d()->DelLight( aLight );
2912 myModel->getViewer3d()->InitDefinedLights();
2914 myModel->getViewer3d()->NextDefinedLights();
2919 V3d_TypeOfLight aType;
2921 QStringList lsData = paramValue.split( ';' );
2922 foreach( QString lsParam, lsData )
2924 QString ls_paramName = lsParam.section( '~', 0, 0 ).trimmed();
2925 QString ls_paramValue = lsParam.section( '~', 1, 1 ).trimmed();
2926 if ( ls_paramName == "lightType" ) aType = V3d_TypeOfLight( ls_paramValue.toInt() );
2927 else if ( ls_paramName == "lightX" ) aX = ls_paramValue.toDouble();
2928 else if ( ls_paramName == "lightY" ) aY = ls_paramValue.toDouble();
2929 else if ( ls_paramName == "lightZ" ) aZ = ls_paramValue.toDouble();
2930 else if ( ls_paramName == "lightColorR" ) cR = ls_paramValue.toDouble();
2931 else if ( ls_paramName == "lightColorG" ) cG = ls_paramValue.toDouble();
2932 else if ( ls_paramName == "lightColorB" ) cB = ls_paramValue.toDouble();
2933 else if ( ls_paramName == "lightHeadlight" ) isHeadlight = ls_paramValue.toInt();
2935 Quantity_Color aColor = Quantity_Color( cR, cG, cB, Quantity_TOC_RGB );
2936 if( aType == V3d_DIRECTIONAL ) {
2937 Handle(V3d_DirectionalLight) aLight = new V3d_DirectionalLight();
2938 myModel->getViewer3d()->AddLight( aLight );
2939 aLight->SetDirection( aX, aY, aZ );
2940 aLight->SetColor( aColor );
2941 aLight->SetHeadlight( isHeadlight );
2942 myModel->getViewer3d()->SetLightOn( aLight );
2944 else if( aType == V3d_POSITIONAL ) {
2945 Handle(V3d_PositionalLight) aLight = new V3d_PositionalLight( gp_Pnt(aX, aY, aZ), aColor.Name() );
2946 myModel->getViewer3d()->AddLight( aLight );
2947 aLight->SetHeadlight( isHeadlight );
2948 myModel->getViewer3d()->SetLightOn( aLight );
2951 else if ( paramName == "background" ) {
2952 QString bg = paramValue.replace( "$", "=" );
2953 bgData = Qtx::stringToBackground( bg );
2957 else // old format - "1.000e+00*0.000e+00..."
2960 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2961 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2962 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2963 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2964 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2965 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2966 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
2967 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2968 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2969 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
2970 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2971 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2972 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2973 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
2974 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
2975 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
2976 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
2977 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
2979 performRestoring( params );
2980 setBackground( bgData );
2981 myModel->setClipPlanes(aClipPlanes);
2985 \brief Handle show event.
2987 Emits Show() signal.
2989 \param theEvent show event
2991 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2993 emit Show( theEvent );
2997 \brief Handle hide event.
2999 Emits Hide() signal.
3001 \param theEvent hide event
3003 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
3005 emit Hide( theEvent );
3010 Save old cursor. [ protected ]
3012 void OCCViewer_ViewWindow::saveCursor()
3014 QCursor* aCursor = NULL;
3016 aCursor = myViewPort->getDefaultCursor();
3017 myCursor = ( aCursor ? *aCursor : cursor() );
3022 Creates default sketcher. [ virtual protected ]
3024 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
3027 return new OCCViewer_RectSketcher( this, type );
3028 if ( type == Polygon )
3029 return new OCCViewer_PolygonSketcher( this, type );
3033 void OCCViewer_ViewWindow::initSketchers()
3035 if ( mySketchers.isEmpty() )
3037 mySketchers.append( createSketcher( Rect ) );
3038 mySketchers.append( createSketcher( Polygon ) );
3042 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ ) const
3044 OCCViewer_ViewSketcher* sketcher = 0;
3045 QList<OCCViewer_ViewSketcher*>::ConstIterator it;
3046 for ( it = mySketchers.cbegin(); it != mySketchers.cend() && !sketcher; ++it )
3048 OCCViewer_ViewSketcher* sk = (*it);
3049 if ( sk->type() == typ )
3056 Handles requests for sketching in the active view. [ virtual public ]
3058 void OCCViewer_ViewWindow::activateSketching( int type )
3060 OCCViewer_ViewPort3d* vp = getViewPort();
3064 if ( !vp->isSketchingEnabled() )
3067 /* Finish current sketching */
3068 if ( type == NoSketching )
3072 onSketchingFinished();
3073 mypSketcher->deactivate();
3077 /* Activate new sketching */
3080 activateSketching( NoSketching ); /* concurrency not suported */
3081 mypSketcher = getSketcher( type );
3084 mypSketcher->activate();
3085 onSketchingStarted();
3091 Unhilights detected entities. [ virtual protected ]
3093 void OCCViewer_ViewWindow::onSketchingStarted()
3098 Selection by rectangle or polygon. [ virtual protected ]
3100 void OCCViewer_ViewWindow::onSketchingFinished()
3102 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
3103 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
3105 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
3106 bool append = mypSketcher->isHasShift();
3107 switch( mypSketcher->type() )
3111 QRect* aRect = (QRect*)mypSketcher->data();
3114 int aLeft = aRect->left();
3115 int aRight = aRect->right();
3116 int aTop = aRect->top();
3117 int aBottom = aRect->bottom();
3121 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False);
3123 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False);
3129 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
3130 if( aPolygon && (aPolygon->size() > 2))
3132 int size = aPolygon->size();
3133 TColgp_Array1OfPnt2d anArray(1, size);
3135 QPolygon::Iterator it = aPolygon->begin();
3136 QPolygon::Iterator itEnd = aPolygon->end();
3137 for (int index = 1; it != itEnd; ++it, index++)
3139 QPoint aPoint = *it;
3140 anArray.SetValue(index, gp_Pnt2d(aPoint.x(), aPoint.y()));
3144 ic->ShiftSelect(anArray, getViewPort()->getView(), Standard_False);
3146 ic->Select(anArray, getViewPort()->getView(), Standard_False);
3154 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
3155 aViewMgr->getOCCViewer()->performSelectionChanged();
3159 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
3164 bool OCCViewer_ViewWindow::transformRequested() const
3166 return ( myOperation != NOVIEWOP );
3169 bool OCCViewer_ViewWindow::transformInProcess() const
3171 return myEventStarted;
3174 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
3176 myEventStarted = bOn;
3180 Set enabled state of transformation (rotate, zoom, etc)
3182 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
3184 if ( id != NOVIEWOP ) myStatus.insert( id, on );
3188 \return enabled state of transformation (rotate, zoom, etc)
3190 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
3192 return myStatus.contains( id ) ? myStatus[ id ] : true;
3195 void OCCViewer_ViewWindow::onMaximizedView()
3197 setMaximized(!isMaximized());
3200 void OCCViewer_ViewWindow::returnTo3dView()
3202 setReturnedTo3dView( true );
3205 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
3207 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
3208 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
3209 if ( !isVisible3dView )
3210 toolMgr()->show( ReturnTo3dViewId );
3212 toolMgr()->hide( ReturnTo3dViewId );
3213 if ( isVisible3dView ) emit returnedTo3d( );
3217 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
3219 QAction* anAction = toolMgr()->action( MaximizedId );
3220 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
3221 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
3223 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
3224 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
3225 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
3226 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
3227 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
3229 emit maximized( this, true );
3233 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
3234 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
3235 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
3236 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
3237 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
3239 emit maximized( this, false );
3244 bool OCCViewer_ViewWindow::isMaximized() const
3246 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
3249 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
3251 IsSketcherStyle = enable;
3254 bool OCCViewer_ViewWindow::isSketcherStyle() const
3256 return IsSketcherStyle;
3260 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
3265 int OCCViewer_ViewWindow::projectionType() const
3267 int mode = Orthographic;
3268 Handle(V3d_View) aView3d = myViewPort->getView();
3269 if ( !aView3d.IsNull() ) {
3270 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3271 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Perspective)
3273 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Orthographic)
3274 mode = Orthographic;
3275 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
3281 void OCCViewer_ViewWindow::setStereoType( int type )
3283 Handle(V3d_View) aView3d = myViewPort->getView();
3284 if ( !aView3d.IsNull() ) {
3285 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3286 aParams->StereoMode = (Graphic3d_StereoMode)type;
3290 int OCCViewer_ViewWindow::stereoType() const
3292 int type = QuadBuffer;
3293 Handle(V3d_View) aView3d = myViewPort->getView();
3294 if ( !aView3d.IsNull() ) {
3295 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3296 type = (OCCViewer_ViewWindow::StereoType)aParams->StereoMode;
3301 void OCCViewer_ViewWindow::setAnaglyphFilter( int type )
3303 Handle(V3d_View) aView3d = myViewPort->getView();
3304 if ( !aView3d.IsNull() ) {
3305 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3306 if (type == RedCyan)
3307 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
3308 if (type == YellowBlue)
3309 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
3310 if (type == GreenMagenta)
3311 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
3315 int OCCViewer_ViewWindow::anaglyphFilter() const
3318 Handle(V3d_View) aView3d = myViewPort->getView();
3319 if ( !aView3d.IsNull() ) {
3320 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3321 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized)
3323 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized)
3325 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple)
3326 type = GreenMagenta;
3331 void OCCViewer_ViewWindow::setStereographicFocus( int type, double value )
3333 Handle(V3d_View) aView3d = myViewPort->getView();
3334 if ( !aView3d.IsNull() ) {
3335 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3336 aCamera->SetZFocus( (Graphic3d_Camera::FocusType) type, value );
3340 int OCCViewer_ViewWindow::stereographicFocusType() const
3342 int type = Relative;
3343 Handle(V3d_View) aView3d = myViewPort->getView();
3344 if ( !aView3d.IsNull() ) {
3345 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3346 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->ZFocusType();
3351 double OCCViewer_ViewWindow::stereographicFocusValue() const
3354 Handle(V3d_View) aView3d = myViewPort->getView();
3355 if ( !aView3d.IsNull() ) {
3356 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3357 value = aCamera->ZFocus();
3362 void OCCViewer_ViewWindow::setInterocularDistance( int type, double value )
3364 Handle(V3d_View) aView3d = myViewPort->getView();
3365 if ( !aView3d.IsNull() ) {
3366 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3367 aCamera->SetIOD( (Graphic3d_Camera::IODType) type, value );
3371 int OCCViewer_ViewWindow::interocularDistanceType() const
3373 int type = Relative;
3374 Handle(V3d_View) aView3d = myViewPort->getView();
3375 if ( !aView3d.IsNull() ) {
3376 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3377 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->GetIODType();
3382 double OCCViewer_ViewWindow::interocularDistanceValue() const
3384 double value = 0.05;
3385 Handle(V3d_View) aView3d = myViewPort->getView();
3386 if ( !aView3d.IsNull() ) {
3387 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3388 value = aCamera->IOD();
3393 void OCCViewer_ViewWindow::setReverseStereo( bool reverse )
3395 Handle(V3d_View) aView3d = myViewPort->getView();
3396 if ( !aView3d.IsNull() ) {
3397 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3398 aParams->ToReverseStereo = reverse;
3402 bool OCCViewer_ViewWindow::isReverseStereo() const
3404 int reverse = false;
3405 Handle(V3d_View) aView3d = myViewPort->getView();
3406 if ( !aView3d.IsNull() ) {
3407 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3408 reverse = aParams->ToReverseStereo;
3413 void OCCViewer_ViewWindow::setVSync( bool enable )
3415 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3416 if ( !anIntCont.IsNull() ) {
3417 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3418 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3419 aCaps->swapInterval = enable;
3423 bool OCCViewer_ViewWindow::isVSync() const
3426 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3427 if ( !anIntCont.IsNull() ) {
3428 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3429 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3430 enable = aCaps->swapInterval;
3435 void OCCViewer_ViewWindow::setQuadBufferSupport( bool enable )
3437 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3438 if ( !anIntCont.IsNull() ) {
3439 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3440 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3441 aCaps->contextStereo = enable;
3445 bool OCCViewer_ViewWindow::isQuadBufferSupport() const
3448 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3449 if ( !anIntCont.IsNull() ) {
3450 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3451 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3452 enable = aCaps->contextStereo;
3457 bool OCCViewer_ViewWindow::isOpenGlStereoSupport() const
3459 GLboolean support[1];
3460 glGetBooleanv (GL_STEREO, support);
3467 QColor OCCViewer_ViewWindow::backgroundColor() const
3469 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
3473 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
3475 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
3478 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
3480 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
3483 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
3485 if ( myViewPort ) myViewPort->setBackground( theBackground );
3488 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
3490 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
3496 void OCCViewer_ViewWindow::clearViewAspects()
3498 myViewAspects.clear();
3502 \return const reference to list of view aspects
3504 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
3506 return myViewAspects;
3510 Appends new view aspect
3511 \param aParams - new view aspects
3513 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
3515 myViewAspects.append( aParams );
3519 Replaces old view aspects by new ones
3520 \param aViewList - list of new view aspects
3522 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
3524 myViewAspects = aViewList;
3528 Get camera properties for the OCC view window.
3529 \return shared pointer on camera properties.
3531 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
3533 SUIT_CameraProperties aProps;
3535 Handle(V3d_View) aSourceView = getViewPort()->getView();
3536 if ( aSourceView.IsNull() )
3539 if ( get2dMode() == No2dMode ) {
3540 aProps.setDimension( SUIT_CameraProperties::Dim3D );
3543 aProps.setDimension( SUIT_CameraProperties::Dim2D );
3544 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
3547 // read common properites of the view
3548 Standard_Real anUp[3];
3549 Standard_Real anAt[3];
3550 Standard_Real anEye[3];
3551 Standard_Real aProj[3];
3552 Standard_Real anAxialScale[3];
3554 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
3555 aSourceView->At( anAt[0], anAt[1], anAt[2] );
3556 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
3557 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3559 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3560 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
3562 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
3564 // store camera properties "as is": it is up to synchronized
3565 // view classes to provide necessary property conversion.
3566 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
3567 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
3569 if ( aSourceView->Camera()->IsOrthographic() )
3571 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
3572 aProps.setViewAngle( 0.0 );
3576 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
3577 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
3579 aProps.setMappingScale( aSourceView->Camera()->Scale() );
3586 This implementation synchronizes OCC view's camera propreties.
3588 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
3590 bool blocked = blockSignals( true );
3592 SUIT_CameraProperties aProps = theView->cameraProperties();
3593 if ( !cameraProperties().isCompatible( aProps ) ) {
3594 // other view, this one is being currently synchronized to, seems has become incompatible
3595 // we have to break synchronization
3600 Handle(V3d_View) aDestView = getViewPort()->getView();
3602 aDestView->SetImmediateUpdate( Standard_False );
3605 double aPosition[3];
3606 double aFocalPoint[3];
3607 double anAxialScale[3];
3609 // get common properties
3610 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3611 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
3612 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3613 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3616 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3617 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
3618 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3619 aDestView->Camera()->SetScale( aProps.getMappingScale() );
3621 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3622 aDestView->SetImmediateUpdate( Standard_True );
3623 aDestView->Redraw();
3625 catch (Standard_Failure) {
3628 blockSignals( blocked );
3632 \brief Indicates whether preselection is enabled
3633 \return true if preselection is enabled
3635 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
3637 return myPreselectionEnabled;
3641 \brief Enables/disables preselection
3642 \param theIsToEnable if true - preselection will be enabled
3644 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
3646 onSwitchPreselection( theIsToEnable );
3650 \brief Indicates whether selection is enabled
3651 \return true if selection is enabled
3653 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3655 return mySelectionEnabled;
3659 \brief Enables/disables selection
3660 \param theIsToEnable if true - selection will be enabled
3662 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3664 onSwitchSelection( theIsToEnable );
3669 \brief called if clipping operation is activated / deactivated.
3671 Enables/disables clipping plane displaying.
3673 \parma on action state
3675 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3677 if(!myModel) return;
3678 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3681 if (!aClippingDlg) {
3682 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3683 myModel->setClippingDlg(aClippingDlg);
3685 if (!aClippingDlg->isVisible())
3686 aClippingDlg->show();
3688 if ( aClippingDlg ) {
3689 aClippingDlg->close();
3690 myModel->setClippingDlg(0);
3694 SUIT_ViewManager* mgr = getViewManager();
3696 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3697 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3698 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3699 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3701 QAction* a = toolMgr()->action( ClippingId );
3703 if(theIsOn != a->isChecked()){
3704 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3705 a->setChecked(theIsOn);
3706 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3713 void OCCViewer_ViewWindow::onRayTracing()
3715 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_RayTracingDlg::getName() ) ) {
3716 QDialog* aDlg = new OCCViewer_RayTracingDlg( this );
3722 void OCCViewer_ViewWindow::onEnvTexture()
3724 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_EnvTextureDlg::getName() ) ) {
3725 QDialog* aDlg = new OCCViewer_EnvTextureDlg( this );
3731 void OCCViewer_ViewWindow::onLightSource()
3733 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_LightSourceDlg::getName() ) ) {
3734 QDialog* aDlg = new OCCViewer_LightSourceDlg( this, myModel );
3740 bool OCCViewer_ViewWindow::isActionVisible( ActionId theId ) const
3742 QAction* a = toolMgr()->action( theId );
3743 return a && a->isVisible();
3746 void OCCViewer_ViewWindow::setActionVisible( ActionId theId, bool isVisible )
3748 QAction* a = toolMgr()->action( theId );
3750 a->setVisible( isVisible );
3753 void OCCViewer_ViewWindow::projAndPanToGravity(V3d_TypeOfOrientation CamOri)
3755 const bool USE_XY = true;
3757 Handle(V3d_View) aView3d = myViewPort->getView();
3758 if (aView3d.IsNull())
3762 double X = 0, Y = 0, Z = 0;
3765 const double EPS = 1E-6;
3766 int xp = myViewPort->width()/2, yp = myViewPort->height()/2, xp1, yp1;
3767 aView3d->Convert( xp, yp, X, Y, Z );
3769 gp_Dir d = aView3d->Camera()->Direction();
3770 if( fabs( d.Z() ) > EPS )
3772 double t = -Z/d.Z();
3779 // It is really necessary to compute gravity center even if it is not used in part of code below.
3780 // Without this calculation the SetProj() method and other methods are not correct.
3782 IsGr = computeGravityCenter(X2, Y2, Z2);
3784 IsGr = OCCViewer_Utilities::computeSceneBBCenter(aView3d, X2, Y2, Z2);
3786 aView3d->SetProj(CamOri);
3789 //aView3d->Update();
3790 Handle(Graphic3d_Camera) Cam = aView3d->Camera();
3792 gp_Vec dir (Cam->Direction());
3793 gp_Pnt eye = Cam->Eye();
3795 Standard_Real D = dir.Dot(V1);
3796 gp_Pnt ppdir = eye.Translated(D*dir);
3797 gp_Vec V2(ppdir, gp);
3798 gp_XYZ trEye = eye.XYZ() + V2.XYZ();
3800 double xat, yat, zat;
3801 aView3d->At(xat, yat, zat);
3802 gp_Pnt At(xat, yat, zat);
3803 gp_XYZ trAt = At.XYZ() + V2.XYZ();
3804 aView3d->SetEye(trEye.X(), trEye.Y(), trEye.Z());
3805 aView3d->SetAt(trAt.X(), trAt.Y(), trAt.Z());
3810 bool OCCViewer_ViewWindow::isAutomaticZoom() const
3812 return myAutomaticZoom;
3815 void OCCViewer_ViewWindow::setAutomaticZoom(const bool isOn)
3817 myAutomaticZoom = isOn;