1 // Copyright (C) 2007-2014 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 <Basics_OCCTVersion.hxx>
40 #include <SUIT_Desktop.h>
41 #include <SUIT_Session.h>
42 #include <SUIT_ViewManager.h>
43 #include <SUIT_Tools.h>
44 #include <SUIT_ResourceMgr.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_Application.h>
48 #include <QtxActionToolMgr.h>
49 #include <QtxMultiAction.h>
50 #include <QtxRubberBand.h>
52 #include <OpenGLUtils_FrameBuffer.h>
58 #include <QMouseEvent>
59 #include <QApplication>
62 #include <AIS_ListOfInteractive.hxx>
63 #include <AIS_ListIteratorOfListOfInteractive.hxx>
64 #include <AIS_Shape.hxx>
66 #include <BRep_Tool.hxx>
67 #include <BRepBndLib.hxx>
68 #include <BRepGProp.hxx>
69 #include <GProp_GProps.hxx>
72 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
73 #include <Graphic3d_MapOfStructure.hxx>
74 #include <Graphic3d_Structure.hxx>
75 #include <Graphic3d_ExportFormat.hxx>
77 #include <Visual3d_View.hxx>
78 #include <V3d_Plane.hxx>
79 #include <V3d_Light.hxx>
83 #include <gp_GTrsf.hxx>
84 #include <TColgp_Array1OfPnt2d.hxx>
86 #if OCC_VERSION_LARGE > 0x06060000
87 #include <Graphic3d_SequenceOfHClipPlane.hxx>
88 #include <Graphic3d_ClipPlane.hxx>
92 #include <Standard_Version.hxx>
94 #include "utilities.h"
98 // #include <highgui.h>
100 static QEvent* l_mbPressEvent = 0;
103 # include <QWindowsStyle>
108 const char* imageZoomCursor[] = {
113 "................................",
114 "................................",
115 ".#######........................",
116 "..aaaaaaa.......................",
117 "................................",
118 ".............#####..............",
119 "...........##.aaaa##............",
120 "..........#.aa.....a#...........",
121 ".........#.a.........#..........",
122 ".........#a..........#a.........",
123 "........#.a...........#.........",
124 "........#a............#a........",
125 "........#a............#a........",
126 "........#a............#a........",
127 "........#a............#a........",
128 ".........#...........#.a........",
129 ".........#a..........#a.........",
130 ".........##.........#.a.........",
131 "........#####.....##.a..........",
132 ".......###aaa#####.aa...........",
133 "......###aa...aaaaa.......#.....",
134 ".....###aa................#a....",
135 "....###aa.................#a....",
136 "...###aa...............#######..",
137 "....#aa.................aa#aaaa.",
138 ".....a....................#a....",
139 "..........................#a....",
140 "...........................a....",
141 "................................",
142 "................................",
143 "................................",
144 "................................"};
146 const char* imageRotateCursor[] = {
151 "................................",
152 "................................",
153 "................................",
154 "................................",
155 "........#.......................",
156 ".......#.a......................",
157 "......#######...................",
158 ".......#aaaaa#####..............",
159 "........#..##.a#aa##........##..",
160 ".........a#.aa..#..a#.....##.aa.",
161 ".........#.a.....#...#..##.aa...",
162 ".........#a.......#..###.aa.....",
163 "........#.a.......#a..#aa.......",
164 "........#a.........#..#a........",
165 "........#a.........#a.#a........",
166 "........#a.........#a.#a........",
167 "........#a.........#a.#a........",
168 ".........#.........#a#.a........",
169 "........##a........#a#a.........",
170 "......##.a#.......#.#.a.........",
171 "....##.aa..##.....##.a..........",
172 "..##.aa.....a#####.aa...........",
173 "...aa.........aaa#a.............",
174 "................#.a.............",
175 "...............#.a..............",
176 "..............#.a...............",
177 "...............a................",
178 "................................",
179 "................................",
180 "................................",
181 "................................",
182 "................................"};
184 const char* imageCrossCursor[] = {
189 "................................",
190 "................................",
191 "................................",
192 "................................",
193 "................................",
194 "................................",
195 "................................",
196 "...............#................",
197 "...............#a...............",
198 "...............#a...............",
199 "...............#a...............",
200 "...............#a...............",
201 "...............#a...............",
202 "...............#a...............",
203 "...............#a...............",
204 ".......#################........",
205 "........aaaaaaa#aaaaaaaaa.......",
206 "...............#a...............",
207 "...............#a...............",
208 "...............#a...............",
209 "...............#a...............",
210 "...............#a...............",
211 "...............#a...............",
212 "...............#a...............",
213 "................a...............",
214 "................................",
215 "................................",
216 "................................",
217 "................................",
218 "................................",
219 "................................",
220 "................................"};
225 \param theDesktop main window of application
226 \param theModel OCC 3D viewer
228 OCCViewer_ViewWindow::OCCViewer_ViewWindow( SUIT_Desktop* theDesktop,
229 OCCViewer_Viewer* theModel )
230 : SUIT_ViewWindow( theDesktop )
234 myEnableDrawMode = false;
236 updateEnabledDrawMode();
238 mySetRotationPointDlg = 0;
241 IsSketcherStyle = false;
248 myInteractionStyle = SUIT_ViewModel::STANDARD;
249 myPreselectionEnabled = true;
250 mySelectionEnabled = true;
260 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
263 qDeleteAll( mySketchers );
267 \brief Internal initialization.
269 void OCCViewer_ViewWindow::initLayout()
271 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
272 myViewPort->installEventFilter(this);
273 setCentralWidget(myViewPort);
274 myOperation = NOTHING;
276 myCurrPointType = GRAVITY;
277 myPrevPointType = GRAVITY;
278 mySelectedPoint = gp_Pnt(0.,0.,0.);
279 myRotationPointSelection = false;
281 setTransformRequested ( NOTHING );
282 setTransformInProcess ( false );
299 // Graduated axes dialog
300 QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
301 myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
302 myCubeAxesDlg->initialize();
304 connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
307 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
309 return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
313 \brief Detect viewer operation according the the mouse button pressed
314 and key modifiers used.
315 \param theEvent mouse event
316 \return type of the operation
318 OCCViewer_ViewWindow::OperationType
319 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
321 OperationType aOp = NOTHING;
322 SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
323 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
324 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
326 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
327 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
329 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
330 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
331 (my2dMode == No2dMode))
338 \brief Customize event handling
339 \param watched event receiver object
341 \return \c true if the event processing should be stopped
343 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
345 if ( watched == myViewPort ) {
346 int aType = e->type();
348 case QEvent::MouseButtonPress:
349 vpMousePressEvent((QMouseEvent*) e);
352 case QEvent::MouseButtonRelease:
353 vpMouseReleaseEvent((QMouseEvent*) e);
356 case QEvent::MouseMove:
357 vpMouseMoveEvent((QMouseEvent*) e);
360 case QEvent::MouseButtonDblClick:
361 emit mouseDoubleClicked(this, (QMouseEvent*)e);
366 QWheelEvent* aEvent = (QWheelEvent*) e;
367 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
368 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
371 int x1 = (int)( aEvent->x() + width()*delta/100 );
372 int y1 = (int)( aEvent->y() + height()*delta/100 );
373 myViewPort->zoom( x, y, x1, y1 );
374 myViewPort->getView()->ZFitAll();
378 case QEvent::ContextMenu:
380 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
381 if ( aEvent->reason() != QContextMenuEvent::Mouse )
382 emit contextMenuRequested( aEvent );
386 case QEvent::KeyPress:
387 emit keyPressed(this, (QKeyEvent*) e);
394 return SUIT_ViewWindow::eventFilter(watched, e);
398 \brief Update state of enable draw mode state.
400 void OCCViewer_ViewWindow::updateEnabledDrawMode()
403 myEnableDrawMode = myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
407 \brief Handle mouse press event
408 \param theEvent mouse event
410 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
412 myStartX = theEvent->x();
413 myStartY = theEvent->y();
414 int anInteractionStyle = interactionStyle();
416 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
417 // which are assigned for pan and rotate - these operations are activated immediately after pressing
418 // of the first button, so it is necessary to switch to zoom when the second button is pressed
419 bool aSwitchToZoom = false;
420 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
421 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
422 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
425 switch ( myOperation ) {
427 if ( theEvent->button() == Qt::LeftButton )
428 emit vpTransformationStarted ( WINDOWFIT );
432 if ( theEvent->button() == Qt::LeftButton )
433 emit vpTransformationStarted ( PANGLOBAL );
437 if ( theEvent->button() == Qt::LeftButton ) {
438 myViewPort->startZoomAtPoint( myStartX, myStartY );
439 emit vpTransformationStarted ( ZOOMVIEW );
444 if ( aSwitchToZoom ) {
445 myViewPort->startZoomAtPoint( myStartX, myStartY );
448 else if ( theEvent->button() == Qt::LeftButton )
449 emit vpTransformationStarted ( PANVIEW );
453 if ( aSwitchToZoom ) {
454 myViewPort->startZoomAtPoint( myStartX, myStartY );
457 else if ( theEvent->button() == Qt::LeftButton ) {
458 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
459 emit vpTransformationStarted ( ROTATE );
464 /* Try to activate a transformation */
465 OperationType aState;
466 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
467 aState = getButtonState(theEvent, anInteractionStyle);
469 aState = OCCViewer_ViewWindow::NOTHING;
474 myViewPort->startZoomAtPoint( myStartX, myStartY );
482 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
485 if ( myRotationPointSelection )
487 if ( theEvent->button() == Qt::LeftButton )
489 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
491 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
493 TopoDS_Shape aShape = ic->SelectedShape();
494 GProp_GProps aSystem;
496 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
498 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
500 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE )
502 BRepGProp::LinearProperties( aShape, aSystem );
503 aPnt = aSystem.CentreOfMass();
505 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE )
507 BRepGProp::SurfaceProperties( aShape, aSystem );
508 aPnt = aSystem.CentreOfMass();
510 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID )
512 BRepGProp::VolumeProperties( aShape, aSystem );
513 aPnt = aSystem.CentreOfMass();
517 myCurrPointType = myPrevPointType;
521 if ( mySetRotationPointDlg )
523 myRotationPointSelection = false;
524 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
527 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
528 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
529 ic->CloseAllContexts();
530 myOperation = NOTHING;
531 myViewPort->setCursor( myCursor );
532 myCursorIsHand = false;
533 myRotationPointSelection = false;
537 emit mousePressed(this, theEvent);
540 /* notify that we start a transformation */
541 if ( transformRequested() )
542 emit vpTransformationStarted ( myOperation );
544 if ( transformRequested() )
545 setTransformInProcess( true );
547 /* we may need it for sketching... */
548 if ( l_mbPressEvent )
549 delete l_mbPressEvent;
550 l_mbPressEvent = new QMouseEvent( *theEvent );
555 \brief Start zooming operation.
557 Sets the corresponding cursor for the widget.
559 void OCCViewer_ViewWindow::activateZoom()
561 if ( !transformRequested() && !myCursorIsHand )
562 myCursor = cursor(); /* save old cursor */
564 if ( myOperation != ZOOMVIEW ) {
565 QPixmap zoomPixmap (imageZoomCursor);
566 QCursor zoomCursor (zoomPixmap);
567 if( setTransformRequested ( ZOOMVIEW ) )
568 myViewPort->setCursor( zoomCursor );
574 \brief Start panning operation.
576 Sets the corresponding cursor for the widget.
578 void OCCViewer_ViewWindow::activatePanning()
580 if ( !transformRequested() && !myCursorIsHand )
581 myCursor = cursor(); // save old cursor
583 if ( myOperation != PANVIEW ) {
584 QCursor panCursor (Qt::SizeAllCursor);
585 if( setTransformRequested ( PANVIEW ) )
586 myViewPort->setCursor( panCursor );
591 \brief Start rotation operation
593 Sets the corresponding cursor for the widget.
595 void OCCViewer_ViewWindow::activateRotation()
597 if ( !transformRequested() && !myCursorIsHand )
598 myCursor = cursor(); // save old cursor
600 if ( myOperation != ROTATE ) {
601 QPixmap rotatePixmap (imageRotateCursor);
602 QCursor rotCursor (rotatePixmap);
603 if( setTransformRequested ( ROTATE ) )
604 myViewPort->setCursor( rotCursor );
609 \brief Compute the gravity center.
610 \param theX used to return X coordinate of the gravity center
611 \param theY used to return Y coordinate of the gravity center
612 \param theZ used to return Z coordinate of the gravity center
613 \return \c true if the gravity center is computed
615 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
617 Handle(V3d_View) aView3d = myViewPort->getView();
619 // Project boundaries points and add to avergae gravity
620 // the ones which lie within the screen limits
621 Standard_Real aScreenLimits[4] = { 0.0, 0.0, 0.0, 0.0 };
623 #if OCC_VERSION_LARGE > 0x06070100
624 // NDC space screen limits
625 aScreenLimits[0] = -1.0;
626 aScreenLimits[1] = 1.0;
627 aScreenLimits[2] = -1.0;
628 aScreenLimits[3] = 1.0;
630 aView3d->View()->ViewMapping().WindowLimit( aScreenLimits[0],
636 Standard_Integer aPointsNb = 0;
638 Standard_Real aXmin = 0.0;
639 Standard_Real aYmin = 0.0;
640 Standard_Real aZmin = 0.0;
641 Standard_Real aXmax = 0.0;
642 Standard_Real aYmax = 0.0;
643 Standard_Real aZmax = 0.0;
645 Graphic3d_MapOfStructure aSetOfStructures;
646 aView3d->View()->DisplayedStructures( aSetOfStructures );
647 Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures );
649 for( ; aStructureIt.More(); aStructureIt.Next() ) {
650 const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key();
651 if ( aStructure->IsEmpty() ) {
655 aStructure->MinMaxValues( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
657 // Infinite structures are skipped
658 Standard_Real aLIM = ShortRealLast() - 1.0;
659 if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
660 || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
664 gp_Pnt aPoints[8] = {
665 gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
666 gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
667 gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
668 gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
671 for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
672 const gp_Pnt& aBBPoint = aPoints[aPointIt];
674 #if OCC_VERSION_LARGE > 0x06070100
675 gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
676 const Standard_Real& U = aProjected.X();
677 const Standard_Real& V = aProjected.Y();
679 Standard_Real U = 0.0;
680 Standard_Real V = 0.0;
681 Standard_Real W = 0.0;
682 aView3d->View()->Projects( aBBPoint.X(), aBBPoint.Y(), aBBPoint.Z(), U, V, W );
685 if (U >= aScreenLimits[0]
686 && U <= aScreenLimits[1]
687 && V >= aScreenLimits[2]
688 && V <= aScreenLimits[3])
691 theX += aBBPoint.X();
692 theY += aBBPoint.Y();
693 theZ += aBBPoint.Z();
708 \brief Set the gravity center as a rotation point.
710 void OCCViewer_ViewWindow::activateSetRotationGravity()
712 if ( myRotationPointSelection )
714 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
715 ic->CloseAllContexts();
716 myOperation = NOTHING;
717 myViewPort->setCursor( myCursor );
718 myCursorIsHand = false;
719 myRotationPointSelection = false;
722 myPrevPointType = myCurrPointType;
723 myCurrPointType = GRAVITY;
725 Standard_Real Xcenter, Ycenter, Zcenter;
726 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
727 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
731 \brief Update gravity center in the "Set Rotation Point" dialog box.
732 \sa OCCViewer_SetRotationPointDlg class
734 void OCCViewer_ViewWindow::updateGravityCoords()
736 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == GRAVITY )
738 Standard_Real Xcenter, Ycenter, Zcenter;
739 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
740 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
745 \brief Set the point selected by the user as a rotation point.
746 \param theX X coordinate of the rotation point
747 \param theY Y coordinate of the rotation point
748 \param theZ Z coordinate of the rotation point
750 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
752 if ( myRotationPointSelection )
754 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
755 ic->CloseAllContexts();
756 myOperation = NOTHING;
757 myViewPort->setCursor( myCursor );
758 myCursorIsHand = false;
759 myRotationPointSelection = false;
762 myPrevPointType = myCurrPointType;
763 myCurrPointType = SELECTED;
764 mySelectedPoint.SetCoord(theX,theY,theZ);
768 \brief Start the shape selection process.
770 void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
772 myPrevPointType = myCurrPointType;
773 myCurrPointType = SELECTED;
775 // activate selection ------>
776 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
778 ic->OpenLocalContext();
780 AIS_ListOfInteractive aList;
781 ic->DisplayedObjects( aList );
782 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
784 Handle(AIS_InteractiveObject) anObj = it.Value();
785 if ( !anObj.IsNull() && anObj->HasPresentation() &&
786 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
789 ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
792 // activate selection <------
794 if ( !myCursorIsHand )
796 QCursor handCursor (Qt::PointingHandCursor);
797 myCursorIsHand = true;
799 myViewPort->setCursor( handCursor );
801 myRotationPointSelection = true;
805 \brief Start global panning operation
807 Sets the corresponding cursor for the widget.
809 void OCCViewer_ViewWindow::activateGlobalPanning()
811 Handle(V3d_View) aView3d = myViewPort->getView();
812 if ( !aView3d.IsNull() ) {
813 QPixmap globalPanPixmap (imageCrossCursor);
814 QCursor glPanCursor (globalPanPixmap);
815 myCurScale = aView3d->Scale();
816 aView3d->FitAll(0.01, false);
817 myCursor = cursor(); // save old cursor
818 myViewPort->fitAll(); // fits view before selecting a new scene center
819 if( setTransformRequested( PANGLOBAL ) )
820 myViewPort->setCursor( glPanCursor );
825 \brief Starts fit operation.
827 Sets the corresponding cursor for the widget.
829 void OCCViewer_ViewWindow::activateWindowFit()
831 if ( !transformRequested() && !myCursorIsHand )
832 myCursor = cursor(); /* save old cursor */
834 if ( myOperation != WINDOWFIT ) {
835 QCursor handCursor (Qt::PointingHandCursor);
836 if( setTransformRequested ( WINDOWFIT ) )
838 myViewPort->setCursor ( handCursor );
839 myCursorIsHand = true;
845 \brief Start delayed viewer operation.
847 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
849 bool ok = transformEnabled( op );
850 myOperation = ok ? op : NOTHING;
851 myViewPort->setMouseTracking( myOperation == NOTHING );
856 \brief Handle mouse move event.
857 \param theEvent mouse event
859 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
861 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
863 switch ( getButtonState( theEvent, interactionStyle() ) ) {
865 myViewPort->startZoomAtPoint( myStartX, myStartY );
873 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
880 myCurrX = theEvent->x();
881 myCurrY = theEvent->y();
882 switch (myOperation) {
884 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
888 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
894 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
908 if ( myRotationPointSelection || isSketcherStyle() )
910 emit mouseMoving( this, theEvent );
914 int aState = theEvent->modifiers();
915 int aButton = theEvent->buttons();
916 int anInteractionStyle = interactionStyle();
917 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
918 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
919 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
920 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
921 myDrawRect = myEnableDrawMode;
924 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
925 QCursor handCursor (Qt::PointingHandCursor);
926 myCursorIsHand = true;
928 myViewPort->setCursor( handCursor );
931 emit mouseMoving( this, theEvent );
933 else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
934 aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
935 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
936 aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
937 OCCViewer_ViewSketcher* sketcher = 0;
938 QList<OCCViewer_ViewSketcher*>::Iterator it;
939 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
941 OCCViewer_ViewSketcher* sk = (*it);
942 if( sk->isDefault() && sk->sketchButton() == aButton )
945 if ( sketcher && myCurSketch == -1 )
947 activateSketching( sketcher->type() );
950 myCurSketch = mypSketcher->sketchButton();
952 if ( l_mbPressEvent )
954 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
955 delete l_mbPressEvent;
958 QApplication::sendEvent( getViewPort(), theEvent );
963 emit mouseMoving( this, theEvent );
969 \brief Handle mouse release event.
970 \param theEvent mouse event
972 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
974 switch ( myOperation ) {
977 int prevState = myCurSketch;
978 if(theEvent->button() == Qt::RightButton)
980 QList<OCCViewer_ViewSketcher*>::Iterator it;
981 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
983 OCCViewer_ViewSketcher* sk = (*it);
984 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
989 emit mouseReleased(this, theEvent);
990 if(theEvent->button() == Qt::RightButton && prevState == -1)
992 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
993 theEvent->pos(), theEvent->globalPos() );
994 emit contextMenuRequested( &aEvent );
999 myViewPort->endRotation();
1005 myViewPort->getView()->ZFitAll();
1010 if ( theEvent->button() == Qt::LeftButton ) {
1011 myViewPort->setCenter( theEvent->x(), theEvent->y() );
1012 myViewPort->getView()->SetScale(myCurScale);
1018 if ( theEvent->button() == Qt::LeftButton ) {
1019 myCurrX = theEvent->x();
1020 myCurrY = theEvent->y();
1022 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1023 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1030 // NOTE: viewer 3D detects a rectangle of selection using this event
1031 // so we must emit it BEFORE resetting the selection rectangle
1033 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1037 myViewPort->update();
1040 if ( l_mbPressEvent )
1042 delete l_mbPressEvent;
1048 \brief Reset the viewport to its initial state
1049 ( no transformations in process etc. )
1051 void OCCViewer_ViewWindow::resetState()
1055 if ( myRotationPointSelection )
1057 QCursor handCursor (Qt::PointingHandCursor);
1058 myViewPort->setCursor( handCursor );
1062 if ( transformRequested() || myCursorIsHand )
1063 myViewPort->setCursor( myCursor );
1064 myCursorIsHand = false;
1067 if ( transformRequested() )
1068 emit vpTransformationFinished (myOperation);
1070 setTransformInProcess( false );
1071 setTransformRequested( NOTHING );
1076 \brief Draw rubber band rectangle.
1078 void OCCViewer_ViewWindow::drawRect()
1080 if ( !myRectBand ) {
1081 myRectBand = new QtxRectRubberBand( myViewPort );
1083 //palette.setColor(myRectBand->foregroundRole(), Qt::white);
1084 //myRectBand->setPalette(palette);
1086 //myRectBand->hide();
1088 myRectBand->setUpdatesEnabled ( false );
1089 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1090 myRectBand->initGeometry( aRect );
1092 if ( !myRectBand->isVisible() )
1095 myRectBand->setUpdatesEnabled ( true );
1096 //myRectBand->repaint();
1098 //myRectBand->setVisible( aRect.isValid() );
1099 //if ( myRectBand->isVisible() )
1100 // myRectBand->repaint();
1102 // myRectBand->show();
1103 //myRectBand->repaint();
1107 \brief Clear rubber band rectangle on the end on the dragging operation.
1109 void OCCViewer_ViewWindow::endDrawRect()
1111 //delete myRectBand;
1115 myRectBand->clearGeometry();
1121 \brief Create actions.
1123 void OCCViewer_ViewWindow::createActions()
1125 if( !toolMgr()->isEmpty() )
1128 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1133 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1134 tr( "MNU_DUMP_VIEW" ), 0, this);
1135 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1136 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1137 toolMgr()->registerAction( aAction, DumpId );
1140 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1141 tr( "MNU_FITALL" ), 0, this);
1142 aAction->setStatusTip(tr("DSC_FITALL"));
1143 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1144 toolMgr()->registerAction( aAction, FitAllId );
1147 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1148 tr( "MNU_FITRECT" ), 0, this);
1149 aAction->setStatusTip(tr("DSC_FITRECT"));
1150 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1151 toolMgr()->registerAction( aAction, FitRectId );
1154 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1155 tr( "MNU_ZOOM_VIEW" ), 0, this);
1156 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1157 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1158 toolMgr()->registerAction( aAction, ZoomId );
1161 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1162 tr( "MNU_PAN_VIEW" ), 0, this);
1163 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1164 connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
1165 toolMgr()->registerAction( aAction, PanId );
1168 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1169 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1170 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1171 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1172 toolMgr()->registerAction( aAction, GlobalPanId );
1175 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1176 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1177 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1178 mySetRotationPointAction->setCheckable( true );
1179 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1180 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1183 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1184 tr( "MNU_ROTATE_VIEW" ), 0, this);
1185 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1186 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1187 toolMgr()->registerAction( aAction, RotationId );
1190 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1191 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1192 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1193 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1194 this->addAction(aAction);
1195 toolMgr()->registerAction( aAction, FrontId );
1197 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1198 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1199 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1200 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1201 this->addAction(aAction);
1202 toolMgr()->registerAction( aAction, BackId );
1204 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1205 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1206 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1207 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1208 this->addAction(aAction);
1209 toolMgr()->registerAction( aAction, TopId );
1211 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1212 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1213 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1214 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1215 this->addAction(aAction);
1216 toolMgr()->registerAction( aAction, BottomId );
1218 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1219 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1220 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1221 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1222 this->addAction(aAction);
1223 toolMgr()->registerAction( aAction, LeftId );
1225 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1226 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1227 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1228 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1229 this->addAction(aAction);
1230 toolMgr()->registerAction( aAction, RightId );
1232 // rotate anticlockwise
1233 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1234 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1235 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1236 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1237 this->addAction(aAction);
1238 toolMgr()->registerAction( aAction, AntiClockWiseId );
1241 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1242 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1243 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1244 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1245 this->addAction(aAction);
1246 toolMgr()->registerAction( aAction, ClockWiseId );
1249 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1250 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1251 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1252 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1253 this->addAction(aAction);
1254 toolMgr()->registerAction( aAction, ResetId );
1257 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1258 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1259 tr("MNU_CLONE_VIEW"), 0, this);
1260 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1261 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1262 toolMgr()->registerAction( aAction, CloneId );
1264 aAction = new QtxAction (tr ("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr ("ICON_OCCVIEWER_CLIPPING")),
1265 tr ("MNU_CLIPPING"), 0, this);
1266 aAction->setStatusTip (tr ("DSC_CLIPPING"));
1267 aAction->setCheckable (true);
1268 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1269 toolMgr()->registerAction (aAction, ClippingId);
1271 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1272 tr( "MNU_SHOOT_VIEW" ), 0, this);
1273 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1274 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1275 toolMgr()->registerAction( aAction, MemId );
1277 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1278 tr( "MNU_PRESETS_VIEW" ), 0, this);
1279 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1280 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1281 toolMgr()->registerAction( aAction, RestoreId );
1283 if (myModel->trihedronActivated()) {
1284 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1285 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1286 aAction->setCheckable( true );
1287 aAction->setChecked( true );
1288 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1289 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1290 toolMgr()->registerAction( aAction, TrihedronShowId );
1294 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1295 tr( "MNU_SCALING" ), 0, this);
1296 aAction->setStatusTip(tr("DSC_SCALING"));
1297 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1298 toolMgr()->registerAction( aAction, AxialScaleId );
1300 // Enable/disable preselection
1301 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1302 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1303 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1304 aAction->setCheckable(true);
1305 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1306 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1308 // Enable/disable selection
1309 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1310 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1311 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1312 aAction->setCheckable(true);
1313 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1314 toolMgr()->registerAction( aAction, SwitchSelectionId );
1317 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1318 tr( "MNU_GRADUATED_AXES" ), 0, this);
1319 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1320 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1321 toolMgr()->registerAction( aAction, GraduatedAxesId );
1323 // Active only ambient light or not
1324 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1325 tr( "MNU_AMBIENT" ), 0, this);
1326 aAction->setStatusTip(tr("DSC_AMBIENT"));
1327 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1328 toolMgr()->registerAction( aAction, AmbientId );
1330 // Switch between interaction styles
1331 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1332 tr( "MNU_STYLE_SWITCH" ), 0, this);
1333 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1334 aAction->setCheckable(true);
1335 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1336 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1338 // Switch between zooming styles
1339 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1340 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1341 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1342 aAction->setCheckable(true);
1343 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1344 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1347 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1348 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1349 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1350 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1351 toolMgr()->registerAction( aAction, MaximizedId );
1353 // Return to 3d view
1354 if (my2dMode!=No2dMode){
1355 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1356 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1357 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1358 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1359 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1363 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1367 \brief Create toolbar.
1369 void OCCViewer_ViewWindow::createToolBar()
1371 QString aToolbarName;
1374 aToolbarName = tr( "LBL_XYTOOLBAR_LABEL" );
1377 aToolbarName = tr( "LBL_XZTOOLBAR_LABEL" );
1380 aToolbarName = tr( "LBL_YZTOOLBAR_LABEL" );
1383 aToolbarName = tr( "LBL_3DTOOLBAR_LABEL" );
1386 int tid = toolMgr()->createToolBar( aToolbarName, false );
1387 if ( my2dMode != No2dMode ){
1388 toolMgr()->append( ReturnTo3dViewId, tid );
1389 toolMgr()->append( toolMgr()->separator(), tid );
1391 toolMgr()->append( DumpId, tid );
1392 toolMgr()->append( SwitchInteractionStyleId, tid );
1393 #if OCC_VERSION_LARGE > 0x0603000A // available only with OCC-6.3-sp11 and higher version
1394 toolMgr()->append( SwitchZoomingStyleId, tid );
1396 toolMgr()->append( SwitchPreselectionId, tid );
1397 toolMgr()->append( SwitchSelectionId, tid );
1398 if( myModel->trihedronActivated() )
1399 toolMgr()->append( TrihedronShowId, tid );
1401 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1402 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1403 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1404 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1405 toolMgr()->append( aScaleAction, tid );
1407 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1408 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1409 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1410 toolMgr()->append( aPanningAction, tid );
1412 if (my2dMode == No2dMode) {
1413 toolMgr()->append( ChangeRotationPointId, tid );
1414 toolMgr()->append( RotationId, tid );
1416 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1417 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1418 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1419 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1420 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1421 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1422 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1423 toolMgr()->append( aViewsAction, tid );
1425 toolMgr()->append( AntiClockWiseId, tid );
1426 toolMgr()->append( ClockWiseId, tid );
1428 toolMgr()->append( ResetId, tid );
1431 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1432 aMemAction->insertAction( toolMgr()->action( MemId ) );
1433 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1434 toolMgr()->append( aMemAction, tid );
1436 toolMgr()->append( toolMgr()->separator(), tid );
1437 toolMgr()->append( CloneId, tid );
1439 toolMgr()->append( toolMgr()->separator(), tid );
1440 toolMgr()->append( ClippingId, tid );
1441 toolMgr()->append( AxialScaleId, tid );
1442 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
1443 toolMgr()->append( GraduatedAxesId, tid );
1445 toolMgr()->append( AmbientId, tid );
1447 toolMgr()->append( MaximizedId, tid );
1448 toolMgr()->append( SynchronizeId, tid );
1452 \brief Perform 'fit all' operation.
1454 void OCCViewer_ViewWindow::onViewFitAll()
1456 myViewPort->fitAll();
1460 \brief Perform "front view" transformation.
1462 void OCCViewer_ViewWindow::onFrontView()
1464 emit vpTransformationStarted ( FRONTVIEW );
1465 Handle(V3d_View) aView3d = myViewPort->getView();
1466 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
1468 emit vpTransformationFinished ( FRONTVIEW );
1472 \brief Perform "back view" transformation.
1474 void OCCViewer_ViewWindow::onBackView()
1476 emit vpTransformationStarted ( BACKVIEW );
1477 Handle(V3d_View) aView3d = myViewPort->getView();
1478 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
1480 emit vpTransformationFinished ( BACKVIEW );
1484 \brief Perform "top view" transformation.
1486 void OCCViewer_ViewWindow::onTopView()
1488 emit vpTransformationStarted ( TOPVIEW );
1489 Handle(V3d_View) aView3d = myViewPort->getView();
1490 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
1492 emit vpTransformationFinished ( TOPVIEW );
1496 \brief Perform "bottom view" transformation.
1498 void OCCViewer_ViewWindow::onBottomView()
1500 emit vpTransformationStarted ( BOTTOMVIEW );
1501 Handle(V3d_View) aView3d = myViewPort->getView();
1502 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
1504 emit vpTransformationFinished ( BOTTOMVIEW );
1508 \brief Perform "left view" transformation.
1510 void OCCViewer_ViewWindow::onLeftView()
1512 emit vpTransformationStarted ( LEFTVIEW );
1513 Handle(V3d_View) aView3d = myViewPort->getView();
1514 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
1516 emit vpTransformationFinished ( LEFTVIEW );
1520 \brief Perform "right view" transformation.
1522 void OCCViewer_ViewWindow::onRightView()
1524 emit vpTransformationStarted ( RIGHTVIEW );
1525 Handle(V3d_View) aView3d = myViewPort->getView();
1526 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
1528 emit vpTransformationFinished ( RIGHTVIEW );
1532 \brief Rotate view 90 degrees clockwise
1534 void OCCViewer_ViewWindow::onClockWiseView()
1536 emit vpTransformationStarted ( CLOCKWISEVIEW );
1537 myViewPort->rotateXY( 90. );
1538 emit vpTransformationFinished ( CLOCKWISEVIEW );
1542 \brief Rotate view 90 degrees conterclockwise
1544 void OCCViewer_ViewWindow::onAntiClockWiseView()
1546 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1547 myViewPort->rotateXY( -90. );
1548 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1552 \brief Perform "reset view" transformation.
1554 Sets default orientation of the viewport camera.
1556 void OCCViewer_ViewWindow::onResetView()
1558 emit vpTransformationStarted( RESETVIEW );
1559 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1560 myViewPort->getView()->Reset( false );
1561 myViewPort->fitAll( false, true, false );
1562 myViewPort->getView()->SetImmediateUpdate( upd );
1563 myViewPort->getView()->Update();
1564 emit vpTransformationFinished( RESETVIEW );
1568 \brief Perform "fit all" transformation.
1570 void OCCViewer_ViewWindow::onFitAll()
1572 emit vpTransformationStarted( FITALLVIEW );
1573 myViewPort->fitAll();
1574 emit vpTransformationFinished( FITALLVIEW );
1578 \brief Called if 'change rotation point' operation is activated.
1579 \param on action state
1581 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1585 if (!mySetRotationPointDlg)
1587 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1588 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1591 if (!mySetRotationPointDlg->isVisible())
1593 //if (mySetRotationPointDlg->IsFirstShown())
1594 if (myCurrPointType == GRAVITY)
1596 Standard_Real Xcenter, Ycenter, Zcenter;
1597 if (computeGravityCenter(Xcenter, Ycenter, Zcenter))
1598 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1600 mySetRotationPointDlg->show();
1605 if (mySetRotationPointDlg->isVisible())
1606 mySetRotationPointDlg->hide();
1611 \brief Create one more window with same content.
1613 void OCCViewer_ViewWindow::onCloneView()
1615 SUIT_ViewWindow* vw = myManager->createViewWindow();
1617 emit viewCloned( vw );
1621 Creates one more window with same content
1623 void OCCViewer_ViewWindow::onAxialScale()
1625 if ( !myScalingDlg )
1626 myScalingDlg = new OCCViewer_AxialScaleDlg( this );
1628 if ( !myScalingDlg->isVisible() )
1630 myScalingDlg->Update();
1631 myScalingDlg->show();
1636 Shows Graduated Axes dialog
1638 void OCCViewer_ViewWindow::onGraduatedAxes()
1640 myCubeAxesDlg->Update();
1641 myCubeAxesDlg->show();
1644 void OCCViewer_ViewWindow::onAmbientToogle()
1646 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
1647 viewer->InitDefinedLights();
1648 while(viewer->MoreDefinedLights())
1650 Handle(V3d_Light) light = viewer->DefinedLight();
1651 if(light->Type() != V3d_AMBIENT)
1653 Handle(V3d_View) aView3d = myViewPort->getView();
1654 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
1655 else viewer->SetLightOn(light);
1657 viewer->NextDefinedLights();
1663 \brief Store view parameters.
1665 void OCCViewer_ViewWindow::onMemorizeView()
1667 appendViewAspect( getViewParams() );
1671 \brief Restore view parameters.
1673 void OCCViewer_ViewWindow::onRestoreView()
1675 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
1676 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
1678 updateViewAspects( aDlg->parameters() );
1679 if( myRestoreFlag && aDlg->parameters().count() )
1680 performRestoring( aDlg->currentItem() );
1684 \brief Restore view parameters.
1685 \param anItem view parameters
1687 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
1689 Handle(V3d_View) aView3d = myViewPort->getView();
1691 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
1692 aView3d->SetScale( anItem.scale );
1693 aView3d->SetTwist( anItem.twist );
1694 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
1695 aView3d->SetImmediateUpdate( prev );
1696 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1697 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1698 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
1700 #if OCC_VERSION_LARGE > 0x06070100
1701 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
1703 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
1705 // "eye" and "at" require conversion to represent center panning
1706 // up direction is only available after setting angle of twist and
1707 // other view parameters
1708 aView3d->Up( anUpX, anUpY, anUpZ );
1710 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
1711 gp_Dir anUp( anUpX, anUpY, anUpZ );
1712 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
1713 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1714 gp_Dir aSide = aProj ^ anUp;
1716 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
1717 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
1719 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
1720 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1723 aView3d->SetCenter( anItem.centerX, anItem.centerY );
1726 if ( !baseParamsOnly ) {
1728 myModel->setTrihedronShown( anItem.isVisible );
1729 myModel->setTrihedronSize( anItem.size );
1731 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
1732 // graduated trihedron
1733 bool anIsVisible = anItem.gtIsVisible;
1734 OCCViewer_AxisWidget::AxisData anAxisData[3];
1735 anAxisData[0].DrawName = anItem.gtDrawNameX;
1736 anAxisData[1].DrawName = anItem.gtDrawNameZ;
1737 anAxisData[2].DrawName = anItem.gtDrawNameZ;
1738 anAxisData[0].Name = anItem.gtNameX;
1739 anAxisData[1].Name = anItem.gtNameZ;
1740 anAxisData[2].Name = anItem.gtNameZ;
1741 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
1742 anItem.gtNameColorGX,
1743 anItem.gtNameColorBX );
1744 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
1745 anItem.gtNameColorGY,
1746 anItem.gtNameColorBY );
1747 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
1748 anItem.gtNameColorGZ,
1749 anItem.gtNameColorBZ );
1750 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
1751 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
1752 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
1753 anAxisData[0].NbValues = anItem.gtNbValuesX;
1754 anAxisData[1].NbValues = anItem.gtNbValuesY;
1755 anAxisData[2].NbValues = anItem.gtNbValuesZ;
1756 anAxisData[0].Offset = anItem.gtOffsetX;
1757 anAxisData[1].Offset = anItem.gtOffsetY;
1758 anAxisData[2].Offset = anItem.gtOffsetZ;
1759 anAxisData[0].Color = QColor( anItem.gtColorRX,
1762 anAxisData[1].Color = QColor( anItem.gtColorRY,
1765 anAxisData[2].Color = QColor( anItem.gtColorRZ,
1768 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
1769 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
1770 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
1771 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
1772 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
1773 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
1775 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
1776 myCubeAxesDlg->ApplyData( aView3d );
1779 } // if ( !baseParamsOnly )
1785 \brief Set restore flag.
1787 void OCCViewer_ViewWindow::setRestoreFlag()
1793 \brief Called when action "show/hide trihedron" is activated.
1795 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
1797 myModel->setTrihedronShown(show);
1801 \brief Toggles preselection (highlighting) on/off
1803 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
1805 myPreselectionEnabled = on;
1806 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
1808 // unhighlight all highlighted objects
1810 myModel->unHighlightAll( true, false );
1813 // update action state if method is called outside
1814 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
1815 if ( a && a->isChecked() != on ) {
1816 a->setChecked( on );
1821 \brief Toggles selection on/off
1823 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
1825 mySelectionEnabled = on;
1826 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
1828 // update action state if method is called outside
1831 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
1833 a->setEnabled( on );
1837 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
1838 if ( a && a->isChecked() != on ) {
1839 a->setChecked( on );
1844 \brief Switches "keyboard free" interaction style on/off
1846 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
1848 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
1850 // update action state if method is called outside
1851 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
1852 if ( a->isChecked() != on )
1853 a->setChecked( on );
1857 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
1859 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
1861 myViewPort->setAdvancedZoomingEnabled( on );
1863 // update action state if method is called outside
1864 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
1865 if ( a->isChecked() != on )
1866 a->setChecked( on );
1870 \brief Get current interaction style
1871 \return interaction style
1873 int OCCViewer_ViewWindow::interactionStyle() const
1875 return myInteractionStyle;
1879 \brief Set current interaction style
1880 \param theStyle interaction style
1882 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
1884 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
1888 \brief Get current zooming style
1889 \return zooming style
1891 int OCCViewer_ViewWindow::zoomingStyle() const
1893 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
1897 \brief Set current zooming style
1898 \param theStyle zooming style
1900 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
1902 onSwitchZoomingStyle( theStyle == 1 );
1906 \brief Dump view window contents to the pixmap.
1907 \return pixmap containing all scene rendered in the window
1909 QImage OCCViewer_ViewWindow::dumpView()
1911 Handle(V3d_View) view = myViewPort->getView();
1912 if ( view.IsNull() )
1915 int aWidth = myViewPort->width();
1916 int aHeight = myViewPort->height();
1917 QApplication::syncX();
1918 view->Redraw(); // In order to reactivate GL context
1921 OpenGLUtils_FrameBuffer aFrameBuffer;
1922 if( aFrameBuffer.init( aWidth, aHeight ) )
1924 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
1926 glPushAttrib( GL_VIEWPORT_BIT );
1927 glViewport( 0, 0, aWidth, aHeight );
1928 aFrameBuffer.bind();
1933 aFrameBuffer.unbind();
1936 aFrameBuffer.bind();
1937 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
1938 aFrameBuffer.unbind();
1940 anImage = anImage.rgbSwapped();
1941 anImage = anImage.mirrored();
1944 // if frame buffers are unsupported, use old functionality
1947 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
1949 QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
1951 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
1954 QImage anImage( data, aWidth, aHeight, QImage::Format_ARGB32 );
1955 anImage = anImage.mirrored();
1956 anImage = anImage.rgbSwapped();
1960 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
1961 const QString& fileName,
1962 const QString& format )
1964 if ( format != "PS" && format != "EPS")
1965 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
1967 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
1970 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
1971 else if (format == "EPS")
1972 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
1978 QString OCCViewer_ViewWindow::filter() const
1980 return tr( "OCC_IMAGE_FILES" );
1985 \brief Set parameters of the cutting plane
1986 \param on if \c true, cutting plane is enabled
1987 \param x X position of plane point
1988 \param y Y position of plane point
1989 \param z Z position of plane point
1990 \param dx X coordinate of plane normal
1991 \param dy Y coordinate of plane normal
1992 \param dz Z coordinate of plane normal
1994 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
1995 const double dx, const double dy, const double dz )
1997 Handle(V3d_View) view = myViewPort->getView();
1998 if ( view.IsNull() )
2002 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2004 // try to use already existing plane or create a new one
2005 Handle(V3d_Plane) clipPlane;
2007 // calculate new a,b,c,d values for the plane
2008 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2010 pln.Coefficients(a, b, c, d);
2012 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2013 Handle(Graphic3d_ClipPlane) aClipPlane;
2014 if(aPlanes.Size() > 0 ) {
2015 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2016 aClipPlane = anIter.Value();
2017 aClipPlane->SetEquation(pln);
2018 aClipPlane->SetOn(Standard_True);
2020 aClipPlane = new Graphic3d_ClipPlane(pln);
2021 view->AddClipPlane(aClipPlane);
2022 aClipPlane->SetOn(Standard_True);
2026 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2027 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2028 for( ;anIter.More();anIter.Next() ){
2029 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2030 aClipPlane->SetOn(Standard_False);
2038 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2040 gp_Dir aDir = pln.Axis().Direction();
2041 gp_Pnt aPnt = pln.Location();
2042 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2047 \brief Check if any cutting plane is enabled
2048 \return \c true if at least one cutting plane is enabled
2050 bool OCCViewer_ViewWindow::isCuttingPlane()
2052 Handle(V3d_View) view = myViewPort->getView();
2054 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2055 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2056 for( ;anIter.More();anIter.Next() ) {
2057 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2058 if(aClipPlane->IsOn()) {
2067 \brief Get the visual parameters of the view window.
2068 \return visual parameters of view window
2070 viewAspect OCCViewer_ViewWindow::getViewParams() const
2072 double projX, projY, projZ, twist;
2073 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2074 double aScaleX, aScaleY, aScaleZ;
2076 Handle(V3d_View) aView3d = myViewPort->getView();
2078 aView3d->Proj( projX, projY, projZ );
2079 aView3d->At( atX, atY, atZ );
2080 aView3d->Eye( eyeX, eyeY, eyeZ );
2081 twist = aView3d->Twist();
2083 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2085 bool isShown = myModel->isTrihedronVisible();
2086 double size = myModel->trihedronSize();
2088 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2091 params.scale = aView3d->Scale();
2092 params.projX = projX;
2093 params.projY = projY;
2094 params.projZ = projZ;
2095 params.twist = twist;
2102 params.scaleX = aScaleX;
2103 params.scaleY = aScaleY;
2104 params.scaleZ = aScaleZ;
2105 params.name = aName;
2106 params.isVisible= isShown;
2109 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2110 aView3d->Center( params.centerX, params.centerY );
2113 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
2114 // graduated trihedron
2115 bool anIsVisible = false;
2116 OCCViewer_AxisWidget::AxisData anAxisData[3];
2117 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2119 params.gtIsVisible = anIsVisible;
2120 params.gtDrawNameX = anAxisData[0].DrawName;
2121 params.gtDrawNameY = anAxisData[1].DrawName;
2122 params.gtDrawNameZ = anAxisData[2].DrawName;
2123 params.gtNameX = anAxisData[0].Name;
2124 params.gtNameY = anAxisData[1].Name;
2125 params.gtNameZ = anAxisData[2].Name;
2126 params.gtNameColorRX = anAxisData[0].NameColor.red();
2127 params.gtNameColorGX = anAxisData[0].NameColor.green();
2128 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2129 params.gtNameColorRY = anAxisData[1].NameColor.red();
2130 params.gtNameColorGY = anAxisData[1].NameColor.green();
2131 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2132 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2133 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2134 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2135 params.gtDrawValuesX = anAxisData[0].DrawValues;
2136 params.gtDrawValuesY = anAxisData[1].DrawValues;
2137 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2138 params.gtNbValuesX = anAxisData[0].NbValues;
2139 params.gtNbValuesY = anAxisData[1].NbValues;
2140 params.gtNbValuesZ = anAxisData[2].NbValues;
2141 params.gtOffsetX = anAxisData[0].Offset;
2142 params.gtOffsetY = anAxisData[1].Offset;
2143 params.gtOffsetZ = anAxisData[2].Offset;
2144 params.gtColorRX = anAxisData[0].Color.red();
2145 params.gtColorGX = anAxisData[0].Color.green();
2146 params.gtColorBX = anAxisData[0].Color.blue();
2147 params.gtColorRY = anAxisData[1].Color.red();
2148 params.gtColorGY = anAxisData[1].Color.green();
2149 params.gtColorBY = anAxisData[1].Color.blue();
2150 params.gtColorRZ = anAxisData[2].Color.red();
2151 params.gtColorGZ = anAxisData[2].Color.green();
2152 params.gtColorBZ = anAxisData[2].Color.blue();
2153 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2154 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2155 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2156 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2157 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2158 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2165 \brief Get visual parameters of this view window.
2166 \return visual parameters of view window
2168 QString OCCViewer_ViewWindow::getVisualParameters()
2170 viewAspect params = getViewParams();
2174 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2175 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2176 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
2177 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
2179 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2180 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2181 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2182 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2183 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2184 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2185 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2186 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2187 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2188 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2189 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2190 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2191 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2192 data << QString( "isVisible=%1" ).arg( params.isVisible );
2193 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2195 ClipPlanesList aPlanes = myModel->getClipPlanes();
2196 for ( int i=0; i < aPlanes.size(); i++ )
2198 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2199 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2200 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2201 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2202 switch ( aPlane.Mode )
2204 case OCCViewer_ClipPlane::Absolute :
2206 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2208 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2210 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2211 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2212 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2216 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2221 case OCCViewer_ClipPlane::Relative :
2223 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2224 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2225 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2230 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2231 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2232 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2233 data << ClippingPlane;
2237 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 or newer version
2238 // graduated trihedron
2239 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2240 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2241 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2242 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2243 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2244 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2245 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2246 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2247 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2248 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2249 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2250 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2251 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2252 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2253 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2254 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2255 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2256 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2257 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2258 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2259 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2260 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2261 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2262 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2263 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2264 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2265 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2266 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2267 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2268 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2269 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2270 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2271 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2272 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2273 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2274 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2275 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2276 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2277 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2278 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2280 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2281 data << QString( "background=%1" ).arg( bg );
2283 return data.join("*");
2287 \brief Restore visual parameters of the view window.
2288 \param parameters visual parameters of view window
2290 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2293 ClipPlanesList aClipPlanes;
2294 QStringList data = parameters.split( '*' );
2295 Qtx::BackgroundData bgData;
2296 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2298 foreach( QString param, data ) {
2299 QString paramName = param.section( '=', 0, 0 ).trimmed();
2300 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2301 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2302 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2303 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2304 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2305 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2306 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2307 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2308 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2309 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2310 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2311 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2312 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2313 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2314 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2315 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2316 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2317 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2318 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2319 else if ( paramName.contains( "ClippingPlane" ) )
2321 QStringList ClipPlaneData = paramValue.split( ';' );
2322 OCCViewer_ClipPlane aPlane;
2323 foreach( QString ClipPlaneParam, ClipPlaneData )
2325 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2326 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2327 if ( ClipPlane_paramName == "Mode" )
2329 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2331 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2332 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2333 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2334 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2337 switch ( aPlane.Mode )
2339 case OCCViewer_ClipPlane::Absolute :
2340 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2341 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2342 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2343 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2344 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2347 case OCCViewer_ClipPlane::Relative :
2348 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2349 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2350 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2355 aClipPlanes.push_back(aPlane);
2357 // graduated trihedron
2358 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2359 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2360 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2361 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2362 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2363 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2364 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2365 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2366 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2367 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2368 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2369 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2370 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2371 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2372 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2373 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2374 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2375 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2376 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2377 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2378 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2379 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2380 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2381 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2382 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2383 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2384 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2385 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2386 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2387 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2388 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2389 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2390 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2391 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2392 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2393 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2394 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2395 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2396 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2397 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2398 else if ( paramName == "background" ) {
2399 QString bg = paramValue.replace( "$", "=" );
2400 bgData = Qtx::stringToBackground( bg );
2404 else // old format - "1.000e+00*0.000e+00..."
2407 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2408 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2409 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2410 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2411 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2412 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2413 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
2414 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2415 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2416 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
2417 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2418 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2419 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2420 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
2421 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
2422 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
2423 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
2424 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
2426 performRestoring( params );
2427 setBackground( bgData );
2428 myModel->setClipPlanes(aClipPlanes);
2432 \brief Handle show event.
2434 Emits Show() signal.
2436 \param theEvent show event
2438 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2440 emit Show( theEvent );
2444 \brief Handle hide event.
2446 Emits Hide() signal.
2448 \param theEvent hide event
2450 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
2452 emit Hide( theEvent );
2457 Creates default sketcher. [ virtual protected ]
2459 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
2462 return new OCCViewer_RectSketcher( this, type );
2463 if ( type == Polygon )
2464 return new OCCViewer_PolygonSketcher( this, type );
2468 void OCCViewer_ViewWindow::initSketchers()
2470 if ( mySketchers.isEmpty() )
2472 mySketchers.append( createSketcher( Rect ) );
2473 mySketchers.append( createSketcher( Polygon ) );
2477 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
2479 OCCViewer_ViewSketcher* sketcher = 0;
2480 QList<OCCViewer_ViewSketcher*>::Iterator it;
2481 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
2483 OCCViewer_ViewSketcher* sk = (*it);
2484 if ( sk->type() == typ )
2491 Handles requests for sketching in the active view. [ virtual public ]
2493 void OCCViewer_ViewWindow::activateSketching( int type )
2495 OCCViewer_ViewPort3d* vp = getViewPort();
2499 if ( !vp->isSketchingEnabled() )
2502 /* Finish current sketching */
2503 if ( type == NoSketching )
2507 onSketchingFinished();
2508 mypSketcher->deactivate();
2512 /* Activate new sketching */
2515 activateSketching( NoSketching ); /* concurrency not suported */
2516 mypSketcher = getSketcher( type );
2519 mypSketcher->activate();
2520 onSketchingStarted();
2526 Unhilights detected entities. [ virtual protected ]
2528 void OCCViewer_ViewWindow::onSketchingStarted()
2533 Selection by rectangle or polygon. [ virtual protected ]
2535 void OCCViewer_ViewWindow::onSketchingFinished()
2537 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
2538 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
2540 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
2541 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
2542 switch( mypSketcher->type() )
2546 QRect* aRect = (QRect*)mypSketcher->data();
2549 int aLeft = aRect->left();
2550 int aRight = aRect->right();
2551 int aTop = aRect->top();
2552 int aBottom = aRect->bottom();
2556 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2558 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2564 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
2567 int size = aPolygon->size();
2568 TColgp_Array1OfPnt2d anArray( 1, size );
2570 QPolygon::Iterator it = aPolygon->begin();
2571 QPolygon::Iterator itEnd = aPolygon->end();
2572 for( int index = 1; it != itEnd; ++it, index++ )
2574 QPoint aPoint = *it;
2575 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
2579 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
2581 ic->Select( anArray, getViewPort()->getView(), Standard_False );
2589 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
2590 aViewMgr->getOCCViewer()->performSelectionChanged();
2594 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
2599 bool OCCViewer_ViewWindow::transformRequested() const
2601 return ( myOperation != NOTHING );
2604 bool OCCViewer_ViewWindow::transformInProcess() const
2606 return myEventStarted;
2609 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
2611 myEventStarted = bOn;
2615 Set enabled state of transformation (rotate, zoom, etc)
2617 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
2619 if ( id != NOTHING ) myStatus.insert( id, on );
2623 \return enabled state of transformation (rotate, zoom, etc)
2625 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
2627 return myStatus.contains( id ) ? myStatus[ id ] : true;
2630 void OCCViewer_ViewWindow::onMaximizedView()
2632 setMaximized(!isMaximized());
2635 void OCCViewer_ViewWindow::returnTo3dView()
2637 setReturnedTo3dView( true );
2640 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
2642 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
2643 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
2644 if ( !isVisible3dView )
2645 toolMgr()->show( ReturnTo3dViewId );
2647 toolMgr()->hide( ReturnTo3dViewId );
2648 if ( isVisible3dView ) emit returnedTo3d( );
2652 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
2654 QAction* anAction = toolMgr()->action( MaximizedId );
2655 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
2656 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
2658 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
2659 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
2660 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
2661 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
2662 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
2664 emit maximized( this, true );
2668 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
2669 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
2670 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
2671 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
2672 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
2674 emit maximized( this, false );
2679 bool OCCViewer_ViewWindow::isMaximized() const
2681 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
2684 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
2686 IsSketcherStyle = enable;
2689 bool OCCViewer_ViewWindow::isSketcherStyle() const
2691 return IsSketcherStyle;
2695 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
2701 QColor OCCViewer_ViewWindow::backgroundColor() const
2703 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
2707 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
2709 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
2712 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
2714 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
2717 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
2719 if ( myViewPort ) myViewPort->setBackground( theBackground );
2722 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
2724 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
2730 void OCCViewer_ViewWindow::clearViewAspects()
2732 myViewAspects.clear();
2736 \return const reference to list of view aspects
2738 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
2740 return myViewAspects;
2744 Appends new view aspect
2745 \param aParams - new view aspects
2747 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
2749 myViewAspects.append( aParams );
2753 Replaces old view aspects by new ones
2754 \param aViewList - list of new view aspects
2756 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
2758 myViewAspects = aViewList;
2762 Get camera properties for the OCC view window.
2763 \return shared pointer on camera properties.
2765 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
2767 SUIT_CameraProperties aProps;
2769 Handle(V3d_View) aSourceView = getViewPort()->getView();
2770 if ( aSourceView.IsNull() )
2773 if ( get2dMode() == No2dMode ) {
2774 aProps.setDimension( SUIT_CameraProperties::Dim3D );
2777 aProps.setDimension( SUIT_CameraProperties::Dim2D );
2778 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
2781 // read common properites of the view
2782 Standard_Real anUp[3];
2783 Standard_Real anAt[3];
2784 Standard_Real anEye[3];
2785 Standard_Real aProj[3];
2786 Standard_Real anAxialScale[3];
2788 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
2789 aSourceView->At( anAt[0], anAt[1], anAt[2] );
2790 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
2791 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2793 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2794 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
2796 #if OCC_VERSION_LARGE > 0x06070100
2797 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
2799 // store camera properties "as is": it is up to synchronized
2800 // view classes to provide necessary property conversion.
2801 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
2802 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
2804 if ( aSourceView->Camera()->IsOrthographic() )
2806 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
2807 aProps.setViewAngle( 0.0 );
2811 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
2812 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
2814 aProps.setMappingScale( aSourceView->Camera()->Scale() );
2816 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
2818 // generate view orientation matrix for transforming OCC projection reference point
2819 // into a camera (eye) position.
2820 gp_Dir aLeftDir = gp_Dir( anUp[0], anUp[1], anUp[2] ) ^ gp_Dir( aProj[0], aProj[1], aProj[2] );
2823 aTrsf.SetValue( 1, 1, aLeftDir.X() );
2824 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
2825 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
2827 aTrsf.SetValue( 1, 2, anUp[0] );
2828 aTrsf.SetValue( 2, 2, anUp[1] );
2829 aTrsf.SetValue( 3, 2, anUp[2] );
2831 aTrsf.SetValue( 1, 3, aProj[0] );
2832 aTrsf.SetValue( 2, 3, aProj[1] );
2833 aTrsf.SetValue( 3, 3, aProj[2] );
2835 aTrsf.SetValue( 1, 4, anAt[0] );
2836 aTrsf.SetValue( 2, 4, anAt[1] );
2837 aTrsf.SetValue( 3, 4, anAt[2] );
2839 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
2841 // transform to world-space coordinate system
2842 gp_XYZ aPosition( aProjRef.X(), aProjRef.Y(), aCameraDepth );
2843 aTrsf.Transforms( aPosition );
2845 // compute focal point
2846 double aFocalPoint[3];
2848 aFocalPoint[0] = aPosition.X() - aProj[0] * aCameraDepth;
2849 aFocalPoint[1] = aPosition.Y() - aProj[1] * aCameraDepth;
2850 aFocalPoint[2] = aPosition.Z() - aProj[2] * aCameraDepth;
2852 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2853 aProps.setPosition( aPosition.X(), aPosition.Y(), aPosition.Z() );
2855 Standard_Real aViewScale[2];
2856 aSourceView->Size( aViewScale[0], aViewScale[1] );
2857 aProps.setMappingScale( aViewScale[1] );
2865 This implementation synchronizes OCC view's camera propreties.
2867 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
2869 bool blocked = blockSignals( true );
2871 SUIT_CameraProperties aProps = theView->cameraProperties();
2872 if ( !cameraProperties().isCompatible( aProps ) ) {
2873 // other view, this one is being currently synchronized to, seems has become incompatible
2874 // we have to break synchronization
2879 Handle(V3d_View) aDestView = getViewPort()->getView();
2881 aDestView->SetImmediateUpdate( Standard_False );
2884 double aPosition[3];
2885 double aFocalPoint[3];
2886 double anAxialScale[3];
2888 // get common properties
2889 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2890 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
2891 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2892 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2894 #if OCC_VERSION_LARGE > 0x06070100
2895 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2896 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
2897 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2898 aDestView->Camera()->SetScale( aProps.getMappingScale() );
2900 gp_Dir aProjDir( aPosition[0] - aFocalPoint[0],
2901 aPosition[1] - aFocalPoint[1],
2902 aPosition[2] - aFocalPoint[2] );
2904 // get custom view translation
2905 Standard_Real aTranslation[3];
2906 aDestView->At( aTranslation[0], aTranslation[1], aTranslation[2] );
2908 gp_Dir aLeftDir = gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] )
2909 ^ gp_Dir( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
2912 aTrsf.SetValue( 1, 1, aLeftDir.X() );
2913 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
2914 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
2916 aTrsf.SetValue( 1, 2, anUpDir[0] );
2917 aTrsf.SetValue( 2, 2, anUpDir[1] );
2918 aTrsf.SetValue( 3, 2, anUpDir[2] );
2920 aTrsf.SetValue( 1, 3, aProjDir.X() );
2921 aTrsf.SetValue( 2, 3, aProjDir.Y() );
2922 aTrsf.SetValue( 3, 3, aProjDir.Z() );
2924 aTrsf.SetValue( 1, 4, aTranslation[0] );
2925 aTrsf.SetValue( 2, 4, aTranslation[1] );
2926 aTrsf.SetValue( 3, 4, aTranslation[2] );
2929 // transform to view-space coordinate system
2930 gp_XYZ aProjRef( aPosition[0], aPosition[1], aPosition[2] );
2931 aTrsf.Transforms( aProjRef );
2933 // set view camera properties using low-level approach. this is done
2934 // in order to avoid interference with static variables in v3d view used
2935 // when rotation is in process in another view.
2936 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
2937 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
2939 Graphic3d_Vector aMappingProj( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
2940 Graphic3d_Vector aMappingUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2942 aMappingProj.Normalize();
2943 aMappingUp.Normalize();
2945 anOrientation.SetViewReferencePlane( aMappingProj );
2946 anOrientation.SetViewReferenceUp( aMappingUp );
2948 aDestView->SetViewMapping( aMapping );
2949 aDestView->SetViewOrientation( anOrientation );
2952 aDestView->SetCenter( aProjRef.X(), aProjRef.Y() );
2954 // set mapping scale
2955 double aMapScaling = aProps.getMappingScale();
2956 Standard_Real aWidth, aHeight;
2957 aDestView->Size( aWidth, aHeight );
2958 aDestView->SetSize ( aWidth > aHeight ? aMapScaling * (aWidth / aHeight) : aMapScaling );
2961 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2963 aDestView->ZFitAll();
2964 aDestView->SetImmediateUpdate( Standard_True );
2965 aDestView->Redraw();
2967 blockSignals( blocked );
2971 \brief Indicates whether preselection is enabled
2972 \return true if preselection is enabled
2974 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
2976 return myPreselectionEnabled;
2980 \brief Enables/disables preselection
2981 \param theIsToEnable if true - preselection will be enabled
2983 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
2985 onSwitchPreselection( theIsToEnable );
2989 \brief Indicates whether selection is enabled
2990 \return true if selection is enabled
2992 bool OCCViewer_ViewWindow::isSelectionEnabled() const
2994 return mySelectionEnabled;
2998 \brief Enables/disables selection
2999 \param theIsToEnable if true - selection will be enabled
3001 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3003 onSwitchSelection( theIsToEnable );
3008 \brief called if clipping operation is activated / deactivated.
3010 Enables/disables clipping plane displaying.
3012 \parma on action state
3014 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3016 if(!myModel) return;
3017 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3020 if (!aClippingDlg) {
3021 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3022 myModel->setClippingDlg(aClippingDlg);
3024 if (!aClippingDlg->isVisible())
3025 aClippingDlg->show();
3027 if ( aClippingDlg ) {
3028 aClippingDlg->close();
3029 myModel->setClippingDlg(0);
3033 SUIT_ViewManager* mgr = getViewManager();
3035 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3036 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3037 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3038 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3040 QAction* a = toolMgr()->action( ClippingId );
3042 if(theIsOn != a->isChecked()){
3043 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3044 a->setChecked(theIsOn);
3045 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));