1 // Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : OCCViewer_ViewWindow.cxx
26 #include "OCCViewer_ViewWindow.h"
27 #include "OCCViewer_ViewFrame.h"
28 #include "OCCViewer_ViewModel.h"
29 #include "OCCViewer_ViewPort3d.h"
30 #include "OCCViewer_ViewManager.h"
31 #include "OCCViewer_ViewSketcher.h"
32 #include "OCCViewer_CreateRestoreViewDlg.h"
33 #include "OCCViewer_ClipPlane.h"
34 #include "OCCViewer_SetRotationPointDlg.h"
35 #include "OCCViewer_AutoRotate.h"
36 #include "OCCViewer_AxialScaleDlg.h"
37 #include "OCCViewer_CubeAxesDlg.h"
38 #include "OCCViewer_ClippingDlg.h"
39 #include "OCCViewer_RayTracingDlg.h"
40 #include "OCCViewer_EnvTextureDlg.h"
41 #include "OCCViewer_LightSourceDlg.h"
42 #include "OCCViewer_Utilities.h"
43 #include "ViewerTools_ScreenScaling.h"
45 #include <SUIT_Desktop.h>
46 #include <SUIT_Session.h>
47 #include <SUIT_ViewManager.h>
48 #include <SUIT_Tools.h>
49 #include <SUIT_ResourceMgr.h>
50 #include <SUIT_MessageBox.h>
51 #include <SUIT_Application.h>
53 #include <QtxActionToolMgr.h>
54 #include <QtxMultiAction.h>
55 #include <QtxRubberBand.h>
61 #include <QMouseEvent>
62 #include <QApplication>
63 #include <QActionGroup>
66 #include <AIS_ListOfInteractive.hxx>
67 #include <AIS_ListIteratorOfListOfInteractive.hxx>
68 #include <AIS_Shape.hxx>
70 #include <BRep_Tool.hxx>
71 #include <BRepBndLib.hxx>
72 #include <BRepGProp.hxx>
73 #include <GProp_GProps.hxx>
76 #include <Graphic3d_SequenceOfHClipPlane.hxx>
77 #include <Graphic3d_ClipPlane.hxx>
78 #include <OpenGl_GraphicDriver.hxx>
79 #include <OpenGLUtils_FrameBuffer.h>
80 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
81 #include <Graphic3d_MapOfStructure.hxx>
82 #include <Graphic3d_Structure.hxx>
83 #include <Graphic3d_StereoMode.hxx>
84 #include <Graphic3d_RenderingParams.hxx>
85 #include <Graphic3d_BndBox3d.hxx>
87 #include <V3d_Plane.hxx>
88 #include <V3d_Light.hxx>
92 #include <gp_GTrsf.hxx>
93 #include <TColgp_Array1OfPnt2d.hxx>
95 #include <Image_PixMap.hxx>
97 #include <Standard_Version.hxx>
98 #include <Standard_Failure.hxx>
100 #include "utilities.h"
102 // // OpenCV includes
104 // #include <highgui.h>
106 static QEvent* l_mbPressEvent = 0;
109 //# include <QWindowsStyle>
113 #include <OpenGL/gl.h>
118 // To avoid conflict between KeyPress from the X.h (define KeyPress 2)
119 // and QEvent::KeyPress (qevent.h)
129 // Enable ray tracing features
130 #define ENABLE_RAY_TRACING
132 const char* imageZoomCursor[] = {
137 "................................",
138 "................................",
139 ".#######........................",
140 "..aaaaaaa.......................",
141 "................................",
142 ".............#####..............",
143 "...........##.aaaa##............",
144 "..........#.aa.....a#...........",
145 ".........#.a.........#..........",
146 ".........#a..........#a.........",
147 "........#.a...........#.........",
148 "........#a............#a........",
149 "........#a............#a........",
150 "........#a............#a........",
151 "........#a............#a........",
152 ".........#...........#.a........",
153 ".........#a..........#a.........",
154 ".........##.........#.a.........",
155 "........#####.....##.a..........",
156 ".......###aaa#####.aa...........",
157 "......###aa...aaaaa.......#.....",
158 ".....###aa................#a....",
159 "....###aa.................#a....",
160 "...###aa...............#######..",
161 "....#aa.................aa#aaaa.",
162 ".....a....................#a....",
163 "..........................#a....",
164 "...........................a....",
165 "................................",
166 "................................",
167 "................................",
168 "................................"};
170 const char* imageRotateCursor[] = {
175 "................................",
176 "................................",
177 "................................",
178 "................................",
179 "........#.......................",
180 ".......#.a......................",
181 "......#######...................",
182 ".......#aaaaa#####..............",
183 "........#..##.a#aa##........##..",
184 ".........a#.aa..#..a#.....##.aa.",
185 ".........#.a.....#...#..##.aa...",
186 ".........#a.......#..###.aa.....",
187 "........#.a.......#a..#aa.......",
188 "........#a.........#..#a........",
189 "........#a.........#a.#a........",
190 "........#a.........#a.#a........",
191 "........#a.........#a.#a........",
192 ".........#.........#a#.a........",
193 "........##a........#a#a.........",
194 "......##.a#.......#.#.a.........",
195 "....##.aa..##.....##.a..........",
196 "..##.aa.....a#####.aa...........",
197 "...aa.........aaa#a.............",
198 "................#.a.............",
199 "...............#.a..............",
200 "..............#.a...............",
201 "...............a................",
202 "................................",
203 "................................",
204 "................................",
205 "................................",
206 "................................"};
208 const char* imageCrossCursor[] = {
213 "................................",
214 "................................",
215 "................................",
216 "................................",
217 "................................",
218 "................................",
219 "................................",
220 "...............#................",
221 "...............#a...............",
222 "...............#a...............",
223 "...............#a...............",
224 "...............#a...............",
225 "...............#a...............",
226 "...............#a...............",
227 "...............#a...............",
228 ".......#################........",
229 "........aaaaaaa#aaaaaaaaa.......",
230 "...............#a...............",
231 "...............#a...............",
232 "...............#a...............",
233 "...............#a...............",
234 "...............#a...............",
235 "...............#a...............",
236 "...............#a...............",
237 "................a...............",
238 "................................",
239 "................................",
240 "................................",
241 "................................",
242 "................................",
243 "................................",
244 "................................"};
249 \param theDesktop main window of application
250 \param theModel OCC 3D viewer
252 OCCViewer_ViewWindow::OCCViewer_ViewWindow( SUIT_Desktop* theDesktop,
253 OCCViewer_Viewer* theModel )
254 : 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()
290 if (myAutoRotate) delete myAutoRotate;
292 qDeleteAll( mySketchers );
296 \brief Internal initialization.
298 void OCCViewer_ViewWindow::initLayout()
300 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
301 myViewPort->installEventFilter(this);
302 setCentralWidget(myViewPort);
303 myOperation = NOVIEWOP;
305 myCurrPointType = BBCENTER;
306 myPrevPointType = BBCENTER;
307 mySelectedPoint = gp_Pnt(0.,0.,0.);
308 myRotationPointSelection = false;
310 setTransformRequested ( NOVIEWOP );
311 setTransformInProcess ( false );
330 // Graduated axes dialog
331 QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
332 myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
333 myCubeAxesDlg->initialize();
335 connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
338 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
340 return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
344 \brief Detect viewer operation according the the mouse button pressed
345 and key modifiers used.
346 \param theEvent mouse event
347 \return type of the operation
349 OCCViewer_ViewWindow::OperationType
350 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
352 OperationType aOp = NOVIEWOP;
353 SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
354 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
355 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
357 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
358 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
360 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
361 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
362 (my2dMode == No2dMode))
369 \brief Customize event handling
370 \param watched event receiver object
372 \return \c true if the event processing should be stopped
374 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
376 if ( watched == myViewPort ) {
377 // Makes a copy event with updated coordinates if we need so
378 e = ViewerTools_ScreenScaling::getDpiAwareEvent(e);
380 int aType = e->type();
382 case QEvent::MouseButtonPress:
383 vpMousePressEvent((QMouseEvent*) e);
386 case QEvent::MouseButtonRelease:
387 vpMouseReleaseEvent((QMouseEvent*) e);
390 case QEvent::MouseMove:
391 vpMouseMoveEvent((QMouseEvent*) e);
394 case QEvent::MouseButtonDblClick:
395 emit mouseDoubleClicked(this, (QMouseEvent*)e);
400 QWheelEvent* aEvent = (QWheelEvent*) e;
402 if ( aEvent->modifiers().testFlag(Qt::ControlModifier) ) {
403 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
404 if ( isPreselectionEnabled() ) {
405 if ( aEvent->delta() > 0 ) {
406 ic->HilightNextDetected( myViewPort->getView() );
408 ic->HilightPreviousDetected( myViewPort->getView() );
413 emit vpTransformationStarted ( ZOOMVIEW );
414 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
415 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
418 int x1 = (int)( aEvent->x() + width()*delta/100 );
419 int y1 = (int)( aEvent->y() + height()*delta/100 );
420 myViewPort->zoom( x, y, x1, y1 );
421 emit vpTransformationFinished ( ZOOMVIEW );
426 case QEvent::ContextMenu:
428 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
429 if ( aEvent->reason() != QContextMenuEvent::Mouse )
430 emit contextMenuRequested( aEvent );
434 case QEvent::KeyPress:
435 emit keyPressed(this, (QKeyEvent*) e);
438 case QEvent::KeyRelease:
439 emit keyReleased(this, (QKeyEvent*) e);
446 return SUIT_ViewWindow::eventFilter(watched, e);
450 \brief Enable / disable draw rect (rubber band) mode
452 bool OCCViewer_ViewWindow::enableDrawMode( bool on )
454 bool prev = myDrawRectEnabled;
455 myDrawRectEnabled = on;
456 updateEnabledDrawMode();
461 \brief Update state of enable draw mode state.
463 void OCCViewer_ViewWindow::updateEnabledDrawMode()
465 myEnableDrawMode = myDrawRectEnabled;
467 myEnableDrawMode = myEnableDrawMode && myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
471 \brief Handle mouse press event
472 \param theEvent mouse event
474 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
476 myStartX = theEvent->x();
477 myStartY = theEvent->y();
478 myStartTime = QDateTime::currentMSecsSinceEpoch();
479 int anInteractionStyle = interactionStyle();
481 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
482 // which are assigned for pan and rotate - these operations are activated immediately after pressing
483 // of the first button, so it is necessary to switch to zoom when the second button is pressed
484 bool aSwitchToZoom = false;
485 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
486 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
487 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
490 switch ( myOperation ) {
492 if ( theEvent->button() == Qt::LeftButton )
493 emit vpTransformationStarted ( WINDOWFIT );
497 if ( theEvent->button() == Qt::LeftButton )
498 emit vpTransformationStarted ( PANGLOBAL );
502 if ( theEvent->button() == Qt::LeftButton ) {
503 myViewPort->startZoomAtPoint( myStartX, myStartY );
504 emit vpTransformationStarted ( ZOOMVIEW );
509 if ( aSwitchToZoom ) {
510 myViewPort->startZoomAtPoint( myStartX, myStartY );
513 else if ( theEvent->button() == Qt::LeftButton )
514 emit vpTransformationStarted ( PANVIEW );
518 if ( aSwitchToZoom ) {
519 myViewPort->startZoomAtPoint( myStartX, myStartY );
522 else if ( theEvent->button() == Qt::LeftButton ) {
523 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
524 emit vpTransformationStarted ( ROTATE );
525 emit vpStartRotate(myStartX, myStartY, myStartTime);
530 /* Try to activate a transformation */
531 OperationType aState;
532 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
533 aState = getButtonState(theEvent, anInteractionStyle);
535 aState = OCCViewer_ViewWindow::NOVIEWOP;
540 myViewPort->startZoomAtPoint( myStartX, myStartY );
548 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
549 emit vpStartRotate(myStartX, myStartY, myStartTime);
552 if ( myRotationPointSelection )
554 if ( theEvent->button() == Qt::LeftButton )
556 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
557 ic->Select( Standard_True );
558 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
560 TopoDS_Shape aShape = ic->SelectedShape();
561 GProp_GProps aSystem;
563 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
565 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
567 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE )
569 BRepGProp::LinearProperties( aShape, aSystem );
570 aPnt = aSystem.CentreOfMass();
572 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE )
574 BRepGProp::SurfaceProperties( aShape, aSystem );
575 aPnt = aSystem.CentreOfMass();
577 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID )
579 BRepGProp::VolumeProperties( aShape, aSystem );
580 aPnt = aSystem.CentreOfMass();
584 myCurrPointType = myPrevPointType;
588 if ( mySetRotationPointDlg )
590 myRotationPointSelection = false;
591 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
594 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
595 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
598 myOperation = NOVIEWOP;
599 myViewPort->setCursor( myCursor );
600 myCursorIsHand = false;
601 myRotationPointSelection = false;
605 emit mousePressed(this, theEvent);
608 /* notify that we start a transformation */
609 if ( transformRequested() )
610 emit vpTransformationStarted ( myOperation );
612 if ( transformRequested() )
613 setTransformInProcess( true );
615 /* we may need it for sketching... */
616 if ( l_mbPressEvent )
617 delete l_mbPressEvent;
618 l_mbPressEvent = new QMouseEvent( *theEvent );
623 \brief Start zooming operation.
625 Sets the corresponding cursor for the widget.
627 void OCCViewer_ViewWindow::activateZoom()
629 if ( !transformRequested() && !myCursorIsHand )
630 saveCursor(); /* save old cursor */
632 if ( myOperation != ZOOMVIEW ) {
633 QPixmap zoomPixmap (imageZoomCursor);
634 QCursor zoomCursor (zoomPixmap);
635 if( setTransformRequested ( ZOOMVIEW ) )
636 myViewPort->setCursor( zoomCursor );
641 void OCCViewer_ViewWindow::onPanning()
643 OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( getViewManager() );
644 bool isChained = aMgr->isChainedOperations();
645 bool isReset = ( myPanningByBtn && isChained );
652 myPanningByBtn = true;
658 \brief Start panning operation.
660 Sets the corresponding cursor for the widget.
662 void OCCViewer_ViewWindow::activatePanning()
664 if ( !transformRequested() && !myCursorIsHand )
665 saveCursor(); // save old cursor
667 if ( myOperation != PANVIEW ) {
668 QCursor panCursor (Qt::SizeAllCursor);
669 if( setTransformRequested ( PANVIEW ) )
670 myViewPort->setCursor( panCursor );
675 \brief Start rotation operation
677 Sets the corresponding cursor for the widget.
679 void OCCViewer_ViewWindow::activateRotation()
681 if ( !transformRequested() && !myCursorIsHand )
682 saveCursor(); // save old cursor
684 if ( myOperation != ROTATE ) {
685 QPixmap rotatePixmap (imageRotateCursor);
686 QCursor rotCursor (rotatePixmap);
687 if( setTransformRequested ( ROTATE ) )
688 myViewPort->setCursor( rotCursor );
693 \brief Compute the gravity center.
694 \param theX used to return X coordinate of the gravity center
695 \param theY used to return Y coordinate of the gravity center
696 \param theZ used to return Z coordinate of the gravity center
697 \return \c true if the gravity center is computed
699 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
701 Handle(V3d_View) aView3d = myViewPort->getView();
703 // Project boundaries points and add to avergae gravity
704 // the ones which lie within the screen limits
705 Standard_Real aScreenLimits[4] = { 0.0, 0.0, 0.0, 0.0 };
707 // NDC space screen limits
708 aScreenLimits[0] = -1.0;
709 aScreenLimits[1] = 1.0;
710 aScreenLimits[2] = -1.0;
711 aScreenLimits[3] = 1.0;
713 Standard_Integer aPointsNb = 0;
715 Standard_Real aXmin = 0.0;
716 Standard_Real aYmin = 0.0;
717 Standard_Real aZmin = 0.0;
718 Standard_Real aXmax = 0.0;
719 Standard_Real aYmax = 0.0;
720 Standard_Real aZmax = 0.0;
722 Graphic3d_MapOfStructure aSetOfStructures;
723 aView3d->View()->DisplayedStructures( aSetOfStructures );
724 Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures );
726 for( ; aStructureIt.More(); aStructureIt.Next() ) {
727 const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key();
728 if ( aStructure->IsEmpty() || !aStructure->IsVisible() || aStructure->CStructure()->IsForHighlight )
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();
796 myOperation = NOVIEWOP;
797 myViewPort->setCursor( myCursor );
798 myCursorIsHand = false;
799 myRotationPointSelection = false;
802 myPrevPointType = myCurrPointType;
803 myCurrPointType = BBCENTER;
805 Standard_Real Xcenter, Ycenter, Zcenter;
806 if ( OCCViewer_Utilities::computeVisibleBBCenter( myViewPort->getView(), Xcenter, Ycenter, Zcenter ) )
807 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
811 \brief Update gravity center in the "Set Rotation Point" dialog box.
812 \sa OCCViewer_SetRotationPointDlg class
814 void OCCViewer_ViewWindow::updateGravityCoords()
816 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == BBCENTER )
818 Standard_Real Xcenter, Ycenter, Zcenter;
819 if ( OCCViewer_Utilities::computeVisibleBBCenter( myViewPort->getView(), Xcenter, Ycenter, Zcenter ) )
820 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
825 \brief Set the point selected by the user as a rotation point.
826 \param theX X coordinate of the rotation point
827 \param theY Y coordinate of the rotation point
828 \param theZ Z coordinate of the rotation point
830 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
832 if ( myRotationPointSelection )
834 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
837 myOperation = NOVIEWOP;
838 myViewPort->setCursor( myCursor );
839 myCursorIsHand = false;
840 myRotationPointSelection = false;
843 myPrevPointType = myCurrPointType;
844 myCurrPointType = SELECTED;
845 mySelectedPoint.SetCoord(theX,theY,theZ);
849 \brief Start the shape selection process.
851 void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
853 myPrevPointType = myCurrPointType;
854 myCurrPointType = SELECTED;
856 // activate selection ------>
857 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
860 AIS_ListOfInteractive aList;
861 ic->DisplayedObjects( aList );
862 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
864 Handle(AIS_InteractiveObject) anObj = it.Value();
865 if ( !anObj.IsNull() && anObj->HasPresentation() &&
866 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
869 ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
872 // activate selection <------
874 if ( !myCursorIsHand )
876 QCursor handCursor (Qt::PointingHandCursor);
877 myCursorIsHand = true;
879 myViewPort->setCursor( handCursor );
881 myRotationPointSelection = true;
885 \brief Start global panning operation
887 Sets the corresponding cursor for the widget.
889 void OCCViewer_ViewWindow::activateGlobalPanning()
891 Handle(V3d_View) aView3d = myViewPort->getView();
892 if ( !aView3d.IsNull() ) {
893 QPixmap globalPanPixmap (imageCrossCursor);
894 QCursor glPanCursor (globalPanPixmap);
895 myCurScale = aView3d->Scale();
896 aView3d->FitAll(0.01, false);
897 saveCursor(); // save old cursor
898 myViewPort->fitAll(); // fits view before selecting a new scene center
899 if( setTransformRequested( PANGLOBAL ) )
900 myViewPort->setCursor( glPanCursor );
905 \brief Starts fit operation.
907 Sets the corresponding cursor for the widget.
909 void OCCViewer_ViewWindow::activateWindowFit()
911 if ( !transformRequested() && !myCursorIsHand )
912 saveCursor(); /* save old cursor */
914 if ( myOperation != WINDOWFIT ) {
915 QCursor handCursor (Qt::PointingHandCursor);
916 if( setTransformRequested ( WINDOWFIT ) )
918 myViewPort->setCursor ( handCursor );
919 myCursorIsHand = true;
925 \brief Start delayed viewer operation.
927 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
929 bool ok = transformEnabled( op );
930 myOperation = ok ? op : NOVIEWOP;
931 myViewPort->setMouseTracking( myOperation == NOVIEWOP );
936 \brief Handle mouse move event.
937 \param theEvent mouse event
939 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
941 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
943 switch ( getButtonState( theEvent, interactionStyle() ) ) {
945 myViewPort->startZoomAtPoint( myStartX, myStartY );
953 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
954 emit vpStartRotate(myStartX, myStartY, myStartTime);
961 myCurrX = theEvent->x();
962 myCurrY = theEvent->y();
963 myCurrTime = QDateTime::currentMSecsSinceEpoch();
964 switch (myOperation) {
966 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
967 emit vpRotate(myCurrX, myCurrY, myCurrTime);
971 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
977 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
991 if ( myRotationPointSelection || isSketcherStyle() )
993 emit mouseMoving( this, theEvent );
997 int aState = theEvent->modifiers();
998 int aButton = theEvent->buttons();
999 int anInteractionStyle = interactionStyle();
1000 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
1001 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || aState == Qt::ShiftModifier ) ) ||
1002 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
1003 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
1004 myDrawRect = myEnableDrawMode;
1007 //if ( !myCursorIsHand ) { // we are going to sketch a rectangle
1008 // QCursor handCursor (Qt::PointingHandCursor);
1009 // myCursorIsHand = true;
1011 // myViewPort->setCursor( handCursor );
1014 SelectionStyle aStyle = selectionStyle();
1015 activateSketching(aStyle == RectStyle ? Rect : Polygon);
1018 if (l_mbPressEvent) {
1019 QApplication::sendEvent(getViewPort(), l_mbPressEvent);
1020 delete l_mbPressEvent;
1023 QApplication::sendEvent(getViewPort(), theEvent);
1026 emit mouseMoving( this, theEvent );
1028 //else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
1029 // aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
1030 // ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
1031 // aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
1032 // OCCViewer_ViewSketcher* sketcher = 0;
1033 // QList<OCCViewer_ViewSketcher*>::Iterator it;
1034 // for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
1036 // OCCViewer_ViewSketcher* sk = (*it);
1037 // if( sk->isDefault() && sk->sketchButton() == aButton )
1040 // if ( sketcher && myCurSketch == -1 )
1042 // activateSketching( sketcher->type() );
1043 // if ( mypSketcher )
1045 // myCurSketch = mypSketcher->sketchButton();
1047 // if ( l_mbPressEvent )
1049 // QApplication::sendEvent( getViewPort(), l_mbPressEvent );
1050 // delete l_mbPressEvent;
1051 // l_mbPressEvent = 0;
1053 // QApplication::sendEvent( getViewPort(), theEvent );
1058 emit mouseMoving( this, theEvent );
1064 \brief Handle mouse release event.
1065 \param theEvent mouse event
1067 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
1069 switch ( myOperation ) {
1072 int prevState = myCurSketch;
1073 if(theEvent->button() == Qt::RightButton)
1075 QList<OCCViewer_ViewSketcher*>::Iterator it;
1076 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
1078 OCCViewer_ViewSketcher* sk = (*it);
1079 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
1084 emit mouseReleased(this, theEvent);
1085 if(theEvent->button() == Qt::RightButton && prevState == -1)
1087 // We need to pass unscaled coordinates to get a menu painted in a right place.
1088 const double pixelRatio = ViewerTools_ScreenScaling::getPR();
1089 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1090 theEvent->pos() / pixelRatio, theEvent->globalPos() / pixelRatio );
1091 emit contextMenuRequested( &aEvent );
1096 myCurrX = theEvent->x();
1097 myCurrY = theEvent->y(),
1098 myCurrTime = QDateTime::currentMSecsSinceEpoch();
1099 myViewPort->endRotation();
1100 emit vpEndRotate(myCurrX, myCurrY, myCurrTime);
1107 OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( getViewManager() );
1108 bool isChained = aMgr->isChainedOperations();
1109 bool isReset = !( myOperation==PANVIEW && myPanningByBtn && isChained ) || theEvent->button() == Qt::RightButton;
1116 if ( theEvent->button() == Qt::LeftButton ) {
1117 myViewPort->setCenter( theEvent->x(), theEvent->y() );
1118 myViewPort->getView()->SetScale(myCurScale);
1124 if ( theEvent->button() == Qt::LeftButton ) {
1125 myCurrX = theEvent->x();
1126 myCurrY = theEvent->y();
1128 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1129 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1138 // NOTE: viewer 3D detects a rectangle of selection using this event
1139 // so we must emit it BEFORE resetting the selection rectangle
1141 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1145 myViewPort->update();
1148 if ( l_mbPressEvent ) {
1149 delete l_mbPressEvent;
1155 \brief Reset the viewport to its initial state
1156 ( no transformations in process etc. )
1158 void OCCViewer_ViewWindow::resetState()
1162 if ( myRotationPointSelection )
1164 QCursor handCursor (Qt::PointingHandCursor);
1165 myViewPort->setCursor( handCursor );
1169 if ( transformRequested() || myCursorIsHand )
1170 myViewPort->setCursor( myCursor );
1171 myCursorIsHand = false;
1174 if ( transformRequested() )
1175 emit vpTransformationFinished (myOperation);
1177 setTransformInProcess( false );
1178 setTransformRequested( NOVIEWOP );
1180 myPanningByBtn = false;
1185 \brief Draw rubber band rectangle.
1187 void OCCViewer_ViewWindow::drawRect()
1189 if ( !myRectBand ) {
1190 myRectBand = new QtxRectRubberBand( myViewPort );
1193 myRectBand->setUpdatesEnabled ( false );
1194 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1195 myRectBand->initGeometry( aRect );
1197 if ( !myRectBand->isVisible() )
1200 myRectBand->setUpdatesEnabled ( true );
1204 \brief Clear rubber band rectangle on the end on the dragging operation.
1206 void OCCViewer_ViewWindow::endDrawRect()
1209 myRectBand->clearGeometry();
1215 \brief Create actions.
1217 void OCCViewer_ViewWindow::createActions()
1219 if( !toolMgr()->isEmpty() )
1222 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1229 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1230 tr( "MNU_DUMP_VIEW" ), 0, this);
1231 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1232 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1233 toolMgr()->registerAction( aAction, DumpId );
1236 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1237 tr( "MNU_FITALL" ), 0, this);
1238 aAction->setStatusTip(tr("DSC_FITALL"));
1239 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1240 toolMgr()->registerAction( aAction, FitAllId );
1243 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1244 tr( "MNU_FITRECT" ), 0, this);
1245 aAction->setStatusTip(tr("DSC_FITRECT"));
1246 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1247 toolMgr()->registerAction( aAction, FitRectId );
1250 aAction = new QtxAction(tr("MNU_FITSELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITSELECTION" ) ),
1251 tr( "MNU_FITSELECTION" ), 0, this);
1252 aAction->setStatusTip(tr("DSC_FITSELECTION"));
1253 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
1254 toolMgr()->registerAction( aAction, FitSelectionId );
1257 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1258 tr( "MNU_ZOOM_VIEW" ), 0, this);
1259 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1260 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1261 toolMgr()->registerAction( aAction, ZoomId );
1264 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1265 tr( "MNU_PAN_VIEW" ), 0, this);
1266 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1267 connect(aAction, SIGNAL(triggered()), this, SLOT(onPanning()));
1268 toolMgr()->registerAction( aAction, PanId );
1271 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1272 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1273 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1274 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1275 toolMgr()->registerAction( aAction, GlobalPanId );
1278 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1279 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1280 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1281 mySetRotationPointAction->setCheckable( true );
1282 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1283 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1286 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1287 tr( "MNU_ROTATE_VIEW" ), 0, this);
1288 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1289 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1290 toolMgr()->registerAction( aAction, RotationId );
1293 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1294 tr( "MNU_FRONT_VIEW" ), 0, this, false, "/#Viewers/View/Set X-");
1295 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1296 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1297 this->addAction(aAction);
1298 toolMgr()->registerAction( aAction, FrontId );
1300 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1301 tr( "MNU_BACK_VIEW" ), 0, this, false, "/#Viewers/View/Set X+");
1302 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1303 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1304 this->addAction(aAction);
1305 toolMgr()->registerAction( aAction, BackId );
1307 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1308 tr( "MNU_TOP_VIEW" ), 0, this, false, "/#Viewers/View/Set Z-");
1309 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1310 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1311 this->addAction(aAction);
1312 toolMgr()->registerAction( aAction, TopId );
1314 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1315 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "/#Viewers/View/Set Z+");
1316 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1317 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1318 this->addAction(aAction);
1319 toolMgr()->registerAction( aAction, BottomId );
1321 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1322 tr( "MNU_LEFT_VIEW" ), 0, this, false, "/#Viewers/View/Set Y+");
1323 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1324 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1325 this->addAction(aAction);
1326 toolMgr()->registerAction( aAction, LeftId );
1328 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1329 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "/#Viewers/View/Set Y-");
1330 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1331 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1332 this->addAction(aAction);
1333 toolMgr()->registerAction( aAction, RightId );
1335 // rotate anticlockwise
1336 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1337 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "/#Viewers/View/Rotate anticlockwise");
1338 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1339 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1340 this->addAction(aAction);
1341 toolMgr()->registerAction( aAction, AntiClockWiseId );
1344 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1345 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "/#Viewers/View/Rotate clockwise");
1346 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1347 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1348 this->addAction(aAction);
1349 toolMgr()->registerAction( aAction, ClockWiseId );
1351 // Projection mode group
1353 // - orthographic projection
1354 aAction = new QtxAction(tr("MNU_ORTHOGRAPHIC_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ORTHOGRAPHIC" ) ),
1355 tr( "MNU_ORTHOGRAPHIC_MODE" ), 0, this);
1356 aAction->setStatusTip(tr("DSC_ORTHOGRAPHIC_MODE"));
1357 aAction->setCheckable(true);
1358 toolMgr()->registerAction( aAction, OrthographicId );
1360 // - perspective projection
1361 aAction = new QtxAction(tr("MNU_PERSPECTIVE_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PERSPECTIVE" ) ),
1362 tr( "MNU_PERSPECTIVE_MODE" ), 0, this);
1363 aAction->setStatusTip(tr("DSC_PERSPECTIVE_MODE"));
1364 aAction->setCheckable(true);
1365 toolMgr()->registerAction( aAction, PerspectiveId );
1367 // - stereo projection
1368 aAction = new QtxAction(tr("MNU_STEREO_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STEREO" ) ),
1369 tr( "MNU_STEREO_MODE" ), 0, this);
1370 aAction->setStatusTip(tr("DSC_STEREO_MODE"));
1371 aAction->setCheckable(true);
1372 toolMgr()->registerAction( aAction, StereoId );
1373 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onStereoType(bool)));
1375 // - add exclusive action group
1376 QActionGroup* aProjectionGroup = new QActionGroup( this );
1377 aProjectionGroup->addAction( toolMgr()->action( OrthographicId ) );
1378 aProjectionGroup->addAction( toolMgr()->action( PerspectiveId ) );
1379 connect(aProjectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProjectionType(QAction*)));
1382 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1383 tr( "MNU_RESET_VIEW" ), 0, this, false, "/#Viewers/View/Reset");
1384 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1385 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1386 this->addAction(aAction);
1387 toolMgr()->registerAction( aAction, ResetId );
1390 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1391 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1392 tr("MNU_CLONE_VIEW"), 0, this);
1393 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1394 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1395 toolMgr()->registerAction( aAction, CloneId );
1397 aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
1398 tr("MNU_CLIPPING"), 0, this);
1399 aAction->setStatusTip (tr("DSC_CLIPPING"));
1400 aAction->setCheckable (true);
1401 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1402 toolMgr()->registerAction (aAction, ClippingId);
1404 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1405 tr( "MNU_SHOOT_VIEW" ), 0, this);
1406 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1407 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1408 toolMgr()->registerAction( aAction, MemId );
1410 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1411 tr( "MNU_PRESETS_VIEW" ), 0, this);
1412 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1413 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1414 toolMgr()->registerAction( aAction, RestoreId );
1416 if (myModel->trihedronActivated()) {
1417 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1418 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1419 aAction->setCheckable( true );
1420 aAction->setChecked( true );
1421 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1422 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1423 toolMgr()->registerAction( aAction, TrihedronShowId );
1426 if (myModel->viewCubeActivated()) {
1427 aAction = new QtxAction(tr("MNU_SHOW_VIEWCUBE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_VIEWCUBE" ) ),
1428 tr( "MNU_SHOW_VIEWCUBE" ), 0, this);
1429 aAction->setCheckable( true );
1430 aAction->setChecked( aResMgr->booleanValue( "OCCViewer", "viewcube_show", true ) );
1431 aAction->setStatusTip(tr("DSC_SHOW_VIEWCUBE"));
1432 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onViewCubeShow(bool)));
1433 toolMgr()->registerAction( aAction, ViewCubeShowId );
1437 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1438 tr( "MNU_SCALING" ), 0, this);
1439 aAction->setStatusTip(tr("DSC_SCALING"));
1440 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1441 toolMgr()->registerAction( aAction, AxialScaleId );
1443 // Enable/disable preselection
1444 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1445 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1446 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1447 aAction->setCheckable(true);
1448 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1449 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1451 // Enable/disable selection
1452 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1453 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1454 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1455 aAction->setCheckable(true);
1456 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1457 toolMgr()->registerAction( aAction, SwitchSelectionId );
1460 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1461 tr( "MNU_GRADUATED_AXES" ), 0, this);
1462 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1463 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1464 toolMgr()->registerAction( aAction, GraduatedAxesId );
1466 // Active only ambient light or not
1467 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1468 tr( "MNU_AMBIENT" ), 0, this);
1469 aAction->setStatusTip(tr("DSC_AMBIENT"));
1470 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1471 toolMgr()->registerAction( aAction, AmbientId );
1473 // Switch between interaction styles
1474 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1475 tr( "MNU_STYLE_SWITCH" ), 0, this);
1476 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1477 aAction->setCheckable(true);
1478 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1479 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1481 // Switch between zooming styles
1482 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1483 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1484 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1485 aAction->setCheckable(true);
1486 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1487 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1489 // Switch advanced selection style (poligone/circle)
1490 aAction = new QtxAction(tr("MNU_RECTANGLE_SELECTION_STYLE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RECT_STYLE" ) ),
1491 tr( "MNU_RECTANGLE_SELECTION_STYLE" ), 0, this);
1492 aAction->setStatusTip(tr("DSC_RECTANGLE_SELECTION_STYLE"));
1493 aAction->setCheckable(true);
1494 toolMgr()->registerAction( aAction, RectangleSelectionStyleId);
1496 aAction = new QtxAction(tr("MNU_POLYGON_SELECTION_STYLE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_POLY_STYLE" ) ),
1497 tr( "MNU_POLYGON_SELECTION_STYLE" ), 0, this);
1498 aAction->setStatusTip(tr("DSC_POLYGON_SELECTION_STYLE"));
1499 aAction->setCheckable(true);
1500 toolMgr()->registerAction( aAction, PolygonSelectionStyleId);
1502 aAction = new QtxAction(tr("MNU_CIRCLE_SELECTION_STYLE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CIRCLE_STYLE" ) ),
1503 tr( "MNU_CIRCLE_SELECTION_STYLE" ), 0, this);
1504 aAction->setStatusTip(tr("DSC_CIRCLE_SELECTION_STYLE"));
1505 aAction->setCheckable(true);
1506 toolMgr()->registerAction( aAction, CircleSelectionStyleId);
1508 // - add exclusive action group
1509 QActionGroup* aSelectionGroup = new QActionGroup(this);
1510 aSelectionGroup->addAction(toolMgr()->action(RectangleSelectionStyleId));
1511 aSelectionGroup->addAction(toolMgr()->action(PolygonSelectionStyleId));
1512 aSelectionGroup->addAction(toolMgr()->action(CircleSelectionStyleId));
1513 connect(aSelectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onSwitchSelectionStyle(QAction*)));
1516 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1517 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1518 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1519 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1520 toolMgr()->registerAction( aAction, MaximizedId );
1522 // Return to 3d view
1523 if (my2dMode!=No2dMode){
1524 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1525 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1526 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1527 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1528 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1532 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1533 #ifdef ENABLE_RAY_TRACING
1535 aAction = new QtxAction( tr("MNU_RAY_TRACING"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_RAY_TRACING") ),
1536 tr("MNU_RAY_TRACING"), 0, this );
1537 aAction->setStatusTip( tr("DSC_RAY_TRACING") );
1538 connect( aAction, SIGNAL( triggered() ), this, SLOT( onRayTracing() ) );
1539 toolMgr()->registerAction( aAction, RayTracingId );
1541 // Environment texture
1542 aAction = new QtxAction( tr("MNU_ENV_TEXTURE"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_ENV_TEXTURE") ),
1543 tr("MNU_ENV_TEXTURE"), 0, this );
1544 aAction->setStatusTip( tr("DSC_ENV_TEXTURE") );
1545 connect( aAction, SIGNAL( triggered() ), this, SLOT( onEnvTexture() ) );
1546 toolMgr()->registerAction( aAction, EnvTextureId );
1549 aAction = new QtxAction( tr("MNU_LIGHT_SOURCE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_LIGHT_SOURCE" ) ),
1550 tr( "MNU_LIGHT_SOURCE" ), 0, this );
1551 aAction->setStatusTip( tr("DSC_LIGHT_SOURCE") );
1552 connect( aAction, SIGNAL( triggered() ), this, SLOT( onLightSource() ) );
1553 toolMgr()->registerAction( aAction, LightSourceId );
1558 \brief Create toolbar.
1560 void OCCViewer_ViewWindow::createToolBar()
1562 static const char* titles[] = {
1563 "LBL_3DTOOLBAR_LABEL",
1564 "LBL_XYTOOLBAR_LABEL",
1565 "LBL_XZTOOLBAR_LABEL",
1566 "LBL_YZTOOLBAR_LABEL",
1568 static const char* names[] = {
1569 "OCCViewer3DViewOperations",
1570 "OCCViewerXYViewOperations",
1571 "OCCViewerXZViewOperations",
1572 "OCCViewerYZViewOperations",
1574 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1575 QString( names[my2dMode] ), // name (language-independant)
1576 false ); // disable floatable toolbar
1577 if ( my2dMode != No2dMode ){
1578 toolMgr()->append( ReturnTo3dViewId, tid );
1579 toolMgr()->append( toolMgr()->separator(), tid );
1581 toolMgr()->append( DumpId, tid );
1582 toolMgr()->append( SwitchInteractionStyleId, tid );
1583 toolMgr()->append( SwitchZoomingStyleId, tid );
1584 toolMgr()->append( SwitchPreselectionId, tid );
1585 toolMgr()->append( SwitchSelectionId, tid );
1587 QtxMultiAction* aSelectionAction = new QtxMultiAction(this);
1588 aSelectionAction->insertAction(toolMgr()->action(RectangleSelectionStyleId));
1589 aSelectionAction->insertAction(toolMgr()->action(PolygonSelectionStyleId));
1590 aSelectionAction->insertAction(toolMgr()->action(CircleSelectionStyleId));
1591 toolMgr()->append(aSelectionAction, tid );
1593 if( myModel->trihedronActivated() )
1594 toolMgr()->append( TrihedronShowId, tid );
1596 if( myModel->viewCubeActivated() )
1597 toolMgr()->append( ViewCubeShowId, tid );
1599 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1600 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1601 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1602 aScaleAction->insertAction( toolMgr()->action( FitSelectionId ) );
1603 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1604 toolMgr()->append( aScaleAction, tid );
1606 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1607 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1608 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1609 toolMgr()->append( aPanningAction, tid );
1611 if (my2dMode == No2dMode) {
1612 toolMgr()->append( ChangeRotationPointId, tid );
1613 toolMgr()->append( RotationId, tid );
1615 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1616 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1617 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1618 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1619 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1620 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1621 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1622 toolMgr()->append( aViewsAction, tid );
1624 toolMgr()->append( AntiClockWiseId, tid );
1625 toolMgr()->append( ClockWiseId, tid );
1627 toolMgr()->append( OrthographicId, tid );
1628 toolMgr()->append( PerspectiveId, tid );
1629 toolMgr()->append( StereoId, tid );
1631 toolMgr()->append( ResetId, tid );
1634 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1635 aMemAction->insertAction( toolMgr()->action( MemId ) );
1636 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1637 toolMgr()->append( aMemAction, tid );
1639 toolMgr()->append( toolMgr()->separator(), tid );
1640 toolMgr()->append( CloneId, tid );
1642 toolMgr()->append( toolMgr()->separator(), tid );
1643 toolMgr()->append( ClippingId, tid );
1644 toolMgr()->append( AxialScaleId, tid );
1645 toolMgr()->append( GraduatedAxesId, tid );
1646 toolMgr()->append( AmbientId, tid );
1648 toolMgr()->append( MaximizedId, tid );
1649 toolMgr()->append( SynchronizeId, tid );
1650 #ifdef ENABLE_RAY_TRACING
1651 toolMgr()->append( RayTracingId, tid );
1652 toolMgr()->append( EnvTextureId, tid );
1653 toolMgr()->append( LightSourceId, tid );
1658 \brief Perform 'fit all' operation.
1660 void OCCViewer_ViewWindow::onViewFitAll()
1662 myViewPort->fitAll();
1666 \brief Perform "front view" transformation.
1668 void OCCViewer_ViewWindow::onFrontView()
1670 emit vpTransformationStarted ( FRONTVIEW );
1671 Handle(V3d_View) aView3d = myViewPort->getView();
1672 if (myAutomaticZoom)
1674 if ( !aView3d.IsNull() )
1675 aView3d->SetProj (V3d_Xpos);
1679 projAndPanToGravity(V3d_Xpos);
1680 emit vpTransformationFinished ( FRONTVIEW );
1684 \brief Perform "back view" transformation.
1686 void OCCViewer_ViewWindow::onBackView()
1688 emit vpTransformationStarted ( BACKVIEW );
1689 Handle(V3d_View) aView3d = myViewPort->getView();
1690 if (myAutomaticZoom)
1692 if ( !aView3d.IsNull() )
1693 aView3d->SetProj (V3d_Xneg);
1697 projAndPanToGravity(V3d_Xneg);
1698 emit vpTransformationFinished ( BACKVIEW );
1702 \brief Perform "top view" transformation.
1704 void OCCViewer_ViewWindow::onTopView()
1706 emit vpTransformationStarted ( TOPVIEW );
1707 Handle(V3d_View) aView3d = myViewPort->getView();
1708 if (myAutomaticZoom)
1710 if ( !aView3d.IsNull() )
1711 aView3d->SetProj (V3d_Zpos);
1715 projAndPanToGravity(V3d_Zpos);
1716 emit vpTransformationFinished ( TOPVIEW );
1720 \brief Perform "bottom view" transformation.
1722 void OCCViewer_ViewWindow::onBottomView()
1724 emit vpTransformationStarted ( BOTTOMVIEW );
1725 Handle(V3d_View) aView3d = myViewPort->getView();
1726 if (myAutomaticZoom)
1728 if ( !aView3d.IsNull() )
1729 aView3d->SetProj (V3d_Zneg);
1733 projAndPanToGravity(V3d_Zneg);
1734 emit vpTransformationFinished ( BOTTOMVIEW );
1738 \brief Perform "left view" transformation.
1740 void OCCViewer_ViewWindow::onLeftView()
1742 emit vpTransformationStarted ( LEFTVIEW );
1743 Handle(V3d_View) aView3d = myViewPort->getView();
1744 if (myAutomaticZoom)
1746 if ( !aView3d.IsNull() )
1747 aView3d->SetProj (V3d_Yneg);
1751 projAndPanToGravity(V3d_Yneg);
1752 emit vpTransformationFinished ( LEFTVIEW );
1756 \brief Perform "right view" transformation.
1758 void OCCViewer_ViewWindow::onRightView()
1760 emit vpTransformationStarted ( RIGHTVIEW );
1761 Handle(V3d_View) aView3d = myViewPort->getView();
1762 if (myAutomaticZoom)
1764 if ( !aView3d.IsNull() )
1765 aView3d->SetProj (V3d_Ypos);
1769 projAndPanToGravity(V3d_Ypos);
1770 emit vpTransformationFinished ( RIGHTVIEW );
1774 \brief Rotate view 90 degrees clockwise
1776 void OCCViewer_ViewWindow::onClockWiseView()
1778 emit vpTransformationStarted ( CLOCKWISEVIEW );
1779 myViewPort->rotateXY( 90. );
1780 emit vpTransformationFinished ( CLOCKWISEVIEW );
1784 \brief Rotate view 90 degrees conterclockwise
1786 void OCCViewer_ViewWindow::onAntiClockWiseView()
1788 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1789 myViewPort->rotateXY( -90. );
1790 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1794 \brief Perform "reset view" transformation.
1796 Sets default orientation of the viewport camera.
1798 void OCCViewer_ViewWindow::onResetView()
1800 emit vpTransformationStarted( RESETVIEW );
1801 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1802 myViewPort->getView()->Reset( false );
1803 myViewPort->fitAll( false, true, false );
1804 myViewPort->getView()->SetImmediateUpdate( upd );
1805 onProjectionType(); // needed to apply projection type properly after reset
1806 myViewPort->getView()->Update();
1807 emit vpTransformationFinished( RESETVIEW );
1811 \brief Set the given projection mode.
1813 Set the given projection mode: Orthographic or Perspective.
1815 void OCCViewer_ViewWindow::onProjectionType( QAction* theAction )
1817 Handle(V3d_View) aView3d = myViewPort->getView();
1818 if ( !aView3d.IsNull() ) {
1819 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1820 if (theAction == toolMgr()->action( OrthographicId )) {
1821 myModel->setProjectionType(Orthographic);
1822 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Orthographic );
1823 aCamera->SetFOVy(45.0);
1825 else if (theAction == toolMgr()->action( PerspectiveId )) {
1826 myModel->setProjectionType(Perspective);
1827 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Perspective );
1828 aCamera->SetFOVy(30.0);
1830 if (toolMgr()->action( StereoId )->isChecked()) {
1831 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1832 aCamera->SetFOVy(30.0);
1840 \brief Sets Stereo projection mode.
1842 Sets Stereo projection mode.
1844 void OCCViewer_ViewWindow::onStereoType( bool activate )
1846 Handle(V3d_View) aView3d = myViewPort->getView();
1847 if ( !aView3d.IsNull() ) {
1848 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1850 toolMgr()->action( PerspectiveId )->setChecked(true);
1851 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1852 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(false);
1854 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1855 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1856 setStereoType( aResMgr->integerValue( "OCCViewer", "stereo_type", 0 ) );
1857 setAnaglyphFilter( aResMgr->integerValue( "OCCViewer", "anaglyph_filter", 0 ) );
1858 setReverseStereo( aResMgr->booleanValue( "OCCViewer", "reverse_stereo", false ) );
1859 setVSync( aResMgr->booleanValue( "OCCViewer", "enable_vsync", true ) );
1860 setQuadBufferSupport( aResMgr->booleanValue( "OCCViewer", "enable_quad_buffer_support", false ) );
1863 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(true);
1864 if (myModel->projectionType() == Orthographic) {
1865 toolMgr()->action( OrthographicId )->setChecked(true);
1866 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Orthographic);
1868 else if (myModel->projectionType() == Perspective) {
1869 toolMgr()->action( PerspectiveId )->setChecked(true);
1870 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1877 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1878 toolMgr()->action( StereoId )->isChecked() )
1879 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1883 \brief Restore the view.
1885 Restore the projection mode based on tool-buttons states.
1887 void OCCViewer_ViewWindow::onProjectionType()
1889 emit vpTransformationStarted( PROJECTION );
1890 if (toolMgr()->action( OrthographicId )->isChecked())
1891 setProjectionType( Orthographic );
1892 if (toolMgr()->action( PerspectiveId )->isChecked())
1893 setProjectionType( Perspective );
1894 if (toolMgr()->action( StereoId )->isChecked())
1895 setProjectionType( Stereo );
1896 emit vpTransformationFinished( PROJECTION );
1899 void OCCViewer_ViewWindow::setProjectionType( int mode )
1901 QtxAction* anOrthographicAction = dynamic_cast<QtxAction*>( toolMgr()->action( OrthographicId ) );
1902 QtxAction* aPerspectiveAction = dynamic_cast<QtxAction*>( toolMgr()->action( PerspectiveId ) );
1903 QtxAction* aStereoAction = dynamic_cast<QtxAction*>( toolMgr()->action( StereoId ) );
1906 onProjectionType( anOrthographicAction );
1909 onProjectionType( aPerspectiveAction );
1912 onStereoType( true );
1915 // update action state if method is called outside
1916 if ( mode == Orthographic && !anOrthographicAction->isChecked() ) {
1917 anOrthographicAction->setChecked( true );
1918 aStereoAction->setChecked( false );
1920 if ( mode == Perspective && !aPerspectiveAction->isChecked() ) {
1921 aPerspectiveAction->setChecked( true );
1922 aStereoAction->setChecked( false );
1924 if ( mode == Stereo ) {
1925 aStereoAction->setChecked( true );
1926 if ( anOrthographicAction->isEnabled() ) {
1927 anOrthographicAction->setEnabled( false );
1928 anOrthographicAction->setChecked( false );
1929 aStereoAction->setChecked( false );
1932 anOrthographicAction->setEnabled( true );
1933 aStereoAction->setChecked( false );
1934 anOrthographicAction->setChecked(myModel->projectionType() == Orthographic);
1936 if ( aPerspectiveAction->isEnabled() ) {
1937 aPerspectiveAction->setEnabled( false );
1938 aPerspectiveAction->setChecked( true );
1939 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1940 toolMgr()->action( StereoId )->isChecked() )
1941 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1944 aPerspectiveAction->setEnabled( true );
1945 aStereoAction->setChecked( false );
1946 aPerspectiveAction->setChecked(myModel->projectionType() == Perspective);
1951 if ( !anOrthographicAction->isEnabled() )
1952 anOrthographicAction->setEnabled( true );
1953 if ( !aPerspectiveAction->isEnabled() )
1954 aPerspectiveAction->setEnabled( true );
1959 \brief Perform "fit all" transformation.
1961 void OCCViewer_ViewWindow::onFitAll()
1963 emit vpTransformationStarted( FITALLVIEW );
1964 if (myModel->fitter())
1965 myModel->fitter()->fitAll(myViewPort->getView());
1967 myViewPort->fitAll();
1968 emit vpTransformationFinished( FITALLVIEW );
1972 \brief Perform "fit selection" transformation.
1974 void OCCViewer_ViewWindow::onFitSelection()
1976 emit vpTransformationStarted( FITSELECTION );
1977 myModel->getAISContext()->FitSelected( getViewPort()->getView() );
1978 emit vpTransformationFinished( FITSELECTION );
1982 \brief Called if 'change rotation point' operation is activated.
1983 \param on action state
1985 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1989 if (!mySetRotationPointDlg)
1991 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1992 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1995 if (!mySetRotationPointDlg->isVisible())
1997 //if (mySetRotationPointDlg->IsFirstShown())
1998 if (myCurrPointType == BBCENTER)
2000 Standard_Real Xcenter, Ycenter, Zcenter;
2001 if (OCCViewer_Utilities::computeVisibleBBCenter(myViewPort->getView(), Xcenter, Ycenter, Zcenter))
2002 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
2004 mySetRotationPointDlg->show();
2009 if (mySetRotationPointDlg->isVisible())
2010 mySetRotationPointDlg->hide();
2015 \brief Create one more window with same content.
2017 void OCCViewer_ViewWindow::onCloneView()
2019 SUIT_ViewWindow* vw = myManager->createViewWindow();
2021 emit viewCloned( vw );
2022 OCCViewer_ViewWindow* occVw = dynamic_cast<OCCViewer_ViewWindow*> (vw);
2023 if(occVw && occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)) {
2024 occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)->synchronize(this);
2029 Creates one more window with same content
2031 void OCCViewer_ViewWindow::onAxialScale()
2033 if ( !myScalingDlg )
2034 myScalingDlg = new OCCViewer_AxialScaleDlg( this , myModel );
2036 if ( !myScalingDlg->isVisible() )
2038 myScalingDlg->Update();
2039 myScalingDlg->show();
2044 Shows Graduated Axes dialog
2046 void OCCViewer_ViewWindow::onGraduatedAxes()
2048 myCubeAxesDlg->Update();
2049 myCubeAxesDlg->show();
2052 void OCCViewer_ViewWindow::onAmbientToogle()
2054 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2055 viewer->InitDefinedLights();
2056 while(viewer->MoreDefinedLights())
2058 Handle(V3d_Light) light = viewer->DefinedLight();
2059 if(light->Type() != V3d_AMBIENT)
2061 Handle(V3d_View) aView3d = myViewPort->getView();
2062 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
2063 else viewer->SetLightOn(light);
2065 viewer->NextDefinedLights();
2071 \brief Store view parameters.
2073 void OCCViewer_ViewWindow::onMemorizeView()
2075 appendViewAspect( getViewParams() );
2079 \brief Restore view parameters.
2081 void OCCViewer_ViewWindow::onRestoreView()
2083 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
2084 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
2086 updateViewAspects( aDlg->parameters() );
2087 if( myRestoreFlag && aDlg->parameters().count() )
2088 performRestoring( aDlg->currentItem() );
2092 \brief Restore view parameters.
2093 \param anItem view parameters
2095 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
2097 Handle(V3d_View) aView3d = myViewPort->getView();
2099 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
2100 aView3d->SetScale( anItem.scale );
2101 aView3d->SetTwist( anItem.twist );
2102 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
2103 aView3d->SetImmediateUpdate( prev );
2104 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2105 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2106 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
2108 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
2110 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
2112 // "eye" and "at" require conversion to represent center panning
2113 // up direction is only available after setting angle of twist and
2114 // other view parameters
2115 aView3d->Up( anUpX, anUpY, anUpZ );
2117 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
2118 gp_Dir anUp( anUpX, anUpY, anUpZ );
2119 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
2120 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2121 gp_Dir aSide = aProj ^ anUp;
2123 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
2124 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
2126 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
2127 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2130 if ( !baseParamsOnly ) {
2132 myModel->setTrihedronShown( anItem.isVisible );
2133 myModel->setTrihedronSize( anItem.size );
2135 myModel->setViewCubeShown( anItem.vcIsVisible );
2137 // graduated trihedron
2138 bool anIsVisible = anItem.gtIsVisible;
2139 OCCViewer_AxisWidget::AxisData anAxisData[3];
2140 anAxisData[0].DrawName = anItem.gtDrawNameX;
2141 anAxisData[1].DrawName = anItem.gtDrawNameZ;
2142 anAxisData[2].DrawName = anItem.gtDrawNameZ;
2143 anAxisData[0].Name = anItem.gtNameX;
2144 anAxisData[1].Name = anItem.gtNameZ;
2145 anAxisData[2].Name = anItem.gtNameZ;
2146 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
2147 anItem.gtNameColorGX,
2148 anItem.gtNameColorBX );
2149 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
2150 anItem.gtNameColorGY,
2151 anItem.gtNameColorBY );
2152 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
2153 anItem.gtNameColorGZ,
2154 anItem.gtNameColorBZ );
2155 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
2156 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
2157 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
2158 anAxisData[0].NbValues = anItem.gtNbValuesX;
2159 anAxisData[1].NbValues = anItem.gtNbValuesY;
2160 anAxisData[2].NbValues = anItem.gtNbValuesZ;
2161 anAxisData[0].Offset = anItem.gtOffsetX;
2162 anAxisData[1].Offset = anItem.gtOffsetY;
2163 anAxisData[2].Offset = anItem.gtOffsetZ;
2164 anAxisData[0].Color = QColor( anItem.gtColorRX,
2167 anAxisData[1].Color = QColor( anItem.gtColorRY,
2170 anAxisData[2].Color = QColor( anItem.gtColorRZ,
2173 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
2174 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
2175 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
2176 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
2177 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
2178 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
2180 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
2181 myCubeAxesDlg->ApplyData( aView3d );
2183 } // if ( !baseParamsOnly )
2189 \brief Set restore flag.
2191 void OCCViewer_ViewWindow::setRestoreFlag()
2197 \brief Called when action "show/hide trihedron" is activated.
2199 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
2201 myModel->setTrihedronShown(show);
2205 \brief Called when action "show/hide view cube" is activated.
2207 void OCCViewer_ViewWindow::onViewCubeShow(bool show)
2209 myModel->setViewCubeShown(show);
2213 \brief Toggles preselection (highlighting) on/off
2215 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
2217 myPreselectionEnabled = on;
2218 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
2220 // unhighlight all highlighted objects
2222 myModel->unHighlightAll( true, false );
2225 // update action state if method is called outside
2226 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2227 if ( a && a->isChecked() != on ) {
2228 a->setChecked( on );
2233 \brief Toggles selection on/off
2235 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
2237 mySelectionEnabled = on;
2238 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
2240 // update action state if method is called outside
2243 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2245 a->setEnabled( on );
2249 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
2250 if ( a && a->isChecked() != on ) {
2251 a->setChecked( on );
2256 \brief Switches style of advanced multiple selection by Poligon/Circle
2258 void OCCViewer_ViewWindow::onSwitchSelectionStyle(QAction* theAction)
2261 OCCViewer_ViewSketcher* aSkecher = getSketcher(Polygon);
2263 if (theAction == toolMgr()->action(PolygonSelectionStyleId)) {
2264 aSkecher->setSketcherMode(OCCViewer_PolygonSketcher::Poligone);
2266 else if (theAction == toolMgr()->action(CircleSelectionStyleId)) {
2267 aSkecher->setSketcherMode(OCCViewer_PolygonSketcher::Circle);
2273 Returns currently selected selection style
2275 OCCViewer_ViewWindow::SelectionStyle OCCViewer_ViewWindow::selectionStyle() const
2277 if (toolMgr()->action(PolygonSelectionStyleId)->isChecked())
2278 return PolygonStyle;
2279 if (toolMgr()->action(CircleSelectionStyleId)->isChecked())
2284 void OCCViewer_ViewWindow::setSelectionStyle(SelectionStyle theMode)
2286 toolMgr()->action(RectangleSelectionStyleId)->setChecked(false);
2287 toolMgr()->action(PolygonSelectionStyleId)->setChecked(false);
2288 toolMgr()->action(CircleSelectionStyleId)->setChecked(false);
2291 toolMgr()->action(RectangleSelectionStyleId)->setChecked(true);
2294 toolMgr()->action(PolygonSelectionStyleId)->setChecked(true);
2297 toolMgr()->action(CircleSelectionStyleId)->setChecked(true);
2302 \brief Switches "keyboard free" interaction style on/off
2304 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
2306 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
2308 // update action state if method is called outside
2309 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
2310 if ( a && a->isChecked() != on )
2311 a->setChecked( on );
2315 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
2317 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
2319 myViewPort->setAdvancedZoomingEnabled( on );
2321 // update action state if method is called outside
2322 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
2323 if ( a && a->isChecked() != on )
2324 a->setChecked( on );
2328 \brief Get current interaction style
2329 \return interaction style
2331 int OCCViewer_ViewWindow::interactionStyle() const
2333 return myInteractionStyle;
2337 \brief Set current interaction style
2338 \param theStyle interaction style
2340 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
2342 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
2346 \brief Get current zooming style
2347 \return zooming style
2349 int OCCViewer_ViewWindow::zoomingStyle() const
2351 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
2355 \brief Set current zooming style
2356 \param theStyle zooming style
2358 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
2360 onSwitchZoomingStyle( theStyle == 1 );
2364 \brief Dump view window contents to the pixmap.
2365 \return pixmap containing all scene rendered in the window
2367 //#define USE_OLD_IMPLEMENTATION
2368 QImage OCCViewer_ViewWindow::dumpView()
2370 Handle(V3d_View) view = myViewPort->getView();
2371 if ( view.IsNull() )
2374 int aWidth = myViewPort->width();
2375 int aHeight = myViewPort->height();
2377 #ifdef USE_OLD_IMPLEMENTATION
2378 // rnv: Old approach to dump the OCCViewer content via Frame Buffer Object
2382 #ifndef DISABLE_GLVIEWER
2383 OpenGLUtils_FrameBuffer aFrameBuffer;
2384 if ( aFrameBuffer.init( aWidth, aHeight ) )
2386 glPushAttrib( GL_VIEWPORT_BIT );
2387 glViewport( 0, 0, aWidth, aHeight );
2388 aFrameBuffer.bind();
2393 aFrameBuffer.unbind();
2396 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
2398 aFrameBuffer.bind();
2399 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
2400 aFrameBuffer.unbind();
2402 anImage = anImage.rgbSwapped();
2403 anImage = anImage.mirrored();
2407 // if frame buffers are unsupported, use old approach
2409 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
2410 QPoint p = myViewPort->mapFromParent( myViewPort->geometry().topLeft() );
2411 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
2413 QImage anImage( data, aWidth, aHeight, QImage::Format_ARGB32 );
2414 anImage = anImage.mirrored();
2415 anImage = anImage.rgbSwapped();
2418 #else // DISABLE_GLVIEWER
2422 #endif // DISABLE_GLVIEWER
2424 #else // USE_OLD_IMPLEMENTATION
2425 // rnv: New approach is to use OCCT built-in procedure
2428 view->ToPixMap(aPix, aWidth, aHeight, Graphic3d_BT_RGB);
2430 QImage anImage( aWidth, aHeight, QImage::Format_ARGB32 );
2431 for ( int i = 0; i < aWidth; i++ ) {
2432 for ( int j = 0; j < aHeight; j++ ) {
2433 Quantity_Color pixel = aPix.PixelColor( i, j ).GetRGB();
2434 QColor color = QColor::fromRgbF( pixel.Red(), pixel.Green(), pixel.Blue() );
2435 anImage.setPixelColor( i, j, color );
2439 if ( aPix.IsTopDown() )
2440 anImage = anImage.mirrored();
2443 #endif // USE_OLD_IMPLEMENTATION
2446 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& /*img*/,
2447 const QString& fileName,
2448 const QString& /*format*/ )
2451 QApplication::setOverrideCursor( Qt::WaitCursor );
2453 res = myViewPort->getView()->Dump( fileName.toStdString().c_str() );
2455 QApplication::restoreOverrideCursor();
2460 QString OCCViewer_ViewWindow::filter() const
2462 // OCCT version > 7.3.0 is not support export to PS and EPS
2463 QString formats = tr( "OCC_IMAGE_FILES" );
2464 return formats.remove(" *.eps *.ps");
2469 \brief Set parameters of the cutting plane
2470 \param on if \c true, cutting plane is enabled
2471 \param x X position of plane point
2472 \param y Y position of plane point
2473 \param z Z position of plane point
2474 \param dx X coordinate of plane normal
2475 \param dy Y coordinate of plane normal
2476 \param dz Z coordinate of plane normal
2478 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2479 const double dx, const double dy, const double dz )
2481 Handle(V3d_View) view = myViewPort->getView();
2482 if ( view.IsNull() )
2486 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2488 // try to use already existing plane or create a new one
2489 Handle(V3d_Plane) clipPlane;
2491 // calculate new a,b,c,d values for the plane
2492 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2494 pln.Coefficients(a, b, c, d);
2495 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2496 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2497 if(aPlanes->Size() > 0 ) {
2498 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2499 aClipPlane->SetEquation(pln);
2500 aClipPlane->SetOn(Standard_True);
2501 aClipPlane->SetUseObjectMaterial(true);
2503 view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2507 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2508 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2509 for( ;anIter.More();anIter.Next() ){
2510 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2511 aClipPlane->SetOn(Standard_False);
2519 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2521 gp_Dir aDir = pln.Axis().Direction();
2522 gp_Pnt aPnt = pln.Location();
2523 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2528 \brief Check if any cutting plane is enabled
2529 \return \c true if at least one cutting plane is enabled
2531 bool OCCViewer_ViewWindow::isCuttingPlane()
2533 Handle(V3d_View) view = myViewPort->getView();
2535 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2536 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2537 for( ;anIter.More();anIter.Next() ) {
2538 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2539 if(aClipPlane->IsOn()) {
2548 \brief Get the visual parameters of the view window.
2549 \return visual parameters of view window
2551 viewAspect OCCViewer_ViewWindow::getViewParams() const
2553 double projX, projY, projZ, twist;
2554 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2555 double aScaleX, aScaleY, aScaleZ;
2557 Handle(V3d_View) aView3d = myViewPort->getView();
2559 aView3d->Proj( projX, projY, projZ );
2560 aView3d->At( atX, atY, atZ );
2561 aView3d->Eye( eyeX, eyeY, eyeZ );
2562 twist = aView3d->Twist();
2564 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2566 bool isShown = myModel->isTrihedronVisible();
2567 double size = myModel->trihedronSize();
2569 bool isVCShown = myModel->isViewCubeVisible();
2571 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2574 params.scale = aView3d->Scale();
2575 params.projX = projX;
2576 params.projY = projY;
2577 params.projZ = projZ;
2578 params.twist = twist;
2585 params.scaleX = aScaleX;
2586 params.scaleY = aScaleY;
2587 params.scaleZ = aScaleZ;
2588 params.name = aName;
2591 params.isVisible= isShown;
2595 params.vcIsVisible= isVCShown;
2597 // graduated trihedron
2598 bool anIsVisible = false;
2599 OCCViewer_AxisWidget::AxisData anAxisData[3];
2600 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2602 params.gtIsVisible = anIsVisible;
2603 params.gtDrawNameX = anAxisData[0].DrawName;
2604 params.gtDrawNameY = anAxisData[1].DrawName;
2605 params.gtDrawNameZ = anAxisData[2].DrawName;
2606 params.gtNameX = anAxisData[0].Name;
2607 params.gtNameY = anAxisData[1].Name;
2608 params.gtNameZ = anAxisData[2].Name;
2609 params.gtNameColorRX = anAxisData[0].NameColor.red();
2610 params.gtNameColorGX = anAxisData[0].NameColor.green();
2611 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2612 params.gtNameColorRY = anAxisData[1].NameColor.red();
2613 params.gtNameColorGY = anAxisData[1].NameColor.green();
2614 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2615 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2616 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2617 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2618 params.gtDrawValuesX = anAxisData[0].DrawValues;
2619 params.gtDrawValuesY = anAxisData[1].DrawValues;
2620 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2621 params.gtNbValuesX = anAxisData[0].NbValues;
2622 params.gtNbValuesY = anAxisData[1].NbValues;
2623 params.gtNbValuesZ = anAxisData[2].NbValues;
2624 params.gtOffsetX = anAxisData[0].Offset;
2625 params.gtOffsetY = anAxisData[1].Offset;
2626 params.gtOffsetZ = anAxisData[2].Offset;
2627 params.gtColorRX = anAxisData[0].Color.red();
2628 params.gtColorGX = anAxisData[0].Color.green();
2629 params.gtColorBX = anAxisData[0].Color.blue();
2630 params.gtColorRY = anAxisData[1].Color.red();
2631 params.gtColorGY = anAxisData[1].Color.green();
2632 params.gtColorBY = anAxisData[1].Color.blue();
2633 params.gtColorRZ = anAxisData[2].Color.red();
2634 params.gtColorGZ = anAxisData[2].Color.green();
2635 params.gtColorBZ = anAxisData[2].Color.blue();
2636 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2637 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2638 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2639 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2640 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2641 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2647 \brief Get visual parameters of this view window.
2648 \return visual parameters of view window
2650 QString OCCViewer_ViewWindow::getVisualParameters()
2652 viewAspect params = getViewParams();
2656 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2657 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2658 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2659 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2660 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2661 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2662 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2663 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2664 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2665 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2666 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2667 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2668 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2669 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2670 data << QString( "isVisible=%1" ).arg( params.isVisible );
2671 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2673 ClipPlanesList aPlanes = myModel->getClipPlanes();
2674 for ( int i=0; i < (int)aPlanes.size(); i++ )
2676 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2677 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2678 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2679 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2680 switch ( aPlane.Mode )
2682 case OCCViewer_ClipPlane::Absolute :
2684 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2686 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2688 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2689 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2690 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2694 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2699 case OCCViewer_ClipPlane::Relative :
2701 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2702 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2703 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2708 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2709 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2710 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2711 data << ClippingPlane;
2714 // graduated trihedron
2715 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2716 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2717 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2718 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2719 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2720 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2721 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2722 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2723 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2724 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2725 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2726 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2727 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2728 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2729 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2730 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2731 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2732 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2733 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2734 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2735 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2736 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2737 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2738 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2739 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2740 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2741 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2742 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2743 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2744 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2745 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2746 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2747 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2748 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2749 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2750 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2751 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2752 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2753 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2754 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2756 // ray tracing parameters
2757 Graphic3d_RenderingParams rendParams = this->getViewPort()->getView()->RenderingParams();
2758 if ( rendParams.Method == Graphic3d_RM_RAYTRACING ) {
2759 QString RayTracing = "rayTracing=";
2760 RayTracing += QString( "rtDepth~%1;" ).arg( rendParams.RaytracingDepth );
2761 RayTracing += QString( "rtReflection~%1;" ).arg( rendParams.IsReflectionEnabled );
2762 RayTracing += QString( "rtAntialiasing~%1;" ).arg( rendParams.IsAntialiasingEnabled );
2763 RayTracing += QString( "rtShadow~%1;" ).arg( rendParams.IsShadowEnabled );
2764 RayTracing += QString( "rtTransShadow~%1;" ).arg( rendParams.IsTransparentShadowEnabled );
2768 // environment texture parameters
2769 Handle(Graphic3d_TextureEnv) aTexture = this->getViewPort()->getView()->TextureEnv();
2770 if ( !aTexture.IsNull() ) {
2771 QString EnvTexture = "envTexture=";
2772 if ( aTexture->Name() == Graphic3d_NOT_ENV_UNKNOWN ) {
2773 TCollection_AsciiString aFileName;
2774 aTexture->Path().SystemName( aFileName );
2775 EnvTexture += QString( "etFile~%1;" ).arg( aFileName.ToCString() );
2778 EnvTexture += QString( "etNumber~%1;" ).arg( aTexture->Name() );
2782 // light source parameters
2783 myModel->getViewer3d()->InitDefinedLights();
2784 while ( myModel->getViewer3d()->MoreDefinedLights() )
2786 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2787 if ( aLight->Type() != V3d_AMBIENT ) {
2788 QString LightSource = QString( "lightSource=" );
2789 LightSource += QString( "lightType~%1;" ).arg( aLight->Type() );
2791 if ( aLight->Type() == V3d_DIRECTIONAL )
2792 Handle(V3d_DirectionalLight)::DownCast( aLight )->Direction( aX, aY, aZ );
2793 else if ( aLight->Type() == V3d_POSITIONAL )
2794 Handle(V3d_PositionalLight)::DownCast( aLight )->Position( aX, aY, aZ );
2796 continue; // not supported type of light source
2797 LightSource += QString( "lightX~%1;" ).arg( aX );
2798 LightSource += QString( "lightY~%1;" ).arg( aY );
2799 LightSource += QString( "lightZ~%1;" ).arg( aZ );
2800 LightSource += QString( "lightColorR~%1;" ).arg( aLight->Color().Red() );
2801 LightSource += QString( "lightColorG~%1;" ).arg( aLight->Color().Green() );
2802 LightSource += QString( "lightColorB~%1;" ).arg( aLight->Color().Blue() );
2803 LightSource += QString( "lightHeadlight~%1;" ).arg( aLight->Headlight() );
2804 data << LightSource;
2806 myModel->getViewer3d()->NextDefinedLights();
2809 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2810 data << QString( "background=%1" ).arg( bg );
2812 return data.join("*");
2816 \brief Restore visual parameters of the view window.
2817 \param parameters visual parameters of view window
2819 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2822 ClipPlanesList aClipPlanes;
2823 QStringList data = parameters.split( '*' );
2824 Qtx::BackgroundData bgData;
2825 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2827 foreach( QString param, data ) {
2828 QString paramName = param.section( '=', 0, 0 ).trimmed();
2829 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2830 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2831 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2832 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2833 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2834 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2835 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2836 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2837 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2838 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2839 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2840 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2841 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2842 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2843 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2844 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2845 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2846 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2847 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2848 else if ( paramName.contains( "ClippingPlane" ) )
2850 QStringList ClipPlaneData = paramValue.split( ';' );
2851 OCCViewer_ClipPlane aPlane;
2852 foreach( QString ClipPlaneParam, ClipPlaneData )
2854 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2855 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2856 if ( ClipPlane_paramName == "Mode" )
2858 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2860 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2861 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2862 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2863 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2866 switch ( aPlane.Mode )
2868 case OCCViewer_ClipPlane::Absolute :
2869 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2870 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2871 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2872 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2873 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2876 case OCCViewer_ClipPlane::Relative :
2877 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2878 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2879 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2884 aClipPlanes.push_back(aPlane);
2886 // graduated trihedron
2887 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2888 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2889 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2890 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2891 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2892 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2893 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2894 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2895 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2896 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2897 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2898 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2899 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2900 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2901 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2902 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2903 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2904 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2905 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2906 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2907 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2908 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2909 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2910 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2911 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2912 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2913 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2914 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2915 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2916 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2917 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2918 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2919 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2920 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2921 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2922 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2923 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2924 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2925 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2926 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2927 else if ( paramName == "rayTracing" )
2929 Graphic3d_RenderingParams& rendParams = this->getViewPort()->getView()->ChangeRenderingParams();
2930 rendParams.Method = Graphic3d_RM_RAYTRACING;
2931 QStringList rtData = paramValue.split( ';' );
2932 foreach( QString rtParam, rtData )
2934 QString rt_paramName = rtParam.section( '~', 0, 0 ).trimmed();
2935 QString rt_paramValue = rtParam.section( '~', 1, 1 ).trimmed();
2936 if ( rt_paramName == "rtDepth" ) rendParams.RaytracingDepth = rt_paramValue.toInt();
2937 else if ( rt_paramName == "rtReflection" ) rendParams.IsReflectionEnabled = rt_paramValue.toInt();
2938 else if ( rt_paramName == "rtAntialiasing" ) rendParams.IsAntialiasingEnabled = rt_paramValue.toInt();
2939 else if ( rt_paramName == "rtShadow" ) rendParams.IsShadowEnabled = rt_paramValue.toInt();
2940 else if ( rt_paramName == "rtTransShadow" ) rendParams.IsTransparentShadowEnabled = rt_paramValue.toInt();
2943 else if ( paramName == "envTexture" )
2945 Handle(Graphic3d_TextureEnv) aTexture;
2946 QStringList etData = paramValue.split( ';' );
2947 foreach( QString etParam, etData )
2949 QString et_paramName = etParam.section( '~', 0, 0 ).trimmed();
2950 QString et_paramValue = etParam.section( '~', 1, 1 ).trimmed();
2951 if ( et_paramName == "etNumber" )
2952 aTexture = new Graphic3d_TextureEnv( Graphic3d_NameOfTextureEnv( et_paramValue.toInt() ) );
2953 else if ( et_paramName == "etFile" )
2954 aTexture = new Graphic3d_TextureEnv( TCollection_AsciiString( et_paramValue.toStdString().c_str() ) );
2955 Handle(V3d_View) aView = this->getViewPort()->getView();
2956 aView->SetTextureEnv( aTexture );
2959 else if ( paramName == "lightSource" )
2961 myModel->getViewer3d()->InitDefinedLights();
2962 while ( myModel->getViewer3d()->MoreDefinedLights() )
2964 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2965 if( aLight->Type() != V3d_AMBIENT ) {
2966 myModel->getViewer3d()->DelLight( aLight );
2967 myModel->getViewer3d()->InitDefinedLights();
2969 myModel->getViewer3d()->NextDefinedLights();
2972 double aX = 0., aY = 0., aZ = 0.;
2973 double cR = 0., cG = 0., cB = 0.;
2974 V3d_TypeOfLight aType = (V3d_TypeOfLight)-1; // not specified
2975 bool isHeadlight = false;
2976 QStringList lsData = paramValue.split( ';' );
2977 foreach( QString lsParam, lsData )
2979 QString ls_paramName = lsParam.section( '~', 0, 0 ).trimmed();
2980 QString ls_paramValue = lsParam.section( '~', 1, 1 ).trimmed();
2981 if ( ls_paramName == "lightType" ) aType = V3d_TypeOfLight( ls_paramValue.toInt() );
2982 else if ( ls_paramName == "lightX" ) aX = ls_paramValue.toDouble();
2983 else if ( ls_paramName == "lightY" ) aY = ls_paramValue.toDouble();
2984 else if ( ls_paramName == "lightZ" ) aZ = ls_paramValue.toDouble();
2985 else if ( ls_paramName == "lightColorR" ) cR = ls_paramValue.toDouble();
2986 else if ( ls_paramName == "lightColorG" ) cG = ls_paramValue.toDouble();
2987 else if ( ls_paramName == "lightColorB" ) cB = ls_paramValue.toDouble();
2988 else if ( ls_paramName == "lightHeadlight" ) isHeadlight = ls_paramValue.toInt();
2990 Quantity_Color aColor = Quantity_Color( cR, cG, cB, Quantity_TOC_RGB );
2991 if( aType == V3d_DIRECTIONAL ) {
2992 Handle(V3d_DirectionalLight) aLight = new V3d_DirectionalLight();
2993 myModel->getViewer3d()->AddLight( aLight );
2994 aLight->SetDirection( aX, aY, aZ );
2995 aLight->SetColor( aColor );
2996 aLight->SetHeadlight( isHeadlight );
2997 myModel->getViewer3d()->SetLightOn( aLight );
2999 else if( aType == V3d_POSITIONAL ) {
3000 Handle(V3d_PositionalLight) aLight = new V3d_PositionalLight( gp_Pnt(aX, aY, aZ), aColor.Name() );
3001 myModel->getViewer3d()->AddLight( aLight );
3002 aLight->SetHeadlight( isHeadlight );
3003 myModel->getViewer3d()->SetLightOn( aLight );
3006 else if ( paramName == "background" ) {
3007 QString bg = paramValue.replace( "$", "=" );
3008 bgData = Qtx::stringToBackground( bg );
3012 else // old format - "1.000e+00*0.000e+00..."
3015 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
3016 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
3017 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
3018 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
3019 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
3020 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
3021 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
3022 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
3023 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
3024 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
3025 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
3026 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
3027 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
3028 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
3029 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
3030 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
3031 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
3032 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
3034 performRestoring( params );
3035 setBackground( bgData );
3036 myModel->setClipPlanes(aClipPlanes);
3040 \brief Handle show event.
3042 Emits Show() signal.
3044 \param theEvent show event
3046 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
3048 emit Show( theEvent );
3052 \brief Handle hide event.
3054 Emits Hide() signal.
3056 \param theEvent hide event
3058 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
3060 emit Hide( theEvent );
3065 Save old cursor. [ protected ]
3067 void OCCViewer_ViewWindow::saveCursor()
3069 QCursor* aCursor = NULL;
3071 aCursor = myViewPort->getDefaultCursor();
3072 myCursor = ( aCursor ? *aCursor : cursor() );
3077 Creates default sketcher. [ virtual protected ]
3079 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
3082 return new OCCViewer_RectSketcher( this, type );
3083 if ( type == Polygon )
3084 return new OCCViewer_PolygonSketcher( this, type );
3088 void OCCViewer_ViewWindow::initSketchers()
3090 if ( mySketchers.isEmpty() )
3092 mySketchers.append( createSketcher( Rect ) );
3093 mySketchers.append( createSketcher( Polygon ) );
3097 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ ) const
3099 OCCViewer_ViewSketcher* sketcher = 0;
3100 QList<OCCViewer_ViewSketcher*>::ConstIterator it;
3101 for ( it = mySketchers.cbegin(); it != mySketchers.cend() && !sketcher; ++it )
3103 OCCViewer_ViewSketcher* sk = (*it);
3104 if ( sk->type() == typ )
3111 Handles requests for sketching in the active view. [ virtual public ]
3113 void OCCViewer_ViewWindow::activateSketching( int type )
3115 OCCViewer_ViewPort3d* vp = getViewPort();
3119 if ( !vp->isSketchingEnabled() )
3122 /* Finish current sketching */
3123 if ( type == NoSketching )
3127 onSketchingFinished();
3128 mypSketcher->deactivate();
3132 /* Activate new sketching */
3135 activateSketching( NoSketching ); /* concurrency not suported */
3136 mypSketcher = getSketcher( type );
3139 mypSketcher->activate();
3140 onSketchingStarted();
3146 Unhilights detected entities. [ virtual protected ]
3148 void OCCViewer_ViewWindow::onSketchingStarted()
3153 Selection by rectangle or polygon. [ virtual protected ]
3155 void OCCViewer_ViewWindow::onSketchingFinished()
3157 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()");
3158 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
3160 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
3161 bool append = mypSketcher->isHasShift();
3163 // Sketcher uses unscaled coordinates to draw a rubber band,
3164 // then we need to scale them here for proper selection.
3165 const double pixelRatio = ViewerTools_ScreenScaling::getPR();
3167 switch( mypSketcher->type() )
3171 QRect* aRect = (QRect*)mypSketcher->data();
3174 int aLeft = aRect->left() * pixelRatio;
3175 int aRight = aRect->right() * pixelRatio;
3176 int aTop = aRect->top() * pixelRatio;
3177 int aBottom = aRect->bottom() * pixelRatio;
3181 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False);
3183 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False);
3189 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
3190 if( aPolygon && (aPolygon->size() > 2))
3192 int size = aPolygon->size();
3193 TColgp_Array1OfPnt2d anArray(1, size);
3195 QPolygon::Iterator it = aPolygon->begin();
3196 QPolygon::Iterator itEnd = aPolygon->end();
3197 for (int index = 1; it != itEnd; ++it, index++)
3199 QPoint aPoint = *it;
3200 anArray.SetValue(index, gp_Pnt2d(aPoint.x() * pixelRatio, aPoint.y() * pixelRatio));
3204 ic->ShiftSelect(anArray, getViewPort()->getView(), Standard_False);
3206 ic->Select(anArray, getViewPort()->getView(), Standard_False);
3214 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
3215 aViewMgr->getOCCViewer()->performSelectionChanged();
3219 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
3224 bool OCCViewer_ViewWindow::transformRequested() const
3226 return ( myOperation != NOVIEWOP );
3229 bool OCCViewer_ViewWindow::transformInProcess() const
3231 return myEventStarted;
3234 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
3236 myEventStarted = bOn;
3240 Set enabled state of transformation (rotate, zoom, etc)
3242 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
3244 if ( id != NOVIEWOP ) myStatus.insert( id, on );
3248 \return enabled state of transformation (rotate, zoom, etc)
3250 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
3252 return myStatus.contains( id ) ? myStatus[ id ] : true;
3255 void OCCViewer_ViewWindow::onMaximizedView()
3257 setMaximized(!isMaximized());
3260 void OCCViewer_ViewWindow::returnTo3dView()
3262 setReturnedTo3dView( true );
3265 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
3267 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
3268 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
3269 if ( !isVisible3dView )
3270 toolMgr()->show( ReturnTo3dViewId );
3272 toolMgr()->hide( ReturnTo3dViewId );
3273 if ( isVisible3dView ) emit returnedTo3d( );
3277 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
3279 QAction* anAction = toolMgr()->action( MaximizedId );
3280 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
3281 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
3283 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
3284 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
3285 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
3286 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
3287 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
3289 emit maximized( this, true );
3293 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
3294 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
3295 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
3296 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
3297 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
3299 emit maximized( this, false );
3304 bool OCCViewer_ViewWindow::isMaximized() const
3306 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
3309 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
3311 IsSketcherStyle = enable;
3314 bool OCCViewer_ViewWindow::isSketcherStyle() const
3316 return IsSketcherStyle;
3320 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
3325 int OCCViewer_ViewWindow::projectionType() const
3327 int mode = Orthographic;
3328 Handle(V3d_View) aView3d = myViewPort->getView();
3329 if ( !aView3d.IsNull() ) {
3330 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3331 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Perspective)
3333 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Orthographic)
3334 mode = Orthographic;
3335 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
3341 void OCCViewer_ViewWindow::setStereoType( int type )
3343 Handle(V3d_View) aView3d = myViewPort->getView();
3344 if ( !aView3d.IsNull() ) {
3345 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3346 aParams->StereoMode = (Graphic3d_StereoMode)type;
3350 int OCCViewer_ViewWindow::stereoType() const
3352 int type = QuadBuffer;
3353 Handle(V3d_View) aView3d = myViewPort->getView();
3354 if ( !aView3d.IsNull() ) {
3355 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3356 type = (OCCViewer_ViewWindow::StereoType)aParams->StereoMode;
3361 void OCCViewer_ViewWindow::setAnaglyphFilter( int type )
3363 Handle(V3d_View) aView3d = myViewPort->getView();
3364 if ( !aView3d.IsNull() ) {
3365 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3366 if (type == RedCyan)
3367 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
3368 if (type == YellowBlue)
3369 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
3370 if (type == GreenMagenta)
3371 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
3375 int OCCViewer_ViewWindow::anaglyphFilter() const
3378 Handle(V3d_View) aView3d = myViewPort->getView();
3379 if ( !aView3d.IsNull() ) {
3380 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3381 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized)
3383 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized)
3385 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple)
3386 type = GreenMagenta;
3391 void OCCViewer_ViewWindow::setStereographicFocus( int type, double value )
3393 Handle(V3d_View) aView3d = myViewPort->getView();
3394 if ( !aView3d.IsNull() ) {
3395 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3396 aCamera->SetZFocus( (Graphic3d_Camera::FocusType) type, value );
3400 int OCCViewer_ViewWindow::stereographicFocusType() const
3402 int type = Relative;
3403 Handle(V3d_View) aView3d = myViewPort->getView();
3404 if ( !aView3d.IsNull() ) {
3405 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3406 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->ZFocusType();
3411 double OCCViewer_ViewWindow::stereographicFocusValue() const
3414 Handle(V3d_View) aView3d = myViewPort->getView();
3415 if ( !aView3d.IsNull() ) {
3416 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3417 value = aCamera->ZFocus();
3422 void OCCViewer_ViewWindow::setInterocularDistance( int type, double value )
3424 Handle(V3d_View) aView3d = myViewPort->getView();
3425 if ( !aView3d.IsNull() ) {
3426 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3427 aCamera->SetIOD( (Graphic3d_Camera::IODType) type, value );
3431 int OCCViewer_ViewWindow::interocularDistanceType() const
3433 int type = Relative;
3434 Handle(V3d_View) aView3d = myViewPort->getView();
3435 if ( !aView3d.IsNull() ) {
3436 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3437 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->GetIODType();
3442 double OCCViewer_ViewWindow::interocularDistanceValue() const
3444 double value = 0.05;
3445 Handle(V3d_View) aView3d = myViewPort->getView();
3446 if ( !aView3d.IsNull() ) {
3447 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3448 value = aCamera->IOD();
3453 void OCCViewer_ViewWindow::setReverseStereo( bool reverse )
3455 Handle(V3d_View) aView3d = myViewPort->getView();
3456 if ( !aView3d.IsNull() ) {
3457 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3458 aParams->ToReverseStereo = reverse;
3462 bool OCCViewer_ViewWindow::isReverseStereo() const
3464 int reverse = false;
3465 Handle(V3d_View) aView3d = myViewPort->getView();
3466 if ( !aView3d.IsNull() ) {
3467 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3468 reverse = aParams->ToReverseStereo;
3473 void OCCViewer_ViewWindow::setVSync( bool enable )
3475 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3476 if ( !anIntCont.IsNull() ) {
3477 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3478 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3479 aCaps->swapInterval = enable;
3483 bool OCCViewer_ViewWindow::isVSync() const
3486 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3487 if ( !anIntCont.IsNull() ) {
3488 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3489 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3490 enable = aCaps->swapInterval;
3495 void OCCViewer_ViewWindow::setQuadBufferSupport( bool enable )
3497 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3498 if ( !anIntCont.IsNull() ) {
3499 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3500 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3501 aCaps->contextStereo = enable;
3505 bool OCCViewer_ViewWindow::isQuadBufferSupport() const
3508 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3509 if ( !anIntCont.IsNull() ) {
3510 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3511 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3512 enable = aCaps->contextStereo;
3517 bool OCCViewer_ViewWindow::isOpenGlStereoSupport() const
3519 GLboolean support[1];
3520 glGetBooleanv (GL_STEREO, support);
3527 QColor OCCViewer_ViewWindow::backgroundColor() const
3529 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
3533 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
3535 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
3538 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
3540 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
3543 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
3545 if ( myViewPort ) myViewPort->setBackground( theBackground );
3548 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
3550 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
3556 void OCCViewer_ViewWindow::clearViewAspects()
3558 myViewAspects.clear();
3562 \return const reference to list of view aspects
3564 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
3566 return myViewAspects;
3570 Appends new view aspect
3571 \param aParams - new view aspects
3573 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
3575 myViewAspects.append( aParams );
3579 Replaces old view aspects by new ones
3580 \param aViewList - list of new view aspects
3582 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
3584 myViewAspects = aViewList;
3588 Get camera properties for the OCC view window.
3589 \return shared pointer on camera properties.
3591 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
3593 SUIT_CameraProperties aProps;
3595 Handle(V3d_View) aSourceView = getViewPort()->getView();
3596 if ( aSourceView.IsNull() )
3599 if ( get2dMode() == No2dMode ) {
3600 aProps.setDimension( SUIT_CameraProperties::Dim3D );
3603 aProps.setDimension( SUIT_CameraProperties::Dim2D );
3604 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
3607 // read common properites of the view
3608 Standard_Real anUp[3];
3609 Standard_Real anAt[3];
3610 Standard_Real anEye[3];
3611 Standard_Real aProj[3];
3612 Standard_Real anAxialScale[3];
3614 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
3615 aSourceView->At( anAt[0], anAt[1], anAt[2] );
3616 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
3617 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3619 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3620 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
3622 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
3624 // store camera properties "as is": it is up to synchronized
3625 // view classes to provide necessary property conversion.
3626 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
3627 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
3629 if ( aSourceView->Camera()->IsOrthographic() )
3631 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
3632 aProps.setViewAngle( 0.0 );
3636 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
3637 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
3639 aProps.setMappingScale( aSourceView->Camera()->Scale() );
3646 This implementation synchronizes OCC view's camera propreties.
3648 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
3650 bool blocked = blockSignals( true );
3652 SUIT_CameraProperties aProps = theView->cameraProperties();
3653 if ( !cameraProperties().isCompatible( aProps ) ) {
3654 // other view, this one is being currently synchronized to, seems has become incompatible
3655 // we have to break synchronization
3660 Handle(V3d_View) aDestView = getViewPort()->getView();
3662 aDestView->SetImmediateUpdate( Standard_False );
3665 double aPosition[3];
3666 double aFocalPoint[3];
3667 double anAxialScale[3];
3669 // get common properties
3670 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3671 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
3672 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3673 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3676 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3677 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
3678 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3679 aDestView->Camera()->SetScale( aProps.getMappingScale() );
3681 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3682 aDestView->SetImmediateUpdate( Standard_True );
3683 aDestView->Redraw();
3685 catch (Standard_Failure&) {
3688 blockSignals( blocked );
3692 \brief Indicates whether preselection is enabled
3693 \return true if preselection is enabled
3695 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
3697 return myPreselectionEnabled;
3701 \brief Enables/disables preselection
3702 \param theIsToEnable if true - preselection will be enabled
3704 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
3706 onSwitchPreselection( theIsToEnable );
3710 \brief Indicates whether selection is enabled
3711 \return true if selection is enabled
3713 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3715 return mySelectionEnabled;
3719 \brief Enables/disables selection
3720 \param theIsToEnable if true - selection will be enabled
3722 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3724 onSwitchSelection( theIsToEnable );
3729 \brief called if clipping operation is activated / deactivated.
3731 Enables/disables clipping plane displaying.
3733 \parma on action state
3735 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3737 if(!myModel) return;
3738 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3741 if (!aClippingDlg) {
3742 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3743 myModel->setClippingDlg(aClippingDlg);
3745 if (!aClippingDlg->isVisible())
3746 aClippingDlg->show();
3748 if ( aClippingDlg ) {
3749 aClippingDlg->close();
3750 myModel->setClippingDlg(0);
3754 SUIT_ViewManager* mgr = getViewManager();
3756 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3757 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3758 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3759 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3761 QAction* a = toolMgr()->action( ClippingId );
3763 if(theIsOn != a->isChecked()){
3764 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3765 a->setChecked(theIsOn);
3766 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3773 void OCCViewer_ViewWindow::onRayTracing()
3775 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_RayTracingDlg::getName() ) ) {
3776 QDialog* aDlg = new OCCViewer_RayTracingDlg( this );
3782 void OCCViewer_ViewWindow::onEnvTexture()
3784 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_EnvTextureDlg::getName() ) ) {
3785 QDialog* aDlg = new OCCViewer_EnvTextureDlg( this );
3791 void OCCViewer_ViewWindow::onLightSource()
3793 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_LightSourceDlg::getName() ) ) {
3794 QDialog* aDlg = new OCCViewer_LightSourceDlg( this, myModel );
3800 bool OCCViewer_ViewWindow::isActionVisible( ActionId theId ) const
3802 QAction* a = toolMgr()->action( theId );
3803 return a && a->isVisible();
3806 void OCCViewer_ViewWindow::setActionVisible( ActionId theId, bool isVisible )
3808 QAction* a = toolMgr()->action( theId );
3810 a->setVisible( isVisible );
3813 void OCCViewer_ViewWindow::projAndPanToGravity(V3d_TypeOfOrientation CamOri)
3815 const bool USE_XY = true;
3817 Handle(V3d_View) aView3d = myViewPort->getView();
3818 if (aView3d.IsNull())
3822 double X = 0, Y = 0, Z = 0;
3825 const double EPS = 1E-6;
3826 int xp = myViewPort->width()/2, yp = myViewPort->height()/2;
3827 aView3d->Convert( xp, yp, X, Y, Z );
3829 gp_Dir d = aView3d->Camera()->Direction();
3830 if( fabs( d.Z() ) > EPS )
3832 double t = -Z/d.Z();
3839 // It is really necessary to compute gravity center even if it is not used in part of code below.
3840 // Without this calculation the SetProj() method and other methods are not correct.
3842 IsGr = computeGravityCenter(X2, Y2, Z2);
3844 IsGr = OCCViewer_Utilities::computeSceneBBCenter(aView3d, X2, Y2, Z2);
3846 aView3d->SetProj(CamOri);
3849 //aView3d->Update();
3850 Handle(Graphic3d_Camera) Cam = aView3d->Camera();
3852 gp_Vec dir (Cam->Direction());
3853 gp_Pnt eye = Cam->Eye();
3855 Standard_Real D = dir.Dot(V1);
3856 gp_Pnt ppdir = eye.Translated(D*dir);
3857 gp_Vec V2(ppdir, gp);
3858 gp_XYZ trEye = eye.XYZ() + V2.XYZ();
3860 double xat, yat, zat;
3861 aView3d->At(xat, yat, zat);
3862 gp_Pnt At(xat, yat, zat);
3863 gp_XYZ trAt = At.XYZ() + V2.XYZ();
3864 aView3d->SetEye(trEye.X(), trEye.Y(), trEye.Z());
3865 aView3d->SetAt(trAt.X(), trAt.Y(), trAt.Z());
3870 bool OCCViewer_ViewWindow::isAutomaticZoom() const
3872 return myAutomaticZoom;
3875 void OCCViewer_ViewWindow::setAutomaticZoom(const bool isOn)
3877 myAutomaticZoom = isOn;
3881 void OCCViewer_ViewWindow::enableAutoRotation( const bool isEnable )
3883 SUIT_ViewWindow::enableAutoRotation(isEnable);
3885 delete myAutoRotate;
3886 myAutoRotate = nullptr;
3889 myAutoRotate = new OCCViewer_AutoRotate(this);