1 // Copyright (C) 2007-2019 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 <Basics_OCCTVersion.hxx>
79 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
80 #include <Graphic3d_MapOfStructure.hxx>
81 #include <Graphic3d_Structure.hxx>
82 #if OCC_VERSION_LARGE <= 0x07030000
83 #include <Graphic3d_ExportFormat.hxx>
85 #include <Graphic3d_StereoMode.hxx>
86 #include <Graphic3d_RenderingParams.hxx>
87 #include <Graphic3d_BndBox3d.hxx>
89 #include <V3d_Plane.hxx>
90 #include <V3d_Light.hxx>
94 #include <gp_GTrsf.hxx>
95 #include <TColgp_Array1OfPnt2d.hxx>
97 #include <Image_PixMap.hxx>
99 #include <Standard_Version.hxx>
101 #include "utilities.h"
103 // // OpenCV includes
105 // #include <highgui.h>
107 static QEvent* l_mbPressEvent = 0;
110 //# include <QWindowsStyle>
114 #include <OpenGL/gl.h>
119 // To avoid conflict between KeyPress from the X.h (define KeyPress 2)
120 // and QEvent::KeyPress (qevent.h)
125 // Enable ray tracing features
126 #define ENABLE_RAY_TRACING
128 const char* imageZoomCursor[] = {
133 "................................",
134 "................................",
135 ".#######........................",
136 "..aaaaaaa.......................",
137 "................................",
138 ".............#####..............",
139 "...........##.aaaa##............",
140 "..........#.aa.....a#...........",
141 ".........#.a.........#..........",
142 ".........#a..........#a.........",
143 "........#.a...........#.........",
144 "........#a............#a........",
145 "........#a............#a........",
146 "........#a............#a........",
147 "........#a............#a........",
148 ".........#...........#.a........",
149 ".........#a..........#a.........",
150 ".........##.........#.a.........",
151 "........#####.....##.a..........",
152 ".......###aaa#####.aa...........",
153 "......###aa...aaaaa.......#.....",
154 ".....###aa................#a....",
155 "....###aa.................#a....",
156 "...###aa...............#######..",
157 "....#aa.................aa#aaaa.",
158 ".....a....................#a....",
159 "..........................#a....",
160 "...........................a....",
161 "................................",
162 "................................",
163 "................................",
164 "................................"};
166 const char* imageRotateCursor[] = {
171 "................................",
172 "................................",
173 "................................",
174 "................................",
175 "........#.......................",
176 ".......#.a......................",
177 "......#######...................",
178 ".......#aaaaa#####..............",
179 "........#..##.a#aa##........##..",
180 ".........a#.aa..#..a#.....##.aa.",
181 ".........#.a.....#...#..##.aa...",
182 ".........#a.......#..###.aa.....",
183 "........#.a.......#a..#aa.......",
184 "........#a.........#..#a........",
185 "........#a.........#a.#a........",
186 "........#a.........#a.#a........",
187 "........#a.........#a.#a........",
188 ".........#.........#a#.a........",
189 "........##a........#a#a.........",
190 "......##.a#.......#.#.a.........",
191 "....##.aa..##.....##.a..........",
192 "..##.aa.....a#####.aa...........",
193 "...aa.........aaa#a.............",
194 "................#.a.............",
195 "...............#.a..............",
196 "..............#.a...............",
197 "...............a................",
198 "................................",
199 "................................",
200 "................................",
201 "................................",
202 "................................"};
204 const char* imageCrossCursor[] = {
209 "................................",
210 "................................",
211 "................................",
212 "................................",
213 "................................",
214 "................................",
215 "................................",
216 "...............#................",
217 "...............#a...............",
218 "...............#a...............",
219 "...............#a...............",
220 "...............#a...............",
221 "...............#a...............",
222 "...............#a...............",
223 "...............#a...............",
224 ".......#################........",
225 "........aaaaaaa#aaaaaaaaa.......",
226 "...............#a...............",
227 "...............#a...............",
228 "...............#a...............",
229 "...............#a...............",
230 "...............#a...............",
231 "...............#a...............",
232 "...............#a...............",
233 "................a...............",
234 "................................",
235 "................................",
236 "................................",
237 "................................",
238 "................................",
239 "................................",
240 "................................"};
245 \param theDesktop main window of application
246 \param theModel OCC 3D viewer
248 OCCViewer_ViewWindow::OCCViewer_ViewWindow( SUIT_Desktop* theDesktop,
249 OCCViewer_Viewer* theModel )
250 : SUIT_ViewWindow( theDesktop )
254 myEnableDrawMode = false;
255 myDrawRectEnabled = true;
257 updateEnabledDrawMode();
259 mySetRotationPointDlg = 0;
262 IsSketcherStyle = false;
269 myInteractionStyle = SUIT_ViewModel::STANDARD;
270 myPreselectionEnabled = true;
271 mySelectionEnabled = true;
273 myCursorIsHand = false;
274 myPanningByBtn = false;
275 myAutomaticZoom = true;
283 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
286 qDeleteAll( mySketchers );
290 \brief Internal initialization.
292 void OCCViewer_ViewWindow::initLayout()
294 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
295 myViewPort->installEventFilter(this);
296 setCentralWidget(myViewPort);
297 myOperation = NOTHING;
299 myCurrPointType = BBCENTER;
300 myPrevPointType = BBCENTER;
301 mySelectedPoint = gp_Pnt(0.,0.,0.);
302 myRotationPointSelection = false;
304 setTransformRequested ( NOTHING );
305 setTransformInProcess ( false );
322 // Graduated axes dialog
323 QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
324 myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
325 myCubeAxesDlg->initialize();
327 connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
330 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
332 return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
336 \brief Detect viewer operation according the the mouse button pressed
337 and key modifiers used.
338 \param theEvent mouse event
339 \return type of the operation
341 OCCViewer_ViewWindow::OperationType
342 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
344 OperationType aOp = NOTHING;
345 SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
346 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
347 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
349 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
350 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
352 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
353 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
354 (my2dMode == No2dMode))
361 \brief Customize event handling
362 \param watched event receiver object
364 \return \c true if the event processing should be stopped
366 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
368 if ( watched == myViewPort ) {
369 int aType = e->type();
371 case QEvent::MouseButtonPress:
372 vpMousePressEvent((QMouseEvent*) e);
375 case QEvent::MouseButtonRelease:
376 vpMouseReleaseEvent((QMouseEvent*) e);
379 case QEvent::MouseMove:
380 vpMouseMoveEvent((QMouseEvent*) e);
383 case QEvent::MouseButtonDblClick:
384 emit mouseDoubleClicked(this, (QMouseEvent*)e);
389 QWheelEvent* aEvent = (QWheelEvent*) e;
391 if ( aEvent->modifiers().testFlag(Qt::ControlModifier) ) {
392 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
393 if ( isPreselectionEnabled()
394 #if OCC_VERSION_LARGE <= 0x07030000
395 && myModel->useLocalSelection()
398 if ( aEvent->delta() > 0 ) {
399 ic->HilightNextDetected( myViewPort->getView() );
401 ic->HilightPreviousDetected( myViewPort->getView() );
406 emit vpTransformationStarted ( ZOOMVIEW );
407 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
408 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
411 int x1 = (int)( aEvent->x() + width()*delta/100 );
412 int y1 = (int)( aEvent->y() + height()*delta/100 );
413 myViewPort->zoom( x, y, x1, y1 );
414 emit vpTransformationFinished ( ZOOMVIEW );
419 case QEvent::ContextMenu:
421 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
422 if ( aEvent->reason() != QContextMenuEvent::Mouse )
423 emit contextMenuRequested( aEvent );
427 case QEvent::KeyPress:
428 emit keyPressed(this, (QKeyEvent*) e);
435 return SUIT_ViewWindow::eventFilter(watched, e);
439 \brief Enable / disable draw rect (rubber band) mode
441 bool OCCViewer_ViewWindow::enableDrawMode( bool on )
443 bool prev = myDrawRectEnabled;
444 myDrawRectEnabled = on;
445 updateEnabledDrawMode();
450 \brief Update state of enable draw mode state.
452 void OCCViewer_ViewWindow::updateEnabledDrawMode()
454 myEnableDrawMode = myDrawRectEnabled;
456 myEnableDrawMode = myEnableDrawMode && myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
460 \brief Handle mouse press event
461 \param theEvent mouse event
463 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
465 myStartX = theEvent->x();
466 myStartY = theEvent->y();
467 int anInteractionStyle = interactionStyle();
469 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
470 // which are assigned for pan and rotate - these operations are activated immediately after pressing
471 // of the first button, so it is necessary to switch to zoom when the second button is pressed
472 bool aSwitchToZoom = false;
473 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
474 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
475 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
478 switch ( myOperation ) {
480 if ( theEvent->button() == Qt::LeftButton )
481 emit vpTransformationStarted ( WINDOWFIT );
485 if ( theEvent->button() == Qt::LeftButton )
486 emit vpTransformationStarted ( PANGLOBAL );
490 if ( theEvent->button() == Qt::LeftButton ) {
491 myViewPort->startZoomAtPoint( myStartX, myStartY );
492 emit vpTransformationStarted ( ZOOMVIEW );
497 if ( aSwitchToZoom ) {
498 myViewPort->startZoomAtPoint( myStartX, myStartY );
501 else if ( theEvent->button() == Qt::LeftButton )
502 emit vpTransformationStarted ( PANVIEW );
506 if ( aSwitchToZoom ) {
507 myViewPort->startZoomAtPoint( myStartX, myStartY );
510 else if ( theEvent->button() == Qt::LeftButton ) {
511 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
512 emit vpTransformationStarted ( ROTATE );
517 /* Try to activate a transformation */
518 OperationType aState;
519 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
520 aState = getButtonState(theEvent, anInteractionStyle);
522 aState = OCCViewer_ViewWindow::NOTHING;
527 myViewPort->startZoomAtPoint( myStartX, myStartY );
535 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
538 if ( myRotationPointSelection )
540 if ( theEvent->button() == Qt::LeftButton )
542 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
543 ic->Select( Standard_True );
544 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
546 TopoDS_Shape aShape = ic->SelectedShape();
547 GProp_GProps aSystem;
549 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
551 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
553 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE )
555 BRepGProp::LinearProperties( aShape, aSystem );
556 aPnt = aSystem.CentreOfMass();
558 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE )
560 BRepGProp::SurfaceProperties( aShape, aSystem );
561 aPnt = aSystem.CentreOfMass();
563 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID )
565 BRepGProp::VolumeProperties( aShape, aSystem );
566 aPnt = aSystem.CentreOfMass();
570 myCurrPointType = myPrevPointType;
574 if ( mySetRotationPointDlg )
576 myRotationPointSelection = false;
577 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
580 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
581 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
582 #if OCC_VERSION_LARGE <= 0x07030000
583 ic->CloseAllContexts( Standard_True );
588 myOperation = NOTHING;
589 myViewPort->setCursor( myCursor );
590 myCursorIsHand = false;
591 myRotationPointSelection = false;
595 emit mousePressed(this, theEvent);
598 /* notify that we start a transformation */
599 if ( transformRequested() )
600 emit vpTransformationStarted ( myOperation );
602 if ( transformRequested() )
603 setTransformInProcess( true );
605 /* we may need it for sketching... */
606 if ( l_mbPressEvent )
607 delete l_mbPressEvent;
608 l_mbPressEvent = new QMouseEvent( *theEvent );
613 \brief Start zooming operation.
615 Sets the corresponding cursor for the widget.
617 void OCCViewer_ViewWindow::activateZoom()
619 if ( !transformRequested() && !myCursorIsHand )
620 saveCursor(); /* save old cursor */
622 if ( myOperation != ZOOMVIEW ) {
623 QPixmap zoomPixmap (imageZoomCursor);
624 QCursor zoomCursor (zoomPixmap);
625 if( setTransformRequested ( ZOOMVIEW ) )
626 myViewPort->setCursor( zoomCursor );
631 void OCCViewer_ViewWindow::onPanning()
633 OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( getViewManager() );
634 bool isChained = aMgr->isChainedOperations();
635 bool isReset = ( myPanningByBtn && isChained );
642 myPanningByBtn = true;
648 \brief Start panning operation.
650 Sets the corresponding cursor for the widget.
652 void OCCViewer_ViewWindow::activatePanning()
654 if ( !transformRequested() && !myCursorIsHand )
655 saveCursor(); // save old cursor
657 if ( myOperation != PANVIEW ) {
658 QCursor panCursor (Qt::SizeAllCursor);
659 if( setTransformRequested ( PANVIEW ) )
660 myViewPort->setCursor( panCursor );
665 \brief Start rotation operation
667 Sets the corresponding cursor for the widget.
669 void OCCViewer_ViewWindow::activateRotation()
671 if ( !transformRequested() && !myCursorIsHand )
672 saveCursor(); // save old cursor
674 if ( myOperation != ROTATE ) {
675 QPixmap rotatePixmap (imageRotateCursor);
676 QCursor rotCursor (rotatePixmap);
677 if( setTransformRequested ( ROTATE ) )
678 myViewPort->setCursor( rotCursor );
683 \brief Compute the gravity center.
684 \param theX used to return X coordinate of the gravity center
685 \param theY used to return Y coordinate of the gravity center
686 \param theZ used to return Z coordinate of the gravity center
687 \return \c true if the gravity center is computed
689 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
691 Handle(V3d_View) aView3d = myViewPort->getView();
693 // Project boundaries points and add to avergae gravity
694 // the ones which lie within the screen limits
695 Standard_Real aScreenLimits[4] = { 0.0, 0.0, 0.0, 0.0 };
697 // NDC space screen limits
698 aScreenLimits[0] = -1.0;
699 aScreenLimits[1] = 1.0;
700 aScreenLimits[2] = -1.0;
701 aScreenLimits[3] = 1.0;
703 Standard_Integer aPointsNb = 0;
705 Standard_Real aXmin = 0.0;
706 Standard_Real aYmin = 0.0;
707 Standard_Real aZmin = 0.0;
708 Standard_Real aXmax = 0.0;
709 Standard_Real aYmax = 0.0;
710 Standard_Real aZmax = 0.0;
712 Graphic3d_MapOfStructure aSetOfStructures;
713 aView3d->View()->DisplayedStructures( aSetOfStructures );
714 Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures );
716 for( ; aStructureIt.More(); aStructureIt.Next() ) {
717 const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key();
718 if ( aStructure->IsEmpty() || !aStructure->IsVisible() || aStructure->CStructure()->IsForHighlight )
721 Bnd_Box aBox1 = aStructure->MinMaxValues();
722 const Graphic3d_BndBox3d& aBox = aStructure->CStructure()->BoundingBox();
725 aXmin = /*aBox.IsVoid() ? RealFirst() :*/ aBox.CornerMin().x();
726 aYmin = /*aBox.IsVoid() ? RealFirst() : */aBox.CornerMin().y();
727 aZmin = /*aBox.IsVoid() ? RealFirst() : */aBox.CornerMin().z();
728 aXmax = /*aBox.IsVoid() ? RealLast() : */aBox.CornerMax().x();
729 aYmax = /*aBox.IsVoid() ? RealLast() : */aBox.CornerMax().y();
730 aZmax = /*aBox.IsVoid() ? RealLast() : */aBox.CornerMax().z();
732 // Infinite structures are skipped
733 Standard_Real aLIM = ShortRealLast() - 1.0;
734 if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
735 || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
739 gp_Pnt aPoints[8] = {
740 gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
741 gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
742 gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
743 gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
746 for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
747 const gp_Pnt& aBBPoint = aPoints[aPointIt];
749 gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
750 const Standard_Real& U = aProjected.X();
751 const Standard_Real& V = aProjected.Y();
753 if (U >= aScreenLimits[0]
754 && U <= aScreenLimits[1]
755 && V >= aScreenLimits[2]
756 && V <= aScreenLimits[3])
759 theX += aBBPoint.X();
760 theY += aBBPoint.Y();
761 theZ += aBBPoint.Z();
778 \brief Set the gravity center as a rotation point.
780 void OCCViewer_ViewWindow::activateSetRotationGravity()
782 if ( myRotationPointSelection )
784 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
785 #if OCC_VERSION_LARGE <= 0x07030000
786 ic->CloseAllContexts( Standard_True );
791 myOperation = NOTHING;
792 myViewPort->setCursor( myCursor );
793 myCursorIsHand = false;
794 myRotationPointSelection = false;
797 myPrevPointType = myCurrPointType;
798 myCurrPointType = BBCENTER;
800 Standard_Real Xcenter, Ycenter, Zcenter;
801 if ( OCCViewer_Utilities::computeVisibleBBCenter( myViewPort->getView(), Xcenter, Ycenter, Zcenter ) )
802 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
806 \brief Update gravity center in the "Set Rotation Point" dialog box.
807 \sa OCCViewer_SetRotationPointDlg class
809 void OCCViewer_ViewWindow::updateGravityCoords()
811 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == BBCENTER )
813 Standard_Real Xcenter, Ycenter, Zcenter;
814 if ( OCCViewer_Utilities::computeVisibleBBCenter( myViewPort->getView(), Xcenter, Ycenter, Zcenter ) )
815 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
820 \brief Set the point selected by the user as a rotation point.
821 \param theX X coordinate of the rotation point
822 \param theY Y coordinate of the rotation point
823 \param theZ Z coordinate of the rotation point
825 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
827 if ( myRotationPointSelection )
829 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
830 #if OCC_VERSION_LARGE < 0x07030000
831 ic->CloseAllContexts( Standard_True );
836 myOperation = NOTHING;
837 myViewPort->setCursor( myCursor );
838 myCursorIsHand = false;
839 myRotationPointSelection = false;
842 myPrevPointType = myCurrPointType;
843 myCurrPointType = SELECTED;
844 mySelectedPoint.SetCoord(theX,theY,theZ);
848 \brief Start the shape selection process.
850 void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
852 myPrevPointType = myCurrPointType;
853 myCurrPointType = SELECTED;
855 // activate selection ------>
856 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
857 #if OCC_VERSION_LARGE <= 0x07030000
858 ic->OpenLocalContext();
863 AIS_ListOfInteractive aList;
864 ic->DisplayedObjects( aList );
865 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
867 Handle(AIS_InteractiveObject) anObj = it.Value();
868 if ( !anObj.IsNull() && anObj->HasPresentation() &&
869 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
872 ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
875 // activate selection <------
877 if ( !myCursorIsHand )
879 QCursor handCursor (Qt::PointingHandCursor);
880 myCursorIsHand = true;
882 myViewPort->setCursor( handCursor );
884 myRotationPointSelection = true;
888 \brief Start global panning operation
890 Sets the corresponding cursor for the widget.
892 void OCCViewer_ViewWindow::activateGlobalPanning()
894 Handle(V3d_View) aView3d = myViewPort->getView();
895 if ( !aView3d.IsNull() ) {
896 QPixmap globalPanPixmap (imageCrossCursor);
897 QCursor glPanCursor (globalPanPixmap);
898 myCurScale = aView3d->Scale();
899 aView3d->FitAll(0.01, false);
900 saveCursor(); // save old cursor
901 myViewPort->fitAll(); // fits view before selecting a new scene center
902 if( setTransformRequested( PANGLOBAL ) )
903 myViewPort->setCursor( glPanCursor );
908 \brief Starts fit operation.
910 Sets the corresponding cursor for the widget.
912 void OCCViewer_ViewWindow::activateWindowFit()
914 if ( !transformRequested() && !myCursorIsHand )
915 saveCursor(); /* save old cursor */
917 if ( myOperation != WINDOWFIT ) {
918 QCursor handCursor (Qt::PointingHandCursor);
919 if( setTransformRequested ( WINDOWFIT ) )
921 myViewPort->setCursor ( handCursor );
922 myCursorIsHand = true;
928 \brief Start delayed viewer operation.
930 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
932 bool ok = transformEnabled( op );
933 myOperation = ok ? op : NOTHING;
934 myViewPort->setMouseTracking( myOperation == NOTHING );
939 \brief Handle mouse move event.
940 \param theEvent mouse event
942 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
944 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
946 switch ( getButtonState( theEvent, interactionStyle() ) ) {
948 myViewPort->startZoomAtPoint( myStartX, myStartY );
956 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
963 myCurrX = theEvent->x();
964 myCurrY = theEvent->y();
965 switch (myOperation) {
967 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
971 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
977 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
991 if ( myRotationPointSelection || isSketcherStyle() )
993 emit mouseMoving( this, theEvent );
997 int aState = theEvent->modifiers();
998 int aButton = theEvent->buttons();
999 int anInteractionStyle = interactionStyle();
1000 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
1001 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
1002 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
1003 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
1004 myDrawRect = myEnableDrawMode;
1007 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
1008 QCursor handCursor (Qt::PointingHandCursor);
1009 myCursorIsHand = true;
1011 myViewPort->setCursor( handCursor );
1014 emit mouseMoving( this, theEvent );
1016 else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
1017 aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
1018 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
1019 aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
1020 OCCViewer_ViewSketcher* sketcher = 0;
1021 QList<OCCViewer_ViewSketcher*>::Iterator it;
1022 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
1024 OCCViewer_ViewSketcher* sk = (*it);
1025 if( sk->isDefault() && sk->sketchButton() == aButton )
1028 if ( sketcher && myCurSketch == -1 )
1030 activateSketching( sketcher->type() );
1033 myCurSketch = mypSketcher->sketchButton();
1035 if ( l_mbPressEvent )
1037 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
1038 delete l_mbPressEvent;
1041 QApplication::sendEvent( getViewPort(), theEvent );
1046 emit mouseMoving( this, theEvent );
1052 \brief Handle mouse release event.
1053 \param theEvent mouse event
1055 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
1057 switch ( myOperation ) {
1060 int prevState = myCurSketch;
1061 if(theEvent->button() == Qt::RightButton)
1063 QList<OCCViewer_ViewSketcher*>::Iterator it;
1064 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
1066 OCCViewer_ViewSketcher* sk = (*it);
1067 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
1072 emit mouseReleased(this, theEvent);
1073 if(theEvent->button() == Qt::RightButton && prevState == -1)
1075 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1076 theEvent->pos(), theEvent->globalPos() );
1077 emit contextMenuRequested( &aEvent );
1082 myViewPort->endRotation();
1089 OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( getViewManager() );
1090 bool isChained = aMgr->isChainedOperations();
1091 bool isReset = !( myOperation==PANVIEW && myPanningByBtn && isChained ) || theEvent->button() == Qt::RightButton;
1098 if ( theEvent->button() == Qt::LeftButton ) {
1099 myViewPort->setCenter( theEvent->x(), theEvent->y() );
1100 myViewPort->getView()->SetScale(myCurScale);
1106 if ( theEvent->button() == Qt::LeftButton ) {
1107 myCurrX = theEvent->x();
1108 myCurrY = theEvent->y();
1110 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1111 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1118 // NOTE: viewer 3D detects a rectangle of selection using this event
1119 // so we must emit it BEFORE resetting the selection rectangle
1121 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1125 myViewPort->update();
1128 if ( l_mbPressEvent )
1130 delete l_mbPressEvent;
1136 \brief Reset the viewport to its initial state
1137 ( no transformations in process etc. )
1139 void OCCViewer_ViewWindow::resetState()
1143 if ( myRotationPointSelection )
1145 QCursor handCursor (Qt::PointingHandCursor);
1146 myViewPort->setCursor( handCursor );
1150 if ( transformRequested() || myCursorIsHand )
1151 myViewPort->setCursor( myCursor );
1152 myCursorIsHand = false;
1155 if ( transformRequested() )
1156 emit vpTransformationFinished (myOperation);
1158 setTransformInProcess( false );
1159 setTransformRequested( NOTHING );
1161 myPanningByBtn = false;
1166 \brief Draw rubber band rectangle.
1168 void OCCViewer_ViewWindow::drawRect()
1170 if ( !myRectBand ) {
1171 myRectBand = new QtxRectRubberBand( myViewPort );
1173 //palette.setColor(myRectBand->foregroundRole(), Qt::white);
1174 //myRectBand->setPalette(palette);
1176 //myRectBand->hide();
1178 myRectBand->setUpdatesEnabled ( false );
1179 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1180 myRectBand->initGeometry( aRect );
1182 if ( !myRectBand->isVisible() )
1185 myRectBand->setUpdatesEnabled ( true );
1186 //myRectBand->repaint();
1188 //myRectBand->setVisible( aRect.isValid() );
1189 //if ( myRectBand->isVisible() )
1190 // myRectBand->repaint();
1192 // myRectBand->show();
1193 //myRectBand->repaint();
1197 \brief Clear rubber band rectangle on the end on the dragging operation.
1199 void OCCViewer_ViewWindow::endDrawRect()
1201 //delete myRectBand;
1205 myRectBand->clearGeometry();
1211 \brief Create actions.
1213 void OCCViewer_ViewWindow::createActions()
1215 if( !toolMgr()->isEmpty() )
1218 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1225 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1226 tr( "MNU_DUMP_VIEW" ), 0, this);
1227 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1228 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1229 toolMgr()->registerAction( aAction, DumpId );
1232 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1233 tr( "MNU_FITALL" ), 0, this);
1234 aAction->setStatusTip(tr("DSC_FITALL"));
1235 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1236 toolMgr()->registerAction( aAction, FitAllId );
1239 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1240 tr( "MNU_FITRECT" ), 0, this);
1241 aAction->setStatusTip(tr("DSC_FITRECT"));
1242 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1243 toolMgr()->registerAction( aAction, FitRectId );
1246 aAction = new QtxAction(tr("MNU_FITSELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITSELECTION" ) ),
1247 tr( "MNU_FITSELECTION" ), 0, this);
1248 aAction->setStatusTip(tr("DSC_FITSELECTION"));
1249 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
1250 toolMgr()->registerAction( aAction, FitSelectionId );
1253 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1254 tr( "MNU_ZOOM_VIEW" ), 0, this);
1255 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1256 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1257 toolMgr()->registerAction( aAction, ZoomId );
1260 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1261 tr( "MNU_PAN_VIEW" ), 0, this);
1262 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1263 connect(aAction, SIGNAL(triggered()), this, SLOT(onPanning()));
1264 toolMgr()->registerAction( aAction, PanId );
1267 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1268 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1269 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1270 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1271 toolMgr()->registerAction( aAction, GlobalPanId );
1274 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1275 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1276 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1277 mySetRotationPointAction->setCheckable( true );
1278 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1279 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1282 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1283 tr( "MNU_ROTATE_VIEW" ), 0, this);
1284 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1285 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1286 toolMgr()->registerAction( aAction, RotationId );
1289 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1290 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1291 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1292 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1293 this->addAction(aAction);
1294 toolMgr()->registerAction( aAction, FrontId );
1296 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1297 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1298 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1299 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1300 this->addAction(aAction);
1301 toolMgr()->registerAction( aAction, BackId );
1303 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1304 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1305 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1306 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1307 this->addAction(aAction);
1308 toolMgr()->registerAction( aAction, TopId );
1310 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1311 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1312 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1313 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1314 this->addAction(aAction);
1315 toolMgr()->registerAction( aAction, BottomId );
1317 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1318 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1319 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1320 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1321 this->addAction(aAction);
1322 toolMgr()->registerAction( aAction, LeftId );
1324 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1325 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1326 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1327 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1328 this->addAction(aAction);
1329 toolMgr()->registerAction( aAction, RightId );
1331 // rotate anticlockwise
1332 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1333 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1334 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1335 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1336 this->addAction(aAction);
1337 toolMgr()->registerAction( aAction, AntiClockWiseId );
1340 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1341 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1342 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1343 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1344 this->addAction(aAction);
1345 toolMgr()->registerAction( aAction, ClockWiseId );
1347 // Projection mode group
1349 // - orthographic projection
1350 aAction = new QtxAction(tr("MNU_ORTHOGRAPHIC_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ORTHOGRAPHIC" ) ),
1351 tr( "MNU_ORTHOGRAPHIC_MODE" ), 0, this);
1352 aAction->setStatusTip(tr("DSC_ORTHOGRAPHIC_MODE"));
1353 aAction->setCheckable(true);
1354 toolMgr()->registerAction( aAction, OrthographicId );
1356 // - perspective projection
1357 aAction = new QtxAction(tr("MNU_PERSPECTIVE_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PERSPECTIVE" ) ),
1358 tr( "MNU_PERSPECTIVE_MODE" ), 0, this);
1359 aAction->setStatusTip(tr("DSC_PERSPECTIVE_MODE"));
1360 aAction->setCheckable(true);
1361 toolMgr()->registerAction( aAction, PerspectiveId );
1363 // - stereo projection
1364 aAction = new QtxAction(tr("MNU_STEREO_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STEREO" ) ),
1365 tr( "MNU_STEREO_MODE" ), 0, this);
1366 aAction->setStatusTip(tr("DSC_STEREO_MODE"));
1367 aAction->setCheckable(true);
1368 toolMgr()->registerAction( aAction, StereoId );
1369 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onStereoType(bool)));
1371 // - add exclusive action group
1372 QActionGroup* aProjectionGroup = new QActionGroup( this );
1373 aProjectionGroup->addAction( toolMgr()->action( OrthographicId ) );
1374 aProjectionGroup->addAction( toolMgr()->action( PerspectiveId ) );
1375 connect(aProjectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProjectionType(QAction*)));
1378 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1379 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1380 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1381 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1382 this->addAction(aAction);
1383 toolMgr()->registerAction( aAction, ResetId );
1386 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1387 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1388 tr("MNU_CLONE_VIEW"), 0, this);
1389 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1390 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1391 toolMgr()->registerAction( aAction, CloneId );
1393 aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
1394 tr("MNU_CLIPPING"), 0, this);
1395 aAction->setStatusTip (tr("DSC_CLIPPING"));
1396 aAction->setCheckable (true);
1397 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1398 toolMgr()->registerAction (aAction, ClippingId);
1400 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1401 tr( "MNU_SHOOT_VIEW" ), 0, this);
1402 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1403 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1404 toolMgr()->registerAction( aAction, MemId );
1406 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1407 tr( "MNU_PRESETS_VIEW" ), 0, this);
1408 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1409 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1410 toolMgr()->registerAction( aAction, RestoreId );
1412 if (myModel->trihedronActivated()) {
1413 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1414 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1415 aAction->setCheckable( true );
1416 aAction->setChecked( true );
1417 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1418 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1419 toolMgr()->registerAction( aAction, TrihedronShowId );
1423 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1424 tr( "MNU_SCALING" ), 0, this);
1425 aAction->setStatusTip(tr("DSC_SCALING"));
1426 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1427 toolMgr()->registerAction( aAction, AxialScaleId );
1429 // Enable/disable preselection
1430 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1431 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1432 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1433 aAction->setCheckable(true);
1434 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1435 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1437 // Enable/disable selection
1438 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1439 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1440 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1441 aAction->setCheckable(true);
1442 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1443 toolMgr()->registerAction( aAction, SwitchSelectionId );
1446 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1447 tr( "MNU_GRADUATED_AXES" ), 0, this);
1448 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1449 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1450 toolMgr()->registerAction( aAction, GraduatedAxesId );
1452 // Active only ambient light or not
1453 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1454 tr( "MNU_AMBIENT" ), 0, this);
1455 aAction->setStatusTip(tr("DSC_AMBIENT"));
1456 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1457 toolMgr()->registerAction( aAction, AmbientId );
1459 // Switch between interaction styles
1460 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1461 tr( "MNU_STYLE_SWITCH" ), 0, this);
1462 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1463 aAction->setCheckable(true);
1464 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1465 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1467 // Switch between zooming styles
1468 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1469 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1470 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1471 aAction->setCheckable(true);
1472 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1473 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1476 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1477 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1478 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1479 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1480 toolMgr()->registerAction( aAction, MaximizedId );
1482 // Return to 3d view
1483 if (my2dMode!=No2dMode){
1484 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1485 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1486 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1487 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1488 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1492 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1493 #ifdef ENABLE_RAY_TRACING
1495 aAction = new QtxAction( tr("MNU_RAY_TRACING"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_RAY_TRACING") ),
1496 tr("MNU_RAY_TRACING"), 0, this );
1497 aAction->setStatusTip( tr("DSC_RAY_TRACING") );
1498 connect( aAction, SIGNAL( triggered() ), this, SLOT( onRayTracing() ) );
1499 toolMgr()->registerAction( aAction, RayTracingId );
1501 // Environment texture
1502 aAction = new QtxAction( tr("MNU_ENV_TEXTURE"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_ENV_TEXTURE") ),
1503 tr("MNU_ENV_TEXTURE"), 0, this );
1504 aAction->setStatusTip( tr("DSC_ENV_TEXTURE") );
1505 connect( aAction, SIGNAL( triggered() ), this, SLOT( onEnvTexture() ) );
1506 toolMgr()->registerAction( aAction, EnvTextureId );
1509 aAction = new QtxAction( tr("MNU_LIGHT_SOURCE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_LIGHT_SOURCE" ) ),
1510 tr( "MNU_LIGHT_SOURCE" ), 0, this );
1511 aAction->setStatusTip( tr("DSC_LIGHT_SOURCE") );
1512 connect( aAction, SIGNAL( triggered() ), this, SLOT( onLightSource() ) );
1513 toolMgr()->registerAction( aAction, LightSourceId );
1518 \brief Create toolbar.
1520 void OCCViewer_ViewWindow::createToolBar()
1522 static const char* titles[] = {
1523 "LBL_3DTOOLBAR_LABEL",
1524 "LBL_XYTOOLBAR_LABEL",
1525 "LBL_XZTOOLBAR_LABEL",
1526 "LBL_YZTOOLBAR_LABEL",
1528 static const char* names[] = {
1529 "OCCViewer3DViewOperations",
1530 "OCCViewerXYViewOperations",
1531 "OCCViewerXZViewOperations",
1532 "OCCViewerYZViewOperations",
1534 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1535 QString( names[my2dMode] ), // name (language-independant)
1536 false ); // disable floatable toolbar
1537 if ( my2dMode != No2dMode ){
1538 toolMgr()->append( ReturnTo3dViewId, tid );
1539 toolMgr()->append( toolMgr()->separator(), tid );
1541 toolMgr()->append( DumpId, tid );
1542 toolMgr()->append( SwitchInteractionStyleId, tid );
1543 toolMgr()->append( SwitchZoomingStyleId, tid );
1544 toolMgr()->append( SwitchPreselectionId, tid );
1545 toolMgr()->append( SwitchSelectionId, tid );
1546 if( myModel->trihedronActivated() )
1547 toolMgr()->append( TrihedronShowId, tid );
1549 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1550 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1551 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1552 aScaleAction->insertAction( toolMgr()->action( FitSelectionId ) );
1553 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1554 toolMgr()->append( aScaleAction, tid );
1556 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1557 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1558 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1559 toolMgr()->append( aPanningAction, tid );
1561 if (my2dMode == No2dMode) {
1562 toolMgr()->append( ChangeRotationPointId, tid );
1563 toolMgr()->append( RotationId, tid );
1565 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1566 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1567 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1568 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1569 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1570 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1571 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1572 toolMgr()->append( aViewsAction, tid );
1574 toolMgr()->append( AntiClockWiseId, tid );
1575 toolMgr()->append( ClockWiseId, tid );
1577 toolMgr()->append( OrthographicId, tid );
1578 toolMgr()->append( PerspectiveId, tid );
1579 toolMgr()->append( StereoId, tid );
1581 toolMgr()->append( ResetId, tid );
1584 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1585 aMemAction->insertAction( toolMgr()->action( MemId ) );
1586 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1587 toolMgr()->append( aMemAction, tid );
1589 toolMgr()->append( toolMgr()->separator(), tid );
1590 toolMgr()->append( CloneId, tid );
1592 toolMgr()->append( toolMgr()->separator(), tid );
1593 toolMgr()->append( ClippingId, tid );
1594 toolMgr()->append( AxialScaleId, tid );
1595 toolMgr()->append( GraduatedAxesId, tid );
1596 toolMgr()->append( AmbientId, tid );
1598 toolMgr()->append( MaximizedId, tid );
1599 toolMgr()->append( SynchronizeId, tid );
1600 #ifdef ENABLE_RAY_TRACING
1601 toolMgr()->append( RayTracingId, tid );
1602 toolMgr()->append( EnvTextureId, tid );
1603 toolMgr()->append( LightSourceId, tid );
1608 \brief Perform 'fit all' operation.
1610 void OCCViewer_ViewWindow::onViewFitAll()
1612 myViewPort->fitAll();
1616 \brief Perform "front view" transformation.
1618 void OCCViewer_ViewWindow::onFrontView()
1620 emit vpTransformationStarted ( FRONTVIEW );
1621 Handle(V3d_View) aView3d = myViewPort->getView();
1622 if (myAutomaticZoom)
1624 if ( !aView3d.IsNull() )
1625 aView3d->SetProj (V3d_Xpos);
1629 projAndPanToGravity(V3d_Xpos);
1630 emit vpTransformationFinished ( FRONTVIEW );
1634 \brief Perform "back view" transformation.
1636 void OCCViewer_ViewWindow::onBackView()
1638 emit vpTransformationStarted ( BACKVIEW );
1639 Handle(V3d_View) aView3d = myViewPort->getView();
1640 if (myAutomaticZoom)
1642 if ( !aView3d.IsNull() )
1643 aView3d->SetProj (V3d_Xneg);
1647 projAndPanToGravity(V3d_Xneg);
1648 emit vpTransformationFinished ( BACKVIEW );
1652 \brief Perform "top view" transformation.
1654 void OCCViewer_ViewWindow::onTopView()
1656 emit vpTransformationStarted ( TOPVIEW );
1657 Handle(V3d_View) aView3d = myViewPort->getView();
1658 if (myAutomaticZoom)
1660 if ( !aView3d.IsNull() )
1661 aView3d->SetProj (V3d_Zpos);
1665 projAndPanToGravity(V3d_Zpos);
1666 emit vpTransformationFinished ( TOPVIEW );
1670 \brief Perform "bottom view" transformation.
1672 void OCCViewer_ViewWindow::onBottomView()
1674 emit vpTransformationStarted ( BOTTOMVIEW );
1675 Handle(V3d_View) aView3d = myViewPort->getView();
1676 if (myAutomaticZoom)
1678 if ( !aView3d.IsNull() )
1679 aView3d->SetProj (V3d_Zneg);
1683 projAndPanToGravity(V3d_Zneg);
1684 emit vpTransformationFinished ( BOTTOMVIEW );
1688 \brief Perform "left view" transformation.
1690 void OCCViewer_ViewWindow::onLeftView()
1692 emit vpTransformationStarted ( LEFTVIEW );
1693 Handle(V3d_View) aView3d = myViewPort->getView();
1694 if (myAutomaticZoom)
1696 if ( !aView3d.IsNull() )
1697 aView3d->SetProj (V3d_Yneg);
1701 projAndPanToGravity(V3d_Yneg);
1702 emit vpTransformationFinished ( LEFTVIEW );
1706 \brief Perform "right view" transformation.
1708 void OCCViewer_ViewWindow::onRightView()
1710 emit vpTransformationStarted ( RIGHTVIEW );
1711 Handle(V3d_View) aView3d = myViewPort->getView();
1712 if (myAutomaticZoom)
1714 if ( !aView3d.IsNull() )
1715 aView3d->SetProj (V3d_Ypos);
1719 projAndPanToGravity(V3d_Ypos);
1720 emit vpTransformationFinished ( RIGHTVIEW );
1724 \brief Rotate view 90 degrees clockwise
1726 void OCCViewer_ViewWindow::onClockWiseView()
1728 emit vpTransformationStarted ( CLOCKWISEVIEW );
1729 myViewPort->rotateXY( 90. );
1730 emit vpTransformationFinished ( CLOCKWISEVIEW );
1734 \brief Rotate view 90 degrees conterclockwise
1736 void OCCViewer_ViewWindow::onAntiClockWiseView()
1738 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1739 myViewPort->rotateXY( -90. );
1740 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1744 \brief Perform "reset view" transformation.
1746 Sets default orientation of the viewport camera.
1748 void OCCViewer_ViewWindow::onResetView()
1750 emit vpTransformationStarted( RESETVIEW );
1751 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1752 myViewPort->getView()->Reset( false );
1753 myViewPort->fitAll( false, true, false );
1754 myViewPort->getView()->SetImmediateUpdate( upd );
1755 onProjectionType(); // needed to apply projection type properly after reset
1756 myViewPort->getView()->Update();
1757 emit vpTransformationFinished( RESETVIEW );
1761 \brief Set the given projection mode.
1763 Set the given projection mode: Orthographic or Perspective.
1765 void OCCViewer_ViewWindow::onProjectionType( QAction* theAction )
1767 Handle(V3d_View) aView3d = myViewPort->getView();
1768 if ( !aView3d.IsNull() ) {
1769 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1770 if (theAction == toolMgr()->action( OrthographicId )) {
1771 myModel->setProjectionType(Orthographic);
1772 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Orthographic );
1773 aCamera->SetFOVy(45.0);
1775 else if (theAction == toolMgr()->action( PerspectiveId )) {
1776 myModel->setProjectionType(Perspective);
1777 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Perspective );
1778 aCamera->SetFOVy(30.0);
1780 if (toolMgr()->action( StereoId )->isChecked()) {
1781 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1782 aCamera->SetFOVy(30.0);
1790 \brief Sets Stereo projection mode.
1792 Sets Stereo projection mode.
1794 void OCCViewer_ViewWindow::onStereoType( bool activate )
1796 Handle(V3d_View) aView3d = myViewPort->getView();
1797 if ( !aView3d.IsNull() ) {
1798 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1800 toolMgr()->action( PerspectiveId )->setChecked(true);
1801 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1802 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(false);
1804 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1805 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1806 setStereoType( aResMgr->integerValue( "OCCViewer", "stereo_type", 0 ) );
1807 setAnaglyphFilter( aResMgr->integerValue( "OCCViewer", "anaglyph_filter", 0 ) );
1808 setReverseStereo( aResMgr->booleanValue( "OCCViewer", "reverse_stereo", false ) );
1809 setVSync( aResMgr->booleanValue( "OCCViewer", "enable_vsync", true ) );
1810 setQuadBufferSupport( aResMgr->booleanValue( "OCCViewer", "enable_quad_buffer_support", false ) );
1813 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(true);
1814 if (myModel->projectionType() == Orthographic) {
1815 toolMgr()->action( OrthographicId )->setChecked(true);
1816 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Orthographic);
1818 else if (myModel->projectionType() == Perspective) {
1819 toolMgr()->action( PerspectiveId )->setChecked(true);
1820 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1827 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1828 toolMgr()->action( StereoId )->isChecked() )
1829 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1833 \brief Restore the view.
1835 Restore the projection mode based on tool-buttons states.
1837 void OCCViewer_ViewWindow::onProjectionType()
1839 emit vpTransformationStarted( PROJECTION );
1840 if (toolMgr()->action( OrthographicId )->isChecked())
1841 setProjectionType( Orthographic );
1842 if (toolMgr()->action( PerspectiveId )->isChecked())
1843 setProjectionType( Perspective );
1844 if (toolMgr()->action( StereoId )->isChecked())
1845 setProjectionType( Stereo );
1846 emit vpTransformationFinished( PROJECTION );
1849 void OCCViewer_ViewWindow::setProjectionType( int mode )
1851 QtxAction* anOrthographicAction = dynamic_cast<QtxAction*>( toolMgr()->action( OrthographicId ) );
1852 QtxAction* aPerspectiveAction = dynamic_cast<QtxAction*>( toolMgr()->action( PerspectiveId ) );
1853 QtxAction* aStereoAction = dynamic_cast<QtxAction*>( toolMgr()->action( StereoId ) );
1856 onProjectionType( anOrthographicAction );
1859 onProjectionType( aPerspectiveAction );
1862 onStereoType( true );
1865 // update action state if method is called outside
1866 if ( mode == Orthographic && !anOrthographicAction->isChecked() ) {
1867 anOrthographicAction->setChecked( true );
1868 aStereoAction->setChecked( false );
1870 if ( mode == Perspective && !aPerspectiveAction->isChecked() ) {
1871 aPerspectiveAction->setChecked( true );
1872 aStereoAction->setChecked( false );
1874 if ( mode == Stereo ) {
1875 aStereoAction->setChecked( true );
1876 if ( anOrthographicAction->isEnabled() ) {
1877 anOrthographicAction->setEnabled( false );
1878 anOrthographicAction->setChecked( false );
1879 aStereoAction->setChecked( false );
1882 anOrthographicAction->setEnabled( true );
1883 aStereoAction->setChecked( false );
1884 anOrthographicAction->setChecked(myModel->projectionType() == Orthographic);
1886 if ( aPerspectiveAction->isEnabled() ) {
1887 aPerspectiveAction->setEnabled( false );
1888 aPerspectiveAction->setChecked( true );
1889 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1890 toolMgr()->action( StereoId )->isChecked() )
1891 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1894 aPerspectiveAction->setEnabled( true );
1895 aStereoAction->setChecked( false );
1896 aPerspectiveAction->setChecked(myModel->projectionType() == Perspective);
1901 if ( !anOrthographicAction->isEnabled() )
1902 anOrthographicAction->setEnabled( true );
1903 if ( !aPerspectiveAction->isEnabled() )
1904 aPerspectiveAction->setEnabled( true );
1909 \brief Perform "fit all" transformation.
1911 void OCCViewer_ViewWindow::onFitAll()
1913 emit vpTransformationStarted( FITALLVIEW );
1914 myViewPort->fitAll();
1915 emit vpTransformationFinished( FITALLVIEW );
1919 \brief Perform "fit selection" transformation.
1921 void OCCViewer_ViewWindow::onFitSelection()
1923 emit vpTransformationStarted( FITSELECTION );
1924 myModel->getAISContext()->FitSelected( getViewPort()->getView() );
1925 emit vpTransformationFinished( FITSELECTION );
1929 \brief Called if 'change rotation point' operation is activated.
1930 \param on action state
1932 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1936 if (!mySetRotationPointDlg)
1938 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1939 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1942 if (!mySetRotationPointDlg->isVisible())
1944 //if (mySetRotationPointDlg->IsFirstShown())
1945 if (myCurrPointType == BBCENTER)
1947 Standard_Real Xcenter, Ycenter, Zcenter;
1948 if (OCCViewer_Utilities::computeVisibleBBCenter(myViewPort->getView(), Xcenter, Ycenter, Zcenter))
1949 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1951 mySetRotationPointDlg->show();
1956 if (mySetRotationPointDlg->isVisible())
1957 mySetRotationPointDlg->hide();
1962 \brief Create one more window with same content.
1964 void OCCViewer_ViewWindow::onCloneView()
1966 SUIT_ViewWindow* vw = myManager->createViewWindow();
1968 emit viewCloned( vw );
1969 OCCViewer_ViewWindow* occVw = dynamic_cast<OCCViewer_ViewWindow*> (vw);
1970 if(occVw && occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)) {
1971 occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)->synchronize(this);
1976 Creates one more window with same content
1978 void OCCViewer_ViewWindow::onAxialScale()
1980 if ( !myScalingDlg )
1981 myScalingDlg = new OCCViewer_AxialScaleDlg( this , myModel );
1983 if ( !myScalingDlg->isVisible() )
1985 myScalingDlg->Update();
1986 myScalingDlg->show();
1991 Shows Graduated Axes dialog
1993 void OCCViewer_ViewWindow::onGraduatedAxes()
1995 myCubeAxesDlg->Update();
1996 myCubeAxesDlg->show();
1999 void OCCViewer_ViewWindow::onAmbientToogle()
2001 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2002 viewer->InitDefinedLights();
2003 while(viewer->MoreDefinedLights())
2005 Handle(V3d_Light) light = viewer->DefinedLight();
2006 if(light->Type() != V3d_AMBIENT)
2008 Handle(V3d_View) aView3d = myViewPort->getView();
2009 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
2010 else viewer->SetLightOn(light);
2012 viewer->NextDefinedLights();
2018 \brief Store view parameters.
2020 void OCCViewer_ViewWindow::onMemorizeView()
2022 appendViewAspect( getViewParams() );
2026 \brief Restore view parameters.
2028 void OCCViewer_ViewWindow::onRestoreView()
2030 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
2031 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
2033 updateViewAspects( aDlg->parameters() );
2034 if( myRestoreFlag && aDlg->parameters().count() )
2035 performRestoring( aDlg->currentItem() );
2039 \brief Restore view parameters.
2040 \param anItem view parameters
2042 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
2044 Handle(V3d_View) aView3d = myViewPort->getView();
2046 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
2047 aView3d->SetScale( anItem.scale );
2048 aView3d->SetTwist( anItem.twist );
2049 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
2050 aView3d->SetImmediateUpdate( prev );
2051 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2052 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2053 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
2055 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
2057 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
2059 // "eye" and "at" require conversion to represent center panning
2060 // up direction is only available after setting angle of twist and
2061 // other view parameters
2062 aView3d->Up( anUpX, anUpY, anUpZ );
2064 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
2065 gp_Dir anUp( anUpX, anUpY, anUpZ );
2066 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
2067 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2068 gp_Dir aSide = aProj ^ anUp;
2070 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
2071 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
2073 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
2074 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2077 if ( !baseParamsOnly ) {
2079 myModel->setTrihedronShown( anItem.isVisible );
2080 myModel->setTrihedronSize( anItem.size );
2082 // graduated trihedron
2083 bool anIsVisible = anItem.gtIsVisible;
2084 OCCViewer_AxisWidget::AxisData anAxisData[3];
2085 anAxisData[0].DrawName = anItem.gtDrawNameX;
2086 anAxisData[1].DrawName = anItem.gtDrawNameZ;
2087 anAxisData[2].DrawName = anItem.gtDrawNameZ;
2088 anAxisData[0].Name = anItem.gtNameX;
2089 anAxisData[1].Name = anItem.gtNameZ;
2090 anAxisData[2].Name = anItem.gtNameZ;
2091 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
2092 anItem.gtNameColorGX,
2093 anItem.gtNameColorBX );
2094 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
2095 anItem.gtNameColorGY,
2096 anItem.gtNameColorBY );
2097 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
2098 anItem.gtNameColorGZ,
2099 anItem.gtNameColorBZ );
2100 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
2101 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
2102 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
2103 anAxisData[0].NbValues = anItem.gtNbValuesX;
2104 anAxisData[1].NbValues = anItem.gtNbValuesY;
2105 anAxisData[2].NbValues = anItem.gtNbValuesZ;
2106 anAxisData[0].Offset = anItem.gtOffsetX;
2107 anAxisData[1].Offset = anItem.gtOffsetY;
2108 anAxisData[2].Offset = anItem.gtOffsetZ;
2109 anAxisData[0].Color = QColor( anItem.gtColorRX,
2112 anAxisData[1].Color = QColor( anItem.gtColorRY,
2115 anAxisData[2].Color = QColor( anItem.gtColorRZ,
2118 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
2119 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
2120 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
2121 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
2122 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
2123 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
2125 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
2126 myCubeAxesDlg->ApplyData( aView3d );
2128 } // if ( !baseParamsOnly )
2134 \brief Set restore flag.
2136 void OCCViewer_ViewWindow::setRestoreFlag()
2142 \brief Called when action "show/hide trihedron" is activated.
2144 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
2146 myModel->setTrihedronShown(show);
2150 \brief Toggles preselection (highlighting) on/off
2152 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
2154 myPreselectionEnabled = on;
2155 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
2157 // unhighlight all highlighted objects
2159 myModel->unHighlightAll( true, false );
2162 // update action state if method is called outside
2163 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2164 if ( a && a->isChecked() != on ) {
2165 a->setChecked( on );
2170 \brief Toggles selection on/off
2172 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
2174 mySelectionEnabled = on;
2175 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
2177 // update action state if method is called outside
2180 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2182 a->setEnabled( on );
2186 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
2187 if ( a && a->isChecked() != on ) {
2188 a->setChecked( on );
2193 \brief Switches "keyboard free" interaction style on/off
2195 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
2197 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
2199 // update action state if method is called outside
2200 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
2201 if ( a && a->isChecked() != on )
2202 a->setChecked( on );
2206 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
2208 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
2210 myViewPort->setAdvancedZoomingEnabled( on );
2212 // update action state if method is called outside
2213 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
2214 if ( a && a->isChecked() != on )
2215 a->setChecked( on );
2219 \brief Get current interaction style
2220 \return interaction style
2222 int OCCViewer_ViewWindow::interactionStyle() const
2224 return myInteractionStyle;
2228 \brief Set current interaction style
2229 \param theStyle interaction style
2231 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
2233 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
2237 \brief Get current zooming style
2238 \return zooming style
2240 int OCCViewer_ViewWindow::zoomingStyle() const
2242 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
2246 \brief Set current zooming style
2247 \param theStyle zooming style
2249 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
2251 onSwitchZoomingStyle( theStyle == 1 );
2255 \brief Dump view window contents to the pixmap.
2256 \return pixmap containing all scene rendered in the window
2258 //#define USE_OLD_IMPLEMENTATION
2259 QImage OCCViewer_ViewWindow::dumpView()
2261 Handle(V3d_View) view = myViewPort->getView();
2262 if ( view.IsNull() )
2265 int aWidth = myViewPort->width();
2266 int aHeight = myViewPort->height();
2268 #ifdef USE_OLD_IMPLEMENTATION
2269 // rnv: Old approach to dump the OCCViewer content via Frame Buffer Object
2273 #ifndef DISABLE_GLVIEWER
2274 OpenGLUtils_FrameBuffer aFrameBuffer;
2275 if ( aFrameBuffer.init( aWidth, aHeight ) )
2277 glPushAttrib( GL_VIEWPORT_BIT );
2278 glViewport( 0, 0, aWidth, aHeight );
2279 aFrameBuffer.bind();
2284 aFrameBuffer.unbind();
2287 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
2289 aFrameBuffer.bind();
2290 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
2291 aFrameBuffer.unbind();
2293 anImage = anImage.rgbSwapped();
2294 anImage = anImage.mirrored();
2298 // if frame buffers are unsupported, use old approach
2300 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
2301 QPoint p = myViewPort->mapFromParent( myViewPort->geometry().topLeft() );
2302 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
2304 QImage anImage( data, aWidth, aHeight, QImage::Format_ARGB32 );
2305 anImage = anImage.mirrored();
2306 anImage = anImage.rgbSwapped();
2309 #else // DISABLE_GLVIEWER
2313 #endif // DISABLE_GLVIEWER
2315 #else // USE_OLD_IMPLEMENTATION
2316 // rnv: New approach is to use OCCT built-in procedure
2319 view->ToPixMap(aPix, aWidth, aHeight, Graphic3d_BT_RGB);
2321 QImage anImage( aWidth, aHeight, QImage::Format_ARGB32 );
2322 for ( int i = 0; i < aWidth; i++ ) {
2323 for ( int j = 0; j < aHeight; j++ ) {
2324 Quantity_Color pixel = aPix.PixelColor( i, j ).GetRGB();
2325 QColor color = QColor::fromRgbF( pixel.Red(), pixel.Green(), pixel.Blue() );
2326 anImage.setPixelColor( i, j, color );
2330 if ( aPix.IsTopDown() )
2331 anImage = anImage.mirrored();
2334 #endif // USE_OLD_IMPLEMENTATION
2337 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
2338 const QString& fileName,
2339 const QString& format )
2342 QApplication::setOverrideCursor( Qt::WaitCursor );
2344 // OCCT version > 7.3.0 is not support export to PS and EPS
2345 #if OCC_VERSION_LARGE <= 0x07030000
2346 Handle(Graphic3d_CView) a3dView = myViewPort->getView()->View();
2348 if (format == "PS") {
2349 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(myViewPort->getViewer()->Driver());
2350 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
2351 int prev = aCaps->ffpEnable;
2352 aCaps->ffpEnable = 1;
2353 res = a3dView->Export(strdup(qUtf8Printable(fileName)), Graphic3d_EF_PostScript);
2354 aCaps->ffpEnable = prev;
2356 else if (format == "EPS") {
2357 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(myViewPort->getViewer()->Driver());
2358 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
2359 int prev = aCaps->ffpEnable;
2360 aCaps->ffpEnable = 1;
2361 res = a3dView->Export(strdup(qUtf8Printable(fileName)), Graphic3d_EF_EnhPostScript);
2362 aCaps->ffpEnable = prev;
2366 res = myViewPort->getView()->Dump( fileName.toStdString().c_str() );
2367 #if OCC_VERSION_LARGE <= 0x07030000
2371 QApplication::restoreOverrideCursor();
2376 QString OCCViewer_ViewWindow::filter() const
2378 #if OCC_VERSION_LARGE <= 0x07030000
2379 return tr( "OCC_IMAGE_FILES" );
2381 QString formats = tr( "OCC_IMAGE_FILES" );
2382 return formats.remove(" *.eps *.ps");
2388 \brief Set parameters of the cutting plane
2389 \param on if \c true, cutting plane is enabled
2390 \param x X position of plane point
2391 \param y Y position of plane point
2392 \param z Z position of plane point
2393 \param dx X coordinate of plane normal
2394 \param dy Y coordinate of plane normal
2395 \param dz Z coordinate of plane normal
2397 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2398 const double dx, const double dy, const double dz )
2400 Handle(V3d_View) view = myViewPort->getView();
2401 if ( view.IsNull() )
2405 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2407 // try to use already existing plane or create a new one
2408 Handle(V3d_Plane) clipPlane;
2410 // calculate new a,b,c,d values for the plane
2411 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2413 pln.Coefficients(a, b, c, d);
2414 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2415 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2416 if(aPlanes->Size() > 0 ) {
2417 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2418 aClipPlane->SetEquation(pln);
2419 aClipPlane->SetOn(Standard_True);
2421 view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2425 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2426 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2427 for( ;anIter.More();anIter.Next() ){
2428 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2429 aClipPlane->SetOn(Standard_False);
2437 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2439 gp_Dir aDir = pln.Axis().Direction();
2440 gp_Pnt aPnt = pln.Location();
2441 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2446 \brief Check if any cutting plane is enabled
2447 \return \c true if at least one cutting plane is enabled
2449 bool OCCViewer_ViewWindow::isCuttingPlane()
2451 Handle(V3d_View) view = myViewPort->getView();
2453 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2454 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2455 for( ;anIter.More();anIter.Next() ) {
2456 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2457 if(aClipPlane->IsOn()) {
2466 \brief Get the visual parameters of the view window.
2467 \return visual parameters of view window
2469 viewAspect OCCViewer_ViewWindow::getViewParams() const
2471 double projX, projY, projZ, twist;
2472 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2473 double aScaleX, aScaleY, aScaleZ;
2475 Handle(V3d_View) aView3d = myViewPort->getView();
2477 aView3d->Proj( projX, projY, projZ );
2478 aView3d->At( atX, atY, atZ );
2479 aView3d->Eye( eyeX, eyeY, eyeZ );
2480 twist = aView3d->Twist();
2482 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2484 bool isShown = myModel->isTrihedronVisible();
2485 double size = myModel->trihedronSize();
2487 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2490 params.scale = aView3d->Scale();
2491 params.projX = projX;
2492 params.projY = projY;
2493 params.projZ = projZ;
2494 params.twist = twist;
2501 params.scaleX = aScaleX;
2502 params.scaleY = aScaleY;
2503 params.scaleZ = aScaleZ;
2504 params.name = aName;
2505 params.isVisible= isShown;
2508 // graduated trihedron
2509 bool anIsVisible = false;
2510 OCCViewer_AxisWidget::AxisData anAxisData[3];
2511 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2513 params.gtIsVisible = anIsVisible;
2514 params.gtDrawNameX = anAxisData[0].DrawName;
2515 params.gtDrawNameY = anAxisData[1].DrawName;
2516 params.gtDrawNameZ = anAxisData[2].DrawName;
2517 params.gtNameX = anAxisData[0].Name;
2518 params.gtNameY = anAxisData[1].Name;
2519 params.gtNameZ = anAxisData[2].Name;
2520 params.gtNameColorRX = anAxisData[0].NameColor.red();
2521 params.gtNameColorGX = anAxisData[0].NameColor.green();
2522 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2523 params.gtNameColorRY = anAxisData[1].NameColor.red();
2524 params.gtNameColorGY = anAxisData[1].NameColor.green();
2525 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2526 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2527 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2528 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2529 params.gtDrawValuesX = anAxisData[0].DrawValues;
2530 params.gtDrawValuesY = anAxisData[1].DrawValues;
2531 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2532 params.gtNbValuesX = anAxisData[0].NbValues;
2533 params.gtNbValuesY = anAxisData[1].NbValues;
2534 params.gtNbValuesZ = anAxisData[2].NbValues;
2535 params.gtOffsetX = anAxisData[0].Offset;
2536 params.gtOffsetY = anAxisData[1].Offset;
2537 params.gtOffsetZ = anAxisData[2].Offset;
2538 params.gtColorRX = anAxisData[0].Color.red();
2539 params.gtColorGX = anAxisData[0].Color.green();
2540 params.gtColorBX = anAxisData[0].Color.blue();
2541 params.gtColorRY = anAxisData[1].Color.red();
2542 params.gtColorGY = anAxisData[1].Color.green();
2543 params.gtColorBY = anAxisData[1].Color.blue();
2544 params.gtColorRZ = anAxisData[2].Color.red();
2545 params.gtColorGZ = anAxisData[2].Color.green();
2546 params.gtColorBZ = anAxisData[2].Color.blue();
2547 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2548 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2549 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2550 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2551 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2552 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2558 \brief Get visual parameters of this view window.
2559 \return visual parameters of view window
2561 QString OCCViewer_ViewWindow::getVisualParameters()
2563 viewAspect params = getViewParams();
2567 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2568 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2569 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2570 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2571 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2572 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2573 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2574 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2575 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2576 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2577 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2578 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2579 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2580 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2581 data << QString( "isVisible=%1" ).arg( params.isVisible );
2582 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2584 ClipPlanesList aPlanes = myModel->getClipPlanes();
2585 for ( int i=0; i < aPlanes.size(); i++ )
2587 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2588 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2589 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2590 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2591 switch ( aPlane.Mode )
2593 case OCCViewer_ClipPlane::Absolute :
2595 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2597 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2599 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2600 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2601 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2605 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2610 case OCCViewer_ClipPlane::Relative :
2612 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2613 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2614 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2619 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2620 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2621 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2622 data << ClippingPlane;
2625 // graduated trihedron
2626 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2627 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2628 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2629 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2630 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2631 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2632 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2633 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2634 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2635 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2636 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2637 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2638 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2639 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2640 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2641 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2642 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2643 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2644 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2645 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2646 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2647 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2648 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2649 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2650 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2651 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2652 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2653 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2654 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2655 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2656 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2657 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2658 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2659 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2660 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2661 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2662 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2663 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2664 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2665 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2667 // ray tracing parameters
2668 Graphic3d_RenderingParams rendParams = this->getViewPort()->getView()->RenderingParams();
2669 if ( rendParams.Method == Graphic3d_RM_RAYTRACING ) {
2670 QString RayTracing = "rayTracing=";
2671 RayTracing += QString( "rtDepth~%1;" ).arg( rendParams.RaytracingDepth );
2672 RayTracing += QString( "rtReflection~%1;" ).arg( rendParams.IsReflectionEnabled );
2673 RayTracing += QString( "rtAntialiasing~%1;" ).arg( rendParams.IsAntialiasingEnabled );
2674 RayTracing += QString( "rtShadow~%1;" ).arg( rendParams.IsShadowEnabled );
2675 RayTracing += QString( "rtTransShadow~%1;" ).arg( rendParams.IsTransparentShadowEnabled );
2679 // environment texture parameters
2680 Handle(Graphic3d_TextureEnv) aTexture = this->getViewPort()->getView()->TextureEnv();
2681 if ( !aTexture.IsNull() ) {
2682 QString EnvTexture = "envTexture=";
2683 if ( aTexture->Name() == Graphic3d_NOT_ENV_UNKNOWN ) {
2684 TCollection_AsciiString aFileName;
2685 aTexture->Path().SystemName( aFileName );
2686 EnvTexture += QString( "etFile~%1;" ).arg( aFileName.ToCString() );
2689 EnvTexture += QString( "etNumber~%1;" ).arg( aTexture->Name() );
2693 // light source parameters
2694 myModel->getViewer3d()->InitDefinedLights();
2695 while ( myModel->getViewer3d()->MoreDefinedLights() )
2697 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2698 if ( aLight->Type() != V3d_AMBIENT ) {
2699 QString LightSource = QString( "lightSource=" );
2700 LightSource += QString( "lightType~%1;" ).arg( aLight->Type() );
2702 if ( aLight->Type() == V3d_DIRECTIONAL )
2703 Handle(V3d_DirectionalLight)::DownCast( aLight )->Direction( aX, aY, aZ );
2704 else if ( aLight->Type() == V3d_POSITIONAL )
2705 Handle(V3d_PositionalLight)::DownCast( aLight )->Position( aX, aY, aZ );
2706 LightSource += QString( "lightX~%1;" ).arg( aX );
2707 LightSource += QString( "lightY~%1;" ).arg( aY );
2708 LightSource += QString( "lightZ~%1;" ).arg( aZ );
2709 LightSource += QString( "lightColorR~%1;" ).arg( aLight->Color().Red() );
2710 LightSource += QString( "lightColorG~%1;" ).arg( aLight->Color().Green() );
2711 LightSource += QString( "lightColorB~%1;" ).arg( aLight->Color().Blue() );
2712 LightSource += QString( "lightHeadlight~%1;" ).arg( aLight->Headlight() );
2713 data << LightSource;
2715 myModel->getViewer3d()->NextDefinedLights();
2718 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2719 data << QString( "background=%1" ).arg( bg );
2721 return data.join("*");
2725 \brief Restore visual parameters of the view window.
2726 \param parameters visual parameters of view window
2728 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2731 ClipPlanesList aClipPlanes;
2732 QStringList data = parameters.split( '*' );
2733 Qtx::BackgroundData bgData;
2734 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2736 foreach( QString param, data ) {
2737 QString paramName = param.section( '=', 0, 0 ).trimmed();
2738 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2739 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2740 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2741 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2742 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2743 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2744 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2745 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2746 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2747 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2748 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2749 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2750 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2751 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2752 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2753 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2754 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2755 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2756 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2757 else if ( paramName.contains( "ClippingPlane" ) )
2759 QStringList ClipPlaneData = paramValue.split( ';' );
2760 OCCViewer_ClipPlane aPlane;
2761 foreach( QString ClipPlaneParam, ClipPlaneData )
2763 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2764 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2765 if ( ClipPlane_paramName == "Mode" )
2767 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2769 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2770 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2771 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2772 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2775 switch ( aPlane.Mode )
2777 case OCCViewer_ClipPlane::Absolute :
2778 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2779 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2780 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2781 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2782 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2785 case OCCViewer_ClipPlane::Relative :
2786 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2787 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2788 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2793 aClipPlanes.push_back(aPlane);
2795 // graduated trihedron
2796 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2797 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2798 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2799 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2800 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2801 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2802 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2803 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2804 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2805 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2806 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2807 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2808 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2809 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2810 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2811 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2812 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2813 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2814 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2815 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2816 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2817 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2818 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2819 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2820 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2821 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2822 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2823 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2824 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2825 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2826 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2827 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2828 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2829 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2830 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2831 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2832 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2833 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2834 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2835 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2836 else if ( paramName == "rayTracing" )
2838 Graphic3d_RenderingParams& rendParams = this->getViewPort()->getView()->ChangeRenderingParams();
2839 rendParams.Method = Graphic3d_RM_RAYTRACING;
2840 QStringList rtData = paramValue.split( ';' );
2841 foreach( QString rtParam, rtData )
2843 QString rt_paramName = rtParam.section( '~', 0, 0 ).trimmed();
2844 QString rt_paramValue = rtParam.section( '~', 1, 1 ).trimmed();
2845 if ( rt_paramName == "rtDepth" ) rendParams.RaytracingDepth = rt_paramValue.toInt();
2846 else if ( rt_paramName == "rtReflection" ) rendParams.IsReflectionEnabled = rt_paramValue.toInt();
2847 else if ( rt_paramName == "rtAntialiasing" ) rendParams.IsAntialiasingEnabled = rt_paramValue.toInt();
2848 else if ( rt_paramName == "rtShadow" ) rendParams.IsShadowEnabled = rt_paramValue.toInt();
2849 else if ( rt_paramName == "rtTransShadow" ) rendParams.IsTransparentShadowEnabled = rt_paramValue.toInt();
2852 else if ( paramName == "envTexture" )
2854 Handle(Graphic3d_TextureEnv) aTexture;
2855 QStringList etData = paramValue.split( ';' );
2856 foreach( QString etParam, etData )
2858 QString et_paramName = etParam.section( '~', 0, 0 ).trimmed();
2859 QString et_paramValue = etParam.section( '~', 1, 1 ).trimmed();
2860 if ( et_paramName == "etNumber" )
2861 aTexture = new Graphic3d_TextureEnv( Graphic3d_NameOfTextureEnv( et_paramValue.toInt() ) );
2862 else if ( et_paramName == "etFile" )
2863 aTexture = new Graphic3d_TextureEnv( TCollection_AsciiString( et_paramValue.toStdString().c_str() ) );
2864 Handle(V3d_View) aView = this->getViewPort()->getView();
2865 aView->SetTextureEnv( aTexture );
2868 else if ( paramName == "lightSource" )
2870 myModel->getViewer3d()->InitDefinedLights();
2871 while ( myModel->getViewer3d()->MoreDefinedLights() )
2873 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2874 if( aLight->Type() != V3d_AMBIENT ) {
2875 myModel->getViewer3d()->DelLight( aLight );
2876 myModel->getViewer3d()->InitDefinedLights();
2878 myModel->getViewer3d()->NextDefinedLights();
2883 V3d_TypeOfLight aType;
2885 QStringList lsData = paramValue.split( ';' );
2886 foreach( QString lsParam, lsData )
2888 QString ls_paramName = lsParam.section( '~', 0, 0 ).trimmed();
2889 QString ls_paramValue = lsParam.section( '~', 1, 1 ).trimmed();
2890 if ( ls_paramName == "lightType" ) aType = V3d_TypeOfLight( ls_paramValue.toInt() );
2891 else if ( ls_paramName == "lightX" ) aX = ls_paramValue.toDouble();
2892 else if ( ls_paramName == "lightY" ) aY = ls_paramValue.toDouble();
2893 else if ( ls_paramName == "lightZ" ) aZ = ls_paramValue.toDouble();
2894 else if ( ls_paramName == "lightColorR" ) cR = ls_paramValue.toDouble();
2895 else if ( ls_paramName == "lightColorG" ) cG = ls_paramValue.toDouble();
2896 else if ( ls_paramName == "lightColorB" ) cB = ls_paramValue.toDouble();
2897 else if ( ls_paramName == "lightHeadlight" ) isHeadlight = ls_paramValue.toInt();
2899 Quantity_Color aColor = Quantity_Color( cR, cG, cB, Quantity_TOC_RGB );
2900 if( aType == V3d_DIRECTIONAL ) {
2901 Handle(V3d_DirectionalLight) aLight = new V3d_DirectionalLight( myModel->getViewer3d() );
2902 aLight->SetDirection( aX, aY, aZ );
2903 aLight->SetColor( aColor );
2904 aLight->SetHeadlight( isHeadlight );
2905 myModel->getViewer3d()->SetLightOn( aLight );
2907 else if( aType == V3d_POSITIONAL ) {
2908 Handle(V3d_PositionalLight) aLight = new V3d_PositionalLight( myModel->getViewer3d(), aX, aY, aZ, aColor.Name() );
2909 aLight->SetHeadlight( isHeadlight );
2910 myModel->getViewer3d()->SetLightOn( aLight );
2913 else if ( paramName == "background" ) {
2914 QString bg = paramValue.replace( "$", "=" );
2915 bgData = Qtx::stringToBackground( bg );
2919 else // old format - "1.000e+00*0.000e+00..."
2922 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2923 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2924 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2925 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2926 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2927 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2928 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
2929 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2930 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2931 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
2932 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2933 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2934 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2935 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
2936 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
2937 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
2938 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
2939 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
2941 performRestoring( params );
2942 setBackground( bgData );
2943 myModel->setClipPlanes(aClipPlanes);
2947 \brief Handle show event.
2949 Emits Show() signal.
2951 \param theEvent show event
2953 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2955 emit Show( theEvent );
2959 \brief Handle hide event.
2961 Emits Hide() signal.
2963 \param theEvent hide event
2965 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
2967 emit Hide( theEvent );
2972 Save old cursor. [ protected ]
2974 void OCCViewer_ViewWindow::saveCursor()
2976 QCursor* aCursor = NULL;
2978 aCursor = myViewPort->getDefaultCursor();
2979 myCursor = ( aCursor ? *aCursor : cursor() );
2984 Creates default sketcher. [ virtual protected ]
2986 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
2989 return new OCCViewer_RectSketcher( this, type );
2990 if ( type == Polygon )
2991 return new OCCViewer_PolygonSketcher( this, type );
2995 void OCCViewer_ViewWindow::initSketchers()
2997 if ( mySketchers.isEmpty() )
2999 mySketchers.append( createSketcher( Rect ) );
3000 mySketchers.append( createSketcher( Polygon ) );
3004 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
3006 OCCViewer_ViewSketcher* sketcher = 0;
3007 QList<OCCViewer_ViewSketcher*>::Iterator it;
3008 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
3010 OCCViewer_ViewSketcher* sk = (*it);
3011 if ( sk->type() == typ )
3018 Handles requests for sketching in the active view. [ virtual public ]
3020 void OCCViewer_ViewWindow::activateSketching( int type )
3022 OCCViewer_ViewPort3d* vp = getViewPort();
3026 if ( !vp->isSketchingEnabled() )
3029 /* Finish current sketching */
3030 if ( type == NoSketching )
3034 onSketchingFinished();
3035 mypSketcher->deactivate();
3039 /* Activate new sketching */
3042 activateSketching( NoSketching ); /* concurrency not suported */
3043 mypSketcher = getSketcher( type );
3046 mypSketcher->activate();
3047 onSketchingStarted();
3053 Unhilights detected entities. [ virtual protected ]
3055 void OCCViewer_ViewWindow::onSketchingStarted()
3060 Selection by rectangle or polygon. [ virtual protected ]
3062 void OCCViewer_ViewWindow::onSketchingFinished()
3064 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
3065 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
3067 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
3068 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
3069 switch( mypSketcher->type() )
3073 QRect* aRect = (QRect*)mypSketcher->data();
3076 int aLeft = aRect->left();
3077 int aRight = aRect->right();
3078 int aTop = aRect->top();
3079 int aBottom = aRect->bottom();
3083 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
3085 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
3091 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
3094 int size = aPolygon->size();
3095 TColgp_Array1OfPnt2d anArray( 1, size );
3097 QPolygon::Iterator it = aPolygon->begin();
3098 QPolygon::Iterator itEnd = aPolygon->end();
3099 for( int index = 1; it != itEnd; ++it, index++ )
3101 QPoint aPoint = *it;
3102 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
3106 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
3108 ic->Select( anArray, getViewPort()->getView(), Standard_False );
3116 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
3117 aViewMgr->getOCCViewer()->performSelectionChanged();
3121 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
3126 bool OCCViewer_ViewWindow::transformRequested() const
3128 return ( myOperation != NOTHING );
3131 bool OCCViewer_ViewWindow::transformInProcess() const
3133 return myEventStarted;
3136 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
3138 myEventStarted = bOn;
3142 Set enabled state of transformation (rotate, zoom, etc)
3144 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
3146 if ( id != NOTHING ) myStatus.insert( id, on );
3150 \return enabled state of transformation (rotate, zoom, etc)
3152 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
3154 return myStatus.contains( id ) ? myStatus[ id ] : true;
3157 void OCCViewer_ViewWindow::onMaximizedView()
3159 setMaximized(!isMaximized());
3162 void OCCViewer_ViewWindow::returnTo3dView()
3164 setReturnedTo3dView( true );
3167 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
3169 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
3170 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
3171 if ( !isVisible3dView )
3172 toolMgr()->show( ReturnTo3dViewId );
3174 toolMgr()->hide( ReturnTo3dViewId );
3175 if ( isVisible3dView ) emit returnedTo3d( );
3179 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
3181 QAction* anAction = toolMgr()->action( MaximizedId );
3182 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
3183 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
3185 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
3186 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
3187 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
3188 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
3189 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
3191 emit maximized( this, true );
3195 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
3196 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
3197 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
3198 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
3199 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
3201 emit maximized( this, false );
3206 bool OCCViewer_ViewWindow::isMaximized() const
3208 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
3211 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
3213 IsSketcherStyle = enable;
3216 bool OCCViewer_ViewWindow::isSketcherStyle() const
3218 return IsSketcherStyle;
3222 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
3227 int OCCViewer_ViewWindow::projectionType() const
3229 int mode = Orthographic;
3230 Handle(V3d_View) aView3d = myViewPort->getView();
3231 if ( !aView3d.IsNull() ) {
3232 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3233 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Perspective)
3235 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Orthographic)
3236 mode = Orthographic;
3237 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
3243 void OCCViewer_ViewWindow::setStereoType( int type )
3245 Handle(V3d_View) aView3d = myViewPort->getView();
3246 if ( !aView3d.IsNull() ) {
3247 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3248 aParams->StereoMode = (Graphic3d_StereoMode)type;
3252 int OCCViewer_ViewWindow::stereoType() const
3254 int type = QuadBuffer;
3255 Handle(V3d_View) aView3d = myViewPort->getView();
3256 if ( !aView3d.IsNull() ) {
3257 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3258 type = (OCCViewer_ViewWindow::StereoType)aParams->StereoMode;
3263 void OCCViewer_ViewWindow::setAnaglyphFilter( int type )
3265 Handle(V3d_View) aView3d = myViewPort->getView();
3266 if ( !aView3d.IsNull() ) {
3267 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3268 if (type == RedCyan)
3269 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
3270 if (type == YellowBlue)
3271 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
3272 if (type == GreenMagenta)
3273 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
3277 int OCCViewer_ViewWindow::anaglyphFilter() const
3280 Handle(V3d_View) aView3d = myViewPort->getView();
3281 if ( !aView3d.IsNull() ) {
3282 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3283 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized)
3285 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized)
3287 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple)
3288 type = GreenMagenta;
3293 void OCCViewer_ViewWindow::setStereographicFocus( int type, double value )
3295 Handle(V3d_View) aView3d = myViewPort->getView();
3296 if ( !aView3d.IsNull() ) {
3297 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3298 aCamera->SetZFocus( (Graphic3d_Camera::FocusType) type, value );
3302 int OCCViewer_ViewWindow::stereographicFocusType() const
3304 int type = Relative;
3305 Handle(V3d_View) aView3d = myViewPort->getView();
3306 if ( !aView3d.IsNull() ) {
3307 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3308 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->ZFocusType();
3313 double OCCViewer_ViewWindow::stereographicFocusValue() const
3316 Handle(V3d_View) aView3d = myViewPort->getView();
3317 if ( !aView3d.IsNull() ) {
3318 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3319 value = aCamera->ZFocus();
3324 void OCCViewer_ViewWindow::setInterocularDistance( int type, double value )
3326 Handle(V3d_View) aView3d = myViewPort->getView();
3327 if ( !aView3d.IsNull() ) {
3328 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3329 aCamera->SetIOD( (Graphic3d_Camera::IODType) type, value );
3333 int OCCViewer_ViewWindow::interocularDistanceType() const
3335 int type = Relative;
3336 Handle(V3d_View) aView3d = myViewPort->getView();
3337 if ( !aView3d.IsNull() ) {
3338 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3339 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->GetIODType();
3344 double OCCViewer_ViewWindow::interocularDistanceValue() const
3346 double value = 0.05;
3347 Handle(V3d_View) aView3d = myViewPort->getView();
3348 if ( !aView3d.IsNull() ) {
3349 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3350 value = aCamera->IOD();
3355 void OCCViewer_ViewWindow::setReverseStereo( bool reverse )
3357 Handle(V3d_View) aView3d = myViewPort->getView();
3358 if ( !aView3d.IsNull() ) {
3359 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3360 aParams->ToReverseStereo = reverse;
3364 bool OCCViewer_ViewWindow::isReverseStereo() const
3366 int reverse = false;
3367 Handle(V3d_View) aView3d = myViewPort->getView();
3368 if ( !aView3d.IsNull() ) {
3369 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3370 reverse = aParams->ToReverseStereo;
3375 void OCCViewer_ViewWindow::setVSync( bool enable )
3377 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3378 if ( !anIntCont.IsNull() ) {
3379 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3380 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3381 aCaps->swapInterval = enable;
3385 bool OCCViewer_ViewWindow::isVSync() const
3388 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3389 if ( !anIntCont.IsNull() ) {
3390 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3391 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3392 enable = aCaps->swapInterval;
3397 void OCCViewer_ViewWindow::setQuadBufferSupport( bool enable )
3399 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3400 if ( !anIntCont.IsNull() ) {
3401 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3402 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3403 aCaps->contextStereo = enable;
3407 bool OCCViewer_ViewWindow::isQuadBufferSupport() const
3410 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3411 if ( !anIntCont.IsNull() ) {
3412 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3413 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3414 enable = aCaps->contextStereo;
3419 bool OCCViewer_ViewWindow::isOpenGlStereoSupport() const
3421 GLboolean support[1];
3422 glGetBooleanv (GL_STEREO, support);
3429 QColor OCCViewer_ViewWindow::backgroundColor() const
3431 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
3435 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
3437 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
3440 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
3442 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
3445 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
3447 if ( myViewPort ) myViewPort->setBackground( theBackground );
3450 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
3452 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
3458 void OCCViewer_ViewWindow::clearViewAspects()
3460 myViewAspects.clear();
3464 \return const reference to list of view aspects
3466 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
3468 return myViewAspects;
3472 Appends new view aspect
3473 \param aParams - new view aspects
3475 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
3477 myViewAspects.append( aParams );
3481 Replaces old view aspects by new ones
3482 \param aViewList - list of new view aspects
3484 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
3486 myViewAspects = aViewList;
3490 Get camera properties for the OCC view window.
3491 \return shared pointer on camera properties.
3493 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
3495 SUIT_CameraProperties aProps;
3497 Handle(V3d_View) aSourceView = getViewPort()->getView();
3498 if ( aSourceView.IsNull() )
3501 if ( get2dMode() == No2dMode ) {
3502 aProps.setDimension( SUIT_CameraProperties::Dim3D );
3505 aProps.setDimension( SUIT_CameraProperties::Dim2D );
3506 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
3509 // read common properites of the view
3510 Standard_Real anUp[3];
3511 Standard_Real anAt[3];
3512 Standard_Real anEye[3];
3513 Standard_Real aProj[3];
3514 Standard_Real anAxialScale[3];
3516 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
3517 aSourceView->At( anAt[0], anAt[1], anAt[2] );
3518 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
3519 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3521 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3522 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
3524 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
3526 // store camera properties "as is": it is up to synchronized
3527 // view classes to provide necessary property conversion.
3528 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
3529 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
3531 if ( aSourceView->Camera()->IsOrthographic() )
3533 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
3534 aProps.setViewAngle( 0.0 );
3538 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
3539 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
3541 aProps.setMappingScale( aSourceView->Camera()->Scale() );
3548 This implementation synchronizes OCC view's camera propreties.
3550 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
3552 bool blocked = blockSignals( true );
3554 SUIT_CameraProperties aProps = theView->cameraProperties();
3555 if ( !cameraProperties().isCompatible( aProps ) ) {
3556 // other view, this one is being currently synchronized to, seems has become incompatible
3557 // we have to break synchronization
3562 Handle(V3d_View) aDestView = getViewPort()->getView();
3564 aDestView->SetImmediateUpdate( Standard_False );
3567 double aPosition[3];
3568 double aFocalPoint[3];
3569 double anAxialScale[3];
3571 // get common properties
3572 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3573 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
3574 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3575 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3577 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3578 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
3579 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3580 aDestView->Camera()->SetScale( aProps.getMappingScale() );
3582 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3583 aDestView->SetImmediateUpdate( Standard_True );
3584 aDestView->Redraw();
3586 blockSignals( blocked );
3590 \brief Indicates whether preselection is enabled
3591 \return true if preselection is enabled
3593 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
3595 return myPreselectionEnabled;
3599 \brief Enables/disables preselection
3600 \param theIsToEnable if true - preselection will be enabled
3602 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
3604 onSwitchPreselection( theIsToEnable );
3608 \brief Indicates whether selection is enabled
3609 \return true if selection is enabled
3611 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3613 return mySelectionEnabled;
3617 \brief Enables/disables selection
3618 \param theIsToEnable if true - selection will be enabled
3620 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3622 onSwitchSelection( theIsToEnable );
3627 \brief called if clipping operation is activated / deactivated.
3629 Enables/disables clipping plane displaying.
3631 \parma on action state
3633 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3635 if(!myModel) return;
3636 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3639 if (!aClippingDlg) {
3640 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3641 myModel->setClippingDlg(aClippingDlg);
3643 if (!aClippingDlg->isVisible())
3644 aClippingDlg->show();
3646 if ( aClippingDlg ) {
3647 aClippingDlg->close();
3648 myModel->setClippingDlg(0);
3652 SUIT_ViewManager* mgr = getViewManager();
3654 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3655 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3656 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3657 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3659 QAction* a = toolMgr()->action( ClippingId );
3661 if(theIsOn != a->isChecked()){
3662 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3663 a->setChecked(theIsOn);
3664 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3671 void OCCViewer_ViewWindow::onRayTracing()
3673 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_RayTracingDlg::getName() ) ) {
3674 QDialog* aDlg = new OCCViewer_RayTracingDlg( this );
3680 void OCCViewer_ViewWindow::onEnvTexture()
3682 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_EnvTextureDlg::getName() ) ) {
3683 QDialog* aDlg = new OCCViewer_EnvTextureDlg( this );
3689 void OCCViewer_ViewWindow::onLightSource()
3691 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_LightSourceDlg::getName() ) ) {
3692 QDialog* aDlg = new OCCViewer_LightSourceDlg( this, myModel );
3698 bool OCCViewer_ViewWindow::isActionVisible( ActionId theId ) const
3700 QAction* a = toolMgr()->action( theId );
3701 return a && a->isVisible();
3704 void OCCViewer_ViewWindow::setActionVisible( ActionId theId, bool isVisible )
3706 QAction* a = toolMgr()->action( theId );
3708 a->setVisible( isVisible );
3711 void OCCViewer_ViewWindow::projAndPanToGravity(V3d_TypeOfOrientation CamOri)
3713 const bool USE_XY = true;
3715 Handle(V3d_View) aView3d = myViewPort->getView();
3716 if (aView3d.IsNull())
3720 double X = 0, Y = 0, Z = 0;
3723 const double EPS = 1E-6;
3724 int xp = myViewPort->width()/2, yp = myViewPort->height()/2, xp1, yp1;
3725 aView3d->Convert( xp, yp, X, Y, Z );
3727 gp_Dir d = aView3d->Camera()->Direction();
3728 if( fabs( d.Z() ) > EPS )
3730 double t = -Z/d.Z();
3737 // It is really necessary to compute gravity center even if it is not used in part of code below.
3738 // Without this calculation the SetProj() method and other methods are not correct.
3740 IsGr = computeGravityCenter(X2, Y2, Z2);
3742 IsGr = OCCViewer_Utilities::computeSceneBBCenter(aView3d, X2, Y2, Z2);
3744 aView3d->SetProj(CamOri);
3747 //aView3d->Update();
3748 Handle(Graphic3d_Camera) Cam = aView3d->Camera();
3750 gp_Vec dir (Cam->Direction());
3751 gp_Pnt eye = Cam->Eye();
3753 Standard_Real D = dir.Dot(V1);
3754 gp_Pnt ppdir = eye.Translated(D*dir);
3755 gp_Vec V2(ppdir, gp);
3756 gp_XYZ trEye = eye.XYZ() + V2.XYZ();
3758 double xat, yat, zat;
3759 aView3d->At(xat, yat, zat);
3760 gp_Pnt At(xat, yat, zat);
3761 gp_XYZ trAt = At.XYZ() + V2.XYZ();
3762 aView3d->SetEye(trEye.X(), trEye.Y(), trEye.Z());
3763 aView3d->SetAt(trAt.X(), trAt.Y(), trAt.Z());
3768 bool OCCViewer_ViewWindow::isAutomaticZoom() const
3770 return myAutomaticZoom;
3773 void OCCViewer_ViewWindow::setAutomaticZoom(const bool isOn)
3775 myAutomaticZoom = isOn;