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>
90 #include <Visual3d_View.hxx>
91 #include <V3d_Plane.hxx>
92 #include <V3d_Light.hxx>
96 #include <gp_GTrsf.hxx>
97 #include <TColgp_Array1OfPnt2d.hxx>
99 #include <Image_PixMap.hxx>
101 #include <Standard_Version.hxx>
103 #include "utilities.h"
105 // // OpenCV includes
107 // #include <highgui.h>
109 static QEvent* l_mbPressEvent = 0;
112 # include <QWindowsStyle>
117 // To avoid conflict between KeyPress from the X.h (define KeyPress 2)
118 // and QEvent::KeyPress (qevent.h)
123 // Enable ray tracing features
124 #define ENABLE_RAY_TRACING
126 const char* imageZoomCursor[] = {
131 "................................",
132 "................................",
133 ".#######........................",
134 "..aaaaaaa.......................",
135 "................................",
136 ".............#####..............",
137 "...........##.aaaa##............",
138 "..........#.aa.....a#...........",
139 ".........#.a.........#..........",
140 ".........#a..........#a.........",
141 "........#.a...........#.........",
142 "........#a............#a........",
143 "........#a............#a........",
144 "........#a............#a........",
145 "........#a............#a........",
146 ".........#...........#.a........",
147 ".........#a..........#a.........",
148 ".........##.........#.a.........",
149 "........#####.....##.a..........",
150 ".......###aaa#####.aa...........",
151 "......###aa...aaaaa.......#.....",
152 ".....###aa................#a....",
153 "....###aa.................#a....",
154 "...###aa...............#######..",
155 "....#aa.................aa#aaaa.",
156 ".....a....................#a....",
157 "..........................#a....",
158 "...........................a....",
159 "................................",
160 "................................",
161 "................................",
162 "................................"};
164 const char* imageRotateCursor[] = {
169 "................................",
170 "................................",
171 "................................",
172 "................................",
173 "........#.......................",
174 ".......#.a......................",
175 "......#######...................",
176 ".......#aaaaa#####..............",
177 "........#..##.a#aa##........##..",
178 ".........a#.aa..#..a#.....##.aa.",
179 ".........#.a.....#...#..##.aa...",
180 ".........#a.......#..###.aa.....",
181 "........#.a.......#a..#aa.......",
182 "........#a.........#..#a........",
183 "........#a.........#a.#a........",
184 "........#a.........#a.#a........",
185 "........#a.........#a.#a........",
186 ".........#.........#a#.a........",
187 "........##a........#a#a.........",
188 "......##.a#.......#.#.a.........",
189 "....##.aa..##.....##.a..........",
190 "..##.aa.....a#####.aa...........",
191 "...aa.........aaa#a.............",
192 "................#.a.............",
193 "...............#.a..............",
194 "..............#.a...............",
195 "...............a................",
196 "................................",
197 "................................",
198 "................................",
199 "................................",
200 "................................"};
202 const char* imageCrossCursor[] = {
207 "................................",
208 "................................",
209 "................................",
210 "................................",
211 "................................",
212 "................................",
213 "................................",
214 "...............#................",
215 "...............#a...............",
216 "...............#a...............",
217 "...............#a...............",
218 "...............#a...............",
219 "...............#a...............",
220 "...............#a...............",
221 "...............#a...............",
222 ".......#################........",
223 "........aaaaaaa#aaaaaaaaa.......",
224 "...............#a...............",
225 "...............#a...............",
226 "...............#a...............",
227 "...............#a...............",
228 "...............#a...............",
229 "...............#a...............",
230 "...............#a...............",
231 "................a...............",
232 "................................",
233 "................................",
234 "................................",
235 "................................",
236 "................................",
237 "................................",
238 "................................"};
243 \param theDesktop main window of application
244 \param theModel OCC 3D viewer
246 OCCViewer_ViewWindow::OCCViewer_ViewWindow( SUIT_Desktop* theDesktop,
247 OCCViewer_Viewer* theModel )
248 : SUIT_ViewWindow( theDesktop )
252 myEnableDrawMode = false;
253 myDrawRectEnabled = true;
255 updateEnabledDrawMode();
257 mySetRotationPointDlg = 0;
260 IsSketcherStyle = false;
267 myInteractionStyle = SUIT_ViewModel::STANDARD;
268 myPreselectionEnabled = true;
269 mySelectionEnabled = true;
271 myCursorIsHand = false;
279 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
282 qDeleteAll( mySketchers );
286 \brief Internal initialization.
288 void OCCViewer_ViewWindow::initLayout()
290 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
291 myViewPort->installEventFilter(this);
292 setCentralWidget(myViewPort);
293 myOperation = NOTHING;
295 myCurrPointType = GRAVITY;
296 myPrevPointType = GRAVITY;
297 mySelectedPoint = gp_Pnt(0.,0.,0.);
298 myRotationPointSelection = false;
300 setTransformRequested ( NOTHING );
301 setTransformInProcess ( false );
318 // Graduated axes dialog
319 QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
320 myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
321 myCubeAxesDlg->initialize();
323 connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
326 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
328 return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
332 \brief Detect viewer operation according the the mouse button pressed
333 and key modifiers used.
334 \param theEvent mouse event
335 \return type of the operation
337 OCCViewer_ViewWindow::OperationType
338 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
340 OperationType aOp = NOTHING;
341 SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
342 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
343 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
345 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
346 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
348 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
349 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
350 (my2dMode == No2dMode))
357 \brief Customize event handling
358 \param watched event receiver object
360 \return \c true if the event processing should be stopped
362 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
364 if ( watched == myViewPort ) {
365 int aType = e->type();
367 case QEvent::MouseButtonPress:
368 vpMousePressEvent((QMouseEvent*) e);
371 case QEvent::MouseButtonRelease:
372 vpMouseReleaseEvent((QMouseEvent*) e);
375 case QEvent::MouseMove:
376 vpMouseMoveEvent((QMouseEvent*) e);
379 case QEvent::MouseButtonDblClick:
380 emit mouseDoubleClicked(this, (QMouseEvent*)e);
385 QWheelEvent* aEvent = (QWheelEvent*) e;
387 if ( aEvent->modifiers().testFlag(Qt::ControlModifier) ) {
388 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
389 if ( isPreselectionEnabled() && ic->HasOpenedContext() ) {
390 if ( aEvent->delta() > 0 ) {
391 ic->HilightNextDetected( myViewPort->getView() );
393 ic->HilightPreviousDetected( myViewPort->getView() );
398 emit vpTransformationStarted ( ZOOMVIEW );
399 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
400 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
403 int x1 = (int)( aEvent->x() + width()*delta/100 );
404 int y1 = (int)( aEvent->y() + height()*delta/100 );
405 myViewPort->zoom( x, y, x1, y1 );
406 myViewPort->getView()->ZFitAll();
407 emit vpTransformationFinished ( ZOOMVIEW );
412 case QEvent::ContextMenu:
414 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
415 if ( aEvent->reason() != QContextMenuEvent::Mouse )
416 emit contextMenuRequested( aEvent );
420 case QEvent::KeyPress:
421 emit keyPressed(this, (QKeyEvent*) e);
428 return SUIT_ViewWindow::eventFilter(watched, e);
432 \brief Enable / disable draw rect (rubber band) mode
434 bool OCCViewer_ViewWindow::enableDrawMode( bool on )
436 bool prev = myDrawRectEnabled;
437 myDrawRectEnabled = on;
438 updateEnabledDrawMode();
443 \brief Update state of enable draw mode state.
445 void OCCViewer_ViewWindow::updateEnabledDrawMode()
447 myEnableDrawMode = myDrawRectEnabled;
449 myEnableDrawMode = myEnableDrawMode && myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
453 \brief Handle mouse press event
454 \param theEvent mouse event
456 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
458 myStartX = theEvent->x();
459 myStartY = theEvent->y();
460 int anInteractionStyle = interactionStyle();
462 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
463 // which are assigned for pan and rotate - these operations are activated immediately after pressing
464 // of the first button, so it is necessary to switch to zoom when the second button is pressed
465 bool aSwitchToZoom = false;
466 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
467 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
468 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
471 switch ( myOperation ) {
473 if ( theEvent->button() == Qt::LeftButton )
474 emit vpTransformationStarted ( WINDOWFIT );
478 if ( theEvent->button() == Qt::LeftButton )
479 emit vpTransformationStarted ( PANGLOBAL );
483 if ( theEvent->button() == Qt::LeftButton ) {
484 myViewPort->startZoomAtPoint( myStartX, myStartY );
485 emit vpTransformationStarted ( ZOOMVIEW );
490 if ( aSwitchToZoom ) {
491 myViewPort->startZoomAtPoint( myStartX, myStartY );
494 else if ( theEvent->button() == Qt::LeftButton )
495 emit vpTransformationStarted ( PANVIEW );
499 if ( aSwitchToZoom ) {
500 myViewPort->startZoomAtPoint( myStartX, myStartY );
503 else if ( theEvent->button() == Qt::LeftButton ) {
504 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
505 emit vpTransformationStarted ( ROTATE );
510 /* Try to activate a transformation */
511 OperationType aState;
512 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
513 aState = getButtonState(theEvent, anInteractionStyle);
515 aState = OCCViewer_ViewWindow::NOTHING;
520 myViewPort->startZoomAtPoint( myStartX, myStartY );
528 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
531 if ( myRotationPointSelection )
533 if ( theEvent->button() == Qt::LeftButton )
535 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
537 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
539 TopoDS_Shape aShape = ic->SelectedShape();
540 GProp_GProps aSystem;
542 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
544 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
546 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE )
548 BRepGProp::LinearProperties( aShape, aSystem );
549 aPnt = aSystem.CentreOfMass();
551 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE )
553 BRepGProp::SurfaceProperties( aShape, aSystem );
554 aPnt = aSystem.CentreOfMass();
556 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID )
558 BRepGProp::VolumeProperties( aShape, aSystem );
559 aPnt = aSystem.CentreOfMass();
563 myCurrPointType = myPrevPointType;
567 if ( mySetRotationPointDlg )
569 myRotationPointSelection = false;
570 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
573 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
574 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
575 ic->CloseAllContexts();
576 myOperation = NOTHING;
577 myViewPort->setCursor( myCursor );
578 myCursorIsHand = false;
579 myRotationPointSelection = false;
583 emit mousePressed(this, theEvent);
586 /* notify that we start a transformation */
587 if ( transformRequested() )
588 emit vpTransformationStarted ( myOperation );
590 if ( transformRequested() )
591 setTransformInProcess( true );
593 /* we may need it for sketching... */
594 if ( l_mbPressEvent )
595 delete l_mbPressEvent;
596 l_mbPressEvent = new QMouseEvent( *theEvent );
601 \brief Start zooming operation.
603 Sets the corresponding cursor for the widget.
605 void OCCViewer_ViewWindow::activateZoom()
607 if ( !transformRequested() && !myCursorIsHand )
608 saveCursor(); /* save old cursor */
610 if ( myOperation != ZOOMVIEW ) {
611 QPixmap zoomPixmap (imageZoomCursor);
612 QCursor zoomCursor (zoomPixmap);
613 if( setTransformRequested ( ZOOMVIEW ) )
614 myViewPort->setCursor( zoomCursor );
620 \brief Start panning operation.
622 Sets the corresponding cursor for the widget.
624 void OCCViewer_ViewWindow::activatePanning()
626 if ( !transformRequested() && !myCursorIsHand )
627 saveCursor(); // save old cursor
629 if ( myOperation != PANVIEW ) {
630 QCursor panCursor (Qt::SizeAllCursor);
631 if( setTransformRequested ( PANVIEW ) )
632 myViewPort->setCursor( panCursor );
637 \brief Start rotation operation
639 Sets the corresponding cursor for the widget.
641 void OCCViewer_ViewWindow::activateRotation()
643 if ( !transformRequested() && !myCursorIsHand )
644 saveCursor(); // save old cursor
646 if ( myOperation != ROTATE ) {
647 QPixmap rotatePixmap (imageRotateCursor);
648 QCursor rotCursor (rotatePixmap);
649 if( setTransformRequested ( ROTATE ) )
650 myViewPort->setCursor( rotCursor );
655 \brief Compute the gravity center.
656 \param theX used to return X coordinate of the gravity center
657 \param theY used to return Y coordinate of the gravity center
658 \param theZ used to return Z coordinate of the gravity center
659 \return \c true if the gravity center is computed
661 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
663 Handle(V3d_View) aView3d = myViewPort->getView();
665 // Project boundaries points and add to avergae gravity
666 // the ones which lie within the screen limits
667 Standard_Real aScreenLimits[4] = { 0.0, 0.0, 0.0, 0.0 };
669 #if OCC_VERSION_LARGE > 0x06070100
670 // NDC space screen limits
671 aScreenLimits[0] = -1.0;
672 aScreenLimits[1] = 1.0;
673 aScreenLimits[2] = -1.0;
674 aScreenLimits[3] = 1.0;
676 aView3d->View()->ViewMapping().WindowLimit( aScreenLimits[0],
682 Standard_Integer aPointsNb = 0;
684 Standard_Real aXmin = 0.0;
685 Standard_Real aYmin = 0.0;
686 Standard_Real aZmin = 0.0;
687 Standard_Real aXmax = 0.0;
688 Standard_Real aYmax = 0.0;
689 Standard_Real aZmax = 0.0;
691 Graphic3d_MapOfStructure aSetOfStructures;
692 aView3d->View()->DisplayedStructures( aSetOfStructures );
693 Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures );
695 for( ; aStructureIt.More(); aStructureIt.Next() ) {
696 const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key();
697 if ( aStructure->IsEmpty() || !aStructure->IsVisible() || aStructure->CStructure()->IsForHighlight )
700 #if OCC_VERSION_LARGE > 0x06070100
701 Bnd_Box aBox = aStructure->MinMaxValues();
702 aXmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().X();
703 aYmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Y();
704 aZmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Z();
705 aXmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().X();
706 aYmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Y();
707 aZmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Z();
709 aStructure->MinMaxValues( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
712 // Infinite structures are skipped
713 Standard_Real aLIM = ShortRealLast() - 1.0;
714 if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
715 || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
719 gp_Pnt aPoints[8] = {
720 gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
721 gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
722 gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
723 gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
726 for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
727 const gp_Pnt& aBBPoint = aPoints[aPointIt];
729 #if OCC_VERSION_LARGE > 0x06070100
730 gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
731 const Standard_Real& U = aProjected.X();
732 const Standard_Real& V = aProjected.Y();
734 Standard_Real U = 0.0;
735 Standard_Real V = 0.0;
736 Standard_Real W = 0.0;
737 aView3d->View()->Projects( aBBPoint.X(), aBBPoint.Y(), aBBPoint.Z(), U, V, W );
740 if (U >= aScreenLimits[0]
741 && U <= aScreenLimits[1]
742 && V >= aScreenLimits[2]
743 && V <= aScreenLimits[3])
746 theX += aBBPoint.X();
747 theY += aBBPoint.Y();
748 theZ += aBBPoint.Z();
763 \brief Set the gravity center as a rotation point.
765 void OCCViewer_ViewWindow::activateSetRotationGravity()
767 if ( myRotationPointSelection )
769 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
770 ic->CloseAllContexts();
771 myOperation = NOTHING;
772 myViewPort->setCursor( myCursor );
773 myCursorIsHand = false;
774 myRotationPointSelection = false;
777 myPrevPointType = myCurrPointType;
778 myCurrPointType = GRAVITY;
780 Standard_Real Xcenter, Ycenter, Zcenter;
781 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
782 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
786 \brief Update gravity center in the "Set Rotation Point" dialog box.
787 \sa OCCViewer_SetRotationPointDlg class
789 void OCCViewer_ViewWindow::updateGravityCoords()
791 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == GRAVITY )
793 Standard_Real Xcenter, Ycenter, Zcenter;
794 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
795 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
800 \brief Set the point selected by the user as a rotation point.
801 \param theX X coordinate of the rotation point
802 \param theY Y coordinate of the rotation point
803 \param theZ Z coordinate of the rotation point
805 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
807 if ( myRotationPointSelection )
809 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
810 ic->CloseAllContexts();
811 myOperation = NOTHING;
812 myViewPort->setCursor( myCursor );
813 myCursorIsHand = false;
814 myRotationPointSelection = false;
817 myPrevPointType = myCurrPointType;
818 myCurrPointType = SELECTED;
819 mySelectedPoint.SetCoord(theX,theY,theZ);
823 \brief Start the shape selection process.
825 void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
827 myPrevPointType = myCurrPointType;
828 myCurrPointType = SELECTED;
830 // activate selection ------>
831 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
833 ic->OpenLocalContext();
835 AIS_ListOfInteractive aList;
836 ic->DisplayedObjects( aList );
837 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
839 Handle(AIS_InteractiveObject) anObj = it.Value();
840 if ( !anObj.IsNull() && anObj->HasPresentation() &&
841 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
844 ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
847 // activate selection <------
849 if ( !myCursorIsHand )
851 QCursor handCursor (Qt::PointingHandCursor);
852 myCursorIsHand = true;
854 myViewPort->setCursor( handCursor );
856 myRotationPointSelection = true;
860 \brief Start global panning operation
862 Sets the corresponding cursor for the widget.
864 void OCCViewer_ViewWindow::activateGlobalPanning()
866 Handle(V3d_View) aView3d = myViewPort->getView();
867 if ( !aView3d.IsNull() ) {
868 QPixmap globalPanPixmap (imageCrossCursor);
869 QCursor glPanCursor (globalPanPixmap);
870 myCurScale = aView3d->Scale();
871 aView3d->FitAll(0.01, false);
872 saveCursor(); // save old cursor
873 myViewPort->fitAll(); // fits view before selecting a new scene center
874 if( setTransformRequested( PANGLOBAL ) )
875 myViewPort->setCursor( glPanCursor );
880 \brief Starts fit operation.
882 Sets the corresponding cursor for the widget.
884 void OCCViewer_ViewWindow::activateWindowFit()
886 if ( !transformRequested() && !myCursorIsHand )
887 saveCursor(); /* save old cursor */
889 if ( myOperation != WINDOWFIT ) {
890 QCursor handCursor (Qt::PointingHandCursor);
891 if( setTransformRequested ( WINDOWFIT ) )
893 myViewPort->setCursor ( handCursor );
894 myCursorIsHand = true;
900 \brief Start delayed viewer operation.
902 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
904 bool ok = transformEnabled( op );
905 myOperation = ok ? op : NOTHING;
906 myViewPort->setMouseTracking( myOperation == NOTHING );
911 \brief Handle mouse move event.
912 \param theEvent mouse event
914 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
916 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
918 switch ( getButtonState( theEvent, interactionStyle() ) ) {
920 myViewPort->startZoomAtPoint( myStartX, myStartY );
928 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
935 myCurrX = theEvent->x();
936 myCurrY = theEvent->y();
937 switch (myOperation) {
939 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
943 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
949 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
963 if ( myRotationPointSelection || isSketcherStyle() )
965 emit mouseMoving( this, theEvent );
969 int aState = theEvent->modifiers();
970 int aButton = theEvent->buttons();
971 int anInteractionStyle = interactionStyle();
972 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
973 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
974 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
975 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
976 myDrawRect = myEnableDrawMode;
979 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
980 QCursor handCursor (Qt::PointingHandCursor);
981 myCursorIsHand = true;
983 myViewPort->setCursor( handCursor );
986 emit mouseMoving( this, theEvent );
988 else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
989 aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
990 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
991 aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
992 OCCViewer_ViewSketcher* sketcher = 0;
993 QList<OCCViewer_ViewSketcher*>::Iterator it;
994 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
996 OCCViewer_ViewSketcher* sk = (*it);
997 if( sk->isDefault() && sk->sketchButton() == aButton )
1000 if ( sketcher && myCurSketch == -1 )
1002 activateSketching( sketcher->type() );
1005 myCurSketch = mypSketcher->sketchButton();
1007 if ( l_mbPressEvent )
1009 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
1010 delete l_mbPressEvent;
1013 QApplication::sendEvent( getViewPort(), theEvent );
1018 emit mouseMoving( this, theEvent );
1024 \brief Handle mouse release event.
1025 \param theEvent mouse event
1027 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
1029 switch ( myOperation ) {
1032 int prevState = myCurSketch;
1033 if(theEvent->button() == Qt::RightButton)
1035 QList<OCCViewer_ViewSketcher*>::Iterator it;
1036 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
1038 OCCViewer_ViewSketcher* sk = (*it);
1039 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
1044 emit mouseReleased(this, theEvent);
1045 if(theEvent->button() == Qt::RightButton && prevState == -1)
1047 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1048 theEvent->pos(), theEvent->globalPos() );
1049 emit contextMenuRequested( &aEvent );
1054 myViewPort->endRotation();
1060 myViewPort->getView()->ZFitAll();
1065 if ( theEvent->button() == Qt::LeftButton ) {
1066 myViewPort->setCenter( theEvent->x(), theEvent->y() );
1067 myViewPort->getView()->SetScale(myCurScale);
1073 if ( theEvent->button() == Qt::LeftButton ) {
1074 myCurrX = theEvent->x();
1075 myCurrY = theEvent->y();
1077 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1078 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1085 // NOTE: viewer 3D detects a rectangle of selection using this event
1086 // so we must emit it BEFORE resetting the selection rectangle
1088 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1092 myViewPort->update();
1095 if ( l_mbPressEvent )
1097 delete l_mbPressEvent;
1103 \brief Reset the viewport to its initial state
1104 ( no transformations in process etc. )
1106 void OCCViewer_ViewWindow::resetState()
1110 if ( myRotationPointSelection )
1112 QCursor handCursor (Qt::PointingHandCursor);
1113 myViewPort->setCursor( handCursor );
1117 if ( transformRequested() || myCursorIsHand )
1118 myViewPort->setCursor( myCursor );
1119 myCursorIsHand = false;
1122 if ( transformRequested() )
1123 emit vpTransformationFinished (myOperation);
1125 setTransformInProcess( false );
1126 setTransformRequested( NOTHING );
1131 \brief Draw rubber band rectangle.
1133 void OCCViewer_ViewWindow::drawRect()
1135 if ( !myRectBand ) {
1136 myRectBand = new QtxRectRubberBand( myViewPort );
1138 //palette.setColor(myRectBand->foregroundRole(), Qt::white);
1139 //myRectBand->setPalette(palette);
1141 //myRectBand->hide();
1143 myRectBand->setUpdatesEnabled ( false );
1144 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1145 myRectBand->initGeometry( aRect );
1147 if ( !myRectBand->isVisible() )
1150 myRectBand->setUpdatesEnabled ( true );
1151 //myRectBand->repaint();
1153 //myRectBand->setVisible( aRect.isValid() );
1154 //if ( myRectBand->isVisible() )
1155 // myRectBand->repaint();
1157 // myRectBand->show();
1158 //myRectBand->repaint();
1162 \brief Clear rubber band rectangle on the end on the dragging operation.
1164 void OCCViewer_ViewWindow::endDrawRect()
1166 //delete myRectBand;
1170 myRectBand->clearGeometry();
1176 \brief Create actions.
1178 void OCCViewer_ViewWindow::createActions()
1180 if( !toolMgr()->isEmpty() )
1183 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1190 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1191 tr( "MNU_DUMP_VIEW" ), 0, this);
1192 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1193 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1194 toolMgr()->registerAction( aAction, DumpId );
1197 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1198 tr( "MNU_FITALL" ), 0, this);
1199 aAction->setStatusTip(tr("DSC_FITALL"));
1200 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1201 toolMgr()->registerAction( aAction, FitAllId );
1204 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1205 tr( "MNU_FITRECT" ), 0, this);
1206 aAction->setStatusTip(tr("DSC_FITRECT"));
1207 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1208 toolMgr()->registerAction( aAction, FitRectId );
1211 aAction = new QtxAction(tr("MNU_FITSELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITSELECTION" ) ),
1212 tr( "MNU_FITSELECTION" ), 0, this);
1213 aAction->setStatusTip(tr("DSC_FITSELECTION"));
1214 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
1215 toolMgr()->registerAction( aAction, FitSelectionId );
1218 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1219 tr( "MNU_ZOOM_VIEW" ), 0, this);
1220 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1221 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1222 toolMgr()->registerAction( aAction, ZoomId );
1225 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1226 tr( "MNU_PAN_VIEW" ), 0, this);
1227 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1228 connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
1229 toolMgr()->registerAction( aAction, PanId );
1232 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1233 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1234 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1235 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1236 toolMgr()->registerAction( aAction, GlobalPanId );
1239 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1240 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1241 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1242 mySetRotationPointAction->setCheckable( true );
1243 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1244 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1247 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1248 tr( "MNU_ROTATE_VIEW" ), 0, this);
1249 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1250 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1251 toolMgr()->registerAction( aAction, RotationId );
1254 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1255 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1256 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1257 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1258 this->addAction(aAction);
1259 toolMgr()->registerAction( aAction, FrontId );
1261 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1262 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1263 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1264 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1265 this->addAction(aAction);
1266 toolMgr()->registerAction( aAction, BackId );
1268 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1269 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1270 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1271 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1272 this->addAction(aAction);
1273 toolMgr()->registerAction( aAction, TopId );
1275 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1276 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1277 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1278 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1279 this->addAction(aAction);
1280 toolMgr()->registerAction( aAction, BottomId );
1282 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1283 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1284 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1285 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1286 this->addAction(aAction);
1287 toolMgr()->registerAction( aAction, LeftId );
1289 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1290 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1291 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1292 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1293 this->addAction(aAction);
1294 toolMgr()->registerAction( aAction, RightId );
1296 // rotate anticlockwise
1297 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1298 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1299 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1300 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1301 this->addAction(aAction);
1302 toolMgr()->registerAction( aAction, AntiClockWiseId );
1305 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1306 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1307 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1308 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1309 this->addAction(aAction);
1310 toolMgr()->registerAction( aAction, ClockWiseId );
1312 // Projection mode group
1314 // - orthographic projection
1315 aAction = new QtxAction(tr("MNU_ORTHOGRAPHIC_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ORTHOGRAPHIC" ) ),
1316 tr( "MNU_ORTHOGRAPHIC_MODE" ), 0, this);
1317 aAction->setStatusTip(tr("DSC_ORTHOGRAPHIC_MODE"));
1318 aAction->setCheckable(true);
1319 toolMgr()->registerAction( aAction, OrthographicId );
1321 // - perspective projection
1322 aAction = new QtxAction(tr("MNU_PERSPECTIVE_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PERSPECTIVE" ) ),
1323 tr( "MNU_PERSPECTIVE_MODE" ), 0, this);
1324 aAction->setStatusTip(tr("DSC_PERSPECTIVE_MODE"));
1325 aAction->setCheckable(true);
1326 toolMgr()->registerAction( aAction, PerspectiveId );
1327 #if OCC_VERSION_LARGE > 0x06090000
1328 // - stereo projection
1329 aAction = new QtxAction(tr("MNU_STEREO_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STEREO" ) ),
1330 tr( "MNU_STEREO_MODE" ), 0, this);
1331 aAction->setStatusTip(tr("DSC_STEREO_MODE"));
1332 aAction->setCheckable(true);
1333 toolMgr()->registerAction( aAction, StereoId );
1334 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onStereoType(bool)));
1336 // - add exclusive action group
1337 QActionGroup* aProjectionGroup = new QActionGroup( this );
1338 aProjectionGroup->addAction( toolMgr()->action( OrthographicId ) );
1339 aProjectionGroup->addAction( toolMgr()->action( PerspectiveId ) );
1340 connect(aProjectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProjectionType(QAction*)));
1343 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1344 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1345 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1346 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1347 this->addAction(aAction);
1348 toolMgr()->registerAction( aAction, ResetId );
1351 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1352 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1353 tr("MNU_CLONE_VIEW"), 0, this);
1354 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1355 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1356 toolMgr()->registerAction( aAction, CloneId );
1358 aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
1359 tr("MNU_CLIPPING"), 0, this);
1360 aAction->setStatusTip (tr("DSC_CLIPPING"));
1361 aAction->setCheckable (true);
1362 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1363 toolMgr()->registerAction (aAction, ClippingId);
1365 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1366 tr( "MNU_SHOOT_VIEW" ), 0, this);
1367 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1368 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1369 toolMgr()->registerAction( aAction, MemId );
1371 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1372 tr( "MNU_PRESETS_VIEW" ), 0, this);
1373 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1374 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1375 toolMgr()->registerAction( aAction, RestoreId );
1377 if (myModel->trihedronActivated()) {
1378 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1379 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1380 aAction->setCheckable( true );
1381 aAction->setChecked( true );
1382 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1383 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1384 toolMgr()->registerAction( aAction, TrihedronShowId );
1388 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1389 tr( "MNU_SCALING" ), 0, this);
1390 aAction->setStatusTip(tr("DSC_SCALING"));
1391 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1392 toolMgr()->registerAction( aAction, AxialScaleId );
1394 // Enable/disable preselection
1395 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1396 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1397 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1398 aAction->setCheckable(true);
1399 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1400 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1402 // Enable/disable selection
1403 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1404 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1405 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1406 aAction->setCheckable(true);
1407 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1408 toolMgr()->registerAction( aAction, SwitchSelectionId );
1411 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1412 tr( "MNU_GRADUATED_AXES" ), 0, this);
1413 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1414 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1415 toolMgr()->registerAction( aAction, GraduatedAxesId );
1417 // Active only ambient light or not
1418 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1419 tr( "MNU_AMBIENT" ), 0, this);
1420 aAction->setStatusTip(tr("DSC_AMBIENT"));
1421 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1422 toolMgr()->registerAction( aAction, AmbientId );
1424 // Switch between interaction styles
1425 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1426 tr( "MNU_STYLE_SWITCH" ), 0, this);
1427 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1428 aAction->setCheckable(true);
1429 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1430 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1432 // Switch between zooming styles
1433 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1434 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1435 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1436 aAction->setCheckable(true);
1437 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1438 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1441 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1442 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1443 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1444 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1445 toolMgr()->registerAction( aAction, MaximizedId );
1447 // Return to 3d view
1448 if (my2dMode!=No2dMode){
1449 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1450 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1451 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1452 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1453 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1457 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1458 #ifdef ENABLE_RAY_TRACING
1460 aAction = new QtxAction( tr("MNU_RAY_TRACING"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_RAY_TRACING") ),
1461 tr("MNU_RAY_TRACING"), 0, this );
1462 aAction->setStatusTip( tr("DSC_RAY_TRACING") );
1463 connect( aAction, SIGNAL( triggered() ), this, SLOT( onRayTracing() ) );
1464 toolMgr()->registerAction( aAction, RayTracingId );
1466 // Environment texture
1467 aAction = new QtxAction( tr("MNU_ENV_TEXTURE"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_ENV_TEXTURE") ),
1468 tr("MNU_ENV_TEXTURE"), 0, this );
1469 aAction->setStatusTip( tr("DSC_ENV_TEXTURE") );
1470 connect( aAction, SIGNAL( triggered() ), this, SLOT( onEnvTexture() ) );
1471 toolMgr()->registerAction( aAction, EnvTextureId );
1474 aAction = new QtxAction( tr("MNU_LIGHT_SOURCE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_LIGHT_SOURCE" ) ),
1475 tr( "MNU_LIGHT_SOURCE" ), 0, this );
1476 aAction->setStatusTip( tr("DSC_LIGHT_SOURCE") );
1477 connect( aAction, SIGNAL( triggered() ), this, SLOT( onLightSource() ) );
1478 toolMgr()->registerAction( aAction, LightSourceId );
1483 \brief Create toolbar.
1485 void OCCViewer_ViewWindow::createToolBar()
1487 static const char* titles[] = {
1488 "LBL_3DTOOLBAR_LABEL",
1489 "LBL_XYTOOLBAR_LABEL",
1490 "LBL_XZTOOLBAR_LABEL",
1491 "LBL_YZTOOLBAR_LABEL",
1493 static const char* names[] = {
1494 "OCCViewer3DViewOperations",
1495 "OCCViewerXYViewOperations",
1496 "OCCViewerXZViewOperations",
1497 "OCCViewerYZViewOperations",
1499 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1500 QString( names[my2dMode] ), // name (language-independant)
1501 false ); // disable floatable toolbar
1502 if ( my2dMode != No2dMode ){
1503 toolMgr()->append( ReturnTo3dViewId, tid );
1504 toolMgr()->append( toolMgr()->separator(), tid );
1506 toolMgr()->append( DumpId, tid );
1507 toolMgr()->append( SwitchInteractionStyleId, tid );
1508 toolMgr()->append( SwitchZoomingStyleId, tid );
1509 toolMgr()->append( SwitchPreselectionId, tid );
1510 toolMgr()->append( SwitchSelectionId, tid );
1511 if( myModel->trihedronActivated() )
1512 toolMgr()->append( TrihedronShowId, tid );
1514 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1515 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1516 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1517 #if OCC_VERSION_LARGE > 0x06090000
1518 aScaleAction->insertAction( toolMgr()->action( FitSelectionId ) );
1520 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1521 toolMgr()->append( aScaleAction, tid );
1523 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1524 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1525 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1526 toolMgr()->append( aPanningAction, tid );
1528 if (my2dMode == No2dMode) {
1529 toolMgr()->append( ChangeRotationPointId, tid );
1530 toolMgr()->append( RotationId, tid );
1532 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1533 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1534 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1535 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1536 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1537 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1538 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1539 toolMgr()->append( aViewsAction, tid );
1541 toolMgr()->append( AntiClockWiseId, tid );
1542 toolMgr()->append( ClockWiseId, tid );
1544 toolMgr()->append( OrthographicId, tid );
1545 toolMgr()->append( PerspectiveId, tid );
1546 #if OCC_VERSION_LARGE > 0x06090000
1547 toolMgr()->append( StereoId, tid );
1550 toolMgr()->append( ResetId, tid );
1553 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1554 aMemAction->insertAction( toolMgr()->action( MemId ) );
1555 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1556 toolMgr()->append( aMemAction, tid );
1558 toolMgr()->append( toolMgr()->separator(), tid );
1559 toolMgr()->append( CloneId, tid );
1561 toolMgr()->append( toolMgr()->separator(), tid );
1562 toolMgr()->append( ClippingId, tid );
1563 toolMgr()->append( AxialScaleId, tid );
1564 toolMgr()->append( GraduatedAxesId, tid );
1565 toolMgr()->append( AmbientId, tid );
1567 toolMgr()->append( MaximizedId, tid );
1568 toolMgr()->append( SynchronizeId, tid );
1569 #ifdef ENABLE_RAY_TRACING
1570 toolMgr()->append( RayTracingId, tid );
1571 toolMgr()->append( EnvTextureId, tid );
1572 toolMgr()->append( LightSourceId, tid );
1577 \brief Perform 'fit all' operation.
1579 void OCCViewer_ViewWindow::onViewFitAll()
1581 myViewPort->fitAll();
1585 \brief Perform "front view" transformation.
1587 void OCCViewer_ViewWindow::onFrontView()
1589 emit vpTransformationStarted ( FRONTVIEW );
1590 Handle(V3d_View) aView3d = myViewPort->getView();
1591 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
1593 emit vpTransformationFinished ( FRONTVIEW );
1597 \brief Perform "back view" transformation.
1599 void OCCViewer_ViewWindow::onBackView()
1601 emit vpTransformationStarted ( BACKVIEW );
1602 Handle(V3d_View) aView3d = myViewPort->getView();
1603 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
1605 emit vpTransformationFinished ( BACKVIEW );
1609 \brief Perform "top view" transformation.
1611 void OCCViewer_ViewWindow::onTopView()
1613 emit vpTransformationStarted ( TOPVIEW );
1614 Handle(V3d_View) aView3d = myViewPort->getView();
1615 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
1617 emit vpTransformationFinished ( TOPVIEW );
1621 \brief Perform "bottom view" transformation.
1623 void OCCViewer_ViewWindow::onBottomView()
1625 emit vpTransformationStarted ( BOTTOMVIEW );
1626 Handle(V3d_View) aView3d = myViewPort->getView();
1627 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
1629 emit vpTransformationFinished ( BOTTOMVIEW );
1633 \brief Perform "left view" transformation.
1635 void OCCViewer_ViewWindow::onLeftView()
1637 emit vpTransformationStarted ( LEFTVIEW );
1638 Handle(V3d_View) aView3d = myViewPort->getView();
1639 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
1641 emit vpTransformationFinished ( LEFTVIEW );
1645 \brief Perform "right view" transformation.
1647 void OCCViewer_ViewWindow::onRightView()
1649 emit vpTransformationStarted ( RIGHTVIEW );
1650 Handle(V3d_View) aView3d = myViewPort->getView();
1651 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
1653 emit vpTransformationFinished ( RIGHTVIEW );
1657 \brief Rotate view 90 degrees clockwise
1659 void OCCViewer_ViewWindow::onClockWiseView()
1661 emit vpTransformationStarted ( CLOCKWISEVIEW );
1662 myViewPort->rotateXY( 90. );
1663 emit vpTransformationFinished ( CLOCKWISEVIEW );
1667 \brief Rotate view 90 degrees conterclockwise
1669 void OCCViewer_ViewWindow::onAntiClockWiseView()
1671 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1672 myViewPort->rotateXY( -90. );
1673 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1677 \brief Perform "reset view" transformation.
1679 Sets default orientation of the viewport camera.
1681 void OCCViewer_ViewWindow::onResetView()
1683 emit vpTransformationStarted( RESETVIEW );
1684 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1685 myViewPort->getView()->Reset( false );
1686 myViewPort->fitAll( false, true, false );
1687 myViewPort->getView()->SetImmediateUpdate( upd );
1688 onProjectionType(); // needed to apply projection type properly after reset
1689 myViewPort->getView()->Update();
1690 emit vpTransformationFinished( RESETVIEW );
1694 \brief Set the given projection mode.
1696 Set the given projection mode: Orthographic or Perspective.
1698 void OCCViewer_ViewWindow::onProjectionType( QAction* theAction )
1700 Handle(V3d_View) aView3d = myViewPort->getView();
1701 if ( !aView3d.IsNull() ) {
1702 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1703 if (theAction == toolMgr()->action( OrthographicId )) {
1704 myModel->setProjectionType(Orthographic);
1705 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Orthographic );
1706 aCamera->SetFOVy(45.0);
1708 else if (theAction == toolMgr()->action( PerspectiveId )) {
1709 myModel->setProjectionType(Perspective);
1710 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Perspective );
1711 aCamera->SetFOVy(30.0);
1713 #if OCC_VERSION_LARGE > 0x06090000
1714 if (toolMgr()->action( StereoId )->isChecked()) {
1715 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1716 aCamera->SetFOVy(30.0);
1725 \brief Sets Stereo projection mode.
1727 Sets Stereo projection mode.
1729 void OCCViewer_ViewWindow::onStereoType( bool activate )
1731 #if OCC_VERSION_LARGE > 0x06090000
1732 Handle(V3d_View) aView3d = myViewPort->getView();
1733 if ( !aView3d.IsNull() ) {
1734 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1736 toolMgr()->action( PerspectiveId )->setChecked(true);
1737 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1738 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(false);
1740 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1741 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1742 setStereoType( aResMgr->integerValue( "OCCViewer", "stereo_type", 0 ) );
1743 setAnaglyphFilter( aResMgr->integerValue( "OCCViewer", "anaglyph_filter", 0 ) );
1744 setReverseStereo( aResMgr->booleanValue( "OCCViewer", "reverse_stereo", false ) );
1745 setVSync( aResMgr->booleanValue( "OCCViewer", "enable_vsync", true ) );
1746 setQuadBufferSupport( aResMgr->booleanValue( "OCCViewer", "enable_quad_buffer_support", false ) );
1749 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(true);
1750 if (myModel->projectionType() == Orthographic) {
1751 toolMgr()->action( OrthographicId )->setChecked(true);
1752 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Orthographic);
1754 else if (myModel->projectionType() == Perspective) {
1755 toolMgr()->action( PerspectiveId )->setChecked(true);
1756 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1763 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1764 toolMgr()->action( StereoId )->isChecked() )
1765 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1770 \brief Restore the view.
1772 Restore the projection mode based on tool-buttons states.
1774 void OCCViewer_ViewWindow::onProjectionType()
1776 emit vpTransformationStarted( PROJECTION );
1777 if (toolMgr()->action( OrthographicId )->isChecked())
1778 setProjectionType( Orthographic );
1779 if (toolMgr()->action( PerspectiveId )->isChecked())
1780 setProjectionType( Perspective );
1781 #if OCC_VERSION_LARGE > 0x06090000
1782 if (toolMgr()->action( StereoId )->isChecked())
1783 setProjectionType( Stereo );
1785 emit vpTransformationFinished( PROJECTION );
1788 void OCCViewer_ViewWindow::setProjectionType( int mode )
1790 QtxAction* anOrthographicAction = dynamic_cast<QtxAction*>( toolMgr()->action( OrthographicId ) );
1791 QtxAction* aPerspectiveAction = dynamic_cast<QtxAction*>( toolMgr()->action( PerspectiveId ) );
1792 #if OCC_VERSION_LARGE > 0x06090000
1793 QtxAction* aStereoAction = dynamic_cast<QtxAction*>( toolMgr()->action( StereoId ) );
1797 onProjectionType( anOrthographicAction );
1800 onProjectionType( aPerspectiveAction );
1803 onStereoType( true );
1806 // update action state if method is called outside
1807 if ( mode == Orthographic && !anOrthographicAction->isChecked() ) {
1808 anOrthographicAction->setChecked( true );
1809 #if OCC_VERSION_LARGE > 0x06090000
1810 aStereoAction->setChecked( false );
1813 if ( mode == Perspective && !aPerspectiveAction->isChecked() ) {
1814 aPerspectiveAction->setChecked( true );
1815 #if OCC_VERSION_LARGE > 0x06090000
1816 aStereoAction->setChecked( false );
1819 #if OCC_VERSION_LARGE > 0x06090000
1820 if ( mode == Stereo ) {
1821 aStereoAction->setChecked( true );
1822 if ( anOrthographicAction->isEnabled() ) {
1823 anOrthographicAction->setEnabled( false );
1824 anOrthographicAction->setChecked( false );
1825 aStereoAction->setChecked( false );
1828 anOrthographicAction->setEnabled( true );
1829 aStereoAction->setChecked( false );
1830 anOrthographicAction->setChecked(myModel->projectionType() == Orthographic);
1832 if ( aPerspectiveAction->isEnabled() ) {
1833 aPerspectiveAction->setEnabled( false );
1834 aPerspectiveAction->setChecked( true );
1835 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1836 toolMgr()->action( StereoId )->isChecked() )
1837 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1840 aPerspectiveAction->setEnabled( true );
1841 aStereoAction->setChecked( false );
1842 aPerspectiveAction->setChecked(myModel->projectionType() == Perspective);
1847 if ( !anOrthographicAction->isEnabled() )
1848 anOrthographicAction->setEnabled( true );
1849 if ( !aPerspectiveAction->isEnabled() )
1850 aPerspectiveAction->setEnabled( true );
1856 \brief Perform "fit all" transformation.
1858 void OCCViewer_ViewWindow::onFitAll()
1860 emit vpTransformationStarted( FITALLVIEW );
1861 myViewPort->fitAll();
1862 emit vpTransformationFinished( FITALLVIEW );
1866 \brief Perform "fit selection" transformation.
1868 void OCCViewer_ViewWindow::onFitSelection()
1870 emit vpTransformationStarted( FITSELECTION );
1871 #if OCC_VERSION_LARGE > 0x06090000
1872 myModel->getAISContext()->FitSelected( getViewPort()->getView() );
1874 emit vpTransformationFinished( FITSELECTION );
1878 \brief Called if 'change rotation point' operation is activated.
1879 \param on action state
1881 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1885 if (!mySetRotationPointDlg)
1887 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1888 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1891 if (!mySetRotationPointDlg->isVisible())
1893 //if (mySetRotationPointDlg->IsFirstShown())
1894 if (myCurrPointType == GRAVITY)
1896 Standard_Real Xcenter, Ycenter, Zcenter;
1897 if (computeGravityCenter(Xcenter, Ycenter, Zcenter))
1898 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1900 mySetRotationPointDlg->show();
1905 if (mySetRotationPointDlg->isVisible())
1906 mySetRotationPointDlg->hide();
1911 \brief Create one more window with same content.
1913 void OCCViewer_ViewWindow::onCloneView()
1915 SUIT_ViewWindow* vw = myManager->createViewWindow();
1917 emit viewCloned( vw );
1921 Creates one more window with same content
1923 void OCCViewer_ViewWindow::onAxialScale()
1925 if ( !myScalingDlg )
1926 myScalingDlg = new OCCViewer_AxialScaleDlg( this );
1928 if ( !myScalingDlg->isVisible() )
1930 myScalingDlg->Update();
1931 myScalingDlg->show();
1936 Shows Graduated Axes dialog
1938 void OCCViewer_ViewWindow::onGraduatedAxes()
1940 myCubeAxesDlg->Update();
1941 myCubeAxesDlg->show();
1944 void OCCViewer_ViewWindow::onAmbientToogle()
1946 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
1947 viewer->InitDefinedLights();
1948 while(viewer->MoreDefinedLights())
1950 Handle(V3d_Light) light = viewer->DefinedLight();
1951 if(light->Type() != V3d_AMBIENT)
1953 Handle(V3d_View) aView3d = myViewPort->getView();
1954 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
1955 else viewer->SetLightOn(light);
1957 viewer->NextDefinedLights();
1963 \brief Store view parameters.
1965 void OCCViewer_ViewWindow::onMemorizeView()
1967 appendViewAspect( getViewParams() );
1971 \brief Restore view parameters.
1973 void OCCViewer_ViewWindow::onRestoreView()
1975 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
1976 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
1978 updateViewAspects( aDlg->parameters() );
1979 if( myRestoreFlag && aDlg->parameters().count() )
1980 performRestoring( aDlg->currentItem() );
1984 \brief Restore view parameters.
1985 \param anItem view parameters
1987 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
1989 Handle(V3d_View) aView3d = myViewPort->getView();
1991 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
1992 aView3d->SetScale( anItem.scale );
1993 aView3d->SetTwist( anItem.twist );
1994 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
1995 aView3d->SetImmediateUpdate( prev );
1996 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1997 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1998 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
2000 #if OCC_VERSION_LARGE > 0x06070100
2001 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
2003 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
2005 // "eye" and "at" require conversion to represent center panning
2006 // up direction is only available after setting angle of twist and
2007 // other view parameters
2008 aView3d->Up( anUpX, anUpY, anUpZ );
2010 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
2011 gp_Dir anUp( anUpX, anUpY, anUpZ );
2012 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
2013 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2014 gp_Dir aSide = aProj ^ anUp;
2016 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
2017 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
2019 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
2020 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2023 aView3d->SetCenter( anItem.centerX, anItem.centerY );
2026 if ( !baseParamsOnly ) {
2028 myModel->setTrihedronShown( anItem.isVisible );
2029 myModel->setTrihedronSize( anItem.size );
2031 // graduated trihedron
2032 bool anIsVisible = anItem.gtIsVisible;
2033 OCCViewer_AxisWidget::AxisData anAxisData[3];
2034 anAxisData[0].DrawName = anItem.gtDrawNameX;
2035 anAxisData[1].DrawName = anItem.gtDrawNameZ;
2036 anAxisData[2].DrawName = anItem.gtDrawNameZ;
2037 anAxisData[0].Name = anItem.gtNameX;
2038 anAxisData[1].Name = anItem.gtNameZ;
2039 anAxisData[2].Name = anItem.gtNameZ;
2040 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
2041 anItem.gtNameColorGX,
2042 anItem.gtNameColorBX );
2043 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
2044 anItem.gtNameColorGY,
2045 anItem.gtNameColorBY );
2046 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
2047 anItem.gtNameColorGZ,
2048 anItem.gtNameColorBZ );
2049 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
2050 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
2051 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
2052 anAxisData[0].NbValues = anItem.gtNbValuesX;
2053 anAxisData[1].NbValues = anItem.gtNbValuesY;
2054 anAxisData[2].NbValues = anItem.gtNbValuesZ;
2055 anAxisData[0].Offset = anItem.gtOffsetX;
2056 anAxisData[1].Offset = anItem.gtOffsetY;
2057 anAxisData[2].Offset = anItem.gtOffsetZ;
2058 anAxisData[0].Color = QColor( anItem.gtColorRX,
2061 anAxisData[1].Color = QColor( anItem.gtColorRY,
2064 anAxisData[2].Color = QColor( anItem.gtColorRZ,
2067 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
2068 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
2069 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
2070 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
2071 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
2072 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
2074 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
2075 myCubeAxesDlg->ApplyData( aView3d );
2077 } // if ( !baseParamsOnly )
2083 \brief Set restore flag.
2085 void OCCViewer_ViewWindow::setRestoreFlag()
2091 \brief Called when action "show/hide trihedron" is activated.
2093 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
2095 myModel->setTrihedronShown(show);
2099 \brief Toggles preselection (highlighting) on/off
2101 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
2103 myPreselectionEnabled = on;
2104 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
2106 // unhighlight all highlighted objects
2108 myModel->unHighlightAll( true, false );
2111 // update action state if method is called outside
2112 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2113 if ( a && a->isChecked() != on ) {
2114 a->setChecked( on );
2119 \brief Toggles selection on/off
2121 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
2123 mySelectionEnabled = on;
2124 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
2126 // update action state if method is called outside
2129 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2131 a->setEnabled( on );
2135 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
2136 if ( a && a->isChecked() != on ) {
2137 a->setChecked( on );
2142 \brief Switches "keyboard free" interaction style on/off
2144 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
2146 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
2148 // update action state if method is called outside
2149 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
2150 if ( a && a->isChecked() != on )
2151 a->setChecked( on );
2155 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
2157 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
2159 myViewPort->setAdvancedZoomingEnabled( on );
2161 // update action state if method is called outside
2162 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
2163 if ( a && a->isChecked() != on )
2164 a->setChecked( on );
2168 \brief Get current interaction style
2169 \return interaction style
2171 int OCCViewer_ViewWindow::interactionStyle() const
2173 return myInteractionStyle;
2177 \brief Set current interaction style
2178 \param theStyle interaction style
2180 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
2182 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
2186 \brief Get current zooming style
2187 \return zooming style
2189 int OCCViewer_ViewWindow::zoomingStyle() const
2191 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
2195 \brief Set current zooming style
2196 \param theStyle zooming style
2198 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
2200 onSwitchZoomingStyle( theStyle == 1 );
2204 \brief Dump view window contents to the pixmap.
2205 \return pixmap containing all scene rendered in the window
2207 QImage OCCViewer_ViewWindow::dumpView()
2209 Handle(V3d_View) view = myViewPort->getView();
2210 if ( view.IsNull() )
2213 int aWidth = myViewPort->width();
2214 int aHeight = myViewPort->height();
2216 // rnv: An old approach to dump the OCCViewer content
2217 // Now used OCCT built-in procedure.
2219 QApplication::syncX();
2220 view->Redraw(); // In order to reactivate GL context
2223 #ifndef DISABLE_GLVIEWER
2224 OpenGLUtils_FrameBuffer aFrameBuffer;
2225 if( aFrameBuffer.init( aWidth, aHeight ) )
2227 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
2229 glPushAttrib( GL_VIEWPORT_BIT );
2230 glViewport( 0, 0, aWidth, aHeight );
2231 aFrameBuffer.bind();
2236 aFrameBuffer.unbind();
2239 aFrameBuffer.bind();
2240 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
2241 aFrameBuffer.unbind();
2243 anImage = anImage.rgbSwapped();
2244 anImage = anImage.mirrored();
2247 // if frame buffers are unsupported, use old functionality
2250 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
2252 QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
2254 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
2260 view->ToPixMap(aPix,aWidth, aHeight,Graphic3d_BT_RGBA);
2262 QImage anImage( aPix.Data(), aWidth, aHeight, QImage::Format_ARGB32 );
2263 anImage = anImage.mirrored();
2267 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
2268 const QString& fileName,
2269 const QString& format )
2272 QApplication::setOverrideCursor( Qt::WaitCursor );
2273 if ( format != "PS" && format != "EPS")
2274 res = myViewPort->getView()->Dump( fileName.toStdString().c_str() );
2276 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
2279 res = a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
2280 else if (format == "EPS")
2281 res = a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
2283 QApplication::restoreOverrideCursor();
2288 QString OCCViewer_ViewWindow::filter() const
2290 return tr( "OCC_IMAGE_FILES" );
2295 \brief Set parameters of the cutting plane
2296 \param on if \c true, cutting plane is enabled
2297 \param x X position of plane point
2298 \param y Y position of plane point
2299 \param z Z position of plane point
2300 \param dx X coordinate of plane normal
2301 \param dy Y coordinate of plane normal
2302 \param dz Z coordinate of plane normal
2304 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2305 const double dx, const double dy, const double dz )
2307 Handle(V3d_View) view = myViewPort->getView();
2308 if ( view.IsNull() )
2312 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2314 // try to use already existing plane or create a new one
2315 Handle(V3d_Plane) clipPlane;
2317 // calculate new a,b,c,d values for the plane
2318 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2320 pln.Coefficients(a, b, c, d);
2322 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2323 if(aPlanes.Size() > 0 ) {
2324 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2325 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2326 aClipPlane->SetEquation(pln);
2327 aClipPlane->SetOn(Standard_True);
2329 view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2333 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2334 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2335 for( ;anIter.More();anIter.Next() ){
2336 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2337 aClipPlane->SetOn(Standard_False);
2345 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2347 gp_Dir aDir = pln.Axis().Direction();
2348 gp_Pnt aPnt = pln.Location();
2349 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2354 \brief Check if any cutting plane is enabled
2355 \return \c true if at least one cutting plane is enabled
2357 bool OCCViewer_ViewWindow::isCuttingPlane()
2359 Handle(V3d_View) view = myViewPort->getView();
2361 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2362 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2363 for( ;anIter.More();anIter.Next() ) {
2364 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2365 if(aClipPlane->IsOn()) {
2374 \brief Get the visual parameters of the view window.
2375 \return visual parameters of view window
2377 viewAspect OCCViewer_ViewWindow::getViewParams() const
2379 double projX, projY, projZ, twist;
2380 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2381 double aScaleX, aScaleY, aScaleZ;
2383 Handle(V3d_View) aView3d = myViewPort->getView();
2385 aView3d->Proj( projX, projY, projZ );
2386 aView3d->At( atX, atY, atZ );
2387 aView3d->Eye( eyeX, eyeY, eyeZ );
2388 twist = aView3d->Twist();
2390 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2392 bool isShown = myModel->isTrihedronVisible();
2393 double size = myModel->trihedronSize();
2395 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2398 params.scale = aView3d->Scale();
2399 params.projX = projX;
2400 params.projY = projY;
2401 params.projZ = projZ;
2402 params.twist = twist;
2409 params.scaleX = aScaleX;
2410 params.scaleY = aScaleY;
2411 params.scaleZ = aScaleZ;
2412 params.name = aName;
2413 params.isVisible= isShown;
2416 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2417 aView3d->Center( params.centerX, params.centerY );
2420 // graduated trihedron
2421 bool anIsVisible = false;
2422 OCCViewer_AxisWidget::AxisData anAxisData[3];
2423 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2425 params.gtIsVisible = anIsVisible;
2426 params.gtDrawNameX = anAxisData[0].DrawName;
2427 params.gtDrawNameY = anAxisData[1].DrawName;
2428 params.gtDrawNameZ = anAxisData[2].DrawName;
2429 params.gtNameX = anAxisData[0].Name;
2430 params.gtNameY = anAxisData[1].Name;
2431 params.gtNameZ = anAxisData[2].Name;
2432 params.gtNameColorRX = anAxisData[0].NameColor.red();
2433 params.gtNameColorGX = anAxisData[0].NameColor.green();
2434 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2435 params.gtNameColorRY = anAxisData[1].NameColor.red();
2436 params.gtNameColorGY = anAxisData[1].NameColor.green();
2437 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2438 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2439 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2440 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2441 params.gtDrawValuesX = anAxisData[0].DrawValues;
2442 params.gtDrawValuesY = anAxisData[1].DrawValues;
2443 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2444 params.gtNbValuesX = anAxisData[0].NbValues;
2445 params.gtNbValuesY = anAxisData[1].NbValues;
2446 params.gtNbValuesZ = anAxisData[2].NbValues;
2447 params.gtOffsetX = anAxisData[0].Offset;
2448 params.gtOffsetY = anAxisData[1].Offset;
2449 params.gtOffsetZ = anAxisData[2].Offset;
2450 params.gtColorRX = anAxisData[0].Color.red();
2451 params.gtColorGX = anAxisData[0].Color.green();
2452 params.gtColorBX = anAxisData[0].Color.blue();
2453 params.gtColorRY = anAxisData[1].Color.red();
2454 params.gtColorGY = anAxisData[1].Color.green();
2455 params.gtColorBY = anAxisData[1].Color.blue();
2456 params.gtColorRZ = anAxisData[2].Color.red();
2457 params.gtColorGZ = anAxisData[2].Color.green();
2458 params.gtColorBZ = anAxisData[2].Color.blue();
2459 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2460 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2461 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2462 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2463 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2464 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2470 \brief Get visual parameters of this view window.
2471 \return visual parameters of view window
2473 QString OCCViewer_ViewWindow::getVisualParameters()
2475 viewAspect params = getViewParams();
2479 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2480 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2481 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
2482 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
2484 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2485 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2486 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2487 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2488 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2489 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2490 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2491 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2492 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2493 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2494 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2495 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2496 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2497 data << QString( "isVisible=%1" ).arg( params.isVisible );
2498 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2500 ClipPlanesList aPlanes = myModel->getClipPlanes();
2501 for ( int i=0; i < aPlanes.size(); i++ )
2503 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2504 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2505 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2506 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2507 switch ( aPlane.Mode )
2509 case OCCViewer_ClipPlane::Absolute :
2511 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2513 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2515 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2516 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2517 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2521 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2526 case OCCViewer_ClipPlane::Relative :
2528 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2529 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2530 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2535 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2536 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2537 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2538 data << ClippingPlane;
2541 // graduated trihedron
2542 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2543 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2544 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2545 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2546 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2547 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2548 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2549 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2550 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2551 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2552 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2553 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2554 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2555 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2556 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2557 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2558 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2559 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2560 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2561 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2562 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2563 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2564 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2565 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2566 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2567 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2568 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2569 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2570 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2571 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2572 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2573 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2574 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2575 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2576 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2577 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2578 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2579 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2580 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2581 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2583 // ray tracing parameters
2584 Graphic3d_RenderingParams rendParams = this->getViewPort()->getView()->RenderingParams();
2585 if ( rendParams.Method == Graphic3d_RM_RAYTRACING ) {
2586 QString RayTracing = "rayTracing=";
2587 RayTracing += QString( "rtDepth~%1;" ).arg( rendParams.RaytracingDepth );
2588 RayTracing += QString( "rtReflection~%1;" ).arg( rendParams.IsReflectionEnabled );
2589 RayTracing += QString( "rtAntialiasing~%1;" ).arg( rendParams.IsAntialiasingEnabled );
2590 RayTracing += QString( "rtShadow~%1;" ).arg( rendParams.IsShadowEnabled );
2591 RayTracing += QString( "rtTransShadow~%1;" ).arg( rendParams.IsTransparentShadowEnabled );
2595 // environment texture parameters
2596 Handle(Graphic3d_TextureEnv) aTexture = this->getViewPort()->getView()->TextureEnv();
2597 if ( !aTexture.IsNull() ) {
2598 QString EnvTexture = "envTexture=";
2599 if ( aTexture->Name() == Graphic3d_NOT_ENV_UNKNOWN ) {
2600 TCollection_AsciiString aFileName;
2601 aTexture->Path().SystemName( aFileName );
2602 EnvTexture += QString( "etFile~%1;" ).arg( aFileName.ToCString() );
2605 EnvTexture += QString( "etNumber~%1;" ).arg( aTexture->Name() );
2609 // light source parameters
2610 myModel->getViewer3d()->InitDefinedLights();
2611 while ( myModel->getViewer3d()->MoreDefinedLights() )
2613 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2614 if ( aLight->Type() != V3d_AMBIENT ) {
2615 QString LightSource = QString( "lightSource=" );
2616 LightSource += QString( "lightType~%1;" ).arg( aLight->Type() );
2618 if ( aLight->Type() == V3d_DIRECTIONAL )
2619 Handle(V3d_DirectionalLight)::DownCast( aLight )->Direction( aX, aY, aZ );
2620 else if ( aLight->Type() == V3d_POSITIONAL )
2621 Handle(V3d_PositionalLight)::DownCast( aLight )->Position( aX, aY, aZ );
2622 LightSource += QString( "lightX~%1;" ).arg( aX );
2623 LightSource += QString( "lightY~%1;" ).arg( aY );
2624 LightSource += QString( "lightZ~%1;" ).arg( aZ );
2625 LightSource += QString( "lightColorR~%1;" ).arg( aLight->Color().Red() );
2626 LightSource += QString( "lightColorG~%1;" ).arg( aLight->Color().Green() );
2627 LightSource += QString( "lightColorB~%1;" ).arg( aLight->Color().Blue() );
2628 LightSource += QString( "lightHeadlight~%1;" ).arg( aLight->Headlight() );
2629 data << LightSource;
2631 myModel->getViewer3d()->NextDefinedLights();
2634 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2635 data << QString( "background=%1" ).arg( bg );
2637 return data.join("*");
2641 \brief Restore visual parameters of the view window.
2642 \param parameters visual parameters of view window
2644 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2647 ClipPlanesList aClipPlanes;
2648 QStringList data = parameters.split( '*' );
2649 Qtx::BackgroundData bgData;
2650 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2652 foreach( QString param, data ) {
2653 QString paramName = param.section( '=', 0, 0 ).trimmed();
2654 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2655 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2656 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2657 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2658 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2659 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2660 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2661 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2662 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2663 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2664 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2665 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2666 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2667 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2668 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2669 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2670 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2671 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2672 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2673 else if ( paramName.contains( "ClippingPlane" ) )
2675 QStringList ClipPlaneData = paramValue.split( ';' );
2676 OCCViewer_ClipPlane aPlane;
2677 foreach( QString ClipPlaneParam, ClipPlaneData )
2679 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2680 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2681 if ( ClipPlane_paramName == "Mode" )
2683 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2685 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2686 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2687 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2688 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2691 switch ( aPlane.Mode )
2693 case OCCViewer_ClipPlane::Absolute :
2694 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2695 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2696 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2697 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2698 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2701 case OCCViewer_ClipPlane::Relative :
2702 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2703 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2704 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2709 aClipPlanes.push_back(aPlane);
2711 // graduated trihedron
2712 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2713 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2714 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2715 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2716 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2717 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2718 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2719 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2720 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2721 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2722 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2723 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2724 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2725 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2726 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2727 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2728 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2729 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2730 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2731 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2732 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2733 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2734 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2735 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2736 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2737 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2738 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2739 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2740 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2741 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2742 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2743 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2744 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2745 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2746 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2747 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2748 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2749 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2750 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2751 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2752 else if ( paramName == "rayTracing" )
2754 Graphic3d_RenderingParams& rendParams = this->getViewPort()->getView()->ChangeRenderingParams();
2755 rendParams.Method = Graphic3d_RM_RAYTRACING;
2756 QStringList rtData = paramValue.split( ';' );
2757 foreach( QString rtParam, rtData )
2759 QString rt_paramName = rtParam.section( '~', 0, 0 ).trimmed();
2760 QString rt_paramValue = rtParam.section( '~', 1, 1 ).trimmed();
2761 if ( rt_paramName == "rtDepth" ) rendParams.RaytracingDepth = rt_paramValue.toInt();
2762 else if ( rt_paramName == "rtReflection" ) rendParams.IsReflectionEnabled = rt_paramValue.toInt();
2763 else if ( rt_paramName == "rtAntialiasing" ) rendParams.IsAntialiasingEnabled = rt_paramValue.toInt();
2764 else if ( rt_paramName == "rtShadow" ) rendParams.IsShadowEnabled = rt_paramValue.toInt();
2765 else if ( rt_paramName == "rtTransShadow" ) rendParams.IsTransparentShadowEnabled = rt_paramValue.toInt();
2768 else if ( paramName == "envTexture" )
2770 Handle(Graphic3d_TextureEnv) aTexture;
2771 QStringList etData = paramValue.split( ';' );
2772 foreach( QString etParam, etData )
2774 QString et_paramName = etParam.section( '~', 0, 0 ).trimmed();
2775 QString et_paramValue = etParam.section( '~', 1, 1 ).trimmed();
2776 if ( et_paramName == "etNumber" )
2777 aTexture = new Graphic3d_TextureEnv( Graphic3d_NameOfTextureEnv( et_paramValue.toInt() ) );
2778 else if ( et_paramName == "etFile" )
2779 aTexture = new Graphic3d_TextureEnv( TCollection_AsciiString( et_paramValue.toStdString().c_str() ) );
2780 Handle(V3d_View) aView = this->getViewPort()->getView();
2781 aView->SetTextureEnv( aTexture );
2782 aView->SetSurfaceDetail( V3d_TEX_ENVIRONMENT );
2785 else if ( paramName == "lightSource" )
2787 myModel->getViewer3d()->InitDefinedLights();
2788 while ( myModel->getViewer3d()->MoreDefinedLights() )
2790 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2791 if( aLight->Type() != V3d_AMBIENT )
2792 myModel->getViewer3d()->DelLight( aLight );
2793 myModel->getViewer3d()->NextDefinedLights();
2797 V3d_TypeOfLight aType;
2799 QStringList lsData = paramValue.split( ';' );
2800 foreach( QString lsParam, lsData )
2802 QString ls_paramName = lsParam.section( '~', 0, 0 ).trimmed();
2803 QString ls_paramValue = lsParam.section( '~', 1, 1 ).trimmed();
2804 if ( ls_paramName == "lightType" ) aType = V3d_TypeOfLight( ls_paramValue.toInt() );
2805 else if ( ls_paramName == "lightX" ) aX = ls_paramValue.toDouble();
2806 else if ( ls_paramName == "lightY" ) aY = ls_paramValue.toDouble();
2807 else if ( ls_paramName == "lightZ" ) aZ = ls_paramValue.toDouble();
2808 else if ( ls_paramName == "lightColorR" ) cR = ls_paramValue.toDouble();
2809 else if ( ls_paramName == "lightColorG" ) cG = ls_paramValue.toDouble();
2810 else if ( ls_paramName == "lightColorB" ) cB = ls_paramValue.toDouble();
2811 else if ( ls_paramName == "lightHeadlight" ) isHeadlight = ls_paramValue.toInt();
2813 Quantity_Color aColor = Quantity_Color( cR, cG, cB, Quantity_TOC_RGB );
2814 if( aType == V3d_DIRECTIONAL ) {
2815 Handle(V3d_DirectionalLight) aLight = new V3d_DirectionalLight( myModel->getViewer3d() );
2816 aLight->SetDirection( aX, aY, aZ );
2817 aLight->SetColor( aColor );
2818 aLight->SetHeadlight( isHeadlight );
2819 myModel->getViewer3d()->SetLightOn( aLight );
2821 else if( aType == V3d_POSITIONAL ) {
2822 Handle(V3d_PositionalLight) aLight = new V3d_PositionalLight( myModel->getViewer3d(), aX, aY, aZ, aColor.Name() );
2823 aLight->SetHeadlight( isHeadlight );
2824 myModel->getViewer3d()->SetLightOn( aLight );
2827 else if ( paramName == "background" ) {
2828 QString bg = paramValue.replace( "$", "=" );
2829 bgData = Qtx::stringToBackground( bg );
2833 else // old format - "1.000e+00*0.000e+00..."
2836 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2837 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2838 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2839 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2840 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2841 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2842 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
2843 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2844 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2845 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
2846 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2847 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2848 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2849 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
2850 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
2851 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
2852 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
2853 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
2855 performRestoring( params );
2856 setBackground( bgData );
2857 myModel->setClipPlanes(aClipPlanes);
2861 \brief Handle show event.
2863 Emits Show() signal.
2865 \param theEvent show event
2867 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2869 emit Show( theEvent );
2873 \brief Handle hide event.
2875 Emits Hide() signal.
2877 \param theEvent hide event
2879 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
2881 emit Hide( theEvent );
2886 Save old cursor. [ protected ]
2888 void OCCViewer_ViewWindow::saveCursor()
2890 QCursor* aCursor = NULL;
2892 aCursor = myViewPort->getDefaultCursor();
2893 myCursor = ( aCursor ? *aCursor : cursor() );
2898 Creates default sketcher. [ virtual protected ]
2900 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
2903 return new OCCViewer_RectSketcher( this, type );
2904 if ( type == Polygon )
2905 return new OCCViewer_PolygonSketcher( this, type );
2909 void OCCViewer_ViewWindow::initSketchers()
2911 if ( mySketchers.isEmpty() )
2913 mySketchers.append( createSketcher( Rect ) );
2914 mySketchers.append( createSketcher( Polygon ) );
2918 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
2920 OCCViewer_ViewSketcher* sketcher = 0;
2921 QList<OCCViewer_ViewSketcher*>::Iterator it;
2922 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
2924 OCCViewer_ViewSketcher* sk = (*it);
2925 if ( sk->type() == typ )
2932 Handles requests for sketching in the active view. [ virtual public ]
2934 void OCCViewer_ViewWindow::activateSketching( int type )
2936 OCCViewer_ViewPort3d* vp = getViewPort();
2940 if ( !vp->isSketchingEnabled() )
2943 /* Finish current sketching */
2944 if ( type == NoSketching )
2948 onSketchingFinished();
2949 mypSketcher->deactivate();
2953 /* Activate new sketching */
2956 activateSketching( NoSketching ); /* concurrency not suported */
2957 mypSketcher = getSketcher( type );
2960 mypSketcher->activate();
2961 onSketchingStarted();
2967 Unhilights detected entities. [ virtual protected ]
2969 void OCCViewer_ViewWindow::onSketchingStarted()
2974 Selection by rectangle or polygon. [ virtual protected ]
2976 void OCCViewer_ViewWindow::onSketchingFinished()
2978 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
2979 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
2981 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
2982 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
2983 switch( mypSketcher->type() )
2987 QRect* aRect = (QRect*)mypSketcher->data();
2990 int aLeft = aRect->left();
2991 int aRight = aRect->right();
2992 int aTop = aRect->top();
2993 int aBottom = aRect->bottom();
2997 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2999 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
3005 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
3008 int size = aPolygon->size();
3009 TColgp_Array1OfPnt2d anArray( 1, size );
3011 QPolygon::Iterator it = aPolygon->begin();
3012 QPolygon::Iterator itEnd = aPolygon->end();
3013 for( int index = 1; it != itEnd; ++it, index++ )
3015 QPoint aPoint = *it;
3016 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
3020 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
3022 ic->Select( anArray, getViewPort()->getView(), Standard_False );
3030 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
3031 aViewMgr->getOCCViewer()->performSelectionChanged();
3035 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
3040 bool OCCViewer_ViewWindow::transformRequested() const
3042 return ( myOperation != NOTHING );
3045 bool OCCViewer_ViewWindow::transformInProcess() const
3047 return myEventStarted;
3050 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
3052 myEventStarted = bOn;
3056 Set enabled state of transformation (rotate, zoom, etc)
3058 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
3060 if ( id != NOTHING ) myStatus.insert( id, on );
3064 \return enabled state of transformation (rotate, zoom, etc)
3066 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
3068 return myStatus.contains( id ) ? myStatus[ id ] : true;
3071 void OCCViewer_ViewWindow::onMaximizedView()
3073 setMaximized(!isMaximized());
3076 void OCCViewer_ViewWindow::returnTo3dView()
3078 setReturnedTo3dView( true );
3081 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
3083 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
3084 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
3085 if ( !isVisible3dView )
3086 toolMgr()->show( ReturnTo3dViewId );
3088 toolMgr()->hide( ReturnTo3dViewId );
3089 if ( isVisible3dView ) emit returnedTo3d( );
3093 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
3095 QAction* anAction = toolMgr()->action( MaximizedId );
3096 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
3097 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
3099 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
3100 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
3101 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
3102 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
3103 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
3105 emit maximized( this, true );
3109 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
3110 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
3111 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
3112 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
3113 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
3115 emit maximized( this, false );
3120 bool OCCViewer_ViewWindow::isMaximized() const
3122 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
3125 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
3127 IsSketcherStyle = enable;
3130 bool OCCViewer_ViewWindow::isSketcherStyle() const
3132 return IsSketcherStyle;
3136 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
3141 int OCCViewer_ViewWindow::projectionType() const
3143 int mode = Orthographic;
3144 Handle(V3d_View) aView3d = myViewPort->getView();
3145 if ( !aView3d.IsNull() ) {
3146 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3147 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Perspective)
3149 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Orthographic)
3150 mode = Orthographic;
3151 #if OCC_VERSION_LARGE > 0x06090000
3152 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
3159 void OCCViewer_ViewWindow::setStereoType( int type )
3161 Handle(V3d_View) aView3d = myViewPort->getView();
3162 if ( !aView3d.IsNull() ) {
3163 #if OCC_VERSION_LARGE > 0x06090000
3164 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3165 aParams->StereoMode = (Graphic3d_StereoMode)type;
3170 int OCCViewer_ViewWindow::stereoType() const
3172 int type = QuadBuffer;
3173 Handle(V3d_View) aView3d = myViewPort->getView();
3174 if ( !aView3d.IsNull() ) {
3175 #if OCC_VERSION_LARGE > 0x06090000
3176 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3177 type = (OCCViewer_ViewWindow::StereoType)aParams->StereoMode;
3183 void OCCViewer_ViewWindow::setAnaglyphFilter( int type )
3185 Handle(V3d_View) aView3d = myViewPort->getView();
3186 if ( !aView3d.IsNull() ) {
3187 #if OCC_VERSION_LARGE > 0x06090000
3188 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3189 if (type == RedCyan)
3190 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
3191 if (type == YellowBlue)
3192 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
3193 if (type == GreenMagenta)
3194 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
3199 int OCCViewer_ViewWindow::anaglyphFilter() const
3202 Handle(V3d_View) aView3d = myViewPort->getView();
3203 if ( !aView3d.IsNull() ) {
3204 #if OCC_VERSION_LARGE > 0x06090000
3205 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3206 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized)
3208 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized)
3210 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple)
3211 type = GreenMagenta;
3217 void OCCViewer_ViewWindow::setStereographicFocus( int type, double value )
3219 Handle(V3d_View) aView3d = myViewPort->getView();
3220 if ( !aView3d.IsNull() ) {
3221 #if OCC_VERSION_LARGE > 0x06090000
3222 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3223 aCamera->SetZFocus( (Graphic3d_Camera::FocusType) type, value );
3228 int OCCViewer_ViewWindow::stereographicFocusType() const
3230 int type = Relative;
3231 Handle(V3d_View) aView3d = myViewPort->getView();
3232 if ( !aView3d.IsNull() ) {
3233 #if OCC_VERSION_LARGE > 0x06090000
3234 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3235 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->ZFocusType();
3241 double OCCViewer_ViewWindow::stereographicFocusValue() const
3244 Handle(V3d_View) aView3d = myViewPort->getView();
3245 if ( !aView3d.IsNull() ) {
3246 #if OCC_VERSION_LARGE > 0x06090000
3247 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3248 value = aCamera->ZFocus();
3254 void OCCViewer_ViewWindow::setInterocularDistance( int type, double value )
3256 Handle(V3d_View) aView3d = myViewPort->getView();
3257 if ( !aView3d.IsNull() ) {
3258 #if OCC_VERSION_LARGE > 0x06090000
3259 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3260 aCamera->SetIOD( (Graphic3d_Camera::IODType) type, value );
3265 int OCCViewer_ViewWindow::interocularDistanceType() const
3267 int type = Relative;
3268 Handle(V3d_View) aView3d = myViewPort->getView();
3269 if ( !aView3d.IsNull() ) {
3270 #if OCC_VERSION_LARGE > 0x06090000
3271 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3272 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->GetIODType();
3278 double OCCViewer_ViewWindow::interocularDistanceValue() const
3280 double value = 0.05;
3281 Handle(V3d_View) aView3d = myViewPort->getView();
3282 if ( !aView3d.IsNull() ) {
3283 #if OCC_VERSION_LARGE > 0x06090000
3284 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3285 value = aCamera->IOD();
3291 void OCCViewer_ViewWindow::setReverseStereo( bool reverse )
3293 Handle(V3d_View) aView3d = myViewPort->getView();
3294 if ( !aView3d.IsNull() ) {
3295 #if OCC_VERSION_LARGE > 0x06090000
3296 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3297 aParams->ToReverseStereo = reverse;
3302 bool OCCViewer_ViewWindow::isReverseStereo() const
3304 int reverse = false;
3305 Handle(V3d_View) aView3d = myViewPort->getView();
3306 if ( !aView3d.IsNull() ) {
3307 #if OCC_VERSION_LARGE > 0x06090000
3308 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3309 reverse = aParams->ToReverseStereo;
3315 void OCCViewer_ViewWindow::setVSync( bool enable )
3317 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3318 if ( !anIntCont.IsNull() ) {
3319 #if OCC_VERSION_LARGE > 0x06090000
3320 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3321 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3322 aCaps->swapInterval = enable;
3327 bool OCCViewer_ViewWindow::isVSync() const
3330 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3331 if ( !anIntCont.IsNull() ) {
3332 #if OCC_VERSION_LARGE > 0x06090000
3333 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3334 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3335 enable = aCaps->swapInterval;
3341 void OCCViewer_ViewWindow::setQuadBufferSupport( bool enable )
3343 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3344 if ( !anIntCont.IsNull() ) {
3345 #if OCC_VERSION_LARGE > 0x06090000
3346 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3347 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3348 aCaps->contextStereo = enable;
3353 bool OCCViewer_ViewWindow::isQuadBufferSupport() const
3356 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3357 if ( !anIntCont.IsNull() ) {
3358 #if OCC_VERSION_LARGE > 0x06090000
3359 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3360 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3361 enable = aCaps->contextStereo;
3368 bool OCCViewer_ViewWindow::isOpenGlStereoSupport() const
3370 GLboolean support[1];
3371 glGetBooleanv (GL_STEREO, support);
3378 QColor OCCViewer_ViewWindow::backgroundColor() const
3380 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
3384 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
3386 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
3389 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
3391 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
3394 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
3396 if ( myViewPort ) myViewPort->setBackground( theBackground );
3399 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
3401 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
3407 void OCCViewer_ViewWindow::clearViewAspects()
3409 myViewAspects.clear();
3413 \return const reference to list of view aspects
3415 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
3417 return myViewAspects;
3421 Appends new view aspect
3422 \param aParams - new view aspects
3424 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
3426 myViewAspects.append( aParams );
3430 Replaces old view aspects by new ones
3431 \param aViewList - list of new view aspects
3433 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
3435 myViewAspects = aViewList;
3439 Get camera properties for the OCC view window.
3440 \return shared pointer on camera properties.
3442 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
3444 SUIT_CameraProperties aProps;
3446 Handle(V3d_View) aSourceView = getViewPort()->getView();
3447 if ( aSourceView.IsNull() )
3450 if ( get2dMode() == No2dMode ) {
3451 aProps.setDimension( SUIT_CameraProperties::Dim3D );
3454 aProps.setDimension( SUIT_CameraProperties::Dim2D );
3455 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
3458 // read common properites of the view
3459 Standard_Real anUp[3];
3460 Standard_Real anAt[3];
3461 Standard_Real anEye[3];
3462 Standard_Real aProj[3];
3463 Standard_Real anAxialScale[3];
3465 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
3466 aSourceView->At( anAt[0], anAt[1], anAt[2] );
3467 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
3468 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3470 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3471 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
3473 #if OCC_VERSION_LARGE > 0x06070100
3474 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
3476 // store camera properties "as is": it is up to synchronized
3477 // view classes to provide necessary property conversion.
3478 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
3479 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
3481 if ( aSourceView->Camera()->IsOrthographic() )
3483 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
3484 aProps.setViewAngle( 0.0 );
3488 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
3489 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
3491 aProps.setMappingScale( aSourceView->Camera()->Scale() );
3493 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
3495 // generate view orientation matrix for transforming OCC projection reference point
3496 // into a camera (eye) position.
3497 gp_Dir aLeftDir = gp_Dir( anUp[0], anUp[1], anUp[2] ) ^ gp_Dir( aProj[0], aProj[1], aProj[2] );
3500 aTrsf.SetValue( 1, 1, aLeftDir.X() );
3501 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
3502 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
3504 aTrsf.SetValue( 1, 2, anUp[0] );
3505 aTrsf.SetValue( 2, 2, anUp[1] );
3506 aTrsf.SetValue( 3, 2, anUp[2] );
3508 aTrsf.SetValue( 1, 3, aProj[0] );
3509 aTrsf.SetValue( 2, 3, aProj[1] );
3510 aTrsf.SetValue( 3, 3, aProj[2] );
3512 aTrsf.SetValue( 1, 4, anAt[0] );
3513 aTrsf.SetValue( 2, 4, anAt[1] );
3514 aTrsf.SetValue( 3, 4, anAt[2] );
3516 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
3518 // transform to world-space coordinate system
3519 gp_XYZ aPosition( aProjRef.X(), aProjRef.Y(), aCameraDepth );
3520 aTrsf.Transforms( aPosition );
3522 // compute focal point
3523 double aFocalPoint[3];
3525 aFocalPoint[0] = aPosition.X() - aProj[0] * aCameraDepth;
3526 aFocalPoint[1] = aPosition.Y() - aProj[1] * aCameraDepth;
3527 aFocalPoint[2] = aPosition.Z() - aProj[2] * aCameraDepth;
3529 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3530 aProps.setPosition( aPosition.X(), aPosition.Y(), aPosition.Z() );
3532 Standard_Real aViewScale[2];
3533 aSourceView->Size( aViewScale[0], aViewScale[1] );
3534 aProps.setMappingScale( aViewScale[1] );
3542 This implementation synchronizes OCC view's camera propreties.
3544 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
3546 bool blocked = blockSignals( true );
3548 SUIT_CameraProperties aProps = theView->cameraProperties();
3549 if ( !cameraProperties().isCompatible( aProps ) ) {
3550 // other view, this one is being currently synchronized to, seems has become incompatible
3551 // we have to break synchronization
3556 Handle(V3d_View) aDestView = getViewPort()->getView();
3558 aDestView->SetImmediateUpdate( Standard_False );
3561 double aPosition[3];
3562 double aFocalPoint[3];
3563 double anAxialScale[3];
3565 // get common properties
3566 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3567 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
3568 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3569 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3571 #if OCC_VERSION_LARGE > 0x06070100
3572 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3573 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
3574 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3575 aDestView->Camera()->SetScale( aProps.getMappingScale() );
3577 gp_Dir aProjDir( aPosition[0] - aFocalPoint[0],
3578 aPosition[1] - aFocalPoint[1],
3579 aPosition[2] - aFocalPoint[2] );
3581 // get custom view translation
3582 Standard_Real aTranslation[3];
3583 aDestView->At( aTranslation[0], aTranslation[1], aTranslation[2] );
3585 gp_Dir aLeftDir = gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] )
3586 ^ gp_Dir( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
3589 aTrsf.SetValue( 1, 1, aLeftDir.X() );
3590 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
3591 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
3593 aTrsf.SetValue( 1, 2, anUpDir[0] );
3594 aTrsf.SetValue( 2, 2, anUpDir[1] );
3595 aTrsf.SetValue( 3, 2, anUpDir[2] );
3597 aTrsf.SetValue( 1, 3, aProjDir.X() );
3598 aTrsf.SetValue( 2, 3, aProjDir.Y() );
3599 aTrsf.SetValue( 3, 3, aProjDir.Z() );
3601 aTrsf.SetValue( 1, 4, aTranslation[0] );
3602 aTrsf.SetValue( 2, 4, aTranslation[1] );
3603 aTrsf.SetValue( 3, 4, aTranslation[2] );
3606 // transform to view-space coordinate system
3607 gp_XYZ aProjRef( aPosition[0], aPosition[1], aPosition[2] );
3608 aTrsf.Transforms( aProjRef );
3610 // set view camera properties using low-level approach. this is done
3611 // in order to avoid interference with static variables in v3d view used
3612 // when rotation is in process in another view.
3613 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
3614 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
3616 Graphic3d_Vector aMappingProj( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
3617 Graphic3d_Vector aMappingUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3619 aMappingProj.Normalize();
3620 aMappingUp.Normalize();
3622 anOrientation.SetViewReferencePlane( aMappingProj );
3623 anOrientation.SetViewReferenceUp( aMappingUp );
3625 aDestView->SetViewMapping( aMapping );
3626 aDestView->SetViewOrientation( anOrientation );
3629 aDestView->SetCenter( aProjRef.X(), aProjRef.Y() );
3631 // set mapping scale
3632 double aMapScaling = aProps.getMappingScale();
3633 Standard_Real aWidth, aHeight;
3634 aDestView->Size( aWidth, aHeight );
3635 aDestView->SetSize ( aWidth > aHeight ? aMapScaling * (aWidth / aHeight) : aMapScaling );
3638 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3640 aDestView->ZFitAll();
3641 aDestView->SetImmediateUpdate( Standard_True );
3642 aDestView->Redraw();
3644 blockSignals( blocked );
3648 \brief Indicates whether preselection is enabled
3649 \return true if preselection is enabled
3651 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
3653 return myPreselectionEnabled;
3657 \brief Enables/disables preselection
3658 \param theIsToEnable if true - preselection will be enabled
3660 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
3662 onSwitchPreselection( theIsToEnable );
3666 \brief Indicates whether selection is enabled
3667 \return true if selection is enabled
3669 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3671 return mySelectionEnabled;
3675 \brief Enables/disables selection
3676 \param theIsToEnable if true - selection will be enabled
3678 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3680 onSwitchSelection( theIsToEnable );
3685 \brief called if clipping operation is activated / deactivated.
3687 Enables/disables clipping plane displaying.
3689 \parma on action state
3691 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3693 if(!myModel) return;
3694 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3697 if (!aClippingDlg) {
3698 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3699 myModel->setClippingDlg(aClippingDlg);
3701 if (!aClippingDlg->isVisible())
3702 aClippingDlg->show();
3704 if ( aClippingDlg ) {
3705 aClippingDlg->close();
3706 myModel->setClippingDlg(0);
3710 SUIT_ViewManager* mgr = getViewManager();
3712 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3713 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3714 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3715 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3717 QAction* a = toolMgr()->action( ClippingId );
3719 if(theIsOn != a->isChecked()){
3720 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3721 a->setChecked(theIsOn);
3722 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3729 void OCCViewer_ViewWindow::onRayTracing()
3731 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_RayTracingDlg::getName() ) ) {
3732 QDialog* aDlg = new OCCViewer_RayTracingDlg( this );
3738 void OCCViewer_ViewWindow::onEnvTexture()
3740 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_EnvTextureDlg::getName() ) ) {
3741 QDialog* aDlg = new OCCViewer_EnvTextureDlg( this );
3747 void OCCViewer_ViewWindow::onLightSource()
3749 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_LightSourceDlg::getName() ) ) {
3750 QDialog* aDlg = new OCCViewer_LightSourceDlg( this, myModel );