1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : OCCViewer_ViewWindow.cxx
26 #include "OCCViewer_ViewWindow.h"
27 #include "OCCViewer_ViewModel.h"
28 #include "OCCViewer_ViewPort3d.h"
29 #include "OCCViewer_ViewManager.h"
30 #include "OCCViewer_ViewSketcher.h"
31 #include "OCCViewer_CreateRestoreViewDlg.h"
32 #include "OCCViewer_ClipPlane.h"
33 #include "OCCViewer_SetRotationPointDlg.h"
34 #include "OCCViewer_AxialScaleDlg.h"
35 #include "OCCViewer_CubeAxesDlg.h"
36 #include "OCCViewer_ClippingDlg.h"
38 #include <SUIT_Desktop.h>
39 #include <SUIT_Session.h>
40 #include <SUIT_ViewManager.h>
41 #include <SUIT_Tools.h>
42 #include <SUIT_ResourceMgr.h>
43 #include <SUIT_MessageBox.h>
44 #include <SUIT_Application.h>
46 #include <QtxActionToolMgr.h>
47 #include <QtxMultiAction.h>
48 #include <QtxRubberBand.h>
50 #include <Basics_OCCTVersion.hxx>
56 #include <QMouseEvent>
57 #include <QApplication>
58 #include <QActionGroup>
61 #include <AIS_ListOfInteractive.hxx>
62 #include <AIS_ListIteratorOfListOfInteractive.hxx>
63 #include <AIS_Shape.hxx>
65 #include <BRep_Tool.hxx>
66 #include <BRepBndLib.hxx>
67 #include <BRepGProp.hxx>
68 #include <GProp_GProps.hxx>
71 #include <Graphic3d_SequenceOfHClipPlane.hxx>
72 #include <Graphic3d_ClipPlane.hxx>
73 #include <OpenGl_GraphicDriver.hxx>
74 #include <OpenGLUtils_FrameBuffer.h>
76 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
77 #include <Graphic3d_MapOfStructure.hxx>
78 #include <Graphic3d_Structure.hxx>
79 #include <Graphic3d_ExportFormat.hxx>
80 #if OCC_VERSION_LARGE > 0x06090000
81 #include <Graphic3d_StereoMode.hxx>
82 #include <Graphic3d_RenderingParams.hxx>
86 #include <Visual3d_View.hxx>
87 #include <V3d_Plane.hxx>
88 #include <V3d_Light.hxx>
92 #include <gp_GTrsf.hxx>
93 #include <TColgp_Array1OfPnt2d.hxx>
95 #include <Image_PixMap.hxx>
97 #include <Standard_Version.hxx>
99 #include "utilities.h"
101 // // OpenCV includes
103 // #include <highgui.h>
105 static QEvent* l_mbPressEvent = 0;
108 # include <QWindowsStyle>
113 // To avoid conflict between KeyPress from the X.h (define KeyPress 2)
114 // and QEvent::KeyPress (qevent.h)
119 const char* imageZoomCursor[] = {
124 "................................",
125 "................................",
126 ".#######........................",
127 "..aaaaaaa.......................",
128 "................................",
129 ".............#####..............",
130 "...........##.aaaa##............",
131 "..........#.aa.....a#...........",
132 ".........#.a.........#..........",
133 ".........#a..........#a.........",
134 "........#.a...........#.........",
135 "........#a............#a........",
136 "........#a............#a........",
137 "........#a............#a........",
138 "........#a............#a........",
139 ".........#...........#.a........",
140 ".........#a..........#a.........",
141 ".........##.........#.a.........",
142 "........#####.....##.a..........",
143 ".......###aaa#####.aa...........",
144 "......###aa...aaaaa.......#.....",
145 ".....###aa................#a....",
146 "....###aa.................#a....",
147 "...###aa...............#######..",
148 "....#aa.................aa#aaaa.",
149 ".....a....................#a....",
150 "..........................#a....",
151 "...........................a....",
152 "................................",
153 "................................",
154 "................................",
155 "................................"};
157 const char* imageRotateCursor[] = {
162 "................................",
163 "................................",
164 "................................",
165 "................................",
166 "........#.......................",
167 ".......#.a......................",
168 "......#######...................",
169 ".......#aaaaa#####..............",
170 "........#..##.a#aa##........##..",
171 ".........a#.aa..#..a#.....##.aa.",
172 ".........#.a.....#...#..##.aa...",
173 ".........#a.......#..###.aa.....",
174 "........#.a.......#a..#aa.......",
175 "........#a.........#..#a........",
176 "........#a.........#a.#a........",
177 "........#a.........#a.#a........",
178 "........#a.........#a.#a........",
179 ".........#.........#a#.a........",
180 "........##a........#a#a.........",
181 "......##.a#.......#.#.a.........",
182 "....##.aa..##.....##.a..........",
183 "..##.aa.....a#####.aa...........",
184 "...aa.........aaa#a.............",
185 "................#.a.............",
186 "...............#.a..............",
187 "..............#.a...............",
188 "...............a................",
189 "................................",
190 "................................",
191 "................................",
192 "................................",
193 "................................"};
195 const char* imageCrossCursor[] = {
200 "................................",
201 "................................",
202 "................................",
203 "................................",
204 "................................",
205 "................................",
206 "................................",
207 "...............#................",
208 "...............#a...............",
209 "...............#a...............",
210 "...............#a...............",
211 "...............#a...............",
212 "...............#a...............",
213 "...............#a...............",
214 "...............#a...............",
215 ".......#################........",
216 "........aaaaaaa#aaaaaaaaa.......",
217 "...............#a...............",
218 "...............#a...............",
219 "...............#a...............",
220 "...............#a...............",
221 "...............#a...............",
222 "...............#a...............",
223 "...............#a...............",
224 "................a...............",
225 "................................",
226 "................................",
227 "................................",
228 "................................",
229 "................................",
230 "................................",
231 "................................"};
236 \param theDesktop main window of application
237 \param theModel OCC 3D viewer
239 OCCViewer_ViewWindow::OCCViewer_ViewWindow( SUIT_Desktop* theDesktop,
240 OCCViewer_Viewer* theModel )
241 : SUIT_ViewWindow( theDesktop )
245 myEnableDrawMode = false;
246 myDrawRectEnabled = true;
248 updateEnabledDrawMode();
250 mySetRotationPointDlg = 0;
253 IsSketcherStyle = false;
260 myInteractionStyle = SUIT_ViewModel::STANDARD;
261 myPreselectionEnabled = true;
262 mySelectionEnabled = true;
264 myCursorIsHand = false;
272 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
275 qDeleteAll( mySketchers );
279 \brief Internal initialization.
281 void OCCViewer_ViewWindow::initLayout()
283 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
284 myViewPort->installEventFilter(this);
285 setCentralWidget(myViewPort);
286 myOperation = NOTHING;
288 myCurrPointType = GRAVITY;
289 myPrevPointType = GRAVITY;
290 mySelectedPoint = gp_Pnt(0.,0.,0.);
291 myRotationPointSelection = false;
293 setTransformRequested ( NOTHING );
294 setTransformInProcess ( false );
311 // Graduated axes dialog
312 QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
313 myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
314 myCubeAxesDlg->initialize();
316 connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
319 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
321 return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
325 \brief Detect viewer operation according the the mouse button pressed
326 and key modifiers used.
327 \param theEvent mouse event
328 \return type of the operation
330 OCCViewer_ViewWindow::OperationType
331 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
333 OperationType aOp = NOTHING;
334 SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
335 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
336 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
338 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
339 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
341 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
342 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
343 (my2dMode == No2dMode))
350 \brief Customize event handling
351 \param watched event receiver object
353 \return \c true if the event processing should be stopped
355 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
357 if ( watched == myViewPort ) {
358 int aType = e->type();
360 case QEvent::MouseButtonPress:
361 vpMousePressEvent((QMouseEvent*) e);
364 case QEvent::MouseButtonRelease:
365 vpMouseReleaseEvent((QMouseEvent*) e);
368 case QEvent::MouseMove:
369 vpMouseMoveEvent((QMouseEvent*) e);
372 case QEvent::MouseButtonDblClick:
373 emit mouseDoubleClicked(this, (QMouseEvent*)e);
378 QWheelEvent* aEvent = (QWheelEvent*) e;
380 if ( aEvent->modifiers().testFlag(Qt::ControlModifier) ) {
381 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
382 if ( isPreselectionEnabled() && ic->HasOpenedContext() ) {
383 if ( aEvent->delta() > 0 ) {
384 ic->HilightNextDetected( myViewPort->getView() );
386 ic->HilightPreviousDetected( myViewPort->getView() );
391 emit vpTransformationStarted ( ZOOMVIEW );
392 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
393 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
396 int x1 = (int)( aEvent->x() + width()*delta/100 );
397 int y1 = (int)( aEvent->y() + height()*delta/100 );
398 myViewPort->zoom( x, y, x1, y1 );
399 myViewPort->getView()->ZFitAll();
400 emit vpTransformationFinished ( ZOOMVIEW );
405 case QEvent::ContextMenu:
407 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
408 if ( aEvent->reason() != QContextMenuEvent::Mouse )
409 emit contextMenuRequested( aEvent );
413 case QEvent::KeyPress:
414 emit keyPressed(this, (QKeyEvent*) e);
421 return SUIT_ViewWindow::eventFilter(watched, e);
425 \brief Enable / disable draw rect (rubber band) mode
427 bool OCCViewer_ViewWindow::enableDrawMode( bool on )
429 bool prev = myDrawRectEnabled;
430 myDrawRectEnabled = on;
431 updateEnabledDrawMode();
436 \brief Update state of enable draw mode state.
438 void OCCViewer_ViewWindow::updateEnabledDrawMode()
440 myEnableDrawMode = myDrawRectEnabled;
442 myEnableDrawMode = myEnableDrawMode && myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
446 \brief Handle mouse press event
447 \param theEvent mouse event
449 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
451 myStartX = theEvent->x();
452 myStartY = theEvent->y();
453 int anInteractionStyle = interactionStyle();
455 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
456 // which are assigned for pan and rotate - these operations are activated immediately after pressing
457 // of the first button, so it is necessary to switch to zoom when the second button is pressed
458 bool aSwitchToZoom = false;
459 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
460 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
461 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
464 switch ( myOperation ) {
466 if ( theEvent->button() == Qt::LeftButton )
467 emit vpTransformationStarted ( WINDOWFIT );
471 if ( theEvent->button() == Qt::LeftButton )
472 emit vpTransformationStarted ( PANGLOBAL );
476 if ( theEvent->button() == Qt::LeftButton ) {
477 myViewPort->startZoomAtPoint( myStartX, myStartY );
478 emit vpTransformationStarted ( ZOOMVIEW );
483 if ( aSwitchToZoom ) {
484 myViewPort->startZoomAtPoint( myStartX, myStartY );
487 else if ( theEvent->button() == Qt::LeftButton )
488 emit vpTransformationStarted ( PANVIEW );
492 if ( aSwitchToZoom ) {
493 myViewPort->startZoomAtPoint( myStartX, myStartY );
496 else if ( theEvent->button() == Qt::LeftButton ) {
497 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
498 emit vpTransformationStarted ( ROTATE );
503 /* Try to activate a transformation */
504 OperationType aState;
505 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
506 aState = getButtonState(theEvent, anInteractionStyle);
508 aState = OCCViewer_ViewWindow::NOTHING;
513 myViewPort->startZoomAtPoint( myStartX, myStartY );
521 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
524 if ( myRotationPointSelection )
526 if ( theEvent->button() == Qt::LeftButton )
528 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
530 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
532 TopoDS_Shape aShape = ic->SelectedShape();
533 GProp_GProps aSystem;
535 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
537 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
539 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE )
541 BRepGProp::LinearProperties( aShape, aSystem );
542 aPnt = aSystem.CentreOfMass();
544 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE )
546 BRepGProp::SurfaceProperties( aShape, aSystem );
547 aPnt = aSystem.CentreOfMass();
549 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID )
551 BRepGProp::VolumeProperties( aShape, aSystem );
552 aPnt = aSystem.CentreOfMass();
556 myCurrPointType = myPrevPointType;
560 if ( mySetRotationPointDlg )
562 myRotationPointSelection = false;
563 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
566 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
567 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
568 ic->CloseAllContexts();
569 myOperation = NOTHING;
570 myViewPort->setCursor( myCursor );
571 myCursorIsHand = false;
572 myRotationPointSelection = false;
576 emit mousePressed(this, theEvent);
579 /* notify that we start a transformation */
580 if ( transformRequested() )
581 emit vpTransformationStarted ( myOperation );
583 if ( transformRequested() )
584 setTransformInProcess( true );
586 /* we may need it for sketching... */
587 if ( l_mbPressEvent )
588 delete l_mbPressEvent;
589 l_mbPressEvent = new QMouseEvent( *theEvent );
594 \brief Start zooming operation.
596 Sets the corresponding cursor for the widget.
598 void OCCViewer_ViewWindow::activateZoom()
600 if ( !transformRequested() && !myCursorIsHand )
601 saveCursor(); /* save old cursor */
603 if ( myOperation != ZOOMVIEW ) {
604 QPixmap zoomPixmap (imageZoomCursor);
605 QCursor zoomCursor (zoomPixmap);
606 if( setTransformRequested ( ZOOMVIEW ) )
607 myViewPort->setCursor( zoomCursor );
613 \brief Start panning operation.
615 Sets the corresponding cursor for the widget.
617 void OCCViewer_ViewWindow::activatePanning()
619 if ( !transformRequested() && !myCursorIsHand )
620 saveCursor(); // save old cursor
622 if ( myOperation != PANVIEW ) {
623 QCursor panCursor (Qt::SizeAllCursor);
624 if( setTransformRequested ( PANVIEW ) )
625 myViewPort->setCursor( panCursor );
630 \brief Start rotation operation
632 Sets the corresponding cursor for the widget.
634 void OCCViewer_ViewWindow::activateRotation()
636 if ( !transformRequested() && !myCursorIsHand )
637 saveCursor(); // save old cursor
639 if ( myOperation != ROTATE ) {
640 QPixmap rotatePixmap (imageRotateCursor);
641 QCursor rotCursor (rotatePixmap);
642 if( setTransformRequested ( ROTATE ) )
643 myViewPort->setCursor( rotCursor );
648 \brief Compute the gravity center.
649 \param theX used to return X coordinate of the gravity center
650 \param theY used to return Y coordinate of the gravity center
651 \param theZ used to return Z coordinate of the gravity center
652 \return \c true if the gravity center is computed
654 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
656 Handle(V3d_View) aView3d = myViewPort->getView();
658 // Project boundaries points and add to avergae gravity
659 // the ones which lie within the screen limits
660 Standard_Real aScreenLimits[4] = { 0.0, 0.0, 0.0, 0.0 };
662 #if OCC_VERSION_LARGE > 0x06070100
663 // NDC space screen limits
664 aScreenLimits[0] = -1.0;
665 aScreenLimits[1] = 1.0;
666 aScreenLimits[2] = -1.0;
667 aScreenLimits[3] = 1.0;
669 aView3d->View()->ViewMapping().WindowLimit( aScreenLimits[0],
675 Standard_Integer aPointsNb = 0;
677 Standard_Real aXmin = 0.0;
678 Standard_Real aYmin = 0.0;
679 Standard_Real aZmin = 0.0;
680 Standard_Real aXmax = 0.0;
681 Standard_Real aYmax = 0.0;
682 Standard_Real aZmax = 0.0;
684 Graphic3d_MapOfStructure aSetOfStructures;
685 aView3d->View()->DisplayedStructures( aSetOfStructures );
686 Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures );
688 for( ; aStructureIt.More(); aStructureIt.Next() ) {
689 const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key();
690 if ( aStructure->IsEmpty() || !aStructure->IsVisible() || aStructure->CStructure()->IsForHighlight )
693 #if OCC_VERSION_LARGE > 0x06070100
694 Bnd_Box aBox = aStructure->MinMaxValues();
695 aXmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().X();
696 aYmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Y();
697 aZmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Z();
698 aXmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().X();
699 aYmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Y();
700 aZmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Z();
702 aStructure->MinMaxValues( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
705 // Infinite structures are skipped
706 Standard_Real aLIM = ShortRealLast() - 1.0;
707 if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
708 || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
712 gp_Pnt aPoints[8] = {
713 gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
714 gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
715 gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
716 gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
719 for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
720 const gp_Pnt& aBBPoint = aPoints[aPointIt];
722 #if OCC_VERSION_LARGE > 0x06070100
723 gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
724 const Standard_Real& U = aProjected.X();
725 const Standard_Real& V = aProjected.Y();
727 Standard_Real U = 0.0;
728 Standard_Real V = 0.0;
729 Standard_Real W = 0.0;
730 aView3d->View()->Projects( aBBPoint.X(), aBBPoint.Y(), aBBPoint.Z(), U, V, W );
733 if (U >= aScreenLimits[0]
734 && U <= aScreenLimits[1]
735 && V >= aScreenLimits[2]
736 && V <= aScreenLimits[3])
739 theX += aBBPoint.X();
740 theY += aBBPoint.Y();
741 theZ += aBBPoint.Z();
756 \brief Set the gravity center as a rotation point.
758 void OCCViewer_ViewWindow::activateSetRotationGravity()
760 if ( myRotationPointSelection )
762 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
763 ic->CloseAllContexts();
764 myOperation = NOTHING;
765 myViewPort->setCursor( myCursor );
766 myCursorIsHand = false;
767 myRotationPointSelection = false;
770 myPrevPointType = myCurrPointType;
771 myCurrPointType = GRAVITY;
773 Standard_Real Xcenter, Ycenter, Zcenter;
774 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
775 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
779 \brief Update gravity center in the "Set Rotation Point" dialog box.
780 \sa OCCViewer_SetRotationPointDlg class
782 void OCCViewer_ViewWindow::updateGravityCoords()
784 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == GRAVITY )
786 Standard_Real Xcenter, Ycenter, Zcenter;
787 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
788 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
793 \brief Set the point selected by the user as a rotation point.
794 \param theX X coordinate of the rotation point
795 \param theY Y coordinate of the rotation point
796 \param theZ Z coordinate of the rotation point
798 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
800 if ( myRotationPointSelection )
802 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
803 ic->CloseAllContexts();
804 myOperation = NOTHING;
805 myViewPort->setCursor( myCursor );
806 myCursorIsHand = false;
807 myRotationPointSelection = false;
810 myPrevPointType = myCurrPointType;
811 myCurrPointType = SELECTED;
812 mySelectedPoint.SetCoord(theX,theY,theZ);
816 \brief Start the shape selection process.
818 void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
820 myPrevPointType = myCurrPointType;
821 myCurrPointType = SELECTED;
823 // activate selection ------>
824 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
826 ic->OpenLocalContext();
828 AIS_ListOfInteractive aList;
829 ic->DisplayedObjects( aList );
830 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
832 Handle(AIS_InteractiveObject) anObj = it.Value();
833 if ( !anObj.IsNull() && anObj->HasPresentation() &&
834 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
837 ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
840 // activate selection <------
842 if ( !myCursorIsHand )
844 QCursor handCursor (Qt::PointingHandCursor);
845 myCursorIsHand = true;
847 myViewPort->setCursor( handCursor );
849 myRotationPointSelection = true;
853 \brief Start global panning operation
855 Sets the corresponding cursor for the widget.
857 void OCCViewer_ViewWindow::activateGlobalPanning()
859 Handle(V3d_View) aView3d = myViewPort->getView();
860 if ( !aView3d.IsNull() ) {
861 QPixmap globalPanPixmap (imageCrossCursor);
862 QCursor glPanCursor (globalPanPixmap);
863 myCurScale = aView3d->Scale();
864 aView3d->FitAll(0.01, false);
865 saveCursor(); // save old cursor
866 myViewPort->fitAll(); // fits view before selecting a new scene center
867 if( setTransformRequested( PANGLOBAL ) )
868 myViewPort->setCursor( glPanCursor );
873 \brief Starts fit operation.
875 Sets the corresponding cursor for the widget.
877 void OCCViewer_ViewWindow::activateWindowFit()
879 if ( !transformRequested() && !myCursorIsHand )
880 saveCursor(); /* save old cursor */
882 if ( myOperation != WINDOWFIT ) {
883 QCursor handCursor (Qt::PointingHandCursor);
884 if( setTransformRequested ( WINDOWFIT ) )
886 myViewPort->setCursor ( handCursor );
887 myCursorIsHand = true;
893 \brief Start delayed viewer operation.
895 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
897 bool ok = transformEnabled( op );
898 myOperation = ok ? op : NOTHING;
899 myViewPort->setMouseTracking( myOperation == NOTHING );
904 \brief Handle mouse move event.
905 \param theEvent mouse event
907 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
909 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
911 switch ( getButtonState( theEvent, interactionStyle() ) ) {
913 myViewPort->startZoomAtPoint( myStartX, myStartY );
921 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
928 myCurrX = theEvent->x();
929 myCurrY = theEvent->y();
930 switch (myOperation) {
932 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
936 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
942 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
956 if ( myRotationPointSelection || isSketcherStyle() )
958 emit mouseMoving( this, theEvent );
962 int aState = theEvent->modifiers();
963 int aButton = theEvent->buttons();
964 int anInteractionStyle = interactionStyle();
965 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
966 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
967 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
968 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
969 myDrawRect = myEnableDrawMode;
972 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
973 QCursor handCursor (Qt::PointingHandCursor);
974 myCursorIsHand = true;
976 myViewPort->setCursor( handCursor );
979 emit mouseMoving( this, theEvent );
981 else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
982 aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
983 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
984 aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
985 OCCViewer_ViewSketcher* sketcher = 0;
986 QList<OCCViewer_ViewSketcher*>::Iterator it;
987 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
989 OCCViewer_ViewSketcher* sk = (*it);
990 if( sk->isDefault() && sk->sketchButton() == aButton )
993 if ( sketcher && myCurSketch == -1 )
995 activateSketching( sketcher->type() );
998 myCurSketch = mypSketcher->sketchButton();
1000 if ( l_mbPressEvent )
1002 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
1003 delete l_mbPressEvent;
1006 QApplication::sendEvent( getViewPort(), theEvent );
1011 emit mouseMoving( this, theEvent );
1017 \brief Handle mouse release event.
1018 \param theEvent mouse event
1020 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
1022 switch ( myOperation ) {
1025 int prevState = myCurSketch;
1026 if(theEvent->button() == Qt::RightButton)
1028 QList<OCCViewer_ViewSketcher*>::Iterator it;
1029 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
1031 OCCViewer_ViewSketcher* sk = (*it);
1032 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
1037 emit mouseReleased(this, theEvent);
1038 if(theEvent->button() == Qt::RightButton && prevState == -1)
1040 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1041 theEvent->pos(), theEvent->globalPos() );
1042 emit contextMenuRequested( &aEvent );
1047 myViewPort->endRotation();
1053 myViewPort->getView()->ZFitAll();
1058 if ( theEvent->button() == Qt::LeftButton ) {
1059 myViewPort->setCenter( theEvent->x(), theEvent->y() );
1060 myViewPort->getView()->SetScale(myCurScale);
1066 if ( theEvent->button() == Qt::LeftButton ) {
1067 myCurrX = theEvent->x();
1068 myCurrY = theEvent->y();
1070 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1071 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1078 // NOTE: viewer 3D detects a rectangle of selection using this event
1079 // so we must emit it BEFORE resetting the selection rectangle
1081 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1085 myViewPort->update();
1088 if ( l_mbPressEvent )
1090 delete l_mbPressEvent;
1096 \brief Reset the viewport to its initial state
1097 ( no transformations in process etc. )
1099 void OCCViewer_ViewWindow::resetState()
1103 if ( myRotationPointSelection )
1105 QCursor handCursor (Qt::PointingHandCursor);
1106 myViewPort->setCursor( handCursor );
1110 if ( transformRequested() || myCursorIsHand )
1111 myViewPort->setCursor( myCursor );
1112 myCursorIsHand = false;
1115 if ( transformRequested() )
1116 emit vpTransformationFinished (myOperation);
1118 setTransformInProcess( false );
1119 setTransformRequested( NOTHING );
1124 \brief Draw rubber band rectangle.
1126 void OCCViewer_ViewWindow::drawRect()
1128 if ( !myRectBand ) {
1129 myRectBand = new QtxRectRubberBand( myViewPort );
1131 //palette.setColor(myRectBand->foregroundRole(), Qt::white);
1132 //myRectBand->setPalette(palette);
1134 //myRectBand->hide();
1136 myRectBand->setUpdatesEnabled ( false );
1137 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1138 myRectBand->initGeometry( aRect );
1140 if ( !myRectBand->isVisible() )
1143 myRectBand->setUpdatesEnabled ( true );
1144 //myRectBand->repaint();
1146 //myRectBand->setVisible( aRect.isValid() );
1147 //if ( myRectBand->isVisible() )
1148 // myRectBand->repaint();
1150 // myRectBand->show();
1151 //myRectBand->repaint();
1155 \brief Clear rubber band rectangle on the end on the dragging operation.
1157 void OCCViewer_ViewWindow::endDrawRect()
1159 //delete myRectBand;
1163 myRectBand->clearGeometry();
1169 \brief Create actions.
1171 void OCCViewer_ViewWindow::createActions()
1173 if( !toolMgr()->isEmpty() )
1176 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1181 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1182 tr( "MNU_DUMP_VIEW" ), 0, this);
1183 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1184 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1185 toolMgr()->registerAction( aAction, DumpId );
1188 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1189 tr( "MNU_FITALL" ), 0, this);
1190 aAction->setStatusTip(tr("DSC_FITALL"));
1191 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1192 toolMgr()->registerAction( aAction, FitAllId );
1195 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1196 tr( "MNU_FITRECT" ), 0, this);
1197 aAction->setStatusTip(tr("DSC_FITRECT"));
1198 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1199 toolMgr()->registerAction( aAction, FitRectId );
1202 aAction = new QtxAction(tr("MNU_FITSELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITSELECTION" ) ),
1203 tr( "MNU_FITSELECTION" ), 0, this);
1204 aAction->setStatusTip(tr("DSC_FITSELECTION"));
1205 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
1206 toolMgr()->registerAction( aAction, FitSelectionId );
1209 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1210 tr( "MNU_ZOOM_VIEW" ), 0, this);
1211 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1212 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1213 toolMgr()->registerAction( aAction, ZoomId );
1216 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1217 tr( "MNU_PAN_VIEW" ), 0, this);
1218 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1219 connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
1220 toolMgr()->registerAction( aAction, PanId );
1223 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1224 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1225 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1226 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1227 toolMgr()->registerAction( aAction, GlobalPanId );
1230 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1231 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1232 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1233 mySetRotationPointAction->setCheckable( true );
1234 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1235 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1238 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1239 tr( "MNU_ROTATE_VIEW" ), 0, this);
1240 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1241 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1242 toolMgr()->registerAction( aAction, RotationId );
1245 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1246 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1247 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1248 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1249 this->addAction(aAction);
1250 toolMgr()->registerAction( aAction, FrontId );
1252 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1253 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1254 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1255 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1256 this->addAction(aAction);
1257 toolMgr()->registerAction( aAction, BackId );
1259 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1260 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1261 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1262 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1263 this->addAction(aAction);
1264 toolMgr()->registerAction( aAction, TopId );
1266 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1267 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1268 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1269 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1270 this->addAction(aAction);
1271 toolMgr()->registerAction( aAction, BottomId );
1273 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1274 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1275 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1276 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1277 this->addAction(aAction);
1278 toolMgr()->registerAction( aAction, LeftId );
1280 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1281 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1282 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1283 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1284 this->addAction(aAction);
1285 toolMgr()->registerAction( aAction, RightId );
1287 // rotate anticlockwise
1288 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1289 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1290 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1291 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1292 this->addAction(aAction);
1293 toolMgr()->registerAction( aAction, AntiClockWiseId );
1296 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1297 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1298 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1299 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1300 this->addAction(aAction);
1301 toolMgr()->registerAction( aAction, ClockWiseId );
1303 // Projection mode group
1305 // - orthographic projection
1306 aAction = new QtxAction(tr("MNU_ORTHOGRAPHIC_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ORTHOGRAPHIC" ) ),
1307 tr( "MNU_ORTHOGRAPHIC_MODE" ), 0, this);
1308 aAction->setStatusTip(tr("DSC_ORTHOGRAPHIC_MODE"));
1309 aAction->setCheckable(true);
1310 toolMgr()->registerAction( aAction, OrthographicId );
1312 // - perspective projection
1313 aAction = new QtxAction(tr("MNU_PERSPECTIVE_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PERSPECTIVE" ) ),
1314 tr( "MNU_PERSPECTIVE_MODE" ), 0, this);
1315 aAction->setStatusTip(tr("DSC_PERSPECTIVE_MODE"));
1316 aAction->setCheckable(true);
1317 toolMgr()->registerAction( aAction, PerspectiveId );
1318 #if OCC_VERSION_LARGE > 0x06090000
1319 // - stereo projection
1320 aAction = new QtxAction(tr("MNU_STEREO_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STEREO" ) ),
1321 tr( "MNU_STEREO_MODE" ), 0, this);
1322 aAction->setStatusTip(tr("DSC_STEREO_MODE"));
1323 aAction->setCheckable(true);
1324 toolMgr()->registerAction( aAction, StereoId );
1325 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onStereoType(bool)));
1327 // - add exclusive action group
1328 QActionGroup* aProjectionGroup = new QActionGroup( this );
1329 aProjectionGroup->addAction( toolMgr()->action( OrthographicId ) );
1330 aProjectionGroup->addAction( toolMgr()->action( PerspectiveId ) );
1331 connect(aProjectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProjectionType(QAction*)));
1334 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1335 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1336 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1337 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1338 this->addAction(aAction);
1339 toolMgr()->registerAction( aAction, ResetId );
1342 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1343 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1344 tr("MNU_CLONE_VIEW"), 0, this);
1345 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1346 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1347 toolMgr()->registerAction( aAction, CloneId );
1349 aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
1350 tr("MNU_CLIPPING"), 0, this);
1351 aAction->setStatusTip (tr("DSC_CLIPPING"));
1352 aAction->setCheckable (true);
1353 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1354 toolMgr()->registerAction (aAction, ClippingId);
1356 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1357 tr( "MNU_SHOOT_VIEW" ), 0, this);
1358 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1359 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1360 toolMgr()->registerAction( aAction, MemId );
1362 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1363 tr( "MNU_PRESETS_VIEW" ), 0, this);
1364 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1365 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1366 toolMgr()->registerAction( aAction, RestoreId );
1368 if (myModel->trihedronActivated()) {
1369 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1370 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1371 aAction->setCheckable( true );
1372 aAction->setChecked( true );
1373 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1374 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1375 toolMgr()->registerAction( aAction, TrihedronShowId );
1379 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1380 tr( "MNU_SCALING" ), 0, this);
1381 aAction->setStatusTip(tr("DSC_SCALING"));
1382 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1383 toolMgr()->registerAction( aAction, AxialScaleId );
1385 // Enable/disable preselection
1386 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1387 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1388 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1389 aAction->setCheckable(true);
1390 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1391 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1393 // Enable/disable selection
1394 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1395 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1396 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1397 aAction->setCheckable(true);
1398 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1399 toolMgr()->registerAction( aAction, SwitchSelectionId );
1402 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1403 tr( "MNU_GRADUATED_AXES" ), 0, this);
1404 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1405 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1406 toolMgr()->registerAction( aAction, GraduatedAxesId );
1408 // Active only ambient light or not
1409 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1410 tr( "MNU_AMBIENT" ), 0, this);
1411 aAction->setStatusTip(tr("DSC_AMBIENT"));
1412 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1413 toolMgr()->registerAction( aAction, AmbientId );
1415 // Switch between interaction styles
1416 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1417 tr( "MNU_STYLE_SWITCH" ), 0, this);
1418 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1419 aAction->setCheckable(true);
1420 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1421 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1423 // Switch between zooming styles
1424 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1425 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1426 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1427 aAction->setCheckable(true);
1428 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1429 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1432 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1433 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1434 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1435 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1436 toolMgr()->registerAction( aAction, MaximizedId );
1438 // Return to 3d view
1439 if (my2dMode!=No2dMode){
1440 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1441 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1442 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1443 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1444 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1448 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1452 \brief Create toolbar.
1454 void OCCViewer_ViewWindow::createToolBar()
1456 static const char* titles[] = {
1457 "LBL_3DTOOLBAR_LABEL",
1458 "LBL_XYTOOLBAR_LABEL",
1459 "LBL_XZTOOLBAR_LABEL",
1460 "LBL_YZTOOLBAR_LABEL",
1462 static const char* names[] = {
1463 "OCCViewer3DViewOperations",
1464 "OCCViewerXYViewOperations",
1465 "OCCViewerXZViewOperations",
1466 "OCCViewerYZViewOperations",
1468 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1469 QString( names[my2dMode] ), // name (language-independant)
1470 false ); // disable floatable toolbar
1471 if ( my2dMode != No2dMode ){
1472 toolMgr()->append( ReturnTo3dViewId, tid );
1473 toolMgr()->append( toolMgr()->separator(), tid );
1475 toolMgr()->append( DumpId, tid );
1476 toolMgr()->append( SwitchInteractionStyleId, tid );
1477 toolMgr()->append( SwitchZoomingStyleId, tid );
1478 toolMgr()->append( SwitchPreselectionId, tid );
1479 toolMgr()->append( SwitchSelectionId, tid );
1480 if( myModel->trihedronActivated() )
1481 toolMgr()->append( TrihedronShowId, tid );
1483 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1484 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1485 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1486 #if OCC_VERSION_LARGE > 0x06090000
1487 aScaleAction->insertAction( toolMgr()->action( FitSelectionId ) );
1489 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1490 toolMgr()->append( aScaleAction, tid );
1492 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1493 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1494 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1495 toolMgr()->append( aPanningAction, tid );
1497 if (my2dMode == No2dMode) {
1498 toolMgr()->append( ChangeRotationPointId, tid );
1499 toolMgr()->append( RotationId, tid );
1501 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1502 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1503 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1504 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1505 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1506 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1507 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1508 toolMgr()->append( aViewsAction, tid );
1510 toolMgr()->append( AntiClockWiseId, tid );
1511 toolMgr()->append( ClockWiseId, tid );
1513 toolMgr()->append( OrthographicId, tid );
1514 toolMgr()->append( PerspectiveId, tid );
1515 #if OCC_VERSION_LARGE > 0x06090000
1516 toolMgr()->append( StereoId, tid );
1519 toolMgr()->append( ResetId, tid );
1522 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1523 aMemAction->insertAction( toolMgr()->action( MemId ) );
1524 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1525 toolMgr()->append( aMemAction, tid );
1527 toolMgr()->append( toolMgr()->separator(), tid );
1528 toolMgr()->append( CloneId, tid );
1530 toolMgr()->append( toolMgr()->separator(), tid );
1531 toolMgr()->append( ClippingId, tid );
1532 toolMgr()->append( AxialScaleId, tid );
1533 toolMgr()->append( GraduatedAxesId, tid );
1534 toolMgr()->append( AmbientId, tid );
1536 toolMgr()->append( MaximizedId, tid );
1537 toolMgr()->append( SynchronizeId, tid );
1541 \brief Perform 'fit all' operation.
1543 void OCCViewer_ViewWindow::onViewFitAll()
1545 myViewPort->fitAll();
1549 \brief Perform "front view" transformation.
1551 void OCCViewer_ViewWindow::onFrontView()
1553 emit vpTransformationStarted ( FRONTVIEW );
1554 Handle(V3d_View) aView3d = myViewPort->getView();
1555 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
1557 emit vpTransformationFinished ( FRONTVIEW );
1561 \brief Perform "back view" transformation.
1563 void OCCViewer_ViewWindow::onBackView()
1565 emit vpTransformationStarted ( BACKVIEW );
1566 Handle(V3d_View) aView3d = myViewPort->getView();
1567 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
1569 emit vpTransformationFinished ( BACKVIEW );
1573 \brief Perform "top view" transformation.
1575 void OCCViewer_ViewWindow::onTopView()
1577 emit vpTransformationStarted ( TOPVIEW );
1578 Handle(V3d_View) aView3d = myViewPort->getView();
1579 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
1581 emit vpTransformationFinished ( TOPVIEW );
1585 \brief Perform "bottom view" transformation.
1587 void OCCViewer_ViewWindow::onBottomView()
1589 emit vpTransformationStarted ( BOTTOMVIEW );
1590 Handle(V3d_View) aView3d = myViewPort->getView();
1591 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
1593 emit vpTransformationFinished ( BOTTOMVIEW );
1597 \brief Perform "left view" transformation.
1599 void OCCViewer_ViewWindow::onLeftView()
1601 emit vpTransformationStarted ( LEFTVIEW );
1602 Handle(V3d_View) aView3d = myViewPort->getView();
1603 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
1605 emit vpTransformationFinished ( LEFTVIEW );
1609 \brief Perform "right view" transformation.
1611 void OCCViewer_ViewWindow::onRightView()
1613 emit vpTransformationStarted ( RIGHTVIEW );
1614 Handle(V3d_View) aView3d = myViewPort->getView();
1615 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
1617 emit vpTransformationFinished ( RIGHTVIEW );
1621 \brief Rotate view 90 degrees clockwise
1623 void OCCViewer_ViewWindow::onClockWiseView()
1625 emit vpTransformationStarted ( CLOCKWISEVIEW );
1626 myViewPort->rotateXY( 90. );
1627 emit vpTransformationFinished ( CLOCKWISEVIEW );
1631 \brief Rotate view 90 degrees conterclockwise
1633 void OCCViewer_ViewWindow::onAntiClockWiseView()
1635 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1636 myViewPort->rotateXY( -90. );
1637 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1641 \brief Perform "reset view" transformation.
1643 Sets default orientation of the viewport camera.
1645 void OCCViewer_ViewWindow::onResetView()
1647 emit vpTransformationStarted( RESETVIEW );
1648 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1649 myViewPort->getView()->Reset( false );
1650 myViewPort->fitAll( false, true, false );
1651 myViewPort->getView()->SetImmediateUpdate( upd );
1652 onProjectionType(); // needed to apply projection type properly after reset
1653 myViewPort->getView()->Update();
1654 emit vpTransformationFinished( RESETVIEW );
1658 \brief Set the given projection mode.
1660 Set the given projection mode: Orthographic or Perspective.
1662 void OCCViewer_ViewWindow::onProjectionType( QAction* theAction )
1664 Handle(V3d_View) aView3d = myViewPort->getView();
1665 if ( !aView3d.IsNull() ) {
1666 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1667 if (theAction == toolMgr()->action( OrthographicId )) {
1668 myModel->setProjectionType(Orthographic);
1669 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Orthographic );
1670 aCamera->SetFOVy(45.0);
1672 else if (theAction == toolMgr()->action( PerspectiveId )) {
1673 myModel->setProjectionType(Perspective);
1674 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Perspective );
1675 aCamera->SetFOVy(30.0);
1677 #if OCC_VERSION_LARGE > 0x06090000
1678 if (toolMgr()->action( StereoId )->isChecked()) {
1679 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1680 aCamera->SetFOVy(30.0);
1689 \brief Sets Stereo projection mode.
1691 Sets Stereo projection mode.
1693 void OCCViewer_ViewWindow::onStereoType( bool activate )
1695 #if OCC_VERSION_LARGE > 0x06090000
1696 Handle(V3d_View) aView3d = myViewPort->getView();
1697 if ( !aView3d.IsNull() ) {
1698 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1700 toolMgr()->action( PerspectiveId )->setChecked(true);
1701 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1702 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(false);
1704 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1705 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1706 setStereoType( aResMgr->integerValue( "OCCViewer", "stereo_type", 0 ) );
1707 setAnaglyphFilter( aResMgr->integerValue( "OCCViewer", "anaglyph_filter", 0 ) );
1708 setReverseStereo( aResMgr->booleanValue( "OCCViewer", "reverse_stereo", false ) );
1709 setVSync( aResMgr->booleanValue( "OCCViewer", "enable_vsync", true ) );
1710 setQuadBufferSupport( aResMgr->booleanValue( "OCCViewer", "enable_quad_buffer_support", false ) );
1713 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(true);
1714 if (myModel->projectionType() == Orthographic) {
1715 toolMgr()->action( OrthographicId )->setChecked(true);
1716 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Orthographic);
1718 else if (myModel->projectionType() == Perspective) {
1719 toolMgr()->action( PerspectiveId )->setChecked(true);
1720 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1727 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1728 toolMgr()->action( StereoId )->isChecked() )
1729 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1734 \brief Restore the view.
1736 Restore the projection mode based on tool-buttons states.
1738 void OCCViewer_ViewWindow::onProjectionType()
1740 emit vpTransformationStarted( PROJECTION );
1741 if (toolMgr()->action( OrthographicId )->isChecked())
1742 setProjectionType( Orthographic );
1743 if (toolMgr()->action( PerspectiveId )->isChecked())
1744 setProjectionType( Perspective );
1745 #if OCC_VERSION_LARGE > 0x06090000
1746 if (toolMgr()->action( StereoId )->isChecked())
1747 setProjectionType( Stereo );
1749 emit vpTransformationFinished( PROJECTION );
1752 void OCCViewer_ViewWindow::setProjectionType( int mode )
1754 QtxAction* anOrthographicAction = dynamic_cast<QtxAction*>( toolMgr()->action( OrthographicId ) );
1755 QtxAction* aPerspectiveAction = dynamic_cast<QtxAction*>( toolMgr()->action( PerspectiveId ) );
1756 #if OCC_VERSION_LARGE > 0x06090000
1757 QtxAction* aStereoAction = dynamic_cast<QtxAction*>( toolMgr()->action( StereoId ) );
1761 onProjectionType( anOrthographicAction );
1764 onProjectionType( aPerspectiveAction );
1767 onStereoType( true );
1770 // update action state if method is called outside
1771 if ( mode == Orthographic && !anOrthographicAction->isChecked() ) {
1772 anOrthographicAction->setChecked( true );
1773 #if OCC_VERSION_LARGE > 0x06090000
1774 aStereoAction->setChecked( false );
1777 if ( mode == Perspective && !aPerspectiveAction->isChecked() ) {
1778 aPerspectiveAction->setChecked( true );
1779 #if OCC_VERSION_LARGE > 0x06090000
1780 aStereoAction->setChecked( false );
1783 #if OCC_VERSION_LARGE > 0x06090000
1784 if ( mode == Stereo ) {
1785 aStereoAction->setChecked( true );
1786 if ( anOrthographicAction->isEnabled() ) {
1787 anOrthographicAction->setEnabled( false );
1788 anOrthographicAction->setChecked( false );
1789 aStereoAction->setChecked( false );
1792 anOrthographicAction->setEnabled( true );
1793 aStereoAction->setChecked( false );
1794 anOrthographicAction->setChecked(myModel->projectionType() == Orthographic);
1796 if ( aPerspectiveAction->isEnabled() ) {
1797 aPerspectiveAction->setEnabled( false );
1798 aPerspectiveAction->setChecked( true );
1799 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1800 toolMgr()->action( StereoId )->isChecked() )
1801 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1804 aPerspectiveAction->setEnabled( true );
1805 aStereoAction->setChecked( false );
1806 aPerspectiveAction->setChecked(myModel->projectionType() == Perspective);
1811 if ( !anOrthographicAction->isEnabled() )
1812 anOrthographicAction->setEnabled( true );
1813 if ( !aPerspectiveAction->isEnabled() )
1814 aPerspectiveAction->setEnabled( true );
1820 \brief Perform "fit all" transformation.
1822 void OCCViewer_ViewWindow::onFitAll()
1824 emit vpTransformationStarted( FITALLVIEW );
1825 myViewPort->fitAll();
1826 emit vpTransformationFinished( FITALLVIEW );
1830 \brief Perform "fit selection" transformation.
1832 void OCCViewer_ViewWindow::onFitSelection()
1834 emit vpTransformationStarted( FITSELECTION );
1835 #if OCC_VERSION_LARGE > 0x06090000
1836 myModel->getAISContext()->FitSelected( getViewPort()->getView() );
1838 emit vpTransformationFinished( FITSELECTION );
1842 \brief Called if 'change rotation point' operation is activated.
1843 \param on action state
1845 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1849 if (!mySetRotationPointDlg)
1851 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1852 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1855 if (!mySetRotationPointDlg->isVisible())
1857 //if (mySetRotationPointDlg->IsFirstShown())
1858 if (myCurrPointType == GRAVITY)
1860 Standard_Real Xcenter, Ycenter, Zcenter;
1861 if (computeGravityCenter(Xcenter, Ycenter, Zcenter))
1862 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1864 mySetRotationPointDlg->show();
1869 if (mySetRotationPointDlg->isVisible())
1870 mySetRotationPointDlg->hide();
1875 \brief Create one more window with same content.
1877 void OCCViewer_ViewWindow::onCloneView()
1879 SUIT_ViewWindow* vw = myManager->createViewWindow();
1881 emit viewCloned( vw );
1885 Creates one more window with same content
1887 void OCCViewer_ViewWindow::onAxialScale()
1889 if ( !myScalingDlg )
1890 myScalingDlg = new OCCViewer_AxialScaleDlg( this );
1892 if ( !myScalingDlg->isVisible() )
1894 myScalingDlg->Update();
1895 myScalingDlg->show();
1900 Shows Graduated Axes dialog
1902 void OCCViewer_ViewWindow::onGraduatedAxes()
1904 myCubeAxesDlg->Update();
1905 myCubeAxesDlg->show();
1908 void OCCViewer_ViewWindow::onAmbientToogle()
1910 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
1911 viewer->InitDefinedLights();
1912 while(viewer->MoreDefinedLights())
1914 Handle(V3d_Light) light = viewer->DefinedLight();
1915 if(light->Type() != V3d_AMBIENT)
1917 Handle(V3d_View) aView3d = myViewPort->getView();
1918 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
1919 else viewer->SetLightOn(light);
1921 viewer->NextDefinedLights();
1927 \brief Store view parameters.
1929 void OCCViewer_ViewWindow::onMemorizeView()
1931 appendViewAspect( getViewParams() );
1935 \brief Restore view parameters.
1937 void OCCViewer_ViewWindow::onRestoreView()
1939 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
1940 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
1942 updateViewAspects( aDlg->parameters() );
1943 if( myRestoreFlag && aDlg->parameters().count() )
1944 performRestoring( aDlg->currentItem() );
1948 \brief Restore view parameters.
1949 \param anItem view parameters
1951 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
1953 Handle(V3d_View) aView3d = myViewPort->getView();
1955 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
1956 aView3d->SetScale( anItem.scale );
1957 aView3d->SetTwist( anItem.twist );
1958 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
1959 aView3d->SetImmediateUpdate( prev );
1960 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1961 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1962 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
1964 #if OCC_VERSION_LARGE > 0x06070100
1965 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
1967 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
1969 // "eye" and "at" require conversion to represent center panning
1970 // up direction is only available after setting angle of twist and
1971 // other view parameters
1972 aView3d->Up( anUpX, anUpY, anUpZ );
1974 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
1975 gp_Dir anUp( anUpX, anUpY, anUpZ );
1976 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
1977 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1978 gp_Dir aSide = aProj ^ anUp;
1980 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
1981 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
1983 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
1984 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1987 aView3d->SetCenter( anItem.centerX, anItem.centerY );
1990 if ( !baseParamsOnly ) {
1992 myModel->setTrihedronShown( anItem.isVisible );
1993 myModel->setTrihedronSize( anItem.size );
1995 // graduated trihedron
1996 bool anIsVisible = anItem.gtIsVisible;
1997 OCCViewer_AxisWidget::AxisData anAxisData[3];
1998 anAxisData[0].DrawName = anItem.gtDrawNameX;
1999 anAxisData[1].DrawName = anItem.gtDrawNameZ;
2000 anAxisData[2].DrawName = anItem.gtDrawNameZ;
2001 anAxisData[0].Name = anItem.gtNameX;
2002 anAxisData[1].Name = anItem.gtNameZ;
2003 anAxisData[2].Name = anItem.gtNameZ;
2004 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
2005 anItem.gtNameColorGX,
2006 anItem.gtNameColorBX );
2007 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
2008 anItem.gtNameColorGY,
2009 anItem.gtNameColorBY );
2010 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
2011 anItem.gtNameColorGZ,
2012 anItem.gtNameColorBZ );
2013 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
2014 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
2015 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
2016 anAxisData[0].NbValues = anItem.gtNbValuesX;
2017 anAxisData[1].NbValues = anItem.gtNbValuesY;
2018 anAxisData[2].NbValues = anItem.gtNbValuesZ;
2019 anAxisData[0].Offset = anItem.gtOffsetX;
2020 anAxisData[1].Offset = anItem.gtOffsetY;
2021 anAxisData[2].Offset = anItem.gtOffsetZ;
2022 anAxisData[0].Color = QColor( anItem.gtColorRX,
2025 anAxisData[1].Color = QColor( anItem.gtColorRY,
2028 anAxisData[2].Color = QColor( anItem.gtColorRZ,
2031 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
2032 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
2033 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
2034 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
2035 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
2036 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
2038 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
2039 myCubeAxesDlg->ApplyData( aView3d );
2041 } // if ( !baseParamsOnly )
2047 \brief Set restore flag.
2049 void OCCViewer_ViewWindow::setRestoreFlag()
2055 \brief Called when action "show/hide trihedron" is activated.
2057 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
2059 myModel->setTrihedronShown(show);
2063 \brief Toggles preselection (highlighting) on/off
2065 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
2067 myPreselectionEnabled = on;
2068 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
2070 // unhighlight all highlighted objects
2072 myModel->unHighlightAll( true, false );
2075 // update action state if method is called outside
2076 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2077 if ( a && a->isChecked() != on ) {
2078 a->setChecked( on );
2083 \brief Toggles selection on/off
2085 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
2087 mySelectionEnabled = on;
2088 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
2090 // update action state if method is called outside
2093 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2095 a->setEnabled( on );
2099 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
2100 if ( a && a->isChecked() != on ) {
2101 a->setChecked( on );
2106 \brief Switches "keyboard free" interaction style on/off
2108 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
2110 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
2112 // update action state if method is called outside
2113 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
2114 if ( a->isChecked() != on )
2115 a->setChecked( on );
2119 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
2121 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
2123 myViewPort->setAdvancedZoomingEnabled( on );
2125 // update action state if method is called outside
2126 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
2127 if ( a->isChecked() != on )
2128 a->setChecked( on );
2132 \brief Get current interaction style
2133 \return interaction style
2135 int OCCViewer_ViewWindow::interactionStyle() const
2137 return myInteractionStyle;
2141 \brief Set current interaction style
2142 \param theStyle interaction style
2144 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
2146 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
2150 \brief Get current zooming style
2151 \return zooming style
2153 int OCCViewer_ViewWindow::zoomingStyle() const
2155 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
2159 \brief Set current zooming style
2160 \param theStyle zooming style
2162 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
2164 onSwitchZoomingStyle( theStyle == 1 );
2168 \brief Dump view window contents to the pixmap.
2169 \return pixmap containing all scene rendered in the window
2171 QImage OCCViewer_ViewWindow::dumpView()
2173 Handle(V3d_View) view = myViewPort->getView();
2174 if ( view.IsNull() )
2177 int aWidth = myViewPort->width();
2178 int aHeight = myViewPort->height();
2180 // rnv: An old approach to dump the OCCViewer content
2181 // Now used OCCT built-in procedure.
2183 QApplication::syncX();
2184 view->Redraw(); // In order to reactivate GL context
2187 #ifndef DISABLE_GLVIEWER
2188 OpenGLUtils_FrameBuffer aFrameBuffer;
2189 if( aFrameBuffer.init( aWidth, aHeight ) )
2191 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
2193 glPushAttrib( GL_VIEWPORT_BIT );
2194 glViewport( 0, 0, aWidth, aHeight );
2195 aFrameBuffer.bind();
2200 aFrameBuffer.unbind();
2203 aFrameBuffer.bind();
2204 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
2205 aFrameBuffer.unbind();
2207 anImage = anImage.rgbSwapped();
2208 anImage = anImage.mirrored();
2211 // if frame buffers are unsupported, use old functionality
2214 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
2216 QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
2218 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
2224 view->ToPixMap(aPix,aWidth, aHeight,Graphic3d_BT_RGBA);
2226 QImage anImage( aPix.Data(), aWidth, aHeight, QImage::Format_ARGB32 );
2227 anImage = anImage.mirrored();
2231 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
2232 const QString& fileName,
2233 const QString& format )
2235 if ( format != "PS" && format != "EPS")
2236 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
2238 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
2241 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
2242 else if (format == "EPS")
2243 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
2249 QString OCCViewer_ViewWindow::filter() const
2251 return tr( "OCC_IMAGE_FILES" );
2256 \brief Set parameters of the cutting plane
2257 \param on if \c true, cutting plane is enabled
2258 \param x X position of plane point
2259 \param y Y position of plane point
2260 \param z Z position of plane point
2261 \param dx X coordinate of plane normal
2262 \param dy Y coordinate of plane normal
2263 \param dz Z coordinate of plane normal
2265 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2266 const double dx, const double dy, const double dz )
2268 Handle(V3d_View) view = myViewPort->getView();
2269 if ( view.IsNull() )
2273 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2275 // try to use already existing plane or create a new one
2276 Handle(V3d_Plane) clipPlane;
2278 // calculate new a,b,c,d values for the plane
2279 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2281 pln.Coefficients(a, b, c, d);
2283 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2284 if(aPlanes.Size() > 0 ) {
2285 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2286 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2287 aClipPlane->SetEquation(pln);
2288 aClipPlane->SetOn(Standard_True);
2290 view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2294 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2295 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2296 for( ;anIter.More();anIter.Next() ){
2297 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2298 aClipPlane->SetOn(Standard_False);
2306 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2308 gp_Dir aDir = pln.Axis().Direction();
2309 gp_Pnt aPnt = pln.Location();
2310 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2315 \brief Check if any cutting plane is enabled
2316 \return \c true if at least one cutting plane is enabled
2318 bool OCCViewer_ViewWindow::isCuttingPlane()
2320 Handle(V3d_View) view = myViewPort->getView();
2322 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2323 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2324 for( ;anIter.More();anIter.Next() ) {
2325 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2326 if(aClipPlane->IsOn()) {
2335 \brief Get the visual parameters of the view window.
2336 \return visual parameters of view window
2338 viewAspect OCCViewer_ViewWindow::getViewParams() const
2340 double projX, projY, projZ, twist;
2341 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2342 double aScaleX, aScaleY, aScaleZ;
2344 Handle(V3d_View) aView3d = myViewPort->getView();
2346 aView3d->Proj( projX, projY, projZ );
2347 aView3d->At( atX, atY, atZ );
2348 aView3d->Eye( eyeX, eyeY, eyeZ );
2349 twist = aView3d->Twist();
2351 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2353 bool isShown = myModel->isTrihedronVisible();
2354 double size = myModel->trihedronSize();
2356 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2359 params.scale = aView3d->Scale();
2360 params.projX = projX;
2361 params.projY = projY;
2362 params.projZ = projZ;
2363 params.twist = twist;
2370 params.scaleX = aScaleX;
2371 params.scaleY = aScaleY;
2372 params.scaleZ = aScaleZ;
2373 params.name = aName;
2374 params.isVisible= isShown;
2377 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2378 aView3d->Center( params.centerX, params.centerY );
2381 // graduated trihedron
2382 bool anIsVisible = false;
2383 OCCViewer_AxisWidget::AxisData anAxisData[3];
2384 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2386 params.gtIsVisible = anIsVisible;
2387 params.gtDrawNameX = anAxisData[0].DrawName;
2388 params.gtDrawNameY = anAxisData[1].DrawName;
2389 params.gtDrawNameZ = anAxisData[2].DrawName;
2390 params.gtNameX = anAxisData[0].Name;
2391 params.gtNameY = anAxisData[1].Name;
2392 params.gtNameZ = anAxisData[2].Name;
2393 params.gtNameColorRX = anAxisData[0].NameColor.red();
2394 params.gtNameColorGX = anAxisData[0].NameColor.green();
2395 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2396 params.gtNameColorRY = anAxisData[1].NameColor.red();
2397 params.gtNameColorGY = anAxisData[1].NameColor.green();
2398 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2399 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2400 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2401 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2402 params.gtDrawValuesX = anAxisData[0].DrawValues;
2403 params.gtDrawValuesY = anAxisData[1].DrawValues;
2404 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2405 params.gtNbValuesX = anAxisData[0].NbValues;
2406 params.gtNbValuesY = anAxisData[1].NbValues;
2407 params.gtNbValuesZ = anAxisData[2].NbValues;
2408 params.gtOffsetX = anAxisData[0].Offset;
2409 params.gtOffsetY = anAxisData[1].Offset;
2410 params.gtOffsetZ = anAxisData[2].Offset;
2411 params.gtColorRX = anAxisData[0].Color.red();
2412 params.gtColorGX = anAxisData[0].Color.green();
2413 params.gtColorBX = anAxisData[0].Color.blue();
2414 params.gtColorRY = anAxisData[1].Color.red();
2415 params.gtColorGY = anAxisData[1].Color.green();
2416 params.gtColorBY = anAxisData[1].Color.blue();
2417 params.gtColorRZ = anAxisData[2].Color.red();
2418 params.gtColorGZ = anAxisData[2].Color.green();
2419 params.gtColorBZ = anAxisData[2].Color.blue();
2420 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2421 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2422 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2423 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2424 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2425 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2431 \brief Get visual parameters of this view window.
2432 \return visual parameters of view window
2434 QString OCCViewer_ViewWindow::getVisualParameters()
2436 viewAspect params = getViewParams();
2440 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2441 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2442 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
2443 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
2445 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2446 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2447 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2448 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2449 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2450 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2451 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2452 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2453 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2454 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2455 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2456 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2457 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2458 data << QString( "isVisible=%1" ).arg( params.isVisible );
2459 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2461 ClipPlanesList aPlanes = myModel->getClipPlanes();
2462 for ( int i=0; i < aPlanes.size(); i++ )
2464 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2465 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2466 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2467 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2468 switch ( aPlane.Mode )
2470 case OCCViewer_ClipPlane::Absolute :
2472 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2474 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2476 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2477 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2478 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2482 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2487 case OCCViewer_ClipPlane::Relative :
2489 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2490 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2491 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2496 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2497 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2498 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2499 data << ClippingPlane;
2502 // graduated trihedron
2503 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2504 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2505 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2506 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2507 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2508 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2509 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2510 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2511 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2512 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2513 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2514 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2515 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2516 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2517 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2518 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2519 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2520 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2521 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2522 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2523 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2524 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2525 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2526 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2527 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2528 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2529 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2530 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2531 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2532 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2533 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2534 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2535 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2536 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2537 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2538 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2539 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2540 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2541 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2542 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2543 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2544 data << QString( "background=%1" ).arg( bg );
2546 return data.join("*");
2550 \brief Restore visual parameters of the view window.
2551 \param parameters visual parameters of view window
2553 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2556 ClipPlanesList aClipPlanes;
2557 QStringList data = parameters.split( '*' );
2558 Qtx::BackgroundData bgData;
2559 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2561 foreach( QString param, data ) {
2562 QString paramName = param.section( '=', 0, 0 ).trimmed();
2563 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2564 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2565 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2566 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2567 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2568 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2569 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2570 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2571 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2572 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2573 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2574 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2575 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2576 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2577 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2578 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2579 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2580 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2581 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2582 else if ( paramName.contains( "ClippingPlane" ) )
2584 QStringList ClipPlaneData = paramValue.split( ';' );
2585 OCCViewer_ClipPlane aPlane;
2586 foreach( QString ClipPlaneParam, ClipPlaneData )
2588 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2589 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2590 if ( ClipPlane_paramName == "Mode" )
2592 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2594 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2595 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2596 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2597 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2600 switch ( aPlane.Mode )
2602 case OCCViewer_ClipPlane::Absolute :
2603 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2604 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2605 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2606 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2607 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2610 case OCCViewer_ClipPlane::Relative :
2611 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2612 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2613 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2618 aClipPlanes.push_back(aPlane);
2620 // graduated trihedron
2621 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2622 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2623 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2624 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2625 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2626 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2627 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2628 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2629 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2630 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2631 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2632 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2633 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2634 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2635 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2636 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2637 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2638 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2639 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2640 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2641 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2642 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2643 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2644 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2645 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2646 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2647 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2648 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2649 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2650 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2651 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2652 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2653 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2654 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2655 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2656 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2657 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2658 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2659 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2660 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2661 else if ( paramName == "background" ) {
2662 QString bg = paramValue.replace( "$", "=" );
2663 bgData = Qtx::stringToBackground( bg );
2667 else // old format - "1.000e+00*0.000e+00..."
2670 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2671 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2672 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2673 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2674 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2675 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2676 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
2677 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2678 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2679 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
2680 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2681 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2682 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2683 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
2684 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
2685 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
2686 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
2687 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
2689 performRestoring( params );
2690 setBackground( bgData );
2691 myModel->setClipPlanes(aClipPlanes);
2695 \brief Handle show event.
2697 Emits Show() signal.
2699 \param theEvent show event
2701 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2703 emit Show( theEvent );
2707 \brief Handle hide event.
2709 Emits Hide() signal.
2711 \param theEvent hide event
2713 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
2715 emit Hide( theEvent );
2720 Save old cursor. [ protected ]
2722 void OCCViewer_ViewWindow::saveCursor()
2724 QCursor* aCursor = NULL;
2726 aCursor = myViewPort->getDefaultCursor();
2727 myCursor = ( aCursor ? *aCursor : cursor() );
2732 Creates default sketcher. [ virtual protected ]
2734 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
2737 return new OCCViewer_RectSketcher( this, type );
2738 if ( type == Polygon )
2739 return new OCCViewer_PolygonSketcher( this, type );
2743 void OCCViewer_ViewWindow::initSketchers()
2745 if ( mySketchers.isEmpty() )
2747 mySketchers.append( createSketcher( Rect ) );
2748 mySketchers.append( createSketcher( Polygon ) );
2752 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
2754 OCCViewer_ViewSketcher* sketcher = 0;
2755 QList<OCCViewer_ViewSketcher*>::Iterator it;
2756 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
2758 OCCViewer_ViewSketcher* sk = (*it);
2759 if ( sk->type() == typ )
2766 Handles requests for sketching in the active view. [ virtual public ]
2768 void OCCViewer_ViewWindow::activateSketching( int type )
2770 OCCViewer_ViewPort3d* vp = getViewPort();
2774 if ( !vp->isSketchingEnabled() )
2777 /* Finish current sketching */
2778 if ( type == NoSketching )
2782 onSketchingFinished();
2783 mypSketcher->deactivate();
2787 /* Activate new sketching */
2790 activateSketching( NoSketching ); /* concurrency not suported */
2791 mypSketcher = getSketcher( type );
2794 mypSketcher->activate();
2795 onSketchingStarted();
2801 Unhilights detected entities. [ virtual protected ]
2803 void OCCViewer_ViewWindow::onSketchingStarted()
2808 Selection by rectangle or polygon. [ virtual protected ]
2810 void OCCViewer_ViewWindow::onSketchingFinished()
2812 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
2813 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
2815 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
2816 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
2817 switch( mypSketcher->type() )
2821 QRect* aRect = (QRect*)mypSketcher->data();
2824 int aLeft = aRect->left();
2825 int aRight = aRect->right();
2826 int aTop = aRect->top();
2827 int aBottom = aRect->bottom();
2831 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2833 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2839 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
2842 int size = aPolygon->size();
2843 TColgp_Array1OfPnt2d anArray( 1, size );
2845 QPolygon::Iterator it = aPolygon->begin();
2846 QPolygon::Iterator itEnd = aPolygon->end();
2847 for( int index = 1; it != itEnd; ++it, index++ )
2849 QPoint aPoint = *it;
2850 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
2854 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
2856 ic->Select( anArray, getViewPort()->getView(), Standard_False );
2864 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
2865 aViewMgr->getOCCViewer()->performSelectionChanged();
2869 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
2874 bool OCCViewer_ViewWindow::transformRequested() const
2876 return ( myOperation != NOTHING );
2879 bool OCCViewer_ViewWindow::transformInProcess() const
2881 return myEventStarted;
2884 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
2886 myEventStarted = bOn;
2890 Set enabled state of transformation (rotate, zoom, etc)
2892 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
2894 if ( id != NOTHING ) myStatus.insert( id, on );
2898 \return enabled state of transformation (rotate, zoom, etc)
2900 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
2902 return myStatus.contains( id ) ? myStatus[ id ] : true;
2905 void OCCViewer_ViewWindow::onMaximizedView()
2907 setMaximized(!isMaximized());
2910 void OCCViewer_ViewWindow::returnTo3dView()
2912 setReturnedTo3dView( true );
2915 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
2917 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
2918 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
2919 if ( !isVisible3dView )
2920 toolMgr()->show( ReturnTo3dViewId );
2922 toolMgr()->hide( ReturnTo3dViewId );
2923 if ( isVisible3dView ) emit returnedTo3d( );
2927 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
2929 QAction* anAction = toolMgr()->action( MaximizedId );
2930 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
2931 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
2933 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
2934 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
2935 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
2936 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
2937 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
2939 emit maximized( this, true );
2943 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
2944 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
2945 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
2946 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
2947 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
2949 emit maximized( this, false );
2954 bool OCCViewer_ViewWindow::isMaximized() const
2956 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
2959 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
2961 IsSketcherStyle = enable;
2964 bool OCCViewer_ViewWindow::isSketcherStyle() const
2966 return IsSketcherStyle;
2970 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
2975 int OCCViewer_ViewWindow::projectionType() const
2977 int mode = Orthographic;
2978 Handle(V3d_View) aView3d = myViewPort->getView();
2979 if ( !aView3d.IsNull() ) {
2980 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
2981 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Perspective)
2983 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Orthographic)
2984 mode = Orthographic;
2985 #if OCC_VERSION_LARGE > 0x06090000
2986 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
2993 void OCCViewer_ViewWindow::setStereoType( int type )
2995 Handle(V3d_View) aView3d = myViewPort->getView();
2996 if ( !aView3d.IsNull() ) {
2997 #if OCC_VERSION_LARGE > 0x06090000
2998 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
2999 aParams->StereoMode = (Graphic3d_StereoMode)type;
3004 int OCCViewer_ViewWindow::stereoType() const
3006 int type = QuadBuffer;
3007 Handle(V3d_View) aView3d = myViewPort->getView();
3008 if ( !aView3d.IsNull() ) {
3009 #if OCC_VERSION_LARGE > 0x06090000
3010 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3011 type = (OCCViewer_ViewWindow::StereoType)aParams->StereoMode;
3017 void OCCViewer_ViewWindow::setAnaglyphFilter( int type )
3019 Handle(V3d_View) aView3d = myViewPort->getView();
3020 if ( !aView3d.IsNull() ) {
3021 #if OCC_VERSION_LARGE > 0x06090000
3022 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3023 if (type == RedCyan)
3024 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
3025 if (type == YellowBlue)
3026 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
3027 if (type == GreenMagenta)
3028 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
3033 int OCCViewer_ViewWindow::anaglyphFilter() const
3036 Handle(V3d_View) aView3d = myViewPort->getView();
3037 if ( !aView3d.IsNull() ) {
3038 #if OCC_VERSION_LARGE > 0x06090000
3039 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3040 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized)
3042 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized)
3044 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple)
3045 type = GreenMagenta;
3051 void OCCViewer_ViewWindow::setStereographicFocus( int type, double value )
3053 Handle(V3d_View) aView3d = myViewPort->getView();
3054 if ( !aView3d.IsNull() ) {
3055 #if OCC_VERSION_LARGE > 0x06090000
3056 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3057 aCamera->SetZFocus( (Graphic3d_Camera::FocusType) type, value );
3062 int OCCViewer_ViewWindow::stereographicFocusType() const
3064 int type = Relative;
3065 Handle(V3d_View) aView3d = myViewPort->getView();
3066 if ( !aView3d.IsNull() ) {
3067 #if OCC_VERSION_LARGE > 0x06090000
3068 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3069 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->ZFocusType();
3075 double OCCViewer_ViewWindow::stereographicFocusValue() const
3078 Handle(V3d_View) aView3d = myViewPort->getView();
3079 if ( !aView3d.IsNull() ) {
3080 #if OCC_VERSION_LARGE > 0x06090000
3081 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3082 value = aCamera->ZFocus();
3088 void OCCViewer_ViewWindow::setInterocularDistance( int type, double value )
3090 Handle(V3d_View) aView3d = myViewPort->getView();
3091 if ( !aView3d.IsNull() ) {
3092 #if OCC_VERSION_LARGE > 0x06090000
3093 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3094 aCamera->SetIOD( (Graphic3d_Camera::IODType) type, value );
3099 int OCCViewer_ViewWindow::interocularDistanceType() const
3101 int type = Relative;
3102 Handle(V3d_View) aView3d = myViewPort->getView();
3103 if ( !aView3d.IsNull() ) {
3104 #if OCC_VERSION_LARGE > 0x06090000
3105 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3106 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->GetIODType();
3112 double OCCViewer_ViewWindow::interocularDistanceValue() const
3114 double value = 0.05;
3115 Handle(V3d_View) aView3d = myViewPort->getView();
3116 if ( !aView3d.IsNull() ) {
3117 #if OCC_VERSION_LARGE > 0x06090000
3118 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3119 value = aCamera->IOD();
3125 void OCCViewer_ViewWindow::setReverseStereo( bool reverse )
3127 Handle(V3d_View) aView3d = myViewPort->getView();
3128 if ( !aView3d.IsNull() ) {
3129 #if OCC_VERSION_LARGE > 0x06090000
3130 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3131 aParams->ToReverseStereo = reverse;
3136 bool OCCViewer_ViewWindow::isReverseStereo() const
3138 int reverse = false;
3139 Handle(V3d_View) aView3d = myViewPort->getView();
3140 if ( !aView3d.IsNull() ) {
3141 #if OCC_VERSION_LARGE > 0x06090000
3142 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3143 reverse = aParams->ToReverseStereo;
3149 void OCCViewer_ViewWindow::setVSync( bool enable )
3151 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3152 if ( !anIntCont.IsNull() ) {
3153 #if OCC_VERSION_LARGE > 0x06090000
3154 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3155 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3156 aCaps->swapInterval = enable;
3161 bool OCCViewer_ViewWindow::isVSync() const
3164 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3165 if ( !anIntCont.IsNull() ) {
3166 #if OCC_VERSION_LARGE > 0x06090000
3167 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3168 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3169 enable = aCaps->swapInterval;
3175 void OCCViewer_ViewWindow::setQuadBufferSupport( bool enable )
3177 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3178 if ( !anIntCont.IsNull() ) {
3179 #if OCC_VERSION_LARGE > 0x06090000
3180 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3181 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3182 aCaps->contextStereo = enable;
3187 bool OCCViewer_ViewWindow::isQuadBufferSupport() const
3190 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3191 if ( !anIntCont.IsNull() ) {
3192 #if OCC_VERSION_LARGE > 0x06090000
3193 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3194 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3195 enable = aCaps->contextStereo;
3202 bool OCCViewer_ViewWindow::isOpenGlStereoSupport() const
3204 GLboolean support[1];
3205 glGetBooleanv (GL_STEREO, support);
3212 QColor OCCViewer_ViewWindow::backgroundColor() const
3214 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
3218 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
3220 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
3223 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
3225 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
3228 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
3230 if ( myViewPort ) myViewPort->setBackground( theBackground );
3233 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
3235 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
3241 void OCCViewer_ViewWindow::clearViewAspects()
3243 myViewAspects.clear();
3247 \return const reference to list of view aspects
3249 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
3251 return myViewAspects;
3255 Appends new view aspect
3256 \param aParams - new view aspects
3258 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
3260 myViewAspects.append( aParams );
3264 Replaces old view aspects by new ones
3265 \param aViewList - list of new view aspects
3267 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
3269 myViewAspects = aViewList;
3273 Get camera properties for the OCC view window.
3274 \return shared pointer on camera properties.
3276 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
3278 SUIT_CameraProperties aProps;
3280 Handle(V3d_View) aSourceView = getViewPort()->getView();
3281 if ( aSourceView.IsNull() )
3284 if ( get2dMode() == No2dMode ) {
3285 aProps.setDimension( SUIT_CameraProperties::Dim3D );
3288 aProps.setDimension( SUIT_CameraProperties::Dim2D );
3289 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
3292 // read common properites of the view
3293 Standard_Real anUp[3];
3294 Standard_Real anAt[3];
3295 Standard_Real anEye[3];
3296 Standard_Real aProj[3];
3297 Standard_Real anAxialScale[3];
3299 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
3300 aSourceView->At( anAt[0], anAt[1], anAt[2] );
3301 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
3302 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3304 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3305 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
3307 #if OCC_VERSION_LARGE > 0x06070100
3308 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
3310 // store camera properties "as is": it is up to synchronized
3311 // view classes to provide necessary property conversion.
3312 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
3313 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
3315 if ( aSourceView->Camera()->IsOrthographic() )
3317 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
3318 aProps.setViewAngle( 0.0 );
3322 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
3323 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
3325 aProps.setMappingScale( aSourceView->Camera()->Scale() );
3327 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
3329 // generate view orientation matrix for transforming OCC projection reference point
3330 // into a camera (eye) position.
3331 gp_Dir aLeftDir = gp_Dir( anUp[0], anUp[1], anUp[2] ) ^ gp_Dir( aProj[0], aProj[1], aProj[2] );
3334 aTrsf.SetValue( 1, 1, aLeftDir.X() );
3335 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
3336 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
3338 aTrsf.SetValue( 1, 2, anUp[0] );
3339 aTrsf.SetValue( 2, 2, anUp[1] );
3340 aTrsf.SetValue( 3, 2, anUp[2] );
3342 aTrsf.SetValue( 1, 3, aProj[0] );
3343 aTrsf.SetValue( 2, 3, aProj[1] );
3344 aTrsf.SetValue( 3, 3, aProj[2] );
3346 aTrsf.SetValue( 1, 4, anAt[0] );
3347 aTrsf.SetValue( 2, 4, anAt[1] );
3348 aTrsf.SetValue( 3, 4, anAt[2] );
3350 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
3352 // transform to world-space coordinate system
3353 gp_XYZ aPosition( aProjRef.X(), aProjRef.Y(), aCameraDepth );
3354 aTrsf.Transforms( aPosition );
3356 // compute focal point
3357 double aFocalPoint[3];
3359 aFocalPoint[0] = aPosition.X() - aProj[0] * aCameraDepth;
3360 aFocalPoint[1] = aPosition.Y() - aProj[1] * aCameraDepth;
3361 aFocalPoint[2] = aPosition.Z() - aProj[2] * aCameraDepth;
3363 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3364 aProps.setPosition( aPosition.X(), aPosition.Y(), aPosition.Z() );
3366 Standard_Real aViewScale[2];
3367 aSourceView->Size( aViewScale[0], aViewScale[1] );
3368 aProps.setMappingScale( aViewScale[1] );
3376 This implementation synchronizes OCC view's camera propreties.
3378 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
3380 bool blocked = blockSignals( true );
3382 SUIT_CameraProperties aProps = theView->cameraProperties();
3383 if ( !cameraProperties().isCompatible( aProps ) ) {
3384 // other view, this one is being currently synchronized to, seems has become incompatible
3385 // we have to break synchronization
3390 Handle(V3d_View) aDestView = getViewPort()->getView();
3392 aDestView->SetImmediateUpdate( Standard_False );
3395 double aPosition[3];
3396 double aFocalPoint[3];
3397 double anAxialScale[3];
3399 // get common properties
3400 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3401 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
3402 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3403 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3405 #if OCC_VERSION_LARGE > 0x06070100
3406 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3407 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
3408 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3409 aDestView->Camera()->SetScale( aProps.getMappingScale() );
3411 gp_Dir aProjDir( aPosition[0] - aFocalPoint[0],
3412 aPosition[1] - aFocalPoint[1],
3413 aPosition[2] - aFocalPoint[2] );
3415 // get custom view translation
3416 Standard_Real aTranslation[3];
3417 aDestView->At( aTranslation[0], aTranslation[1], aTranslation[2] );
3419 gp_Dir aLeftDir = gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] )
3420 ^ gp_Dir( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
3423 aTrsf.SetValue( 1, 1, aLeftDir.X() );
3424 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
3425 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
3427 aTrsf.SetValue( 1, 2, anUpDir[0] );
3428 aTrsf.SetValue( 2, 2, anUpDir[1] );
3429 aTrsf.SetValue( 3, 2, anUpDir[2] );
3431 aTrsf.SetValue( 1, 3, aProjDir.X() );
3432 aTrsf.SetValue( 2, 3, aProjDir.Y() );
3433 aTrsf.SetValue( 3, 3, aProjDir.Z() );
3435 aTrsf.SetValue( 1, 4, aTranslation[0] );
3436 aTrsf.SetValue( 2, 4, aTranslation[1] );
3437 aTrsf.SetValue( 3, 4, aTranslation[2] );
3440 // transform to view-space coordinate system
3441 gp_XYZ aProjRef( aPosition[0], aPosition[1], aPosition[2] );
3442 aTrsf.Transforms( aProjRef );
3444 // set view camera properties using low-level approach. this is done
3445 // in order to avoid interference with static variables in v3d view used
3446 // when rotation is in process in another view.
3447 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
3448 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
3450 Graphic3d_Vector aMappingProj( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
3451 Graphic3d_Vector aMappingUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3453 aMappingProj.Normalize();
3454 aMappingUp.Normalize();
3456 anOrientation.SetViewReferencePlane( aMappingProj );
3457 anOrientation.SetViewReferenceUp( aMappingUp );
3459 aDestView->SetViewMapping( aMapping );
3460 aDestView->SetViewOrientation( anOrientation );
3463 aDestView->SetCenter( aProjRef.X(), aProjRef.Y() );
3465 // set mapping scale
3466 double aMapScaling = aProps.getMappingScale();
3467 Standard_Real aWidth, aHeight;
3468 aDestView->Size( aWidth, aHeight );
3469 aDestView->SetSize ( aWidth > aHeight ? aMapScaling * (aWidth / aHeight) : aMapScaling );
3472 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3474 aDestView->ZFitAll();
3475 aDestView->SetImmediateUpdate( Standard_True );
3476 aDestView->Redraw();
3478 blockSignals( blocked );
3482 \brief Indicates whether preselection is enabled
3483 \return true if preselection is enabled
3485 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
3487 return myPreselectionEnabled;
3491 \brief Enables/disables preselection
3492 \param theIsToEnable if true - preselection will be enabled
3494 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
3496 onSwitchPreselection( theIsToEnable );
3500 \brief Indicates whether selection is enabled
3501 \return true if selection is enabled
3503 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3505 return mySelectionEnabled;
3509 \brief Enables/disables selection
3510 \param theIsToEnable if true - selection will be enabled
3512 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3514 onSwitchSelection( theIsToEnable );
3519 \brief called if clipping operation is activated / deactivated.
3521 Enables/disables clipping plane displaying.
3523 \parma on action state
3525 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3527 if(!myModel) return;
3528 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3531 if (!aClippingDlg) {
3532 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3533 myModel->setClippingDlg(aClippingDlg);
3535 if (!aClippingDlg->isVisible())
3536 aClippingDlg->show();
3538 if ( aClippingDlg ) {
3539 aClippingDlg->close();
3540 myModel->setClippingDlg(0);
3544 SUIT_ViewManager* mgr = getViewManager();
3546 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3547 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3548 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3549 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3551 QAction* a = toolMgr()->action( ClippingId );
3553 if(theIsOn != a->isChecked()){
3554 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3555 a->setChecked(theIsOn);
3556 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));