1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : OCCViewer_ViewWindow.cxx
26 #include "OCCViewer_ViewWindow.h"
27 #include "OCCViewer_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>
89 #if OCC_VERSION_MAJOR < 7
90 #include <Visual3d_View.hxx>
93 #include <V3d_Plane.hxx>
94 #include <V3d_Light.hxx>
98 #include <gp_GTrsf.hxx>
99 #include <TColgp_Array1OfPnt2d.hxx>
101 #include <Image_PixMap.hxx>
103 #include <Standard_Version.hxx>
105 #include "utilities.h"
107 // // OpenCV includes
109 // #include <highgui.h>
111 static QEvent* l_mbPressEvent = 0;
114 //# include <QWindowsStyle>
119 // To avoid conflict between KeyPress from the X.h (define KeyPress 2)
120 // and QEvent::KeyPress (qevent.h)
125 // Enable ray tracing features
126 #define ENABLE_RAY_TRACING
128 const char* imageZoomCursor[] = {
133 "................................",
134 "................................",
135 ".#######........................",
136 "..aaaaaaa.......................",
137 "................................",
138 ".............#####..............",
139 "...........##.aaaa##............",
140 "..........#.aa.....a#...........",
141 ".........#.a.........#..........",
142 ".........#a..........#a.........",
143 "........#.a...........#.........",
144 "........#a............#a........",
145 "........#a............#a........",
146 "........#a............#a........",
147 "........#a............#a........",
148 ".........#...........#.a........",
149 ".........#a..........#a.........",
150 ".........##.........#.a.........",
151 "........#####.....##.a..........",
152 ".......###aaa#####.aa...........",
153 "......###aa...aaaaa.......#.....",
154 ".....###aa................#a....",
155 "....###aa.................#a....",
156 "...###aa...............#######..",
157 "....#aa.................aa#aaaa.",
158 ".....a....................#a....",
159 "..........................#a....",
160 "...........................a....",
161 "................................",
162 "................................",
163 "................................",
164 "................................"};
166 const char* imageRotateCursor[] = {
171 "................................",
172 "................................",
173 "................................",
174 "................................",
175 "........#.......................",
176 ".......#.a......................",
177 "......#######...................",
178 ".......#aaaaa#####..............",
179 "........#..##.a#aa##........##..",
180 ".........a#.aa..#..a#.....##.aa.",
181 ".........#.a.....#...#..##.aa...",
182 ".........#a.......#..###.aa.....",
183 "........#.a.......#a..#aa.......",
184 "........#a.........#..#a........",
185 "........#a.........#a.#a........",
186 "........#a.........#a.#a........",
187 "........#a.........#a.#a........",
188 ".........#.........#a#.a........",
189 "........##a........#a#a.........",
190 "......##.a#.......#.#.a.........",
191 "....##.aa..##.....##.a..........",
192 "..##.aa.....a#####.aa...........",
193 "...aa.........aaa#a.............",
194 "................#.a.............",
195 "...............#.a..............",
196 "..............#.a...............",
197 "...............a................",
198 "................................",
199 "................................",
200 "................................",
201 "................................",
202 "................................"};
204 const char* imageCrossCursor[] = {
209 "................................",
210 "................................",
211 "................................",
212 "................................",
213 "................................",
214 "................................",
215 "................................",
216 "...............#................",
217 "...............#a...............",
218 "...............#a...............",
219 "...............#a...............",
220 "...............#a...............",
221 "...............#a...............",
222 "...............#a...............",
223 "...............#a...............",
224 ".......#################........",
225 "........aaaaaaa#aaaaaaaaa.......",
226 "...............#a...............",
227 "...............#a...............",
228 "...............#a...............",
229 "...............#a...............",
230 "...............#a...............",
231 "...............#a...............",
232 "...............#a...............",
233 "................a...............",
234 "................................",
235 "................................",
236 "................................",
237 "................................",
238 "................................",
239 "................................",
240 "................................"};
245 \param theDesktop main window of application
246 \param theModel OCC 3D viewer
248 OCCViewer_ViewWindow::OCCViewer_ViewWindow( SUIT_Desktop* theDesktop,
249 OCCViewer_Viewer* theModel )
250 : SUIT_ViewWindow( theDesktop )
254 myEnableDrawMode = false;
255 myDrawRectEnabled = true;
257 updateEnabledDrawMode();
259 mySetRotationPointDlg = 0;
262 IsSketcherStyle = false;
269 myInteractionStyle = SUIT_ViewModel::STANDARD;
270 myPreselectionEnabled = true;
271 mySelectionEnabled = true;
273 myCursorIsHand = false;
281 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
284 qDeleteAll( mySketchers );
288 \brief Internal initialization.
290 void OCCViewer_ViewWindow::initLayout()
292 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
293 myViewPort->installEventFilter(this);
294 setCentralWidget(myViewPort);
295 myOperation = NOTHING;
297 myCurrPointType = GRAVITY;
298 myPrevPointType = GRAVITY;
299 mySelectedPoint = gp_Pnt(0.,0.,0.);
300 myRotationPointSelection = false;
302 setTransformRequested ( NOTHING );
303 setTransformInProcess ( false );
320 // Graduated axes dialog
321 QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
322 myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
323 myCubeAxesDlg->initialize();
325 connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
328 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
330 return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
334 \brief Detect viewer operation according the the mouse button pressed
335 and key modifiers used.
336 \param theEvent mouse event
337 \return type of the operation
339 OCCViewer_ViewWindow::OperationType
340 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
342 OperationType aOp = NOTHING;
343 SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
344 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
345 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
347 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
348 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
350 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
351 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
352 (my2dMode == No2dMode))
359 \brief Customize event handling
360 \param watched event receiver object
362 \return \c true if the event processing should be stopped
364 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
366 if ( watched == myViewPort ) {
367 int aType = e->type();
369 case QEvent::MouseButtonPress:
370 vpMousePressEvent((QMouseEvent*) e);
373 case QEvent::MouseButtonRelease:
374 vpMouseReleaseEvent((QMouseEvent*) e);
377 case QEvent::MouseMove:
378 vpMouseMoveEvent((QMouseEvent*) e);
381 case QEvent::MouseButtonDblClick:
382 emit mouseDoubleClicked(this, (QMouseEvent*)e);
387 QWheelEvent* aEvent = (QWheelEvent*) e;
389 if ( aEvent->modifiers().testFlag(Qt::ControlModifier) ) {
390 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
391 if ( isPreselectionEnabled() && ic->HasOpenedContext() ) {
392 if ( aEvent->delta() > 0 ) {
393 ic->HilightNextDetected( myViewPort->getView() );
395 ic->HilightPreviousDetected( myViewPort->getView() );
400 emit vpTransformationStarted ( ZOOMVIEW );
401 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
402 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
405 int x1 = (int)( aEvent->x() + width()*delta/100 );
406 int y1 = (int)( aEvent->y() + height()*delta/100 );
407 myViewPort->zoom( x, y, x1, y1 );
408 myViewPort->getView()->ZFitAll();
409 emit vpTransformationFinished ( ZOOMVIEW );
414 case QEvent::ContextMenu:
416 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
417 if ( aEvent->reason() != QContextMenuEvent::Mouse )
418 emit contextMenuRequested( aEvent );
422 case QEvent::KeyPress:
423 emit keyPressed(this, (QKeyEvent*) e);
430 return SUIT_ViewWindow::eventFilter(watched, e);
434 \brief Enable / disable draw rect (rubber band) mode
436 bool OCCViewer_ViewWindow::enableDrawMode( bool on )
438 bool prev = myDrawRectEnabled;
439 myDrawRectEnabled = on;
440 updateEnabledDrawMode();
445 \brief Update state of enable draw mode state.
447 void OCCViewer_ViewWindow::updateEnabledDrawMode()
449 myEnableDrawMode = myDrawRectEnabled;
451 myEnableDrawMode = myEnableDrawMode && myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
455 \brief Handle mouse press event
456 \param theEvent mouse event
458 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
460 myStartX = theEvent->x();
461 myStartY = theEvent->y();
462 int anInteractionStyle = interactionStyle();
464 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
465 // which are assigned for pan and rotate - these operations are activated immediately after pressing
466 // of the first button, so it is necessary to switch to zoom when the second button is pressed
467 bool aSwitchToZoom = false;
468 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
469 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
470 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
473 switch ( myOperation ) {
475 if ( theEvent->button() == Qt::LeftButton )
476 emit vpTransformationStarted ( WINDOWFIT );
480 if ( theEvent->button() == Qt::LeftButton )
481 emit vpTransformationStarted ( PANGLOBAL );
485 if ( theEvent->button() == Qt::LeftButton ) {
486 myViewPort->startZoomAtPoint( myStartX, myStartY );
487 emit vpTransformationStarted ( ZOOMVIEW );
492 if ( aSwitchToZoom ) {
493 myViewPort->startZoomAtPoint( myStartX, myStartY );
496 else if ( theEvent->button() == Qt::LeftButton )
497 emit vpTransformationStarted ( PANVIEW );
501 if ( aSwitchToZoom ) {
502 myViewPort->startZoomAtPoint( myStartX, myStartY );
505 else if ( theEvent->button() == Qt::LeftButton ) {
506 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
507 emit vpTransformationStarted ( ROTATE );
512 /* Try to activate a transformation */
513 OperationType aState;
514 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
515 aState = getButtonState(theEvent, anInteractionStyle);
517 aState = OCCViewer_ViewWindow::NOTHING;
522 myViewPort->startZoomAtPoint( myStartX, myStartY );
530 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
533 if ( myRotationPointSelection )
535 if ( theEvent->button() == Qt::LeftButton )
537 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
539 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
541 TopoDS_Shape aShape = ic->SelectedShape();
542 GProp_GProps aSystem;
544 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
546 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
548 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE )
550 BRepGProp::LinearProperties( aShape, aSystem );
551 aPnt = aSystem.CentreOfMass();
553 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE )
555 BRepGProp::SurfaceProperties( aShape, aSystem );
556 aPnt = aSystem.CentreOfMass();
558 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID )
560 BRepGProp::VolumeProperties( aShape, aSystem );
561 aPnt = aSystem.CentreOfMass();
565 myCurrPointType = myPrevPointType;
569 if ( mySetRotationPointDlg )
571 myRotationPointSelection = false;
572 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
575 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
576 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
577 ic->CloseAllContexts();
578 myOperation = NOTHING;
579 myViewPort->setCursor( myCursor );
580 myCursorIsHand = false;
581 myRotationPointSelection = false;
585 emit mousePressed(this, theEvent);
588 /* notify that we start a transformation */
589 if ( transformRequested() )
590 emit vpTransformationStarted ( myOperation );
592 if ( transformRequested() )
593 setTransformInProcess( true );
595 /* we may need it for sketching... */
596 if ( l_mbPressEvent )
597 delete l_mbPressEvent;
598 l_mbPressEvent = new QMouseEvent( *theEvent );
603 \brief Start zooming operation.
605 Sets the corresponding cursor for the widget.
607 void OCCViewer_ViewWindow::activateZoom()
609 if ( !transformRequested() && !myCursorIsHand )
610 saveCursor(); /* save old cursor */
612 if ( myOperation != ZOOMVIEW ) {
613 QPixmap zoomPixmap (imageZoomCursor);
614 QCursor zoomCursor (zoomPixmap);
615 if( setTransformRequested ( ZOOMVIEW ) )
616 myViewPort->setCursor( zoomCursor );
622 \brief Start panning operation.
624 Sets the corresponding cursor for the widget.
626 void OCCViewer_ViewWindow::activatePanning()
628 if ( !transformRequested() && !myCursorIsHand )
629 saveCursor(); // save old cursor
631 if ( myOperation != PANVIEW ) {
632 QCursor panCursor (Qt::SizeAllCursor);
633 if( setTransformRequested ( PANVIEW ) )
634 myViewPort->setCursor( panCursor );
639 \brief Start rotation operation
641 Sets the corresponding cursor for the widget.
643 void OCCViewer_ViewWindow::activateRotation()
645 if ( !transformRequested() && !myCursorIsHand )
646 saveCursor(); // save old cursor
648 if ( myOperation != ROTATE ) {
649 QPixmap rotatePixmap (imageRotateCursor);
650 QCursor rotCursor (rotatePixmap);
651 if( setTransformRequested ( ROTATE ) )
652 myViewPort->setCursor( rotCursor );
657 \brief Compute the gravity center.
658 \param theX used to return X coordinate of the gravity center
659 \param theY used to return Y coordinate of the gravity center
660 \param theZ used to return Z coordinate of the gravity center
661 \return \c true if the gravity center is computed
663 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
665 Handle(V3d_View) aView3d = myViewPort->getView();
667 // Project boundaries points and add to avergae gravity
668 // the ones which lie within the screen limits
669 Standard_Real aScreenLimits[4] = { 0.0, 0.0, 0.0, 0.0 };
671 #if OCC_VERSION_LARGE > 0x06070100
672 // NDC space screen limits
673 aScreenLimits[0] = -1.0;
674 aScreenLimits[1] = 1.0;
675 aScreenLimits[2] = -1.0;
676 aScreenLimits[3] = 1.0;
678 aView3d->View()->ViewMapping().WindowLimit( aScreenLimits[0],
684 Standard_Integer aPointsNb = 0;
686 Standard_Real aXmin = 0.0;
687 Standard_Real aYmin = 0.0;
688 Standard_Real aZmin = 0.0;
689 Standard_Real aXmax = 0.0;
690 Standard_Real aYmax = 0.0;
691 Standard_Real aZmax = 0.0;
693 Graphic3d_MapOfStructure aSetOfStructures;
694 aView3d->View()->DisplayedStructures( aSetOfStructures );
695 Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures );
697 for( ; aStructureIt.More(); aStructureIt.Next() ) {
698 const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key();
699 if ( aStructure->IsEmpty() || !aStructure->IsVisible() || aStructure->CStructure()->IsForHighlight )
702 #if OCC_VERSION_LARGE > 0x06070100
703 Bnd_Box aBox = aStructure->MinMaxValues();
704 aXmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().X();
705 aYmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Y();
706 aZmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Z();
707 aXmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().X();
708 aYmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Y();
709 aZmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Z();
711 aStructure->MinMaxValues( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
714 // Infinite structures are skipped
715 Standard_Real aLIM = ShortRealLast() - 1.0;
716 if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
717 || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
721 gp_Pnt aPoints[8] = {
722 gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
723 gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
724 gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
725 gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
728 for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
729 const gp_Pnt& aBBPoint = aPoints[aPointIt];
731 #if OCC_VERSION_LARGE > 0x06070100
732 gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
733 const Standard_Real& U = aProjected.X();
734 const Standard_Real& V = aProjected.Y();
736 Standard_Real U = 0.0;
737 Standard_Real V = 0.0;
738 Standard_Real W = 0.0;
739 aView3d->View()->Projects( aBBPoint.X(), aBBPoint.Y(), aBBPoint.Z(), U, V, W );
742 if (U >= aScreenLimits[0]
743 && U <= aScreenLimits[1]
744 && V >= aScreenLimits[2]
745 && V <= aScreenLimits[3])
748 theX += aBBPoint.X();
749 theY += aBBPoint.Y();
750 theZ += aBBPoint.Z();
765 \brief Set the gravity center as a rotation point.
767 void OCCViewer_ViewWindow::activateSetRotationGravity()
769 if ( myRotationPointSelection )
771 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
772 ic->CloseAllContexts();
773 myOperation = NOTHING;
774 myViewPort->setCursor( myCursor );
775 myCursorIsHand = false;
776 myRotationPointSelection = false;
779 myPrevPointType = myCurrPointType;
780 myCurrPointType = GRAVITY;
782 Standard_Real Xcenter, Ycenter, Zcenter;
783 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
784 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
788 \brief Update gravity center in the "Set Rotation Point" dialog box.
789 \sa OCCViewer_SetRotationPointDlg class
791 void OCCViewer_ViewWindow::updateGravityCoords()
793 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == GRAVITY )
795 Standard_Real Xcenter, Ycenter, Zcenter;
796 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
797 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
802 \brief Set the point selected by the user as a rotation point.
803 \param theX X coordinate of the rotation point
804 \param theY Y coordinate of the rotation point
805 \param theZ Z coordinate of the rotation point
807 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
809 if ( myRotationPointSelection )
811 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
812 ic->CloseAllContexts();
813 myOperation = NOTHING;
814 myViewPort->setCursor( myCursor );
815 myCursorIsHand = false;
816 myRotationPointSelection = false;
819 myPrevPointType = myCurrPointType;
820 myCurrPointType = SELECTED;
821 mySelectedPoint.SetCoord(theX,theY,theZ);
825 \brief Start the shape selection process.
827 void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
829 myPrevPointType = myCurrPointType;
830 myCurrPointType = SELECTED;
832 // activate selection ------>
833 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
835 ic->OpenLocalContext();
837 AIS_ListOfInteractive aList;
838 ic->DisplayedObjects( aList );
839 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
841 Handle(AIS_InteractiveObject) anObj = it.Value();
842 if ( !anObj.IsNull() && anObj->HasPresentation() &&
843 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
846 ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
849 // activate selection <------
851 if ( !myCursorIsHand )
853 QCursor handCursor (Qt::PointingHandCursor);
854 myCursorIsHand = true;
856 myViewPort->setCursor( handCursor );
858 myRotationPointSelection = true;
862 \brief Start global panning operation
864 Sets the corresponding cursor for the widget.
866 void OCCViewer_ViewWindow::activateGlobalPanning()
868 Handle(V3d_View) aView3d = myViewPort->getView();
869 if ( !aView3d.IsNull() ) {
870 QPixmap globalPanPixmap (imageCrossCursor);
871 QCursor glPanCursor (globalPanPixmap);
872 myCurScale = aView3d->Scale();
873 aView3d->FitAll(0.01, false);
874 saveCursor(); // save old cursor
875 myViewPort->fitAll(); // fits view before selecting a new scene center
876 if( setTransformRequested( PANGLOBAL ) )
877 myViewPort->setCursor( glPanCursor );
882 \brief Starts fit operation.
884 Sets the corresponding cursor for the widget.
886 void OCCViewer_ViewWindow::activateWindowFit()
888 if ( !transformRequested() && !myCursorIsHand )
889 saveCursor(); /* save old cursor */
891 if ( myOperation != WINDOWFIT ) {
892 QCursor handCursor (Qt::PointingHandCursor);
893 if( setTransformRequested ( WINDOWFIT ) )
895 myViewPort->setCursor ( handCursor );
896 myCursorIsHand = true;
902 \brief Start delayed viewer operation.
904 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
906 bool ok = transformEnabled( op );
907 myOperation = ok ? op : NOTHING;
908 myViewPort->setMouseTracking( myOperation == NOTHING );
913 \brief Handle mouse move event.
914 \param theEvent mouse event
916 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
918 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
920 switch ( getButtonState( theEvent, interactionStyle() ) ) {
922 myViewPort->startZoomAtPoint( myStartX, myStartY );
930 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
937 myCurrX = theEvent->x();
938 myCurrY = theEvent->y();
939 switch (myOperation) {
941 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
945 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
951 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
965 if ( myRotationPointSelection || isSketcherStyle() )
967 emit mouseMoving( this, theEvent );
971 int aState = theEvent->modifiers();
972 int aButton = theEvent->buttons();
973 int anInteractionStyle = interactionStyle();
974 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
975 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
976 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
977 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
978 myDrawRect = myEnableDrawMode;
981 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
982 QCursor handCursor (Qt::PointingHandCursor);
983 myCursorIsHand = true;
985 myViewPort->setCursor( handCursor );
988 emit mouseMoving( this, theEvent );
990 else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
991 aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
992 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
993 aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
994 OCCViewer_ViewSketcher* sketcher = 0;
995 QList<OCCViewer_ViewSketcher*>::Iterator it;
996 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
998 OCCViewer_ViewSketcher* sk = (*it);
999 if( sk->isDefault() && sk->sketchButton() == aButton )
1002 if ( sketcher && myCurSketch == -1 )
1004 activateSketching( sketcher->type() );
1007 myCurSketch = mypSketcher->sketchButton();
1009 if ( l_mbPressEvent )
1011 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
1012 delete l_mbPressEvent;
1015 QApplication::sendEvent( getViewPort(), theEvent );
1020 emit mouseMoving( this, theEvent );
1026 \brief Handle mouse release event.
1027 \param theEvent mouse event
1029 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
1031 switch ( myOperation ) {
1034 int prevState = myCurSketch;
1035 if(theEvent->button() == Qt::RightButton)
1037 QList<OCCViewer_ViewSketcher*>::Iterator it;
1038 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
1040 OCCViewer_ViewSketcher* sk = (*it);
1041 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
1046 emit mouseReleased(this, theEvent);
1047 if(theEvent->button() == Qt::RightButton && prevState == -1)
1049 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1050 theEvent->pos(), theEvent->globalPos() );
1051 emit contextMenuRequested( &aEvent );
1056 myViewPort->endRotation();
1062 myViewPort->getView()->ZFitAll();
1067 if ( theEvent->button() == Qt::LeftButton ) {
1068 myViewPort->setCenter( theEvent->x(), theEvent->y() );
1069 myViewPort->getView()->SetScale(myCurScale);
1075 if ( theEvent->button() == Qt::LeftButton ) {
1076 myCurrX = theEvent->x();
1077 myCurrY = theEvent->y();
1079 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1080 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1087 // NOTE: viewer 3D detects a rectangle of selection using this event
1088 // so we must emit it BEFORE resetting the selection rectangle
1090 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1094 myViewPort->update();
1097 if ( l_mbPressEvent )
1099 delete l_mbPressEvent;
1105 \brief Reset the viewport to its initial state
1106 ( no transformations in process etc. )
1108 void OCCViewer_ViewWindow::resetState()
1112 if ( myRotationPointSelection )
1114 QCursor handCursor (Qt::PointingHandCursor);
1115 myViewPort->setCursor( handCursor );
1119 if ( transformRequested() || myCursorIsHand )
1120 myViewPort->setCursor( myCursor );
1121 myCursorIsHand = false;
1124 if ( transformRequested() )
1125 emit vpTransformationFinished (myOperation);
1127 setTransformInProcess( false );
1128 setTransformRequested( NOTHING );
1133 \brief Draw rubber band rectangle.
1135 void OCCViewer_ViewWindow::drawRect()
1137 if ( !myRectBand ) {
1138 myRectBand = new QtxRectRubberBand( myViewPort );
1140 //palette.setColor(myRectBand->foregroundRole(), Qt::white);
1141 //myRectBand->setPalette(palette);
1143 //myRectBand->hide();
1145 myRectBand->setUpdatesEnabled ( false );
1146 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1147 myRectBand->initGeometry( aRect );
1149 if ( !myRectBand->isVisible() )
1152 myRectBand->setUpdatesEnabled ( true );
1153 //myRectBand->repaint();
1155 //myRectBand->setVisible( aRect.isValid() );
1156 //if ( myRectBand->isVisible() )
1157 // myRectBand->repaint();
1159 // myRectBand->show();
1160 //myRectBand->repaint();
1164 \brief Clear rubber band rectangle on the end on the dragging operation.
1166 void OCCViewer_ViewWindow::endDrawRect()
1168 //delete myRectBand;
1172 myRectBand->clearGeometry();
1178 \brief Create actions.
1180 void OCCViewer_ViewWindow::createActions()
1182 if( !toolMgr()->isEmpty() )
1185 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1192 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1193 tr( "MNU_DUMP_VIEW" ), 0, this);
1194 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1195 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1196 toolMgr()->registerAction( aAction, DumpId );
1199 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1200 tr( "MNU_FITALL" ), 0, this);
1201 aAction->setStatusTip(tr("DSC_FITALL"));
1202 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1203 toolMgr()->registerAction( aAction, FitAllId );
1206 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1207 tr( "MNU_FITRECT" ), 0, this);
1208 aAction->setStatusTip(tr("DSC_FITRECT"));
1209 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1210 toolMgr()->registerAction( aAction, FitRectId );
1213 aAction = new QtxAction(tr("MNU_FITSELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITSELECTION" ) ),
1214 tr( "MNU_FITSELECTION" ), 0, this);
1215 aAction->setStatusTip(tr("DSC_FITSELECTION"));
1216 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
1217 toolMgr()->registerAction( aAction, FitSelectionId );
1220 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1221 tr( "MNU_ZOOM_VIEW" ), 0, this);
1222 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1223 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1224 toolMgr()->registerAction( aAction, ZoomId );
1227 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1228 tr( "MNU_PAN_VIEW" ), 0, this);
1229 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1230 connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
1231 toolMgr()->registerAction( aAction, PanId );
1234 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1235 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1236 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1237 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1238 toolMgr()->registerAction( aAction, GlobalPanId );
1241 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1242 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1243 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1244 mySetRotationPointAction->setCheckable( true );
1245 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1246 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1249 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1250 tr( "MNU_ROTATE_VIEW" ), 0, this);
1251 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1252 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1253 toolMgr()->registerAction( aAction, RotationId );
1256 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1257 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1258 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1259 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1260 this->addAction(aAction);
1261 toolMgr()->registerAction( aAction, FrontId );
1263 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1264 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1265 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1266 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1267 this->addAction(aAction);
1268 toolMgr()->registerAction( aAction, BackId );
1270 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1271 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1272 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1273 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1274 this->addAction(aAction);
1275 toolMgr()->registerAction( aAction, TopId );
1277 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1278 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1279 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1280 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1281 this->addAction(aAction);
1282 toolMgr()->registerAction( aAction, BottomId );
1284 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1285 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1286 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1287 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1288 this->addAction(aAction);
1289 toolMgr()->registerAction( aAction, LeftId );
1291 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1292 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1293 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1294 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1295 this->addAction(aAction);
1296 toolMgr()->registerAction( aAction, RightId );
1298 // rotate anticlockwise
1299 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1300 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1301 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1302 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1303 this->addAction(aAction);
1304 toolMgr()->registerAction( aAction, AntiClockWiseId );
1307 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1308 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1309 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1310 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1311 this->addAction(aAction);
1312 toolMgr()->registerAction( aAction, ClockWiseId );
1314 // Projection mode group
1316 // - orthographic projection
1317 aAction = new QtxAction(tr("MNU_ORTHOGRAPHIC_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ORTHOGRAPHIC" ) ),
1318 tr( "MNU_ORTHOGRAPHIC_MODE" ), 0, this);
1319 aAction->setStatusTip(tr("DSC_ORTHOGRAPHIC_MODE"));
1320 aAction->setCheckable(true);
1321 toolMgr()->registerAction( aAction, OrthographicId );
1323 // - perspective projection
1324 aAction = new QtxAction(tr("MNU_PERSPECTIVE_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PERSPECTIVE" ) ),
1325 tr( "MNU_PERSPECTIVE_MODE" ), 0, this);
1326 aAction->setStatusTip(tr("DSC_PERSPECTIVE_MODE"));
1327 aAction->setCheckable(true);
1328 toolMgr()->registerAction( aAction, PerspectiveId );
1329 #if OCC_VERSION_LARGE > 0x06090000
1330 // - stereo projection
1331 aAction = new QtxAction(tr("MNU_STEREO_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STEREO" ) ),
1332 tr( "MNU_STEREO_MODE" ), 0, this);
1333 aAction->setStatusTip(tr("DSC_STEREO_MODE"));
1334 aAction->setCheckable(true);
1335 toolMgr()->registerAction( aAction, StereoId );
1336 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onStereoType(bool)));
1338 // - add exclusive action group
1339 QActionGroup* aProjectionGroup = new QActionGroup( this );
1340 aProjectionGroup->addAction( toolMgr()->action( OrthographicId ) );
1341 aProjectionGroup->addAction( toolMgr()->action( PerspectiveId ) );
1342 connect(aProjectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProjectionType(QAction*)));
1345 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1346 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1347 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1348 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1349 this->addAction(aAction);
1350 toolMgr()->registerAction( aAction, ResetId );
1353 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1354 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1355 tr("MNU_CLONE_VIEW"), 0, this);
1356 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1357 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1358 toolMgr()->registerAction( aAction, CloneId );
1360 aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
1361 tr("MNU_CLIPPING"), 0, this);
1362 aAction->setStatusTip (tr("DSC_CLIPPING"));
1363 aAction->setCheckable (true);
1364 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1365 toolMgr()->registerAction (aAction, ClippingId);
1367 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1368 tr( "MNU_SHOOT_VIEW" ), 0, this);
1369 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1370 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1371 toolMgr()->registerAction( aAction, MemId );
1373 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1374 tr( "MNU_PRESETS_VIEW" ), 0, this);
1375 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1376 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1377 toolMgr()->registerAction( aAction, RestoreId );
1379 if (myModel->trihedronActivated()) {
1380 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1381 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1382 aAction->setCheckable( true );
1383 aAction->setChecked( true );
1384 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1385 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1386 toolMgr()->registerAction( aAction, TrihedronShowId );
1390 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1391 tr( "MNU_SCALING" ), 0, this);
1392 aAction->setStatusTip(tr("DSC_SCALING"));
1393 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1394 toolMgr()->registerAction( aAction, AxialScaleId );
1396 // Enable/disable preselection
1397 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1398 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1399 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1400 aAction->setCheckable(true);
1401 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1402 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1404 // Enable/disable selection
1405 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1406 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1407 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1408 aAction->setCheckable(true);
1409 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1410 toolMgr()->registerAction( aAction, SwitchSelectionId );
1413 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1414 tr( "MNU_GRADUATED_AXES" ), 0, this);
1415 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1416 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1417 toolMgr()->registerAction( aAction, GraduatedAxesId );
1419 // Active only ambient light or not
1420 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1421 tr( "MNU_AMBIENT" ), 0, this);
1422 aAction->setStatusTip(tr("DSC_AMBIENT"));
1423 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1424 toolMgr()->registerAction( aAction, AmbientId );
1426 // Switch between interaction styles
1427 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1428 tr( "MNU_STYLE_SWITCH" ), 0, this);
1429 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1430 aAction->setCheckable(true);
1431 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1432 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1434 // Switch between zooming styles
1435 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1436 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1437 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1438 aAction->setCheckable(true);
1439 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1440 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1443 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1444 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1445 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1446 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1447 toolMgr()->registerAction( aAction, MaximizedId );
1449 // Return to 3d view
1450 if (my2dMode!=No2dMode){
1451 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1452 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1453 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1454 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1455 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1459 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1460 #ifdef ENABLE_RAY_TRACING
1462 aAction = new QtxAction( tr("MNU_RAY_TRACING"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_RAY_TRACING") ),
1463 tr("MNU_RAY_TRACING"), 0, this );
1464 aAction->setStatusTip( tr("DSC_RAY_TRACING") );
1465 connect( aAction, SIGNAL( triggered() ), this, SLOT( onRayTracing() ) );
1466 toolMgr()->registerAction( aAction, RayTracingId );
1468 // Environment texture
1469 aAction = new QtxAction( tr("MNU_ENV_TEXTURE"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_ENV_TEXTURE") ),
1470 tr("MNU_ENV_TEXTURE"), 0, this );
1471 aAction->setStatusTip( tr("DSC_ENV_TEXTURE") );
1472 connect( aAction, SIGNAL( triggered() ), this, SLOT( onEnvTexture() ) );
1473 toolMgr()->registerAction( aAction, EnvTextureId );
1476 aAction = new QtxAction( tr("MNU_LIGHT_SOURCE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_LIGHT_SOURCE" ) ),
1477 tr( "MNU_LIGHT_SOURCE" ), 0, this );
1478 aAction->setStatusTip( tr("DSC_LIGHT_SOURCE") );
1479 connect( aAction, SIGNAL( triggered() ), this, SLOT( onLightSource() ) );
1480 toolMgr()->registerAction( aAction, LightSourceId );
1485 \brief Create toolbar.
1487 void OCCViewer_ViewWindow::createToolBar()
1489 static const char* titles[] = {
1490 "LBL_3DTOOLBAR_LABEL",
1491 "LBL_XYTOOLBAR_LABEL",
1492 "LBL_XZTOOLBAR_LABEL",
1493 "LBL_YZTOOLBAR_LABEL",
1495 static const char* names[] = {
1496 "OCCViewer3DViewOperations",
1497 "OCCViewerXYViewOperations",
1498 "OCCViewerXZViewOperations",
1499 "OCCViewerYZViewOperations",
1501 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1502 QString( names[my2dMode] ), // name (language-independant)
1503 false ); // disable floatable toolbar
1504 if ( my2dMode != No2dMode ){
1505 toolMgr()->append( ReturnTo3dViewId, tid );
1506 toolMgr()->append( toolMgr()->separator(), tid );
1508 toolMgr()->append( DumpId, tid );
1509 toolMgr()->append( SwitchInteractionStyleId, tid );
1510 toolMgr()->append( SwitchZoomingStyleId, tid );
1511 toolMgr()->append( SwitchPreselectionId, tid );
1512 toolMgr()->append( SwitchSelectionId, tid );
1513 if( myModel->trihedronActivated() )
1514 toolMgr()->append( TrihedronShowId, tid );
1516 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1517 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1518 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1519 #if OCC_VERSION_LARGE > 0x06090000
1520 aScaleAction->insertAction( toolMgr()->action( FitSelectionId ) );
1522 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1523 toolMgr()->append( aScaleAction, tid );
1525 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1526 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1527 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1528 toolMgr()->append( aPanningAction, tid );
1530 if (my2dMode == No2dMode) {
1531 toolMgr()->append( ChangeRotationPointId, tid );
1532 toolMgr()->append( RotationId, tid );
1534 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1535 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1536 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1537 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1538 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1539 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1540 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1541 toolMgr()->append( aViewsAction, tid );
1543 toolMgr()->append( AntiClockWiseId, tid );
1544 toolMgr()->append( ClockWiseId, tid );
1546 toolMgr()->append( OrthographicId, tid );
1547 toolMgr()->append( PerspectiveId, tid );
1548 #if OCC_VERSION_LARGE > 0x06090000
1549 toolMgr()->append( StereoId, tid );
1552 toolMgr()->append( ResetId, tid );
1555 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1556 aMemAction->insertAction( toolMgr()->action( MemId ) );
1557 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1558 toolMgr()->append( aMemAction, tid );
1560 toolMgr()->append( toolMgr()->separator(), tid );
1561 toolMgr()->append( CloneId, tid );
1563 toolMgr()->append( toolMgr()->separator(), tid );
1564 toolMgr()->append( ClippingId, tid );
1565 toolMgr()->append( AxialScaleId, tid );
1566 toolMgr()->append( GraduatedAxesId, tid );
1567 toolMgr()->append( AmbientId, tid );
1569 toolMgr()->append( MaximizedId, tid );
1570 toolMgr()->append( SynchronizeId, tid );
1571 #ifdef ENABLE_RAY_TRACING
1572 toolMgr()->append( RayTracingId, tid );
1573 toolMgr()->append( EnvTextureId, tid );
1574 toolMgr()->append( LightSourceId, tid );
1579 \brief Perform 'fit all' operation.
1581 void OCCViewer_ViewWindow::onViewFitAll()
1583 myViewPort->fitAll();
1587 \brief Perform "front view" transformation.
1589 void OCCViewer_ViewWindow::onFrontView()
1591 emit vpTransformationStarted ( FRONTVIEW );
1592 Handle(V3d_View) aView3d = myViewPort->getView();
1593 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
1595 emit vpTransformationFinished ( FRONTVIEW );
1599 \brief Perform "back view" transformation.
1601 void OCCViewer_ViewWindow::onBackView()
1603 emit vpTransformationStarted ( BACKVIEW );
1604 Handle(V3d_View) aView3d = myViewPort->getView();
1605 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
1607 emit vpTransformationFinished ( BACKVIEW );
1611 \brief Perform "top view" transformation.
1613 void OCCViewer_ViewWindow::onTopView()
1615 emit vpTransformationStarted ( TOPVIEW );
1616 Handle(V3d_View) aView3d = myViewPort->getView();
1617 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
1619 emit vpTransformationFinished ( TOPVIEW );
1623 \brief Perform "bottom view" transformation.
1625 void OCCViewer_ViewWindow::onBottomView()
1627 emit vpTransformationStarted ( BOTTOMVIEW );
1628 Handle(V3d_View) aView3d = myViewPort->getView();
1629 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
1631 emit vpTransformationFinished ( BOTTOMVIEW );
1635 \brief Perform "left view" transformation.
1637 void OCCViewer_ViewWindow::onLeftView()
1639 emit vpTransformationStarted ( LEFTVIEW );
1640 Handle(V3d_View) aView3d = myViewPort->getView();
1641 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
1643 emit vpTransformationFinished ( LEFTVIEW );
1647 \brief Perform "right view" transformation.
1649 void OCCViewer_ViewWindow::onRightView()
1651 emit vpTransformationStarted ( RIGHTVIEW );
1652 Handle(V3d_View) aView3d = myViewPort->getView();
1653 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
1655 emit vpTransformationFinished ( RIGHTVIEW );
1659 \brief Rotate view 90 degrees clockwise
1661 void OCCViewer_ViewWindow::onClockWiseView()
1663 emit vpTransformationStarted ( CLOCKWISEVIEW );
1664 myViewPort->rotateXY( 90. );
1665 emit vpTransformationFinished ( CLOCKWISEVIEW );
1669 \brief Rotate view 90 degrees conterclockwise
1671 void OCCViewer_ViewWindow::onAntiClockWiseView()
1673 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1674 myViewPort->rotateXY( -90. );
1675 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1679 \brief Perform "reset view" transformation.
1681 Sets default orientation of the viewport camera.
1683 void OCCViewer_ViewWindow::onResetView()
1685 emit vpTransformationStarted( RESETVIEW );
1686 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1687 myViewPort->getView()->Reset( false );
1688 myViewPort->fitAll( false, true, false );
1689 myViewPort->getView()->SetImmediateUpdate( upd );
1690 onProjectionType(); // needed to apply projection type properly after reset
1691 myViewPort->getView()->Update();
1692 emit vpTransformationFinished( RESETVIEW );
1696 \brief Set the given projection mode.
1698 Set the given projection mode: Orthographic or Perspective.
1700 void OCCViewer_ViewWindow::onProjectionType( QAction* theAction )
1702 Handle(V3d_View) aView3d = myViewPort->getView();
1703 if ( !aView3d.IsNull() ) {
1704 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1705 if (theAction == toolMgr()->action( OrthographicId )) {
1706 myModel->setProjectionType(Orthographic);
1707 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Orthographic );
1708 aCamera->SetFOVy(45.0);
1710 else if (theAction == toolMgr()->action( PerspectiveId )) {
1711 myModel->setProjectionType(Perspective);
1712 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Perspective );
1713 aCamera->SetFOVy(30.0);
1715 #if OCC_VERSION_LARGE > 0x06090000
1716 if (toolMgr()->action( StereoId )->isChecked()) {
1717 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1718 aCamera->SetFOVy(30.0);
1727 \brief Sets Stereo projection mode.
1729 Sets Stereo projection mode.
1731 void OCCViewer_ViewWindow::onStereoType( bool activate )
1733 #if OCC_VERSION_LARGE > 0x06090000
1734 Handle(V3d_View) aView3d = myViewPort->getView();
1735 if ( !aView3d.IsNull() ) {
1736 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1738 toolMgr()->action( PerspectiveId )->setChecked(true);
1739 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1740 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(false);
1742 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1743 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1744 setStereoType( aResMgr->integerValue( "OCCViewer", "stereo_type", 0 ) );
1745 setAnaglyphFilter( aResMgr->integerValue( "OCCViewer", "anaglyph_filter", 0 ) );
1746 setReverseStereo( aResMgr->booleanValue( "OCCViewer", "reverse_stereo", false ) );
1747 setVSync( aResMgr->booleanValue( "OCCViewer", "enable_vsync", true ) );
1748 setQuadBufferSupport( aResMgr->booleanValue( "OCCViewer", "enable_quad_buffer_support", false ) );
1751 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(true);
1752 if (myModel->projectionType() == Orthographic) {
1753 toolMgr()->action( OrthographicId )->setChecked(true);
1754 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Orthographic);
1756 else if (myModel->projectionType() == Perspective) {
1757 toolMgr()->action( PerspectiveId )->setChecked(true);
1758 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1765 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1766 toolMgr()->action( StereoId )->isChecked() )
1767 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1772 \brief Restore the view.
1774 Restore the projection mode based on tool-buttons states.
1776 void OCCViewer_ViewWindow::onProjectionType()
1778 emit vpTransformationStarted( PROJECTION );
1779 if (toolMgr()->action( OrthographicId )->isChecked())
1780 setProjectionType( Orthographic );
1781 if (toolMgr()->action( PerspectiveId )->isChecked())
1782 setProjectionType( Perspective );
1783 #if OCC_VERSION_LARGE > 0x06090000
1784 if (toolMgr()->action( StereoId )->isChecked())
1785 setProjectionType( Stereo );
1787 emit vpTransformationFinished( PROJECTION );
1790 void OCCViewer_ViewWindow::setProjectionType( int mode )
1792 QtxAction* anOrthographicAction = dynamic_cast<QtxAction*>( toolMgr()->action( OrthographicId ) );
1793 QtxAction* aPerspectiveAction = dynamic_cast<QtxAction*>( toolMgr()->action( PerspectiveId ) );
1794 #if OCC_VERSION_LARGE > 0x06090000
1795 QtxAction* aStereoAction = dynamic_cast<QtxAction*>( toolMgr()->action( StereoId ) );
1799 onProjectionType( anOrthographicAction );
1802 onProjectionType( aPerspectiveAction );
1805 onStereoType( true );
1808 // update action state if method is called outside
1809 if ( mode == Orthographic && !anOrthographicAction->isChecked() ) {
1810 anOrthographicAction->setChecked( true );
1811 #if OCC_VERSION_LARGE > 0x06090000
1812 aStereoAction->setChecked( false );
1815 if ( mode == Perspective && !aPerspectiveAction->isChecked() ) {
1816 aPerspectiveAction->setChecked( true );
1817 #if OCC_VERSION_LARGE > 0x06090000
1818 aStereoAction->setChecked( false );
1821 #if OCC_VERSION_LARGE > 0x06090000
1822 if ( mode == Stereo ) {
1823 aStereoAction->setChecked( true );
1824 if ( anOrthographicAction->isEnabled() ) {
1825 anOrthographicAction->setEnabled( false );
1826 anOrthographicAction->setChecked( false );
1827 aStereoAction->setChecked( false );
1830 anOrthographicAction->setEnabled( true );
1831 aStereoAction->setChecked( false );
1832 anOrthographicAction->setChecked(myModel->projectionType() == Orthographic);
1834 if ( aPerspectiveAction->isEnabled() ) {
1835 aPerspectiveAction->setEnabled( false );
1836 aPerspectiveAction->setChecked( true );
1837 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1838 toolMgr()->action( StereoId )->isChecked() )
1839 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1842 aPerspectiveAction->setEnabled( true );
1843 aStereoAction->setChecked( false );
1844 aPerspectiveAction->setChecked(myModel->projectionType() == Perspective);
1849 if ( !anOrthographicAction->isEnabled() )
1850 anOrthographicAction->setEnabled( true );
1851 if ( !aPerspectiveAction->isEnabled() )
1852 aPerspectiveAction->setEnabled( true );
1858 \brief Perform "fit all" transformation.
1860 void OCCViewer_ViewWindow::onFitAll()
1862 emit vpTransformationStarted( FITALLVIEW );
1863 myViewPort->fitAll();
1864 emit vpTransformationFinished( FITALLVIEW );
1868 \brief Perform "fit selection" transformation.
1870 void OCCViewer_ViewWindow::onFitSelection()
1872 emit vpTransformationStarted( FITSELECTION );
1873 #if OCC_VERSION_LARGE > 0x06090000
1874 myModel->getAISContext()->FitSelected( getViewPort()->getView() );
1876 emit vpTransformationFinished( FITSELECTION );
1880 \brief Called if 'change rotation point' operation is activated.
1881 \param on action state
1883 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1887 if (!mySetRotationPointDlg)
1889 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1890 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1893 if (!mySetRotationPointDlg->isVisible())
1895 //if (mySetRotationPointDlg->IsFirstShown())
1896 if (myCurrPointType == GRAVITY)
1898 Standard_Real Xcenter, Ycenter, Zcenter;
1899 if (computeGravityCenter(Xcenter, Ycenter, Zcenter))
1900 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1902 mySetRotationPointDlg->show();
1907 if (mySetRotationPointDlg->isVisible())
1908 mySetRotationPointDlg->hide();
1913 \brief Create one more window with same content.
1915 void OCCViewer_ViewWindow::onCloneView()
1917 SUIT_ViewWindow* vw = myManager->createViewWindow();
1919 emit viewCloned( vw );
1923 Creates one more window with same content
1925 void OCCViewer_ViewWindow::onAxialScale()
1927 if ( !myScalingDlg )
1928 myScalingDlg = new OCCViewer_AxialScaleDlg( this , myModel );
1930 if ( !myScalingDlg->isVisible() )
1932 myScalingDlg->Update();
1933 myScalingDlg->show();
1938 Shows Graduated Axes dialog
1940 void OCCViewer_ViewWindow::onGraduatedAxes()
1942 myCubeAxesDlg->Update();
1943 myCubeAxesDlg->show();
1946 void OCCViewer_ViewWindow::onAmbientToogle()
1948 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
1949 viewer->InitDefinedLights();
1950 while(viewer->MoreDefinedLights())
1952 Handle(V3d_Light) light = viewer->DefinedLight();
1953 if(light->Type() != V3d_AMBIENT)
1955 Handle(V3d_View) aView3d = myViewPort->getView();
1956 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
1957 else viewer->SetLightOn(light);
1959 viewer->NextDefinedLights();
1965 \brief Store view parameters.
1967 void OCCViewer_ViewWindow::onMemorizeView()
1969 appendViewAspect( getViewParams() );
1973 \brief Restore view parameters.
1975 void OCCViewer_ViewWindow::onRestoreView()
1977 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
1978 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
1980 updateViewAspects( aDlg->parameters() );
1981 if( myRestoreFlag && aDlg->parameters().count() )
1982 performRestoring( aDlg->currentItem() );
1986 \brief Restore view parameters.
1987 \param anItem view parameters
1989 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
1991 Handle(V3d_View) aView3d = myViewPort->getView();
1993 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
1994 aView3d->SetScale( anItem.scale );
1995 aView3d->SetTwist( anItem.twist );
1996 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
1997 aView3d->SetImmediateUpdate( prev );
1998 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1999 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2000 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
2002 #if OCC_VERSION_LARGE > 0x06070100
2003 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
2005 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
2007 // "eye" and "at" require conversion to represent center panning
2008 // up direction is only available after setting angle of twist and
2009 // other view parameters
2010 aView3d->Up( anUpX, anUpY, anUpZ );
2012 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
2013 gp_Dir anUp( anUpX, anUpY, anUpZ );
2014 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
2015 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2016 gp_Dir aSide = aProj ^ anUp;
2018 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
2019 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
2021 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
2022 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2025 aView3d->SetCenter( anItem.centerX, anItem.centerY );
2028 if ( !baseParamsOnly ) {
2030 myModel->setTrihedronShown( anItem.isVisible );
2031 myModel->setTrihedronSize( anItem.size );
2033 // graduated trihedron
2034 bool anIsVisible = anItem.gtIsVisible;
2035 OCCViewer_AxisWidget::AxisData anAxisData[3];
2036 anAxisData[0].DrawName = anItem.gtDrawNameX;
2037 anAxisData[1].DrawName = anItem.gtDrawNameZ;
2038 anAxisData[2].DrawName = anItem.gtDrawNameZ;
2039 anAxisData[0].Name = anItem.gtNameX;
2040 anAxisData[1].Name = anItem.gtNameZ;
2041 anAxisData[2].Name = anItem.gtNameZ;
2042 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
2043 anItem.gtNameColorGX,
2044 anItem.gtNameColorBX );
2045 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
2046 anItem.gtNameColorGY,
2047 anItem.gtNameColorBY );
2048 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
2049 anItem.gtNameColorGZ,
2050 anItem.gtNameColorBZ );
2051 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
2052 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
2053 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
2054 anAxisData[0].NbValues = anItem.gtNbValuesX;
2055 anAxisData[1].NbValues = anItem.gtNbValuesY;
2056 anAxisData[2].NbValues = anItem.gtNbValuesZ;
2057 anAxisData[0].Offset = anItem.gtOffsetX;
2058 anAxisData[1].Offset = anItem.gtOffsetY;
2059 anAxisData[2].Offset = anItem.gtOffsetZ;
2060 anAxisData[0].Color = QColor( anItem.gtColorRX,
2063 anAxisData[1].Color = QColor( anItem.gtColorRY,
2066 anAxisData[2].Color = QColor( anItem.gtColorRZ,
2069 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
2070 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
2071 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
2072 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
2073 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
2074 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
2076 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
2077 myCubeAxesDlg->ApplyData( aView3d );
2079 } // if ( !baseParamsOnly )
2085 \brief Set restore flag.
2087 void OCCViewer_ViewWindow::setRestoreFlag()
2093 \brief Called when action "show/hide trihedron" is activated.
2095 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
2097 myModel->setTrihedronShown(show);
2101 \brief Toggles preselection (highlighting) on/off
2103 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
2105 myPreselectionEnabled = on;
2106 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
2108 // unhighlight all highlighted objects
2110 myModel->unHighlightAll( true, false );
2113 // update action state if method is called outside
2114 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2115 if ( a && a->isChecked() != on ) {
2116 a->setChecked( on );
2121 \brief Toggles selection on/off
2123 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
2125 mySelectionEnabled = on;
2126 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
2128 // update action state if method is called outside
2131 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2133 a->setEnabled( on );
2137 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
2138 if ( a && a->isChecked() != on ) {
2139 a->setChecked( on );
2144 \brief Switches "keyboard free" interaction style on/off
2146 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
2148 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
2150 // update action state if method is called outside
2151 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
2152 if ( a && a->isChecked() != on )
2153 a->setChecked( on );
2157 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
2159 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
2161 myViewPort->setAdvancedZoomingEnabled( on );
2163 // update action state if method is called outside
2164 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
2165 if ( a && a->isChecked() != on )
2166 a->setChecked( on );
2170 \brief Get current interaction style
2171 \return interaction style
2173 int OCCViewer_ViewWindow::interactionStyle() const
2175 return myInteractionStyle;
2179 \brief Set current interaction style
2180 \param theStyle interaction style
2182 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
2184 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
2188 \brief Get current zooming style
2189 \return zooming style
2191 int OCCViewer_ViewWindow::zoomingStyle() const
2193 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
2197 \brief Set current zooming style
2198 \param theStyle zooming style
2200 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
2202 onSwitchZoomingStyle( theStyle == 1 );
2206 \brief Dump view window contents to the pixmap.
2207 \return pixmap containing all scene rendered in the window
2209 QImage OCCViewer_ViewWindow::dumpView()
2211 Handle(V3d_View) view = myViewPort->getView();
2212 if ( view.IsNull() )
2215 int aWidth = myViewPort->width();
2216 int aHeight = myViewPort->height();
2218 // rnv: An old approach to dump the OCCViewer content
2219 // Now used OCCT built-in procedure.
2221 QApplication::syncX();
2222 view->Redraw(); // In order to reactivate GL context
2225 #ifndef DISABLE_GLVIEWER
2226 OpenGLUtils_FrameBuffer aFrameBuffer;
2227 if( aFrameBuffer.init( aWidth, aHeight ) )
2229 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
2231 glPushAttrib( GL_VIEWPORT_BIT );
2232 glViewport( 0, 0, aWidth, aHeight );
2233 aFrameBuffer.bind();
2238 aFrameBuffer.unbind();
2241 aFrameBuffer.bind();
2242 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
2243 aFrameBuffer.unbind();
2245 anImage = anImage.rgbSwapped();
2246 anImage = anImage.mirrored();
2249 // if frame buffers are unsupported, use old functionality
2252 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
2254 QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
2256 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
2262 view->ToPixMap(aPix,aWidth, aHeight,Graphic3d_BT_RGBA);
2264 QImage anImage( aPix.Data(), aWidth, aHeight, QImage::Format_ARGB32 );
2265 anImage = anImage.mirrored();
2269 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
2270 const QString& fileName,
2271 const QString& format )
2274 QApplication::setOverrideCursor( Qt::WaitCursor );
2275 if ( format != "PS" && format != "EPS")
2276 res = myViewPort->getView()->Dump( fileName.toStdString().c_str() );
2278 #if OCC_VERSION_MAJOR < 7
2279 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
2281 Handle(Graphic3d_CView) a3dView = myViewPort->getView()->View();
2285 res = a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
2286 else if (format == "EPS")
2287 res = a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
2289 QApplication::restoreOverrideCursor();
2294 QString OCCViewer_ViewWindow::filter() const
2296 return tr( "OCC_IMAGE_FILES" );
2301 \brief Set parameters of the cutting plane
2302 \param on if \c true, cutting plane is enabled
2303 \param x X position of plane point
2304 \param y Y position of plane point
2305 \param z Z position of plane point
2306 \param dx X coordinate of plane normal
2307 \param dy Y coordinate of plane normal
2308 \param dz Z coordinate of plane normal
2310 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2311 const double dx, const double dy, const double dz )
2313 Handle(V3d_View) view = myViewPort->getView();
2314 if ( view.IsNull() )
2318 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2320 // try to use already existing plane or create a new one
2321 Handle(V3d_Plane) clipPlane;
2323 // calculate new a,b,c,d values for the plane
2324 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2326 pln.Coefficients(a, b, c, d);
2328 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2329 if(aPlanes.Size() > 0 ) {
2330 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2331 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2332 aClipPlane->SetEquation(pln);
2333 aClipPlane->SetOn(Standard_True);
2335 view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2339 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2340 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2341 for( ;anIter.More();anIter.Next() ){
2342 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2343 aClipPlane->SetOn(Standard_False);
2351 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2353 gp_Dir aDir = pln.Axis().Direction();
2354 gp_Pnt aPnt = pln.Location();
2355 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2360 \brief Check if any cutting plane is enabled
2361 \return \c true if at least one cutting plane is enabled
2363 bool OCCViewer_ViewWindow::isCuttingPlane()
2365 Handle(V3d_View) view = myViewPort->getView();
2367 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2368 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2369 for( ;anIter.More();anIter.Next() ) {
2370 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2371 if(aClipPlane->IsOn()) {
2380 \brief Get the visual parameters of the view window.
2381 \return visual parameters of view window
2383 viewAspect OCCViewer_ViewWindow::getViewParams() const
2385 double projX, projY, projZ, twist;
2386 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2387 double aScaleX, aScaleY, aScaleZ;
2389 Handle(V3d_View) aView3d = myViewPort->getView();
2391 aView3d->Proj( projX, projY, projZ );
2392 aView3d->At( atX, atY, atZ );
2393 aView3d->Eye( eyeX, eyeY, eyeZ );
2394 twist = aView3d->Twist();
2396 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2398 bool isShown = myModel->isTrihedronVisible();
2399 double size = myModel->trihedronSize();
2401 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2404 params.scale = aView3d->Scale();
2405 params.projX = projX;
2406 params.projY = projY;
2407 params.projZ = projZ;
2408 params.twist = twist;
2415 params.scaleX = aScaleX;
2416 params.scaleY = aScaleY;
2417 params.scaleZ = aScaleZ;
2418 params.name = aName;
2419 params.isVisible= isShown;
2422 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2423 aView3d->Center( params.centerX, params.centerY );
2426 // graduated trihedron
2427 bool anIsVisible = false;
2428 OCCViewer_AxisWidget::AxisData anAxisData[3];
2429 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2431 params.gtIsVisible = anIsVisible;
2432 params.gtDrawNameX = anAxisData[0].DrawName;
2433 params.gtDrawNameY = anAxisData[1].DrawName;
2434 params.gtDrawNameZ = anAxisData[2].DrawName;
2435 params.gtNameX = anAxisData[0].Name;
2436 params.gtNameY = anAxisData[1].Name;
2437 params.gtNameZ = anAxisData[2].Name;
2438 params.gtNameColorRX = anAxisData[0].NameColor.red();
2439 params.gtNameColorGX = anAxisData[0].NameColor.green();
2440 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2441 params.gtNameColorRY = anAxisData[1].NameColor.red();
2442 params.gtNameColorGY = anAxisData[1].NameColor.green();
2443 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2444 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2445 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2446 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2447 params.gtDrawValuesX = anAxisData[0].DrawValues;
2448 params.gtDrawValuesY = anAxisData[1].DrawValues;
2449 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2450 params.gtNbValuesX = anAxisData[0].NbValues;
2451 params.gtNbValuesY = anAxisData[1].NbValues;
2452 params.gtNbValuesZ = anAxisData[2].NbValues;
2453 params.gtOffsetX = anAxisData[0].Offset;
2454 params.gtOffsetY = anAxisData[1].Offset;
2455 params.gtOffsetZ = anAxisData[2].Offset;
2456 params.gtColorRX = anAxisData[0].Color.red();
2457 params.gtColorGX = anAxisData[0].Color.green();
2458 params.gtColorBX = anAxisData[0].Color.blue();
2459 params.gtColorRY = anAxisData[1].Color.red();
2460 params.gtColorGY = anAxisData[1].Color.green();
2461 params.gtColorBY = anAxisData[1].Color.blue();
2462 params.gtColorRZ = anAxisData[2].Color.red();
2463 params.gtColorGZ = anAxisData[2].Color.green();
2464 params.gtColorBZ = anAxisData[2].Color.blue();
2465 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2466 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2467 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2468 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2469 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2470 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2476 \brief Get visual parameters of this view window.
2477 \return visual parameters of view window
2479 QString OCCViewer_ViewWindow::getVisualParameters()
2481 viewAspect params = getViewParams();
2485 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2486 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2487 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
2488 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
2490 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2491 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2492 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2493 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2494 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2495 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2496 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2497 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2498 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2499 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2500 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2501 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2502 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2503 data << QString( "isVisible=%1" ).arg( params.isVisible );
2504 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2506 ClipPlanesList aPlanes = myModel->getClipPlanes();
2507 for ( int i=0; i < aPlanes.size(); i++ )
2509 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2510 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2511 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2512 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2513 switch ( aPlane.Mode )
2515 case OCCViewer_ClipPlane::Absolute :
2517 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2519 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2521 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2522 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2523 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2527 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2532 case OCCViewer_ClipPlane::Relative :
2534 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2535 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2536 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2541 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2542 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2543 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2544 data << ClippingPlane;
2547 // graduated trihedron
2548 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2549 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2550 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2551 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2552 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2553 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2554 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2555 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2556 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2557 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2558 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2559 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2560 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2561 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2562 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2563 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2564 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2565 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2566 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2567 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2568 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2569 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2570 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2571 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2572 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2573 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2574 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2575 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2576 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2577 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2578 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2579 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2580 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2581 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2582 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2583 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2584 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2585 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2586 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2587 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2589 // ray tracing parameters
2590 Graphic3d_RenderingParams rendParams = this->getViewPort()->getView()->RenderingParams();
2591 if ( rendParams.Method == Graphic3d_RM_RAYTRACING ) {
2592 QString RayTracing = "rayTracing=";
2593 RayTracing += QString( "rtDepth~%1;" ).arg( rendParams.RaytracingDepth );
2594 RayTracing += QString( "rtReflection~%1;" ).arg( rendParams.IsReflectionEnabled );
2595 RayTracing += QString( "rtAntialiasing~%1;" ).arg( rendParams.IsAntialiasingEnabled );
2596 RayTracing += QString( "rtShadow~%1;" ).arg( rendParams.IsShadowEnabled );
2597 RayTracing += QString( "rtTransShadow~%1;" ).arg( rendParams.IsTransparentShadowEnabled );
2601 // environment texture parameters
2602 Handle(Graphic3d_TextureEnv) aTexture = this->getViewPort()->getView()->TextureEnv();
2603 if ( !aTexture.IsNull() ) {
2604 QString EnvTexture = "envTexture=";
2605 if ( aTexture->Name() == Graphic3d_NOT_ENV_UNKNOWN ) {
2606 TCollection_AsciiString aFileName;
2607 aTexture->Path().SystemName( aFileName );
2608 EnvTexture += QString( "etFile~%1;" ).arg( aFileName.ToCString() );
2611 EnvTexture += QString( "etNumber~%1;" ).arg( aTexture->Name() );
2615 // light source parameters
2616 myModel->getViewer3d()->InitDefinedLights();
2617 while ( myModel->getViewer3d()->MoreDefinedLights() )
2619 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2620 if ( aLight->Type() != V3d_AMBIENT ) {
2621 QString LightSource = QString( "lightSource=" );
2622 LightSource += QString( "lightType~%1;" ).arg( aLight->Type() );
2624 if ( aLight->Type() == V3d_DIRECTIONAL )
2625 Handle(V3d_DirectionalLight)::DownCast( aLight )->Direction( aX, aY, aZ );
2626 else if ( aLight->Type() == V3d_POSITIONAL )
2627 Handle(V3d_PositionalLight)::DownCast( aLight )->Position( aX, aY, aZ );
2628 LightSource += QString( "lightX~%1;" ).arg( aX );
2629 LightSource += QString( "lightY~%1;" ).arg( aY );
2630 LightSource += QString( "lightZ~%1;" ).arg( aZ );
2631 LightSource += QString( "lightColorR~%1;" ).arg( aLight->Color().Red() );
2632 LightSource += QString( "lightColorG~%1;" ).arg( aLight->Color().Green() );
2633 LightSource += QString( "lightColorB~%1;" ).arg( aLight->Color().Blue() );
2634 LightSource += QString( "lightHeadlight~%1;" ).arg( aLight->Headlight() );
2635 data << LightSource;
2637 myModel->getViewer3d()->NextDefinedLights();
2640 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2641 data << QString( "background=%1" ).arg( bg );
2643 return data.join("*");
2647 \brief Restore visual parameters of the view window.
2648 \param parameters visual parameters of view window
2650 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2653 ClipPlanesList aClipPlanes;
2654 QStringList data = parameters.split( '*' );
2655 Qtx::BackgroundData bgData;
2656 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2658 foreach( QString param, data ) {
2659 QString paramName = param.section( '=', 0, 0 ).trimmed();
2660 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2661 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2662 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2663 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2664 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2665 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2666 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2667 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2668 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2669 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2670 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2671 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2672 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2673 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2674 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2675 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2676 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2677 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2678 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2679 else if ( paramName.contains( "ClippingPlane" ) )
2681 QStringList ClipPlaneData = paramValue.split( ';' );
2682 OCCViewer_ClipPlane aPlane;
2683 foreach( QString ClipPlaneParam, ClipPlaneData )
2685 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2686 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2687 if ( ClipPlane_paramName == "Mode" )
2689 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2691 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2692 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2693 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2694 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2697 switch ( aPlane.Mode )
2699 case OCCViewer_ClipPlane::Absolute :
2700 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2701 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2702 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2703 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2704 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2707 case OCCViewer_ClipPlane::Relative :
2708 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2709 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2710 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2715 aClipPlanes.push_back(aPlane);
2717 // graduated trihedron
2718 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2719 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2720 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2721 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2722 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2723 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2724 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2725 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2726 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2727 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2728 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2729 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2730 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2731 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2732 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2733 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2734 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2735 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2736 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2737 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2738 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2739 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2740 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2741 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2742 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2743 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2744 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2745 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2746 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2747 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2748 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2749 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2750 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2751 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2752 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2753 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2754 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2755 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2756 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2757 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2758 else if ( paramName == "rayTracing" )
2760 Graphic3d_RenderingParams& rendParams = this->getViewPort()->getView()->ChangeRenderingParams();
2761 rendParams.Method = Graphic3d_RM_RAYTRACING;
2762 QStringList rtData = paramValue.split( ';' );
2763 foreach( QString rtParam, rtData )
2765 QString rt_paramName = rtParam.section( '~', 0, 0 ).trimmed();
2766 QString rt_paramValue = rtParam.section( '~', 1, 1 ).trimmed();
2767 if ( rt_paramName == "rtDepth" ) rendParams.RaytracingDepth = rt_paramValue.toInt();
2768 else if ( rt_paramName == "rtReflection" ) rendParams.IsReflectionEnabled = rt_paramValue.toInt();
2769 else if ( rt_paramName == "rtAntialiasing" ) rendParams.IsAntialiasingEnabled = rt_paramValue.toInt();
2770 else if ( rt_paramName == "rtShadow" ) rendParams.IsShadowEnabled = rt_paramValue.toInt();
2771 else if ( rt_paramName == "rtTransShadow" ) rendParams.IsTransparentShadowEnabled = rt_paramValue.toInt();
2774 else if ( paramName == "envTexture" )
2776 Handle(Graphic3d_TextureEnv) aTexture;
2777 QStringList etData = paramValue.split( ';' );
2778 foreach( QString etParam, etData )
2780 QString et_paramName = etParam.section( '~', 0, 0 ).trimmed();
2781 QString et_paramValue = etParam.section( '~', 1, 1 ).trimmed();
2782 if ( et_paramName == "etNumber" )
2783 aTexture = new Graphic3d_TextureEnv( Graphic3d_NameOfTextureEnv( et_paramValue.toInt() ) );
2784 else if ( et_paramName == "etFile" )
2785 aTexture = new Graphic3d_TextureEnv( TCollection_AsciiString( et_paramValue.toStdString().c_str() ) );
2786 Handle(V3d_View) aView = this->getViewPort()->getView();
2787 aView->SetTextureEnv( aTexture );
2788 #if OCC_VERSION_LARGE <= 0x07000000
2789 aView->SetSurfaceDetail( V3d_TEX_ENVIRONMENT );
2793 else if ( paramName == "lightSource" )
2795 myModel->getViewer3d()->InitDefinedLights();
2796 while ( myModel->getViewer3d()->MoreDefinedLights() )
2798 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2799 if( aLight->Type() != V3d_AMBIENT ) {
2800 myModel->getViewer3d()->DelLight( aLight );
2801 myModel->getViewer3d()->InitDefinedLights();
2803 myModel->getViewer3d()->NextDefinedLights();
2808 V3d_TypeOfLight aType;
2810 QStringList lsData = paramValue.split( ';' );
2811 foreach( QString lsParam, lsData )
2813 QString ls_paramName = lsParam.section( '~', 0, 0 ).trimmed();
2814 QString ls_paramValue = lsParam.section( '~', 1, 1 ).trimmed();
2815 if ( ls_paramName == "lightType" ) aType = V3d_TypeOfLight( ls_paramValue.toInt() );
2816 else if ( ls_paramName == "lightX" ) aX = ls_paramValue.toDouble();
2817 else if ( ls_paramName == "lightY" ) aY = ls_paramValue.toDouble();
2818 else if ( ls_paramName == "lightZ" ) aZ = ls_paramValue.toDouble();
2819 else if ( ls_paramName == "lightColorR" ) cR = ls_paramValue.toDouble();
2820 else if ( ls_paramName == "lightColorG" ) cG = ls_paramValue.toDouble();
2821 else if ( ls_paramName == "lightColorB" ) cB = ls_paramValue.toDouble();
2822 else if ( ls_paramName == "lightHeadlight" ) isHeadlight = ls_paramValue.toInt();
2824 Quantity_Color aColor = Quantity_Color( cR, cG, cB, Quantity_TOC_RGB );
2825 if( aType == V3d_DIRECTIONAL ) {
2826 Handle(V3d_DirectionalLight) aLight = new V3d_DirectionalLight( myModel->getViewer3d() );
2827 aLight->SetDirection( aX, aY, aZ );
2828 aLight->SetColor( aColor );
2829 aLight->SetHeadlight( isHeadlight );
2830 myModel->getViewer3d()->SetLightOn( aLight );
2832 else if( aType == V3d_POSITIONAL ) {
2833 Handle(V3d_PositionalLight) aLight = new V3d_PositionalLight( myModel->getViewer3d(), aX, aY, aZ, aColor.Name() );
2834 aLight->SetHeadlight( isHeadlight );
2835 myModel->getViewer3d()->SetLightOn( aLight );
2838 else if ( paramName == "background" ) {
2839 QString bg = paramValue.replace( "$", "=" );
2840 bgData = Qtx::stringToBackground( bg );
2844 else // old format - "1.000e+00*0.000e+00..."
2847 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2848 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2849 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2850 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2851 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2852 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2853 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
2854 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2855 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2856 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
2857 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2858 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2859 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2860 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
2861 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
2862 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
2863 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
2864 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
2866 performRestoring( params );
2867 setBackground( bgData );
2868 myModel->setClipPlanes(aClipPlanes);
2872 \brief Handle show event.
2874 Emits Show() signal.
2876 \param theEvent show event
2878 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2880 emit Show( theEvent );
2884 \brief Handle hide event.
2886 Emits Hide() signal.
2888 \param theEvent hide event
2890 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
2892 emit Hide( theEvent );
2897 Save old cursor. [ protected ]
2899 void OCCViewer_ViewWindow::saveCursor()
2901 QCursor* aCursor = NULL;
2903 aCursor = myViewPort->getDefaultCursor();
2904 myCursor = ( aCursor ? *aCursor : cursor() );
2909 Creates default sketcher. [ virtual protected ]
2911 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
2914 return new OCCViewer_RectSketcher( this, type );
2915 if ( type == Polygon )
2916 return new OCCViewer_PolygonSketcher( this, type );
2920 void OCCViewer_ViewWindow::initSketchers()
2922 if ( mySketchers.isEmpty() )
2924 mySketchers.append( createSketcher( Rect ) );
2925 mySketchers.append( createSketcher( Polygon ) );
2929 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
2931 OCCViewer_ViewSketcher* sketcher = 0;
2932 QList<OCCViewer_ViewSketcher*>::Iterator it;
2933 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
2935 OCCViewer_ViewSketcher* sk = (*it);
2936 if ( sk->type() == typ )
2943 Handles requests for sketching in the active view. [ virtual public ]
2945 void OCCViewer_ViewWindow::activateSketching( int type )
2947 OCCViewer_ViewPort3d* vp = getViewPort();
2951 if ( !vp->isSketchingEnabled() )
2954 /* Finish current sketching */
2955 if ( type == NoSketching )
2959 onSketchingFinished();
2960 mypSketcher->deactivate();
2964 /* Activate new sketching */
2967 activateSketching( NoSketching ); /* concurrency not suported */
2968 mypSketcher = getSketcher( type );
2971 mypSketcher->activate();
2972 onSketchingStarted();
2978 Unhilights detected entities. [ virtual protected ]
2980 void OCCViewer_ViewWindow::onSketchingStarted()
2985 Selection by rectangle or polygon. [ virtual protected ]
2987 void OCCViewer_ViewWindow::onSketchingFinished()
2989 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
2990 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
2992 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
2993 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
2994 switch( mypSketcher->type() )
2998 QRect* aRect = (QRect*)mypSketcher->data();
3001 int aLeft = aRect->left();
3002 int aRight = aRect->right();
3003 int aTop = aRect->top();
3004 int aBottom = aRect->bottom();
3008 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
3010 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
3016 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
3019 int size = aPolygon->size();
3020 TColgp_Array1OfPnt2d anArray( 1, size );
3022 QPolygon::Iterator it = aPolygon->begin();
3023 QPolygon::Iterator itEnd = aPolygon->end();
3024 for( int index = 1; it != itEnd; ++it, index++ )
3026 QPoint aPoint = *it;
3027 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
3031 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
3033 ic->Select( anArray, getViewPort()->getView(), Standard_False );
3041 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
3042 aViewMgr->getOCCViewer()->performSelectionChanged();
3046 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
3051 bool OCCViewer_ViewWindow::transformRequested() const
3053 return ( myOperation != NOTHING );
3056 bool OCCViewer_ViewWindow::transformInProcess() const
3058 return myEventStarted;
3061 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
3063 myEventStarted = bOn;
3067 Set enabled state of transformation (rotate, zoom, etc)
3069 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
3071 if ( id != NOTHING ) myStatus.insert( id, on );
3075 \return enabled state of transformation (rotate, zoom, etc)
3077 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
3079 return myStatus.contains( id ) ? myStatus[ id ] : true;
3082 void OCCViewer_ViewWindow::onMaximizedView()
3084 setMaximized(!isMaximized());
3087 void OCCViewer_ViewWindow::returnTo3dView()
3089 setReturnedTo3dView( true );
3092 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
3094 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
3095 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
3096 if ( !isVisible3dView )
3097 toolMgr()->show( ReturnTo3dViewId );
3099 toolMgr()->hide( ReturnTo3dViewId );
3100 if ( isVisible3dView ) emit returnedTo3d( );
3104 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
3106 QAction* anAction = toolMgr()->action( MaximizedId );
3107 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
3108 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
3110 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
3111 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
3112 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
3113 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
3114 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
3116 emit maximized( this, true );
3120 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
3121 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
3122 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
3123 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
3124 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
3126 emit maximized( this, false );
3131 bool OCCViewer_ViewWindow::isMaximized() const
3133 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
3136 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
3138 IsSketcherStyle = enable;
3141 bool OCCViewer_ViewWindow::isSketcherStyle() const
3143 return IsSketcherStyle;
3147 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
3152 int OCCViewer_ViewWindow::projectionType() const
3154 int mode = Orthographic;
3155 Handle(V3d_View) aView3d = myViewPort->getView();
3156 if ( !aView3d.IsNull() ) {
3157 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3158 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Perspective)
3160 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Orthographic)
3161 mode = Orthographic;
3162 #if OCC_VERSION_LARGE > 0x06090000
3163 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
3170 void OCCViewer_ViewWindow::setStereoType( int type )
3172 Handle(V3d_View) aView3d = myViewPort->getView();
3173 if ( !aView3d.IsNull() ) {
3174 #if OCC_VERSION_LARGE > 0x06090000
3175 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3176 aParams->StereoMode = (Graphic3d_StereoMode)type;
3181 int OCCViewer_ViewWindow::stereoType() const
3183 int type = QuadBuffer;
3184 Handle(V3d_View) aView3d = myViewPort->getView();
3185 if ( !aView3d.IsNull() ) {
3186 #if OCC_VERSION_LARGE > 0x06090000
3187 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3188 type = (OCCViewer_ViewWindow::StereoType)aParams->StereoMode;
3194 void OCCViewer_ViewWindow::setAnaglyphFilter( int type )
3196 Handle(V3d_View) aView3d = myViewPort->getView();
3197 if ( !aView3d.IsNull() ) {
3198 #if OCC_VERSION_LARGE > 0x06090000
3199 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3200 if (type == RedCyan)
3201 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
3202 if (type == YellowBlue)
3203 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
3204 if (type == GreenMagenta)
3205 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
3210 int OCCViewer_ViewWindow::anaglyphFilter() const
3213 Handle(V3d_View) aView3d = myViewPort->getView();
3214 if ( !aView3d.IsNull() ) {
3215 #if OCC_VERSION_LARGE > 0x06090000
3216 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3217 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized)
3219 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized)
3221 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple)
3222 type = GreenMagenta;
3228 void OCCViewer_ViewWindow::setStereographicFocus( int type, double value )
3230 Handle(V3d_View) aView3d = myViewPort->getView();
3231 if ( !aView3d.IsNull() ) {
3232 #if OCC_VERSION_LARGE > 0x06090000
3233 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3234 aCamera->SetZFocus( (Graphic3d_Camera::FocusType) type, value );
3239 int OCCViewer_ViewWindow::stereographicFocusType() const
3241 int type = Relative;
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 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->ZFocusType();
3252 double OCCViewer_ViewWindow::stereographicFocusValue() const
3255 Handle(V3d_View) aView3d = myViewPort->getView();
3256 if ( !aView3d.IsNull() ) {
3257 #if OCC_VERSION_LARGE > 0x06090000
3258 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3259 value = aCamera->ZFocus();
3265 void OCCViewer_ViewWindow::setInterocularDistance( int type, double value )
3267 Handle(V3d_View) aView3d = myViewPort->getView();
3268 if ( !aView3d.IsNull() ) {
3269 #if OCC_VERSION_LARGE > 0x06090000
3270 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3271 aCamera->SetIOD( (Graphic3d_Camera::IODType) type, value );
3276 int OCCViewer_ViewWindow::interocularDistanceType() const
3278 int type = Relative;
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 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->GetIODType();
3289 double OCCViewer_ViewWindow::interocularDistanceValue() const
3291 double value = 0.05;
3292 Handle(V3d_View) aView3d = myViewPort->getView();
3293 if ( !aView3d.IsNull() ) {
3294 #if OCC_VERSION_LARGE > 0x06090000
3295 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3296 value = aCamera->IOD();
3302 void OCCViewer_ViewWindow::setReverseStereo( bool reverse )
3304 Handle(V3d_View) aView3d = myViewPort->getView();
3305 if ( !aView3d.IsNull() ) {
3306 #if OCC_VERSION_LARGE > 0x06090000
3307 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3308 aParams->ToReverseStereo = reverse;
3313 bool OCCViewer_ViewWindow::isReverseStereo() const
3315 int reverse = false;
3316 Handle(V3d_View) aView3d = myViewPort->getView();
3317 if ( !aView3d.IsNull() ) {
3318 #if OCC_VERSION_LARGE > 0x06090000
3319 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3320 reverse = aParams->ToReverseStereo;
3326 void OCCViewer_ViewWindow::setVSync( bool enable )
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 aCaps->swapInterval = enable;
3338 bool OCCViewer_ViewWindow::isVSync() const
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 enable = aCaps->swapInterval;
3352 void OCCViewer_ViewWindow::setQuadBufferSupport( bool enable )
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 aCaps->contextStereo = enable;
3364 bool OCCViewer_ViewWindow::isQuadBufferSupport() const
3367 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3368 if ( !anIntCont.IsNull() ) {
3369 #if OCC_VERSION_LARGE > 0x06090000
3370 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3371 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3372 enable = aCaps->contextStereo;
3379 bool OCCViewer_ViewWindow::isOpenGlStereoSupport() const
3381 GLboolean support[1];
3382 glGetBooleanv (GL_STEREO, support);
3389 QColor OCCViewer_ViewWindow::backgroundColor() const
3391 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
3395 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
3397 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
3400 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
3402 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
3405 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
3407 if ( myViewPort ) myViewPort->setBackground( theBackground );
3410 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
3412 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
3418 void OCCViewer_ViewWindow::clearViewAspects()
3420 myViewAspects.clear();
3424 \return const reference to list of view aspects
3426 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
3428 return myViewAspects;
3432 Appends new view aspect
3433 \param aParams - new view aspects
3435 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
3437 myViewAspects.append( aParams );
3441 Replaces old view aspects by new ones
3442 \param aViewList - list of new view aspects
3444 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
3446 myViewAspects = aViewList;
3450 Get camera properties for the OCC view window.
3451 \return shared pointer on camera properties.
3453 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
3455 SUIT_CameraProperties aProps;
3457 Handle(V3d_View) aSourceView = getViewPort()->getView();
3458 if ( aSourceView.IsNull() )
3461 if ( get2dMode() == No2dMode ) {
3462 aProps.setDimension( SUIT_CameraProperties::Dim3D );
3465 aProps.setDimension( SUIT_CameraProperties::Dim2D );
3466 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
3469 // read common properites of the view
3470 Standard_Real anUp[3];
3471 Standard_Real anAt[3];
3472 Standard_Real anEye[3];
3473 Standard_Real aProj[3];
3474 Standard_Real anAxialScale[3];
3476 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
3477 aSourceView->At( anAt[0], anAt[1], anAt[2] );
3478 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
3479 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3481 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3482 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
3484 #if OCC_VERSION_LARGE > 0x06070100
3485 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
3487 // store camera properties "as is": it is up to synchronized
3488 // view classes to provide necessary property conversion.
3489 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
3490 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
3492 if ( aSourceView->Camera()->IsOrthographic() )
3494 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
3495 aProps.setViewAngle( 0.0 );
3499 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
3500 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
3502 aProps.setMappingScale( aSourceView->Camera()->Scale() );
3504 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
3506 // generate view orientation matrix for transforming OCC projection reference point
3507 // into a camera (eye) position.
3508 gp_Dir aLeftDir = gp_Dir( anUp[0], anUp[1], anUp[2] ) ^ gp_Dir( aProj[0], aProj[1], aProj[2] );
3511 aTrsf.SetValue( 1, 1, aLeftDir.X() );
3512 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
3513 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
3515 aTrsf.SetValue( 1, 2, anUp[0] );
3516 aTrsf.SetValue( 2, 2, anUp[1] );
3517 aTrsf.SetValue( 3, 2, anUp[2] );
3519 aTrsf.SetValue( 1, 3, aProj[0] );
3520 aTrsf.SetValue( 2, 3, aProj[1] );
3521 aTrsf.SetValue( 3, 3, aProj[2] );
3523 aTrsf.SetValue( 1, 4, anAt[0] );
3524 aTrsf.SetValue( 2, 4, anAt[1] );
3525 aTrsf.SetValue( 3, 4, anAt[2] );
3527 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
3529 // transform to world-space coordinate system
3530 gp_XYZ aPosition( aProjRef.X(), aProjRef.Y(), aCameraDepth );
3531 aTrsf.Transforms( aPosition );
3533 // compute focal point
3534 double aFocalPoint[3];
3536 aFocalPoint[0] = aPosition.X() - aProj[0] * aCameraDepth;
3537 aFocalPoint[1] = aPosition.Y() - aProj[1] * aCameraDepth;
3538 aFocalPoint[2] = aPosition.Z() - aProj[2] * aCameraDepth;
3540 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3541 aProps.setPosition( aPosition.X(), aPosition.Y(), aPosition.Z() );
3543 Standard_Real aViewScale[2];
3544 aSourceView->Size( aViewScale[0], aViewScale[1] );
3545 aProps.setMappingScale( aViewScale[1] );
3553 This implementation synchronizes OCC view's camera propreties.
3555 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
3557 bool blocked = blockSignals( true );
3559 SUIT_CameraProperties aProps = theView->cameraProperties();
3560 if ( !cameraProperties().isCompatible( aProps ) ) {
3561 // other view, this one is being currently synchronized to, seems has become incompatible
3562 // we have to break synchronization
3567 Handle(V3d_View) aDestView = getViewPort()->getView();
3569 aDestView->SetImmediateUpdate( Standard_False );
3572 double aPosition[3];
3573 double aFocalPoint[3];
3574 double anAxialScale[3];
3576 // get common properties
3577 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3578 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
3579 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3580 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3582 #if OCC_VERSION_LARGE > 0x06070100
3583 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3584 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
3585 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3586 aDestView->Camera()->SetScale( aProps.getMappingScale() );
3588 gp_Dir aProjDir( aPosition[0] - aFocalPoint[0],
3589 aPosition[1] - aFocalPoint[1],
3590 aPosition[2] - aFocalPoint[2] );
3592 // get custom view translation
3593 Standard_Real aTranslation[3];
3594 aDestView->At( aTranslation[0], aTranslation[1], aTranslation[2] );
3596 gp_Dir aLeftDir = gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] )
3597 ^ gp_Dir( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
3600 aTrsf.SetValue( 1, 1, aLeftDir.X() );
3601 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
3602 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
3604 aTrsf.SetValue( 1, 2, anUpDir[0] );
3605 aTrsf.SetValue( 2, 2, anUpDir[1] );
3606 aTrsf.SetValue( 3, 2, anUpDir[2] );
3608 aTrsf.SetValue( 1, 3, aProjDir.X() );
3609 aTrsf.SetValue( 2, 3, aProjDir.Y() );
3610 aTrsf.SetValue( 3, 3, aProjDir.Z() );
3612 aTrsf.SetValue( 1, 4, aTranslation[0] );
3613 aTrsf.SetValue( 2, 4, aTranslation[1] );
3614 aTrsf.SetValue( 3, 4, aTranslation[2] );
3617 // transform to view-space coordinate system
3618 gp_XYZ aProjRef( aPosition[0], aPosition[1], aPosition[2] );
3619 aTrsf.Transforms( aProjRef );
3621 // set view camera properties using low-level approach. this is done
3622 // in order to avoid interference with static variables in v3d view used
3623 // when rotation is in process in another view.
3624 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
3625 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
3627 Graphic3d_Vector aMappingProj( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
3628 Graphic3d_Vector aMappingUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3630 aMappingProj.Normalize();
3631 aMappingUp.Normalize();
3633 anOrientation.SetViewReferencePlane( aMappingProj );
3634 anOrientation.SetViewReferenceUp( aMappingUp );
3636 aDestView->SetViewMapping( aMapping );
3637 aDestView->SetViewOrientation( anOrientation );
3640 aDestView->SetCenter( aProjRef.X(), aProjRef.Y() );
3642 // set mapping scale
3643 double aMapScaling = aProps.getMappingScale();
3644 Standard_Real aWidth, aHeight;
3645 aDestView->Size( aWidth, aHeight );
3646 aDestView->SetSize ( aWidth > aHeight ? aMapScaling * (aWidth / aHeight) : aMapScaling );
3649 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3651 aDestView->ZFitAll();
3652 aDestView->SetImmediateUpdate( Standard_True );
3653 aDestView->Redraw();
3655 blockSignals( blocked );
3659 \brief Indicates whether preselection is enabled
3660 \return true if preselection is enabled
3662 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
3664 return myPreselectionEnabled;
3668 \brief Enables/disables preselection
3669 \param theIsToEnable if true - preselection will be enabled
3671 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
3673 onSwitchPreselection( theIsToEnable );
3677 \brief Indicates whether selection is enabled
3678 \return true if selection is enabled
3680 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3682 return mySelectionEnabled;
3686 \brief Enables/disables selection
3687 \param theIsToEnable if true - selection will be enabled
3689 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3691 onSwitchSelection( theIsToEnable );
3696 \brief called if clipping operation is activated / deactivated.
3698 Enables/disables clipping plane displaying.
3700 \parma on action state
3702 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3704 if(!myModel) return;
3705 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3708 if (!aClippingDlg) {
3709 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3710 myModel->setClippingDlg(aClippingDlg);
3712 if (!aClippingDlg->isVisible())
3713 aClippingDlg->show();
3715 if ( aClippingDlg ) {
3716 aClippingDlg->close();
3717 myModel->setClippingDlg(0);
3721 SUIT_ViewManager* mgr = getViewManager();
3723 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3724 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3725 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3726 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3728 QAction* a = toolMgr()->action( ClippingId );
3730 if(theIsOn != a->isChecked()){
3731 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3732 a->setChecked(theIsOn);
3733 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3740 void OCCViewer_ViewWindow::onRayTracing()
3742 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_RayTracingDlg::getName() ) ) {
3743 QDialog* aDlg = new OCCViewer_RayTracingDlg( this );
3749 void OCCViewer_ViewWindow::onEnvTexture()
3751 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_EnvTextureDlg::getName() ) ) {
3752 QDialog* aDlg = new OCCViewer_EnvTextureDlg( this );
3758 void OCCViewer_ViewWindow::onLightSource()
3760 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_LightSourceDlg::getName() ) ) {
3761 QDialog* aDlg = new OCCViewer_LightSourceDlg( this, myModel );