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;
247 updateEnabledDrawMode();
249 mySetRotationPointDlg = 0;
252 IsSketcherStyle = false;
259 myInteractionStyle = SUIT_ViewModel::STANDARD;
260 myPreselectionEnabled = true;
261 mySelectionEnabled = true;
263 myCursorIsHand = false;
271 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
274 qDeleteAll( mySketchers );
278 \brief Internal initialization.
280 void OCCViewer_ViewWindow::initLayout()
282 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
283 myViewPort->installEventFilter(this);
284 setCentralWidget(myViewPort);
285 myOperation = NOTHING;
287 myCurrPointType = GRAVITY;
288 myPrevPointType = GRAVITY;
289 mySelectedPoint = gp_Pnt(0.,0.,0.);
290 myRotationPointSelection = false;
292 setTransformRequested ( NOTHING );
293 setTransformInProcess ( false );
310 // Graduated axes dialog
311 QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
312 myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
313 myCubeAxesDlg->initialize();
315 connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
318 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
320 return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
324 \brief Detect viewer operation according the the mouse button pressed
325 and key modifiers used.
326 \param theEvent mouse event
327 \return type of the operation
329 OCCViewer_ViewWindow::OperationType
330 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
332 OperationType aOp = NOTHING;
333 SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
334 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
335 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
337 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
338 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
340 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
341 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
342 (my2dMode == No2dMode))
349 \brief Customize event handling
350 \param watched event receiver object
352 \return \c true if the event processing should be stopped
354 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
356 if ( watched == myViewPort ) {
357 int aType = e->type();
359 case QEvent::MouseButtonPress:
360 vpMousePressEvent((QMouseEvent*) e);
363 case QEvent::MouseButtonRelease:
364 vpMouseReleaseEvent((QMouseEvent*) e);
367 case QEvent::MouseMove:
368 vpMouseMoveEvent((QMouseEvent*) e);
371 case QEvent::MouseButtonDblClick:
372 emit mouseDoubleClicked(this, (QMouseEvent*)e);
377 QWheelEvent* aEvent = (QWheelEvent*) e;
379 if ( aEvent->modifiers().testFlag(Qt::ControlModifier) ) {
380 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
381 if ( isPreselectionEnabled() && ic->HasOpenedContext() ) {
382 if ( aEvent->delta() > 0 ) {
383 ic->HilightNextDetected( myViewPort->getView() );
385 ic->HilightPreviousDetected( myViewPort->getView() );
390 emit vpTransformationStarted ( ZOOMVIEW );
391 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
392 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
395 int x1 = (int)( aEvent->x() + width()*delta/100 );
396 int y1 = (int)( aEvent->y() + height()*delta/100 );
397 myViewPort->zoom( x, y, x1, y1 );
398 myViewPort->getView()->ZFitAll();
399 emit vpTransformationFinished ( ZOOMVIEW );
404 case QEvent::ContextMenu:
406 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
407 if ( aEvent->reason() != QContextMenuEvent::Mouse )
408 emit contextMenuRequested( aEvent );
412 case QEvent::KeyPress:
413 emit keyPressed(this, (QKeyEvent*) e);
420 return SUIT_ViewWindow::eventFilter(watched, e);
424 \brief Update state of enable draw mode state.
426 void OCCViewer_ViewWindow::updateEnabledDrawMode()
429 myEnableDrawMode = myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
433 \brief Handle mouse press event
434 \param theEvent mouse event
436 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
438 myStartX = theEvent->x();
439 myStartY = theEvent->y();
440 int anInteractionStyle = interactionStyle();
442 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
443 // which are assigned for pan and rotate - these operations are activated immediately after pressing
444 // of the first button, so it is necessary to switch to zoom when the second button is pressed
445 bool aSwitchToZoom = false;
446 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
447 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
448 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
451 switch ( myOperation ) {
453 if ( theEvent->button() == Qt::LeftButton )
454 emit vpTransformationStarted ( WINDOWFIT );
458 if ( theEvent->button() == Qt::LeftButton )
459 emit vpTransformationStarted ( PANGLOBAL );
463 if ( theEvent->button() == Qt::LeftButton ) {
464 myViewPort->startZoomAtPoint( myStartX, myStartY );
465 emit vpTransformationStarted ( ZOOMVIEW );
470 if ( aSwitchToZoom ) {
471 myViewPort->startZoomAtPoint( myStartX, myStartY );
474 else if ( theEvent->button() == Qt::LeftButton )
475 emit vpTransformationStarted ( PANVIEW );
479 if ( aSwitchToZoom ) {
480 myViewPort->startZoomAtPoint( myStartX, myStartY );
483 else if ( theEvent->button() == Qt::LeftButton ) {
484 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
485 emit vpTransformationStarted ( ROTATE );
490 /* Try to activate a transformation */
491 OperationType aState;
492 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
493 aState = getButtonState(theEvent, anInteractionStyle);
495 aState = OCCViewer_ViewWindow::NOTHING;
500 myViewPort->startZoomAtPoint( myStartX, myStartY );
508 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
511 if ( myRotationPointSelection )
513 if ( theEvent->button() == Qt::LeftButton )
515 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
517 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
519 TopoDS_Shape aShape = ic->SelectedShape();
520 GProp_GProps aSystem;
522 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
524 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
526 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE )
528 BRepGProp::LinearProperties( aShape, aSystem );
529 aPnt = aSystem.CentreOfMass();
531 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE )
533 BRepGProp::SurfaceProperties( aShape, aSystem );
534 aPnt = aSystem.CentreOfMass();
536 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID )
538 BRepGProp::VolumeProperties( aShape, aSystem );
539 aPnt = aSystem.CentreOfMass();
543 myCurrPointType = myPrevPointType;
547 if ( mySetRotationPointDlg )
549 myRotationPointSelection = false;
550 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
553 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
554 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
555 ic->CloseAllContexts();
556 myOperation = NOTHING;
557 myViewPort->setCursor( myCursor );
558 myCursorIsHand = false;
559 myRotationPointSelection = false;
563 emit mousePressed(this, theEvent);
566 /* notify that we start a transformation */
567 if ( transformRequested() )
568 emit vpTransformationStarted ( myOperation );
570 if ( transformRequested() )
571 setTransformInProcess( true );
573 /* we may need it for sketching... */
574 if ( l_mbPressEvent )
575 delete l_mbPressEvent;
576 l_mbPressEvent = new QMouseEvent( *theEvent );
581 \brief Start zooming operation.
583 Sets the corresponding cursor for the widget.
585 void OCCViewer_ViewWindow::activateZoom()
587 if ( !transformRequested() && !myCursorIsHand )
588 saveCursor(); /* save old cursor */
590 if ( myOperation != ZOOMVIEW ) {
591 QPixmap zoomPixmap (imageZoomCursor);
592 QCursor zoomCursor (zoomPixmap);
593 if( setTransformRequested ( ZOOMVIEW ) )
594 myViewPort->setCursor( zoomCursor );
600 \brief Start panning operation.
602 Sets the corresponding cursor for the widget.
604 void OCCViewer_ViewWindow::activatePanning()
606 if ( !transformRequested() && !myCursorIsHand )
607 saveCursor(); // save old cursor
609 if ( myOperation != PANVIEW ) {
610 QCursor panCursor (Qt::SizeAllCursor);
611 if( setTransformRequested ( PANVIEW ) )
612 myViewPort->setCursor( panCursor );
617 \brief Start rotation operation
619 Sets the corresponding cursor for the widget.
621 void OCCViewer_ViewWindow::activateRotation()
623 if ( !transformRequested() && !myCursorIsHand )
624 saveCursor(); // save old cursor
626 if ( myOperation != ROTATE ) {
627 QPixmap rotatePixmap (imageRotateCursor);
628 QCursor rotCursor (rotatePixmap);
629 if( setTransformRequested ( ROTATE ) )
630 myViewPort->setCursor( rotCursor );
635 \brief Compute the gravity center.
636 \param theX used to return X coordinate of the gravity center
637 \param theY used to return Y coordinate of the gravity center
638 \param theZ used to return Z coordinate of the gravity center
639 \return \c true if the gravity center is computed
641 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
643 Handle(V3d_View) aView3d = myViewPort->getView();
645 // Project boundaries points and add to avergae gravity
646 // the ones which lie within the screen limits
647 Standard_Real aScreenLimits[4] = { 0.0, 0.0, 0.0, 0.0 };
649 #if OCC_VERSION_LARGE > 0x06070100
650 // NDC space screen limits
651 aScreenLimits[0] = -1.0;
652 aScreenLimits[1] = 1.0;
653 aScreenLimits[2] = -1.0;
654 aScreenLimits[3] = 1.0;
656 aView3d->View()->ViewMapping().WindowLimit( aScreenLimits[0],
662 Standard_Integer aPointsNb = 0;
664 Standard_Real aXmin = 0.0;
665 Standard_Real aYmin = 0.0;
666 Standard_Real aZmin = 0.0;
667 Standard_Real aXmax = 0.0;
668 Standard_Real aYmax = 0.0;
669 Standard_Real aZmax = 0.0;
671 Graphic3d_MapOfStructure aSetOfStructures;
672 aView3d->View()->DisplayedStructures( aSetOfStructures );
673 Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures );
675 for( ; aStructureIt.More(); aStructureIt.Next() ) {
676 const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key();
677 if ( aStructure->IsEmpty() ) {
681 #if OCC_VERSION_LARGE > 0x06070100
682 Bnd_Box aBox = aStructure->MinMaxValues();
683 aXmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().X();
684 aYmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Y();
685 aZmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Z();
686 aXmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().X();
687 aYmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Y();
688 aZmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Z();
690 aStructure->MinMaxValues( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
693 // Infinite structures are skipped
694 Standard_Real aLIM = ShortRealLast() - 1.0;
695 if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
696 || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
700 gp_Pnt aPoints[8] = {
701 gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
702 gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
703 gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
704 gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
707 for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
708 const gp_Pnt& aBBPoint = aPoints[aPointIt];
710 #if OCC_VERSION_LARGE > 0x06070100
711 gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
712 const Standard_Real& U = aProjected.X();
713 const Standard_Real& V = aProjected.Y();
715 Standard_Real U = 0.0;
716 Standard_Real V = 0.0;
717 Standard_Real W = 0.0;
718 aView3d->View()->Projects( aBBPoint.X(), aBBPoint.Y(), aBBPoint.Z(), U, V, W );
721 if (U >= aScreenLimits[0]
722 && U <= aScreenLimits[1]
723 && V >= aScreenLimits[2]
724 && V <= aScreenLimits[3])
727 theX += aBBPoint.X();
728 theY += aBBPoint.Y();
729 theZ += aBBPoint.Z();
744 \brief Set the gravity center as a rotation point.
746 void OCCViewer_ViewWindow::activateSetRotationGravity()
748 if ( myRotationPointSelection )
750 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
751 ic->CloseAllContexts();
752 myOperation = NOTHING;
753 myViewPort->setCursor( myCursor );
754 myCursorIsHand = false;
755 myRotationPointSelection = false;
758 myPrevPointType = myCurrPointType;
759 myCurrPointType = GRAVITY;
761 Standard_Real Xcenter, Ycenter, Zcenter;
762 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
763 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
767 \brief Update gravity center in the "Set Rotation Point" dialog box.
768 \sa OCCViewer_SetRotationPointDlg class
770 void OCCViewer_ViewWindow::updateGravityCoords()
772 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == GRAVITY )
774 Standard_Real Xcenter, Ycenter, Zcenter;
775 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
776 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
781 \brief Set the point selected by the user as a rotation point.
782 \param theX X coordinate of the rotation point
783 \param theY Y coordinate of the rotation point
784 \param theZ Z coordinate of the rotation point
786 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
788 if ( myRotationPointSelection )
790 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
791 ic->CloseAllContexts();
792 myOperation = NOTHING;
793 myViewPort->setCursor( myCursor );
794 myCursorIsHand = false;
795 myRotationPointSelection = false;
798 myPrevPointType = myCurrPointType;
799 myCurrPointType = SELECTED;
800 mySelectedPoint.SetCoord(theX,theY,theZ);
804 \brief Start the shape selection process.
806 void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
808 myPrevPointType = myCurrPointType;
809 myCurrPointType = SELECTED;
811 // activate selection ------>
812 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
814 ic->OpenLocalContext();
816 AIS_ListOfInteractive aList;
817 ic->DisplayedObjects( aList );
818 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
820 Handle(AIS_InteractiveObject) anObj = it.Value();
821 if ( !anObj.IsNull() && anObj->HasPresentation() &&
822 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
825 ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
828 // activate selection <------
830 if ( !myCursorIsHand )
832 QCursor handCursor (Qt::PointingHandCursor);
833 myCursorIsHand = true;
835 myViewPort->setCursor( handCursor );
837 myRotationPointSelection = true;
841 \brief Start global panning operation
843 Sets the corresponding cursor for the widget.
845 void OCCViewer_ViewWindow::activateGlobalPanning()
847 Handle(V3d_View) aView3d = myViewPort->getView();
848 if ( !aView3d.IsNull() ) {
849 QPixmap globalPanPixmap (imageCrossCursor);
850 QCursor glPanCursor (globalPanPixmap);
851 myCurScale = aView3d->Scale();
852 aView3d->FitAll(0.01, false);
853 saveCursor(); // save old cursor
854 myViewPort->fitAll(); // fits view before selecting a new scene center
855 if( setTransformRequested( PANGLOBAL ) )
856 myViewPort->setCursor( glPanCursor );
861 \brief Starts fit operation.
863 Sets the corresponding cursor for the widget.
865 void OCCViewer_ViewWindow::activateWindowFit()
867 if ( !transformRequested() && !myCursorIsHand )
868 saveCursor(); /* save old cursor */
870 if ( myOperation != WINDOWFIT ) {
871 QCursor handCursor (Qt::PointingHandCursor);
872 if( setTransformRequested ( WINDOWFIT ) )
874 myViewPort->setCursor ( handCursor );
875 myCursorIsHand = true;
881 \brief Start delayed viewer operation.
883 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
885 bool ok = transformEnabled( op );
886 myOperation = ok ? op : NOTHING;
887 myViewPort->setMouseTracking( myOperation == NOTHING );
892 \brief Handle mouse move event.
893 \param theEvent mouse event
895 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
897 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
899 switch ( getButtonState( theEvent, interactionStyle() ) ) {
901 myViewPort->startZoomAtPoint( myStartX, myStartY );
909 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
916 myCurrX = theEvent->x();
917 myCurrY = theEvent->y();
918 switch (myOperation) {
920 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
924 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
930 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
944 if ( myRotationPointSelection || isSketcherStyle() )
946 emit mouseMoving( this, theEvent );
950 int aState = theEvent->modifiers();
951 int aButton = theEvent->buttons();
952 int anInteractionStyle = interactionStyle();
953 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
954 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
955 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
956 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
957 myDrawRect = myEnableDrawMode;
960 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
961 QCursor handCursor (Qt::PointingHandCursor);
962 myCursorIsHand = true;
964 myViewPort->setCursor( handCursor );
967 emit mouseMoving( this, theEvent );
969 else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
970 aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
971 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
972 aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
973 OCCViewer_ViewSketcher* sketcher = 0;
974 QList<OCCViewer_ViewSketcher*>::Iterator it;
975 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
977 OCCViewer_ViewSketcher* sk = (*it);
978 if( sk->isDefault() && sk->sketchButton() == aButton )
981 if ( sketcher && myCurSketch == -1 )
983 activateSketching( sketcher->type() );
986 myCurSketch = mypSketcher->sketchButton();
988 if ( l_mbPressEvent )
990 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
991 delete l_mbPressEvent;
994 QApplication::sendEvent( getViewPort(), theEvent );
999 emit mouseMoving( this, theEvent );
1005 \brief Handle mouse release event.
1006 \param theEvent mouse event
1008 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
1010 switch ( myOperation ) {
1013 int prevState = myCurSketch;
1014 if(theEvent->button() == Qt::RightButton)
1016 QList<OCCViewer_ViewSketcher*>::Iterator it;
1017 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
1019 OCCViewer_ViewSketcher* sk = (*it);
1020 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
1025 emit mouseReleased(this, theEvent);
1026 if(theEvent->button() == Qt::RightButton && prevState == -1)
1028 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1029 theEvent->pos(), theEvent->globalPos() );
1030 emit contextMenuRequested( &aEvent );
1035 myViewPort->endRotation();
1041 myViewPort->getView()->ZFitAll();
1046 if ( theEvent->button() == Qt::LeftButton ) {
1047 myViewPort->setCenter( theEvent->x(), theEvent->y() );
1048 myViewPort->getView()->SetScale(myCurScale);
1054 if ( theEvent->button() == Qt::LeftButton ) {
1055 myCurrX = theEvent->x();
1056 myCurrY = theEvent->y();
1058 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1059 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1066 // NOTE: viewer 3D detects a rectangle of selection using this event
1067 // so we must emit it BEFORE resetting the selection rectangle
1069 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1073 myViewPort->update();
1076 if ( l_mbPressEvent )
1078 delete l_mbPressEvent;
1084 \brief Reset the viewport to its initial state
1085 ( no transformations in process etc. )
1087 void OCCViewer_ViewWindow::resetState()
1091 if ( myRotationPointSelection )
1093 QCursor handCursor (Qt::PointingHandCursor);
1094 myViewPort->setCursor( handCursor );
1098 if ( transformRequested() || myCursorIsHand )
1099 myViewPort->setCursor( myCursor );
1100 myCursorIsHand = false;
1103 if ( transformRequested() )
1104 emit vpTransformationFinished (myOperation);
1106 setTransformInProcess( false );
1107 setTransformRequested( NOTHING );
1112 \brief Draw rubber band rectangle.
1114 void OCCViewer_ViewWindow::drawRect()
1116 if ( !myRectBand ) {
1117 myRectBand = new QtxRectRubberBand( myViewPort );
1119 //palette.setColor(myRectBand->foregroundRole(), Qt::white);
1120 //myRectBand->setPalette(palette);
1122 //myRectBand->hide();
1124 myRectBand->setUpdatesEnabled ( false );
1125 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1126 myRectBand->initGeometry( aRect );
1128 if ( !myRectBand->isVisible() )
1131 myRectBand->setUpdatesEnabled ( true );
1132 //myRectBand->repaint();
1134 //myRectBand->setVisible( aRect.isValid() );
1135 //if ( myRectBand->isVisible() )
1136 // myRectBand->repaint();
1138 // myRectBand->show();
1139 //myRectBand->repaint();
1143 \brief Clear rubber band rectangle on the end on the dragging operation.
1145 void OCCViewer_ViewWindow::endDrawRect()
1147 //delete myRectBand;
1151 myRectBand->clearGeometry();
1157 \brief Create actions.
1159 void OCCViewer_ViewWindow::createActions()
1161 if( !toolMgr()->isEmpty() )
1164 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1169 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1170 tr( "MNU_DUMP_VIEW" ), 0, this);
1171 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1172 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1173 toolMgr()->registerAction( aAction, DumpId );
1176 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1177 tr( "MNU_FITALL" ), 0, this);
1178 aAction->setStatusTip(tr("DSC_FITALL"));
1179 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1180 toolMgr()->registerAction( aAction, FitAllId );
1183 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1184 tr( "MNU_FITRECT" ), 0, this);
1185 aAction->setStatusTip(tr("DSC_FITRECT"));
1186 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1187 toolMgr()->registerAction( aAction, FitRectId );
1190 aAction = new QtxAction(tr("MNU_FITSELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITSELECTION" ) ),
1191 tr( "MNU_FITSELECTION" ), 0, this);
1192 aAction->setStatusTip(tr("DSC_FITSELECTION"));
1193 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
1194 toolMgr()->registerAction( aAction, FitSelectionId );
1197 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1198 tr( "MNU_ZOOM_VIEW" ), 0, this);
1199 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1200 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1201 toolMgr()->registerAction( aAction, ZoomId );
1204 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1205 tr( "MNU_PAN_VIEW" ), 0, this);
1206 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1207 connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
1208 toolMgr()->registerAction( aAction, PanId );
1211 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1212 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1213 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1214 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1215 toolMgr()->registerAction( aAction, GlobalPanId );
1218 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1219 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1220 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1221 mySetRotationPointAction->setCheckable( true );
1222 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1223 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1226 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1227 tr( "MNU_ROTATE_VIEW" ), 0, this);
1228 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1229 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1230 toolMgr()->registerAction( aAction, RotationId );
1233 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1234 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1235 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1236 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1237 this->addAction(aAction);
1238 toolMgr()->registerAction( aAction, FrontId );
1240 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1241 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1242 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1243 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1244 this->addAction(aAction);
1245 toolMgr()->registerAction( aAction, BackId );
1247 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1248 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1249 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1250 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1251 this->addAction(aAction);
1252 toolMgr()->registerAction( aAction, TopId );
1254 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1255 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1256 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1257 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1258 this->addAction(aAction);
1259 toolMgr()->registerAction( aAction, BottomId );
1261 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1262 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1263 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1264 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1265 this->addAction(aAction);
1266 toolMgr()->registerAction( aAction, LeftId );
1268 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1269 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1270 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1271 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1272 this->addAction(aAction);
1273 toolMgr()->registerAction( aAction, RightId );
1275 // rotate anticlockwise
1276 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1277 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1278 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1279 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1280 this->addAction(aAction);
1281 toolMgr()->registerAction( aAction, AntiClockWiseId );
1284 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1285 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1286 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1287 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1288 this->addAction(aAction);
1289 toolMgr()->registerAction( aAction, ClockWiseId );
1291 // Projection mode group
1293 // - orthographic projection
1294 aAction = new QtxAction(tr("MNU_ORTHOGRAPHIC_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ORTHOGRAPHIC" ) ),
1295 tr( "MNU_ORTHOGRAPHIC_MODE" ), 0, this);
1296 aAction->setStatusTip(tr("DSC_ORTHOGRAPHIC_MODE"));
1297 aAction->setCheckable(true);
1298 toolMgr()->registerAction( aAction, OrthographicId );
1300 // - perspective projection
1301 aAction = new QtxAction(tr("MNU_PERSPECTIVE_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PERSPECTIVE" ) ),
1302 tr( "MNU_PERSPECTIVE_MODE" ), 0, this);
1303 aAction->setStatusTip(tr("DSC_PERSPECTIVE_MODE"));
1304 aAction->setCheckable(true);
1305 toolMgr()->registerAction( aAction, PerspectiveId );
1306 #if OCC_VERSION_LARGE > 0x06090000
1307 // - stereo projection
1308 aAction = new QtxAction(tr("MNU_STEREO_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STEREO" ) ),
1309 tr( "MNU_STEREO_MODE" ), 0, this);
1310 aAction->setStatusTip(tr("DSC_STEREO_MODE"));
1311 aAction->setCheckable(true);
1312 toolMgr()->registerAction( aAction, StereoId );
1313 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onStereoType(bool)));
1315 // - add exclusive action group
1316 QActionGroup* aProjectionGroup = new QActionGroup( this );
1317 aProjectionGroup->addAction( toolMgr()->action( OrthographicId ) );
1318 aProjectionGroup->addAction( toolMgr()->action( PerspectiveId ) );
1319 connect(aProjectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProjectionType(QAction*)));
1322 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1323 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1324 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1325 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1326 this->addAction(aAction);
1327 toolMgr()->registerAction( aAction, ResetId );
1330 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1331 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1332 tr("MNU_CLONE_VIEW"), 0, this);
1333 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1334 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1335 toolMgr()->registerAction( aAction, CloneId );
1337 aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
1338 tr("MNU_CLIPPING"), 0, this);
1339 aAction->setStatusTip (tr("DSC_CLIPPING"));
1340 aAction->setCheckable (true);
1341 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1342 toolMgr()->registerAction (aAction, ClippingId);
1344 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1345 tr( "MNU_SHOOT_VIEW" ), 0, this);
1346 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1347 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1348 toolMgr()->registerAction( aAction, MemId );
1350 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1351 tr( "MNU_PRESETS_VIEW" ), 0, this);
1352 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1353 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1354 toolMgr()->registerAction( aAction, RestoreId );
1356 if (myModel->trihedronActivated()) {
1357 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1358 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1359 aAction->setCheckable( true );
1360 aAction->setChecked( true );
1361 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1362 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1363 toolMgr()->registerAction( aAction, TrihedronShowId );
1367 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1368 tr( "MNU_SCALING" ), 0, this);
1369 aAction->setStatusTip(tr("DSC_SCALING"));
1370 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1371 toolMgr()->registerAction( aAction, AxialScaleId );
1373 // Enable/disable preselection
1374 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1375 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1376 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1377 aAction->setCheckable(true);
1378 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1379 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1381 // Enable/disable selection
1382 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1383 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1384 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1385 aAction->setCheckable(true);
1386 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1387 toolMgr()->registerAction( aAction, SwitchSelectionId );
1390 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1391 tr( "MNU_GRADUATED_AXES" ), 0, this);
1392 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1393 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1394 toolMgr()->registerAction( aAction, GraduatedAxesId );
1396 // Active only ambient light or not
1397 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1398 tr( "MNU_AMBIENT" ), 0, this);
1399 aAction->setStatusTip(tr("DSC_AMBIENT"));
1400 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1401 toolMgr()->registerAction( aAction, AmbientId );
1403 // Switch between interaction styles
1404 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1405 tr( "MNU_STYLE_SWITCH" ), 0, this);
1406 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1407 aAction->setCheckable(true);
1408 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1409 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1411 // Switch between zooming styles
1412 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1413 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1414 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1415 aAction->setCheckable(true);
1416 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1417 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1420 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1421 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1422 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1423 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1424 toolMgr()->registerAction( aAction, MaximizedId );
1426 // Return to 3d view
1427 if (my2dMode!=No2dMode){
1428 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1429 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1430 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1431 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1432 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1436 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1440 \brief Create toolbar.
1442 void OCCViewer_ViewWindow::createToolBar()
1444 static const char* titles[] = {
1445 "LBL_3DTOOLBAR_LABEL",
1446 "LBL_XYTOOLBAR_LABEL",
1447 "LBL_XZTOOLBAR_LABEL",
1448 "LBL_YZTOOLBAR_LABEL",
1450 static const char* names[] = {
1451 "OCCViewer3DViewOperations",
1452 "OCCViewerXYViewOperations",
1453 "OCCViewerXZViewOperations",
1454 "OCCViewerYZViewOperations",
1456 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1457 QString( names[my2dMode] ), // name (language-independant)
1458 false ); // disable floatable toolbar
1459 if ( my2dMode != No2dMode ){
1460 toolMgr()->append( ReturnTo3dViewId, tid );
1461 toolMgr()->append( toolMgr()->separator(), tid );
1463 toolMgr()->append( DumpId, tid );
1464 toolMgr()->append( SwitchInteractionStyleId, tid );
1465 toolMgr()->append( SwitchZoomingStyleId, tid );
1466 toolMgr()->append( SwitchPreselectionId, tid );
1467 toolMgr()->append( SwitchSelectionId, tid );
1468 if( myModel->trihedronActivated() )
1469 toolMgr()->append( TrihedronShowId, tid );
1471 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1472 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1473 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1474 #if OCC_VERSION_LARGE > 0x06090000
1475 aScaleAction->insertAction( toolMgr()->action( FitSelectionId ) );
1477 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1478 toolMgr()->append( aScaleAction, tid );
1480 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1481 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1482 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1483 toolMgr()->append( aPanningAction, tid );
1485 if (my2dMode == No2dMode) {
1486 toolMgr()->append( ChangeRotationPointId, tid );
1487 toolMgr()->append( RotationId, tid );
1489 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1490 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1491 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1492 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1493 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1494 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1495 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1496 toolMgr()->append( aViewsAction, tid );
1498 toolMgr()->append( AntiClockWiseId, tid );
1499 toolMgr()->append( ClockWiseId, tid );
1501 toolMgr()->append( OrthographicId, tid );
1502 toolMgr()->append( PerspectiveId, tid );
1503 #if OCC_VERSION_LARGE > 0x06090000
1504 toolMgr()->append( StereoId, tid );
1507 toolMgr()->append( ResetId, tid );
1510 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1511 aMemAction->insertAction( toolMgr()->action( MemId ) );
1512 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1513 toolMgr()->append( aMemAction, tid );
1515 toolMgr()->append( toolMgr()->separator(), tid );
1516 toolMgr()->append( CloneId, tid );
1518 toolMgr()->append( toolMgr()->separator(), tid );
1519 toolMgr()->append( ClippingId, tid );
1520 toolMgr()->append( AxialScaleId, tid );
1521 toolMgr()->append( GraduatedAxesId, tid );
1522 toolMgr()->append( AmbientId, tid );
1524 toolMgr()->append( MaximizedId, tid );
1525 toolMgr()->append( SynchronizeId, tid );
1529 \brief Perform 'fit all' operation.
1531 void OCCViewer_ViewWindow::onViewFitAll()
1533 myViewPort->fitAll();
1537 \brief Perform "front view" transformation.
1539 void OCCViewer_ViewWindow::onFrontView()
1541 emit vpTransformationStarted ( FRONTVIEW );
1542 Handle(V3d_View) aView3d = myViewPort->getView();
1543 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
1545 emit vpTransformationFinished ( FRONTVIEW );
1549 \brief Perform "back view" transformation.
1551 void OCCViewer_ViewWindow::onBackView()
1553 emit vpTransformationStarted ( BACKVIEW );
1554 Handle(V3d_View) aView3d = myViewPort->getView();
1555 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
1557 emit vpTransformationFinished ( BACKVIEW );
1561 \brief Perform "top view" transformation.
1563 void OCCViewer_ViewWindow::onTopView()
1565 emit vpTransformationStarted ( TOPVIEW );
1566 Handle(V3d_View) aView3d = myViewPort->getView();
1567 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
1569 emit vpTransformationFinished ( TOPVIEW );
1573 \brief Perform "bottom view" transformation.
1575 void OCCViewer_ViewWindow::onBottomView()
1577 emit vpTransformationStarted ( BOTTOMVIEW );
1578 Handle(V3d_View) aView3d = myViewPort->getView();
1579 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
1581 emit vpTransformationFinished ( BOTTOMVIEW );
1585 \brief Perform "left view" transformation.
1587 void OCCViewer_ViewWindow::onLeftView()
1589 emit vpTransformationStarted ( LEFTVIEW );
1590 Handle(V3d_View) aView3d = myViewPort->getView();
1591 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
1593 emit vpTransformationFinished ( LEFTVIEW );
1597 \brief Perform "right view" transformation.
1599 void OCCViewer_ViewWindow::onRightView()
1601 emit vpTransformationStarted ( RIGHTVIEW );
1602 Handle(V3d_View) aView3d = myViewPort->getView();
1603 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
1605 emit vpTransformationFinished ( RIGHTVIEW );
1609 \brief Rotate view 90 degrees clockwise
1611 void OCCViewer_ViewWindow::onClockWiseView()
1613 emit vpTransformationStarted ( CLOCKWISEVIEW );
1614 myViewPort->rotateXY( 90. );
1615 emit vpTransformationFinished ( CLOCKWISEVIEW );
1619 \brief Rotate view 90 degrees conterclockwise
1621 void OCCViewer_ViewWindow::onAntiClockWiseView()
1623 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1624 myViewPort->rotateXY( -90. );
1625 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1629 \brief Perform "reset view" transformation.
1631 Sets default orientation of the viewport camera.
1633 void OCCViewer_ViewWindow::onResetView()
1635 emit vpTransformationStarted( RESETVIEW );
1636 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1637 myViewPort->getView()->Reset( false );
1638 myViewPort->fitAll( false, true, false );
1639 myViewPort->getView()->SetImmediateUpdate( upd );
1640 onProjectionType(); // needed to apply projection type properly after reset
1641 myViewPort->getView()->Update();
1642 emit vpTransformationFinished( RESETVIEW );
1646 \brief Set the given projection mode.
1648 Set the given projection mode: Orthographic or Perspective.
1650 void OCCViewer_ViewWindow::onProjectionType( QAction* theAction )
1652 Handle(V3d_View) aView3d = myViewPort->getView();
1653 if ( !aView3d.IsNull() ) {
1654 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1655 if (theAction == toolMgr()->action( OrthographicId )) {
1656 myModel->setProjectionType(Orthographic);
1657 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Orthographic );
1658 aCamera->SetFOVy(45.0);
1660 else if (theAction == toolMgr()->action( PerspectiveId )) {
1661 myModel->setProjectionType(Perspective);
1662 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Perspective );
1663 aCamera->SetFOVy(30.0);
1665 #if OCC_VERSION_LARGE > 0x06090000
1666 if (toolMgr()->action( StereoId )->isChecked()) {
1667 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1668 aCamera->SetFOVy(30.0);
1677 \brief Sets Stereo projection mode.
1679 Sets Stereo projection mode.
1681 void OCCViewer_ViewWindow::onStereoType( bool activate )
1683 #if OCC_VERSION_LARGE > 0x06090000
1684 Handle(V3d_View) aView3d = myViewPort->getView();
1685 if ( !aView3d.IsNull() ) {
1686 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1688 toolMgr()->action( PerspectiveId )->setChecked(true);
1689 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1690 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(false);
1692 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1693 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1694 setStereoType( aResMgr->integerValue( "OCCViewer", "stereo_type", 0 ) );
1695 setAnaglyphFilter( aResMgr->integerValue( "OCCViewer", "anaglyph_filter", 0 ) );
1696 setReverseStereo( aResMgr->booleanValue( "OCCViewer", "reverse_stereo", false ) );
1697 setVSync( aResMgr->booleanValue( "OCCViewer", "enable_vsync", true ) );
1698 setQuadBufferSupport( aResMgr->booleanValue( "OCCViewer", "enable_quad_buffer_support", false ) );
1701 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(true);
1702 if (myModel->projectionType() == Orthographic) {
1703 toolMgr()->action( OrthographicId )->setChecked(true);
1704 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Orthographic);
1706 else if (myModel->projectionType() == Perspective) {
1707 toolMgr()->action( PerspectiveId )->setChecked(true);
1708 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1715 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1716 toolMgr()->action( StereoId )->isChecked() )
1717 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1722 \brief Restore the view.
1724 Restore the projection mode based on tool-buttons states.
1726 void OCCViewer_ViewWindow::onProjectionType()
1728 emit vpTransformationStarted( PROJECTION );
1729 if (toolMgr()->action( OrthographicId )->isChecked())
1730 setProjectionType( Orthographic );
1731 if (toolMgr()->action( PerspectiveId )->isChecked())
1732 setProjectionType( Perspective );
1733 #if OCC_VERSION_LARGE > 0x06090000
1734 if (toolMgr()->action( StereoId )->isChecked())
1735 setProjectionType( Stereo );
1737 emit vpTransformationFinished( PROJECTION );
1740 void OCCViewer_ViewWindow::setProjectionType( int mode )
1742 QtxAction* anOrthographicAction = dynamic_cast<QtxAction*>( toolMgr()->action( OrthographicId ) );
1743 QtxAction* aPerspectiveAction = dynamic_cast<QtxAction*>( toolMgr()->action( PerspectiveId ) );
1744 #if OCC_VERSION_LARGE > 0x06090000
1745 QtxAction* aStereoAction = dynamic_cast<QtxAction*>( toolMgr()->action( StereoId ) );
1749 onProjectionType( anOrthographicAction );
1752 onProjectionType( aPerspectiveAction );
1755 onStereoType( true );
1758 // update action state if method is called outside
1759 if ( mode == Orthographic && !anOrthographicAction->isChecked() ) {
1760 anOrthographicAction->setChecked( true );
1761 #if OCC_VERSION_LARGE > 0x06090000
1762 aStereoAction->setChecked( false );
1765 if ( mode == Perspective && !aPerspectiveAction->isChecked() ) {
1766 aPerspectiveAction->setChecked( true );
1767 #if OCC_VERSION_LARGE > 0x06090000
1768 aStereoAction->setChecked( false );
1771 #if OCC_VERSION_LARGE > 0x06090000
1772 if ( mode == Stereo ) {
1773 aStereoAction->setChecked( true );
1774 if ( anOrthographicAction->isEnabled() ) {
1775 anOrthographicAction->setEnabled( false );
1776 anOrthographicAction->setChecked( false );
1777 aStereoAction->setChecked( false );
1780 anOrthographicAction->setEnabled( true );
1781 aStereoAction->setChecked( false );
1782 anOrthographicAction->setChecked(myModel->projectionType() == Orthographic);
1784 if ( aPerspectiveAction->isEnabled() ) {
1785 aPerspectiveAction->setEnabled( false );
1786 aPerspectiveAction->setChecked( true );
1787 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1788 toolMgr()->action( StereoId )->isChecked() )
1789 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1792 aPerspectiveAction->setEnabled( true );
1793 aStereoAction->setChecked( false );
1794 aPerspectiveAction->setChecked(myModel->projectionType() == Perspective);
1799 if ( !anOrthographicAction->isEnabled() )
1800 anOrthographicAction->setEnabled( true );
1801 if ( !aPerspectiveAction->isEnabled() )
1802 aPerspectiveAction->setEnabled( true );
1808 \brief Perform "fit all" transformation.
1810 void OCCViewer_ViewWindow::onFitAll()
1812 emit vpTransformationStarted( FITALLVIEW );
1813 myViewPort->fitAll();
1814 emit vpTransformationFinished( FITALLVIEW );
1818 \brief Perform "fit selection" transformation.
1820 void OCCViewer_ViewWindow::onFitSelection()
1822 emit vpTransformationStarted( FITSELECTION );
1823 #if OCC_VERSION_LARGE > 0x06090000
1824 myModel->getAISContext()->FitSelected( getViewPort()->getView() );
1826 emit vpTransformationFinished( FITSELECTION );
1830 \brief Called if 'change rotation point' operation is activated.
1831 \param on action state
1833 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1837 if (!mySetRotationPointDlg)
1839 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1840 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1843 if (!mySetRotationPointDlg->isVisible())
1845 //if (mySetRotationPointDlg->IsFirstShown())
1846 if (myCurrPointType == GRAVITY)
1848 Standard_Real Xcenter, Ycenter, Zcenter;
1849 if (computeGravityCenter(Xcenter, Ycenter, Zcenter))
1850 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1852 mySetRotationPointDlg->show();
1857 if (mySetRotationPointDlg->isVisible())
1858 mySetRotationPointDlg->hide();
1863 \brief Create one more window with same content.
1865 void OCCViewer_ViewWindow::onCloneView()
1867 SUIT_ViewWindow* vw = myManager->createViewWindow();
1869 emit viewCloned( vw );
1873 Creates one more window with same content
1875 void OCCViewer_ViewWindow::onAxialScale()
1877 if ( !myScalingDlg )
1878 myScalingDlg = new OCCViewer_AxialScaleDlg( this );
1880 if ( !myScalingDlg->isVisible() )
1882 myScalingDlg->Update();
1883 myScalingDlg->show();
1888 Shows Graduated Axes dialog
1890 void OCCViewer_ViewWindow::onGraduatedAxes()
1892 myCubeAxesDlg->Update();
1893 myCubeAxesDlg->show();
1896 void OCCViewer_ViewWindow::onAmbientToogle()
1898 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
1899 viewer->InitDefinedLights();
1900 while(viewer->MoreDefinedLights())
1902 Handle(V3d_Light) light = viewer->DefinedLight();
1903 if(light->Type() != V3d_AMBIENT)
1905 Handle(V3d_View) aView3d = myViewPort->getView();
1906 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
1907 else viewer->SetLightOn(light);
1909 viewer->NextDefinedLights();
1915 \brief Store view parameters.
1917 void OCCViewer_ViewWindow::onMemorizeView()
1919 appendViewAspect( getViewParams() );
1923 \brief Restore view parameters.
1925 void OCCViewer_ViewWindow::onRestoreView()
1927 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
1928 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
1930 updateViewAspects( aDlg->parameters() );
1931 if( myRestoreFlag && aDlg->parameters().count() )
1932 performRestoring( aDlg->currentItem() );
1936 \brief Restore view parameters.
1937 \param anItem view parameters
1939 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
1941 Handle(V3d_View) aView3d = myViewPort->getView();
1943 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
1944 aView3d->SetScale( anItem.scale );
1945 aView3d->SetTwist( anItem.twist );
1946 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
1947 aView3d->SetImmediateUpdate( prev );
1948 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1949 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1950 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
1952 #if OCC_VERSION_LARGE > 0x06070100
1953 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
1955 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
1957 // "eye" and "at" require conversion to represent center panning
1958 // up direction is only available after setting angle of twist and
1959 // other view parameters
1960 aView3d->Up( anUpX, anUpY, anUpZ );
1962 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
1963 gp_Dir anUp( anUpX, anUpY, anUpZ );
1964 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
1965 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1966 gp_Dir aSide = aProj ^ anUp;
1968 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
1969 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
1971 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
1972 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1975 aView3d->SetCenter( anItem.centerX, anItem.centerY );
1978 if ( !baseParamsOnly ) {
1980 myModel->setTrihedronShown( anItem.isVisible );
1981 myModel->setTrihedronSize( anItem.size );
1983 // graduated trihedron
1984 bool anIsVisible = anItem.gtIsVisible;
1985 OCCViewer_AxisWidget::AxisData anAxisData[3];
1986 anAxisData[0].DrawName = anItem.gtDrawNameX;
1987 anAxisData[1].DrawName = anItem.gtDrawNameZ;
1988 anAxisData[2].DrawName = anItem.gtDrawNameZ;
1989 anAxisData[0].Name = anItem.gtNameX;
1990 anAxisData[1].Name = anItem.gtNameZ;
1991 anAxisData[2].Name = anItem.gtNameZ;
1992 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
1993 anItem.gtNameColorGX,
1994 anItem.gtNameColorBX );
1995 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
1996 anItem.gtNameColorGY,
1997 anItem.gtNameColorBY );
1998 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
1999 anItem.gtNameColorGZ,
2000 anItem.gtNameColorBZ );
2001 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
2002 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
2003 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
2004 anAxisData[0].NbValues = anItem.gtNbValuesX;
2005 anAxisData[1].NbValues = anItem.gtNbValuesY;
2006 anAxisData[2].NbValues = anItem.gtNbValuesZ;
2007 anAxisData[0].Offset = anItem.gtOffsetX;
2008 anAxisData[1].Offset = anItem.gtOffsetY;
2009 anAxisData[2].Offset = anItem.gtOffsetZ;
2010 anAxisData[0].Color = QColor( anItem.gtColorRX,
2013 anAxisData[1].Color = QColor( anItem.gtColorRY,
2016 anAxisData[2].Color = QColor( anItem.gtColorRZ,
2019 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
2020 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
2021 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
2022 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
2023 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
2024 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
2026 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
2027 myCubeAxesDlg->ApplyData( aView3d );
2029 } // if ( !baseParamsOnly )
2035 \brief Set restore flag.
2037 void OCCViewer_ViewWindow::setRestoreFlag()
2043 \brief Called when action "show/hide trihedron" is activated.
2045 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
2047 myModel->setTrihedronShown(show);
2051 \brief Toggles preselection (highlighting) on/off
2053 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
2055 myPreselectionEnabled = on;
2056 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
2058 // unhighlight all highlighted objects
2060 myModel->unHighlightAll( true, false );
2063 // update action state if method is called outside
2064 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2065 if ( a && a->isChecked() != on ) {
2066 a->setChecked( on );
2071 \brief Toggles selection on/off
2073 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
2075 mySelectionEnabled = on;
2076 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
2078 // update action state if method is called outside
2081 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2083 a->setEnabled( on );
2087 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
2088 if ( a && a->isChecked() != on ) {
2089 a->setChecked( on );
2094 \brief Switches "keyboard free" interaction style on/off
2096 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
2098 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
2100 // update action state if method is called outside
2101 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
2102 if ( a->isChecked() != on )
2103 a->setChecked( on );
2107 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
2109 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
2111 myViewPort->setAdvancedZoomingEnabled( on );
2113 // update action state if method is called outside
2114 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
2115 if ( a->isChecked() != on )
2116 a->setChecked( on );
2120 \brief Get current interaction style
2121 \return interaction style
2123 int OCCViewer_ViewWindow::interactionStyle() const
2125 return myInteractionStyle;
2129 \brief Set current interaction style
2130 \param theStyle interaction style
2132 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
2134 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
2138 \brief Get current zooming style
2139 \return zooming style
2141 int OCCViewer_ViewWindow::zoomingStyle() const
2143 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
2147 \brief Set current zooming style
2148 \param theStyle zooming style
2150 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
2152 onSwitchZoomingStyle( theStyle == 1 );
2156 \brief Dump view window contents to the pixmap.
2157 \return pixmap containing all scene rendered in the window
2159 QImage OCCViewer_ViewWindow::dumpView()
2161 Handle(V3d_View) view = myViewPort->getView();
2162 if ( view.IsNull() )
2165 int aWidth = myViewPort->width();
2166 int aHeight = myViewPort->height();
2168 // rnv: An old approach to dump the OCCViewer content
2169 // Now used OCCT built-in procedure.
2171 QApplication::syncX();
2172 view->Redraw(); // In order to reactivate GL context
2175 #ifndef DISABLE_GLVIEWER
2176 OpenGLUtils_FrameBuffer aFrameBuffer;
2177 if( aFrameBuffer.init( aWidth, aHeight ) )
2179 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
2181 glPushAttrib( GL_VIEWPORT_BIT );
2182 glViewport( 0, 0, aWidth, aHeight );
2183 aFrameBuffer.bind();
2188 aFrameBuffer.unbind();
2191 aFrameBuffer.bind();
2192 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
2193 aFrameBuffer.unbind();
2195 anImage = anImage.rgbSwapped();
2196 anImage = anImage.mirrored();
2199 // if frame buffers are unsupported, use old functionality
2202 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
2204 QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
2206 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
2212 view->ToPixMap(aPix,aWidth, aHeight,Graphic3d_BT_RGBA);
2214 QImage anImage( aPix.Data(), aWidth, aHeight, QImage::Format_ARGB32 );
2215 anImage = anImage.mirrored();
2219 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
2220 const QString& fileName,
2221 const QString& format )
2223 if ( format != "PS" && format != "EPS")
2224 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
2226 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
2229 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
2230 else if (format == "EPS")
2231 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
2237 QString OCCViewer_ViewWindow::filter() const
2239 return tr( "OCC_IMAGE_FILES" );
2244 \brief Set parameters of the cutting plane
2245 \param on if \c true, cutting plane is enabled
2246 \param x X position of plane point
2247 \param y Y position of plane point
2248 \param z Z position of plane point
2249 \param dx X coordinate of plane normal
2250 \param dy Y coordinate of plane normal
2251 \param dz Z coordinate of plane normal
2253 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2254 const double dx, const double dy, const double dz )
2256 Handle(V3d_View) view = myViewPort->getView();
2257 if ( view.IsNull() )
2261 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2263 // try to use already existing plane or create a new one
2264 Handle(V3d_Plane) clipPlane;
2266 // calculate new a,b,c,d values for the plane
2267 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2269 pln.Coefficients(a, b, c, d);
2271 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2272 if(aPlanes.Size() > 0 ) {
2273 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2274 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2275 aClipPlane->SetEquation(pln);
2276 aClipPlane->SetOn(Standard_True);
2278 view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2282 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2283 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2284 for( ;anIter.More();anIter.Next() ){
2285 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2286 aClipPlane->SetOn(Standard_False);
2294 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2296 gp_Dir aDir = pln.Axis().Direction();
2297 gp_Pnt aPnt = pln.Location();
2298 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2303 \brief Check if any cutting plane is enabled
2304 \return \c true if at least one cutting plane is enabled
2306 bool OCCViewer_ViewWindow::isCuttingPlane()
2308 Handle(V3d_View) view = myViewPort->getView();
2310 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2311 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2312 for( ;anIter.More();anIter.Next() ) {
2313 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2314 if(aClipPlane->IsOn()) {
2323 \brief Get the visual parameters of the view window.
2324 \return visual parameters of view window
2326 viewAspect OCCViewer_ViewWindow::getViewParams() const
2328 double projX, projY, projZ, twist;
2329 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2330 double aScaleX, aScaleY, aScaleZ;
2332 Handle(V3d_View) aView3d = myViewPort->getView();
2334 aView3d->Proj( projX, projY, projZ );
2335 aView3d->At( atX, atY, atZ );
2336 aView3d->Eye( eyeX, eyeY, eyeZ );
2337 twist = aView3d->Twist();
2339 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2341 bool isShown = myModel->isTrihedronVisible();
2342 double size = myModel->trihedronSize();
2344 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2347 params.scale = aView3d->Scale();
2348 params.projX = projX;
2349 params.projY = projY;
2350 params.projZ = projZ;
2351 params.twist = twist;
2358 params.scaleX = aScaleX;
2359 params.scaleY = aScaleY;
2360 params.scaleZ = aScaleZ;
2361 params.name = aName;
2362 params.isVisible= isShown;
2365 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2366 aView3d->Center( params.centerX, params.centerY );
2369 // graduated trihedron
2370 bool anIsVisible = false;
2371 OCCViewer_AxisWidget::AxisData anAxisData[3];
2372 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2374 params.gtIsVisible = anIsVisible;
2375 params.gtDrawNameX = anAxisData[0].DrawName;
2376 params.gtDrawNameY = anAxisData[1].DrawName;
2377 params.gtDrawNameZ = anAxisData[2].DrawName;
2378 params.gtNameX = anAxisData[0].Name;
2379 params.gtNameY = anAxisData[1].Name;
2380 params.gtNameZ = anAxisData[2].Name;
2381 params.gtNameColorRX = anAxisData[0].NameColor.red();
2382 params.gtNameColorGX = anAxisData[0].NameColor.green();
2383 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2384 params.gtNameColorRY = anAxisData[1].NameColor.red();
2385 params.gtNameColorGY = anAxisData[1].NameColor.green();
2386 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2387 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2388 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2389 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2390 params.gtDrawValuesX = anAxisData[0].DrawValues;
2391 params.gtDrawValuesY = anAxisData[1].DrawValues;
2392 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2393 params.gtNbValuesX = anAxisData[0].NbValues;
2394 params.gtNbValuesY = anAxisData[1].NbValues;
2395 params.gtNbValuesZ = anAxisData[2].NbValues;
2396 params.gtOffsetX = anAxisData[0].Offset;
2397 params.gtOffsetY = anAxisData[1].Offset;
2398 params.gtOffsetZ = anAxisData[2].Offset;
2399 params.gtColorRX = anAxisData[0].Color.red();
2400 params.gtColorGX = anAxisData[0].Color.green();
2401 params.gtColorBX = anAxisData[0].Color.blue();
2402 params.gtColorRY = anAxisData[1].Color.red();
2403 params.gtColorGY = anAxisData[1].Color.green();
2404 params.gtColorBY = anAxisData[1].Color.blue();
2405 params.gtColorRZ = anAxisData[2].Color.red();
2406 params.gtColorGZ = anAxisData[2].Color.green();
2407 params.gtColorBZ = anAxisData[2].Color.blue();
2408 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2409 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2410 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2411 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2412 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2413 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2419 \brief Get visual parameters of this view window.
2420 \return visual parameters of view window
2422 QString OCCViewer_ViewWindow::getVisualParameters()
2424 viewAspect params = getViewParams();
2428 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2429 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2430 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
2431 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
2433 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2434 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2435 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2436 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2437 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2438 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2439 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2440 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2441 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2442 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2443 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2444 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2445 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2446 data << QString( "isVisible=%1" ).arg( params.isVisible );
2447 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2449 ClipPlanesList aPlanes = myModel->getClipPlanes();
2450 for ( int i=0; i < aPlanes.size(); i++ )
2452 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2453 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2454 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2455 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2456 switch ( aPlane.Mode )
2458 case OCCViewer_ClipPlane::Absolute :
2460 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2462 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2464 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2465 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2466 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2470 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2475 case OCCViewer_ClipPlane::Relative :
2477 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2478 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2479 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2484 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2485 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2486 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2487 data << ClippingPlane;
2490 // graduated trihedron
2491 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2492 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2493 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2494 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2495 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2496 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2497 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2498 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2499 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2500 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2501 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2502 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2503 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2504 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2505 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2506 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2507 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2508 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2509 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2510 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2511 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2512 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2513 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2514 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2515 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2516 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2517 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2518 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2519 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2520 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2521 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2522 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2523 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2524 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2525 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2526 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2527 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2528 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2529 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2530 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2531 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2532 data << QString( "background=%1" ).arg( bg );
2534 return data.join("*");
2538 \brief Restore visual parameters of the view window.
2539 \param parameters visual parameters of view window
2541 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2544 ClipPlanesList aClipPlanes;
2545 QStringList data = parameters.split( '*' );
2546 Qtx::BackgroundData bgData;
2547 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2549 foreach( QString param, data ) {
2550 QString paramName = param.section( '=', 0, 0 ).trimmed();
2551 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2552 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2553 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2554 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2555 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2556 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2557 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2558 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2559 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2560 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2561 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2562 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2563 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2564 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2565 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2566 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2567 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2568 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2569 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2570 else if ( paramName.contains( "ClippingPlane" ) )
2572 QStringList ClipPlaneData = paramValue.split( ';' );
2573 OCCViewer_ClipPlane aPlane;
2574 foreach( QString ClipPlaneParam, ClipPlaneData )
2576 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2577 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2578 if ( ClipPlane_paramName == "Mode" )
2580 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2582 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2583 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2584 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2585 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2588 switch ( aPlane.Mode )
2590 case OCCViewer_ClipPlane::Absolute :
2591 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2592 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2593 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2594 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2595 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2598 case OCCViewer_ClipPlane::Relative :
2599 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2600 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2601 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2606 aClipPlanes.push_back(aPlane);
2608 // graduated trihedron
2609 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2610 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2611 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2612 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2613 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2614 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2615 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2616 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2617 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2618 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2619 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2620 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2621 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2622 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2623 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2624 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2625 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2626 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2627 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2628 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2629 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2630 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2631 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2632 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2633 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2634 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2635 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2636 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2637 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2638 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2639 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2640 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2641 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2642 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2643 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2644 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2645 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2646 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2647 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2648 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2649 else if ( paramName == "background" ) {
2650 QString bg = paramValue.replace( "$", "=" );
2651 bgData = Qtx::stringToBackground( bg );
2655 else // old format - "1.000e+00*0.000e+00..."
2658 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2659 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2660 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2661 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2662 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2663 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2664 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
2665 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2666 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2667 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
2668 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2669 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2670 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2671 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
2672 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
2673 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
2674 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
2675 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
2677 performRestoring( params );
2678 setBackground( bgData );
2679 myModel->setClipPlanes(aClipPlanes);
2683 \brief Handle show event.
2685 Emits Show() signal.
2687 \param theEvent show event
2689 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2691 emit Show( theEvent );
2695 \brief Handle hide event.
2697 Emits Hide() signal.
2699 \param theEvent hide event
2701 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
2703 emit Hide( theEvent );
2708 Save old cursor. [ protected ]
2710 void OCCViewer_ViewWindow::saveCursor()
2712 QCursor* aCursor = NULL;
2714 aCursor = myViewPort->getDefaultCursor();
2715 myCursor = ( aCursor ? *aCursor : cursor() );
2720 Creates default sketcher. [ virtual protected ]
2722 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
2725 return new OCCViewer_RectSketcher( this, type );
2726 if ( type == Polygon )
2727 return new OCCViewer_PolygonSketcher( this, type );
2731 void OCCViewer_ViewWindow::initSketchers()
2733 if ( mySketchers.isEmpty() )
2735 mySketchers.append( createSketcher( Rect ) );
2736 mySketchers.append( createSketcher( Polygon ) );
2740 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
2742 OCCViewer_ViewSketcher* sketcher = 0;
2743 QList<OCCViewer_ViewSketcher*>::Iterator it;
2744 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
2746 OCCViewer_ViewSketcher* sk = (*it);
2747 if ( sk->type() == typ )
2754 Handles requests for sketching in the active view. [ virtual public ]
2756 void OCCViewer_ViewWindow::activateSketching( int type )
2758 OCCViewer_ViewPort3d* vp = getViewPort();
2762 if ( !vp->isSketchingEnabled() )
2765 /* Finish current sketching */
2766 if ( type == NoSketching )
2770 onSketchingFinished();
2771 mypSketcher->deactivate();
2775 /* Activate new sketching */
2778 activateSketching( NoSketching ); /* concurrency not suported */
2779 mypSketcher = getSketcher( type );
2782 mypSketcher->activate();
2783 onSketchingStarted();
2789 Unhilights detected entities. [ virtual protected ]
2791 void OCCViewer_ViewWindow::onSketchingStarted()
2796 Selection by rectangle or polygon. [ virtual protected ]
2798 void OCCViewer_ViewWindow::onSketchingFinished()
2800 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
2801 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
2803 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
2804 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
2805 switch( mypSketcher->type() )
2809 QRect* aRect = (QRect*)mypSketcher->data();
2812 int aLeft = aRect->left();
2813 int aRight = aRect->right();
2814 int aTop = aRect->top();
2815 int aBottom = aRect->bottom();
2819 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2821 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2827 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
2830 int size = aPolygon->size();
2831 TColgp_Array1OfPnt2d anArray( 1, size );
2833 QPolygon::Iterator it = aPolygon->begin();
2834 QPolygon::Iterator itEnd = aPolygon->end();
2835 for( int index = 1; it != itEnd; ++it, index++ )
2837 QPoint aPoint = *it;
2838 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
2842 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
2844 ic->Select( anArray, getViewPort()->getView(), Standard_False );
2852 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
2853 aViewMgr->getOCCViewer()->performSelectionChanged();
2857 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
2862 bool OCCViewer_ViewWindow::transformRequested() const
2864 return ( myOperation != NOTHING );
2867 bool OCCViewer_ViewWindow::transformInProcess() const
2869 return myEventStarted;
2872 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
2874 myEventStarted = bOn;
2878 Set enabled state of transformation (rotate, zoom, etc)
2880 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
2882 if ( id != NOTHING ) myStatus.insert( id, on );
2886 \return enabled state of transformation (rotate, zoom, etc)
2888 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
2890 return myStatus.contains( id ) ? myStatus[ id ] : true;
2893 void OCCViewer_ViewWindow::onMaximizedView()
2895 setMaximized(!isMaximized());
2898 void OCCViewer_ViewWindow::returnTo3dView()
2900 setReturnedTo3dView( true );
2903 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
2905 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
2906 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
2907 if ( !isVisible3dView )
2908 toolMgr()->show( ReturnTo3dViewId );
2910 toolMgr()->hide( ReturnTo3dViewId );
2911 if ( isVisible3dView ) emit returnedTo3d( );
2915 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
2917 QAction* anAction = toolMgr()->action( MaximizedId );
2918 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
2919 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
2921 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
2922 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
2923 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
2924 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
2925 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
2927 emit maximized( this, true );
2931 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
2932 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
2933 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
2934 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
2935 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
2937 emit maximized( this, false );
2942 bool OCCViewer_ViewWindow::isMaximized() const
2944 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
2947 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
2949 IsSketcherStyle = enable;
2952 bool OCCViewer_ViewWindow::isSketcherStyle() const
2954 return IsSketcherStyle;
2958 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
2963 int OCCViewer_ViewWindow::projectionType() const
2965 int mode = Orthographic;
2966 Handle(V3d_View) aView3d = myViewPort->getView();
2967 if ( !aView3d.IsNull() ) {
2968 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
2969 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Perspective)
2971 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Orthographic)
2972 mode = Orthographic;
2973 #if OCC_VERSION_LARGE > 0x06090000
2974 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
2981 void OCCViewer_ViewWindow::setStereoType( int type )
2983 Handle(V3d_View) aView3d = myViewPort->getView();
2984 if ( !aView3d.IsNull() ) {
2985 #if OCC_VERSION_LARGE > 0x06090000
2986 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
2987 aParams->StereoMode = (Graphic3d_StereoMode)type;
2992 int OCCViewer_ViewWindow::stereoType() const
2994 int type = QuadBuffer;
2995 Handle(V3d_View) aView3d = myViewPort->getView();
2996 if ( !aView3d.IsNull() ) {
2997 #if OCC_VERSION_LARGE > 0x06090000
2998 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
2999 type = (OCCViewer_ViewWindow::StereoType)aParams->StereoMode;
3005 void OCCViewer_ViewWindow::setAnaglyphFilter( int type )
3007 Handle(V3d_View) aView3d = myViewPort->getView();
3008 if ( !aView3d.IsNull() ) {
3009 #if OCC_VERSION_LARGE > 0x06090000
3010 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3011 if (type == RedCyan)
3012 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
3013 if (type == YellowBlue)
3014 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
3015 if (type == GreenMagenta)
3016 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
3021 int OCCViewer_ViewWindow::anaglyphFilter() const
3024 Handle(V3d_View) aView3d = myViewPort->getView();
3025 if ( !aView3d.IsNull() ) {
3026 #if OCC_VERSION_LARGE > 0x06090000
3027 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3028 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized)
3030 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized)
3032 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple)
3033 type = GreenMagenta;
3039 void OCCViewer_ViewWindow::setStereographicFocus( int type, double value )
3041 Handle(V3d_View) aView3d = myViewPort->getView();
3042 if ( !aView3d.IsNull() ) {
3043 #if OCC_VERSION_LARGE > 0x06090000
3044 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3045 aCamera->SetZFocus( (Graphic3d_Camera::FocusType) type, value );
3050 int OCCViewer_ViewWindow::stereographicFocusType() const
3052 int type = Relative;
3053 Handle(V3d_View) aView3d = myViewPort->getView();
3054 if ( !aView3d.IsNull() ) {
3055 #if OCC_VERSION_LARGE > 0x06090000
3056 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3057 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->ZFocusType();
3063 double OCCViewer_ViewWindow::stereographicFocusValue() const
3066 Handle(V3d_View) aView3d = myViewPort->getView();
3067 if ( !aView3d.IsNull() ) {
3068 #if OCC_VERSION_LARGE > 0x06090000
3069 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3070 value = aCamera->ZFocus();
3076 void OCCViewer_ViewWindow::setInterocularDistance( int type, double value )
3078 Handle(V3d_View) aView3d = myViewPort->getView();
3079 if ( !aView3d.IsNull() ) {
3080 #if OCC_VERSION_LARGE > 0x06090000
3081 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3082 aCamera->SetIOD( (Graphic3d_Camera::IODType) type, value );
3087 int OCCViewer_ViewWindow::interocularDistanceType() const
3089 int type = Relative;
3090 Handle(V3d_View) aView3d = myViewPort->getView();
3091 if ( !aView3d.IsNull() ) {
3092 #if OCC_VERSION_LARGE > 0x06090000
3093 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3094 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->GetIODType();
3100 double OCCViewer_ViewWindow::interocularDistanceValue() const
3102 double value = 0.05;
3103 Handle(V3d_View) aView3d = myViewPort->getView();
3104 if ( !aView3d.IsNull() ) {
3105 #if OCC_VERSION_LARGE > 0x06090000
3106 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3107 value = aCamera->IOD();
3113 void OCCViewer_ViewWindow::setReverseStereo( bool reverse )
3115 Handle(V3d_View) aView3d = myViewPort->getView();
3116 if ( !aView3d.IsNull() ) {
3117 #if OCC_VERSION_LARGE > 0x06090000
3118 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3119 aParams->ToReverseStereo = reverse;
3124 bool OCCViewer_ViewWindow::isReverseStereo() const
3126 int reverse = false;
3127 Handle(V3d_View) aView3d = myViewPort->getView();
3128 if ( !aView3d.IsNull() ) {
3129 #if OCC_VERSION_LARGE > 0x06090000
3130 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3131 reverse = aParams->ToReverseStereo;
3137 void OCCViewer_ViewWindow::setVSync( bool enable )
3139 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3140 if ( !anIntCont.IsNull() ) {
3141 #if OCC_VERSION_LARGE > 0x06090000
3142 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3143 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3144 aCaps->swapInterval = enable;
3149 bool OCCViewer_ViewWindow::isVSync() const
3152 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3153 if ( !anIntCont.IsNull() ) {
3154 #if OCC_VERSION_LARGE > 0x06090000
3155 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3156 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3157 enable = aCaps->swapInterval;
3163 void OCCViewer_ViewWindow::setQuadBufferSupport( bool enable )
3165 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3166 if ( !anIntCont.IsNull() ) {
3167 #if OCC_VERSION_LARGE > 0x06090000
3168 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3169 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3170 aCaps->contextStereo = enable;
3175 bool OCCViewer_ViewWindow::isQuadBufferSupport() const
3178 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3179 if ( !anIntCont.IsNull() ) {
3180 #if OCC_VERSION_LARGE > 0x06090000
3181 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3182 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3183 enable = aCaps->contextStereo;
3190 bool OCCViewer_ViewWindow::isOpenGlStereoSupport() const
3192 GLboolean support[1];
3193 glGetBooleanv (GL_STEREO, support);
3200 QColor OCCViewer_ViewWindow::backgroundColor() const
3202 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
3206 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
3208 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
3211 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
3213 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
3216 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
3218 if ( myViewPort ) myViewPort->setBackground( theBackground );
3221 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
3223 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
3229 void OCCViewer_ViewWindow::clearViewAspects()
3231 myViewAspects.clear();
3235 \return const reference to list of view aspects
3237 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
3239 return myViewAspects;
3243 Appends new view aspect
3244 \param aParams - new view aspects
3246 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
3248 myViewAspects.append( aParams );
3252 Replaces old view aspects by new ones
3253 \param aViewList - list of new view aspects
3255 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
3257 myViewAspects = aViewList;
3261 Get camera properties for the OCC view window.
3262 \return shared pointer on camera properties.
3264 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
3266 SUIT_CameraProperties aProps;
3268 Handle(V3d_View) aSourceView = getViewPort()->getView();
3269 if ( aSourceView.IsNull() )
3272 if ( get2dMode() == No2dMode ) {
3273 aProps.setDimension( SUIT_CameraProperties::Dim3D );
3276 aProps.setDimension( SUIT_CameraProperties::Dim2D );
3277 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
3280 // read common properites of the view
3281 Standard_Real anUp[3];
3282 Standard_Real anAt[3];
3283 Standard_Real anEye[3];
3284 Standard_Real aProj[3];
3285 Standard_Real anAxialScale[3];
3287 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
3288 aSourceView->At( anAt[0], anAt[1], anAt[2] );
3289 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
3290 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3292 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3293 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
3295 #if OCC_VERSION_LARGE > 0x06070100
3296 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
3298 // store camera properties "as is": it is up to synchronized
3299 // view classes to provide necessary property conversion.
3300 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
3301 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
3303 if ( aSourceView->Camera()->IsOrthographic() )
3305 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
3306 aProps.setViewAngle( 0.0 );
3310 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
3311 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
3313 aProps.setMappingScale( aSourceView->Camera()->Scale() );
3315 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
3317 // generate view orientation matrix for transforming OCC projection reference point
3318 // into a camera (eye) position.
3319 gp_Dir aLeftDir = gp_Dir( anUp[0], anUp[1], anUp[2] ) ^ gp_Dir( aProj[0], aProj[1], aProj[2] );
3322 aTrsf.SetValue( 1, 1, aLeftDir.X() );
3323 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
3324 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
3326 aTrsf.SetValue( 1, 2, anUp[0] );
3327 aTrsf.SetValue( 2, 2, anUp[1] );
3328 aTrsf.SetValue( 3, 2, anUp[2] );
3330 aTrsf.SetValue( 1, 3, aProj[0] );
3331 aTrsf.SetValue( 2, 3, aProj[1] );
3332 aTrsf.SetValue( 3, 3, aProj[2] );
3334 aTrsf.SetValue( 1, 4, anAt[0] );
3335 aTrsf.SetValue( 2, 4, anAt[1] );
3336 aTrsf.SetValue( 3, 4, anAt[2] );
3338 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
3340 // transform to world-space coordinate system
3341 gp_XYZ aPosition( aProjRef.X(), aProjRef.Y(), aCameraDepth );
3342 aTrsf.Transforms( aPosition );
3344 // compute focal point
3345 double aFocalPoint[3];
3347 aFocalPoint[0] = aPosition.X() - aProj[0] * aCameraDepth;
3348 aFocalPoint[1] = aPosition.Y() - aProj[1] * aCameraDepth;
3349 aFocalPoint[2] = aPosition.Z() - aProj[2] * aCameraDepth;
3351 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3352 aProps.setPosition( aPosition.X(), aPosition.Y(), aPosition.Z() );
3354 Standard_Real aViewScale[2];
3355 aSourceView->Size( aViewScale[0], aViewScale[1] );
3356 aProps.setMappingScale( aViewScale[1] );
3364 This implementation synchronizes OCC view's camera propreties.
3366 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
3368 bool blocked = blockSignals( true );
3370 SUIT_CameraProperties aProps = theView->cameraProperties();
3371 if ( !cameraProperties().isCompatible( aProps ) ) {
3372 // other view, this one is being currently synchronized to, seems has become incompatible
3373 // we have to break synchronization
3378 Handle(V3d_View) aDestView = getViewPort()->getView();
3380 aDestView->SetImmediateUpdate( Standard_False );
3383 double aPosition[3];
3384 double aFocalPoint[3];
3385 double anAxialScale[3];
3387 // get common properties
3388 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3389 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
3390 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3391 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3393 #if OCC_VERSION_LARGE > 0x06070100
3394 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3395 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
3396 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3397 aDestView->Camera()->SetScale( aProps.getMappingScale() );
3399 gp_Dir aProjDir( aPosition[0] - aFocalPoint[0],
3400 aPosition[1] - aFocalPoint[1],
3401 aPosition[2] - aFocalPoint[2] );
3403 // get custom view translation
3404 Standard_Real aTranslation[3];
3405 aDestView->At( aTranslation[0], aTranslation[1], aTranslation[2] );
3407 gp_Dir aLeftDir = gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] )
3408 ^ gp_Dir( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
3411 aTrsf.SetValue( 1, 1, aLeftDir.X() );
3412 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
3413 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
3415 aTrsf.SetValue( 1, 2, anUpDir[0] );
3416 aTrsf.SetValue( 2, 2, anUpDir[1] );
3417 aTrsf.SetValue( 3, 2, anUpDir[2] );
3419 aTrsf.SetValue( 1, 3, aProjDir.X() );
3420 aTrsf.SetValue( 2, 3, aProjDir.Y() );
3421 aTrsf.SetValue( 3, 3, aProjDir.Z() );
3423 aTrsf.SetValue( 1, 4, aTranslation[0] );
3424 aTrsf.SetValue( 2, 4, aTranslation[1] );
3425 aTrsf.SetValue( 3, 4, aTranslation[2] );
3428 // transform to view-space coordinate system
3429 gp_XYZ aProjRef( aPosition[0], aPosition[1], aPosition[2] );
3430 aTrsf.Transforms( aProjRef );
3432 // set view camera properties using low-level approach. this is done
3433 // in order to avoid interference with static variables in v3d view used
3434 // when rotation is in process in another view.
3435 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
3436 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
3438 Graphic3d_Vector aMappingProj( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
3439 Graphic3d_Vector aMappingUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3441 aMappingProj.Normalize();
3442 aMappingUp.Normalize();
3444 anOrientation.SetViewReferencePlane( aMappingProj );
3445 anOrientation.SetViewReferenceUp( aMappingUp );
3447 aDestView->SetViewMapping( aMapping );
3448 aDestView->SetViewOrientation( anOrientation );
3451 aDestView->SetCenter( aProjRef.X(), aProjRef.Y() );
3453 // set mapping scale
3454 double aMapScaling = aProps.getMappingScale();
3455 Standard_Real aWidth, aHeight;
3456 aDestView->Size( aWidth, aHeight );
3457 aDestView->SetSize ( aWidth > aHeight ? aMapScaling * (aWidth / aHeight) : aMapScaling );
3460 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3462 aDestView->ZFitAll();
3463 aDestView->SetImmediateUpdate( Standard_True );
3464 aDestView->Redraw();
3466 blockSignals( blocked );
3470 \brief Indicates whether preselection is enabled
3471 \return true if preselection is enabled
3473 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
3475 return myPreselectionEnabled;
3479 \brief Enables/disables preselection
3480 \param theIsToEnable if true - preselection will be enabled
3482 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
3484 onSwitchPreselection( theIsToEnable );
3488 \brief Indicates whether selection is enabled
3489 \return true if selection is enabled
3491 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3493 return mySelectionEnabled;
3497 \brief Enables/disables selection
3498 \param theIsToEnable if true - selection will be enabled
3500 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3502 onSwitchSelection( theIsToEnable );
3507 \brief called if clipping operation is activated / deactivated.
3509 Enables/disables clipping plane displaying.
3511 \parma on action state
3513 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3515 if(!myModel) return;
3516 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3519 if (!aClippingDlg) {
3520 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3521 myModel->setClippingDlg(aClippingDlg);
3523 if (!aClippingDlg->isVisible())
3524 aClippingDlg->show();
3526 if ( aClippingDlg ) {
3527 aClippingDlg->close();
3528 myModel->setClippingDlg(0);
3532 SUIT_ViewManager* mgr = getViewManager();
3534 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3535 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3536 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3537 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3539 QAction* a = toolMgr()->action( ClippingId );
3541 if(theIsOn != a->isChecked()){
3542 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3543 a->setChecked(theIsOn);
3544 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));