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>
90 #if OCC_VERSION_MAJOR < 7
91 #include <Visual3d_View.hxx>
94 #include <V3d_Plane.hxx>
95 #include <V3d_Light.hxx>
99 #include <gp_GTrsf.hxx>
100 #include <TColgp_Array1OfPnt2d.hxx>
102 #include <Image_PixMap.hxx>
104 #include <Standard_Version.hxx>
106 #include "utilities.h"
108 // // OpenCV includes
110 // #include <highgui.h>
112 static QEvent* l_mbPressEvent = 0;
115 //# include <QWindowsStyle>
119 #include <OpenGL/gl.h>
124 // To avoid conflict between KeyPress from the X.h (define KeyPress 2)
125 // and QEvent::KeyPress (qevent.h)
130 // Enable ray tracing features
131 #define ENABLE_RAY_TRACING
133 const char* imageZoomCursor[] = {
138 "................................",
139 "................................",
140 ".#######........................",
141 "..aaaaaaa.......................",
142 "................................",
143 ".............#####..............",
144 "...........##.aaaa##............",
145 "..........#.aa.....a#...........",
146 ".........#.a.........#..........",
147 ".........#a..........#a.........",
148 "........#.a...........#.........",
149 "........#a............#a........",
150 "........#a............#a........",
151 "........#a............#a........",
152 "........#a............#a........",
153 ".........#...........#.a........",
154 ".........#a..........#a.........",
155 ".........##.........#.a.........",
156 "........#####.....##.a..........",
157 ".......###aaa#####.aa...........",
158 "......###aa...aaaaa.......#.....",
159 ".....###aa................#a....",
160 "....###aa.................#a....",
161 "...###aa...............#######..",
162 "....#aa.................aa#aaaa.",
163 ".....a....................#a....",
164 "..........................#a....",
165 "...........................a....",
166 "................................",
167 "................................",
168 "................................",
169 "................................"};
171 const char* imageRotateCursor[] = {
176 "................................",
177 "................................",
178 "................................",
179 "................................",
180 "........#.......................",
181 ".......#.a......................",
182 "......#######...................",
183 ".......#aaaaa#####..............",
184 "........#..##.a#aa##........##..",
185 ".........a#.aa..#..a#.....##.aa.",
186 ".........#.a.....#...#..##.aa...",
187 ".........#a.......#..###.aa.....",
188 "........#.a.......#a..#aa.......",
189 "........#a.........#..#a........",
190 "........#a.........#a.#a........",
191 "........#a.........#a.#a........",
192 "........#a.........#a.#a........",
193 ".........#.........#a#.a........",
194 "........##a........#a#a.........",
195 "......##.a#.......#.#.a.........",
196 "....##.aa..##.....##.a..........",
197 "..##.aa.....a#####.aa...........",
198 "...aa.........aaa#a.............",
199 "................#.a.............",
200 "...............#.a..............",
201 "..............#.a...............",
202 "...............a................",
203 "................................",
204 "................................",
205 "................................",
206 "................................",
207 "................................"};
209 const char* imageCrossCursor[] = {
214 "................................",
215 "................................",
216 "................................",
217 "................................",
218 "................................",
219 "................................",
220 "................................",
221 "...............#................",
222 "...............#a...............",
223 "...............#a...............",
224 "...............#a...............",
225 "...............#a...............",
226 "...............#a...............",
227 "...............#a...............",
228 "...............#a...............",
229 ".......#################........",
230 "........aaaaaaa#aaaaaaaaa.......",
231 "...............#a...............",
232 "...............#a...............",
233 "...............#a...............",
234 "...............#a...............",
235 "...............#a...............",
236 "...............#a...............",
237 "...............#a...............",
238 "................a...............",
239 "................................",
240 "................................",
241 "................................",
242 "................................",
243 "................................",
244 "................................",
245 "................................"};
250 \param theDesktop main window of application
251 \param theModel OCC 3D viewer
253 OCCViewer_ViewWindow::OCCViewer_ViewWindow( SUIT_Desktop* theDesktop,
254 OCCViewer_Viewer* theModel )
255 : SUIT_ViewWindow( theDesktop )
259 myEnableDrawMode = false;
260 myDrawRectEnabled = true;
262 updateEnabledDrawMode();
264 mySetRotationPointDlg = 0;
267 IsSketcherStyle = false;
274 myInteractionStyle = SUIT_ViewModel::STANDARD;
275 myPreselectionEnabled = true;
276 mySelectionEnabled = true;
278 myCursorIsHand = false;
286 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
289 qDeleteAll( mySketchers );
293 \brief Internal initialization.
295 void OCCViewer_ViewWindow::initLayout()
297 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
298 myViewPort->installEventFilter(this);
299 setCentralWidget(myViewPort);
300 myOperation = NOTHING;
302 myCurrPointType = BBCENTER;
303 myPrevPointType = BBCENTER;
304 mySelectedPoint = gp_Pnt(0.,0.,0.);
305 myRotationPointSelection = false;
307 setTransformRequested ( NOTHING );
308 setTransformInProcess ( false );
325 // Graduated axes dialog
326 QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
327 myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
328 myCubeAxesDlg->initialize();
330 connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
333 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
335 return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
339 \brief Detect viewer operation according the the mouse button pressed
340 and key modifiers used.
341 \param theEvent mouse event
342 \return type of the operation
344 OCCViewer_ViewWindow::OperationType
345 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
347 OperationType aOp = NOTHING;
348 SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
349 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
350 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
352 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
353 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
355 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
356 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
357 (my2dMode == No2dMode))
364 \brief Customize event handling
365 \param watched event receiver object
367 \return \c true if the event processing should be stopped
369 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
371 if ( watched == myViewPort ) {
372 int aType = e->type();
374 case QEvent::MouseButtonPress:
375 vpMousePressEvent((QMouseEvent*) e);
378 case QEvent::MouseButtonRelease:
379 vpMouseReleaseEvent((QMouseEvent*) e);
382 case QEvent::MouseMove:
383 vpMouseMoveEvent((QMouseEvent*) e);
386 case QEvent::MouseButtonDblClick:
387 emit mouseDoubleClicked(this, (QMouseEvent*)e);
392 QWheelEvent* aEvent = (QWheelEvent*) e;
394 if ( aEvent->modifiers().testFlag(Qt::ControlModifier) ) {
395 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
396 if ( isPreselectionEnabled() && myModel->useLocalSelection() ) {
397 if ( aEvent->delta() > 0 ) {
398 ic->HilightNextDetected( myViewPort->getView() );
400 ic->HilightPreviousDetected( myViewPort->getView() );
405 emit vpTransformationStarted ( ZOOMVIEW );
406 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
407 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
410 int x1 = (int)( aEvent->x() + width()*delta/100 );
411 int y1 = (int)( aEvent->y() + height()*delta/100 );
412 myViewPort->zoom( x, y, x1, y1 );
413 #if OCC_VERSION_LARGE <= 0x07000000
414 myViewPort->getView()->ZFitAll();
416 emit vpTransformationFinished ( ZOOMVIEW );
421 case QEvent::ContextMenu:
423 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
424 if ( aEvent->reason() != QContextMenuEvent::Mouse )
425 emit contextMenuRequested( aEvent );
429 case QEvent::KeyPress:
430 emit keyPressed(this, (QKeyEvent*) e);
437 return SUIT_ViewWindow::eventFilter(watched, e);
441 \brief Enable / disable draw rect (rubber band) mode
443 bool OCCViewer_ViewWindow::enableDrawMode( bool on )
445 bool prev = myDrawRectEnabled;
446 myDrawRectEnabled = on;
447 updateEnabledDrawMode();
452 \brief Update state of enable draw mode state.
454 void OCCViewer_ViewWindow::updateEnabledDrawMode()
456 myEnableDrawMode = myDrawRectEnabled;
458 myEnableDrawMode = myEnableDrawMode && myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
462 \brief Handle mouse press event
463 \param theEvent mouse event
465 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
467 myStartX = theEvent->x();
468 myStartY = theEvent->y();
469 int anInteractionStyle = interactionStyle();
471 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
472 // which are assigned for pan and rotate - these operations are activated immediately after pressing
473 // of the first button, so it is necessary to switch to zoom when the second button is pressed
474 bool aSwitchToZoom = false;
475 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
476 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
477 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
480 switch ( myOperation ) {
482 if ( theEvent->button() == Qt::LeftButton )
483 emit vpTransformationStarted ( WINDOWFIT );
487 if ( theEvent->button() == Qt::LeftButton )
488 emit vpTransformationStarted ( PANGLOBAL );
492 if ( theEvent->button() == Qt::LeftButton ) {
493 myViewPort->startZoomAtPoint( myStartX, myStartY );
494 emit vpTransformationStarted ( ZOOMVIEW );
499 if ( aSwitchToZoom ) {
500 myViewPort->startZoomAtPoint( myStartX, myStartY );
503 else if ( theEvent->button() == Qt::LeftButton )
504 emit vpTransformationStarted ( PANVIEW );
508 if ( aSwitchToZoom ) {
509 myViewPort->startZoomAtPoint( myStartX, myStartY );
512 else if ( theEvent->button() == Qt::LeftButton ) {
513 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
514 emit vpTransformationStarted ( ROTATE );
519 /* Try to activate a transformation */
520 OperationType aState;
521 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
522 aState = getButtonState(theEvent, anInteractionStyle);
524 aState = OCCViewer_ViewWindow::NOTHING;
529 myViewPort->startZoomAtPoint( myStartX, myStartY );
537 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
540 if ( myRotationPointSelection )
542 if ( theEvent->button() == Qt::LeftButton )
544 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
545 ic->Select( Standard_True );
546 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
548 TopoDS_Shape aShape = ic->SelectedShape();
549 GProp_GProps aSystem;
551 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
553 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
555 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE )
557 BRepGProp::LinearProperties( aShape, aSystem );
558 aPnt = aSystem.CentreOfMass();
560 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE )
562 BRepGProp::SurfaceProperties( aShape, aSystem );
563 aPnt = aSystem.CentreOfMass();
565 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID )
567 BRepGProp::VolumeProperties( aShape, aSystem );
568 aPnt = aSystem.CentreOfMass();
572 myCurrPointType = myPrevPointType;
576 if ( mySetRotationPointDlg )
578 myRotationPointSelection = false;
579 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
582 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
583 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
584 ic->CloseAllContexts( Standard_True );
585 myOperation = NOTHING;
586 myViewPort->setCursor( myCursor );
587 myCursorIsHand = false;
588 myRotationPointSelection = false;
592 emit mousePressed(this, theEvent);
595 /* notify that we start a transformation */
596 if ( transformRequested() )
597 emit vpTransformationStarted ( myOperation );
599 if ( transformRequested() )
600 setTransformInProcess( true );
602 /* we may need it for sketching... */
603 if ( l_mbPressEvent )
604 delete l_mbPressEvent;
605 l_mbPressEvent = new QMouseEvent( *theEvent );
610 \brief Start zooming operation.
612 Sets the corresponding cursor for the widget.
614 void OCCViewer_ViewWindow::activateZoom()
616 if ( !transformRequested() && !myCursorIsHand )
617 saveCursor(); /* save old cursor */
619 if ( myOperation != ZOOMVIEW ) {
620 QPixmap zoomPixmap (imageZoomCursor);
621 QCursor zoomCursor (zoomPixmap);
622 if( setTransformRequested ( ZOOMVIEW ) )
623 myViewPort->setCursor( zoomCursor );
629 \brief Start panning operation.
631 Sets the corresponding cursor for the widget.
633 void OCCViewer_ViewWindow::activatePanning()
635 if ( !transformRequested() && !myCursorIsHand )
636 saveCursor(); // save old cursor
638 if ( myOperation != PANVIEW ) {
639 QCursor panCursor (Qt::SizeAllCursor);
640 if( setTransformRequested ( PANVIEW ) )
641 myViewPort->setCursor( panCursor );
646 \brief Start rotation operation
648 Sets the corresponding cursor for the widget.
650 void OCCViewer_ViewWindow::activateRotation()
652 if ( !transformRequested() && !myCursorIsHand )
653 saveCursor(); // save old cursor
655 if ( myOperation != ROTATE ) {
656 QPixmap rotatePixmap (imageRotateCursor);
657 QCursor rotCursor (rotatePixmap);
658 if( setTransformRequested ( ROTATE ) )
659 myViewPort->setCursor( rotCursor );
664 \brief Compute the gravity center.
665 \param theX used to return X coordinate of the gravity center
666 \param theY used to return Y coordinate of the gravity center
667 \param theZ used to return Z coordinate of the gravity center
668 \return \c true if the gravity center is computed
670 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
672 Handle(V3d_View) aView3d = myViewPort->getView();
674 // Project boundaries points and add to avergae gravity
675 // the ones which lie within the screen limits
676 Standard_Real aScreenLimits[4] = { 0.0, 0.0, 0.0, 0.0 };
678 #if OCC_VERSION_LARGE > 0x06070100
679 // NDC space screen limits
680 aScreenLimits[0] = -1.0;
681 aScreenLimits[1] = 1.0;
682 aScreenLimits[2] = -1.0;
683 aScreenLimits[3] = 1.0;
685 aView3d->View()->ViewMapping().WindowLimit( aScreenLimits[0],
691 Standard_Integer aPointsNb = 0;
693 Standard_Real aXmin = 0.0;
694 Standard_Real aYmin = 0.0;
695 Standard_Real aZmin = 0.0;
696 Standard_Real aXmax = 0.0;
697 Standard_Real aYmax = 0.0;
698 Standard_Real aZmax = 0.0;
700 Graphic3d_MapOfStructure aSetOfStructures;
701 aView3d->View()->DisplayedStructures( aSetOfStructures );
702 Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures );
704 for( ; aStructureIt.More(); aStructureIt.Next() ) {
705 const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key();
706 if ( aStructure->IsEmpty() || !aStructure->IsVisible() || aStructure->CStructure()->IsForHighlight )
709 #if OCC_VERSION_LARGE > 0x06070100
710 Bnd_Box aBox = aStructure->MinMaxValues();
711 aXmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().X();
712 aYmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Y();
713 aZmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Z();
714 aXmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().X();
715 aYmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Y();
716 aZmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Z();
718 aStructure->MinMaxValues( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
721 // Infinite structures are skipped
722 Standard_Real aLIM = ShortRealLast() - 1.0;
723 if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
724 || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
728 gp_Pnt aPoints[8] = {
729 gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
730 gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
731 gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
732 gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
735 for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
736 const gp_Pnt& aBBPoint = aPoints[aPointIt];
738 #if OCC_VERSION_LARGE > 0x06070100
739 gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
740 const Standard_Real& U = aProjected.X();
741 const Standard_Real& V = aProjected.Y();
743 Standard_Real U = 0.0;
744 Standard_Real V = 0.0;
745 Standard_Real W = 0.0;
746 aView3d->View()->Projects( aBBPoint.X(), aBBPoint.Y(), aBBPoint.Z(), U, V, W );
749 if (U >= aScreenLimits[0]
750 && U <= aScreenLimits[1]
751 && V >= aScreenLimits[2]
752 && V <= aScreenLimits[3])
755 theX += aBBPoint.X();
756 theY += aBBPoint.Y();
757 theZ += aBBPoint.Z();
772 \brief Set the gravity center as a rotation point.
774 void OCCViewer_ViewWindow::activateSetRotationGravity()
776 if ( myRotationPointSelection )
778 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
779 ic->CloseAllContexts( Standard_True );
780 myOperation = NOTHING;
781 myViewPort->setCursor( myCursor );
782 myCursorIsHand = false;
783 myRotationPointSelection = false;
786 myPrevPointType = myCurrPointType;
787 myCurrPointType = BBCENTER;
789 Standard_Real Xcenter, Ycenter, Zcenter;
790 if ( OCCViewer_Utilities::computeVisibleBBCenter( myViewPort->getView(), Xcenter, Ycenter, Zcenter ) )
791 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
795 \brief Update gravity center in the "Set Rotation Point" dialog box.
796 \sa OCCViewer_SetRotationPointDlg class
798 void OCCViewer_ViewWindow::updateGravityCoords()
800 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == BBCENTER )
802 Standard_Real Xcenter, Ycenter, Zcenter;
803 if ( OCCViewer_Utilities::computeVisibleBBCenter( myViewPort->getView(), Xcenter, Ycenter, Zcenter ) )
804 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
809 \brief Set the point selected by the user as a rotation point.
810 \param theX X coordinate of the rotation point
811 \param theY Y coordinate of the rotation point
812 \param theZ Z coordinate of the rotation point
814 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
816 if ( myRotationPointSelection )
818 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
819 ic->CloseAllContexts( Standard_True );
820 myOperation = NOTHING;
821 myViewPort->setCursor( myCursor );
822 myCursorIsHand = false;
823 myRotationPointSelection = false;
826 myPrevPointType = myCurrPointType;
827 myCurrPointType = SELECTED;
828 mySelectedPoint.SetCoord(theX,theY,theZ);
832 \brief Start the shape selection process.
834 void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
836 myPrevPointType = myCurrPointType;
837 myCurrPointType = SELECTED;
839 // activate selection ------>
840 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
842 ic->OpenLocalContext();
844 AIS_ListOfInteractive aList;
845 ic->DisplayedObjects( aList );
846 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
848 Handle(AIS_InteractiveObject) anObj = it.Value();
849 if ( !anObj.IsNull() && anObj->HasPresentation() &&
850 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
853 ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
856 // activate selection <------
858 if ( !myCursorIsHand )
860 QCursor handCursor (Qt::PointingHandCursor);
861 myCursorIsHand = true;
863 myViewPort->setCursor( handCursor );
865 myRotationPointSelection = true;
869 \brief Start global panning operation
871 Sets the corresponding cursor for the widget.
873 void OCCViewer_ViewWindow::activateGlobalPanning()
875 Handle(V3d_View) aView3d = myViewPort->getView();
876 if ( !aView3d.IsNull() ) {
877 QPixmap globalPanPixmap (imageCrossCursor);
878 QCursor glPanCursor (globalPanPixmap);
879 myCurScale = aView3d->Scale();
880 aView3d->FitAll(0.01, false);
881 saveCursor(); // save old cursor
882 myViewPort->fitAll(); // fits view before selecting a new scene center
883 if( setTransformRequested( PANGLOBAL ) )
884 myViewPort->setCursor( glPanCursor );
889 \brief Starts fit operation.
891 Sets the corresponding cursor for the widget.
893 void OCCViewer_ViewWindow::activateWindowFit()
895 if ( !transformRequested() && !myCursorIsHand )
896 saveCursor(); /* save old cursor */
898 if ( myOperation != WINDOWFIT ) {
899 QCursor handCursor (Qt::PointingHandCursor);
900 if( setTransformRequested ( WINDOWFIT ) )
902 myViewPort->setCursor ( handCursor );
903 myCursorIsHand = true;
909 \brief Start delayed viewer operation.
911 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
913 bool ok = transformEnabled( op );
914 myOperation = ok ? op : NOTHING;
915 myViewPort->setMouseTracking( myOperation == NOTHING );
920 \brief Handle mouse move event.
921 \param theEvent mouse event
923 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
925 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
927 switch ( getButtonState( theEvent, interactionStyle() ) ) {
929 myViewPort->startZoomAtPoint( myStartX, myStartY );
937 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
944 myCurrX = theEvent->x();
945 myCurrY = theEvent->y();
946 switch (myOperation) {
948 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
952 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
958 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
972 if ( myRotationPointSelection || isSketcherStyle() )
974 emit mouseMoving( this, theEvent );
978 int aState = theEvent->modifiers();
979 int aButton = theEvent->buttons();
980 int anInteractionStyle = interactionStyle();
981 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
982 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
983 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
984 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
985 myDrawRect = myEnableDrawMode;
988 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
989 QCursor handCursor (Qt::PointingHandCursor);
990 myCursorIsHand = true;
992 myViewPort->setCursor( handCursor );
995 emit mouseMoving( this, theEvent );
997 else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
998 aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
999 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
1000 aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
1001 OCCViewer_ViewSketcher* sketcher = 0;
1002 QList<OCCViewer_ViewSketcher*>::Iterator it;
1003 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
1005 OCCViewer_ViewSketcher* sk = (*it);
1006 if( sk->isDefault() && sk->sketchButton() == aButton )
1009 if ( sketcher && myCurSketch == -1 )
1011 activateSketching( sketcher->type() );
1014 myCurSketch = mypSketcher->sketchButton();
1016 if ( l_mbPressEvent )
1018 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
1019 delete l_mbPressEvent;
1022 QApplication::sendEvent( getViewPort(), theEvent );
1027 emit mouseMoving( this, theEvent );
1033 \brief Handle mouse release event.
1034 \param theEvent mouse event
1036 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
1038 switch ( myOperation ) {
1041 int prevState = myCurSketch;
1042 if(theEvent->button() == Qt::RightButton)
1044 QList<OCCViewer_ViewSketcher*>::Iterator it;
1045 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
1047 OCCViewer_ViewSketcher* sk = (*it);
1048 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
1053 emit mouseReleased(this, theEvent);
1054 if(theEvent->button() == Qt::RightButton && prevState == -1)
1056 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1057 theEvent->pos(), theEvent->globalPos() );
1058 emit contextMenuRequested( &aEvent );
1063 myViewPort->endRotation();
1069 #if OCC_VERSION_LARGE <= 0x07000000
1070 myViewPort->getView()->ZFitAll();
1076 if ( theEvent->button() == Qt::LeftButton ) {
1077 myViewPort->setCenter( theEvent->x(), theEvent->y() );
1078 myViewPort->getView()->SetScale(myCurScale);
1084 if ( theEvent->button() == Qt::LeftButton ) {
1085 myCurrX = theEvent->x();
1086 myCurrY = theEvent->y();
1088 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1089 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1096 // NOTE: viewer 3D detects a rectangle of selection using this event
1097 // so we must emit it BEFORE resetting the selection rectangle
1099 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1103 myViewPort->update();
1106 if ( l_mbPressEvent )
1108 delete l_mbPressEvent;
1114 \brief Reset the viewport to its initial state
1115 ( no transformations in process etc. )
1117 void OCCViewer_ViewWindow::resetState()
1121 if ( myRotationPointSelection )
1123 QCursor handCursor (Qt::PointingHandCursor);
1124 myViewPort->setCursor( handCursor );
1128 if ( transformRequested() || myCursorIsHand )
1129 myViewPort->setCursor( myCursor );
1130 myCursorIsHand = false;
1133 if ( transformRequested() )
1134 emit vpTransformationFinished (myOperation);
1136 setTransformInProcess( false );
1137 setTransformRequested( NOTHING );
1142 \brief Draw rubber band rectangle.
1144 void OCCViewer_ViewWindow::drawRect()
1146 if ( !myRectBand ) {
1147 myRectBand = new QtxRectRubberBand( myViewPort );
1149 //palette.setColor(myRectBand->foregroundRole(), Qt::white);
1150 //myRectBand->setPalette(palette);
1152 //myRectBand->hide();
1154 myRectBand->setUpdatesEnabled ( false );
1155 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1156 myRectBand->initGeometry( aRect );
1158 if ( !myRectBand->isVisible() )
1161 myRectBand->setUpdatesEnabled ( true );
1162 //myRectBand->repaint();
1164 //myRectBand->setVisible( aRect.isValid() );
1165 //if ( myRectBand->isVisible() )
1166 // myRectBand->repaint();
1168 // myRectBand->show();
1169 //myRectBand->repaint();
1173 \brief Clear rubber band rectangle on the end on the dragging operation.
1175 void OCCViewer_ViewWindow::endDrawRect()
1177 //delete myRectBand;
1181 myRectBand->clearGeometry();
1187 \brief Create actions.
1189 void OCCViewer_ViewWindow::createActions()
1191 if( !toolMgr()->isEmpty() )
1194 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1201 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1202 tr( "MNU_DUMP_VIEW" ), 0, this);
1203 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1204 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1205 toolMgr()->registerAction( aAction, DumpId );
1208 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1209 tr( "MNU_FITALL" ), 0, this);
1210 aAction->setStatusTip(tr("DSC_FITALL"));
1211 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1212 toolMgr()->registerAction( aAction, FitAllId );
1215 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1216 tr( "MNU_FITRECT" ), 0, this);
1217 aAction->setStatusTip(tr("DSC_FITRECT"));
1218 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1219 toolMgr()->registerAction( aAction, FitRectId );
1222 aAction = new QtxAction(tr("MNU_FITSELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITSELECTION" ) ),
1223 tr( "MNU_FITSELECTION" ), 0, this);
1224 aAction->setStatusTip(tr("DSC_FITSELECTION"));
1225 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
1226 toolMgr()->registerAction( aAction, FitSelectionId );
1229 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1230 tr( "MNU_ZOOM_VIEW" ), 0, this);
1231 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1232 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1233 toolMgr()->registerAction( aAction, ZoomId );
1236 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1237 tr( "MNU_PAN_VIEW" ), 0, this);
1238 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1239 connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
1240 toolMgr()->registerAction( aAction, PanId );
1243 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1244 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1245 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1246 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1247 toolMgr()->registerAction( aAction, GlobalPanId );
1250 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1251 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1252 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1253 mySetRotationPointAction->setCheckable( true );
1254 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1255 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1258 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1259 tr( "MNU_ROTATE_VIEW" ), 0, this);
1260 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1261 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1262 toolMgr()->registerAction( aAction, RotationId );
1265 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1266 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1267 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1268 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1269 this->addAction(aAction);
1270 toolMgr()->registerAction( aAction, FrontId );
1272 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1273 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1274 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1275 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1276 this->addAction(aAction);
1277 toolMgr()->registerAction( aAction, BackId );
1279 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1280 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1281 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1282 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1283 this->addAction(aAction);
1284 toolMgr()->registerAction( aAction, TopId );
1286 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1287 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1288 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1289 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1290 this->addAction(aAction);
1291 toolMgr()->registerAction( aAction, BottomId );
1293 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1294 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1295 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1296 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1297 this->addAction(aAction);
1298 toolMgr()->registerAction( aAction, LeftId );
1300 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1301 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1302 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1303 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1304 this->addAction(aAction);
1305 toolMgr()->registerAction( aAction, RightId );
1307 // rotate anticlockwise
1308 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1309 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1310 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1311 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1312 this->addAction(aAction);
1313 toolMgr()->registerAction( aAction, AntiClockWiseId );
1316 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1317 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1318 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1319 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1320 this->addAction(aAction);
1321 toolMgr()->registerAction( aAction, ClockWiseId );
1323 // Projection mode group
1325 // - orthographic projection
1326 aAction = new QtxAction(tr("MNU_ORTHOGRAPHIC_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ORTHOGRAPHIC" ) ),
1327 tr( "MNU_ORTHOGRAPHIC_MODE" ), 0, this);
1328 aAction->setStatusTip(tr("DSC_ORTHOGRAPHIC_MODE"));
1329 aAction->setCheckable(true);
1330 toolMgr()->registerAction( aAction, OrthographicId );
1332 // - perspective projection
1333 aAction = new QtxAction(tr("MNU_PERSPECTIVE_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PERSPECTIVE" ) ),
1334 tr( "MNU_PERSPECTIVE_MODE" ), 0, this);
1335 aAction->setStatusTip(tr("DSC_PERSPECTIVE_MODE"));
1336 aAction->setCheckable(true);
1337 toolMgr()->registerAction( aAction, PerspectiveId );
1338 #if OCC_VERSION_LARGE > 0x06090000
1339 // - stereo projection
1340 aAction = new QtxAction(tr("MNU_STEREO_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STEREO" ) ),
1341 tr( "MNU_STEREO_MODE" ), 0, this);
1342 aAction->setStatusTip(tr("DSC_STEREO_MODE"));
1343 aAction->setCheckable(true);
1344 toolMgr()->registerAction( aAction, StereoId );
1345 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onStereoType(bool)));
1347 // - add exclusive action group
1348 QActionGroup* aProjectionGroup = new QActionGroup( this );
1349 aProjectionGroup->addAction( toolMgr()->action( OrthographicId ) );
1350 aProjectionGroup->addAction( toolMgr()->action( PerspectiveId ) );
1351 connect(aProjectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProjectionType(QAction*)));
1354 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1355 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1356 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1357 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1358 this->addAction(aAction);
1359 toolMgr()->registerAction( aAction, ResetId );
1362 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1363 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1364 tr("MNU_CLONE_VIEW"), 0, this);
1365 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1366 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1367 toolMgr()->registerAction( aAction, CloneId );
1369 aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
1370 tr("MNU_CLIPPING"), 0, this);
1371 aAction->setStatusTip (tr("DSC_CLIPPING"));
1372 aAction->setCheckable (true);
1373 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1374 toolMgr()->registerAction (aAction, ClippingId);
1376 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1377 tr( "MNU_SHOOT_VIEW" ), 0, this);
1378 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1379 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1380 toolMgr()->registerAction( aAction, MemId );
1382 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1383 tr( "MNU_PRESETS_VIEW" ), 0, this);
1384 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1385 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1386 toolMgr()->registerAction( aAction, RestoreId );
1388 if (myModel->trihedronActivated()) {
1389 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1390 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1391 aAction->setCheckable( true );
1392 aAction->setChecked( true );
1393 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1394 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1395 toolMgr()->registerAction( aAction, TrihedronShowId );
1399 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1400 tr( "MNU_SCALING" ), 0, this);
1401 aAction->setStatusTip(tr("DSC_SCALING"));
1402 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1403 toolMgr()->registerAction( aAction, AxialScaleId );
1405 // Enable/disable preselection
1406 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1407 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1408 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1409 aAction->setCheckable(true);
1410 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1411 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1413 // Enable/disable selection
1414 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1415 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1416 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1417 aAction->setCheckable(true);
1418 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1419 toolMgr()->registerAction( aAction, SwitchSelectionId );
1422 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1423 tr( "MNU_GRADUATED_AXES" ), 0, this);
1424 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1425 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1426 toolMgr()->registerAction( aAction, GraduatedAxesId );
1428 // Active only ambient light or not
1429 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1430 tr( "MNU_AMBIENT" ), 0, this);
1431 aAction->setStatusTip(tr("DSC_AMBIENT"));
1432 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1433 toolMgr()->registerAction( aAction, AmbientId );
1435 // Switch between interaction styles
1436 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1437 tr( "MNU_STYLE_SWITCH" ), 0, this);
1438 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1439 aAction->setCheckable(true);
1440 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1441 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1443 // Switch between zooming styles
1444 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1445 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1446 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1447 aAction->setCheckable(true);
1448 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1449 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1452 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1453 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1454 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1455 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1456 toolMgr()->registerAction( aAction, MaximizedId );
1458 // Return to 3d view
1459 if (my2dMode!=No2dMode){
1460 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1461 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1462 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1463 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1464 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1468 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1469 #ifdef ENABLE_RAY_TRACING
1471 aAction = new QtxAction( tr("MNU_RAY_TRACING"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_RAY_TRACING") ),
1472 tr("MNU_RAY_TRACING"), 0, this );
1473 aAction->setStatusTip( tr("DSC_RAY_TRACING") );
1474 connect( aAction, SIGNAL( triggered() ), this, SLOT( onRayTracing() ) );
1475 toolMgr()->registerAction( aAction, RayTracingId );
1477 // Environment texture
1478 aAction = new QtxAction( tr("MNU_ENV_TEXTURE"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_ENV_TEXTURE") ),
1479 tr("MNU_ENV_TEXTURE"), 0, this );
1480 aAction->setStatusTip( tr("DSC_ENV_TEXTURE") );
1481 connect( aAction, SIGNAL( triggered() ), this, SLOT( onEnvTexture() ) );
1482 toolMgr()->registerAction( aAction, EnvTextureId );
1485 aAction = new QtxAction( tr("MNU_LIGHT_SOURCE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_LIGHT_SOURCE" ) ),
1486 tr( "MNU_LIGHT_SOURCE" ), 0, this );
1487 aAction->setStatusTip( tr("DSC_LIGHT_SOURCE") );
1488 connect( aAction, SIGNAL( triggered() ), this, SLOT( onLightSource() ) );
1489 toolMgr()->registerAction( aAction, LightSourceId );
1494 \brief Create toolbar.
1496 void OCCViewer_ViewWindow::createToolBar()
1498 static const char* titles[] = {
1499 "LBL_3DTOOLBAR_LABEL",
1500 "LBL_XYTOOLBAR_LABEL",
1501 "LBL_XZTOOLBAR_LABEL",
1502 "LBL_YZTOOLBAR_LABEL",
1504 static const char* names[] = {
1505 "OCCViewer3DViewOperations",
1506 "OCCViewerXYViewOperations",
1507 "OCCViewerXZViewOperations",
1508 "OCCViewerYZViewOperations",
1510 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1511 QString( names[my2dMode] ), // name (language-independant)
1512 false ); // disable floatable toolbar
1513 if ( my2dMode != No2dMode ){
1514 toolMgr()->append( ReturnTo3dViewId, tid );
1515 toolMgr()->append( toolMgr()->separator(), tid );
1517 toolMgr()->append( DumpId, tid );
1518 toolMgr()->append( SwitchInteractionStyleId, tid );
1519 toolMgr()->append( SwitchZoomingStyleId, tid );
1520 toolMgr()->append( SwitchPreselectionId, tid );
1521 toolMgr()->append( SwitchSelectionId, tid );
1522 if( myModel->trihedronActivated() )
1523 toolMgr()->append( TrihedronShowId, tid );
1525 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1526 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1527 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1528 #if OCC_VERSION_LARGE > 0x06090000
1529 aScaleAction->insertAction( toolMgr()->action( FitSelectionId ) );
1531 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1532 toolMgr()->append( aScaleAction, tid );
1534 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1535 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1536 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1537 toolMgr()->append( aPanningAction, tid );
1539 if (my2dMode == No2dMode) {
1540 toolMgr()->append( ChangeRotationPointId, tid );
1541 toolMgr()->append( RotationId, tid );
1543 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1544 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1545 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1546 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1547 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1548 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1549 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1550 toolMgr()->append( aViewsAction, tid );
1552 toolMgr()->append( AntiClockWiseId, tid );
1553 toolMgr()->append( ClockWiseId, tid );
1555 toolMgr()->append( OrthographicId, tid );
1556 toolMgr()->append( PerspectiveId, tid );
1557 #if OCC_VERSION_LARGE > 0x06090000
1558 toolMgr()->append( StereoId, tid );
1561 toolMgr()->append( ResetId, tid );
1564 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1565 aMemAction->insertAction( toolMgr()->action( MemId ) );
1566 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1567 toolMgr()->append( aMemAction, tid );
1569 toolMgr()->append( toolMgr()->separator(), tid );
1570 toolMgr()->append( CloneId, tid );
1572 toolMgr()->append( toolMgr()->separator(), tid );
1573 toolMgr()->append( ClippingId, tid );
1574 toolMgr()->append( AxialScaleId, tid );
1575 toolMgr()->append( GraduatedAxesId, tid );
1576 toolMgr()->append( AmbientId, tid );
1578 toolMgr()->append( MaximizedId, tid );
1579 toolMgr()->append( SynchronizeId, tid );
1580 #ifdef ENABLE_RAY_TRACING
1581 toolMgr()->append( RayTracingId, tid );
1582 toolMgr()->append( EnvTextureId, tid );
1583 toolMgr()->append( LightSourceId, tid );
1588 \brief Perform 'fit all' operation.
1590 void OCCViewer_ViewWindow::onViewFitAll()
1592 myViewPort->fitAll();
1596 \brief Perform "front view" transformation.
1598 void OCCViewer_ViewWindow::onFrontView()
1600 emit vpTransformationStarted ( FRONTVIEW );
1601 Handle(V3d_View) aView3d = myViewPort->getView();
1602 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
1604 emit vpTransformationFinished ( FRONTVIEW );
1608 \brief Perform "back view" transformation.
1610 void OCCViewer_ViewWindow::onBackView()
1612 emit vpTransformationStarted ( BACKVIEW );
1613 Handle(V3d_View) aView3d = myViewPort->getView();
1614 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
1616 emit vpTransformationFinished ( BACKVIEW );
1620 \brief Perform "top view" transformation.
1622 void OCCViewer_ViewWindow::onTopView()
1624 emit vpTransformationStarted ( TOPVIEW );
1625 Handle(V3d_View) aView3d = myViewPort->getView();
1626 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
1628 emit vpTransformationFinished ( TOPVIEW );
1632 \brief Perform "bottom view" transformation.
1634 void OCCViewer_ViewWindow::onBottomView()
1636 emit vpTransformationStarted ( BOTTOMVIEW );
1637 Handle(V3d_View) aView3d = myViewPort->getView();
1638 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
1640 emit vpTransformationFinished ( BOTTOMVIEW );
1644 \brief Perform "left view" transformation.
1646 void OCCViewer_ViewWindow::onLeftView()
1648 emit vpTransformationStarted ( LEFTVIEW );
1649 Handle(V3d_View) aView3d = myViewPort->getView();
1650 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
1652 emit vpTransformationFinished ( LEFTVIEW );
1656 \brief Perform "right view" transformation.
1658 void OCCViewer_ViewWindow::onRightView()
1660 emit vpTransformationStarted ( RIGHTVIEW );
1661 Handle(V3d_View) aView3d = myViewPort->getView();
1662 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
1664 emit vpTransformationFinished ( RIGHTVIEW );
1668 \brief Rotate view 90 degrees clockwise
1670 void OCCViewer_ViewWindow::onClockWiseView()
1672 emit vpTransformationStarted ( CLOCKWISEVIEW );
1673 myViewPort->rotateXY( 90. );
1674 emit vpTransformationFinished ( CLOCKWISEVIEW );
1678 \brief Rotate view 90 degrees conterclockwise
1680 void OCCViewer_ViewWindow::onAntiClockWiseView()
1682 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1683 myViewPort->rotateXY( -90. );
1684 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1688 \brief Perform "reset view" transformation.
1690 Sets default orientation of the viewport camera.
1692 void OCCViewer_ViewWindow::onResetView()
1694 emit vpTransformationStarted( RESETVIEW );
1695 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1696 myViewPort->getView()->Reset( false );
1697 myViewPort->fitAll( false, true, false );
1698 myViewPort->getView()->SetImmediateUpdate( upd );
1699 onProjectionType(); // needed to apply projection type properly after reset
1700 myViewPort->getView()->Update();
1701 emit vpTransformationFinished( RESETVIEW );
1705 \brief Set the given projection mode.
1707 Set the given projection mode: Orthographic or Perspective.
1709 void OCCViewer_ViewWindow::onProjectionType( QAction* theAction )
1711 Handle(V3d_View) aView3d = myViewPort->getView();
1712 if ( !aView3d.IsNull() ) {
1713 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1714 if (theAction == toolMgr()->action( OrthographicId )) {
1715 myModel->setProjectionType(Orthographic);
1716 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Orthographic );
1717 aCamera->SetFOVy(45.0);
1719 else if (theAction == toolMgr()->action( PerspectiveId )) {
1720 myModel->setProjectionType(Perspective);
1721 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Perspective );
1722 aCamera->SetFOVy(30.0);
1724 #if OCC_VERSION_LARGE > 0x06090000
1725 if (toolMgr()->action( StereoId )->isChecked()) {
1726 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1727 aCamera->SetFOVy(30.0);
1736 \brief Sets Stereo projection mode.
1738 Sets Stereo projection mode.
1740 void OCCViewer_ViewWindow::onStereoType( bool activate )
1742 #if OCC_VERSION_LARGE > 0x06090000
1743 Handle(V3d_View) aView3d = myViewPort->getView();
1744 if ( !aView3d.IsNull() ) {
1745 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1747 toolMgr()->action( PerspectiveId )->setChecked(true);
1748 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1749 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(false);
1751 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1752 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1753 setStereoType( aResMgr->integerValue( "OCCViewer", "stereo_type", 0 ) );
1754 setAnaglyphFilter( aResMgr->integerValue( "OCCViewer", "anaglyph_filter", 0 ) );
1755 setReverseStereo( aResMgr->booleanValue( "OCCViewer", "reverse_stereo", false ) );
1756 setVSync( aResMgr->booleanValue( "OCCViewer", "enable_vsync", true ) );
1757 setQuadBufferSupport( aResMgr->booleanValue( "OCCViewer", "enable_quad_buffer_support", false ) );
1760 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(true);
1761 if (myModel->projectionType() == Orthographic) {
1762 toolMgr()->action( OrthographicId )->setChecked(true);
1763 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Orthographic);
1765 else if (myModel->projectionType() == Perspective) {
1766 toolMgr()->action( PerspectiveId )->setChecked(true);
1767 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1774 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1775 toolMgr()->action( StereoId )->isChecked() )
1776 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1781 \brief Restore the view.
1783 Restore the projection mode based on tool-buttons states.
1785 void OCCViewer_ViewWindow::onProjectionType()
1787 emit vpTransformationStarted( PROJECTION );
1788 if (toolMgr()->action( OrthographicId )->isChecked())
1789 setProjectionType( Orthographic );
1790 if (toolMgr()->action( PerspectiveId )->isChecked())
1791 setProjectionType( Perspective );
1792 #if OCC_VERSION_LARGE > 0x06090000
1793 if (toolMgr()->action( StereoId )->isChecked())
1794 setProjectionType( Stereo );
1796 emit vpTransformationFinished( PROJECTION );
1799 void OCCViewer_ViewWindow::setProjectionType( int mode )
1801 QtxAction* anOrthographicAction = dynamic_cast<QtxAction*>( toolMgr()->action( OrthographicId ) );
1802 QtxAction* aPerspectiveAction = dynamic_cast<QtxAction*>( toolMgr()->action( PerspectiveId ) );
1803 #if OCC_VERSION_LARGE > 0x06090000
1804 QtxAction* aStereoAction = dynamic_cast<QtxAction*>( toolMgr()->action( StereoId ) );
1808 onProjectionType( anOrthographicAction );
1811 onProjectionType( aPerspectiveAction );
1814 onStereoType( true );
1817 // update action state if method is called outside
1818 if ( mode == Orthographic && !anOrthographicAction->isChecked() ) {
1819 anOrthographicAction->setChecked( true );
1820 #if OCC_VERSION_LARGE > 0x06090000
1821 aStereoAction->setChecked( false );
1824 if ( mode == Perspective && !aPerspectiveAction->isChecked() ) {
1825 aPerspectiveAction->setChecked( true );
1826 #if OCC_VERSION_LARGE > 0x06090000
1827 aStereoAction->setChecked( false );
1830 #if OCC_VERSION_LARGE > 0x06090000
1831 if ( mode == Stereo ) {
1832 aStereoAction->setChecked( true );
1833 if ( anOrthographicAction->isEnabled() ) {
1834 anOrthographicAction->setEnabled( false );
1835 anOrthographicAction->setChecked( false );
1836 aStereoAction->setChecked( false );
1839 anOrthographicAction->setEnabled( true );
1840 aStereoAction->setChecked( false );
1841 anOrthographicAction->setChecked(myModel->projectionType() == Orthographic);
1843 if ( aPerspectiveAction->isEnabled() ) {
1844 aPerspectiveAction->setEnabled( false );
1845 aPerspectiveAction->setChecked( true );
1846 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1847 toolMgr()->action( StereoId )->isChecked() )
1848 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1851 aPerspectiveAction->setEnabled( true );
1852 aStereoAction->setChecked( false );
1853 aPerspectiveAction->setChecked(myModel->projectionType() == Perspective);
1858 if ( !anOrthographicAction->isEnabled() )
1859 anOrthographicAction->setEnabled( true );
1860 if ( !aPerspectiveAction->isEnabled() )
1861 aPerspectiveAction->setEnabled( true );
1867 \brief Perform "fit all" transformation.
1869 void OCCViewer_ViewWindow::onFitAll()
1871 emit vpTransformationStarted( FITALLVIEW );
1872 myViewPort->fitAll();
1873 emit vpTransformationFinished( FITALLVIEW );
1877 \brief Perform "fit selection" transformation.
1879 void OCCViewer_ViewWindow::onFitSelection()
1881 emit vpTransformationStarted( FITSELECTION );
1882 #if OCC_VERSION_LARGE > 0x06090000
1883 myModel->getAISContext()->FitSelected( getViewPort()->getView() );
1885 emit vpTransformationFinished( FITSELECTION );
1889 \brief Called if 'change rotation point' operation is activated.
1890 \param on action state
1892 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1896 if (!mySetRotationPointDlg)
1898 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1899 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1902 if (!mySetRotationPointDlg->isVisible())
1904 //if (mySetRotationPointDlg->IsFirstShown())
1905 if (myCurrPointType == BBCENTER)
1907 Standard_Real Xcenter, Ycenter, Zcenter;
1908 if (OCCViewer_Utilities::computeVisibleBBCenter(myViewPort->getView(), Xcenter, Ycenter, Zcenter))
1909 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1911 mySetRotationPointDlg->show();
1916 if (mySetRotationPointDlg->isVisible())
1917 mySetRotationPointDlg->hide();
1922 \brief Create one more window with same content.
1924 void OCCViewer_ViewWindow::onCloneView()
1926 SUIT_ViewWindow* vw = myManager->createViewWindow();
1928 emit viewCloned( vw );
1929 OCCViewer_ViewWindow* occVw = dynamic_cast<OCCViewer_ViewWindow*> (vw);
1930 if(occVw && occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)) {
1931 occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)->synchronize(this);
1936 Creates one more window with same content
1938 void OCCViewer_ViewWindow::onAxialScale()
1940 if ( !myScalingDlg )
1941 myScalingDlg = new OCCViewer_AxialScaleDlg( this , myModel );
1943 if ( !myScalingDlg->isVisible() )
1945 myScalingDlg->Update();
1946 myScalingDlg->show();
1951 Shows Graduated Axes dialog
1953 void OCCViewer_ViewWindow::onGraduatedAxes()
1955 myCubeAxesDlg->Update();
1956 myCubeAxesDlg->show();
1959 void OCCViewer_ViewWindow::onAmbientToogle()
1961 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
1962 viewer->InitDefinedLights();
1963 while(viewer->MoreDefinedLights())
1965 Handle(V3d_Light) light = viewer->DefinedLight();
1966 if(light->Type() != V3d_AMBIENT)
1968 Handle(V3d_View) aView3d = myViewPort->getView();
1969 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
1970 else viewer->SetLightOn(light);
1972 viewer->NextDefinedLights();
1978 \brief Store view parameters.
1980 void OCCViewer_ViewWindow::onMemorizeView()
1982 appendViewAspect( getViewParams() );
1986 \brief Restore view parameters.
1988 void OCCViewer_ViewWindow::onRestoreView()
1990 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
1991 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
1993 updateViewAspects( aDlg->parameters() );
1994 if( myRestoreFlag && aDlg->parameters().count() )
1995 performRestoring( aDlg->currentItem() );
1999 \brief Restore view parameters.
2000 \param anItem view parameters
2002 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
2004 Handle(V3d_View) aView3d = myViewPort->getView();
2006 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
2007 aView3d->SetScale( anItem.scale );
2008 aView3d->SetTwist( anItem.twist );
2009 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
2010 aView3d->SetImmediateUpdate( prev );
2011 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2012 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2013 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
2015 #if OCC_VERSION_LARGE > 0x06070100
2016 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
2018 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
2020 // "eye" and "at" require conversion to represent center panning
2021 // up direction is only available after setting angle of twist and
2022 // other view parameters
2023 aView3d->Up( anUpX, anUpY, anUpZ );
2025 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
2026 gp_Dir anUp( anUpX, anUpY, anUpZ );
2027 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
2028 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2029 gp_Dir aSide = aProj ^ anUp;
2031 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
2032 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
2034 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
2035 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2038 aView3d->SetCenter( anItem.centerX, anItem.centerY );
2041 if ( !baseParamsOnly ) {
2043 myModel->setTrihedronShown( anItem.isVisible );
2044 myModel->setTrihedronSize( anItem.size );
2046 // graduated trihedron
2047 bool anIsVisible = anItem.gtIsVisible;
2048 OCCViewer_AxisWidget::AxisData anAxisData[3];
2049 anAxisData[0].DrawName = anItem.gtDrawNameX;
2050 anAxisData[1].DrawName = anItem.gtDrawNameZ;
2051 anAxisData[2].DrawName = anItem.gtDrawNameZ;
2052 anAxisData[0].Name = anItem.gtNameX;
2053 anAxisData[1].Name = anItem.gtNameZ;
2054 anAxisData[2].Name = anItem.gtNameZ;
2055 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
2056 anItem.gtNameColorGX,
2057 anItem.gtNameColorBX );
2058 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
2059 anItem.gtNameColorGY,
2060 anItem.gtNameColorBY );
2061 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
2062 anItem.gtNameColorGZ,
2063 anItem.gtNameColorBZ );
2064 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
2065 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
2066 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
2067 anAxisData[0].NbValues = anItem.gtNbValuesX;
2068 anAxisData[1].NbValues = anItem.gtNbValuesY;
2069 anAxisData[2].NbValues = anItem.gtNbValuesZ;
2070 anAxisData[0].Offset = anItem.gtOffsetX;
2071 anAxisData[1].Offset = anItem.gtOffsetY;
2072 anAxisData[2].Offset = anItem.gtOffsetZ;
2073 anAxisData[0].Color = QColor( anItem.gtColorRX,
2076 anAxisData[1].Color = QColor( anItem.gtColorRY,
2079 anAxisData[2].Color = QColor( anItem.gtColorRZ,
2082 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
2083 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
2084 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
2085 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
2086 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
2087 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
2089 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
2090 myCubeAxesDlg->ApplyData( aView3d );
2092 } // if ( !baseParamsOnly )
2098 \brief Set restore flag.
2100 void OCCViewer_ViewWindow::setRestoreFlag()
2106 \brief Called when action "show/hide trihedron" is activated.
2108 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
2110 myModel->setTrihedronShown(show);
2114 \brief Toggles preselection (highlighting) on/off
2116 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
2118 myPreselectionEnabled = on;
2119 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
2121 // unhighlight all highlighted objects
2123 myModel->unHighlightAll( true, false );
2126 // update action state if method is called outside
2127 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2128 if ( a && a->isChecked() != on ) {
2129 a->setChecked( on );
2134 \brief Toggles selection on/off
2136 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
2138 mySelectionEnabled = on;
2139 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
2141 // update action state if method is called outside
2144 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2146 a->setEnabled( on );
2150 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
2151 if ( a && a->isChecked() != on ) {
2152 a->setChecked( on );
2157 \brief Switches "keyboard free" interaction style on/off
2159 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
2161 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
2163 // update action state if method is called outside
2164 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
2165 if ( a && a->isChecked() != on )
2166 a->setChecked( on );
2170 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
2172 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
2174 myViewPort->setAdvancedZoomingEnabled( on );
2176 // update action state if method is called outside
2177 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
2178 if ( a && a->isChecked() != on )
2179 a->setChecked( on );
2183 \brief Get current interaction style
2184 \return interaction style
2186 int OCCViewer_ViewWindow::interactionStyle() const
2188 return myInteractionStyle;
2192 \brief Set current interaction style
2193 \param theStyle interaction style
2195 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
2197 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
2201 \brief Get current zooming style
2202 \return zooming style
2204 int OCCViewer_ViewWindow::zoomingStyle() const
2206 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
2210 \brief Set current zooming style
2211 \param theStyle zooming style
2213 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
2215 onSwitchZoomingStyle( theStyle == 1 );
2219 \brief Dump view window contents to the pixmap.
2220 \return pixmap containing all scene rendered in the window
2222 //#define USE_OLD_IMPLEMENTATION
2223 QImage OCCViewer_ViewWindow::dumpView()
2225 Handle(V3d_View) view = myViewPort->getView();
2226 if ( view.IsNull() )
2229 int aWidth = myViewPort->width();
2230 int aHeight = myViewPort->height();
2232 #ifdef USE_OLD_IMPLEMENTATION
2233 // rnv: Old approach to dump the OCCViewer content via Frame Buffer Object
2237 #ifndef DISABLE_GLVIEWER
2238 OpenGLUtils_FrameBuffer aFrameBuffer;
2239 if ( aFrameBuffer.init( aWidth, aHeight ) )
2241 glPushAttrib( GL_VIEWPORT_BIT );
2242 glViewport( 0, 0, aWidth, aHeight );
2243 aFrameBuffer.bind();
2248 aFrameBuffer.unbind();
2251 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
2253 aFrameBuffer.bind();
2254 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
2255 aFrameBuffer.unbind();
2257 anImage = anImage.rgbSwapped();
2258 anImage = anImage.mirrored();
2262 // if frame buffers are unsupported, use old approach
2264 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
2265 QPoint p = myViewPort->mapFromParent( myViewPort->geometry().topLeft() );
2266 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
2268 QImage anImage( data, aWidth, aHeight, QImage::Format_ARGB32 );
2269 anImage = anImage.mirrored();
2270 anImage = anImage.rgbSwapped();
2273 #else // DISABLE_GLVIEWER
2277 #endif // DISABLE_GLVIEWER
2279 #else // USE_OLD_IMPLEMENTATION
2280 // rnv: New approach is to use OCCT built-in procedure
2283 view->ToPixMap(aPix, aWidth, aHeight, Graphic3d_BT_RGB);
2285 QImage anImage( aWidth, aHeight, QImage::Format_ARGB32 );
2286 for ( int i = 0; i < aWidth; i++ ) {
2287 for ( int j = 0; j < aHeight; j++ ) {
2288 #if OCC_VERSION_LARGE > 0x07010001
2289 Quantity_Color pixel = aPix.PixelColor( i, j ).GetRGB();
2291 Quantity_Color pixel = aPix.PixelColor( i, j );
2293 QColor color = QColor::fromRgbF( pixel.Red(), pixel.Green(), pixel.Blue() );
2294 anImage.setPixelColor( i, j, color );
2298 if ( aPix.IsTopDown() )
2299 anImage = anImage.mirrored();
2302 #endif // USE_OLD_IMPLEMENTATION
2305 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
2306 const QString& fileName,
2307 const QString& format )
2310 QApplication::setOverrideCursor( Qt::WaitCursor );
2311 if ( format != "PS" && format != "EPS")
2312 res = myViewPort->getView()->Dump( fileName.toStdString().c_str() );
2314 #if OCC_VERSION_MAJOR < 7
2315 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
2317 Handle(Graphic3d_CView) a3dView = myViewPort->getView()->View();
2321 res = a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
2322 else if (format == "EPS")
2323 res = a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
2325 QApplication::restoreOverrideCursor();
2330 QString OCCViewer_ViewWindow::filter() const
2332 return tr( "OCC_IMAGE_FILES" );
2337 \brief Set parameters of the cutting plane
2338 \param on if \c true, cutting plane is enabled
2339 \param x X position of plane point
2340 \param y Y position of plane point
2341 \param z Z position of plane point
2342 \param dx X coordinate of plane normal
2343 \param dy Y coordinate of plane normal
2344 \param dz Z coordinate of plane normal
2346 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2347 const double dx, const double dy, const double dz )
2349 Handle(V3d_View) view = myViewPort->getView();
2350 if ( view.IsNull() )
2354 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2356 // try to use already existing plane or create a new one
2357 Handle(V3d_Plane) clipPlane;
2359 // calculate new a,b,c,d values for the plane
2360 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2362 pln.Coefficients(a, b, c, d);
2363 #if OCC_VERSION_LARGE > 0x07000000
2364 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2365 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2366 if(aPlanes->Size() > 0 ) {
2368 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2369 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2370 if(aPlanes.Size() > 0 ) {
2372 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2373 aClipPlane->SetEquation(pln);
2374 aClipPlane->SetOn(Standard_True);
2376 view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2380 #if OCC_VERSION_LARGE > 0x07000000
2381 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2382 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2384 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2385 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2387 for( ;anIter.More();anIter.Next() ){
2388 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2389 aClipPlane->SetOn(Standard_False);
2397 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2399 gp_Dir aDir = pln.Axis().Direction();
2400 gp_Pnt aPnt = pln.Location();
2401 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2406 \brief Check if any cutting plane is enabled
2407 \return \c true if at least one cutting plane is enabled
2409 bool OCCViewer_ViewWindow::isCuttingPlane()
2411 Handle(V3d_View) view = myViewPort->getView();
2413 #if OCC_VERSION_LARGE > 0x07000000
2414 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2415 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2417 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2418 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2420 for( ;anIter.More();anIter.Next() ) {
2421 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2422 if(aClipPlane->IsOn()) {
2431 \brief Get the visual parameters of the view window.
2432 \return visual parameters of view window
2434 viewAspect OCCViewer_ViewWindow::getViewParams() const
2436 double projX, projY, projZ, twist;
2437 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2438 double aScaleX, aScaleY, aScaleZ;
2440 Handle(V3d_View) aView3d = myViewPort->getView();
2442 aView3d->Proj( projX, projY, projZ );
2443 aView3d->At( atX, atY, atZ );
2444 aView3d->Eye( eyeX, eyeY, eyeZ );
2445 twist = aView3d->Twist();
2447 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2449 bool isShown = myModel->isTrihedronVisible();
2450 double size = myModel->trihedronSize();
2452 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2455 params.scale = aView3d->Scale();
2456 params.projX = projX;
2457 params.projY = projY;
2458 params.projZ = projZ;
2459 params.twist = twist;
2466 params.scaleX = aScaleX;
2467 params.scaleY = aScaleY;
2468 params.scaleZ = aScaleZ;
2469 params.name = aName;
2470 params.isVisible= isShown;
2473 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2474 aView3d->Center( params.centerX, params.centerY );
2477 // graduated trihedron
2478 bool anIsVisible = false;
2479 OCCViewer_AxisWidget::AxisData anAxisData[3];
2480 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2482 params.gtIsVisible = anIsVisible;
2483 params.gtDrawNameX = anAxisData[0].DrawName;
2484 params.gtDrawNameY = anAxisData[1].DrawName;
2485 params.gtDrawNameZ = anAxisData[2].DrawName;
2486 params.gtNameX = anAxisData[0].Name;
2487 params.gtNameY = anAxisData[1].Name;
2488 params.gtNameZ = anAxisData[2].Name;
2489 params.gtNameColorRX = anAxisData[0].NameColor.red();
2490 params.gtNameColorGX = anAxisData[0].NameColor.green();
2491 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2492 params.gtNameColorRY = anAxisData[1].NameColor.red();
2493 params.gtNameColorGY = anAxisData[1].NameColor.green();
2494 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2495 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2496 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2497 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2498 params.gtDrawValuesX = anAxisData[0].DrawValues;
2499 params.gtDrawValuesY = anAxisData[1].DrawValues;
2500 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2501 params.gtNbValuesX = anAxisData[0].NbValues;
2502 params.gtNbValuesY = anAxisData[1].NbValues;
2503 params.gtNbValuesZ = anAxisData[2].NbValues;
2504 params.gtOffsetX = anAxisData[0].Offset;
2505 params.gtOffsetY = anAxisData[1].Offset;
2506 params.gtOffsetZ = anAxisData[2].Offset;
2507 params.gtColorRX = anAxisData[0].Color.red();
2508 params.gtColorGX = anAxisData[0].Color.green();
2509 params.gtColorBX = anAxisData[0].Color.blue();
2510 params.gtColorRY = anAxisData[1].Color.red();
2511 params.gtColorGY = anAxisData[1].Color.green();
2512 params.gtColorBY = anAxisData[1].Color.blue();
2513 params.gtColorRZ = anAxisData[2].Color.red();
2514 params.gtColorGZ = anAxisData[2].Color.green();
2515 params.gtColorBZ = anAxisData[2].Color.blue();
2516 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2517 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2518 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2519 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2520 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2521 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2527 \brief Get visual parameters of this view window.
2528 \return visual parameters of view window
2530 QString OCCViewer_ViewWindow::getVisualParameters()
2532 viewAspect params = getViewParams();
2536 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2537 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2538 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
2539 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
2541 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2542 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2543 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2544 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2545 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2546 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2547 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2548 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2549 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2550 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2551 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2552 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2553 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2554 data << QString( "isVisible=%1" ).arg( params.isVisible );
2555 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2557 ClipPlanesList aPlanes = myModel->getClipPlanes();
2558 for ( int i=0; i < aPlanes.size(); i++ )
2560 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2561 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2562 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2563 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2564 switch ( aPlane.Mode )
2566 case OCCViewer_ClipPlane::Absolute :
2568 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2570 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2572 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2573 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2574 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2578 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2583 case OCCViewer_ClipPlane::Relative :
2585 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2586 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2587 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2592 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2593 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2594 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2595 data << ClippingPlane;
2598 // graduated trihedron
2599 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2600 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2601 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2602 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2603 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2604 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2605 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2606 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2607 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2608 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2609 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2610 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2611 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2612 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2613 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2614 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2615 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2616 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2617 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2618 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2619 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2620 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2621 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2622 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2623 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2624 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2625 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2626 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2627 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2628 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2629 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2630 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2631 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2632 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2633 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2634 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2635 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2636 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2637 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2638 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2640 // ray tracing parameters
2641 Graphic3d_RenderingParams rendParams = this->getViewPort()->getView()->RenderingParams();
2642 if ( rendParams.Method == Graphic3d_RM_RAYTRACING ) {
2643 QString RayTracing = "rayTracing=";
2644 RayTracing += QString( "rtDepth~%1;" ).arg( rendParams.RaytracingDepth );
2645 RayTracing += QString( "rtReflection~%1;" ).arg( rendParams.IsReflectionEnabled );
2646 RayTracing += QString( "rtAntialiasing~%1;" ).arg( rendParams.IsAntialiasingEnabled );
2647 RayTracing += QString( "rtShadow~%1;" ).arg( rendParams.IsShadowEnabled );
2648 RayTracing += QString( "rtTransShadow~%1;" ).arg( rendParams.IsTransparentShadowEnabled );
2652 // environment texture parameters
2653 Handle(Graphic3d_TextureEnv) aTexture = this->getViewPort()->getView()->TextureEnv();
2654 if ( !aTexture.IsNull() ) {
2655 QString EnvTexture = "envTexture=";
2656 if ( aTexture->Name() == Graphic3d_NOT_ENV_UNKNOWN ) {
2657 TCollection_AsciiString aFileName;
2658 aTexture->Path().SystemName( aFileName );
2659 EnvTexture += QString( "etFile~%1;" ).arg( aFileName.ToCString() );
2662 EnvTexture += QString( "etNumber~%1;" ).arg( aTexture->Name() );
2666 // light source parameters
2667 myModel->getViewer3d()->InitDefinedLights();
2668 while ( myModel->getViewer3d()->MoreDefinedLights() )
2670 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2671 if ( aLight->Type() != V3d_AMBIENT ) {
2672 QString LightSource = QString( "lightSource=" );
2673 LightSource += QString( "lightType~%1;" ).arg( aLight->Type() );
2675 if ( aLight->Type() == V3d_DIRECTIONAL )
2676 Handle(V3d_DirectionalLight)::DownCast( aLight )->Direction( aX, aY, aZ );
2677 else if ( aLight->Type() == V3d_POSITIONAL )
2678 Handle(V3d_PositionalLight)::DownCast( aLight )->Position( aX, aY, aZ );
2679 LightSource += QString( "lightX~%1;" ).arg( aX );
2680 LightSource += QString( "lightY~%1;" ).arg( aY );
2681 LightSource += QString( "lightZ~%1;" ).arg( aZ );
2682 LightSource += QString( "lightColorR~%1;" ).arg( aLight->Color().Red() );
2683 LightSource += QString( "lightColorG~%1;" ).arg( aLight->Color().Green() );
2684 LightSource += QString( "lightColorB~%1;" ).arg( aLight->Color().Blue() );
2685 LightSource += QString( "lightHeadlight~%1;" ).arg( aLight->Headlight() );
2686 data << LightSource;
2688 myModel->getViewer3d()->NextDefinedLights();
2691 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2692 data << QString( "background=%1" ).arg( bg );
2694 return data.join("*");
2698 \brief Restore visual parameters of the view window.
2699 \param parameters visual parameters of view window
2701 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2704 ClipPlanesList aClipPlanes;
2705 QStringList data = parameters.split( '*' );
2706 Qtx::BackgroundData bgData;
2707 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2709 foreach( QString param, data ) {
2710 QString paramName = param.section( '=', 0, 0 ).trimmed();
2711 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2712 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2713 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2714 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2715 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2716 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2717 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2718 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2719 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2720 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2721 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2722 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2723 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2724 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2725 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2726 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2727 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2728 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2729 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2730 else if ( paramName.contains( "ClippingPlane" ) )
2732 QStringList ClipPlaneData = paramValue.split( ';' );
2733 OCCViewer_ClipPlane aPlane;
2734 foreach( QString ClipPlaneParam, ClipPlaneData )
2736 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2737 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2738 if ( ClipPlane_paramName == "Mode" )
2740 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2742 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2743 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2744 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2745 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2748 switch ( aPlane.Mode )
2750 case OCCViewer_ClipPlane::Absolute :
2751 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2752 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2753 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2754 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2755 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2758 case OCCViewer_ClipPlane::Relative :
2759 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2760 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2761 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2766 aClipPlanes.push_back(aPlane);
2768 // graduated trihedron
2769 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2770 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2771 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2772 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2773 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2774 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2775 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2776 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2777 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2778 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2779 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2780 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2781 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2782 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2783 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2784 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2785 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2786 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2787 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2788 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2789 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2790 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2791 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2792 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2793 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2794 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2795 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2796 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2797 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2798 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2799 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2800 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2801 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2802 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2803 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2804 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2805 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2806 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2807 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2808 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2809 else if ( paramName == "rayTracing" )
2811 Graphic3d_RenderingParams& rendParams = this->getViewPort()->getView()->ChangeRenderingParams();
2812 rendParams.Method = Graphic3d_RM_RAYTRACING;
2813 QStringList rtData = paramValue.split( ';' );
2814 foreach( QString rtParam, rtData )
2816 QString rt_paramName = rtParam.section( '~', 0, 0 ).trimmed();
2817 QString rt_paramValue = rtParam.section( '~', 1, 1 ).trimmed();
2818 if ( rt_paramName == "rtDepth" ) rendParams.RaytracingDepth = rt_paramValue.toInt();
2819 else if ( rt_paramName == "rtReflection" ) rendParams.IsReflectionEnabled = rt_paramValue.toInt();
2820 else if ( rt_paramName == "rtAntialiasing" ) rendParams.IsAntialiasingEnabled = rt_paramValue.toInt();
2821 else if ( rt_paramName == "rtShadow" ) rendParams.IsShadowEnabled = rt_paramValue.toInt();
2822 else if ( rt_paramName == "rtTransShadow" ) rendParams.IsTransparentShadowEnabled = rt_paramValue.toInt();
2825 else if ( paramName == "envTexture" )
2827 Handle(Graphic3d_TextureEnv) aTexture;
2828 QStringList etData = paramValue.split( ';' );
2829 foreach( QString etParam, etData )
2831 QString et_paramName = etParam.section( '~', 0, 0 ).trimmed();
2832 QString et_paramValue = etParam.section( '~', 1, 1 ).trimmed();
2833 if ( et_paramName == "etNumber" )
2834 aTexture = new Graphic3d_TextureEnv( Graphic3d_NameOfTextureEnv( et_paramValue.toInt() ) );
2835 else if ( et_paramName == "etFile" )
2836 aTexture = new Graphic3d_TextureEnv( TCollection_AsciiString( et_paramValue.toStdString().c_str() ) );
2837 Handle(V3d_View) aView = this->getViewPort()->getView();
2838 aView->SetTextureEnv( aTexture );
2839 #if OCC_VERSION_LARGE <= 0x07000000
2840 aView->SetSurfaceDetail( V3d_TEX_ENVIRONMENT );
2844 else if ( paramName == "lightSource" )
2846 myModel->getViewer3d()->InitDefinedLights();
2847 while ( myModel->getViewer3d()->MoreDefinedLights() )
2849 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2850 if( aLight->Type() != V3d_AMBIENT ) {
2851 myModel->getViewer3d()->DelLight( aLight );
2852 myModel->getViewer3d()->InitDefinedLights();
2854 myModel->getViewer3d()->NextDefinedLights();
2859 V3d_TypeOfLight aType;
2861 QStringList lsData = paramValue.split( ';' );
2862 foreach( QString lsParam, lsData )
2864 QString ls_paramName = lsParam.section( '~', 0, 0 ).trimmed();
2865 QString ls_paramValue = lsParam.section( '~', 1, 1 ).trimmed();
2866 if ( ls_paramName == "lightType" ) aType = V3d_TypeOfLight( ls_paramValue.toInt() );
2867 else if ( ls_paramName == "lightX" ) aX = ls_paramValue.toDouble();
2868 else if ( ls_paramName == "lightY" ) aY = ls_paramValue.toDouble();
2869 else if ( ls_paramName == "lightZ" ) aZ = ls_paramValue.toDouble();
2870 else if ( ls_paramName == "lightColorR" ) cR = ls_paramValue.toDouble();
2871 else if ( ls_paramName == "lightColorG" ) cG = ls_paramValue.toDouble();
2872 else if ( ls_paramName == "lightColorB" ) cB = ls_paramValue.toDouble();
2873 else if ( ls_paramName == "lightHeadlight" ) isHeadlight = ls_paramValue.toInt();
2875 Quantity_Color aColor = Quantity_Color( cR, cG, cB, Quantity_TOC_RGB );
2876 if( aType == V3d_DIRECTIONAL ) {
2877 Handle(V3d_DirectionalLight) aLight = new V3d_DirectionalLight( myModel->getViewer3d() );
2878 aLight->SetDirection( aX, aY, aZ );
2879 aLight->SetColor( aColor );
2880 aLight->SetHeadlight( isHeadlight );
2881 myModel->getViewer3d()->SetLightOn( aLight );
2883 else if( aType == V3d_POSITIONAL ) {
2884 Handle(V3d_PositionalLight) aLight = new V3d_PositionalLight( myModel->getViewer3d(), aX, aY, aZ, aColor.Name() );
2885 aLight->SetHeadlight( isHeadlight );
2886 myModel->getViewer3d()->SetLightOn( aLight );
2889 else if ( paramName == "background" ) {
2890 QString bg = paramValue.replace( "$", "=" );
2891 bgData = Qtx::stringToBackground( bg );
2895 else // old format - "1.000e+00*0.000e+00..."
2898 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2899 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2900 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2901 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2902 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2903 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2904 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
2905 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2906 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2907 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
2908 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2909 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2910 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2911 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
2912 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
2913 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
2914 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
2915 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
2917 performRestoring( params );
2918 setBackground( bgData );
2919 myModel->setClipPlanes(aClipPlanes);
2923 \brief Handle show event.
2925 Emits Show() signal.
2927 \param theEvent show event
2929 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2931 emit Show( theEvent );
2935 \brief Handle hide event.
2937 Emits Hide() signal.
2939 \param theEvent hide event
2941 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
2943 emit Hide( theEvent );
2948 Save old cursor. [ protected ]
2950 void OCCViewer_ViewWindow::saveCursor()
2952 QCursor* aCursor = NULL;
2954 aCursor = myViewPort->getDefaultCursor();
2955 myCursor = ( aCursor ? *aCursor : cursor() );
2960 Creates default sketcher. [ virtual protected ]
2962 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
2965 return new OCCViewer_RectSketcher( this, type );
2966 if ( type == Polygon )
2967 return new OCCViewer_PolygonSketcher( this, type );
2971 void OCCViewer_ViewWindow::initSketchers()
2973 if ( mySketchers.isEmpty() )
2975 mySketchers.append( createSketcher( Rect ) );
2976 mySketchers.append( createSketcher( Polygon ) );
2980 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
2982 OCCViewer_ViewSketcher* sketcher = 0;
2983 QList<OCCViewer_ViewSketcher*>::Iterator it;
2984 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
2986 OCCViewer_ViewSketcher* sk = (*it);
2987 if ( sk->type() == typ )
2994 Handles requests for sketching in the active view. [ virtual public ]
2996 void OCCViewer_ViewWindow::activateSketching( int type )
2998 OCCViewer_ViewPort3d* vp = getViewPort();
3002 if ( !vp->isSketchingEnabled() )
3005 /* Finish current sketching */
3006 if ( type == NoSketching )
3010 onSketchingFinished();
3011 mypSketcher->deactivate();
3015 /* Activate new sketching */
3018 activateSketching( NoSketching ); /* concurrency not suported */
3019 mypSketcher = getSketcher( type );
3022 mypSketcher->activate();
3023 onSketchingStarted();
3029 Unhilights detected entities. [ virtual protected ]
3031 void OCCViewer_ViewWindow::onSketchingStarted()
3036 Selection by rectangle or polygon. [ virtual protected ]
3038 void OCCViewer_ViewWindow::onSketchingFinished()
3040 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
3041 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
3043 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
3044 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
3045 switch( mypSketcher->type() )
3049 QRect* aRect = (QRect*)mypSketcher->data();
3052 int aLeft = aRect->left();
3053 int aRight = aRect->right();
3054 int aTop = aRect->top();
3055 int aBottom = aRect->bottom();
3059 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
3061 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
3067 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
3070 int size = aPolygon->size();
3071 TColgp_Array1OfPnt2d anArray( 1, size );
3073 QPolygon::Iterator it = aPolygon->begin();
3074 QPolygon::Iterator itEnd = aPolygon->end();
3075 for( int index = 1; it != itEnd; ++it, index++ )
3077 QPoint aPoint = *it;
3078 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
3082 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
3084 ic->Select( anArray, getViewPort()->getView(), Standard_False );
3092 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
3093 aViewMgr->getOCCViewer()->performSelectionChanged();
3097 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
3102 bool OCCViewer_ViewWindow::transformRequested() const
3104 return ( myOperation != NOTHING );
3107 bool OCCViewer_ViewWindow::transformInProcess() const
3109 return myEventStarted;
3112 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
3114 myEventStarted = bOn;
3118 Set enabled state of transformation (rotate, zoom, etc)
3120 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
3122 if ( id != NOTHING ) myStatus.insert( id, on );
3126 \return enabled state of transformation (rotate, zoom, etc)
3128 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
3130 return myStatus.contains( id ) ? myStatus[ id ] : true;
3133 void OCCViewer_ViewWindow::onMaximizedView()
3135 setMaximized(!isMaximized());
3138 void OCCViewer_ViewWindow::returnTo3dView()
3140 setReturnedTo3dView( true );
3143 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
3145 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
3146 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
3147 if ( !isVisible3dView )
3148 toolMgr()->show( ReturnTo3dViewId );
3150 toolMgr()->hide( ReturnTo3dViewId );
3151 if ( isVisible3dView ) emit returnedTo3d( );
3155 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
3157 QAction* anAction = toolMgr()->action( MaximizedId );
3158 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
3159 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
3161 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
3162 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
3163 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
3164 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
3165 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
3167 emit maximized( this, true );
3171 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
3172 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
3173 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
3174 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
3175 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
3177 emit maximized( this, false );
3182 bool OCCViewer_ViewWindow::isMaximized() const
3184 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
3187 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
3189 IsSketcherStyle = enable;
3192 bool OCCViewer_ViewWindow::isSketcherStyle() const
3194 return IsSketcherStyle;
3198 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
3203 int OCCViewer_ViewWindow::projectionType() const
3205 int mode = Orthographic;
3206 Handle(V3d_View) aView3d = myViewPort->getView();
3207 if ( !aView3d.IsNull() ) {
3208 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3209 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Perspective)
3211 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Orthographic)
3212 mode = Orthographic;
3213 #if OCC_VERSION_LARGE > 0x06090000
3214 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
3221 void OCCViewer_ViewWindow::setStereoType( int type )
3223 Handle(V3d_View) aView3d = myViewPort->getView();
3224 if ( !aView3d.IsNull() ) {
3225 #if OCC_VERSION_LARGE > 0x06090000
3226 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3227 aParams->StereoMode = (Graphic3d_StereoMode)type;
3232 int OCCViewer_ViewWindow::stereoType() const
3234 int type = QuadBuffer;
3235 Handle(V3d_View) aView3d = myViewPort->getView();
3236 if ( !aView3d.IsNull() ) {
3237 #if OCC_VERSION_LARGE > 0x06090000
3238 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3239 type = (OCCViewer_ViewWindow::StereoType)aParams->StereoMode;
3245 void OCCViewer_ViewWindow::setAnaglyphFilter( int type )
3247 Handle(V3d_View) aView3d = myViewPort->getView();
3248 if ( !aView3d.IsNull() ) {
3249 #if OCC_VERSION_LARGE > 0x06090000
3250 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3251 if (type == RedCyan)
3252 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
3253 if (type == YellowBlue)
3254 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
3255 if (type == GreenMagenta)
3256 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
3261 int OCCViewer_ViewWindow::anaglyphFilter() const
3264 Handle(V3d_View) aView3d = myViewPort->getView();
3265 if ( !aView3d.IsNull() ) {
3266 #if OCC_VERSION_LARGE > 0x06090000
3267 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3268 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized)
3270 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized)
3272 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple)
3273 type = GreenMagenta;
3279 void OCCViewer_ViewWindow::setStereographicFocus( int type, double value )
3281 Handle(V3d_View) aView3d = myViewPort->getView();
3282 if ( !aView3d.IsNull() ) {
3283 #if OCC_VERSION_LARGE > 0x06090000
3284 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3285 aCamera->SetZFocus( (Graphic3d_Camera::FocusType) type, value );
3290 int OCCViewer_ViewWindow::stereographicFocusType() const
3292 int type = Relative;
3293 Handle(V3d_View) aView3d = myViewPort->getView();
3294 if ( !aView3d.IsNull() ) {
3295 #if OCC_VERSION_LARGE > 0x06090000
3296 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3297 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->ZFocusType();
3303 double OCCViewer_ViewWindow::stereographicFocusValue() const
3306 Handle(V3d_View) aView3d = myViewPort->getView();
3307 if ( !aView3d.IsNull() ) {
3308 #if OCC_VERSION_LARGE > 0x06090000
3309 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3310 value = aCamera->ZFocus();
3316 void OCCViewer_ViewWindow::setInterocularDistance( int type, double value )
3318 Handle(V3d_View) aView3d = myViewPort->getView();
3319 if ( !aView3d.IsNull() ) {
3320 #if OCC_VERSION_LARGE > 0x06090000
3321 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3322 aCamera->SetIOD( (Graphic3d_Camera::IODType) type, value );
3327 int OCCViewer_ViewWindow::interocularDistanceType() const
3329 int type = Relative;
3330 Handle(V3d_View) aView3d = myViewPort->getView();
3331 if ( !aView3d.IsNull() ) {
3332 #if OCC_VERSION_LARGE > 0x06090000
3333 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3334 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->GetIODType();
3340 double OCCViewer_ViewWindow::interocularDistanceValue() const
3342 double value = 0.05;
3343 Handle(V3d_View) aView3d = myViewPort->getView();
3344 if ( !aView3d.IsNull() ) {
3345 #if OCC_VERSION_LARGE > 0x06090000
3346 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3347 value = aCamera->IOD();
3353 void OCCViewer_ViewWindow::setReverseStereo( bool reverse )
3355 Handle(V3d_View) aView3d = myViewPort->getView();
3356 if ( !aView3d.IsNull() ) {
3357 #if OCC_VERSION_LARGE > 0x06090000
3358 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3359 aParams->ToReverseStereo = reverse;
3364 bool OCCViewer_ViewWindow::isReverseStereo() const
3366 int reverse = false;
3367 Handle(V3d_View) aView3d = myViewPort->getView();
3368 if ( !aView3d.IsNull() ) {
3369 #if OCC_VERSION_LARGE > 0x06090000
3370 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3371 reverse = aParams->ToReverseStereo;
3377 void OCCViewer_ViewWindow::setVSync( bool enable )
3379 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3380 if ( !anIntCont.IsNull() ) {
3381 #if OCC_VERSION_LARGE > 0x06090000
3382 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3383 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3384 aCaps->swapInterval = enable;
3389 bool OCCViewer_ViewWindow::isVSync() const
3392 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3393 if ( !anIntCont.IsNull() ) {
3394 #if OCC_VERSION_LARGE > 0x06090000
3395 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3396 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3397 enable = aCaps->swapInterval;
3403 void OCCViewer_ViewWindow::setQuadBufferSupport( bool enable )
3405 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3406 if ( !anIntCont.IsNull() ) {
3407 #if OCC_VERSION_LARGE > 0x06090000
3408 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3409 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3410 aCaps->contextStereo = enable;
3415 bool OCCViewer_ViewWindow::isQuadBufferSupport() const
3418 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3419 if ( !anIntCont.IsNull() ) {
3420 #if OCC_VERSION_LARGE > 0x06090000
3421 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3422 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3423 enable = aCaps->contextStereo;
3430 bool OCCViewer_ViewWindow::isOpenGlStereoSupport() const
3432 GLboolean support[1];
3433 glGetBooleanv (GL_STEREO, support);
3440 QColor OCCViewer_ViewWindow::backgroundColor() const
3442 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
3446 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
3448 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
3451 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
3453 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
3456 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
3458 if ( myViewPort ) myViewPort->setBackground( theBackground );
3461 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
3463 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
3469 void OCCViewer_ViewWindow::clearViewAspects()
3471 myViewAspects.clear();
3475 \return const reference to list of view aspects
3477 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
3479 return myViewAspects;
3483 Appends new view aspect
3484 \param aParams - new view aspects
3486 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
3488 myViewAspects.append( aParams );
3492 Replaces old view aspects by new ones
3493 \param aViewList - list of new view aspects
3495 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
3497 myViewAspects = aViewList;
3501 Get camera properties for the OCC view window.
3502 \return shared pointer on camera properties.
3504 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
3506 SUIT_CameraProperties aProps;
3508 Handle(V3d_View) aSourceView = getViewPort()->getView();
3509 if ( aSourceView.IsNull() )
3512 if ( get2dMode() == No2dMode ) {
3513 aProps.setDimension( SUIT_CameraProperties::Dim3D );
3516 aProps.setDimension( SUIT_CameraProperties::Dim2D );
3517 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
3520 // read common properites of the view
3521 Standard_Real anUp[3];
3522 Standard_Real anAt[3];
3523 Standard_Real anEye[3];
3524 Standard_Real aProj[3];
3525 Standard_Real anAxialScale[3];
3527 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
3528 aSourceView->At( anAt[0], anAt[1], anAt[2] );
3529 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
3530 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3532 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3533 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
3535 #if OCC_VERSION_LARGE > 0x06070100
3536 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
3538 // store camera properties "as is": it is up to synchronized
3539 // view classes to provide necessary property conversion.
3540 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
3541 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
3543 if ( aSourceView->Camera()->IsOrthographic() )
3545 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
3546 aProps.setViewAngle( 0.0 );
3550 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
3551 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
3553 aProps.setMappingScale( aSourceView->Camera()->Scale() );
3555 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
3557 // generate view orientation matrix for transforming OCC projection reference point
3558 // into a camera (eye) position.
3559 gp_Dir aLeftDir = gp_Dir( anUp[0], anUp[1], anUp[2] ) ^ gp_Dir( aProj[0], aProj[1], aProj[2] );
3562 aTrsf.SetValue( 1, 1, aLeftDir.X() );
3563 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
3564 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
3566 aTrsf.SetValue( 1, 2, anUp[0] );
3567 aTrsf.SetValue( 2, 2, anUp[1] );
3568 aTrsf.SetValue( 3, 2, anUp[2] );
3570 aTrsf.SetValue( 1, 3, aProj[0] );
3571 aTrsf.SetValue( 2, 3, aProj[1] );
3572 aTrsf.SetValue( 3, 3, aProj[2] );
3574 aTrsf.SetValue( 1, 4, anAt[0] );
3575 aTrsf.SetValue( 2, 4, anAt[1] );
3576 aTrsf.SetValue( 3, 4, anAt[2] );
3578 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
3580 // transform to world-space coordinate system
3581 gp_XYZ aPosition( aProjRef.X(), aProjRef.Y(), aCameraDepth );
3582 aTrsf.Transforms( aPosition );
3584 // compute focal point
3585 double aFocalPoint[3];
3587 aFocalPoint[0] = aPosition.X() - aProj[0] * aCameraDepth;
3588 aFocalPoint[1] = aPosition.Y() - aProj[1] * aCameraDepth;
3589 aFocalPoint[2] = aPosition.Z() - aProj[2] * aCameraDepth;
3591 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3592 aProps.setPosition( aPosition.X(), aPosition.Y(), aPosition.Z() );
3594 Standard_Real aViewScale[2];
3595 aSourceView->Size( aViewScale[0], aViewScale[1] );
3596 aProps.setMappingScale( aViewScale[1] );
3604 This implementation synchronizes OCC view's camera propreties.
3606 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
3608 bool blocked = blockSignals( true );
3610 SUIT_CameraProperties aProps = theView->cameraProperties();
3611 if ( !cameraProperties().isCompatible( aProps ) ) {
3612 // other view, this one is being currently synchronized to, seems has become incompatible
3613 // we have to break synchronization
3618 Handle(V3d_View) aDestView = getViewPort()->getView();
3620 aDestView->SetImmediateUpdate( Standard_False );
3623 double aPosition[3];
3624 double aFocalPoint[3];
3625 double anAxialScale[3];
3627 // get common properties
3628 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3629 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
3630 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3631 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3633 #if OCC_VERSION_LARGE > 0x06070100
3634 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3635 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
3636 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3637 aDestView->Camera()->SetScale( aProps.getMappingScale() );
3639 gp_Dir aProjDir( aPosition[0] - aFocalPoint[0],
3640 aPosition[1] - aFocalPoint[1],
3641 aPosition[2] - aFocalPoint[2] );
3643 // get custom view translation
3644 Standard_Real aTranslation[3];
3645 aDestView->At( aTranslation[0], aTranslation[1], aTranslation[2] );
3647 gp_Dir aLeftDir = gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] )
3648 ^ gp_Dir( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
3651 aTrsf.SetValue( 1, 1, aLeftDir.X() );
3652 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
3653 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
3655 aTrsf.SetValue( 1, 2, anUpDir[0] );
3656 aTrsf.SetValue( 2, 2, anUpDir[1] );
3657 aTrsf.SetValue( 3, 2, anUpDir[2] );
3659 aTrsf.SetValue( 1, 3, aProjDir.X() );
3660 aTrsf.SetValue( 2, 3, aProjDir.Y() );
3661 aTrsf.SetValue( 3, 3, aProjDir.Z() );
3663 aTrsf.SetValue( 1, 4, aTranslation[0] );
3664 aTrsf.SetValue( 2, 4, aTranslation[1] );
3665 aTrsf.SetValue( 3, 4, aTranslation[2] );
3668 // transform to view-space coordinate system
3669 gp_XYZ aProjRef( aPosition[0], aPosition[1], aPosition[2] );
3670 aTrsf.Transforms( aProjRef );
3672 // set view camera properties using low-level approach. this is done
3673 // in order to avoid interference with static variables in v3d view used
3674 // when rotation is in process in another view.
3675 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
3676 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
3678 Graphic3d_Vector aMappingProj( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
3679 Graphic3d_Vector aMappingUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3681 aMappingProj.Normalize();
3682 aMappingUp.Normalize();
3684 anOrientation.SetViewReferencePlane( aMappingProj );
3685 anOrientation.SetViewReferenceUp( aMappingUp );
3687 aDestView->SetViewMapping( aMapping );
3688 aDestView->SetViewOrientation( anOrientation );
3691 aDestView->SetCenter( aProjRef.X(), aProjRef.Y() );
3693 // set mapping scale
3694 double aMapScaling = aProps.getMappingScale();
3695 Standard_Real aWidth, aHeight;
3696 aDestView->Size( aWidth, aHeight );
3697 aDestView->SetSize ( aWidth > aHeight ? aMapScaling * (aWidth / aHeight) : aMapScaling );
3700 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3701 #if OCC_VERSION_LARGE <= 0x07000000
3702 aDestView->ZFitAll();
3704 aDestView->SetImmediateUpdate( Standard_True );
3705 aDestView->Redraw();
3707 blockSignals( blocked );
3711 \brief Indicates whether preselection is enabled
3712 \return true if preselection is enabled
3714 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
3716 return myPreselectionEnabled;
3720 \brief Enables/disables preselection
3721 \param theIsToEnable if true - preselection will be enabled
3723 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
3725 onSwitchPreselection( theIsToEnable );
3729 \brief Indicates whether selection is enabled
3730 \return true if selection is enabled
3732 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3734 return mySelectionEnabled;
3738 \brief Enables/disables selection
3739 \param theIsToEnable if true - selection will be enabled
3741 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3743 onSwitchSelection( theIsToEnable );
3748 \brief called if clipping operation is activated / deactivated.
3750 Enables/disables clipping plane displaying.
3752 \parma on action state
3754 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3756 if(!myModel) return;
3757 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3760 if (!aClippingDlg) {
3761 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3762 myModel->setClippingDlg(aClippingDlg);
3764 if (!aClippingDlg->isVisible())
3765 aClippingDlg->show();
3767 if ( aClippingDlg ) {
3768 aClippingDlg->close();
3769 myModel->setClippingDlg(0);
3773 SUIT_ViewManager* mgr = getViewManager();
3775 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3776 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3777 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3778 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3780 QAction* a = toolMgr()->action( ClippingId );
3782 if(theIsOn != a->isChecked()){
3783 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3784 a->setChecked(theIsOn);
3785 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3792 void OCCViewer_ViewWindow::onRayTracing()
3794 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_RayTracingDlg::getName() ) ) {
3795 QDialog* aDlg = new OCCViewer_RayTracingDlg( this );
3801 void OCCViewer_ViewWindow::onEnvTexture()
3803 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_EnvTextureDlg::getName() ) ) {
3804 QDialog* aDlg = new OCCViewer_EnvTextureDlg( this );
3810 void OCCViewer_ViewWindow::onLightSource()
3812 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_LightSourceDlg::getName() ) ) {
3813 QDialog* aDlg = new OCCViewer_LightSourceDlg( this, myModel );