1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : OCCViewer_ViewWindow.cxx
26 #include "OCCViewer_ViewWindow.h"
27 #include "OCCViewer_ViewFrame.h"
28 #include "OCCViewer_ViewModel.h"
29 #include "OCCViewer_ViewPort3d.h"
30 #include "OCCViewer_ViewManager.h"
31 #include "OCCViewer_ViewSketcher.h"
32 #include "OCCViewer_CreateRestoreViewDlg.h"
33 #include "OCCViewer_ClipPlane.h"
34 #include "OCCViewer_SetRotationPointDlg.h"
35 #include "OCCViewer_AxialScaleDlg.h"
36 #include "OCCViewer_CubeAxesDlg.h"
37 #include "OCCViewer_ClippingDlg.h"
38 #include "OCCViewer_RayTracingDlg.h"
39 #include "OCCViewer_EnvTextureDlg.h"
40 #include "OCCViewer_LightSourceDlg.h"
41 #include "OCCViewer_Utilities.h"
43 #include <SUIT_Desktop.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_ViewManager.h>
46 #include <SUIT_Tools.h>
47 #include <SUIT_ResourceMgr.h>
48 #include <SUIT_MessageBox.h>
49 #include <SUIT_Application.h>
51 #include <QtxActionToolMgr.h>
52 #include <QtxMultiAction.h>
53 #include <QtxRubberBand.h>
55 #include <Basics_OCCTVersion.hxx>
61 #include <QMouseEvent>
62 #include <QApplication>
63 #include <QActionGroup>
66 #include <AIS_ListOfInteractive.hxx>
67 #include <AIS_ListIteratorOfListOfInteractive.hxx>
68 #include <AIS_Shape.hxx>
70 #include <BRep_Tool.hxx>
71 #include <BRepBndLib.hxx>
72 #include <BRepGProp.hxx>
73 #include <GProp_GProps.hxx>
76 #include <Graphic3d_SequenceOfHClipPlane.hxx>
77 #include <Graphic3d_ClipPlane.hxx>
78 #include <OpenGl_GraphicDriver.hxx>
79 #include <OpenGLUtils_FrameBuffer.h>
81 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
82 #include <Graphic3d_MapOfStructure.hxx>
83 #include <Graphic3d_Structure.hxx>
84 #include <Graphic3d_ExportFormat.hxx>
85 #if OCC_VERSION_LARGE > 0x06090000
86 #include <Graphic3d_StereoMode.hxx>
87 #include <Graphic3d_RenderingParams.hxx>
90 #if OCC_VERSION_MAJOR < 7
91 #include <Visual3d_View.hxx>
94 #include <V3d_Plane.hxx>
95 #include <V3d_Light.hxx>
99 #include <gp_GTrsf.hxx>
100 #include <TColgp_Array1OfPnt2d.hxx>
102 #include <Image_PixMap.hxx>
104 #include <Standard_Version.hxx>
106 #include "utilities.h"
108 // // OpenCV includes
110 // #include <highgui.h>
112 static QEvent* l_mbPressEvent = 0;
115 //# include <QWindowsStyle>
120 // To avoid conflict between KeyPress from the X.h (define KeyPress 2)
121 // and QEvent::KeyPress (qevent.h)
126 // Enable ray tracing features
127 #define ENABLE_RAY_TRACING
129 const char* imageZoomCursor[] = {
134 "................................",
135 "................................",
136 ".#######........................",
137 "..aaaaaaa.......................",
138 "................................",
139 ".............#####..............",
140 "...........##.aaaa##............",
141 "..........#.aa.....a#...........",
142 ".........#.a.........#..........",
143 ".........#a..........#a.........",
144 "........#.a...........#.........",
145 "........#a............#a........",
146 "........#a............#a........",
147 "........#a............#a........",
148 "........#a............#a........",
149 ".........#...........#.a........",
150 ".........#a..........#a.........",
151 ".........##.........#.a.........",
152 "........#####.....##.a..........",
153 ".......###aaa#####.aa...........",
154 "......###aa...aaaaa.......#.....",
155 ".....###aa................#a....",
156 "....###aa.................#a....",
157 "...###aa...............#######..",
158 "....#aa.................aa#aaaa.",
159 ".....a....................#a....",
160 "..........................#a....",
161 "...........................a....",
162 "................................",
163 "................................",
164 "................................",
165 "................................"};
167 const char* imageRotateCursor[] = {
172 "................................",
173 "................................",
174 "................................",
175 "................................",
176 "........#.......................",
177 ".......#.a......................",
178 "......#######...................",
179 ".......#aaaaa#####..............",
180 "........#..##.a#aa##........##..",
181 ".........a#.aa..#..a#.....##.aa.",
182 ".........#.a.....#...#..##.aa...",
183 ".........#a.......#..###.aa.....",
184 "........#.a.......#a..#aa.......",
185 "........#a.........#..#a........",
186 "........#a.........#a.#a........",
187 "........#a.........#a.#a........",
188 "........#a.........#a.#a........",
189 ".........#.........#a#.a........",
190 "........##a........#a#a.........",
191 "......##.a#.......#.#.a.........",
192 "....##.aa..##.....##.a..........",
193 "..##.aa.....a#####.aa...........",
194 "...aa.........aaa#a.............",
195 "................#.a.............",
196 "...............#.a..............",
197 "..............#.a...............",
198 "...............a................",
199 "................................",
200 "................................",
201 "................................",
202 "................................",
203 "................................"};
205 const char* imageCrossCursor[] = {
210 "................................",
211 "................................",
212 "................................",
213 "................................",
214 "................................",
215 "................................",
216 "................................",
217 "...............#................",
218 "...............#a...............",
219 "...............#a...............",
220 "...............#a...............",
221 "...............#a...............",
222 "...............#a...............",
223 "...............#a...............",
224 "...............#a...............",
225 ".......#################........",
226 "........aaaaaaa#aaaaaaaaa.......",
227 "...............#a...............",
228 "...............#a...............",
229 "...............#a...............",
230 "...............#a...............",
231 "...............#a...............",
232 "...............#a...............",
233 "...............#a...............",
234 "................a...............",
235 "................................",
236 "................................",
237 "................................",
238 "................................",
239 "................................",
240 "................................",
241 "................................"};
246 \param theDesktop main window of application
247 \param theModel OCC 3D viewer
249 OCCViewer_ViewWindow::OCCViewer_ViewWindow( SUIT_Desktop* theDesktop,
250 OCCViewer_Viewer* theModel )
251 : SUIT_ViewWindow( theDesktop )
255 myEnableDrawMode = false;
256 myDrawRectEnabled = true;
258 updateEnabledDrawMode();
260 mySetRotationPointDlg = 0;
263 IsSketcherStyle = false;
270 myInteractionStyle = SUIT_ViewModel::STANDARD;
271 myPreselectionEnabled = true;
272 mySelectionEnabled = true;
274 myCursorIsHand = false;
282 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
285 qDeleteAll( mySketchers );
289 \brief Internal initialization.
291 void OCCViewer_ViewWindow::initLayout()
293 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
294 myViewPort->installEventFilter(this);
295 setCentralWidget(myViewPort);
296 myOperation = NOTHING;
298 myCurrPointType = BBCENTER;
299 myPrevPointType = BBCENTER;
300 mySelectedPoint = gp_Pnt(0.,0.,0.);
301 myRotationPointSelection = false;
303 setTransformRequested ( NOTHING );
304 setTransformInProcess ( false );
321 // Graduated axes dialog
322 QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
323 myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
324 myCubeAxesDlg->initialize();
326 connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
329 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
331 return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
335 \brief Detect viewer operation according the the mouse button pressed
336 and key modifiers used.
337 \param theEvent mouse event
338 \return type of the operation
340 OCCViewer_ViewWindow::OperationType
341 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
343 OperationType aOp = NOTHING;
344 SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
345 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
346 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
348 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
349 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
351 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
352 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
353 (my2dMode == No2dMode))
360 \brief Customize event handling
361 \param watched event receiver object
363 \return \c true if the event processing should be stopped
365 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
367 if ( watched == myViewPort ) {
368 int aType = e->type();
370 case QEvent::MouseButtonPress:
371 vpMousePressEvent((QMouseEvent*) e);
374 case QEvent::MouseButtonRelease:
375 vpMouseReleaseEvent((QMouseEvent*) e);
378 case QEvent::MouseMove:
379 vpMouseMoveEvent((QMouseEvent*) e);
382 case QEvent::MouseButtonDblClick:
383 emit mouseDoubleClicked(this, (QMouseEvent*)e);
388 QWheelEvent* aEvent = (QWheelEvent*) e;
390 if ( aEvent->modifiers().testFlag(Qt::ControlModifier) ) {
391 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
392 if ( isPreselectionEnabled() && ic->HasOpenedContext() ) {
393 if ( aEvent->delta() > 0 ) {
394 ic->HilightNextDetected( myViewPort->getView() );
396 ic->HilightPreviousDetected( myViewPort->getView() );
401 emit vpTransformationStarted ( ZOOMVIEW );
402 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
403 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
406 int x1 = (int)( aEvent->x() + width()*delta/100 );
407 int y1 = (int)( aEvent->y() + height()*delta/100 );
408 myViewPort->zoom( x, y, x1, y1 );
409 #if OCC_VERSION_LARGE <= 0x07000000
410 myViewPort->getView()->ZFitAll();
412 emit vpTransformationFinished ( ZOOMVIEW );
417 case QEvent::ContextMenu:
419 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
420 if ( aEvent->reason() != QContextMenuEvent::Mouse )
421 emit contextMenuRequested( aEvent );
425 case QEvent::KeyPress:
426 emit keyPressed(this, (QKeyEvent*) e);
433 return SUIT_ViewWindow::eventFilter(watched, e);
437 \brief Enable / disable draw rect (rubber band) mode
439 bool OCCViewer_ViewWindow::enableDrawMode( bool on )
441 bool prev = myDrawRectEnabled;
442 myDrawRectEnabled = on;
443 updateEnabledDrawMode();
448 \brief Update state of enable draw mode state.
450 void OCCViewer_ViewWindow::updateEnabledDrawMode()
452 myEnableDrawMode = myDrawRectEnabled;
454 myEnableDrawMode = myEnableDrawMode && myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
458 \brief Handle mouse press event
459 \param theEvent mouse event
461 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
463 myStartX = theEvent->x();
464 myStartY = theEvent->y();
465 int anInteractionStyle = interactionStyle();
467 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
468 // which are assigned for pan and rotate - these operations are activated immediately after pressing
469 // of the first button, so it is necessary to switch to zoom when the second button is pressed
470 bool aSwitchToZoom = false;
471 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
472 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
473 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
476 switch ( myOperation ) {
478 if ( theEvent->button() == Qt::LeftButton )
479 emit vpTransformationStarted ( WINDOWFIT );
483 if ( theEvent->button() == Qt::LeftButton )
484 emit vpTransformationStarted ( PANGLOBAL );
488 if ( theEvent->button() == Qt::LeftButton ) {
489 myViewPort->startZoomAtPoint( myStartX, myStartY );
490 emit vpTransformationStarted ( ZOOMVIEW );
495 if ( aSwitchToZoom ) {
496 myViewPort->startZoomAtPoint( myStartX, myStartY );
499 else if ( theEvent->button() == Qt::LeftButton )
500 emit vpTransformationStarted ( PANVIEW );
504 if ( aSwitchToZoom ) {
505 myViewPort->startZoomAtPoint( myStartX, myStartY );
508 else if ( theEvent->button() == Qt::LeftButton ) {
509 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
510 emit vpTransformationStarted ( ROTATE );
515 /* Try to activate a transformation */
516 OperationType aState;
517 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
518 aState = getButtonState(theEvent, anInteractionStyle);
520 aState = OCCViewer_ViewWindow::NOTHING;
525 myViewPort->startZoomAtPoint( myStartX, myStartY );
533 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
536 if ( myRotationPointSelection )
538 if ( theEvent->button() == Qt::LeftButton )
540 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
542 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
544 TopoDS_Shape aShape = ic->SelectedShape();
545 GProp_GProps aSystem;
547 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
549 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
551 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE )
553 BRepGProp::LinearProperties( aShape, aSystem );
554 aPnt = aSystem.CentreOfMass();
556 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE )
558 BRepGProp::SurfaceProperties( aShape, aSystem );
559 aPnt = aSystem.CentreOfMass();
561 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID )
563 BRepGProp::VolumeProperties( aShape, aSystem );
564 aPnt = aSystem.CentreOfMass();
568 myCurrPointType = myPrevPointType;
572 if ( mySetRotationPointDlg )
574 myRotationPointSelection = false;
575 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
578 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
579 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
580 ic->CloseAllContexts();
581 myOperation = NOTHING;
582 myViewPort->setCursor( myCursor );
583 myCursorIsHand = false;
584 myRotationPointSelection = false;
588 emit mousePressed(this, theEvent);
591 /* notify that we start a transformation */
592 if ( transformRequested() )
593 emit vpTransformationStarted ( myOperation );
595 if ( transformRequested() )
596 setTransformInProcess( true );
598 /* we may need it for sketching... */
599 if ( l_mbPressEvent )
600 delete l_mbPressEvent;
601 l_mbPressEvent = new QMouseEvent( *theEvent );
606 \brief Start zooming operation.
608 Sets the corresponding cursor for the widget.
610 void OCCViewer_ViewWindow::activateZoom()
612 if ( !transformRequested() && !myCursorIsHand )
613 saveCursor(); /* save old cursor */
615 if ( myOperation != ZOOMVIEW ) {
616 QPixmap zoomPixmap (imageZoomCursor);
617 QCursor zoomCursor (zoomPixmap);
618 if( setTransformRequested ( ZOOMVIEW ) )
619 myViewPort->setCursor( zoomCursor );
625 \brief Start panning operation.
627 Sets the corresponding cursor for the widget.
629 void OCCViewer_ViewWindow::activatePanning()
631 if ( !transformRequested() && !myCursorIsHand )
632 saveCursor(); // save old cursor
634 if ( myOperation != PANVIEW ) {
635 QCursor panCursor (Qt::SizeAllCursor);
636 if( setTransformRequested ( PANVIEW ) )
637 myViewPort->setCursor( panCursor );
642 \brief Start rotation operation
644 Sets the corresponding cursor for the widget.
646 void OCCViewer_ViewWindow::activateRotation()
648 if ( !transformRequested() && !myCursorIsHand )
649 saveCursor(); // save old cursor
651 if ( myOperation != ROTATE ) {
652 QPixmap rotatePixmap (imageRotateCursor);
653 QCursor rotCursor (rotatePixmap);
654 if( setTransformRequested ( ROTATE ) )
655 myViewPort->setCursor( rotCursor );
660 \brief Compute the gravity center.
661 \param theX used to return X coordinate of the gravity center
662 \param theY used to return Y coordinate of the gravity center
663 \param theZ used to return Z coordinate of the gravity center
664 \return \c true if the gravity center is computed
666 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
668 Handle(V3d_View) aView3d = myViewPort->getView();
670 // Project boundaries points and add to avergae gravity
671 // the ones which lie within the screen limits
672 Standard_Real aScreenLimits[4] = { 0.0, 0.0, 0.0, 0.0 };
674 #if OCC_VERSION_LARGE > 0x06070100
675 // NDC space screen limits
676 aScreenLimits[0] = -1.0;
677 aScreenLimits[1] = 1.0;
678 aScreenLimits[2] = -1.0;
679 aScreenLimits[3] = 1.0;
681 aView3d->View()->ViewMapping().WindowLimit( aScreenLimits[0],
687 Standard_Integer aPointsNb = 0;
689 Standard_Real aXmin = 0.0;
690 Standard_Real aYmin = 0.0;
691 Standard_Real aZmin = 0.0;
692 Standard_Real aXmax = 0.0;
693 Standard_Real aYmax = 0.0;
694 Standard_Real aZmax = 0.0;
696 Graphic3d_MapOfStructure aSetOfStructures;
697 aView3d->View()->DisplayedStructures( aSetOfStructures );
698 Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures );
700 for( ; aStructureIt.More(); aStructureIt.Next() ) {
701 const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key();
702 if ( aStructure->IsEmpty() || !aStructure->IsVisible() || aStructure->CStructure()->IsForHighlight )
705 #if OCC_VERSION_LARGE > 0x06070100
706 Bnd_Box aBox = aStructure->MinMaxValues();
707 aXmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().X();
708 aYmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Y();
709 aZmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Z();
710 aXmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().X();
711 aYmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Y();
712 aZmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Z();
714 aStructure->MinMaxValues( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
717 // Infinite structures are skipped
718 Standard_Real aLIM = ShortRealLast() - 1.0;
719 if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
720 || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
724 gp_Pnt aPoints[8] = {
725 gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
726 gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
727 gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
728 gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
731 for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
732 const gp_Pnt& aBBPoint = aPoints[aPointIt];
734 #if OCC_VERSION_LARGE > 0x06070100
735 gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
736 const Standard_Real& U = aProjected.X();
737 const Standard_Real& V = aProjected.Y();
739 Standard_Real U = 0.0;
740 Standard_Real V = 0.0;
741 Standard_Real W = 0.0;
742 aView3d->View()->Projects( aBBPoint.X(), aBBPoint.Y(), aBBPoint.Z(), U, V, W );
745 if (U >= aScreenLimits[0]
746 && U <= aScreenLimits[1]
747 && V >= aScreenLimits[2]
748 && V <= aScreenLimits[3])
751 theX += aBBPoint.X();
752 theY += aBBPoint.Y();
753 theZ += aBBPoint.Z();
768 \brief Set the gravity center as a rotation point.
770 void OCCViewer_ViewWindow::activateSetRotationGravity()
772 if ( myRotationPointSelection )
774 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
775 ic->CloseAllContexts();
776 myOperation = NOTHING;
777 myViewPort->setCursor( myCursor );
778 myCursorIsHand = false;
779 myRotationPointSelection = false;
782 myPrevPointType = myCurrPointType;
783 myCurrPointType = BBCENTER;
785 Standard_Real Xcenter, Ycenter, Zcenter;
786 if ( OCCViewer_Utilities::computeVisibleBBCenter( myViewPort->getView(), Xcenter, Ycenter, Zcenter ) )
787 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
791 \brief Update gravity center in the "Set Rotation Point" dialog box.
792 \sa OCCViewer_SetRotationPointDlg class
794 void OCCViewer_ViewWindow::updateGravityCoords()
796 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == BBCENTER )
798 Standard_Real Xcenter, Ycenter, Zcenter;
799 if ( OCCViewer_Utilities::computeVisibleBBCenter( myViewPort->getView(), Xcenter, Ycenter, Zcenter ) )
800 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
805 \brief Set the point selected by the user as a rotation point.
806 \param theX X coordinate of the rotation point
807 \param theY Y coordinate of the rotation point
808 \param theZ Z coordinate of the rotation point
810 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
812 if ( myRotationPointSelection )
814 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
815 ic->CloseAllContexts();
816 myOperation = NOTHING;
817 myViewPort->setCursor( myCursor );
818 myCursorIsHand = false;
819 myRotationPointSelection = false;
822 myPrevPointType = myCurrPointType;
823 myCurrPointType = SELECTED;
824 mySelectedPoint.SetCoord(theX,theY,theZ);
828 \brief Start the shape selection process.
830 void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
832 myPrevPointType = myCurrPointType;
833 myCurrPointType = SELECTED;
835 // activate selection ------>
836 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
838 ic->OpenLocalContext();
840 AIS_ListOfInteractive aList;
841 ic->DisplayedObjects( aList );
842 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
844 Handle(AIS_InteractiveObject) anObj = it.Value();
845 if ( !anObj.IsNull() && anObj->HasPresentation() &&
846 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
849 ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
852 // activate selection <------
854 if ( !myCursorIsHand )
856 QCursor handCursor (Qt::PointingHandCursor);
857 myCursorIsHand = true;
859 myViewPort->setCursor( handCursor );
861 myRotationPointSelection = true;
865 \brief Start global panning operation
867 Sets the corresponding cursor for the widget.
869 void OCCViewer_ViewWindow::activateGlobalPanning()
871 Handle(V3d_View) aView3d = myViewPort->getView();
872 if ( !aView3d.IsNull() ) {
873 QPixmap globalPanPixmap (imageCrossCursor);
874 QCursor glPanCursor (globalPanPixmap);
875 myCurScale = aView3d->Scale();
876 aView3d->FitAll(0.01, false);
877 saveCursor(); // save old cursor
878 myViewPort->fitAll(); // fits view before selecting a new scene center
879 if( setTransformRequested( PANGLOBAL ) )
880 myViewPort->setCursor( glPanCursor );
885 \brief Starts fit operation.
887 Sets the corresponding cursor for the widget.
889 void OCCViewer_ViewWindow::activateWindowFit()
891 if ( !transformRequested() && !myCursorIsHand )
892 saveCursor(); /* save old cursor */
894 if ( myOperation != WINDOWFIT ) {
895 QCursor handCursor (Qt::PointingHandCursor);
896 if( setTransformRequested ( WINDOWFIT ) )
898 myViewPort->setCursor ( handCursor );
899 myCursorIsHand = true;
905 \brief Start delayed viewer operation.
907 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
909 bool ok = transformEnabled( op );
910 myOperation = ok ? op : NOTHING;
911 myViewPort->setMouseTracking( myOperation == NOTHING );
916 \brief Handle mouse move event.
917 \param theEvent mouse event
919 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
921 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
923 switch ( getButtonState( theEvent, interactionStyle() ) ) {
925 myViewPort->startZoomAtPoint( myStartX, myStartY );
933 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
940 myCurrX = theEvent->x();
941 myCurrY = theEvent->y();
942 switch (myOperation) {
944 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
948 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
954 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
968 if ( myRotationPointSelection || isSketcherStyle() )
970 emit mouseMoving( this, theEvent );
974 int aState = theEvent->modifiers();
975 int aButton = theEvent->buttons();
976 int anInteractionStyle = interactionStyle();
977 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
978 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
979 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
980 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
981 myDrawRect = myEnableDrawMode;
984 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
985 QCursor handCursor (Qt::PointingHandCursor);
986 myCursorIsHand = true;
988 myViewPort->setCursor( handCursor );
991 emit mouseMoving( this, theEvent );
993 else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
994 aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
995 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
996 aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
997 OCCViewer_ViewSketcher* sketcher = 0;
998 QList<OCCViewer_ViewSketcher*>::Iterator it;
999 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
1001 OCCViewer_ViewSketcher* sk = (*it);
1002 if( sk->isDefault() && sk->sketchButton() == aButton )
1005 if ( sketcher && myCurSketch == -1 )
1007 activateSketching( sketcher->type() );
1010 myCurSketch = mypSketcher->sketchButton();
1012 if ( l_mbPressEvent )
1014 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
1015 delete l_mbPressEvent;
1018 QApplication::sendEvent( getViewPort(), theEvent );
1023 emit mouseMoving( this, theEvent );
1029 \brief Handle mouse release event.
1030 \param theEvent mouse event
1032 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
1034 switch ( myOperation ) {
1037 int prevState = myCurSketch;
1038 if(theEvent->button() == Qt::RightButton)
1040 QList<OCCViewer_ViewSketcher*>::Iterator it;
1041 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
1043 OCCViewer_ViewSketcher* sk = (*it);
1044 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
1049 emit mouseReleased(this, theEvent);
1050 if(theEvent->button() == Qt::RightButton && prevState == -1)
1052 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1053 theEvent->pos(), theEvent->globalPos() );
1054 emit contextMenuRequested( &aEvent );
1059 myViewPort->endRotation();
1065 #if OCC_VERSION_LARGE <= 0x07000000
1066 myViewPort->getView()->ZFitAll();
1072 if ( theEvent->button() == Qt::LeftButton ) {
1073 myViewPort->setCenter( theEvent->x(), theEvent->y() );
1074 myViewPort->getView()->SetScale(myCurScale);
1080 if ( theEvent->button() == Qt::LeftButton ) {
1081 myCurrX = theEvent->x();
1082 myCurrY = theEvent->y();
1084 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1085 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1092 // NOTE: viewer 3D detects a rectangle of selection using this event
1093 // so we must emit it BEFORE resetting the selection rectangle
1095 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1099 myViewPort->update();
1102 if ( l_mbPressEvent )
1104 delete l_mbPressEvent;
1110 \brief Reset the viewport to its initial state
1111 ( no transformations in process etc. )
1113 void OCCViewer_ViewWindow::resetState()
1117 if ( myRotationPointSelection )
1119 QCursor handCursor (Qt::PointingHandCursor);
1120 myViewPort->setCursor( handCursor );
1124 if ( transformRequested() || myCursorIsHand )
1125 myViewPort->setCursor( myCursor );
1126 myCursorIsHand = false;
1129 if ( transformRequested() )
1130 emit vpTransformationFinished (myOperation);
1132 setTransformInProcess( false );
1133 setTransformRequested( NOTHING );
1138 \brief Draw rubber band rectangle.
1140 void OCCViewer_ViewWindow::drawRect()
1142 if ( !myRectBand ) {
1143 myRectBand = new QtxRectRubberBand( myViewPort );
1145 //palette.setColor(myRectBand->foregroundRole(), Qt::white);
1146 //myRectBand->setPalette(palette);
1148 //myRectBand->hide();
1150 myRectBand->setUpdatesEnabled ( false );
1151 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1152 myRectBand->initGeometry( aRect );
1154 if ( !myRectBand->isVisible() )
1157 myRectBand->setUpdatesEnabled ( true );
1158 //myRectBand->repaint();
1160 //myRectBand->setVisible( aRect.isValid() );
1161 //if ( myRectBand->isVisible() )
1162 // myRectBand->repaint();
1164 // myRectBand->show();
1165 //myRectBand->repaint();
1169 \brief Clear rubber band rectangle on the end on the dragging operation.
1171 void OCCViewer_ViewWindow::endDrawRect()
1173 //delete myRectBand;
1177 myRectBand->clearGeometry();
1183 \brief Create actions.
1185 void OCCViewer_ViewWindow::createActions()
1187 if( !toolMgr()->isEmpty() )
1190 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1197 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1198 tr( "MNU_DUMP_VIEW" ), 0, this);
1199 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1200 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1201 toolMgr()->registerAction( aAction, DumpId );
1204 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1205 tr( "MNU_FITALL" ), 0, this);
1206 aAction->setStatusTip(tr("DSC_FITALL"));
1207 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1208 toolMgr()->registerAction( aAction, FitAllId );
1211 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1212 tr( "MNU_FITRECT" ), 0, this);
1213 aAction->setStatusTip(tr("DSC_FITRECT"));
1214 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1215 toolMgr()->registerAction( aAction, FitRectId );
1218 aAction = new QtxAction(tr("MNU_FITSELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITSELECTION" ) ),
1219 tr( "MNU_FITSELECTION" ), 0, this);
1220 aAction->setStatusTip(tr("DSC_FITSELECTION"));
1221 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
1222 toolMgr()->registerAction( aAction, FitSelectionId );
1225 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1226 tr( "MNU_ZOOM_VIEW" ), 0, this);
1227 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1228 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1229 toolMgr()->registerAction( aAction, ZoomId );
1232 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1233 tr( "MNU_PAN_VIEW" ), 0, this);
1234 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1235 connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
1236 toolMgr()->registerAction( aAction, PanId );
1239 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1240 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1241 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1242 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1243 toolMgr()->registerAction( aAction, GlobalPanId );
1246 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1247 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1248 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1249 mySetRotationPointAction->setCheckable( true );
1250 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1251 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1254 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1255 tr( "MNU_ROTATE_VIEW" ), 0, this);
1256 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1257 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1258 toolMgr()->registerAction( aAction, RotationId );
1261 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1262 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1263 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1264 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1265 this->addAction(aAction);
1266 toolMgr()->registerAction( aAction, FrontId );
1268 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1269 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1270 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1271 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1272 this->addAction(aAction);
1273 toolMgr()->registerAction( aAction, BackId );
1275 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1276 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1277 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1278 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1279 this->addAction(aAction);
1280 toolMgr()->registerAction( aAction, TopId );
1282 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1283 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1284 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1285 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1286 this->addAction(aAction);
1287 toolMgr()->registerAction( aAction, BottomId );
1289 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1290 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1291 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1292 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1293 this->addAction(aAction);
1294 toolMgr()->registerAction( aAction, LeftId );
1296 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1297 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1298 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1299 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1300 this->addAction(aAction);
1301 toolMgr()->registerAction( aAction, RightId );
1303 // rotate anticlockwise
1304 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1305 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1306 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1307 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1308 this->addAction(aAction);
1309 toolMgr()->registerAction( aAction, AntiClockWiseId );
1312 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1313 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1314 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1315 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1316 this->addAction(aAction);
1317 toolMgr()->registerAction( aAction, ClockWiseId );
1319 // Projection mode group
1321 // - orthographic projection
1322 aAction = new QtxAction(tr("MNU_ORTHOGRAPHIC_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ORTHOGRAPHIC" ) ),
1323 tr( "MNU_ORTHOGRAPHIC_MODE" ), 0, this);
1324 aAction->setStatusTip(tr("DSC_ORTHOGRAPHIC_MODE"));
1325 aAction->setCheckable(true);
1326 toolMgr()->registerAction( aAction, OrthographicId );
1328 // - perspective projection
1329 aAction = new QtxAction(tr("MNU_PERSPECTIVE_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PERSPECTIVE" ) ),
1330 tr( "MNU_PERSPECTIVE_MODE" ), 0, this);
1331 aAction->setStatusTip(tr("DSC_PERSPECTIVE_MODE"));
1332 aAction->setCheckable(true);
1333 toolMgr()->registerAction( aAction, PerspectiveId );
1334 #if OCC_VERSION_LARGE > 0x06090000
1335 // - stereo projection
1336 aAction = new QtxAction(tr("MNU_STEREO_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STEREO" ) ),
1337 tr( "MNU_STEREO_MODE" ), 0, this);
1338 aAction->setStatusTip(tr("DSC_STEREO_MODE"));
1339 aAction->setCheckable(true);
1340 toolMgr()->registerAction( aAction, StereoId );
1341 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onStereoType(bool)));
1343 // - add exclusive action group
1344 QActionGroup* aProjectionGroup = new QActionGroup( this );
1345 aProjectionGroup->addAction( toolMgr()->action( OrthographicId ) );
1346 aProjectionGroup->addAction( toolMgr()->action( PerspectiveId ) );
1347 connect(aProjectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProjectionType(QAction*)));
1350 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1351 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1352 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1353 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1354 this->addAction(aAction);
1355 toolMgr()->registerAction( aAction, ResetId );
1358 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1359 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1360 tr("MNU_CLONE_VIEW"), 0, this);
1361 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1362 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1363 toolMgr()->registerAction( aAction, CloneId );
1365 aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
1366 tr("MNU_CLIPPING"), 0, this);
1367 aAction->setStatusTip (tr("DSC_CLIPPING"));
1368 aAction->setCheckable (true);
1369 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1370 toolMgr()->registerAction (aAction, ClippingId);
1372 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1373 tr( "MNU_SHOOT_VIEW" ), 0, this);
1374 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1375 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1376 toolMgr()->registerAction( aAction, MemId );
1378 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1379 tr( "MNU_PRESETS_VIEW" ), 0, this);
1380 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1381 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1382 toolMgr()->registerAction( aAction, RestoreId );
1384 if (myModel->trihedronActivated()) {
1385 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1386 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1387 aAction->setCheckable( true );
1388 aAction->setChecked( true );
1389 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1390 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1391 toolMgr()->registerAction( aAction, TrihedronShowId );
1395 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1396 tr( "MNU_SCALING" ), 0, this);
1397 aAction->setStatusTip(tr("DSC_SCALING"));
1398 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1399 toolMgr()->registerAction( aAction, AxialScaleId );
1401 // Enable/disable preselection
1402 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1403 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1404 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1405 aAction->setCheckable(true);
1406 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1407 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1409 // Enable/disable selection
1410 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1411 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1412 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1413 aAction->setCheckable(true);
1414 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1415 toolMgr()->registerAction( aAction, SwitchSelectionId );
1418 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1419 tr( "MNU_GRADUATED_AXES" ), 0, this);
1420 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1421 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1422 toolMgr()->registerAction( aAction, GraduatedAxesId );
1424 // Active only ambient light or not
1425 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1426 tr( "MNU_AMBIENT" ), 0, this);
1427 aAction->setStatusTip(tr("DSC_AMBIENT"));
1428 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1429 toolMgr()->registerAction( aAction, AmbientId );
1431 // Switch between interaction styles
1432 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1433 tr( "MNU_STYLE_SWITCH" ), 0, this);
1434 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1435 aAction->setCheckable(true);
1436 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1437 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1439 // Switch between zooming styles
1440 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1441 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1442 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1443 aAction->setCheckable(true);
1444 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1445 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1448 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1449 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1450 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1451 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1452 toolMgr()->registerAction( aAction, MaximizedId );
1454 // Return to 3d view
1455 if (my2dMode!=No2dMode){
1456 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1457 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1458 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1459 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1460 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1464 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1465 #ifdef ENABLE_RAY_TRACING
1467 aAction = new QtxAction( tr("MNU_RAY_TRACING"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_RAY_TRACING") ),
1468 tr("MNU_RAY_TRACING"), 0, this );
1469 aAction->setStatusTip( tr("DSC_RAY_TRACING") );
1470 connect( aAction, SIGNAL( triggered() ), this, SLOT( onRayTracing() ) );
1471 toolMgr()->registerAction( aAction, RayTracingId );
1473 // Environment texture
1474 aAction = new QtxAction( tr("MNU_ENV_TEXTURE"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_ENV_TEXTURE") ),
1475 tr("MNU_ENV_TEXTURE"), 0, this );
1476 aAction->setStatusTip( tr("DSC_ENV_TEXTURE") );
1477 connect( aAction, SIGNAL( triggered() ), this, SLOT( onEnvTexture() ) );
1478 toolMgr()->registerAction( aAction, EnvTextureId );
1481 aAction = new QtxAction( tr("MNU_LIGHT_SOURCE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_LIGHT_SOURCE" ) ),
1482 tr( "MNU_LIGHT_SOURCE" ), 0, this );
1483 aAction->setStatusTip( tr("DSC_LIGHT_SOURCE") );
1484 connect( aAction, SIGNAL( triggered() ), this, SLOT( onLightSource() ) );
1485 toolMgr()->registerAction( aAction, LightSourceId );
1490 \brief Create toolbar.
1492 void OCCViewer_ViewWindow::createToolBar()
1494 static const char* titles[] = {
1495 "LBL_3DTOOLBAR_LABEL",
1496 "LBL_XYTOOLBAR_LABEL",
1497 "LBL_XZTOOLBAR_LABEL",
1498 "LBL_YZTOOLBAR_LABEL",
1500 static const char* names[] = {
1501 "OCCViewer3DViewOperations",
1502 "OCCViewerXYViewOperations",
1503 "OCCViewerXZViewOperations",
1504 "OCCViewerYZViewOperations",
1506 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1507 QString( names[my2dMode] ), // name (language-independant)
1508 false ); // disable floatable toolbar
1509 if ( my2dMode != No2dMode ){
1510 toolMgr()->append( ReturnTo3dViewId, tid );
1511 toolMgr()->append( toolMgr()->separator(), tid );
1513 toolMgr()->append( DumpId, tid );
1514 toolMgr()->append( SwitchInteractionStyleId, tid );
1515 toolMgr()->append( SwitchZoomingStyleId, tid );
1516 toolMgr()->append( SwitchPreselectionId, tid );
1517 toolMgr()->append( SwitchSelectionId, tid );
1518 if( myModel->trihedronActivated() )
1519 toolMgr()->append( TrihedronShowId, tid );
1521 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1522 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1523 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1524 #if OCC_VERSION_LARGE > 0x06090000
1525 aScaleAction->insertAction( toolMgr()->action( FitSelectionId ) );
1527 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1528 toolMgr()->append( aScaleAction, tid );
1530 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1531 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1532 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1533 toolMgr()->append( aPanningAction, tid );
1535 if (my2dMode == No2dMode) {
1536 toolMgr()->append( ChangeRotationPointId, tid );
1537 toolMgr()->append( RotationId, tid );
1539 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1540 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1541 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1542 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1543 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1544 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1545 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1546 toolMgr()->append( aViewsAction, tid );
1548 toolMgr()->append( AntiClockWiseId, tid );
1549 toolMgr()->append( ClockWiseId, tid );
1551 toolMgr()->append( OrthographicId, tid );
1552 toolMgr()->append( PerspectiveId, tid );
1553 #if OCC_VERSION_LARGE > 0x06090000
1554 toolMgr()->append( StereoId, tid );
1557 toolMgr()->append( ResetId, tid );
1560 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1561 aMemAction->insertAction( toolMgr()->action( MemId ) );
1562 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1563 toolMgr()->append( aMemAction, tid );
1565 toolMgr()->append( toolMgr()->separator(), tid );
1566 toolMgr()->append( CloneId, tid );
1568 toolMgr()->append( toolMgr()->separator(), tid );
1569 toolMgr()->append( ClippingId, tid );
1570 toolMgr()->append( AxialScaleId, tid );
1571 toolMgr()->append( GraduatedAxesId, tid );
1572 toolMgr()->append( AmbientId, tid );
1574 toolMgr()->append( MaximizedId, tid );
1575 toolMgr()->append( SynchronizeId, tid );
1576 #ifdef ENABLE_RAY_TRACING
1577 toolMgr()->append( RayTracingId, tid );
1578 toolMgr()->append( EnvTextureId, tid );
1579 toolMgr()->append( LightSourceId, tid );
1584 \brief Perform 'fit all' operation.
1586 void OCCViewer_ViewWindow::onViewFitAll()
1588 myViewPort->fitAll();
1592 \brief Perform "front view" transformation.
1594 void OCCViewer_ViewWindow::onFrontView()
1596 emit vpTransformationStarted ( FRONTVIEW );
1597 Handle(V3d_View) aView3d = myViewPort->getView();
1598 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
1600 emit vpTransformationFinished ( FRONTVIEW );
1604 \brief Perform "back view" transformation.
1606 void OCCViewer_ViewWindow::onBackView()
1608 emit vpTransformationStarted ( BACKVIEW );
1609 Handle(V3d_View) aView3d = myViewPort->getView();
1610 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
1612 emit vpTransformationFinished ( BACKVIEW );
1616 \brief Perform "top view" transformation.
1618 void OCCViewer_ViewWindow::onTopView()
1620 emit vpTransformationStarted ( TOPVIEW );
1621 Handle(V3d_View) aView3d = myViewPort->getView();
1622 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
1624 emit vpTransformationFinished ( TOPVIEW );
1628 \brief Perform "bottom view" transformation.
1630 void OCCViewer_ViewWindow::onBottomView()
1632 emit vpTransformationStarted ( BOTTOMVIEW );
1633 Handle(V3d_View) aView3d = myViewPort->getView();
1634 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
1636 emit vpTransformationFinished ( BOTTOMVIEW );
1640 \brief Perform "left view" transformation.
1642 void OCCViewer_ViewWindow::onLeftView()
1644 emit vpTransformationStarted ( LEFTVIEW );
1645 Handle(V3d_View) aView3d = myViewPort->getView();
1646 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
1648 emit vpTransformationFinished ( LEFTVIEW );
1652 \brief Perform "right view" transformation.
1654 void OCCViewer_ViewWindow::onRightView()
1656 emit vpTransformationStarted ( RIGHTVIEW );
1657 Handle(V3d_View) aView3d = myViewPort->getView();
1658 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
1660 emit vpTransformationFinished ( RIGHTVIEW );
1664 \brief Rotate view 90 degrees clockwise
1666 void OCCViewer_ViewWindow::onClockWiseView()
1668 emit vpTransformationStarted ( CLOCKWISEVIEW );
1669 myViewPort->rotateXY( 90. );
1670 emit vpTransformationFinished ( CLOCKWISEVIEW );
1674 \brief Rotate view 90 degrees conterclockwise
1676 void OCCViewer_ViewWindow::onAntiClockWiseView()
1678 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1679 myViewPort->rotateXY( -90. );
1680 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1684 \brief Perform "reset view" transformation.
1686 Sets default orientation of the viewport camera.
1688 void OCCViewer_ViewWindow::onResetView()
1690 emit vpTransformationStarted( RESETVIEW );
1691 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1692 myViewPort->getView()->Reset( false );
1693 myViewPort->fitAll( false, true, false );
1694 myViewPort->getView()->SetImmediateUpdate( upd );
1695 onProjectionType(); // needed to apply projection type properly after reset
1696 myViewPort->getView()->Update();
1697 emit vpTransformationFinished( RESETVIEW );
1701 \brief Set the given projection mode.
1703 Set the given projection mode: Orthographic or Perspective.
1705 void OCCViewer_ViewWindow::onProjectionType( QAction* theAction )
1707 Handle(V3d_View) aView3d = myViewPort->getView();
1708 if ( !aView3d.IsNull() ) {
1709 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1710 if (theAction == toolMgr()->action( OrthographicId )) {
1711 myModel->setProjectionType(Orthographic);
1712 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Orthographic );
1713 aCamera->SetFOVy(45.0);
1715 else if (theAction == toolMgr()->action( PerspectiveId )) {
1716 myModel->setProjectionType(Perspective);
1717 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Perspective );
1718 aCamera->SetFOVy(30.0);
1720 #if OCC_VERSION_LARGE > 0x06090000
1721 if (toolMgr()->action( StereoId )->isChecked()) {
1722 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1723 aCamera->SetFOVy(30.0);
1732 \brief Sets Stereo projection mode.
1734 Sets Stereo projection mode.
1736 void OCCViewer_ViewWindow::onStereoType( bool activate )
1738 #if OCC_VERSION_LARGE > 0x06090000
1739 Handle(V3d_View) aView3d = myViewPort->getView();
1740 if ( !aView3d.IsNull() ) {
1741 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1743 toolMgr()->action( PerspectiveId )->setChecked(true);
1744 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1745 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(false);
1747 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1748 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1749 setStereoType( aResMgr->integerValue( "OCCViewer", "stereo_type", 0 ) );
1750 setAnaglyphFilter( aResMgr->integerValue( "OCCViewer", "anaglyph_filter", 0 ) );
1751 setReverseStereo( aResMgr->booleanValue( "OCCViewer", "reverse_stereo", false ) );
1752 setVSync( aResMgr->booleanValue( "OCCViewer", "enable_vsync", true ) );
1753 setQuadBufferSupport( aResMgr->booleanValue( "OCCViewer", "enable_quad_buffer_support", false ) );
1756 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(true);
1757 if (myModel->projectionType() == Orthographic) {
1758 toolMgr()->action( OrthographicId )->setChecked(true);
1759 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Orthographic);
1761 else if (myModel->projectionType() == Perspective) {
1762 toolMgr()->action( PerspectiveId )->setChecked(true);
1763 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1770 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1771 toolMgr()->action( StereoId )->isChecked() )
1772 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1777 \brief Restore the view.
1779 Restore the projection mode based on tool-buttons states.
1781 void OCCViewer_ViewWindow::onProjectionType()
1783 emit vpTransformationStarted( PROJECTION );
1784 if (toolMgr()->action( OrthographicId )->isChecked())
1785 setProjectionType( Orthographic );
1786 if (toolMgr()->action( PerspectiveId )->isChecked())
1787 setProjectionType( Perspective );
1788 #if OCC_VERSION_LARGE > 0x06090000
1789 if (toolMgr()->action( StereoId )->isChecked())
1790 setProjectionType( Stereo );
1792 emit vpTransformationFinished( PROJECTION );
1795 void OCCViewer_ViewWindow::setProjectionType( int mode )
1797 QtxAction* anOrthographicAction = dynamic_cast<QtxAction*>( toolMgr()->action( OrthographicId ) );
1798 QtxAction* aPerspectiveAction = dynamic_cast<QtxAction*>( toolMgr()->action( PerspectiveId ) );
1799 #if OCC_VERSION_LARGE > 0x06090000
1800 QtxAction* aStereoAction = dynamic_cast<QtxAction*>( toolMgr()->action( StereoId ) );
1804 onProjectionType( anOrthographicAction );
1807 onProjectionType( aPerspectiveAction );
1810 onStereoType( true );
1813 // update action state if method is called outside
1814 if ( mode == Orthographic && !anOrthographicAction->isChecked() ) {
1815 anOrthographicAction->setChecked( true );
1816 #if OCC_VERSION_LARGE > 0x06090000
1817 aStereoAction->setChecked( false );
1820 if ( mode == Perspective && !aPerspectiveAction->isChecked() ) {
1821 aPerspectiveAction->setChecked( true );
1822 #if OCC_VERSION_LARGE > 0x06090000
1823 aStereoAction->setChecked( false );
1826 #if OCC_VERSION_LARGE > 0x06090000
1827 if ( mode == Stereo ) {
1828 aStereoAction->setChecked( true );
1829 if ( anOrthographicAction->isEnabled() ) {
1830 anOrthographicAction->setEnabled( false );
1831 anOrthographicAction->setChecked( false );
1832 aStereoAction->setChecked( false );
1835 anOrthographicAction->setEnabled( true );
1836 aStereoAction->setChecked( false );
1837 anOrthographicAction->setChecked(myModel->projectionType() == Orthographic);
1839 if ( aPerspectiveAction->isEnabled() ) {
1840 aPerspectiveAction->setEnabled( false );
1841 aPerspectiveAction->setChecked( true );
1842 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1843 toolMgr()->action( StereoId )->isChecked() )
1844 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1847 aPerspectiveAction->setEnabled( true );
1848 aStereoAction->setChecked( false );
1849 aPerspectiveAction->setChecked(myModel->projectionType() == Perspective);
1854 if ( !anOrthographicAction->isEnabled() )
1855 anOrthographicAction->setEnabled( true );
1856 if ( !aPerspectiveAction->isEnabled() )
1857 aPerspectiveAction->setEnabled( true );
1863 \brief Perform "fit all" transformation.
1865 void OCCViewer_ViewWindow::onFitAll()
1867 emit vpTransformationStarted( FITALLVIEW );
1868 myViewPort->fitAll();
1869 emit vpTransformationFinished( FITALLVIEW );
1873 \brief Perform "fit selection" transformation.
1875 void OCCViewer_ViewWindow::onFitSelection()
1877 emit vpTransformationStarted( FITSELECTION );
1878 #if OCC_VERSION_LARGE > 0x06090000
1879 myModel->getAISContext()->FitSelected( getViewPort()->getView() );
1881 emit vpTransformationFinished( FITSELECTION );
1885 \brief Called if 'change rotation point' operation is activated.
1886 \param on action state
1888 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1892 if (!mySetRotationPointDlg)
1894 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1895 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1898 if (!mySetRotationPointDlg->isVisible())
1900 //if (mySetRotationPointDlg->IsFirstShown())
1901 if (myCurrPointType == BBCENTER)
1903 Standard_Real Xcenter, Ycenter, Zcenter;
1904 if (OCCViewer_Utilities::computeVisibleBBCenter(myViewPort->getView(), Xcenter, Ycenter, Zcenter))
1905 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1907 mySetRotationPointDlg->show();
1912 if (mySetRotationPointDlg->isVisible())
1913 mySetRotationPointDlg->hide();
1918 \brief Create one more window with same content.
1920 void OCCViewer_ViewWindow::onCloneView()
1922 SUIT_ViewWindow* vw = myManager->createViewWindow();
1924 emit viewCloned( vw );
1925 OCCViewer_ViewWindow* occVw = dynamic_cast<OCCViewer_ViewWindow*> (vw);
1926 if(occVw && occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)) {
1927 occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)->synchronize(this);
1932 Creates one more window with same content
1934 void OCCViewer_ViewWindow::onAxialScale()
1936 if ( !myScalingDlg )
1937 myScalingDlg = new OCCViewer_AxialScaleDlg( this , myModel );
1939 if ( !myScalingDlg->isVisible() )
1941 myScalingDlg->Update();
1942 myScalingDlg->show();
1947 Shows Graduated Axes dialog
1949 void OCCViewer_ViewWindow::onGraduatedAxes()
1951 myCubeAxesDlg->Update();
1952 myCubeAxesDlg->show();
1955 void OCCViewer_ViewWindow::onAmbientToogle()
1957 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
1958 viewer->InitDefinedLights();
1959 while(viewer->MoreDefinedLights())
1961 Handle(V3d_Light) light = viewer->DefinedLight();
1962 if(light->Type() != V3d_AMBIENT)
1964 Handle(V3d_View) aView3d = myViewPort->getView();
1965 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
1966 else viewer->SetLightOn(light);
1968 viewer->NextDefinedLights();
1974 \brief Store view parameters.
1976 void OCCViewer_ViewWindow::onMemorizeView()
1978 appendViewAspect( getViewParams() );
1982 \brief Restore view parameters.
1984 void OCCViewer_ViewWindow::onRestoreView()
1986 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
1987 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
1989 updateViewAspects( aDlg->parameters() );
1990 if( myRestoreFlag && aDlg->parameters().count() )
1991 performRestoring( aDlg->currentItem() );
1995 \brief Restore view parameters.
1996 \param anItem view parameters
1998 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
2000 Handle(V3d_View) aView3d = myViewPort->getView();
2002 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
2003 aView3d->SetScale( anItem.scale );
2004 aView3d->SetTwist( anItem.twist );
2005 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
2006 aView3d->SetImmediateUpdate( prev );
2007 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2008 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2009 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
2011 #if OCC_VERSION_LARGE > 0x06070100
2012 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
2014 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
2016 // "eye" and "at" require conversion to represent center panning
2017 // up direction is only available after setting angle of twist and
2018 // other view parameters
2019 aView3d->Up( anUpX, anUpY, anUpZ );
2021 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
2022 gp_Dir anUp( anUpX, anUpY, anUpZ );
2023 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
2024 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2025 gp_Dir aSide = aProj ^ anUp;
2027 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
2028 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
2030 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
2031 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2034 aView3d->SetCenter( anItem.centerX, anItem.centerY );
2037 if ( !baseParamsOnly ) {
2039 myModel->setTrihedronShown( anItem.isVisible );
2040 myModel->setTrihedronSize( anItem.size );
2042 // graduated trihedron
2043 bool anIsVisible = anItem.gtIsVisible;
2044 OCCViewer_AxisWidget::AxisData anAxisData[3];
2045 anAxisData[0].DrawName = anItem.gtDrawNameX;
2046 anAxisData[1].DrawName = anItem.gtDrawNameZ;
2047 anAxisData[2].DrawName = anItem.gtDrawNameZ;
2048 anAxisData[0].Name = anItem.gtNameX;
2049 anAxisData[1].Name = anItem.gtNameZ;
2050 anAxisData[2].Name = anItem.gtNameZ;
2051 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
2052 anItem.gtNameColorGX,
2053 anItem.gtNameColorBX );
2054 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
2055 anItem.gtNameColorGY,
2056 anItem.gtNameColorBY );
2057 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
2058 anItem.gtNameColorGZ,
2059 anItem.gtNameColorBZ );
2060 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
2061 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
2062 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
2063 anAxisData[0].NbValues = anItem.gtNbValuesX;
2064 anAxisData[1].NbValues = anItem.gtNbValuesY;
2065 anAxisData[2].NbValues = anItem.gtNbValuesZ;
2066 anAxisData[0].Offset = anItem.gtOffsetX;
2067 anAxisData[1].Offset = anItem.gtOffsetY;
2068 anAxisData[2].Offset = anItem.gtOffsetZ;
2069 anAxisData[0].Color = QColor( anItem.gtColorRX,
2072 anAxisData[1].Color = QColor( anItem.gtColorRY,
2075 anAxisData[2].Color = QColor( anItem.gtColorRZ,
2078 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
2079 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
2080 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
2081 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
2082 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
2083 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
2085 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
2086 myCubeAxesDlg->ApplyData( aView3d );
2088 } // if ( !baseParamsOnly )
2094 \brief Set restore flag.
2096 void OCCViewer_ViewWindow::setRestoreFlag()
2102 \brief Called when action "show/hide trihedron" is activated.
2104 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
2106 myModel->setTrihedronShown(show);
2110 \brief Toggles preselection (highlighting) on/off
2112 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
2114 myPreselectionEnabled = on;
2115 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
2117 // unhighlight all highlighted objects
2119 myModel->unHighlightAll( true, false );
2122 // update action state if method is called outside
2123 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2124 if ( a && a->isChecked() != on ) {
2125 a->setChecked( on );
2130 \brief Toggles selection on/off
2132 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
2134 mySelectionEnabled = on;
2135 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
2137 // update action state if method is called outside
2140 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2142 a->setEnabled( on );
2146 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
2147 if ( a && a->isChecked() != on ) {
2148 a->setChecked( on );
2153 \brief Switches "keyboard free" interaction style on/off
2155 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
2157 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
2159 // update action state if method is called outside
2160 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
2161 if ( a && a->isChecked() != on )
2162 a->setChecked( on );
2166 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
2168 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
2170 myViewPort->setAdvancedZoomingEnabled( on );
2172 // update action state if method is called outside
2173 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
2174 if ( a && a->isChecked() != on )
2175 a->setChecked( on );
2179 \brief Get current interaction style
2180 \return interaction style
2182 int OCCViewer_ViewWindow::interactionStyle() const
2184 return myInteractionStyle;
2188 \brief Set current interaction style
2189 \param theStyle interaction style
2191 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
2193 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
2197 \brief Get current zooming style
2198 \return zooming style
2200 int OCCViewer_ViewWindow::zoomingStyle() const
2202 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
2206 \brief Set current zooming style
2207 \param theStyle zooming style
2209 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
2211 onSwitchZoomingStyle( theStyle == 1 );
2215 \brief Dump view window contents to the pixmap.
2216 \return pixmap containing all scene rendered in the window
2218 QImage OCCViewer_ViewWindow::dumpView()
2220 Handle(V3d_View) view = myViewPort->getView();
2221 if ( view.IsNull() )
2224 int aWidth = myViewPort->width();
2225 int aHeight = myViewPort->height();
2227 // rnv: An old approach to dump the OCCViewer content
2228 // Now used OCCT built-in procedure.
2230 QApplication::syncX();
2231 view->Redraw(); // In order to reactivate GL context
2234 #ifndef DISABLE_GLVIEWER
2235 OpenGLUtils_FrameBuffer aFrameBuffer;
2236 if( aFrameBuffer.init( aWidth, aHeight ) )
2238 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
2240 glPushAttrib( GL_VIEWPORT_BIT );
2241 glViewport( 0, 0, aWidth, aHeight );
2242 aFrameBuffer.bind();
2247 aFrameBuffer.unbind();
2250 aFrameBuffer.bind();
2251 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
2252 aFrameBuffer.unbind();
2254 anImage = anImage.rgbSwapped();
2255 anImage = anImage.mirrored();
2258 // if frame buffers are unsupported, use old functionality
2261 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
2263 QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
2265 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
2271 view->ToPixMap(aPix,aWidth, aHeight,Graphic3d_BT_RGBA);
2273 QImage anImage( aPix.Data(), aWidth, aHeight, QImage::Format_ARGB32 );
2274 anImage = anImage.mirrored();
2278 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
2279 const QString& fileName,
2280 const QString& format )
2283 QApplication::setOverrideCursor( Qt::WaitCursor );
2284 if ( format != "PS" && format != "EPS")
2285 res = myViewPort->getView()->Dump( fileName.toStdString().c_str() );
2287 #if OCC_VERSION_MAJOR < 7
2288 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
2290 Handle(Graphic3d_CView) a3dView = myViewPort->getView()->View();
2294 res = a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
2295 else if (format == "EPS")
2296 res = a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
2298 QApplication::restoreOverrideCursor();
2303 QString OCCViewer_ViewWindow::filter() const
2305 return tr( "OCC_IMAGE_FILES" );
2310 \brief Set parameters of the cutting plane
2311 \param on if \c true, cutting plane is enabled
2312 \param x X position of plane point
2313 \param y Y position of plane point
2314 \param z Z position of plane point
2315 \param dx X coordinate of plane normal
2316 \param dy Y coordinate of plane normal
2317 \param dz Z coordinate of plane normal
2319 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2320 const double dx, const double dy, const double dz )
2322 Handle(V3d_View) view = myViewPort->getView();
2323 if ( view.IsNull() )
2327 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2329 // try to use already existing plane or create a new one
2330 Handle(V3d_Plane) clipPlane;
2332 // calculate new a,b,c,d values for the plane
2333 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2335 pln.Coefficients(a, b, c, d);
2336 #if OCC_VERSION_LARGE > 0x07000000
2337 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2338 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2339 if(aPlanes->Size() > 0 ) {
2341 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2342 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2343 if(aPlanes.Size() > 0 ) {
2345 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2346 aClipPlane->SetEquation(pln);
2347 aClipPlane->SetOn(Standard_True);
2349 view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2353 #if OCC_VERSION_LARGE > 0x07000000
2354 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2355 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2357 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2358 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2360 for( ;anIter.More();anIter.Next() ){
2361 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2362 aClipPlane->SetOn(Standard_False);
2370 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2372 gp_Dir aDir = pln.Axis().Direction();
2373 gp_Pnt aPnt = pln.Location();
2374 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2379 \brief Check if any cutting plane is enabled
2380 \return \c true if at least one cutting plane is enabled
2382 bool OCCViewer_ViewWindow::isCuttingPlane()
2384 Handle(V3d_View) view = myViewPort->getView();
2386 #if OCC_VERSION_LARGE > 0x07000000
2387 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2388 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2390 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2391 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2393 for( ;anIter.More();anIter.Next() ) {
2394 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2395 if(aClipPlane->IsOn()) {
2404 \brief Get the visual parameters of the view window.
2405 \return visual parameters of view window
2407 viewAspect OCCViewer_ViewWindow::getViewParams() const
2409 double projX, projY, projZ, twist;
2410 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2411 double aScaleX, aScaleY, aScaleZ;
2413 Handle(V3d_View) aView3d = myViewPort->getView();
2415 aView3d->Proj( projX, projY, projZ );
2416 aView3d->At( atX, atY, atZ );
2417 aView3d->Eye( eyeX, eyeY, eyeZ );
2418 twist = aView3d->Twist();
2420 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2422 bool isShown = myModel->isTrihedronVisible();
2423 double size = myModel->trihedronSize();
2425 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2428 params.scale = aView3d->Scale();
2429 params.projX = projX;
2430 params.projY = projY;
2431 params.projZ = projZ;
2432 params.twist = twist;
2439 params.scaleX = aScaleX;
2440 params.scaleY = aScaleY;
2441 params.scaleZ = aScaleZ;
2442 params.name = aName;
2443 params.isVisible= isShown;
2446 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2447 aView3d->Center( params.centerX, params.centerY );
2450 // graduated trihedron
2451 bool anIsVisible = false;
2452 OCCViewer_AxisWidget::AxisData anAxisData[3];
2453 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2455 params.gtIsVisible = anIsVisible;
2456 params.gtDrawNameX = anAxisData[0].DrawName;
2457 params.gtDrawNameY = anAxisData[1].DrawName;
2458 params.gtDrawNameZ = anAxisData[2].DrawName;
2459 params.gtNameX = anAxisData[0].Name;
2460 params.gtNameY = anAxisData[1].Name;
2461 params.gtNameZ = anAxisData[2].Name;
2462 params.gtNameColorRX = anAxisData[0].NameColor.red();
2463 params.gtNameColorGX = anAxisData[0].NameColor.green();
2464 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2465 params.gtNameColorRY = anAxisData[1].NameColor.red();
2466 params.gtNameColorGY = anAxisData[1].NameColor.green();
2467 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2468 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2469 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2470 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2471 params.gtDrawValuesX = anAxisData[0].DrawValues;
2472 params.gtDrawValuesY = anAxisData[1].DrawValues;
2473 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2474 params.gtNbValuesX = anAxisData[0].NbValues;
2475 params.gtNbValuesY = anAxisData[1].NbValues;
2476 params.gtNbValuesZ = anAxisData[2].NbValues;
2477 params.gtOffsetX = anAxisData[0].Offset;
2478 params.gtOffsetY = anAxisData[1].Offset;
2479 params.gtOffsetZ = anAxisData[2].Offset;
2480 params.gtColorRX = anAxisData[0].Color.red();
2481 params.gtColorGX = anAxisData[0].Color.green();
2482 params.gtColorBX = anAxisData[0].Color.blue();
2483 params.gtColorRY = anAxisData[1].Color.red();
2484 params.gtColorGY = anAxisData[1].Color.green();
2485 params.gtColorBY = anAxisData[1].Color.blue();
2486 params.gtColorRZ = anAxisData[2].Color.red();
2487 params.gtColorGZ = anAxisData[2].Color.green();
2488 params.gtColorBZ = anAxisData[2].Color.blue();
2489 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2490 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2491 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2492 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2493 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2494 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2500 \brief Get visual parameters of this view window.
2501 \return visual parameters of view window
2503 QString OCCViewer_ViewWindow::getVisualParameters()
2505 viewAspect params = getViewParams();
2509 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2510 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2511 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
2512 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
2514 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2515 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2516 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2517 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2518 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2519 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2520 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2521 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2522 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2523 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2524 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2525 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2526 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2527 data << QString( "isVisible=%1" ).arg( params.isVisible );
2528 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2530 ClipPlanesList aPlanes = myModel->getClipPlanes();
2531 for ( int i=0; i < aPlanes.size(); i++ )
2533 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2534 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2535 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2536 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2537 switch ( aPlane.Mode )
2539 case OCCViewer_ClipPlane::Absolute :
2541 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2543 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2545 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2546 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2547 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2551 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2556 case OCCViewer_ClipPlane::Relative :
2558 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2559 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2560 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2565 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2566 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2567 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2568 data << ClippingPlane;
2571 // graduated trihedron
2572 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2573 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2574 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2575 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2576 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2577 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2578 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2579 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2580 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2581 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2582 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2583 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2584 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2585 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2586 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2587 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2588 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2589 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2590 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2591 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2592 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2593 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2594 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2595 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2596 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2597 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2598 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2599 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2600 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2601 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2602 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2603 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2604 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2605 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2606 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2607 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2608 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2609 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2610 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2611 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2613 // ray tracing parameters
2614 Graphic3d_RenderingParams rendParams = this->getViewPort()->getView()->RenderingParams();
2615 if ( rendParams.Method == Graphic3d_RM_RAYTRACING ) {
2616 QString RayTracing = "rayTracing=";
2617 RayTracing += QString( "rtDepth~%1;" ).arg( rendParams.RaytracingDepth );
2618 RayTracing += QString( "rtReflection~%1;" ).arg( rendParams.IsReflectionEnabled );
2619 RayTracing += QString( "rtAntialiasing~%1;" ).arg( rendParams.IsAntialiasingEnabled );
2620 RayTracing += QString( "rtShadow~%1;" ).arg( rendParams.IsShadowEnabled );
2621 RayTracing += QString( "rtTransShadow~%1;" ).arg( rendParams.IsTransparentShadowEnabled );
2625 // environment texture parameters
2626 Handle(Graphic3d_TextureEnv) aTexture = this->getViewPort()->getView()->TextureEnv();
2627 if ( !aTexture.IsNull() ) {
2628 QString EnvTexture = "envTexture=";
2629 if ( aTexture->Name() == Graphic3d_NOT_ENV_UNKNOWN ) {
2630 TCollection_AsciiString aFileName;
2631 aTexture->Path().SystemName( aFileName );
2632 EnvTexture += QString( "etFile~%1;" ).arg( aFileName.ToCString() );
2635 EnvTexture += QString( "etNumber~%1;" ).arg( aTexture->Name() );
2639 // light source parameters
2640 myModel->getViewer3d()->InitDefinedLights();
2641 while ( myModel->getViewer3d()->MoreDefinedLights() )
2643 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2644 if ( aLight->Type() != V3d_AMBIENT ) {
2645 QString LightSource = QString( "lightSource=" );
2646 LightSource += QString( "lightType~%1;" ).arg( aLight->Type() );
2648 if ( aLight->Type() == V3d_DIRECTIONAL )
2649 Handle(V3d_DirectionalLight)::DownCast( aLight )->Direction( aX, aY, aZ );
2650 else if ( aLight->Type() == V3d_POSITIONAL )
2651 Handle(V3d_PositionalLight)::DownCast( aLight )->Position( aX, aY, aZ );
2652 LightSource += QString( "lightX~%1;" ).arg( aX );
2653 LightSource += QString( "lightY~%1;" ).arg( aY );
2654 LightSource += QString( "lightZ~%1;" ).arg( aZ );
2655 LightSource += QString( "lightColorR~%1;" ).arg( aLight->Color().Red() );
2656 LightSource += QString( "lightColorG~%1;" ).arg( aLight->Color().Green() );
2657 LightSource += QString( "lightColorB~%1;" ).arg( aLight->Color().Blue() );
2658 LightSource += QString( "lightHeadlight~%1;" ).arg( aLight->Headlight() );
2659 data << LightSource;
2661 myModel->getViewer3d()->NextDefinedLights();
2664 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2665 data << QString( "background=%1" ).arg( bg );
2667 return data.join("*");
2671 \brief Restore visual parameters of the view window.
2672 \param parameters visual parameters of view window
2674 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2677 ClipPlanesList aClipPlanes;
2678 QStringList data = parameters.split( '*' );
2679 Qtx::BackgroundData bgData;
2680 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2682 foreach( QString param, data ) {
2683 QString paramName = param.section( '=', 0, 0 ).trimmed();
2684 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2685 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2686 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2687 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2688 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2689 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2690 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2691 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2692 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2693 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2694 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2695 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2696 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2697 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2698 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2699 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2700 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2701 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2702 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2703 else if ( paramName.contains( "ClippingPlane" ) )
2705 QStringList ClipPlaneData = paramValue.split( ';' );
2706 OCCViewer_ClipPlane aPlane;
2707 foreach( QString ClipPlaneParam, ClipPlaneData )
2709 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2710 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2711 if ( ClipPlane_paramName == "Mode" )
2713 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2715 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2716 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2717 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2718 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2721 switch ( aPlane.Mode )
2723 case OCCViewer_ClipPlane::Absolute :
2724 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2725 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2726 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2727 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2728 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2731 case OCCViewer_ClipPlane::Relative :
2732 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2733 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2734 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2739 aClipPlanes.push_back(aPlane);
2741 // graduated trihedron
2742 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2743 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2744 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2745 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2746 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2747 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2748 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2749 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2750 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2751 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2752 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2753 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2754 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2755 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2756 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2757 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2758 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2759 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2760 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2761 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2762 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2763 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2764 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2765 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2766 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2767 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2768 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2769 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2770 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2771 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2772 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2773 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2774 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2775 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2776 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2777 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2778 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2779 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2780 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2781 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2782 else if ( paramName == "rayTracing" )
2784 Graphic3d_RenderingParams& rendParams = this->getViewPort()->getView()->ChangeRenderingParams();
2785 rendParams.Method = Graphic3d_RM_RAYTRACING;
2786 QStringList rtData = paramValue.split( ';' );
2787 foreach( QString rtParam, rtData )
2789 QString rt_paramName = rtParam.section( '~', 0, 0 ).trimmed();
2790 QString rt_paramValue = rtParam.section( '~', 1, 1 ).trimmed();
2791 if ( rt_paramName == "rtDepth" ) rendParams.RaytracingDepth = rt_paramValue.toInt();
2792 else if ( rt_paramName == "rtReflection" ) rendParams.IsReflectionEnabled = rt_paramValue.toInt();
2793 else if ( rt_paramName == "rtAntialiasing" ) rendParams.IsAntialiasingEnabled = rt_paramValue.toInt();
2794 else if ( rt_paramName == "rtShadow" ) rendParams.IsShadowEnabled = rt_paramValue.toInt();
2795 else if ( rt_paramName == "rtTransShadow" ) rendParams.IsTransparentShadowEnabled = rt_paramValue.toInt();
2798 else if ( paramName == "envTexture" )
2800 Handle(Graphic3d_TextureEnv) aTexture;
2801 QStringList etData = paramValue.split( ';' );
2802 foreach( QString etParam, etData )
2804 QString et_paramName = etParam.section( '~', 0, 0 ).trimmed();
2805 QString et_paramValue = etParam.section( '~', 1, 1 ).trimmed();
2806 if ( et_paramName == "etNumber" )
2807 aTexture = new Graphic3d_TextureEnv( Graphic3d_NameOfTextureEnv( et_paramValue.toInt() ) );
2808 else if ( et_paramName == "etFile" )
2809 aTexture = new Graphic3d_TextureEnv( TCollection_AsciiString( et_paramValue.toStdString().c_str() ) );
2810 Handle(V3d_View) aView = this->getViewPort()->getView();
2811 aView->SetTextureEnv( aTexture );
2812 #if OCC_VERSION_LARGE <= 0x07000000
2813 aView->SetSurfaceDetail( V3d_TEX_ENVIRONMENT );
2817 else if ( paramName == "lightSource" )
2819 myModel->getViewer3d()->InitDefinedLights();
2820 while ( myModel->getViewer3d()->MoreDefinedLights() )
2822 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2823 if( aLight->Type() != V3d_AMBIENT ) {
2824 myModel->getViewer3d()->DelLight( aLight );
2825 myModel->getViewer3d()->InitDefinedLights();
2827 myModel->getViewer3d()->NextDefinedLights();
2832 V3d_TypeOfLight aType;
2834 QStringList lsData = paramValue.split( ';' );
2835 foreach( QString lsParam, lsData )
2837 QString ls_paramName = lsParam.section( '~', 0, 0 ).trimmed();
2838 QString ls_paramValue = lsParam.section( '~', 1, 1 ).trimmed();
2839 if ( ls_paramName == "lightType" ) aType = V3d_TypeOfLight( ls_paramValue.toInt() );
2840 else if ( ls_paramName == "lightX" ) aX = ls_paramValue.toDouble();
2841 else if ( ls_paramName == "lightY" ) aY = ls_paramValue.toDouble();
2842 else if ( ls_paramName == "lightZ" ) aZ = ls_paramValue.toDouble();
2843 else if ( ls_paramName == "lightColorR" ) cR = ls_paramValue.toDouble();
2844 else if ( ls_paramName == "lightColorG" ) cG = ls_paramValue.toDouble();
2845 else if ( ls_paramName == "lightColorB" ) cB = ls_paramValue.toDouble();
2846 else if ( ls_paramName == "lightHeadlight" ) isHeadlight = ls_paramValue.toInt();
2848 Quantity_Color aColor = Quantity_Color( cR, cG, cB, Quantity_TOC_RGB );
2849 if( aType == V3d_DIRECTIONAL ) {
2850 Handle(V3d_DirectionalLight) aLight = new V3d_DirectionalLight( myModel->getViewer3d() );
2851 aLight->SetDirection( aX, aY, aZ );
2852 aLight->SetColor( aColor );
2853 aLight->SetHeadlight( isHeadlight );
2854 myModel->getViewer3d()->SetLightOn( aLight );
2856 else if( aType == V3d_POSITIONAL ) {
2857 Handle(V3d_PositionalLight) aLight = new V3d_PositionalLight( myModel->getViewer3d(), aX, aY, aZ, aColor.Name() );
2858 aLight->SetHeadlight( isHeadlight );
2859 myModel->getViewer3d()->SetLightOn( aLight );
2862 else if ( paramName == "background" ) {
2863 QString bg = paramValue.replace( "$", "=" );
2864 bgData = Qtx::stringToBackground( bg );
2868 else // old format - "1.000e+00*0.000e+00..."
2871 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2872 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2873 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2874 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2875 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2876 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2877 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
2878 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2879 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2880 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
2881 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2882 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2883 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2884 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
2885 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
2886 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
2887 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
2888 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
2890 performRestoring( params );
2891 setBackground( bgData );
2892 myModel->setClipPlanes(aClipPlanes);
2896 \brief Handle show event.
2898 Emits Show() signal.
2900 \param theEvent show event
2902 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2904 emit Show( theEvent );
2908 \brief Handle hide event.
2910 Emits Hide() signal.
2912 \param theEvent hide event
2914 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
2916 emit Hide( theEvent );
2921 Save old cursor. [ protected ]
2923 void OCCViewer_ViewWindow::saveCursor()
2925 QCursor* aCursor = NULL;
2927 aCursor = myViewPort->getDefaultCursor();
2928 myCursor = ( aCursor ? *aCursor : cursor() );
2933 Creates default sketcher. [ virtual protected ]
2935 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
2938 return new OCCViewer_RectSketcher( this, type );
2939 if ( type == Polygon )
2940 return new OCCViewer_PolygonSketcher( this, type );
2944 void OCCViewer_ViewWindow::initSketchers()
2946 if ( mySketchers.isEmpty() )
2948 mySketchers.append( createSketcher( Rect ) );
2949 mySketchers.append( createSketcher( Polygon ) );
2953 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
2955 OCCViewer_ViewSketcher* sketcher = 0;
2956 QList<OCCViewer_ViewSketcher*>::Iterator it;
2957 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
2959 OCCViewer_ViewSketcher* sk = (*it);
2960 if ( sk->type() == typ )
2967 Handles requests for sketching in the active view. [ virtual public ]
2969 void OCCViewer_ViewWindow::activateSketching( int type )
2971 OCCViewer_ViewPort3d* vp = getViewPort();
2975 if ( !vp->isSketchingEnabled() )
2978 /* Finish current sketching */
2979 if ( type == NoSketching )
2983 onSketchingFinished();
2984 mypSketcher->deactivate();
2988 /* Activate new sketching */
2991 activateSketching( NoSketching ); /* concurrency not suported */
2992 mypSketcher = getSketcher( type );
2995 mypSketcher->activate();
2996 onSketchingStarted();
3002 Unhilights detected entities. [ virtual protected ]
3004 void OCCViewer_ViewWindow::onSketchingStarted()
3009 Selection by rectangle or polygon. [ virtual protected ]
3011 void OCCViewer_ViewWindow::onSketchingFinished()
3013 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
3014 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
3016 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
3017 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
3018 switch( mypSketcher->type() )
3022 QRect* aRect = (QRect*)mypSketcher->data();
3025 int aLeft = aRect->left();
3026 int aRight = aRect->right();
3027 int aTop = aRect->top();
3028 int aBottom = aRect->bottom();
3032 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
3034 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
3040 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
3043 int size = aPolygon->size();
3044 TColgp_Array1OfPnt2d anArray( 1, size );
3046 QPolygon::Iterator it = aPolygon->begin();
3047 QPolygon::Iterator itEnd = aPolygon->end();
3048 for( int index = 1; it != itEnd; ++it, index++ )
3050 QPoint aPoint = *it;
3051 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
3055 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
3057 ic->Select( anArray, getViewPort()->getView(), Standard_False );
3065 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
3066 aViewMgr->getOCCViewer()->performSelectionChanged();
3070 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
3075 bool OCCViewer_ViewWindow::transformRequested() const
3077 return ( myOperation != NOTHING );
3080 bool OCCViewer_ViewWindow::transformInProcess() const
3082 return myEventStarted;
3085 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
3087 myEventStarted = bOn;
3091 Set enabled state of transformation (rotate, zoom, etc)
3093 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
3095 if ( id != NOTHING ) myStatus.insert( id, on );
3099 \return enabled state of transformation (rotate, zoom, etc)
3101 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
3103 return myStatus.contains( id ) ? myStatus[ id ] : true;
3106 void OCCViewer_ViewWindow::onMaximizedView()
3108 setMaximized(!isMaximized());
3111 void OCCViewer_ViewWindow::returnTo3dView()
3113 setReturnedTo3dView( true );
3116 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
3118 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
3119 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
3120 if ( !isVisible3dView )
3121 toolMgr()->show( ReturnTo3dViewId );
3123 toolMgr()->hide( ReturnTo3dViewId );
3124 if ( isVisible3dView ) emit returnedTo3d( );
3128 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
3130 QAction* anAction = toolMgr()->action( MaximizedId );
3131 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
3132 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
3134 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
3135 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
3136 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
3137 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
3138 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
3140 emit maximized( this, true );
3144 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
3145 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
3146 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
3147 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
3148 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
3150 emit maximized( this, false );
3155 bool OCCViewer_ViewWindow::isMaximized() const
3157 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
3160 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
3162 IsSketcherStyle = enable;
3165 bool OCCViewer_ViewWindow::isSketcherStyle() const
3167 return IsSketcherStyle;
3171 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
3176 int OCCViewer_ViewWindow::projectionType() const
3178 int mode = Orthographic;
3179 Handle(V3d_View) aView3d = myViewPort->getView();
3180 if ( !aView3d.IsNull() ) {
3181 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3182 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Perspective)
3184 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Orthographic)
3185 mode = Orthographic;
3186 #if OCC_VERSION_LARGE > 0x06090000
3187 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
3194 void OCCViewer_ViewWindow::setStereoType( int type )
3196 Handle(V3d_View) aView3d = myViewPort->getView();
3197 if ( !aView3d.IsNull() ) {
3198 #if OCC_VERSION_LARGE > 0x06090000
3199 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3200 aParams->StereoMode = (Graphic3d_StereoMode)type;
3205 int OCCViewer_ViewWindow::stereoType() const
3207 int type = QuadBuffer;
3208 Handle(V3d_View) aView3d = myViewPort->getView();
3209 if ( !aView3d.IsNull() ) {
3210 #if OCC_VERSION_LARGE > 0x06090000
3211 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3212 type = (OCCViewer_ViewWindow::StereoType)aParams->StereoMode;
3218 void OCCViewer_ViewWindow::setAnaglyphFilter( int type )
3220 Handle(V3d_View) aView3d = myViewPort->getView();
3221 if ( !aView3d.IsNull() ) {
3222 #if OCC_VERSION_LARGE > 0x06090000
3223 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3224 if (type == RedCyan)
3225 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
3226 if (type == YellowBlue)
3227 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
3228 if (type == GreenMagenta)
3229 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
3234 int OCCViewer_ViewWindow::anaglyphFilter() const
3237 Handle(V3d_View) aView3d = myViewPort->getView();
3238 if ( !aView3d.IsNull() ) {
3239 #if OCC_VERSION_LARGE > 0x06090000
3240 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3241 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized)
3243 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized)
3245 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple)
3246 type = GreenMagenta;
3252 void OCCViewer_ViewWindow::setStereographicFocus( int type, double value )
3254 Handle(V3d_View) aView3d = myViewPort->getView();
3255 if ( !aView3d.IsNull() ) {
3256 #if OCC_VERSION_LARGE > 0x06090000
3257 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3258 aCamera->SetZFocus( (Graphic3d_Camera::FocusType) type, value );
3263 int OCCViewer_ViewWindow::stereographicFocusType() const
3265 int type = Relative;
3266 Handle(V3d_View) aView3d = myViewPort->getView();
3267 if ( !aView3d.IsNull() ) {
3268 #if OCC_VERSION_LARGE > 0x06090000
3269 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3270 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->ZFocusType();
3276 double OCCViewer_ViewWindow::stereographicFocusValue() const
3279 Handle(V3d_View) aView3d = myViewPort->getView();
3280 if ( !aView3d.IsNull() ) {
3281 #if OCC_VERSION_LARGE > 0x06090000
3282 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3283 value = aCamera->ZFocus();
3289 void OCCViewer_ViewWindow::setInterocularDistance( int type, double value )
3291 Handle(V3d_View) aView3d = myViewPort->getView();
3292 if ( !aView3d.IsNull() ) {
3293 #if OCC_VERSION_LARGE > 0x06090000
3294 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3295 aCamera->SetIOD( (Graphic3d_Camera::IODType) type, value );
3300 int OCCViewer_ViewWindow::interocularDistanceType() const
3302 int type = Relative;
3303 Handle(V3d_View) aView3d = myViewPort->getView();
3304 if ( !aView3d.IsNull() ) {
3305 #if OCC_VERSION_LARGE > 0x06090000
3306 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3307 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->GetIODType();
3313 double OCCViewer_ViewWindow::interocularDistanceValue() const
3315 double value = 0.05;
3316 Handle(V3d_View) aView3d = myViewPort->getView();
3317 if ( !aView3d.IsNull() ) {
3318 #if OCC_VERSION_LARGE > 0x06090000
3319 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3320 value = aCamera->IOD();
3326 void OCCViewer_ViewWindow::setReverseStereo( bool reverse )
3328 Handle(V3d_View) aView3d = myViewPort->getView();
3329 if ( !aView3d.IsNull() ) {
3330 #if OCC_VERSION_LARGE > 0x06090000
3331 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3332 aParams->ToReverseStereo = reverse;
3337 bool OCCViewer_ViewWindow::isReverseStereo() const
3339 int reverse = false;
3340 Handle(V3d_View) aView3d = myViewPort->getView();
3341 if ( !aView3d.IsNull() ) {
3342 #if OCC_VERSION_LARGE > 0x06090000
3343 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3344 reverse = aParams->ToReverseStereo;
3350 void OCCViewer_ViewWindow::setVSync( bool enable )
3352 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3353 if ( !anIntCont.IsNull() ) {
3354 #if OCC_VERSION_LARGE > 0x06090000
3355 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3356 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3357 aCaps->swapInterval = enable;
3362 bool OCCViewer_ViewWindow::isVSync() const
3365 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3366 if ( !anIntCont.IsNull() ) {
3367 #if OCC_VERSION_LARGE > 0x06090000
3368 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3369 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3370 enable = aCaps->swapInterval;
3376 void OCCViewer_ViewWindow::setQuadBufferSupport( bool enable )
3378 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3379 if ( !anIntCont.IsNull() ) {
3380 #if OCC_VERSION_LARGE > 0x06090000
3381 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3382 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3383 aCaps->contextStereo = enable;
3388 bool OCCViewer_ViewWindow::isQuadBufferSupport() const
3391 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3392 if ( !anIntCont.IsNull() ) {
3393 #if OCC_VERSION_LARGE > 0x06090000
3394 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3395 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3396 enable = aCaps->contextStereo;
3403 bool OCCViewer_ViewWindow::isOpenGlStereoSupport() const
3405 GLboolean support[1];
3406 glGetBooleanv (GL_STEREO, support);
3413 QColor OCCViewer_ViewWindow::backgroundColor() const
3415 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
3419 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
3421 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
3424 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
3426 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
3429 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
3431 if ( myViewPort ) myViewPort->setBackground( theBackground );
3434 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
3436 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
3442 void OCCViewer_ViewWindow::clearViewAspects()
3444 myViewAspects.clear();
3448 \return const reference to list of view aspects
3450 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
3452 return myViewAspects;
3456 Appends new view aspect
3457 \param aParams - new view aspects
3459 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
3461 myViewAspects.append( aParams );
3465 Replaces old view aspects by new ones
3466 \param aViewList - list of new view aspects
3468 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
3470 myViewAspects = aViewList;
3474 Get camera properties for the OCC view window.
3475 \return shared pointer on camera properties.
3477 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
3479 SUIT_CameraProperties aProps;
3481 Handle(V3d_View) aSourceView = getViewPort()->getView();
3482 if ( aSourceView.IsNull() )
3485 if ( get2dMode() == No2dMode ) {
3486 aProps.setDimension( SUIT_CameraProperties::Dim3D );
3489 aProps.setDimension( SUIT_CameraProperties::Dim2D );
3490 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
3493 // read common properites of the view
3494 Standard_Real anUp[3];
3495 Standard_Real anAt[3];
3496 Standard_Real anEye[3];
3497 Standard_Real aProj[3];
3498 Standard_Real anAxialScale[3];
3500 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
3501 aSourceView->At( anAt[0], anAt[1], anAt[2] );
3502 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
3503 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3505 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3506 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
3508 #if OCC_VERSION_LARGE > 0x06070100
3509 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
3511 // store camera properties "as is": it is up to synchronized
3512 // view classes to provide necessary property conversion.
3513 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
3514 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
3516 if ( aSourceView->Camera()->IsOrthographic() )
3518 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
3519 aProps.setViewAngle( 0.0 );
3523 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
3524 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
3526 aProps.setMappingScale( aSourceView->Camera()->Scale() );
3528 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
3530 // generate view orientation matrix for transforming OCC projection reference point
3531 // into a camera (eye) position.
3532 gp_Dir aLeftDir = gp_Dir( anUp[0], anUp[1], anUp[2] ) ^ gp_Dir( aProj[0], aProj[1], aProj[2] );
3535 aTrsf.SetValue( 1, 1, aLeftDir.X() );
3536 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
3537 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
3539 aTrsf.SetValue( 1, 2, anUp[0] );
3540 aTrsf.SetValue( 2, 2, anUp[1] );
3541 aTrsf.SetValue( 3, 2, anUp[2] );
3543 aTrsf.SetValue( 1, 3, aProj[0] );
3544 aTrsf.SetValue( 2, 3, aProj[1] );
3545 aTrsf.SetValue( 3, 3, aProj[2] );
3547 aTrsf.SetValue( 1, 4, anAt[0] );
3548 aTrsf.SetValue( 2, 4, anAt[1] );
3549 aTrsf.SetValue( 3, 4, anAt[2] );
3551 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
3553 // transform to world-space coordinate system
3554 gp_XYZ aPosition( aProjRef.X(), aProjRef.Y(), aCameraDepth );
3555 aTrsf.Transforms( aPosition );
3557 // compute focal point
3558 double aFocalPoint[3];
3560 aFocalPoint[0] = aPosition.X() - aProj[0] * aCameraDepth;
3561 aFocalPoint[1] = aPosition.Y() - aProj[1] * aCameraDepth;
3562 aFocalPoint[2] = aPosition.Z() - aProj[2] * aCameraDepth;
3564 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3565 aProps.setPosition( aPosition.X(), aPosition.Y(), aPosition.Z() );
3567 Standard_Real aViewScale[2];
3568 aSourceView->Size( aViewScale[0], aViewScale[1] );
3569 aProps.setMappingScale( aViewScale[1] );
3577 This implementation synchronizes OCC view's camera propreties.
3579 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
3581 bool blocked = blockSignals( true );
3583 SUIT_CameraProperties aProps = theView->cameraProperties();
3584 if ( !cameraProperties().isCompatible( aProps ) ) {
3585 // other view, this one is being currently synchronized to, seems has become incompatible
3586 // we have to break synchronization
3591 Handle(V3d_View) aDestView = getViewPort()->getView();
3593 aDestView->SetImmediateUpdate( Standard_False );
3596 double aPosition[3];
3597 double aFocalPoint[3];
3598 double anAxialScale[3];
3600 // get common properties
3601 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3602 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
3603 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3604 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3606 #if OCC_VERSION_LARGE > 0x06070100
3607 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3608 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
3609 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3610 aDestView->Camera()->SetScale( aProps.getMappingScale() );
3612 gp_Dir aProjDir( aPosition[0] - aFocalPoint[0],
3613 aPosition[1] - aFocalPoint[1],
3614 aPosition[2] - aFocalPoint[2] );
3616 // get custom view translation
3617 Standard_Real aTranslation[3];
3618 aDestView->At( aTranslation[0], aTranslation[1], aTranslation[2] );
3620 gp_Dir aLeftDir = gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] )
3621 ^ gp_Dir( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
3624 aTrsf.SetValue( 1, 1, aLeftDir.X() );
3625 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
3626 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
3628 aTrsf.SetValue( 1, 2, anUpDir[0] );
3629 aTrsf.SetValue( 2, 2, anUpDir[1] );
3630 aTrsf.SetValue( 3, 2, anUpDir[2] );
3632 aTrsf.SetValue( 1, 3, aProjDir.X() );
3633 aTrsf.SetValue( 2, 3, aProjDir.Y() );
3634 aTrsf.SetValue( 3, 3, aProjDir.Z() );
3636 aTrsf.SetValue( 1, 4, aTranslation[0] );
3637 aTrsf.SetValue( 2, 4, aTranslation[1] );
3638 aTrsf.SetValue( 3, 4, aTranslation[2] );
3641 // transform to view-space coordinate system
3642 gp_XYZ aProjRef( aPosition[0], aPosition[1], aPosition[2] );
3643 aTrsf.Transforms( aProjRef );
3645 // set view camera properties using low-level approach. this is done
3646 // in order to avoid interference with static variables in v3d view used
3647 // when rotation is in process in another view.
3648 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
3649 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
3651 Graphic3d_Vector aMappingProj( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
3652 Graphic3d_Vector aMappingUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3654 aMappingProj.Normalize();
3655 aMappingUp.Normalize();
3657 anOrientation.SetViewReferencePlane( aMappingProj );
3658 anOrientation.SetViewReferenceUp( aMappingUp );
3660 aDestView->SetViewMapping( aMapping );
3661 aDestView->SetViewOrientation( anOrientation );
3664 aDestView->SetCenter( aProjRef.X(), aProjRef.Y() );
3666 // set mapping scale
3667 double aMapScaling = aProps.getMappingScale();
3668 Standard_Real aWidth, aHeight;
3669 aDestView->Size( aWidth, aHeight );
3670 aDestView->SetSize ( aWidth > aHeight ? aMapScaling * (aWidth / aHeight) : aMapScaling );
3673 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3674 #if OCC_VERSION_LARGE <= 0x07000000
3675 aDestView->ZFitAll();
3677 aDestView->SetImmediateUpdate( Standard_True );
3678 aDestView->Redraw();
3680 blockSignals( blocked );
3684 \brief Indicates whether preselection is enabled
3685 \return true if preselection is enabled
3687 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
3689 return myPreselectionEnabled;
3693 \brief Enables/disables preselection
3694 \param theIsToEnable if true - preselection will be enabled
3696 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
3698 onSwitchPreselection( theIsToEnable );
3702 \brief Indicates whether selection is enabled
3703 \return true if selection is enabled
3705 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3707 return mySelectionEnabled;
3711 \brief Enables/disables selection
3712 \param theIsToEnable if true - selection will be enabled
3714 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3716 onSwitchSelection( theIsToEnable );
3721 \brief called if clipping operation is activated / deactivated.
3723 Enables/disables clipping plane displaying.
3725 \parma on action state
3727 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3729 if(!myModel) return;
3730 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3733 if (!aClippingDlg) {
3734 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3735 myModel->setClippingDlg(aClippingDlg);
3737 if (!aClippingDlg->isVisible())
3738 aClippingDlg->show();
3740 if ( aClippingDlg ) {
3741 aClippingDlg->close();
3742 myModel->setClippingDlg(0);
3746 SUIT_ViewManager* mgr = getViewManager();
3748 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3749 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3750 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3751 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3753 QAction* a = toolMgr()->action( ClippingId );
3755 if(theIsOn != a->isChecked()){
3756 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3757 a->setChecked(theIsOn);
3758 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3765 void OCCViewer_ViewWindow::onRayTracing()
3767 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_RayTracingDlg::getName() ) ) {
3768 QDialog* aDlg = new OCCViewer_RayTracingDlg( this );
3774 void OCCViewer_ViewWindow::onEnvTexture()
3776 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_EnvTextureDlg::getName() ) ) {
3777 QDialog* aDlg = new OCCViewer_EnvTextureDlg( this );
3783 void OCCViewer_ViewWindow::onLightSource()
3785 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_LightSourceDlg::getName() ) ) {
3786 QDialog* aDlg = new OCCViewer_LightSourceDlg( this, myModel );