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>
119 #include <OpenGL/gl.h>
124 // To avoid conflict between KeyPress from the X.h (define KeyPress 2)
125 // and QEvent::KeyPress (qevent.h)
130 // Enable ray tracing features
131 #define ENABLE_RAY_TRACING
133 const char* imageZoomCursor[] = {
138 "................................",
139 "................................",
140 ".#######........................",
141 "..aaaaaaa.......................",
142 "................................",
143 ".............#####..............",
144 "...........##.aaaa##............",
145 "..........#.aa.....a#...........",
146 ".........#.a.........#..........",
147 ".........#a..........#a.........",
148 "........#.a...........#.........",
149 "........#a............#a........",
150 "........#a............#a........",
151 "........#a............#a........",
152 "........#a............#a........",
153 ".........#...........#.a........",
154 ".........#a..........#a.........",
155 ".........##.........#.a.........",
156 "........#####.....##.a..........",
157 ".......###aaa#####.aa...........",
158 "......###aa...aaaaa.......#.....",
159 ".....###aa................#a....",
160 "....###aa.................#a....",
161 "...###aa...............#######..",
162 "....#aa.................aa#aaaa.",
163 ".....a....................#a....",
164 "..........................#a....",
165 "...........................a....",
166 "................................",
167 "................................",
168 "................................",
169 "................................"};
171 const char* imageRotateCursor[] = {
176 "................................",
177 "................................",
178 "................................",
179 "................................",
180 "........#.......................",
181 ".......#.a......................",
182 "......#######...................",
183 ".......#aaaaa#####..............",
184 "........#..##.a#aa##........##..",
185 ".........a#.aa..#..a#.....##.aa.",
186 ".........#.a.....#...#..##.aa...",
187 ".........#a.......#..###.aa.....",
188 "........#.a.......#a..#aa.......",
189 "........#a.........#..#a........",
190 "........#a.........#a.#a........",
191 "........#a.........#a.#a........",
192 "........#a.........#a.#a........",
193 ".........#.........#a#.a........",
194 "........##a........#a#a.........",
195 "......##.a#.......#.#.a.........",
196 "....##.aa..##.....##.a..........",
197 "..##.aa.....a#####.aa...........",
198 "...aa.........aaa#a.............",
199 "................#.a.............",
200 "...............#.a..............",
201 "..............#.a...............",
202 "...............a................",
203 "................................",
204 "................................",
205 "................................",
206 "................................",
207 "................................"};
209 const char* imageCrossCursor[] = {
214 "................................",
215 "................................",
216 "................................",
217 "................................",
218 "................................",
219 "................................",
220 "................................",
221 "...............#................",
222 "...............#a...............",
223 "...............#a...............",
224 "...............#a...............",
225 "...............#a...............",
226 "...............#a...............",
227 "...............#a...............",
228 "...............#a...............",
229 ".......#################........",
230 "........aaaaaaa#aaaaaaaaa.......",
231 "...............#a...............",
232 "...............#a...............",
233 "...............#a...............",
234 "...............#a...............",
235 "...............#a...............",
236 "...............#a...............",
237 "...............#a...............",
238 "................a...............",
239 "................................",
240 "................................",
241 "................................",
242 "................................",
243 "................................",
244 "................................",
245 "................................"};
250 \param theDesktop main window of application
251 \param theModel OCC 3D viewer
253 OCCViewer_ViewWindow::OCCViewer_ViewWindow( SUIT_Desktop* theDesktop,
254 OCCViewer_Viewer* theModel )
255 : SUIT_ViewWindow( theDesktop )
259 myEnableDrawMode = false;
260 myDrawRectEnabled = true;
262 updateEnabledDrawMode();
264 mySetRotationPointDlg = 0;
267 IsSketcherStyle = false;
274 myInteractionStyle = SUIT_ViewModel::STANDARD;
275 myPreselectionEnabled = true;
276 mySelectionEnabled = true;
278 myCursorIsHand = false;
279 myPanningByBtn = false;
287 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
290 qDeleteAll( mySketchers );
294 \brief Internal initialization.
296 void OCCViewer_ViewWindow::initLayout()
298 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
299 myViewPort->installEventFilter(this);
300 setCentralWidget(myViewPort);
301 myOperation = NOTHING;
303 myCurrPointType = BBCENTER;
304 myPrevPointType = BBCENTER;
305 mySelectedPoint = gp_Pnt(0.,0.,0.);
306 myRotationPointSelection = false;
308 setTransformRequested ( NOTHING );
309 setTransformInProcess ( false );
326 // Graduated axes dialog
327 QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
328 myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
329 myCubeAxesDlg->initialize();
331 connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
334 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
336 return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
340 \brief Detect viewer operation according the the mouse button pressed
341 and key modifiers used.
342 \param theEvent mouse event
343 \return type of the operation
345 OCCViewer_ViewWindow::OperationType
346 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
348 OperationType aOp = NOTHING;
349 SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
350 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
351 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
353 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
354 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
356 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
357 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
358 (my2dMode == No2dMode))
365 \brief Customize event handling
366 \param watched event receiver object
368 \return \c true if the event processing should be stopped
370 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
372 if ( watched == myViewPort ) {
373 int aType = e->type();
375 case QEvent::MouseButtonPress:
376 vpMousePressEvent((QMouseEvent*) e);
379 case QEvent::MouseButtonRelease:
380 vpMouseReleaseEvent((QMouseEvent*) e);
383 case QEvent::MouseMove:
384 vpMouseMoveEvent((QMouseEvent*) e);
387 case QEvent::MouseButtonDblClick:
388 emit mouseDoubleClicked(this, (QMouseEvent*)e);
393 QWheelEvent* aEvent = (QWheelEvent*) e;
395 if ( aEvent->modifiers().testFlag(Qt::ControlModifier) ) {
396 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
397 if ( isPreselectionEnabled() && ic->HasOpenedContext() ) {
398 if ( aEvent->delta() > 0 ) {
399 ic->HilightNextDetected( myViewPort->getView() );
401 ic->HilightPreviousDetected( myViewPort->getView() );
406 emit vpTransformationStarted ( ZOOMVIEW );
407 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
408 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
411 int x1 = (int)( aEvent->x() + width()*delta/100 );
412 int y1 = (int)( aEvent->y() + height()*delta/100 );
413 myViewPort->zoom( x, y, x1, y1 );
414 #if OCC_VERSION_LARGE <= 0x07000000
415 myViewPort->getView()->ZFitAll();
417 emit vpTransformationFinished ( ZOOMVIEW );
422 case QEvent::ContextMenu:
424 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
425 if ( aEvent->reason() != QContextMenuEvent::Mouse )
426 emit contextMenuRequested( aEvent );
430 case QEvent::KeyPress:
431 emit keyPressed(this, (QKeyEvent*) e);
438 return SUIT_ViewWindow::eventFilter(watched, e);
442 \brief Enable / disable draw rect (rubber band) mode
444 bool OCCViewer_ViewWindow::enableDrawMode( bool on )
446 bool prev = myDrawRectEnabled;
447 myDrawRectEnabled = on;
448 updateEnabledDrawMode();
453 \brief Update state of enable draw mode state.
455 void OCCViewer_ViewWindow::updateEnabledDrawMode()
457 myEnableDrawMode = myDrawRectEnabled;
459 myEnableDrawMode = myEnableDrawMode && myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
463 \brief Handle mouse press event
464 \param theEvent mouse event
466 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
468 myStartX = theEvent->x();
469 myStartY = theEvent->y();
470 int anInteractionStyle = interactionStyle();
472 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
473 // which are assigned for pan and rotate - these operations are activated immediately after pressing
474 // of the first button, so it is necessary to switch to zoom when the second button is pressed
475 bool aSwitchToZoom = false;
476 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
477 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
478 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
481 switch ( myOperation ) {
483 if ( theEvent->button() == Qt::LeftButton )
484 emit vpTransformationStarted ( WINDOWFIT );
488 if ( theEvent->button() == Qt::LeftButton )
489 emit vpTransformationStarted ( PANGLOBAL );
493 if ( theEvent->button() == Qt::LeftButton ) {
494 myViewPort->startZoomAtPoint( myStartX, myStartY );
495 emit vpTransformationStarted ( ZOOMVIEW );
500 if ( aSwitchToZoom ) {
501 myViewPort->startZoomAtPoint( myStartX, myStartY );
504 else if ( theEvent->button() == Qt::LeftButton )
505 emit vpTransformationStarted ( PANVIEW );
509 if ( aSwitchToZoom ) {
510 myViewPort->startZoomAtPoint( myStartX, myStartY );
513 else if ( theEvent->button() == Qt::LeftButton ) {
514 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
515 emit vpTransformationStarted ( ROTATE );
520 /* Try to activate a transformation */
521 OperationType aState;
522 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
523 aState = getButtonState(theEvent, anInteractionStyle);
525 aState = OCCViewer_ViewWindow::NOTHING;
530 myViewPort->startZoomAtPoint( myStartX, myStartY );
538 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
541 if ( myRotationPointSelection )
543 if ( theEvent->button() == Qt::LeftButton )
545 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
546 ic->Select( Standard_True );
547 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
549 TopoDS_Shape aShape = ic->SelectedShape();
550 GProp_GProps aSystem;
552 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
554 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
556 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE )
558 BRepGProp::LinearProperties( aShape, aSystem );
559 aPnt = aSystem.CentreOfMass();
561 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE )
563 BRepGProp::SurfaceProperties( aShape, aSystem );
564 aPnt = aSystem.CentreOfMass();
566 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID )
568 BRepGProp::VolumeProperties( aShape, aSystem );
569 aPnt = aSystem.CentreOfMass();
573 myCurrPointType = myPrevPointType;
577 if ( mySetRotationPointDlg )
579 myRotationPointSelection = false;
580 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
583 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
584 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
585 ic->CloseAllContexts( Standard_True );
586 myOperation = NOTHING;
587 myViewPort->setCursor( myCursor );
588 myCursorIsHand = false;
589 myRotationPointSelection = false;
593 emit mousePressed(this, theEvent);
596 /* notify that we start a transformation */
597 if ( transformRequested() )
598 emit vpTransformationStarted ( myOperation );
600 if ( transformRequested() )
601 setTransformInProcess( true );
603 /* we may need it for sketching... */
604 if ( l_mbPressEvent )
605 delete l_mbPressEvent;
606 l_mbPressEvent = new QMouseEvent( *theEvent );
611 \brief Start zooming operation.
613 Sets the corresponding cursor for the widget.
615 void OCCViewer_ViewWindow::activateZoom()
617 if ( !transformRequested() && !myCursorIsHand )
618 saveCursor(); /* save old cursor */
620 if ( myOperation != ZOOMVIEW ) {
621 QPixmap zoomPixmap (imageZoomCursor);
622 QCursor zoomCursor (zoomPixmap);
623 if( setTransformRequested ( ZOOMVIEW ) )
624 myViewPort->setCursor( zoomCursor );
629 void OCCViewer_ViewWindow::onPanning()
631 myPanningByBtn = true;
636 \brief Start panning operation.
638 Sets the corresponding cursor for the widget.
640 void OCCViewer_ViewWindow::activatePanning()
642 if ( !transformRequested() && !myCursorIsHand )
643 saveCursor(); // save old cursor
645 if ( myOperation != PANVIEW ) {
646 QCursor panCursor (Qt::SizeAllCursor);
647 if( setTransformRequested ( PANVIEW ) )
648 myViewPort->setCursor( panCursor );
653 \brief Start rotation operation
655 Sets the corresponding cursor for the widget.
657 void OCCViewer_ViewWindow::activateRotation()
659 if ( !transformRequested() && !myCursorIsHand )
660 saveCursor(); // save old cursor
662 if ( myOperation != ROTATE ) {
663 QPixmap rotatePixmap (imageRotateCursor);
664 QCursor rotCursor (rotatePixmap);
665 if( setTransformRequested ( ROTATE ) )
666 myViewPort->setCursor( rotCursor );
671 \brief Compute the gravity center.
672 \param theX used to return X coordinate of the gravity center
673 \param theY used to return Y coordinate of the gravity center
674 \param theZ used to return Z coordinate of the gravity center
675 \return \c true if the gravity center is computed
677 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
679 Handle(V3d_View) aView3d = myViewPort->getView();
681 // Project boundaries points and add to avergae gravity
682 // the ones which lie within the screen limits
683 Standard_Real aScreenLimits[4] = { 0.0, 0.0, 0.0, 0.0 };
685 #if OCC_VERSION_LARGE > 0x06070100
686 // NDC space screen limits
687 aScreenLimits[0] = -1.0;
688 aScreenLimits[1] = 1.0;
689 aScreenLimits[2] = -1.0;
690 aScreenLimits[3] = 1.0;
692 aView3d->View()->ViewMapping().WindowLimit( aScreenLimits[0],
698 Standard_Integer aPointsNb = 0;
700 Standard_Real aXmin = 0.0;
701 Standard_Real aYmin = 0.0;
702 Standard_Real aZmin = 0.0;
703 Standard_Real aXmax = 0.0;
704 Standard_Real aYmax = 0.0;
705 Standard_Real aZmax = 0.0;
707 Graphic3d_MapOfStructure aSetOfStructures;
708 aView3d->View()->DisplayedStructures( aSetOfStructures );
709 Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures );
711 for( ; aStructureIt.More(); aStructureIt.Next() ) {
712 const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key();
713 if ( aStructure->IsEmpty() || !aStructure->IsVisible() || aStructure->CStructure()->IsForHighlight )
716 #if OCC_VERSION_LARGE > 0x06070100
717 Bnd_Box aBox = aStructure->MinMaxValues();
718 aXmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().X();
719 aYmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Y();
720 aZmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Z();
721 aXmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().X();
722 aYmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Y();
723 aZmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Z();
725 aStructure->MinMaxValues( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
728 // Infinite structures are skipped
729 Standard_Real aLIM = ShortRealLast() - 1.0;
730 if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
731 || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
735 gp_Pnt aPoints[8] = {
736 gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
737 gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
738 gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
739 gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
742 for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
743 const gp_Pnt& aBBPoint = aPoints[aPointIt];
745 #if OCC_VERSION_LARGE > 0x06070100
746 gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
747 const Standard_Real& U = aProjected.X();
748 const Standard_Real& V = aProjected.Y();
750 Standard_Real U = 0.0;
751 Standard_Real V = 0.0;
752 Standard_Real W = 0.0;
753 aView3d->View()->Projects( aBBPoint.X(), aBBPoint.Y(), aBBPoint.Z(), U, V, W );
756 if (U >= aScreenLimits[0]
757 && U <= aScreenLimits[1]
758 && V >= aScreenLimits[2]
759 && V <= aScreenLimits[3])
762 theX += aBBPoint.X();
763 theY += aBBPoint.Y();
764 theZ += aBBPoint.Z();
779 \brief Set the gravity center as a rotation point.
781 void OCCViewer_ViewWindow::activateSetRotationGravity()
783 if ( myRotationPointSelection )
785 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
786 ic->CloseAllContexts( Standard_True );
787 myOperation = NOTHING;
788 myViewPort->setCursor( myCursor );
789 myCursorIsHand = false;
790 myRotationPointSelection = false;
793 myPrevPointType = myCurrPointType;
794 myCurrPointType = BBCENTER;
796 Standard_Real Xcenter, Ycenter, Zcenter;
797 if ( OCCViewer_Utilities::computeVisibleBBCenter( myViewPort->getView(), Xcenter, Ycenter, Zcenter ) )
798 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
802 \brief Update gravity center in the "Set Rotation Point" dialog box.
803 \sa OCCViewer_SetRotationPointDlg class
805 void OCCViewer_ViewWindow::updateGravityCoords()
807 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == BBCENTER )
809 Standard_Real Xcenter, Ycenter, Zcenter;
810 if ( OCCViewer_Utilities::computeVisibleBBCenter( myViewPort->getView(), Xcenter, Ycenter, Zcenter ) )
811 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
816 \brief Set the point selected by the user as a rotation point.
817 \param theX X coordinate of the rotation point
818 \param theY Y coordinate of the rotation point
819 \param theZ Z coordinate of the rotation point
821 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
823 if ( myRotationPointSelection )
825 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
826 ic->CloseAllContexts( Standard_True );
827 myOperation = NOTHING;
828 myViewPort->setCursor( myCursor );
829 myCursorIsHand = false;
830 myRotationPointSelection = false;
833 myPrevPointType = myCurrPointType;
834 myCurrPointType = SELECTED;
835 mySelectedPoint.SetCoord(theX,theY,theZ);
839 \brief Start the shape selection process.
841 void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
843 myPrevPointType = myCurrPointType;
844 myCurrPointType = SELECTED;
846 // activate selection ------>
847 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
849 ic->OpenLocalContext();
851 AIS_ListOfInteractive aList;
852 ic->DisplayedObjects( aList );
853 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
855 Handle(AIS_InteractiveObject) anObj = it.Value();
856 if ( !anObj.IsNull() && anObj->HasPresentation() &&
857 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
860 ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
863 // activate selection <------
865 if ( !myCursorIsHand )
867 QCursor handCursor (Qt::PointingHandCursor);
868 myCursorIsHand = true;
870 myViewPort->setCursor( handCursor );
872 myRotationPointSelection = true;
876 \brief Start global panning operation
878 Sets the corresponding cursor for the widget.
880 void OCCViewer_ViewWindow::activateGlobalPanning()
882 Handle(V3d_View) aView3d = myViewPort->getView();
883 if ( !aView3d.IsNull() ) {
884 QPixmap globalPanPixmap (imageCrossCursor);
885 QCursor glPanCursor (globalPanPixmap);
886 myCurScale = aView3d->Scale();
887 aView3d->FitAll(0.01, false);
888 saveCursor(); // save old cursor
889 myViewPort->fitAll(); // fits view before selecting a new scene center
890 if( setTransformRequested( PANGLOBAL ) )
891 myViewPort->setCursor( glPanCursor );
896 \brief Starts fit operation.
898 Sets the corresponding cursor for the widget.
900 void OCCViewer_ViewWindow::activateWindowFit()
902 if ( !transformRequested() && !myCursorIsHand )
903 saveCursor(); /* save old cursor */
905 if ( myOperation != WINDOWFIT ) {
906 QCursor handCursor (Qt::PointingHandCursor);
907 if( setTransformRequested ( WINDOWFIT ) )
909 myViewPort->setCursor ( handCursor );
910 myCursorIsHand = true;
916 \brief Start delayed viewer operation.
918 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
920 bool ok = transformEnabled( op );
921 myOperation = ok ? op : NOTHING;
922 myViewPort->setMouseTracking( myOperation == NOTHING );
927 \brief Handle mouse move event.
928 \param theEvent mouse event
930 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
932 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
934 switch ( getButtonState( theEvent, interactionStyle() ) ) {
936 myViewPort->startZoomAtPoint( myStartX, myStartY );
944 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
951 myCurrX = theEvent->x();
952 myCurrY = theEvent->y();
953 switch (myOperation) {
955 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
959 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
965 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
979 if ( myRotationPointSelection || isSketcherStyle() )
981 emit mouseMoving( this, theEvent );
985 int aState = theEvent->modifiers();
986 int aButton = theEvent->buttons();
987 int anInteractionStyle = interactionStyle();
988 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
989 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
990 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
991 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
992 myDrawRect = myEnableDrawMode;
995 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
996 QCursor handCursor (Qt::PointingHandCursor);
997 myCursorIsHand = true;
999 myViewPort->setCursor( handCursor );
1002 emit mouseMoving( this, theEvent );
1004 else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
1005 aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
1006 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
1007 aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
1008 OCCViewer_ViewSketcher* sketcher = 0;
1009 QList<OCCViewer_ViewSketcher*>::Iterator it;
1010 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
1012 OCCViewer_ViewSketcher* sk = (*it);
1013 if( sk->isDefault() && sk->sketchButton() == aButton )
1016 if ( sketcher && myCurSketch == -1 )
1018 activateSketching( sketcher->type() );
1021 myCurSketch = mypSketcher->sketchButton();
1023 if ( l_mbPressEvent )
1025 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
1026 delete l_mbPressEvent;
1029 QApplication::sendEvent( getViewPort(), theEvent );
1034 emit mouseMoving( this, theEvent );
1040 \brief Handle mouse release event.
1041 \param theEvent mouse event
1043 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
1045 switch ( myOperation ) {
1048 int prevState = myCurSketch;
1049 if(theEvent->button() == Qt::RightButton)
1051 QList<OCCViewer_ViewSketcher*>::Iterator it;
1052 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
1054 OCCViewer_ViewSketcher* sk = (*it);
1055 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
1060 emit mouseReleased(this, theEvent);
1061 if(theEvent->button() == Qt::RightButton && prevState == -1)
1063 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1064 theEvent->pos(), theEvent->globalPos() );
1065 emit contextMenuRequested( &aEvent );
1070 myViewPort->endRotation();
1076 #if OCC_VERSION_LARGE <= 0x07000000
1077 myViewPort->getView()->ZFitAll();
1080 OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( getViewManager() );
1081 bool isChained = aMgr->isChainedOperations();
1082 bool isReset = !( myOperation==PANVIEW && myPanningByBtn && isChained ) || theEvent->button() == Qt::RightButton;
1089 if ( theEvent->button() == Qt::LeftButton ) {
1090 myViewPort->setCenter( theEvent->x(), theEvent->y() );
1091 myViewPort->getView()->SetScale(myCurScale);
1097 if ( theEvent->button() == Qt::LeftButton ) {
1098 myCurrX = theEvent->x();
1099 myCurrY = theEvent->y();
1101 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1102 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1109 // NOTE: viewer 3D detects a rectangle of selection using this event
1110 // so we must emit it BEFORE resetting the selection rectangle
1112 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1116 myViewPort->update();
1119 if ( l_mbPressEvent )
1121 delete l_mbPressEvent;
1127 \brief Reset the viewport to its initial state
1128 ( no transformations in process etc. )
1130 void OCCViewer_ViewWindow::resetState()
1134 if ( myRotationPointSelection )
1136 QCursor handCursor (Qt::PointingHandCursor);
1137 myViewPort->setCursor( handCursor );
1141 if ( transformRequested() || myCursorIsHand )
1142 myViewPort->setCursor( myCursor );
1143 myCursorIsHand = false;
1146 if ( transformRequested() )
1147 emit vpTransformationFinished (myOperation);
1149 setTransformInProcess( false );
1150 setTransformRequested( NOTHING );
1155 \brief Draw rubber band rectangle.
1157 void OCCViewer_ViewWindow::drawRect()
1159 if ( !myRectBand ) {
1160 myRectBand = new QtxRectRubberBand( myViewPort );
1162 //palette.setColor(myRectBand->foregroundRole(), Qt::white);
1163 //myRectBand->setPalette(palette);
1165 //myRectBand->hide();
1167 myRectBand->setUpdatesEnabled ( false );
1168 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1169 myRectBand->initGeometry( aRect );
1171 if ( !myRectBand->isVisible() )
1174 myRectBand->setUpdatesEnabled ( true );
1175 //myRectBand->repaint();
1177 //myRectBand->setVisible( aRect.isValid() );
1178 //if ( myRectBand->isVisible() )
1179 // myRectBand->repaint();
1181 // myRectBand->show();
1182 //myRectBand->repaint();
1186 \brief Clear rubber band rectangle on the end on the dragging operation.
1188 void OCCViewer_ViewWindow::endDrawRect()
1190 //delete myRectBand;
1194 myRectBand->clearGeometry();
1200 \brief Create actions.
1202 void OCCViewer_ViewWindow::createActions()
1204 if( !toolMgr()->isEmpty() )
1207 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1214 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1215 tr( "MNU_DUMP_VIEW" ), 0, this);
1216 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1217 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1218 toolMgr()->registerAction( aAction, DumpId );
1221 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1222 tr( "MNU_FITALL" ), 0, this);
1223 aAction->setStatusTip(tr("DSC_FITALL"));
1224 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1225 toolMgr()->registerAction( aAction, FitAllId );
1228 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1229 tr( "MNU_FITRECT" ), 0, this);
1230 aAction->setStatusTip(tr("DSC_FITRECT"));
1231 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1232 toolMgr()->registerAction( aAction, FitRectId );
1235 aAction = new QtxAction(tr("MNU_FITSELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITSELECTION" ) ),
1236 tr( "MNU_FITSELECTION" ), 0, this);
1237 aAction->setStatusTip(tr("DSC_FITSELECTION"));
1238 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
1239 toolMgr()->registerAction( aAction, FitSelectionId );
1242 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1243 tr( "MNU_ZOOM_VIEW" ), 0, this);
1244 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1245 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1246 toolMgr()->registerAction( aAction, ZoomId );
1249 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1250 tr( "MNU_PAN_VIEW" ), 0, this);
1251 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1252 connect(aAction, SIGNAL(triggered()), this, SLOT(onPanning()));
1253 toolMgr()->registerAction( aAction, PanId );
1256 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1257 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1258 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1259 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1260 toolMgr()->registerAction( aAction, GlobalPanId );
1263 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1264 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1265 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1266 mySetRotationPointAction->setCheckable( true );
1267 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1268 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1271 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1272 tr( "MNU_ROTATE_VIEW" ), 0, this);
1273 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1274 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1275 toolMgr()->registerAction( aAction, RotationId );
1278 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1279 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1280 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1281 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1282 this->addAction(aAction);
1283 toolMgr()->registerAction( aAction, FrontId );
1285 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1286 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1287 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1288 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1289 this->addAction(aAction);
1290 toolMgr()->registerAction( aAction, BackId );
1292 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1293 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1294 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1295 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1296 this->addAction(aAction);
1297 toolMgr()->registerAction( aAction, TopId );
1299 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1300 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1301 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1302 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1303 this->addAction(aAction);
1304 toolMgr()->registerAction( aAction, BottomId );
1306 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1307 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1308 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1309 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1310 this->addAction(aAction);
1311 toolMgr()->registerAction( aAction, LeftId );
1313 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1314 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1315 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1316 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1317 this->addAction(aAction);
1318 toolMgr()->registerAction( aAction, RightId );
1320 // rotate anticlockwise
1321 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1322 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1323 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1324 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1325 this->addAction(aAction);
1326 toolMgr()->registerAction( aAction, AntiClockWiseId );
1329 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1330 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1331 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1332 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1333 this->addAction(aAction);
1334 toolMgr()->registerAction( aAction, ClockWiseId );
1336 // Projection mode group
1338 // - orthographic projection
1339 aAction = new QtxAction(tr("MNU_ORTHOGRAPHIC_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ORTHOGRAPHIC" ) ),
1340 tr( "MNU_ORTHOGRAPHIC_MODE" ), 0, this);
1341 aAction->setStatusTip(tr("DSC_ORTHOGRAPHIC_MODE"));
1342 aAction->setCheckable(true);
1343 toolMgr()->registerAction( aAction, OrthographicId );
1345 // - perspective projection
1346 aAction = new QtxAction(tr("MNU_PERSPECTIVE_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PERSPECTIVE" ) ),
1347 tr( "MNU_PERSPECTIVE_MODE" ), 0, this);
1348 aAction->setStatusTip(tr("DSC_PERSPECTIVE_MODE"));
1349 aAction->setCheckable(true);
1350 toolMgr()->registerAction( aAction, PerspectiveId );
1351 #if OCC_VERSION_LARGE > 0x06090000
1352 // - stereo projection
1353 aAction = new QtxAction(tr("MNU_STEREO_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STEREO" ) ),
1354 tr( "MNU_STEREO_MODE" ), 0, this);
1355 aAction->setStatusTip(tr("DSC_STEREO_MODE"));
1356 aAction->setCheckable(true);
1357 toolMgr()->registerAction( aAction, StereoId );
1358 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onStereoType(bool)));
1360 // - add exclusive action group
1361 QActionGroup* aProjectionGroup = new QActionGroup( this );
1362 aProjectionGroup->addAction( toolMgr()->action( OrthographicId ) );
1363 aProjectionGroup->addAction( toolMgr()->action( PerspectiveId ) );
1364 connect(aProjectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProjectionType(QAction*)));
1367 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1368 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1369 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1370 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1371 this->addAction(aAction);
1372 toolMgr()->registerAction( aAction, ResetId );
1375 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1376 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1377 tr("MNU_CLONE_VIEW"), 0, this);
1378 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1379 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1380 toolMgr()->registerAction( aAction, CloneId );
1382 aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
1383 tr("MNU_CLIPPING"), 0, this);
1384 aAction->setStatusTip (tr("DSC_CLIPPING"));
1385 aAction->setCheckable (true);
1386 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1387 toolMgr()->registerAction (aAction, ClippingId);
1389 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1390 tr( "MNU_SHOOT_VIEW" ), 0, this);
1391 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1392 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1393 toolMgr()->registerAction( aAction, MemId );
1395 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1396 tr( "MNU_PRESETS_VIEW" ), 0, this);
1397 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1398 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1399 toolMgr()->registerAction( aAction, RestoreId );
1401 if (myModel->trihedronActivated()) {
1402 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1403 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1404 aAction->setCheckable( true );
1405 aAction->setChecked( true );
1406 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1407 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1408 toolMgr()->registerAction( aAction, TrihedronShowId );
1412 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1413 tr( "MNU_SCALING" ), 0, this);
1414 aAction->setStatusTip(tr("DSC_SCALING"));
1415 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1416 toolMgr()->registerAction( aAction, AxialScaleId );
1418 // Enable/disable preselection
1419 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1420 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1421 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1422 aAction->setCheckable(true);
1423 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1424 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1426 // Enable/disable selection
1427 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1428 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1429 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1430 aAction->setCheckable(true);
1431 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1432 toolMgr()->registerAction( aAction, SwitchSelectionId );
1435 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1436 tr( "MNU_GRADUATED_AXES" ), 0, this);
1437 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1438 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1439 toolMgr()->registerAction( aAction, GraduatedAxesId );
1441 // Active only ambient light or not
1442 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1443 tr( "MNU_AMBIENT" ), 0, this);
1444 aAction->setStatusTip(tr("DSC_AMBIENT"));
1445 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1446 toolMgr()->registerAction( aAction, AmbientId );
1448 // Switch between interaction styles
1449 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1450 tr( "MNU_STYLE_SWITCH" ), 0, this);
1451 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1452 aAction->setCheckable(true);
1453 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1454 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1456 // Switch between zooming styles
1457 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1458 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1459 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1460 aAction->setCheckable(true);
1461 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1462 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1465 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1466 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1467 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1468 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1469 toolMgr()->registerAction( aAction, MaximizedId );
1471 // Return to 3d view
1472 if (my2dMode!=No2dMode){
1473 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1474 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1475 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1476 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1477 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1481 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1482 #ifdef ENABLE_RAY_TRACING
1484 aAction = new QtxAction( tr("MNU_RAY_TRACING"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_RAY_TRACING") ),
1485 tr("MNU_RAY_TRACING"), 0, this );
1486 aAction->setStatusTip( tr("DSC_RAY_TRACING") );
1487 connect( aAction, SIGNAL( triggered() ), this, SLOT( onRayTracing() ) );
1488 toolMgr()->registerAction( aAction, RayTracingId );
1490 // Environment texture
1491 aAction = new QtxAction( tr("MNU_ENV_TEXTURE"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_ENV_TEXTURE") ),
1492 tr("MNU_ENV_TEXTURE"), 0, this );
1493 aAction->setStatusTip( tr("DSC_ENV_TEXTURE") );
1494 connect( aAction, SIGNAL( triggered() ), this, SLOT( onEnvTexture() ) );
1495 toolMgr()->registerAction( aAction, EnvTextureId );
1498 aAction = new QtxAction( tr("MNU_LIGHT_SOURCE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_LIGHT_SOURCE" ) ),
1499 tr( "MNU_LIGHT_SOURCE" ), 0, this );
1500 aAction->setStatusTip( tr("DSC_LIGHT_SOURCE") );
1501 connect( aAction, SIGNAL( triggered() ), this, SLOT( onLightSource() ) );
1502 toolMgr()->registerAction( aAction, LightSourceId );
1507 \brief Create toolbar.
1509 void OCCViewer_ViewWindow::createToolBar()
1511 static const char* titles[] = {
1512 "LBL_3DTOOLBAR_LABEL",
1513 "LBL_XYTOOLBAR_LABEL",
1514 "LBL_XZTOOLBAR_LABEL",
1515 "LBL_YZTOOLBAR_LABEL",
1517 static const char* names[] = {
1518 "OCCViewer3DViewOperations",
1519 "OCCViewerXYViewOperations",
1520 "OCCViewerXZViewOperations",
1521 "OCCViewerYZViewOperations",
1523 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1524 QString( names[my2dMode] ), // name (language-independant)
1525 false ); // disable floatable toolbar
1526 if ( my2dMode != No2dMode ){
1527 toolMgr()->append( ReturnTo3dViewId, tid );
1528 toolMgr()->append( toolMgr()->separator(), tid );
1530 toolMgr()->append( DumpId, tid );
1531 toolMgr()->append( SwitchInteractionStyleId, tid );
1532 toolMgr()->append( SwitchZoomingStyleId, tid );
1533 toolMgr()->append( SwitchPreselectionId, tid );
1534 toolMgr()->append( SwitchSelectionId, tid );
1535 if( myModel->trihedronActivated() )
1536 toolMgr()->append( TrihedronShowId, tid );
1538 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1539 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1540 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1541 #if OCC_VERSION_LARGE > 0x06090000
1542 aScaleAction->insertAction( toolMgr()->action( FitSelectionId ) );
1544 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1545 toolMgr()->append( aScaleAction, tid );
1547 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1548 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1549 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1550 toolMgr()->append( aPanningAction, tid );
1552 if (my2dMode == No2dMode) {
1553 toolMgr()->append( ChangeRotationPointId, tid );
1554 toolMgr()->append( RotationId, tid );
1556 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1557 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1558 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1559 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1560 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1561 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1562 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1563 toolMgr()->append( aViewsAction, tid );
1565 toolMgr()->append( AntiClockWiseId, tid );
1566 toolMgr()->append( ClockWiseId, tid );
1568 toolMgr()->append( OrthographicId, tid );
1569 toolMgr()->append( PerspectiveId, tid );
1570 #if OCC_VERSION_LARGE > 0x06090000
1571 toolMgr()->append( StereoId, tid );
1574 toolMgr()->append( ResetId, tid );
1577 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1578 aMemAction->insertAction( toolMgr()->action( MemId ) );
1579 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1580 toolMgr()->append( aMemAction, tid );
1582 toolMgr()->append( toolMgr()->separator(), tid );
1583 toolMgr()->append( CloneId, tid );
1585 toolMgr()->append( toolMgr()->separator(), tid );
1586 toolMgr()->append( ClippingId, tid );
1587 toolMgr()->append( AxialScaleId, tid );
1588 toolMgr()->append( GraduatedAxesId, tid );
1589 toolMgr()->append( AmbientId, tid );
1591 toolMgr()->append( MaximizedId, tid );
1592 toolMgr()->append( SynchronizeId, tid );
1593 #ifdef ENABLE_RAY_TRACING
1594 toolMgr()->append( RayTracingId, tid );
1595 toolMgr()->append( EnvTextureId, tid );
1596 toolMgr()->append( LightSourceId, tid );
1601 \brief Perform 'fit all' operation.
1603 void OCCViewer_ViewWindow::onViewFitAll()
1605 myViewPort->fitAll();
1609 \brief Perform "front view" transformation.
1611 void OCCViewer_ViewWindow::onFrontView()
1613 emit vpTransformationStarted ( FRONTVIEW );
1614 Handle(V3d_View) aView3d = myViewPort->getView();
1615 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
1617 emit vpTransformationFinished ( FRONTVIEW );
1621 \brief Perform "back view" transformation.
1623 void OCCViewer_ViewWindow::onBackView()
1625 emit vpTransformationStarted ( BACKVIEW );
1626 Handle(V3d_View) aView3d = myViewPort->getView();
1627 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
1629 emit vpTransformationFinished ( BACKVIEW );
1633 \brief Perform "top view" transformation.
1635 void OCCViewer_ViewWindow::onTopView()
1637 emit vpTransformationStarted ( TOPVIEW );
1638 Handle(V3d_View) aView3d = myViewPort->getView();
1639 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
1641 emit vpTransformationFinished ( TOPVIEW );
1645 \brief Perform "bottom view" transformation.
1647 void OCCViewer_ViewWindow::onBottomView()
1649 emit vpTransformationStarted ( BOTTOMVIEW );
1650 Handle(V3d_View) aView3d = myViewPort->getView();
1651 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
1653 emit vpTransformationFinished ( BOTTOMVIEW );
1657 \brief Perform "left view" transformation.
1659 void OCCViewer_ViewWindow::onLeftView()
1661 emit vpTransformationStarted ( LEFTVIEW );
1662 Handle(V3d_View) aView3d = myViewPort->getView();
1663 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
1665 emit vpTransformationFinished ( LEFTVIEW );
1669 \brief Perform "right view" transformation.
1671 void OCCViewer_ViewWindow::onRightView()
1673 emit vpTransformationStarted ( RIGHTVIEW );
1674 Handle(V3d_View) aView3d = myViewPort->getView();
1675 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
1677 emit vpTransformationFinished ( RIGHTVIEW );
1681 \brief Rotate view 90 degrees clockwise
1683 void OCCViewer_ViewWindow::onClockWiseView()
1685 emit vpTransformationStarted ( CLOCKWISEVIEW );
1686 myViewPort->rotateXY( 90. );
1687 emit vpTransformationFinished ( CLOCKWISEVIEW );
1691 \brief Rotate view 90 degrees conterclockwise
1693 void OCCViewer_ViewWindow::onAntiClockWiseView()
1695 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1696 myViewPort->rotateXY( -90. );
1697 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1701 \brief Perform "reset view" transformation.
1703 Sets default orientation of the viewport camera.
1705 void OCCViewer_ViewWindow::onResetView()
1707 emit vpTransformationStarted( RESETVIEW );
1708 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1709 myViewPort->getView()->Reset( false );
1710 myViewPort->fitAll( false, true, false );
1711 myViewPort->getView()->SetImmediateUpdate( upd );
1712 onProjectionType(); // needed to apply projection type properly after reset
1713 myViewPort->getView()->Update();
1714 emit vpTransformationFinished( RESETVIEW );
1718 \brief Set the given projection mode.
1720 Set the given projection mode: Orthographic or Perspective.
1722 void OCCViewer_ViewWindow::onProjectionType( QAction* theAction )
1724 Handle(V3d_View) aView3d = myViewPort->getView();
1725 if ( !aView3d.IsNull() ) {
1726 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1727 if (theAction == toolMgr()->action( OrthographicId )) {
1728 myModel->setProjectionType(Orthographic);
1729 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Orthographic );
1730 aCamera->SetFOVy(45.0);
1732 else if (theAction == toolMgr()->action( PerspectiveId )) {
1733 myModel->setProjectionType(Perspective);
1734 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Perspective );
1735 aCamera->SetFOVy(30.0);
1737 #if OCC_VERSION_LARGE > 0x06090000
1738 if (toolMgr()->action( StereoId )->isChecked()) {
1739 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1740 aCamera->SetFOVy(30.0);
1749 \brief Sets Stereo projection mode.
1751 Sets Stereo projection mode.
1753 void OCCViewer_ViewWindow::onStereoType( bool activate )
1755 #if OCC_VERSION_LARGE > 0x06090000
1756 Handle(V3d_View) aView3d = myViewPort->getView();
1757 if ( !aView3d.IsNull() ) {
1758 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1760 toolMgr()->action( PerspectiveId )->setChecked(true);
1761 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1762 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(false);
1764 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1765 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1766 setStereoType( aResMgr->integerValue( "OCCViewer", "stereo_type", 0 ) );
1767 setAnaglyphFilter( aResMgr->integerValue( "OCCViewer", "anaglyph_filter", 0 ) );
1768 setReverseStereo( aResMgr->booleanValue( "OCCViewer", "reverse_stereo", false ) );
1769 setVSync( aResMgr->booleanValue( "OCCViewer", "enable_vsync", true ) );
1770 setQuadBufferSupport( aResMgr->booleanValue( "OCCViewer", "enable_quad_buffer_support", false ) );
1773 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(true);
1774 if (myModel->projectionType() == Orthographic) {
1775 toolMgr()->action( OrthographicId )->setChecked(true);
1776 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Orthographic);
1778 else if (myModel->projectionType() == Perspective) {
1779 toolMgr()->action( PerspectiveId )->setChecked(true);
1780 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1787 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1788 toolMgr()->action( StereoId )->isChecked() )
1789 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1794 \brief Restore the view.
1796 Restore the projection mode based on tool-buttons states.
1798 void OCCViewer_ViewWindow::onProjectionType()
1800 emit vpTransformationStarted( PROJECTION );
1801 if (toolMgr()->action( OrthographicId )->isChecked())
1802 setProjectionType( Orthographic );
1803 if (toolMgr()->action( PerspectiveId )->isChecked())
1804 setProjectionType( Perspective );
1805 #if OCC_VERSION_LARGE > 0x06090000
1806 if (toolMgr()->action( StereoId )->isChecked())
1807 setProjectionType( Stereo );
1809 emit vpTransformationFinished( PROJECTION );
1812 void OCCViewer_ViewWindow::setProjectionType( int mode )
1814 QtxAction* anOrthographicAction = dynamic_cast<QtxAction*>( toolMgr()->action( OrthographicId ) );
1815 QtxAction* aPerspectiveAction = dynamic_cast<QtxAction*>( toolMgr()->action( PerspectiveId ) );
1816 #if OCC_VERSION_LARGE > 0x06090000
1817 QtxAction* aStereoAction = dynamic_cast<QtxAction*>( toolMgr()->action( StereoId ) );
1821 onProjectionType( anOrthographicAction );
1824 onProjectionType( aPerspectiveAction );
1827 onStereoType( true );
1830 // update action state if method is called outside
1831 if ( mode == Orthographic && !anOrthographicAction->isChecked() ) {
1832 anOrthographicAction->setChecked( true );
1833 #if OCC_VERSION_LARGE > 0x06090000
1834 aStereoAction->setChecked( false );
1837 if ( mode == Perspective && !aPerspectiveAction->isChecked() ) {
1838 aPerspectiveAction->setChecked( true );
1839 #if OCC_VERSION_LARGE > 0x06090000
1840 aStereoAction->setChecked( false );
1843 #if OCC_VERSION_LARGE > 0x06090000
1844 if ( mode == Stereo ) {
1845 aStereoAction->setChecked( true );
1846 if ( anOrthographicAction->isEnabled() ) {
1847 anOrthographicAction->setEnabled( false );
1848 anOrthographicAction->setChecked( false );
1849 aStereoAction->setChecked( false );
1852 anOrthographicAction->setEnabled( true );
1853 aStereoAction->setChecked( false );
1854 anOrthographicAction->setChecked(myModel->projectionType() == Orthographic);
1856 if ( aPerspectiveAction->isEnabled() ) {
1857 aPerspectiveAction->setEnabled( false );
1858 aPerspectiveAction->setChecked( true );
1859 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1860 toolMgr()->action( StereoId )->isChecked() )
1861 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1864 aPerspectiveAction->setEnabled( true );
1865 aStereoAction->setChecked( false );
1866 aPerspectiveAction->setChecked(myModel->projectionType() == Perspective);
1871 if ( !anOrthographicAction->isEnabled() )
1872 anOrthographicAction->setEnabled( true );
1873 if ( !aPerspectiveAction->isEnabled() )
1874 aPerspectiveAction->setEnabled( true );
1880 \brief Perform "fit all" transformation.
1882 void OCCViewer_ViewWindow::onFitAll()
1884 emit vpTransformationStarted( FITALLVIEW );
1885 myViewPort->fitAll();
1886 emit vpTransformationFinished( FITALLVIEW );
1890 \brief Perform "fit selection" transformation.
1892 void OCCViewer_ViewWindow::onFitSelection()
1894 emit vpTransformationStarted( FITSELECTION );
1895 #if OCC_VERSION_LARGE > 0x06090000
1896 myModel->getAISContext()->FitSelected( getViewPort()->getView() );
1898 emit vpTransformationFinished( FITSELECTION );
1902 \brief Called if 'change rotation point' operation is activated.
1903 \param on action state
1905 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1909 if (!mySetRotationPointDlg)
1911 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1912 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1915 if (!mySetRotationPointDlg->isVisible())
1917 //if (mySetRotationPointDlg->IsFirstShown())
1918 if (myCurrPointType == BBCENTER)
1920 Standard_Real Xcenter, Ycenter, Zcenter;
1921 if (OCCViewer_Utilities::computeVisibleBBCenter(myViewPort->getView(), Xcenter, Ycenter, Zcenter))
1922 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1924 mySetRotationPointDlg->show();
1929 if (mySetRotationPointDlg->isVisible())
1930 mySetRotationPointDlg->hide();
1935 \brief Create one more window with same content.
1937 void OCCViewer_ViewWindow::onCloneView()
1939 SUIT_ViewWindow* vw = myManager->createViewWindow();
1941 emit viewCloned( vw );
1942 OCCViewer_ViewWindow* occVw = dynamic_cast<OCCViewer_ViewWindow*> (vw);
1943 if(occVw && occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)) {
1944 occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)->synchronize(this);
1949 Creates one more window with same content
1951 void OCCViewer_ViewWindow::onAxialScale()
1953 if ( !myScalingDlg )
1954 myScalingDlg = new OCCViewer_AxialScaleDlg( this , myModel );
1956 if ( !myScalingDlg->isVisible() )
1958 myScalingDlg->Update();
1959 myScalingDlg->show();
1964 Shows Graduated Axes dialog
1966 void OCCViewer_ViewWindow::onGraduatedAxes()
1968 myCubeAxesDlg->Update();
1969 myCubeAxesDlg->show();
1972 void OCCViewer_ViewWindow::onAmbientToogle()
1974 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
1975 viewer->InitDefinedLights();
1976 while(viewer->MoreDefinedLights())
1978 Handle(V3d_Light) light = viewer->DefinedLight();
1979 if(light->Type() != V3d_AMBIENT)
1981 Handle(V3d_View) aView3d = myViewPort->getView();
1982 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
1983 else viewer->SetLightOn(light);
1985 viewer->NextDefinedLights();
1991 \brief Store view parameters.
1993 void OCCViewer_ViewWindow::onMemorizeView()
1995 appendViewAspect( getViewParams() );
1999 \brief Restore view parameters.
2001 void OCCViewer_ViewWindow::onRestoreView()
2003 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
2004 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
2006 updateViewAspects( aDlg->parameters() );
2007 if( myRestoreFlag && aDlg->parameters().count() )
2008 performRestoring( aDlg->currentItem() );
2012 \brief Restore view parameters.
2013 \param anItem view parameters
2015 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
2017 Handle(V3d_View) aView3d = myViewPort->getView();
2019 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
2020 aView3d->SetScale( anItem.scale );
2021 aView3d->SetTwist( anItem.twist );
2022 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
2023 aView3d->SetImmediateUpdate( prev );
2024 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2025 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2026 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
2028 #if OCC_VERSION_LARGE > 0x06070100
2029 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
2031 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
2033 // "eye" and "at" require conversion to represent center panning
2034 // up direction is only available after setting angle of twist and
2035 // other view parameters
2036 aView3d->Up( anUpX, anUpY, anUpZ );
2038 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
2039 gp_Dir anUp( anUpX, anUpY, anUpZ );
2040 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
2041 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2042 gp_Dir aSide = aProj ^ anUp;
2044 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
2045 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
2047 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
2048 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2051 aView3d->SetCenter( anItem.centerX, anItem.centerY );
2054 if ( !baseParamsOnly ) {
2056 myModel->setTrihedronShown( anItem.isVisible );
2057 myModel->setTrihedronSize( anItem.size );
2059 // graduated trihedron
2060 bool anIsVisible = anItem.gtIsVisible;
2061 OCCViewer_AxisWidget::AxisData anAxisData[3];
2062 anAxisData[0].DrawName = anItem.gtDrawNameX;
2063 anAxisData[1].DrawName = anItem.gtDrawNameZ;
2064 anAxisData[2].DrawName = anItem.gtDrawNameZ;
2065 anAxisData[0].Name = anItem.gtNameX;
2066 anAxisData[1].Name = anItem.gtNameZ;
2067 anAxisData[2].Name = anItem.gtNameZ;
2068 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
2069 anItem.gtNameColorGX,
2070 anItem.gtNameColorBX );
2071 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
2072 anItem.gtNameColorGY,
2073 anItem.gtNameColorBY );
2074 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
2075 anItem.gtNameColorGZ,
2076 anItem.gtNameColorBZ );
2077 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
2078 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
2079 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
2080 anAxisData[0].NbValues = anItem.gtNbValuesX;
2081 anAxisData[1].NbValues = anItem.gtNbValuesY;
2082 anAxisData[2].NbValues = anItem.gtNbValuesZ;
2083 anAxisData[0].Offset = anItem.gtOffsetX;
2084 anAxisData[1].Offset = anItem.gtOffsetY;
2085 anAxisData[2].Offset = anItem.gtOffsetZ;
2086 anAxisData[0].Color = QColor( anItem.gtColorRX,
2089 anAxisData[1].Color = QColor( anItem.gtColorRY,
2092 anAxisData[2].Color = QColor( anItem.gtColorRZ,
2095 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
2096 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
2097 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
2098 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
2099 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
2100 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
2102 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
2103 myCubeAxesDlg->ApplyData( aView3d );
2105 } // if ( !baseParamsOnly )
2111 \brief Set restore flag.
2113 void OCCViewer_ViewWindow::setRestoreFlag()
2119 \brief Called when action "show/hide trihedron" is activated.
2121 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
2123 myModel->setTrihedronShown(show);
2127 \brief Toggles preselection (highlighting) on/off
2129 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
2131 myPreselectionEnabled = on;
2132 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
2134 // unhighlight all highlighted objects
2136 myModel->unHighlightAll( true, false );
2139 // update action state if method is called outside
2140 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2141 if ( a && a->isChecked() != on ) {
2142 a->setChecked( on );
2147 \brief Toggles selection on/off
2149 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
2151 mySelectionEnabled = on;
2152 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
2154 // update action state if method is called outside
2157 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2159 a->setEnabled( on );
2163 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
2164 if ( a && a->isChecked() != on ) {
2165 a->setChecked( on );
2170 \brief Switches "keyboard free" interaction style on/off
2172 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
2174 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
2176 // update action state if method is called outside
2177 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
2178 if ( a && a->isChecked() != on )
2179 a->setChecked( on );
2183 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
2185 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
2187 myViewPort->setAdvancedZoomingEnabled( on );
2189 // update action state if method is called outside
2190 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
2191 if ( a && a->isChecked() != on )
2192 a->setChecked( on );
2196 \brief Get current interaction style
2197 \return interaction style
2199 int OCCViewer_ViewWindow::interactionStyle() const
2201 return myInteractionStyle;
2205 \brief Set current interaction style
2206 \param theStyle interaction style
2208 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
2210 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
2214 \brief Get current zooming style
2215 \return zooming style
2217 int OCCViewer_ViewWindow::zoomingStyle() const
2219 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
2223 \brief Set current zooming style
2224 \param theStyle zooming style
2226 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
2228 onSwitchZoomingStyle( theStyle == 1 );
2232 \brief Dump view window contents to the pixmap.
2233 \return pixmap containing all scene rendered in the window
2235 QImage OCCViewer_ViewWindow::dumpView()
2237 Handle(V3d_View) view = myViewPort->getView();
2238 if ( view.IsNull() )
2241 int aWidth = myViewPort->width();
2242 int aHeight = myViewPort->height();
2244 // rnv: An old approach to dump the OCCViewer content
2245 // Now used OCCT built-in procedure.
2247 QApplication::syncX();
2248 view->Redraw(); // In order to reactivate GL context
2251 #ifndef DISABLE_GLVIEWER
2252 OpenGLUtils_FrameBuffer aFrameBuffer;
2253 if( aFrameBuffer.init( aWidth, aHeight ) )
2255 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
2257 glPushAttrib( GL_VIEWPORT_BIT );
2258 glViewport( 0, 0, aWidth, aHeight );
2259 aFrameBuffer.bind();
2264 aFrameBuffer.unbind();
2267 aFrameBuffer.bind();
2268 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
2269 aFrameBuffer.unbind();
2271 anImage = anImage.rgbSwapped();
2272 anImage = anImage.mirrored();
2275 // if frame buffers are unsupported, use old functionality
2278 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
2280 QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
2282 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
2288 view->ToPixMap(aPix,aWidth, aHeight,Graphic3d_BT_RGBA);
2290 QImage anImage( aPix.Data(), aWidth, aHeight, QImage::Format_ARGB32 );
2291 anImage = anImage.mirrored();
2295 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
2296 const QString& fileName,
2297 const QString& format )
2300 QApplication::setOverrideCursor( Qt::WaitCursor );
2301 if ( format != "PS" && format != "EPS")
2302 res = myViewPort->getView()->Dump( fileName.toStdString().c_str() );
2304 #if OCC_VERSION_MAJOR < 7
2305 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
2307 Handle(Graphic3d_CView) a3dView = myViewPort->getView()->View();
2311 res = a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
2312 else if (format == "EPS")
2313 res = a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
2315 QApplication::restoreOverrideCursor();
2320 QString OCCViewer_ViewWindow::filter() const
2322 return tr( "OCC_IMAGE_FILES" );
2327 \brief Set parameters of the cutting plane
2328 \param on if \c true, cutting plane is enabled
2329 \param x X position of plane point
2330 \param y Y position of plane point
2331 \param z Z position of plane point
2332 \param dx X coordinate of plane normal
2333 \param dy Y coordinate of plane normal
2334 \param dz Z coordinate of plane normal
2336 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2337 const double dx, const double dy, const double dz )
2339 Handle(V3d_View) view = myViewPort->getView();
2340 if ( view.IsNull() )
2344 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2346 // try to use already existing plane or create a new one
2347 Handle(V3d_Plane) clipPlane;
2349 // calculate new a,b,c,d values for the plane
2350 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2352 pln.Coefficients(a, b, c, d);
2353 #if OCC_VERSION_LARGE > 0x07000000
2354 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2355 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2356 if(aPlanes->Size() > 0 ) {
2358 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2359 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2360 if(aPlanes.Size() > 0 ) {
2362 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2363 aClipPlane->SetEquation(pln);
2364 aClipPlane->SetOn(Standard_True);
2366 view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2370 #if OCC_VERSION_LARGE > 0x07000000
2371 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2372 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2374 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2375 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2377 for( ;anIter.More();anIter.Next() ){
2378 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2379 aClipPlane->SetOn(Standard_False);
2387 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2389 gp_Dir aDir = pln.Axis().Direction();
2390 gp_Pnt aPnt = pln.Location();
2391 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2396 \brief Check if any cutting plane is enabled
2397 \return \c true if at least one cutting plane is enabled
2399 bool OCCViewer_ViewWindow::isCuttingPlane()
2401 Handle(V3d_View) view = myViewPort->getView();
2403 #if OCC_VERSION_LARGE > 0x07000000
2404 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2405 Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2407 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2408 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2410 for( ;anIter.More();anIter.Next() ) {
2411 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2412 if(aClipPlane->IsOn()) {
2421 \brief Get the visual parameters of the view window.
2422 \return visual parameters of view window
2424 viewAspect OCCViewer_ViewWindow::getViewParams() const
2426 double projX, projY, projZ, twist;
2427 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2428 double aScaleX, aScaleY, aScaleZ;
2430 Handle(V3d_View) aView3d = myViewPort->getView();
2432 aView3d->Proj( projX, projY, projZ );
2433 aView3d->At( atX, atY, atZ );
2434 aView3d->Eye( eyeX, eyeY, eyeZ );
2435 twist = aView3d->Twist();
2437 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2439 bool isShown = myModel->isTrihedronVisible();
2440 double size = myModel->trihedronSize();
2442 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2445 params.scale = aView3d->Scale();
2446 params.projX = projX;
2447 params.projY = projY;
2448 params.projZ = projZ;
2449 params.twist = twist;
2456 params.scaleX = aScaleX;
2457 params.scaleY = aScaleY;
2458 params.scaleZ = aScaleZ;
2459 params.name = aName;
2460 params.isVisible= isShown;
2463 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2464 aView3d->Center( params.centerX, params.centerY );
2467 // graduated trihedron
2468 bool anIsVisible = false;
2469 OCCViewer_AxisWidget::AxisData anAxisData[3];
2470 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2472 params.gtIsVisible = anIsVisible;
2473 params.gtDrawNameX = anAxisData[0].DrawName;
2474 params.gtDrawNameY = anAxisData[1].DrawName;
2475 params.gtDrawNameZ = anAxisData[2].DrawName;
2476 params.gtNameX = anAxisData[0].Name;
2477 params.gtNameY = anAxisData[1].Name;
2478 params.gtNameZ = anAxisData[2].Name;
2479 params.gtNameColorRX = anAxisData[0].NameColor.red();
2480 params.gtNameColorGX = anAxisData[0].NameColor.green();
2481 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2482 params.gtNameColorRY = anAxisData[1].NameColor.red();
2483 params.gtNameColorGY = anAxisData[1].NameColor.green();
2484 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2485 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2486 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2487 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2488 params.gtDrawValuesX = anAxisData[0].DrawValues;
2489 params.gtDrawValuesY = anAxisData[1].DrawValues;
2490 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2491 params.gtNbValuesX = anAxisData[0].NbValues;
2492 params.gtNbValuesY = anAxisData[1].NbValues;
2493 params.gtNbValuesZ = anAxisData[2].NbValues;
2494 params.gtOffsetX = anAxisData[0].Offset;
2495 params.gtOffsetY = anAxisData[1].Offset;
2496 params.gtOffsetZ = anAxisData[2].Offset;
2497 params.gtColorRX = anAxisData[0].Color.red();
2498 params.gtColorGX = anAxisData[0].Color.green();
2499 params.gtColorBX = anAxisData[0].Color.blue();
2500 params.gtColorRY = anAxisData[1].Color.red();
2501 params.gtColorGY = anAxisData[1].Color.green();
2502 params.gtColorBY = anAxisData[1].Color.blue();
2503 params.gtColorRZ = anAxisData[2].Color.red();
2504 params.gtColorGZ = anAxisData[2].Color.green();
2505 params.gtColorBZ = anAxisData[2].Color.blue();
2506 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2507 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2508 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2509 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2510 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2511 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2517 \brief Get visual parameters of this view window.
2518 \return visual parameters of view window
2520 QString OCCViewer_ViewWindow::getVisualParameters()
2522 viewAspect params = getViewParams();
2526 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2527 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2528 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
2529 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
2531 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2532 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2533 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2534 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2535 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2536 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2537 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2538 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2539 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2540 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2541 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2542 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2543 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2544 data << QString( "isVisible=%1" ).arg( params.isVisible );
2545 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2547 ClipPlanesList aPlanes = myModel->getClipPlanes();
2548 for ( int i=0; i < aPlanes.size(); i++ )
2550 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2551 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2552 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2553 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2554 switch ( aPlane.Mode )
2556 case OCCViewer_ClipPlane::Absolute :
2558 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2560 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2562 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2563 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2564 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2568 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2573 case OCCViewer_ClipPlane::Relative :
2575 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2576 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2577 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2582 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2583 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2584 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2585 data << ClippingPlane;
2588 // graduated trihedron
2589 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2590 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2591 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2592 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2593 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2594 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2595 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2596 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2597 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2598 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2599 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2600 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2601 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2602 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2603 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2604 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2605 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2606 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2607 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2608 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2609 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2610 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2611 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2612 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2613 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2614 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2615 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2616 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2617 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2618 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2619 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2620 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2621 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2622 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2623 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2624 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2625 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2626 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2627 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2628 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2630 // ray tracing parameters
2631 Graphic3d_RenderingParams rendParams = this->getViewPort()->getView()->RenderingParams();
2632 if ( rendParams.Method == Graphic3d_RM_RAYTRACING ) {
2633 QString RayTracing = "rayTracing=";
2634 RayTracing += QString( "rtDepth~%1;" ).arg( rendParams.RaytracingDepth );
2635 RayTracing += QString( "rtReflection~%1;" ).arg( rendParams.IsReflectionEnabled );
2636 RayTracing += QString( "rtAntialiasing~%1;" ).arg( rendParams.IsAntialiasingEnabled );
2637 RayTracing += QString( "rtShadow~%1;" ).arg( rendParams.IsShadowEnabled );
2638 RayTracing += QString( "rtTransShadow~%1;" ).arg( rendParams.IsTransparentShadowEnabled );
2642 // environment texture parameters
2643 Handle(Graphic3d_TextureEnv) aTexture = this->getViewPort()->getView()->TextureEnv();
2644 if ( !aTexture.IsNull() ) {
2645 QString EnvTexture = "envTexture=";
2646 if ( aTexture->Name() == Graphic3d_NOT_ENV_UNKNOWN ) {
2647 TCollection_AsciiString aFileName;
2648 aTexture->Path().SystemName( aFileName );
2649 EnvTexture += QString( "etFile~%1;" ).arg( aFileName.ToCString() );
2652 EnvTexture += QString( "etNumber~%1;" ).arg( aTexture->Name() );
2656 // light source parameters
2657 myModel->getViewer3d()->InitDefinedLights();
2658 while ( myModel->getViewer3d()->MoreDefinedLights() )
2660 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2661 if ( aLight->Type() != V3d_AMBIENT ) {
2662 QString LightSource = QString( "lightSource=" );
2663 LightSource += QString( "lightType~%1;" ).arg( aLight->Type() );
2665 if ( aLight->Type() == V3d_DIRECTIONAL )
2666 Handle(V3d_DirectionalLight)::DownCast( aLight )->Direction( aX, aY, aZ );
2667 else if ( aLight->Type() == V3d_POSITIONAL )
2668 Handle(V3d_PositionalLight)::DownCast( aLight )->Position( aX, aY, aZ );
2669 LightSource += QString( "lightX~%1;" ).arg( aX );
2670 LightSource += QString( "lightY~%1;" ).arg( aY );
2671 LightSource += QString( "lightZ~%1;" ).arg( aZ );
2672 LightSource += QString( "lightColorR~%1;" ).arg( aLight->Color().Red() );
2673 LightSource += QString( "lightColorG~%1;" ).arg( aLight->Color().Green() );
2674 LightSource += QString( "lightColorB~%1;" ).arg( aLight->Color().Blue() );
2675 LightSource += QString( "lightHeadlight~%1;" ).arg( aLight->Headlight() );
2676 data << LightSource;
2678 myModel->getViewer3d()->NextDefinedLights();
2681 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2682 data << QString( "background=%1" ).arg( bg );
2684 return data.join("*");
2688 \brief Restore visual parameters of the view window.
2689 \param parameters visual parameters of view window
2691 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2694 ClipPlanesList aClipPlanes;
2695 QStringList data = parameters.split( '*' );
2696 Qtx::BackgroundData bgData;
2697 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2699 foreach( QString param, data ) {
2700 QString paramName = param.section( '=', 0, 0 ).trimmed();
2701 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2702 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2703 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2704 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2705 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2706 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2707 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2708 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2709 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2710 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2711 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2712 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2713 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2714 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2715 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2716 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2717 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2718 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2719 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2720 else if ( paramName.contains( "ClippingPlane" ) )
2722 QStringList ClipPlaneData = paramValue.split( ';' );
2723 OCCViewer_ClipPlane aPlane;
2724 foreach( QString ClipPlaneParam, ClipPlaneData )
2726 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2727 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2728 if ( ClipPlane_paramName == "Mode" )
2730 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2732 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2733 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2734 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2735 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2738 switch ( aPlane.Mode )
2740 case OCCViewer_ClipPlane::Absolute :
2741 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2742 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2743 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2744 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2745 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2748 case OCCViewer_ClipPlane::Relative :
2749 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2750 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2751 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2756 aClipPlanes.push_back(aPlane);
2758 // graduated trihedron
2759 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2760 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2761 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2762 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2763 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2764 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2765 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2766 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2767 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2768 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2769 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2770 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2771 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2772 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2773 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2774 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2775 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2776 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2777 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2778 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2779 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2780 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2781 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2782 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2783 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2784 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2785 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2786 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2787 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2788 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2789 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2790 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2791 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2792 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2793 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2794 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2795 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2796 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2797 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2798 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2799 else if ( paramName == "rayTracing" )
2801 Graphic3d_RenderingParams& rendParams = this->getViewPort()->getView()->ChangeRenderingParams();
2802 rendParams.Method = Graphic3d_RM_RAYTRACING;
2803 QStringList rtData = paramValue.split( ';' );
2804 foreach( QString rtParam, rtData )
2806 QString rt_paramName = rtParam.section( '~', 0, 0 ).trimmed();
2807 QString rt_paramValue = rtParam.section( '~', 1, 1 ).trimmed();
2808 if ( rt_paramName == "rtDepth" ) rendParams.RaytracingDepth = rt_paramValue.toInt();
2809 else if ( rt_paramName == "rtReflection" ) rendParams.IsReflectionEnabled = rt_paramValue.toInt();
2810 else if ( rt_paramName == "rtAntialiasing" ) rendParams.IsAntialiasingEnabled = rt_paramValue.toInt();
2811 else if ( rt_paramName == "rtShadow" ) rendParams.IsShadowEnabled = rt_paramValue.toInt();
2812 else if ( rt_paramName == "rtTransShadow" ) rendParams.IsTransparentShadowEnabled = rt_paramValue.toInt();
2815 else if ( paramName == "envTexture" )
2817 Handle(Graphic3d_TextureEnv) aTexture;
2818 QStringList etData = paramValue.split( ';' );
2819 foreach( QString etParam, etData )
2821 QString et_paramName = etParam.section( '~', 0, 0 ).trimmed();
2822 QString et_paramValue = etParam.section( '~', 1, 1 ).trimmed();
2823 if ( et_paramName == "etNumber" )
2824 aTexture = new Graphic3d_TextureEnv( Graphic3d_NameOfTextureEnv( et_paramValue.toInt() ) );
2825 else if ( et_paramName == "etFile" )
2826 aTexture = new Graphic3d_TextureEnv( TCollection_AsciiString( et_paramValue.toStdString().c_str() ) );
2827 Handle(V3d_View) aView = this->getViewPort()->getView();
2828 aView->SetTextureEnv( aTexture );
2829 #if OCC_VERSION_LARGE <= 0x07000000
2830 aView->SetSurfaceDetail( V3d_TEX_ENVIRONMENT );
2834 else if ( paramName == "lightSource" )
2836 myModel->getViewer3d()->InitDefinedLights();
2837 while ( myModel->getViewer3d()->MoreDefinedLights() )
2839 Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2840 if( aLight->Type() != V3d_AMBIENT ) {
2841 myModel->getViewer3d()->DelLight( aLight );
2842 myModel->getViewer3d()->InitDefinedLights();
2844 myModel->getViewer3d()->NextDefinedLights();
2849 V3d_TypeOfLight aType;
2851 QStringList lsData = paramValue.split( ';' );
2852 foreach( QString lsParam, lsData )
2854 QString ls_paramName = lsParam.section( '~', 0, 0 ).trimmed();
2855 QString ls_paramValue = lsParam.section( '~', 1, 1 ).trimmed();
2856 if ( ls_paramName == "lightType" ) aType = V3d_TypeOfLight( ls_paramValue.toInt() );
2857 else if ( ls_paramName == "lightX" ) aX = ls_paramValue.toDouble();
2858 else if ( ls_paramName == "lightY" ) aY = ls_paramValue.toDouble();
2859 else if ( ls_paramName == "lightZ" ) aZ = ls_paramValue.toDouble();
2860 else if ( ls_paramName == "lightColorR" ) cR = ls_paramValue.toDouble();
2861 else if ( ls_paramName == "lightColorG" ) cG = ls_paramValue.toDouble();
2862 else if ( ls_paramName == "lightColorB" ) cB = ls_paramValue.toDouble();
2863 else if ( ls_paramName == "lightHeadlight" ) isHeadlight = ls_paramValue.toInt();
2865 Quantity_Color aColor = Quantity_Color( cR, cG, cB, Quantity_TOC_RGB );
2866 if( aType == V3d_DIRECTIONAL ) {
2867 Handle(V3d_DirectionalLight) aLight = new V3d_DirectionalLight( myModel->getViewer3d() );
2868 aLight->SetDirection( aX, aY, aZ );
2869 aLight->SetColor( aColor );
2870 aLight->SetHeadlight( isHeadlight );
2871 myModel->getViewer3d()->SetLightOn( aLight );
2873 else if( aType == V3d_POSITIONAL ) {
2874 Handle(V3d_PositionalLight) aLight = new V3d_PositionalLight( myModel->getViewer3d(), aX, aY, aZ, aColor.Name() );
2875 aLight->SetHeadlight( isHeadlight );
2876 myModel->getViewer3d()->SetLightOn( aLight );
2879 else if ( paramName == "background" ) {
2880 QString bg = paramValue.replace( "$", "=" );
2881 bgData = Qtx::stringToBackground( bg );
2885 else // old format - "1.000e+00*0.000e+00..."
2888 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2889 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2890 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2891 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2892 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2893 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2894 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
2895 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2896 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2897 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
2898 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2899 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2900 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2901 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
2902 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
2903 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
2904 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
2905 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
2907 performRestoring( params );
2908 setBackground( bgData );
2909 myModel->setClipPlanes(aClipPlanes);
2913 \brief Handle show event.
2915 Emits Show() signal.
2917 \param theEvent show event
2919 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2921 emit Show( theEvent );
2925 \brief Handle hide event.
2927 Emits Hide() signal.
2929 \param theEvent hide event
2931 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
2933 emit Hide( theEvent );
2938 Save old cursor. [ protected ]
2940 void OCCViewer_ViewWindow::saveCursor()
2942 QCursor* aCursor = NULL;
2944 aCursor = myViewPort->getDefaultCursor();
2945 myCursor = ( aCursor ? *aCursor : cursor() );
2950 Creates default sketcher. [ virtual protected ]
2952 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
2955 return new OCCViewer_RectSketcher( this, type );
2956 if ( type == Polygon )
2957 return new OCCViewer_PolygonSketcher( this, type );
2961 void OCCViewer_ViewWindow::initSketchers()
2963 if ( mySketchers.isEmpty() )
2965 mySketchers.append( createSketcher( Rect ) );
2966 mySketchers.append( createSketcher( Polygon ) );
2970 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
2972 OCCViewer_ViewSketcher* sketcher = 0;
2973 QList<OCCViewer_ViewSketcher*>::Iterator it;
2974 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
2976 OCCViewer_ViewSketcher* sk = (*it);
2977 if ( sk->type() == typ )
2984 Handles requests for sketching in the active view. [ virtual public ]
2986 void OCCViewer_ViewWindow::activateSketching( int type )
2988 OCCViewer_ViewPort3d* vp = getViewPort();
2992 if ( !vp->isSketchingEnabled() )
2995 /* Finish current sketching */
2996 if ( type == NoSketching )
3000 onSketchingFinished();
3001 mypSketcher->deactivate();
3005 /* Activate new sketching */
3008 activateSketching( NoSketching ); /* concurrency not suported */
3009 mypSketcher = getSketcher( type );
3012 mypSketcher->activate();
3013 onSketchingStarted();
3019 Unhilights detected entities. [ virtual protected ]
3021 void OCCViewer_ViewWindow::onSketchingStarted()
3026 Selection by rectangle or polygon. [ virtual protected ]
3028 void OCCViewer_ViewWindow::onSketchingFinished()
3030 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
3031 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
3033 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
3034 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
3035 switch( mypSketcher->type() )
3039 QRect* aRect = (QRect*)mypSketcher->data();
3042 int aLeft = aRect->left();
3043 int aRight = aRect->right();
3044 int aTop = aRect->top();
3045 int aBottom = aRect->bottom();
3049 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
3051 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
3057 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
3060 int size = aPolygon->size();
3061 TColgp_Array1OfPnt2d anArray( 1, size );
3063 QPolygon::Iterator it = aPolygon->begin();
3064 QPolygon::Iterator itEnd = aPolygon->end();
3065 for( int index = 1; it != itEnd; ++it, index++ )
3067 QPoint aPoint = *it;
3068 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
3072 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
3074 ic->Select( anArray, getViewPort()->getView(), Standard_False );
3082 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
3083 aViewMgr->getOCCViewer()->performSelectionChanged();
3087 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
3092 bool OCCViewer_ViewWindow::transformRequested() const
3094 return ( myOperation != NOTHING );
3097 bool OCCViewer_ViewWindow::transformInProcess() const
3099 return myEventStarted;
3102 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
3104 myEventStarted = bOn;
3108 Set enabled state of transformation (rotate, zoom, etc)
3110 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
3112 if ( id != NOTHING ) myStatus.insert( id, on );
3116 \return enabled state of transformation (rotate, zoom, etc)
3118 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
3120 return myStatus.contains( id ) ? myStatus[ id ] : true;
3123 void OCCViewer_ViewWindow::onMaximizedView()
3125 setMaximized(!isMaximized());
3128 void OCCViewer_ViewWindow::returnTo3dView()
3130 setReturnedTo3dView( true );
3133 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
3135 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
3136 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
3137 if ( !isVisible3dView )
3138 toolMgr()->show( ReturnTo3dViewId );
3140 toolMgr()->hide( ReturnTo3dViewId );
3141 if ( isVisible3dView ) emit returnedTo3d( );
3145 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
3147 QAction* anAction = toolMgr()->action( MaximizedId );
3148 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
3149 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
3151 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
3152 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
3153 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
3154 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
3155 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
3157 emit maximized( this, true );
3161 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
3162 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
3163 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
3164 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
3165 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
3167 emit maximized( this, false );
3172 bool OCCViewer_ViewWindow::isMaximized() const
3174 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
3177 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
3179 IsSketcherStyle = enable;
3182 bool OCCViewer_ViewWindow::isSketcherStyle() const
3184 return IsSketcherStyle;
3188 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
3193 int OCCViewer_ViewWindow::projectionType() const
3195 int mode = Orthographic;
3196 Handle(V3d_View) aView3d = myViewPort->getView();
3197 if ( !aView3d.IsNull() ) {
3198 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3199 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Perspective)
3201 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Orthographic)
3202 mode = Orthographic;
3203 #if OCC_VERSION_LARGE > 0x06090000
3204 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
3211 void OCCViewer_ViewWindow::setStereoType( int type )
3213 Handle(V3d_View) aView3d = myViewPort->getView();
3214 if ( !aView3d.IsNull() ) {
3215 #if OCC_VERSION_LARGE > 0x06090000
3216 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3217 aParams->StereoMode = (Graphic3d_StereoMode)type;
3222 int OCCViewer_ViewWindow::stereoType() const
3224 int type = QuadBuffer;
3225 Handle(V3d_View) aView3d = myViewPort->getView();
3226 if ( !aView3d.IsNull() ) {
3227 #if OCC_VERSION_LARGE > 0x06090000
3228 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3229 type = (OCCViewer_ViewWindow::StereoType)aParams->StereoMode;
3235 void OCCViewer_ViewWindow::setAnaglyphFilter( int type )
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 (type == RedCyan)
3242 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
3243 if (type == YellowBlue)
3244 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
3245 if (type == GreenMagenta)
3246 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
3251 int OCCViewer_ViewWindow::anaglyphFilter() const
3254 Handle(V3d_View) aView3d = myViewPort->getView();
3255 if ( !aView3d.IsNull() ) {
3256 #if OCC_VERSION_LARGE > 0x06090000
3257 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3258 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized)
3260 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized)
3262 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple)
3263 type = GreenMagenta;
3269 void OCCViewer_ViewWindow::setStereographicFocus( int type, double value )
3271 Handle(V3d_View) aView3d = myViewPort->getView();
3272 if ( !aView3d.IsNull() ) {
3273 #if OCC_VERSION_LARGE > 0x06090000
3274 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3275 aCamera->SetZFocus( (Graphic3d_Camera::FocusType) type, value );
3280 int OCCViewer_ViewWindow::stereographicFocusType() const
3282 int type = Relative;
3283 Handle(V3d_View) aView3d = myViewPort->getView();
3284 if ( !aView3d.IsNull() ) {
3285 #if OCC_VERSION_LARGE > 0x06090000
3286 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3287 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->ZFocusType();
3293 double OCCViewer_ViewWindow::stereographicFocusValue() const
3296 Handle(V3d_View) aView3d = myViewPort->getView();
3297 if ( !aView3d.IsNull() ) {
3298 #if OCC_VERSION_LARGE > 0x06090000
3299 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3300 value = aCamera->ZFocus();
3306 void OCCViewer_ViewWindow::setInterocularDistance( int type, double value )
3308 Handle(V3d_View) aView3d = myViewPort->getView();
3309 if ( !aView3d.IsNull() ) {
3310 #if OCC_VERSION_LARGE > 0x06090000
3311 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3312 aCamera->SetIOD( (Graphic3d_Camera::IODType) type, value );
3317 int OCCViewer_ViewWindow::interocularDistanceType() const
3319 int type = Relative;
3320 Handle(V3d_View) aView3d = myViewPort->getView();
3321 if ( !aView3d.IsNull() ) {
3322 #if OCC_VERSION_LARGE > 0x06090000
3323 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3324 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->GetIODType();
3330 double OCCViewer_ViewWindow::interocularDistanceValue() const
3332 double value = 0.05;
3333 Handle(V3d_View) aView3d = myViewPort->getView();
3334 if ( !aView3d.IsNull() ) {
3335 #if OCC_VERSION_LARGE > 0x06090000
3336 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3337 value = aCamera->IOD();
3343 void OCCViewer_ViewWindow::setReverseStereo( bool reverse )
3345 Handle(V3d_View) aView3d = myViewPort->getView();
3346 if ( !aView3d.IsNull() ) {
3347 #if OCC_VERSION_LARGE > 0x06090000
3348 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3349 aParams->ToReverseStereo = reverse;
3354 bool OCCViewer_ViewWindow::isReverseStereo() const
3356 int reverse = false;
3357 Handle(V3d_View) aView3d = myViewPort->getView();
3358 if ( !aView3d.IsNull() ) {
3359 #if OCC_VERSION_LARGE > 0x06090000
3360 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3361 reverse = aParams->ToReverseStereo;
3367 void OCCViewer_ViewWindow::setVSync( bool enable )
3369 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3370 if ( !anIntCont.IsNull() ) {
3371 #if OCC_VERSION_LARGE > 0x06090000
3372 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3373 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3374 aCaps->swapInterval = enable;
3379 bool OCCViewer_ViewWindow::isVSync() const
3382 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3383 if ( !anIntCont.IsNull() ) {
3384 #if OCC_VERSION_LARGE > 0x06090000
3385 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3386 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3387 enable = aCaps->swapInterval;
3393 void OCCViewer_ViewWindow::setQuadBufferSupport( bool enable )
3395 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3396 if ( !anIntCont.IsNull() ) {
3397 #if OCC_VERSION_LARGE > 0x06090000
3398 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3399 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3400 aCaps->contextStereo = enable;
3405 bool OCCViewer_ViewWindow::isQuadBufferSupport() const
3408 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3409 if ( !anIntCont.IsNull() ) {
3410 #if OCC_VERSION_LARGE > 0x06090000
3411 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3412 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3413 enable = aCaps->contextStereo;
3420 bool OCCViewer_ViewWindow::isOpenGlStereoSupport() const
3422 GLboolean support[1];
3423 glGetBooleanv (GL_STEREO, support);
3430 QColor OCCViewer_ViewWindow::backgroundColor() const
3432 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
3436 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
3438 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
3441 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
3443 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
3446 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
3448 if ( myViewPort ) myViewPort->setBackground( theBackground );
3451 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
3453 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
3459 void OCCViewer_ViewWindow::clearViewAspects()
3461 myViewAspects.clear();
3465 \return const reference to list of view aspects
3467 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
3469 return myViewAspects;
3473 Appends new view aspect
3474 \param aParams - new view aspects
3476 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
3478 myViewAspects.append( aParams );
3482 Replaces old view aspects by new ones
3483 \param aViewList - list of new view aspects
3485 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
3487 myViewAspects = aViewList;
3491 Get camera properties for the OCC view window.
3492 \return shared pointer on camera properties.
3494 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
3496 SUIT_CameraProperties aProps;
3498 Handle(V3d_View) aSourceView = getViewPort()->getView();
3499 if ( aSourceView.IsNull() )
3502 if ( get2dMode() == No2dMode ) {
3503 aProps.setDimension( SUIT_CameraProperties::Dim3D );
3506 aProps.setDimension( SUIT_CameraProperties::Dim2D );
3507 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
3510 // read common properites of the view
3511 Standard_Real anUp[3];
3512 Standard_Real anAt[3];
3513 Standard_Real anEye[3];
3514 Standard_Real aProj[3];
3515 Standard_Real anAxialScale[3];
3517 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
3518 aSourceView->At( anAt[0], anAt[1], anAt[2] );
3519 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
3520 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3522 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3523 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
3525 #if OCC_VERSION_LARGE > 0x06070100
3526 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
3528 // store camera properties "as is": it is up to synchronized
3529 // view classes to provide necessary property conversion.
3530 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
3531 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
3533 if ( aSourceView->Camera()->IsOrthographic() )
3535 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
3536 aProps.setViewAngle( 0.0 );
3540 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
3541 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
3543 aProps.setMappingScale( aSourceView->Camera()->Scale() );
3545 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
3547 // generate view orientation matrix for transforming OCC projection reference point
3548 // into a camera (eye) position.
3549 gp_Dir aLeftDir = gp_Dir( anUp[0], anUp[1], anUp[2] ) ^ gp_Dir( aProj[0], aProj[1], aProj[2] );
3552 aTrsf.SetValue( 1, 1, aLeftDir.X() );
3553 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
3554 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
3556 aTrsf.SetValue( 1, 2, anUp[0] );
3557 aTrsf.SetValue( 2, 2, anUp[1] );
3558 aTrsf.SetValue( 3, 2, anUp[2] );
3560 aTrsf.SetValue( 1, 3, aProj[0] );
3561 aTrsf.SetValue( 2, 3, aProj[1] );
3562 aTrsf.SetValue( 3, 3, aProj[2] );
3564 aTrsf.SetValue( 1, 4, anAt[0] );
3565 aTrsf.SetValue( 2, 4, anAt[1] );
3566 aTrsf.SetValue( 3, 4, anAt[2] );
3568 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
3570 // transform to world-space coordinate system
3571 gp_XYZ aPosition( aProjRef.X(), aProjRef.Y(), aCameraDepth );
3572 aTrsf.Transforms( aPosition );
3574 // compute focal point
3575 double aFocalPoint[3];
3577 aFocalPoint[0] = aPosition.X() - aProj[0] * aCameraDepth;
3578 aFocalPoint[1] = aPosition.Y() - aProj[1] * aCameraDepth;
3579 aFocalPoint[2] = aPosition.Z() - aProj[2] * aCameraDepth;
3581 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3582 aProps.setPosition( aPosition.X(), aPosition.Y(), aPosition.Z() );
3584 Standard_Real aViewScale[2];
3585 aSourceView->Size( aViewScale[0], aViewScale[1] );
3586 aProps.setMappingScale( aViewScale[1] );
3594 This implementation synchronizes OCC view's camera propreties.
3596 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
3598 bool blocked = blockSignals( true );
3600 SUIT_CameraProperties aProps = theView->cameraProperties();
3601 if ( !cameraProperties().isCompatible( aProps ) ) {
3602 // other view, this one is being currently synchronized to, seems has become incompatible
3603 // we have to break synchronization
3608 Handle(V3d_View) aDestView = getViewPort()->getView();
3610 aDestView->SetImmediateUpdate( Standard_False );
3613 double aPosition[3];
3614 double aFocalPoint[3];
3615 double anAxialScale[3];
3617 // get common properties
3618 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3619 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
3620 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3621 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3623 #if OCC_VERSION_LARGE > 0x06070100
3624 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3625 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
3626 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3627 aDestView->Camera()->SetScale( aProps.getMappingScale() );
3629 gp_Dir aProjDir( aPosition[0] - aFocalPoint[0],
3630 aPosition[1] - aFocalPoint[1],
3631 aPosition[2] - aFocalPoint[2] );
3633 // get custom view translation
3634 Standard_Real aTranslation[3];
3635 aDestView->At( aTranslation[0], aTranslation[1], aTranslation[2] );
3637 gp_Dir aLeftDir = gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] )
3638 ^ gp_Dir( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
3641 aTrsf.SetValue( 1, 1, aLeftDir.X() );
3642 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
3643 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
3645 aTrsf.SetValue( 1, 2, anUpDir[0] );
3646 aTrsf.SetValue( 2, 2, anUpDir[1] );
3647 aTrsf.SetValue( 3, 2, anUpDir[2] );
3649 aTrsf.SetValue( 1, 3, aProjDir.X() );
3650 aTrsf.SetValue( 2, 3, aProjDir.Y() );
3651 aTrsf.SetValue( 3, 3, aProjDir.Z() );
3653 aTrsf.SetValue( 1, 4, aTranslation[0] );
3654 aTrsf.SetValue( 2, 4, aTranslation[1] );
3655 aTrsf.SetValue( 3, 4, aTranslation[2] );
3658 // transform to view-space coordinate system
3659 gp_XYZ aProjRef( aPosition[0], aPosition[1], aPosition[2] );
3660 aTrsf.Transforms( aProjRef );
3662 // set view camera properties using low-level approach. this is done
3663 // in order to avoid interference with static variables in v3d view used
3664 // when rotation is in process in another view.
3665 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
3666 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
3668 Graphic3d_Vector aMappingProj( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
3669 Graphic3d_Vector aMappingUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3671 aMappingProj.Normalize();
3672 aMappingUp.Normalize();
3674 anOrientation.SetViewReferencePlane( aMappingProj );
3675 anOrientation.SetViewReferenceUp( aMappingUp );
3677 aDestView->SetViewMapping( aMapping );
3678 aDestView->SetViewOrientation( anOrientation );
3681 aDestView->SetCenter( aProjRef.X(), aProjRef.Y() );
3683 // set mapping scale
3684 double aMapScaling = aProps.getMappingScale();
3685 Standard_Real aWidth, aHeight;
3686 aDestView->Size( aWidth, aHeight );
3687 aDestView->SetSize ( aWidth > aHeight ? aMapScaling * (aWidth / aHeight) : aMapScaling );
3690 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3691 #if OCC_VERSION_LARGE <= 0x07000000
3692 aDestView->ZFitAll();
3694 aDestView->SetImmediateUpdate( Standard_True );
3695 aDestView->Redraw();
3697 blockSignals( blocked );
3701 \brief Indicates whether preselection is enabled
3702 \return true if preselection is enabled
3704 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
3706 return myPreselectionEnabled;
3710 \brief Enables/disables preselection
3711 \param theIsToEnable if true - preselection will be enabled
3713 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
3715 onSwitchPreselection( theIsToEnable );
3719 \brief Indicates whether selection is enabled
3720 \return true if selection is enabled
3722 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3724 return mySelectionEnabled;
3728 \brief Enables/disables selection
3729 \param theIsToEnable if true - selection will be enabled
3731 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3733 onSwitchSelection( theIsToEnable );
3738 \brief called if clipping operation is activated / deactivated.
3740 Enables/disables clipping plane displaying.
3742 \parma on action state
3744 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3746 if(!myModel) return;
3747 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3750 if (!aClippingDlg) {
3751 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3752 myModel->setClippingDlg(aClippingDlg);
3754 if (!aClippingDlg->isVisible())
3755 aClippingDlg->show();
3757 if ( aClippingDlg ) {
3758 aClippingDlg->close();
3759 myModel->setClippingDlg(0);
3763 SUIT_ViewManager* mgr = getViewManager();
3765 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3766 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3767 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3768 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3770 QAction* a = toolMgr()->action( ClippingId );
3772 if(theIsOn != a->isChecked()){
3773 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3774 a->setChecked(theIsOn);
3775 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3782 void OCCViewer_ViewWindow::onRayTracing()
3784 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_RayTracingDlg::getName() ) ) {
3785 QDialog* aDlg = new OCCViewer_RayTracingDlg( this );
3791 void OCCViewer_ViewWindow::onEnvTexture()
3793 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_EnvTextureDlg::getName() ) ) {
3794 QDialog* aDlg = new OCCViewer_EnvTextureDlg( this );
3800 void OCCViewer_ViewWindow::onLightSource()
3802 if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_LightSourceDlg::getName() ) ) {
3803 QDialog* aDlg = new OCCViewer_LightSourceDlg( this, myModel );