1 // Copyright (C) 2007-2015 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_ViewModel.h"
28 #include "OCCViewer_ViewPort3d.h"
29 #include "OCCViewer_ViewManager.h"
30 #include "OCCViewer_ViewSketcher.h"
31 #include "OCCViewer_CreateRestoreViewDlg.h"
32 #include "OCCViewer_ClipPlane.h"
33 #include "OCCViewer_SetRotationPointDlg.h"
34 #include "OCCViewer_AxialScaleDlg.h"
35 #include "OCCViewer_CubeAxesDlg.h"
36 #include "OCCViewer_ClippingDlg.h"
37 #include "OCCViewer_RayTracingDlg.h"
38 #include "OCCViewer_EnvTextureDlg.h"
39 #include "OCCViewer_LightSourceDlg.h"
40 #include "OCCViewer_Utilities.h"
42 #include <SUIT_Desktop.h>
43 #include <SUIT_Session.h>
44 #include <SUIT_ViewManager.h>
45 #include <SUIT_Tools.h>
46 #include <SUIT_ResourceMgr.h>
47 #include <SUIT_MessageBox.h>
48 #include <SUIT_Application.h>
50 #include <QtxActionToolMgr.h>
51 #include <QtxMultiAction.h>
52 #include <QtxRubberBand.h>
54 #include <Basics_OCCTVersion.hxx>
60 #include <QMouseEvent>
61 #include <QApplication>
62 #include <QActionGroup>
65 #include <AIS_ListOfInteractive.hxx>
66 #include <AIS_ListIteratorOfListOfInteractive.hxx>
67 #include <AIS_Shape.hxx>
69 #include <BRep_Tool.hxx>
70 #include <BRepBndLib.hxx>
71 #include <BRepGProp.hxx>
72 #include <GProp_GProps.hxx>
75 #include <Graphic3d_SequenceOfHClipPlane.hxx>
76 #include <Graphic3d_ClipPlane.hxx>
77 #include <OpenGl_GraphicDriver.hxx>
78 #include <OpenGLUtils_FrameBuffer.h>
80 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
81 #include <Graphic3d_MapOfStructure.hxx>
82 #include <Graphic3d_Structure.hxx>
83 #include <Graphic3d_ExportFormat.hxx>
84 #if OCC_VERSION_LARGE > 0x06090000
85 #include <Graphic3d_StereoMode.hxx>
86 #include <Graphic3d_RenderingParams.hxx>
90 #include <Visual3d_View.hxx>
91 #include <V3d_Plane.hxx>
92 #include <V3d_Light.hxx>
96 #include <gp_GTrsf.hxx>
97 #include <TColgp_Array1OfPnt2d.hxx>
99 #include <Image_PixMap.hxx>
101 #include <Standard_Version.hxx>
103 #include "utilities.h"
105 // // OpenCV includes
107 // #include <highgui.h>
109 static QEvent* l_mbPressEvent = 0;
112 # include <QWindowsStyle>
117 // To avoid conflict between KeyPress from the X.h (define KeyPress 2)
118 // and QEvent::KeyPress (qevent.h)
123 // Enable ray tracing features
124 #define ENABLE_RAY_TRACING
126 const char* imageZoomCursor[] = {
131 "................................",
132 "................................",
133 ".#######........................",
134 "..aaaaaaa.......................",
135 "................................",
136 ".............#####..............",
137 "...........##.aaaa##............",
138 "..........#.aa.....a#...........",
139 ".........#.a.........#..........",
140 ".........#a..........#a.........",
141 "........#.a...........#.........",
142 "........#a............#a........",
143 "........#a............#a........",
144 "........#a............#a........",
145 "........#a............#a........",
146 ".........#...........#.a........",
147 ".........#a..........#a.........",
148 ".........##.........#.a.........",
149 "........#####.....##.a..........",
150 ".......###aaa#####.aa...........",
151 "......###aa...aaaaa.......#.....",
152 ".....###aa................#a....",
153 "....###aa.................#a....",
154 "...###aa...............#######..",
155 "....#aa.................aa#aaaa.",
156 ".....a....................#a....",
157 "..........................#a....",
158 "...........................a....",
159 "................................",
160 "................................",
161 "................................",
162 "................................"};
164 const char* imageRotateCursor[] = {
169 "................................",
170 "................................",
171 "................................",
172 "................................",
173 "........#.......................",
174 ".......#.a......................",
175 "......#######...................",
176 ".......#aaaaa#####..............",
177 "........#..##.a#aa##........##..",
178 ".........a#.aa..#..a#.....##.aa.",
179 ".........#.a.....#...#..##.aa...",
180 ".........#a.......#..###.aa.....",
181 "........#.a.......#a..#aa.......",
182 "........#a.........#..#a........",
183 "........#a.........#a.#a........",
184 "........#a.........#a.#a........",
185 "........#a.........#a.#a........",
186 ".........#.........#a#.a........",
187 "........##a........#a#a.........",
188 "......##.a#.......#.#.a.........",
189 "....##.aa..##.....##.a..........",
190 "..##.aa.....a#####.aa...........",
191 "...aa.........aaa#a.............",
192 "................#.a.............",
193 "...............#.a..............",
194 "..............#.a...............",
195 "...............a................",
196 "................................",
197 "................................",
198 "................................",
199 "................................",
200 "................................"};
202 const char* imageCrossCursor[] = {
207 "................................",
208 "................................",
209 "................................",
210 "................................",
211 "................................",
212 "................................",
213 "................................",
214 "...............#................",
215 "...............#a...............",
216 "...............#a...............",
217 "...............#a...............",
218 "...............#a...............",
219 "...............#a...............",
220 "...............#a...............",
221 "...............#a...............",
222 ".......#################........",
223 "........aaaaaaa#aaaaaaaaa.......",
224 "...............#a...............",
225 "...............#a...............",
226 "...............#a...............",
227 "...............#a...............",
228 "...............#a...............",
229 "...............#a...............",
230 "...............#a...............",
231 "................a...............",
232 "................................",
233 "................................",
234 "................................",
235 "................................",
236 "................................",
237 "................................",
238 "................................"};
243 \param theDesktop main window of application
244 \param theModel OCC 3D viewer
246 OCCViewer_ViewWindow::OCCViewer_ViewWindow( SUIT_Desktop* theDesktop,
247 OCCViewer_Viewer* theModel )
248 : SUIT_ViewWindow( theDesktop )
252 myEnableDrawMode = false;
253 myDrawRectEnabled = true;
255 updateEnabledDrawMode();
257 mySetRotationPointDlg = 0;
260 IsSketcherStyle = false;
267 myInteractionStyle = SUIT_ViewModel::STANDARD;
268 myPreselectionEnabled = true;
269 mySelectionEnabled = true;
271 myCursorIsHand = false;
279 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
282 qDeleteAll( mySketchers );
286 \brief Internal initialization.
288 void OCCViewer_ViewWindow::initLayout()
290 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
291 myViewPort->installEventFilter(this);
292 setCentralWidget(myViewPort);
293 myOperation = NOTHING;
295 myCurrPointType = GRAVITY;
296 myPrevPointType = GRAVITY;
297 mySelectedPoint = gp_Pnt(0.,0.,0.);
298 myRotationPointSelection = false;
300 setTransformRequested ( NOTHING );
301 setTransformInProcess ( false );
318 // Graduated axes dialog
319 QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
320 myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
321 myCubeAxesDlg->initialize();
323 connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
326 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
328 return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
332 \brief Detect viewer operation according the the mouse button pressed
333 and key modifiers used.
334 \param theEvent mouse event
335 \return type of the operation
337 OCCViewer_ViewWindow::OperationType
338 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
340 OperationType aOp = NOTHING;
341 SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
342 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
343 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
345 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
346 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
348 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
349 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
350 (my2dMode == No2dMode))
357 \brief Customize event handling
358 \param watched event receiver object
360 \return \c true if the event processing should be stopped
362 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
364 if ( watched == myViewPort ) {
365 int aType = e->type();
367 case QEvent::MouseButtonPress:
368 vpMousePressEvent((QMouseEvent*) e);
371 case QEvent::MouseButtonRelease:
372 vpMouseReleaseEvent((QMouseEvent*) e);
375 case QEvent::MouseMove:
376 vpMouseMoveEvent((QMouseEvent*) e);
379 case QEvent::MouseButtonDblClick:
380 emit mouseDoubleClicked(this, (QMouseEvent*)e);
385 QWheelEvent* aEvent = (QWheelEvent*) e;
387 if ( aEvent->modifiers().testFlag(Qt::ControlModifier) ) {
388 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
389 if ( isPreselectionEnabled() && ic->HasOpenedContext() ) {
390 if ( aEvent->delta() > 0 ) {
391 ic->HilightNextDetected( myViewPort->getView() );
393 ic->HilightPreviousDetected( myViewPort->getView() );
398 emit vpTransformationStarted ( ZOOMVIEW );
399 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
400 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
403 int x1 = (int)( aEvent->x() + width()*delta/100 );
404 int y1 = (int)( aEvent->y() + height()*delta/100 );
405 myViewPort->zoom( x, y, x1, y1 );
406 myViewPort->getView()->ZFitAll();
407 emit vpTransformationFinished ( ZOOMVIEW );
412 case QEvent::ContextMenu:
414 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
415 if ( aEvent->reason() != QContextMenuEvent::Mouse )
416 emit contextMenuRequested( aEvent );
420 case QEvent::KeyPress:
421 emit keyPressed(this, (QKeyEvent*) e);
428 return SUIT_ViewWindow::eventFilter(watched, e);
432 \brief Enable / disable draw rect (rubber band) mode
434 bool OCCViewer_ViewWindow::enableDrawMode( bool on )
436 bool prev = myDrawRectEnabled;
437 myDrawRectEnabled = on;
438 updateEnabledDrawMode();
443 \brief Update state of enable draw mode state.
445 void OCCViewer_ViewWindow::updateEnabledDrawMode()
447 myEnableDrawMode = myDrawRectEnabled;
449 myEnableDrawMode = myEnableDrawMode && myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
453 \brief Handle mouse press event
454 \param theEvent mouse event
456 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
458 myStartX = theEvent->x();
459 myStartY = theEvent->y();
460 int anInteractionStyle = interactionStyle();
462 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
463 // which are assigned for pan and rotate - these operations are activated immediately after pressing
464 // of the first button, so it is necessary to switch to zoom when the second button is pressed
465 bool aSwitchToZoom = false;
466 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
467 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
468 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
471 switch ( myOperation ) {
473 if ( theEvent->button() == Qt::LeftButton )
474 emit vpTransformationStarted ( WINDOWFIT );
478 if ( theEvent->button() == Qt::LeftButton )
479 emit vpTransformationStarted ( PANGLOBAL );
483 if ( theEvent->button() == Qt::LeftButton ) {
484 myViewPort->startZoomAtPoint( myStartX, myStartY );
485 emit vpTransformationStarted ( ZOOMVIEW );
490 if ( aSwitchToZoom ) {
491 myViewPort->startZoomAtPoint( myStartX, myStartY );
494 else if ( theEvent->button() == Qt::LeftButton )
495 emit vpTransformationStarted ( PANVIEW );
499 if ( aSwitchToZoom ) {
500 myViewPort->startZoomAtPoint( myStartX, myStartY );
503 else if ( theEvent->button() == Qt::LeftButton ) {
504 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
505 emit vpTransformationStarted ( ROTATE );
510 /* Try to activate a transformation */
511 OperationType aState;
512 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
513 aState = getButtonState(theEvent, anInteractionStyle);
515 aState = OCCViewer_ViewWindow::NOTHING;
520 myViewPort->startZoomAtPoint( myStartX, myStartY );
528 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
531 if ( myRotationPointSelection )
533 if ( theEvent->button() == Qt::LeftButton )
535 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
537 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
539 TopoDS_Shape aShape = ic->SelectedShape();
540 GProp_GProps aSystem;
542 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
544 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
546 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE )
548 BRepGProp::LinearProperties( aShape, aSystem );
549 aPnt = aSystem.CentreOfMass();
551 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE )
553 BRepGProp::SurfaceProperties( aShape, aSystem );
554 aPnt = aSystem.CentreOfMass();
556 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID )
558 BRepGProp::VolumeProperties( aShape, aSystem );
559 aPnt = aSystem.CentreOfMass();
563 myCurrPointType = myPrevPointType;
567 if ( mySetRotationPointDlg )
569 myRotationPointSelection = false;
570 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
573 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
574 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
575 ic->CloseAllContexts();
576 myOperation = NOTHING;
577 myViewPort->setCursor( myCursor );
578 myCursorIsHand = false;
579 myRotationPointSelection = false;
583 emit mousePressed(this, theEvent);
586 /* notify that we start a transformation */
587 if ( transformRequested() )
588 emit vpTransformationStarted ( myOperation );
590 if ( transformRequested() )
591 setTransformInProcess( true );
593 /* we may need it for sketching... */
594 if ( l_mbPressEvent )
595 delete l_mbPressEvent;
596 l_mbPressEvent = new QMouseEvent( *theEvent );
601 \brief Start zooming operation.
603 Sets the corresponding cursor for the widget.
605 void OCCViewer_ViewWindow::activateZoom()
607 if ( !transformRequested() && !myCursorIsHand )
608 saveCursor(); /* save old cursor */
610 if ( myOperation != ZOOMVIEW ) {
611 QPixmap zoomPixmap (imageZoomCursor);
612 QCursor zoomCursor (zoomPixmap);
613 if( setTransformRequested ( ZOOMVIEW ) )
614 myViewPort->setCursor( zoomCursor );
620 \brief Start panning operation.
622 Sets the corresponding cursor for the widget.
624 void OCCViewer_ViewWindow::activatePanning()
626 if ( !transformRequested() && !myCursorIsHand )
627 saveCursor(); // save old cursor
629 if ( myOperation != PANVIEW ) {
630 QCursor panCursor (Qt::SizeAllCursor);
631 if( setTransformRequested ( PANVIEW ) )
632 myViewPort->setCursor( panCursor );
637 \brief Start rotation operation
639 Sets the corresponding cursor for the widget.
641 void OCCViewer_ViewWindow::activateRotation()
643 if ( !transformRequested() && !myCursorIsHand )
644 saveCursor(); // save old cursor
646 if ( myOperation != ROTATE ) {
647 QPixmap rotatePixmap (imageRotateCursor);
648 QCursor rotCursor (rotatePixmap);
649 if( setTransformRequested ( ROTATE ) )
650 myViewPort->setCursor( rotCursor );
655 \brief Compute the gravity center.
656 \param theX used to return X coordinate of the gravity center
657 \param theY used to return Y coordinate of the gravity center
658 \param theZ used to return Z coordinate of the gravity center
659 \return \c true if the gravity center is computed
661 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
663 Handle(V3d_View) aView3d = myViewPort->getView();
665 // Project boundaries points and add to avergae gravity
666 // the ones which lie within the screen limits
667 Standard_Real aScreenLimits[4] = { 0.0, 0.0, 0.0, 0.0 };
669 #if OCC_VERSION_LARGE > 0x06070100
670 // NDC space screen limits
671 aScreenLimits[0] = -1.0;
672 aScreenLimits[1] = 1.0;
673 aScreenLimits[2] = -1.0;
674 aScreenLimits[3] = 1.0;
676 aView3d->View()->ViewMapping().WindowLimit( aScreenLimits[0],
682 Standard_Integer aPointsNb = 0;
684 Standard_Real aXmin = 0.0;
685 Standard_Real aYmin = 0.0;
686 Standard_Real aZmin = 0.0;
687 Standard_Real aXmax = 0.0;
688 Standard_Real aYmax = 0.0;
689 Standard_Real aZmax = 0.0;
691 Graphic3d_MapOfStructure aSetOfStructures;
692 aView3d->View()->DisplayedStructures( aSetOfStructures );
693 Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures );
695 for( ; aStructureIt.More(); aStructureIt.Next() ) {
696 const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key();
697 if ( aStructure->IsEmpty() || !aStructure->IsVisible() || aStructure->CStructure()->IsForHighlight )
700 #if OCC_VERSION_LARGE > 0x06070100
701 Bnd_Box aBox = aStructure->MinMaxValues();
702 aXmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().X();
703 aYmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Y();
704 aZmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Z();
705 aXmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().X();
706 aYmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Y();
707 aZmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Z();
709 aStructure->MinMaxValues( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
712 // Infinite structures are skipped
713 Standard_Real aLIM = ShortRealLast() - 1.0;
714 if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
715 || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
719 gp_Pnt aPoints[8] = {
720 gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
721 gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
722 gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
723 gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
726 for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
727 const gp_Pnt& aBBPoint = aPoints[aPointIt];
729 #if OCC_VERSION_LARGE > 0x06070100
730 gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
731 const Standard_Real& U = aProjected.X();
732 const Standard_Real& V = aProjected.Y();
734 Standard_Real U = 0.0;
735 Standard_Real V = 0.0;
736 Standard_Real W = 0.0;
737 aView3d->View()->Projects( aBBPoint.X(), aBBPoint.Y(), aBBPoint.Z(), U, V, W );
740 if (U >= aScreenLimits[0]
741 && U <= aScreenLimits[1]
742 && V >= aScreenLimits[2]
743 && V <= aScreenLimits[3])
746 theX += aBBPoint.X();
747 theY += aBBPoint.Y();
748 theZ += aBBPoint.Z();
763 \brief Set the gravity center as a rotation point.
765 void OCCViewer_ViewWindow::activateSetRotationGravity()
767 if ( myRotationPointSelection )
769 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
770 ic->CloseAllContexts();
771 myOperation = NOTHING;
772 myViewPort->setCursor( myCursor );
773 myCursorIsHand = false;
774 myRotationPointSelection = false;
777 myPrevPointType = myCurrPointType;
778 myCurrPointType = GRAVITY;
780 Standard_Real Xcenter, Ycenter, Zcenter;
781 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
782 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
786 \brief Update gravity center in the "Set Rotation Point" dialog box.
787 \sa OCCViewer_SetRotationPointDlg class
789 void OCCViewer_ViewWindow::updateGravityCoords()
791 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == GRAVITY )
793 Standard_Real Xcenter, Ycenter, Zcenter;
794 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
795 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
800 \brief Set the point selected by the user as a rotation point.
801 \param theX X coordinate of the rotation point
802 \param theY Y coordinate of the rotation point
803 \param theZ Z coordinate of the rotation point
805 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
807 if ( myRotationPointSelection )
809 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
810 ic->CloseAllContexts();
811 myOperation = NOTHING;
812 myViewPort->setCursor( myCursor );
813 myCursorIsHand = false;
814 myRotationPointSelection = false;
817 myPrevPointType = myCurrPointType;
818 myCurrPointType = SELECTED;
819 mySelectedPoint.SetCoord(theX,theY,theZ);
823 \brief Start the shape selection process.
825 void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
827 myPrevPointType = myCurrPointType;
828 myCurrPointType = SELECTED;
830 // activate selection ------>
831 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
833 ic->OpenLocalContext();
835 AIS_ListOfInteractive aList;
836 ic->DisplayedObjects( aList );
837 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
839 Handle(AIS_InteractiveObject) anObj = it.Value();
840 if ( !anObj.IsNull() && anObj->HasPresentation() &&
841 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
844 ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
847 // activate selection <------
849 if ( !myCursorIsHand )
851 QCursor handCursor (Qt::PointingHandCursor);
852 myCursorIsHand = true;
854 myViewPort->setCursor( handCursor );
856 myRotationPointSelection = true;
860 \brief Start global panning operation
862 Sets the corresponding cursor for the widget.
864 void OCCViewer_ViewWindow::activateGlobalPanning()
866 Handle(V3d_View) aView3d = myViewPort->getView();
867 if ( !aView3d.IsNull() ) {
868 QPixmap globalPanPixmap (imageCrossCursor);
869 QCursor glPanCursor (globalPanPixmap);
870 myCurScale = aView3d->Scale();
871 aView3d->FitAll(0.01, false);
872 saveCursor(); // save old cursor
873 myViewPort->fitAll(); // fits view before selecting a new scene center
874 if( setTransformRequested( PANGLOBAL ) )
875 myViewPort->setCursor( glPanCursor );
880 \brief Starts fit operation.
882 Sets the corresponding cursor for the widget.
884 void OCCViewer_ViewWindow::activateWindowFit()
886 if ( !transformRequested() && !myCursorIsHand )
887 saveCursor(); /* save old cursor */
889 if ( myOperation != WINDOWFIT ) {
890 QCursor handCursor (Qt::PointingHandCursor);
891 if( setTransformRequested ( WINDOWFIT ) )
893 myViewPort->setCursor ( handCursor );
894 myCursorIsHand = true;
900 \brief Start delayed viewer operation.
902 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
904 bool ok = transformEnabled( op );
905 myOperation = ok ? op : NOTHING;
906 myViewPort->setMouseTracking( myOperation == NOTHING );
911 \brief Handle mouse move event.
912 \param theEvent mouse event
914 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
916 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
918 switch ( getButtonState( theEvent, interactionStyle() ) ) {
920 myViewPort->startZoomAtPoint( myStartX, myStartY );
928 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
935 myCurrX = theEvent->x();
936 myCurrY = theEvent->y();
937 switch (myOperation) {
939 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
943 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
949 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
963 if ( myRotationPointSelection || isSketcherStyle() )
965 emit mouseMoving( this, theEvent );
969 int aState = theEvent->modifiers();
970 int aButton = theEvent->buttons();
971 int anInteractionStyle = interactionStyle();
972 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
973 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
974 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
975 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
976 myDrawRect = myEnableDrawMode;
979 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
980 QCursor handCursor (Qt::PointingHandCursor);
981 myCursorIsHand = true;
983 myViewPort->setCursor( handCursor );
986 emit mouseMoving( this, theEvent );
988 else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
989 aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
990 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
991 aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
992 OCCViewer_ViewSketcher* sketcher = 0;
993 QList<OCCViewer_ViewSketcher*>::Iterator it;
994 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
996 OCCViewer_ViewSketcher* sk = (*it);
997 if( sk->isDefault() && sk->sketchButton() == aButton )
1000 if ( sketcher && myCurSketch == -1 )
1002 activateSketching( sketcher->type() );
1005 myCurSketch = mypSketcher->sketchButton();
1007 if ( l_mbPressEvent )
1009 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
1010 delete l_mbPressEvent;
1013 QApplication::sendEvent( getViewPort(), theEvent );
1018 emit mouseMoving( this, theEvent );
1024 \brief Handle mouse release event.
1025 \param theEvent mouse event
1027 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
1029 switch ( myOperation ) {
1032 int prevState = myCurSketch;
1033 if(theEvent->button() == Qt::RightButton)
1035 QList<OCCViewer_ViewSketcher*>::Iterator it;
1036 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
1038 OCCViewer_ViewSketcher* sk = (*it);
1039 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
1044 emit mouseReleased(this, theEvent);
1045 if(theEvent->button() == Qt::RightButton && prevState == -1)
1047 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1048 theEvent->pos(), theEvent->globalPos() );
1049 emit contextMenuRequested( &aEvent );
1054 myViewPort->endRotation();
1060 myViewPort->getView()->ZFitAll();
1065 if ( theEvent->button() == Qt::LeftButton ) {
1066 myViewPort->setCenter( theEvent->x(), theEvent->y() );
1067 myViewPort->getView()->SetScale(myCurScale);
1073 if ( theEvent->button() == Qt::LeftButton ) {
1074 myCurrX = theEvent->x();
1075 myCurrY = theEvent->y();
1077 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1078 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1085 // NOTE: viewer 3D detects a rectangle of selection using this event
1086 // so we must emit it BEFORE resetting the selection rectangle
1088 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1092 myViewPort->update();
1095 if ( l_mbPressEvent )
1097 delete l_mbPressEvent;
1103 \brief Reset the viewport to its initial state
1104 ( no transformations in process etc. )
1106 void OCCViewer_ViewWindow::resetState()
1110 if ( myRotationPointSelection )
1112 QCursor handCursor (Qt::PointingHandCursor);
1113 myViewPort->setCursor( handCursor );
1117 if ( transformRequested() || myCursorIsHand )
1118 myViewPort->setCursor( myCursor );
1119 myCursorIsHand = false;
1122 if ( transformRequested() )
1123 emit vpTransformationFinished (myOperation);
1125 setTransformInProcess( false );
1126 setTransformRequested( NOTHING );
1131 \brief Draw rubber band rectangle.
1133 void OCCViewer_ViewWindow::drawRect()
1135 if ( !myRectBand ) {
1136 myRectBand = new QtxRectRubberBand( myViewPort );
1138 //palette.setColor(myRectBand->foregroundRole(), Qt::white);
1139 //myRectBand->setPalette(palette);
1141 //myRectBand->hide();
1143 myRectBand->setUpdatesEnabled ( false );
1144 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1145 myRectBand->initGeometry( aRect );
1147 if ( !myRectBand->isVisible() )
1150 myRectBand->setUpdatesEnabled ( true );
1151 //myRectBand->repaint();
1153 //myRectBand->setVisible( aRect.isValid() );
1154 //if ( myRectBand->isVisible() )
1155 // myRectBand->repaint();
1157 // myRectBand->show();
1158 //myRectBand->repaint();
1162 \brief Clear rubber band rectangle on the end on the dragging operation.
1164 void OCCViewer_ViewWindow::endDrawRect()
1166 //delete myRectBand;
1170 myRectBand->clearGeometry();
1176 \brief Create actions.
1178 void OCCViewer_ViewWindow::createActions()
1180 if( !toolMgr()->isEmpty() )
1183 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1188 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1189 tr( "MNU_DUMP_VIEW" ), 0, this);
1190 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1191 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1192 toolMgr()->registerAction( aAction, DumpId );
1195 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1196 tr( "MNU_FITALL" ), 0, this);
1197 aAction->setStatusTip(tr("DSC_FITALL"));
1198 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1199 toolMgr()->registerAction( aAction, FitAllId );
1202 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1203 tr( "MNU_FITRECT" ), 0, this);
1204 aAction->setStatusTip(tr("DSC_FITRECT"));
1205 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1206 toolMgr()->registerAction( aAction, FitRectId );
1209 aAction = new QtxAction(tr("MNU_FITSELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITSELECTION" ) ),
1210 tr( "MNU_FITSELECTION" ), 0, this);
1211 aAction->setStatusTip(tr("DSC_FITSELECTION"));
1212 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
1213 toolMgr()->registerAction( aAction, FitSelectionId );
1216 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1217 tr( "MNU_ZOOM_VIEW" ), 0, this);
1218 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1219 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1220 toolMgr()->registerAction( aAction, ZoomId );
1223 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1224 tr( "MNU_PAN_VIEW" ), 0, this);
1225 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1226 connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
1227 toolMgr()->registerAction( aAction, PanId );
1230 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1231 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1232 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1233 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1234 toolMgr()->registerAction( aAction, GlobalPanId );
1237 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1238 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1239 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1240 mySetRotationPointAction->setCheckable( true );
1241 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1242 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1245 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1246 tr( "MNU_ROTATE_VIEW" ), 0, this);
1247 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1248 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1249 toolMgr()->registerAction( aAction, RotationId );
1252 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1253 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1254 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1255 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1256 this->addAction(aAction);
1257 toolMgr()->registerAction( aAction, FrontId );
1259 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1260 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1261 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1262 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1263 this->addAction(aAction);
1264 toolMgr()->registerAction( aAction, BackId );
1266 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1267 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1268 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1269 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1270 this->addAction(aAction);
1271 toolMgr()->registerAction( aAction, TopId );
1273 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1274 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1275 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1276 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1277 this->addAction(aAction);
1278 toolMgr()->registerAction( aAction, BottomId );
1280 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1281 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1282 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1283 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1284 this->addAction(aAction);
1285 toolMgr()->registerAction( aAction, LeftId );
1287 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1288 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1289 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1290 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1291 this->addAction(aAction);
1292 toolMgr()->registerAction( aAction, RightId );
1294 // rotate anticlockwise
1295 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1296 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1297 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1298 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1299 this->addAction(aAction);
1300 toolMgr()->registerAction( aAction, AntiClockWiseId );
1303 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1304 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1305 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1306 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1307 this->addAction(aAction);
1308 toolMgr()->registerAction( aAction, ClockWiseId );
1310 // Projection mode group
1312 // - orthographic projection
1313 aAction = new QtxAction(tr("MNU_ORTHOGRAPHIC_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ORTHOGRAPHIC" ) ),
1314 tr( "MNU_ORTHOGRAPHIC_MODE" ), 0, this);
1315 aAction->setStatusTip(tr("DSC_ORTHOGRAPHIC_MODE"));
1316 aAction->setCheckable(true);
1317 toolMgr()->registerAction( aAction, OrthographicId );
1319 // - perspective projection
1320 aAction = new QtxAction(tr("MNU_PERSPECTIVE_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PERSPECTIVE" ) ),
1321 tr( "MNU_PERSPECTIVE_MODE" ), 0, this);
1322 aAction->setStatusTip(tr("DSC_PERSPECTIVE_MODE"));
1323 aAction->setCheckable(true);
1324 toolMgr()->registerAction( aAction, PerspectiveId );
1325 #if OCC_VERSION_LARGE > 0x06090000
1326 // - stereo projection
1327 aAction = new QtxAction(tr("MNU_STEREO_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STEREO" ) ),
1328 tr( "MNU_STEREO_MODE" ), 0, this);
1329 aAction->setStatusTip(tr("DSC_STEREO_MODE"));
1330 aAction->setCheckable(true);
1331 toolMgr()->registerAction( aAction, StereoId );
1332 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onStereoType(bool)));
1334 // - add exclusive action group
1335 QActionGroup* aProjectionGroup = new QActionGroup( this );
1336 aProjectionGroup->addAction( toolMgr()->action( OrthographicId ) );
1337 aProjectionGroup->addAction( toolMgr()->action( PerspectiveId ) );
1338 connect(aProjectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProjectionType(QAction*)));
1341 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1342 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1343 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1344 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1345 this->addAction(aAction);
1346 toolMgr()->registerAction( aAction, ResetId );
1349 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1350 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1351 tr("MNU_CLONE_VIEW"), 0, this);
1352 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1353 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1354 toolMgr()->registerAction( aAction, CloneId );
1356 aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
1357 tr("MNU_CLIPPING"), 0, this);
1358 aAction->setStatusTip (tr("DSC_CLIPPING"));
1359 aAction->setCheckable (true);
1360 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1361 toolMgr()->registerAction (aAction, ClippingId);
1363 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1364 tr( "MNU_SHOOT_VIEW" ), 0, this);
1365 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1366 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1367 toolMgr()->registerAction( aAction, MemId );
1369 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1370 tr( "MNU_PRESETS_VIEW" ), 0, this);
1371 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1372 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1373 toolMgr()->registerAction( aAction, RestoreId );
1375 if (myModel->trihedronActivated()) {
1376 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1377 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1378 aAction->setCheckable( true );
1379 aAction->setChecked( true );
1380 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1381 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1382 toolMgr()->registerAction( aAction, TrihedronShowId );
1386 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1387 tr( "MNU_SCALING" ), 0, this);
1388 aAction->setStatusTip(tr("DSC_SCALING"));
1389 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1390 toolMgr()->registerAction( aAction, AxialScaleId );
1392 // Enable/disable preselection
1393 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1394 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1395 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1396 aAction->setCheckable(true);
1397 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1398 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1400 // Enable/disable selection
1401 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1402 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1403 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1404 aAction->setCheckable(true);
1405 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1406 toolMgr()->registerAction( aAction, SwitchSelectionId );
1409 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1410 tr( "MNU_GRADUATED_AXES" ), 0, this);
1411 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1412 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1413 toolMgr()->registerAction( aAction, GraduatedAxesId );
1415 // Active only ambient light or not
1416 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1417 tr( "MNU_AMBIENT" ), 0, this);
1418 aAction->setStatusTip(tr("DSC_AMBIENT"));
1419 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1420 toolMgr()->registerAction( aAction, AmbientId );
1422 // Switch between interaction styles
1423 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1424 tr( "MNU_STYLE_SWITCH" ), 0, this);
1425 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1426 aAction->setCheckable(true);
1427 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1428 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1430 // Switch between zooming styles
1431 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1432 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1433 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1434 aAction->setCheckable(true);
1435 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1436 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1439 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1440 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1441 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1442 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1443 toolMgr()->registerAction( aAction, MaximizedId );
1445 // Return to 3d view
1446 if (my2dMode!=No2dMode){
1447 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1448 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1449 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1450 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1451 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1455 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1456 #ifdef ENABLE_RAY_TRACING
1458 aAction = new QtxAction( tr("MNU_RAY_TRACING"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_RAY_TRACING") ),
1459 tr("MNU_RAY_TRACING"), 0, this );
1460 aAction->setStatusTip( tr("DSC_RAY_TRACING") );
1461 connect( aAction, SIGNAL( triggered() ), this, SLOT( onRayTracing() ) );
1462 toolMgr()->registerAction( aAction, RayTracingId );
1464 // Environment texture
1465 aAction = new QtxAction( tr("MNU_ENV_TEXTURE"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_ENV_TEXTURE") ),
1466 tr("MNU_ENV_TEXTURE"), 0, this );
1467 aAction->setStatusTip( tr("DSC_ENV_TEXTURE") );
1468 connect( aAction, SIGNAL( triggered() ), this, SLOT( onEnvTexture() ) );
1469 toolMgr()->registerAction( aAction, EnvTextureId );
1472 aAction = new QtxAction( tr("MNU_LIGHT_SOURCE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_LIGHT_SOURCE" ) ),
1473 tr( "MNU_LIGHT_SOURCE" ), 0, this );
1474 aAction->setStatusTip( tr("DSC_LIGHT_SOURCE") );
1475 connect( aAction, SIGNAL( triggered() ), this, SLOT( onLightSource() ) );
1476 toolMgr()->registerAction( aAction, LightSourceId );
1481 \brief Create toolbar.
1483 void OCCViewer_ViewWindow::createToolBar()
1485 static const char* titles[] = {
1486 "LBL_3DTOOLBAR_LABEL",
1487 "LBL_XYTOOLBAR_LABEL",
1488 "LBL_XZTOOLBAR_LABEL",
1489 "LBL_YZTOOLBAR_LABEL",
1491 static const char* names[] = {
1492 "OCCViewer3DViewOperations",
1493 "OCCViewerXYViewOperations",
1494 "OCCViewerXZViewOperations",
1495 "OCCViewerYZViewOperations",
1497 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1498 QString( names[my2dMode] ), // name (language-independant)
1499 false ); // disable floatable toolbar
1500 if ( my2dMode != No2dMode ){
1501 toolMgr()->append( ReturnTo3dViewId, tid );
1502 toolMgr()->append( toolMgr()->separator(), tid );
1504 toolMgr()->append( DumpId, tid );
1505 toolMgr()->append( SwitchInteractionStyleId, tid );
1506 toolMgr()->append( SwitchZoomingStyleId, tid );
1507 toolMgr()->append( SwitchPreselectionId, tid );
1508 toolMgr()->append( SwitchSelectionId, tid );
1509 if( myModel->trihedronActivated() )
1510 toolMgr()->append( TrihedronShowId, tid );
1512 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1513 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1514 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1515 #if OCC_VERSION_LARGE > 0x06090000
1516 aScaleAction->insertAction( toolMgr()->action( FitSelectionId ) );
1518 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1519 toolMgr()->append( aScaleAction, tid );
1521 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1522 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1523 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1524 toolMgr()->append( aPanningAction, tid );
1526 if (my2dMode == No2dMode) {
1527 toolMgr()->append( ChangeRotationPointId, tid );
1528 toolMgr()->append( RotationId, tid );
1530 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1531 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1532 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1533 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1534 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1535 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1536 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1537 toolMgr()->append( aViewsAction, tid );
1539 toolMgr()->append( AntiClockWiseId, tid );
1540 toolMgr()->append( ClockWiseId, tid );
1542 toolMgr()->append( OrthographicId, tid );
1543 toolMgr()->append( PerspectiveId, tid );
1544 #if OCC_VERSION_LARGE > 0x06090000
1545 toolMgr()->append( StereoId, tid );
1548 toolMgr()->append( ResetId, tid );
1551 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1552 aMemAction->insertAction( toolMgr()->action( MemId ) );
1553 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1554 toolMgr()->append( aMemAction, tid );
1556 toolMgr()->append( toolMgr()->separator(), tid );
1557 toolMgr()->append( CloneId, tid );
1559 toolMgr()->append( toolMgr()->separator(), tid );
1560 toolMgr()->append( ClippingId, tid );
1561 toolMgr()->append( AxialScaleId, tid );
1562 toolMgr()->append( GraduatedAxesId, tid );
1563 toolMgr()->append( AmbientId, tid );
1565 toolMgr()->append( MaximizedId, tid );
1566 toolMgr()->append( SynchronizeId, tid );
1567 #ifdef ENABLE_RAY_TRACING
1568 toolMgr()->append( RayTracingId, tid );
1569 toolMgr()->append( EnvTextureId, tid );
1570 toolMgr()->append( LightSourceId, tid );
1575 \brief Perform 'fit all' operation.
1577 void OCCViewer_ViewWindow::onViewFitAll()
1579 myViewPort->fitAll();
1583 \brief Perform "front view" transformation.
1585 void OCCViewer_ViewWindow::onFrontView()
1587 emit vpTransformationStarted ( FRONTVIEW );
1588 Handle(V3d_View) aView3d = myViewPort->getView();
1589 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
1591 emit vpTransformationFinished ( FRONTVIEW );
1595 \brief Perform "back view" transformation.
1597 void OCCViewer_ViewWindow::onBackView()
1599 emit vpTransformationStarted ( BACKVIEW );
1600 Handle(V3d_View) aView3d = myViewPort->getView();
1601 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
1603 emit vpTransformationFinished ( BACKVIEW );
1607 \brief Perform "top view" transformation.
1609 void OCCViewer_ViewWindow::onTopView()
1611 emit vpTransformationStarted ( TOPVIEW );
1612 Handle(V3d_View) aView3d = myViewPort->getView();
1613 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
1615 emit vpTransformationFinished ( TOPVIEW );
1619 \brief Perform "bottom view" transformation.
1621 void OCCViewer_ViewWindow::onBottomView()
1623 emit vpTransformationStarted ( BOTTOMVIEW );
1624 Handle(V3d_View) aView3d = myViewPort->getView();
1625 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
1627 emit vpTransformationFinished ( BOTTOMVIEW );
1631 \brief Perform "left view" transformation.
1633 void OCCViewer_ViewWindow::onLeftView()
1635 emit vpTransformationStarted ( LEFTVIEW );
1636 Handle(V3d_View) aView3d = myViewPort->getView();
1637 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
1639 emit vpTransformationFinished ( LEFTVIEW );
1643 \brief Perform "right view" transformation.
1645 void OCCViewer_ViewWindow::onRightView()
1647 emit vpTransformationStarted ( RIGHTVIEW );
1648 Handle(V3d_View) aView3d = myViewPort->getView();
1649 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
1651 emit vpTransformationFinished ( RIGHTVIEW );
1655 \brief Rotate view 90 degrees clockwise
1657 void OCCViewer_ViewWindow::onClockWiseView()
1659 emit vpTransformationStarted ( CLOCKWISEVIEW );
1660 myViewPort->rotateXY( 90. );
1661 emit vpTransformationFinished ( CLOCKWISEVIEW );
1665 \brief Rotate view 90 degrees conterclockwise
1667 void OCCViewer_ViewWindow::onAntiClockWiseView()
1669 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1670 myViewPort->rotateXY( -90. );
1671 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1675 \brief Perform "reset view" transformation.
1677 Sets default orientation of the viewport camera.
1679 void OCCViewer_ViewWindow::onResetView()
1681 emit vpTransformationStarted( RESETVIEW );
1682 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1683 myViewPort->getView()->Reset( false );
1684 myViewPort->fitAll( false, true, false );
1685 myViewPort->getView()->SetImmediateUpdate( upd );
1686 onProjectionType(); // needed to apply projection type properly after reset
1687 myViewPort->getView()->Update();
1688 emit vpTransformationFinished( RESETVIEW );
1692 \brief Set the given projection mode.
1694 Set the given projection mode: Orthographic or Perspective.
1696 void OCCViewer_ViewWindow::onProjectionType( QAction* theAction )
1698 Handle(V3d_View) aView3d = myViewPort->getView();
1699 if ( !aView3d.IsNull() ) {
1700 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1701 if (theAction == toolMgr()->action( OrthographicId )) {
1702 myModel->setProjectionType(Orthographic);
1703 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Orthographic );
1704 aCamera->SetFOVy(45.0);
1706 else if (theAction == toolMgr()->action( PerspectiveId )) {
1707 myModel->setProjectionType(Perspective);
1708 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Perspective );
1709 aCamera->SetFOVy(30.0);
1711 #if OCC_VERSION_LARGE > 0x06090000
1712 if (toolMgr()->action( StereoId )->isChecked()) {
1713 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1714 aCamera->SetFOVy(30.0);
1723 \brief Sets Stereo projection mode.
1725 Sets Stereo projection mode.
1727 void OCCViewer_ViewWindow::onStereoType( bool activate )
1729 #if OCC_VERSION_LARGE > 0x06090000
1730 Handle(V3d_View) aView3d = myViewPort->getView();
1731 if ( !aView3d.IsNull() ) {
1732 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1734 toolMgr()->action( PerspectiveId )->setChecked(true);
1735 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1736 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(false);
1738 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1739 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1740 setStereoType( aResMgr->integerValue( "OCCViewer", "stereo_type", 0 ) );
1741 setAnaglyphFilter( aResMgr->integerValue( "OCCViewer", "anaglyph_filter", 0 ) );
1742 setReverseStereo( aResMgr->booleanValue( "OCCViewer", "reverse_stereo", false ) );
1743 setVSync( aResMgr->booleanValue( "OCCViewer", "enable_vsync", true ) );
1744 setQuadBufferSupport( aResMgr->booleanValue( "OCCViewer", "enable_quad_buffer_support", false ) );
1747 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(true);
1748 if (myModel->projectionType() == Orthographic) {
1749 toolMgr()->action( OrthographicId )->setChecked(true);
1750 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Orthographic);
1752 else if (myModel->projectionType() == Perspective) {
1753 toolMgr()->action( PerspectiveId )->setChecked(true);
1754 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1761 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1762 toolMgr()->action( StereoId )->isChecked() )
1763 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1768 \brief Restore the view.
1770 Restore the projection mode based on tool-buttons states.
1772 void OCCViewer_ViewWindow::onProjectionType()
1774 emit vpTransformationStarted( PROJECTION );
1775 if (toolMgr()->action( OrthographicId )->isChecked())
1776 setProjectionType( Orthographic );
1777 if (toolMgr()->action( PerspectiveId )->isChecked())
1778 setProjectionType( Perspective );
1779 #if OCC_VERSION_LARGE > 0x06090000
1780 if (toolMgr()->action( StereoId )->isChecked())
1781 setProjectionType( Stereo );
1783 emit vpTransformationFinished( PROJECTION );
1786 void OCCViewer_ViewWindow::setProjectionType( int mode )
1788 QtxAction* anOrthographicAction = dynamic_cast<QtxAction*>( toolMgr()->action( OrthographicId ) );
1789 QtxAction* aPerspectiveAction = dynamic_cast<QtxAction*>( toolMgr()->action( PerspectiveId ) );
1790 #if OCC_VERSION_LARGE > 0x06090000
1791 QtxAction* aStereoAction = dynamic_cast<QtxAction*>( toolMgr()->action( StereoId ) );
1795 onProjectionType( anOrthographicAction );
1798 onProjectionType( aPerspectiveAction );
1801 onStereoType( true );
1804 // update action state if method is called outside
1805 if ( mode == Orthographic && !anOrthographicAction->isChecked() ) {
1806 anOrthographicAction->setChecked( true );
1807 #if OCC_VERSION_LARGE > 0x06090000
1808 aStereoAction->setChecked( false );
1811 if ( mode == Perspective && !aPerspectiveAction->isChecked() ) {
1812 aPerspectiveAction->setChecked( true );
1813 #if OCC_VERSION_LARGE > 0x06090000
1814 aStereoAction->setChecked( false );
1817 #if OCC_VERSION_LARGE > 0x06090000
1818 if ( mode == Stereo ) {
1819 aStereoAction->setChecked( true );
1820 if ( anOrthographicAction->isEnabled() ) {
1821 anOrthographicAction->setEnabled( false );
1822 anOrthographicAction->setChecked( false );
1823 aStereoAction->setChecked( false );
1826 anOrthographicAction->setEnabled( true );
1827 aStereoAction->setChecked( false );
1828 anOrthographicAction->setChecked(myModel->projectionType() == Orthographic);
1830 if ( aPerspectiveAction->isEnabled() ) {
1831 aPerspectiveAction->setEnabled( false );
1832 aPerspectiveAction->setChecked( true );
1833 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1834 toolMgr()->action( StereoId )->isChecked() )
1835 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1838 aPerspectiveAction->setEnabled( true );
1839 aStereoAction->setChecked( false );
1840 aPerspectiveAction->setChecked(myModel->projectionType() == Perspective);
1845 if ( !anOrthographicAction->isEnabled() )
1846 anOrthographicAction->setEnabled( true );
1847 if ( !aPerspectiveAction->isEnabled() )
1848 aPerspectiveAction->setEnabled( true );
1854 \brief Perform "fit all" transformation.
1856 void OCCViewer_ViewWindow::onFitAll()
1858 emit vpTransformationStarted( FITALLVIEW );
1859 myViewPort->fitAll();
1860 emit vpTransformationFinished( FITALLVIEW );
1864 \brief Perform "fit selection" transformation.
1866 void OCCViewer_ViewWindow::onFitSelection()
1868 emit vpTransformationStarted( FITSELECTION );
1869 #if OCC_VERSION_LARGE > 0x06090000
1870 myModel->getAISContext()->FitSelected( getViewPort()->getView() );
1872 emit vpTransformationFinished( FITSELECTION );
1876 \brief Called if 'change rotation point' operation is activated.
1877 \param on action state
1879 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1883 if (!mySetRotationPointDlg)
1885 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1886 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1889 if (!mySetRotationPointDlg->isVisible())
1891 //if (mySetRotationPointDlg->IsFirstShown())
1892 if (myCurrPointType == GRAVITY)
1894 Standard_Real Xcenter, Ycenter, Zcenter;
1895 if (computeGravityCenter(Xcenter, Ycenter, Zcenter))
1896 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1898 mySetRotationPointDlg->show();
1903 if (mySetRotationPointDlg->isVisible())
1904 mySetRotationPointDlg->hide();
1909 \brief Create one more window with same content.
1911 void OCCViewer_ViewWindow::onCloneView()
1913 SUIT_ViewWindow* vw = myManager->createViewWindow();
1915 emit viewCloned( vw );
1919 Creates one more window with same content
1921 void OCCViewer_ViewWindow::onAxialScale()
1923 if ( !myScalingDlg )
1924 myScalingDlg = new OCCViewer_AxialScaleDlg( this );
1926 if ( !myScalingDlg->isVisible() )
1928 myScalingDlg->Update();
1929 myScalingDlg->show();
1934 Shows Graduated Axes dialog
1936 void OCCViewer_ViewWindow::onGraduatedAxes()
1938 myCubeAxesDlg->Update();
1939 myCubeAxesDlg->show();
1942 void OCCViewer_ViewWindow::onAmbientToogle()
1944 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
1945 viewer->InitDefinedLights();
1946 while(viewer->MoreDefinedLights())
1948 Handle(V3d_Light) light = viewer->DefinedLight();
1949 if(light->Type() != V3d_AMBIENT)
1951 Handle(V3d_View) aView3d = myViewPort->getView();
1952 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
1953 else viewer->SetLightOn(light);
1955 viewer->NextDefinedLights();
1961 \brief Store view parameters.
1963 void OCCViewer_ViewWindow::onMemorizeView()
1965 appendViewAspect( getViewParams() );
1969 \brief Restore view parameters.
1971 void OCCViewer_ViewWindow::onRestoreView()
1973 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
1974 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
1976 updateViewAspects( aDlg->parameters() );
1977 if( myRestoreFlag && aDlg->parameters().count() )
1978 performRestoring( aDlg->currentItem() );
1982 \brief Restore view parameters.
1983 \param anItem view parameters
1985 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
1987 Handle(V3d_View) aView3d = myViewPort->getView();
1989 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
1990 aView3d->SetScale( anItem.scale );
1991 aView3d->SetTwist( anItem.twist );
1992 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
1993 aView3d->SetImmediateUpdate( prev );
1994 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1995 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1996 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
1998 #if OCC_VERSION_LARGE > 0x06070100
1999 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
2001 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
2003 // "eye" and "at" require conversion to represent center panning
2004 // up direction is only available after setting angle of twist and
2005 // other view parameters
2006 aView3d->Up( anUpX, anUpY, anUpZ );
2008 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
2009 gp_Dir anUp( anUpX, anUpY, anUpZ );
2010 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
2011 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2012 gp_Dir aSide = aProj ^ anUp;
2014 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
2015 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
2017 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
2018 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2021 aView3d->SetCenter( anItem.centerX, anItem.centerY );
2024 if ( !baseParamsOnly ) {
2026 myModel->setTrihedronShown( anItem.isVisible );
2027 myModel->setTrihedronSize( anItem.size );
2029 // graduated trihedron
2030 bool anIsVisible = anItem.gtIsVisible;
2031 OCCViewer_AxisWidget::AxisData anAxisData[3];
2032 anAxisData[0].DrawName = anItem.gtDrawNameX;
2033 anAxisData[1].DrawName = anItem.gtDrawNameZ;
2034 anAxisData[2].DrawName = anItem.gtDrawNameZ;
2035 anAxisData[0].Name = anItem.gtNameX;
2036 anAxisData[1].Name = anItem.gtNameZ;
2037 anAxisData[2].Name = anItem.gtNameZ;
2038 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
2039 anItem.gtNameColorGX,
2040 anItem.gtNameColorBX );
2041 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
2042 anItem.gtNameColorGY,
2043 anItem.gtNameColorBY );
2044 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
2045 anItem.gtNameColorGZ,
2046 anItem.gtNameColorBZ );
2047 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
2048 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
2049 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
2050 anAxisData[0].NbValues = anItem.gtNbValuesX;
2051 anAxisData[1].NbValues = anItem.gtNbValuesY;
2052 anAxisData[2].NbValues = anItem.gtNbValuesZ;
2053 anAxisData[0].Offset = anItem.gtOffsetX;
2054 anAxisData[1].Offset = anItem.gtOffsetY;
2055 anAxisData[2].Offset = anItem.gtOffsetZ;
2056 anAxisData[0].Color = QColor( anItem.gtColorRX,
2059 anAxisData[1].Color = QColor( anItem.gtColorRY,
2062 anAxisData[2].Color = QColor( anItem.gtColorRZ,
2065 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
2066 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
2067 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
2068 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
2069 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
2070 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
2072 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
2073 myCubeAxesDlg->ApplyData( aView3d );
2075 } // if ( !baseParamsOnly )
2081 \brief Set restore flag.
2083 void OCCViewer_ViewWindow::setRestoreFlag()
2089 \brief Called when action "show/hide trihedron" is activated.
2091 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
2093 myModel->setTrihedronShown(show);
2097 \brief Toggles preselection (highlighting) on/off
2099 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
2101 myPreselectionEnabled = on;
2102 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
2104 // unhighlight all highlighted objects
2106 myModel->unHighlightAll( true, false );
2109 // update action state if method is called outside
2110 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2111 if ( a && a->isChecked() != on ) {
2112 a->setChecked( on );
2117 \brief Toggles selection on/off
2119 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
2121 mySelectionEnabled = on;
2122 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
2124 // update action state if method is called outside
2127 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2129 a->setEnabled( on );
2133 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
2134 if ( a && a->isChecked() != on ) {
2135 a->setChecked( on );
2140 \brief Switches "keyboard free" interaction style on/off
2142 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
2144 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
2146 // update action state if method is called outside
2147 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
2148 if ( a->isChecked() != on )
2149 a->setChecked( on );
2153 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
2155 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
2157 myViewPort->setAdvancedZoomingEnabled( on );
2159 // update action state if method is called outside
2160 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
2161 if ( a->isChecked() != on )
2162 a->setChecked( on );
2166 \brief Get current interaction style
2167 \return interaction style
2169 int OCCViewer_ViewWindow::interactionStyle() const
2171 return myInteractionStyle;
2175 \brief Set current interaction style
2176 \param theStyle interaction style
2178 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
2180 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
2184 \brief Get current zooming style
2185 \return zooming style
2187 int OCCViewer_ViewWindow::zoomingStyle() const
2189 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
2193 \brief Set current zooming style
2194 \param theStyle zooming style
2196 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
2198 onSwitchZoomingStyle( theStyle == 1 );
2202 \brief Dump view window contents to the pixmap.
2203 \return pixmap containing all scene rendered in the window
2205 QImage OCCViewer_ViewWindow::dumpView()
2207 Handle(V3d_View) view = myViewPort->getView();
2208 if ( view.IsNull() )
2211 int aWidth = myViewPort->width();
2212 int aHeight = myViewPort->height();
2214 // rnv: An old approach to dump the OCCViewer content
2215 // Now used OCCT built-in procedure.
2217 QApplication::syncX();
2218 view->Redraw(); // In order to reactivate GL context
2221 #ifndef DISABLE_GLVIEWER
2222 OpenGLUtils_FrameBuffer aFrameBuffer;
2223 if( aFrameBuffer.init( aWidth, aHeight ) )
2225 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
2227 glPushAttrib( GL_VIEWPORT_BIT );
2228 glViewport( 0, 0, aWidth, aHeight );
2229 aFrameBuffer.bind();
2234 aFrameBuffer.unbind();
2237 aFrameBuffer.bind();
2238 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
2239 aFrameBuffer.unbind();
2241 anImage = anImage.rgbSwapped();
2242 anImage = anImage.mirrored();
2245 // if frame buffers are unsupported, use old functionality
2248 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
2250 QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
2252 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
2258 view->ToPixMap(aPix,aWidth, aHeight,Graphic3d_BT_RGBA);
2260 QImage anImage( aPix.Data(), aWidth, aHeight, QImage::Format_ARGB32 );
2261 anImage = anImage.mirrored();
2265 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
2266 const QString& fileName,
2267 const QString& format )
2270 QApplication::setOverrideCursor( Qt::WaitCursor );
2271 if ( format != "PS" && format != "EPS")
2272 res = myViewPort->getView()->Dump( fileName.toStdString().c_str() );
2274 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
2277 res = a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
2278 else if (format == "EPS")
2279 res = a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
2281 QApplication::restoreOverrideCursor();
2286 QString OCCViewer_ViewWindow::filter() const
2288 return tr( "OCC_IMAGE_FILES" );
2293 \brief Set parameters of the cutting plane
2294 \param on if \c true, cutting plane is enabled
2295 \param x X position of plane point
2296 \param y Y position of plane point
2297 \param z Z position of plane point
2298 \param dx X coordinate of plane normal
2299 \param dy Y coordinate of plane normal
2300 \param dz Z coordinate of plane normal
2302 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2303 const double dx, const double dy, const double dz )
2305 Handle(V3d_View) view = myViewPort->getView();
2306 if ( view.IsNull() )
2310 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2312 // try to use already existing plane or create a new one
2313 Handle(V3d_Plane) clipPlane;
2315 // calculate new a,b,c,d values for the plane
2316 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2318 pln.Coefficients(a, b, c, d);
2320 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2321 if(aPlanes.Size() > 0 ) {
2322 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2323 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2324 aClipPlane->SetEquation(pln);
2325 aClipPlane->SetOn(Standard_True);
2327 view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2331 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2332 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2333 for( ;anIter.More();anIter.Next() ){
2334 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2335 aClipPlane->SetOn(Standard_False);
2343 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2345 gp_Dir aDir = pln.Axis().Direction();
2346 gp_Pnt aPnt = pln.Location();
2347 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2352 \brief Check if any cutting plane is enabled
2353 \return \c true if at least one cutting plane is enabled
2355 bool OCCViewer_ViewWindow::isCuttingPlane()
2357 Handle(V3d_View) view = myViewPort->getView();
2359 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2360 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2361 for( ;anIter.More();anIter.Next() ) {
2362 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2363 if(aClipPlane->IsOn()) {
2372 \brief Get the visual parameters of the view window.
2373 \return visual parameters of view window
2375 viewAspect OCCViewer_ViewWindow::getViewParams() const
2377 double projX, projY, projZ, twist;
2378 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2379 double aScaleX, aScaleY, aScaleZ;
2381 Handle(V3d_View) aView3d = myViewPort->getView();
2383 aView3d->Proj( projX, projY, projZ );
2384 aView3d->At( atX, atY, atZ );
2385 aView3d->Eye( eyeX, eyeY, eyeZ );
2386 twist = aView3d->Twist();
2388 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2390 bool isShown = myModel->isTrihedronVisible();
2391 double size = myModel->trihedronSize();
2393 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2396 params.scale = aView3d->Scale();
2397 params.projX = projX;
2398 params.projY = projY;
2399 params.projZ = projZ;
2400 params.twist = twist;
2407 params.scaleX = aScaleX;
2408 params.scaleY = aScaleY;
2409 params.scaleZ = aScaleZ;
2410 params.name = aName;
2411 params.isVisible= isShown;
2414 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2415 aView3d->Center( params.centerX, params.centerY );
2418 // graduated trihedron
2419 bool anIsVisible = false;
2420 OCCViewer_AxisWidget::AxisData anAxisData[3];
2421 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2423 params.gtIsVisible = anIsVisible;
2424 params.gtDrawNameX = anAxisData[0].DrawName;
2425 params.gtDrawNameY = anAxisData[1].DrawName;
2426 params.gtDrawNameZ = anAxisData[2].DrawName;
2427 params.gtNameX = anAxisData[0].Name;
2428 params.gtNameY = anAxisData[1].Name;
2429 params.gtNameZ = anAxisData[2].Name;
2430 params.gtNameColorRX = anAxisData[0].NameColor.red();
2431 params.gtNameColorGX = anAxisData[0].NameColor.green();
2432 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2433 params.gtNameColorRY = anAxisData[1].NameColor.red();
2434 params.gtNameColorGY = anAxisData[1].NameColor.green();
2435 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2436 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2437 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2438 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2439 params.gtDrawValuesX = anAxisData[0].DrawValues;
2440 params.gtDrawValuesY = anAxisData[1].DrawValues;
2441 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2442 params.gtNbValuesX = anAxisData[0].NbValues;
2443 params.gtNbValuesY = anAxisData[1].NbValues;
2444 params.gtNbValuesZ = anAxisData[2].NbValues;
2445 params.gtOffsetX = anAxisData[0].Offset;
2446 params.gtOffsetY = anAxisData[1].Offset;
2447 params.gtOffsetZ = anAxisData[2].Offset;
2448 params.gtColorRX = anAxisData[0].Color.red();
2449 params.gtColorGX = anAxisData[0].Color.green();
2450 params.gtColorBX = anAxisData[0].Color.blue();
2451 params.gtColorRY = anAxisData[1].Color.red();
2452 params.gtColorGY = anAxisData[1].Color.green();
2453 params.gtColorBY = anAxisData[1].Color.blue();
2454 params.gtColorRZ = anAxisData[2].Color.red();
2455 params.gtColorGZ = anAxisData[2].Color.green();
2456 params.gtColorBZ = anAxisData[2].Color.blue();
2457 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2458 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2459 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2460 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2461 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2462 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2468 \brief Get visual parameters of this view window.
2469 \return visual parameters of view window
2471 QString OCCViewer_ViewWindow::getVisualParameters()
2473 viewAspect params = getViewParams();
2477 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2478 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2479 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
2480 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
2482 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2483 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2484 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2485 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2486 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2487 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2488 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2489 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2490 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2491 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2492 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2493 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2494 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2495 data << QString( "isVisible=%1" ).arg( params.isVisible );
2496 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2498 ClipPlanesList aPlanes = myModel->getClipPlanes();
2499 for ( int i=0; i < aPlanes.size(); i++ )
2501 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2502 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2503 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2504 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2505 switch ( aPlane.Mode )
2507 case OCCViewer_ClipPlane::Absolute :
2509 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2511 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2513 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2514 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2515 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2519 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2524 case OCCViewer_ClipPlane::Relative :
2526 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2527 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2528 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2533 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2534 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2535 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2536 data << ClippingPlane;
2539 // graduated trihedron
2540 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2541 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2542 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2543 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2544 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2545 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2546 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2547 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2548 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2549 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2550 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2551 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2552 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2553 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2554 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2555 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2556 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2557 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2558 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2559 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2560 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2561 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2562 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2563 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2564 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2565 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2566 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2567 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2568 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2569 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2570 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2571 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2572 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2573 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2574 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2575 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2576 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2577 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2578 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2579 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2581 // ray tracing parameters
2582 Graphic3d_RenderingParams rendParams = this->getViewPort()->getView()->RenderingParams();
2583 if ( rendParams.Method == Graphic3d_RM_RAYTRACING ) {
2584 QString RayTracing = "rayTracing=";
2585 RayTracing += QString( "rtDepth~%1;" ).arg( rendParams.RaytracingDepth );
2586 RayTracing += QString( "rtReflection~%1;" ).arg( rendParams.IsReflectionEnabled );
2587 RayTracing += QString( "rtAntialiasing~%1;" ).arg( rendParams.IsAntialiasingEnabled );
2588 RayTracing += QString( "rtShadow~%1;" ).arg( rendParams.IsShadowEnabled );
2589 RayTracing += QString( "rtTransShadow~%1;" ).arg( rendParams.IsTransparentShadowEnabled );
2593 // environment texture parameters
2594 Handle(Graphic3d_TextureEnv) aTexture = this->getViewPort()->getView()->TextureEnv();
2595 if ( !aTexture.IsNull() ) {
2596 QString EnvTexture = "envTexture=";
2597 if ( aTexture->Name() == Graphic3d_NOT_ENV_UNKNOWN ) {
2598 TCollection_AsciiString aFileName;
2599 aTexture->Path().SystemName( aFileName );
2600 EnvTexture += QString( "etFile~%1;" ).arg( aFileName.ToCString() );
2603 EnvTexture += QString( "etNumber~%1;" ).arg( aTexture->Name() );
2607 // light source parameters
2608 myModel->getViewer3d()->InitDefinedLights();
2609 while ( myModel->getViewer3d()->MoreDefinedLights() )
2611 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2612 if ( aLight->Type() != V3d_AMBIENT ) {
2613 QString LightSource = QString( "lightSource=" );
2614 LightSource += QString( "lightType~%1;" ).arg( aLight->Type() );
2616 if ( aLight->Type() == V3d_DIRECTIONAL )
2617 Handle(V3d_DirectionalLight)::DownCast( aLight )->Direction( aX, aY, aZ );
2618 else if ( aLight->Type() == V3d_POSITIONAL )
2619 Handle(V3d_PositionalLight)::DownCast( aLight )->Position( aX, aY, aZ );
2620 LightSource += QString( "lightX~%1;" ).arg( aX );
2621 LightSource += QString( "lightY~%1;" ).arg( aY );
2622 LightSource += QString( "lightZ~%1;" ).arg( aZ );
2623 LightSource += QString( "lightColorR~%1;" ).arg( aLight->Color().Red() );
2624 LightSource += QString( "lightColorG~%1;" ).arg( aLight->Color().Green() );
2625 LightSource += QString( "lightColorB~%1;" ).arg( aLight->Color().Blue() );
2626 LightSource += QString( "lightHeadlight~%1;" ).arg( aLight->Headlight() );
2627 data << LightSource;
2629 myModel->getViewer3d()->NextDefinedLights();
2632 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2633 data << QString( "background=%1" ).arg( bg );
2635 return data.join("*");
2639 \brief Restore visual parameters of the view window.
2640 \param parameters visual parameters of view window
2642 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2645 ClipPlanesList aClipPlanes;
2646 QStringList data = parameters.split( '*' );
2647 Qtx::BackgroundData bgData;
2648 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2650 foreach( QString param, data ) {
2651 QString paramName = param.section( '=', 0, 0 ).trimmed();
2652 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2653 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2654 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2655 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2656 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2657 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2658 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2659 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2660 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2661 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2662 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2663 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2664 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2665 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2666 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2667 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2668 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2669 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2670 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2671 else if ( paramName.contains( "ClippingPlane" ) )
2673 QStringList ClipPlaneData = paramValue.split( ';' );
2674 OCCViewer_ClipPlane aPlane;
2675 foreach( QString ClipPlaneParam, ClipPlaneData )
2677 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2678 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2679 if ( ClipPlane_paramName == "Mode" )
2681 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2683 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2684 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2685 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2686 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2689 switch ( aPlane.Mode )
2691 case OCCViewer_ClipPlane::Absolute :
2692 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2693 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2694 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2695 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2696 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2699 case OCCViewer_ClipPlane::Relative :
2700 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2701 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2702 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2707 aClipPlanes.push_back(aPlane);
2709 // graduated trihedron
2710 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2711 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2712 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2713 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2714 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2715 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2716 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2717 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2718 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2719 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2720 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2721 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2722 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2723 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2724 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2725 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2726 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2727 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2728 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2729 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2730 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2731 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2732 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2733 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2734 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2735 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2736 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2737 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2738 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2739 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2740 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2741 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2742 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2743 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2744 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2745 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2746 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2747 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2748 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2749 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2750 else if ( paramName == "rayTracing" )
2752 Graphic3d_RenderingParams& rendParams = this->getViewPort()->getView()->ChangeRenderingParams();
2753 rendParams.Method = Graphic3d_RM_RAYTRACING;
2754 QStringList rtData = paramValue.split( ';' );
2755 foreach( QString rtParam, rtData )
2757 QString rt_paramName = rtParam.section( '~', 0, 0 ).trimmed();
2758 QString rt_paramValue = rtParam.section( '~', 1, 1 ).trimmed();
2759 if ( rt_paramName == "rtDepth" ) rendParams.RaytracingDepth = rt_paramValue.toInt();
2760 else if ( rt_paramName == "rtReflection" ) rendParams.IsReflectionEnabled = rt_paramValue.toInt();
2761 else if ( rt_paramName == "rtAntialiasing" ) rendParams.IsAntialiasingEnabled = rt_paramValue.toInt();
2762 else if ( rt_paramName == "rtShadow" ) rendParams.IsShadowEnabled = rt_paramValue.toInt();
2763 else if ( rt_paramName == "rtTransShadow" ) rendParams.IsTransparentShadowEnabled = rt_paramValue.toInt();
2766 else if ( paramName == "envTexture" )
2768 Handle(Graphic3d_TextureEnv) aTexture;
2769 QStringList etData = paramValue.split( ';' );
2770 foreach( QString etParam, etData )
2772 QString et_paramName = etParam.section( '~', 0, 0 ).trimmed();
2773 QString et_paramValue = etParam.section( '~', 1, 1 ).trimmed();
2774 if ( et_paramName == "etNumber" )
2775 aTexture = new Graphic3d_TextureEnv( Graphic3d_NameOfTextureEnv( et_paramValue.toInt() ) );
2776 else if ( et_paramName == "etFile" )
2777 aTexture = new Graphic3d_TextureEnv( TCollection_AsciiString( et_paramValue.toStdString().c_str() ) );
2778 Handle(V3d_View) aView = this->getViewPort()->getView();
2779 aView->SetTextureEnv( aTexture );
2780 aView->SetSurfaceDetail( V3d_TEX_ENVIRONMENT );
2783 else if ( paramName == "lightSource" )
2785 myModel->getViewer3d()->InitDefinedLights();
2786 while ( myModel->getViewer3d()->MoreDefinedLights() )
2788 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2789 if( aLight->Type() != V3d_AMBIENT )
2790 myModel->getViewer3d()->DelLight( aLight );
2791 myModel->getViewer3d()->NextDefinedLights();
2795 V3d_TypeOfLight aType;
2797 QStringList lsData = paramValue.split( ';' );
2798 foreach( QString lsParam, lsData )
2800 QString ls_paramName = lsParam.section( '~', 0, 0 ).trimmed();
2801 QString ls_paramValue = lsParam.section( '~', 1, 1 ).trimmed();
2802 if ( ls_paramName == "lightType" ) aType = V3d_TypeOfLight( ls_paramValue.toInt() );
2803 else if ( ls_paramName == "lightX" ) aX = ls_paramValue.toDouble();
2804 else if ( ls_paramName == "lightY" ) aY = ls_paramValue.toDouble();
2805 else if ( ls_paramName == "lightZ" ) aZ = ls_paramValue.toDouble();
2806 else if ( ls_paramName == "lightColorR" ) cR = ls_paramValue.toDouble();
2807 else if ( ls_paramName == "lightColorG" ) cG = ls_paramValue.toDouble();
2808 else if ( ls_paramName == "lightColorB" ) cB = ls_paramValue.toDouble();
2809 else if ( ls_paramName == "lightHeadlight" ) isHeadlight = ls_paramValue.toInt();
2811 Quantity_Color aColor = Quantity_Color( cR, cG, cB, Quantity_TOC_RGB );
2812 if( aType == V3d_DIRECTIONAL ) {
2813 Handle(V3d_DirectionalLight) aLight = new V3d_DirectionalLight( myModel->getViewer3d() );
2814 aLight->SetDirection( aX, aY, aZ );
2815 aLight->SetColor( aColor );
2816 aLight->SetHeadlight( isHeadlight );
2817 myModel->getViewer3d()->SetLightOn( aLight );
2819 else if( aType == V3d_POSITIONAL ) {
2820 Handle(V3d_PositionalLight) aLight = new V3d_PositionalLight( myModel->getViewer3d(), aX, aY, aZ, aColor.Name() );
2821 aLight->SetHeadlight( isHeadlight );
2822 myModel->getViewer3d()->SetLightOn( aLight );
2825 else if ( paramName == "background" ) {
2826 QString bg = paramValue.replace( "$", "=" );
2827 bgData = Qtx::stringToBackground( bg );
2831 else // old format - "1.000e+00*0.000e+00..."
2834 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2835 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2836 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2837 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2838 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2839 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2840 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
2841 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2842 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2843 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
2844 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2845 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2846 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2847 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
2848 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
2849 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
2850 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
2851 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
2853 performRestoring( params );
2854 setBackground( bgData );
2855 myModel->setClipPlanes(aClipPlanes);
2859 \brief Handle show event.
2861 Emits Show() signal.
2863 \param theEvent show event
2865 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2867 emit Show( theEvent );
2871 \brief Handle hide event.
2873 Emits Hide() signal.
2875 \param theEvent hide event
2877 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
2879 emit Hide( theEvent );
2884 Save old cursor. [ protected ]
2886 void OCCViewer_ViewWindow::saveCursor()
2888 QCursor* aCursor = NULL;
2890 aCursor = myViewPort->getDefaultCursor();
2891 myCursor = ( aCursor ? *aCursor : cursor() );
2896 Creates default sketcher. [ virtual protected ]
2898 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
2901 return new OCCViewer_RectSketcher( this, type );
2902 if ( type == Polygon )
2903 return new OCCViewer_PolygonSketcher( this, type );
2907 void OCCViewer_ViewWindow::initSketchers()
2909 if ( mySketchers.isEmpty() )
2911 mySketchers.append( createSketcher( Rect ) );
2912 mySketchers.append( createSketcher( Polygon ) );
2916 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
2918 OCCViewer_ViewSketcher* sketcher = 0;
2919 QList<OCCViewer_ViewSketcher*>::Iterator it;
2920 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
2922 OCCViewer_ViewSketcher* sk = (*it);
2923 if ( sk->type() == typ )
2930 Handles requests for sketching in the active view. [ virtual public ]
2932 void OCCViewer_ViewWindow::activateSketching( int type )
2934 OCCViewer_ViewPort3d* vp = getViewPort();
2938 if ( !vp->isSketchingEnabled() )
2941 /* Finish current sketching */
2942 if ( type == NoSketching )
2946 onSketchingFinished();
2947 mypSketcher->deactivate();
2951 /* Activate new sketching */
2954 activateSketching( NoSketching ); /* concurrency not suported */
2955 mypSketcher = getSketcher( type );
2958 mypSketcher->activate();
2959 onSketchingStarted();
2965 Unhilights detected entities. [ virtual protected ]
2967 void OCCViewer_ViewWindow::onSketchingStarted()
2972 Selection by rectangle or polygon. [ virtual protected ]
2974 void OCCViewer_ViewWindow::onSketchingFinished()
2976 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
2977 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
2979 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
2980 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
2981 switch( mypSketcher->type() )
2985 QRect* aRect = (QRect*)mypSketcher->data();
2988 int aLeft = aRect->left();
2989 int aRight = aRect->right();
2990 int aTop = aRect->top();
2991 int aBottom = aRect->bottom();
2995 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2997 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
3003 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
3006 int size = aPolygon->size();
3007 TColgp_Array1OfPnt2d anArray( 1, size );
3009 QPolygon::Iterator it = aPolygon->begin();
3010 QPolygon::Iterator itEnd = aPolygon->end();
3011 for( int index = 1; it != itEnd; ++it, index++ )
3013 QPoint aPoint = *it;
3014 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
3018 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
3020 ic->Select( anArray, getViewPort()->getView(), Standard_False );
3028 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
3029 aViewMgr->getOCCViewer()->performSelectionChanged();
3033 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
3038 bool OCCViewer_ViewWindow::transformRequested() const
3040 return ( myOperation != NOTHING );
3043 bool OCCViewer_ViewWindow::transformInProcess() const
3045 return myEventStarted;
3048 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
3050 myEventStarted = bOn;
3054 Set enabled state of transformation (rotate, zoom, etc)
3056 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
3058 if ( id != NOTHING ) myStatus.insert( id, on );
3062 \return enabled state of transformation (rotate, zoom, etc)
3064 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
3066 return myStatus.contains( id ) ? myStatus[ id ] : true;
3069 void OCCViewer_ViewWindow::onMaximizedView()
3071 setMaximized(!isMaximized());
3074 void OCCViewer_ViewWindow::returnTo3dView()
3076 setReturnedTo3dView( true );
3079 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
3081 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
3082 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
3083 if ( !isVisible3dView )
3084 toolMgr()->show( ReturnTo3dViewId );
3086 toolMgr()->hide( ReturnTo3dViewId );
3087 if ( isVisible3dView ) emit returnedTo3d( );
3091 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
3093 QAction* anAction = toolMgr()->action( MaximizedId );
3094 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
3095 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
3097 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
3098 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
3099 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
3100 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
3101 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
3103 emit maximized( this, true );
3107 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
3108 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
3109 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
3110 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
3111 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
3113 emit maximized( this, false );
3118 bool OCCViewer_ViewWindow::isMaximized() const
3120 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
3123 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
3125 IsSketcherStyle = enable;
3128 bool OCCViewer_ViewWindow::isSketcherStyle() const
3130 return IsSketcherStyle;
3134 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
3139 int OCCViewer_ViewWindow::projectionType() const
3141 int mode = Orthographic;
3142 Handle(V3d_View) aView3d = myViewPort->getView();
3143 if ( !aView3d.IsNull() ) {
3144 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3145 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Perspective)
3147 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Orthographic)
3148 mode = Orthographic;
3149 #if OCC_VERSION_LARGE > 0x06090000
3150 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
3157 void OCCViewer_ViewWindow::setStereoType( int type )
3159 Handle(V3d_View) aView3d = myViewPort->getView();
3160 if ( !aView3d.IsNull() ) {
3161 #if OCC_VERSION_LARGE > 0x06090000
3162 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3163 aParams->StereoMode = (Graphic3d_StereoMode)type;
3168 int OCCViewer_ViewWindow::stereoType() const
3170 int type = QuadBuffer;
3171 Handle(V3d_View) aView3d = myViewPort->getView();
3172 if ( !aView3d.IsNull() ) {
3173 #if OCC_VERSION_LARGE > 0x06090000
3174 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3175 type = (OCCViewer_ViewWindow::StereoType)aParams->StereoMode;
3181 void OCCViewer_ViewWindow::setAnaglyphFilter( int type )
3183 Handle(V3d_View) aView3d = myViewPort->getView();
3184 if ( !aView3d.IsNull() ) {
3185 #if OCC_VERSION_LARGE > 0x06090000
3186 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3187 if (type == RedCyan)
3188 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
3189 if (type == YellowBlue)
3190 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
3191 if (type == GreenMagenta)
3192 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
3197 int OCCViewer_ViewWindow::anaglyphFilter() const
3200 Handle(V3d_View) aView3d = myViewPort->getView();
3201 if ( !aView3d.IsNull() ) {
3202 #if OCC_VERSION_LARGE > 0x06090000
3203 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3204 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized)
3206 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized)
3208 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple)
3209 type = GreenMagenta;
3215 void OCCViewer_ViewWindow::setStereographicFocus( int type, double value )
3217 Handle(V3d_View) aView3d = myViewPort->getView();
3218 if ( !aView3d.IsNull() ) {
3219 #if OCC_VERSION_LARGE > 0x06090000
3220 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3221 aCamera->SetZFocus( (Graphic3d_Camera::FocusType) type, value );
3226 int OCCViewer_ViewWindow::stereographicFocusType() const
3228 int type = Relative;
3229 Handle(V3d_View) aView3d = myViewPort->getView();
3230 if ( !aView3d.IsNull() ) {
3231 #if OCC_VERSION_LARGE > 0x06090000
3232 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3233 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->ZFocusType();
3239 double OCCViewer_ViewWindow::stereographicFocusValue() const
3242 Handle(V3d_View) aView3d = myViewPort->getView();
3243 if ( !aView3d.IsNull() ) {
3244 #if OCC_VERSION_LARGE > 0x06090000
3245 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3246 value = aCamera->ZFocus();
3252 void OCCViewer_ViewWindow::setInterocularDistance( int type, double value )
3254 Handle(V3d_View) aView3d = myViewPort->getView();
3255 if ( !aView3d.IsNull() ) {
3256 #if OCC_VERSION_LARGE > 0x06090000
3257 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3258 aCamera->SetIOD( (Graphic3d_Camera::IODType) type, value );
3263 int OCCViewer_ViewWindow::interocularDistanceType() const
3265 int type = Relative;
3266 Handle(V3d_View) aView3d = myViewPort->getView();
3267 if ( !aView3d.IsNull() ) {
3268 #if OCC_VERSION_LARGE > 0x06090000
3269 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3270 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->GetIODType();
3276 double OCCViewer_ViewWindow::interocularDistanceValue() const
3278 double value = 0.05;
3279 Handle(V3d_View) aView3d = myViewPort->getView();
3280 if ( !aView3d.IsNull() ) {
3281 #if OCC_VERSION_LARGE > 0x06090000
3282 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3283 value = aCamera->IOD();
3289 void OCCViewer_ViewWindow::setReverseStereo( bool reverse )
3291 Handle(V3d_View) aView3d = myViewPort->getView();
3292 if ( !aView3d.IsNull() ) {
3293 #if OCC_VERSION_LARGE > 0x06090000
3294 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3295 aParams->ToReverseStereo = reverse;
3300 bool OCCViewer_ViewWindow::isReverseStereo() const
3302 int reverse = false;
3303 Handle(V3d_View) aView3d = myViewPort->getView();
3304 if ( !aView3d.IsNull() ) {
3305 #if OCC_VERSION_LARGE > 0x06090000
3306 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3307 reverse = aParams->ToReverseStereo;
3313 void OCCViewer_ViewWindow::setVSync( bool enable )
3315 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3316 if ( !anIntCont.IsNull() ) {
3317 #if OCC_VERSION_LARGE > 0x06090000
3318 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3319 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3320 aCaps->swapInterval = enable;
3325 bool OCCViewer_ViewWindow::isVSync() const
3328 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3329 if ( !anIntCont.IsNull() ) {
3330 #if OCC_VERSION_LARGE > 0x06090000
3331 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3332 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3333 enable = aCaps->swapInterval;
3339 void OCCViewer_ViewWindow::setQuadBufferSupport( bool enable )
3341 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3342 if ( !anIntCont.IsNull() ) {
3343 #if OCC_VERSION_LARGE > 0x06090000
3344 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3345 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3346 aCaps->contextStereo = enable;
3351 bool OCCViewer_ViewWindow::isQuadBufferSupport() const
3354 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3355 if ( !anIntCont.IsNull() ) {
3356 #if OCC_VERSION_LARGE > 0x06090000
3357 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3358 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3359 enable = aCaps->contextStereo;
3366 bool OCCViewer_ViewWindow::isOpenGlStereoSupport() const
3368 GLboolean support[1];
3369 glGetBooleanv (GL_STEREO, support);
3376 QColor OCCViewer_ViewWindow::backgroundColor() const
3378 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
3382 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
3384 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
3387 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
3389 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
3392 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
3394 if ( myViewPort ) myViewPort->setBackground( theBackground );
3397 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
3399 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
3405 void OCCViewer_ViewWindow::clearViewAspects()
3407 myViewAspects.clear();
3411 \return const reference to list of view aspects
3413 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
3415 return myViewAspects;
3419 Appends new view aspect
3420 \param aParams - new view aspects
3422 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
3424 myViewAspects.append( aParams );
3428 Replaces old view aspects by new ones
3429 \param aViewList - list of new view aspects
3431 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
3433 myViewAspects = aViewList;
3437 Get camera properties for the OCC view window.
3438 \return shared pointer on camera properties.
3440 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
3442 SUIT_CameraProperties aProps;
3444 Handle(V3d_View) aSourceView = getViewPort()->getView();
3445 if ( aSourceView.IsNull() )
3448 if ( get2dMode() == No2dMode ) {
3449 aProps.setDimension( SUIT_CameraProperties::Dim3D );
3452 aProps.setDimension( SUIT_CameraProperties::Dim2D );
3453 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
3456 // read common properites of the view
3457 Standard_Real anUp[3];
3458 Standard_Real anAt[3];
3459 Standard_Real anEye[3];
3460 Standard_Real aProj[3];
3461 Standard_Real anAxialScale[3];
3463 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
3464 aSourceView->At( anAt[0], anAt[1], anAt[2] );
3465 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
3466 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3468 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3469 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
3471 #if OCC_VERSION_LARGE > 0x06070100
3472 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
3474 // store camera properties "as is": it is up to synchronized
3475 // view classes to provide necessary property conversion.
3476 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
3477 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
3479 if ( aSourceView->Camera()->IsOrthographic() )
3481 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
3482 aProps.setViewAngle( 0.0 );
3486 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
3487 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
3489 aProps.setMappingScale( aSourceView->Camera()->Scale() );
3491 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
3493 // generate view orientation matrix for transforming OCC projection reference point
3494 // into a camera (eye) position.
3495 gp_Dir aLeftDir = gp_Dir( anUp[0], anUp[1], anUp[2] ) ^ gp_Dir( aProj[0], aProj[1], aProj[2] );
3498 aTrsf.SetValue( 1, 1, aLeftDir.X() );
3499 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
3500 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
3502 aTrsf.SetValue( 1, 2, anUp[0] );
3503 aTrsf.SetValue( 2, 2, anUp[1] );
3504 aTrsf.SetValue( 3, 2, anUp[2] );
3506 aTrsf.SetValue( 1, 3, aProj[0] );
3507 aTrsf.SetValue( 2, 3, aProj[1] );
3508 aTrsf.SetValue( 3, 3, aProj[2] );
3510 aTrsf.SetValue( 1, 4, anAt[0] );
3511 aTrsf.SetValue( 2, 4, anAt[1] );
3512 aTrsf.SetValue( 3, 4, anAt[2] );
3514 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
3516 // transform to world-space coordinate system
3517 gp_XYZ aPosition( aProjRef.X(), aProjRef.Y(), aCameraDepth );
3518 aTrsf.Transforms( aPosition );
3520 // compute focal point
3521 double aFocalPoint[3];
3523 aFocalPoint[0] = aPosition.X() - aProj[0] * aCameraDepth;
3524 aFocalPoint[1] = aPosition.Y() - aProj[1] * aCameraDepth;
3525 aFocalPoint[2] = aPosition.Z() - aProj[2] * aCameraDepth;
3527 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3528 aProps.setPosition( aPosition.X(), aPosition.Y(), aPosition.Z() );
3530 Standard_Real aViewScale[2];
3531 aSourceView->Size( aViewScale[0], aViewScale[1] );
3532 aProps.setMappingScale( aViewScale[1] );
3540 This implementation synchronizes OCC view's camera propreties.
3542 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
3544 bool blocked = blockSignals( true );
3546 SUIT_CameraProperties aProps = theView->cameraProperties();
3547 if ( !cameraProperties().isCompatible( aProps ) ) {
3548 // other view, this one is being currently synchronized to, seems has become incompatible
3549 // we have to break synchronization
3554 Handle(V3d_View) aDestView = getViewPort()->getView();
3556 aDestView->SetImmediateUpdate( Standard_False );
3559 double aPosition[3];
3560 double aFocalPoint[3];
3561 double anAxialScale[3];
3563 // get common properties
3564 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3565 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
3566 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3567 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3569 #if OCC_VERSION_LARGE > 0x06070100
3570 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3571 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
3572 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3573 aDestView->Camera()->SetScale( aProps.getMappingScale() );
3575 gp_Dir aProjDir( aPosition[0] - aFocalPoint[0],
3576 aPosition[1] - aFocalPoint[1],
3577 aPosition[2] - aFocalPoint[2] );
3579 // get custom view translation
3580 Standard_Real aTranslation[3];
3581 aDestView->At( aTranslation[0], aTranslation[1], aTranslation[2] );
3583 gp_Dir aLeftDir = gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] )
3584 ^ gp_Dir( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
3587 aTrsf.SetValue( 1, 1, aLeftDir.X() );
3588 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
3589 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
3591 aTrsf.SetValue( 1, 2, anUpDir[0] );
3592 aTrsf.SetValue( 2, 2, anUpDir[1] );
3593 aTrsf.SetValue( 3, 2, anUpDir[2] );
3595 aTrsf.SetValue( 1, 3, aProjDir.X() );
3596 aTrsf.SetValue( 2, 3, aProjDir.Y() );
3597 aTrsf.SetValue( 3, 3, aProjDir.Z() );
3599 aTrsf.SetValue( 1, 4, aTranslation[0] );
3600 aTrsf.SetValue( 2, 4, aTranslation[1] );
3601 aTrsf.SetValue( 3, 4, aTranslation[2] );
3604 // transform to view-space coordinate system
3605 gp_XYZ aProjRef( aPosition[0], aPosition[1], aPosition[2] );
3606 aTrsf.Transforms( aProjRef );
3608 // set view camera properties using low-level approach. this is done
3609 // in order to avoid interference with static variables in v3d view used
3610 // when rotation is in process in another view.
3611 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
3612 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
3614 Graphic3d_Vector aMappingProj( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
3615 Graphic3d_Vector aMappingUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3617 aMappingProj.Normalize();
3618 aMappingUp.Normalize();
3620 anOrientation.SetViewReferencePlane( aMappingProj );
3621 anOrientation.SetViewReferenceUp( aMappingUp );
3623 aDestView->SetViewMapping( aMapping );
3624 aDestView->SetViewOrientation( anOrientation );
3627 aDestView->SetCenter( aProjRef.X(), aProjRef.Y() );
3629 // set mapping scale
3630 double aMapScaling = aProps.getMappingScale();
3631 Standard_Real aWidth, aHeight;
3632 aDestView->Size( aWidth, aHeight );
3633 aDestView->SetSize ( aWidth > aHeight ? aMapScaling * (aWidth / aHeight) : aMapScaling );
3636 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3638 aDestView->ZFitAll();
3639 aDestView->SetImmediateUpdate( Standard_True );
3640 aDestView->Redraw();
3642 blockSignals( blocked );
3646 \brief Indicates whether preselection is enabled
3647 \return true if preselection is enabled
3649 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
3651 return myPreselectionEnabled;
3655 \brief Enables/disables preselection
3656 \param theIsToEnable if true - preselection will be enabled
3658 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
3660 onSwitchPreselection( theIsToEnable );
3664 \brief Indicates whether selection is enabled
3665 \return true if selection is enabled
3667 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3669 return mySelectionEnabled;
3673 \brief Enables/disables selection
3674 \param theIsToEnable if true - selection will be enabled
3676 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3678 onSwitchSelection( theIsToEnable );
3683 \brief called if clipping operation is activated / deactivated.
3685 Enables/disables clipping plane displaying.
3687 \parma on action state
3689 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3691 if(!myModel) return;
3692 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3695 if (!aClippingDlg) {
3696 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3697 myModel->setClippingDlg(aClippingDlg);
3699 if (!aClippingDlg->isVisible())
3700 aClippingDlg->show();
3702 if ( aClippingDlg ) {
3703 aClippingDlg->close();
3704 myModel->setClippingDlg(0);
3708 SUIT_ViewManager* mgr = getViewManager();
3710 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3711 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3712 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3713 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3715 QAction* a = toolMgr()->action( ClippingId );
3717 if(theIsOn != a->isChecked()){
3718 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3719 a->setChecked(theIsOn);
3720 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3727 void OCCViewer_ViewWindow::onRayTracing()
3729 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_RayTracingDlg::getName() ) ) {
3730 QDialog* aDlg = new OCCViewer_RayTracingDlg( this );
3736 void OCCViewer_ViewWindow::onEnvTexture()
3738 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_EnvTextureDlg::getName() ) ) {
3739 QDialog* aDlg = new OCCViewer_EnvTextureDlg( this );
3745 void OCCViewer_ViewWindow::onLightSource()
3747 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_LightSourceDlg::getName() ) ) {
3748 QDialog* aDlg = new OCCViewer_LightSourceDlg( this, myModel );