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() || !aStructure->IsVisible() || aStructure->CStructure()->IsForHighlight )
680 #if OCC_VERSION_LARGE > 0x06070100
681 Bnd_Box aBox = aStructure->MinMaxValues();
682 aXmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().X();
683 aYmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Y();
684 aZmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Z();
685 aXmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().X();
686 aYmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Y();
687 aZmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Z();
689 aStructure->MinMaxValues( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
692 // Infinite structures are skipped
693 Standard_Real aLIM = ShortRealLast() - 1.0;
694 if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
695 || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
699 gp_Pnt aPoints[8] = {
700 gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
701 gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
702 gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
703 gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
706 for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
707 const gp_Pnt& aBBPoint = aPoints[aPointIt];
709 #if OCC_VERSION_LARGE > 0x06070100
710 gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
711 const Standard_Real& U = aProjected.X();
712 const Standard_Real& V = aProjected.Y();
714 Standard_Real U = 0.0;
715 Standard_Real V = 0.0;
716 Standard_Real W = 0.0;
717 aView3d->View()->Projects( aBBPoint.X(), aBBPoint.Y(), aBBPoint.Z(), U, V, W );
720 if (U >= aScreenLimits[0]
721 && U <= aScreenLimits[1]
722 && V >= aScreenLimits[2]
723 && V <= aScreenLimits[3])
726 theX += aBBPoint.X();
727 theY += aBBPoint.Y();
728 theZ += aBBPoint.Z();
743 \brief Set the gravity center as a rotation point.
745 void OCCViewer_ViewWindow::activateSetRotationGravity()
747 if ( myRotationPointSelection )
749 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
750 ic->CloseAllContexts();
751 myOperation = NOTHING;
752 myViewPort->setCursor( myCursor );
753 myCursorIsHand = false;
754 myRotationPointSelection = false;
757 myPrevPointType = myCurrPointType;
758 myCurrPointType = GRAVITY;
760 Standard_Real Xcenter, Ycenter, Zcenter;
761 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
762 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
766 \brief Update gravity center in the "Set Rotation Point" dialog box.
767 \sa OCCViewer_SetRotationPointDlg class
769 void OCCViewer_ViewWindow::updateGravityCoords()
771 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == GRAVITY )
773 Standard_Real Xcenter, Ycenter, Zcenter;
774 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
775 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
780 \brief Set the point selected by the user as a rotation point.
781 \param theX X coordinate of the rotation point
782 \param theY Y coordinate of the rotation point
783 \param theZ Z coordinate of the rotation point
785 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
787 if ( myRotationPointSelection )
789 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
790 ic->CloseAllContexts();
791 myOperation = NOTHING;
792 myViewPort->setCursor( myCursor );
793 myCursorIsHand = false;
794 myRotationPointSelection = false;
797 myPrevPointType = myCurrPointType;
798 myCurrPointType = SELECTED;
799 mySelectedPoint.SetCoord(theX,theY,theZ);
803 \brief Start the shape selection process.
805 void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
807 myPrevPointType = myCurrPointType;
808 myCurrPointType = SELECTED;
810 // activate selection ------>
811 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
813 ic->OpenLocalContext();
815 AIS_ListOfInteractive aList;
816 ic->DisplayedObjects( aList );
817 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
819 Handle(AIS_InteractiveObject) anObj = it.Value();
820 if ( !anObj.IsNull() && anObj->HasPresentation() &&
821 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
824 ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
827 // activate selection <------
829 if ( !myCursorIsHand )
831 QCursor handCursor (Qt::PointingHandCursor);
832 myCursorIsHand = true;
834 myViewPort->setCursor( handCursor );
836 myRotationPointSelection = true;
840 \brief Start global panning operation
842 Sets the corresponding cursor for the widget.
844 void OCCViewer_ViewWindow::activateGlobalPanning()
846 Handle(V3d_View) aView3d = myViewPort->getView();
847 if ( !aView3d.IsNull() ) {
848 QPixmap globalPanPixmap (imageCrossCursor);
849 QCursor glPanCursor (globalPanPixmap);
850 myCurScale = aView3d->Scale();
851 aView3d->FitAll(0.01, false);
852 saveCursor(); // save old cursor
853 myViewPort->fitAll(); // fits view before selecting a new scene center
854 if( setTransformRequested( PANGLOBAL ) )
855 myViewPort->setCursor( glPanCursor );
860 \brief Starts fit operation.
862 Sets the corresponding cursor for the widget.
864 void OCCViewer_ViewWindow::activateWindowFit()
866 if ( !transformRequested() && !myCursorIsHand )
867 saveCursor(); /* save old cursor */
869 if ( myOperation != WINDOWFIT ) {
870 QCursor handCursor (Qt::PointingHandCursor);
871 if( setTransformRequested ( WINDOWFIT ) )
873 myViewPort->setCursor ( handCursor );
874 myCursorIsHand = true;
880 \brief Start delayed viewer operation.
882 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
884 bool ok = transformEnabled( op );
885 myOperation = ok ? op : NOTHING;
886 myViewPort->setMouseTracking( myOperation == NOTHING );
891 \brief Handle mouse move event.
892 \param theEvent mouse event
894 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
896 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
898 switch ( getButtonState( theEvent, interactionStyle() ) ) {
900 myViewPort->startZoomAtPoint( myStartX, myStartY );
908 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
915 myCurrX = theEvent->x();
916 myCurrY = theEvent->y();
917 switch (myOperation) {
919 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
923 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
929 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
943 if ( myRotationPointSelection || isSketcherStyle() )
945 emit mouseMoving( this, theEvent );
949 int aState = theEvent->modifiers();
950 int aButton = theEvent->buttons();
951 int anInteractionStyle = interactionStyle();
952 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
953 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
954 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
955 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
956 myDrawRect = myEnableDrawMode;
959 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
960 QCursor handCursor (Qt::PointingHandCursor);
961 myCursorIsHand = true;
963 myViewPort->setCursor( handCursor );
966 emit mouseMoving( this, theEvent );
968 else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
969 aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
970 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
971 aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
972 OCCViewer_ViewSketcher* sketcher = 0;
973 QList<OCCViewer_ViewSketcher*>::Iterator it;
974 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
976 OCCViewer_ViewSketcher* sk = (*it);
977 if( sk->isDefault() && sk->sketchButton() == aButton )
980 if ( sketcher && myCurSketch == -1 )
982 activateSketching( sketcher->type() );
985 myCurSketch = mypSketcher->sketchButton();
987 if ( l_mbPressEvent )
989 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
990 delete l_mbPressEvent;
993 QApplication::sendEvent( getViewPort(), theEvent );
998 emit mouseMoving( this, theEvent );
1004 \brief Handle mouse release event.
1005 \param theEvent mouse event
1007 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
1009 switch ( myOperation ) {
1012 int prevState = myCurSketch;
1013 if(theEvent->button() == Qt::RightButton)
1015 QList<OCCViewer_ViewSketcher*>::Iterator it;
1016 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
1018 OCCViewer_ViewSketcher* sk = (*it);
1019 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
1024 emit mouseReleased(this, theEvent);
1025 if(theEvent->button() == Qt::RightButton && prevState == -1)
1027 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1028 theEvent->pos(), theEvent->globalPos() );
1029 emit contextMenuRequested( &aEvent );
1034 myViewPort->endRotation();
1040 myViewPort->getView()->ZFitAll();
1045 if ( theEvent->button() == Qt::LeftButton ) {
1046 myViewPort->setCenter( theEvent->x(), theEvent->y() );
1047 myViewPort->getView()->SetScale(myCurScale);
1053 if ( theEvent->button() == Qt::LeftButton ) {
1054 myCurrX = theEvent->x();
1055 myCurrY = theEvent->y();
1057 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1058 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1065 // NOTE: viewer 3D detects a rectangle of selection using this event
1066 // so we must emit it BEFORE resetting the selection rectangle
1068 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1072 myViewPort->update();
1075 if ( l_mbPressEvent )
1077 delete l_mbPressEvent;
1083 \brief Reset the viewport to its initial state
1084 ( no transformations in process etc. )
1086 void OCCViewer_ViewWindow::resetState()
1090 if ( myRotationPointSelection )
1092 QCursor handCursor (Qt::PointingHandCursor);
1093 myViewPort->setCursor( handCursor );
1097 if ( transformRequested() || myCursorIsHand )
1098 myViewPort->setCursor( myCursor );
1099 myCursorIsHand = false;
1102 if ( transformRequested() )
1103 emit vpTransformationFinished (myOperation);
1105 setTransformInProcess( false );
1106 setTransformRequested( NOTHING );
1111 \brief Draw rubber band rectangle.
1113 void OCCViewer_ViewWindow::drawRect()
1115 if ( !myRectBand ) {
1116 myRectBand = new QtxRectRubberBand( myViewPort );
1118 //palette.setColor(myRectBand->foregroundRole(), Qt::white);
1119 //myRectBand->setPalette(palette);
1121 //myRectBand->hide();
1123 myRectBand->setUpdatesEnabled ( false );
1124 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1125 myRectBand->initGeometry( aRect );
1127 if ( !myRectBand->isVisible() )
1130 myRectBand->setUpdatesEnabled ( true );
1131 //myRectBand->repaint();
1133 //myRectBand->setVisible( aRect.isValid() );
1134 //if ( myRectBand->isVisible() )
1135 // myRectBand->repaint();
1137 // myRectBand->show();
1138 //myRectBand->repaint();
1142 \brief Clear rubber band rectangle on the end on the dragging operation.
1144 void OCCViewer_ViewWindow::endDrawRect()
1146 //delete myRectBand;
1150 myRectBand->clearGeometry();
1156 \brief Create actions.
1158 void OCCViewer_ViewWindow::createActions()
1160 if( !toolMgr()->isEmpty() )
1163 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1168 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1169 tr( "MNU_DUMP_VIEW" ), 0, this);
1170 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1171 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1172 toolMgr()->registerAction( aAction, DumpId );
1175 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1176 tr( "MNU_FITALL" ), 0, this);
1177 aAction->setStatusTip(tr("DSC_FITALL"));
1178 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1179 toolMgr()->registerAction( aAction, FitAllId );
1182 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1183 tr( "MNU_FITRECT" ), 0, this);
1184 aAction->setStatusTip(tr("DSC_FITRECT"));
1185 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1186 toolMgr()->registerAction( aAction, FitRectId );
1189 aAction = new QtxAction(tr("MNU_FITSELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITSELECTION" ) ),
1190 tr( "MNU_FITSELECTION" ), 0, this);
1191 aAction->setStatusTip(tr("DSC_FITSELECTION"));
1192 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
1193 toolMgr()->registerAction( aAction, FitSelectionId );
1196 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1197 tr( "MNU_ZOOM_VIEW" ), 0, this);
1198 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1199 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1200 toolMgr()->registerAction( aAction, ZoomId );
1203 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1204 tr( "MNU_PAN_VIEW" ), 0, this);
1205 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1206 connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
1207 toolMgr()->registerAction( aAction, PanId );
1210 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1211 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1212 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1213 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1214 toolMgr()->registerAction( aAction, GlobalPanId );
1217 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1218 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1219 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1220 mySetRotationPointAction->setCheckable( true );
1221 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1222 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1225 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1226 tr( "MNU_ROTATE_VIEW" ), 0, this);
1227 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1228 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1229 toolMgr()->registerAction( aAction, RotationId );
1232 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1233 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1234 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1235 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1236 this->addAction(aAction);
1237 toolMgr()->registerAction( aAction, FrontId );
1239 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1240 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1241 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1242 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1243 this->addAction(aAction);
1244 toolMgr()->registerAction( aAction, BackId );
1246 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1247 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1248 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1249 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1250 this->addAction(aAction);
1251 toolMgr()->registerAction( aAction, TopId );
1253 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1254 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1255 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1256 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1257 this->addAction(aAction);
1258 toolMgr()->registerAction( aAction, BottomId );
1260 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1261 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1262 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1263 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1264 this->addAction(aAction);
1265 toolMgr()->registerAction( aAction, LeftId );
1267 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1268 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1269 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1270 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1271 this->addAction(aAction);
1272 toolMgr()->registerAction( aAction, RightId );
1274 // rotate anticlockwise
1275 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1276 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1277 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1278 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1279 this->addAction(aAction);
1280 toolMgr()->registerAction( aAction, AntiClockWiseId );
1283 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1284 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1285 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1286 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1287 this->addAction(aAction);
1288 toolMgr()->registerAction( aAction, ClockWiseId );
1290 // Projection mode group
1292 // - orthographic projection
1293 aAction = new QtxAction(tr("MNU_ORTHOGRAPHIC_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ORTHOGRAPHIC" ) ),
1294 tr( "MNU_ORTHOGRAPHIC_MODE" ), 0, this);
1295 aAction->setStatusTip(tr("DSC_ORTHOGRAPHIC_MODE"));
1296 aAction->setCheckable(true);
1297 toolMgr()->registerAction( aAction, OrthographicId );
1299 // - perspective projection
1300 aAction = new QtxAction(tr("MNU_PERSPECTIVE_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PERSPECTIVE" ) ),
1301 tr( "MNU_PERSPECTIVE_MODE" ), 0, this);
1302 aAction->setStatusTip(tr("DSC_PERSPECTIVE_MODE"));
1303 aAction->setCheckable(true);
1304 toolMgr()->registerAction( aAction, PerspectiveId );
1305 #if OCC_VERSION_LARGE > 0x06090000
1306 // - stereo projection
1307 aAction = new QtxAction(tr("MNU_STEREO_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STEREO" ) ),
1308 tr( "MNU_STEREO_MODE" ), 0, this);
1309 aAction->setStatusTip(tr("DSC_STEREO_MODE"));
1310 aAction->setCheckable(true);
1311 toolMgr()->registerAction( aAction, StereoId );
1312 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onStereoType(bool)));
1314 // - add exclusive action group
1315 QActionGroup* aProjectionGroup = new QActionGroup( this );
1316 aProjectionGroup->addAction( toolMgr()->action( OrthographicId ) );
1317 aProjectionGroup->addAction( toolMgr()->action( PerspectiveId ) );
1318 connect(aProjectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProjectionType(QAction*)));
1321 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1322 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1323 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1324 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1325 this->addAction(aAction);
1326 toolMgr()->registerAction( aAction, ResetId );
1329 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1330 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1331 tr("MNU_CLONE_VIEW"), 0, this);
1332 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1333 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1334 toolMgr()->registerAction( aAction, CloneId );
1336 aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
1337 tr("MNU_CLIPPING"), 0, this);
1338 aAction->setStatusTip (tr("DSC_CLIPPING"));
1339 aAction->setCheckable (true);
1340 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1341 toolMgr()->registerAction (aAction, ClippingId);
1343 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1344 tr( "MNU_SHOOT_VIEW" ), 0, this);
1345 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1346 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1347 toolMgr()->registerAction( aAction, MemId );
1349 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1350 tr( "MNU_PRESETS_VIEW" ), 0, this);
1351 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1352 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1353 toolMgr()->registerAction( aAction, RestoreId );
1355 if (myModel->trihedronActivated()) {
1356 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1357 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1358 aAction->setCheckable( true );
1359 aAction->setChecked( true );
1360 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1361 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1362 toolMgr()->registerAction( aAction, TrihedronShowId );
1366 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1367 tr( "MNU_SCALING" ), 0, this);
1368 aAction->setStatusTip(tr("DSC_SCALING"));
1369 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1370 toolMgr()->registerAction( aAction, AxialScaleId );
1372 // Enable/disable preselection
1373 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1374 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1375 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1376 aAction->setCheckable(true);
1377 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1378 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1380 // Enable/disable selection
1381 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1382 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1383 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1384 aAction->setCheckable(true);
1385 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1386 toolMgr()->registerAction( aAction, SwitchSelectionId );
1389 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1390 tr( "MNU_GRADUATED_AXES" ), 0, this);
1391 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1392 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1393 toolMgr()->registerAction( aAction, GraduatedAxesId );
1395 // Active only ambient light or not
1396 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1397 tr( "MNU_AMBIENT" ), 0, this);
1398 aAction->setStatusTip(tr("DSC_AMBIENT"));
1399 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1400 toolMgr()->registerAction( aAction, AmbientId );
1402 // Switch between interaction styles
1403 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1404 tr( "MNU_STYLE_SWITCH" ), 0, this);
1405 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1406 aAction->setCheckable(true);
1407 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1408 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1410 // Switch between zooming styles
1411 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1412 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1413 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1414 aAction->setCheckable(true);
1415 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1416 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1419 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1420 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1421 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1422 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1423 toolMgr()->registerAction( aAction, MaximizedId );
1425 // Return to 3d view
1426 if (my2dMode!=No2dMode){
1427 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1428 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1429 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1430 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1431 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1435 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1439 \brief Create toolbar.
1441 void OCCViewer_ViewWindow::createToolBar()
1443 static const char* titles[] = {
1444 "LBL_3DTOOLBAR_LABEL",
1445 "LBL_XYTOOLBAR_LABEL",
1446 "LBL_XZTOOLBAR_LABEL",
1447 "LBL_YZTOOLBAR_LABEL",
1449 static const char* names[] = {
1450 "OCCViewer3DViewOperations",
1451 "OCCViewerXYViewOperations",
1452 "OCCViewerXZViewOperations",
1453 "OCCViewerYZViewOperations",
1455 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1456 QString( names[my2dMode] ), // name (language-independant)
1457 false ); // disable floatable toolbar
1458 if ( my2dMode != No2dMode ){
1459 toolMgr()->append( ReturnTo3dViewId, tid );
1460 toolMgr()->append( toolMgr()->separator(), tid );
1462 toolMgr()->append( DumpId, tid );
1463 toolMgr()->append( SwitchInteractionStyleId, tid );
1464 toolMgr()->append( SwitchZoomingStyleId, tid );
1465 toolMgr()->append( SwitchPreselectionId, tid );
1466 toolMgr()->append( SwitchSelectionId, tid );
1467 if( myModel->trihedronActivated() )
1468 toolMgr()->append( TrihedronShowId, tid );
1470 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1471 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1472 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1473 #if OCC_VERSION_LARGE > 0x06090000
1474 aScaleAction->insertAction( toolMgr()->action( FitSelectionId ) );
1476 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1477 toolMgr()->append( aScaleAction, tid );
1479 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1480 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1481 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1482 toolMgr()->append( aPanningAction, tid );
1484 if (my2dMode == No2dMode) {
1485 toolMgr()->append( ChangeRotationPointId, tid );
1486 toolMgr()->append( RotationId, tid );
1488 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1489 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1490 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1491 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1492 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1493 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1494 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1495 toolMgr()->append( aViewsAction, tid );
1497 toolMgr()->append( AntiClockWiseId, tid );
1498 toolMgr()->append( ClockWiseId, tid );
1500 toolMgr()->append( OrthographicId, tid );
1501 toolMgr()->append( PerspectiveId, tid );
1502 #if OCC_VERSION_LARGE > 0x06090000
1503 toolMgr()->append( StereoId, tid );
1506 toolMgr()->append( ResetId, tid );
1509 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1510 aMemAction->insertAction( toolMgr()->action( MemId ) );
1511 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1512 toolMgr()->append( aMemAction, tid );
1514 toolMgr()->append( toolMgr()->separator(), tid );
1515 toolMgr()->append( CloneId, tid );
1517 toolMgr()->append( toolMgr()->separator(), tid );
1518 toolMgr()->append( ClippingId, tid );
1519 toolMgr()->append( AxialScaleId, tid );
1520 toolMgr()->append( GraduatedAxesId, tid );
1521 toolMgr()->append( AmbientId, tid );
1523 toolMgr()->append( MaximizedId, tid );
1524 toolMgr()->append( SynchronizeId, tid );
1528 \brief Perform 'fit all' operation.
1530 void OCCViewer_ViewWindow::onViewFitAll()
1532 myViewPort->fitAll();
1536 \brief Perform "front view" transformation.
1538 void OCCViewer_ViewWindow::onFrontView()
1540 emit vpTransformationStarted ( FRONTVIEW );
1541 Handle(V3d_View) aView3d = myViewPort->getView();
1542 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
1544 emit vpTransformationFinished ( FRONTVIEW );
1548 \brief Perform "back view" transformation.
1550 void OCCViewer_ViewWindow::onBackView()
1552 emit vpTransformationStarted ( BACKVIEW );
1553 Handle(V3d_View) aView3d = myViewPort->getView();
1554 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
1556 emit vpTransformationFinished ( BACKVIEW );
1560 \brief Perform "top view" transformation.
1562 void OCCViewer_ViewWindow::onTopView()
1564 emit vpTransformationStarted ( TOPVIEW );
1565 Handle(V3d_View) aView3d = myViewPort->getView();
1566 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
1568 emit vpTransformationFinished ( TOPVIEW );
1572 \brief Perform "bottom view" transformation.
1574 void OCCViewer_ViewWindow::onBottomView()
1576 emit vpTransformationStarted ( BOTTOMVIEW );
1577 Handle(V3d_View) aView3d = myViewPort->getView();
1578 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
1580 emit vpTransformationFinished ( BOTTOMVIEW );
1584 \brief Perform "left view" transformation.
1586 void OCCViewer_ViewWindow::onLeftView()
1588 emit vpTransformationStarted ( LEFTVIEW );
1589 Handle(V3d_View) aView3d = myViewPort->getView();
1590 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
1592 emit vpTransformationFinished ( LEFTVIEW );
1596 \brief Perform "right view" transformation.
1598 void OCCViewer_ViewWindow::onRightView()
1600 emit vpTransformationStarted ( RIGHTVIEW );
1601 Handle(V3d_View) aView3d = myViewPort->getView();
1602 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
1604 emit vpTransformationFinished ( RIGHTVIEW );
1608 \brief Rotate view 90 degrees clockwise
1610 void OCCViewer_ViewWindow::onClockWiseView()
1612 emit vpTransformationStarted ( CLOCKWISEVIEW );
1613 myViewPort->rotateXY( 90. );
1614 emit vpTransformationFinished ( CLOCKWISEVIEW );
1618 \brief Rotate view 90 degrees conterclockwise
1620 void OCCViewer_ViewWindow::onAntiClockWiseView()
1622 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1623 myViewPort->rotateXY( -90. );
1624 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1628 \brief Perform "reset view" transformation.
1630 Sets default orientation of the viewport camera.
1632 void OCCViewer_ViewWindow::onResetView()
1634 emit vpTransformationStarted( RESETVIEW );
1635 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1636 myViewPort->getView()->Reset( false );
1637 myViewPort->fitAll( false, true, false );
1638 myViewPort->getView()->SetImmediateUpdate( upd );
1639 onProjectionType(); // needed to apply projection type properly after reset
1640 myViewPort->getView()->Update();
1641 emit vpTransformationFinished( RESETVIEW );
1645 \brief Set the given projection mode.
1647 Set the given projection mode: Orthographic or Perspective.
1649 void OCCViewer_ViewWindow::onProjectionType( QAction* theAction )
1651 Handle(V3d_View) aView3d = myViewPort->getView();
1652 if ( !aView3d.IsNull() ) {
1653 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1654 if (theAction == toolMgr()->action( OrthographicId )) {
1655 myModel->setProjectionType(Orthographic);
1656 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Orthographic );
1657 aCamera->SetFOVy(45.0);
1659 else if (theAction == toolMgr()->action( PerspectiveId )) {
1660 myModel->setProjectionType(Perspective);
1661 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Perspective );
1662 aCamera->SetFOVy(30.0);
1664 #if OCC_VERSION_LARGE > 0x06090000
1665 if (toolMgr()->action( StereoId )->isChecked()) {
1666 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1667 aCamera->SetFOVy(30.0);
1676 \brief Sets Stereo projection mode.
1678 Sets Stereo projection mode.
1680 void OCCViewer_ViewWindow::onStereoType( bool activate )
1682 #if OCC_VERSION_LARGE > 0x06090000
1683 Handle(V3d_View) aView3d = myViewPort->getView();
1684 if ( !aView3d.IsNull() ) {
1685 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1687 toolMgr()->action( PerspectiveId )->setChecked(true);
1688 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1689 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(false);
1691 aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1692 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1693 setStereoType( aResMgr->integerValue( "OCCViewer", "stereo_type", 0 ) );
1694 setAnaglyphFilter( aResMgr->integerValue( "OCCViewer", "anaglyph_filter", 0 ) );
1695 setReverseStereo( aResMgr->booleanValue( "OCCViewer", "reverse_stereo", false ) );
1696 setVSync( aResMgr->booleanValue( "OCCViewer", "enable_vsync", true ) );
1697 setQuadBufferSupport( aResMgr->booleanValue( "OCCViewer", "enable_quad_buffer_support", false ) );
1700 toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(true);
1701 if (myModel->projectionType() == Orthographic) {
1702 toolMgr()->action( OrthographicId )->setChecked(true);
1703 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Orthographic);
1705 else if (myModel->projectionType() == Perspective) {
1706 toolMgr()->action( PerspectiveId )->setChecked(true);
1707 aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1714 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1715 toolMgr()->action( StereoId )->isChecked() )
1716 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1721 \brief Restore the view.
1723 Restore the projection mode based on tool-buttons states.
1725 void OCCViewer_ViewWindow::onProjectionType()
1727 emit vpTransformationStarted( PROJECTION );
1728 if (toolMgr()->action( OrthographicId )->isChecked())
1729 setProjectionType( Orthographic );
1730 if (toolMgr()->action( PerspectiveId )->isChecked())
1731 setProjectionType( Perspective );
1732 #if OCC_VERSION_LARGE > 0x06090000
1733 if (toolMgr()->action( StereoId )->isChecked())
1734 setProjectionType( Stereo );
1736 emit vpTransformationFinished( PROJECTION );
1739 void OCCViewer_ViewWindow::setProjectionType( int mode )
1741 QtxAction* anOrthographicAction = dynamic_cast<QtxAction*>( toolMgr()->action( OrthographicId ) );
1742 QtxAction* aPerspectiveAction = dynamic_cast<QtxAction*>( toolMgr()->action( PerspectiveId ) );
1743 #if OCC_VERSION_LARGE > 0x06090000
1744 QtxAction* aStereoAction = dynamic_cast<QtxAction*>( toolMgr()->action( StereoId ) );
1748 onProjectionType( anOrthographicAction );
1751 onProjectionType( aPerspectiveAction );
1754 onStereoType( true );
1757 // update action state if method is called outside
1758 if ( mode == Orthographic && !anOrthographicAction->isChecked() ) {
1759 anOrthographicAction->setChecked( true );
1760 #if OCC_VERSION_LARGE > 0x06090000
1761 aStereoAction->setChecked( false );
1764 if ( mode == Perspective && !aPerspectiveAction->isChecked() ) {
1765 aPerspectiveAction->setChecked( true );
1766 #if OCC_VERSION_LARGE > 0x06090000
1767 aStereoAction->setChecked( false );
1770 #if OCC_VERSION_LARGE > 0x06090000
1771 if ( mode == Stereo ) {
1772 aStereoAction->setChecked( true );
1773 if ( anOrthographicAction->isEnabled() ) {
1774 anOrthographicAction->setEnabled( false );
1775 anOrthographicAction->setChecked( false );
1776 aStereoAction->setChecked( false );
1779 anOrthographicAction->setEnabled( true );
1780 aStereoAction->setChecked( false );
1781 anOrthographicAction->setChecked(myModel->projectionType() == Orthographic);
1783 if ( aPerspectiveAction->isEnabled() ) {
1784 aPerspectiveAction->setEnabled( false );
1785 aPerspectiveAction->setChecked( true );
1786 if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1787 toolMgr()->action( StereoId )->isChecked() )
1788 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1791 aPerspectiveAction->setEnabled( true );
1792 aStereoAction->setChecked( false );
1793 aPerspectiveAction->setChecked(myModel->projectionType() == Perspective);
1798 if ( !anOrthographicAction->isEnabled() )
1799 anOrthographicAction->setEnabled( true );
1800 if ( !aPerspectiveAction->isEnabled() )
1801 aPerspectiveAction->setEnabled( true );
1807 \brief Perform "fit all" transformation.
1809 void OCCViewer_ViewWindow::onFitAll()
1811 emit vpTransformationStarted( FITALLVIEW );
1812 myViewPort->fitAll();
1813 emit vpTransformationFinished( FITALLVIEW );
1817 \brief Perform "fit selection" transformation.
1819 void OCCViewer_ViewWindow::onFitSelection()
1821 emit vpTransformationStarted( FITSELECTION );
1822 #if OCC_VERSION_LARGE > 0x06090000
1823 myModel->getAISContext()->FitSelected( getViewPort()->getView() );
1825 emit vpTransformationFinished( FITSELECTION );
1829 \brief Called if 'change rotation point' operation is activated.
1830 \param on action state
1832 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1836 if (!mySetRotationPointDlg)
1838 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1839 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1842 if (!mySetRotationPointDlg->isVisible())
1844 //if (mySetRotationPointDlg->IsFirstShown())
1845 if (myCurrPointType == GRAVITY)
1847 Standard_Real Xcenter, Ycenter, Zcenter;
1848 if (computeGravityCenter(Xcenter, Ycenter, Zcenter))
1849 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1851 mySetRotationPointDlg->show();
1856 if (mySetRotationPointDlg->isVisible())
1857 mySetRotationPointDlg->hide();
1862 \brief Create one more window with same content.
1864 void OCCViewer_ViewWindow::onCloneView()
1866 SUIT_ViewWindow* vw = myManager->createViewWindow();
1868 emit viewCloned( vw );
1872 Creates one more window with same content
1874 void OCCViewer_ViewWindow::onAxialScale()
1876 if ( !myScalingDlg )
1877 myScalingDlg = new OCCViewer_AxialScaleDlg( this );
1879 if ( !myScalingDlg->isVisible() )
1881 myScalingDlg->Update();
1882 myScalingDlg->show();
1887 Shows Graduated Axes dialog
1889 void OCCViewer_ViewWindow::onGraduatedAxes()
1891 myCubeAxesDlg->Update();
1892 myCubeAxesDlg->show();
1895 void OCCViewer_ViewWindow::onAmbientToogle()
1897 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
1898 viewer->InitDefinedLights();
1899 while(viewer->MoreDefinedLights())
1901 Handle(V3d_Light) light = viewer->DefinedLight();
1902 if(light->Type() != V3d_AMBIENT)
1904 Handle(V3d_View) aView3d = myViewPort->getView();
1905 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
1906 else viewer->SetLightOn(light);
1908 viewer->NextDefinedLights();
1914 \brief Store view parameters.
1916 void OCCViewer_ViewWindow::onMemorizeView()
1918 appendViewAspect( getViewParams() );
1922 \brief Restore view parameters.
1924 void OCCViewer_ViewWindow::onRestoreView()
1926 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
1927 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
1929 updateViewAspects( aDlg->parameters() );
1930 if( myRestoreFlag && aDlg->parameters().count() )
1931 performRestoring( aDlg->currentItem() );
1935 \brief Restore view parameters.
1936 \param anItem view parameters
1938 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
1940 Handle(V3d_View) aView3d = myViewPort->getView();
1942 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
1943 aView3d->SetScale( anItem.scale );
1944 aView3d->SetTwist( anItem.twist );
1945 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
1946 aView3d->SetImmediateUpdate( prev );
1947 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1948 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1949 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
1951 #if OCC_VERSION_LARGE > 0x06070100
1952 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
1954 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
1956 // "eye" and "at" require conversion to represent center panning
1957 // up direction is only available after setting angle of twist and
1958 // other view parameters
1959 aView3d->Up( anUpX, anUpY, anUpZ );
1961 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
1962 gp_Dir anUp( anUpX, anUpY, anUpZ );
1963 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
1964 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1965 gp_Dir aSide = aProj ^ anUp;
1967 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
1968 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
1970 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
1971 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1974 aView3d->SetCenter( anItem.centerX, anItem.centerY );
1977 if ( !baseParamsOnly ) {
1979 myModel->setTrihedronShown( anItem.isVisible );
1980 myModel->setTrihedronSize( anItem.size );
1982 // graduated trihedron
1983 bool anIsVisible = anItem.gtIsVisible;
1984 OCCViewer_AxisWidget::AxisData anAxisData[3];
1985 anAxisData[0].DrawName = anItem.gtDrawNameX;
1986 anAxisData[1].DrawName = anItem.gtDrawNameZ;
1987 anAxisData[2].DrawName = anItem.gtDrawNameZ;
1988 anAxisData[0].Name = anItem.gtNameX;
1989 anAxisData[1].Name = anItem.gtNameZ;
1990 anAxisData[2].Name = anItem.gtNameZ;
1991 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
1992 anItem.gtNameColorGX,
1993 anItem.gtNameColorBX );
1994 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
1995 anItem.gtNameColorGY,
1996 anItem.gtNameColorBY );
1997 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
1998 anItem.gtNameColorGZ,
1999 anItem.gtNameColorBZ );
2000 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
2001 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
2002 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
2003 anAxisData[0].NbValues = anItem.gtNbValuesX;
2004 anAxisData[1].NbValues = anItem.gtNbValuesY;
2005 anAxisData[2].NbValues = anItem.gtNbValuesZ;
2006 anAxisData[0].Offset = anItem.gtOffsetX;
2007 anAxisData[1].Offset = anItem.gtOffsetY;
2008 anAxisData[2].Offset = anItem.gtOffsetZ;
2009 anAxisData[0].Color = QColor( anItem.gtColorRX,
2012 anAxisData[1].Color = QColor( anItem.gtColorRY,
2015 anAxisData[2].Color = QColor( anItem.gtColorRZ,
2018 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
2019 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
2020 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
2021 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
2022 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
2023 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
2025 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
2026 myCubeAxesDlg->ApplyData( aView3d );
2028 } // if ( !baseParamsOnly )
2034 \brief Set restore flag.
2036 void OCCViewer_ViewWindow::setRestoreFlag()
2042 \brief Called when action "show/hide trihedron" is activated.
2044 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
2046 myModel->setTrihedronShown(show);
2050 \brief Toggles preselection (highlighting) on/off
2052 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
2054 myPreselectionEnabled = on;
2055 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
2057 // unhighlight all highlighted objects
2059 myModel->unHighlightAll( true, false );
2062 // update action state if method is called outside
2063 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2064 if ( a && a->isChecked() != on ) {
2065 a->setChecked( on );
2070 \brief Toggles selection on/off
2072 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
2074 mySelectionEnabled = on;
2075 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
2077 // update action state if method is called outside
2080 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2082 a->setEnabled( on );
2086 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
2087 if ( a && a->isChecked() != on ) {
2088 a->setChecked( on );
2093 \brief Switches "keyboard free" interaction style on/off
2095 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
2097 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
2099 // update action state if method is called outside
2100 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
2101 if ( a->isChecked() != on )
2102 a->setChecked( on );
2106 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
2108 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
2110 myViewPort->setAdvancedZoomingEnabled( on );
2112 // update action state if method is called outside
2113 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
2114 if ( a->isChecked() != on )
2115 a->setChecked( on );
2119 \brief Get current interaction style
2120 \return interaction style
2122 int OCCViewer_ViewWindow::interactionStyle() const
2124 return myInteractionStyle;
2128 \brief Set current interaction style
2129 \param theStyle interaction style
2131 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
2133 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
2137 \brief Get current zooming style
2138 \return zooming style
2140 int OCCViewer_ViewWindow::zoomingStyle() const
2142 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
2146 \brief Set current zooming style
2147 \param theStyle zooming style
2149 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
2151 onSwitchZoomingStyle( theStyle == 1 );
2155 \brief Dump view window contents to the pixmap.
2156 \return pixmap containing all scene rendered in the window
2158 QImage OCCViewer_ViewWindow::dumpView()
2160 Handle(V3d_View) view = myViewPort->getView();
2161 if ( view.IsNull() )
2164 int aWidth = myViewPort->width();
2165 int aHeight = myViewPort->height();
2167 // rnv: An old approach to dump the OCCViewer content
2168 // Now used OCCT built-in procedure.
2170 QApplication::syncX();
2171 view->Redraw(); // In order to reactivate GL context
2174 #ifndef DISABLE_GLVIEWER
2175 OpenGLUtils_FrameBuffer aFrameBuffer;
2176 if( aFrameBuffer.init( aWidth, aHeight ) )
2178 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
2180 glPushAttrib( GL_VIEWPORT_BIT );
2181 glViewport( 0, 0, aWidth, aHeight );
2182 aFrameBuffer.bind();
2187 aFrameBuffer.unbind();
2190 aFrameBuffer.bind();
2191 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
2192 aFrameBuffer.unbind();
2194 anImage = anImage.rgbSwapped();
2195 anImage = anImage.mirrored();
2198 // if frame buffers are unsupported, use old functionality
2201 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
2203 QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
2205 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
2211 view->ToPixMap(aPix,aWidth, aHeight,Graphic3d_BT_RGBA);
2213 QImage anImage( aPix.Data(), aWidth, aHeight, QImage::Format_ARGB32 );
2214 anImage = anImage.mirrored();
2218 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
2219 const QString& fileName,
2220 const QString& format )
2222 if ( format != "PS" && format != "EPS")
2223 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
2225 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
2228 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
2229 else if (format == "EPS")
2230 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
2236 QString OCCViewer_ViewWindow::filter() const
2238 return tr( "OCC_IMAGE_FILES" );
2243 \brief Set parameters of the cutting plane
2244 \param on if \c true, cutting plane is enabled
2245 \param x X position of plane point
2246 \param y Y position of plane point
2247 \param z Z position of plane point
2248 \param dx X coordinate of plane normal
2249 \param dy Y coordinate of plane normal
2250 \param dz Z coordinate of plane normal
2252 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2253 const double dx, const double dy, const double dz )
2255 Handle(V3d_View) view = myViewPort->getView();
2256 if ( view.IsNull() )
2260 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2262 // try to use already existing plane or create a new one
2263 Handle(V3d_Plane) clipPlane;
2265 // calculate new a,b,c,d values for the plane
2266 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2268 pln.Coefficients(a, b, c, d);
2270 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2271 if(aPlanes.Size() > 0 ) {
2272 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2273 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2274 aClipPlane->SetEquation(pln);
2275 aClipPlane->SetOn(Standard_True);
2277 view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2281 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2282 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2283 for( ;anIter.More();anIter.Next() ){
2284 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2285 aClipPlane->SetOn(Standard_False);
2293 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2295 gp_Dir aDir = pln.Axis().Direction();
2296 gp_Pnt aPnt = pln.Location();
2297 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2302 \brief Check if any cutting plane is enabled
2303 \return \c true if at least one cutting plane is enabled
2305 bool OCCViewer_ViewWindow::isCuttingPlane()
2307 Handle(V3d_View) view = myViewPort->getView();
2309 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2310 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2311 for( ;anIter.More();anIter.Next() ) {
2312 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2313 if(aClipPlane->IsOn()) {
2322 \brief Get the visual parameters of the view window.
2323 \return visual parameters of view window
2325 viewAspect OCCViewer_ViewWindow::getViewParams() const
2327 double projX, projY, projZ, twist;
2328 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2329 double aScaleX, aScaleY, aScaleZ;
2331 Handle(V3d_View) aView3d = myViewPort->getView();
2333 aView3d->Proj( projX, projY, projZ );
2334 aView3d->At( atX, atY, atZ );
2335 aView3d->Eye( eyeX, eyeY, eyeZ );
2336 twist = aView3d->Twist();
2338 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2340 bool isShown = myModel->isTrihedronVisible();
2341 double size = myModel->trihedronSize();
2343 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2346 params.scale = aView3d->Scale();
2347 params.projX = projX;
2348 params.projY = projY;
2349 params.projZ = projZ;
2350 params.twist = twist;
2357 params.scaleX = aScaleX;
2358 params.scaleY = aScaleY;
2359 params.scaleZ = aScaleZ;
2360 params.name = aName;
2361 params.isVisible= isShown;
2364 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2365 aView3d->Center( params.centerX, params.centerY );
2368 // graduated trihedron
2369 bool anIsVisible = false;
2370 OCCViewer_AxisWidget::AxisData anAxisData[3];
2371 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2373 params.gtIsVisible = anIsVisible;
2374 params.gtDrawNameX = anAxisData[0].DrawName;
2375 params.gtDrawNameY = anAxisData[1].DrawName;
2376 params.gtDrawNameZ = anAxisData[2].DrawName;
2377 params.gtNameX = anAxisData[0].Name;
2378 params.gtNameY = anAxisData[1].Name;
2379 params.gtNameZ = anAxisData[2].Name;
2380 params.gtNameColorRX = anAxisData[0].NameColor.red();
2381 params.gtNameColorGX = anAxisData[0].NameColor.green();
2382 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2383 params.gtNameColorRY = anAxisData[1].NameColor.red();
2384 params.gtNameColorGY = anAxisData[1].NameColor.green();
2385 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2386 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2387 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2388 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2389 params.gtDrawValuesX = anAxisData[0].DrawValues;
2390 params.gtDrawValuesY = anAxisData[1].DrawValues;
2391 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2392 params.gtNbValuesX = anAxisData[0].NbValues;
2393 params.gtNbValuesY = anAxisData[1].NbValues;
2394 params.gtNbValuesZ = anAxisData[2].NbValues;
2395 params.gtOffsetX = anAxisData[0].Offset;
2396 params.gtOffsetY = anAxisData[1].Offset;
2397 params.gtOffsetZ = anAxisData[2].Offset;
2398 params.gtColorRX = anAxisData[0].Color.red();
2399 params.gtColorGX = anAxisData[0].Color.green();
2400 params.gtColorBX = anAxisData[0].Color.blue();
2401 params.gtColorRY = anAxisData[1].Color.red();
2402 params.gtColorGY = anAxisData[1].Color.green();
2403 params.gtColorBY = anAxisData[1].Color.blue();
2404 params.gtColorRZ = anAxisData[2].Color.red();
2405 params.gtColorGZ = anAxisData[2].Color.green();
2406 params.gtColorBZ = anAxisData[2].Color.blue();
2407 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2408 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2409 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2410 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2411 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2412 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2418 \brief Get visual parameters of this view window.
2419 \return visual parameters of view window
2421 QString OCCViewer_ViewWindow::getVisualParameters()
2423 viewAspect params = getViewParams();
2427 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2428 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2429 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
2430 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
2432 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2433 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2434 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2435 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2436 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2437 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2438 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2439 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2440 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2441 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2442 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2443 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2444 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2445 data << QString( "isVisible=%1" ).arg( params.isVisible );
2446 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2448 ClipPlanesList aPlanes = myModel->getClipPlanes();
2449 for ( int i=0; i < aPlanes.size(); i++ )
2451 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2452 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2453 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2454 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2455 switch ( aPlane.Mode )
2457 case OCCViewer_ClipPlane::Absolute :
2459 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2461 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2463 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2464 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2465 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2469 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2474 case OCCViewer_ClipPlane::Relative :
2476 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2477 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2478 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2483 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2484 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2485 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2486 data << ClippingPlane;
2489 // graduated trihedron
2490 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2491 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2492 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2493 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2494 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2495 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2496 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2497 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2498 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2499 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2500 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2501 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2502 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2503 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2504 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2505 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2506 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2507 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2508 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2509 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2510 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2511 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2512 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2513 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2514 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2515 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2516 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2517 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2518 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2519 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2520 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2521 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2522 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2523 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2524 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2525 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2526 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2527 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2528 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2529 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2530 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2531 data << QString( "background=%1" ).arg( bg );
2533 return data.join("*");
2537 \brief Restore visual parameters of the view window.
2538 \param parameters visual parameters of view window
2540 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2543 ClipPlanesList aClipPlanes;
2544 QStringList data = parameters.split( '*' );
2545 Qtx::BackgroundData bgData;
2546 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2548 foreach( QString param, data ) {
2549 QString paramName = param.section( '=', 0, 0 ).trimmed();
2550 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2551 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2552 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2553 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2554 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2555 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2556 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2557 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2558 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2559 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2560 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2561 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2562 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2563 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2564 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2565 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2566 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2567 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2568 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2569 else if ( paramName.contains( "ClippingPlane" ) )
2571 QStringList ClipPlaneData = paramValue.split( ';' );
2572 OCCViewer_ClipPlane aPlane;
2573 foreach( QString ClipPlaneParam, ClipPlaneData )
2575 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2576 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2577 if ( ClipPlane_paramName == "Mode" )
2579 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2581 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2582 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2583 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2584 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2587 switch ( aPlane.Mode )
2589 case OCCViewer_ClipPlane::Absolute :
2590 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2591 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2592 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2593 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2594 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2597 case OCCViewer_ClipPlane::Relative :
2598 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2599 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2600 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2605 aClipPlanes.push_back(aPlane);
2607 // graduated trihedron
2608 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2609 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2610 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2611 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2612 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2613 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2614 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2615 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2616 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2617 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2618 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2619 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2620 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2621 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2622 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2623 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2624 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2625 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2626 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2627 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2628 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2629 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2630 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2631 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2632 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2633 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2634 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2635 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2636 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2637 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2638 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2639 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2640 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2641 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2642 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2643 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2644 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2645 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2646 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2647 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2648 else if ( paramName == "background" ) {
2649 QString bg = paramValue.replace( "$", "=" );
2650 bgData = Qtx::stringToBackground( bg );
2654 else // old format - "1.000e+00*0.000e+00..."
2657 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2658 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2659 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2660 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2661 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2662 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2663 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
2664 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2665 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2666 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
2667 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2668 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2669 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2670 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
2671 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
2672 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
2673 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
2674 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
2676 performRestoring( params );
2677 setBackground( bgData );
2678 myModel->setClipPlanes(aClipPlanes);
2682 \brief Handle show event.
2684 Emits Show() signal.
2686 \param theEvent show event
2688 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2690 emit Show( theEvent );
2694 \brief Handle hide event.
2696 Emits Hide() signal.
2698 \param theEvent hide event
2700 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
2702 emit Hide( theEvent );
2707 Save old cursor. [ protected ]
2709 void OCCViewer_ViewWindow::saveCursor()
2711 QCursor* aCursor = NULL;
2713 aCursor = myViewPort->getDefaultCursor();
2714 myCursor = ( aCursor ? *aCursor : cursor() );
2719 Creates default sketcher. [ virtual protected ]
2721 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
2724 return new OCCViewer_RectSketcher( this, type );
2725 if ( type == Polygon )
2726 return new OCCViewer_PolygonSketcher( this, type );
2730 void OCCViewer_ViewWindow::initSketchers()
2732 if ( mySketchers.isEmpty() )
2734 mySketchers.append( createSketcher( Rect ) );
2735 mySketchers.append( createSketcher( Polygon ) );
2739 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
2741 OCCViewer_ViewSketcher* sketcher = 0;
2742 QList<OCCViewer_ViewSketcher*>::Iterator it;
2743 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
2745 OCCViewer_ViewSketcher* sk = (*it);
2746 if ( sk->type() == typ )
2753 Handles requests for sketching in the active view. [ virtual public ]
2755 void OCCViewer_ViewWindow::activateSketching( int type )
2757 OCCViewer_ViewPort3d* vp = getViewPort();
2761 if ( !vp->isSketchingEnabled() )
2764 /* Finish current sketching */
2765 if ( type == NoSketching )
2769 onSketchingFinished();
2770 mypSketcher->deactivate();
2774 /* Activate new sketching */
2777 activateSketching( NoSketching ); /* concurrency not suported */
2778 mypSketcher = getSketcher( type );
2781 mypSketcher->activate();
2782 onSketchingStarted();
2788 Unhilights detected entities. [ virtual protected ]
2790 void OCCViewer_ViewWindow::onSketchingStarted()
2795 Selection by rectangle or polygon. [ virtual protected ]
2797 void OCCViewer_ViewWindow::onSketchingFinished()
2799 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
2800 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
2802 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
2803 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
2804 switch( mypSketcher->type() )
2808 QRect* aRect = (QRect*)mypSketcher->data();
2811 int aLeft = aRect->left();
2812 int aRight = aRect->right();
2813 int aTop = aRect->top();
2814 int aBottom = aRect->bottom();
2818 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2820 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2826 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
2829 int size = aPolygon->size();
2830 TColgp_Array1OfPnt2d anArray( 1, size );
2832 QPolygon::Iterator it = aPolygon->begin();
2833 QPolygon::Iterator itEnd = aPolygon->end();
2834 for( int index = 1; it != itEnd; ++it, index++ )
2836 QPoint aPoint = *it;
2837 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
2841 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
2843 ic->Select( anArray, getViewPort()->getView(), Standard_False );
2851 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
2852 aViewMgr->getOCCViewer()->performSelectionChanged();
2856 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
2861 bool OCCViewer_ViewWindow::transformRequested() const
2863 return ( myOperation != NOTHING );
2866 bool OCCViewer_ViewWindow::transformInProcess() const
2868 return myEventStarted;
2871 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
2873 myEventStarted = bOn;
2877 Set enabled state of transformation (rotate, zoom, etc)
2879 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
2881 if ( id != NOTHING ) myStatus.insert( id, on );
2885 \return enabled state of transformation (rotate, zoom, etc)
2887 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
2889 return myStatus.contains( id ) ? myStatus[ id ] : true;
2892 void OCCViewer_ViewWindow::onMaximizedView()
2894 setMaximized(!isMaximized());
2897 void OCCViewer_ViewWindow::returnTo3dView()
2899 setReturnedTo3dView( true );
2902 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
2904 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
2905 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
2906 if ( !isVisible3dView )
2907 toolMgr()->show( ReturnTo3dViewId );
2909 toolMgr()->hide( ReturnTo3dViewId );
2910 if ( isVisible3dView ) emit returnedTo3d( );
2914 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
2916 QAction* anAction = toolMgr()->action( MaximizedId );
2917 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
2918 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
2920 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
2921 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
2922 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
2923 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
2924 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
2926 emit maximized( this, true );
2930 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
2931 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
2932 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
2933 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
2934 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
2936 emit maximized( this, false );
2941 bool OCCViewer_ViewWindow::isMaximized() const
2943 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
2946 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
2948 IsSketcherStyle = enable;
2951 bool OCCViewer_ViewWindow::isSketcherStyle() const
2953 return IsSketcherStyle;
2957 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
2962 int OCCViewer_ViewWindow::projectionType() const
2964 int mode = Orthographic;
2965 Handle(V3d_View) aView3d = myViewPort->getView();
2966 if ( !aView3d.IsNull() ) {
2967 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
2968 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Perspective)
2970 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Orthographic)
2971 mode = Orthographic;
2972 #if OCC_VERSION_LARGE > 0x06090000
2973 if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
2980 void OCCViewer_ViewWindow::setStereoType( int type )
2982 Handle(V3d_View) aView3d = myViewPort->getView();
2983 if ( !aView3d.IsNull() ) {
2984 #if OCC_VERSION_LARGE > 0x06090000
2985 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
2986 aParams->StereoMode = (Graphic3d_StereoMode)type;
2991 int OCCViewer_ViewWindow::stereoType() const
2993 int type = QuadBuffer;
2994 Handle(V3d_View) aView3d = myViewPort->getView();
2995 if ( !aView3d.IsNull() ) {
2996 #if OCC_VERSION_LARGE > 0x06090000
2997 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
2998 type = (OCCViewer_ViewWindow::StereoType)aParams->StereoMode;
3004 void OCCViewer_ViewWindow::setAnaglyphFilter( int type )
3006 Handle(V3d_View) aView3d = myViewPort->getView();
3007 if ( !aView3d.IsNull() ) {
3008 #if OCC_VERSION_LARGE > 0x06090000
3009 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3010 if (type == RedCyan)
3011 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
3012 if (type == YellowBlue)
3013 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
3014 if (type == GreenMagenta)
3015 aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
3020 int OCCViewer_ViewWindow::anaglyphFilter() const
3023 Handle(V3d_View) aView3d = myViewPort->getView();
3024 if ( !aView3d.IsNull() ) {
3025 #if OCC_VERSION_LARGE > 0x06090000
3026 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3027 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized)
3029 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized)
3031 if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple)
3032 type = GreenMagenta;
3038 void OCCViewer_ViewWindow::setStereographicFocus( int type, double value )
3040 Handle(V3d_View) aView3d = myViewPort->getView();
3041 if ( !aView3d.IsNull() ) {
3042 #if OCC_VERSION_LARGE > 0x06090000
3043 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3044 aCamera->SetZFocus( (Graphic3d_Camera::FocusType) type, value );
3049 int OCCViewer_ViewWindow::stereographicFocusType() const
3051 int type = Relative;
3052 Handle(V3d_View) aView3d = myViewPort->getView();
3053 if ( !aView3d.IsNull() ) {
3054 #if OCC_VERSION_LARGE > 0x06090000
3055 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3056 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->ZFocusType();
3062 double OCCViewer_ViewWindow::stereographicFocusValue() const
3065 Handle(V3d_View) aView3d = myViewPort->getView();
3066 if ( !aView3d.IsNull() ) {
3067 #if OCC_VERSION_LARGE > 0x06090000
3068 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3069 value = aCamera->ZFocus();
3075 void OCCViewer_ViewWindow::setInterocularDistance( int type, double value )
3077 Handle(V3d_View) aView3d = myViewPort->getView();
3078 if ( !aView3d.IsNull() ) {
3079 #if OCC_VERSION_LARGE > 0x06090000
3080 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3081 aCamera->SetIOD( (Graphic3d_Camera::IODType) type, value );
3086 int OCCViewer_ViewWindow::interocularDistanceType() const
3088 int type = Relative;
3089 Handle(V3d_View) aView3d = myViewPort->getView();
3090 if ( !aView3d.IsNull() ) {
3091 #if OCC_VERSION_LARGE > 0x06090000
3092 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3093 type = (OCCViewer_ViewWindow::FocusIODType)aCamera->GetIODType();
3099 double OCCViewer_ViewWindow::interocularDistanceValue() const
3101 double value = 0.05;
3102 Handle(V3d_View) aView3d = myViewPort->getView();
3103 if ( !aView3d.IsNull() ) {
3104 #if OCC_VERSION_LARGE > 0x06090000
3105 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3106 value = aCamera->IOD();
3112 void OCCViewer_ViewWindow::setReverseStereo( bool reverse )
3114 Handle(V3d_View) aView3d = myViewPort->getView();
3115 if ( !aView3d.IsNull() ) {
3116 #if OCC_VERSION_LARGE > 0x06090000
3117 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3118 aParams->ToReverseStereo = reverse;
3123 bool OCCViewer_ViewWindow::isReverseStereo() const
3125 int reverse = false;
3126 Handle(V3d_View) aView3d = myViewPort->getView();
3127 if ( !aView3d.IsNull() ) {
3128 #if OCC_VERSION_LARGE > 0x06090000
3129 Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3130 reverse = aParams->ToReverseStereo;
3136 void OCCViewer_ViewWindow::setVSync( bool enable )
3138 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3139 if ( !anIntCont.IsNull() ) {
3140 #if OCC_VERSION_LARGE > 0x06090000
3141 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3142 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3143 aCaps->swapInterval = enable;
3148 bool OCCViewer_ViewWindow::isVSync() const
3151 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3152 if ( !anIntCont.IsNull() ) {
3153 #if OCC_VERSION_LARGE > 0x06090000
3154 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3155 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3156 enable = aCaps->swapInterval;
3162 void OCCViewer_ViewWindow::setQuadBufferSupport( bool enable )
3164 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3165 if ( !anIntCont.IsNull() ) {
3166 #if OCC_VERSION_LARGE > 0x06090000
3167 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3168 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3169 aCaps->contextStereo = enable;
3174 bool OCCViewer_ViewWindow::isQuadBufferSupport() const
3177 Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3178 if ( !anIntCont.IsNull() ) {
3179 #if OCC_VERSION_LARGE > 0x06090000
3180 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3181 OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3182 enable = aCaps->contextStereo;
3189 bool OCCViewer_ViewWindow::isOpenGlStereoSupport() const
3191 GLboolean support[1];
3192 glGetBooleanv (GL_STEREO, support);
3199 QColor OCCViewer_ViewWindow::backgroundColor() const
3201 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
3205 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
3207 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
3210 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
3212 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
3215 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
3217 if ( myViewPort ) myViewPort->setBackground( theBackground );
3220 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
3222 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
3228 void OCCViewer_ViewWindow::clearViewAspects()
3230 myViewAspects.clear();
3234 \return const reference to list of view aspects
3236 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
3238 return myViewAspects;
3242 Appends new view aspect
3243 \param aParams - new view aspects
3245 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
3247 myViewAspects.append( aParams );
3251 Replaces old view aspects by new ones
3252 \param aViewList - list of new view aspects
3254 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
3256 myViewAspects = aViewList;
3260 Get camera properties for the OCC view window.
3261 \return shared pointer on camera properties.
3263 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
3265 SUIT_CameraProperties aProps;
3267 Handle(V3d_View) aSourceView = getViewPort()->getView();
3268 if ( aSourceView.IsNull() )
3271 if ( get2dMode() == No2dMode ) {
3272 aProps.setDimension( SUIT_CameraProperties::Dim3D );
3275 aProps.setDimension( SUIT_CameraProperties::Dim2D );
3276 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
3279 // read common properites of the view
3280 Standard_Real anUp[3];
3281 Standard_Real anAt[3];
3282 Standard_Real anEye[3];
3283 Standard_Real aProj[3];
3284 Standard_Real anAxialScale[3];
3286 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
3287 aSourceView->At( anAt[0], anAt[1], anAt[2] );
3288 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
3289 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3291 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3292 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
3294 #if OCC_VERSION_LARGE > 0x06070100
3295 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
3297 // store camera properties "as is": it is up to synchronized
3298 // view classes to provide necessary property conversion.
3299 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
3300 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
3302 if ( aSourceView->Camera()->IsOrthographic() )
3304 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
3305 aProps.setViewAngle( 0.0 );
3309 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
3310 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
3312 aProps.setMappingScale( aSourceView->Camera()->Scale() );
3314 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
3316 // generate view orientation matrix for transforming OCC projection reference point
3317 // into a camera (eye) position.
3318 gp_Dir aLeftDir = gp_Dir( anUp[0], anUp[1], anUp[2] ) ^ gp_Dir( aProj[0], aProj[1], aProj[2] );
3321 aTrsf.SetValue( 1, 1, aLeftDir.X() );
3322 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
3323 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
3325 aTrsf.SetValue( 1, 2, anUp[0] );
3326 aTrsf.SetValue( 2, 2, anUp[1] );
3327 aTrsf.SetValue( 3, 2, anUp[2] );
3329 aTrsf.SetValue( 1, 3, aProj[0] );
3330 aTrsf.SetValue( 2, 3, aProj[1] );
3331 aTrsf.SetValue( 3, 3, aProj[2] );
3333 aTrsf.SetValue( 1, 4, anAt[0] );
3334 aTrsf.SetValue( 2, 4, anAt[1] );
3335 aTrsf.SetValue( 3, 4, anAt[2] );
3337 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
3339 // transform to world-space coordinate system
3340 gp_XYZ aPosition( aProjRef.X(), aProjRef.Y(), aCameraDepth );
3341 aTrsf.Transforms( aPosition );
3343 // compute focal point
3344 double aFocalPoint[3];
3346 aFocalPoint[0] = aPosition.X() - aProj[0] * aCameraDepth;
3347 aFocalPoint[1] = aPosition.Y() - aProj[1] * aCameraDepth;
3348 aFocalPoint[2] = aPosition.Z() - aProj[2] * aCameraDepth;
3350 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3351 aProps.setPosition( aPosition.X(), aPosition.Y(), aPosition.Z() );
3353 Standard_Real aViewScale[2];
3354 aSourceView->Size( aViewScale[0], aViewScale[1] );
3355 aProps.setMappingScale( aViewScale[1] );
3363 This implementation synchronizes OCC view's camera propreties.
3365 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
3367 bool blocked = blockSignals( true );
3369 SUIT_CameraProperties aProps = theView->cameraProperties();
3370 if ( !cameraProperties().isCompatible( aProps ) ) {
3371 // other view, this one is being currently synchronized to, seems has become incompatible
3372 // we have to break synchronization
3377 Handle(V3d_View) aDestView = getViewPort()->getView();
3379 aDestView->SetImmediateUpdate( Standard_False );
3382 double aPosition[3];
3383 double aFocalPoint[3];
3384 double anAxialScale[3];
3386 // get common properties
3387 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3388 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
3389 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3390 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3392 #if OCC_VERSION_LARGE > 0x06070100
3393 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3394 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
3395 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3396 aDestView->Camera()->SetScale( aProps.getMappingScale() );
3398 gp_Dir aProjDir( aPosition[0] - aFocalPoint[0],
3399 aPosition[1] - aFocalPoint[1],
3400 aPosition[2] - aFocalPoint[2] );
3402 // get custom view translation
3403 Standard_Real aTranslation[3];
3404 aDestView->At( aTranslation[0], aTranslation[1], aTranslation[2] );
3406 gp_Dir aLeftDir = gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] )
3407 ^ gp_Dir( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
3410 aTrsf.SetValue( 1, 1, aLeftDir.X() );
3411 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
3412 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
3414 aTrsf.SetValue( 1, 2, anUpDir[0] );
3415 aTrsf.SetValue( 2, 2, anUpDir[1] );
3416 aTrsf.SetValue( 3, 2, anUpDir[2] );
3418 aTrsf.SetValue( 1, 3, aProjDir.X() );
3419 aTrsf.SetValue( 2, 3, aProjDir.Y() );
3420 aTrsf.SetValue( 3, 3, aProjDir.Z() );
3422 aTrsf.SetValue( 1, 4, aTranslation[0] );
3423 aTrsf.SetValue( 2, 4, aTranslation[1] );
3424 aTrsf.SetValue( 3, 4, aTranslation[2] );
3427 // transform to view-space coordinate system
3428 gp_XYZ aProjRef( aPosition[0], aPosition[1], aPosition[2] );
3429 aTrsf.Transforms( aProjRef );
3431 // set view camera properties using low-level approach. this is done
3432 // in order to avoid interference with static variables in v3d view used
3433 // when rotation is in process in another view.
3434 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
3435 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
3437 Graphic3d_Vector aMappingProj( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
3438 Graphic3d_Vector aMappingUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3440 aMappingProj.Normalize();
3441 aMappingUp.Normalize();
3443 anOrientation.SetViewReferencePlane( aMappingProj );
3444 anOrientation.SetViewReferenceUp( aMappingUp );
3446 aDestView->SetViewMapping( aMapping );
3447 aDestView->SetViewOrientation( anOrientation );
3450 aDestView->SetCenter( aProjRef.X(), aProjRef.Y() );
3452 // set mapping scale
3453 double aMapScaling = aProps.getMappingScale();
3454 Standard_Real aWidth, aHeight;
3455 aDestView->Size( aWidth, aHeight );
3456 aDestView->SetSize ( aWidth > aHeight ? aMapScaling * (aWidth / aHeight) : aMapScaling );
3459 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3461 aDestView->ZFitAll();
3462 aDestView->SetImmediateUpdate( Standard_True );
3463 aDestView->Redraw();
3465 blockSignals( blocked );
3469 \brief Indicates whether preselection is enabled
3470 \return true if preselection is enabled
3472 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
3474 return myPreselectionEnabled;
3478 \brief Enables/disables preselection
3479 \param theIsToEnable if true - preselection will be enabled
3481 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
3483 onSwitchPreselection( theIsToEnable );
3487 \brief Indicates whether selection is enabled
3488 \return true if selection is enabled
3490 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3492 return mySelectionEnabled;
3496 \brief Enables/disables selection
3497 \param theIsToEnable if true - selection will be enabled
3499 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3501 onSwitchSelection( theIsToEnable );
3506 \brief called if clipping operation is activated / deactivated.
3508 Enables/disables clipping plane displaying.
3510 \parma on action state
3512 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3514 if(!myModel) return;
3515 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3518 if (!aClippingDlg) {
3519 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3520 myModel->setClippingDlg(aClippingDlg);
3522 if (!aClippingDlg->isVisible())
3523 aClippingDlg->show();
3525 if ( aClippingDlg ) {
3526 aClippingDlg->close();
3527 myModel->setClippingDlg(0);
3531 SUIT_ViewManager* mgr = getViewManager();
3533 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3534 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3535 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3536 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3538 QAction* a = toolMgr()->action( ClippingId );
3540 if(theIsOn != a->isChecked()){
3541 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3542 a->setChecked(theIsOn);
3543 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));