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() && ic->HasOpenedContext() ) {
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();
1073 OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( getViewManager() );
1074 bool isChained = aMgr->isChainedOperations();
1075 bool isReset = !( myOperation==PANVIEW && isChained ) || theEvent->button() == Qt::RightButton;
1082 if ( theEvent->button() == Qt::LeftButton ) {
1083 myViewPort->setCenter( theEvent->x(), theEvent->y() );
1084 myViewPort->getView()->SetScale(myCurScale);
1090 if ( theEvent->button() == Qt::LeftButton ) {
1091 myCurrX = theEvent->x();
1092 myCurrY = theEvent->y();
1094 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1095 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1102 // NOTE: viewer 3D detects a rectangle of selection using this event
1103 // so we must emit it BEFORE resetting the selection rectangle
1105 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1109 myViewPort->update();
1112 if ( l_mbPressEvent )
1114 delete l_mbPressEvent;
1120 \brief Reset the viewport to its initial state
1121 ( no transformations in process etc. )
1123 void OCCViewer_ViewWindow::resetState()
1127 if ( myRotationPointSelection )
1129 QCursor handCursor (Qt::PointingHandCursor);
1130 myViewPort->setCursor( handCursor );
1134 if ( transformRequested() || myCursorIsHand )
1135 myViewPort->setCursor( myCursor );
1136 myCursorIsHand = false;
1139 if ( transformRequested() )
1140 emit vpTransformationFinished (myOperation);
1142 setTransformInProcess( false );
1143 setTransformRequested( NOTHING );
1148 \brief Draw rubber band rectangle.
1150 void OCCViewer_ViewWindow::drawRect()
1152 if ( !myRectBand ) {
1153 myRectBand = new QtxRectRubberBand( myViewPort );
1155 //palette.setColor(myRectBand->foregroundRole(), Qt::white);
1156 //myRectBand->setPalette(palette);
1158 //myRectBand->hide();
1160 myRectBand->setUpdatesEnabled ( false );
1161 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1162 myRectBand->initGeometry( aRect );
1164 if ( !myRectBand->isVisible() )
1167 myRectBand->setUpdatesEnabled ( true );
1168 //myRectBand->repaint();
1170 //myRectBand->setVisible( aRect.isValid() );
1171 //if ( myRectBand->isVisible() )
1172 // myRectBand->repaint();
1174 // myRectBand->show();
1175 //myRectBand->repaint();
1179 \brief Clear rubber band rectangle on the end on the dragging operation.
1181 void OCCViewer_ViewWindow::endDrawRect()
1183 //delete myRectBand;
1187 myRectBand->clearGeometry();
1193 \brief Create actions.
1195 void OCCViewer_ViewWindow::createActions()
1197 if( !toolMgr()->isEmpty() )
1200 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1207 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1208 tr( "MNU_DUMP_VIEW" ), 0, this);
1209 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1210 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1211 toolMgr()->registerAction( aAction, DumpId );
1214 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1215 tr( "MNU_FITALL" ), 0, this);
1216 aAction->setStatusTip(tr("DSC_FITALL"));
1217 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1218 toolMgr()->registerAction( aAction, FitAllId );
1221 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1222 tr( "MNU_FITRECT" ), 0, this);
1223 aAction->setStatusTip(tr("DSC_FITRECT"));
1224 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1225 toolMgr()->registerAction( aAction, FitRectId );
1228 aAction = new QtxAction(tr("MNU_FITSELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITSELECTION" ) ),
1229 tr( "MNU_FITSELECTION" ), 0, this);
1230 aAction->setStatusTip(tr("DSC_FITSELECTION"));
1231 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
1232 toolMgr()->registerAction( aAction, FitSelectionId );
1235 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1236 tr( "MNU_ZOOM_VIEW" ), 0, this);
1237 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1238 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1239 toolMgr()->registerAction( aAction, ZoomId );
1242 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1243 tr( "MNU_PAN_VIEW" ), 0, this);
1244 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1245 connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
1246 toolMgr()->registerAction( aAction, PanId );
1249 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1250 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1251 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1252 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1253 toolMgr()->registerAction( aAction, GlobalPanId );
1256 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1257 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1258 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1259 mySetRotationPointAction->setCheckable( true );
1260 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1261 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1264 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1265 tr( "MNU_ROTATE_VIEW" ), 0, this);
1266 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1267 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1268 toolMgr()->registerAction( aAction, RotationId );
1271 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1272 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1273 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1274 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1275 this->addAction(aAction);
1276 toolMgr()->registerAction( aAction, FrontId );
1278 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1279 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1280 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1281 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1282 this->addAction(aAction);
1283 toolMgr()->registerAction( aAction, BackId );
1285 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1286 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1287 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1288 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1289 this->addAction(aAction);
1290 toolMgr()->registerAction( aAction, TopId );
1292 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1293 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1294 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1295 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1296 this->addAction(aAction);
1297 toolMgr()->registerAction( aAction, BottomId );
1299 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1300 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1301 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1302 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1303 this->addAction(aAction);
1304 toolMgr()->registerAction( aAction, LeftId );
1306 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1307 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1308 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1309 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1310 this->addAction(aAction);
1311 toolMgr()->registerAction( aAction, RightId );
1313 // rotate anticlockwise
1314 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1315 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1316 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1317 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1318 this->addAction(aAction);
1319 toolMgr()->registerAction( aAction, AntiClockWiseId );
1322 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1323 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1324 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1325 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1326 this->addAction(aAction);
1327 toolMgr()->registerAction( aAction, ClockWiseId );
1329 // Projection mode group
1331 // - orthographic projection
1332 aAction = new QtxAction(tr("MNU_ORTHOGRAPHIC_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ORTHOGRAPHIC" ) ),
1333 tr( "MNU_ORTHOGRAPHIC_MODE" ), 0, this);
1334 aAction->setStatusTip(tr("DSC_ORTHOGRAPHIC_MODE"));
1335 aAction->setCheckable(true);
1336 toolMgr()->registerAction( aAction, OrthographicId );
1338 // - perspective projection
1339 aAction = new QtxAction(tr("MNU_PERSPECTIVE_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PERSPECTIVE" ) ),
1340 tr( "MNU_PERSPECTIVE_MODE" ), 0, this);
1341 aAction->setStatusTip(tr("DSC_PERSPECTIVE_MODE"));
1342 aAction->setCheckable(true);
1343 toolMgr()->registerAction( aAction, PerspectiveId );
1344 #if OCC_VERSION_LARGE > 0x06090000
1345 // - stereo projection
1346 aAction = new QtxAction(tr("MNU_STEREO_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STEREO" ) ),
1347 tr( "MNU_STEREO_MODE" ), 0, this);
1348 aAction->setStatusTip(tr("DSC_STEREO_MODE"));
1349 aAction->setCheckable(true);
1350 toolMgr()->registerAction( aAction, StereoId );
1351 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onStereoType(bool)));
1353 // - add exclusive action group
1354 QActionGroup* aProjectionGroup = new QActionGroup( this );
1355 aProjectionGroup->addAction( toolMgr()->action( OrthographicId ) );
1356 aProjectionGroup->addAction( toolMgr()->action( PerspectiveId ) );
1357 connect(aProjectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProjectionType(QAction*)));
1360 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1361 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1362 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1363 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1364 this->addAction(aAction);
1365 toolMgr()->registerAction( aAction, ResetId );
1368 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1369 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1370 tr("MNU_CLONE_VIEW"), 0, this);
1371 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1372 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1373 toolMgr()->registerAction( aAction, CloneId );
1375 aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
1376 tr("MNU_CLIPPING"), 0, this);
1377 aAction->setStatusTip (tr("DSC_CLIPPING"));
1378 aAction->setCheckable (true);
1379 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1380 toolMgr()->registerAction (aAction, ClippingId);
1382 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1383 tr( "MNU_SHOOT_VIEW" ), 0, this);
1384 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1385 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1386 toolMgr()->registerAction( aAction, MemId );
1388 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1389 tr( "MNU_PRESETS_VIEW" ), 0, this);
1390 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1391 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1392 toolMgr()->registerAction( aAction, RestoreId );
1394 if (myModel->trihedronActivated()) {
1395 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1396 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1397 aAction->setCheckable( true );
1398 aAction->setChecked( true );
1399 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1400 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1401 toolMgr()->registerAction( aAction, TrihedronShowId );
1405 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1406 tr( "MNU_SCALING" ), 0, this);
1407 aAction->setStatusTip(tr("DSC_SCALING"));
1408 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1409 toolMgr()->registerAction( aAction, AxialScaleId );
1411 // Enable/disable preselection
1412 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1413 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1414 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1415 aAction->setCheckable(true);
1416 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1417 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1419 // Enable/disable selection
1420 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1421 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1422 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1423 aAction->setCheckable(true);
1424 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1425 toolMgr()->registerAction( aAction, SwitchSelectionId );
1428 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1429 tr( "MNU_GRADUATED_AXES" ), 0, this);
1430 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1431 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1432 toolMgr()->registerAction( aAction, GraduatedAxesId );
1434 // Active only ambient light or not
1435 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1436 tr( "MNU_AMBIENT" ), 0, this);
1437 aAction->setStatusTip(tr("DSC_AMBIENT"));
1438 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1439 toolMgr()->registerAction( aAction, AmbientId );
1441 // Switch between interaction styles
1442 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1443 tr( "MNU_STYLE_SWITCH" ), 0, this);
1444 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1445 aAction->setCheckable(true);
1446 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1447 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1449 // Switch between zooming styles
1450 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1451 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1452 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1453 aAction->setCheckable(true);
1454 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1455 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1458 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1459 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1460 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1461 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1462 toolMgr()->registerAction( aAction, MaximizedId );
1464 // Return to 3d view
1465 if (my2dMode!=No2dMode){
1466 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1467 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1468 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1469 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1470 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1474 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1475 #ifdef ENABLE_RAY_TRACING
1477 aAction = new QtxAction( tr("MNU_RAY_TRACING"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_RAY_TRACING") ),
1478 tr("MNU_RAY_TRACING"), 0, this );
1479 aAction->setStatusTip( tr("DSC_RAY_TRACING") );
1480 connect( aAction, SIGNAL( triggered() ), this, SLOT( onRayTracing() ) );
1481 toolMgr()->registerAction( aAction, RayTracingId );
1483 // Environment texture
1484 aAction = new QtxAction( tr("MNU_ENV_TEXTURE"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_ENV_TEXTURE") ),
1485 tr("MNU_ENV_TEXTURE"), 0, this );
1486 aAction->setStatusTip( tr("DSC_ENV_TEXTURE") );
1487 connect( aAction, SIGNAL( triggered() ), this, SLOT( onEnvTexture() ) );
1488 toolMgr()->registerAction( aAction, EnvTextureId );
1491 aAction = new QtxAction( tr("MNU_LIGHT_SOURCE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_LIGHT_SOURCE" ) ),
1492 tr( "MNU_LIGHT_SOURCE" ), 0, this );
1493 aAction->setStatusTip( tr("DSC_LIGHT_SOURCE") );
1494 connect( aAction, SIGNAL( triggered() ), this, SLOT( onLightSource() ) );
1495 toolMgr()->registerAction( aAction, LightSourceId );
1500 \brief Create toolbar.
1502 void OCCViewer_ViewWindow::createToolBar()
1504 static const char* titles[] = {
1505 "LBL_3DTOOLBAR_LABEL",
1506 "LBL_XYTOOLBAR_LABEL",
1507 "LBL_XZTOOLBAR_LABEL",
1508 "LBL_YZTOOLBAR_LABEL",
1510 static const char* names[] = {
1511 "OCCViewer3DViewOperations",
1512 "OCCViewerXYViewOperations",
1513 "OCCViewerXZViewOperations",
1514 "OCCViewerYZViewOperations",
1516 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1517 QString( names[my2dMode] ), // name (language-independant)
1518 false ); // disable floatable toolbar
1519 if ( my2dMode != No2dMode ){
1520 toolMgr()->append( ReturnTo3dViewId, tid );
1521 toolMgr()->append( toolMgr()->separator(), tid );
1523 toolMgr()->append( DumpId, tid );
1524 toolMgr()->append( SwitchInteractionStyleId, tid );
1525 toolMgr()->append( SwitchZoomingStyleId, tid );
1526 toolMgr()->append( SwitchPreselectionId, tid );
1527 toolMgr()->append( SwitchSelectionId, tid );
1528 if( myModel->trihedronActivated() )
1529 toolMgr()->append( TrihedronShowId, tid );
1531 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1532 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1533 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1534 #if OCC_VERSION_LARGE > 0x06090000
1535 aScaleAction->insertAction( toolMgr()->action( FitSelectionId ) );
1537 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1538 toolMgr()->append( aScaleAction, tid );
1540 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1541 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1542 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1543 toolMgr()->append( aPanningAction, tid );
1545 if (my2dMode == No2dMode) {
1546 toolMgr()->append( ChangeRotationPointId, tid );
1547 toolMgr()->append( RotationId, tid );
1549 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1550 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1551 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1552 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1553 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1554 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1555 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1556 toolMgr()->append( aViewsAction, tid );
1558 toolMgr()->append( AntiClockWiseId, tid );
1559 toolMgr()->append( ClockWiseId, tid );
1561 toolMgr()->append( OrthographicId, tid );
1562 toolMgr()->append( PerspectiveId, tid );
1563 #if OCC_VERSION_LARGE > 0x06090000
1564 toolMgr()->append( StereoId, tid );
1567 toolMgr()->append( ResetId, tid );
1570 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1571 aMemAction->insertAction( toolMgr()->action( MemId ) );
1572 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1573 toolMgr()->append( aMemAction, tid );
1575 toolMgr()->append( toolMgr()->separator(), tid );
1576 toolMgr()->append( CloneId, tid );
1578 toolMgr()->append( toolMgr()->separator(), tid );
1579 toolMgr()->append( ClippingId, tid );
1580 toolMgr()->append( AxialScaleId, tid );
1581 toolMgr()->append( GraduatedAxesId, tid );
1582 toolMgr()->append( AmbientId, tid );
1584 toolMgr()->append( MaximizedId, tid );
1585 toolMgr()->append( SynchronizeId, tid );
1586 #ifdef ENABLE_RAY_TRACING
1587 toolMgr()->append( RayTracingId, tid );
1588 toolMgr()->append( EnvTextureId, tid );
1589 toolMgr()->append( LightSourceId, tid );
1594 \brief Perform 'fit all' operation.
1596 void OCCViewer_ViewWindow::onViewFitAll()
1598 myViewPort->fitAll();
1602 \brief Perform "front view" transformation.
1604 void OCCViewer_ViewWindow::onFrontView()
1606 emit vpTransformationStarted ( FRONTVIEW );
1607 Handle(V3d_View) aView3d = myViewPort->getView();
1608 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
1610 emit vpTransformationFinished ( FRONTVIEW );
1614 \brief Perform "back view" transformation.
1616 void OCCViewer_ViewWindow::onBackView()
1618 emit vpTransformationStarted ( BACKVIEW );
1619 Handle(V3d_View) aView3d = myViewPort->getView();
1620 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
1622 emit vpTransformationFinished ( BACKVIEW );
1626 \brief Perform "top view" transformation.
1628 void OCCViewer_ViewWindow::onTopView()
1630 emit vpTransformationStarted ( TOPVIEW );
1631 Handle(V3d_View) aView3d = myViewPort->getView();
1632 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
1634 emit vpTransformationFinished ( TOPVIEW );
1638 \brief Perform "bottom view" transformation.
1640 void OCCViewer_ViewWindow::onBottomView()
1642 emit vpTransformationStarted ( BOTTOMVIEW );
1643 Handle(V3d_View) aView3d = myViewPort->getView();
1644 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
1646 emit vpTransformationFinished ( BOTTOMVIEW );
1650 \brief Perform "left view" transformation.
1652 void OCCViewer_ViewWindow::onLeftView()
1654 emit vpTransformationStarted ( LEFTVIEW );
1655 Handle(V3d_View) aView3d = myViewPort->getView();
1656 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
1658 emit vpTransformationFinished ( LEFTVIEW );
1662 \brief Perform "right view" transformation.
1664 void OCCViewer_ViewWindow::onRightView()
1666 emit vpTransformationStarted ( RIGHTVIEW );
1667 Handle(V3d_View) aView3d = myViewPort->getView();
1668 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
1670 emit vpTransformationFinished ( RIGHTVIEW );
1674 \brief Rotate view 90 degrees clockwise
1676 void OCCViewer_ViewWindow::onClockWiseView()
1678 emit vpTransformationStarted ( CLOCKWISEVIEW );
1679 myViewPort->rotateXY( 90. );
1680 emit vpTransformationFinished ( CLOCKWISEVIEW );
1684 \brief Rotate view 90 degrees conterclockwise
1686 void OCCViewer_ViewWindow::onAntiClockWiseView()
1688 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1689 myViewPort->rotateXY( -90. );
1690 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1694 \brief Perform "reset view" transformation.
1696 Sets default orientation of the viewport camera.
1698 void OCCViewer_ViewWindow::onResetView()
1700 emit vpTransformationStarted( RESETVIEW );
1701 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1702 myViewPort->getView()->Reset( false );
1703 myViewPort->fitAll( false, true, false );
1704 myViewPort->getView()->SetImmediateUpdate( upd );
1705 onProjectionType(); // needed to apply projection type properly after reset
1706 myViewPort->getView()->Update();
1707 emit vpTransformationFinished( RESETVIEW );
1711 \brief Set the given projection mode.
1713 Set the given projection mode: Orthographic or Perspective.
1715 void OCCViewer_ViewWindow::onProjectionType( QAction* theAction )
1717 Handle(V3d_View) aView3d = myViewPort->getView();
1718 if ( !aView3d.IsNull() ) {
1719 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1720 if (theAction == toolMgr()->action( OrthographicId )) {
1721 myModel->setProjectionType(Orthographic);
1722 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Orthographic );
1723 aCamera->SetFOVy(45.0);
1725 else if (theAction == toolMgr()->action( PerspectiveId )) {
1726 myModel->setProjectionType(Perspective);
1727 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Perspective );
1728 aCamera->SetFOVy(30.0);
1730 #if OCC_VERSION_LARGE > 0x06090000
1731 if (toolMgr()->action( StereoId )->isChecked()) {
1732 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1733 aCamera->SetFOVy(30.0);
1742 \brief Sets Stereo projection mode.
1744 Sets Stereo projection mode.
1746 void OCCViewer_ViewWindow::onStereoType( bool activate )
1748 #if OCC_VERSION_LARGE > 0x06090000
1749 Handle(V3d_View) aView3d = myViewPort->getView();
1750 if ( !aView3d.IsNull() ) {
1751 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1753 toolMgr()->action( PerspectiveId )->setChecked(true);
1754 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1755 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(false);
1757 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1758 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1759 setStereoType( aResMgr->integerValue( "OCCViewer", "stereo_type", 0 ) );
1760 setAnaglyphFilter( aResMgr->integerValue( "OCCViewer", "anaglyph_filter", 0 ) );
1761 setReverseStereo( aResMgr->booleanValue( "OCCViewer", "reverse_stereo", false ) );
1762 setVSync( aResMgr->booleanValue( "OCCViewer", "enable_vsync", true ) );
1763 setQuadBufferSupport( aResMgr->booleanValue( "OCCViewer", "enable_quad_buffer_support", false ) );
1766 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(true);
1767 if (myModel->projectionType() == Orthographic) {
1768 toolMgr()->action( OrthographicId )->setChecked(true);
1769 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Orthographic);
1771 else if (myModel->projectionType() == Perspective) {
1772 toolMgr()->action( PerspectiveId )->setChecked(true);
1773 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1780 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1781 toolMgr()->action( StereoId )->isChecked() )
1782 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1787 \brief Restore the view.
1789 Restore the projection mode based on tool-buttons states.
1791 void OCCViewer_ViewWindow::onProjectionType()
1793 emit vpTransformationStarted( PROJECTION );
1794 if (toolMgr()->action( OrthographicId )->isChecked())
1795 setProjectionType( Orthographic );
1796 if (toolMgr()->action( PerspectiveId )->isChecked())
1797 setProjectionType( Perspective );
1798 #if OCC_VERSION_LARGE > 0x06090000
1799 if (toolMgr()->action( StereoId )->isChecked())
1800 setProjectionType( Stereo );
1802 emit vpTransformationFinished( PROJECTION );
1805 void OCCViewer_ViewWindow::setProjectionType( int mode )
1807 QtxAction* anOrthographicAction = dynamic_cast<QtxAction*>( toolMgr()->action( OrthographicId ) );
1808 QtxAction* aPerspectiveAction = dynamic_cast<QtxAction*>( toolMgr()->action( PerspectiveId ) );
1809 #if OCC_VERSION_LARGE > 0x06090000
1810 QtxAction* aStereoAction = dynamic_cast<QtxAction*>( toolMgr()->action( StereoId ) );
1814 onProjectionType( anOrthographicAction );
1817 onProjectionType( aPerspectiveAction );
1820 onStereoType( true );
1823 // update action state if method is called outside
1824 if ( mode == Orthographic && !anOrthographicAction->isChecked() ) {
1825 anOrthographicAction->setChecked( true );
1826 #if OCC_VERSION_LARGE > 0x06090000
1827 aStereoAction->setChecked( false );
1830 if ( mode == Perspective && !aPerspectiveAction->isChecked() ) {
1831 aPerspectiveAction->setChecked( true );
1832 #if OCC_VERSION_LARGE > 0x06090000
1833 aStereoAction->setChecked( false );
1836 #if OCC_VERSION_LARGE > 0x06090000
1837 if ( mode == Stereo ) {
1838 aStereoAction->setChecked( true );
1839 if ( anOrthographicAction->isEnabled() ) {
1840 anOrthographicAction->setEnabled( false );
1841 anOrthographicAction->setChecked( false );
1842 aStereoAction->setChecked( false );
1845 anOrthographicAction->setEnabled( true );
1846 aStereoAction->setChecked( false );
1847 anOrthographicAction->setChecked(myModel->projectionType() == Orthographic);
1849 if ( aPerspectiveAction->isEnabled() ) {
1850 aPerspectiveAction->setEnabled( false );
1851 aPerspectiveAction->setChecked( true );
1852 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1853 toolMgr()->action( StereoId )->isChecked() )
1854 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1857 aPerspectiveAction->setEnabled( true );
1858 aStereoAction->setChecked( false );
1859 aPerspectiveAction->setChecked(myModel->projectionType() == Perspective);
1864 if ( !anOrthographicAction->isEnabled() )
1865 anOrthographicAction->setEnabled( true );
1866 if ( !aPerspectiveAction->isEnabled() )
1867 aPerspectiveAction->setEnabled( true );
1873 \brief Perform "fit all" transformation.
1875 void OCCViewer_ViewWindow::onFitAll()
1877 emit vpTransformationStarted( FITALLVIEW );
1878 myViewPort->fitAll();
1879 emit vpTransformationFinished( FITALLVIEW );
1883 \brief Perform "fit selection" transformation.
1885 void OCCViewer_ViewWindow::onFitSelection()
1887 emit vpTransformationStarted( FITSELECTION );
1888 #if OCC_VERSION_LARGE > 0x06090000
1889 myModel->getAISContext()->FitSelected( getViewPort()->getView() );
1891 emit vpTransformationFinished( FITSELECTION );
1895 \brief Called if 'change rotation point' operation is activated.
1896 \param on action state
1898 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1902 if (!mySetRotationPointDlg)
1904 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1905 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1908 if (!mySetRotationPointDlg->isVisible())
1910 //if (mySetRotationPointDlg->IsFirstShown())
1911 if (myCurrPointType == BBCENTER)
1913 Standard_Real Xcenter, Ycenter, Zcenter;
1914 if (OCCViewer_Utilities::computeVisibleBBCenter(myViewPort->getView(), Xcenter, Ycenter, Zcenter))
1915 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1917 mySetRotationPointDlg->show();
1922 if (mySetRotationPointDlg->isVisible())
1923 mySetRotationPointDlg->hide();
1928 \brief Create one more window with same content.
1930 void OCCViewer_ViewWindow::onCloneView()
1932 SUIT_ViewWindow* vw = myManager->createViewWindow();
1934 emit viewCloned( vw );
1935 OCCViewer_ViewWindow* occVw = dynamic_cast<OCCViewer_ViewWindow*> (vw);
1936 if(occVw && occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)) {
1937 occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)->synchronize(this);
1942 Creates one more window with same content
1944 void OCCViewer_ViewWindow::onAxialScale()
1946 if ( !myScalingDlg )
1947 myScalingDlg = new OCCViewer_AxialScaleDlg( this , myModel );
1949 if ( !myScalingDlg->isVisible() )
1951 myScalingDlg->Update();
1952 myScalingDlg->show();
1957 Shows Graduated Axes dialog
1959 void OCCViewer_ViewWindow::onGraduatedAxes()
1961 myCubeAxesDlg->Update();
1962 myCubeAxesDlg->show();
1965 void OCCViewer_ViewWindow::onAmbientToogle()
1967 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
1968 viewer->InitDefinedLights();
1969 while(viewer->MoreDefinedLights())
1971 Handle(V3d_Light) light = viewer->DefinedLight();
1972 if(light->Type() != V3d_AMBIENT)
1974 Handle(V3d_View) aView3d = myViewPort->getView();
1975 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
1976 else viewer->SetLightOn(light);
1978 viewer->NextDefinedLights();
1984 \brief Store view parameters.
1986 void OCCViewer_ViewWindow::onMemorizeView()
1988 appendViewAspect( getViewParams() );
1992 \brief Restore view parameters.
1994 void OCCViewer_ViewWindow::onRestoreView()
1996 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
1997 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
1999 updateViewAspects( aDlg->parameters() );
2000 if( myRestoreFlag && aDlg->parameters().count() )
2001 performRestoring( aDlg->currentItem() );
2005 \brief Restore view parameters.
2006 \param anItem view parameters
2008 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
2010 Handle(V3d_View) aView3d = myViewPort->getView();
2012 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
2013 aView3d->SetScale( anItem.scale );
2014 aView3d->SetTwist( anItem.twist );
2015 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
2016 aView3d->SetImmediateUpdate( prev );
2017 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2018 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2019 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
2021 #if OCC_VERSION_LARGE > 0x06070100
2022 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
2024 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
2026 // "eye" and "at" require conversion to represent center panning
2027 // up direction is only available after setting angle of twist and
2028 // other view parameters
2029 aView3d->Up( anUpX, anUpY, anUpZ );
2031 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
2032 gp_Dir anUp( anUpX, anUpY, anUpZ );
2033 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
2034 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2035 gp_Dir aSide = aProj ^ anUp;
2037 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
2038 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
2040 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
2041 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2044 aView3d->SetCenter( anItem.centerX, anItem.centerY );
2047 if ( !baseParamsOnly ) {
2049 myModel->setTrihedronShown( anItem.isVisible );
2050 myModel->setTrihedronSize( anItem.size );
2052 // graduated trihedron
2053 bool anIsVisible = anItem.gtIsVisible;
2054 OCCViewer_AxisWidget::AxisData anAxisData[3];
2055 anAxisData[0].DrawName = anItem.gtDrawNameX;
2056 anAxisData[1].DrawName = anItem.gtDrawNameZ;
2057 anAxisData[2].DrawName = anItem.gtDrawNameZ;
2058 anAxisData[0].Name = anItem.gtNameX;
2059 anAxisData[1].Name = anItem.gtNameZ;
2060 anAxisData[2].Name = anItem.gtNameZ;
2061 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
2062 anItem.gtNameColorGX,
2063 anItem.gtNameColorBX );
2064 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
2065 anItem.gtNameColorGY,
2066 anItem.gtNameColorBY );
2067 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
2068 anItem.gtNameColorGZ,
2069 anItem.gtNameColorBZ );
2070 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
2071 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
2072 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
2073 anAxisData[0].NbValues = anItem.gtNbValuesX;
2074 anAxisData[1].NbValues = anItem.gtNbValuesY;
2075 anAxisData[2].NbValues = anItem.gtNbValuesZ;
2076 anAxisData[0].Offset = anItem.gtOffsetX;
2077 anAxisData[1].Offset = anItem.gtOffsetY;
2078 anAxisData[2].Offset = anItem.gtOffsetZ;
2079 anAxisData[0].Color = QColor( anItem.gtColorRX,
2082 anAxisData[1].Color = QColor( anItem.gtColorRY,
2085 anAxisData[2].Color = QColor( anItem.gtColorRZ,
2088 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
2089 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
2090 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
2091 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
2092 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
2093 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
2095 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
2096 myCubeAxesDlg->ApplyData( aView3d );
2098 } // if ( !baseParamsOnly )
2104 \brief Set restore flag.
2106 void OCCViewer_ViewWindow::setRestoreFlag()
2112 \brief Called when action "show/hide trihedron" is activated.
2114 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
2116 myModel->setTrihedronShown(show);
2120 \brief Toggles preselection (highlighting) on/off
2122 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
2124 myPreselectionEnabled = on;
2125 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
2127 // unhighlight all highlighted objects
2129 myModel->unHighlightAll( true, false );
2132 // update action state if method is called outside
2133 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2134 if ( a && a->isChecked() != on ) {
2135 a->setChecked( on );
2140 \brief Toggles selection on/off
2142 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
2144 mySelectionEnabled = on;
2145 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
2147 // update action state if method is called outside
2150 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2152 a->setEnabled( on );
2156 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
2157 if ( a && a->isChecked() != on ) {
2158 a->setChecked( on );
2163 \brief Switches "keyboard free" interaction style on/off
2165 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
2167 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
2169 // update action state if method is called outside
2170 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
2171 if ( a && a->isChecked() != on )
2172 a->setChecked( on );
2176 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
2178 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
2180 myViewPort->setAdvancedZoomingEnabled( on );
2182 // update action state if method is called outside
2183 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
2184 if ( a && a->isChecked() != on )
2185 a->setChecked( on );
2189 \brief Get current interaction style
2190 \return interaction style
2192 int OCCViewer_ViewWindow::interactionStyle() const
2194 return myInteractionStyle;
2198 \brief Set current interaction style
2199 \param theStyle interaction style
2201 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
2203 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
2207 \brief Get current zooming style
2208 \return zooming style
2210 int OCCViewer_ViewWindow::zoomingStyle() const
2212 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
2216 \brief Set current zooming style
2217 \param theStyle zooming style
2219 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
2221 onSwitchZoomingStyle( theStyle == 1 );
2225 \brief Dump view window contents to the pixmap.
2226 \return pixmap containing all scene rendered in the window
2228 QImage OCCViewer_ViewWindow::dumpView()
2230 Handle(V3d_View) view = myViewPort->getView();
2231 if ( view.IsNull() )
2234 int aWidth = myViewPort->width();
2235 int aHeight = myViewPort->height();
2237 // rnv: An old approach to dump the OCCViewer content
2238 // Now used OCCT built-in procedure.
2240 QApplication::syncX();
2241 view->Redraw(); // In order to reactivate GL context
2244 #ifndef DISABLE_GLVIEWER
2245 OpenGLUtils_FrameBuffer aFrameBuffer;
2246 if( aFrameBuffer.init( aWidth, aHeight ) )
2248 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
2250 glPushAttrib( GL_VIEWPORT_BIT );
2251 glViewport( 0, 0, aWidth, aHeight );
2252 aFrameBuffer.bind();
2257 aFrameBuffer.unbind();
2260 aFrameBuffer.bind();
2261 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
2262 aFrameBuffer.unbind();
2264 anImage = anImage.rgbSwapped();
2265 anImage = anImage.mirrored();
2268 // if frame buffers are unsupported, use old functionality
2271 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
2273 QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
2275 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
2281 view->ToPixMap(aPix,aWidth, aHeight,Graphic3d_BT_RGBA);
2283 QImage anImage( aPix.Data(), aWidth, aHeight, QImage::Format_ARGB32 );
2284 anImage = anImage.mirrored();
2288 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
2289 const QString& fileName,
2290 const QString& format )
2293 QApplication::setOverrideCursor( Qt::WaitCursor );
2294 if ( format != "PS" && format != "EPS")
2295 res = myViewPort->getView()->Dump( fileName.toStdString().c_str() );
2297 #if OCC_VERSION_MAJOR < 7
2298 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
2300 Handle(Graphic3d_CView) a3dView = myViewPort->getView()->View();
2304 res = a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
2305 else if (format == "EPS")
2306 res = a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
2308 QApplication::restoreOverrideCursor();
2313 QString OCCViewer_ViewWindow::filter() const
2315 return tr( "OCC_IMAGE_FILES" );
2320 \brief Set parameters of the cutting plane
2321 \param on if \c true, cutting plane is enabled
2322 \param x X position of plane point
2323 \param y Y position of plane point
2324 \param z Z position of plane point
2325 \param dx X coordinate of plane normal
2326 \param dy Y coordinate of plane normal
2327 \param dz Z coordinate of plane normal
2329 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2330 const double dx, const double dy, const double dz )
2332 Handle(V3d_View) view = myViewPort->getView();
2333 if ( view.IsNull() )
2337 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2339 // try to use already existing plane or create a new one
2340 Handle(V3d_Plane) clipPlane;
2342 // calculate new a,b,c,d values for the plane
2343 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2345 pln.Coefficients(a, b, c, d);
2346 #if OCC_VERSION_LARGE > 0x07000000
2347 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2348 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2349 if(aPlanes->Size() > 0 ) {
2351 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2352 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2353 if(aPlanes.Size() > 0 ) {
2355 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2356 aClipPlane->SetEquation(pln);
2357 aClipPlane->SetOn(Standard_True);
2359 view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2363 #if OCC_VERSION_LARGE > 0x07000000
2364 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2365 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2367 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2368 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2370 for( ;anIter.More();anIter.Next() ){
2371 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2372 aClipPlane->SetOn(Standard_False);
2380 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2382 gp_Dir aDir = pln.Axis().Direction();
2383 gp_Pnt aPnt = pln.Location();
2384 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2389 \brief Check if any cutting plane is enabled
2390 \return \c true if at least one cutting plane is enabled
2392 bool OCCViewer_ViewWindow::isCuttingPlane()
2394 Handle(V3d_View) view = myViewPort->getView();
2396 #if OCC_VERSION_LARGE > 0x07000000
2397 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2398 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2400 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2401 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2403 for( ;anIter.More();anIter.Next() ) {
2404 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2405 if(aClipPlane->IsOn()) {
2414 \brief Get the visual parameters of the view window.
2415 \return visual parameters of view window
2417 viewAspect OCCViewer_ViewWindow::getViewParams() const
2419 double projX, projY, projZ, twist;
2420 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2421 double aScaleX, aScaleY, aScaleZ;
2423 Handle(V3d_View) aView3d = myViewPort->getView();
2425 aView3d->Proj( projX, projY, projZ );
2426 aView3d->At( atX, atY, atZ );
2427 aView3d->Eye( eyeX, eyeY, eyeZ );
2428 twist = aView3d->Twist();
2430 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2432 bool isShown = myModel->isTrihedronVisible();
2433 double size = myModel->trihedronSize();
2435 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2438 params.scale = aView3d->Scale();
2439 params.projX = projX;
2440 params.projY = projY;
2441 params.projZ = projZ;
2442 params.twist = twist;
2449 params.scaleX = aScaleX;
2450 params.scaleY = aScaleY;
2451 params.scaleZ = aScaleZ;
2452 params.name = aName;
2453 params.isVisible= isShown;
2456 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2457 aView3d->Center( params.centerX, params.centerY );
2460 // graduated trihedron
2461 bool anIsVisible = false;
2462 OCCViewer_AxisWidget::AxisData anAxisData[3];
2463 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2465 params.gtIsVisible = anIsVisible;
2466 params.gtDrawNameX = anAxisData[0].DrawName;
2467 params.gtDrawNameY = anAxisData[1].DrawName;
2468 params.gtDrawNameZ = anAxisData[2].DrawName;
2469 params.gtNameX = anAxisData[0].Name;
2470 params.gtNameY = anAxisData[1].Name;
2471 params.gtNameZ = anAxisData[2].Name;
2472 params.gtNameColorRX = anAxisData[0].NameColor.red();
2473 params.gtNameColorGX = anAxisData[0].NameColor.green();
2474 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2475 params.gtNameColorRY = anAxisData[1].NameColor.red();
2476 params.gtNameColorGY = anAxisData[1].NameColor.green();
2477 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2478 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2479 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2480 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2481 params.gtDrawValuesX = anAxisData[0].DrawValues;
2482 params.gtDrawValuesY = anAxisData[1].DrawValues;
2483 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2484 params.gtNbValuesX = anAxisData[0].NbValues;
2485 params.gtNbValuesY = anAxisData[1].NbValues;
2486 params.gtNbValuesZ = anAxisData[2].NbValues;
2487 params.gtOffsetX = anAxisData[0].Offset;
2488 params.gtOffsetY = anAxisData[1].Offset;
2489 params.gtOffsetZ = anAxisData[2].Offset;
2490 params.gtColorRX = anAxisData[0].Color.red();
2491 params.gtColorGX = anAxisData[0].Color.green();
2492 params.gtColorBX = anAxisData[0].Color.blue();
2493 params.gtColorRY = anAxisData[1].Color.red();
2494 params.gtColorGY = anAxisData[1].Color.green();
2495 params.gtColorBY = anAxisData[1].Color.blue();
2496 params.gtColorRZ = anAxisData[2].Color.red();
2497 params.gtColorGZ = anAxisData[2].Color.green();
2498 params.gtColorBZ = anAxisData[2].Color.blue();
2499 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2500 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2501 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2502 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2503 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2504 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2510 \brief Get visual parameters of this view window.
2511 \return visual parameters of view window
2513 QString OCCViewer_ViewWindow::getVisualParameters()
2515 viewAspect params = getViewParams();
2519 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2520 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2521 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
2522 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
2524 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2525 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2526 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2527 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2528 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2529 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2530 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2531 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2532 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2533 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2534 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2535 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2536 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2537 data << QString( "isVisible=%1" ).arg( params.isVisible );
2538 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2540 ClipPlanesList aPlanes = myModel->getClipPlanes();
2541 for ( int i=0; i < aPlanes.size(); i++ )
2543 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2544 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2545 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2546 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2547 switch ( aPlane.Mode )
2549 case OCCViewer_ClipPlane::Absolute :
2551 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2553 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2555 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2556 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2557 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2561 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2566 case OCCViewer_ClipPlane::Relative :
2568 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2569 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2570 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2575 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2576 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2577 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2578 data << ClippingPlane;
2581 // graduated trihedron
2582 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2583 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2584 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2585 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2586 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2587 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2588 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2589 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2590 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2591 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2592 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2593 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2594 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2595 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2596 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2597 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2598 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2599 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2600 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2601 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2602 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2603 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2604 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2605 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2606 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2607 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2608 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2609 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2610 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2611 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2612 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2613 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2614 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2615 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2616 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2617 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2618 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2619 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2620 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2621 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2623 // ray tracing parameters
2624 Graphic3d_RenderingParams rendParams = this->getViewPort()->getView()->RenderingParams();
2625 if ( rendParams.Method == Graphic3d_RM_RAYTRACING ) {
2626 QString RayTracing = "rayTracing=";
2627 RayTracing += QString( "rtDepth~%1;" ).arg( rendParams.RaytracingDepth );
2628 RayTracing += QString( "rtReflection~%1;" ).arg( rendParams.IsReflectionEnabled );
2629 RayTracing += QString( "rtAntialiasing~%1;" ).arg( rendParams.IsAntialiasingEnabled );
2630 RayTracing += QString( "rtShadow~%1;" ).arg( rendParams.IsShadowEnabled );
2631 RayTracing += QString( "rtTransShadow~%1;" ).arg( rendParams.IsTransparentShadowEnabled );
2635 // environment texture parameters
2636 Handle(Graphic3d_TextureEnv) aTexture = this->getViewPort()->getView()->TextureEnv();
2637 if ( !aTexture.IsNull() ) {
2638 QString EnvTexture = "envTexture=";
2639 if ( aTexture->Name() == Graphic3d_NOT_ENV_UNKNOWN ) {
2640 TCollection_AsciiString aFileName;
2641 aTexture->Path().SystemName( aFileName );
2642 EnvTexture += QString( "etFile~%1;" ).arg( aFileName.ToCString() );
2645 EnvTexture += QString( "etNumber~%1;" ).arg( aTexture->Name() );
2649 // light source parameters
2650 myModel->getViewer3d()->InitDefinedLights();
2651 while ( myModel->getViewer3d()->MoreDefinedLights() )
2653 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2654 if ( aLight->Type() != V3d_AMBIENT ) {
2655 QString LightSource = QString( "lightSource=" );
2656 LightSource += QString( "lightType~%1;" ).arg( aLight->Type() );
2658 if ( aLight->Type() == V3d_DIRECTIONAL )
2659 Handle(V3d_DirectionalLight)::DownCast( aLight )->Direction( aX, aY, aZ );
2660 else if ( aLight->Type() == V3d_POSITIONAL )
2661 Handle(V3d_PositionalLight)::DownCast( aLight )->Position( aX, aY, aZ );
2662 LightSource += QString( "lightX~%1;" ).arg( aX );
2663 LightSource += QString( "lightY~%1;" ).arg( aY );
2664 LightSource += QString( "lightZ~%1;" ).arg( aZ );
2665 LightSource += QString( "lightColorR~%1;" ).arg( aLight->Color().Red() );
2666 LightSource += QString( "lightColorG~%1;" ).arg( aLight->Color().Green() );
2667 LightSource += QString( "lightColorB~%1;" ).arg( aLight->Color().Blue() );
2668 LightSource += QString( "lightHeadlight~%1;" ).arg( aLight->Headlight() );
2669 data << LightSource;
2671 myModel->getViewer3d()->NextDefinedLights();
2674 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2675 data << QString( "background=%1" ).arg( bg );
2677 return data.join("*");
2681 \brief Restore visual parameters of the view window.
2682 \param parameters visual parameters of view window
2684 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2687 ClipPlanesList aClipPlanes;
2688 QStringList data = parameters.split( '*' );
2689 Qtx::BackgroundData bgData;
2690 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2692 foreach( QString param, data ) {
2693 QString paramName = param.section( '=', 0, 0 ).trimmed();
2694 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2695 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2696 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2697 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2698 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2699 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2700 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2701 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2702 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2703 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2704 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2705 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2706 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2707 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2708 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2709 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2710 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2711 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2712 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2713 else if ( paramName.contains( "ClippingPlane" ) )
2715 QStringList ClipPlaneData = paramValue.split( ';' );
2716 OCCViewer_ClipPlane aPlane;
2717 foreach( QString ClipPlaneParam, ClipPlaneData )
2719 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2720 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2721 if ( ClipPlane_paramName == "Mode" )
2723 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2725 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2726 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2727 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2728 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2731 switch ( aPlane.Mode )
2733 case OCCViewer_ClipPlane::Absolute :
2734 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2735 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2736 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2737 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2738 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2741 case OCCViewer_ClipPlane::Relative :
2742 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2743 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2744 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2749 aClipPlanes.push_back(aPlane);
2751 // graduated trihedron
2752 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2753 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2754 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2755 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2756 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2757 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2758 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2759 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2760 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2761 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2762 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2763 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2764 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2765 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2766 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2767 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2768 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2769 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2770 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2771 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2772 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2773 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2774 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2775 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2776 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2777 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2778 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2779 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2780 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2781 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2782 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2783 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2784 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2785 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2786 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2787 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2788 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2789 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2790 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2791 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2792 else if ( paramName == "rayTracing" )
2794 Graphic3d_RenderingParams& rendParams = this->getViewPort()->getView()->ChangeRenderingParams();
2795 rendParams.Method = Graphic3d_RM_RAYTRACING;
2796 QStringList rtData = paramValue.split( ';' );
2797 foreach( QString rtParam, rtData )
2799 QString rt_paramName = rtParam.section( '~', 0, 0 ).trimmed();
2800 QString rt_paramValue = rtParam.section( '~', 1, 1 ).trimmed();
2801 if ( rt_paramName == "rtDepth" ) rendParams.RaytracingDepth = rt_paramValue.toInt();
2802 else if ( rt_paramName == "rtReflection" ) rendParams.IsReflectionEnabled = rt_paramValue.toInt();
2803 else if ( rt_paramName == "rtAntialiasing" ) rendParams.IsAntialiasingEnabled = rt_paramValue.toInt();
2804 else if ( rt_paramName == "rtShadow" ) rendParams.IsShadowEnabled = rt_paramValue.toInt();
2805 else if ( rt_paramName == "rtTransShadow" ) rendParams.IsTransparentShadowEnabled = rt_paramValue.toInt();
2808 else if ( paramName == "envTexture" )
2810 Handle(Graphic3d_TextureEnv) aTexture;
2811 QStringList etData = paramValue.split( ';' );
2812 foreach( QString etParam, etData )
2814 QString et_paramName = etParam.section( '~', 0, 0 ).trimmed();
2815 QString et_paramValue = etParam.section( '~', 1, 1 ).trimmed();
2816 if ( et_paramName == "etNumber" )
2817 aTexture = new Graphic3d_TextureEnv( Graphic3d_NameOfTextureEnv( et_paramValue.toInt() ) );
2818 else if ( et_paramName == "etFile" )
2819 aTexture = new Graphic3d_TextureEnv( TCollection_AsciiString( et_paramValue.toStdString().c_str() ) );
2820 Handle(V3d_View) aView = this->getViewPort()->getView();
2821 aView->SetTextureEnv( aTexture );
2822 #if OCC_VERSION_LARGE <= 0x07000000
2823 aView->SetSurfaceDetail( V3d_TEX_ENVIRONMENT );
2827 else if ( paramName == "lightSource" )
2829 myModel->getViewer3d()->InitDefinedLights();
2830 while ( myModel->getViewer3d()->MoreDefinedLights() )
2832 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2833 if( aLight->Type() != V3d_AMBIENT ) {
2834 myModel->getViewer3d()->DelLight( aLight );
2835 myModel->getViewer3d()->InitDefinedLights();
2837 myModel->getViewer3d()->NextDefinedLights();
2842 V3d_TypeOfLight aType;
2844 QStringList lsData = paramValue.split( ';' );
2845 foreach( QString lsParam, lsData )
2847 QString ls_paramName = lsParam.section( '~', 0, 0 ).trimmed();
2848 QString ls_paramValue = lsParam.section( '~', 1, 1 ).trimmed();
2849 if ( ls_paramName == "lightType" ) aType = V3d_TypeOfLight( ls_paramValue.toInt() );
2850 else if ( ls_paramName == "lightX" ) aX = ls_paramValue.toDouble();
2851 else if ( ls_paramName == "lightY" ) aY = ls_paramValue.toDouble();
2852 else if ( ls_paramName == "lightZ" ) aZ = ls_paramValue.toDouble();
2853 else if ( ls_paramName == "lightColorR" ) cR = ls_paramValue.toDouble();
2854 else if ( ls_paramName == "lightColorG" ) cG = ls_paramValue.toDouble();
2855 else if ( ls_paramName == "lightColorB" ) cB = ls_paramValue.toDouble();
2856 else if ( ls_paramName == "lightHeadlight" ) isHeadlight = ls_paramValue.toInt();
2858 Quantity_Color aColor = Quantity_Color( cR, cG, cB, Quantity_TOC_RGB );
2859 if( aType == V3d_DIRECTIONAL ) {
2860 Handle(V3d_DirectionalLight) aLight = new V3d_DirectionalLight( myModel->getViewer3d() );
2861 aLight->SetDirection( aX, aY, aZ );
2862 aLight->SetColor( aColor );
2863 aLight->SetHeadlight( isHeadlight );
2864 myModel->getViewer3d()->SetLightOn( aLight );
2866 else if( aType == V3d_POSITIONAL ) {
2867 Handle(V3d_PositionalLight) aLight = new V3d_PositionalLight( myModel->getViewer3d(), aX, aY, aZ, aColor.Name() );
2868 aLight->SetHeadlight( isHeadlight );
2869 myModel->getViewer3d()->SetLightOn( aLight );
2872 else if ( paramName == "background" ) {
2873 QString bg = paramValue.replace( "$", "=" );
2874 bgData = Qtx::stringToBackground( bg );
2878 else // old format - "1.000e+00*0.000e+00..."
2881 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2882 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2883 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2884 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2885 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2886 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2887 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
2888 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2889 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2890 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
2891 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2892 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2893 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2894 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
2895 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
2896 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
2897 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
2898 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
2900 performRestoring( params );
2901 setBackground( bgData );
2902 myModel->setClipPlanes(aClipPlanes);
2906 \brief Handle show event.
2908 Emits Show() signal.
2910 \param theEvent show event
2912 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2914 emit Show( theEvent );
2918 \brief Handle hide event.
2920 Emits Hide() signal.
2922 \param theEvent hide event
2924 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
2926 emit Hide( theEvent );
2931 Save old cursor. [ protected ]
2933 void OCCViewer_ViewWindow::saveCursor()
2935 QCursor* aCursor = NULL;
2937 aCursor = myViewPort->getDefaultCursor();
2938 myCursor = ( aCursor ? *aCursor : cursor() );
2943 Creates default sketcher. [ virtual protected ]
2945 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
2948 return new OCCViewer_RectSketcher( this, type );
2949 if ( type == Polygon )
2950 return new OCCViewer_PolygonSketcher( this, type );
2954 void OCCViewer_ViewWindow::initSketchers()
2956 if ( mySketchers.isEmpty() )
2958 mySketchers.append( createSketcher( Rect ) );
2959 mySketchers.append( createSketcher( Polygon ) );
2963 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
2965 OCCViewer_ViewSketcher* sketcher = 0;
2966 QList<OCCViewer_ViewSketcher*>::Iterator it;
2967 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
2969 OCCViewer_ViewSketcher* sk = (*it);
2970 if ( sk->type() == typ )
2977 Handles requests for sketching in the active view. [ virtual public ]
2979 void OCCViewer_ViewWindow::activateSketching( int type )
2981 OCCViewer_ViewPort3d* vp = getViewPort();
2985 if ( !vp->isSketchingEnabled() )
2988 /* Finish current sketching */
2989 if ( type == NoSketching )
2993 onSketchingFinished();
2994 mypSketcher->deactivate();
2998 /* Activate new sketching */
3001 activateSketching( NoSketching ); /* concurrency not suported */
3002 mypSketcher = getSketcher( type );
3005 mypSketcher->activate();
3006 onSketchingStarted();
3012 Unhilights detected entities. [ virtual protected ]
3014 void OCCViewer_ViewWindow::onSketchingStarted()
3019 Selection by rectangle or polygon. [ virtual protected ]
3021 void OCCViewer_ViewWindow::onSketchingFinished()
3023 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
3024 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
3026 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
3027 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
3028 switch( mypSketcher->type() )
3032 QRect* aRect = (QRect*)mypSketcher->data();
3035 int aLeft = aRect->left();
3036 int aRight = aRect->right();
3037 int aTop = aRect->top();
3038 int aBottom = aRect->bottom();
3042 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
3044 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
3050 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
3053 int size = aPolygon->size();
3054 TColgp_Array1OfPnt2d anArray( 1, size );
3056 QPolygon::Iterator it = aPolygon->begin();
3057 QPolygon::Iterator itEnd = aPolygon->end();
3058 for( int index = 1; it != itEnd; ++it, index++ )
3060 QPoint aPoint = *it;
3061 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
3065 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
3067 ic->Select( anArray, getViewPort()->getView(), Standard_False );
3075 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
3076 aViewMgr->getOCCViewer()->performSelectionChanged();
3080 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
3085 bool OCCViewer_ViewWindow::transformRequested() const
3087 return ( myOperation != NOTHING );
3090 bool OCCViewer_ViewWindow::transformInProcess() const
3092 return myEventStarted;
3095 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
3097 myEventStarted = bOn;
3101 Set enabled state of transformation (rotate, zoom, etc)
3103 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
3105 if ( id != NOTHING ) myStatus.insert( id, on );
3109 \return enabled state of transformation (rotate, zoom, etc)
3111 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
3113 return myStatus.contains( id ) ? myStatus[ id ] : true;
3116 void OCCViewer_ViewWindow::onMaximizedView()
3118 setMaximized(!isMaximized());
3121 void OCCViewer_ViewWindow::returnTo3dView()
3123 setReturnedTo3dView( true );
3126 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
3128 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
3129 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
3130 if ( !isVisible3dView )
3131 toolMgr()->show( ReturnTo3dViewId );
3133 toolMgr()->hide( ReturnTo3dViewId );
3134 if ( isVisible3dView ) emit returnedTo3d( );
3138 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
3140 QAction* anAction = toolMgr()->action( MaximizedId );
3141 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
3142 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
3144 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
3145 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
3146 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
3147 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
3148 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
3150 emit maximized( this, true );
3154 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
3155 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
3156 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
3157 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
3158 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
3160 emit maximized( this, false );
3165 bool OCCViewer_ViewWindow::isMaximized() const
3167 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
3170 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
3172 IsSketcherStyle = enable;
3175 bool OCCViewer_ViewWindow::isSketcherStyle() const
3177 return IsSketcherStyle;
3181 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
3186 int OCCViewer_ViewWindow::projectionType() const
3188 int mode = Orthographic;
3189 Handle(V3d_View) aView3d = myViewPort->getView();
3190 if ( !aView3d.IsNull() ) {
3191 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3192 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Perspective)
3194 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Orthographic)
3195 mode = Orthographic;
3196 #if OCC_VERSION_LARGE > 0x06090000
3197 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
3204 void OCCViewer_ViewWindow::setStereoType( int type )
3206 Handle(V3d_View) aView3d = myViewPort->getView();
3207 if ( !aView3d.IsNull() ) {
3208 #if OCC_VERSION_LARGE > 0x06090000
3209 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3210 aParams->StereoMode = (Graphic3d_StereoMode)type;
3215 int OCCViewer_ViewWindow::stereoType() const
3217 int type = QuadBuffer;
3218 Handle(V3d_View) aView3d = myViewPort->getView();
3219 if ( !aView3d.IsNull() ) {
3220 #if OCC_VERSION_LARGE > 0x06090000
3221 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3222 type = (OCCViewer_ViewWindow::StereoType)aParams->StereoMode;
3228 void OCCViewer_ViewWindow::setAnaglyphFilter( int type )
3230 Handle(V3d_View) aView3d = myViewPort->getView();
3231 if ( !aView3d.IsNull() ) {
3232 #if OCC_VERSION_LARGE > 0x06090000
3233 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3234 if (type == RedCyan)
3235 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
3236 if (type == YellowBlue)
3237 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
3238 if (type == GreenMagenta)
3239 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
3244 int OCCViewer_ViewWindow::anaglyphFilter() const
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 (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized)
3253 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized)
3255 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple)
3256 type = GreenMagenta;
3262 void OCCViewer_ViewWindow::setStereographicFocus( int type, double value )
3264 Handle(V3d_View) aView3d = myViewPort->getView();
3265 if ( !aView3d.IsNull() ) {
3266 #if OCC_VERSION_LARGE > 0x06090000
3267 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3268 aCamera->SetZFocus( (Graphic3d_Camera::FocusType) type, value );
3273 int OCCViewer_ViewWindow::stereographicFocusType() const
3275 int type = Relative;
3276 Handle(V3d_View) aView3d = myViewPort->getView();
3277 if ( !aView3d.IsNull() ) {
3278 #if OCC_VERSION_LARGE > 0x06090000
3279 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3280 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->ZFocusType();
3286 double OCCViewer_ViewWindow::stereographicFocusValue() const
3289 Handle(V3d_View) aView3d = myViewPort->getView();
3290 if ( !aView3d.IsNull() ) {
3291 #if OCC_VERSION_LARGE > 0x06090000
3292 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3293 value = aCamera->ZFocus();
3299 void OCCViewer_ViewWindow::setInterocularDistance( int type, double value )
3301 Handle(V3d_View) aView3d = myViewPort->getView();
3302 if ( !aView3d.IsNull() ) {
3303 #if OCC_VERSION_LARGE > 0x06090000
3304 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3305 aCamera->SetIOD( (Graphic3d_Camera::IODType) type, value );
3310 int OCCViewer_ViewWindow::interocularDistanceType() const
3312 int type = Relative;
3313 Handle(V3d_View) aView3d = myViewPort->getView();
3314 if ( !aView3d.IsNull() ) {
3315 #if OCC_VERSION_LARGE > 0x06090000
3316 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3317 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->GetIODType();
3323 double OCCViewer_ViewWindow::interocularDistanceValue() const
3325 double value = 0.05;
3326 Handle(V3d_View) aView3d = myViewPort->getView();
3327 if ( !aView3d.IsNull() ) {
3328 #if OCC_VERSION_LARGE > 0x06090000
3329 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3330 value = aCamera->IOD();
3336 void OCCViewer_ViewWindow::setReverseStereo( bool reverse )
3338 Handle(V3d_View) aView3d = myViewPort->getView();
3339 if ( !aView3d.IsNull() ) {
3340 #if OCC_VERSION_LARGE > 0x06090000
3341 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3342 aParams->ToReverseStereo = reverse;
3347 bool OCCViewer_ViewWindow::isReverseStereo() const
3349 int reverse = false;
3350 Handle(V3d_View) aView3d = myViewPort->getView();
3351 if ( !aView3d.IsNull() ) {
3352 #if OCC_VERSION_LARGE > 0x06090000
3353 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3354 reverse = aParams->ToReverseStereo;
3360 void OCCViewer_ViewWindow::setVSync( bool enable )
3362 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3363 if ( !anIntCont.IsNull() ) {
3364 #if OCC_VERSION_LARGE > 0x06090000
3365 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3366 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3367 aCaps->swapInterval = enable;
3372 bool OCCViewer_ViewWindow::isVSync() const
3375 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3376 if ( !anIntCont.IsNull() ) {
3377 #if OCC_VERSION_LARGE > 0x06090000
3378 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3379 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3380 enable = aCaps->swapInterval;
3386 void OCCViewer_ViewWindow::setQuadBufferSupport( bool enable )
3388 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3389 if ( !anIntCont.IsNull() ) {
3390 #if OCC_VERSION_LARGE > 0x06090000
3391 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3392 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3393 aCaps->contextStereo = enable;
3398 bool OCCViewer_ViewWindow::isQuadBufferSupport() const
3401 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3402 if ( !anIntCont.IsNull() ) {
3403 #if OCC_VERSION_LARGE > 0x06090000
3404 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3405 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3406 enable = aCaps->contextStereo;
3413 bool OCCViewer_ViewWindow::isOpenGlStereoSupport() const
3415 GLboolean support[1];
3416 glGetBooleanv (GL_STEREO, support);
3423 QColor OCCViewer_ViewWindow::backgroundColor() const
3425 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
3429 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
3431 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
3434 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
3436 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
3439 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
3441 if ( myViewPort ) myViewPort->setBackground( theBackground );
3444 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
3446 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
3452 void OCCViewer_ViewWindow::clearViewAspects()
3454 myViewAspects.clear();
3458 \return const reference to list of view aspects
3460 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
3462 return myViewAspects;
3466 Appends new view aspect
3467 \param aParams - new view aspects
3469 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
3471 myViewAspects.append( aParams );
3475 Replaces old view aspects by new ones
3476 \param aViewList - list of new view aspects
3478 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
3480 myViewAspects = aViewList;
3484 Get camera properties for the OCC view window.
3485 \return shared pointer on camera properties.
3487 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
3489 SUIT_CameraProperties aProps;
3491 Handle(V3d_View) aSourceView = getViewPort()->getView();
3492 if ( aSourceView.IsNull() )
3495 if ( get2dMode() == No2dMode ) {
3496 aProps.setDimension( SUIT_CameraProperties::Dim3D );
3499 aProps.setDimension( SUIT_CameraProperties::Dim2D );
3500 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
3503 // read common properites of the view
3504 Standard_Real anUp[3];
3505 Standard_Real anAt[3];
3506 Standard_Real anEye[3];
3507 Standard_Real aProj[3];
3508 Standard_Real anAxialScale[3];
3510 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
3511 aSourceView->At( anAt[0], anAt[1], anAt[2] );
3512 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
3513 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3515 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3516 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
3518 #if OCC_VERSION_LARGE > 0x06070100
3519 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
3521 // store camera properties "as is": it is up to synchronized
3522 // view classes to provide necessary property conversion.
3523 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
3524 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
3526 if ( aSourceView->Camera()->IsOrthographic() )
3528 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
3529 aProps.setViewAngle( 0.0 );
3533 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
3534 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
3536 aProps.setMappingScale( aSourceView->Camera()->Scale() );
3538 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
3540 // generate view orientation matrix for transforming OCC projection reference point
3541 // into a camera (eye) position.
3542 gp_Dir aLeftDir = gp_Dir( anUp[0], anUp[1], anUp[2] ) ^ gp_Dir( aProj[0], aProj[1], aProj[2] );
3545 aTrsf.SetValue( 1, 1, aLeftDir.X() );
3546 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
3547 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
3549 aTrsf.SetValue( 1, 2, anUp[0] );
3550 aTrsf.SetValue( 2, 2, anUp[1] );
3551 aTrsf.SetValue( 3, 2, anUp[2] );
3553 aTrsf.SetValue( 1, 3, aProj[0] );
3554 aTrsf.SetValue( 2, 3, aProj[1] );
3555 aTrsf.SetValue( 3, 3, aProj[2] );
3557 aTrsf.SetValue( 1, 4, anAt[0] );
3558 aTrsf.SetValue( 2, 4, anAt[1] );
3559 aTrsf.SetValue( 3, 4, anAt[2] );
3561 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
3563 // transform to world-space coordinate system
3564 gp_XYZ aPosition( aProjRef.X(), aProjRef.Y(), aCameraDepth );
3565 aTrsf.Transforms( aPosition );
3567 // compute focal point
3568 double aFocalPoint[3];
3570 aFocalPoint[0] = aPosition.X() - aProj[0] * aCameraDepth;
3571 aFocalPoint[1] = aPosition.Y() - aProj[1] * aCameraDepth;
3572 aFocalPoint[2] = aPosition.Z() - aProj[2] * aCameraDepth;
3574 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3575 aProps.setPosition( aPosition.X(), aPosition.Y(), aPosition.Z() );
3577 Standard_Real aViewScale[2];
3578 aSourceView->Size( aViewScale[0], aViewScale[1] );
3579 aProps.setMappingScale( aViewScale[1] );
3587 This implementation synchronizes OCC view's camera propreties.
3589 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
3591 bool blocked = blockSignals( true );
3593 SUIT_CameraProperties aProps = theView->cameraProperties();
3594 if ( !cameraProperties().isCompatible( aProps ) ) {
3595 // other view, this one is being currently synchronized to, seems has become incompatible
3596 // we have to break synchronization
3601 Handle(V3d_View) aDestView = getViewPort()->getView();
3603 aDestView->SetImmediateUpdate( Standard_False );
3606 double aPosition[3];
3607 double aFocalPoint[3];
3608 double anAxialScale[3];
3610 // get common properties
3611 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3612 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
3613 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3614 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3616 #if OCC_VERSION_LARGE > 0x06070100
3617 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3618 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
3619 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3620 aDestView->Camera()->SetScale( aProps.getMappingScale() );
3622 gp_Dir aProjDir( aPosition[0] - aFocalPoint[0],
3623 aPosition[1] - aFocalPoint[1],
3624 aPosition[2] - aFocalPoint[2] );
3626 // get custom view translation
3627 Standard_Real aTranslation[3];
3628 aDestView->At( aTranslation[0], aTranslation[1], aTranslation[2] );
3630 gp_Dir aLeftDir = gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] )
3631 ^ gp_Dir( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
3634 aTrsf.SetValue( 1, 1, aLeftDir.X() );
3635 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
3636 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
3638 aTrsf.SetValue( 1, 2, anUpDir[0] );
3639 aTrsf.SetValue( 2, 2, anUpDir[1] );
3640 aTrsf.SetValue( 3, 2, anUpDir[2] );
3642 aTrsf.SetValue( 1, 3, aProjDir.X() );
3643 aTrsf.SetValue( 2, 3, aProjDir.Y() );
3644 aTrsf.SetValue( 3, 3, aProjDir.Z() );
3646 aTrsf.SetValue( 1, 4, aTranslation[0] );
3647 aTrsf.SetValue( 2, 4, aTranslation[1] );
3648 aTrsf.SetValue( 3, 4, aTranslation[2] );
3651 // transform to view-space coordinate system
3652 gp_XYZ aProjRef( aPosition[0], aPosition[1], aPosition[2] );
3653 aTrsf.Transforms( aProjRef );
3655 // set view camera properties using low-level approach. this is done
3656 // in order to avoid interference with static variables in v3d view used
3657 // when rotation is in process in another view.
3658 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
3659 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
3661 Graphic3d_Vector aMappingProj( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
3662 Graphic3d_Vector aMappingUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3664 aMappingProj.Normalize();
3665 aMappingUp.Normalize();
3667 anOrientation.SetViewReferencePlane( aMappingProj );
3668 anOrientation.SetViewReferenceUp( aMappingUp );
3670 aDestView->SetViewMapping( aMapping );
3671 aDestView->SetViewOrientation( anOrientation );
3674 aDestView->SetCenter( aProjRef.X(), aProjRef.Y() );
3676 // set mapping scale
3677 double aMapScaling = aProps.getMappingScale();
3678 Standard_Real aWidth, aHeight;
3679 aDestView->Size( aWidth, aHeight );
3680 aDestView->SetSize ( aWidth > aHeight ? aMapScaling * (aWidth / aHeight) : aMapScaling );
3683 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3684 #if OCC_VERSION_LARGE <= 0x07000000
3685 aDestView->ZFitAll();
3687 aDestView->SetImmediateUpdate( Standard_True );
3688 aDestView->Redraw();
3690 blockSignals( blocked );
3694 \brief Indicates whether preselection is enabled
3695 \return true if preselection is enabled
3697 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
3699 return myPreselectionEnabled;
3703 \brief Enables/disables preselection
3704 \param theIsToEnable if true - preselection will be enabled
3706 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
3708 onSwitchPreselection( theIsToEnable );
3712 \brief Indicates whether selection is enabled
3713 \return true if selection is enabled
3715 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3717 return mySelectionEnabled;
3721 \brief Enables/disables selection
3722 \param theIsToEnable if true - selection will be enabled
3724 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3726 onSwitchSelection( theIsToEnable );
3731 \brief called if clipping operation is activated / deactivated.
3733 Enables/disables clipping plane displaying.
3735 \parma on action state
3737 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3739 if(!myModel) return;
3740 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3743 if (!aClippingDlg) {
3744 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3745 myModel->setClippingDlg(aClippingDlg);
3747 if (!aClippingDlg->isVisible())
3748 aClippingDlg->show();
3750 if ( aClippingDlg ) {
3751 aClippingDlg->close();
3752 myModel->setClippingDlg(0);
3756 SUIT_ViewManager* mgr = getViewManager();
3758 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3759 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3760 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3761 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3763 QAction* a = toolMgr()->action( ClippingId );
3765 if(theIsOn != a->isChecked()){
3766 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3767 a->setChecked(theIsOn);
3768 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3775 void OCCViewer_ViewWindow::onRayTracing()
3777 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_RayTracingDlg::getName() ) ) {
3778 QDialog* aDlg = new OCCViewer_RayTracingDlg( this );
3784 void OCCViewer_ViewWindow::onEnvTexture()
3786 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_EnvTextureDlg::getName() ) ) {
3787 QDialog* aDlg = new OCCViewer_EnvTextureDlg( this );
3793 void OCCViewer_ViewWindow::onLightSource()
3795 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_LightSourceDlg::getName() ) ) {
3796 QDialog* aDlg = new OCCViewer_LightSourceDlg( this, myModel );