1 // Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : OCCViewer_ViewWindow.cxx
26 #include "OCCViewer_ViewWindow.h"
27 #include "OCCViewer_ViewFrame.h"
28 #include "OCCViewer_ViewModel.h"
29 #include "OCCViewer_ViewPort3d.h"
30 #include "OCCViewer_ViewManager.h"
31 #include "OCCViewer_ViewSketcher.h"
32 #include "OCCViewer_CreateRestoreViewDlg.h"
33 #include "OCCViewer_ClipPlane.h"
34 #include "OCCViewer_SetRotationPointDlg.h"
35 #include "OCCViewer_AxialScaleDlg.h"
36 #include "OCCViewer_CubeAxesDlg.h"
37 #include "OCCViewer_ClippingDlg.h"
38 #include "OCCViewer_RayTracingDlg.h"
39 #include "OCCViewer_EnvTextureDlg.h"
40 #include "OCCViewer_LightSourceDlg.h"
41 #include "OCCViewer_Utilities.h"
43 #include <SUIT_Desktop.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_ViewManager.h>
46 #include <SUIT_Tools.h>
47 #include <SUIT_ResourceMgr.h>
48 #include <SUIT_MessageBox.h>
49 #include <SUIT_Application.h>
51 #include <QtxActionToolMgr.h>
52 #include <QtxMultiAction.h>
53 #include <QtxRubberBand.h>
59 #include <QMouseEvent>
60 #include <QApplication>
61 #include <QActionGroup>
64 #include <AIS_ListOfInteractive.hxx>
65 #include <AIS_ListIteratorOfListOfInteractive.hxx>
66 #include <AIS_Shape.hxx>
68 #include <BRep_Tool.hxx>
69 #include <BRepBndLib.hxx>
70 #include <BRepGProp.hxx>
71 #include <GProp_GProps.hxx>
74 #include <Graphic3d_SequenceOfHClipPlane.hxx>
75 #include <Graphic3d_ClipPlane.hxx>
76 #include <OpenGl_GraphicDriver.hxx>
77 #include <OpenGLUtils_FrameBuffer.h>
78 #include <Basics_OCCTVersion.hxx>
79 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
80 #include <Graphic3d_MapOfStructure.hxx>
81 #include <Graphic3d_Structure.hxx>
82 #if OCC_VERSION_LARGE <= 0x07030000
83 #include <Graphic3d_ExportFormat.hxx>
85 #include <Graphic3d_StereoMode.hxx>
86 #include <Graphic3d_RenderingParams.hxx>
87 #include <Graphic3d_BndBox3d.hxx>
89 #include <V3d_Plane.hxx>
90 #include <V3d_Light.hxx>
94 #include <gp_GTrsf.hxx>
95 #include <TColgp_Array1OfPnt2d.hxx>
97 #include <Image_PixMap.hxx>
99 #include <Standard_Version.hxx>
100 #include <Standard_Failure.hxx>
102 #include "utilities.h"
104 // // OpenCV includes
106 // #include <highgui.h>
108 static QEvent* l_mbPressEvent = 0;
111 //# include <QWindowsStyle>
115 #include <OpenGL/gl.h>
120 // To avoid conflict between KeyPress from the X.h (define KeyPress 2)
121 // and QEvent::KeyPress (qevent.h)
131 // Enable ray tracing features
132 #define ENABLE_RAY_TRACING
134 const char* imageZoomCursor[] = {
139 "................................",
140 "................................",
141 ".#######........................",
142 "..aaaaaaa.......................",
143 "................................",
144 ".............#####..............",
145 "...........##.aaaa##............",
146 "..........#.aa.....a#...........",
147 ".........#.a.........#..........",
148 ".........#a..........#a.........",
149 "........#.a...........#.........",
150 "........#a............#a........",
151 "........#a............#a........",
152 "........#a............#a........",
153 "........#a............#a........",
154 ".........#...........#.a........",
155 ".........#a..........#a.........",
156 ".........##.........#.a.........",
157 "........#####.....##.a..........",
158 ".......###aaa#####.aa...........",
159 "......###aa...aaaaa.......#.....",
160 ".....###aa................#a....",
161 "....###aa.................#a....",
162 "...###aa...............#######..",
163 "....#aa.................aa#aaaa.",
164 ".....a....................#a....",
165 "..........................#a....",
166 "...........................a....",
167 "................................",
168 "................................",
169 "................................",
170 "................................"};
172 const char* imageRotateCursor[] = {
177 "................................",
178 "................................",
179 "................................",
180 "................................",
181 "........#.......................",
182 ".......#.a......................",
183 "......#######...................",
184 ".......#aaaaa#####..............",
185 "........#..##.a#aa##........##..",
186 ".........a#.aa..#..a#.....##.aa.",
187 ".........#.a.....#...#..##.aa...",
188 ".........#a.......#..###.aa.....",
189 "........#.a.......#a..#aa.......",
190 "........#a.........#..#a........",
191 "........#a.........#a.#a........",
192 "........#a.........#a.#a........",
193 "........#a.........#a.#a........",
194 ".........#.........#a#.a........",
195 "........##a........#a#a.........",
196 "......##.a#.......#.#.a.........",
197 "....##.aa..##.....##.a..........",
198 "..##.aa.....a#####.aa...........",
199 "...aa.........aaa#a.............",
200 "................#.a.............",
201 "...............#.a..............",
202 "..............#.a...............",
203 "...............a................",
204 "................................",
205 "................................",
206 "................................",
207 "................................",
208 "................................"};
210 const char* imageCrossCursor[] = {
215 "................................",
216 "................................",
217 "................................",
218 "................................",
219 "................................",
220 "................................",
221 "................................",
222 "...............#................",
223 "...............#a...............",
224 "...............#a...............",
225 "...............#a...............",
226 "...............#a...............",
227 "...............#a...............",
228 "...............#a...............",
229 "...............#a...............",
230 ".......#################........",
231 "........aaaaaaa#aaaaaaaaa.......",
232 "...............#a...............",
233 "...............#a...............",
234 "...............#a...............",
235 "...............#a...............",
236 "...............#a...............",
237 "...............#a...............",
238 "...............#a...............",
239 "................a...............",
240 "................................",
241 "................................",
242 "................................",
243 "................................",
244 "................................",
245 "................................",
246 "................................"};
251 \param theDesktop main window of application
252 \param theModel OCC 3D viewer
254 OCCViewer_ViewWindow::OCCViewer_ViewWindow( SUIT_Desktop* theDesktop,
255 OCCViewer_Viewer* theModel )
256 : SUIT_ViewWindow( theDesktop )
260 myEnableDrawMode = false;
261 myDrawRectEnabled = true;
263 updateEnabledDrawMode();
265 mySetRotationPointDlg = 0;
268 IsSketcherStyle = false;
275 myInteractionStyle = SUIT_ViewModel::STANDARD;
276 myPreselectionEnabled = true;
277 mySelectionEnabled = true;
279 myCursorIsHand = false;
280 myPanningByBtn = false;
281 myAutomaticZoom = true;
289 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
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 );
328 // Graduated axes dialog
329 QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
330 myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
331 myCubeAxesDlg->initialize();
333 connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
336 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
338 return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
342 \brief Detect viewer operation according the the mouse button pressed
343 and key modifiers used.
344 \param theEvent mouse event
345 \return type of the operation
347 OCCViewer_ViewWindow::OperationType
348 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
350 OperationType aOp = NOVIEWOP;
351 SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
352 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
353 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
355 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
356 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
358 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
359 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
360 (my2dMode == No2dMode))
367 \brief Customize event handling
368 \param watched event receiver object
370 \return \c true if the event processing should be stopped
372 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
374 if ( watched == myViewPort ) {
375 int aType = e->type();
377 case QEvent::MouseButtonPress:
378 vpMousePressEvent((QMouseEvent*) e);
381 case QEvent::MouseButtonRelease:
382 vpMouseReleaseEvent((QMouseEvent*) e);
385 case QEvent::MouseMove:
386 vpMouseMoveEvent((QMouseEvent*) e);
389 case QEvent::MouseButtonDblClick:
390 emit mouseDoubleClicked(this, (QMouseEvent*)e);
395 QWheelEvent* aEvent = (QWheelEvent*) e;
397 if ( aEvent->modifiers().testFlag(Qt::ControlModifier) ) {
398 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
399 if ( isPreselectionEnabled()
400 #if OCC_VERSION_LARGE <= 0x07030000
401 && myModel->useLocalSelection()
404 if ( aEvent->delta() > 0 ) {
405 ic->HilightNextDetected( myViewPort->getView() );
407 ic->HilightPreviousDetected( myViewPort->getView() );
412 emit vpTransformationStarted ( ZOOMVIEW );
413 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
414 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
417 int x1 = (int)( aEvent->x() + width()*delta/100 );
418 int y1 = (int)( aEvent->y() + height()*delta/100 );
419 myViewPort->zoom( x, y, x1, y1 );
420 emit vpTransformationFinished ( ZOOMVIEW );
425 case QEvent::ContextMenu:
427 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
428 if ( aEvent->reason() != QContextMenuEvent::Mouse )
429 emit contextMenuRequested( aEvent );
433 case QEvent::KeyPress:
434 emit keyPressed(this, (QKeyEvent*) e);
437 case QEvent::KeyRelease:
438 emit keyReleased(this, (QKeyEvent*) e);
445 return SUIT_ViewWindow::eventFilter(watched, e);
449 \brief Enable / disable draw rect (rubber band) mode
451 bool OCCViewer_ViewWindow::enableDrawMode( bool on )
453 bool prev = myDrawRectEnabled;
454 myDrawRectEnabled = on;
455 updateEnabledDrawMode();
460 \brief Update state of enable draw mode state.
462 void OCCViewer_ViewWindow::updateEnabledDrawMode()
464 myEnableDrawMode = myDrawRectEnabled;
466 myEnableDrawMode = myEnableDrawMode && myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
470 \brief Handle mouse press event
471 \param theEvent mouse event
473 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
475 myStartX = theEvent->x();
476 myStartY = theEvent->y();
477 int anInteractionStyle = interactionStyle();
479 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
480 // which are assigned for pan and rotate - these operations are activated immediately after pressing
481 // of the first button, so it is necessary to switch to zoom when the second button is pressed
482 bool aSwitchToZoom = false;
483 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
484 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
485 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
488 switch ( myOperation ) {
490 if ( theEvent->button() == Qt::LeftButton )
491 emit vpTransformationStarted ( WINDOWFIT );
495 if ( theEvent->button() == Qt::LeftButton )
496 emit vpTransformationStarted ( PANGLOBAL );
500 if ( theEvent->button() == Qt::LeftButton ) {
501 myViewPort->startZoomAtPoint( myStartX, myStartY );
502 emit vpTransformationStarted ( ZOOMVIEW );
507 if ( aSwitchToZoom ) {
508 myViewPort->startZoomAtPoint( myStartX, myStartY );
511 else if ( theEvent->button() == Qt::LeftButton )
512 emit vpTransformationStarted ( PANVIEW );
516 if ( aSwitchToZoom ) {
517 myViewPort->startZoomAtPoint( myStartX, myStartY );
520 else if ( theEvent->button() == Qt::LeftButton ) {
521 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
522 emit vpTransformationStarted ( ROTATE );
527 /* Try to activate a transformation */
528 OperationType aState;
529 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
530 aState = getButtonState(theEvent, anInteractionStyle);
532 aState = OCCViewer_ViewWindow::NOVIEWOP;
537 myViewPort->startZoomAtPoint( myStartX, myStartY );
545 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
548 if ( myRotationPointSelection )
550 if ( theEvent->button() == Qt::LeftButton )
552 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
553 ic->Select( Standard_True );
554 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
556 TopoDS_Shape aShape = ic->SelectedShape();
557 GProp_GProps aSystem;
559 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
561 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
563 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE )
565 BRepGProp::LinearProperties( aShape, aSystem );
566 aPnt = aSystem.CentreOfMass();
568 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE )
570 BRepGProp::SurfaceProperties( aShape, aSystem );
571 aPnt = aSystem.CentreOfMass();
573 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID )
575 BRepGProp::VolumeProperties( aShape, aSystem );
576 aPnt = aSystem.CentreOfMass();
580 myCurrPointType = myPrevPointType;
584 if ( mySetRotationPointDlg )
586 myRotationPointSelection = false;
587 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
590 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
591 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
592 #if OCC_VERSION_LARGE <= 0x07030000
593 ic->CloseAllContexts( Standard_True );
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 Bnd_Box aBox1 = aStructure->MinMaxValues();
732 const Graphic3d_BndBox3d& aBox = aStructure->CStructure()->BoundingBox();
735 aXmin = /*aBox.IsVoid() ? RealFirst() :*/ aBox.CornerMin().x();
736 aYmin = /*aBox.IsVoid() ? RealFirst() : */aBox.CornerMin().y();
737 aZmin = /*aBox.IsVoid() ? RealFirst() : */aBox.CornerMin().z();
738 aXmax = /*aBox.IsVoid() ? RealLast() : */aBox.CornerMax().x();
739 aYmax = /*aBox.IsVoid() ? RealLast() : */aBox.CornerMax().y();
740 aZmax = /*aBox.IsVoid() ? RealLast() : */aBox.CornerMax().z();
742 // Infinite structures are skipped
743 Standard_Real aLIM = ShortRealLast() - 1.0;
744 if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
745 || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
749 gp_Pnt aPoints[8] = {
750 gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
751 gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
752 gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
753 gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
756 for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
757 const gp_Pnt& aBBPoint = aPoints[aPointIt];
759 gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
760 const Standard_Real& U = aProjected.X();
761 const Standard_Real& V = aProjected.Y();
763 if (U >= aScreenLimits[0]
764 && U <= aScreenLimits[1]
765 && V >= aScreenLimits[2]
766 && V <= aScreenLimits[3])
769 theX += aBBPoint.X();
770 theY += aBBPoint.Y();
771 theZ += aBBPoint.Z();
788 \brief Set the gravity center as a rotation point.
790 void OCCViewer_ViewWindow::activateSetRotationGravity()
792 if ( myRotationPointSelection )
794 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
795 #if OCC_VERSION_LARGE <= 0x07030000
796 ic->CloseAllContexts( Standard_True );
801 myOperation = NOVIEWOP;
802 myViewPort->setCursor( myCursor );
803 myCursorIsHand = false;
804 myRotationPointSelection = false;
807 myPrevPointType = myCurrPointType;
808 myCurrPointType = BBCENTER;
810 Standard_Real Xcenter, Ycenter, Zcenter;
811 if ( OCCViewer_Utilities::computeVisibleBBCenter( myViewPort->getView(), Xcenter, Ycenter, Zcenter ) )
812 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
816 \brief Update gravity center in the "Set Rotation Point" dialog box.
817 \sa OCCViewer_SetRotationPointDlg class
819 void OCCViewer_ViewWindow::updateGravityCoords()
821 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == BBCENTER )
823 Standard_Real Xcenter, Ycenter, Zcenter;
824 if ( OCCViewer_Utilities::computeVisibleBBCenter( myViewPort->getView(), Xcenter, Ycenter, Zcenter ) )
825 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
830 \brief Set the point selected by the user as a rotation point.
831 \param theX X coordinate of the rotation point
832 \param theY Y coordinate of the rotation point
833 \param theZ Z coordinate of the rotation point
835 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
837 if ( myRotationPointSelection )
839 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
840 #if OCC_VERSION_LARGE < 0x07030000
841 ic->CloseAllContexts( Standard_True );
846 myOperation = NOVIEWOP;
847 myViewPort->setCursor( myCursor );
848 myCursorIsHand = false;
849 myRotationPointSelection = false;
852 myPrevPointType = myCurrPointType;
853 myCurrPointType = SELECTED;
854 mySelectedPoint.SetCoord(theX,theY,theZ);
858 \brief Start the shape selection process.
860 void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
862 myPrevPointType = myCurrPointType;
863 myCurrPointType = SELECTED;
865 // activate selection ------>
866 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
867 #if OCC_VERSION_LARGE <= 0x07030000
868 ic->OpenLocalContext();
873 AIS_ListOfInteractive aList;
874 ic->DisplayedObjects( aList );
875 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
877 Handle(AIS_InteractiveObject) anObj = it.Value();
878 if ( !anObj.IsNull() && anObj->HasPresentation() &&
879 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
882 ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
885 // activate selection <------
887 if ( !myCursorIsHand )
889 QCursor handCursor (Qt::PointingHandCursor);
890 myCursorIsHand = true;
892 myViewPort->setCursor( handCursor );
894 myRotationPointSelection = true;
898 \brief Start global panning operation
900 Sets the corresponding cursor for the widget.
902 void OCCViewer_ViewWindow::activateGlobalPanning()
904 Handle(V3d_View) aView3d = myViewPort->getView();
905 if ( !aView3d.IsNull() ) {
906 QPixmap globalPanPixmap (imageCrossCursor);
907 QCursor glPanCursor (globalPanPixmap);
908 myCurScale = aView3d->Scale();
909 aView3d->FitAll(0.01, false);
910 saveCursor(); // save old cursor
911 myViewPort->fitAll(); // fits view before selecting a new scene center
912 if( setTransformRequested( PANGLOBAL ) )
913 myViewPort->setCursor( glPanCursor );
918 \brief Starts fit operation.
920 Sets the corresponding cursor for the widget.
922 void OCCViewer_ViewWindow::activateWindowFit()
924 if ( !transformRequested() && !myCursorIsHand )
925 saveCursor(); /* save old cursor */
927 if ( myOperation != WINDOWFIT ) {
928 QCursor handCursor (Qt::PointingHandCursor);
929 if( setTransformRequested ( WINDOWFIT ) )
931 myViewPort->setCursor ( handCursor );
932 myCursorIsHand = true;
938 \brief Start delayed viewer operation.
940 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
942 bool ok = transformEnabled( op );
943 myOperation = ok ? op : NOVIEWOP;
944 myViewPort->setMouseTracking( myOperation == NOVIEWOP );
949 \brief Handle mouse move event.
950 \param theEvent mouse event
952 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
954 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
956 switch ( getButtonState( theEvent, interactionStyle() ) ) {
958 myViewPort->startZoomAtPoint( myStartX, myStartY );
966 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
973 myCurrX = theEvent->x();
974 myCurrY = theEvent->y();
975 switch (myOperation) {
977 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
981 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
987 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
1001 if ( myRotationPointSelection || isSketcherStyle() )
1003 emit mouseMoving( this, theEvent );
1007 int aState = theEvent->modifiers();
1008 int aButton = theEvent->buttons();
1009 int anInteractionStyle = interactionStyle();
1010 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
1011 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
1012 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
1013 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
1014 myDrawRect = myEnableDrawMode;
1017 //if ( !myCursorIsHand ) { // we are going to sketch a rectangle
1018 // QCursor handCursor (Qt::PointingHandCursor);
1019 // myCursorIsHand = true;
1021 // myViewPort->setCursor( handCursor );
1024 SelectionStyle aStyle = selectionStyle();
1025 activateSketching(aStyle == RectStyle ? Rect : Polygon);
1028 if (l_mbPressEvent) {
1029 QApplication::sendEvent(getViewPort(), l_mbPressEvent);
1030 delete l_mbPressEvent;
1033 QApplication::sendEvent(getViewPort(), theEvent);
1036 emit mouseMoving( this, theEvent );
1038 //else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
1039 // aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
1040 // ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
1041 // aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
1042 // OCCViewer_ViewSketcher* sketcher = 0;
1043 // QList<OCCViewer_ViewSketcher*>::Iterator it;
1044 // for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
1046 // OCCViewer_ViewSketcher* sk = (*it);
1047 // if( sk->isDefault() && sk->sketchButton() == aButton )
1050 // if ( sketcher && myCurSketch == -1 )
1052 // activateSketching( sketcher->type() );
1053 // if ( mypSketcher )
1055 // myCurSketch = mypSketcher->sketchButton();
1057 // if ( l_mbPressEvent )
1059 // QApplication::sendEvent( getViewPort(), l_mbPressEvent );
1060 // delete l_mbPressEvent;
1061 // l_mbPressEvent = 0;
1063 // QApplication::sendEvent( getViewPort(), theEvent );
1068 emit mouseMoving( this, theEvent );
1074 \brief Handle mouse release event.
1075 \param theEvent mouse event
1077 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
1079 switch ( myOperation ) {
1082 int prevState = myCurSketch;
1083 if(theEvent->button() == Qt::RightButton)
1085 QList<OCCViewer_ViewSketcher*>::Iterator it;
1086 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
1088 OCCViewer_ViewSketcher* sk = (*it);
1089 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
1094 emit mouseReleased(this, theEvent);
1095 if(theEvent->button() == Qt::RightButton && prevState == -1)
1097 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1098 theEvent->pos(), theEvent->globalPos() );
1099 emit contextMenuRequested( &aEvent );
1104 myViewPort->endRotation();
1111 OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( getViewManager() );
1112 bool isChained = aMgr->isChainedOperations();
1113 bool isReset = !( myOperation==PANVIEW && myPanningByBtn && isChained ) || theEvent->button() == Qt::RightButton;
1120 if ( theEvent->button() == Qt::LeftButton ) {
1121 myViewPort->setCenter( theEvent->x(), theEvent->y() );
1122 myViewPort->getView()->SetScale(myCurScale);
1128 if ( theEvent->button() == Qt::LeftButton ) {
1129 myCurrX = theEvent->x();
1130 myCurrY = theEvent->y();
1132 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1133 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1140 // NOTE: viewer 3D detects a rectangle of selection using this event
1141 // so we must emit it BEFORE resetting the selection rectangle
1143 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1147 myViewPort->update();
1150 if ( l_mbPressEvent ) {
1151 delete l_mbPressEvent;
1157 \brief Reset the viewport to its initial state
1158 ( no transformations in process etc. )
1160 void OCCViewer_ViewWindow::resetState()
1164 if ( myRotationPointSelection )
1166 QCursor handCursor (Qt::PointingHandCursor);
1167 myViewPort->setCursor( handCursor );
1171 if ( transformRequested() || myCursorIsHand )
1172 myViewPort->setCursor( myCursor );
1173 myCursorIsHand = false;
1176 if ( transformRequested() )
1177 emit vpTransformationFinished (myOperation);
1179 setTransformInProcess( false );
1180 setTransformRequested( NOVIEWOP );
1182 myPanningByBtn = false;
1187 \brief Draw rubber band rectangle.
1189 void OCCViewer_ViewWindow::drawRect()
1191 if ( !myRectBand ) {
1192 myRectBand = new QtxRectRubberBand( myViewPort );
1195 myRectBand->setUpdatesEnabled ( false );
1196 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1197 myRectBand->initGeometry( aRect );
1199 if ( !myRectBand->isVisible() )
1202 myRectBand->setUpdatesEnabled ( true );
1206 \brief Clear rubber band rectangle on the end on the dragging operation.
1208 void OCCViewer_ViewWindow::endDrawRect()
1211 myRectBand->clearGeometry();
1217 \brief Create actions.
1219 void OCCViewer_ViewWindow::createActions()
1221 if( !toolMgr()->isEmpty() )
1224 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1231 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1232 tr( "MNU_DUMP_VIEW" ), 0, this);
1233 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1234 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1235 toolMgr()->registerAction( aAction, DumpId );
1238 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1239 tr( "MNU_FITALL" ), 0, this);
1240 aAction->setStatusTip(tr("DSC_FITALL"));
1241 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1242 toolMgr()->registerAction( aAction, FitAllId );
1245 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1246 tr( "MNU_FITRECT" ), 0, this);
1247 aAction->setStatusTip(tr("DSC_FITRECT"));
1248 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1249 toolMgr()->registerAction( aAction, FitRectId );
1252 aAction = new QtxAction(tr("MNU_FITSELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITSELECTION" ) ),
1253 tr( "MNU_FITSELECTION" ), 0, this);
1254 aAction->setStatusTip(tr("DSC_FITSELECTION"));
1255 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
1256 toolMgr()->registerAction( aAction, FitSelectionId );
1259 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1260 tr( "MNU_ZOOM_VIEW" ), 0, this);
1261 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1262 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1263 toolMgr()->registerAction( aAction, ZoomId );
1266 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1267 tr( "MNU_PAN_VIEW" ), 0, this);
1268 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1269 connect(aAction, SIGNAL(triggered()), this, SLOT(onPanning()));
1270 toolMgr()->registerAction( aAction, PanId );
1273 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1274 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1275 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1276 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1277 toolMgr()->registerAction( aAction, GlobalPanId );
1280 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1281 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1282 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1283 mySetRotationPointAction->setCheckable( true );
1284 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1285 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1288 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1289 tr( "MNU_ROTATE_VIEW" ), 0, this);
1290 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1291 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1292 toolMgr()->registerAction( aAction, RotationId );
1295 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1296 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1297 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1298 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1299 this->addAction(aAction);
1300 toolMgr()->registerAction( aAction, FrontId );
1302 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1303 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1304 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1305 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1306 this->addAction(aAction);
1307 toolMgr()->registerAction( aAction, BackId );
1309 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1310 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1311 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1312 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1313 this->addAction(aAction);
1314 toolMgr()->registerAction( aAction, TopId );
1316 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1317 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1318 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1319 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1320 this->addAction(aAction);
1321 toolMgr()->registerAction( aAction, BottomId );
1323 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1324 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1325 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1326 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1327 this->addAction(aAction);
1328 toolMgr()->registerAction( aAction, LeftId );
1330 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1331 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1332 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1333 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1334 this->addAction(aAction);
1335 toolMgr()->registerAction( aAction, RightId );
1337 // rotate anticlockwise
1338 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1339 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1340 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1341 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1342 this->addAction(aAction);
1343 toolMgr()->registerAction( aAction, AntiClockWiseId );
1346 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1347 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1348 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1349 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1350 this->addAction(aAction);
1351 toolMgr()->registerAction( aAction, ClockWiseId );
1353 // Projection mode group
1355 // - orthographic projection
1356 aAction = new QtxAction(tr("MNU_ORTHOGRAPHIC_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ORTHOGRAPHIC" ) ),
1357 tr( "MNU_ORTHOGRAPHIC_MODE" ), 0, this);
1358 aAction->setStatusTip(tr("DSC_ORTHOGRAPHIC_MODE"));
1359 aAction->setCheckable(true);
1360 toolMgr()->registerAction( aAction, OrthographicId );
1362 // - perspective projection
1363 aAction = new QtxAction(tr("MNU_PERSPECTIVE_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PERSPECTIVE" ) ),
1364 tr( "MNU_PERSPECTIVE_MODE" ), 0, this);
1365 aAction->setStatusTip(tr("DSC_PERSPECTIVE_MODE"));
1366 aAction->setCheckable(true);
1367 toolMgr()->registerAction( aAction, PerspectiveId );
1369 // - stereo projection
1370 aAction = new QtxAction(tr("MNU_STEREO_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STEREO" ) ),
1371 tr( "MNU_STEREO_MODE" ), 0, this);
1372 aAction->setStatusTip(tr("DSC_STEREO_MODE"));
1373 aAction->setCheckable(true);
1374 toolMgr()->registerAction( aAction, StereoId );
1375 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onStereoType(bool)));
1377 // - add exclusive action group
1378 QActionGroup* aProjectionGroup = new QActionGroup( this );
1379 aProjectionGroup->addAction( toolMgr()->action( OrthographicId ) );
1380 aProjectionGroup->addAction( toolMgr()->action( PerspectiveId ) );
1381 connect(aProjectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProjectionType(QAction*)));
1384 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1385 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1386 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1387 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1388 this->addAction(aAction);
1389 toolMgr()->registerAction( aAction, ResetId );
1392 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1393 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1394 tr("MNU_CLONE_VIEW"), 0, this);
1395 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1396 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1397 toolMgr()->registerAction( aAction, CloneId );
1399 aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
1400 tr("MNU_CLIPPING"), 0, this);
1401 aAction->setStatusTip (tr("DSC_CLIPPING"));
1402 aAction->setCheckable (true);
1403 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1404 toolMgr()->registerAction (aAction, ClippingId);
1406 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1407 tr( "MNU_SHOOT_VIEW" ), 0, this);
1408 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1409 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1410 toolMgr()->registerAction( aAction, MemId );
1412 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1413 tr( "MNU_PRESETS_VIEW" ), 0, this);
1414 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1415 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1416 toolMgr()->registerAction( aAction, RestoreId );
1418 if (myModel->trihedronActivated()) {
1419 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1420 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1421 aAction->setCheckable( true );
1422 aAction->setChecked( true );
1423 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1424 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1425 toolMgr()->registerAction( aAction, TrihedronShowId );
1429 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1430 tr( "MNU_SCALING" ), 0, this);
1431 aAction->setStatusTip(tr("DSC_SCALING"));
1432 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1433 toolMgr()->registerAction( aAction, AxialScaleId );
1435 // Enable/disable preselection
1436 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1437 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1438 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1439 aAction->setCheckable(true);
1440 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1441 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1443 // Enable/disable selection
1444 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1445 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1446 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1447 aAction->setCheckable(true);
1448 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1449 toolMgr()->registerAction( aAction, SwitchSelectionId );
1452 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1453 tr( "MNU_GRADUATED_AXES" ), 0, this);
1454 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1455 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1456 toolMgr()->registerAction( aAction, GraduatedAxesId );
1458 // Active only ambient light or not
1459 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1460 tr( "MNU_AMBIENT" ), 0, this);
1461 aAction->setStatusTip(tr("DSC_AMBIENT"));
1462 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1463 toolMgr()->registerAction( aAction, AmbientId );
1465 // Switch between interaction styles
1466 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1467 tr( "MNU_STYLE_SWITCH" ), 0, this);
1468 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1469 aAction->setCheckable(true);
1470 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1471 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1473 // Switch between zooming styles
1474 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1475 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1476 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1477 aAction->setCheckable(true);
1478 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1479 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1481 // Switch advanced selection style (poligone/circle)
1482 aAction = new QtxAction(tr("MNU_RECTANGLE_SELECTION_STYLE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RECT_STYLE" ) ),
1483 tr( "MNU_RECTANGLE_SELECTION_STYLE" ), 0, this);
1484 aAction->setStatusTip(tr("DSC_RECTANGLE_SELECTION_STYLE"));
1485 aAction->setCheckable(true);
1486 toolMgr()->registerAction( aAction, RectangleSelectionStyleId);
1488 aAction = new QtxAction(tr("MNU_POLYGON_SELECTION_STYLE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_POLY_STYLE" ) ),
1489 tr( "MNU_POLYGON_SELECTION_STYLE" ), 0, this);
1490 aAction->setStatusTip(tr("DSC_POLYGON_SELECTION_STYLE"));
1491 aAction->setCheckable(true);
1492 toolMgr()->registerAction( aAction, PolygonSelectionStyleId);
1494 aAction = new QtxAction(tr("MNU_CIRCLE_SELECTION_STYLE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CIRCLE_STYLE" ) ),
1495 tr( "MNU_CIRCLE_SELECTION_STYLE" ), 0, this);
1496 aAction->setStatusTip(tr("DSC_CIRCLE_SELECTION_STYLE"));
1497 aAction->setCheckable(true);
1498 toolMgr()->registerAction( aAction, CircleSelectionStyleId);
1500 // - add exclusive action group
1501 QActionGroup* aSelectionGroup = new QActionGroup(this);
1502 aSelectionGroup->addAction(toolMgr()->action(RectangleSelectionStyleId));
1503 aSelectionGroup->addAction(toolMgr()->action(PolygonSelectionStyleId));
1504 aSelectionGroup->addAction(toolMgr()->action(CircleSelectionStyleId));
1505 connect(aSelectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onSwitchSelectionStyle(QAction*)));
1508 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1509 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1510 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1511 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1512 toolMgr()->registerAction( aAction, MaximizedId );
1514 // Return to 3d view
1515 if (my2dMode!=No2dMode){
1516 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1517 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1518 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1519 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1520 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1524 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1525 #ifdef ENABLE_RAY_TRACING
1527 aAction = new QtxAction( tr("MNU_RAY_TRACING"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_RAY_TRACING") ),
1528 tr("MNU_RAY_TRACING"), 0, this );
1529 aAction->setStatusTip( tr("DSC_RAY_TRACING") );
1530 connect( aAction, SIGNAL( triggered() ), this, SLOT( onRayTracing() ) );
1531 toolMgr()->registerAction( aAction, RayTracingId );
1533 // Environment texture
1534 aAction = new QtxAction( tr("MNU_ENV_TEXTURE"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_ENV_TEXTURE") ),
1535 tr("MNU_ENV_TEXTURE"), 0, this );
1536 aAction->setStatusTip( tr("DSC_ENV_TEXTURE") );
1537 connect( aAction, SIGNAL( triggered() ), this, SLOT( onEnvTexture() ) );
1538 toolMgr()->registerAction( aAction, EnvTextureId );
1541 aAction = new QtxAction( tr("MNU_LIGHT_SOURCE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_LIGHT_SOURCE" ) ),
1542 tr( "MNU_LIGHT_SOURCE" ), 0, this );
1543 aAction->setStatusTip( tr("DSC_LIGHT_SOURCE") );
1544 connect( aAction, SIGNAL( triggered() ), this, SLOT( onLightSource() ) );
1545 toolMgr()->registerAction( aAction, LightSourceId );
1550 \brief Create toolbar.
1552 void OCCViewer_ViewWindow::createToolBar()
1554 static const char* titles[] = {
1555 "LBL_3DTOOLBAR_LABEL",
1556 "LBL_XYTOOLBAR_LABEL",
1557 "LBL_XZTOOLBAR_LABEL",
1558 "LBL_YZTOOLBAR_LABEL",
1560 static const char* names[] = {
1561 "OCCViewer3DViewOperations",
1562 "OCCViewerXYViewOperations",
1563 "OCCViewerXZViewOperations",
1564 "OCCViewerYZViewOperations",
1566 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1567 QString( names[my2dMode] ), // name (language-independant)
1568 false ); // disable floatable toolbar
1569 if ( my2dMode != No2dMode ){
1570 toolMgr()->append( ReturnTo3dViewId, tid );
1571 toolMgr()->append( toolMgr()->separator(), tid );
1573 toolMgr()->append( DumpId, tid );
1574 toolMgr()->append( SwitchInteractionStyleId, tid );
1575 toolMgr()->append( SwitchZoomingStyleId, tid );
1576 toolMgr()->append( SwitchPreselectionId, tid );
1577 toolMgr()->append( SwitchSelectionId, tid );
1579 QtxMultiAction* aSelectionAction = new QtxMultiAction(this);
1580 aSelectionAction->insertAction(toolMgr()->action(RectangleSelectionStyleId));
1581 aSelectionAction->insertAction(toolMgr()->action(PolygonSelectionStyleId));
1582 aSelectionAction->insertAction(toolMgr()->action(CircleSelectionStyleId));
1583 toolMgr()->append(aSelectionAction, tid );
1585 if( myModel->trihedronActivated() )
1586 toolMgr()->append( TrihedronShowId, tid );
1588 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1589 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1590 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1591 aScaleAction->insertAction( toolMgr()->action( FitSelectionId ) );
1592 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1593 toolMgr()->append( aScaleAction, tid );
1595 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1596 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1597 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1598 toolMgr()->append( aPanningAction, tid );
1600 if (my2dMode == No2dMode) {
1601 toolMgr()->append( ChangeRotationPointId, tid );
1602 toolMgr()->append( RotationId, tid );
1604 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1605 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1606 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1607 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1608 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1609 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1610 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1611 toolMgr()->append( aViewsAction, tid );
1613 toolMgr()->append( AntiClockWiseId, tid );
1614 toolMgr()->append( ClockWiseId, tid );
1616 toolMgr()->append( OrthographicId, tid );
1617 toolMgr()->append( PerspectiveId, tid );
1618 toolMgr()->append( StereoId, tid );
1620 toolMgr()->append( ResetId, tid );
1623 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1624 aMemAction->insertAction( toolMgr()->action( MemId ) );
1625 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1626 toolMgr()->append( aMemAction, tid );
1628 toolMgr()->append( toolMgr()->separator(), tid );
1629 toolMgr()->append( CloneId, tid );
1631 toolMgr()->append( toolMgr()->separator(), tid );
1632 toolMgr()->append( ClippingId, tid );
1633 toolMgr()->append( AxialScaleId, tid );
1634 toolMgr()->append( GraduatedAxesId, tid );
1635 toolMgr()->append( AmbientId, tid );
1637 toolMgr()->append( MaximizedId, tid );
1638 toolMgr()->append( SynchronizeId, tid );
1639 #ifdef ENABLE_RAY_TRACING
1640 toolMgr()->append( RayTracingId, tid );
1641 toolMgr()->append( EnvTextureId, tid );
1642 toolMgr()->append( LightSourceId, tid );
1647 \brief Perform 'fit all' operation.
1649 void OCCViewer_ViewWindow::onViewFitAll()
1651 myViewPort->fitAll();
1655 \brief Perform "front view" transformation.
1657 void OCCViewer_ViewWindow::onFrontView()
1659 emit vpTransformationStarted ( FRONTVIEW );
1660 Handle(V3d_View) aView3d = myViewPort->getView();
1661 if (myAutomaticZoom)
1663 if ( !aView3d.IsNull() )
1664 aView3d->SetProj (V3d_Xpos);
1668 projAndPanToGravity(V3d_Xpos);
1669 emit vpTransformationFinished ( FRONTVIEW );
1673 \brief Perform "back view" transformation.
1675 void OCCViewer_ViewWindow::onBackView()
1677 emit vpTransformationStarted ( BACKVIEW );
1678 Handle(V3d_View) aView3d = myViewPort->getView();
1679 if (myAutomaticZoom)
1681 if ( !aView3d.IsNull() )
1682 aView3d->SetProj (V3d_Xneg);
1686 projAndPanToGravity(V3d_Xneg);
1687 emit vpTransformationFinished ( BACKVIEW );
1691 \brief Perform "top view" transformation.
1693 void OCCViewer_ViewWindow::onTopView()
1695 emit vpTransformationStarted ( TOPVIEW );
1696 Handle(V3d_View) aView3d = myViewPort->getView();
1697 if (myAutomaticZoom)
1699 if ( !aView3d.IsNull() )
1700 aView3d->SetProj (V3d_Zpos);
1704 projAndPanToGravity(V3d_Zpos);
1705 emit vpTransformationFinished ( TOPVIEW );
1709 \brief Perform "bottom view" transformation.
1711 void OCCViewer_ViewWindow::onBottomView()
1713 emit vpTransformationStarted ( BOTTOMVIEW );
1714 Handle(V3d_View) aView3d = myViewPort->getView();
1715 if (myAutomaticZoom)
1717 if ( !aView3d.IsNull() )
1718 aView3d->SetProj (V3d_Zneg);
1722 projAndPanToGravity(V3d_Zneg);
1723 emit vpTransformationFinished ( BOTTOMVIEW );
1727 \brief Perform "left view" transformation.
1729 void OCCViewer_ViewWindow::onLeftView()
1731 emit vpTransformationStarted ( LEFTVIEW );
1732 Handle(V3d_View) aView3d = myViewPort->getView();
1733 if (myAutomaticZoom)
1735 if ( !aView3d.IsNull() )
1736 aView3d->SetProj (V3d_Yneg);
1740 projAndPanToGravity(V3d_Yneg);
1741 emit vpTransformationFinished ( LEFTVIEW );
1745 \brief Perform "right view" transformation.
1747 void OCCViewer_ViewWindow::onRightView()
1749 emit vpTransformationStarted ( RIGHTVIEW );
1750 Handle(V3d_View) aView3d = myViewPort->getView();
1751 if (myAutomaticZoom)
1753 if ( !aView3d.IsNull() )
1754 aView3d->SetProj (V3d_Ypos);
1758 projAndPanToGravity(V3d_Ypos);
1759 emit vpTransformationFinished ( RIGHTVIEW );
1763 \brief Rotate view 90 degrees clockwise
1765 void OCCViewer_ViewWindow::onClockWiseView()
1767 emit vpTransformationStarted ( CLOCKWISEVIEW );
1768 myViewPort->rotateXY( 90. );
1769 emit vpTransformationFinished ( CLOCKWISEVIEW );
1773 \brief Rotate view 90 degrees conterclockwise
1775 void OCCViewer_ViewWindow::onAntiClockWiseView()
1777 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1778 myViewPort->rotateXY( -90. );
1779 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1783 \brief Perform "reset view" transformation.
1785 Sets default orientation of the viewport camera.
1787 void OCCViewer_ViewWindow::onResetView()
1789 emit vpTransformationStarted( RESETVIEW );
1790 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1791 myViewPort->getView()->Reset( false );
1792 myViewPort->fitAll( false, true, false );
1793 myViewPort->getView()->SetImmediateUpdate( upd );
1794 onProjectionType(); // needed to apply projection type properly after reset
1795 myViewPort->getView()->Update();
1796 emit vpTransformationFinished( RESETVIEW );
1800 \brief Set the given projection mode.
1802 Set the given projection mode: Orthographic or Perspective.
1804 void OCCViewer_ViewWindow::onProjectionType( QAction* theAction )
1806 Handle(V3d_View) aView3d = myViewPort->getView();
1807 if ( !aView3d.IsNull() ) {
1808 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1809 if (theAction == toolMgr()->action( OrthographicId )) {
1810 myModel->setProjectionType(Orthographic);
1811 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Orthographic );
1812 aCamera->SetFOVy(45.0);
1814 else if (theAction == toolMgr()->action( PerspectiveId )) {
1815 myModel->setProjectionType(Perspective);
1816 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Perspective );
1817 aCamera->SetFOVy(30.0);
1819 if (toolMgr()->action( StereoId )->isChecked()) {
1820 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1821 aCamera->SetFOVy(30.0);
1829 \brief Sets Stereo projection mode.
1831 Sets Stereo projection mode.
1833 void OCCViewer_ViewWindow::onStereoType( bool activate )
1835 Handle(V3d_View) aView3d = myViewPort->getView();
1836 if ( !aView3d.IsNull() ) {
1837 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1839 toolMgr()->action( PerspectiveId )->setChecked(true);
1840 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1841 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(false);
1843 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1844 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1845 setStereoType( aResMgr->integerValue( "OCCViewer", "stereo_type", 0 ) );
1846 setAnaglyphFilter( aResMgr->integerValue( "OCCViewer", "anaglyph_filter", 0 ) );
1847 setReverseStereo( aResMgr->booleanValue( "OCCViewer", "reverse_stereo", false ) );
1848 setVSync( aResMgr->booleanValue( "OCCViewer", "enable_vsync", true ) );
1849 setQuadBufferSupport( aResMgr->booleanValue( "OCCViewer", "enable_quad_buffer_support", false ) );
1852 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(true);
1853 if (myModel->projectionType() == Orthographic) {
1854 toolMgr()->action( OrthographicId )->setChecked(true);
1855 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Orthographic);
1857 else if (myModel->projectionType() == Perspective) {
1858 toolMgr()->action( PerspectiveId )->setChecked(true);
1859 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1866 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1867 toolMgr()->action( StereoId )->isChecked() )
1868 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1872 \brief Restore the view.
1874 Restore the projection mode based on tool-buttons states.
1876 void OCCViewer_ViewWindow::onProjectionType()
1878 emit vpTransformationStarted( PROJECTION );
1879 if (toolMgr()->action( OrthographicId )->isChecked())
1880 setProjectionType( Orthographic );
1881 if (toolMgr()->action( PerspectiveId )->isChecked())
1882 setProjectionType( Perspective );
1883 if (toolMgr()->action( StereoId )->isChecked())
1884 setProjectionType( Stereo );
1885 emit vpTransformationFinished( PROJECTION );
1888 void OCCViewer_ViewWindow::setProjectionType( int mode )
1890 QtxAction* anOrthographicAction = dynamic_cast<QtxAction*>( toolMgr()->action( OrthographicId ) );
1891 QtxAction* aPerspectiveAction = dynamic_cast<QtxAction*>( toolMgr()->action( PerspectiveId ) );
1892 QtxAction* aStereoAction = dynamic_cast<QtxAction*>( toolMgr()->action( StereoId ) );
1895 onProjectionType( anOrthographicAction );
1898 onProjectionType( aPerspectiveAction );
1901 onStereoType( true );
1904 // update action state if method is called outside
1905 if ( mode == Orthographic && !anOrthographicAction->isChecked() ) {
1906 anOrthographicAction->setChecked( true );
1907 aStereoAction->setChecked( false );
1909 if ( mode == Perspective && !aPerspectiveAction->isChecked() ) {
1910 aPerspectiveAction->setChecked( true );
1911 aStereoAction->setChecked( false );
1913 if ( mode == Stereo ) {
1914 aStereoAction->setChecked( true );
1915 if ( anOrthographicAction->isEnabled() ) {
1916 anOrthographicAction->setEnabled( false );
1917 anOrthographicAction->setChecked( false );
1918 aStereoAction->setChecked( false );
1921 anOrthographicAction->setEnabled( true );
1922 aStereoAction->setChecked( false );
1923 anOrthographicAction->setChecked(myModel->projectionType() == Orthographic);
1925 if ( aPerspectiveAction->isEnabled() ) {
1926 aPerspectiveAction->setEnabled( false );
1927 aPerspectiveAction->setChecked( true );
1928 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1929 toolMgr()->action( StereoId )->isChecked() )
1930 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1933 aPerspectiveAction->setEnabled( true );
1934 aStereoAction->setChecked( false );
1935 aPerspectiveAction->setChecked(myModel->projectionType() == Perspective);
1940 if ( !anOrthographicAction->isEnabled() )
1941 anOrthographicAction->setEnabled( true );
1942 if ( !aPerspectiveAction->isEnabled() )
1943 aPerspectiveAction->setEnabled( true );
1948 \brief Perform "fit all" transformation.
1950 void OCCViewer_ViewWindow::onFitAll()
1952 emit vpTransformationStarted( FITALLVIEW );
1953 if (myModel->fitter())
1954 myModel->fitter()->fitAll(myViewPort->getView());
1956 myViewPort->fitAll();
1957 emit vpTransformationFinished( FITALLVIEW );
1961 \brief Perform "fit selection" transformation.
1963 void OCCViewer_ViewWindow::onFitSelection()
1965 emit vpTransformationStarted( FITSELECTION );
1966 myModel->getAISContext()->FitSelected( getViewPort()->getView() );
1967 emit vpTransformationFinished( FITSELECTION );
1971 \brief Called if 'change rotation point' operation is activated.
1972 \param on action state
1974 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1978 if (!mySetRotationPointDlg)
1980 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1981 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1984 if (!mySetRotationPointDlg->isVisible())
1986 //if (mySetRotationPointDlg->IsFirstShown())
1987 if (myCurrPointType == BBCENTER)
1989 Standard_Real Xcenter, Ycenter, Zcenter;
1990 if (OCCViewer_Utilities::computeVisibleBBCenter(myViewPort->getView(), Xcenter, Ycenter, Zcenter))
1991 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1993 mySetRotationPointDlg->show();
1998 if (mySetRotationPointDlg->isVisible())
1999 mySetRotationPointDlg->hide();
2004 \brief Create one more window with same content.
2006 void OCCViewer_ViewWindow::onCloneView()
2008 SUIT_ViewWindow* vw = myManager->createViewWindow();
2010 emit viewCloned( vw );
2011 OCCViewer_ViewWindow* occVw = dynamic_cast<OCCViewer_ViewWindow*> (vw);
2012 if(occVw && occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)) {
2013 occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)->synchronize(this);
2018 Creates one more window with same content
2020 void OCCViewer_ViewWindow::onAxialScale()
2022 if ( !myScalingDlg )
2023 myScalingDlg = new OCCViewer_AxialScaleDlg( this , myModel );
2025 if ( !myScalingDlg->isVisible() )
2027 myScalingDlg->Update();
2028 myScalingDlg->show();
2033 Shows Graduated Axes dialog
2035 void OCCViewer_ViewWindow::onGraduatedAxes()
2037 myCubeAxesDlg->Update();
2038 myCubeAxesDlg->show();
2041 void OCCViewer_ViewWindow::onAmbientToogle()
2043 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2044 viewer->InitDefinedLights();
2045 while(viewer->MoreDefinedLights())
2047 Handle(V3d_Light) light = viewer->DefinedLight();
2048 if(light->Type() != V3d_AMBIENT)
2050 Handle(V3d_View) aView3d = myViewPort->getView();
2051 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
2052 else viewer->SetLightOn(light);
2054 viewer->NextDefinedLights();
2060 \brief Store view parameters.
2062 void OCCViewer_ViewWindow::onMemorizeView()
2064 appendViewAspect( getViewParams() );
2068 \brief Restore view parameters.
2070 void OCCViewer_ViewWindow::onRestoreView()
2072 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
2073 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
2075 updateViewAspects( aDlg->parameters() );
2076 if( myRestoreFlag && aDlg->parameters().count() )
2077 performRestoring( aDlg->currentItem() );
2081 \brief Restore view parameters.
2082 \param anItem view parameters
2084 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
2086 Handle(V3d_View) aView3d = myViewPort->getView();
2088 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
2089 aView3d->SetScale( anItem.scale );
2090 aView3d->SetTwist( anItem.twist );
2091 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
2092 aView3d->SetImmediateUpdate( prev );
2093 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2094 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2095 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
2097 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
2099 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
2101 // "eye" and "at" require conversion to represent center panning
2102 // up direction is only available after setting angle of twist and
2103 // other view parameters
2104 aView3d->Up( anUpX, anUpY, anUpZ );
2106 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
2107 gp_Dir anUp( anUpX, anUpY, anUpZ );
2108 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
2109 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2110 gp_Dir aSide = aProj ^ anUp;
2112 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
2113 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
2115 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
2116 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2119 if ( !baseParamsOnly ) {
2121 myModel->setTrihedronShown( anItem.isVisible );
2122 myModel->setTrihedronSize( anItem.size );
2124 // graduated trihedron
2125 bool anIsVisible = anItem.gtIsVisible;
2126 OCCViewer_AxisWidget::AxisData anAxisData[3];
2127 anAxisData[0].DrawName = anItem.gtDrawNameX;
2128 anAxisData[1].DrawName = anItem.gtDrawNameZ;
2129 anAxisData[2].DrawName = anItem.gtDrawNameZ;
2130 anAxisData[0].Name = anItem.gtNameX;
2131 anAxisData[1].Name = anItem.gtNameZ;
2132 anAxisData[2].Name = anItem.gtNameZ;
2133 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
2134 anItem.gtNameColorGX,
2135 anItem.gtNameColorBX );
2136 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
2137 anItem.gtNameColorGY,
2138 anItem.gtNameColorBY );
2139 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
2140 anItem.gtNameColorGZ,
2141 anItem.gtNameColorBZ );
2142 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
2143 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
2144 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
2145 anAxisData[0].NbValues = anItem.gtNbValuesX;
2146 anAxisData[1].NbValues = anItem.gtNbValuesY;
2147 anAxisData[2].NbValues = anItem.gtNbValuesZ;
2148 anAxisData[0].Offset = anItem.gtOffsetX;
2149 anAxisData[1].Offset = anItem.gtOffsetY;
2150 anAxisData[2].Offset = anItem.gtOffsetZ;
2151 anAxisData[0].Color = QColor( anItem.gtColorRX,
2154 anAxisData[1].Color = QColor( anItem.gtColorRY,
2157 anAxisData[2].Color = QColor( anItem.gtColorRZ,
2160 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
2161 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
2162 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
2163 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
2164 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
2165 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
2167 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
2168 myCubeAxesDlg->ApplyData( aView3d );
2170 } // if ( !baseParamsOnly )
2176 \brief Set restore flag.
2178 void OCCViewer_ViewWindow::setRestoreFlag()
2184 \brief Called when action "show/hide trihedron" is activated.
2186 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
2188 myModel->setTrihedronShown(show);
2192 \brief Toggles preselection (highlighting) on/off
2194 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
2196 myPreselectionEnabled = on;
2197 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
2199 // unhighlight all highlighted objects
2201 myModel->unHighlightAll( true, false );
2204 // update action state if method is called outside
2205 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2206 if ( a && a->isChecked() != on ) {
2207 a->setChecked( on );
2212 \brief Toggles selection on/off
2214 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
2216 mySelectionEnabled = on;
2217 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
2219 // update action state if method is called outside
2222 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2224 a->setEnabled( on );
2228 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
2229 if ( a && a->isChecked() != on ) {
2230 a->setChecked( on );
2235 \brief Switches style of advanced multiple selection by Poligon/Circle
2237 void OCCViewer_ViewWindow::onSwitchSelectionStyle(QAction* theAction)
2240 OCCViewer_ViewSketcher* aSkecher = getSketcher(Polygon);
2242 if (theAction == toolMgr()->action(PolygonSelectionStyleId)) {
2243 aSkecher->setSketcherMode(OCCViewer_PolygonSketcher::Poligone);
2245 else if (theAction == toolMgr()->action(CircleSelectionStyleId)) {
2246 aSkecher->setSketcherMode(OCCViewer_PolygonSketcher::Circle);
2252 Returns currently selected selection style
2254 OCCViewer_ViewWindow::SelectionStyle OCCViewer_ViewWindow::selectionStyle() const
2256 if (toolMgr()->action(PolygonSelectionStyleId)->isChecked())
2257 return PolygonStyle;
2258 if (toolMgr()->action(CircleSelectionStyleId)->isChecked())
2263 void OCCViewer_ViewWindow::setSelectionStyle(SelectionStyle theMode)
2265 toolMgr()->action(RectangleSelectionStyleId)->setChecked(false);
2266 toolMgr()->action(PolygonSelectionStyleId)->setChecked(false);
2267 toolMgr()->action(CircleSelectionStyleId)->setChecked(false);
2270 toolMgr()->action(RectangleSelectionStyleId)->setChecked(true);
2273 toolMgr()->action(PolygonSelectionStyleId)->setChecked(true);
2276 toolMgr()->action(CircleSelectionStyleId)->setChecked(true);
2281 \brief Switches "keyboard free" interaction style on/off
2283 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
2285 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
2287 // update action state if method is called outside
2288 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
2289 if ( a && a->isChecked() != on )
2290 a->setChecked( on );
2294 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
2296 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
2298 myViewPort->setAdvancedZoomingEnabled( on );
2300 // update action state if method is called outside
2301 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
2302 if ( a && a->isChecked() != on )
2303 a->setChecked( on );
2307 \brief Get current interaction style
2308 \return interaction style
2310 int OCCViewer_ViewWindow::interactionStyle() const
2312 return myInteractionStyle;
2316 \brief Set current interaction style
2317 \param theStyle interaction style
2319 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
2321 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
2325 \brief Get current zooming style
2326 \return zooming style
2328 int OCCViewer_ViewWindow::zoomingStyle() const
2330 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
2334 \brief Set current zooming style
2335 \param theStyle zooming style
2337 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
2339 onSwitchZoomingStyle( theStyle == 1 );
2343 \brief Dump view window contents to the pixmap.
2344 \return pixmap containing all scene rendered in the window
2346 //#define USE_OLD_IMPLEMENTATION
2347 QImage OCCViewer_ViewWindow::dumpView()
2349 Handle(V3d_View) view = myViewPort->getView();
2350 if ( view.IsNull() )
2353 int aWidth = myViewPort->width();
2354 int aHeight = myViewPort->height();
2356 #ifdef USE_OLD_IMPLEMENTATION
2357 // rnv: Old approach to dump the OCCViewer content via Frame Buffer Object
2361 #ifndef DISABLE_GLVIEWER
2362 OpenGLUtils_FrameBuffer aFrameBuffer;
2363 if ( aFrameBuffer.init( aWidth, aHeight ) )
2365 glPushAttrib( GL_VIEWPORT_BIT );
2366 glViewport( 0, 0, aWidth, aHeight );
2367 aFrameBuffer.bind();
2372 aFrameBuffer.unbind();
2375 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
2377 aFrameBuffer.bind();
2378 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
2379 aFrameBuffer.unbind();
2381 anImage = anImage.rgbSwapped();
2382 anImage = anImage.mirrored();
2386 // if frame buffers are unsupported, use old approach
2388 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
2389 QPoint p = myViewPort->mapFromParent( myViewPort->geometry().topLeft() );
2390 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
2392 QImage anImage( data, aWidth, aHeight, QImage::Format_ARGB32 );
2393 anImage = anImage.mirrored();
2394 anImage = anImage.rgbSwapped();
2397 #else // DISABLE_GLVIEWER
2401 #endif // DISABLE_GLVIEWER
2403 #else // USE_OLD_IMPLEMENTATION
2404 // rnv: New approach is to use OCCT built-in procedure
2407 view->ToPixMap(aPix, aWidth, aHeight, Graphic3d_BT_RGB);
2409 QImage anImage( aWidth, aHeight, QImage::Format_ARGB32 );
2410 for ( int i = 0; i < aWidth; i++ ) {
2411 for ( int j = 0; j < aHeight; j++ ) {
2412 Quantity_Color pixel = aPix.PixelColor( i, j ).GetRGB();
2413 QColor color = QColor::fromRgbF( pixel.Red(), pixel.Green(), pixel.Blue() );
2414 anImage.setPixelColor( i, j, color );
2418 if ( aPix.IsTopDown() )
2419 anImage = anImage.mirrored();
2422 #endif // USE_OLD_IMPLEMENTATION
2425 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
2426 const QString& fileName,
2427 const QString& format )
2430 QApplication::setOverrideCursor( Qt::WaitCursor );
2432 // OCCT version > 7.3.0 is not support export to PS and EPS
2433 #if OCC_VERSION_LARGE <= 0x07030000
2434 Handle(Graphic3d_CView) a3dView = myViewPort->getView()->View();
2436 if (format == "PS") {
2437 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(myViewPort->getViewer()->Driver());
2438 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
2439 int prev = aCaps->ffpEnable;
2440 aCaps->ffpEnable = 1;
2441 res = a3dView->Export(strdup(qUtf8Printable(fileName)), Graphic3d_EF_PostScript);
2442 aCaps->ffpEnable = prev;
2444 else if (format == "EPS") {
2445 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(myViewPort->getViewer()->Driver());
2446 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
2447 int prev = aCaps->ffpEnable;
2448 aCaps->ffpEnable = 1;
2449 res = a3dView->Export(strdup(qUtf8Printable(fileName)), Graphic3d_EF_EnhPostScript);
2450 aCaps->ffpEnable = prev;
2454 res = myViewPort->getView()->Dump( fileName.toStdString().c_str() );
2455 #if OCC_VERSION_LARGE <= 0x07030000
2459 QApplication::restoreOverrideCursor();
2464 QString OCCViewer_ViewWindow::filter() const
2466 #if OCC_VERSION_LARGE <= 0x07030000
2467 return tr( "OCC_IMAGE_FILES" );
2469 QString formats = tr( "OCC_IMAGE_FILES" );
2470 return formats.remove(" *.eps *.ps");
2476 \brief Set parameters of the cutting plane
2477 \param on if \c true, cutting plane is enabled
2478 \param x X position of plane point
2479 \param y Y position of plane point
2480 \param z Z position of plane point
2481 \param dx X coordinate of plane normal
2482 \param dy Y coordinate of plane normal
2483 \param dz Z coordinate of plane normal
2485 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2486 const double dx, const double dy, const double dz )
2488 Handle(V3d_View) view = myViewPort->getView();
2489 if ( view.IsNull() )
2493 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2495 // try to use already existing plane or create a new one
2496 Handle(V3d_Plane) clipPlane;
2498 // calculate new a,b,c,d values for the plane
2499 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2501 pln.Coefficients(a, b, c, d);
2502 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2503 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2504 if(aPlanes->Size() > 0 ) {
2505 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2506 aClipPlane->SetEquation(pln);
2507 aClipPlane->SetOn(Standard_True);
2509 view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2513 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2514 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2515 for( ;anIter.More();anIter.Next() ){
2516 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2517 aClipPlane->SetOn(Standard_False);
2525 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2527 gp_Dir aDir = pln.Axis().Direction();
2528 gp_Pnt aPnt = pln.Location();
2529 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2534 \brief Check if any cutting plane is enabled
2535 \return \c true if at least one cutting plane is enabled
2537 bool OCCViewer_ViewWindow::isCuttingPlane()
2539 Handle(V3d_View) view = myViewPort->getView();
2541 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2542 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2543 for( ;anIter.More();anIter.Next() ) {
2544 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2545 if(aClipPlane->IsOn()) {
2554 \brief Get the visual parameters of the view window.
2555 \return visual parameters of view window
2557 viewAspect OCCViewer_ViewWindow::getViewParams() const
2559 double projX, projY, projZ, twist;
2560 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2561 double aScaleX, aScaleY, aScaleZ;
2563 Handle(V3d_View) aView3d = myViewPort->getView();
2565 aView3d->Proj( projX, projY, projZ );
2566 aView3d->At( atX, atY, atZ );
2567 aView3d->Eye( eyeX, eyeY, eyeZ );
2568 twist = aView3d->Twist();
2570 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2572 bool isShown = myModel->isTrihedronVisible();
2573 double size = myModel->trihedronSize();
2575 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2578 params.scale = aView3d->Scale();
2579 params.projX = projX;
2580 params.projY = projY;
2581 params.projZ = projZ;
2582 params.twist = twist;
2589 params.scaleX = aScaleX;
2590 params.scaleY = aScaleY;
2591 params.scaleZ = aScaleZ;
2592 params.name = aName;
2593 params.isVisible= isShown;
2596 // graduated trihedron
2597 bool anIsVisible = false;
2598 OCCViewer_AxisWidget::AxisData anAxisData[3];
2599 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2601 params.gtIsVisible = anIsVisible;
2602 params.gtDrawNameX = anAxisData[0].DrawName;
2603 params.gtDrawNameY = anAxisData[1].DrawName;
2604 params.gtDrawNameZ = anAxisData[2].DrawName;
2605 params.gtNameX = anAxisData[0].Name;
2606 params.gtNameY = anAxisData[1].Name;
2607 params.gtNameZ = anAxisData[2].Name;
2608 params.gtNameColorRX = anAxisData[0].NameColor.red();
2609 params.gtNameColorGX = anAxisData[0].NameColor.green();
2610 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2611 params.gtNameColorRY = anAxisData[1].NameColor.red();
2612 params.gtNameColorGY = anAxisData[1].NameColor.green();
2613 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2614 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2615 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2616 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2617 params.gtDrawValuesX = anAxisData[0].DrawValues;
2618 params.gtDrawValuesY = anAxisData[1].DrawValues;
2619 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2620 params.gtNbValuesX = anAxisData[0].NbValues;
2621 params.gtNbValuesY = anAxisData[1].NbValues;
2622 params.gtNbValuesZ = anAxisData[2].NbValues;
2623 params.gtOffsetX = anAxisData[0].Offset;
2624 params.gtOffsetY = anAxisData[1].Offset;
2625 params.gtOffsetZ = anAxisData[2].Offset;
2626 params.gtColorRX = anAxisData[0].Color.red();
2627 params.gtColorGX = anAxisData[0].Color.green();
2628 params.gtColorBX = anAxisData[0].Color.blue();
2629 params.gtColorRY = anAxisData[1].Color.red();
2630 params.gtColorGY = anAxisData[1].Color.green();
2631 params.gtColorBY = anAxisData[1].Color.blue();
2632 params.gtColorRZ = anAxisData[2].Color.red();
2633 params.gtColorGZ = anAxisData[2].Color.green();
2634 params.gtColorBZ = anAxisData[2].Color.blue();
2635 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2636 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2637 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2638 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2639 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2640 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2646 \brief Get visual parameters of this view window.
2647 \return visual parameters of view window
2649 QString OCCViewer_ViewWindow::getVisualParameters()
2651 viewAspect params = getViewParams();
2655 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2656 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2657 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2658 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2659 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2660 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2661 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2662 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2663 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2664 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2665 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2666 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2667 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2668 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2669 data << QString( "isVisible=%1" ).arg( params.isVisible );
2670 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2672 ClipPlanesList aPlanes = myModel->getClipPlanes();
2673 for ( int i=0; i < aPlanes.size(); i++ )
2675 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2676 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2677 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2678 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2679 switch ( aPlane.Mode )
2681 case OCCViewer_ClipPlane::Absolute :
2683 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2685 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2687 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2688 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2689 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2693 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2698 case OCCViewer_ClipPlane::Relative :
2700 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2701 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2702 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2707 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2708 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2709 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2710 data << ClippingPlane;
2713 // graduated trihedron
2714 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2715 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2716 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2717 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2718 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2719 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2720 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2721 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2722 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2723 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2724 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2725 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2726 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2727 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2728 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2729 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2730 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2731 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2732 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2733 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2734 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2735 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2736 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2737 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2738 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2739 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2740 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2741 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2742 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2743 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2744 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2745 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2746 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2747 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2748 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2749 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2750 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2751 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2752 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2753 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2755 // ray tracing parameters
2756 Graphic3d_RenderingParams rendParams = this->getViewPort()->getView()->RenderingParams();
2757 if ( rendParams.Method == Graphic3d_RM_RAYTRACING ) {
2758 QString RayTracing = "rayTracing=";
2759 RayTracing += QString( "rtDepth~%1;" ).arg( rendParams.RaytracingDepth );
2760 RayTracing += QString( "rtReflection~%1;" ).arg( rendParams.IsReflectionEnabled );
2761 RayTracing += QString( "rtAntialiasing~%1;" ).arg( rendParams.IsAntialiasingEnabled );
2762 RayTracing += QString( "rtShadow~%1;" ).arg( rendParams.IsShadowEnabled );
2763 RayTracing += QString( "rtTransShadow~%1;" ).arg( rendParams.IsTransparentShadowEnabled );
2767 // environment texture parameters
2768 Handle(Graphic3d_TextureEnv) aTexture = this->getViewPort()->getView()->TextureEnv();
2769 if ( !aTexture.IsNull() ) {
2770 QString EnvTexture = "envTexture=";
2771 if ( aTexture->Name() == Graphic3d_NOT_ENV_UNKNOWN ) {
2772 TCollection_AsciiString aFileName;
2773 aTexture->Path().SystemName( aFileName );
2774 EnvTexture += QString( "etFile~%1;" ).arg( aFileName.ToCString() );
2777 EnvTexture += QString( "etNumber~%1;" ).arg( aTexture->Name() );
2781 // light source parameters
2782 myModel->getViewer3d()->InitDefinedLights();
2783 while ( myModel->getViewer3d()->MoreDefinedLights() )
2785 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2786 if ( aLight->Type() != V3d_AMBIENT ) {
2787 QString LightSource = QString( "lightSource=" );
2788 LightSource += QString( "lightType~%1;" ).arg( aLight->Type() );
2790 if ( aLight->Type() == V3d_DIRECTIONAL )
2791 Handle(V3d_DirectionalLight)::DownCast( aLight )->Direction( aX, aY, aZ );
2792 else if ( aLight->Type() == V3d_POSITIONAL )
2793 Handle(V3d_PositionalLight)::DownCast( aLight )->Position( aX, aY, aZ );
2794 LightSource += QString( "lightX~%1;" ).arg( aX );
2795 LightSource += QString( "lightY~%1;" ).arg( aY );
2796 LightSource += QString( "lightZ~%1;" ).arg( aZ );
2797 LightSource += QString( "lightColorR~%1;" ).arg( aLight->Color().Red() );
2798 LightSource += QString( "lightColorG~%1;" ).arg( aLight->Color().Green() );
2799 LightSource += QString( "lightColorB~%1;" ).arg( aLight->Color().Blue() );
2800 LightSource += QString( "lightHeadlight~%1;" ).arg( aLight->Headlight() );
2801 data << LightSource;
2803 myModel->getViewer3d()->NextDefinedLights();
2806 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2807 data << QString( "background=%1" ).arg( bg );
2809 return data.join("*");
2813 \brief Restore visual parameters of the view window.
2814 \param parameters visual parameters of view window
2816 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2819 ClipPlanesList aClipPlanes;
2820 QStringList data = parameters.split( '*' );
2821 Qtx::BackgroundData bgData;
2822 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2824 foreach( QString param, data ) {
2825 QString paramName = param.section( '=', 0, 0 ).trimmed();
2826 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2827 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2828 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2829 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2830 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2831 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2832 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2833 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2834 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2835 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2836 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2837 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2838 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2839 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2840 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2841 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2842 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2843 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2844 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2845 else if ( paramName.contains( "ClippingPlane" ) )
2847 QStringList ClipPlaneData = paramValue.split( ';' );
2848 OCCViewer_ClipPlane aPlane;
2849 foreach( QString ClipPlaneParam, ClipPlaneData )
2851 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2852 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2853 if ( ClipPlane_paramName == "Mode" )
2855 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2857 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2858 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2859 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2860 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2863 switch ( aPlane.Mode )
2865 case OCCViewer_ClipPlane::Absolute :
2866 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2867 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2868 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2869 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2870 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2873 case OCCViewer_ClipPlane::Relative :
2874 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2875 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2876 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2881 aClipPlanes.push_back(aPlane);
2883 // graduated trihedron
2884 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2885 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2886 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2887 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2888 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2889 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2890 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2891 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2892 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2893 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2894 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2895 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2896 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2897 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2898 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2899 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2900 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2901 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2902 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2903 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2904 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2905 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2906 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2907 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2908 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2909 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2910 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2911 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2912 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2913 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2914 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2915 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2916 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2917 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2918 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2919 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2920 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2921 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2922 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2923 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2924 else if ( paramName == "rayTracing" )
2926 Graphic3d_RenderingParams& rendParams = this->getViewPort()->getView()->ChangeRenderingParams();
2927 rendParams.Method = Graphic3d_RM_RAYTRACING;
2928 QStringList rtData = paramValue.split( ';' );
2929 foreach( QString rtParam, rtData )
2931 QString rt_paramName = rtParam.section( '~', 0, 0 ).trimmed();
2932 QString rt_paramValue = rtParam.section( '~', 1, 1 ).trimmed();
2933 if ( rt_paramName == "rtDepth" ) rendParams.RaytracingDepth = rt_paramValue.toInt();
2934 else if ( rt_paramName == "rtReflection" ) rendParams.IsReflectionEnabled = rt_paramValue.toInt();
2935 else if ( rt_paramName == "rtAntialiasing" ) rendParams.IsAntialiasingEnabled = rt_paramValue.toInt();
2936 else if ( rt_paramName == "rtShadow" ) rendParams.IsShadowEnabled = rt_paramValue.toInt();
2937 else if ( rt_paramName == "rtTransShadow" ) rendParams.IsTransparentShadowEnabled = rt_paramValue.toInt();
2940 else if ( paramName == "envTexture" )
2942 Handle(Graphic3d_TextureEnv) aTexture;
2943 QStringList etData = paramValue.split( ';' );
2944 foreach( QString etParam, etData )
2946 QString et_paramName = etParam.section( '~', 0, 0 ).trimmed();
2947 QString et_paramValue = etParam.section( '~', 1, 1 ).trimmed();
2948 if ( et_paramName == "etNumber" )
2949 aTexture = new Graphic3d_TextureEnv( Graphic3d_NameOfTextureEnv( et_paramValue.toInt() ) );
2950 else if ( et_paramName == "etFile" )
2951 aTexture = new Graphic3d_TextureEnv( TCollection_AsciiString( et_paramValue.toStdString().c_str() ) );
2952 Handle(V3d_View) aView = this->getViewPort()->getView();
2953 aView->SetTextureEnv( aTexture );
2956 else if ( paramName == "lightSource" )
2958 myModel->getViewer3d()->InitDefinedLights();
2959 while ( myModel->getViewer3d()->MoreDefinedLights() )
2961 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2962 if( aLight->Type() != V3d_AMBIENT ) {
2963 myModel->getViewer3d()->DelLight( aLight );
2964 myModel->getViewer3d()->InitDefinedLights();
2966 myModel->getViewer3d()->NextDefinedLights();
2971 V3d_TypeOfLight aType;
2973 QStringList lsData = paramValue.split( ';' );
2974 foreach( QString lsParam, lsData )
2976 QString ls_paramName = lsParam.section( '~', 0, 0 ).trimmed();
2977 QString ls_paramValue = lsParam.section( '~', 1, 1 ).trimmed();
2978 if ( ls_paramName == "lightType" ) aType = V3d_TypeOfLight( ls_paramValue.toInt() );
2979 else if ( ls_paramName == "lightX" ) aX = ls_paramValue.toDouble();
2980 else if ( ls_paramName == "lightY" ) aY = ls_paramValue.toDouble();
2981 else if ( ls_paramName == "lightZ" ) aZ = ls_paramValue.toDouble();
2982 else if ( ls_paramName == "lightColorR" ) cR = ls_paramValue.toDouble();
2983 else if ( ls_paramName == "lightColorG" ) cG = ls_paramValue.toDouble();
2984 else if ( ls_paramName == "lightColorB" ) cB = ls_paramValue.toDouble();
2985 else if ( ls_paramName == "lightHeadlight" ) isHeadlight = ls_paramValue.toInt();
2987 Quantity_Color aColor = Quantity_Color( cR, cG, cB, Quantity_TOC_RGB );
2988 if( aType == V3d_DIRECTIONAL ) {
2989 Handle(V3d_DirectionalLight) aLight = new V3d_DirectionalLight();
2990 myModel->getViewer3d()->AddLight( aLight );
2991 aLight->SetDirection( aX, aY, aZ );
2992 aLight->SetColor( aColor );
2993 aLight->SetHeadlight( isHeadlight );
2994 myModel->getViewer3d()->SetLightOn( aLight );
2996 else if( aType == V3d_POSITIONAL ) {
2997 Handle(V3d_PositionalLight) aLight = new V3d_PositionalLight( gp_Pnt(aX, aY, aZ), aColor.Name() );
2998 myModel->getViewer3d()->AddLight( aLight );
2999 aLight->SetHeadlight( isHeadlight );
3000 myModel->getViewer3d()->SetLightOn( aLight );
3003 else if ( paramName == "background" ) {
3004 QString bg = paramValue.replace( "$", "=" );
3005 bgData = Qtx::stringToBackground( bg );
3009 else // old format - "1.000e+00*0.000e+00..."
3012 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
3013 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
3014 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
3015 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
3016 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
3017 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
3018 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
3019 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
3020 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
3021 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
3022 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
3023 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
3024 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
3025 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
3026 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
3027 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
3028 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
3029 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
3031 performRestoring( params );
3032 setBackground( bgData );
3033 myModel->setClipPlanes(aClipPlanes);
3037 \brief Handle show event.
3039 Emits Show() signal.
3041 \param theEvent show event
3043 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
3045 emit Show( theEvent );
3049 \brief Handle hide event.
3051 Emits Hide() signal.
3053 \param theEvent hide event
3055 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
3057 emit Hide( theEvent );
3062 Save old cursor. [ protected ]
3064 void OCCViewer_ViewWindow::saveCursor()
3066 QCursor* aCursor = NULL;
3068 aCursor = myViewPort->getDefaultCursor();
3069 myCursor = ( aCursor ? *aCursor : cursor() );
3074 Creates default sketcher. [ virtual protected ]
3076 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
3079 return new OCCViewer_RectSketcher( this, type );
3080 if ( type == Polygon )
3081 return new OCCViewer_PolygonSketcher( this, type );
3085 void OCCViewer_ViewWindow::initSketchers()
3087 if ( mySketchers.isEmpty() )
3089 mySketchers.append( createSketcher( Rect ) );
3090 mySketchers.append( createSketcher( Polygon ) );
3094 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ ) const
3096 OCCViewer_ViewSketcher* sketcher = 0;
3097 QList<OCCViewer_ViewSketcher*>::ConstIterator it;
3098 for ( it = mySketchers.cbegin(); it != mySketchers.cend() && !sketcher; ++it )
3100 OCCViewer_ViewSketcher* sk = (*it);
3101 if ( sk->type() == typ )
3108 Handles requests for sketching in the active view. [ virtual public ]
3110 void OCCViewer_ViewWindow::activateSketching( int type )
3112 OCCViewer_ViewPort3d* vp = getViewPort();
3116 if ( !vp->isSketchingEnabled() )
3119 /* Finish current sketching */
3120 if ( type == NoSketching )
3124 onSketchingFinished();
3125 mypSketcher->deactivate();
3129 /* Activate new sketching */
3132 activateSketching( NoSketching ); /* concurrency not suported */
3133 mypSketcher = getSketcher( type );
3136 mypSketcher->activate();
3137 onSketchingStarted();
3143 Unhilights detected entities. [ virtual protected ]
3145 void OCCViewer_ViewWindow::onSketchingStarted()
3150 Selection by rectangle or polygon. [ virtual protected ]
3152 void OCCViewer_ViewWindow::onSketchingFinished()
3154 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
3155 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
3157 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
3158 bool append = mypSketcher->isHasShift();
3159 switch( mypSketcher->type() )
3163 QRect* aRect = (QRect*)mypSketcher->data();
3166 int aLeft = aRect->left();
3167 int aRight = aRect->right();
3168 int aTop = aRect->top();
3169 int aBottom = aRect->bottom();
3173 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False);
3175 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False);
3181 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
3182 if( aPolygon && (aPolygon->size() > 2))
3184 int size = aPolygon->size();
3185 TColgp_Array1OfPnt2d anArray(1, size);
3187 QPolygon::Iterator it = aPolygon->begin();
3188 QPolygon::Iterator itEnd = aPolygon->end();
3189 for (int index = 1; it != itEnd; ++it, index++)
3191 QPoint aPoint = *it;
3192 anArray.SetValue(index, gp_Pnt2d(aPoint.x(), aPoint.y()));
3196 ic->ShiftSelect(anArray, getViewPort()->getView(), Standard_False);
3198 ic->Select(anArray, getViewPort()->getView(), Standard_False);
3206 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
3207 aViewMgr->getOCCViewer()->performSelectionChanged();
3211 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
3216 bool OCCViewer_ViewWindow::transformRequested() const
3218 return ( myOperation != NOVIEWOP );
3221 bool OCCViewer_ViewWindow::transformInProcess() const
3223 return myEventStarted;
3226 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
3228 myEventStarted = bOn;
3232 Set enabled state of transformation (rotate, zoom, etc)
3234 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
3236 if ( id != NOVIEWOP ) myStatus.insert( id, on );
3240 \return enabled state of transformation (rotate, zoom, etc)
3242 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
3244 return myStatus.contains( id ) ? myStatus[ id ] : true;
3247 void OCCViewer_ViewWindow::onMaximizedView()
3249 setMaximized(!isMaximized());
3252 void OCCViewer_ViewWindow::returnTo3dView()
3254 setReturnedTo3dView( true );
3257 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
3259 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
3260 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
3261 if ( !isVisible3dView )
3262 toolMgr()->show( ReturnTo3dViewId );
3264 toolMgr()->hide( ReturnTo3dViewId );
3265 if ( isVisible3dView ) emit returnedTo3d( );
3269 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
3271 QAction* anAction = toolMgr()->action( MaximizedId );
3272 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
3273 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
3275 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
3276 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
3277 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
3278 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
3279 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
3281 emit maximized( this, true );
3285 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
3286 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
3287 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
3288 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
3289 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
3291 emit maximized( this, false );
3296 bool OCCViewer_ViewWindow::isMaximized() const
3298 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
3301 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
3303 IsSketcherStyle = enable;
3306 bool OCCViewer_ViewWindow::isSketcherStyle() const
3308 return IsSketcherStyle;
3312 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
3317 int OCCViewer_ViewWindow::projectionType() const
3319 int mode = Orthographic;
3320 Handle(V3d_View) aView3d = myViewPort->getView();
3321 if ( !aView3d.IsNull() ) {
3322 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3323 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Perspective)
3325 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Orthographic)
3326 mode = Orthographic;
3327 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
3333 void OCCViewer_ViewWindow::setStereoType( int type )
3335 Handle(V3d_View) aView3d = myViewPort->getView();
3336 if ( !aView3d.IsNull() ) {
3337 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3338 aParams->StereoMode = (Graphic3d_StereoMode)type;
3342 int OCCViewer_ViewWindow::stereoType() const
3344 int type = QuadBuffer;
3345 Handle(V3d_View) aView3d = myViewPort->getView();
3346 if ( !aView3d.IsNull() ) {
3347 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3348 type = (OCCViewer_ViewWindow::StereoType)aParams->StereoMode;
3353 void OCCViewer_ViewWindow::setAnaglyphFilter( int type )
3355 Handle(V3d_View) aView3d = myViewPort->getView();
3356 if ( !aView3d.IsNull() ) {
3357 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3358 if (type == RedCyan)
3359 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
3360 if (type == YellowBlue)
3361 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
3362 if (type == GreenMagenta)
3363 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
3367 int OCCViewer_ViewWindow::anaglyphFilter() const
3370 Handle(V3d_View) aView3d = myViewPort->getView();
3371 if ( !aView3d.IsNull() ) {
3372 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3373 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized)
3375 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized)
3377 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple)
3378 type = GreenMagenta;
3383 void OCCViewer_ViewWindow::setStereographicFocus( int type, double value )
3385 Handle(V3d_View) aView3d = myViewPort->getView();
3386 if ( !aView3d.IsNull() ) {
3387 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3388 aCamera->SetZFocus( (Graphic3d_Camera::FocusType) type, value );
3392 int OCCViewer_ViewWindow::stereographicFocusType() const
3394 int type = Relative;
3395 Handle(V3d_View) aView3d = myViewPort->getView();
3396 if ( !aView3d.IsNull() ) {
3397 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3398 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->ZFocusType();
3403 double OCCViewer_ViewWindow::stereographicFocusValue() const
3406 Handle(V3d_View) aView3d = myViewPort->getView();
3407 if ( !aView3d.IsNull() ) {
3408 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3409 value = aCamera->ZFocus();
3414 void OCCViewer_ViewWindow::setInterocularDistance( int type, double value )
3416 Handle(V3d_View) aView3d = myViewPort->getView();
3417 if ( !aView3d.IsNull() ) {
3418 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3419 aCamera->SetIOD( (Graphic3d_Camera::IODType) type, value );
3423 int OCCViewer_ViewWindow::interocularDistanceType() const
3425 int type = Relative;
3426 Handle(V3d_View) aView3d = myViewPort->getView();
3427 if ( !aView3d.IsNull() ) {
3428 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3429 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->GetIODType();
3434 double OCCViewer_ViewWindow::interocularDistanceValue() const
3436 double value = 0.05;
3437 Handle(V3d_View) aView3d = myViewPort->getView();
3438 if ( !aView3d.IsNull() ) {
3439 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3440 value = aCamera->IOD();
3445 void OCCViewer_ViewWindow::setReverseStereo( bool reverse )
3447 Handle(V3d_View) aView3d = myViewPort->getView();
3448 if ( !aView3d.IsNull() ) {
3449 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3450 aParams->ToReverseStereo = reverse;
3454 bool OCCViewer_ViewWindow::isReverseStereo() const
3456 int reverse = false;
3457 Handle(V3d_View) aView3d = myViewPort->getView();
3458 if ( !aView3d.IsNull() ) {
3459 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3460 reverse = aParams->ToReverseStereo;
3465 void OCCViewer_ViewWindow::setVSync( bool enable )
3467 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3468 if ( !anIntCont.IsNull() ) {
3469 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3470 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3471 aCaps->swapInterval = enable;
3475 bool OCCViewer_ViewWindow::isVSync() const
3478 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3479 if ( !anIntCont.IsNull() ) {
3480 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3481 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3482 enable = aCaps->swapInterval;
3487 void OCCViewer_ViewWindow::setQuadBufferSupport( bool enable )
3489 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3490 if ( !anIntCont.IsNull() ) {
3491 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3492 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3493 aCaps->contextStereo = enable;
3497 bool OCCViewer_ViewWindow::isQuadBufferSupport() const
3500 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3501 if ( !anIntCont.IsNull() ) {
3502 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3503 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3504 enable = aCaps->contextStereo;
3509 bool OCCViewer_ViewWindow::isOpenGlStereoSupport() const
3511 GLboolean support[1];
3512 glGetBooleanv (GL_STEREO, support);
3519 QColor OCCViewer_ViewWindow::backgroundColor() const
3521 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
3525 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
3527 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
3530 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
3532 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
3535 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
3537 if ( myViewPort ) myViewPort->setBackground( theBackground );
3540 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
3542 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
3548 void OCCViewer_ViewWindow::clearViewAspects()
3550 myViewAspects.clear();
3554 \return const reference to list of view aspects
3556 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
3558 return myViewAspects;
3562 Appends new view aspect
3563 \param aParams - new view aspects
3565 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
3567 myViewAspects.append( aParams );
3571 Replaces old view aspects by new ones
3572 \param aViewList - list of new view aspects
3574 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
3576 myViewAspects = aViewList;
3580 Get camera properties for the OCC view window.
3581 \return shared pointer on camera properties.
3583 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
3585 SUIT_CameraProperties aProps;
3587 Handle(V3d_View) aSourceView = getViewPort()->getView();
3588 if ( aSourceView.IsNull() )
3591 if ( get2dMode() == No2dMode ) {
3592 aProps.setDimension( SUIT_CameraProperties::Dim3D );
3595 aProps.setDimension( SUIT_CameraProperties::Dim2D );
3596 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
3599 // read common properites of the view
3600 Standard_Real anUp[3];
3601 Standard_Real anAt[3];
3602 Standard_Real anEye[3];
3603 Standard_Real aProj[3];
3604 Standard_Real anAxialScale[3];
3606 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
3607 aSourceView->At( anAt[0], anAt[1], anAt[2] );
3608 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
3609 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3611 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3612 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
3614 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
3616 // store camera properties "as is": it is up to synchronized
3617 // view classes to provide necessary property conversion.
3618 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
3619 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
3621 if ( aSourceView->Camera()->IsOrthographic() )
3623 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
3624 aProps.setViewAngle( 0.0 );
3628 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
3629 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
3631 aProps.setMappingScale( aSourceView->Camera()->Scale() );
3638 This implementation synchronizes OCC view's camera propreties.
3640 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
3642 bool blocked = blockSignals( true );
3644 SUIT_CameraProperties aProps = theView->cameraProperties();
3645 if ( !cameraProperties().isCompatible( aProps ) ) {
3646 // other view, this one is being currently synchronized to, seems has become incompatible
3647 // we have to break synchronization
3652 Handle(V3d_View) aDestView = getViewPort()->getView();
3654 aDestView->SetImmediateUpdate( Standard_False );
3657 double aPosition[3];
3658 double aFocalPoint[3];
3659 double anAxialScale[3];
3661 // get common properties
3662 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3663 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
3664 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3665 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3668 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3669 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
3670 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3671 aDestView->Camera()->SetScale( aProps.getMappingScale() );
3673 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3674 aDestView->SetImmediateUpdate( Standard_True );
3675 aDestView->Redraw();
3677 catch (Standard_Failure) {
3680 blockSignals( blocked );
3684 \brief Indicates whether preselection is enabled
3685 \return true if preselection is enabled
3687 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
3689 return myPreselectionEnabled;
3693 \brief Enables/disables preselection
3694 \param theIsToEnable if true - preselection will be enabled
3696 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
3698 onSwitchPreselection( theIsToEnable );
3702 \brief Indicates whether selection is enabled
3703 \return true if selection is enabled
3705 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3707 return mySelectionEnabled;
3711 \brief Enables/disables selection
3712 \param theIsToEnable if true - selection will be enabled
3714 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3716 onSwitchSelection( theIsToEnable );
3721 \brief called if clipping operation is activated / deactivated.
3723 Enables/disables clipping plane displaying.
3725 \parma on action state
3727 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3729 if(!myModel) return;
3730 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3733 if (!aClippingDlg) {
3734 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3735 myModel->setClippingDlg(aClippingDlg);
3737 if (!aClippingDlg->isVisible())
3738 aClippingDlg->show();
3740 if ( aClippingDlg ) {
3741 aClippingDlg->close();
3742 myModel->setClippingDlg(0);
3746 SUIT_ViewManager* mgr = getViewManager();
3748 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3749 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3750 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3751 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3753 QAction* a = toolMgr()->action( ClippingId );
3755 if(theIsOn != a->isChecked()){
3756 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3757 a->setChecked(theIsOn);
3758 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3765 void OCCViewer_ViewWindow::onRayTracing()
3767 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_RayTracingDlg::getName() ) ) {
3768 QDialog* aDlg = new OCCViewer_RayTracingDlg( this );
3774 void OCCViewer_ViewWindow::onEnvTexture()
3776 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_EnvTextureDlg::getName() ) ) {
3777 QDialog* aDlg = new OCCViewer_EnvTextureDlg( this );
3783 void OCCViewer_ViewWindow::onLightSource()
3785 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_LightSourceDlg::getName() ) ) {
3786 QDialog* aDlg = new OCCViewer_LightSourceDlg( this, myModel );
3792 bool OCCViewer_ViewWindow::isActionVisible( ActionId theId ) const
3794 QAction* a = toolMgr()->action( theId );
3795 return a && a->isVisible();
3798 void OCCViewer_ViewWindow::setActionVisible( ActionId theId, bool isVisible )
3800 QAction* a = toolMgr()->action( theId );
3802 a->setVisible( isVisible );
3805 void OCCViewer_ViewWindow::projAndPanToGravity(V3d_TypeOfOrientation CamOri)
3807 const bool USE_XY = true;
3809 Handle(V3d_View) aView3d = myViewPort->getView();
3810 if (aView3d.IsNull())
3814 double X = 0, Y = 0, Z = 0;
3817 const double EPS = 1E-6;
3818 int xp = myViewPort->width()/2, yp = myViewPort->height()/2, xp1, yp1;
3819 aView3d->Convert( xp, yp, X, Y, Z );
3821 gp_Dir d = aView3d->Camera()->Direction();
3822 if( fabs( d.Z() ) > EPS )
3824 double t = -Z/d.Z();
3831 // It is really necessary to compute gravity center even if it is not used in part of code below.
3832 // Without this calculation the SetProj() method and other methods are not correct.
3834 IsGr = computeGravityCenter(X2, Y2, Z2);
3836 IsGr = OCCViewer_Utilities::computeSceneBBCenter(aView3d, X2, Y2, Z2);
3838 aView3d->SetProj(CamOri);
3841 //aView3d->Update();
3842 Handle(Graphic3d_Camera) Cam = aView3d->Camera();
3844 gp_Vec dir (Cam->Direction());
3845 gp_Pnt eye = Cam->Eye();
3847 Standard_Real D = dir.Dot(V1);
3848 gp_Pnt ppdir = eye.Translated(D*dir);
3849 gp_Vec V2(ppdir, gp);
3850 gp_XYZ trEye = eye.XYZ() + V2.XYZ();
3852 double xat, yat, zat;
3853 aView3d->At(xat, yat, zat);
3854 gp_Pnt At(xat, yat, zat);
3855 gp_XYZ trAt = At.XYZ() + V2.XYZ();
3856 aView3d->SetEye(trEye.X(), trEye.Y(), trEye.Z());
3857 aView3d->SetAt(trAt.X(), trAt.Y(), trAt.Z());
3862 bool OCCViewer_ViewWindow::isAutomaticZoom() const
3864 return myAutomaticZoom;
3867 void OCCViewer_ViewWindow::setAutomaticZoom(const bool isOn)
3869 myAutomaticZoom = isOn;