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>
120 // To avoid conflict between KeyPress from the X.h (define KeyPress 2)
121 // and QEvent::KeyPress (qevent.h)
126 // Enable ray tracing features
127 #define ENABLE_RAY_TRACING
129 const char* imageZoomCursor[] = {
134 "................................",
135 "................................",
136 ".#######........................",
137 "..aaaaaaa.......................",
138 "................................",
139 ".............#####..............",
140 "...........##.aaaa##............",
141 "..........#.aa.....a#...........",
142 ".........#.a.........#..........",
143 ".........#a..........#a.........",
144 "........#.a...........#.........",
145 "........#a............#a........",
146 "........#a............#a........",
147 "........#a............#a........",
148 "........#a............#a........",
149 ".........#...........#.a........",
150 ".........#a..........#a.........",
151 ".........##.........#.a.........",
152 "........#####.....##.a..........",
153 ".......###aaa#####.aa...........",
154 "......###aa...aaaaa.......#.....",
155 ".....###aa................#a....",
156 "....###aa.................#a....",
157 "...###aa...............#######..",
158 "....#aa.................aa#aaaa.",
159 ".....a....................#a....",
160 "..........................#a....",
161 "...........................a....",
162 "................................",
163 "................................",
164 "................................",
165 "................................"};
167 const char* imageRotateCursor[] = {
172 "................................",
173 "................................",
174 "................................",
175 "................................",
176 "........#.......................",
177 ".......#.a......................",
178 "......#######...................",
179 ".......#aaaaa#####..............",
180 "........#..##.a#aa##........##..",
181 ".........a#.aa..#..a#.....##.aa.",
182 ".........#.a.....#...#..##.aa...",
183 ".........#a.......#..###.aa.....",
184 "........#.a.......#a..#aa.......",
185 "........#a.........#..#a........",
186 "........#a.........#a.#a........",
187 "........#a.........#a.#a........",
188 "........#a.........#a.#a........",
189 ".........#.........#a#.a........",
190 "........##a........#a#a.........",
191 "......##.a#.......#.#.a.........",
192 "....##.aa..##.....##.a..........",
193 "..##.aa.....a#####.aa...........",
194 "...aa.........aaa#a.............",
195 "................#.a.............",
196 "...............#.a..............",
197 "..............#.a...............",
198 "...............a................",
199 "................................",
200 "................................",
201 "................................",
202 "................................",
203 "................................"};
205 const char* imageCrossCursor[] = {
210 "................................",
211 "................................",
212 "................................",
213 "................................",
214 "................................",
215 "................................",
216 "................................",
217 "...............#................",
218 "...............#a...............",
219 "...............#a...............",
220 "...............#a...............",
221 "...............#a...............",
222 "...............#a...............",
223 "...............#a...............",
224 "...............#a...............",
225 ".......#################........",
226 "........aaaaaaa#aaaaaaaaa.......",
227 "...............#a...............",
228 "...............#a...............",
229 "...............#a...............",
230 "...............#a...............",
231 "...............#a...............",
232 "...............#a...............",
233 "...............#a...............",
234 "................a...............",
235 "................................",
236 "................................",
237 "................................",
238 "................................",
239 "................................",
240 "................................",
241 "................................"};
246 \param theDesktop main window of application
247 \param theModel OCC 3D viewer
249 OCCViewer_ViewWindow::OCCViewer_ViewWindow( SUIT_Desktop* theDesktop,
250 OCCViewer_Viewer* theModel )
251 : SUIT_ViewWindow( theDesktop )
255 myEnableDrawMode = false;
256 myDrawRectEnabled = true;
258 updateEnabledDrawMode();
260 mySetRotationPointDlg = 0;
263 IsSketcherStyle = false;
270 myInteractionStyle = SUIT_ViewModel::STANDARD;
271 myPreselectionEnabled = true;
272 mySelectionEnabled = true;
274 myCursorIsHand = false;
282 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
285 qDeleteAll( mySketchers );
289 \brief Internal initialization.
291 void OCCViewer_ViewWindow::initLayout()
293 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
294 myViewPort->installEventFilter(this);
295 setCentralWidget(myViewPort);
296 myOperation = NOTHING;
298 myCurrPointType = BBCENTER;
299 myPrevPointType = BBCENTER;
300 mySelectedPoint = gp_Pnt(0.,0.,0.);
301 myRotationPointSelection = false;
303 setTransformRequested ( NOTHING );
304 setTransformInProcess ( false );
321 // Graduated axes dialog
322 QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
323 myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
324 myCubeAxesDlg->initialize();
326 connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
329 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
331 return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
335 \brief Detect viewer operation according the the mouse button pressed
336 and key modifiers used.
337 \param theEvent mouse event
338 \return type of the operation
340 OCCViewer_ViewWindow::OperationType
341 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
343 OperationType aOp = NOTHING;
344 SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
345 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
346 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
348 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
349 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
351 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
352 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
353 (my2dMode == No2dMode))
360 \brief Customize event handling
361 \param watched event receiver object
363 \return \c true if the event processing should be stopped
365 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
367 if ( watched == myViewPort ) {
368 int aType = e->type();
370 case QEvent::MouseButtonPress:
371 vpMousePressEvent((QMouseEvent*) e);
374 case QEvent::MouseButtonRelease:
375 vpMouseReleaseEvent((QMouseEvent*) e);
378 case QEvent::MouseMove:
379 vpMouseMoveEvent((QMouseEvent*) e);
382 case QEvent::MouseButtonDblClick:
383 emit mouseDoubleClicked(this, (QMouseEvent*)e);
388 QWheelEvent* aEvent = (QWheelEvent*) e;
390 if ( aEvent->modifiers().testFlag(Qt::ControlModifier) ) {
391 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
392 if ( isPreselectionEnabled() && ic->HasOpenedContext() ) {
393 if ( aEvent->delta() > 0 ) {
394 ic->HilightNextDetected( myViewPort->getView() );
396 ic->HilightPreviousDetected( myViewPort->getView() );
401 emit vpTransformationStarted ( ZOOMVIEW );
402 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
403 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
406 int x1 = (int)( aEvent->x() + width()*delta/100 );
407 int y1 = (int)( aEvent->y() + height()*delta/100 );
408 myViewPort->zoom( x, y, x1, y1 );
409 myViewPort->getView()->ZFitAll();
410 emit vpTransformationFinished ( ZOOMVIEW );
415 case QEvent::ContextMenu:
417 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
418 if ( aEvent->reason() != QContextMenuEvent::Mouse )
419 emit contextMenuRequested( aEvent );
423 case QEvent::KeyPress:
424 emit keyPressed(this, (QKeyEvent*) e);
431 return SUIT_ViewWindow::eventFilter(watched, e);
435 \brief Enable / disable draw rect (rubber band) mode
437 bool OCCViewer_ViewWindow::enableDrawMode( bool on )
439 bool prev = myDrawRectEnabled;
440 myDrawRectEnabled = on;
441 updateEnabledDrawMode();
446 \brief Update state of enable draw mode state.
448 void OCCViewer_ViewWindow::updateEnabledDrawMode()
450 myEnableDrawMode = myDrawRectEnabled;
452 myEnableDrawMode = myEnableDrawMode && myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
456 \brief Handle mouse press event
457 \param theEvent mouse event
459 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
461 myStartX = theEvent->x();
462 myStartY = theEvent->y();
463 int anInteractionStyle = interactionStyle();
465 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
466 // which are assigned for pan and rotate - these operations are activated immediately after pressing
467 // of the first button, so it is necessary to switch to zoom when the second button is pressed
468 bool aSwitchToZoom = false;
469 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
470 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
471 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
474 switch ( myOperation ) {
476 if ( theEvent->button() == Qt::LeftButton )
477 emit vpTransformationStarted ( WINDOWFIT );
481 if ( theEvent->button() == Qt::LeftButton )
482 emit vpTransformationStarted ( PANGLOBAL );
486 if ( theEvent->button() == Qt::LeftButton ) {
487 myViewPort->startZoomAtPoint( myStartX, myStartY );
488 emit vpTransformationStarted ( ZOOMVIEW );
493 if ( aSwitchToZoom ) {
494 myViewPort->startZoomAtPoint( myStartX, myStartY );
497 else if ( theEvent->button() == Qt::LeftButton )
498 emit vpTransformationStarted ( PANVIEW );
502 if ( aSwitchToZoom ) {
503 myViewPort->startZoomAtPoint( myStartX, myStartY );
506 else if ( theEvent->button() == Qt::LeftButton ) {
507 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
508 emit vpTransformationStarted ( ROTATE );
513 /* Try to activate a transformation */
514 OperationType aState;
515 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
516 aState = getButtonState(theEvent, anInteractionStyle);
518 aState = OCCViewer_ViewWindow::NOTHING;
523 myViewPort->startZoomAtPoint( myStartX, myStartY );
531 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
534 if ( myRotationPointSelection )
536 if ( theEvent->button() == Qt::LeftButton )
538 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
540 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
542 TopoDS_Shape aShape = ic->SelectedShape();
543 GProp_GProps aSystem;
545 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
547 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
549 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE )
551 BRepGProp::LinearProperties( aShape, aSystem );
552 aPnt = aSystem.CentreOfMass();
554 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE )
556 BRepGProp::SurfaceProperties( aShape, aSystem );
557 aPnt = aSystem.CentreOfMass();
559 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID )
561 BRepGProp::VolumeProperties( aShape, aSystem );
562 aPnt = aSystem.CentreOfMass();
566 myCurrPointType = myPrevPointType;
570 if ( mySetRotationPointDlg )
572 myRotationPointSelection = false;
573 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
576 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
577 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
578 ic->CloseAllContexts();
579 myOperation = NOTHING;
580 myViewPort->setCursor( myCursor );
581 myCursorIsHand = false;
582 myRotationPointSelection = false;
586 emit mousePressed(this, theEvent);
589 /* notify that we start a transformation */
590 if ( transformRequested() )
591 emit vpTransformationStarted ( myOperation );
593 if ( transformRequested() )
594 setTransformInProcess( true );
596 /* we may need it for sketching... */
597 if ( l_mbPressEvent )
598 delete l_mbPressEvent;
599 l_mbPressEvent = new QMouseEvent( *theEvent );
604 \brief Start zooming operation.
606 Sets the corresponding cursor for the widget.
608 void OCCViewer_ViewWindow::activateZoom()
610 if ( !transformRequested() && !myCursorIsHand )
611 saveCursor(); /* save old cursor */
613 if ( myOperation != ZOOMVIEW ) {
614 QPixmap zoomPixmap (imageZoomCursor);
615 QCursor zoomCursor (zoomPixmap);
616 if( setTransformRequested ( ZOOMVIEW ) )
617 myViewPort->setCursor( zoomCursor );
623 \brief Start panning operation.
625 Sets the corresponding cursor for the widget.
627 void OCCViewer_ViewWindow::activatePanning()
629 if ( !transformRequested() && !myCursorIsHand )
630 saveCursor(); // save old cursor
632 if ( myOperation != PANVIEW ) {
633 QCursor panCursor (Qt::SizeAllCursor);
634 if( setTransformRequested ( PANVIEW ) )
635 myViewPort->setCursor( panCursor );
640 \brief Start rotation operation
642 Sets the corresponding cursor for the widget.
644 void OCCViewer_ViewWindow::activateRotation()
646 if ( !transformRequested() && !myCursorIsHand )
647 saveCursor(); // save old cursor
649 if ( myOperation != ROTATE ) {
650 QPixmap rotatePixmap (imageRotateCursor);
651 QCursor rotCursor (rotatePixmap);
652 if( setTransformRequested ( ROTATE ) )
653 myViewPort->setCursor( rotCursor );
658 \brief Compute the gravity center.
659 \param theX used to return X coordinate of the gravity center
660 \param theY used to return Y coordinate of the gravity center
661 \param theZ used to return Z coordinate of the gravity center
662 \return \c true if the gravity center is computed
664 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
666 Handle(V3d_View) aView3d = myViewPort->getView();
668 // Project boundaries points and add to avergae gravity
669 // the ones which lie within the screen limits
670 Standard_Real aScreenLimits[4] = { 0.0, 0.0, 0.0, 0.0 };
672 #if OCC_VERSION_LARGE > 0x06070100
673 // NDC space screen limits
674 aScreenLimits[0] = -1.0;
675 aScreenLimits[1] = 1.0;
676 aScreenLimits[2] = -1.0;
677 aScreenLimits[3] = 1.0;
679 aView3d->View()->ViewMapping().WindowLimit( aScreenLimits[0],
685 Standard_Integer aPointsNb = 0;
687 Standard_Real aXmin = 0.0;
688 Standard_Real aYmin = 0.0;
689 Standard_Real aZmin = 0.0;
690 Standard_Real aXmax = 0.0;
691 Standard_Real aYmax = 0.0;
692 Standard_Real aZmax = 0.0;
694 Graphic3d_MapOfStructure aSetOfStructures;
695 aView3d->View()->DisplayedStructures( aSetOfStructures );
696 Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures );
698 for( ; aStructureIt.More(); aStructureIt.Next() ) {
699 const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key();
700 if ( aStructure->IsEmpty() || !aStructure->IsVisible() || aStructure->CStructure()->IsForHighlight )
703 #if OCC_VERSION_LARGE > 0x06070100
704 Bnd_Box aBox = aStructure->MinMaxValues();
705 aXmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().X();
706 aYmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Y();
707 aZmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Z();
708 aXmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().X();
709 aYmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Y();
710 aZmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Z();
712 aStructure->MinMaxValues( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
715 // Infinite structures are skipped
716 Standard_Real aLIM = ShortRealLast() - 1.0;
717 if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
718 || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
722 gp_Pnt aPoints[8] = {
723 gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
724 gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
725 gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
726 gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
729 for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
730 const gp_Pnt& aBBPoint = aPoints[aPointIt];
732 #if OCC_VERSION_LARGE > 0x06070100
733 gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
734 const Standard_Real& U = aProjected.X();
735 const Standard_Real& V = aProjected.Y();
737 Standard_Real U = 0.0;
738 Standard_Real V = 0.0;
739 Standard_Real W = 0.0;
740 aView3d->View()->Projects( aBBPoint.X(), aBBPoint.Y(), aBBPoint.Z(), U, V, W );
743 if (U >= aScreenLimits[0]
744 && U <= aScreenLimits[1]
745 && V >= aScreenLimits[2]
746 && V <= aScreenLimits[3])
749 theX += aBBPoint.X();
750 theY += aBBPoint.Y();
751 theZ += aBBPoint.Z();
766 \brief Set the gravity center as a rotation point.
768 void OCCViewer_ViewWindow::activateSetRotationGravity()
770 if ( myRotationPointSelection )
772 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
773 ic->CloseAllContexts();
774 myOperation = NOTHING;
775 myViewPort->setCursor( myCursor );
776 myCursorIsHand = false;
777 myRotationPointSelection = false;
780 myPrevPointType = myCurrPointType;
781 myCurrPointType = BBCENTER;
783 Standard_Real Xcenter, Ycenter, Zcenter;
784 if ( OCCViewer_Utilities::computeVisibleBBCenter( myViewPort->getView(), Xcenter, Ycenter, Zcenter ) )
785 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
789 \brief Update gravity center in the "Set Rotation Point" dialog box.
790 \sa OCCViewer_SetRotationPointDlg class
792 void OCCViewer_ViewWindow::updateGravityCoords()
794 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == BBCENTER )
796 Standard_Real Xcenter, Ycenter, Zcenter;
797 if ( OCCViewer_Utilities::computeVisibleBBCenter( myViewPort->getView(), Xcenter, Ycenter, Zcenter ) )
798 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
803 \brief Set the point selected by the user as a rotation point.
804 \param theX X coordinate of the rotation point
805 \param theY Y coordinate of the rotation point
806 \param theZ Z coordinate of the rotation point
808 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
810 if ( myRotationPointSelection )
812 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
813 ic->CloseAllContexts();
814 myOperation = NOTHING;
815 myViewPort->setCursor( myCursor );
816 myCursorIsHand = false;
817 myRotationPointSelection = false;
820 myPrevPointType = myCurrPointType;
821 myCurrPointType = SELECTED;
822 mySelectedPoint.SetCoord(theX,theY,theZ);
826 \brief Start the shape selection process.
828 void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
830 myPrevPointType = myCurrPointType;
831 myCurrPointType = SELECTED;
833 // activate selection ------>
834 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
836 ic->OpenLocalContext();
838 AIS_ListOfInteractive aList;
839 ic->DisplayedObjects( aList );
840 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
842 Handle(AIS_InteractiveObject) anObj = it.Value();
843 if ( !anObj.IsNull() && anObj->HasPresentation() &&
844 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
847 ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
850 // activate selection <------
852 if ( !myCursorIsHand )
854 QCursor handCursor (Qt::PointingHandCursor);
855 myCursorIsHand = true;
857 myViewPort->setCursor( handCursor );
859 myRotationPointSelection = true;
863 \brief Start global panning operation
865 Sets the corresponding cursor for the widget.
867 void OCCViewer_ViewWindow::activateGlobalPanning()
869 Handle(V3d_View) aView3d = myViewPort->getView();
870 if ( !aView3d.IsNull() ) {
871 QPixmap globalPanPixmap (imageCrossCursor);
872 QCursor glPanCursor (globalPanPixmap);
873 myCurScale = aView3d->Scale();
874 aView3d->FitAll(0.01, false);
875 saveCursor(); // save old cursor
876 myViewPort->fitAll(); // fits view before selecting a new scene center
877 if( setTransformRequested( PANGLOBAL ) )
878 myViewPort->setCursor( glPanCursor );
883 \brief Starts fit operation.
885 Sets the corresponding cursor for the widget.
887 void OCCViewer_ViewWindow::activateWindowFit()
889 if ( !transformRequested() && !myCursorIsHand )
890 saveCursor(); /* save old cursor */
892 if ( myOperation != WINDOWFIT ) {
893 QCursor handCursor (Qt::PointingHandCursor);
894 if( setTransformRequested ( WINDOWFIT ) )
896 myViewPort->setCursor ( handCursor );
897 myCursorIsHand = true;
903 \brief Start delayed viewer operation.
905 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
907 bool ok = transformEnabled( op );
908 myOperation = ok ? op : NOTHING;
909 myViewPort->setMouseTracking( myOperation == NOTHING );
914 \brief Handle mouse move event.
915 \param theEvent mouse event
917 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
919 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
921 switch ( getButtonState( theEvent, interactionStyle() ) ) {
923 myViewPort->startZoomAtPoint( myStartX, myStartY );
931 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
938 myCurrX = theEvent->x();
939 myCurrY = theEvent->y();
940 switch (myOperation) {
942 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
946 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
952 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
966 if ( myRotationPointSelection || isSketcherStyle() )
968 emit mouseMoving( this, theEvent );
972 int aState = theEvent->modifiers();
973 int aButton = theEvent->buttons();
974 int anInteractionStyle = interactionStyle();
975 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
976 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
977 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
978 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
979 myDrawRect = myEnableDrawMode;
982 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
983 QCursor handCursor (Qt::PointingHandCursor);
984 myCursorIsHand = true;
986 myViewPort->setCursor( handCursor );
989 emit mouseMoving( this, theEvent );
991 else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
992 aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
993 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
994 aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
995 OCCViewer_ViewSketcher* sketcher = 0;
996 QList<OCCViewer_ViewSketcher*>::Iterator it;
997 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
999 OCCViewer_ViewSketcher* sk = (*it);
1000 if( sk->isDefault() && sk->sketchButton() == aButton )
1003 if ( sketcher && myCurSketch == -1 )
1005 activateSketching( sketcher->type() );
1008 myCurSketch = mypSketcher->sketchButton();
1010 if ( l_mbPressEvent )
1012 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
1013 delete l_mbPressEvent;
1016 QApplication::sendEvent( getViewPort(), theEvent );
1021 emit mouseMoving( this, theEvent );
1027 \brief Handle mouse release event.
1028 \param theEvent mouse event
1030 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
1032 switch ( myOperation ) {
1035 int prevState = myCurSketch;
1036 if(theEvent->button() == Qt::RightButton)
1038 QList<OCCViewer_ViewSketcher*>::Iterator it;
1039 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
1041 OCCViewer_ViewSketcher* sk = (*it);
1042 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
1047 emit mouseReleased(this, theEvent);
1048 if(theEvent->button() == Qt::RightButton && prevState == -1)
1050 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1051 theEvent->pos(), theEvent->globalPos() );
1052 emit contextMenuRequested( &aEvent );
1057 myViewPort->endRotation();
1063 myViewPort->getView()->ZFitAll();
1068 if ( theEvent->button() == Qt::LeftButton ) {
1069 myViewPort->setCenter( theEvent->x(), theEvent->y() );
1070 myViewPort->getView()->SetScale(myCurScale);
1076 if ( theEvent->button() == Qt::LeftButton ) {
1077 myCurrX = theEvent->x();
1078 myCurrY = theEvent->y();
1080 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1081 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1088 // NOTE: viewer 3D detects a rectangle of selection using this event
1089 // so we must emit it BEFORE resetting the selection rectangle
1091 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1095 myViewPort->update();
1098 if ( l_mbPressEvent )
1100 delete l_mbPressEvent;
1106 \brief Reset the viewport to its initial state
1107 ( no transformations in process etc. )
1109 void OCCViewer_ViewWindow::resetState()
1113 if ( myRotationPointSelection )
1115 QCursor handCursor (Qt::PointingHandCursor);
1116 myViewPort->setCursor( handCursor );
1120 if ( transformRequested() || myCursorIsHand )
1121 myViewPort->setCursor( myCursor );
1122 myCursorIsHand = false;
1125 if ( transformRequested() )
1126 emit vpTransformationFinished (myOperation);
1128 setTransformInProcess( false );
1129 setTransformRequested( NOTHING );
1134 \brief Draw rubber band rectangle.
1136 void OCCViewer_ViewWindow::drawRect()
1138 if ( !myRectBand ) {
1139 myRectBand = new QtxRectRubberBand( myViewPort );
1141 //palette.setColor(myRectBand->foregroundRole(), Qt::white);
1142 //myRectBand->setPalette(palette);
1144 //myRectBand->hide();
1146 myRectBand->setUpdatesEnabled ( false );
1147 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1148 myRectBand->initGeometry( aRect );
1150 if ( !myRectBand->isVisible() )
1153 myRectBand->setUpdatesEnabled ( true );
1154 //myRectBand->repaint();
1156 //myRectBand->setVisible( aRect.isValid() );
1157 //if ( myRectBand->isVisible() )
1158 // myRectBand->repaint();
1160 // myRectBand->show();
1161 //myRectBand->repaint();
1165 \brief Clear rubber band rectangle on the end on the dragging operation.
1167 void OCCViewer_ViewWindow::endDrawRect()
1169 //delete myRectBand;
1173 myRectBand->clearGeometry();
1179 \brief Create actions.
1181 void OCCViewer_ViewWindow::createActions()
1183 if( !toolMgr()->isEmpty() )
1186 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1193 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1194 tr( "MNU_DUMP_VIEW" ), 0, this);
1195 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1196 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1197 toolMgr()->registerAction( aAction, DumpId );
1200 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1201 tr( "MNU_FITALL" ), 0, this);
1202 aAction->setStatusTip(tr("DSC_FITALL"));
1203 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1204 toolMgr()->registerAction( aAction, FitAllId );
1207 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1208 tr( "MNU_FITRECT" ), 0, this);
1209 aAction->setStatusTip(tr("DSC_FITRECT"));
1210 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1211 toolMgr()->registerAction( aAction, FitRectId );
1214 aAction = new QtxAction(tr("MNU_FITSELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITSELECTION" ) ),
1215 tr( "MNU_FITSELECTION" ), 0, this);
1216 aAction->setStatusTip(tr("DSC_FITSELECTION"));
1217 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
1218 toolMgr()->registerAction( aAction, FitSelectionId );
1221 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1222 tr( "MNU_ZOOM_VIEW" ), 0, this);
1223 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1224 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1225 toolMgr()->registerAction( aAction, ZoomId );
1228 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1229 tr( "MNU_PAN_VIEW" ), 0, this);
1230 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1231 connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
1232 toolMgr()->registerAction( aAction, PanId );
1235 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1236 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1237 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1238 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1239 toolMgr()->registerAction( aAction, GlobalPanId );
1242 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1243 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1244 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1245 mySetRotationPointAction->setCheckable( true );
1246 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1247 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1250 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1251 tr( "MNU_ROTATE_VIEW" ), 0, this);
1252 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1253 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1254 toolMgr()->registerAction( aAction, RotationId );
1257 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1258 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1259 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1260 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1261 this->addAction(aAction);
1262 toolMgr()->registerAction( aAction, FrontId );
1264 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1265 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1266 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1267 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1268 this->addAction(aAction);
1269 toolMgr()->registerAction( aAction, BackId );
1271 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1272 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1273 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1274 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1275 this->addAction(aAction);
1276 toolMgr()->registerAction( aAction, TopId );
1278 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1279 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1280 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1281 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1282 this->addAction(aAction);
1283 toolMgr()->registerAction( aAction, BottomId );
1285 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1286 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1287 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1288 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1289 this->addAction(aAction);
1290 toolMgr()->registerAction( aAction, LeftId );
1292 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1293 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1294 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1295 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1296 this->addAction(aAction);
1297 toolMgr()->registerAction( aAction, RightId );
1299 // rotate anticlockwise
1300 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1301 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1302 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1303 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1304 this->addAction(aAction);
1305 toolMgr()->registerAction( aAction, AntiClockWiseId );
1308 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1309 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1310 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1311 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1312 this->addAction(aAction);
1313 toolMgr()->registerAction( aAction, ClockWiseId );
1315 // Projection mode group
1317 // - orthographic projection
1318 aAction = new QtxAction(tr("MNU_ORTHOGRAPHIC_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ORTHOGRAPHIC" ) ),
1319 tr( "MNU_ORTHOGRAPHIC_MODE" ), 0, this);
1320 aAction->setStatusTip(tr("DSC_ORTHOGRAPHIC_MODE"));
1321 aAction->setCheckable(true);
1322 toolMgr()->registerAction( aAction, OrthographicId );
1324 // - perspective projection
1325 aAction = new QtxAction(tr("MNU_PERSPECTIVE_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PERSPECTIVE" ) ),
1326 tr( "MNU_PERSPECTIVE_MODE" ), 0, this);
1327 aAction->setStatusTip(tr("DSC_PERSPECTIVE_MODE"));
1328 aAction->setCheckable(true);
1329 toolMgr()->registerAction( aAction, PerspectiveId );
1330 #if OCC_VERSION_LARGE > 0x06090000
1331 // - stereo projection
1332 aAction = new QtxAction(tr("MNU_STEREO_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STEREO" ) ),
1333 tr( "MNU_STEREO_MODE" ), 0, this);
1334 aAction->setStatusTip(tr("DSC_STEREO_MODE"));
1335 aAction->setCheckable(true);
1336 toolMgr()->registerAction( aAction, StereoId );
1337 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onStereoType(bool)));
1339 // - add exclusive action group
1340 QActionGroup* aProjectionGroup = new QActionGroup( this );
1341 aProjectionGroup->addAction( toolMgr()->action( OrthographicId ) );
1342 aProjectionGroup->addAction( toolMgr()->action( PerspectiveId ) );
1343 connect(aProjectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProjectionType(QAction*)));
1346 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1347 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1348 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1349 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1350 this->addAction(aAction);
1351 toolMgr()->registerAction( aAction, ResetId );
1354 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1355 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1356 tr("MNU_CLONE_VIEW"), 0, this);
1357 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1358 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1359 toolMgr()->registerAction( aAction, CloneId );
1361 aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
1362 tr("MNU_CLIPPING"), 0, this);
1363 aAction->setStatusTip (tr("DSC_CLIPPING"));
1364 aAction->setCheckable (true);
1365 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1366 toolMgr()->registerAction (aAction, ClippingId);
1368 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1369 tr( "MNU_SHOOT_VIEW" ), 0, this);
1370 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1371 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1372 toolMgr()->registerAction( aAction, MemId );
1374 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1375 tr( "MNU_PRESETS_VIEW" ), 0, this);
1376 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1377 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1378 toolMgr()->registerAction( aAction, RestoreId );
1380 if (myModel->trihedronActivated()) {
1381 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1382 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1383 aAction->setCheckable( true );
1384 aAction->setChecked( true );
1385 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1386 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1387 toolMgr()->registerAction( aAction, TrihedronShowId );
1391 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1392 tr( "MNU_SCALING" ), 0, this);
1393 aAction->setStatusTip(tr("DSC_SCALING"));
1394 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1395 toolMgr()->registerAction( aAction, AxialScaleId );
1397 // Enable/disable preselection
1398 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1399 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1400 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1401 aAction->setCheckable(true);
1402 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1403 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1405 // Enable/disable selection
1406 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1407 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1408 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1409 aAction->setCheckable(true);
1410 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1411 toolMgr()->registerAction( aAction, SwitchSelectionId );
1414 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1415 tr( "MNU_GRADUATED_AXES" ), 0, this);
1416 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1417 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1418 toolMgr()->registerAction( aAction, GraduatedAxesId );
1420 // Active only ambient light or not
1421 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1422 tr( "MNU_AMBIENT" ), 0, this);
1423 aAction->setStatusTip(tr("DSC_AMBIENT"));
1424 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1425 toolMgr()->registerAction( aAction, AmbientId );
1427 // Switch between interaction styles
1428 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1429 tr( "MNU_STYLE_SWITCH" ), 0, this);
1430 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1431 aAction->setCheckable(true);
1432 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1433 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1435 // Switch between zooming styles
1436 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1437 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1438 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1439 aAction->setCheckable(true);
1440 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1441 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1444 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1445 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1446 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1447 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1448 toolMgr()->registerAction( aAction, MaximizedId );
1450 // Return to 3d view
1451 if (my2dMode!=No2dMode){
1452 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1453 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1454 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1455 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1456 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1460 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1461 #ifdef ENABLE_RAY_TRACING
1463 aAction = new QtxAction( tr("MNU_RAY_TRACING"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_RAY_TRACING") ),
1464 tr("MNU_RAY_TRACING"), 0, this );
1465 aAction->setStatusTip( tr("DSC_RAY_TRACING") );
1466 connect( aAction, SIGNAL( triggered() ), this, SLOT( onRayTracing() ) );
1467 toolMgr()->registerAction( aAction, RayTracingId );
1469 // Environment texture
1470 aAction = new QtxAction( tr("MNU_ENV_TEXTURE"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_ENV_TEXTURE") ),
1471 tr("MNU_ENV_TEXTURE"), 0, this );
1472 aAction->setStatusTip( tr("DSC_ENV_TEXTURE") );
1473 connect( aAction, SIGNAL( triggered() ), this, SLOT( onEnvTexture() ) );
1474 toolMgr()->registerAction( aAction, EnvTextureId );
1477 aAction = new QtxAction( tr("MNU_LIGHT_SOURCE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_LIGHT_SOURCE" ) ),
1478 tr( "MNU_LIGHT_SOURCE" ), 0, this );
1479 aAction->setStatusTip( tr("DSC_LIGHT_SOURCE") );
1480 connect( aAction, SIGNAL( triggered() ), this, SLOT( onLightSource() ) );
1481 toolMgr()->registerAction( aAction, LightSourceId );
1486 \brief Create toolbar.
1488 void OCCViewer_ViewWindow::createToolBar()
1490 static const char* titles[] = {
1491 "LBL_3DTOOLBAR_LABEL",
1492 "LBL_XYTOOLBAR_LABEL",
1493 "LBL_XZTOOLBAR_LABEL",
1494 "LBL_YZTOOLBAR_LABEL",
1496 static const char* names[] = {
1497 "OCCViewer3DViewOperations",
1498 "OCCViewerXYViewOperations",
1499 "OCCViewerXZViewOperations",
1500 "OCCViewerYZViewOperations",
1502 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1503 QString( names[my2dMode] ), // name (language-independant)
1504 false ); // disable floatable toolbar
1505 if ( my2dMode != No2dMode ){
1506 toolMgr()->append( ReturnTo3dViewId, tid );
1507 toolMgr()->append( toolMgr()->separator(), tid );
1509 toolMgr()->append( DumpId, tid );
1510 toolMgr()->append( SwitchInteractionStyleId, tid );
1511 toolMgr()->append( SwitchZoomingStyleId, tid );
1512 toolMgr()->append( SwitchPreselectionId, tid );
1513 toolMgr()->append( SwitchSelectionId, tid );
1514 if( myModel->trihedronActivated() )
1515 toolMgr()->append( TrihedronShowId, tid );
1517 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1518 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1519 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1520 #if OCC_VERSION_LARGE > 0x06090000
1521 aScaleAction->insertAction( toolMgr()->action( FitSelectionId ) );
1523 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1524 toolMgr()->append( aScaleAction, tid );
1526 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1527 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1528 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1529 toolMgr()->append( aPanningAction, tid );
1531 if (my2dMode == No2dMode) {
1532 toolMgr()->append( ChangeRotationPointId, tid );
1533 toolMgr()->append( RotationId, tid );
1535 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1536 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1537 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1538 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1539 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1540 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1541 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1542 toolMgr()->append( aViewsAction, tid );
1544 toolMgr()->append( AntiClockWiseId, tid );
1545 toolMgr()->append( ClockWiseId, tid );
1547 toolMgr()->append( OrthographicId, tid );
1548 toolMgr()->append( PerspectiveId, tid );
1549 #if OCC_VERSION_LARGE > 0x06090000
1550 toolMgr()->append( StereoId, tid );
1553 toolMgr()->append( ResetId, tid );
1556 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1557 aMemAction->insertAction( toolMgr()->action( MemId ) );
1558 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1559 toolMgr()->append( aMemAction, tid );
1561 toolMgr()->append( toolMgr()->separator(), tid );
1562 toolMgr()->append( CloneId, tid );
1564 toolMgr()->append( toolMgr()->separator(), tid );
1565 toolMgr()->append( ClippingId, tid );
1566 toolMgr()->append( AxialScaleId, tid );
1567 toolMgr()->append( GraduatedAxesId, tid );
1568 toolMgr()->append( AmbientId, tid );
1570 toolMgr()->append( MaximizedId, tid );
1571 toolMgr()->append( SynchronizeId, tid );
1572 #ifdef ENABLE_RAY_TRACING
1573 toolMgr()->append( RayTracingId, tid );
1574 toolMgr()->append( EnvTextureId, tid );
1575 toolMgr()->append( LightSourceId, tid );
1580 \brief Perform 'fit all' operation.
1582 void OCCViewer_ViewWindow::onViewFitAll()
1584 myViewPort->fitAll();
1588 \brief Perform "front view" transformation.
1590 void OCCViewer_ViewWindow::onFrontView()
1592 emit vpTransformationStarted ( FRONTVIEW );
1593 Handle(V3d_View) aView3d = myViewPort->getView();
1594 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
1596 emit vpTransformationFinished ( FRONTVIEW );
1600 \brief Perform "back view" transformation.
1602 void OCCViewer_ViewWindow::onBackView()
1604 emit vpTransformationStarted ( BACKVIEW );
1605 Handle(V3d_View) aView3d = myViewPort->getView();
1606 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
1608 emit vpTransformationFinished ( BACKVIEW );
1612 \brief Perform "top view" transformation.
1614 void OCCViewer_ViewWindow::onTopView()
1616 emit vpTransformationStarted ( TOPVIEW );
1617 Handle(V3d_View) aView3d = myViewPort->getView();
1618 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
1620 emit vpTransformationFinished ( TOPVIEW );
1624 \brief Perform "bottom view" transformation.
1626 void OCCViewer_ViewWindow::onBottomView()
1628 emit vpTransformationStarted ( BOTTOMVIEW );
1629 Handle(V3d_View) aView3d = myViewPort->getView();
1630 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
1632 emit vpTransformationFinished ( BOTTOMVIEW );
1636 \brief Perform "left view" transformation.
1638 void OCCViewer_ViewWindow::onLeftView()
1640 emit vpTransformationStarted ( LEFTVIEW );
1641 Handle(V3d_View) aView3d = myViewPort->getView();
1642 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
1644 emit vpTransformationFinished ( LEFTVIEW );
1648 \brief Perform "right view" transformation.
1650 void OCCViewer_ViewWindow::onRightView()
1652 emit vpTransformationStarted ( RIGHTVIEW );
1653 Handle(V3d_View) aView3d = myViewPort->getView();
1654 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
1656 emit vpTransformationFinished ( RIGHTVIEW );
1660 \brief Rotate view 90 degrees clockwise
1662 void OCCViewer_ViewWindow::onClockWiseView()
1664 emit vpTransformationStarted ( CLOCKWISEVIEW );
1665 myViewPort->rotateXY( 90. );
1666 emit vpTransformationFinished ( CLOCKWISEVIEW );
1670 \brief Rotate view 90 degrees conterclockwise
1672 void OCCViewer_ViewWindow::onAntiClockWiseView()
1674 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1675 myViewPort->rotateXY( -90. );
1676 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1680 \brief Perform "reset view" transformation.
1682 Sets default orientation of the viewport camera.
1684 void OCCViewer_ViewWindow::onResetView()
1686 emit vpTransformationStarted( RESETVIEW );
1687 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1688 myViewPort->getView()->Reset( false );
1689 myViewPort->fitAll( false, true, false );
1690 myViewPort->getView()->SetImmediateUpdate( upd );
1691 onProjectionType(); // needed to apply projection type properly after reset
1692 myViewPort->getView()->Update();
1693 emit vpTransformationFinished( RESETVIEW );
1697 \brief Set the given projection mode.
1699 Set the given projection mode: Orthographic or Perspective.
1701 void OCCViewer_ViewWindow::onProjectionType( QAction* theAction )
1703 Handle(V3d_View) aView3d = myViewPort->getView();
1704 if ( !aView3d.IsNull() ) {
1705 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1706 if (theAction == toolMgr()->action( OrthographicId )) {
1707 myModel->setProjectionType(Orthographic);
1708 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Orthographic );
1709 aCamera->SetFOVy(45.0);
1711 else if (theAction == toolMgr()->action( PerspectiveId )) {
1712 myModel->setProjectionType(Perspective);
1713 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Perspective );
1714 aCamera->SetFOVy(30.0);
1716 #if OCC_VERSION_LARGE > 0x06090000
1717 if (toolMgr()->action( StereoId )->isChecked()) {
1718 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1719 aCamera->SetFOVy(30.0);
1728 \brief Sets Stereo projection mode.
1730 Sets Stereo projection mode.
1732 void OCCViewer_ViewWindow::onStereoType( bool activate )
1734 #if OCC_VERSION_LARGE > 0x06090000
1735 Handle(V3d_View) aView3d = myViewPort->getView();
1736 if ( !aView3d.IsNull() ) {
1737 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1739 toolMgr()->action( PerspectiveId )->setChecked(true);
1740 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1741 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(false);
1743 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1744 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1745 setStereoType( aResMgr->integerValue( "OCCViewer", "stereo_type", 0 ) );
1746 setAnaglyphFilter( aResMgr->integerValue( "OCCViewer", "anaglyph_filter", 0 ) );
1747 setReverseStereo( aResMgr->booleanValue( "OCCViewer", "reverse_stereo", false ) );
1748 setVSync( aResMgr->booleanValue( "OCCViewer", "enable_vsync", true ) );
1749 setQuadBufferSupport( aResMgr->booleanValue( "OCCViewer", "enable_quad_buffer_support", false ) );
1752 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(true);
1753 if (myModel->projectionType() == Orthographic) {
1754 toolMgr()->action( OrthographicId )->setChecked(true);
1755 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Orthographic);
1757 else if (myModel->projectionType() == Perspective) {
1758 toolMgr()->action( PerspectiveId )->setChecked(true);
1759 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1766 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1767 toolMgr()->action( StereoId )->isChecked() )
1768 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1773 \brief Restore the view.
1775 Restore the projection mode based on tool-buttons states.
1777 void OCCViewer_ViewWindow::onProjectionType()
1779 emit vpTransformationStarted( PROJECTION );
1780 if (toolMgr()->action( OrthographicId )->isChecked())
1781 setProjectionType( Orthographic );
1782 if (toolMgr()->action( PerspectiveId )->isChecked())
1783 setProjectionType( Perspective );
1784 #if OCC_VERSION_LARGE > 0x06090000
1785 if (toolMgr()->action( StereoId )->isChecked())
1786 setProjectionType( Stereo );
1788 emit vpTransformationFinished( PROJECTION );
1791 void OCCViewer_ViewWindow::setProjectionType( int mode )
1793 QtxAction* anOrthographicAction = dynamic_cast<QtxAction*>( toolMgr()->action( OrthographicId ) );
1794 QtxAction* aPerspectiveAction = dynamic_cast<QtxAction*>( toolMgr()->action( PerspectiveId ) );
1795 #if OCC_VERSION_LARGE > 0x06090000
1796 QtxAction* aStereoAction = dynamic_cast<QtxAction*>( toolMgr()->action( StereoId ) );
1800 onProjectionType( anOrthographicAction );
1803 onProjectionType( aPerspectiveAction );
1806 onStereoType( true );
1809 // update action state if method is called outside
1810 if ( mode == Orthographic && !anOrthographicAction->isChecked() ) {
1811 anOrthographicAction->setChecked( true );
1812 #if OCC_VERSION_LARGE > 0x06090000
1813 aStereoAction->setChecked( false );
1816 if ( mode == Perspective && !aPerspectiveAction->isChecked() ) {
1817 aPerspectiveAction->setChecked( true );
1818 #if OCC_VERSION_LARGE > 0x06090000
1819 aStereoAction->setChecked( false );
1822 #if OCC_VERSION_LARGE > 0x06090000
1823 if ( mode == Stereo ) {
1824 aStereoAction->setChecked( true );
1825 if ( anOrthographicAction->isEnabled() ) {
1826 anOrthographicAction->setEnabled( false );
1827 anOrthographicAction->setChecked( false );
1828 aStereoAction->setChecked( false );
1831 anOrthographicAction->setEnabled( true );
1832 aStereoAction->setChecked( false );
1833 anOrthographicAction->setChecked(myModel->projectionType() == Orthographic);
1835 if ( aPerspectiveAction->isEnabled() ) {
1836 aPerspectiveAction->setEnabled( false );
1837 aPerspectiveAction->setChecked( true );
1838 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1839 toolMgr()->action( StereoId )->isChecked() )
1840 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1843 aPerspectiveAction->setEnabled( true );
1844 aStereoAction->setChecked( false );
1845 aPerspectiveAction->setChecked(myModel->projectionType() == Perspective);
1850 if ( !anOrthographicAction->isEnabled() )
1851 anOrthographicAction->setEnabled( true );
1852 if ( !aPerspectiveAction->isEnabled() )
1853 aPerspectiveAction->setEnabled( true );
1859 \brief Perform "fit all" transformation.
1861 void OCCViewer_ViewWindow::onFitAll()
1863 emit vpTransformationStarted( FITALLVIEW );
1864 myViewPort->fitAll();
1865 emit vpTransformationFinished( FITALLVIEW );
1869 \brief Perform "fit selection" transformation.
1871 void OCCViewer_ViewWindow::onFitSelection()
1873 emit vpTransformationStarted( FITSELECTION );
1874 #if OCC_VERSION_LARGE > 0x06090000
1875 myModel->getAISContext()->FitSelected( getViewPort()->getView() );
1877 emit vpTransformationFinished( FITSELECTION );
1881 \brief Called if 'change rotation point' operation is activated.
1882 \param on action state
1884 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1888 if (!mySetRotationPointDlg)
1890 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1891 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1894 if (!mySetRotationPointDlg->isVisible())
1896 //if (mySetRotationPointDlg->IsFirstShown())
1897 if (myCurrPointType == BBCENTER)
1899 Standard_Real Xcenter, Ycenter, Zcenter;
1900 if (OCCViewer_Utilities::computeVisibleBBCenter(myViewPort->getView(), Xcenter, Ycenter, Zcenter))
1901 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1903 mySetRotationPointDlg->show();
1908 if (mySetRotationPointDlg->isVisible())
1909 mySetRotationPointDlg->hide();
1914 \brief Create one more window with same content.
1916 void OCCViewer_ViewWindow::onCloneView()
1918 SUIT_ViewWindow* vw = myManager->createViewWindow();
1920 emit viewCloned( vw );
1921 OCCViewer_ViewWindow* occVw = dynamic_cast<OCCViewer_ViewWindow*> (vw);
1922 if(occVw && occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)) {
1923 occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)->synchronize(this);
1928 Creates one more window with same content
1930 void OCCViewer_ViewWindow::onAxialScale()
1932 if ( !myScalingDlg )
1933 myScalingDlg = new OCCViewer_AxialScaleDlg( this , myModel );
1935 if ( !myScalingDlg->isVisible() )
1937 myScalingDlg->Update();
1938 myScalingDlg->show();
1943 Shows Graduated Axes dialog
1945 void OCCViewer_ViewWindow::onGraduatedAxes()
1947 myCubeAxesDlg->Update();
1948 myCubeAxesDlg->show();
1951 void OCCViewer_ViewWindow::onAmbientToogle()
1953 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
1954 viewer->InitDefinedLights();
1955 while(viewer->MoreDefinedLights())
1957 Handle(V3d_Light) light = viewer->DefinedLight();
1958 if(light->Type() != V3d_AMBIENT)
1960 Handle(V3d_View) aView3d = myViewPort->getView();
1961 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
1962 else viewer->SetLightOn(light);
1964 viewer->NextDefinedLights();
1970 \brief Store view parameters.
1972 void OCCViewer_ViewWindow::onMemorizeView()
1974 appendViewAspect( getViewParams() );
1978 \brief Restore view parameters.
1980 void OCCViewer_ViewWindow::onRestoreView()
1982 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
1983 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
1985 updateViewAspects( aDlg->parameters() );
1986 if( myRestoreFlag && aDlg->parameters().count() )
1987 performRestoring( aDlg->currentItem() );
1991 \brief Restore view parameters.
1992 \param anItem view parameters
1994 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
1996 Handle(V3d_View) aView3d = myViewPort->getView();
1998 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
1999 aView3d->SetScale( anItem.scale );
2000 aView3d->SetTwist( anItem.twist );
2001 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
2002 aView3d->SetImmediateUpdate( prev );
2003 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2004 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2005 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
2007 #if OCC_VERSION_LARGE > 0x06070100
2008 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
2010 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
2012 // "eye" and "at" require conversion to represent center panning
2013 // up direction is only available after setting angle of twist and
2014 // other view parameters
2015 aView3d->Up( anUpX, anUpY, anUpZ );
2017 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
2018 gp_Dir anUp( anUpX, anUpY, anUpZ );
2019 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
2020 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2021 gp_Dir aSide = aProj ^ anUp;
2023 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
2024 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
2026 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
2027 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2030 aView3d->SetCenter( anItem.centerX, anItem.centerY );
2033 if ( !baseParamsOnly ) {
2035 myModel->setTrihedronShown( anItem.isVisible );
2036 myModel->setTrihedronSize( anItem.size );
2038 // graduated trihedron
2039 bool anIsVisible = anItem.gtIsVisible;
2040 OCCViewer_AxisWidget::AxisData anAxisData[3];
2041 anAxisData[0].DrawName = anItem.gtDrawNameX;
2042 anAxisData[1].DrawName = anItem.gtDrawNameZ;
2043 anAxisData[2].DrawName = anItem.gtDrawNameZ;
2044 anAxisData[0].Name = anItem.gtNameX;
2045 anAxisData[1].Name = anItem.gtNameZ;
2046 anAxisData[2].Name = anItem.gtNameZ;
2047 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
2048 anItem.gtNameColorGX,
2049 anItem.gtNameColorBX );
2050 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
2051 anItem.gtNameColorGY,
2052 anItem.gtNameColorBY );
2053 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
2054 anItem.gtNameColorGZ,
2055 anItem.gtNameColorBZ );
2056 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
2057 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
2058 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
2059 anAxisData[0].NbValues = anItem.gtNbValuesX;
2060 anAxisData[1].NbValues = anItem.gtNbValuesY;
2061 anAxisData[2].NbValues = anItem.gtNbValuesZ;
2062 anAxisData[0].Offset = anItem.gtOffsetX;
2063 anAxisData[1].Offset = anItem.gtOffsetY;
2064 anAxisData[2].Offset = anItem.gtOffsetZ;
2065 anAxisData[0].Color = QColor( anItem.gtColorRX,
2068 anAxisData[1].Color = QColor( anItem.gtColorRY,
2071 anAxisData[2].Color = QColor( anItem.gtColorRZ,
2074 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
2075 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
2076 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
2077 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
2078 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
2079 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
2081 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
2082 myCubeAxesDlg->ApplyData( aView3d );
2084 } // if ( !baseParamsOnly )
2090 \brief Set restore flag.
2092 void OCCViewer_ViewWindow::setRestoreFlag()
2098 \brief Called when action "show/hide trihedron" is activated.
2100 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
2102 myModel->setTrihedronShown(show);
2106 \brief Toggles preselection (highlighting) on/off
2108 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
2110 myPreselectionEnabled = on;
2111 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
2113 // unhighlight all highlighted objects
2115 myModel->unHighlightAll( true, false );
2118 // update action state if method is called outside
2119 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2120 if ( a && a->isChecked() != on ) {
2121 a->setChecked( on );
2126 \brief Toggles selection on/off
2128 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
2130 mySelectionEnabled = on;
2131 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
2133 // update action state if method is called outside
2136 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2138 a->setEnabled( on );
2142 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
2143 if ( a && a->isChecked() != on ) {
2144 a->setChecked( on );
2149 \brief Switches "keyboard free" interaction style on/off
2151 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
2153 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
2155 // update action state if method is called outside
2156 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
2157 if ( a && a->isChecked() != on )
2158 a->setChecked( on );
2162 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
2164 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
2166 myViewPort->setAdvancedZoomingEnabled( on );
2168 // update action state if method is called outside
2169 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
2170 if ( a && a->isChecked() != on )
2171 a->setChecked( on );
2175 \brief Get current interaction style
2176 \return interaction style
2178 int OCCViewer_ViewWindow::interactionStyle() const
2180 return myInteractionStyle;
2184 \brief Set current interaction style
2185 \param theStyle interaction style
2187 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
2189 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
2193 \brief Get current zooming style
2194 \return zooming style
2196 int OCCViewer_ViewWindow::zoomingStyle() const
2198 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
2202 \brief Set current zooming style
2203 \param theStyle zooming style
2205 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
2207 onSwitchZoomingStyle( theStyle == 1 );
2211 \brief Dump view window contents to the pixmap.
2212 \return pixmap containing all scene rendered in the window
2214 QImage OCCViewer_ViewWindow::dumpView()
2216 Handle(V3d_View) view = myViewPort->getView();
2217 if ( view.IsNull() )
2220 int aWidth = myViewPort->width();
2221 int aHeight = myViewPort->height();
2223 // rnv: An old approach to dump the OCCViewer content
2224 // Now used OCCT built-in procedure.
2226 QApplication::syncX();
2227 view->Redraw(); // In order to reactivate GL context
2230 #ifndef DISABLE_GLVIEWER
2231 OpenGLUtils_FrameBuffer aFrameBuffer;
2232 if( aFrameBuffer.init( aWidth, aHeight ) )
2234 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
2236 glPushAttrib( GL_VIEWPORT_BIT );
2237 glViewport( 0, 0, aWidth, aHeight );
2238 aFrameBuffer.bind();
2243 aFrameBuffer.unbind();
2246 aFrameBuffer.bind();
2247 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
2248 aFrameBuffer.unbind();
2250 anImage = anImage.rgbSwapped();
2251 anImage = anImage.mirrored();
2254 // if frame buffers are unsupported, use old functionality
2257 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
2259 QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
2261 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
2267 view->ToPixMap(aPix,aWidth, aHeight,Graphic3d_BT_RGBA);
2269 QImage anImage( aPix.Data(), aWidth, aHeight, QImage::Format_ARGB32 );
2270 anImage = anImage.mirrored();
2274 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
2275 const QString& fileName,
2276 const QString& format )
2279 QApplication::setOverrideCursor( Qt::WaitCursor );
2280 if ( format != "PS" && format != "EPS")
2281 res = myViewPort->getView()->Dump( fileName.toStdString().c_str() );
2283 #if OCC_VERSION_MAJOR < 7
2284 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
2286 Handle(Graphic3d_CView) a3dView = myViewPort->getView()->View();
2290 res = a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
2291 else if (format == "EPS")
2292 res = a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
2294 QApplication::restoreOverrideCursor();
2299 QString OCCViewer_ViewWindow::filter() const
2301 return tr( "OCC_IMAGE_FILES" );
2306 \brief Set parameters of the cutting plane
2307 \param on if \c true, cutting plane is enabled
2308 \param x X position of plane point
2309 \param y Y position of plane point
2310 \param z Z position of plane point
2311 \param dx X coordinate of plane normal
2312 \param dy Y coordinate of plane normal
2313 \param dz Z coordinate of plane normal
2315 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2316 const double dx, const double dy, const double dz )
2318 Handle(V3d_View) view = myViewPort->getView();
2319 if ( view.IsNull() )
2323 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2325 // try to use already existing plane or create a new one
2326 Handle(V3d_Plane) clipPlane;
2328 // calculate new a,b,c,d values for the plane
2329 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2331 pln.Coefficients(a, b, c, d);
2333 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2334 if(aPlanes.Size() > 0 ) {
2335 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2336 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2337 aClipPlane->SetEquation(pln);
2338 aClipPlane->SetOn(Standard_True);
2340 view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2344 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2345 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2346 for( ;anIter.More();anIter.Next() ){
2347 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2348 aClipPlane->SetOn(Standard_False);
2356 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2358 gp_Dir aDir = pln.Axis().Direction();
2359 gp_Pnt aPnt = pln.Location();
2360 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2365 \brief Check if any cutting plane is enabled
2366 \return \c true if at least one cutting plane is enabled
2368 bool OCCViewer_ViewWindow::isCuttingPlane()
2370 Handle(V3d_View) view = myViewPort->getView();
2372 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2373 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2374 for( ;anIter.More();anIter.Next() ) {
2375 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2376 if(aClipPlane->IsOn()) {
2385 \brief Get the visual parameters of the view window.
2386 \return visual parameters of view window
2388 viewAspect OCCViewer_ViewWindow::getViewParams() const
2390 double projX, projY, projZ, twist;
2391 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2392 double aScaleX, aScaleY, aScaleZ;
2394 Handle(V3d_View) aView3d = myViewPort->getView();
2396 aView3d->Proj( projX, projY, projZ );
2397 aView3d->At( atX, atY, atZ );
2398 aView3d->Eye( eyeX, eyeY, eyeZ );
2399 twist = aView3d->Twist();
2401 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2403 bool isShown = myModel->isTrihedronVisible();
2404 double size = myModel->trihedronSize();
2406 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2409 params.scale = aView3d->Scale();
2410 params.projX = projX;
2411 params.projY = projY;
2412 params.projZ = projZ;
2413 params.twist = twist;
2420 params.scaleX = aScaleX;
2421 params.scaleY = aScaleY;
2422 params.scaleZ = aScaleZ;
2423 params.name = aName;
2424 params.isVisible= isShown;
2427 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2428 aView3d->Center( params.centerX, params.centerY );
2431 // graduated trihedron
2432 bool anIsVisible = false;
2433 OCCViewer_AxisWidget::AxisData anAxisData[3];
2434 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2436 params.gtIsVisible = anIsVisible;
2437 params.gtDrawNameX = anAxisData[0].DrawName;
2438 params.gtDrawNameY = anAxisData[1].DrawName;
2439 params.gtDrawNameZ = anAxisData[2].DrawName;
2440 params.gtNameX = anAxisData[0].Name;
2441 params.gtNameY = anAxisData[1].Name;
2442 params.gtNameZ = anAxisData[2].Name;
2443 params.gtNameColorRX = anAxisData[0].NameColor.red();
2444 params.gtNameColorGX = anAxisData[0].NameColor.green();
2445 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2446 params.gtNameColorRY = anAxisData[1].NameColor.red();
2447 params.gtNameColorGY = anAxisData[1].NameColor.green();
2448 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2449 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2450 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2451 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2452 params.gtDrawValuesX = anAxisData[0].DrawValues;
2453 params.gtDrawValuesY = anAxisData[1].DrawValues;
2454 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2455 params.gtNbValuesX = anAxisData[0].NbValues;
2456 params.gtNbValuesY = anAxisData[1].NbValues;
2457 params.gtNbValuesZ = anAxisData[2].NbValues;
2458 params.gtOffsetX = anAxisData[0].Offset;
2459 params.gtOffsetY = anAxisData[1].Offset;
2460 params.gtOffsetZ = anAxisData[2].Offset;
2461 params.gtColorRX = anAxisData[0].Color.red();
2462 params.gtColorGX = anAxisData[0].Color.green();
2463 params.gtColorBX = anAxisData[0].Color.blue();
2464 params.gtColorRY = anAxisData[1].Color.red();
2465 params.gtColorGY = anAxisData[1].Color.green();
2466 params.gtColorBY = anAxisData[1].Color.blue();
2467 params.gtColorRZ = anAxisData[2].Color.red();
2468 params.gtColorGZ = anAxisData[2].Color.green();
2469 params.gtColorBZ = anAxisData[2].Color.blue();
2470 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2471 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2472 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2473 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2474 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2475 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2481 \brief Get visual parameters of this view window.
2482 \return visual parameters of view window
2484 QString OCCViewer_ViewWindow::getVisualParameters()
2486 viewAspect params = getViewParams();
2490 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2491 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2492 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
2493 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
2495 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2496 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2497 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2498 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2499 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2500 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2501 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2502 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2503 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2504 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2505 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2506 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2507 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2508 data << QString( "isVisible=%1" ).arg( params.isVisible );
2509 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2511 ClipPlanesList aPlanes = myModel->getClipPlanes();
2512 for ( int i=0; i < aPlanes.size(); i++ )
2514 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2515 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2516 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2517 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2518 switch ( aPlane.Mode )
2520 case OCCViewer_ClipPlane::Absolute :
2522 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2524 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2526 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2527 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2528 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2532 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2537 case OCCViewer_ClipPlane::Relative :
2539 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2540 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2541 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2546 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2547 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2548 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2549 data << ClippingPlane;
2552 // graduated trihedron
2553 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2554 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2555 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2556 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2557 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2558 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2559 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2560 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2561 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2562 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2563 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2564 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2565 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2566 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2567 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2568 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2569 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2570 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2571 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2572 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2573 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2574 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2575 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2576 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2577 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2578 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2579 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2580 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2581 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2582 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2583 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2584 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2585 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2586 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2587 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2588 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2589 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2590 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2591 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2592 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2594 // ray tracing parameters
2595 Graphic3d_RenderingParams rendParams = this->getViewPort()->getView()->RenderingParams();
2596 if ( rendParams.Method == Graphic3d_RM_RAYTRACING ) {
2597 QString RayTracing = "rayTracing=";
2598 RayTracing += QString( "rtDepth~%1;" ).arg( rendParams.RaytracingDepth );
2599 RayTracing += QString( "rtReflection~%1;" ).arg( rendParams.IsReflectionEnabled );
2600 RayTracing += QString( "rtAntialiasing~%1;" ).arg( rendParams.IsAntialiasingEnabled );
2601 RayTracing += QString( "rtShadow~%1;" ).arg( rendParams.IsShadowEnabled );
2602 RayTracing += QString( "rtTransShadow~%1;" ).arg( rendParams.IsTransparentShadowEnabled );
2606 // environment texture parameters
2607 Handle(Graphic3d_TextureEnv) aTexture = this->getViewPort()->getView()->TextureEnv();
2608 if ( !aTexture.IsNull() ) {
2609 QString EnvTexture = "envTexture=";
2610 if ( aTexture->Name() == Graphic3d_NOT_ENV_UNKNOWN ) {
2611 TCollection_AsciiString aFileName;
2612 aTexture->Path().SystemName( aFileName );
2613 EnvTexture += QString( "etFile~%1;" ).arg( aFileName.ToCString() );
2616 EnvTexture += QString( "etNumber~%1;" ).arg( aTexture->Name() );
2620 // light source parameters
2621 myModel->getViewer3d()->InitDefinedLights();
2622 while ( myModel->getViewer3d()->MoreDefinedLights() )
2624 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2625 if ( aLight->Type() != V3d_AMBIENT ) {
2626 QString LightSource = QString( "lightSource=" );
2627 LightSource += QString( "lightType~%1;" ).arg( aLight->Type() );
2629 if ( aLight->Type() == V3d_DIRECTIONAL )
2630 Handle(V3d_DirectionalLight)::DownCast( aLight )->Direction( aX, aY, aZ );
2631 else if ( aLight->Type() == V3d_POSITIONAL )
2632 Handle(V3d_PositionalLight)::DownCast( aLight )->Position( aX, aY, aZ );
2633 LightSource += QString( "lightX~%1;" ).arg( aX );
2634 LightSource += QString( "lightY~%1;" ).arg( aY );
2635 LightSource += QString( "lightZ~%1;" ).arg( aZ );
2636 LightSource += QString( "lightColorR~%1;" ).arg( aLight->Color().Red() );
2637 LightSource += QString( "lightColorG~%1;" ).arg( aLight->Color().Green() );
2638 LightSource += QString( "lightColorB~%1;" ).arg( aLight->Color().Blue() );
2639 LightSource += QString( "lightHeadlight~%1;" ).arg( aLight->Headlight() );
2640 data << LightSource;
2642 myModel->getViewer3d()->NextDefinedLights();
2645 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2646 data << QString( "background=%1" ).arg( bg );
2648 return data.join("*");
2652 \brief Restore visual parameters of the view window.
2653 \param parameters visual parameters of view window
2655 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2658 ClipPlanesList aClipPlanes;
2659 QStringList data = parameters.split( '*' );
2660 Qtx::BackgroundData bgData;
2661 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2663 foreach( QString param, data ) {
2664 QString paramName = param.section( '=', 0, 0 ).trimmed();
2665 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2666 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2667 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2668 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2669 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2670 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2671 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2672 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2673 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2674 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2675 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2676 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2677 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2678 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2679 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2680 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2681 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2682 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2683 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2684 else if ( paramName.contains( "ClippingPlane" ) )
2686 QStringList ClipPlaneData = paramValue.split( ';' );
2687 OCCViewer_ClipPlane aPlane;
2688 foreach( QString ClipPlaneParam, ClipPlaneData )
2690 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2691 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2692 if ( ClipPlane_paramName == "Mode" )
2694 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2696 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2697 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2698 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2699 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2702 switch ( aPlane.Mode )
2704 case OCCViewer_ClipPlane::Absolute :
2705 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2706 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2707 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2708 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2709 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2712 case OCCViewer_ClipPlane::Relative :
2713 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2714 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2715 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2720 aClipPlanes.push_back(aPlane);
2722 // graduated trihedron
2723 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2724 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2725 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2726 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2727 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2728 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2729 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2730 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2731 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2732 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2733 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2734 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2735 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2736 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2737 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2738 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2739 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2740 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2741 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2742 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2743 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2744 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2745 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2746 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2747 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2748 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2749 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2750 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2751 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2752 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2753 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2754 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2755 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2756 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2757 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2758 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2759 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2760 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2761 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2762 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2763 else if ( paramName == "rayTracing" )
2765 Graphic3d_RenderingParams& rendParams = this->getViewPort()->getView()->ChangeRenderingParams();
2766 rendParams.Method = Graphic3d_RM_RAYTRACING;
2767 QStringList rtData = paramValue.split( ';' );
2768 foreach( QString rtParam, rtData )
2770 QString rt_paramName = rtParam.section( '~', 0, 0 ).trimmed();
2771 QString rt_paramValue = rtParam.section( '~', 1, 1 ).trimmed();
2772 if ( rt_paramName == "rtDepth" ) rendParams.RaytracingDepth = rt_paramValue.toInt();
2773 else if ( rt_paramName == "rtReflection" ) rendParams.IsReflectionEnabled = rt_paramValue.toInt();
2774 else if ( rt_paramName == "rtAntialiasing" ) rendParams.IsAntialiasingEnabled = rt_paramValue.toInt();
2775 else if ( rt_paramName == "rtShadow" ) rendParams.IsShadowEnabled = rt_paramValue.toInt();
2776 else if ( rt_paramName == "rtTransShadow" ) rendParams.IsTransparentShadowEnabled = rt_paramValue.toInt();
2779 else if ( paramName == "envTexture" )
2781 Handle(Graphic3d_TextureEnv) aTexture;
2782 QStringList etData = paramValue.split( ';' );
2783 foreach( QString etParam, etData )
2785 QString et_paramName = etParam.section( '~', 0, 0 ).trimmed();
2786 QString et_paramValue = etParam.section( '~', 1, 1 ).trimmed();
2787 if ( et_paramName == "etNumber" )
2788 aTexture = new Graphic3d_TextureEnv( Graphic3d_NameOfTextureEnv( et_paramValue.toInt() ) );
2789 else if ( et_paramName == "etFile" )
2790 aTexture = new Graphic3d_TextureEnv( TCollection_AsciiString( et_paramValue.toStdString().c_str() ) );
2791 Handle(V3d_View) aView = this->getViewPort()->getView();
2792 aView->SetTextureEnv( aTexture );
2793 #if OCC_VERSION_LARGE <= 0x07000000
2794 aView->SetSurfaceDetail( V3d_TEX_ENVIRONMENT );
2798 else if ( paramName == "lightSource" )
2800 myModel->getViewer3d()->InitDefinedLights();
2801 while ( myModel->getViewer3d()->MoreDefinedLights() )
2803 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2804 if( aLight->Type() != V3d_AMBIENT ) {
2805 myModel->getViewer3d()->DelLight( aLight );
2806 myModel->getViewer3d()->InitDefinedLights();
2808 myModel->getViewer3d()->NextDefinedLights();
2813 V3d_TypeOfLight aType;
2815 QStringList lsData = paramValue.split( ';' );
2816 foreach( QString lsParam, lsData )
2818 QString ls_paramName = lsParam.section( '~', 0, 0 ).trimmed();
2819 QString ls_paramValue = lsParam.section( '~', 1, 1 ).trimmed();
2820 if ( ls_paramName == "lightType" ) aType = V3d_TypeOfLight( ls_paramValue.toInt() );
2821 else if ( ls_paramName == "lightX" ) aX = ls_paramValue.toDouble();
2822 else if ( ls_paramName == "lightY" ) aY = ls_paramValue.toDouble();
2823 else if ( ls_paramName == "lightZ" ) aZ = ls_paramValue.toDouble();
2824 else if ( ls_paramName == "lightColorR" ) cR = ls_paramValue.toDouble();
2825 else if ( ls_paramName == "lightColorG" ) cG = ls_paramValue.toDouble();
2826 else if ( ls_paramName == "lightColorB" ) cB = ls_paramValue.toDouble();
2827 else if ( ls_paramName == "lightHeadlight" ) isHeadlight = ls_paramValue.toInt();
2829 Quantity_Color aColor = Quantity_Color( cR, cG, cB, Quantity_TOC_RGB );
2830 if( aType == V3d_DIRECTIONAL ) {
2831 Handle(V3d_DirectionalLight) aLight = new V3d_DirectionalLight( myModel->getViewer3d() );
2832 aLight->SetDirection( aX, aY, aZ );
2833 aLight->SetColor( aColor );
2834 aLight->SetHeadlight( isHeadlight );
2835 myModel->getViewer3d()->SetLightOn( aLight );
2837 else if( aType == V3d_POSITIONAL ) {
2838 Handle(V3d_PositionalLight) aLight = new V3d_PositionalLight( myModel->getViewer3d(), aX, aY, aZ, aColor.Name() );
2839 aLight->SetHeadlight( isHeadlight );
2840 myModel->getViewer3d()->SetLightOn( aLight );
2843 else if ( paramName == "background" ) {
2844 QString bg = paramValue.replace( "$", "=" );
2845 bgData = Qtx::stringToBackground( bg );
2849 else // old format - "1.000e+00*0.000e+00..."
2852 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2853 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2854 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2855 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2856 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2857 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2858 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
2859 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2860 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2861 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
2862 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2863 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2864 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2865 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
2866 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
2867 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
2868 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
2869 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
2871 performRestoring( params );
2872 setBackground( bgData );
2873 myModel->setClipPlanes(aClipPlanes);
2877 \brief Handle show event.
2879 Emits Show() signal.
2881 \param theEvent show event
2883 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2885 emit Show( theEvent );
2889 \brief Handle hide event.
2891 Emits Hide() signal.
2893 \param theEvent hide event
2895 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
2897 emit Hide( theEvent );
2902 Save old cursor. [ protected ]
2904 void OCCViewer_ViewWindow::saveCursor()
2906 QCursor* aCursor = NULL;
2908 aCursor = myViewPort->getDefaultCursor();
2909 myCursor = ( aCursor ? *aCursor : cursor() );
2914 Creates default sketcher. [ virtual protected ]
2916 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
2919 return new OCCViewer_RectSketcher( this, type );
2920 if ( type == Polygon )
2921 return new OCCViewer_PolygonSketcher( this, type );
2925 void OCCViewer_ViewWindow::initSketchers()
2927 if ( mySketchers.isEmpty() )
2929 mySketchers.append( createSketcher( Rect ) );
2930 mySketchers.append( createSketcher( Polygon ) );
2934 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
2936 OCCViewer_ViewSketcher* sketcher = 0;
2937 QList<OCCViewer_ViewSketcher*>::Iterator it;
2938 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
2940 OCCViewer_ViewSketcher* sk = (*it);
2941 if ( sk->type() == typ )
2948 Handles requests for sketching in the active view. [ virtual public ]
2950 void OCCViewer_ViewWindow::activateSketching( int type )
2952 OCCViewer_ViewPort3d* vp = getViewPort();
2956 if ( !vp->isSketchingEnabled() )
2959 /* Finish current sketching */
2960 if ( type == NoSketching )
2964 onSketchingFinished();
2965 mypSketcher->deactivate();
2969 /* Activate new sketching */
2972 activateSketching( NoSketching ); /* concurrency not suported */
2973 mypSketcher = getSketcher( type );
2976 mypSketcher->activate();
2977 onSketchingStarted();
2983 Unhilights detected entities. [ virtual protected ]
2985 void OCCViewer_ViewWindow::onSketchingStarted()
2990 Selection by rectangle or polygon. [ virtual protected ]
2992 void OCCViewer_ViewWindow::onSketchingFinished()
2994 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
2995 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
2997 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
2998 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
2999 switch( mypSketcher->type() )
3003 QRect* aRect = (QRect*)mypSketcher->data();
3006 int aLeft = aRect->left();
3007 int aRight = aRect->right();
3008 int aTop = aRect->top();
3009 int aBottom = aRect->bottom();
3013 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
3015 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
3021 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
3024 int size = aPolygon->size();
3025 TColgp_Array1OfPnt2d anArray( 1, size );
3027 QPolygon::Iterator it = aPolygon->begin();
3028 QPolygon::Iterator itEnd = aPolygon->end();
3029 for( int index = 1; it != itEnd; ++it, index++ )
3031 QPoint aPoint = *it;
3032 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
3036 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
3038 ic->Select( anArray, getViewPort()->getView(), Standard_False );
3046 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
3047 aViewMgr->getOCCViewer()->performSelectionChanged();
3051 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
3056 bool OCCViewer_ViewWindow::transformRequested() const
3058 return ( myOperation != NOTHING );
3061 bool OCCViewer_ViewWindow::transformInProcess() const
3063 return myEventStarted;
3066 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
3068 myEventStarted = bOn;
3072 Set enabled state of transformation (rotate, zoom, etc)
3074 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
3076 if ( id != NOTHING ) myStatus.insert( id, on );
3080 \return enabled state of transformation (rotate, zoom, etc)
3082 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
3084 return myStatus.contains( id ) ? myStatus[ id ] : true;
3087 void OCCViewer_ViewWindow::onMaximizedView()
3089 setMaximized(!isMaximized());
3092 void OCCViewer_ViewWindow::returnTo3dView()
3094 setReturnedTo3dView( true );
3097 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
3099 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
3100 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
3101 if ( !isVisible3dView )
3102 toolMgr()->show( ReturnTo3dViewId );
3104 toolMgr()->hide( ReturnTo3dViewId );
3105 if ( isVisible3dView ) emit returnedTo3d( );
3109 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
3111 QAction* anAction = toolMgr()->action( MaximizedId );
3112 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
3113 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
3115 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
3116 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
3117 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
3118 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
3119 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
3121 emit maximized( this, true );
3125 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
3126 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
3127 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
3128 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
3129 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
3131 emit maximized( this, false );
3136 bool OCCViewer_ViewWindow::isMaximized() const
3138 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
3141 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
3143 IsSketcherStyle = enable;
3146 bool OCCViewer_ViewWindow::isSketcherStyle() const
3148 return IsSketcherStyle;
3152 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
3157 int OCCViewer_ViewWindow::projectionType() const
3159 int mode = Orthographic;
3160 Handle(V3d_View) aView3d = myViewPort->getView();
3161 if ( !aView3d.IsNull() ) {
3162 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3163 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Perspective)
3165 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Orthographic)
3166 mode = Orthographic;
3167 #if OCC_VERSION_LARGE > 0x06090000
3168 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
3175 void OCCViewer_ViewWindow::setStereoType( int type )
3177 Handle(V3d_View) aView3d = myViewPort->getView();
3178 if ( !aView3d.IsNull() ) {
3179 #if OCC_VERSION_LARGE > 0x06090000
3180 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3181 aParams->StereoMode = (Graphic3d_StereoMode)type;
3186 int OCCViewer_ViewWindow::stereoType() const
3188 int type = QuadBuffer;
3189 Handle(V3d_View) aView3d = myViewPort->getView();
3190 if ( !aView3d.IsNull() ) {
3191 #if OCC_VERSION_LARGE > 0x06090000
3192 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3193 type = (OCCViewer_ViewWindow::StereoType)aParams->StereoMode;
3199 void OCCViewer_ViewWindow::setAnaglyphFilter( int type )
3201 Handle(V3d_View) aView3d = myViewPort->getView();
3202 if ( !aView3d.IsNull() ) {
3203 #if OCC_VERSION_LARGE > 0x06090000
3204 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3205 if (type == RedCyan)
3206 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
3207 if (type == YellowBlue)
3208 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
3209 if (type == GreenMagenta)
3210 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
3215 int OCCViewer_ViewWindow::anaglyphFilter() const
3218 Handle(V3d_View) aView3d = myViewPort->getView();
3219 if ( !aView3d.IsNull() ) {
3220 #if OCC_VERSION_LARGE > 0x06090000
3221 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3222 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized)
3224 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized)
3226 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple)
3227 type = GreenMagenta;
3233 void OCCViewer_ViewWindow::setStereographicFocus( int type, double value )
3235 Handle(V3d_View) aView3d = myViewPort->getView();
3236 if ( !aView3d.IsNull() ) {
3237 #if OCC_VERSION_LARGE > 0x06090000
3238 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3239 aCamera->SetZFocus( (Graphic3d_Camera::FocusType) type, value );
3244 int OCCViewer_ViewWindow::stereographicFocusType() const
3246 int type = Relative;
3247 Handle(V3d_View) aView3d = myViewPort->getView();
3248 if ( !aView3d.IsNull() ) {
3249 #if OCC_VERSION_LARGE > 0x06090000
3250 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3251 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->ZFocusType();
3257 double OCCViewer_ViewWindow::stereographicFocusValue() const
3260 Handle(V3d_View) aView3d = myViewPort->getView();
3261 if ( !aView3d.IsNull() ) {
3262 #if OCC_VERSION_LARGE > 0x06090000
3263 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3264 value = aCamera->ZFocus();
3270 void OCCViewer_ViewWindow::setInterocularDistance( int type, double value )
3272 Handle(V3d_View) aView3d = myViewPort->getView();
3273 if ( !aView3d.IsNull() ) {
3274 #if OCC_VERSION_LARGE > 0x06090000
3275 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3276 aCamera->SetIOD( (Graphic3d_Camera::IODType) type, value );
3281 int OCCViewer_ViewWindow::interocularDistanceType() const
3283 int type = Relative;
3284 Handle(V3d_View) aView3d = myViewPort->getView();
3285 if ( !aView3d.IsNull() ) {
3286 #if OCC_VERSION_LARGE > 0x06090000
3287 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3288 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->GetIODType();
3294 double OCCViewer_ViewWindow::interocularDistanceValue() const
3296 double value = 0.05;
3297 Handle(V3d_View) aView3d = myViewPort->getView();
3298 if ( !aView3d.IsNull() ) {
3299 #if OCC_VERSION_LARGE > 0x06090000
3300 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3301 value = aCamera->IOD();
3307 void OCCViewer_ViewWindow::setReverseStereo( bool reverse )
3309 Handle(V3d_View) aView3d = myViewPort->getView();
3310 if ( !aView3d.IsNull() ) {
3311 #if OCC_VERSION_LARGE > 0x06090000
3312 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3313 aParams->ToReverseStereo = reverse;
3318 bool OCCViewer_ViewWindow::isReverseStereo() const
3320 int reverse = false;
3321 Handle(V3d_View) aView3d = myViewPort->getView();
3322 if ( !aView3d.IsNull() ) {
3323 #if OCC_VERSION_LARGE > 0x06090000
3324 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3325 reverse = aParams->ToReverseStereo;
3331 void OCCViewer_ViewWindow::setVSync( bool enable )
3333 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3334 if ( !anIntCont.IsNull() ) {
3335 #if OCC_VERSION_LARGE > 0x06090000
3336 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3337 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3338 aCaps->swapInterval = enable;
3343 bool OCCViewer_ViewWindow::isVSync() const
3346 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3347 if ( !anIntCont.IsNull() ) {
3348 #if OCC_VERSION_LARGE > 0x06090000
3349 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3350 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3351 enable = aCaps->swapInterval;
3357 void OCCViewer_ViewWindow::setQuadBufferSupport( bool enable )
3359 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3360 if ( !anIntCont.IsNull() ) {
3361 #if OCC_VERSION_LARGE > 0x06090000
3362 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3363 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3364 aCaps->contextStereo = enable;
3369 bool OCCViewer_ViewWindow::isQuadBufferSupport() const
3372 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3373 if ( !anIntCont.IsNull() ) {
3374 #if OCC_VERSION_LARGE > 0x06090000
3375 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3376 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3377 enable = aCaps->contextStereo;
3384 bool OCCViewer_ViewWindow::isOpenGlStereoSupport() const
3386 GLboolean support[1];
3387 glGetBooleanv (GL_STEREO, support);
3394 QColor OCCViewer_ViewWindow::backgroundColor() const
3396 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
3400 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
3402 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
3405 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
3407 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
3410 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
3412 if ( myViewPort ) myViewPort->setBackground( theBackground );
3415 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
3417 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
3423 void OCCViewer_ViewWindow::clearViewAspects()
3425 myViewAspects.clear();
3429 \return const reference to list of view aspects
3431 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
3433 return myViewAspects;
3437 Appends new view aspect
3438 \param aParams - new view aspects
3440 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
3442 myViewAspects.append( aParams );
3446 Replaces old view aspects by new ones
3447 \param aViewList - list of new view aspects
3449 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
3451 myViewAspects = aViewList;
3455 Get camera properties for the OCC view window.
3456 \return shared pointer on camera properties.
3458 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
3460 SUIT_CameraProperties aProps;
3462 Handle(V3d_View) aSourceView = getViewPort()->getView();
3463 if ( aSourceView.IsNull() )
3466 if ( get2dMode() == No2dMode ) {
3467 aProps.setDimension( SUIT_CameraProperties::Dim3D );
3470 aProps.setDimension( SUIT_CameraProperties::Dim2D );
3471 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
3474 // read common properites of the view
3475 Standard_Real anUp[3];
3476 Standard_Real anAt[3];
3477 Standard_Real anEye[3];
3478 Standard_Real aProj[3];
3479 Standard_Real anAxialScale[3];
3481 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
3482 aSourceView->At( anAt[0], anAt[1], anAt[2] );
3483 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
3484 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3486 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3487 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
3489 #if OCC_VERSION_LARGE > 0x06070100
3490 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
3492 // store camera properties "as is": it is up to synchronized
3493 // view classes to provide necessary property conversion.
3494 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
3495 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
3497 if ( aSourceView->Camera()->IsOrthographic() )
3499 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
3500 aProps.setViewAngle( 0.0 );
3504 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
3505 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
3507 aProps.setMappingScale( aSourceView->Camera()->Scale() );
3509 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
3511 // generate view orientation matrix for transforming OCC projection reference point
3512 // into a camera (eye) position.
3513 gp_Dir aLeftDir = gp_Dir( anUp[0], anUp[1], anUp[2] ) ^ gp_Dir( aProj[0], aProj[1], aProj[2] );
3516 aTrsf.SetValue( 1, 1, aLeftDir.X() );
3517 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
3518 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
3520 aTrsf.SetValue( 1, 2, anUp[0] );
3521 aTrsf.SetValue( 2, 2, anUp[1] );
3522 aTrsf.SetValue( 3, 2, anUp[2] );
3524 aTrsf.SetValue( 1, 3, aProj[0] );
3525 aTrsf.SetValue( 2, 3, aProj[1] );
3526 aTrsf.SetValue( 3, 3, aProj[2] );
3528 aTrsf.SetValue( 1, 4, anAt[0] );
3529 aTrsf.SetValue( 2, 4, anAt[1] );
3530 aTrsf.SetValue( 3, 4, anAt[2] );
3532 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
3534 // transform to world-space coordinate system
3535 gp_XYZ aPosition( aProjRef.X(), aProjRef.Y(), aCameraDepth );
3536 aTrsf.Transforms( aPosition );
3538 // compute focal point
3539 double aFocalPoint[3];
3541 aFocalPoint[0] = aPosition.X() - aProj[0] * aCameraDepth;
3542 aFocalPoint[1] = aPosition.Y() - aProj[1] * aCameraDepth;
3543 aFocalPoint[2] = aPosition.Z() - aProj[2] * aCameraDepth;
3545 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3546 aProps.setPosition( aPosition.X(), aPosition.Y(), aPosition.Z() );
3548 Standard_Real aViewScale[2];
3549 aSourceView->Size( aViewScale[0], aViewScale[1] );
3550 aProps.setMappingScale( aViewScale[1] );
3558 This implementation synchronizes OCC view's camera propreties.
3560 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
3562 bool blocked = blockSignals( true );
3564 SUIT_CameraProperties aProps = theView->cameraProperties();
3565 if ( !cameraProperties().isCompatible( aProps ) ) {
3566 // other view, this one is being currently synchronized to, seems has become incompatible
3567 // we have to break synchronization
3572 Handle(V3d_View) aDestView = getViewPort()->getView();
3574 aDestView->SetImmediateUpdate( Standard_False );
3577 double aPosition[3];
3578 double aFocalPoint[3];
3579 double anAxialScale[3];
3581 // get common properties
3582 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3583 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
3584 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3585 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3587 #if OCC_VERSION_LARGE > 0x06070100
3588 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3589 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
3590 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3591 aDestView->Camera()->SetScale( aProps.getMappingScale() );
3593 gp_Dir aProjDir( aPosition[0] - aFocalPoint[0],
3594 aPosition[1] - aFocalPoint[1],
3595 aPosition[2] - aFocalPoint[2] );
3597 // get custom view translation
3598 Standard_Real aTranslation[3];
3599 aDestView->At( aTranslation[0], aTranslation[1], aTranslation[2] );
3601 gp_Dir aLeftDir = gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] )
3602 ^ gp_Dir( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
3605 aTrsf.SetValue( 1, 1, aLeftDir.X() );
3606 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
3607 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
3609 aTrsf.SetValue( 1, 2, anUpDir[0] );
3610 aTrsf.SetValue( 2, 2, anUpDir[1] );
3611 aTrsf.SetValue( 3, 2, anUpDir[2] );
3613 aTrsf.SetValue( 1, 3, aProjDir.X() );
3614 aTrsf.SetValue( 2, 3, aProjDir.Y() );
3615 aTrsf.SetValue( 3, 3, aProjDir.Z() );
3617 aTrsf.SetValue( 1, 4, aTranslation[0] );
3618 aTrsf.SetValue( 2, 4, aTranslation[1] );
3619 aTrsf.SetValue( 3, 4, aTranslation[2] );
3622 // transform to view-space coordinate system
3623 gp_XYZ aProjRef( aPosition[0], aPosition[1], aPosition[2] );
3624 aTrsf.Transforms( aProjRef );
3626 // set view camera properties using low-level approach. this is done
3627 // in order to avoid interference with static variables in v3d view used
3628 // when rotation is in process in another view.
3629 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
3630 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
3632 Graphic3d_Vector aMappingProj( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
3633 Graphic3d_Vector aMappingUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3635 aMappingProj.Normalize();
3636 aMappingUp.Normalize();
3638 anOrientation.SetViewReferencePlane( aMappingProj );
3639 anOrientation.SetViewReferenceUp( aMappingUp );
3641 aDestView->SetViewMapping( aMapping );
3642 aDestView->SetViewOrientation( anOrientation );
3645 aDestView->SetCenter( aProjRef.X(), aProjRef.Y() );
3647 // set mapping scale
3648 double aMapScaling = aProps.getMappingScale();
3649 Standard_Real aWidth, aHeight;
3650 aDestView->Size( aWidth, aHeight );
3651 aDestView->SetSize ( aWidth > aHeight ? aMapScaling * (aWidth / aHeight) : aMapScaling );
3654 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3656 aDestView->ZFitAll();
3657 aDestView->SetImmediateUpdate( Standard_True );
3658 aDestView->Redraw();
3660 blockSignals( blocked );
3664 \brief Indicates whether preselection is enabled
3665 \return true if preselection is enabled
3667 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
3669 return myPreselectionEnabled;
3673 \brief Enables/disables preselection
3674 \param theIsToEnable if true - preselection will be enabled
3676 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
3678 onSwitchPreselection( theIsToEnable );
3682 \brief Indicates whether selection is enabled
3683 \return true if selection is enabled
3685 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3687 return mySelectionEnabled;
3691 \brief Enables/disables selection
3692 \param theIsToEnable if true - selection will be enabled
3694 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3696 onSwitchSelection( theIsToEnable );
3701 \brief called if clipping operation is activated / deactivated.
3703 Enables/disables clipping plane displaying.
3705 \parma on action state
3707 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3709 if(!myModel) return;
3710 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3713 if (!aClippingDlg) {
3714 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3715 myModel->setClippingDlg(aClippingDlg);
3717 if (!aClippingDlg->isVisible())
3718 aClippingDlg->show();
3720 if ( aClippingDlg ) {
3721 aClippingDlg->close();
3722 myModel->setClippingDlg(0);
3726 SUIT_ViewManager* mgr = getViewManager();
3728 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3729 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3730 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3731 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3733 QAction* a = toolMgr()->action( ClippingId );
3735 if(theIsOn != a->isChecked()){
3736 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3737 a->setChecked(theIsOn);
3738 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3745 void OCCViewer_ViewWindow::onRayTracing()
3747 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_RayTracingDlg::getName() ) ) {
3748 QDialog* aDlg = new OCCViewer_RayTracingDlg( this );
3754 void OCCViewer_ViewWindow::onEnvTexture()
3756 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_EnvTextureDlg::getName() ) ) {
3757 QDialog* aDlg = new OCCViewer_EnvTextureDlg( this );
3763 void OCCViewer_ViewWindow::onLightSource()
3765 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_LightSourceDlg::getName() ) ) {
3766 QDialog* aDlg = new OCCViewer_LightSourceDlg( this, myModel );