1 // Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : OCCViewer_ViewWindow.cxx
26 #include "OCCViewer_ViewWindow.h"
27 #include "OCCViewer_ViewFrame.h"
28 #include "OCCViewer_ViewModel.h"
29 #include "OCCViewer_ViewPort3d.h"
30 #include "OCCViewer_ViewManager.h"
31 #include "OCCViewer_ViewSketcher.h"
32 #include "OCCViewer_CreateRestoreViewDlg.h"
33 #include "OCCViewer_ClipPlane.h"
34 #include "OCCViewer_SetRotationPointDlg.h"
35 #include "OCCViewer_AxialScaleDlg.h"
36 #include "OCCViewer_CubeAxesDlg.h"
37 #include "OCCViewer_ClippingDlg.h"
38 #include "OCCViewer_RayTracingDlg.h"
39 #include "OCCViewer_EnvTextureDlg.h"
40 #include "OCCViewer_LightSourceDlg.h"
41 #include "OCCViewer_Utilities.h"
43 #include <SUIT_Desktop.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_ViewManager.h>
46 #include <SUIT_Tools.h>
47 #include <SUIT_ResourceMgr.h>
48 #include <SUIT_MessageBox.h>
49 #include <SUIT_Application.h>
51 #include <QtxActionToolMgr.h>
52 #include <QtxMultiAction.h>
53 #include <QtxRubberBand.h>
59 #include <QMouseEvent>
60 #include <QApplication>
61 #include <QActionGroup>
64 #include <AIS_ListOfInteractive.hxx>
65 #include <AIS_ListIteratorOfListOfInteractive.hxx>
66 #include <AIS_Shape.hxx>
68 #include <BRep_Tool.hxx>
69 #include <BRepBndLib.hxx>
70 #include <BRepGProp.hxx>
71 #include <GProp_GProps.hxx>
74 #include <Graphic3d_SequenceOfHClipPlane.hxx>
75 #include <Graphic3d_ClipPlane.hxx>
76 #include <OpenGl_GraphicDriver.hxx>
77 #include <OpenGLUtils_FrameBuffer.h>
78 #include <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)
130 // Enable ray tracing features
131 #define ENABLE_RAY_TRACING
133 const char* imageZoomCursor[] = {
138 "................................",
139 "................................",
140 ".#######........................",
141 "..aaaaaaa.......................",
142 "................................",
143 ".............#####..............",
144 "...........##.aaaa##............",
145 "..........#.aa.....a#...........",
146 ".........#.a.........#..........",
147 ".........#a..........#a.........",
148 "........#.a...........#.........",
149 "........#a............#a........",
150 "........#a............#a........",
151 "........#a............#a........",
152 "........#a............#a........",
153 ".........#...........#.a........",
154 ".........#a..........#a.........",
155 ".........##.........#.a.........",
156 "........#####.....##.a..........",
157 ".......###aaa#####.aa...........",
158 "......###aa...aaaaa.......#.....",
159 ".....###aa................#a....",
160 "....###aa.................#a....",
161 "...###aa...............#######..",
162 "....#aa.................aa#aaaa.",
163 ".....a....................#a....",
164 "..........................#a....",
165 "...........................a....",
166 "................................",
167 "................................",
168 "................................",
169 "................................"};
171 const char* imageRotateCursor[] = {
176 "................................",
177 "................................",
178 "................................",
179 "................................",
180 "........#.......................",
181 ".......#.a......................",
182 "......#######...................",
183 ".......#aaaaa#####..............",
184 "........#..##.a#aa##........##..",
185 ".........a#.aa..#..a#.....##.aa.",
186 ".........#.a.....#...#..##.aa...",
187 ".........#a.......#..###.aa.....",
188 "........#.a.......#a..#aa.......",
189 "........#a.........#..#a........",
190 "........#a.........#a.#a........",
191 "........#a.........#a.#a........",
192 "........#a.........#a.#a........",
193 ".........#.........#a#.a........",
194 "........##a........#a#a.........",
195 "......##.a#.......#.#.a.........",
196 "....##.aa..##.....##.a..........",
197 "..##.aa.....a#####.aa...........",
198 "...aa.........aaa#a.............",
199 "................#.a.............",
200 "...............#.a..............",
201 "..............#.a...............",
202 "...............a................",
203 "................................",
204 "................................",
205 "................................",
206 "................................",
207 "................................"};
209 const char* imageCrossCursor[] = {
214 "................................",
215 "................................",
216 "................................",
217 "................................",
218 "................................",
219 "................................",
220 "................................",
221 "...............#................",
222 "...............#a...............",
223 "...............#a...............",
224 "...............#a...............",
225 "...............#a...............",
226 "...............#a...............",
227 "...............#a...............",
228 "...............#a...............",
229 ".......#################........",
230 "........aaaaaaa#aaaaaaaaa.......",
231 "...............#a...............",
232 "...............#a...............",
233 "...............#a...............",
234 "...............#a...............",
235 "...............#a...............",
236 "...............#a...............",
237 "...............#a...............",
238 "................a...............",
239 "................................",
240 "................................",
241 "................................",
242 "................................",
243 "................................",
244 "................................",
245 "................................"};
250 \param theDesktop main window of application
251 \param theModel OCC 3D viewer
253 OCCViewer_ViewWindow::OCCViewer_ViewWindow( SUIT_Desktop* theDesktop,
254 OCCViewer_Viewer* theModel )
255 : SUIT_ViewWindow( theDesktop )
259 myEnableDrawMode = false;
260 myDrawRectEnabled = true;
262 updateEnabledDrawMode();
264 mySetRotationPointDlg = 0;
267 IsSketcherStyle = false;
274 myInteractionStyle = SUIT_ViewModel::STANDARD;
275 myPreselectionEnabled = true;
276 mySelectionEnabled = true;
278 myCursorIsHand = false;
279 myPanningByBtn = false;
280 myAutomaticZoom = true;
288 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
291 qDeleteAll( mySketchers );
295 \brief Internal initialization.
297 void OCCViewer_ViewWindow::initLayout()
299 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
300 myViewPort->installEventFilter(this);
301 setCentralWidget(myViewPort);
302 myOperation = NOVIEWOP;
304 myCurrPointType = BBCENTER;
305 myPrevPointType = BBCENTER;
306 mySelectedPoint = gp_Pnt(0.,0.,0.);
307 myRotationPointSelection = false;
309 setTransformRequested ( NOVIEWOP );
310 setTransformInProcess ( false );
327 // Graduated axes dialog
328 QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
329 myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
330 myCubeAxesDlg->initialize();
332 connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
335 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
337 return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
341 \brief Detect viewer operation according the the mouse button pressed
342 and key modifiers used.
343 \param theEvent mouse event
344 \return type of the operation
346 OCCViewer_ViewWindow::OperationType
347 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
349 OperationType aOp = NOVIEWOP;
350 SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
351 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
352 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
354 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
355 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
357 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
358 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
359 (my2dMode == No2dMode))
366 \brief Customize event handling
367 \param watched event receiver object
369 \return \c true if the event processing should be stopped
371 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
373 if ( watched == myViewPort ) {
374 int aType = e->type();
376 case QEvent::MouseButtonPress:
377 vpMousePressEvent((QMouseEvent*) e);
380 case QEvent::MouseButtonRelease:
381 vpMouseReleaseEvent((QMouseEvent*) e);
384 case QEvent::MouseMove:
385 vpMouseMoveEvent((QMouseEvent*) e);
388 case QEvent::MouseButtonDblClick:
389 emit mouseDoubleClicked(this, (QMouseEvent*)e);
394 QWheelEvent* aEvent = (QWheelEvent*) e;
396 if ( aEvent->modifiers().testFlag(Qt::ControlModifier) ) {
397 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
398 if ( isPreselectionEnabled()
399 #if OCC_VERSION_LARGE <= 0x07030000
400 && myModel->useLocalSelection()
403 if ( aEvent->delta() > 0 ) {
404 ic->HilightNextDetected( myViewPort->getView() );
406 ic->HilightPreviousDetected( myViewPort->getView() );
411 emit vpTransformationStarted ( ZOOMVIEW );
412 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
413 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
416 int x1 = (int)( aEvent->x() + width()*delta/100 );
417 int y1 = (int)( aEvent->y() + height()*delta/100 );
418 myViewPort->zoom( x, y, x1, y1 );
419 emit vpTransformationFinished ( ZOOMVIEW );
424 case QEvent::ContextMenu:
426 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
427 if ( aEvent->reason() != QContextMenuEvent::Mouse )
428 emit contextMenuRequested( aEvent );
432 case QEvent::KeyPress:
433 emit keyPressed(this, (QKeyEvent*) e);
436 case QEvent::KeyRelease:
437 emit keyReleased(this, (QKeyEvent*) e);
444 return SUIT_ViewWindow::eventFilter(watched, e);
448 \brief Enable / disable draw rect (rubber band) mode
450 bool OCCViewer_ViewWindow::enableDrawMode( bool on )
452 bool prev = myDrawRectEnabled;
453 myDrawRectEnabled = on;
454 updateEnabledDrawMode();
459 \brief Update state of enable draw mode state.
461 void OCCViewer_ViewWindow::updateEnabledDrawMode()
463 myEnableDrawMode = myDrawRectEnabled;
465 myEnableDrawMode = myEnableDrawMode && myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
469 \brief Handle mouse press event
470 \param theEvent mouse event
472 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
474 myStartX = theEvent->x();
475 myStartY = theEvent->y();
476 int anInteractionStyle = interactionStyle();
478 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
479 // which are assigned for pan and rotate - these operations are activated immediately after pressing
480 // of the first button, so it is necessary to switch to zoom when the second button is pressed
481 bool aSwitchToZoom = false;
482 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
483 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
484 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
487 switch ( myOperation ) {
489 if ( theEvent->button() == Qt::LeftButton )
490 emit vpTransformationStarted ( WINDOWFIT );
494 if ( theEvent->button() == Qt::LeftButton )
495 emit vpTransformationStarted ( PANGLOBAL );
499 if ( theEvent->button() == Qt::LeftButton ) {
500 myViewPort->startZoomAtPoint( myStartX, myStartY );
501 emit vpTransformationStarted ( ZOOMVIEW );
506 if ( aSwitchToZoom ) {
507 myViewPort->startZoomAtPoint( myStartX, myStartY );
510 else if ( theEvent->button() == Qt::LeftButton )
511 emit vpTransformationStarted ( PANVIEW );
515 if ( aSwitchToZoom ) {
516 myViewPort->startZoomAtPoint( myStartX, myStartY );
519 else if ( theEvent->button() == Qt::LeftButton ) {
520 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
521 emit vpTransformationStarted ( ROTATE );
526 /* Try to activate a transformation */
527 OperationType aState;
528 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
529 aState = getButtonState(theEvent, anInteractionStyle);
531 aState = OCCViewer_ViewWindow::NOVIEWOP;
536 myViewPort->startZoomAtPoint( myStartX, myStartY );
544 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
547 if ( myRotationPointSelection )
549 if ( theEvent->button() == Qt::LeftButton )
551 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
552 ic->Select( Standard_True );
553 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
555 TopoDS_Shape aShape = ic->SelectedShape();
556 GProp_GProps aSystem;
558 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
560 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
562 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE )
564 BRepGProp::LinearProperties( aShape, aSystem );
565 aPnt = aSystem.CentreOfMass();
567 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE )
569 BRepGProp::SurfaceProperties( aShape, aSystem );
570 aPnt = aSystem.CentreOfMass();
572 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID )
574 BRepGProp::VolumeProperties( aShape, aSystem );
575 aPnt = aSystem.CentreOfMass();
579 myCurrPointType = myPrevPointType;
583 if ( mySetRotationPointDlg )
585 myRotationPointSelection = false;
586 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
589 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
590 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
591 #if OCC_VERSION_LARGE <= 0x07030000
592 ic->CloseAllContexts( Standard_True );
597 myOperation = NOVIEWOP;
598 myViewPort->setCursor( myCursor );
599 myCursorIsHand = false;
600 myRotationPointSelection = false;
604 emit mousePressed(this, theEvent);
607 /* notify that we start a transformation */
608 if ( transformRequested() )
609 emit vpTransformationStarted ( myOperation );
611 if ( transformRequested() )
612 setTransformInProcess( true );
614 /* we may need it for sketching... */
615 if ( l_mbPressEvent )
616 delete l_mbPressEvent;
617 l_mbPressEvent = new QMouseEvent( *theEvent );
622 \brief Start zooming operation.
624 Sets the corresponding cursor for the widget.
626 void OCCViewer_ViewWindow::activateZoom()
628 if ( !transformRequested() && !myCursorIsHand )
629 saveCursor(); /* save old cursor */
631 if ( myOperation != ZOOMVIEW ) {
632 QPixmap zoomPixmap (imageZoomCursor);
633 QCursor zoomCursor (zoomPixmap);
634 if( setTransformRequested ( ZOOMVIEW ) )
635 myViewPort->setCursor( zoomCursor );
640 void OCCViewer_ViewWindow::onPanning()
642 OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( getViewManager() );
643 bool isChained = aMgr->isChainedOperations();
644 bool isReset = ( myPanningByBtn && isChained );
651 myPanningByBtn = true;
657 \brief Start panning operation.
659 Sets the corresponding cursor for the widget.
661 void OCCViewer_ViewWindow::activatePanning()
663 if ( !transformRequested() && !myCursorIsHand )
664 saveCursor(); // save old cursor
666 if ( myOperation != PANVIEW ) {
667 QCursor panCursor (Qt::SizeAllCursor);
668 if( setTransformRequested ( PANVIEW ) )
669 myViewPort->setCursor( panCursor );
674 \brief Start rotation operation
676 Sets the corresponding cursor for the widget.
678 void OCCViewer_ViewWindow::activateRotation()
680 if ( !transformRequested() && !myCursorIsHand )
681 saveCursor(); // save old cursor
683 if ( myOperation != ROTATE ) {
684 QPixmap rotatePixmap (imageRotateCursor);
685 QCursor rotCursor (rotatePixmap);
686 if( setTransformRequested ( ROTATE ) )
687 myViewPort->setCursor( rotCursor );
692 \brief Compute the gravity center.
693 \param theX used to return X coordinate of the gravity center
694 \param theY used to return Y coordinate of the gravity center
695 \param theZ used to return Z coordinate of the gravity center
696 \return \c true if the gravity center is computed
698 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
700 Handle(V3d_View) aView3d = myViewPort->getView();
702 // Project boundaries points and add to avergae gravity
703 // the ones which lie within the screen limits
704 Standard_Real aScreenLimits[4] = { 0.0, 0.0, 0.0, 0.0 };
706 // NDC space screen limits
707 aScreenLimits[0] = -1.0;
708 aScreenLimits[1] = 1.0;
709 aScreenLimits[2] = -1.0;
710 aScreenLimits[3] = 1.0;
712 Standard_Integer aPointsNb = 0;
714 Standard_Real aXmin = 0.0;
715 Standard_Real aYmin = 0.0;
716 Standard_Real aZmin = 0.0;
717 Standard_Real aXmax = 0.0;
718 Standard_Real aYmax = 0.0;
719 Standard_Real aZmax = 0.0;
721 Graphic3d_MapOfStructure aSetOfStructures;
722 aView3d->View()->DisplayedStructures( aSetOfStructures );
723 Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures );
725 for( ; aStructureIt.More(); aStructureIt.Next() ) {
726 const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key();
727 if ( aStructure->IsEmpty() || !aStructure->IsVisible() || aStructure->CStructure()->IsForHighlight )
730 Bnd_Box aBox1 = aStructure->MinMaxValues();
731 const Graphic3d_BndBox3d& aBox = aStructure->CStructure()->BoundingBox();
734 aXmin = /*aBox.IsVoid() ? RealFirst() :*/ aBox.CornerMin().x();
735 aYmin = /*aBox.IsVoid() ? RealFirst() : */aBox.CornerMin().y();
736 aZmin = /*aBox.IsVoid() ? RealFirst() : */aBox.CornerMin().z();
737 aXmax = /*aBox.IsVoid() ? RealLast() : */aBox.CornerMax().x();
738 aYmax = /*aBox.IsVoid() ? RealLast() : */aBox.CornerMax().y();
739 aZmax = /*aBox.IsVoid() ? RealLast() : */aBox.CornerMax().z();
741 // Infinite structures are skipped
742 Standard_Real aLIM = ShortRealLast() - 1.0;
743 if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
744 || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
748 gp_Pnt aPoints[8] = {
749 gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
750 gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
751 gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
752 gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
755 for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
756 const gp_Pnt& aBBPoint = aPoints[aPointIt];
758 gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
759 const Standard_Real& U = aProjected.X();
760 const Standard_Real& V = aProjected.Y();
762 if (U >= aScreenLimits[0]
763 && U <= aScreenLimits[1]
764 && V >= aScreenLimits[2]
765 && V <= aScreenLimits[3])
768 theX += aBBPoint.X();
769 theY += aBBPoint.Y();
770 theZ += aBBPoint.Z();
787 \brief Set the gravity center as a rotation point.
789 void OCCViewer_ViewWindow::activateSetRotationGravity()
791 if ( myRotationPointSelection )
793 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
794 #if OCC_VERSION_LARGE <= 0x07030000
795 ic->CloseAllContexts( Standard_True );
800 myOperation = NOVIEWOP;
801 myViewPort->setCursor( myCursor );
802 myCursorIsHand = false;
803 myRotationPointSelection = false;
806 myPrevPointType = myCurrPointType;
807 myCurrPointType = BBCENTER;
809 Standard_Real Xcenter, Ycenter, Zcenter;
810 if ( OCCViewer_Utilities::computeVisibleBBCenter( myViewPort->getView(), Xcenter, Ycenter, Zcenter ) )
811 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
815 \brief Update gravity center in the "Set Rotation Point" dialog box.
816 \sa OCCViewer_SetRotationPointDlg class
818 void OCCViewer_ViewWindow::updateGravityCoords()
820 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == BBCENTER )
822 Standard_Real Xcenter, Ycenter, Zcenter;
823 if ( OCCViewer_Utilities::computeVisibleBBCenter( myViewPort->getView(), Xcenter, Ycenter, Zcenter ) )
824 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
829 \brief Set the point selected by the user as a rotation point.
830 \param theX X coordinate of the rotation point
831 \param theY Y coordinate of the rotation point
832 \param theZ Z coordinate of the rotation point
834 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
836 if ( myRotationPointSelection )
838 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
839 #if OCC_VERSION_LARGE < 0x07030000
840 ic->CloseAllContexts( Standard_True );
845 myOperation = NOVIEWOP;
846 myViewPort->setCursor( myCursor );
847 myCursorIsHand = false;
848 myRotationPointSelection = false;
851 myPrevPointType = myCurrPointType;
852 myCurrPointType = SELECTED;
853 mySelectedPoint.SetCoord(theX,theY,theZ);
857 \brief Start the shape selection process.
859 void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
861 myPrevPointType = myCurrPointType;
862 myCurrPointType = SELECTED;
864 // activate selection ------>
865 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
866 #if OCC_VERSION_LARGE <= 0x07030000
867 ic->OpenLocalContext();
872 AIS_ListOfInteractive aList;
873 ic->DisplayedObjects( aList );
874 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
876 Handle(AIS_InteractiveObject) anObj = it.Value();
877 if ( !anObj.IsNull() && anObj->HasPresentation() &&
878 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
881 ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
884 // activate selection <------
886 if ( !myCursorIsHand )
888 QCursor handCursor (Qt::PointingHandCursor);
889 myCursorIsHand = true;
891 myViewPort->setCursor( handCursor );
893 myRotationPointSelection = true;
897 \brief Start global panning operation
899 Sets the corresponding cursor for the widget.
901 void OCCViewer_ViewWindow::activateGlobalPanning()
903 Handle(V3d_View) aView3d = myViewPort->getView();
904 if ( !aView3d.IsNull() ) {
905 QPixmap globalPanPixmap (imageCrossCursor);
906 QCursor glPanCursor (globalPanPixmap);
907 myCurScale = aView3d->Scale();
908 aView3d->FitAll(0.01, false);
909 saveCursor(); // save old cursor
910 myViewPort->fitAll(); // fits view before selecting a new scene center
911 if( setTransformRequested( PANGLOBAL ) )
912 myViewPort->setCursor( glPanCursor );
917 \brief Starts fit operation.
919 Sets the corresponding cursor for the widget.
921 void OCCViewer_ViewWindow::activateWindowFit()
923 if ( !transformRequested() && !myCursorIsHand )
924 saveCursor(); /* save old cursor */
926 if ( myOperation != WINDOWFIT ) {
927 QCursor handCursor (Qt::PointingHandCursor);
928 if( setTransformRequested ( WINDOWFIT ) )
930 myViewPort->setCursor ( handCursor );
931 myCursorIsHand = true;
937 \brief Start delayed viewer operation.
939 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
941 bool ok = transformEnabled( op );
942 myOperation = ok ? op : NOVIEWOP;
943 myViewPort->setMouseTracking( myOperation == NOVIEWOP );
948 \brief Handle mouse move event.
949 \param theEvent mouse event
951 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
953 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
955 switch ( getButtonState( theEvent, interactionStyle() ) ) {
957 myViewPort->startZoomAtPoint( myStartX, myStartY );
965 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
972 myCurrX = theEvent->x();
973 myCurrY = theEvent->y();
974 switch (myOperation) {
976 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
980 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
986 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
1000 if ( myRotationPointSelection || isSketcherStyle() )
1002 emit mouseMoving( this, theEvent );
1006 int aState = theEvent->modifiers();
1007 int aButton = theEvent->buttons();
1008 int anInteractionStyle = interactionStyle();
1009 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
1010 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
1011 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
1012 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
1013 myDrawRect = myEnableDrawMode;
1016 //if ( !myCursorIsHand ) { // we are going to sketch a rectangle
1017 // QCursor handCursor (Qt::PointingHandCursor);
1018 // myCursorIsHand = true;
1020 // myViewPort->setCursor( handCursor );
1023 SelectionStyle aStyle = selectionStyle();
1024 activateSketching(aStyle == RectStyle ? Rect : Polygon);
1027 if (l_mbPressEvent) {
1028 QApplication::sendEvent(getViewPort(), l_mbPressEvent);
1029 delete l_mbPressEvent;
1032 QApplication::sendEvent(getViewPort(), theEvent);
1035 emit mouseMoving( this, theEvent );
1037 //else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
1038 // aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
1039 // ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
1040 // aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
1041 // OCCViewer_ViewSketcher* sketcher = 0;
1042 // QList<OCCViewer_ViewSketcher*>::Iterator it;
1043 // for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
1045 // OCCViewer_ViewSketcher* sk = (*it);
1046 // if( sk->isDefault() && sk->sketchButton() == aButton )
1049 // if ( sketcher && myCurSketch == -1 )
1051 // activateSketching( sketcher->type() );
1052 // if ( mypSketcher )
1054 // myCurSketch = mypSketcher->sketchButton();
1056 // if ( l_mbPressEvent )
1058 // QApplication::sendEvent( getViewPort(), l_mbPressEvent );
1059 // delete l_mbPressEvent;
1060 // l_mbPressEvent = 0;
1062 // QApplication::sendEvent( getViewPort(), theEvent );
1067 emit mouseMoving( this, theEvent );
1073 \brief Handle mouse release event.
1074 \param theEvent mouse event
1076 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
1078 switch ( myOperation ) {
1081 int prevState = myCurSketch;
1082 if(theEvent->button() == Qt::RightButton)
1084 QList<OCCViewer_ViewSketcher*>::Iterator it;
1085 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
1087 OCCViewer_ViewSketcher* sk = (*it);
1088 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
1093 emit mouseReleased(this, theEvent);
1094 if(theEvent->button() == Qt::RightButton && prevState == -1)
1096 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1097 theEvent->pos(), theEvent->globalPos() );
1098 emit contextMenuRequested( &aEvent );
1103 myViewPort->endRotation();
1110 OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( getViewManager() );
1111 bool isChained = aMgr->isChainedOperations();
1112 bool isReset = !( myOperation==PANVIEW && myPanningByBtn && isChained ) || theEvent->button() == Qt::RightButton;
1119 if ( theEvent->button() == Qt::LeftButton ) {
1120 myViewPort->setCenter( theEvent->x(), theEvent->y() );
1121 myViewPort->getView()->SetScale(myCurScale);
1127 if ( theEvent->button() == Qt::LeftButton ) {
1128 myCurrX = theEvent->x();
1129 myCurrY = theEvent->y();
1131 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1132 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1139 // NOTE: viewer 3D detects a rectangle of selection using this event
1140 // so we must emit it BEFORE resetting the selection rectangle
1142 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1146 myViewPort->update();
1149 if ( l_mbPressEvent ) {
1150 delete l_mbPressEvent;
1156 \brief Reset the viewport to its initial state
1157 ( no transformations in process etc. )
1159 void OCCViewer_ViewWindow::resetState()
1163 if ( myRotationPointSelection )
1165 QCursor handCursor (Qt::PointingHandCursor);
1166 myViewPort->setCursor( handCursor );
1170 if ( transformRequested() || myCursorIsHand )
1171 myViewPort->setCursor( myCursor );
1172 myCursorIsHand = false;
1175 if ( transformRequested() )
1176 emit vpTransformationFinished (myOperation);
1178 setTransformInProcess( false );
1179 setTransformRequested( NOVIEWOP );
1181 myPanningByBtn = false;
1186 \brief Draw rubber band rectangle.
1188 void OCCViewer_ViewWindow::drawRect()
1190 if ( !myRectBand ) {
1191 myRectBand = new QtxRectRubberBand( myViewPort );
1194 myRectBand->setUpdatesEnabled ( false );
1195 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1196 myRectBand->initGeometry( aRect );
1198 if ( !myRectBand->isVisible() )
1201 myRectBand->setUpdatesEnabled ( true );
1205 \brief Clear rubber band rectangle on the end on the dragging operation.
1207 void OCCViewer_ViewWindow::endDrawRect()
1210 myRectBand->clearGeometry();
1216 \brief Create actions.
1218 void OCCViewer_ViewWindow::createActions()
1220 if( !toolMgr()->isEmpty() )
1223 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1230 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1231 tr( "MNU_DUMP_VIEW" ), 0, this);
1232 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1233 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1234 toolMgr()->registerAction( aAction, DumpId );
1237 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1238 tr( "MNU_FITALL" ), 0, this);
1239 aAction->setStatusTip(tr("DSC_FITALL"));
1240 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1241 toolMgr()->registerAction( aAction, FitAllId );
1244 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1245 tr( "MNU_FITRECT" ), 0, this);
1246 aAction->setStatusTip(tr("DSC_FITRECT"));
1247 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1248 toolMgr()->registerAction( aAction, FitRectId );
1251 aAction = new QtxAction(tr("MNU_FITSELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITSELECTION" ) ),
1252 tr( "MNU_FITSELECTION" ), 0, this);
1253 aAction->setStatusTip(tr("DSC_FITSELECTION"));
1254 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
1255 toolMgr()->registerAction( aAction, FitSelectionId );
1258 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1259 tr( "MNU_ZOOM_VIEW" ), 0, this);
1260 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1261 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1262 toolMgr()->registerAction( aAction, ZoomId );
1265 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1266 tr( "MNU_PAN_VIEW" ), 0, this);
1267 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1268 connect(aAction, SIGNAL(triggered()), this, SLOT(onPanning()));
1269 toolMgr()->registerAction( aAction, PanId );
1272 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1273 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1274 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1275 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1276 toolMgr()->registerAction( aAction, GlobalPanId );
1279 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1280 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1281 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1282 mySetRotationPointAction->setCheckable( true );
1283 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1284 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1287 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1288 tr( "MNU_ROTATE_VIEW" ), 0, this);
1289 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1290 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1291 toolMgr()->registerAction( aAction, RotationId );
1294 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1295 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1296 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1297 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1298 this->addAction(aAction);
1299 toolMgr()->registerAction( aAction, FrontId );
1301 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1302 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1303 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1304 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1305 this->addAction(aAction);
1306 toolMgr()->registerAction( aAction, BackId );
1308 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1309 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1310 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1311 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1312 this->addAction(aAction);
1313 toolMgr()->registerAction( aAction, TopId );
1315 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1316 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1317 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1318 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1319 this->addAction(aAction);
1320 toolMgr()->registerAction( aAction, BottomId );
1322 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1323 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1324 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1325 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1326 this->addAction(aAction);
1327 toolMgr()->registerAction( aAction, LeftId );
1329 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1330 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1331 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1332 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1333 this->addAction(aAction);
1334 toolMgr()->registerAction( aAction, RightId );
1336 // rotate anticlockwise
1337 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1338 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1339 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1340 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1341 this->addAction(aAction);
1342 toolMgr()->registerAction( aAction, AntiClockWiseId );
1345 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1346 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1347 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1348 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1349 this->addAction(aAction);
1350 toolMgr()->registerAction( aAction, ClockWiseId );
1352 // Projection mode group
1354 // - orthographic projection
1355 aAction = new QtxAction(tr("MNU_ORTHOGRAPHIC_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ORTHOGRAPHIC" ) ),
1356 tr( "MNU_ORTHOGRAPHIC_MODE" ), 0, this);
1357 aAction->setStatusTip(tr("DSC_ORTHOGRAPHIC_MODE"));
1358 aAction->setCheckable(true);
1359 toolMgr()->registerAction( aAction, OrthographicId );
1361 // - perspective projection
1362 aAction = new QtxAction(tr("MNU_PERSPECTIVE_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PERSPECTIVE" ) ),
1363 tr( "MNU_PERSPECTIVE_MODE" ), 0, this);
1364 aAction->setStatusTip(tr("DSC_PERSPECTIVE_MODE"));
1365 aAction->setCheckable(true);
1366 toolMgr()->registerAction( aAction, PerspectiveId );
1368 // - stereo projection
1369 aAction = new QtxAction(tr("MNU_STEREO_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STEREO" ) ),
1370 tr( "MNU_STEREO_MODE" ), 0, this);
1371 aAction->setStatusTip(tr("DSC_STEREO_MODE"));
1372 aAction->setCheckable(true);
1373 toolMgr()->registerAction( aAction, StereoId );
1374 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onStereoType(bool)));
1376 // - add exclusive action group
1377 QActionGroup* aProjectionGroup = new QActionGroup( this );
1378 aProjectionGroup->addAction( toolMgr()->action( OrthographicId ) );
1379 aProjectionGroup->addAction( toolMgr()->action( PerspectiveId ) );
1380 connect(aProjectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProjectionType(QAction*)));
1383 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1384 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1385 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1386 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1387 this->addAction(aAction);
1388 toolMgr()->registerAction( aAction, ResetId );
1391 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1392 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1393 tr("MNU_CLONE_VIEW"), 0, this);
1394 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1395 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1396 toolMgr()->registerAction( aAction, CloneId );
1398 aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
1399 tr("MNU_CLIPPING"), 0, this);
1400 aAction->setStatusTip (tr("DSC_CLIPPING"));
1401 aAction->setCheckable (true);
1402 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1403 toolMgr()->registerAction (aAction, ClippingId);
1405 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1406 tr( "MNU_SHOOT_VIEW" ), 0, this);
1407 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1408 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1409 toolMgr()->registerAction( aAction, MemId );
1411 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1412 tr( "MNU_PRESETS_VIEW" ), 0, this);
1413 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1414 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1415 toolMgr()->registerAction( aAction, RestoreId );
1417 if (myModel->trihedronActivated()) {
1418 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1419 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1420 aAction->setCheckable( true );
1421 aAction->setChecked( true );
1422 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1423 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1424 toolMgr()->registerAction( aAction, TrihedronShowId );
1428 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1429 tr( "MNU_SCALING" ), 0, this);
1430 aAction->setStatusTip(tr("DSC_SCALING"));
1431 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1432 toolMgr()->registerAction( aAction, AxialScaleId );
1434 // Enable/disable preselection
1435 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1436 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1437 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1438 aAction->setCheckable(true);
1439 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1440 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1442 // Enable/disable selection
1443 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1444 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1445 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1446 aAction->setCheckable(true);
1447 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1448 toolMgr()->registerAction( aAction, SwitchSelectionId );
1451 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1452 tr( "MNU_GRADUATED_AXES" ), 0, this);
1453 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1454 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1455 toolMgr()->registerAction( aAction, GraduatedAxesId );
1457 // Active only ambient light or not
1458 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1459 tr( "MNU_AMBIENT" ), 0, this);
1460 aAction->setStatusTip(tr("DSC_AMBIENT"));
1461 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1462 toolMgr()->registerAction( aAction, AmbientId );
1464 // Switch between interaction styles
1465 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1466 tr( "MNU_STYLE_SWITCH" ), 0, this);
1467 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1468 aAction->setCheckable(true);
1469 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1470 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1472 // Switch between zooming styles
1473 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1474 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1475 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1476 aAction->setCheckable(true);
1477 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1478 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1480 // Switch advanced selection style (poligone/circle)
1481 aAction = new QtxAction(tr("MNU_RECTANGLE_SELECTION_STYLE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RECT_STYLE" ) ),
1482 tr( "MNU_RECTANGLE_SELECTION_STYLE" ), 0, this);
1483 aAction->setStatusTip(tr("DSC_RECTANGLE_SELECTION_STYLE"));
1484 aAction->setCheckable(true);
1485 toolMgr()->registerAction( aAction, RectangleSelectionStyleId);
1487 aAction = new QtxAction(tr("MNU_POLYGON_SELECTION_STYLE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_POLY_STYLE" ) ),
1488 tr( "MNU_POLYGON_SELECTION_STYLE" ), 0, this);
1489 aAction->setStatusTip(tr("DSC_POLYGON_SELECTION_STYLE"));
1490 aAction->setCheckable(true);
1491 toolMgr()->registerAction( aAction, PolygonSelectionStyleId);
1493 aAction = new QtxAction(tr("MNU_CIRCLE_SELECTION_STYLE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CIRCLE_STYLE" ) ),
1494 tr( "MNU_CIRCLE_SELECTION_STYLE" ), 0, this);
1495 aAction->setStatusTip(tr("DSC_CIRCLE_SELECTION_STYLE"));
1496 aAction->setCheckable(true);
1497 toolMgr()->registerAction( aAction, CircleSelectionStyleId);
1499 // - add exclusive action group
1500 QActionGroup* aSelectionGroup = new QActionGroup(this);
1501 aSelectionGroup->addAction(toolMgr()->action(RectangleSelectionStyleId));
1502 aSelectionGroup->addAction(toolMgr()->action(PolygonSelectionStyleId));
1503 aSelectionGroup->addAction(toolMgr()->action(CircleSelectionStyleId));
1504 connect(aSelectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onSwitchSelectionStyle(QAction*)));
1507 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1508 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1509 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1510 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1511 toolMgr()->registerAction( aAction, MaximizedId );
1513 // Return to 3d view
1514 if (my2dMode!=No2dMode){
1515 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1516 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1517 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1518 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1519 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1523 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1524 #ifdef ENABLE_RAY_TRACING
1526 aAction = new QtxAction( tr("MNU_RAY_TRACING"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_RAY_TRACING") ),
1527 tr("MNU_RAY_TRACING"), 0, this );
1528 aAction->setStatusTip( tr("DSC_RAY_TRACING") );
1529 connect( aAction, SIGNAL( triggered() ), this, SLOT( onRayTracing() ) );
1530 toolMgr()->registerAction( aAction, RayTracingId );
1532 // Environment texture
1533 aAction = new QtxAction( tr("MNU_ENV_TEXTURE"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_ENV_TEXTURE") ),
1534 tr("MNU_ENV_TEXTURE"), 0, this );
1535 aAction->setStatusTip( tr("DSC_ENV_TEXTURE") );
1536 connect( aAction, SIGNAL( triggered() ), this, SLOT( onEnvTexture() ) );
1537 toolMgr()->registerAction( aAction, EnvTextureId );
1540 aAction = new QtxAction( tr("MNU_LIGHT_SOURCE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_LIGHT_SOURCE" ) ),
1541 tr( "MNU_LIGHT_SOURCE" ), 0, this );
1542 aAction->setStatusTip( tr("DSC_LIGHT_SOURCE") );
1543 connect( aAction, SIGNAL( triggered() ), this, SLOT( onLightSource() ) );
1544 toolMgr()->registerAction( aAction, LightSourceId );
1549 \brief Create toolbar.
1551 void OCCViewer_ViewWindow::createToolBar()
1553 static const char* titles[] = {
1554 "LBL_3DTOOLBAR_LABEL",
1555 "LBL_XYTOOLBAR_LABEL",
1556 "LBL_XZTOOLBAR_LABEL",
1557 "LBL_YZTOOLBAR_LABEL",
1559 static const char* names[] = {
1560 "OCCViewer3DViewOperations",
1561 "OCCViewerXYViewOperations",
1562 "OCCViewerXZViewOperations",
1563 "OCCViewerYZViewOperations",
1565 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1566 QString( names[my2dMode] ), // name (language-independant)
1567 false ); // disable floatable toolbar
1568 if ( my2dMode != No2dMode ){
1569 toolMgr()->append( ReturnTo3dViewId, tid );
1570 toolMgr()->append( toolMgr()->separator(), tid );
1572 toolMgr()->append( DumpId, tid );
1573 toolMgr()->append( SwitchInteractionStyleId, tid );
1574 toolMgr()->append( SwitchZoomingStyleId, tid );
1575 toolMgr()->append( SwitchPreselectionId, tid );
1576 toolMgr()->append( SwitchSelectionId, tid );
1578 QtxMultiAction* aSelectionAction = new QtxMultiAction(this);
1579 aSelectionAction->insertAction(toolMgr()->action(RectangleSelectionStyleId));
1580 aSelectionAction->insertAction(toolMgr()->action(PolygonSelectionStyleId));
1581 aSelectionAction->insertAction(toolMgr()->action(CircleSelectionStyleId));
1582 toolMgr()->append(aSelectionAction, tid );
1584 if( myModel->trihedronActivated() )
1585 toolMgr()->append( TrihedronShowId, tid );
1587 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1588 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1589 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1590 aScaleAction->insertAction( toolMgr()->action( FitSelectionId ) );
1591 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1592 toolMgr()->append( aScaleAction, tid );
1594 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1595 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1596 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1597 toolMgr()->append( aPanningAction, tid );
1599 if (my2dMode == No2dMode) {
1600 toolMgr()->append( ChangeRotationPointId, tid );
1601 toolMgr()->append( RotationId, tid );
1603 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1604 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1605 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1606 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1607 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1608 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1609 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1610 toolMgr()->append( aViewsAction, tid );
1612 toolMgr()->append( AntiClockWiseId, tid );
1613 toolMgr()->append( ClockWiseId, tid );
1615 toolMgr()->append( OrthographicId, tid );
1616 toolMgr()->append( PerspectiveId, tid );
1617 toolMgr()->append( StereoId, tid );
1619 toolMgr()->append( ResetId, tid );
1622 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1623 aMemAction->insertAction( toolMgr()->action( MemId ) );
1624 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1625 toolMgr()->append( aMemAction, tid );
1627 toolMgr()->append( toolMgr()->separator(), tid );
1628 toolMgr()->append( CloneId, tid );
1630 toolMgr()->append( toolMgr()->separator(), tid );
1631 toolMgr()->append( ClippingId, tid );
1632 toolMgr()->append( AxialScaleId, tid );
1633 toolMgr()->append( GraduatedAxesId, tid );
1634 toolMgr()->append( AmbientId, tid );
1636 toolMgr()->append( MaximizedId, tid );
1637 toolMgr()->append( SynchronizeId, tid );
1638 #ifdef ENABLE_RAY_TRACING
1639 toolMgr()->append( RayTracingId, tid );
1640 toolMgr()->append( EnvTextureId, tid );
1641 toolMgr()->append( LightSourceId, tid );
1646 \brief Perform 'fit all' operation.
1648 void OCCViewer_ViewWindow::onViewFitAll()
1650 myViewPort->fitAll();
1654 \brief Perform "front view" transformation.
1656 void OCCViewer_ViewWindow::onFrontView()
1658 emit vpTransformationStarted ( FRONTVIEW );
1659 Handle(V3d_View) aView3d = myViewPort->getView();
1660 if (myAutomaticZoom)
1662 if ( !aView3d.IsNull() )
1663 aView3d->SetProj (V3d_Xpos);
1667 projAndPanToGravity(V3d_Xpos);
1668 emit vpTransformationFinished ( FRONTVIEW );
1672 \brief Perform "back view" transformation.
1674 void OCCViewer_ViewWindow::onBackView()
1676 emit vpTransformationStarted ( BACKVIEW );
1677 Handle(V3d_View) aView3d = myViewPort->getView();
1678 if (myAutomaticZoom)
1680 if ( !aView3d.IsNull() )
1681 aView3d->SetProj (V3d_Xneg);
1685 projAndPanToGravity(V3d_Xneg);
1686 emit vpTransformationFinished ( BACKVIEW );
1690 \brief Perform "top view" transformation.
1692 void OCCViewer_ViewWindow::onTopView()
1694 emit vpTransformationStarted ( TOPVIEW );
1695 Handle(V3d_View) aView3d = myViewPort->getView();
1696 if (myAutomaticZoom)
1698 if ( !aView3d.IsNull() )
1699 aView3d->SetProj (V3d_Zpos);
1703 projAndPanToGravity(V3d_Zpos);
1704 emit vpTransformationFinished ( TOPVIEW );
1708 \brief Perform "bottom view" transformation.
1710 void OCCViewer_ViewWindow::onBottomView()
1712 emit vpTransformationStarted ( BOTTOMVIEW );
1713 Handle(V3d_View) aView3d = myViewPort->getView();
1714 if (myAutomaticZoom)
1716 if ( !aView3d.IsNull() )
1717 aView3d->SetProj (V3d_Zneg);
1721 projAndPanToGravity(V3d_Zneg);
1722 emit vpTransformationFinished ( BOTTOMVIEW );
1726 \brief Perform "left view" transformation.
1728 void OCCViewer_ViewWindow::onLeftView()
1730 emit vpTransformationStarted ( LEFTVIEW );
1731 Handle(V3d_View) aView3d = myViewPort->getView();
1732 if (myAutomaticZoom)
1734 if ( !aView3d.IsNull() )
1735 aView3d->SetProj (V3d_Yneg);
1739 projAndPanToGravity(V3d_Yneg);
1740 emit vpTransformationFinished ( LEFTVIEW );
1744 \brief Perform "right view" transformation.
1746 void OCCViewer_ViewWindow::onRightView()
1748 emit vpTransformationStarted ( RIGHTVIEW );
1749 Handle(V3d_View) aView3d = myViewPort->getView();
1750 if (myAutomaticZoom)
1752 if ( !aView3d.IsNull() )
1753 aView3d->SetProj (V3d_Ypos);
1757 projAndPanToGravity(V3d_Ypos);
1758 emit vpTransformationFinished ( RIGHTVIEW );
1762 \brief Rotate view 90 degrees clockwise
1764 void OCCViewer_ViewWindow::onClockWiseView()
1766 emit vpTransformationStarted ( CLOCKWISEVIEW );
1767 myViewPort->rotateXY( 90. );
1768 emit vpTransformationFinished ( CLOCKWISEVIEW );
1772 \brief Rotate view 90 degrees conterclockwise
1774 void OCCViewer_ViewWindow::onAntiClockWiseView()
1776 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1777 myViewPort->rotateXY( -90. );
1778 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1782 \brief Perform "reset view" transformation.
1784 Sets default orientation of the viewport camera.
1786 void OCCViewer_ViewWindow::onResetView()
1788 emit vpTransformationStarted( RESETVIEW );
1789 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1790 myViewPort->getView()->Reset( false );
1791 myViewPort->fitAll( false, true, false );
1792 myViewPort->getView()->SetImmediateUpdate( upd );
1793 onProjectionType(); // needed to apply projection type properly after reset
1794 myViewPort->getView()->Update();
1795 emit vpTransformationFinished( RESETVIEW );
1799 \brief Set the given projection mode.
1801 Set the given projection mode: Orthographic or Perspective.
1803 void OCCViewer_ViewWindow::onProjectionType( QAction* theAction )
1805 Handle(V3d_View) aView3d = myViewPort->getView();
1806 if ( !aView3d.IsNull() ) {
1807 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1808 if (theAction == toolMgr()->action( OrthographicId )) {
1809 myModel->setProjectionType(Orthographic);
1810 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Orthographic );
1811 aCamera->SetFOVy(45.0);
1813 else if (theAction == toolMgr()->action( PerspectiveId )) {
1814 myModel->setProjectionType(Perspective);
1815 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Perspective );
1816 aCamera->SetFOVy(30.0);
1818 if (toolMgr()->action( StereoId )->isChecked()) {
1819 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1820 aCamera->SetFOVy(30.0);
1828 \brief Sets Stereo projection mode.
1830 Sets Stereo projection mode.
1832 void OCCViewer_ViewWindow::onStereoType( bool activate )
1834 Handle(V3d_View) aView3d = myViewPort->getView();
1835 if ( !aView3d.IsNull() ) {
1836 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1838 toolMgr()->action( PerspectiveId )->setChecked(true);
1839 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1840 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(false);
1842 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1843 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1844 setStereoType( aResMgr->integerValue( "OCCViewer", "stereo_type", 0 ) );
1845 setAnaglyphFilter( aResMgr->integerValue( "OCCViewer", "anaglyph_filter", 0 ) );
1846 setReverseStereo( aResMgr->booleanValue( "OCCViewer", "reverse_stereo", false ) );
1847 setVSync( aResMgr->booleanValue( "OCCViewer", "enable_vsync", true ) );
1848 setQuadBufferSupport( aResMgr->booleanValue( "OCCViewer", "enable_quad_buffer_support", false ) );
1851 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(true);
1852 if (myModel->projectionType() == Orthographic) {
1853 toolMgr()->action( OrthographicId )->setChecked(true);
1854 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Orthographic);
1856 else if (myModel->projectionType() == Perspective) {
1857 toolMgr()->action( PerspectiveId )->setChecked(true);
1858 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1865 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1866 toolMgr()->action( StereoId )->isChecked() )
1867 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1871 \brief Restore the view.
1873 Restore the projection mode based on tool-buttons states.
1875 void OCCViewer_ViewWindow::onProjectionType()
1877 emit vpTransformationStarted( PROJECTION );
1878 if (toolMgr()->action( OrthographicId )->isChecked())
1879 setProjectionType( Orthographic );
1880 if (toolMgr()->action( PerspectiveId )->isChecked())
1881 setProjectionType( Perspective );
1882 if (toolMgr()->action( StereoId )->isChecked())
1883 setProjectionType( Stereo );
1884 emit vpTransformationFinished( PROJECTION );
1887 void OCCViewer_ViewWindow::setProjectionType( int mode )
1889 QtxAction* anOrthographicAction = dynamic_cast<QtxAction*>( toolMgr()->action( OrthographicId ) );
1890 QtxAction* aPerspectiveAction = dynamic_cast<QtxAction*>( toolMgr()->action( PerspectiveId ) );
1891 QtxAction* aStereoAction = dynamic_cast<QtxAction*>( toolMgr()->action( StereoId ) );
1894 onProjectionType( anOrthographicAction );
1897 onProjectionType( aPerspectiveAction );
1900 onStereoType( true );
1903 // update action state if method is called outside
1904 if ( mode == Orthographic && !anOrthographicAction->isChecked() ) {
1905 anOrthographicAction->setChecked( true );
1906 aStereoAction->setChecked( false );
1908 if ( mode == Perspective && !aPerspectiveAction->isChecked() ) {
1909 aPerspectiveAction->setChecked( true );
1910 aStereoAction->setChecked( false );
1912 if ( mode == Stereo ) {
1913 aStereoAction->setChecked( true );
1914 if ( anOrthographicAction->isEnabled() ) {
1915 anOrthographicAction->setEnabled( false );
1916 anOrthographicAction->setChecked( false );
1917 aStereoAction->setChecked( false );
1920 anOrthographicAction->setEnabled( true );
1921 aStereoAction->setChecked( false );
1922 anOrthographicAction->setChecked(myModel->projectionType() == Orthographic);
1924 if ( aPerspectiveAction->isEnabled() ) {
1925 aPerspectiveAction->setEnabled( false );
1926 aPerspectiveAction->setChecked( true );
1927 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1928 toolMgr()->action( StereoId )->isChecked() )
1929 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1932 aPerspectiveAction->setEnabled( true );
1933 aStereoAction->setChecked( false );
1934 aPerspectiveAction->setChecked(myModel->projectionType() == Perspective);
1939 if ( !anOrthographicAction->isEnabled() )
1940 anOrthographicAction->setEnabled( true );
1941 if ( !aPerspectiveAction->isEnabled() )
1942 aPerspectiveAction->setEnabled( true );
1947 \brief Perform "fit all" transformation.
1949 void OCCViewer_ViewWindow::onFitAll()
1951 emit vpTransformationStarted( FITALLVIEW );
1952 if (myModel->fitter())
1953 myModel->fitter()->fitAll(myViewPort->getView());
1955 myViewPort->fitAll();
1956 emit vpTransformationFinished( FITALLVIEW );
1960 \brief Perform "fit selection" transformation.
1962 void OCCViewer_ViewWindow::onFitSelection()
1964 emit vpTransformationStarted( FITSELECTION );
1965 myModel->getAISContext()->FitSelected( getViewPort()->getView() );
1966 emit vpTransformationFinished( FITSELECTION );
1970 \brief Called if 'change rotation point' operation is activated.
1971 \param on action state
1973 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1977 if (!mySetRotationPointDlg)
1979 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1980 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1983 if (!mySetRotationPointDlg->isVisible())
1985 //if (mySetRotationPointDlg->IsFirstShown())
1986 if (myCurrPointType == BBCENTER)
1988 Standard_Real Xcenter, Ycenter, Zcenter;
1989 if (OCCViewer_Utilities::computeVisibleBBCenter(myViewPort->getView(), Xcenter, Ycenter, Zcenter))
1990 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1992 mySetRotationPointDlg->show();
1997 if (mySetRotationPointDlg->isVisible())
1998 mySetRotationPointDlg->hide();
2003 \brief Create one more window with same content.
2005 void OCCViewer_ViewWindow::onCloneView()
2007 SUIT_ViewWindow* vw = myManager->createViewWindow();
2009 emit viewCloned( vw );
2010 OCCViewer_ViewWindow* occVw = dynamic_cast<OCCViewer_ViewWindow*> (vw);
2011 if(occVw && occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)) {
2012 occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)->synchronize(this);
2017 Creates one more window with same content
2019 void OCCViewer_ViewWindow::onAxialScale()
2021 if ( !myScalingDlg )
2022 myScalingDlg = new OCCViewer_AxialScaleDlg( this , myModel );
2024 if ( !myScalingDlg->isVisible() )
2026 myScalingDlg->Update();
2027 myScalingDlg->show();
2032 Shows Graduated Axes dialog
2034 void OCCViewer_ViewWindow::onGraduatedAxes()
2036 myCubeAxesDlg->Update();
2037 myCubeAxesDlg->show();
2040 void OCCViewer_ViewWindow::onAmbientToogle()
2042 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2043 viewer->InitDefinedLights();
2044 while(viewer->MoreDefinedLights())
2046 Handle(V3d_Light) light = viewer->DefinedLight();
2047 if(light->Type() != V3d_AMBIENT)
2049 Handle(V3d_View) aView3d = myViewPort->getView();
2050 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
2051 else viewer->SetLightOn(light);
2053 viewer->NextDefinedLights();
2059 \brief Store view parameters.
2061 void OCCViewer_ViewWindow::onMemorizeView()
2063 appendViewAspect( getViewParams() );
2067 \brief Restore view parameters.
2069 void OCCViewer_ViewWindow::onRestoreView()
2071 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
2072 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
2074 updateViewAspects( aDlg->parameters() );
2075 if( myRestoreFlag && aDlg->parameters().count() )
2076 performRestoring( aDlg->currentItem() );
2080 \brief Restore view parameters.
2081 \param anItem view parameters
2083 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
2085 Handle(V3d_View) aView3d = myViewPort->getView();
2087 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
2088 aView3d->SetScale( anItem.scale );
2089 aView3d->SetTwist( anItem.twist );
2090 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
2091 aView3d->SetImmediateUpdate( prev );
2092 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2093 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2094 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
2096 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
2098 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
2100 // "eye" and "at" require conversion to represent center panning
2101 // up direction is only available after setting angle of twist and
2102 // other view parameters
2103 aView3d->Up( anUpX, anUpY, anUpZ );
2105 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
2106 gp_Dir anUp( anUpX, anUpY, anUpZ );
2107 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
2108 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2109 gp_Dir aSide = aProj ^ anUp;
2111 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
2112 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
2114 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
2115 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2118 if ( !baseParamsOnly ) {
2120 myModel->setTrihedronShown( anItem.isVisible );
2121 myModel->setTrihedronSize( anItem.size );
2123 // graduated trihedron
2124 bool anIsVisible = anItem.gtIsVisible;
2125 OCCViewer_AxisWidget::AxisData anAxisData[3];
2126 anAxisData[0].DrawName = anItem.gtDrawNameX;
2127 anAxisData[1].DrawName = anItem.gtDrawNameZ;
2128 anAxisData[2].DrawName = anItem.gtDrawNameZ;
2129 anAxisData[0].Name = anItem.gtNameX;
2130 anAxisData[1].Name = anItem.gtNameZ;
2131 anAxisData[2].Name = anItem.gtNameZ;
2132 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
2133 anItem.gtNameColorGX,
2134 anItem.gtNameColorBX );
2135 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
2136 anItem.gtNameColorGY,
2137 anItem.gtNameColorBY );
2138 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
2139 anItem.gtNameColorGZ,
2140 anItem.gtNameColorBZ );
2141 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
2142 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
2143 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
2144 anAxisData[0].NbValues = anItem.gtNbValuesX;
2145 anAxisData[1].NbValues = anItem.gtNbValuesY;
2146 anAxisData[2].NbValues = anItem.gtNbValuesZ;
2147 anAxisData[0].Offset = anItem.gtOffsetX;
2148 anAxisData[1].Offset = anItem.gtOffsetY;
2149 anAxisData[2].Offset = anItem.gtOffsetZ;
2150 anAxisData[0].Color = QColor( anItem.gtColorRX,
2153 anAxisData[1].Color = QColor( anItem.gtColorRY,
2156 anAxisData[2].Color = QColor( anItem.gtColorRZ,
2159 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
2160 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
2161 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
2162 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
2163 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
2164 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
2166 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
2167 myCubeAxesDlg->ApplyData( aView3d );
2169 } // if ( !baseParamsOnly )
2175 \brief Set restore flag.
2177 void OCCViewer_ViewWindow::setRestoreFlag()
2183 \brief Called when action "show/hide trihedron" is activated.
2185 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
2187 myModel->setTrihedronShown(show);
2191 \brief Toggles preselection (highlighting) on/off
2193 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
2195 myPreselectionEnabled = on;
2196 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
2198 // unhighlight all highlighted objects
2200 myModel->unHighlightAll( true, false );
2203 // update action state if method is called outside
2204 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2205 if ( a && a->isChecked() != on ) {
2206 a->setChecked( on );
2211 \brief Toggles selection on/off
2213 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
2215 mySelectionEnabled = on;
2216 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
2218 // update action state if method is called outside
2221 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2223 a->setEnabled( on );
2227 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
2228 if ( a && a->isChecked() != on ) {
2229 a->setChecked( on );
2234 \brief Switches style of advanced multiple selection by Poligon/Circle
2236 void OCCViewer_ViewWindow::onSwitchSelectionStyle(QAction* theAction)
2239 OCCViewer_ViewSketcher* aSkecher = getSketcher(Polygon);
2241 if (theAction == toolMgr()->action(PolygonSelectionStyleId)) {
2242 aSkecher->setSketcherMode(OCCViewer_PolygonSketcher::Poligone);
2244 else if (theAction == toolMgr()->action(CircleSelectionStyleId)) {
2245 aSkecher->setSketcherMode(OCCViewer_PolygonSketcher::Circle);
2251 Returns currently selected selection style
2253 OCCViewer_ViewWindow::SelectionStyle OCCViewer_ViewWindow::selectionStyle() const
2255 if (toolMgr()->action(PolygonSelectionStyleId)->isChecked())
2256 return PolygonStyle;
2257 if (toolMgr()->action(CircleSelectionStyleId)->isChecked())
2262 void OCCViewer_ViewWindow::setSelectionStyle(SelectionStyle theMode)
2264 toolMgr()->action(RectangleSelectionStyleId)->setChecked(false);
2265 toolMgr()->action(PolygonSelectionStyleId)->setChecked(false);
2266 toolMgr()->action(CircleSelectionStyleId)->setChecked(false);
2269 toolMgr()->action(RectangleSelectionStyleId)->setChecked(true);
2272 toolMgr()->action(PolygonSelectionStyleId)->setChecked(true);
2275 toolMgr()->action(CircleSelectionStyleId)->setChecked(true);
2280 \brief Switches "keyboard free" interaction style on/off
2282 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
2284 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
2286 // update action state if method is called outside
2287 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
2288 if ( a && a->isChecked() != on )
2289 a->setChecked( on );
2293 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
2295 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
2297 myViewPort->setAdvancedZoomingEnabled( on );
2299 // update action state if method is called outside
2300 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
2301 if ( a && a->isChecked() != on )
2302 a->setChecked( on );
2306 \brief Get current interaction style
2307 \return interaction style
2309 int OCCViewer_ViewWindow::interactionStyle() const
2311 return myInteractionStyle;
2315 \brief Set current interaction style
2316 \param theStyle interaction style
2318 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
2320 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
2324 \brief Get current zooming style
2325 \return zooming style
2327 int OCCViewer_ViewWindow::zoomingStyle() const
2329 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
2333 \brief Set current zooming style
2334 \param theStyle zooming style
2336 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
2338 onSwitchZoomingStyle( theStyle == 1 );
2342 \brief Dump view window contents to the pixmap.
2343 \return pixmap containing all scene rendered in the window
2345 //#define USE_OLD_IMPLEMENTATION
2346 QImage OCCViewer_ViewWindow::dumpView()
2348 Handle(V3d_View) view = myViewPort->getView();
2349 if ( view.IsNull() )
2352 int aWidth = myViewPort->width();
2353 int aHeight = myViewPort->height();
2355 #ifdef USE_OLD_IMPLEMENTATION
2356 // rnv: Old approach to dump the OCCViewer content via Frame Buffer Object
2360 #ifndef DISABLE_GLVIEWER
2361 OpenGLUtils_FrameBuffer aFrameBuffer;
2362 if ( aFrameBuffer.init( aWidth, aHeight ) )
2364 glPushAttrib( GL_VIEWPORT_BIT );
2365 glViewport( 0, 0, aWidth, aHeight );
2366 aFrameBuffer.bind();
2371 aFrameBuffer.unbind();
2374 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
2376 aFrameBuffer.bind();
2377 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
2378 aFrameBuffer.unbind();
2380 anImage = anImage.rgbSwapped();
2381 anImage = anImage.mirrored();
2385 // if frame buffers are unsupported, use old approach
2387 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
2388 QPoint p = myViewPort->mapFromParent( myViewPort->geometry().topLeft() );
2389 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
2391 QImage anImage( data, aWidth, aHeight, QImage::Format_ARGB32 );
2392 anImage = anImage.mirrored();
2393 anImage = anImage.rgbSwapped();
2396 #else // DISABLE_GLVIEWER
2400 #endif // DISABLE_GLVIEWER
2402 #else // USE_OLD_IMPLEMENTATION
2403 // rnv: New approach is to use OCCT built-in procedure
2406 view->ToPixMap(aPix, aWidth, aHeight, Graphic3d_BT_RGB);
2408 QImage anImage( aWidth, aHeight, QImage::Format_ARGB32 );
2409 for ( int i = 0; i < aWidth; i++ ) {
2410 for ( int j = 0; j < aHeight; j++ ) {
2411 Quantity_Color pixel = aPix.PixelColor( i, j ).GetRGB();
2412 QColor color = QColor::fromRgbF( pixel.Red(), pixel.Green(), pixel.Blue() );
2413 anImage.setPixelColor( i, j, color );
2417 if ( aPix.IsTopDown() )
2418 anImage = anImage.mirrored();
2421 #endif // USE_OLD_IMPLEMENTATION
2424 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
2425 const QString& fileName,
2426 const QString& format )
2429 QApplication::setOverrideCursor( Qt::WaitCursor );
2431 // OCCT version > 7.3.0 is not support export to PS and EPS
2432 #if OCC_VERSION_LARGE <= 0x07030000
2433 Handle(Graphic3d_CView) a3dView = myViewPort->getView()->View();
2435 if (format == "PS") {
2436 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(myViewPort->getViewer()->Driver());
2437 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
2438 int prev = aCaps->ffpEnable;
2439 aCaps->ffpEnable = 1;
2440 res = a3dView->Export(strdup(qUtf8Printable(fileName)), Graphic3d_EF_PostScript);
2441 aCaps->ffpEnable = prev;
2443 else if (format == "EPS") {
2444 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(myViewPort->getViewer()->Driver());
2445 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
2446 int prev = aCaps->ffpEnable;
2447 aCaps->ffpEnable = 1;
2448 res = a3dView->Export(strdup(qUtf8Printable(fileName)), Graphic3d_EF_EnhPostScript);
2449 aCaps->ffpEnable = prev;
2453 res = myViewPort->getView()->Dump( fileName.toStdString().c_str() );
2454 #if OCC_VERSION_LARGE <= 0x07030000
2458 QApplication::restoreOverrideCursor();
2463 QString OCCViewer_ViewWindow::filter() const
2465 #if OCC_VERSION_LARGE <= 0x07030000
2466 return tr( "OCC_IMAGE_FILES" );
2468 QString formats = tr( "OCC_IMAGE_FILES" );
2469 return formats.remove(" *.eps *.ps");
2475 \brief Set parameters of the cutting plane
2476 \param on if \c true, cutting plane is enabled
2477 \param x X position of plane point
2478 \param y Y position of plane point
2479 \param z Z position of plane point
2480 \param dx X coordinate of plane normal
2481 \param dy Y coordinate of plane normal
2482 \param dz Z coordinate of plane normal
2484 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2485 const double dx, const double dy, const double dz )
2487 Handle(V3d_View) view = myViewPort->getView();
2488 if ( view.IsNull() )
2492 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2494 // try to use already existing plane or create a new one
2495 Handle(V3d_Plane) clipPlane;
2497 // calculate new a,b,c,d values for the plane
2498 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2500 pln.Coefficients(a, b, c, d);
2501 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2502 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2503 if(aPlanes->Size() > 0 ) {
2504 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2505 aClipPlane->SetEquation(pln);
2506 aClipPlane->SetOn(Standard_True);
2508 view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2512 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2513 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2514 for( ;anIter.More();anIter.Next() ){
2515 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2516 aClipPlane->SetOn(Standard_False);
2524 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2526 gp_Dir aDir = pln.Axis().Direction();
2527 gp_Pnt aPnt = pln.Location();
2528 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2533 \brief Check if any cutting plane is enabled
2534 \return \c true if at least one cutting plane is enabled
2536 bool OCCViewer_ViewWindow::isCuttingPlane()
2538 Handle(V3d_View) view = myViewPort->getView();
2540 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2541 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2542 for( ;anIter.More();anIter.Next() ) {
2543 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2544 if(aClipPlane->IsOn()) {
2553 \brief Get the visual parameters of the view window.
2554 \return visual parameters of view window
2556 viewAspect OCCViewer_ViewWindow::getViewParams() const
2558 double projX, projY, projZ, twist;
2559 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2560 double aScaleX, aScaleY, aScaleZ;
2562 Handle(V3d_View) aView3d = myViewPort->getView();
2564 aView3d->Proj( projX, projY, projZ );
2565 aView3d->At( atX, atY, atZ );
2566 aView3d->Eye( eyeX, eyeY, eyeZ );
2567 twist = aView3d->Twist();
2569 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2571 bool isShown = myModel->isTrihedronVisible();
2572 double size = myModel->trihedronSize();
2574 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2577 params.scale = aView3d->Scale();
2578 params.projX = projX;
2579 params.projY = projY;
2580 params.projZ = projZ;
2581 params.twist = twist;
2588 params.scaleX = aScaleX;
2589 params.scaleY = aScaleY;
2590 params.scaleZ = aScaleZ;
2591 params.name = aName;
2592 params.isVisible= isShown;
2595 // graduated trihedron
2596 bool anIsVisible = false;
2597 OCCViewer_AxisWidget::AxisData anAxisData[3];
2598 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2600 params.gtIsVisible = anIsVisible;
2601 params.gtDrawNameX = anAxisData[0].DrawName;
2602 params.gtDrawNameY = anAxisData[1].DrawName;
2603 params.gtDrawNameZ = anAxisData[2].DrawName;
2604 params.gtNameX = anAxisData[0].Name;
2605 params.gtNameY = anAxisData[1].Name;
2606 params.gtNameZ = anAxisData[2].Name;
2607 params.gtNameColorRX = anAxisData[0].NameColor.red();
2608 params.gtNameColorGX = anAxisData[0].NameColor.green();
2609 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2610 params.gtNameColorRY = anAxisData[1].NameColor.red();
2611 params.gtNameColorGY = anAxisData[1].NameColor.green();
2612 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2613 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2614 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2615 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2616 params.gtDrawValuesX = anAxisData[0].DrawValues;
2617 params.gtDrawValuesY = anAxisData[1].DrawValues;
2618 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2619 params.gtNbValuesX = anAxisData[0].NbValues;
2620 params.gtNbValuesY = anAxisData[1].NbValues;
2621 params.gtNbValuesZ = anAxisData[2].NbValues;
2622 params.gtOffsetX = anAxisData[0].Offset;
2623 params.gtOffsetY = anAxisData[1].Offset;
2624 params.gtOffsetZ = anAxisData[2].Offset;
2625 params.gtColorRX = anAxisData[0].Color.red();
2626 params.gtColorGX = anAxisData[0].Color.green();
2627 params.gtColorBX = anAxisData[0].Color.blue();
2628 params.gtColorRY = anAxisData[1].Color.red();
2629 params.gtColorGY = anAxisData[1].Color.green();
2630 params.gtColorBY = anAxisData[1].Color.blue();
2631 params.gtColorRZ = anAxisData[2].Color.red();
2632 params.gtColorGZ = anAxisData[2].Color.green();
2633 params.gtColorBZ = anAxisData[2].Color.blue();
2634 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2635 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2636 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2637 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2638 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2639 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2645 \brief Get visual parameters of this view window.
2646 \return visual parameters of view window
2648 QString OCCViewer_ViewWindow::getVisualParameters()
2650 viewAspect params = getViewParams();
2654 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2655 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2656 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2657 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2658 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2659 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2660 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2661 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2662 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2663 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2664 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2665 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2666 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2667 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2668 data << QString( "isVisible=%1" ).arg( params.isVisible );
2669 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2671 ClipPlanesList aPlanes = myModel->getClipPlanes();
2672 for ( int i=0; i < aPlanes.size(); i++ )
2674 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2675 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2676 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2677 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2678 switch ( aPlane.Mode )
2680 case OCCViewer_ClipPlane::Absolute :
2682 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2684 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2686 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2687 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2688 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2692 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2697 case OCCViewer_ClipPlane::Relative :
2699 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2700 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2701 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2706 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2707 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2708 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2709 data << ClippingPlane;
2712 // graduated trihedron
2713 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2714 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2715 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2716 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2717 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2718 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2719 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2720 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2721 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2722 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2723 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2724 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2725 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2726 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2727 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2728 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2729 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2730 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2731 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2732 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2733 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2734 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2735 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2736 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2737 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2738 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2739 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2740 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2741 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2742 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2743 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2744 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2745 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2746 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2747 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2748 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2749 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2750 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2751 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2752 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2754 // ray tracing parameters
2755 Graphic3d_RenderingParams rendParams = this->getViewPort()->getView()->RenderingParams();
2756 if ( rendParams.Method == Graphic3d_RM_RAYTRACING ) {
2757 QString RayTracing = "rayTracing=";
2758 RayTracing += QString( "rtDepth~%1;" ).arg( rendParams.RaytracingDepth );
2759 RayTracing += QString( "rtReflection~%1;" ).arg( rendParams.IsReflectionEnabled );
2760 RayTracing += QString( "rtAntialiasing~%1;" ).arg( rendParams.IsAntialiasingEnabled );
2761 RayTracing += QString( "rtShadow~%1;" ).arg( rendParams.IsShadowEnabled );
2762 RayTracing += QString( "rtTransShadow~%1;" ).arg( rendParams.IsTransparentShadowEnabled );
2766 // environment texture parameters
2767 Handle(Graphic3d_TextureEnv) aTexture = this->getViewPort()->getView()->TextureEnv();
2768 if ( !aTexture.IsNull() ) {
2769 QString EnvTexture = "envTexture=";
2770 if ( aTexture->Name() == Graphic3d_NOT_ENV_UNKNOWN ) {
2771 TCollection_AsciiString aFileName;
2772 aTexture->Path().SystemName( aFileName );
2773 EnvTexture += QString( "etFile~%1;" ).arg( aFileName.ToCString() );
2776 EnvTexture += QString( "etNumber~%1;" ).arg( aTexture->Name() );
2780 // light source parameters
2781 myModel->getViewer3d()->InitDefinedLights();
2782 while ( myModel->getViewer3d()->MoreDefinedLights() )
2784 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2785 if ( aLight->Type() != V3d_AMBIENT ) {
2786 QString LightSource = QString( "lightSource=" );
2787 LightSource += QString( "lightType~%1;" ).arg( aLight->Type() );
2789 if ( aLight->Type() == V3d_DIRECTIONAL )
2790 Handle(V3d_DirectionalLight)::DownCast( aLight )->Direction( aX, aY, aZ );
2791 else if ( aLight->Type() == V3d_POSITIONAL )
2792 Handle(V3d_PositionalLight)::DownCast( aLight )->Position( aX, aY, aZ );
2793 LightSource += QString( "lightX~%1;" ).arg( aX );
2794 LightSource += QString( "lightY~%1;" ).arg( aY );
2795 LightSource += QString( "lightZ~%1;" ).arg( aZ );
2796 LightSource += QString( "lightColorR~%1;" ).arg( aLight->Color().Red() );
2797 LightSource += QString( "lightColorG~%1;" ).arg( aLight->Color().Green() );
2798 LightSource += QString( "lightColorB~%1;" ).arg( aLight->Color().Blue() );
2799 LightSource += QString( "lightHeadlight~%1;" ).arg( aLight->Headlight() );
2800 data << LightSource;
2802 myModel->getViewer3d()->NextDefinedLights();
2805 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2806 data << QString( "background=%1" ).arg( bg );
2808 return data.join("*");
2812 \brief Restore visual parameters of the view window.
2813 \param parameters visual parameters of view window
2815 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2818 ClipPlanesList aClipPlanes;
2819 QStringList data = parameters.split( '*' );
2820 Qtx::BackgroundData bgData;
2821 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2823 foreach( QString param, data ) {
2824 QString paramName = param.section( '=', 0, 0 ).trimmed();
2825 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2826 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2827 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2828 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2829 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2830 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2831 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2832 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2833 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2834 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2835 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2836 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2837 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2838 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2839 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2840 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2841 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2842 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2843 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2844 else if ( paramName.contains( "ClippingPlane" ) )
2846 QStringList ClipPlaneData = paramValue.split( ';' );
2847 OCCViewer_ClipPlane aPlane;
2848 foreach( QString ClipPlaneParam, ClipPlaneData )
2850 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2851 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2852 if ( ClipPlane_paramName == "Mode" )
2854 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2856 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2857 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2858 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2859 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2862 switch ( aPlane.Mode )
2864 case OCCViewer_ClipPlane::Absolute :
2865 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2866 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2867 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2868 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2869 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2872 case OCCViewer_ClipPlane::Relative :
2873 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2874 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2875 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2880 aClipPlanes.push_back(aPlane);
2882 // graduated trihedron
2883 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2884 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2885 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2886 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2887 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2888 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2889 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2890 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2891 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2892 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2893 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2894 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2895 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2896 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2897 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2898 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2899 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2900 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2901 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2902 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2903 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2904 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2905 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2906 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2907 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2908 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2909 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2910 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2911 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2912 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2913 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2914 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2915 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2916 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2917 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2918 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2919 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2920 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2921 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2922 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2923 else if ( paramName == "rayTracing" )
2925 Graphic3d_RenderingParams& rendParams = this->getViewPort()->getView()->ChangeRenderingParams();
2926 rendParams.Method = Graphic3d_RM_RAYTRACING;
2927 QStringList rtData = paramValue.split( ';' );
2928 foreach( QString rtParam, rtData )
2930 QString rt_paramName = rtParam.section( '~', 0, 0 ).trimmed();
2931 QString rt_paramValue = rtParam.section( '~', 1, 1 ).trimmed();
2932 if ( rt_paramName == "rtDepth" ) rendParams.RaytracingDepth = rt_paramValue.toInt();
2933 else if ( rt_paramName == "rtReflection" ) rendParams.IsReflectionEnabled = rt_paramValue.toInt();
2934 else if ( rt_paramName == "rtAntialiasing" ) rendParams.IsAntialiasingEnabled = rt_paramValue.toInt();
2935 else if ( rt_paramName == "rtShadow" ) rendParams.IsShadowEnabled = rt_paramValue.toInt();
2936 else if ( rt_paramName == "rtTransShadow" ) rendParams.IsTransparentShadowEnabled = rt_paramValue.toInt();
2939 else if ( paramName == "envTexture" )
2941 Handle(Graphic3d_TextureEnv) aTexture;
2942 QStringList etData = paramValue.split( ';' );
2943 foreach( QString etParam, etData )
2945 QString et_paramName = etParam.section( '~', 0, 0 ).trimmed();
2946 QString et_paramValue = etParam.section( '~', 1, 1 ).trimmed();
2947 if ( et_paramName == "etNumber" )
2948 aTexture = new Graphic3d_TextureEnv( Graphic3d_NameOfTextureEnv( et_paramValue.toInt() ) );
2949 else if ( et_paramName == "etFile" )
2950 aTexture = new Graphic3d_TextureEnv( TCollection_AsciiString( et_paramValue.toStdString().c_str() ) );
2951 Handle(V3d_View) aView = this->getViewPort()->getView();
2952 aView->SetTextureEnv( aTexture );
2955 else if ( paramName == "lightSource" )
2957 myModel->getViewer3d()->InitDefinedLights();
2958 while ( myModel->getViewer3d()->MoreDefinedLights() )
2960 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2961 if( aLight->Type() != V3d_AMBIENT ) {
2962 myModel->getViewer3d()->DelLight( aLight );
2963 myModel->getViewer3d()->InitDefinedLights();
2965 myModel->getViewer3d()->NextDefinedLights();
2970 V3d_TypeOfLight aType;
2972 QStringList lsData = paramValue.split( ';' );
2973 foreach( QString lsParam, lsData )
2975 QString ls_paramName = lsParam.section( '~', 0, 0 ).trimmed();
2976 QString ls_paramValue = lsParam.section( '~', 1, 1 ).trimmed();
2977 if ( ls_paramName == "lightType" ) aType = V3d_TypeOfLight( ls_paramValue.toInt() );
2978 else if ( ls_paramName == "lightX" ) aX = ls_paramValue.toDouble();
2979 else if ( ls_paramName == "lightY" ) aY = ls_paramValue.toDouble();
2980 else if ( ls_paramName == "lightZ" ) aZ = ls_paramValue.toDouble();
2981 else if ( ls_paramName == "lightColorR" ) cR = ls_paramValue.toDouble();
2982 else if ( ls_paramName == "lightColorG" ) cG = ls_paramValue.toDouble();
2983 else if ( ls_paramName == "lightColorB" ) cB = ls_paramValue.toDouble();
2984 else if ( ls_paramName == "lightHeadlight" ) isHeadlight = ls_paramValue.toInt();
2986 Quantity_Color aColor = Quantity_Color( cR, cG, cB, Quantity_TOC_RGB );
2987 if( aType == V3d_DIRECTIONAL ) {
2988 Handle(V3d_DirectionalLight) aLight = new V3d_DirectionalLight();
2989 myModel->getViewer3d()->AddLight( aLight );
2990 aLight->SetDirection( aX, aY, aZ );
2991 aLight->SetColor( aColor );
2992 aLight->SetHeadlight( isHeadlight );
2993 myModel->getViewer3d()->SetLightOn( aLight );
2995 else if( aType == V3d_POSITIONAL ) {
2996 Handle(V3d_PositionalLight) aLight = new V3d_PositionalLight( gp_Pnt(aX, aY, aZ), aColor.Name() );
2997 myModel->getViewer3d()->AddLight( aLight );
2998 aLight->SetHeadlight( isHeadlight );
2999 myModel->getViewer3d()->SetLightOn( aLight );
3002 else if ( paramName == "background" ) {
3003 QString bg = paramValue.replace( "$", "=" );
3004 bgData = Qtx::stringToBackground( bg );
3008 else // old format - "1.000e+00*0.000e+00..."
3011 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
3012 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
3013 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
3014 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
3015 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
3016 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
3017 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
3018 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
3019 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
3020 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
3021 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
3022 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
3023 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
3024 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
3025 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
3026 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
3027 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
3028 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
3030 performRestoring( params );
3031 setBackground( bgData );
3032 myModel->setClipPlanes(aClipPlanes);
3036 \brief Handle show event.
3038 Emits Show() signal.
3040 \param theEvent show event
3042 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
3044 emit Show( theEvent );
3048 \brief Handle hide event.
3050 Emits Hide() signal.
3052 \param theEvent hide event
3054 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
3056 emit Hide( theEvent );
3061 Save old cursor. [ protected ]
3063 void OCCViewer_ViewWindow::saveCursor()
3065 QCursor* aCursor = NULL;
3067 aCursor = myViewPort->getDefaultCursor();
3068 myCursor = ( aCursor ? *aCursor : cursor() );
3073 Creates default sketcher. [ virtual protected ]
3075 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
3078 return new OCCViewer_RectSketcher( this, type );
3079 if ( type == Polygon )
3080 return new OCCViewer_PolygonSketcher( this, type );
3084 void OCCViewer_ViewWindow::initSketchers()
3086 if ( mySketchers.isEmpty() )
3088 mySketchers.append( createSketcher( Rect ) );
3089 mySketchers.append( createSketcher( Polygon ) );
3093 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ ) const
3095 OCCViewer_ViewSketcher* sketcher = 0;
3096 QList<OCCViewer_ViewSketcher*>::ConstIterator it;
3097 for ( it = mySketchers.cbegin(); it != mySketchers.cend() && !sketcher; ++it )
3099 OCCViewer_ViewSketcher* sk = (*it);
3100 if ( sk->type() == typ )
3107 Handles requests for sketching in the active view. [ virtual public ]
3109 void OCCViewer_ViewWindow::activateSketching( int type )
3111 OCCViewer_ViewPort3d* vp = getViewPort();
3115 if ( !vp->isSketchingEnabled() )
3118 /* Finish current sketching */
3119 if ( type == NoSketching )
3123 onSketchingFinished();
3124 mypSketcher->deactivate();
3128 /* Activate new sketching */
3131 activateSketching( NoSketching ); /* concurrency not suported */
3132 mypSketcher = getSketcher( type );
3135 mypSketcher->activate();
3136 onSketchingStarted();
3142 Unhilights detected entities. [ virtual protected ]
3144 void OCCViewer_ViewWindow::onSketchingStarted()
3149 Selection by rectangle or polygon. [ virtual protected ]
3151 void OCCViewer_ViewWindow::onSketchingFinished()
3153 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
3154 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
3156 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
3157 bool append = mypSketcher->isHasShift();
3158 switch( mypSketcher->type() )
3162 QRect* aRect = (QRect*)mypSketcher->data();
3163 // Use rectangle selection only if the rect has a reasonable size
3164 // If it is too small then it is very probably tremor of a mouse pointer
3165 if ( aRect && OCCViewer::overThreshold( *aRect ) )
3167 int aLeft = aRect->left();
3168 int aRight = aRect->right();
3169 int aTop = aRect->top();
3170 int aBottom = aRect->bottom();
3174 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False);
3176 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False);
3182 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
3185 QRect aRect = aPolygon->boundingRect();
3186 if ( OCCViewer::overThreshold( aRect ) ) {
3187 int size = aPolygon->size();
3188 TColgp_Array1OfPnt2d anArray(1, size);
3190 QPolygon::Iterator it = aPolygon->begin();
3191 QPolygon::Iterator itEnd = aPolygon->end();
3192 for (int index = 1; it != itEnd; ++it, index++)
3194 QPoint aPoint = *it;
3195 anArray.SetValue(index, gp_Pnt2d(aPoint.x(), aPoint.y()));
3199 ic->ShiftSelect(anArray, getViewPort()->getView(), Standard_False);
3201 ic->Select(anArray, getViewPort()->getView(), Standard_False);
3210 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
3211 aViewMgr->getOCCViewer()->performSelectionChanged();
3212 aViewMgr->getOCCViewer()->doNotSelect();
3216 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
3221 bool OCCViewer_ViewWindow::transformRequested() const
3223 return ( myOperation != NOVIEWOP );
3226 bool OCCViewer_ViewWindow::transformInProcess() const
3228 return myEventStarted;
3231 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
3233 myEventStarted = bOn;
3237 Set enabled state of transformation (rotate, zoom, etc)
3239 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
3241 if ( id != NOVIEWOP ) myStatus.insert( id, on );
3245 \return enabled state of transformation (rotate, zoom, etc)
3247 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
3249 return myStatus.contains( id ) ? myStatus[ id ] : true;
3252 void OCCViewer_ViewWindow::onMaximizedView()
3254 setMaximized(!isMaximized());
3257 void OCCViewer_ViewWindow::returnTo3dView()
3259 setReturnedTo3dView( true );
3262 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
3264 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
3265 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
3266 if ( !isVisible3dView )
3267 toolMgr()->show( ReturnTo3dViewId );
3269 toolMgr()->hide( ReturnTo3dViewId );
3270 if ( isVisible3dView ) emit returnedTo3d( );
3274 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
3276 QAction* anAction = toolMgr()->action( MaximizedId );
3277 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
3278 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
3280 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
3281 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
3282 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
3283 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
3284 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
3286 emit maximized( this, true );
3290 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
3291 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
3292 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
3293 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
3294 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
3296 emit maximized( this, false );
3301 bool OCCViewer_ViewWindow::isMaximized() const
3303 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
3306 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
3308 IsSketcherStyle = enable;
3311 bool OCCViewer_ViewWindow::isSketcherStyle() const
3313 return IsSketcherStyle;
3317 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
3322 int OCCViewer_ViewWindow::projectionType() const
3324 int mode = Orthographic;
3325 Handle(V3d_View) aView3d = myViewPort->getView();
3326 if ( !aView3d.IsNull() ) {
3327 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3328 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Perspective)
3330 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Orthographic)
3331 mode = Orthographic;
3332 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
3338 void OCCViewer_ViewWindow::setStereoType( int type )
3340 Handle(V3d_View) aView3d = myViewPort->getView();
3341 if ( !aView3d.IsNull() ) {
3342 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3343 aParams->StereoMode = (Graphic3d_StereoMode)type;
3347 int OCCViewer_ViewWindow::stereoType() const
3349 int type = QuadBuffer;
3350 Handle(V3d_View) aView3d = myViewPort->getView();
3351 if ( !aView3d.IsNull() ) {
3352 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3353 type = (OCCViewer_ViewWindow::StereoType)aParams->StereoMode;
3358 void OCCViewer_ViewWindow::setAnaglyphFilter( int type )
3360 Handle(V3d_View) aView3d = myViewPort->getView();
3361 if ( !aView3d.IsNull() ) {
3362 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3363 if (type == RedCyan)
3364 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
3365 if (type == YellowBlue)
3366 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
3367 if (type == GreenMagenta)
3368 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
3372 int OCCViewer_ViewWindow::anaglyphFilter() const
3375 Handle(V3d_View) aView3d = myViewPort->getView();
3376 if ( !aView3d.IsNull() ) {
3377 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3378 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized)
3380 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized)
3382 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple)
3383 type = GreenMagenta;
3388 void OCCViewer_ViewWindow::setStereographicFocus( int type, double value )
3390 Handle(V3d_View) aView3d = myViewPort->getView();
3391 if ( !aView3d.IsNull() ) {
3392 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3393 aCamera->SetZFocus( (Graphic3d_Camera::FocusType) type, value );
3397 int OCCViewer_ViewWindow::stereographicFocusType() const
3399 int type = Relative;
3400 Handle(V3d_View) aView3d = myViewPort->getView();
3401 if ( !aView3d.IsNull() ) {
3402 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3403 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->ZFocusType();
3408 double OCCViewer_ViewWindow::stereographicFocusValue() const
3411 Handle(V3d_View) aView3d = myViewPort->getView();
3412 if ( !aView3d.IsNull() ) {
3413 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3414 value = aCamera->ZFocus();
3419 void OCCViewer_ViewWindow::setInterocularDistance( int type, double value )
3421 Handle(V3d_View) aView3d = myViewPort->getView();
3422 if ( !aView3d.IsNull() ) {
3423 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3424 aCamera->SetIOD( (Graphic3d_Camera::IODType) type, value );
3428 int OCCViewer_ViewWindow::interocularDistanceType() const
3430 int type = Relative;
3431 Handle(V3d_View) aView3d = myViewPort->getView();
3432 if ( !aView3d.IsNull() ) {
3433 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3434 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->GetIODType();
3439 double OCCViewer_ViewWindow::interocularDistanceValue() const
3441 double value = 0.05;
3442 Handle(V3d_View) aView3d = myViewPort->getView();
3443 if ( !aView3d.IsNull() ) {
3444 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3445 value = aCamera->IOD();
3450 void OCCViewer_ViewWindow::setReverseStereo( bool reverse )
3452 Handle(V3d_View) aView3d = myViewPort->getView();
3453 if ( !aView3d.IsNull() ) {
3454 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3455 aParams->ToReverseStereo = reverse;
3459 bool OCCViewer_ViewWindow::isReverseStereo() const
3461 int reverse = false;
3462 Handle(V3d_View) aView3d = myViewPort->getView();
3463 if ( !aView3d.IsNull() ) {
3464 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3465 reverse = aParams->ToReverseStereo;
3470 void OCCViewer_ViewWindow::setVSync( bool enable )
3472 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3473 if ( !anIntCont.IsNull() ) {
3474 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3475 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3476 aCaps->swapInterval = enable;
3480 bool OCCViewer_ViewWindow::isVSync() const
3483 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3484 if ( !anIntCont.IsNull() ) {
3485 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3486 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3487 enable = aCaps->swapInterval;
3492 void OCCViewer_ViewWindow::setQuadBufferSupport( bool enable )
3494 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3495 if ( !anIntCont.IsNull() ) {
3496 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3497 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3498 aCaps->contextStereo = enable;
3502 bool OCCViewer_ViewWindow::isQuadBufferSupport() const
3505 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3506 if ( !anIntCont.IsNull() ) {
3507 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3508 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3509 enable = aCaps->contextStereo;
3514 bool OCCViewer_ViewWindow::isOpenGlStereoSupport() const
3516 GLboolean support[1];
3517 glGetBooleanv (GL_STEREO, support);
3524 QColor OCCViewer_ViewWindow::backgroundColor() const
3526 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
3530 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
3532 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
3535 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
3537 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
3540 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
3542 if ( myViewPort ) myViewPort->setBackground( theBackground );
3545 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
3547 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
3553 void OCCViewer_ViewWindow::clearViewAspects()
3555 myViewAspects.clear();
3559 \return const reference to list of view aspects
3561 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
3563 return myViewAspects;
3567 Appends new view aspect
3568 \param aParams - new view aspects
3570 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
3572 myViewAspects.append( aParams );
3576 Replaces old view aspects by new ones
3577 \param aViewList - list of new view aspects
3579 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
3581 myViewAspects = aViewList;
3585 Get camera properties for the OCC view window.
3586 \return shared pointer on camera properties.
3588 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
3590 SUIT_CameraProperties aProps;
3592 Handle(V3d_View) aSourceView = getViewPort()->getView();
3593 if ( aSourceView.IsNull() )
3596 if ( get2dMode() == No2dMode ) {
3597 aProps.setDimension( SUIT_CameraProperties::Dim3D );
3600 aProps.setDimension( SUIT_CameraProperties::Dim2D );
3601 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
3604 // read common properites of the view
3605 Standard_Real anUp[3];
3606 Standard_Real anAt[3];
3607 Standard_Real anEye[3];
3608 Standard_Real aProj[3];
3609 Standard_Real anAxialScale[3];
3611 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
3612 aSourceView->At( anAt[0], anAt[1], anAt[2] );
3613 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
3614 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3616 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3617 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
3619 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
3621 // store camera properties "as is": it is up to synchronized
3622 // view classes to provide necessary property conversion.
3623 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
3624 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
3626 if ( aSourceView->Camera()->IsOrthographic() )
3628 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
3629 aProps.setViewAngle( 0.0 );
3633 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
3634 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
3636 aProps.setMappingScale( aSourceView->Camera()->Scale() );
3643 This implementation synchronizes OCC view's camera propreties.
3645 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
3647 bool blocked = blockSignals( true );
3649 SUIT_CameraProperties aProps = theView->cameraProperties();
3650 if ( !cameraProperties().isCompatible( aProps ) ) {
3651 // other view, this one is being currently synchronized to, seems has become incompatible
3652 // we have to break synchronization
3657 Handle(V3d_View) aDestView = getViewPort()->getView();
3659 aDestView->SetImmediateUpdate( Standard_False );
3662 double aPosition[3];
3663 double aFocalPoint[3];
3664 double anAxialScale[3];
3666 // get common properties
3667 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3668 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
3669 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3670 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3672 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3673 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
3674 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3675 aDestView->Camera()->SetScale( aProps.getMappingScale() );
3677 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3678 aDestView->SetImmediateUpdate( Standard_True );
3679 aDestView->Redraw();
3681 blockSignals( blocked );
3685 \brief Indicates whether preselection is enabled
3686 \return true if preselection is enabled
3688 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
3690 return myPreselectionEnabled;
3694 \brief Enables/disables preselection
3695 \param theIsToEnable if true - preselection will be enabled
3697 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
3699 onSwitchPreselection( theIsToEnable );
3703 \brief Indicates whether selection is enabled
3704 \return true if selection is enabled
3706 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3708 return mySelectionEnabled;
3712 \brief Enables/disables selection
3713 \param theIsToEnable if true - selection will be enabled
3715 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3717 onSwitchSelection( theIsToEnable );
3722 \brief called if clipping operation is activated / deactivated.
3724 Enables/disables clipping plane displaying.
3726 \parma on action state
3728 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3730 if(!myModel) return;
3731 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3734 if (!aClippingDlg) {
3735 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3736 myModel->setClippingDlg(aClippingDlg);
3738 if (!aClippingDlg->isVisible())
3739 aClippingDlg->show();
3741 if ( aClippingDlg ) {
3742 aClippingDlg->close();
3743 myModel->setClippingDlg(0);
3747 SUIT_ViewManager* mgr = getViewManager();
3749 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3750 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3751 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3752 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3754 QAction* a = toolMgr()->action( ClippingId );
3756 if(theIsOn != a->isChecked()){
3757 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3758 a->setChecked(theIsOn);
3759 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3766 void OCCViewer_ViewWindow::onRayTracing()
3768 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_RayTracingDlg::getName() ) ) {
3769 QDialog* aDlg = new OCCViewer_RayTracingDlg( this );
3775 void OCCViewer_ViewWindow::onEnvTexture()
3777 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_EnvTextureDlg::getName() ) ) {
3778 QDialog* aDlg = new OCCViewer_EnvTextureDlg( this );
3784 void OCCViewer_ViewWindow::onLightSource()
3786 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_LightSourceDlg::getName() ) ) {
3787 QDialog* aDlg = new OCCViewer_LightSourceDlg( this, myModel );
3793 bool OCCViewer_ViewWindow::isActionVisible( ActionId theId ) const
3795 QAction* a = toolMgr()->action( theId );
3796 return a && a->isVisible();
3799 void OCCViewer_ViewWindow::setActionVisible( ActionId theId, bool isVisible )
3801 QAction* a = toolMgr()->action( theId );
3803 a->setVisible( isVisible );
3806 void OCCViewer_ViewWindow::projAndPanToGravity(V3d_TypeOfOrientation CamOri)
3808 const bool USE_XY = true;
3810 Handle(V3d_View) aView3d = myViewPort->getView();
3811 if (aView3d.IsNull())
3815 double X = 0, Y = 0, Z = 0;
3818 const double EPS = 1E-6;
3819 int xp = myViewPort->width()/2, yp = myViewPort->height()/2, xp1, yp1;
3820 aView3d->Convert( xp, yp, X, Y, Z );
3822 gp_Dir d = aView3d->Camera()->Direction();
3823 if( fabs( d.Z() ) > EPS )
3825 double t = -Z/d.Z();
3832 // It is really necessary to compute gravity center even if it is not used in part of code below.
3833 // Without this calculation the SetProj() method and other methods are not correct.
3835 IsGr = computeGravityCenter(X2, Y2, Z2);
3837 IsGr = OCCViewer_Utilities::computeSceneBBCenter(aView3d, X2, Y2, Z2);
3839 aView3d->SetProj(CamOri);
3842 //aView3d->Update();
3843 Handle(Graphic3d_Camera) Cam = aView3d->Camera();
3845 gp_Vec dir (Cam->Direction());
3846 gp_Pnt eye = Cam->Eye();
3848 Standard_Real D = dir.Dot(V1);
3849 gp_Pnt ppdir = eye.Translated(D*dir);
3850 gp_Vec V2(ppdir, gp);
3851 gp_XYZ trEye = eye.XYZ() + V2.XYZ();
3853 double xat, yat, zat;
3854 aView3d->At(xat, yat, zat);
3855 gp_Pnt At(xat, yat, zat);
3856 gp_XYZ trAt = At.XYZ() + V2.XYZ();
3857 aView3d->SetEye(trEye.X(), trEye.Y(), trEye.Z());
3858 aView3d->SetAt(trAt.X(), trAt.Y(), trAt.Z());
3863 bool OCCViewer_ViewWindow::isAutomaticZoom() const
3865 return myAutomaticZoom;
3868 void OCCViewer_ViewWindow::setAutomaticZoom(const bool isOn)
3870 myAutomaticZoom = isOn;