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();
1183 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1184 tr( "MNU_DUMP_VIEW" ), 0, this);
1185 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1186 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1187 toolMgr()->registerAction( aAction, DumpId );
1190 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1191 tr( "MNU_FITALL" ), 0, this);
1192 aAction->setStatusTip(tr("DSC_FITALL"));
1193 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1194 toolMgr()->registerAction( aAction, FitAllId );
1197 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1198 tr( "MNU_FITRECT" ), 0, this);
1199 aAction->setStatusTip(tr("DSC_FITRECT"));
1200 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1201 toolMgr()->registerAction( aAction, FitRectId );
1204 aAction = new QtxAction(tr("MNU_FITSELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITSELECTION" ) ),
1205 tr( "MNU_FITSELECTION" ), 0, this);
1206 aAction->setStatusTip(tr("DSC_FITSELECTION"));
1207 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
1208 toolMgr()->registerAction( aAction, FitSelectionId );
1211 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1212 tr( "MNU_ZOOM_VIEW" ), 0, this);
1213 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1214 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1215 toolMgr()->registerAction( aAction, ZoomId );
1218 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1219 tr( "MNU_PAN_VIEW" ), 0, this);
1220 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1221 connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
1222 toolMgr()->registerAction( aAction, PanId );
1225 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1226 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1227 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1228 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1229 toolMgr()->registerAction( aAction, GlobalPanId );
1232 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1233 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1234 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1235 mySetRotationPointAction->setCheckable( true );
1236 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1237 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1240 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1241 tr( "MNU_ROTATE_VIEW" ), 0, this);
1242 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1243 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1244 toolMgr()->registerAction( aAction, RotationId );
1247 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1248 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1249 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1250 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1251 this->addAction(aAction);
1252 toolMgr()->registerAction( aAction, FrontId );
1254 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1255 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1256 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1257 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1258 this->addAction(aAction);
1259 toolMgr()->registerAction( aAction, BackId );
1261 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1262 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1263 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1264 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1265 this->addAction(aAction);
1266 toolMgr()->registerAction( aAction, TopId );
1268 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1269 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1270 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1271 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1272 this->addAction(aAction);
1273 toolMgr()->registerAction( aAction, BottomId );
1275 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1276 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1277 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1278 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1279 this->addAction(aAction);
1280 toolMgr()->registerAction( aAction, LeftId );
1282 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1283 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1284 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1285 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1286 this->addAction(aAction);
1287 toolMgr()->registerAction( aAction, RightId );
1289 // rotate anticlockwise
1290 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1291 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1292 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1293 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1294 this->addAction(aAction);
1295 toolMgr()->registerAction( aAction, AntiClockWiseId );
1298 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1299 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1300 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1301 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1302 this->addAction(aAction);
1303 toolMgr()->registerAction( aAction, ClockWiseId );
1305 // Projection mode group
1307 // - orthographic projection
1308 aAction = new QtxAction(tr("MNU_ORTHOGRAPHIC_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ORTHOGRAPHIC" ) ),
1309 tr( "MNU_ORTHOGRAPHIC_MODE" ), 0, this);
1310 aAction->setStatusTip(tr("DSC_ORTHOGRAPHIC_MODE"));
1311 aAction->setCheckable(true);
1312 toolMgr()->registerAction( aAction, OrthographicId );
1314 // - perspective projection
1315 aAction = new QtxAction(tr("MNU_PERSPECTIVE_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PERSPECTIVE" ) ),
1316 tr( "MNU_PERSPECTIVE_MODE" ), 0, this);
1317 aAction->setStatusTip(tr("DSC_PERSPECTIVE_MODE"));
1318 aAction->setCheckable(true);
1319 toolMgr()->registerAction( aAction, PerspectiveId );
1320 #if OCC_VERSION_LARGE > 0x06090000
1321 // - stereo projection
1322 aAction = new QtxAction(tr("MNU_STEREO_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STEREO" ) ),
1323 tr( "MNU_STEREO_MODE" ), 0, this);
1324 aAction->setStatusTip(tr("DSC_STEREO_MODE"));
1325 aAction->setCheckable(true);
1326 toolMgr()->registerAction( aAction, StereoId );
1327 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onStereoType(bool)));
1329 // - add exclusive action group
1330 QActionGroup* aProjectionGroup = new QActionGroup( this );
1331 aProjectionGroup->addAction( toolMgr()->action( OrthographicId ) );
1332 aProjectionGroup->addAction( toolMgr()->action( PerspectiveId ) );
1333 connect(aProjectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProjectionType(QAction*)));
1336 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1337 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1338 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1339 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1340 this->addAction(aAction);
1341 toolMgr()->registerAction( aAction, ResetId );
1344 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1345 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1346 tr("MNU_CLONE_VIEW"), 0, this);
1347 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1348 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1349 toolMgr()->registerAction( aAction, CloneId );
1351 aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
1352 tr("MNU_CLIPPING"), 0, this);
1353 aAction->setStatusTip (tr("DSC_CLIPPING"));
1354 aAction->setCheckable (true);
1355 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1356 toolMgr()->registerAction (aAction, ClippingId);
1358 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1359 tr( "MNU_SHOOT_VIEW" ), 0, this);
1360 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1361 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1362 toolMgr()->registerAction( aAction, MemId );
1364 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1365 tr( "MNU_PRESETS_VIEW" ), 0, this);
1366 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1367 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1368 toolMgr()->registerAction( aAction, RestoreId );
1370 if (myModel->trihedronActivated()) {
1371 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1372 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1373 aAction->setCheckable( true );
1374 aAction->setChecked( true );
1375 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1376 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1377 toolMgr()->registerAction( aAction, TrihedronShowId );
1381 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1382 tr( "MNU_SCALING" ), 0, this);
1383 aAction->setStatusTip(tr("DSC_SCALING"));
1384 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1385 toolMgr()->registerAction( aAction, AxialScaleId );
1387 // Enable/disable preselection
1388 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1389 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1390 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1391 aAction->setCheckable(true);
1392 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1393 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1395 // Enable/disable selection
1396 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1397 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1398 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1399 aAction->setCheckable(true);
1400 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1401 toolMgr()->registerAction( aAction, SwitchSelectionId );
1404 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1405 tr( "MNU_GRADUATED_AXES" ), 0, this);
1406 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1407 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1408 toolMgr()->registerAction( aAction, GraduatedAxesId );
1410 // Active only ambient light or not
1411 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1412 tr( "MNU_AMBIENT" ), 0, this);
1413 aAction->setStatusTip(tr("DSC_AMBIENT"));
1414 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1415 toolMgr()->registerAction( aAction, AmbientId );
1417 // Switch between interaction styles
1418 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1419 tr( "MNU_STYLE_SWITCH" ), 0, this);
1420 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1421 aAction->setCheckable(true);
1422 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1423 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1425 // Switch between zooming styles
1426 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1427 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1428 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1429 aAction->setCheckable(true);
1430 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1431 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1434 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1435 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1436 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1437 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1438 toolMgr()->registerAction( aAction, MaximizedId );
1440 // Return to 3d view
1441 if (my2dMode!=No2dMode){
1442 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1443 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1444 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1445 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1446 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1450 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1454 \brief Create toolbar.
1456 void OCCViewer_ViewWindow::createToolBar()
1458 static const char* titles[] = {
1459 "LBL_3DTOOLBAR_LABEL",
1460 "LBL_XYTOOLBAR_LABEL",
1461 "LBL_XZTOOLBAR_LABEL",
1462 "LBL_YZTOOLBAR_LABEL",
1464 static const char* names[] = {
1465 "OCCViewer3DViewOperations",
1466 "OCCViewerXYViewOperations",
1467 "OCCViewerXZViewOperations",
1468 "OCCViewerYZViewOperations",
1470 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1471 QString( names[my2dMode] ), // name (language-independant)
1472 false ); // disable floatable toolbar
1473 if ( my2dMode != No2dMode ){
1474 toolMgr()->append( ReturnTo3dViewId, tid );
1475 toolMgr()->append( toolMgr()->separator(), tid );
1477 toolMgr()->append( DumpId, tid );
1478 toolMgr()->append( SwitchInteractionStyleId, tid );
1479 toolMgr()->append( SwitchZoomingStyleId, tid );
1480 toolMgr()->append( SwitchPreselectionId, tid );
1481 toolMgr()->append( SwitchSelectionId, tid );
1482 if( myModel->trihedronActivated() )
1483 toolMgr()->append( TrihedronShowId, tid );
1485 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1486 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1487 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1488 #if OCC_VERSION_LARGE > 0x06090000
1489 aScaleAction->insertAction( toolMgr()->action( FitSelectionId ) );
1491 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1492 toolMgr()->append( aScaleAction, tid );
1494 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1495 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1496 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1497 toolMgr()->append( aPanningAction, tid );
1499 if (my2dMode == No2dMode) {
1500 toolMgr()->append( ChangeRotationPointId, tid );
1501 toolMgr()->append( RotationId, tid );
1503 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1504 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1505 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1506 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1507 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1508 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1509 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1510 toolMgr()->append( aViewsAction, tid );
1512 toolMgr()->append( AntiClockWiseId, tid );
1513 toolMgr()->append( ClockWiseId, tid );
1515 toolMgr()->append( OrthographicId, tid );
1516 toolMgr()->append( PerspectiveId, tid );
1517 #if OCC_VERSION_LARGE > 0x06090000
1518 toolMgr()->append( StereoId, tid );
1521 toolMgr()->append( ResetId, tid );
1524 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1525 aMemAction->insertAction( toolMgr()->action( MemId ) );
1526 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1527 toolMgr()->append( aMemAction, tid );
1529 toolMgr()->append( toolMgr()->separator(), tid );
1530 toolMgr()->append( CloneId, tid );
1532 toolMgr()->append( toolMgr()->separator(), tid );
1533 toolMgr()->append( ClippingId, tid );
1534 toolMgr()->append( AxialScaleId, tid );
1535 toolMgr()->append( GraduatedAxesId, tid );
1536 toolMgr()->append( AmbientId, tid );
1538 toolMgr()->append( MaximizedId, tid );
1539 toolMgr()->append( SynchronizeId, tid );
1543 \brief Perform 'fit all' operation.
1545 void OCCViewer_ViewWindow::onViewFitAll()
1547 myViewPort->fitAll();
1551 \brief Perform "front view" transformation.
1553 void OCCViewer_ViewWindow::onFrontView()
1555 emit vpTransformationStarted ( FRONTVIEW );
1556 Handle(V3d_View) aView3d = myViewPort->getView();
1557 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
1559 emit vpTransformationFinished ( FRONTVIEW );
1563 \brief Perform "back view" transformation.
1565 void OCCViewer_ViewWindow::onBackView()
1567 emit vpTransformationStarted ( BACKVIEW );
1568 Handle(V3d_View) aView3d = myViewPort->getView();
1569 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
1571 emit vpTransformationFinished ( BACKVIEW );
1575 \brief Perform "top view" transformation.
1577 void OCCViewer_ViewWindow::onTopView()
1579 emit vpTransformationStarted ( TOPVIEW );
1580 Handle(V3d_View) aView3d = myViewPort->getView();
1581 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
1583 emit vpTransformationFinished ( TOPVIEW );
1587 \brief Perform "bottom view" transformation.
1589 void OCCViewer_ViewWindow::onBottomView()
1591 emit vpTransformationStarted ( BOTTOMVIEW );
1592 Handle(V3d_View) aView3d = myViewPort->getView();
1593 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
1595 emit vpTransformationFinished ( BOTTOMVIEW );
1599 \brief Perform "left view" transformation.
1601 void OCCViewer_ViewWindow::onLeftView()
1603 emit vpTransformationStarted ( LEFTVIEW );
1604 Handle(V3d_View) aView3d = myViewPort->getView();
1605 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
1607 emit vpTransformationFinished ( LEFTVIEW );
1611 \brief Perform "right view" transformation.
1613 void OCCViewer_ViewWindow::onRightView()
1615 emit vpTransformationStarted ( RIGHTVIEW );
1616 Handle(V3d_View) aView3d = myViewPort->getView();
1617 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
1619 emit vpTransformationFinished ( RIGHTVIEW );
1623 \brief Rotate view 90 degrees clockwise
1625 void OCCViewer_ViewWindow::onClockWiseView()
1627 emit vpTransformationStarted ( CLOCKWISEVIEW );
1628 myViewPort->rotateXY( 90. );
1629 emit vpTransformationFinished ( CLOCKWISEVIEW );
1633 \brief Rotate view 90 degrees conterclockwise
1635 void OCCViewer_ViewWindow::onAntiClockWiseView()
1637 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1638 myViewPort->rotateXY( -90. );
1639 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1643 \brief Perform "reset view" transformation.
1645 Sets default orientation of the viewport camera.
1647 void OCCViewer_ViewWindow::onResetView()
1649 emit vpTransformationStarted( RESETVIEW );
1650 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1651 myViewPort->getView()->Reset( false );
1652 myViewPort->fitAll( false, true, false );
1653 myViewPort->getView()->SetImmediateUpdate( upd );
1654 onProjectionType(); // needed to apply projection type properly after reset
1655 myViewPort->getView()->Update();
1656 emit vpTransformationFinished( RESETVIEW );
1660 \brief Set the given projection mode.
1662 Set the given projection mode: Orthographic or Perspective.
1664 void OCCViewer_ViewWindow::onProjectionType( QAction* theAction )
1666 Handle(V3d_View) aView3d = myViewPort->getView();
1667 if ( !aView3d.IsNull() ) {
1668 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1669 if (theAction == toolMgr()->action( OrthographicId )) {
1670 myModel->setProjectionType(Orthographic);
1671 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Orthographic );
1672 aCamera->SetFOVy(45.0);
1674 else if (theAction == toolMgr()->action( PerspectiveId )) {
1675 myModel->setProjectionType(Perspective);
1676 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Perspective );
1677 aCamera->SetFOVy(30.0);
1679 #if OCC_VERSION_LARGE > 0x06090000
1680 if (toolMgr()->action( StereoId )->isChecked()) {
1681 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1682 aCamera->SetFOVy(30.0);
1691 \brief Sets Stereo projection mode.
1693 Sets Stereo projection mode.
1695 void OCCViewer_ViewWindow::onStereoType( bool activate )
1697 #if OCC_VERSION_LARGE > 0x06090000
1698 Handle(V3d_View) aView3d = myViewPort->getView();
1699 if ( !aView3d.IsNull() ) {
1700 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1702 toolMgr()->action( PerspectiveId )->setChecked(true);
1703 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1704 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(false);
1706 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1707 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1708 setStereoType( aResMgr->integerValue( "OCCViewer", "stereo_type", 0 ) );
1709 setAnaglyphFilter( aResMgr->integerValue( "OCCViewer", "anaglyph_filter", 0 ) );
1710 setReverseStereo( aResMgr->booleanValue( "OCCViewer", "reverse_stereo", false ) );
1711 setVSync( aResMgr->booleanValue( "OCCViewer", "enable_vsync", true ) );
1712 setQuadBufferSupport( aResMgr->booleanValue( "OCCViewer", "enable_quad_buffer_support", false ) );
1715 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(true);
1716 if (myModel->projectionType() == Orthographic) {
1717 toolMgr()->action( OrthographicId )->setChecked(true);
1718 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Orthographic);
1720 else if (myModel->projectionType() == Perspective) {
1721 toolMgr()->action( PerspectiveId )->setChecked(true);
1722 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1729 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1730 toolMgr()->action( StereoId )->isChecked() )
1731 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1736 \brief Restore the view.
1738 Restore the projection mode based on tool-buttons states.
1740 void OCCViewer_ViewWindow::onProjectionType()
1742 emit vpTransformationStarted( PROJECTION );
1743 if (toolMgr()->action( OrthographicId )->isChecked())
1744 setProjectionType( Orthographic );
1745 if (toolMgr()->action( PerspectiveId )->isChecked())
1746 setProjectionType( Perspective );
1747 #if OCC_VERSION_LARGE > 0x06090000
1748 if (toolMgr()->action( StereoId )->isChecked())
1749 setProjectionType( Stereo );
1751 emit vpTransformationFinished( PROJECTION );
1754 void OCCViewer_ViewWindow::setProjectionType( int mode )
1756 QtxAction* anOrthographicAction = dynamic_cast<QtxAction*>( toolMgr()->action( OrthographicId ) );
1757 QtxAction* aPerspectiveAction = dynamic_cast<QtxAction*>( toolMgr()->action( PerspectiveId ) );
1758 #if OCC_VERSION_LARGE > 0x06090000
1759 QtxAction* aStereoAction = dynamic_cast<QtxAction*>( toolMgr()->action( StereoId ) );
1763 onProjectionType( anOrthographicAction );
1766 onProjectionType( aPerspectiveAction );
1769 onStereoType( true );
1772 // update action state if method is called outside
1773 if ( mode == Orthographic && !anOrthographicAction->isChecked() ) {
1774 anOrthographicAction->setChecked( true );
1775 #if OCC_VERSION_LARGE > 0x06090000
1776 aStereoAction->setChecked( false );
1779 if ( mode == Perspective && !aPerspectiveAction->isChecked() ) {
1780 aPerspectiveAction->setChecked( true );
1781 #if OCC_VERSION_LARGE > 0x06090000
1782 aStereoAction->setChecked( false );
1785 #if OCC_VERSION_LARGE > 0x06090000
1786 if ( mode == Stereo ) {
1787 aStereoAction->setChecked( true );
1788 if ( anOrthographicAction->isEnabled() ) {
1789 anOrthographicAction->setEnabled( false );
1790 anOrthographicAction->setChecked( false );
1791 aStereoAction->setChecked( false );
1794 anOrthographicAction->setEnabled( true );
1795 aStereoAction->setChecked( false );
1796 anOrthographicAction->setChecked(myModel->projectionType() == Orthographic);
1798 if ( aPerspectiveAction->isEnabled() ) {
1799 aPerspectiveAction->setEnabled( false );
1800 aPerspectiveAction->setChecked( true );
1801 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1802 toolMgr()->action( StereoId )->isChecked() )
1803 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1806 aPerspectiveAction->setEnabled( true );
1807 aStereoAction->setChecked( false );
1808 aPerspectiveAction->setChecked(myModel->projectionType() == Perspective);
1813 if ( !anOrthographicAction->isEnabled() )
1814 anOrthographicAction->setEnabled( true );
1815 if ( !aPerspectiveAction->isEnabled() )
1816 aPerspectiveAction->setEnabled( true );
1822 \brief Perform "fit all" transformation.
1824 void OCCViewer_ViewWindow::onFitAll()
1826 emit vpTransformationStarted( FITALLVIEW );
1827 myViewPort->fitAll();
1828 emit vpTransformationFinished( FITALLVIEW );
1832 \brief Perform "fit selection" transformation.
1834 void OCCViewer_ViewWindow::onFitSelection()
1836 emit vpTransformationStarted( FITSELECTION );
1837 #if OCC_VERSION_LARGE > 0x06090000
1838 myModel->getAISContext()->FitSelected( getViewPort()->getView() );
1840 emit vpTransformationFinished( FITSELECTION );
1844 \brief Called if 'change rotation point' operation is activated.
1845 \param on action state
1847 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1851 if (!mySetRotationPointDlg)
1853 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1854 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1857 if (!mySetRotationPointDlg->isVisible())
1859 //if (mySetRotationPointDlg->IsFirstShown())
1860 if (myCurrPointType == GRAVITY)
1862 Standard_Real Xcenter, Ycenter, Zcenter;
1863 if (computeGravityCenter(Xcenter, Ycenter, Zcenter))
1864 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1866 mySetRotationPointDlg->show();
1871 if (mySetRotationPointDlg->isVisible())
1872 mySetRotationPointDlg->hide();
1877 \brief Create one more window with same content.
1879 void OCCViewer_ViewWindow::onCloneView()
1881 SUIT_ViewWindow* vw = myManager->createViewWindow();
1883 emit viewCloned( vw );
1887 Creates one more window with same content
1889 void OCCViewer_ViewWindow::onAxialScale()
1891 if ( !myScalingDlg )
1892 myScalingDlg = new OCCViewer_AxialScaleDlg( this );
1894 if ( !myScalingDlg->isVisible() )
1896 myScalingDlg->Update();
1897 myScalingDlg->show();
1902 Shows Graduated Axes dialog
1904 void OCCViewer_ViewWindow::onGraduatedAxes()
1906 myCubeAxesDlg->Update();
1907 myCubeAxesDlg->show();
1910 void OCCViewer_ViewWindow::onAmbientToogle()
1912 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
1913 viewer->InitDefinedLights();
1914 while(viewer->MoreDefinedLights())
1916 Handle(V3d_Light) light = viewer->DefinedLight();
1917 if(light->Type() != V3d_AMBIENT)
1919 Handle(V3d_View) aView3d = myViewPort->getView();
1920 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
1921 else viewer->SetLightOn(light);
1923 viewer->NextDefinedLights();
1929 \brief Store view parameters.
1931 void OCCViewer_ViewWindow::onMemorizeView()
1933 appendViewAspect( getViewParams() );
1937 \brief Restore view parameters.
1939 void OCCViewer_ViewWindow::onRestoreView()
1941 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
1942 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
1944 updateViewAspects( aDlg->parameters() );
1945 if( myRestoreFlag && aDlg->parameters().count() )
1946 performRestoring( aDlg->currentItem() );
1950 \brief Restore view parameters.
1951 \param anItem view parameters
1953 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
1955 Handle(V3d_View) aView3d = myViewPort->getView();
1957 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
1958 aView3d->SetScale( anItem.scale );
1959 aView3d->SetTwist( anItem.twist );
1960 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
1961 aView3d->SetImmediateUpdate( prev );
1962 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1963 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1964 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
1966 #if OCC_VERSION_LARGE > 0x06070100
1967 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
1969 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
1971 // "eye" and "at" require conversion to represent center panning
1972 // up direction is only available after setting angle of twist and
1973 // other view parameters
1974 aView3d->Up( anUpX, anUpY, anUpZ );
1976 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
1977 gp_Dir anUp( anUpX, anUpY, anUpZ );
1978 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
1979 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1980 gp_Dir aSide = aProj ^ anUp;
1982 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
1983 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
1985 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
1986 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1989 aView3d->SetCenter( anItem.centerX, anItem.centerY );
1992 if ( !baseParamsOnly ) {
1994 myModel->setTrihedronShown( anItem.isVisible );
1995 myModel->setTrihedronSize( anItem.size );
1997 // graduated trihedron
1998 bool anIsVisible = anItem.gtIsVisible;
1999 OCCViewer_AxisWidget::AxisData anAxisData[3];
2000 anAxisData[0].DrawName = anItem.gtDrawNameX;
2001 anAxisData[1].DrawName = anItem.gtDrawNameZ;
2002 anAxisData[2].DrawName = anItem.gtDrawNameZ;
2003 anAxisData[0].Name = anItem.gtNameX;
2004 anAxisData[1].Name = anItem.gtNameZ;
2005 anAxisData[2].Name = anItem.gtNameZ;
2006 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
2007 anItem.gtNameColorGX,
2008 anItem.gtNameColorBX );
2009 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
2010 anItem.gtNameColorGY,
2011 anItem.gtNameColorBY );
2012 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
2013 anItem.gtNameColorGZ,
2014 anItem.gtNameColorBZ );
2015 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
2016 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
2017 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
2018 anAxisData[0].NbValues = anItem.gtNbValuesX;
2019 anAxisData[1].NbValues = anItem.gtNbValuesY;
2020 anAxisData[2].NbValues = anItem.gtNbValuesZ;
2021 anAxisData[0].Offset = anItem.gtOffsetX;
2022 anAxisData[1].Offset = anItem.gtOffsetY;
2023 anAxisData[2].Offset = anItem.gtOffsetZ;
2024 anAxisData[0].Color = QColor( anItem.gtColorRX,
2027 anAxisData[1].Color = QColor( anItem.gtColorRY,
2030 anAxisData[2].Color = QColor( anItem.gtColorRZ,
2033 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
2034 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
2035 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
2036 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
2037 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
2038 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
2040 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
2041 myCubeAxesDlg->ApplyData( aView3d );
2043 } // if ( !baseParamsOnly )
2049 \brief Set restore flag.
2051 void OCCViewer_ViewWindow::setRestoreFlag()
2057 \brief Called when action "show/hide trihedron" is activated.
2059 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
2061 myModel->setTrihedronShown(show);
2065 \brief Toggles preselection (highlighting) on/off
2067 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
2069 myPreselectionEnabled = on;
2070 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
2072 // unhighlight all highlighted objects
2074 myModel->unHighlightAll( true, false );
2077 // update action state if method is called outside
2078 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2079 if ( a && a->isChecked() != on ) {
2080 a->setChecked( on );
2085 \brief Toggles selection on/off
2087 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
2089 mySelectionEnabled = on;
2090 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
2092 // update action state if method is called outside
2095 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2097 a->setEnabled( on );
2101 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
2102 if ( a && a->isChecked() != on ) {
2103 a->setChecked( on );
2108 \brief Switches "keyboard free" interaction style on/off
2110 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
2112 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
2114 // update action state if method is called outside
2115 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
2116 if ( a && a->isChecked() != on )
2117 a->setChecked( on );
2121 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
2123 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
2125 myViewPort->setAdvancedZoomingEnabled( on );
2127 // update action state if method is called outside
2128 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
2129 if ( a && a->isChecked() != on )
2130 a->setChecked( on );
2134 \brief Get current interaction style
2135 \return interaction style
2137 int OCCViewer_ViewWindow::interactionStyle() const
2139 return myInteractionStyle;
2143 \brief Set current interaction style
2144 \param theStyle interaction style
2146 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
2148 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
2152 \brief Get current zooming style
2153 \return zooming style
2155 int OCCViewer_ViewWindow::zoomingStyle() const
2157 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
2161 \brief Set current zooming style
2162 \param theStyle zooming style
2164 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
2166 onSwitchZoomingStyle( theStyle == 1 );
2170 \brief Dump view window contents to the pixmap.
2171 \return pixmap containing all scene rendered in the window
2173 QImage OCCViewer_ViewWindow::dumpView()
2175 Handle(V3d_View) view = myViewPort->getView();
2176 if ( view.IsNull() )
2179 int aWidth = myViewPort->width();
2180 int aHeight = myViewPort->height();
2182 // rnv: An old approach to dump the OCCViewer content
2183 // Now used OCCT built-in procedure.
2185 QApplication::syncX();
2186 view->Redraw(); // In order to reactivate GL context
2189 #ifndef DISABLE_GLVIEWER
2190 OpenGLUtils_FrameBuffer aFrameBuffer;
2191 if( aFrameBuffer.init( aWidth, aHeight ) )
2193 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
2195 glPushAttrib( GL_VIEWPORT_BIT );
2196 glViewport( 0, 0, aWidth, aHeight );
2197 aFrameBuffer.bind();
2202 aFrameBuffer.unbind();
2205 aFrameBuffer.bind();
2206 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
2207 aFrameBuffer.unbind();
2209 anImage = anImage.rgbSwapped();
2210 anImage = anImage.mirrored();
2213 // if frame buffers are unsupported, use old functionality
2216 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
2218 QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
2220 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
2226 view->ToPixMap(aPix,aWidth, aHeight,Graphic3d_BT_RGBA);
2228 QImage anImage( aPix.Data(), aWidth, aHeight, QImage::Format_ARGB32 );
2229 anImage = anImage.mirrored();
2233 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
2234 const QString& fileName,
2235 const QString& format )
2237 if ( format != "PS" && format != "EPS")
2238 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
2240 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
2243 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
2244 else if (format == "EPS")
2245 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
2251 QString OCCViewer_ViewWindow::filter() const
2253 return tr( "OCC_IMAGE_FILES" );
2258 \brief Set parameters of the cutting plane
2259 \param on if \c true, cutting plane is enabled
2260 \param x X position of plane point
2261 \param y Y position of plane point
2262 \param z Z position of plane point
2263 \param dx X coordinate of plane normal
2264 \param dy Y coordinate of plane normal
2265 \param dz Z coordinate of plane normal
2267 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2268 const double dx, const double dy, const double dz )
2270 Handle(V3d_View) view = myViewPort->getView();
2271 if ( view.IsNull() )
2275 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2277 // try to use already existing plane or create a new one
2278 Handle(V3d_Plane) clipPlane;
2280 // calculate new a,b,c,d values for the plane
2281 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2283 pln.Coefficients(a, b, c, d);
2285 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2286 if(aPlanes.Size() > 0 ) {
2287 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2288 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2289 aClipPlane->SetEquation(pln);
2290 aClipPlane->SetOn(Standard_True);
2292 view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2296 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2297 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2298 for( ;anIter.More();anIter.Next() ){
2299 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2300 aClipPlane->SetOn(Standard_False);
2308 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2310 gp_Dir aDir = pln.Axis().Direction();
2311 gp_Pnt aPnt = pln.Location();
2312 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2317 \brief Check if any cutting plane is enabled
2318 \return \c true if at least one cutting plane is enabled
2320 bool OCCViewer_ViewWindow::isCuttingPlane()
2322 Handle(V3d_View) view = myViewPort->getView();
2324 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2325 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2326 for( ;anIter.More();anIter.Next() ) {
2327 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2328 if(aClipPlane->IsOn()) {
2337 \brief Get the visual parameters of the view window.
2338 \return visual parameters of view window
2340 viewAspect OCCViewer_ViewWindow::getViewParams() const
2342 double projX, projY, projZ, twist;
2343 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2344 double aScaleX, aScaleY, aScaleZ;
2346 Handle(V3d_View) aView3d = myViewPort->getView();
2348 aView3d->Proj( projX, projY, projZ );
2349 aView3d->At( atX, atY, atZ );
2350 aView3d->Eye( eyeX, eyeY, eyeZ );
2351 twist = aView3d->Twist();
2353 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2355 bool isShown = myModel->isTrihedronVisible();
2356 double size = myModel->trihedronSize();
2358 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2361 params.scale = aView3d->Scale();
2362 params.projX = projX;
2363 params.projY = projY;
2364 params.projZ = projZ;
2365 params.twist = twist;
2372 params.scaleX = aScaleX;
2373 params.scaleY = aScaleY;
2374 params.scaleZ = aScaleZ;
2375 params.name = aName;
2376 params.isVisible= isShown;
2379 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2380 aView3d->Center( params.centerX, params.centerY );
2383 // graduated trihedron
2384 bool anIsVisible = false;
2385 OCCViewer_AxisWidget::AxisData anAxisData[3];
2386 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2388 params.gtIsVisible = anIsVisible;
2389 params.gtDrawNameX = anAxisData[0].DrawName;
2390 params.gtDrawNameY = anAxisData[1].DrawName;
2391 params.gtDrawNameZ = anAxisData[2].DrawName;
2392 params.gtNameX = anAxisData[0].Name;
2393 params.gtNameY = anAxisData[1].Name;
2394 params.gtNameZ = anAxisData[2].Name;
2395 params.gtNameColorRX = anAxisData[0].NameColor.red();
2396 params.gtNameColorGX = anAxisData[0].NameColor.green();
2397 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2398 params.gtNameColorRY = anAxisData[1].NameColor.red();
2399 params.gtNameColorGY = anAxisData[1].NameColor.green();
2400 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2401 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2402 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2403 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2404 params.gtDrawValuesX = anAxisData[0].DrawValues;
2405 params.gtDrawValuesY = anAxisData[1].DrawValues;
2406 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2407 params.gtNbValuesX = anAxisData[0].NbValues;
2408 params.gtNbValuesY = anAxisData[1].NbValues;
2409 params.gtNbValuesZ = anAxisData[2].NbValues;
2410 params.gtOffsetX = anAxisData[0].Offset;
2411 params.gtOffsetY = anAxisData[1].Offset;
2412 params.gtOffsetZ = anAxisData[2].Offset;
2413 params.gtColorRX = anAxisData[0].Color.red();
2414 params.gtColorGX = anAxisData[0].Color.green();
2415 params.gtColorBX = anAxisData[0].Color.blue();
2416 params.gtColorRY = anAxisData[1].Color.red();
2417 params.gtColorGY = anAxisData[1].Color.green();
2418 params.gtColorBY = anAxisData[1].Color.blue();
2419 params.gtColorRZ = anAxisData[2].Color.red();
2420 params.gtColorGZ = anAxisData[2].Color.green();
2421 params.gtColorBZ = anAxisData[2].Color.blue();
2422 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2423 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2424 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2425 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2426 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2427 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2433 \brief Get visual parameters of this view window.
2434 \return visual parameters of view window
2436 QString OCCViewer_ViewWindow::getVisualParameters()
2438 viewAspect params = getViewParams();
2442 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2443 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2444 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
2445 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
2447 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2448 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2449 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2450 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2451 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2452 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2453 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2454 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2455 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2456 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2457 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2458 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2459 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2460 data << QString( "isVisible=%1" ).arg( params.isVisible );
2461 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2463 ClipPlanesList aPlanes = myModel->getClipPlanes();
2464 for ( int i=0; i < aPlanes.size(); i++ )
2466 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2467 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2468 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2469 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2470 switch ( aPlane.Mode )
2472 case OCCViewer_ClipPlane::Absolute :
2474 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2476 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2478 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2479 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2480 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2484 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2489 case OCCViewer_ClipPlane::Relative :
2491 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2492 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2493 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2498 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2499 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2500 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2501 data << ClippingPlane;
2504 // graduated trihedron
2505 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2506 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2507 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2508 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2509 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2510 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2511 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2512 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2513 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2514 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2515 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2516 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2517 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2518 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2519 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2520 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2521 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2522 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2523 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2524 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2525 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2526 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2527 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2528 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2529 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2530 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2531 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2532 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2533 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2534 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2535 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2536 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2537 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2538 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2539 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2540 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2541 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2542 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2543 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2544 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2545 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2546 data << QString( "background=%1" ).arg( bg );
2548 return data.join("*");
2552 \brief Restore visual parameters of the view window.
2553 \param parameters visual parameters of view window
2555 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2558 ClipPlanesList aClipPlanes;
2559 QStringList data = parameters.split( '*' );
2560 Qtx::BackgroundData bgData;
2561 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2563 foreach( QString param, data ) {
2564 QString paramName = param.section( '=', 0, 0 ).trimmed();
2565 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2566 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2567 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2568 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2569 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2570 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2571 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2572 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2573 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2574 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2575 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2576 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2577 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2578 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2579 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2580 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2581 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2582 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2583 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2584 else if ( paramName.contains( "ClippingPlane" ) )
2586 QStringList ClipPlaneData = paramValue.split( ';' );
2587 OCCViewer_ClipPlane aPlane;
2588 foreach( QString ClipPlaneParam, ClipPlaneData )
2590 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2591 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2592 if ( ClipPlane_paramName == "Mode" )
2594 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2596 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2597 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2598 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2599 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2602 switch ( aPlane.Mode )
2604 case OCCViewer_ClipPlane::Absolute :
2605 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2606 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2607 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2608 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2609 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2612 case OCCViewer_ClipPlane::Relative :
2613 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2614 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2615 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2620 aClipPlanes.push_back(aPlane);
2622 // graduated trihedron
2623 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2624 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2625 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2626 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2627 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2628 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2629 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2630 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2631 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2632 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2633 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2634 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2635 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2636 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2637 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2638 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2639 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2640 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2641 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2642 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2643 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2644 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2645 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2646 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2647 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2648 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2649 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2650 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2651 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2652 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2653 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2654 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2655 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2656 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2657 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2658 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2659 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2660 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2661 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2662 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2663 else if ( paramName == "background" ) {
2664 QString bg = paramValue.replace( "$", "=" );
2665 bgData = Qtx::stringToBackground( bg );
2669 else // old format - "1.000e+00*0.000e+00..."
2672 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2673 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2674 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2675 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2676 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2677 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2678 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
2679 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2680 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2681 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
2682 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2683 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2684 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2685 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
2686 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
2687 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
2688 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
2689 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
2691 performRestoring( params );
2692 setBackground( bgData );
2693 myModel->setClipPlanes(aClipPlanes);
2697 \brief Handle show event.
2699 Emits Show() signal.
2701 \param theEvent show event
2703 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2705 emit Show( theEvent );
2709 \brief Handle hide event.
2711 Emits Hide() signal.
2713 \param theEvent hide event
2715 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
2717 emit Hide( theEvent );
2722 Save old cursor. [ protected ]
2724 void OCCViewer_ViewWindow::saveCursor()
2726 QCursor* aCursor = NULL;
2728 aCursor = myViewPort->getDefaultCursor();
2729 myCursor = ( aCursor ? *aCursor : cursor() );
2734 Creates default sketcher. [ virtual protected ]
2736 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
2739 return new OCCViewer_RectSketcher( this, type );
2740 if ( type == Polygon )
2741 return new OCCViewer_PolygonSketcher( this, type );
2745 void OCCViewer_ViewWindow::initSketchers()
2747 if ( mySketchers.isEmpty() )
2749 mySketchers.append( createSketcher( Rect ) );
2750 mySketchers.append( createSketcher( Polygon ) );
2754 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
2756 OCCViewer_ViewSketcher* sketcher = 0;
2757 QList<OCCViewer_ViewSketcher*>::Iterator it;
2758 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
2760 OCCViewer_ViewSketcher* sk = (*it);
2761 if ( sk->type() == typ )
2768 Handles requests for sketching in the active view. [ virtual public ]
2770 void OCCViewer_ViewWindow::activateSketching( int type )
2772 OCCViewer_ViewPort3d* vp = getViewPort();
2776 if ( !vp->isSketchingEnabled() )
2779 /* Finish current sketching */
2780 if ( type == NoSketching )
2784 onSketchingFinished();
2785 mypSketcher->deactivate();
2789 /* Activate new sketching */
2792 activateSketching( NoSketching ); /* concurrency not suported */
2793 mypSketcher = getSketcher( type );
2796 mypSketcher->activate();
2797 onSketchingStarted();
2803 Unhilights detected entities. [ virtual protected ]
2805 void OCCViewer_ViewWindow::onSketchingStarted()
2810 Selection by rectangle or polygon. [ virtual protected ]
2812 void OCCViewer_ViewWindow::onSketchingFinished()
2814 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
2815 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
2817 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
2818 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
2819 switch( mypSketcher->type() )
2823 QRect* aRect = (QRect*)mypSketcher->data();
2826 int aLeft = aRect->left();
2827 int aRight = aRect->right();
2828 int aTop = aRect->top();
2829 int aBottom = aRect->bottom();
2833 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2835 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2841 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
2844 int size = aPolygon->size();
2845 TColgp_Array1OfPnt2d anArray( 1, size );
2847 QPolygon::Iterator it = aPolygon->begin();
2848 QPolygon::Iterator itEnd = aPolygon->end();
2849 for( int index = 1; it != itEnd; ++it, index++ )
2851 QPoint aPoint = *it;
2852 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
2856 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
2858 ic->Select( anArray, getViewPort()->getView(), Standard_False );
2866 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
2867 aViewMgr->getOCCViewer()->performSelectionChanged();
2871 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
2876 bool OCCViewer_ViewWindow::transformRequested() const
2878 return ( myOperation != NOTHING );
2881 bool OCCViewer_ViewWindow::transformInProcess() const
2883 return myEventStarted;
2886 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
2888 myEventStarted = bOn;
2892 Set enabled state of transformation (rotate, zoom, etc)
2894 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
2896 if ( id != NOTHING ) myStatus.insert( id, on );
2900 \return enabled state of transformation (rotate, zoom, etc)
2902 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
2904 return myStatus.contains( id ) ? myStatus[ id ] : true;
2907 void OCCViewer_ViewWindow::onMaximizedView()
2909 setMaximized(!isMaximized());
2912 void OCCViewer_ViewWindow::returnTo3dView()
2914 setReturnedTo3dView( true );
2917 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
2919 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
2920 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
2921 if ( !isVisible3dView )
2922 toolMgr()->show( ReturnTo3dViewId );
2924 toolMgr()->hide( ReturnTo3dViewId );
2925 if ( isVisible3dView ) emit returnedTo3d( );
2929 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
2931 QAction* anAction = toolMgr()->action( MaximizedId );
2932 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
2933 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
2935 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
2936 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
2937 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
2938 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
2939 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
2941 emit maximized( this, true );
2945 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
2946 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
2947 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
2948 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
2949 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
2951 emit maximized( this, false );
2956 bool OCCViewer_ViewWindow::isMaximized() const
2958 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
2961 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
2963 IsSketcherStyle = enable;
2966 bool OCCViewer_ViewWindow::isSketcherStyle() const
2968 return IsSketcherStyle;
2972 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
2977 int OCCViewer_ViewWindow::projectionType() const
2979 int mode = Orthographic;
2980 Handle(V3d_View) aView3d = myViewPort->getView();
2981 if ( !aView3d.IsNull() ) {
2982 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
2983 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Perspective)
2985 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Orthographic)
2986 mode = Orthographic;
2987 #if OCC_VERSION_LARGE > 0x06090000
2988 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
2995 void OCCViewer_ViewWindow::setStereoType( int type )
2997 Handle(V3d_View) aView3d = myViewPort->getView();
2998 if ( !aView3d.IsNull() ) {
2999 #if OCC_VERSION_LARGE > 0x06090000
3000 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3001 aParams->StereoMode = (Graphic3d_StereoMode)type;
3006 int OCCViewer_ViewWindow::stereoType() const
3008 int type = QuadBuffer;
3009 Handle(V3d_View) aView3d = myViewPort->getView();
3010 if ( !aView3d.IsNull() ) {
3011 #if OCC_VERSION_LARGE > 0x06090000
3012 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3013 type = (OCCViewer_ViewWindow::StereoType)aParams->StereoMode;
3019 void OCCViewer_ViewWindow::setAnaglyphFilter( int type )
3021 Handle(V3d_View) aView3d = myViewPort->getView();
3022 if ( !aView3d.IsNull() ) {
3023 #if OCC_VERSION_LARGE > 0x06090000
3024 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3025 if (type == RedCyan)
3026 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
3027 if (type == YellowBlue)
3028 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
3029 if (type == GreenMagenta)
3030 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
3035 int OCCViewer_ViewWindow::anaglyphFilter() const
3038 Handle(V3d_View) aView3d = myViewPort->getView();
3039 if ( !aView3d.IsNull() ) {
3040 #if OCC_VERSION_LARGE > 0x06090000
3041 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3042 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized)
3044 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized)
3046 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple)
3047 type = GreenMagenta;
3053 void OCCViewer_ViewWindow::setStereographicFocus( int type, double value )
3055 Handle(V3d_View) aView3d = myViewPort->getView();
3056 if ( !aView3d.IsNull() ) {
3057 #if OCC_VERSION_LARGE > 0x06090000
3058 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3059 aCamera->SetZFocus( (Graphic3d_Camera::FocusType) type, value );
3064 int OCCViewer_ViewWindow::stereographicFocusType() const
3066 int type = Relative;
3067 Handle(V3d_View) aView3d = myViewPort->getView();
3068 if ( !aView3d.IsNull() ) {
3069 #if OCC_VERSION_LARGE > 0x06090000
3070 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3071 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->ZFocusType();
3077 double OCCViewer_ViewWindow::stereographicFocusValue() const
3080 Handle(V3d_View) aView3d = myViewPort->getView();
3081 if ( !aView3d.IsNull() ) {
3082 #if OCC_VERSION_LARGE > 0x06090000
3083 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3084 value = aCamera->ZFocus();
3090 void OCCViewer_ViewWindow::setInterocularDistance( int type, double value )
3092 Handle(V3d_View) aView3d = myViewPort->getView();
3093 if ( !aView3d.IsNull() ) {
3094 #if OCC_VERSION_LARGE > 0x06090000
3095 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3096 aCamera->SetIOD( (Graphic3d_Camera::IODType) type, value );
3101 int OCCViewer_ViewWindow::interocularDistanceType() const
3103 int type = Relative;
3104 Handle(V3d_View) aView3d = myViewPort->getView();
3105 if ( !aView3d.IsNull() ) {
3106 #if OCC_VERSION_LARGE > 0x06090000
3107 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3108 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->GetIODType();
3114 double OCCViewer_ViewWindow::interocularDistanceValue() const
3116 double value = 0.05;
3117 Handle(V3d_View) aView3d = myViewPort->getView();
3118 if ( !aView3d.IsNull() ) {
3119 #if OCC_VERSION_LARGE > 0x06090000
3120 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3121 value = aCamera->IOD();
3127 void OCCViewer_ViewWindow::setReverseStereo( bool reverse )
3129 Handle(V3d_View) aView3d = myViewPort->getView();
3130 if ( !aView3d.IsNull() ) {
3131 #if OCC_VERSION_LARGE > 0x06090000
3132 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3133 aParams->ToReverseStereo = reverse;
3138 bool OCCViewer_ViewWindow::isReverseStereo() const
3140 int reverse = false;
3141 Handle(V3d_View) aView3d = myViewPort->getView();
3142 if ( !aView3d.IsNull() ) {
3143 #if OCC_VERSION_LARGE > 0x06090000
3144 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3145 reverse = aParams->ToReverseStereo;
3151 void OCCViewer_ViewWindow::setVSync( bool enable )
3153 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3154 if ( !anIntCont.IsNull() ) {
3155 #if OCC_VERSION_LARGE > 0x06090000
3156 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3157 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3158 aCaps->swapInterval = enable;
3163 bool OCCViewer_ViewWindow::isVSync() const
3166 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3167 if ( !anIntCont.IsNull() ) {
3168 #if OCC_VERSION_LARGE > 0x06090000
3169 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3170 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3171 enable = aCaps->swapInterval;
3177 void OCCViewer_ViewWindow::setQuadBufferSupport( bool enable )
3179 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3180 if ( !anIntCont.IsNull() ) {
3181 #if OCC_VERSION_LARGE > 0x06090000
3182 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3183 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3184 aCaps->contextStereo = enable;
3189 bool OCCViewer_ViewWindow::isQuadBufferSupport() const
3192 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3193 if ( !anIntCont.IsNull() ) {
3194 #if OCC_VERSION_LARGE > 0x06090000
3195 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3196 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3197 enable = aCaps->contextStereo;
3204 bool OCCViewer_ViewWindow::isOpenGlStereoSupport() const
3206 GLboolean support[1];
3207 glGetBooleanv (GL_STEREO, support);
3214 QColor OCCViewer_ViewWindow::backgroundColor() const
3216 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
3220 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
3222 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
3225 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
3227 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
3230 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
3232 if ( myViewPort ) myViewPort->setBackground( theBackground );
3235 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
3237 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
3243 void OCCViewer_ViewWindow::clearViewAspects()
3245 myViewAspects.clear();
3249 \return const reference to list of view aspects
3251 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
3253 return myViewAspects;
3257 Appends new view aspect
3258 \param aParams - new view aspects
3260 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
3262 myViewAspects.append( aParams );
3266 Replaces old view aspects by new ones
3267 \param aViewList - list of new view aspects
3269 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
3271 myViewAspects = aViewList;
3275 Get camera properties for the OCC view window.
3276 \return shared pointer on camera properties.
3278 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
3280 SUIT_CameraProperties aProps;
3282 Handle(V3d_View) aSourceView = getViewPort()->getView();
3283 if ( aSourceView.IsNull() )
3286 if ( get2dMode() == No2dMode ) {
3287 aProps.setDimension( SUIT_CameraProperties::Dim3D );
3290 aProps.setDimension( SUIT_CameraProperties::Dim2D );
3291 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
3294 // read common properites of the view
3295 Standard_Real anUp[3];
3296 Standard_Real anAt[3];
3297 Standard_Real anEye[3];
3298 Standard_Real aProj[3];
3299 Standard_Real anAxialScale[3];
3301 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
3302 aSourceView->At( anAt[0], anAt[1], anAt[2] );
3303 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
3304 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3306 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3307 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
3309 #if OCC_VERSION_LARGE > 0x06070100
3310 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
3312 // store camera properties "as is": it is up to synchronized
3313 // view classes to provide necessary property conversion.
3314 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
3315 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
3317 if ( aSourceView->Camera()->IsOrthographic() )
3319 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
3320 aProps.setViewAngle( 0.0 );
3324 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
3325 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
3327 aProps.setMappingScale( aSourceView->Camera()->Scale() );
3329 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
3331 // generate view orientation matrix for transforming OCC projection reference point
3332 // into a camera (eye) position.
3333 gp_Dir aLeftDir = gp_Dir( anUp[0], anUp[1], anUp[2] ) ^ gp_Dir( aProj[0], aProj[1], aProj[2] );
3336 aTrsf.SetValue( 1, 1, aLeftDir.X() );
3337 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
3338 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
3340 aTrsf.SetValue( 1, 2, anUp[0] );
3341 aTrsf.SetValue( 2, 2, anUp[1] );
3342 aTrsf.SetValue( 3, 2, anUp[2] );
3344 aTrsf.SetValue( 1, 3, aProj[0] );
3345 aTrsf.SetValue( 2, 3, aProj[1] );
3346 aTrsf.SetValue( 3, 3, aProj[2] );
3348 aTrsf.SetValue( 1, 4, anAt[0] );
3349 aTrsf.SetValue( 2, 4, anAt[1] );
3350 aTrsf.SetValue( 3, 4, anAt[2] );
3352 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
3354 // transform to world-space coordinate system
3355 gp_XYZ aPosition( aProjRef.X(), aProjRef.Y(), aCameraDepth );
3356 aTrsf.Transforms( aPosition );
3358 // compute focal point
3359 double aFocalPoint[3];
3361 aFocalPoint[0] = aPosition.X() - aProj[0] * aCameraDepth;
3362 aFocalPoint[1] = aPosition.Y() - aProj[1] * aCameraDepth;
3363 aFocalPoint[2] = aPosition.Z() - aProj[2] * aCameraDepth;
3365 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3366 aProps.setPosition( aPosition.X(), aPosition.Y(), aPosition.Z() );
3368 Standard_Real aViewScale[2];
3369 aSourceView->Size( aViewScale[0], aViewScale[1] );
3370 aProps.setMappingScale( aViewScale[1] );
3378 This implementation synchronizes OCC view's camera propreties.
3380 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
3382 bool blocked = blockSignals( true );
3384 SUIT_CameraProperties aProps = theView->cameraProperties();
3385 if ( !cameraProperties().isCompatible( aProps ) ) {
3386 // other view, this one is being currently synchronized to, seems has become incompatible
3387 // we have to break synchronization
3392 Handle(V3d_View) aDestView = getViewPort()->getView();
3394 aDestView->SetImmediateUpdate( Standard_False );
3397 double aPosition[3];
3398 double aFocalPoint[3];
3399 double anAxialScale[3];
3401 // get common properties
3402 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3403 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
3404 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3405 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3407 #if OCC_VERSION_LARGE > 0x06070100
3408 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3409 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
3410 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3411 aDestView->Camera()->SetScale( aProps.getMappingScale() );
3413 gp_Dir aProjDir( aPosition[0] - aFocalPoint[0],
3414 aPosition[1] - aFocalPoint[1],
3415 aPosition[2] - aFocalPoint[2] );
3417 // get custom view translation
3418 Standard_Real aTranslation[3];
3419 aDestView->At( aTranslation[0], aTranslation[1], aTranslation[2] );
3421 gp_Dir aLeftDir = gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] )
3422 ^ gp_Dir( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
3425 aTrsf.SetValue( 1, 1, aLeftDir.X() );
3426 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
3427 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
3429 aTrsf.SetValue( 1, 2, anUpDir[0] );
3430 aTrsf.SetValue( 2, 2, anUpDir[1] );
3431 aTrsf.SetValue( 3, 2, anUpDir[2] );
3433 aTrsf.SetValue( 1, 3, aProjDir.X() );
3434 aTrsf.SetValue( 2, 3, aProjDir.Y() );
3435 aTrsf.SetValue( 3, 3, aProjDir.Z() );
3437 aTrsf.SetValue( 1, 4, aTranslation[0] );
3438 aTrsf.SetValue( 2, 4, aTranslation[1] );
3439 aTrsf.SetValue( 3, 4, aTranslation[2] );
3442 // transform to view-space coordinate system
3443 gp_XYZ aProjRef( aPosition[0], aPosition[1], aPosition[2] );
3444 aTrsf.Transforms( aProjRef );
3446 // set view camera properties using low-level approach. this is done
3447 // in order to avoid interference with static variables in v3d view used
3448 // when rotation is in process in another view.
3449 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
3450 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
3452 Graphic3d_Vector aMappingProj( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
3453 Graphic3d_Vector aMappingUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3455 aMappingProj.Normalize();
3456 aMappingUp.Normalize();
3458 anOrientation.SetViewReferencePlane( aMappingProj );
3459 anOrientation.SetViewReferenceUp( aMappingUp );
3461 aDestView->SetViewMapping( aMapping );
3462 aDestView->SetViewOrientation( anOrientation );
3465 aDestView->SetCenter( aProjRef.X(), aProjRef.Y() );
3467 // set mapping scale
3468 double aMapScaling = aProps.getMappingScale();
3469 Standard_Real aWidth, aHeight;
3470 aDestView->Size( aWidth, aHeight );
3471 aDestView->SetSize ( aWidth > aHeight ? aMapScaling * (aWidth / aHeight) : aMapScaling );
3474 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3476 aDestView->ZFitAll();
3477 aDestView->SetImmediateUpdate( Standard_True );
3478 aDestView->Redraw();
3480 blockSignals( blocked );
3484 \brief Indicates whether preselection is enabled
3485 \return true if preselection is enabled
3487 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
3489 return myPreselectionEnabled;
3493 \brief Enables/disables preselection
3494 \param theIsToEnable if true - preselection will be enabled
3496 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
3498 onSwitchPreselection( theIsToEnable );
3502 \brief Indicates whether selection is enabled
3503 \return true if selection is enabled
3505 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3507 return mySelectionEnabled;
3511 \brief Enables/disables selection
3512 \param theIsToEnable if true - selection will be enabled
3514 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3516 onSwitchSelection( theIsToEnable );
3521 \brief called if clipping operation is activated / deactivated.
3523 Enables/disables clipping plane displaying.
3525 \parma on action state
3527 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3529 if(!myModel) return;
3530 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3533 if (!aClippingDlg) {
3534 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3535 myModel->setClippingDlg(aClippingDlg);
3537 if (!aClippingDlg->isVisible())
3538 aClippingDlg->show();
3540 if ( aClippingDlg ) {
3541 aClippingDlg->close();
3542 myModel->setClippingDlg(0);
3546 SUIT_ViewManager* mgr = getViewManager();
3548 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3549 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3550 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3551 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3553 QAction* a = toolMgr()->action( ClippingId );
3555 if(theIsOn != a->isChecked()){
3556 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3557 a->setChecked(theIsOn);
3558 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));