1 // Copyright (C) 2007-2016 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>
55 #include <Basics_OCCTVersion.hxx>
61 #include <QMouseEvent>
62 #include <QApplication>
63 #include <QActionGroup>
66 #include <AIS_ListOfInteractive.hxx>
67 #include <AIS_ListIteratorOfListOfInteractive.hxx>
68 #include <AIS_Shape.hxx>
70 #include <BRep_Tool.hxx>
71 #include <BRepBndLib.hxx>
72 #include <BRepGProp.hxx>
73 #include <GProp_GProps.hxx>
76 #include <Graphic3d_SequenceOfHClipPlane.hxx>
77 #include <Graphic3d_ClipPlane.hxx>
78 #include <OpenGl_GraphicDriver.hxx>
79 #include <OpenGLUtils_FrameBuffer.h>
81 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
82 #include <Graphic3d_MapOfStructure.hxx>
83 #include <Graphic3d_Structure.hxx>
84 #include <Graphic3d_ExportFormat.hxx>
85 #if OCC_VERSION_LARGE > 0x06090000
86 #include <Graphic3d_StereoMode.hxx>
87 #include <Graphic3d_RenderingParams.hxx>
88 #include <Graphic3d_BndBox3d.hxx>
91 #if OCC_VERSION_MAJOR < 7
92 #include <Visual3d_View.hxx>
95 #include <V3d_Plane.hxx>
96 #include <V3d_Light.hxx>
100 #include <gp_GTrsf.hxx>
101 #include <TColgp_Array1OfPnt2d.hxx>
103 #include <Image_PixMap.hxx>
105 #include <Standard_Version.hxx>
107 #include "utilities.h"
109 // // OpenCV includes
111 // #include <highgui.h>
113 static QEvent* l_mbPressEvent = 0;
116 //# include <QWindowsStyle>
120 #include <OpenGL/gl.h>
125 // To avoid conflict between KeyPress from the X.h (define KeyPress 2)
126 // 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 = NOTHING;
305 myCurrPointType = BBCENTER;
306 myPrevPointType = BBCENTER;
307 mySelectedPoint = gp_Pnt(0.,0.,0.);
308 myRotationPointSelection = false;
310 setTransformRequested ( NOTHING );
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 = NOTHING;
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() && ic->HasOpenedContext() ) {
400 if ( aEvent->delta() > 0 ) {
401 ic->HilightNextDetected( myViewPort->getView() );
403 ic->HilightPreviousDetected( myViewPort->getView() );
408 emit vpTransformationStarted ( ZOOMVIEW );
409 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
410 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
413 int x1 = (int)( aEvent->x() + width()*delta/100 );
414 int y1 = (int)( aEvent->y() + height()*delta/100 );
415 myViewPort->zoom( x, y, x1, y1 );
416 #if OCC_VERSION_LARGE <= 0x07000000
417 myViewPort->getView()->ZFitAll();
419 emit vpTransformationFinished ( ZOOMVIEW );
424 case QEvent::ContextMenu:
426 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
427 if ( aEvent->reason() != QContextMenuEvent::Mouse )
428 emit contextMenuRequested( aEvent );
432 case QEvent::KeyPress:
433 emit keyPressed(this, (QKeyEvent*) e);
440 return SUIT_ViewWindow::eventFilter(watched, e);
444 \brief Enable / disable draw rect (rubber band) mode
446 bool OCCViewer_ViewWindow::enableDrawMode( bool on )
448 bool prev = myDrawRectEnabled;
449 myDrawRectEnabled = on;
450 updateEnabledDrawMode();
455 \brief Update state of enable draw mode state.
457 void OCCViewer_ViewWindow::updateEnabledDrawMode()
459 myEnableDrawMode = myDrawRectEnabled;
461 myEnableDrawMode = myEnableDrawMode && myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
465 \brief Handle mouse press event
466 \param theEvent mouse event
468 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
470 myStartX = theEvent->x();
471 myStartY = theEvent->y();
472 int anInteractionStyle = interactionStyle();
474 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
475 // which are assigned for pan and rotate - these operations are activated immediately after pressing
476 // of the first button, so it is necessary to switch to zoom when the second button is pressed
477 bool aSwitchToZoom = false;
478 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
479 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
480 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
483 switch ( myOperation ) {
485 if ( theEvent->button() == Qt::LeftButton )
486 emit vpTransformationStarted ( WINDOWFIT );
490 if ( theEvent->button() == Qt::LeftButton )
491 emit vpTransformationStarted ( PANGLOBAL );
495 if ( theEvent->button() == Qt::LeftButton ) {
496 myViewPort->startZoomAtPoint( myStartX, myStartY );
497 emit vpTransformationStarted ( ZOOMVIEW );
502 if ( aSwitchToZoom ) {
503 myViewPort->startZoomAtPoint( myStartX, myStartY );
506 else if ( theEvent->button() == Qt::LeftButton )
507 emit vpTransformationStarted ( PANVIEW );
511 if ( aSwitchToZoom ) {
512 myViewPort->startZoomAtPoint( myStartX, myStartY );
515 else if ( theEvent->button() == Qt::LeftButton ) {
516 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
517 emit vpTransformationStarted ( ROTATE );
522 /* Try to activate a transformation */
523 OperationType aState;
524 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
525 aState = getButtonState(theEvent, anInteractionStyle);
527 aState = OCCViewer_ViewWindow::NOTHING;
532 myViewPort->startZoomAtPoint( myStartX, myStartY );
540 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
543 if ( myRotationPointSelection )
545 if ( theEvent->button() == Qt::LeftButton )
547 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
548 ic->Select( Standard_True );
549 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
551 TopoDS_Shape aShape = ic->SelectedShape();
552 GProp_GProps aSystem;
554 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
556 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
558 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE )
560 BRepGProp::LinearProperties( aShape, aSystem );
561 aPnt = aSystem.CentreOfMass();
563 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE )
565 BRepGProp::SurfaceProperties( aShape, aSystem );
566 aPnt = aSystem.CentreOfMass();
568 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID )
570 BRepGProp::VolumeProperties( aShape, aSystem );
571 aPnt = aSystem.CentreOfMass();
575 myCurrPointType = myPrevPointType;
579 if ( mySetRotationPointDlg )
581 myRotationPointSelection = false;
582 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
585 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
586 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
587 ic->CloseAllContexts( Standard_True );
588 myOperation = NOTHING;
589 myViewPort->setCursor( myCursor );
590 myCursorIsHand = false;
591 myRotationPointSelection = false;
595 emit mousePressed(this, theEvent);
598 /* notify that we start a transformation */
599 if ( transformRequested() )
600 emit vpTransformationStarted ( myOperation );
602 if ( transformRequested() )
603 setTransformInProcess( true );
605 /* we may need it for sketching... */
606 if ( l_mbPressEvent )
607 delete l_mbPressEvent;
608 l_mbPressEvent = new QMouseEvent( *theEvent );
613 \brief Start zooming operation.
615 Sets the corresponding cursor for the widget.
617 void OCCViewer_ViewWindow::activateZoom()
619 if ( !transformRequested() && !myCursorIsHand )
620 saveCursor(); /* save old cursor */
622 if ( myOperation != ZOOMVIEW ) {
623 QPixmap zoomPixmap (imageZoomCursor);
624 QCursor zoomCursor (zoomPixmap);
625 if( setTransformRequested ( ZOOMVIEW ) )
626 myViewPort->setCursor( zoomCursor );
631 void OCCViewer_ViewWindow::onPanning()
633 OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( getViewManager() );
634 bool isChained = aMgr->isChainedOperations();
635 bool isReset = ( myPanningByBtn && isChained );
642 myPanningByBtn = true;
648 \brief Start panning operation.
650 Sets the corresponding cursor for the widget.
652 void OCCViewer_ViewWindow::activatePanning()
654 if ( !transformRequested() && !myCursorIsHand )
655 saveCursor(); // save old cursor
657 if ( myOperation != PANVIEW ) {
658 QCursor panCursor (Qt::SizeAllCursor);
659 if( setTransformRequested ( PANVIEW ) )
660 myViewPort->setCursor( panCursor );
665 \brief Start rotation operation
667 Sets the corresponding cursor for the widget.
669 void OCCViewer_ViewWindow::activateRotation()
671 if ( !transformRequested() && !myCursorIsHand )
672 saveCursor(); // save old cursor
674 if ( myOperation != ROTATE ) {
675 QPixmap rotatePixmap (imageRotateCursor);
676 QCursor rotCursor (rotatePixmap);
677 if( setTransformRequested ( ROTATE ) )
678 myViewPort->setCursor( rotCursor );
683 \brief Compute the gravity center.
684 \param theX used to return X coordinate of the gravity center
685 \param theY used to return Y coordinate of the gravity center
686 \param theZ used to return Z coordinate of the gravity center
687 \return \c true if the gravity center is computed
689 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
691 Handle(V3d_View) aView3d = myViewPort->getView();
693 // Project boundaries points and add to avergae gravity
694 // the ones which lie within the screen limits
695 Standard_Real aScreenLimits[4] = { 0.0, 0.0, 0.0, 0.0 };
697 #if OCC_VERSION_LARGE > 0x06070100
698 // NDC space screen limits
699 aScreenLimits[0] = -1.0;
700 aScreenLimits[1] = 1.0;
701 aScreenLimits[2] = -1.0;
702 aScreenLimits[3] = 1.0;
704 aView3d->View()->ViewMapping().WindowLimit( aScreenLimits[0],
710 Standard_Integer aPointsNb = 0;
712 Standard_Real aXmin = 0.0;
713 Standard_Real aYmin = 0.0;
714 Standard_Real aZmin = 0.0;
715 Standard_Real aXmax = 0.0;
716 Standard_Real aYmax = 0.0;
717 Standard_Real aZmax = 0.0;
719 Graphic3d_MapOfStructure aSetOfStructures;
720 aView3d->View()->DisplayedStructures( aSetOfStructures );
721 Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures );
723 for( ; aStructureIt.More(); aStructureIt.Next() ) {
724 const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key();
725 if ( aStructure->IsEmpty() || !aStructure->IsVisible() || aStructure->CStructure()->IsForHighlight )
728 #if OCC_VERSION_LARGE > 0x06070100
729 Bnd_Box aBox1 = aStructure->MinMaxValues();
730 const Graphic3d_BndBox3d& aBox = aStructure->CStructure()->BoundingBox();
733 aXmin = /*aBox.IsVoid() ? RealFirst() :*/ aBox.CornerMin().x();
734 aYmin = /*aBox.IsVoid() ? RealFirst() : */aBox.CornerMin().y();
735 aZmin = /*aBox.IsVoid() ? RealFirst() : */aBox.CornerMin().z();
736 aXmax = /*aBox.IsVoid() ? RealLast() : */aBox.CornerMax().x();
737 aYmax = /*aBox.IsVoid() ? RealLast() : */aBox.CornerMax().y();
738 aZmax = /*aBox.IsVoid() ? RealLast() : */aBox.CornerMax().z();
740 aStructure->MinMaxValues( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
743 // Infinite structures are skipped
744 Standard_Real aLIM = ShortRealLast() - 1.0;
745 if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
746 || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
750 gp_Pnt aPoints[8] = {
751 gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
752 gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
753 gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
754 gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
757 for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
758 const gp_Pnt& aBBPoint = aPoints[aPointIt];
760 #if OCC_VERSION_LARGE > 0x06070100
761 gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
762 const Standard_Real& U = aProjected.X();
763 const Standard_Real& V = aProjected.Y();
765 Standard_Real U = 0.0;
766 Standard_Real V = 0.0;
767 Standard_Real W = 0.0;
768 aView3d->View()->Projects( aBBPoint.X(), aBBPoint.Y(), aBBPoint.Z(), U, V, W );
771 if (U >= aScreenLimits[0]
772 && U <= aScreenLimits[1]
773 && V >= aScreenLimits[2]
774 && V <= aScreenLimits[3])
777 theX += aBBPoint.X();
778 theY += aBBPoint.Y();
779 theZ += aBBPoint.Z();
795 bool OCCViewer_ViewWindow::computeGravityCenter1(gp_XYZ& gravityCenter)
797 Handle(V3d_View) aView3d = myViewPort->getView();
798 Graphic3d_MapOfStructure aSetOfStructures;
799 aView3d->View()->DisplayedStructures (aSetOfStructures);
801 Standard_Boolean hasSelection = Standard_False;
802 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aSetOfStructures);
803 aStructIter.More(); aStructIter.Next())
805 if (aStructIter.Key()->IsHighlighted()
806 && aStructIter.Key()->IsVisible())
808 hasSelection = Standard_True;
813 Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
814 Standard_Integer aNbPoints = 0;
815 gravityCenter.SetCoord(0,0,0);
816 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aSetOfStructures);
817 aStructIter.More(); aStructIter.Next())
819 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
820 if (!aStruct->IsVisible()
821 || aStruct->IsInfinite()
822 || (hasSelection && !aStruct->IsHighlighted()))
827 const Graphic3d_BndBox3d& aBox = aStruct->CStructure()->BoundingBox();
833 // skip transformation-persistent objects
834 if (!aStruct->TransformPersistence().IsNull())
837 // use camera projection to find gravity point
838 Xmin = aBox.CornerMin().x();
839 Ymin = aBox.CornerMin().y();
840 Zmin = aBox.CornerMin().z();
841 Xmax = aBox.CornerMax().x();
842 Ymax = aBox.CornerMax().y();
843 Zmax = aBox.CornerMax().z();
846 gp_Pnt (Xmin, Ymin, Zmin), gp_Pnt (Xmin, Ymin, Zmax),
847 gp_Pnt (Xmin, Ymax, Zmin), gp_Pnt (Xmin, Ymax, Zmax),
848 gp_Pnt (Xmax, Ymin, Zmin), gp_Pnt (Xmax, Ymin, Zmax),
849 gp_Pnt (Xmax, Ymax, Zmin), gp_Pnt (Xmax, Ymax, Zmax)
852 for (Standard_Integer aPntIt = 0; aPntIt < 8; ++aPntIt)
854 const gp_Pnt& aBndPnt = aPnts[aPntIt];
855 const gp_Pnt aProjected = aView3d->Camera()->Project (aBndPnt);
856 if (Abs (aProjected.X()) <= 1.0
857 && Abs (aProjected.Y()) <= 1.0)
859 gravityCenter += aBndPnt.XYZ();
871 \brief Set the gravity center as a rotation point.
873 void OCCViewer_ViewWindow::activateSetRotationGravity()
875 if ( myRotationPointSelection )
877 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
878 ic->CloseAllContexts( Standard_True );
879 myOperation = NOTHING;
880 myViewPort->setCursor( myCursor );
881 myCursorIsHand = false;
882 myRotationPointSelection = false;
885 myPrevPointType = myCurrPointType;
886 myCurrPointType = BBCENTER;
888 Standard_Real Xcenter, Ycenter, Zcenter;
889 if ( OCCViewer_Utilities::computeVisibleBBCenter( myViewPort->getView(), Xcenter, Ycenter, Zcenter ) )
890 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
894 \brief Update gravity center in the "Set Rotation Point" dialog box.
895 \sa OCCViewer_SetRotationPointDlg class
897 void OCCViewer_ViewWindow::updateGravityCoords()
899 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == BBCENTER )
901 Standard_Real Xcenter, Ycenter, Zcenter;
902 if ( OCCViewer_Utilities::computeVisibleBBCenter( myViewPort->getView(), Xcenter, Ycenter, Zcenter ) )
903 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
908 \brief Set the point selected by the user as a rotation point.
909 \param theX X coordinate of the rotation point
910 \param theY Y coordinate of the rotation point
911 \param theZ Z coordinate of the rotation point
913 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
915 if ( myRotationPointSelection )
917 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
918 ic->CloseAllContexts( Standard_True );
919 myOperation = NOTHING;
920 myViewPort->setCursor( myCursor );
921 myCursorIsHand = false;
922 myRotationPointSelection = false;
925 myPrevPointType = myCurrPointType;
926 myCurrPointType = SELECTED;
927 mySelectedPoint.SetCoord(theX,theY,theZ);
931 \brief Start the shape selection process.
933 void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
935 myPrevPointType = myCurrPointType;
936 myCurrPointType = SELECTED;
938 // activate selection ------>
939 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
941 ic->OpenLocalContext();
943 AIS_ListOfInteractive aList;
944 ic->DisplayedObjects( aList );
945 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
947 Handle(AIS_InteractiveObject) anObj = it.Value();
948 if ( !anObj.IsNull() && anObj->HasPresentation() &&
949 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
952 ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
955 // activate selection <------
957 if ( !myCursorIsHand )
959 QCursor handCursor (Qt::PointingHandCursor);
960 myCursorIsHand = true;
962 myViewPort->setCursor( handCursor );
964 myRotationPointSelection = true;
968 \brief Start global panning operation
970 Sets the corresponding cursor for the widget.
972 void OCCViewer_ViewWindow::activateGlobalPanning()
974 Handle(V3d_View) aView3d = myViewPort->getView();
975 if ( !aView3d.IsNull() ) {
976 QPixmap globalPanPixmap (imageCrossCursor);
977 QCursor glPanCursor (globalPanPixmap);
978 myCurScale = aView3d->Scale();
979 aView3d->FitAll(0.01, false);
980 saveCursor(); // save old cursor
981 myViewPort->fitAll(); // fits view before selecting a new scene center
982 if( setTransformRequested( PANGLOBAL ) )
983 myViewPort->setCursor( glPanCursor );
988 \brief Starts fit operation.
990 Sets the corresponding cursor for the widget.
992 void OCCViewer_ViewWindow::activateWindowFit()
994 if ( !transformRequested() && !myCursorIsHand )
995 saveCursor(); /* save old cursor */
997 if ( myOperation != WINDOWFIT ) {
998 QCursor handCursor (Qt::PointingHandCursor);
999 if( setTransformRequested ( WINDOWFIT ) )
1001 myViewPort->setCursor ( handCursor );
1002 myCursorIsHand = true;
1008 \brief Start delayed viewer operation.
1010 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
1012 bool ok = transformEnabled( op );
1013 myOperation = ok ? op : NOTHING;
1014 myViewPort->setMouseTracking( myOperation == NOTHING );
1019 \brief Handle mouse move event.
1020 \param theEvent mouse event
1022 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
1024 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
1025 myIsKeyFree = false;
1026 switch ( getButtonState( theEvent, interactionStyle() ) ) {
1028 myViewPort->startZoomAtPoint( myStartX, myStartY );
1036 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
1043 myCurrX = theEvent->x();
1044 myCurrY = theEvent->y();
1045 switch (myOperation) {
1047 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
1051 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
1057 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
1071 if ( myRotationPointSelection || isSketcherStyle() )
1073 emit mouseMoving( this, theEvent );
1077 int aState = theEvent->modifiers();
1078 int aButton = theEvent->buttons();
1079 int anInteractionStyle = interactionStyle();
1080 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
1081 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
1082 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
1083 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
1084 myDrawRect = myEnableDrawMode;
1087 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
1088 QCursor handCursor (Qt::PointingHandCursor);
1089 myCursorIsHand = true;
1091 myViewPort->setCursor( handCursor );
1094 emit mouseMoving( this, theEvent );
1096 else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
1097 aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
1098 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
1099 aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
1100 OCCViewer_ViewSketcher* sketcher = 0;
1101 QList<OCCViewer_ViewSketcher*>::Iterator it;
1102 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
1104 OCCViewer_ViewSketcher* sk = (*it);
1105 if( sk->isDefault() && sk->sketchButton() == aButton )
1108 if ( sketcher && myCurSketch == -1 )
1110 activateSketching( sketcher->type() );
1113 myCurSketch = mypSketcher->sketchButton();
1115 if ( l_mbPressEvent )
1117 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
1118 delete l_mbPressEvent;
1121 QApplication::sendEvent( getViewPort(), theEvent );
1126 emit mouseMoving( this, theEvent );
1132 \brief Handle mouse release event.
1133 \param theEvent mouse event
1135 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
1137 switch ( myOperation ) {
1140 int prevState = myCurSketch;
1141 if(theEvent->button() == Qt::RightButton)
1143 QList<OCCViewer_ViewSketcher*>::Iterator it;
1144 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
1146 OCCViewer_ViewSketcher* sk = (*it);
1147 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
1152 emit mouseReleased(this, theEvent);
1153 if(theEvent->button() == Qt::RightButton && prevState == -1)
1155 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1156 theEvent->pos(), theEvent->globalPos() );
1157 emit contextMenuRequested( &aEvent );
1162 myViewPort->endRotation();
1168 #if OCC_VERSION_LARGE <= 0x07000000
1169 myViewPort->getView()->ZFitAll();
1172 OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( getViewManager() );
1173 bool isChained = aMgr->isChainedOperations();
1174 bool isReset = !( myOperation==PANVIEW && myPanningByBtn && isChained ) || theEvent->button() == Qt::RightButton;
1181 if ( theEvent->button() == Qt::LeftButton ) {
1182 myViewPort->setCenter( theEvent->x(), theEvent->y() );
1183 myViewPort->getView()->SetScale(myCurScale);
1189 if ( theEvent->button() == Qt::LeftButton ) {
1190 myCurrX = theEvent->x();
1191 myCurrY = theEvent->y();
1193 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1194 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1201 // NOTE: viewer 3D detects a rectangle of selection using this event
1202 // so we must emit it BEFORE resetting the selection rectangle
1204 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1208 myViewPort->update();
1211 if ( l_mbPressEvent )
1213 delete l_mbPressEvent;
1219 \brief Reset the viewport to its initial state
1220 ( no transformations in process etc. )
1222 void OCCViewer_ViewWindow::resetState()
1226 if ( myRotationPointSelection )
1228 QCursor handCursor (Qt::PointingHandCursor);
1229 myViewPort->setCursor( handCursor );
1233 if ( transformRequested() || myCursorIsHand )
1234 myViewPort->setCursor( myCursor );
1235 myCursorIsHand = false;
1238 if ( transformRequested() )
1239 emit vpTransformationFinished (myOperation);
1241 setTransformInProcess( false );
1242 setTransformRequested( NOTHING );
1244 myPanningByBtn = false;
1249 \brief Draw rubber band rectangle.
1251 void OCCViewer_ViewWindow::drawRect()
1253 if ( !myRectBand ) {
1254 myRectBand = new QtxRectRubberBand( myViewPort );
1256 //palette.setColor(myRectBand->foregroundRole(), Qt::white);
1257 //myRectBand->setPalette(palette);
1259 //myRectBand->hide();
1261 myRectBand->setUpdatesEnabled ( false );
1262 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1263 myRectBand->initGeometry( aRect );
1265 if ( !myRectBand->isVisible() )
1268 myRectBand->setUpdatesEnabled ( true );
1269 //myRectBand->repaint();
1271 //myRectBand->setVisible( aRect.isValid() );
1272 //if ( myRectBand->isVisible() )
1273 // myRectBand->repaint();
1275 // myRectBand->show();
1276 //myRectBand->repaint();
1280 \brief Clear rubber band rectangle on the end on the dragging operation.
1282 void OCCViewer_ViewWindow::endDrawRect()
1284 //delete myRectBand;
1288 myRectBand->clearGeometry();
1294 \brief Create actions.
1296 void OCCViewer_ViewWindow::createActions()
1298 if( !toolMgr()->isEmpty() )
1301 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1308 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1309 tr( "MNU_DUMP_VIEW" ), 0, this);
1310 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1311 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1312 toolMgr()->registerAction( aAction, DumpId );
1315 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1316 tr( "MNU_FITALL" ), 0, this);
1317 aAction->setStatusTip(tr("DSC_FITALL"));
1318 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1319 toolMgr()->registerAction( aAction, FitAllId );
1322 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1323 tr( "MNU_FITRECT" ), 0, this);
1324 aAction->setStatusTip(tr("DSC_FITRECT"));
1325 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1326 toolMgr()->registerAction( aAction, FitRectId );
1329 aAction = new QtxAction(tr("MNU_FITSELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITSELECTION" ) ),
1330 tr( "MNU_FITSELECTION" ), 0, this);
1331 aAction->setStatusTip(tr("DSC_FITSELECTION"));
1332 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
1333 toolMgr()->registerAction( aAction, FitSelectionId );
1336 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1337 tr( "MNU_ZOOM_VIEW" ), 0, this);
1338 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1339 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1340 toolMgr()->registerAction( aAction, ZoomId );
1343 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1344 tr( "MNU_PAN_VIEW" ), 0, this);
1345 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1346 connect(aAction, SIGNAL(triggered()), this, SLOT(onPanning()));
1347 toolMgr()->registerAction( aAction, PanId );
1350 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1351 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1352 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1353 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1354 toolMgr()->registerAction( aAction, GlobalPanId );
1357 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1358 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1359 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1360 mySetRotationPointAction->setCheckable( true );
1361 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1362 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1365 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1366 tr( "MNU_ROTATE_VIEW" ), 0, this);
1367 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1368 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1369 toolMgr()->registerAction( aAction, RotationId );
1372 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1373 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1374 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1375 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1376 this->addAction(aAction);
1377 toolMgr()->registerAction( aAction, FrontId );
1379 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1380 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1381 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1382 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1383 this->addAction(aAction);
1384 toolMgr()->registerAction( aAction, BackId );
1386 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1387 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1388 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1389 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1390 this->addAction(aAction);
1391 toolMgr()->registerAction( aAction, TopId );
1393 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1394 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1395 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1396 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1397 this->addAction(aAction);
1398 toolMgr()->registerAction( aAction, BottomId );
1400 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1401 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1402 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1403 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1404 this->addAction(aAction);
1405 toolMgr()->registerAction( aAction, LeftId );
1407 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1408 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1409 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1410 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1411 this->addAction(aAction);
1412 toolMgr()->registerAction( aAction, RightId );
1414 // rotate anticlockwise
1415 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1416 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1417 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1418 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1419 this->addAction(aAction);
1420 toolMgr()->registerAction( aAction, AntiClockWiseId );
1423 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1424 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1425 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1426 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1427 this->addAction(aAction);
1428 toolMgr()->registerAction( aAction, ClockWiseId );
1430 // Projection mode group
1432 // - orthographic projection
1433 aAction = new QtxAction(tr("MNU_ORTHOGRAPHIC_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ORTHOGRAPHIC" ) ),
1434 tr( "MNU_ORTHOGRAPHIC_MODE" ), 0, this);
1435 aAction->setStatusTip(tr("DSC_ORTHOGRAPHIC_MODE"));
1436 aAction->setCheckable(true);
1437 toolMgr()->registerAction( aAction, OrthographicId );
1439 // - perspective projection
1440 aAction = new QtxAction(tr("MNU_PERSPECTIVE_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PERSPECTIVE" ) ),
1441 tr( "MNU_PERSPECTIVE_MODE" ), 0, this);
1442 aAction->setStatusTip(tr("DSC_PERSPECTIVE_MODE"));
1443 aAction->setCheckable(true);
1444 toolMgr()->registerAction( aAction, PerspectiveId );
1445 #if OCC_VERSION_LARGE > 0x06090000
1446 // - stereo projection
1447 aAction = new QtxAction(tr("MNU_STEREO_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STEREO" ) ),
1448 tr( "MNU_STEREO_MODE" ), 0, this);
1449 aAction->setStatusTip(tr("DSC_STEREO_MODE"));
1450 aAction->setCheckable(true);
1451 toolMgr()->registerAction( aAction, StereoId );
1452 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onStereoType(bool)));
1454 // - add exclusive action group
1455 QActionGroup* aProjectionGroup = new QActionGroup( this );
1456 aProjectionGroup->addAction( toolMgr()->action( OrthographicId ) );
1457 aProjectionGroup->addAction( toolMgr()->action( PerspectiveId ) );
1458 connect(aProjectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProjectionType(QAction*)));
1461 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1462 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1463 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1464 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1465 this->addAction(aAction);
1466 toolMgr()->registerAction( aAction, ResetId );
1469 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1470 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1471 tr("MNU_CLONE_VIEW"), 0, this);
1472 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1473 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1474 toolMgr()->registerAction( aAction, CloneId );
1476 aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
1477 tr("MNU_CLIPPING"), 0, this);
1478 aAction->setStatusTip (tr("DSC_CLIPPING"));
1479 aAction->setCheckable (true);
1480 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1481 toolMgr()->registerAction (aAction, ClippingId);
1483 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1484 tr( "MNU_SHOOT_VIEW" ), 0, this);
1485 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1486 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1487 toolMgr()->registerAction( aAction, MemId );
1489 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1490 tr( "MNU_PRESETS_VIEW" ), 0, this);
1491 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1492 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1493 toolMgr()->registerAction( aAction, RestoreId );
1495 if (myModel->trihedronActivated()) {
1496 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1497 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1498 aAction->setCheckable( true );
1499 aAction->setChecked( true );
1500 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1501 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1502 toolMgr()->registerAction( aAction, TrihedronShowId );
1506 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1507 tr( "MNU_SCALING" ), 0, this);
1508 aAction->setStatusTip(tr("DSC_SCALING"));
1509 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1510 toolMgr()->registerAction( aAction, AxialScaleId );
1512 // Enable/disable preselection
1513 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1514 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1515 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1516 aAction->setCheckable(true);
1517 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1518 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1520 // Enable/disable selection
1521 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1522 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1523 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1524 aAction->setCheckable(true);
1525 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1526 toolMgr()->registerAction( aAction, SwitchSelectionId );
1529 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1530 tr( "MNU_GRADUATED_AXES" ), 0, this);
1531 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1532 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1533 toolMgr()->registerAction( aAction, GraduatedAxesId );
1535 // Active only ambient light or not
1536 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1537 tr( "MNU_AMBIENT" ), 0, this);
1538 aAction->setStatusTip(tr("DSC_AMBIENT"));
1539 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1540 toolMgr()->registerAction( aAction, AmbientId );
1542 // Switch between interaction styles
1543 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1544 tr( "MNU_STYLE_SWITCH" ), 0, this);
1545 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1546 aAction->setCheckable(true);
1547 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1548 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1550 // Switch between zooming styles
1551 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1552 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1553 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1554 aAction->setCheckable(true);
1555 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1556 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1559 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1560 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1561 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1562 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1563 toolMgr()->registerAction( aAction, MaximizedId );
1565 // Return to 3d view
1566 if (my2dMode!=No2dMode){
1567 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1568 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1569 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1570 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1571 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1575 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1576 #ifdef ENABLE_RAY_TRACING
1578 aAction = new QtxAction( tr("MNU_RAY_TRACING"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_RAY_TRACING") ),
1579 tr("MNU_RAY_TRACING"), 0, this );
1580 aAction->setStatusTip( tr("DSC_RAY_TRACING") );
1581 connect( aAction, SIGNAL( triggered() ), this, SLOT( onRayTracing() ) );
1582 toolMgr()->registerAction( aAction, RayTracingId );
1584 // Environment texture
1585 aAction = new QtxAction( tr("MNU_ENV_TEXTURE"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_ENV_TEXTURE") ),
1586 tr("MNU_ENV_TEXTURE"), 0, this );
1587 aAction->setStatusTip( tr("DSC_ENV_TEXTURE") );
1588 connect( aAction, SIGNAL( triggered() ), this, SLOT( onEnvTexture() ) );
1589 toolMgr()->registerAction( aAction, EnvTextureId );
1592 aAction = new QtxAction( tr("MNU_LIGHT_SOURCE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_LIGHT_SOURCE" ) ),
1593 tr( "MNU_LIGHT_SOURCE" ), 0, this );
1594 aAction->setStatusTip( tr("DSC_LIGHT_SOURCE") );
1595 connect( aAction, SIGNAL( triggered() ), this, SLOT( onLightSource() ) );
1596 toolMgr()->registerAction( aAction, LightSourceId );
1601 \brief Create toolbar.
1603 void OCCViewer_ViewWindow::createToolBar()
1605 static const char* titles[] = {
1606 "LBL_3DTOOLBAR_LABEL",
1607 "LBL_XYTOOLBAR_LABEL",
1608 "LBL_XZTOOLBAR_LABEL",
1609 "LBL_YZTOOLBAR_LABEL",
1611 static const char* names[] = {
1612 "OCCViewer3DViewOperations",
1613 "OCCViewerXYViewOperations",
1614 "OCCViewerXZViewOperations",
1615 "OCCViewerYZViewOperations",
1617 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1618 QString( names[my2dMode] ), // name (language-independant)
1619 false ); // disable floatable toolbar
1620 if ( my2dMode != No2dMode ){
1621 toolMgr()->append( ReturnTo3dViewId, tid );
1622 toolMgr()->append( toolMgr()->separator(), tid );
1624 toolMgr()->append( DumpId, tid );
1625 toolMgr()->append( SwitchInteractionStyleId, tid );
1626 toolMgr()->append( SwitchZoomingStyleId, tid );
1627 toolMgr()->append( SwitchPreselectionId, tid );
1628 toolMgr()->append( SwitchSelectionId, tid );
1629 if( myModel->trihedronActivated() )
1630 toolMgr()->append( TrihedronShowId, tid );
1632 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1633 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1634 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1635 #if OCC_VERSION_LARGE > 0x06090000
1636 aScaleAction->insertAction( toolMgr()->action( FitSelectionId ) );
1638 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1639 toolMgr()->append( aScaleAction, tid );
1641 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1642 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1643 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1644 toolMgr()->append( aPanningAction, tid );
1646 if (my2dMode == No2dMode) {
1647 toolMgr()->append( ChangeRotationPointId, tid );
1648 toolMgr()->append( RotationId, tid );
1650 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1651 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1652 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1653 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1654 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1655 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1656 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1657 toolMgr()->append( aViewsAction, tid );
1659 toolMgr()->append( AntiClockWiseId, tid );
1660 toolMgr()->append( ClockWiseId, tid );
1662 toolMgr()->append( OrthographicId, tid );
1663 toolMgr()->append( PerspectiveId, tid );
1664 #if OCC_VERSION_LARGE > 0x06090000
1665 toolMgr()->append( StereoId, tid );
1668 toolMgr()->append( ResetId, tid );
1671 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1672 aMemAction->insertAction( toolMgr()->action( MemId ) );
1673 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1674 toolMgr()->append( aMemAction, tid );
1676 toolMgr()->append( toolMgr()->separator(), tid );
1677 toolMgr()->append( CloneId, tid );
1679 toolMgr()->append( toolMgr()->separator(), tid );
1680 toolMgr()->append( ClippingId, tid );
1681 toolMgr()->append( AxialScaleId, tid );
1682 toolMgr()->append( GraduatedAxesId, tid );
1683 toolMgr()->append( AmbientId, tid );
1685 toolMgr()->append( MaximizedId, tid );
1686 toolMgr()->append( SynchronizeId, tid );
1687 #ifdef ENABLE_RAY_TRACING
1688 toolMgr()->append( RayTracingId, tid );
1689 toolMgr()->append( EnvTextureId, tid );
1690 toolMgr()->append( LightSourceId, tid );
1695 \brief Perform 'fit all' operation.
1697 void OCCViewer_ViewWindow::onViewFitAll()
1699 myViewPort->fitAll();
1703 \brief Perform "front view" transformation.
1705 void OCCViewer_ViewWindow::onFrontView()
1707 emit vpTransformationStarted ( FRONTVIEW );
1708 Handle(V3d_View) aView3d = myViewPort->getView();
1709 if (myAutomaticZoom)
1711 if ( !aView3d.IsNull() )
1712 aView3d->SetProj (V3d_Xpos);
1716 ProjAndPanToGravity(V3d_Xpos);
1717 emit vpTransformationFinished ( FRONTVIEW );
1721 \brief Perform "back view" transformation.
1723 void OCCViewer_ViewWindow::onBackView()
1725 emit vpTransformationStarted ( BACKVIEW );
1726 Handle(V3d_View) aView3d = myViewPort->getView();
1727 if (myAutomaticZoom)
1729 if ( !aView3d.IsNull() )
1730 aView3d->SetProj (V3d_Xneg);
1734 ProjAndPanToGravity(V3d_Xneg);
1735 emit vpTransformationFinished ( BACKVIEW );
1739 \brief Perform "top view" transformation.
1741 void OCCViewer_ViewWindow::onTopView()
1743 emit vpTransformationStarted ( TOPVIEW );
1744 Handle(V3d_View) aView3d = myViewPort->getView();
1745 if (myAutomaticZoom)
1747 if ( !aView3d.IsNull() )
1748 aView3d->SetProj (V3d_Zpos);
1752 ProjAndPanToGravity(V3d_Zpos);
1753 emit vpTransformationFinished ( TOPVIEW );
1757 \brief Perform "bottom view" transformation.
1759 void OCCViewer_ViewWindow::onBottomView()
1761 emit vpTransformationStarted ( BOTTOMVIEW );
1762 Handle(V3d_View) aView3d = myViewPort->getView();
1763 if (myAutomaticZoom)
1765 if ( !aView3d.IsNull() )
1766 aView3d->SetProj (V3d_Zneg);
1770 ProjAndPanToGravity(V3d_Zneg);
1771 emit vpTransformationFinished ( BOTTOMVIEW );
1775 \brief Perform "left view" transformation.
1777 void OCCViewer_ViewWindow::onLeftView()
1779 emit vpTransformationStarted ( LEFTVIEW );
1780 Handle(V3d_View) aView3d = myViewPort->getView();
1781 if (myAutomaticZoom)
1783 if ( !aView3d.IsNull() )
1784 aView3d->SetProj (V3d_Yneg);
1788 ProjAndPanToGravity(V3d_Yneg);
1789 emit vpTransformationFinished ( LEFTVIEW );
1793 \brief Perform "right view" transformation.
1795 void OCCViewer_ViewWindow::onRightView()
1797 emit vpTransformationStarted ( RIGHTVIEW );
1798 Handle(V3d_View) aView3d = myViewPort->getView();
1799 if (myAutomaticZoom)
1801 if ( !aView3d.IsNull() )
1802 aView3d->SetProj (V3d_Ypos);
1806 ProjAndPanToGravity(V3d_Ypos);
1807 emit vpTransformationFinished ( RIGHTVIEW );
1811 \brief Rotate view 90 degrees clockwise
1813 void OCCViewer_ViewWindow::onClockWiseView()
1815 emit vpTransformationStarted ( CLOCKWISEVIEW );
1816 myViewPort->rotateXY( 90. );
1817 emit vpTransformationFinished ( CLOCKWISEVIEW );
1821 \brief Rotate view 90 degrees conterclockwise
1823 void OCCViewer_ViewWindow::onAntiClockWiseView()
1825 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1826 myViewPort->rotateXY( -90. );
1827 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1831 \brief Perform "reset view" transformation.
1833 Sets default orientation of the viewport camera.
1835 void OCCViewer_ViewWindow::onResetView()
1837 emit vpTransformationStarted( RESETVIEW );
1838 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1839 myViewPort->getView()->Reset( false );
1840 myViewPort->fitAll( false, true, false );
1841 myViewPort->getView()->SetImmediateUpdate( upd );
1842 onProjectionType(); // needed to apply projection type properly after reset
1843 myViewPort->getView()->Update();
1844 emit vpTransformationFinished( RESETVIEW );
1848 \brief Set the given projection mode.
1850 Set the given projection mode: Orthographic or Perspective.
1852 void OCCViewer_ViewWindow::onProjectionType( QAction* theAction )
1854 Handle(V3d_View) aView3d = myViewPort->getView();
1855 if ( !aView3d.IsNull() ) {
1856 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1857 if (theAction == toolMgr()->action( OrthographicId )) {
1858 myModel->setProjectionType(Orthographic);
1859 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Orthographic );
1860 aCamera->SetFOVy(45.0);
1862 else if (theAction == toolMgr()->action( PerspectiveId )) {
1863 myModel->setProjectionType(Perspective);
1864 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Perspective );
1865 aCamera->SetFOVy(30.0);
1867 #if OCC_VERSION_LARGE > 0x06090000
1868 if (toolMgr()->action( StereoId )->isChecked()) {
1869 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1870 aCamera->SetFOVy(30.0);
1879 \brief Sets Stereo projection mode.
1881 Sets Stereo projection mode.
1883 void OCCViewer_ViewWindow::onStereoType( bool activate )
1885 #if OCC_VERSION_LARGE > 0x06090000
1886 Handle(V3d_View) aView3d = myViewPort->getView();
1887 if ( !aView3d.IsNull() ) {
1888 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1890 toolMgr()->action( PerspectiveId )->setChecked(true);
1891 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1892 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(false);
1894 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1895 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1896 setStereoType( aResMgr->integerValue( "OCCViewer", "stereo_type", 0 ) );
1897 setAnaglyphFilter( aResMgr->integerValue( "OCCViewer", "anaglyph_filter", 0 ) );
1898 setReverseStereo( aResMgr->booleanValue( "OCCViewer", "reverse_stereo", false ) );
1899 setVSync( aResMgr->booleanValue( "OCCViewer", "enable_vsync", true ) );
1900 setQuadBufferSupport( aResMgr->booleanValue( "OCCViewer", "enable_quad_buffer_support", false ) );
1903 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(true);
1904 if (myModel->projectionType() == Orthographic) {
1905 toolMgr()->action( OrthographicId )->setChecked(true);
1906 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Orthographic);
1908 else if (myModel->projectionType() == Perspective) {
1909 toolMgr()->action( PerspectiveId )->setChecked(true);
1910 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1917 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1918 toolMgr()->action( StereoId )->isChecked() )
1919 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1924 \brief Restore the view.
1926 Restore the projection mode based on tool-buttons states.
1928 void OCCViewer_ViewWindow::onProjectionType()
1930 emit vpTransformationStarted( PROJECTION );
1931 if (toolMgr()->action( OrthographicId )->isChecked())
1932 setProjectionType( Orthographic );
1933 if (toolMgr()->action( PerspectiveId )->isChecked())
1934 setProjectionType( Perspective );
1935 #if OCC_VERSION_LARGE > 0x06090000
1936 if (toolMgr()->action( StereoId )->isChecked())
1937 setProjectionType( Stereo );
1939 emit vpTransformationFinished( PROJECTION );
1942 void OCCViewer_ViewWindow::setProjectionType( int mode )
1944 QtxAction* anOrthographicAction = dynamic_cast<QtxAction*>( toolMgr()->action( OrthographicId ) );
1945 QtxAction* aPerspectiveAction = dynamic_cast<QtxAction*>( toolMgr()->action( PerspectiveId ) );
1946 #if OCC_VERSION_LARGE > 0x06090000
1947 QtxAction* aStereoAction = dynamic_cast<QtxAction*>( toolMgr()->action( StereoId ) );
1951 onProjectionType( anOrthographicAction );
1954 onProjectionType( aPerspectiveAction );
1957 onStereoType( true );
1960 // update action state if method is called outside
1961 if ( mode == Orthographic && !anOrthographicAction->isChecked() ) {
1962 anOrthographicAction->setChecked( true );
1963 #if OCC_VERSION_LARGE > 0x06090000
1964 aStereoAction->setChecked( false );
1967 if ( mode == Perspective && !aPerspectiveAction->isChecked() ) {
1968 aPerspectiveAction->setChecked( true );
1969 #if OCC_VERSION_LARGE > 0x06090000
1970 aStereoAction->setChecked( false );
1973 #if OCC_VERSION_LARGE > 0x06090000
1974 if ( mode == Stereo ) {
1975 aStereoAction->setChecked( true );
1976 if ( anOrthographicAction->isEnabled() ) {
1977 anOrthographicAction->setEnabled( false );
1978 anOrthographicAction->setChecked( false );
1979 aStereoAction->setChecked( false );
1982 anOrthographicAction->setEnabled( true );
1983 aStereoAction->setChecked( false );
1984 anOrthographicAction->setChecked(myModel->projectionType() == Orthographic);
1986 if ( aPerspectiveAction->isEnabled() ) {
1987 aPerspectiveAction->setEnabled( false );
1988 aPerspectiveAction->setChecked( true );
1989 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1990 toolMgr()->action( StereoId )->isChecked() )
1991 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1994 aPerspectiveAction->setEnabled( true );
1995 aStereoAction->setChecked( false );
1996 aPerspectiveAction->setChecked(myModel->projectionType() == Perspective);
2001 if ( !anOrthographicAction->isEnabled() )
2002 anOrthographicAction->setEnabled( true );
2003 if ( !aPerspectiveAction->isEnabled() )
2004 aPerspectiveAction->setEnabled( true );
2010 \brief Perform "fit all" transformation.
2012 void OCCViewer_ViewWindow::onFitAll()
2014 emit vpTransformationStarted( FITALLVIEW );
2015 myViewPort->fitAll();
2016 emit vpTransformationFinished( FITALLVIEW );
2020 \brief Perform "fit selection" transformation.
2022 void OCCViewer_ViewWindow::onFitSelection()
2024 emit vpTransformationStarted( FITSELECTION );
2025 #if OCC_VERSION_LARGE > 0x06090000
2026 myModel->getAISContext()->FitSelected( getViewPort()->getView() );
2028 emit vpTransformationFinished( FITSELECTION );
2032 \brief Called if 'change rotation point' operation is activated.
2033 \param on action state
2035 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
2039 if (!mySetRotationPointDlg)
2041 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
2042 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
2045 if (!mySetRotationPointDlg->isVisible())
2047 //if (mySetRotationPointDlg->IsFirstShown())
2048 if (myCurrPointType == BBCENTER)
2050 Standard_Real Xcenter, Ycenter, Zcenter;
2051 if (OCCViewer_Utilities::computeVisibleBBCenter(myViewPort->getView(), Xcenter, Ycenter, Zcenter))
2052 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
2054 mySetRotationPointDlg->show();
2059 if (mySetRotationPointDlg->isVisible())
2060 mySetRotationPointDlg->hide();
2065 \brief Create one more window with same content.
2067 void OCCViewer_ViewWindow::onCloneView()
2069 SUIT_ViewWindow* vw = myManager->createViewWindow();
2071 emit viewCloned( vw );
2072 OCCViewer_ViewWindow* occVw = dynamic_cast<OCCViewer_ViewWindow*> (vw);
2073 if(occVw && occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)) {
2074 occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)->synchronize(this);
2079 Creates one more window with same content
2081 void OCCViewer_ViewWindow::onAxialScale()
2083 if ( !myScalingDlg )
2084 myScalingDlg = new OCCViewer_AxialScaleDlg( this , myModel );
2086 if ( !myScalingDlg->isVisible() )
2088 myScalingDlg->Update();
2089 myScalingDlg->show();
2094 Shows Graduated Axes dialog
2096 void OCCViewer_ViewWindow::onGraduatedAxes()
2098 myCubeAxesDlg->Update();
2099 myCubeAxesDlg->show();
2102 void OCCViewer_ViewWindow::onAmbientToogle()
2104 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2105 viewer->InitDefinedLights();
2106 while(viewer->MoreDefinedLights())
2108 Handle(V3d_Light) light = viewer->DefinedLight();
2109 if(light->Type() != V3d_AMBIENT)
2111 Handle(V3d_View) aView3d = myViewPort->getView();
2112 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
2113 else viewer->SetLightOn(light);
2115 viewer->NextDefinedLights();
2121 \brief Store view parameters.
2123 void OCCViewer_ViewWindow::onMemorizeView()
2125 appendViewAspect( getViewParams() );
2129 \brief Restore view parameters.
2131 void OCCViewer_ViewWindow::onRestoreView()
2133 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
2134 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
2136 updateViewAspects( aDlg->parameters() );
2137 if( myRestoreFlag && aDlg->parameters().count() )
2138 performRestoring( aDlg->currentItem() );
2142 \brief Restore view parameters.
2143 \param anItem view parameters
2145 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
2147 Handle(V3d_View) aView3d = myViewPort->getView();
2149 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
2150 aView3d->SetScale( anItem.scale );
2151 aView3d->SetTwist( anItem.twist );
2152 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
2153 aView3d->SetImmediateUpdate( prev );
2154 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2155 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2156 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
2158 #if OCC_VERSION_LARGE > 0x06070100
2159 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
2161 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
2163 // "eye" and "at" require conversion to represent center panning
2164 // up direction is only available after setting angle of twist and
2165 // other view parameters
2166 aView3d->Up( anUpX, anUpY, anUpZ );
2168 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
2169 gp_Dir anUp( anUpX, anUpY, anUpZ );
2170 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
2171 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2172 gp_Dir aSide = aProj ^ anUp;
2174 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
2175 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
2177 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
2178 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2181 aView3d->SetCenter( anItem.centerX, anItem.centerY );
2184 if ( !baseParamsOnly ) {
2186 myModel->setTrihedronShown( anItem.isVisible );
2187 myModel->setTrihedronSize( anItem.size );
2189 // graduated trihedron
2190 bool anIsVisible = anItem.gtIsVisible;
2191 OCCViewer_AxisWidget::AxisData anAxisData[3];
2192 anAxisData[0].DrawName = anItem.gtDrawNameX;
2193 anAxisData[1].DrawName = anItem.gtDrawNameZ;
2194 anAxisData[2].DrawName = anItem.gtDrawNameZ;
2195 anAxisData[0].Name = anItem.gtNameX;
2196 anAxisData[1].Name = anItem.gtNameZ;
2197 anAxisData[2].Name = anItem.gtNameZ;
2198 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
2199 anItem.gtNameColorGX,
2200 anItem.gtNameColorBX );
2201 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
2202 anItem.gtNameColorGY,
2203 anItem.gtNameColorBY );
2204 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
2205 anItem.gtNameColorGZ,
2206 anItem.gtNameColorBZ );
2207 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
2208 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
2209 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
2210 anAxisData[0].NbValues = anItem.gtNbValuesX;
2211 anAxisData[1].NbValues = anItem.gtNbValuesY;
2212 anAxisData[2].NbValues = anItem.gtNbValuesZ;
2213 anAxisData[0].Offset = anItem.gtOffsetX;
2214 anAxisData[1].Offset = anItem.gtOffsetY;
2215 anAxisData[2].Offset = anItem.gtOffsetZ;
2216 anAxisData[0].Color = QColor( anItem.gtColorRX,
2219 anAxisData[1].Color = QColor( anItem.gtColorRY,
2222 anAxisData[2].Color = QColor( anItem.gtColorRZ,
2225 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
2226 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
2227 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
2228 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
2229 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
2230 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
2232 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
2233 myCubeAxesDlg->ApplyData( aView3d );
2235 } // if ( !baseParamsOnly )
2241 \brief Set restore flag.
2243 void OCCViewer_ViewWindow::setRestoreFlag()
2249 \brief Called when action "show/hide trihedron" is activated.
2251 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
2253 myModel->setTrihedronShown(show);
2257 \brief Toggles preselection (highlighting) on/off
2259 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
2261 myPreselectionEnabled = on;
2262 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
2264 // unhighlight all highlighted objects
2266 myModel->unHighlightAll( true, false );
2269 // update action state if method is called outside
2270 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2271 if ( a && a->isChecked() != on ) {
2272 a->setChecked( on );
2277 \brief Toggles selection on/off
2279 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
2281 mySelectionEnabled = on;
2282 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
2284 // update action state if method is called outside
2287 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2289 a->setEnabled( on );
2293 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
2294 if ( a && a->isChecked() != on ) {
2295 a->setChecked( on );
2300 \brief Switches "keyboard free" interaction style on/off
2302 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
2304 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
2306 // update action state if method is called outside
2307 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
2308 if ( a && a->isChecked() != on )
2309 a->setChecked( on );
2313 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
2315 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
2317 myViewPort->setAdvancedZoomingEnabled( on );
2319 // update action state if method is called outside
2320 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
2321 if ( a && a->isChecked() != on )
2322 a->setChecked( on );
2326 \brief Get current interaction style
2327 \return interaction style
2329 int OCCViewer_ViewWindow::interactionStyle() const
2331 return myInteractionStyle;
2335 \brief Set current interaction style
2336 \param theStyle interaction style
2338 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
2340 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
2344 \brief Get current zooming style
2345 \return zooming style
2347 int OCCViewer_ViewWindow::zoomingStyle() const
2349 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
2353 \brief Set current zooming style
2354 \param theStyle zooming style
2356 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
2358 onSwitchZoomingStyle( theStyle == 1 );
2362 \brief Dump view window contents to the pixmap.
2363 \return pixmap containing all scene rendered in the window
2365 QImage OCCViewer_ViewWindow::dumpView()
2367 Handle(V3d_View) view = myViewPort->getView();
2368 if ( view.IsNull() )
2371 int aWidth = myViewPort->width();
2372 int aHeight = myViewPort->height();
2374 // rnv: An old approach to dump the OCCViewer content
2375 // Now used OCCT built-in procedure.
2377 QApplication::syncX();
2378 view->Redraw(); // In order to reactivate GL context
2381 #ifndef DISABLE_GLVIEWER
2382 OpenGLUtils_FrameBuffer aFrameBuffer;
2383 if( aFrameBuffer.init( aWidth, aHeight ) )
2385 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
2387 glPushAttrib( GL_VIEWPORT_BIT );
2388 glViewport( 0, 0, aWidth, aHeight );
2389 aFrameBuffer.bind();
2394 aFrameBuffer.unbind();
2397 aFrameBuffer.bind();
2398 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
2399 aFrameBuffer.unbind();
2401 anImage = anImage.rgbSwapped();
2402 anImage = anImage.mirrored();
2405 // if frame buffers are unsupported, use old functionality
2408 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
2410 QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
2412 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
2418 view->ToPixMap(aPix,aWidth, aHeight,Graphic3d_BT_RGBA);
2420 QImage anImage( aPix.Data(), aWidth, aHeight, QImage::Format_ARGB32 );
2421 anImage = anImage.mirrored();
2425 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
2426 const QString& fileName,
2427 const QString& format )
2430 QApplication::setOverrideCursor( Qt::WaitCursor );
2431 if ( format != "PS" && format != "EPS")
2432 res = myViewPort->getView()->Dump( fileName.toStdString().c_str() );
2434 #if OCC_VERSION_MAJOR < 7
2435 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
2437 Handle(Graphic3d_CView) a3dView = myViewPort->getView()->View();
2441 res = a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
2442 else if (format == "EPS")
2443 res = a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
2445 QApplication::restoreOverrideCursor();
2450 QString OCCViewer_ViewWindow::filter() const
2452 return tr( "OCC_IMAGE_FILES" );
2457 \brief Set parameters of the cutting plane
2458 \param on if \c true, cutting plane is enabled
2459 \param x X position of plane point
2460 \param y Y position of plane point
2461 \param z Z position of plane point
2462 \param dx X coordinate of plane normal
2463 \param dy Y coordinate of plane normal
2464 \param dz Z coordinate of plane normal
2466 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2467 const double dx, const double dy, const double dz )
2469 Handle(V3d_View) view = myViewPort->getView();
2470 if ( view.IsNull() )
2474 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2476 // try to use already existing plane or create a new one
2477 Handle(V3d_Plane) clipPlane;
2479 // calculate new a,b,c,d values for the plane
2480 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2482 pln.Coefficients(a, b, c, d);
2483 #if OCC_VERSION_LARGE > 0x07000000
2484 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2485 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2486 if(aPlanes->Size() > 0 ) {
2488 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2489 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2490 if(aPlanes.Size() > 0 ) {
2492 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2493 aClipPlane->SetEquation(pln);
2494 aClipPlane->SetOn(Standard_True);
2496 view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2500 #if OCC_VERSION_LARGE > 0x07000000
2501 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2502 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2504 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2505 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2507 for( ;anIter.More();anIter.Next() ){
2508 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2509 aClipPlane->SetOn(Standard_False);
2517 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2519 gp_Dir aDir = pln.Axis().Direction();
2520 gp_Pnt aPnt = pln.Location();
2521 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2526 \brief Check if any cutting plane is enabled
2527 \return \c true if at least one cutting plane is enabled
2529 bool OCCViewer_ViewWindow::isCuttingPlane()
2531 Handle(V3d_View) view = myViewPort->getView();
2533 #if OCC_VERSION_LARGE > 0x07000000
2534 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2535 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2537 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2538 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2540 for( ;anIter.More();anIter.Next() ) {
2541 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2542 if(aClipPlane->IsOn()) {
2551 \brief Get the visual parameters of the view window.
2552 \return visual parameters of view window
2554 viewAspect OCCViewer_ViewWindow::getViewParams() const
2556 double projX, projY, projZ, twist;
2557 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2558 double aScaleX, aScaleY, aScaleZ;
2560 Handle(V3d_View) aView3d = myViewPort->getView();
2562 aView3d->Proj( projX, projY, projZ );
2563 aView3d->At( atX, atY, atZ );
2564 aView3d->Eye( eyeX, eyeY, eyeZ );
2565 twist = aView3d->Twist();
2567 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2569 bool isShown = myModel->isTrihedronVisible();
2570 double size = myModel->trihedronSize();
2572 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2575 params.scale = aView3d->Scale();
2576 params.projX = projX;
2577 params.projY = projY;
2578 params.projZ = projZ;
2579 params.twist = twist;
2586 params.scaleX = aScaleX;
2587 params.scaleY = aScaleY;
2588 params.scaleZ = aScaleZ;
2589 params.name = aName;
2590 params.isVisible= isShown;
2593 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2594 aView3d->Center( params.centerX, params.centerY );
2597 // graduated trihedron
2598 bool anIsVisible = false;
2599 OCCViewer_AxisWidget::AxisData anAxisData[3];
2600 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2602 params.gtIsVisible = anIsVisible;
2603 params.gtDrawNameX = anAxisData[0].DrawName;
2604 params.gtDrawNameY = anAxisData[1].DrawName;
2605 params.gtDrawNameZ = anAxisData[2].DrawName;
2606 params.gtNameX = anAxisData[0].Name;
2607 params.gtNameY = anAxisData[1].Name;
2608 params.gtNameZ = anAxisData[2].Name;
2609 params.gtNameColorRX = anAxisData[0].NameColor.red();
2610 params.gtNameColorGX = anAxisData[0].NameColor.green();
2611 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2612 params.gtNameColorRY = anAxisData[1].NameColor.red();
2613 params.gtNameColorGY = anAxisData[1].NameColor.green();
2614 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2615 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2616 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2617 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2618 params.gtDrawValuesX = anAxisData[0].DrawValues;
2619 params.gtDrawValuesY = anAxisData[1].DrawValues;
2620 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2621 params.gtNbValuesX = anAxisData[0].NbValues;
2622 params.gtNbValuesY = anAxisData[1].NbValues;
2623 params.gtNbValuesZ = anAxisData[2].NbValues;
2624 params.gtOffsetX = anAxisData[0].Offset;
2625 params.gtOffsetY = anAxisData[1].Offset;
2626 params.gtOffsetZ = anAxisData[2].Offset;
2627 params.gtColorRX = anAxisData[0].Color.red();
2628 params.gtColorGX = anAxisData[0].Color.green();
2629 params.gtColorBX = anAxisData[0].Color.blue();
2630 params.gtColorRY = anAxisData[1].Color.red();
2631 params.gtColorGY = anAxisData[1].Color.green();
2632 params.gtColorBY = anAxisData[1].Color.blue();
2633 params.gtColorRZ = anAxisData[2].Color.red();
2634 params.gtColorGZ = anAxisData[2].Color.green();
2635 params.gtColorBZ = anAxisData[2].Color.blue();
2636 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2637 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2638 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2639 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2640 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2641 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2647 \brief Get visual parameters of this view window.
2648 \return visual parameters of view window
2650 QString OCCViewer_ViewWindow::getVisualParameters()
2652 viewAspect params = getViewParams();
2656 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2657 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2658 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
2659 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
2661 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2662 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2663 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2664 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2665 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2666 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2667 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2668 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2669 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2670 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2671 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2672 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2673 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2674 data << QString( "isVisible=%1" ).arg( params.isVisible );
2675 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2677 ClipPlanesList aPlanes = myModel->getClipPlanes();
2678 for ( int i=0; i < aPlanes.size(); i++ )
2680 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2681 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2682 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2683 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2684 switch ( aPlane.Mode )
2686 case OCCViewer_ClipPlane::Absolute :
2688 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2690 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2692 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2693 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2694 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2698 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2703 case OCCViewer_ClipPlane::Relative :
2705 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2706 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2707 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2712 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2713 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2714 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2715 data << ClippingPlane;
2718 // graduated trihedron
2719 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2720 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2721 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2722 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2723 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2724 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2725 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2726 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2727 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2728 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2729 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2730 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2731 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2732 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2733 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2734 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2735 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2736 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2737 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2738 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2739 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2740 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2741 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2742 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2743 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2744 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2745 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2746 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2747 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2748 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2749 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2750 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2751 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2752 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2753 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2754 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2755 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2756 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2757 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2758 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2760 // ray tracing parameters
2761 Graphic3d_RenderingParams rendParams = this->getViewPort()->getView()->RenderingParams();
2762 if ( rendParams.Method == Graphic3d_RM_RAYTRACING ) {
2763 QString RayTracing = "rayTracing=";
2764 RayTracing += QString( "rtDepth~%1;" ).arg( rendParams.RaytracingDepth );
2765 RayTracing += QString( "rtReflection~%1;" ).arg( rendParams.IsReflectionEnabled );
2766 RayTracing += QString( "rtAntialiasing~%1;" ).arg( rendParams.IsAntialiasingEnabled );
2767 RayTracing += QString( "rtShadow~%1;" ).arg( rendParams.IsShadowEnabled );
2768 RayTracing += QString( "rtTransShadow~%1;" ).arg( rendParams.IsTransparentShadowEnabled );
2772 // environment texture parameters
2773 Handle(Graphic3d_TextureEnv) aTexture = this->getViewPort()->getView()->TextureEnv();
2774 if ( !aTexture.IsNull() ) {
2775 QString EnvTexture = "envTexture=";
2776 if ( aTexture->Name() == Graphic3d_NOT_ENV_UNKNOWN ) {
2777 TCollection_AsciiString aFileName;
2778 aTexture->Path().SystemName( aFileName );
2779 EnvTexture += QString( "etFile~%1;" ).arg( aFileName.ToCString() );
2782 EnvTexture += QString( "etNumber~%1;" ).arg( aTexture->Name() );
2786 // light source parameters
2787 myModel->getViewer3d()->InitDefinedLights();
2788 while ( myModel->getViewer3d()->MoreDefinedLights() )
2790 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2791 if ( aLight->Type() != V3d_AMBIENT ) {
2792 QString LightSource = QString( "lightSource=" );
2793 LightSource += QString( "lightType~%1;" ).arg( aLight->Type() );
2795 if ( aLight->Type() == V3d_DIRECTIONAL )
2796 Handle(V3d_DirectionalLight)::DownCast( aLight )->Direction( aX, aY, aZ );
2797 else if ( aLight->Type() == V3d_POSITIONAL )
2798 Handle(V3d_PositionalLight)::DownCast( aLight )->Position( aX, aY, aZ );
2799 LightSource += QString( "lightX~%1;" ).arg( aX );
2800 LightSource += QString( "lightY~%1;" ).arg( aY );
2801 LightSource += QString( "lightZ~%1;" ).arg( aZ );
2802 LightSource += QString( "lightColorR~%1;" ).arg( aLight->Color().Red() );
2803 LightSource += QString( "lightColorG~%1;" ).arg( aLight->Color().Green() );
2804 LightSource += QString( "lightColorB~%1;" ).arg( aLight->Color().Blue() );
2805 LightSource += QString( "lightHeadlight~%1;" ).arg( aLight->Headlight() );
2806 data << LightSource;
2808 myModel->getViewer3d()->NextDefinedLights();
2811 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2812 data << QString( "background=%1" ).arg( bg );
2814 return data.join("*");
2818 \brief Restore visual parameters of the view window.
2819 \param parameters visual parameters of view window
2821 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2824 ClipPlanesList aClipPlanes;
2825 QStringList data = parameters.split( '*' );
2826 Qtx::BackgroundData bgData;
2827 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2829 foreach( QString param, data ) {
2830 QString paramName = param.section( '=', 0, 0 ).trimmed();
2831 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2832 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2833 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2834 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2835 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2836 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2837 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2838 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2839 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2840 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2841 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2842 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2843 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2844 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2845 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2846 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2847 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2848 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2849 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2850 else if ( paramName.contains( "ClippingPlane" ) )
2852 QStringList ClipPlaneData = paramValue.split( ';' );
2853 OCCViewer_ClipPlane aPlane;
2854 foreach( QString ClipPlaneParam, ClipPlaneData )
2856 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2857 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2858 if ( ClipPlane_paramName == "Mode" )
2860 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2862 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2863 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2864 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2865 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2868 switch ( aPlane.Mode )
2870 case OCCViewer_ClipPlane::Absolute :
2871 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2872 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2873 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2874 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2875 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2878 case OCCViewer_ClipPlane::Relative :
2879 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2880 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2881 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2886 aClipPlanes.push_back(aPlane);
2888 // graduated trihedron
2889 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2890 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2891 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2892 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2893 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2894 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2895 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2896 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2897 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2898 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2899 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2900 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2901 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2902 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2903 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2904 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2905 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2906 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2907 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2908 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2909 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2910 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2911 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2912 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2913 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2914 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2915 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2916 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2917 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2918 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2919 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2920 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2921 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2922 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2923 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2924 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2925 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2926 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2927 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2928 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2929 else if ( paramName == "rayTracing" )
2931 Graphic3d_RenderingParams& rendParams = this->getViewPort()->getView()->ChangeRenderingParams();
2932 rendParams.Method = Graphic3d_RM_RAYTRACING;
2933 QStringList rtData = paramValue.split( ';' );
2934 foreach( QString rtParam, rtData )
2936 QString rt_paramName = rtParam.section( '~', 0, 0 ).trimmed();
2937 QString rt_paramValue = rtParam.section( '~', 1, 1 ).trimmed();
2938 if ( rt_paramName == "rtDepth" ) rendParams.RaytracingDepth = rt_paramValue.toInt();
2939 else if ( rt_paramName == "rtReflection" ) rendParams.IsReflectionEnabled = rt_paramValue.toInt();
2940 else if ( rt_paramName == "rtAntialiasing" ) rendParams.IsAntialiasingEnabled = rt_paramValue.toInt();
2941 else if ( rt_paramName == "rtShadow" ) rendParams.IsShadowEnabled = rt_paramValue.toInt();
2942 else if ( rt_paramName == "rtTransShadow" ) rendParams.IsTransparentShadowEnabled = rt_paramValue.toInt();
2945 else if ( paramName == "envTexture" )
2947 Handle(Graphic3d_TextureEnv) aTexture;
2948 QStringList etData = paramValue.split( ';' );
2949 foreach( QString etParam, etData )
2951 QString et_paramName = etParam.section( '~', 0, 0 ).trimmed();
2952 QString et_paramValue = etParam.section( '~', 1, 1 ).trimmed();
2953 if ( et_paramName == "etNumber" )
2954 aTexture = new Graphic3d_TextureEnv( Graphic3d_NameOfTextureEnv( et_paramValue.toInt() ) );
2955 else if ( et_paramName == "etFile" )
2956 aTexture = new Graphic3d_TextureEnv( TCollection_AsciiString( et_paramValue.toStdString().c_str() ) );
2957 Handle(V3d_View) aView = this->getViewPort()->getView();
2958 aView->SetTextureEnv( aTexture );
2959 #if OCC_VERSION_LARGE <= 0x07000000
2960 aView->SetSurfaceDetail( V3d_TEX_ENVIRONMENT );
2964 else if ( paramName == "lightSource" )
2966 myModel->getViewer3d()->InitDefinedLights();
2967 while ( myModel->getViewer3d()->MoreDefinedLights() )
2969 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2970 if( aLight->Type() != V3d_AMBIENT ) {
2971 myModel->getViewer3d()->DelLight( aLight );
2972 myModel->getViewer3d()->InitDefinedLights();
2974 myModel->getViewer3d()->NextDefinedLights();
2979 V3d_TypeOfLight aType;
2981 QStringList lsData = paramValue.split( ';' );
2982 foreach( QString lsParam, lsData )
2984 QString ls_paramName = lsParam.section( '~', 0, 0 ).trimmed();
2985 QString ls_paramValue = lsParam.section( '~', 1, 1 ).trimmed();
2986 if ( ls_paramName == "lightType" ) aType = V3d_TypeOfLight( ls_paramValue.toInt() );
2987 else if ( ls_paramName == "lightX" ) aX = ls_paramValue.toDouble();
2988 else if ( ls_paramName == "lightY" ) aY = ls_paramValue.toDouble();
2989 else if ( ls_paramName == "lightZ" ) aZ = ls_paramValue.toDouble();
2990 else if ( ls_paramName == "lightColorR" ) cR = ls_paramValue.toDouble();
2991 else if ( ls_paramName == "lightColorG" ) cG = ls_paramValue.toDouble();
2992 else if ( ls_paramName == "lightColorB" ) cB = ls_paramValue.toDouble();
2993 else if ( ls_paramName == "lightHeadlight" ) isHeadlight = ls_paramValue.toInt();
2995 Quantity_Color aColor = Quantity_Color( cR, cG, cB, Quantity_TOC_RGB );
2996 if( aType == V3d_DIRECTIONAL ) {
2997 Handle(V3d_DirectionalLight) aLight = new V3d_DirectionalLight( myModel->getViewer3d() );
2998 aLight->SetDirection( aX, aY, aZ );
2999 aLight->SetColor( aColor );
3000 aLight->SetHeadlight( isHeadlight );
3001 myModel->getViewer3d()->SetLightOn( aLight );
3003 else if( aType == V3d_POSITIONAL ) {
3004 Handle(V3d_PositionalLight) aLight = new V3d_PositionalLight( myModel->getViewer3d(), aX, aY, aZ, aColor.Name() );
3005 aLight->SetHeadlight( isHeadlight );
3006 myModel->getViewer3d()->SetLightOn( aLight );
3009 else if ( paramName == "background" ) {
3010 QString bg = paramValue.replace( "$", "=" );
3011 bgData = Qtx::stringToBackground( bg );
3015 else // old format - "1.000e+00*0.000e+00..."
3018 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
3019 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
3020 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
3021 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
3022 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
3023 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
3024 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
3025 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
3026 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
3027 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
3028 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
3029 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
3030 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
3031 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
3032 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
3033 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
3034 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
3035 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
3037 performRestoring( params );
3038 setBackground( bgData );
3039 myModel->setClipPlanes(aClipPlanes);
3043 \brief Handle show event.
3045 Emits Show() signal.
3047 \param theEvent show event
3049 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
3051 emit Show( theEvent );
3055 \brief Handle hide event.
3057 Emits Hide() signal.
3059 \param theEvent hide event
3061 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
3063 emit Hide( theEvent );
3068 Save old cursor. [ protected ]
3070 void OCCViewer_ViewWindow::saveCursor()
3072 QCursor* aCursor = NULL;
3074 aCursor = myViewPort->getDefaultCursor();
3075 myCursor = ( aCursor ? *aCursor : cursor() );
3080 Creates default sketcher. [ virtual protected ]
3082 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
3085 return new OCCViewer_RectSketcher( this, type );
3086 if ( type == Polygon )
3087 return new OCCViewer_PolygonSketcher( this, type );
3091 void OCCViewer_ViewWindow::initSketchers()
3093 if ( mySketchers.isEmpty() )
3095 mySketchers.append( createSketcher( Rect ) );
3096 mySketchers.append( createSketcher( Polygon ) );
3100 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
3102 OCCViewer_ViewSketcher* sketcher = 0;
3103 QList<OCCViewer_ViewSketcher*>::Iterator it;
3104 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
3106 OCCViewer_ViewSketcher* sk = (*it);
3107 if ( sk->type() == typ )
3114 Handles requests for sketching in the active view. [ virtual public ]
3116 void OCCViewer_ViewWindow::activateSketching( int type )
3118 OCCViewer_ViewPort3d* vp = getViewPort();
3122 if ( !vp->isSketchingEnabled() )
3125 /* Finish current sketching */
3126 if ( type == NoSketching )
3130 onSketchingFinished();
3131 mypSketcher->deactivate();
3135 /* Activate new sketching */
3138 activateSketching( NoSketching ); /* concurrency not suported */
3139 mypSketcher = getSketcher( type );
3142 mypSketcher->activate();
3143 onSketchingStarted();
3149 Unhilights detected entities. [ virtual protected ]
3151 void OCCViewer_ViewWindow::onSketchingStarted()
3156 Selection by rectangle or polygon. [ virtual protected ]
3158 void OCCViewer_ViewWindow::onSketchingFinished()
3160 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
3161 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
3163 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
3164 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
3165 switch( mypSketcher->type() )
3169 QRect* aRect = (QRect*)mypSketcher->data();
3172 int aLeft = aRect->left();
3173 int aRight = aRect->right();
3174 int aTop = aRect->top();
3175 int aBottom = aRect->bottom();
3179 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
3181 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
3187 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
3190 int size = aPolygon->size();
3191 TColgp_Array1OfPnt2d anArray( 1, size );
3193 QPolygon::Iterator it = aPolygon->begin();
3194 QPolygon::Iterator itEnd = aPolygon->end();
3195 for( int index = 1; it != itEnd; ++it, index++ )
3197 QPoint aPoint = *it;
3198 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
3202 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
3204 ic->Select( anArray, getViewPort()->getView(), Standard_False );
3212 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
3213 aViewMgr->getOCCViewer()->performSelectionChanged();
3217 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
3222 bool OCCViewer_ViewWindow::transformRequested() const
3224 return ( myOperation != NOTHING );
3227 bool OCCViewer_ViewWindow::transformInProcess() const
3229 return myEventStarted;
3232 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
3234 myEventStarted = bOn;
3238 Set enabled state of transformation (rotate, zoom, etc)
3240 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
3242 if ( id != NOTHING ) myStatus.insert( id, on );
3246 \return enabled state of transformation (rotate, zoom, etc)
3248 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
3250 return myStatus.contains( id ) ? myStatus[ id ] : true;
3253 void OCCViewer_ViewWindow::onMaximizedView()
3255 setMaximized(!isMaximized());
3258 void OCCViewer_ViewWindow::returnTo3dView()
3260 setReturnedTo3dView( true );
3263 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
3265 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
3266 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
3267 if ( !isVisible3dView )
3268 toolMgr()->show( ReturnTo3dViewId );
3270 toolMgr()->hide( ReturnTo3dViewId );
3271 if ( isVisible3dView ) emit returnedTo3d( );
3275 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
3277 QAction* anAction = toolMgr()->action( MaximizedId );
3278 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
3279 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
3281 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
3282 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
3283 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
3284 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
3285 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
3287 emit maximized( this, true );
3291 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
3292 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
3293 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
3294 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
3295 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
3297 emit maximized( this, false );
3302 bool OCCViewer_ViewWindow::isMaximized() const
3304 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
3307 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
3309 IsSketcherStyle = enable;
3312 bool OCCViewer_ViewWindow::isSketcherStyle() const
3314 return IsSketcherStyle;
3318 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
3323 int OCCViewer_ViewWindow::projectionType() const
3325 int mode = Orthographic;
3326 Handle(V3d_View) aView3d = myViewPort->getView();
3327 if ( !aView3d.IsNull() ) {
3328 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3329 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Perspective)
3331 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Orthographic)
3332 mode = Orthographic;
3333 #if OCC_VERSION_LARGE > 0x06090000
3334 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
3341 void OCCViewer_ViewWindow::setStereoType( int type )
3343 Handle(V3d_View) aView3d = myViewPort->getView();
3344 if ( !aView3d.IsNull() ) {
3345 #if OCC_VERSION_LARGE > 0x06090000
3346 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3347 aParams->StereoMode = (Graphic3d_StereoMode)type;
3352 int OCCViewer_ViewWindow::stereoType() const
3354 int type = QuadBuffer;
3355 Handle(V3d_View) aView3d = myViewPort->getView();
3356 if ( !aView3d.IsNull() ) {
3357 #if OCC_VERSION_LARGE > 0x06090000
3358 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3359 type = (OCCViewer_ViewWindow::StereoType)aParams->StereoMode;
3365 void OCCViewer_ViewWindow::setAnaglyphFilter( int type )
3367 Handle(V3d_View) aView3d = myViewPort->getView();
3368 if ( !aView3d.IsNull() ) {
3369 #if OCC_VERSION_LARGE > 0x06090000
3370 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3371 if (type == RedCyan)
3372 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
3373 if (type == YellowBlue)
3374 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
3375 if (type == GreenMagenta)
3376 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
3381 int OCCViewer_ViewWindow::anaglyphFilter() const
3384 Handle(V3d_View) aView3d = myViewPort->getView();
3385 if ( !aView3d.IsNull() ) {
3386 #if OCC_VERSION_LARGE > 0x06090000
3387 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3388 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized)
3390 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized)
3392 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple)
3393 type = GreenMagenta;
3399 void OCCViewer_ViewWindow::setStereographicFocus( int type, double value )
3401 Handle(V3d_View) aView3d = myViewPort->getView();
3402 if ( !aView3d.IsNull() ) {
3403 #if OCC_VERSION_LARGE > 0x06090000
3404 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3405 aCamera->SetZFocus( (Graphic3d_Camera::FocusType) type, value );
3410 int OCCViewer_ViewWindow::stereographicFocusType() const
3412 int type = Relative;
3413 Handle(V3d_View) aView3d = myViewPort->getView();
3414 if ( !aView3d.IsNull() ) {
3415 #if OCC_VERSION_LARGE > 0x06090000
3416 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3417 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->ZFocusType();
3423 double OCCViewer_ViewWindow::stereographicFocusValue() const
3426 Handle(V3d_View) aView3d = myViewPort->getView();
3427 if ( !aView3d.IsNull() ) {
3428 #if OCC_VERSION_LARGE > 0x06090000
3429 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3430 value = aCamera->ZFocus();
3436 void OCCViewer_ViewWindow::setInterocularDistance( int type, double value )
3438 Handle(V3d_View) aView3d = myViewPort->getView();
3439 if ( !aView3d.IsNull() ) {
3440 #if OCC_VERSION_LARGE > 0x06090000
3441 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3442 aCamera->SetIOD( (Graphic3d_Camera::IODType) type, value );
3447 int OCCViewer_ViewWindow::interocularDistanceType() const
3449 int type = Relative;
3450 Handle(V3d_View) aView3d = myViewPort->getView();
3451 if ( !aView3d.IsNull() ) {
3452 #if OCC_VERSION_LARGE > 0x06090000
3453 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3454 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->GetIODType();
3460 double OCCViewer_ViewWindow::interocularDistanceValue() const
3462 double value = 0.05;
3463 Handle(V3d_View) aView3d = myViewPort->getView();
3464 if ( !aView3d.IsNull() ) {
3465 #if OCC_VERSION_LARGE > 0x06090000
3466 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3467 value = aCamera->IOD();
3473 void OCCViewer_ViewWindow::setReverseStereo( bool reverse )
3475 Handle(V3d_View) aView3d = myViewPort->getView();
3476 if ( !aView3d.IsNull() ) {
3477 #if OCC_VERSION_LARGE > 0x06090000
3478 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3479 aParams->ToReverseStereo = reverse;
3484 bool OCCViewer_ViewWindow::isReverseStereo() const
3486 int reverse = false;
3487 Handle(V3d_View) aView3d = myViewPort->getView();
3488 if ( !aView3d.IsNull() ) {
3489 #if OCC_VERSION_LARGE > 0x06090000
3490 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3491 reverse = aParams->ToReverseStereo;
3497 void OCCViewer_ViewWindow::setVSync( bool enable )
3499 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3500 if ( !anIntCont.IsNull() ) {
3501 #if OCC_VERSION_LARGE > 0x06090000
3502 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3503 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3504 aCaps->swapInterval = enable;
3509 bool OCCViewer_ViewWindow::isVSync() const
3512 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3513 if ( !anIntCont.IsNull() ) {
3514 #if OCC_VERSION_LARGE > 0x06090000
3515 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3516 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3517 enable = aCaps->swapInterval;
3523 void OCCViewer_ViewWindow::setQuadBufferSupport( bool enable )
3525 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3526 if ( !anIntCont.IsNull() ) {
3527 #if OCC_VERSION_LARGE > 0x06090000
3528 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3529 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3530 aCaps->contextStereo = enable;
3535 bool OCCViewer_ViewWindow::isQuadBufferSupport() const
3538 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3539 if ( !anIntCont.IsNull() ) {
3540 #if OCC_VERSION_LARGE > 0x06090000
3541 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3542 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3543 enable = aCaps->contextStereo;
3549 bool OCCViewer_ViewWindow::isOpenGlStereoSupport() const
3551 GLboolean support[1];
3552 glGetBooleanv (GL_STEREO, support);
3559 QColor OCCViewer_ViewWindow::backgroundColor() const
3561 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
3565 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
3567 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
3570 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
3572 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
3575 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
3577 if ( myViewPort ) myViewPort->setBackground( theBackground );
3580 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
3582 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
3588 void OCCViewer_ViewWindow::clearViewAspects()
3590 myViewAspects.clear();
3594 \return const reference to list of view aspects
3596 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
3598 return myViewAspects;
3602 Appends new view aspect
3603 \param aParams - new view aspects
3605 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
3607 myViewAspects.append( aParams );
3611 Replaces old view aspects by new ones
3612 \param aViewList - list of new view aspects
3614 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
3616 myViewAspects = aViewList;
3620 Get camera properties for the OCC view window.
3621 \return shared pointer on camera properties.
3623 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
3625 SUIT_CameraProperties aProps;
3627 Handle(V3d_View) aSourceView = getViewPort()->getView();
3628 if ( aSourceView.IsNull() )
3631 if ( get2dMode() == No2dMode ) {
3632 aProps.setDimension( SUIT_CameraProperties::Dim3D );
3635 aProps.setDimension( SUIT_CameraProperties::Dim2D );
3636 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
3639 // read common properites of the view
3640 Standard_Real anUp[3];
3641 Standard_Real anAt[3];
3642 Standard_Real anEye[3];
3643 Standard_Real aProj[3];
3644 Standard_Real anAxialScale[3];
3646 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
3647 aSourceView->At( anAt[0], anAt[1], anAt[2] );
3648 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
3649 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3651 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3652 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
3654 #if OCC_VERSION_LARGE > 0x06070100
3655 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
3657 // store camera properties "as is": it is up to synchronized
3658 // view classes to provide necessary property conversion.
3659 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
3660 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
3662 if ( aSourceView->Camera()->IsOrthographic() )
3664 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
3665 aProps.setViewAngle( 0.0 );
3669 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
3670 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
3672 aProps.setMappingScale( aSourceView->Camera()->Scale() );
3674 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
3676 // generate view orientation matrix for transforming OCC projection reference point
3677 // into a camera (eye) position.
3678 gp_Dir aLeftDir = gp_Dir( anUp[0], anUp[1], anUp[2] ) ^ gp_Dir( aProj[0], aProj[1], aProj[2] );
3681 aTrsf.SetValue( 1, 1, aLeftDir.X() );
3682 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
3683 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
3685 aTrsf.SetValue( 1, 2, anUp[0] );
3686 aTrsf.SetValue( 2, 2, anUp[1] );
3687 aTrsf.SetValue( 3, 2, anUp[2] );
3689 aTrsf.SetValue( 1, 3, aProj[0] );
3690 aTrsf.SetValue( 2, 3, aProj[1] );
3691 aTrsf.SetValue( 3, 3, aProj[2] );
3693 aTrsf.SetValue( 1, 4, anAt[0] );
3694 aTrsf.SetValue( 2, 4, anAt[1] );
3695 aTrsf.SetValue( 3, 4, anAt[2] );
3697 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
3699 // transform to world-space coordinate system
3700 gp_XYZ aPosition( aProjRef.X(), aProjRef.Y(), aCameraDepth );
3701 aTrsf.Transforms( aPosition );
3703 // compute focal point
3704 double aFocalPoint[3];
3706 aFocalPoint[0] = aPosition.X() - aProj[0] * aCameraDepth;
3707 aFocalPoint[1] = aPosition.Y() - aProj[1] * aCameraDepth;
3708 aFocalPoint[2] = aPosition.Z() - aProj[2] * aCameraDepth;
3710 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3711 aProps.setPosition( aPosition.X(), aPosition.Y(), aPosition.Z() );
3713 Standard_Real aViewScale[2];
3714 aSourceView->Size( aViewScale[0], aViewScale[1] );
3715 aProps.setMappingScale( aViewScale[1] );
3723 This implementation synchronizes OCC view's camera propreties.
3725 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
3727 bool blocked = blockSignals( true );
3729 SUIT_CameraProperties aProps = theView->cameraProperties();
3730 if ( !cameraProperties().isCompatible( aProps ) ) {
3731 // other view, this one is being currently synchronized to, seems has become incompatible
3732 // we have to break synchronization
3737 Handle(V3d_View) aDestView = getViewPort()->getView();
3739 aDestView->SetImmediateUpdate( Standard_False );
3742 double aPosition[3];
3743 double aFocalPoint[3];
3744 double anAxialScale[3];
3746 // get common properties
3747 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3748 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
3749 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3750 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3752 #if OCC_VERSION_LARGE > 0x06070100
3753 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3754 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
3755 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3756 aDestView->Camera()->SetScale( aProps.getMappingScale() );
3758 gp_Dir aProjDir( aPosition[0] - aFocalPoint[0],
3759 aPosition[1] - aFocalPoint[1],
3760 aPosition[2] - aFocalPoint[2] );
3762 // get custom view translation
3763 Standard_Real aTranslation[3];
3764 aDestView->At( aTranslation[0], aTranslation[1], aTranslation[2] );
3766 gp_Dir aLeftDir = gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] )
3767 ^ gp_Dir( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
3770 aTrsf.SetValue( 1, 1, aLeftDir.X() );
3771 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
3772 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
3774 aTrsf.SetValue( 1, 2, anUpDir[0] );
3775 aTrsf.SetValue( 2, 2, anUpDir[1] );
3776 aTrsf.SetValue( 3, 2, anUpDir[2] );
3778 aTrsf.SetValue( 1, 3, aProjDir.X() );
3779 aTrsf.SetValue( 2, 3, aProjDir.Y() );
3780 aTrsf.SetValue( 3, 3, aProjDir.Z() );
3782 aTrsf.SetValue( 1, 4, aTranslation[0] );
3783 aTrsf.SetValue( 2, 4, aTranslation[1] );
3784 aTrsf.SetValue( 3, 4, aTranslation[2] );
3787 // transform to view-space coordinate system
3788 gp_XYZ aProjRef( aPosition[0], aPosition[1], aPosition[2] );
3789 aTrsf.Transforms( aProjRef );
3791 // set view camera properties using low-level approach. this is done
3792 // in order to avoid interference with static variables in v3d view used
3793 // when rotation is in process in another view.
3794 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
3795 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
3797 Graphic3d_Vector aMappingProj( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
3798 Graphic3d_Vector aMappingUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3800 aMappingProj.Normalize();
3801 aMappingUp.Normalize();
3803 anOrientation.SetViewReferencePlane( aMappingProj );
3804 anOrientation.SetViewReferenceUp( aMappingUp );
3806 aDestView->SetViewMapping( aMapping );
3807 aDestView->SetViewOrientation( anOrientation );
3810 aDestView->SetCenter( aProjRef.X(), aProjRef.Y() );
3812 // set mapping scale
3813 double aMapScaling = aProps.getMappingScale();
3814 Standard_Real aWidth, aHeight;
3815 aDestView->Size( aWidth, aHeight );
3816 aDestView->SetSize ( aWidth > aHeight ? aMapScaling * (aWidth / aHeight) : aMapScaling );
3819 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3820 #if OCC_VERSION_LARGE <= 0x07000000
3821 aDestView->ZFitAll();
3823 aDestView->SetImmediateUpdate( Standard_True );
3824 aDestView->Redraw();
3826 blockSignals( blocked );
3830 \brief Indicates whether preselection is enabled
3831 \return true if preselection is enabled
3833 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
3835 return myPreselectionEnabled;
3839 \brief Enables/disables preselection
3840 \param theIsToEnable if true - preselection will be enabled
3842 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
3844 onSwitchPreselection( theIsToEnable );
3848 \brief Indicates whether selection is enabled
3849 \return true if selection is enabled
3851 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3853 return mySelectionEnabled;
3857 \brief Enables/disables selection
3858 \param theIsToEnable if true - selection will be enabled
3860 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3862 onSwitchSelection( theIsToEnable );
3867 \brief called if clipping operation is activated / deactivated.
3869 Enables/disables clipping plane displaying.
3871 \parma on action state
3873 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3875 if(!myModel) return;
3876 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3879 if (!aClippingDlg) {
3880 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3881 myModel->setClippingDlg(aClippingDlg);
3883 if (!aClippingDlg->isVisible())
3884 aClippingDlg->show();
3886 if ( aClippingDlg ) {
3887 aClippingDlg->close();
3888 myModel->setClippingDlg(0);
3892 SUIT_ViewManager* mgr = getViewManager();
3894 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3895 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3896 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3897 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3899 QAction* a = toolMgr()->action( ClippingId );
3901 if(theIsOn != a->isChecked()){
3902 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3903 a->setChecked(theIsOn);
3904 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3911 void OCCViewer_ViewWindow::onRayTracing()
3913 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_RayTracingDlg::getName() ) ) {
3914 QDialog* aDlg = new OCCViewer_RayTracingDlg( this );
3920 void OCCViewer_ViewWindow::onEnvTexture()
3922 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_EnvTextureDlg::getName() ) ) {
3923 QDialog* aDlg = new OCCViewer_EnvTextureDlg( this );
3929 void OCCViewer_ViewWindow::onLightSource()
3931 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_LightSourceDlg::getName() ) ) {
3932 QDialog* aDlg = new OCCViewer_LightSourceDlg( this, myModel );
3938 void OCCViewer_ViewWindow::ProjAndPanToGravity(V3d_TypeOfOrientation CamOri)
3940 const bool USE_XY = true;
3942 Handle(V3d_View) aView3d = myViewPort->getView();
3943 if (aView3d.IsNull())
3947 double X = 0, Y = 0, Z = 0;
3950 const double EPS = 1E-6;
3951 int xp = myViewPort->width()/2, yp = myViewPort->height()/2, xp1, yp1;
3952 aView3d->Convert( xp, yp, X, Y, Z );
3954 gp_Dir d = aView3d->Camera()->Direction();
3955 if( fabs( d.Z() ) > EPS )
3957 double t = -Z/d.Z();
3964 // It is really necessary to compute gravity center even if it is not used in part of code below.
3965 // Without this calculation the SetProj() method and other methods are not correct.
3967 IsGr = computeGravityCenter(X2, Y2, Z2);
3969 IsGr = OCCViewer_Utilities::computeSceneBBCenter(aView3d, X2, Y2, Z2);
3971 aView3d->SetProj(CamOri);
3974 //aView3d->Update();
3975 Handle(Graphic3d_Camera) Cam = aView3d->Camera();
3977 gp_Vec dir (Cam->Direction());
3978 gp_Pnt eye = Cam->Eye();
3980 Standard_Real D = dir.Dot(V1);
3981 gp_Pnt ppdir = eye.Translated(D*dir);
3982 gp_Vec V2(ppdir, gp);
3983 gp_XYZ trEye = eye.XYZ() + V2.XYZ();
3985 double xat, yat, zat;
3986 aView3d->At(xat, yat, zat);
3987 gp_Pnt At(xat, yat, zat);
3988 gp_XYZ trAt = At.XYZ() + V2.XYZ();
3989 aView3d->SetEye(trEye.X(), trEye.Y(), trEye.Z());
3990 aView3d->SetAt(trAt.X(), trAt.Y(), trAt.Z());
3995 bool OCCViewer_ViewWindow::isAutomaticZoom() const
3997 return myAutomaticZoom;
4000 void OCCViewer_ViewWindow::setAutomaticZoom(const bool isOn)
4002 myAutomaticZoom = isOn;