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 #include <Graphic3d_SequenceOfHClipPlane.hxx>
87 #include <Graphic3d_ClipPlane.hxx>
89 #include <Image_PixMap.hxx>
91 #include <Standard_Version.hxx>
93 #include "utilities.h"
97 // #include <highgui.h>
99 static QEvent* l_mbPressEvent = 0;
102 # include <QWindowsStyle>
107 const char* imageZoomCursor[] = {
112 "................................",
113 "................................",
114 ".#######........................",
115 "..aaaaaaa.......................",
116 "................................",
117 ".............#####..............",
118 "...........##.aaaa##............",
119 "..........#.aa.....a#...........",
120 ".........#.a.........#..........",
121 ".........#a..........#a.........",
122 "........#.a...........#.........",
123 "........#a............#a........",
124 "........#a............#a........",
125 "........#a............#a........",
126 "........#a............#a........",
127 ".........#...........#.a........",
128 ".........#a..........#a.........",
129 ".........##.........#.a.........",
130 "........#####.....##.a..........",
131 ".......###aaa#####.aa...........",
132 "......###aa...aaaaa.......#.....",
133 ".....###aa................#a....",
134 "....###aa.................#a....",
135 "...###aa...............#######..",
136 "....#aa.................aa#aaaa.",
137 ".....a....................#a....",
138 "..........................#a....",
139 "...........................a....",
140 "................................",
141 "................................",
142 "................................",
143 "................................"};
145 const char* imageRotateCursor[] = {
150 "................................",
151 "................................",
152 "................................",
153 "................................",
154 "........#.......................",
155 ".......#.a......................",
156 "......#######...................",
157 ".......#aaaaa#####..............",
158 "........#..##.a#aa##........##..",
159 ".........a#.aa..#..a#.....##.aa.",
160 ".........#.a.....#...#..##.aa...",
161 ".........#a.......#..###.aa.....",
162 "........#.a.......#a..#aa.......",
163 "........#a.........#..#a........",
164 "........#a.........#a.#a........",
165 "........#a.........#a.#a........",
166 "........#a.........#a.#a........",
167 ".........#.........#a#.a........",
168 "........##a........#a#a.........",
169 "......##.a#.......#.#.a.........",
170 "....##.aa..##.....##.a..........",
171 "..##.aa.....a#####.aa...........",
172 "...aa.........aaa#a.............",
173 "................#.a.............",
174 "...............#.a..............",
175 "..............#.a...............",
176 "...............a................",
177 "................................",
178 "................................",
179 "................................",
180 "................................",
181 "................................"};
183 const char* imageCrossCursor[] = {
188 "................................",
189 "................................",
190 "................................",
191 "................................",
192 "................................",
193 "................................",
194 "................................",
195 "...............#................",
196 "...............#a...............",
197 "...............#a...............",
198 "...............#a...............",
199 "...............#a...............",
200 "...............#a...............",
201 "...............#a...............",
202 "...............#a...............",
203 ".......#################........",
204 "........aaaaaaa#aaaaaaaaa.......",
205 "...............#a...............",
206 "...............#a...............",
207 "...............#a...............",
208 "...............#a...............",
209 "...............#a...............",
210 "...............#a...............",
211 "...............#a...............",
212 "................a...............",
213 "................................",
214 "................................",
215 "................................",
216 "................................",
217 "................................",
218 "................................",
219 "................................"};
224 \param theDesktop main window of application
225 \param theModel OCC 3D viewer
227 OCCViewer_ViewWindow::OCCViewer_ViewWindow( SUIT_Desktop* theDesktop,
228 OCCViewer_Viewer* theModel )
229 : SUIT_ViewWindow( theDesktop )
233 myEnableDrawMode = false;
235 updateEnabledDrawMode();
237 mySetRotationPointDlg = 0;
240 IsSketcherStyle = false;
247 myInteractionStyle = SUIT_ViewModel::STANDARD;
248 myPreselectionEnabled = true;
249 mySelectionEnabled = true;
259 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
262 qDeleteAll( mySketchers );
266 \brief Internal initialization.
268 void OCCViewer_ViewWindow::initLayout()
270 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
271 myViewPort->installEventFilter(this);
272 setCentralWidget(myViewPort);
273 myOperation = NOTHING;
275 myCurrPointType = GRAVITY;
276 myPrevPointType = GRAVITY;
277 mySelectedPoint = gp_Pnt(0.,0.,0.);
278 myRotationPointSelection = false;
280 setTransformRequested ( NOTHING );
281 setTransformInProcess ( false );
298 // Graduated axes dialog
299 QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
300 myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
301 myCubeAxesDlg->initialize();
303 connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
306 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
308 return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
312 \brief Detect viewer operation according the the mouse button pressed
313 and key modifiers used.
314 \param theEvent mouse event
315 \return type of the operation
317 OCCViewer_ViewWindow::OperationType
318 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
320 OperationType aOp = NOTHING;
321 SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
322 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
323 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
325 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
326 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
328 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
329 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
330 (my2dMode == No2dMode))
337 \brief Customize event handling
338 \param watched event receiver object
340 \return \c true if the event processing should be stopped
342 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
344 if ( watched == myViewPort ) {
345 int aType = e->type();
347 case QEvent::MouseButtonPress:
348 vpMousePressEvent((QMouseEvent*) e);
351 case QEvent::MouseButtonRelease:
352 vpMouseReleaseEvent((QMouseEvent*) e);
355 case QEvent::MouseMove:
356 vpMouseMoveEvent((QMouseEvent*) e);
359 case QEvent::MouseButtonDblClick:
360 emit mouseDoubleClicked(this, (QMouseEvent*)e);
365 QWheelEvent* aEvent = (QWheelEvent*) e;
366 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
367 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
370 int x1 = (int)( aEvent->x() + width()*delta/100 );
371 int y1 = (int)( aEvent->y() + height()*delta/100 );
372 myViewPort->zoom( x, y, x1, y1 );
373 myViewPort->getView()->ZFitAll();
377 case QEvent::ContextMenu:
379 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
380 if ( aEvent->reason() != QContextMenuEvent::Mouse )
381 emit contextMenuRequested( aEvent );
385 case QEvent::KeyPress:
386 emit keyPressed(this, (QKeyEvent*) e);
393 return SUIT_ViewWindow::eventFilter(watched, e);
397 \brief Update state of enable draw mode state.
399 void OCCViewer_ViewWindow::updateEnabledDrawMode()
402 myEnableDrawMode = myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
406 \brief Handle mouse press event
407 \param theEvent mouse event
409 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
411 myStartX = theEvent->x();
412 myStartY = theEvent->y();
413 int anInteractionStyle = interactionStyle();
415 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
416 // which are assigned for pan and rotate - these operations are activated immediately after pressing
417 // of the first button, so it is necessary to switch to zoom when the second button is pressed
418 bool aSwitchToZoom = false;
419 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
420 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
421 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
424 switch ( myOperation ) {
426 if ( theEvent->button() == Qt::LeftButton )
427 emit vpTransformationStarted ( WINDOWFIT );
431 if ( theEvent->button() == Qt::LeftButton )
432 emit vpTransformationStarted ( PANGLOBAL );
436 if ( theEvent->button() == Qt::LeftButton ) {
437 myViewPort->startZoomAtPoint( myStartX, myStartY );
438 emit vpTransformationStarted ( ZOOMVIEW );
443 if ( aSwitchToZoom ) {
444 myViewPort->startZoomAtPoint( myStartX, myStartY );
447 else if ( theEvent->button() == Qt::LeftButton )
448 emit vpTransformationStarted ( PANVIEW );
452 if ( aSwitchToZoom ) {
453 myViewPort->startZoomAtPoint( myStartX, myStartY );
456 else if ( theEvent->button() == Qt::LeftButton ) {
457 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
458 emit vpTransformationStarted ( ROTATE );
463 /* Try to activate a transformation */
464 OperationType aState;
465 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
466 aState = getButtonState(theEvent, anInteractionStyle);
468 aState = OCCViewer_ViewWindow::NOTHING;
473 myViewPort->startZoomAtPoint( myStartX, myStartY );
481 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
484 if ( myRotationPointSelection )
486 if ( theEvent->button() == Qt::LeftButton )
488 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
490 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
492 TopoDS_Shape aShape = ic->SelectedShape();
493 GProp_GProps aSystem;
495 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
497 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
499 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE )
501 BRepGProp::LinearProperties( aShape, aSystem );
502 aPnt = aSystem.CentreOfMass();
504 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE )
506 BRepGProp::SurfaceProperties( aShape, aSystem );
507 aPnt = aSystem.CentreOfMass();
509 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID )
511 BRepGProp::VolumeProperties( aShape, aSystem );
512 aPnt = aSystem.CentreOfMass();
516 myCurrPointType = myPrevPointType;
520 if ( mySetRotationPointDlg )
522 myRotationPointSelection = false;
523 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
526 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
527 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
528 ic->CloseAllContexts();
529 myOperation = NOTHING;
530 myViewPort->setCursor( myCursor );
531 myCursorIsHand = false;
532 myRotationPointSelection = false;
536 emit mousePressed(this, theEvent);
539 /* notify that we start a transformation */
540 if ( transformRequested() )
541 emit vpTransformationStarted ( myOperation );
543 if ( transformRequested() )
544 setTransformInProcess( true );
546 /* we may need it for sketching... */
547 if ( l_mbPressEvent )
548 delete l_mbPressEvent;
549 l_mbPressEvent = new QMouseEvent( *theEvent );
554 \brief Start zooming operation.
556 Sets the corresponding cursor for the widget.
558 void OCCViewer_ViewWindow::activateZoom()
560 if ( !transformRequested() && !myCursorIsHand )
561 myCursor = cursor(); /* save old cursor */
563 if ( myOperation != ZOOMVIEW ) {
564 QPixmap zoomPixmap (imageZoomCursor);
565 QCursor zoomCursor (zoomPixmap);
566 if( setTransformRequested ( ZOOMVIEW ) )
567 myViewPort->setCursor( zoomCursor );
573 \brief Start panning operation.
575 Sets the corresponding cursor for the widget.
577 void OCCViewer_ViewWindow::activatePanning()
579 if ( !transformRequested() && !myCursorIsHand )
580 myCursor = cursor(); // save old cursor
582 if ( myOperation != PANVIEW ) {
583 QCursor panCursor (Qt::SizeAllCursor);
584 if( setTransformRequested ( PANVIEW ) )
585 myViewPort->setCursor( panCursor );
590 \brief Start rotation operation
592 Sets the corresponding cursor for the widget.
594 void OCCViewer_ViewWindow::activateRotation()
596 if ( !transformRequested() && !myCursorIsHand )
597 myCursor = cursor(); // save old cursor
599 if ( myOperation != ROTATE ) {
600 QPixmap rotatePixmap (imageRotateCursor);
601 QCursor rotCursor (rotatePixmap);
602 if( setTransformRequested ( ROTATE ) )
603 myViewPort->setCursor( rotCursor );
608 \brief Compute the gravity center.
609 \param theX used to return X coordinate of the gravity center
610 \param theY used to return Y coordinate of the gravity center
611 \param theZ used to return Z coordinate of the gravity center
612 \return \c true if the gravity center is computed
614 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
616 Handle(V3d_View) aView3d = myViewPort->getView();
618 // Project boundaries points and add to avergae gravity
619 // the ones which lie within the screen limits
620 Standard_Real aScreenLimits[4] = { 0.0, 0.0, 0.0, 0.0 };
622 #if OCC_VERSION_LARGE > 0x06070100
623 // NDC space screen limits
624 aScreenLimits[0] = -1.0;
625 aScreenLimits[1] = 1.0;
626 aScreenLimits[2] = -1.0;
627 aScreenLimits[3] = 1.0;
629 aView3d->View()->ViewMapping().WindowLimit( aScreenLimits[0],
635 Standard_Integer aPointsNb = 0;
637 Standard_Real aXmin = 0.0;
638 Standard_Real aYmin = 0.0;
639 Standard_Real aZmin = 0.0;
640 Standard_Real aXmax = 0.0;
641 Standard_Real aYmax = 0.0;
642 Standard_Real aZmax = 0.0;
644 Graphic3d_MapOfStructure aSetOfStructures;
645 aView3d->View()->DisplayedStructures( aSetOfStructures );
646 Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures );
648 for( ; aStructureIt.More(); aStructureIt.Next() ) {
649 const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key();
650 if ( aStructure->IsEmpty() ) {
654 #if OCC_VERSION_LARGE > 0x06070100
655 Bnd_Box aBox = aStructure->MinMaxValues();
656 aXmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().X();
657 aYmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Y();
658 aZmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Z();
659 aXmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().X();
660 aYmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Y();
661 aZmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Z();
663 aStructure->MinMaxValues( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
666 // Infinite structures are skipped
667 Standard_Real aLIM = ShortRealLast() - 1.0;
668 if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
669 || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
673 gp_Pnt aPoints[8] = {
674 gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
675 gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
676 gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
677 gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
680 for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
681 const gp_Pnt& aBBPoint = aPoints[aPointIt];
683 #if OCC_VERSION_LARGE > 0x06070100
684 gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
685 const Standard_Real& U = aProjected.X();
686 const Standard_Real& V = aProjected.Y();
688 Standard_Real U = 0.0;
689 Standard_Real V = 0.0;
690 Standard_Real W = 0.0;
691 aView3d->View()->Projects( aBBPoint.X(), aBBPoint.Y(), aBBPoint.Z(), U, V, W );
694 if (U >= aScreenLimits[0]
695 && U <= aScreenLimits[1]
696 && V >= aScreenLimits[2]
697 && V <= aScreenLimits[3])
700 theX += aBBPoint.X();
701 theY += aBBPoint.Y();
702 theZ += aBBPoint.Z();
717 \brief Set the gravity center as a rotation point.
719 void OCCViewer_ViewWindow::activateSetRotationGravity()
721 if ( myRotationPointSelection )
723 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
724 ic->CloseAllContexts();
725 myOperation = NOTHING;
726 myViewPort->setCursor( myCursor );
727 myCursorIsHand = false;
728 myRotationPointSelection = false;
731 myPrevPointType = myCurrPointType;
732 myCurrPointType = GRAVITY;
734 Standard_Real Xcenter, Ycenter, Zcenter;
735 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
736 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
740 \brief Update gravity center in the "Set Rotation Point" dialog box.
741 \sa OCCViewer_SetRotationPointDlg class
743 void OCCViewer_ViewWindow::updateGravityCoords()
745 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == GRAVITY )
747 Standard_Real Xcenter, Ycenter, Zcenter;
748 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
749 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
754 \brief Set the point selected by the user as a rotation point.
755 \param theX X coordinate of the rotation point
756 \param theY Y coordinate of the rotation point
757 \param theZ Z coordinate of the rotation point
759 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
761 if ( myRotationPointSelection )
763 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
764 ic->CloseAllContexts();
765 myOperation = NOTHING;
766 myViewPort->setCursor( myCursor );
767 myCursorIsHand = false;
768 myRotationPointSelection = false;
771 myPrevPointType = myCurrPointType;
772 myCurrPointType = SELECTED;
773 mySelectedPoint.SetCoord(theX,theY,theZ);
777 \brief Start the shape selection process.
779 void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
781 myPrevPointType = myCurrPointType;
782 myCurrPointType = SELECTED;
784 // activate selection ------>
785 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
787 ic->OpenLocalContext();
789 AIS_ListOfInteractive aList;
790 ic->DisplayedObjects( aList );
791 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
793 Handle(AIS_InteractiveObject) anObj = it.Value();
794 if ( !anObj.IsNull() && anObj->HasPresentation() &&
795 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
798 ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
801 // activate selection <------
803 if ( !myCursorIsHand )
805 QCursor handCursor (Qt::PointingHandCursor);
806 myCursorIsHand = true;
808 myViewPort->setCursor( handCursor );
810 myRotationPointSelection = true;
814 \brief Start global panning operation
816 Sets the corresponding cursor for the widget.
818 void OCCViewer_ViewWindow::activateGlobalPanning()
820 Handle(V3d_View) aView3d = myViewPort->getView();
821 if ( !aView3d.IsNull() ) {
822 QPixmap globalPanPixmap (imageCrossCursor);
823 QCursor glPanCursor (globalPanPixmap);
824 myCurScale = aView3d->Scale();
825 aView3d->FitAll(0.01, false);
826 myCursor = cursor(); // save old cursor
827 myViewPort->fitAll(); // fits view before selecting a new scene center
828 if( setTransformRequested( PANGLOBAL ) )
829 myViewPort->setCursor( glPanCursor );
834 \brief Starts fit operation.
836 Sets the corresponding cursor for the widget.
838 void OCCViewer_ViewWindow::activateWindowFit()
840 if ( !transformRequested() && !myCursorIsHand )
841 myCursor = cursor(); /* save old cursor */
843 if ( myOperation != WINDOWFIT ) {
844 QCursor handCursor (Qt::PointingHandCursor);
845 if( setTransformRequested ( WINDOWFIT ) )
847 myViewPort->setCursor ( handCursor );
848 myCursorIsHand = true;
854 \brief Start delayed viewer operation.
856 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
858 bool ok = transformEnabled( op );
859 myOperation = ok ? op : NOTHING;
860 myViewPort->setMouseTracking( myOperation == NOTHING );
865 \brief Handle mouse move event.
866 \param theEvent mouse event
868 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
870 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
872 switch ( getButtonState( theEvent, interactionStyle() ) ) {
874 myViewPort->startZoomAtPoint( myStartX, myStartY );
882 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
889 myCurrX = theEvent->x();
890 myCurrY = theEvent->y();
891 switch (myOperation) {
893 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
897 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
903 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
917 if ( myRotationPointSelection || isSketcherStyle() )
919 emit mouseMoving( this, theEvent );
923 int aState = theEvent->modifiers();
924 int aButton = theEvent->buttons();
925 int anInteractionStyle = interactionStyle();
926 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
927 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
928 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
929 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
930 myDrawRect = myEnableDrawMode;
933 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
934 QCursor handCursor (Qt::PointingHandCursor);
935 myCursorIsHand = true;
937 myViewPort->setCursor( handCursor );
940 emit mouseMoving( this, theEvent );
942 else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
943 aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
944 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
945 aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
946 OCCViewer_ViewSketcher* sketcher = 0;
947 QList<OCCViewer_ViewSketcher*>::Iterator it;
948 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
950 OCCViewer_ViewSketcher* sk = (*it);
951 if( sk->isDefault() && sk->sketchButton() == aButton )
954 if ( sketcher && myCurSketch == -1 )
956 activateSketching( sketcher->type() );
959 myCurSketch = mypSketcher->sketchButton();
961 if ( l_mbPressEvent )
963 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
964 delete l_mbPressEvent;
967 QApplication::sendEvent( getViewPort(), theEvent );
972 emit mouseMoving( this, theEvent );
978 \brief Handle mouse release event.
979 \param theEvent mouse event
981 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
983 switch ( myOperation ) {
986 int prevState = myCurSketch;
987 if(theEvent->button() == Qt::RightButton)
989 QList<OCCViewer_ViewSketcher*>::Iterator it;
990 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
992 OCCViewer_ViewSketcher* sk = (*it);
993 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
998 emit mouseReleased(this, theEvent);
999 if(theEvent->button() == Qt::RightButton && prevState == -1)
1001 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1002 theEvent->pos(), theEvent->globalPos() );
1003 emit contextMenuRequested( &aEvent );
1008 myViewPort->endRotation();
1014 myViewPort->getView()->ZFitAll();
1019 if ( theEvent->button() == Qt::LeftButton ) {
1020 myViewPort->setCenter( theEvent->x(), theEvent->y() );
1021 myViewPort->getView()->SetScale(myCurScale);
1027 if ( theEvent->button() == Qt::LeftButton ) {
1028 myCurrX = theEvent->x();
1029 myCurrY = theEvent->y();
1031 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1032 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1039 // NOTE: viewer 3D detects a rectangle of selection using this event
1040 // so we must emit it BEFORE resetting the selection rectangle
1042 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1046 myViewPort->update();
1049 if ( l_mbPressEvent )
1051 delete l_mbPressEvent;
1057 \brief Reset the viewport to its initial state
1058 ( no transformations in process etc. )
1060 void OCCViewer_ViewWindow::resetState()
1064 if ( myRotationPointSelection )
1066 QCursor handCursor (Qt::PointingHandCursor);
1067 myViewPort->setCursor( handCursor );
1071 if ( transformRequested() || myCursorIsHand )
1072 myViewPort->setCursor( myCursor );
1073 myCursorIsHand = false;
1076 if ( transformRequested() )
1077 emit vpTransformationFinished (myOperation);
1079 setTransformInProcess( false );
1080 setTransformRequested( NOTHING );
1085 \brief Draw rubber band rectangle.
1087 void OCCViewer_ViewWindow::drawRect()
1089 if ( !myRectBand ) {
1090 myRectBand = new QtxRectRubberBand( myViewPort );
1092 //palette.setColor(myRectBand->foregroundRole(), Qt::white);
1093 //myRectBand->setPalette(palette);
1095 //myRectBand->hide();
1097 myRectBand->setUpdatesEnabled ( false );
1098 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1099 myRectBand->initGeometry( aRect );
1101 if ( !myRectBand->isVisible() )
1104 myRectBand->setUpdatesEnabled ( true );
1105 //myRectBand->repaint();
1107 //myRectBand->setVisible( aRect.isValid() );
1108 //if ( myRectBand->isVisible() )
1109 // myRectBand->repaint();
1111 // myRectBand->show();
1112 //myRectBand->repaint();
1116 \brief Clear rubber band rectangle on the end on the dragging operation.
1118 void OCCViewer_ViewWindow::endDrawRect()
1120 //delete myRectBand;
1124 myRectBand->clearGeometry();
1130 \brief Create actions.
1132 void OCCViewer_ViewWindow::createActions()
1134 if( !toolMgr()->isEmpty() )
1137 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1142 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1143 tr( "MNU_DUMP_VIEW" ), 0, this);
1144 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1145 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1146 toolMgr()->registerAction( aAction, DumpId );
1149 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1150 tr( "MNU_FITALL" ), 0, this);
1151 aAction->setStatusTip(tr("DSC_FITALL"));
1152 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1153 toolMgr()->registerAction( aAction, FitAllId );
1156 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1157 tr( "MNU_FITRECT" ), 0, this);
1158 aAction->setStatusTip(tr("DSC_FITRECT"));
1159 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1160 toolMgr()->registerAction( aAction, FitRectId );
1163 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1164 tr( "MNU_ZOOM_VIEW" ), 0, this);
1165 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1166 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1167 toolMgr()->registerAction( aAction, ZoomId );
1170 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1171 tr( "MNU_PAN_VIEW" ), 0, this);
1172 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1173 connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
1174 toolMgr()->registerAction( aAction, PanId );
1177 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1178 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1179 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1180 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1181 toolMgr()->registerAction( aAction, GlobalPanId );
1184 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1185 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1186 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1187 mySetRotationPointAction->setCheckable( true );
1188 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1189 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1192 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1193 tr( "MNU_ROTATE_VIEW" ), 0, this);
1194 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1195 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1196 toolMgr()->registerAction( aAction, RotationId );
1199 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1200 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1201 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1202 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1203 this->addAction(aAction);
1204 toolMgr()->registerAction( aAction, FrontId );
1206 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1207 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1208 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1209 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1210 this->addAction(aAction);
1211 toolMgr()->registerAction( aAction, BackId );
1213 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1214 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1215 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1216 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1217 this->addAction(aAction);
1218 toolMgr()->registerAction( aAction, TopId );
1220 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1221 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1222 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1223 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1224 this->addAction(aAction);
1225 toolMgr()->registerAction( aAction, BottomId );
1227 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1228 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1229 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1230 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1231 this->addAction(aAction);
1232 toolMgr()->registerAction( aAction, LeftId );
1234 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1235 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1236 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1237 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1238 this->addAction(aAction);
1239 toolMgr()->registerAction( aAction, RightId );
1241 // rotate anticlockwise
1242 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1243 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1244 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1245 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1246 this->addAction(aAction);
1247 toolMgr()->registerAction( aAction, AntiClockWiseId );
1250 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1251 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1252 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1253 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1254 this->addAction(aAction);
1255 toolMgr()->registerAction( aAction, ClockWiseId );
1258 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1259 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1260 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1261 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1262 this->addAction(aAction);
1263 toolMgr()->registerAction( aAction, ResetId );
1266 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1267 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1268 tr("MNU_CLONE_VIEW"), 0, this);
1269 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1270 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1271 toolMgr()->registerAction( aAction, CloneId );
1273 aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
1274 tr("MNU_CLIPPING"), 0, this);
1275 aAction->setStatusTip (tr("DSC_CLIPPING"));
1276 aAction->setCheckable (true);
1277 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1278 toolMgr()->registerAction (aAction, ClippingId);
1280 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1281 tr( "MNU_SHOOT_VIEW" ), 0, this);
1282 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1283 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1284 toolMgr()->registerAction( aAction, MemId );
1286 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1287 tr( "MNU_PRESETS_VIEW" ), 0, this);
1288 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1289 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1290 toolMgr()->registerAction( aAction, RestoreId );
1292 if (myModel->trihedronActivated()) {
1293 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1294 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1295 aAction->setCheckable( true );
1296 aAction->setChecked( true );
1297 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1298 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1299 toolMgr()->registerAction( aAction, TrihedronShowId );
1303 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1304 tr( "MNU_SCALING" ), 0, this);
1305 aAction->setStatusTip(tr("DSC_SCALING"));
1306 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1307 toolMgr()->registerAction( aAction, AxialScaleId );
1309 // Enable/disable preselection
1310 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1311 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1312 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1313 aAction->setCheckable(true);
1314 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1315 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1317 // Enable/disable selection
1318 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1319 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1320 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1321 aAction->setCheckable(true);
1322 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1323 toolMgr()->registerAction( aAction, SwitchSelectionId );
1326 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1327 tr( "MNU_GRADUATED_AXES" ), 0, this);
1328 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1329 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1330 toolMgr()->registerAction( aAction, GraduatedAxesId );
1332 // Active only ambient light or not
1333 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1334 tr( "MNU_AMBIENT" ), 0, this);
1335 aAction->setStatusTip(tr("DSC_AMBIENT"));
1336 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1337 toolMgr()->registerAction( aAction, AmbientId );
1339 // Switch between interaction styles
1340 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1341 tr( "MNU_STYLE_SWITCH" ), 0, this);
1342 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1343 aAction->setCheckable(true);
1344 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1345 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1347 // Switch between zooming styles
1348 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1349 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1350 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1351 aAction->setCheckable(true);
1352 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1353 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1356 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1357 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1358 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1359 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1360 toolMgr()->registerAction( aAction, MaximizedId );
1362 // Return to 3d view
1363 if (my2dMode!=No2dMode){
1364 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1365 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1366 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1367 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1368 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1372 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1376 \brief Create toolbar.
1378 void OCCViewer_ViewWindow::createToolBar()
1380 static const char* titles[] = {
1381 "LBL_3DTOOLBAR_LABEL",
1382 "LBL_XYTOOLBAR_LABEL",
1383 "LBL_XZTOOLBAR_LABEL",
1384 "LBL_YZTOOLBAR_LABEL",
1386 static const char* names[] = {
1387 "OCCViewer3DViewOperations",
1388 "OCCViewerXYViewOperations",
1389 "OCCViewerXZViewOperations",
1390 "OCCViewerYZViewOperations",
1392 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1393 QString( names[my2dMode] ), // name (language-independant)
1394 false ); // disable floatable toolbar
1395 if ( my2dMode != No2dMode ){
1396 toolMgr()->append( ReturnTo3dViewId, tid );
1397 toolMgr()->append( toolMgr()->separator(), tid );
1399 toolMgr()->append( DumpId, tid );
1400 toolMgr()->append( SwitchInteractionStyleId, tid );
1401 toolMgr()->append( SwitchZoomingStyleId, tid );
1402 toolMgr()->append( SwitchPreselectionId, tid );
1403 toolMgr()->append( SwitchSelectionId, tid );
1404 if( myModel->trihedronActivated() )
1405 toolMgr()->append( TrihedronShowId, tid );
1407 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1408 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1409 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1410 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1411 toolMgr()->append( aScaleAction, tid );
1413 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1414 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1415 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1416 toolMgr()->append( aPanningAction, tid );
1418 if (my2dMode == No2dMode) {
1419 toolMgr()->append( ChangeRotationPointId, tid );
1420 toolMgr()->append( RotationId, tid );
1422 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1423 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1424 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1425 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1426 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1427 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1428 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1429 toolMgr()->append( aViewsAction, tid );
1431 toolMgr()->append( AntiClockWiseId, tid );
1432 toolMgr()->append( ClockWiseId, tid );
1434 toolMgr()->append( ResetId, tid );
1437 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1438 aMemAction->insertAction( toolMgr()->action( MemId ) );
1439 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1440 toolMgr()->append( aMemAction, tid );
1442 toolMgr()->append( toolMgr()->separator(), tid );
1443 toolMgr()->append( CloneId, tid );
1445 toolMgr()->append( toolMgr()->separator(), tid );
1446 toolMgr()->append( ClippingId, tid );
1447 toolMgr()->append( AxialScaleId, tid );
1448 toolMgr()->append( GraduatedAxesId, tid );
1449 toolMgr()->append( AmbientId, tid );
1451 toolMgr()->append( MaximizedId, tid );
1452 toolMgr()->append( SynchronizeId, tid );
1456 \brief Perform 'fit all' operation.
1458 void OCCViewer_ViewWindow::onViewFitAll()
1460 myViewPort->fitAll();
1464 \brief Perform "front view" transformation.
1466 void OCCViewer_ViewWindow::onFrontView()
1468 emit vpTransformationStarted ( FRONTVIEW );
1469 Handle(V3d_View) aView3d = myViewPort->getView();
1470 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
1472 emit vpTransformationFinished ( FRONTVIEW );
1476 \brief Perform "back view" transformation.
1478 void OCCViewer_ViewWindow::onBackView()
1480 emit vpTransformationStarted ( BACKVIEW );
1481 Handle(V3d_View) aView3d = myViewPort->getView();
1482 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
1484 emit vpTransformationFinished ( BACKVIEW );
1488 \brief Perform "top view" transformation.
1490 void OCCViewer_ViewWindow::onTopView()
1492 emit vpTransformationStarted ( TOPVIEW );
1493 Handle(V3d_View) aView3d = myViewPort->getView();
1494 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
1496 emit vpTransformationFinished ( TOPVIEW );
1500 \brief Perform "bottom view" transformation.
1502 void OCCViewer_ViewWindow::onBottomView()
1504 emit vpTransformationStarted ( BOTTOMVIEW );
1505 Handle(V3d_View) aView3d = myViewPort->getView();
1506 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
1508 emit vpTransformationFinished ( BOTTOMVIEW );
1512 \brief Perform "left view" transformation.
1514 void OCCViewer_ViewWindow::onLeftView()
1516 emit vpTransformationStarted ( LEFTVIEW );
1517 Handle(V3d_View) aView3d = myViewPort->getView();
1518 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
1520 emit vpTransformationFinished ( LEFTVIEW );
1524 \brief Perform "right view" transformation.
1526 void OCCViewer_ViewWindow::onRightView()
1528 emit vpTransformationStarted ( RIGHTVIEW );
1529 Handle(V3d_View) aView3d = myViewPort->getView();
1530 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
1532 emit vpTransformationFinished ( RIGHTVIEW );
1536 \brief Rotate view 90 degrees clockwise
1538 void OCCViewer_ViewWindow::onClockWiseView()
1540 emit vpTransformationStarted ( CLOCKWISEVIEW );
1541 myViewPort->rotateXY( 90. );
1542 emit vpTransformationFinished ( CLOCKWISEVIEW );
1546 \brief Rotate view 90 degrees conterclockwise
1548 void OCCViewer_ViewWindow::onAntiClockWiseView()
1550 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1551 myViewPort->rotateXY( -90. );
1552 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1556 \brief Perform "reset view" transformation.
1558 Sets default orientation of the viewport camera.
1560 void OCCViewer_ViewWindow::onResetView()
1562 emit vpTransformationStarted( RESETVIEW );
1563 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1564 myViewPort->getView()->Reset( false );
1565 myViewPort->fitAll( false, true, false );
1566 myViewPort->getView()->SetImmediateUpdate( upd );
1567 myViewPort->getView()->Update();
1568 emit vpTransformationFinished( RESETVIEW );
1572 \brief Perform "fit all" transformation.
1574 void OCCViewer_ViewWindow::onFitAll()
1576 emit vpTransformationStarted( FITALLVIEW );
1577 myViewPort->fitAll();
1578 emit vpTransformationFinished( FITALLVIEW );
1582 \brief Called if 'change rotation point' operation is activated.
1583 \param on action state
1585 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1589 if (!mySetRotationPointDlg)
1591 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1592 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1595 if (!mySetRotationPointDlg->isVisible())
1597 //if (mySetRotationPointDlg->IsFirstShown())
1598 if (myCurrPointType == GRAVITY)
1600 Standard_Real Xcenter, Ycenter, Zcenter;
1601 if (computeGravityCenter(Xcenter, Ycenter, Zcenter))
1602 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1604 mySetRotationPointDlg->show();
1609 if (mySetRotationPointDlg->isVisible())
1610 mySetRotationPointDlg->hide();
1615 \brief Create one more window with same content.
1617 void OCCViewer_ViewWindow::onCloneView()
1619 SUIT_ViewWindow* vw = myManager->createViewWindow();
1621 emit viewCloned( vw );
1625 Creates one more window with same content
1627 void OCCViewer_ViewWindow::onAxialScale()
1629 if ( !myScalingDlg )
1630 myScalingDlg = new OCCViewer_AxialScaleDlg( this );
1632 if ( !myScalingDlg->isVisible() )
1634 myScalingDlg->Update();
1635 myScalingDlg->show();
1640 Shows Graduated Axes dialog
1642 void OCCViewer_ViewWindow::onGraduatedAxes()
1644 myCubeAxesDlg->Update();
1645 myCubeAxesDlg->show();
1648 void OCCViewer_ViewWindow::onAmbientToogle()
1650 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
1651 viewer->InitDefinedLights();
1652 while(viewer->MoreDefinedLights())
1654 Handle(V3d_Light) light = viewer->DefinedLight();
1655 if(light->Type() != V3d_AMBIENT)
1657 Handle(V3d_View) aView3d = myViewPort->getView();
1658 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
1659 else viewer->SetLightOn(light);
1661 viewer->NextDefinedLights();
1667 \brief Store view parameters.
1669 void OCCViewer_ViewWindow::onMemorizeView()
1671 appendViewAspect( getViewParams() );
1675 \brief Restore view parameters.
1677 void OCCViewer_ViewWindow::onRestoreView()
1679 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
1680 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
1682 updateViewAspects( aDlg->parameters() );
1683 if( myRestoreFlag && aDlg->parameters().count() )
1684 performRestoring( aDlg->currentItem() );
1688 \brief Restore view parameters.
1689 \param anItem view parameters
1691 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
1693 Handle(V3d_View) aView3d = myViewPort->getView();
1695 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
1696 aView3d->SetScale( anItem.scale );
1697 aView3d->SetTwist( anItem.twist );
1698 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
1699 aView3d->SetImmediateUpdate( prev );
1700 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1701 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1702 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
1704 #if OCC_VERSION_LARGE > 0x06070100
1705 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
1707 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
1709 // "eye" and "at" require conversion to represent center panning
1710 // up direction is only available after setting angle of twist and
1711 // other view parameters
1712 aView3d->Up( anUpX, anUpY, anUpZ );
1714 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
1715 gp_Dir anUp( anUpX, anUpY, anUpZ );
1716 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
1717 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1718 gp_Dir aSide = aProj ^ anUp;
1720 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
1721 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
1723 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
1724 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1727 aView3d->SetCenter( anItem.centerX, anItem.centerY );
1730 if ( !baseParamsOnly ) {
1732 myModel->setTrihedronShown( anItem.isVisible );
1733 myModel->setTrihedronSize( anItem.size );
1735 // graduated trihedron
1736 bool anIsVisible = anItem.gtIsVisible;
1737 OCCViewer_AxisWidget::AxisData anAxisData[3];
1738 anAxisData[0].DrawName = anItem.gtDrawNameX;
1739 anAxisData[1].DrawName = anItem.gtDrawNameZ;
1740 anAxisData[2].DrawName = anItem.gtDrawNameZ;
1741 anAxisData[0].Name = anItem.gtNameX;
1742 anAxisData[1].Name = anItem.gtNameZ;
1743 anAxisData[2].Name = anItem.gtNameZ;
1744 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
1745 anItem.gtNameColorGX,
1746 anItem.gtNameColorBX );
1747 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
1748 anItem.gtNameColorGY,
1749 anItem.gtNameColorBY );
1750 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
1751 anItem.gtNameColorGZ,
1752 anItem.gtNameColorBZ );
1753 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
1754 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
1755 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
1756 anAxisData[0].NbValues = anItem.gtNbValuesX;
1757 anAxisData[1].NbValues = anItem.gtNbValuesY;
1758 anAxisData[2].NbValues = anItem.gtNbValuesZ;
1759 anAxisData[0].Offset = anItem.gtOffsetX;
1760 anAxisData[1].Offset = anItem.gtOffsetY;
1761 anAxisData[2].Offset = anItem.gtOffsetZ;
1762 anAxisData[0].Color = QColor( anItem.gtColorRX,
1765 anAxisData[1].Color = QColor( anItem.gtColorRY,
1768 anAxisData[2].Color = QColor( anItem.gtColorRZ,
1771 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
1772 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
1773 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
1774 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
1775 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
1776 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
1778 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
1779 myCubeAxesDlg->ApplyData( aView3d );
1781 } // if ( !baseParamsOnly )
1787 \brief Set restore flag.
1789 void OCCViewer_ViewWindow::setRestoreFlag()
1795 \brief Called when action "show/hide trihedron" is activated.
1797 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
1799 myModel->setTrihedronShown(show);
1803 \brief Toggles preselection (highlighting) on/off
1805 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
1807 myPreselectionEnabled = on;
1808 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
1810 // unhighlight all highlighted objects
1812 myModel->unHighlightAll( true, false );
1815 // update action state if method is called outside
1816 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
1817 if ( a && a->isChecked() != on ) {
1818 a->setChecked( on );
1823 \brief Toggles selection on/off
1825 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
1827 mySelectionEnabled = on;
1828 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
1830 // update action state if method is called outside
1833 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
1835 a->setEnabled( on );
1839 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
1840 if ( a && a->isChecked() != on ) {
1841 a->setChecked( on );
1846 \brief Switches "keyboard free" interaction style on/off
1848 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
1850 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
1852 // update action state if method is called outside
1853 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
1854 if ( a->isChecked() != on )
1855 a->setChecked( on );
1859 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
1861 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
1863 myViewPort->setAdvancedZoomingEnabled( on );
1865 // update action state if method is called outside
1866 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
1867 if ( a->isChecked() != on )
1868 a->setChecked( on );
1872 \brief Get current interaction style
1873 \return interaction style
1875 int OCCViewer_ViewWindow::interactionStyle() const
1877 return myInteractionStyle;
1881 \brief Set current interaction style
1882 \param theStyle interaction style
1884 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
1886 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
1890 \brief Get current zooming style
1891 \return zooming style
1893 int OCCViewer_ViewWindow::zoomingStyle() const
1895 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
1899 \brief Set current zooming style
1900 \param theStyle zooming style
1902 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
1904 onSwitchZoomingStyle( theStyle == 1 );
1908 \brief Dump view window contents to the pixmap.
1909 \return pixmap containing all scene rendered in the window
1911 QImage OCCViewer_ViewWindow::dumpView()
1913 Handle(V3d_View) view = myViewPort->getView();
1914 if ( view.IsNull() )
1917 int aWidth = myViewPort->width();
1918 int aHeight = myViewPort->height();
1920 // rnv: An old approach to dump the OCCViewer content
1921 // Now used OCCT built-in procedure.
1923 QApplication::syncX();
1924 view->Redraw(); // In order to reactivate GL context
1927 OpenGLUtils_FrameBuffer aFrameBuffer;
1928 if( aFrameBuffer.init( aWidth, aHeight ) )
1930 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
1932 glPushAttrib( GL_VIEWPORT_BIT );
1933 glViewport( 0, 0, aWidth, aHeight );
1934 aFrameBuffer.bind();
1939 aFrameBuffer.unbind();
1942 aFrameBuffer.bind();
1943 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
1944 aFrameBuffer.unbind();
1946 anImage = anImage.rgbSwapped();
1947 anImage = anImage.mirrored();
1950 // if frame buffers are unsupported, use old functionality
1953 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
1955 QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
1957 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
1962 view->ToPixMap(aPix,aWidth, aHeight,Graphic3d_BT_RGBA);
1964 QImage anImage( aPix.Data(), aWidth, aHeight, QImage::Format_ARGB32 );
1965 anImage = anImage.mirrored();
1969 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
1970 const QString& fileName,
1971 const QString& format )
1973 if ( format != "PS" && format != "EPS")
1974 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
1976 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
1979 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
1980 else if (format == "EPS")
1981 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
1987 QString OCCViewer_ViewWindow::filter() const
1989 return tr( "OCC_IMAGE_FILES" );
1994 \brief Set parameters of the cutting plane
1995 \param on if \c true, cutting plane is enabled
1996 \param x X position of plane point
1997 \param y Y position of plane point
1998 \param z Z position of plane point
1999 \param dx X coordinate of plane normal
2000 \param dy Y coordinate of plane normal
2001 \param dz Z coordinate of plane normal
2003 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2004 const double dx, const double dy, const double dz )
2006 Handle(V3d_View) view = myViewPort->getView();
2007 if ( view.IsNull() )
2011 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2013 // try to use already existing plane or create a new one
2014 Handle(V3d_Plane) clipPlane;
2016 // calculate new a,b,c,d values for the plane
2017 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2019 pln.Coefficients(a, b, c, d);
2021 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2022 if(aPlanes.Size() > 0 ) {
2023 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2024 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2025 aClipPlane->SetEquation(pln);
2026 aClipPlane->SetOn(Standard_True);
2028 view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2032 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2033 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2034 for( ;anIter.More();anIter.Next() ){
2035 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2036 aClipPlane->SetOn(Standard_False);
2044 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2046 gp_Dir aDir = pln.Axis().Direction();
2047 gp_Pnt aPnt = pln.Location();
2048 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2053 \brief Check if any cutting plane is enabled
2054 \return \c true if at least one cutting plane is enabled
2056 bool OCCViewer_ViewWindow::isCuttingPlane()
2058 Handle(V3d_View) view = myViewPort->getView();
2060 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2061 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2062 for( ;anIter.More();anIter.Next() ) {
2063 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2064 if(aClipPlane->IsOn()) {
2073 \brief Get the visual parameters of the view window.
2074 \return visual parameters of view window
2076 viewAspect OCCViewer_ViewWindow::getViewParams() const
2078 double projX, projY, projZ, twist;
2079 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2080 double aScaleX, aScaleY, aScaleZ;
2082 Handle(V3d_View) aView3d = myViewPort->getView();
2084 aView3d->Proj( projX, projY, projZ );
2085 aView3d->At( atX, atY, atZ );
2086 aView3d->Eye( eyeX, eyeY, eyeZ );
2087 twist = aView3d->Twist();
2089 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2091 bool isShown = myModel->isTrihedronVisible();
2092 double size = myModel->trihedronSize();
2094 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2097 params.scale = aView3d->Scale();
2098 params.projX = projX;
2099 params.projY = projY;
2100 params.projZ = projZ;
2101 params.twist = twist;
2108 params.scaleX = aScaleX;
2109 params.scaleY = aScaleY;
2110 params.scaleZ = aScaleZ;
2111 params.name = aName;
2112 params.isVisible= isShown;
2115 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2116 aView3d->Center( params.centerX, params.centerY );
2119 // graduated trihedron
2120 bool anIsVisible = false;
2121 OCCViewer_AxisWidget::AxisData anAxisData[3];
2122 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2124 params.gtIsVisible = anIsVisible;
2125 params.gtDrawNameX = anAxisData[0].DrawName;
2126 params.gtDrawNameY = anAxisData[1].DrawName;
2127 params.gtDrawNameZ = anAxisData[2].DrawName;
2128 params.gtNameX = anAxisData[0].Name;
2129 params.gtNameY = anAxisData[1].Name;
2130 params.gtNameZ = anAxisData[2].Name;
2131 params.gtNameColorRX = anAxisData[0].NameColor.red();
2132 params.gtNameColorGX = anAxisData[0].NameColor.green();
2133 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2134 params.gtNameColorRY = anAxisData[1].NameColor.red();
2135 params.gtNameColorGY = anAxisData[1].NameColor.green();
2136 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2137 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2138 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2139 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2140 params.gtDrawValuesX = anAxisData[0].DrawValues;
2141 params.gtDrawValuesY = anAxisData[1].DrawValues;
2142 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2143 params.gtNbValuesX = anAxisData[0].NbValues;
2144 params.gtNbValuesY = anAxisData[1].NbValues;
2145 params.gtNbValuesZ = anAxisData[2].NbValues;
2146 params.gtOffsetX = anAxisData[0].Offset;
2147 params.gtOffsetY = anAxisData[1].Offset;
2148 params.gtOffsetZ = anAxisData[2].Offset;
2149 params.gtColorRX = anAxisData[0].Color.red();
2150 params.gtColorGX = anAxisData[0].Color.green();
2151 params.gtColorBX = anAxisData[0].Color.blue();
2152 params.gtColorRY = anAxisData[1].Color.red();
2153 params.gtColorGY = anAxisData[1].Color.green();
2154 params.gtColorBY = anAxisData[1].Color.blue();
2155 params.gtColorRZ = anAxisData[2].Color.red();
2156 params.gtColorGZ = anAxisData[2].Color.green();
2157 params.gtColorBZ = anAxisData[2].Color.blue();
2158 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2159 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2160 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2161 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2162 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2163 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2169 \brief Get visual parameters of this view window.
2170 \return visual parameters of view window
2172 QString OCCViewer_ViewWindow::getVisualParameters()
2174 viewAspect params = getViewParams();
2178 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2179 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2180 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
2181 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
2183 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2184 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2185 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2186 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2187 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2188 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2189 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2190 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2191 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2192 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2193 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2194 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2195 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2196 data << QString( "isVisible=%1" ).arg( params.isVisible );
2197 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2199 ClipPlanesList aPlanes = myModel->getClipPlanes();
2200 for ( int i=0; i < aPlanes.size(); i++ )
2202 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2203 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2204 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2205 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2206 switch ( aPlane.Mode )
2208 case OCCViewer_ClipPlane::Absolute :
2210 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2212 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2214 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2215 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2216 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2220 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2225 case OCCViewer_ClipPlane::Relative :
2227 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2228 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2229 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2234 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2235 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2236 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2237 data << ClippingPlane;
2240 // graduated trihedron
2241 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2242 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2243 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2244 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2245 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2246 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2247 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2248 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2249 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2250 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2251 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2252 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2253 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2254 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2255 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2256 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2257 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2258 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2259 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2260 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2261 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2262 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2263 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2264 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2265 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2266 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2267 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2268 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2269 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2270 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2271 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2272 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2273 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2274 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2275 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2276 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2277 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2278 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2279 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2280 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2281 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2282 data << QString( "background=%1" ).arg( bg );
2284 return data.join("*");
2288 \brief Restore visual parameters of the view window.
2289 \param parameters visual parameters of view window
2291 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2294 ClipPlanesList aClipPlanes;
2295 QStringList data = parameters.split( '*' );
2296 Qtx::BackgroundData bgData;
2297 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2299 foreach( QString param, data ) {
2300 QString paramName = param.section( '=', 0, 0 ).trimmed();
2301 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2302 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2303 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2304 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2305 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2306 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2307 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2308 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2309 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2310 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2311 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2312 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2313 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2314 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2315 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2316 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2317 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2318 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2319 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2320 else if ( paramName.contains( "ClippingPlane" ) )
2322 QStringList ClipPlaneData = paramValue.split( ';' );
2323 OCCViewer_ClipPlane aPlane;
2324 foreach( QString ClipPlaneParam, ClipPlaneData )
2326 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2327 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2328 if ( ClipPlane_paramName == "Mode" )
2330 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2332 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2333 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2334 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2335 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2338 switch ( aPlane.Mode )
2340 case OCCViewer_ClipPlane::Absolute :
2341 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2342 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2343 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2344 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2345 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2348 case OCCViewer_ClipPlane::Relative :
2349 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2350 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2351 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2356 aClipPlanes.push_back(aPlane);
2358 // graduated trihedron
2359 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2360 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2361 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2362 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2363 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2364 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2365 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2366 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2367 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2368 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2369 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2370 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2371 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2372 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2373 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2374 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2375 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2376 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2377 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2378 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2379 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2380 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2381 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2382 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2383 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2384 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2385 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2386 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2387 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2388 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2389 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2390 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2391 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2392 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2393 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2394 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2395 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2396 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2397 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2398 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2399 else if ( paramName == "background" ) {
2400 QString bg = paramValue.replace( "$", "=" );
2401 bgData = Qtx::stringToBackground( bg );
2405 else // old format - "1.000e+00*0.000e+00..."
2408 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2409 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2410 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2411 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2412 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2413 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2414 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
2415 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2416 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2417 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
2418 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2419 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2420 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2421 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
2422 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
2423 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
2424 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
2425 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
2427 performRestoring( params );
2428 setBackground( bgData );
2429 myModel->setClipPlanes(aClipPlanes);
2433 \brief Handle show event.
2435 Emits Show() signal.
2437 \param theEvent show event
2439 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2441 emit Show( theEvent );
2445 \brief Handle hide event.
2447 Emits Hide() signal.
2449 \param theEvent hide event
2451 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
2453 emit Hide( theEvent );
2458 Creates default sketcher. [ virtual protected ]
2460 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
2463 return new OCCViewer_RectSketcher( this, type );
2464 if ( type == Polygon )
2465 return new OCCViewer_PolygonSketcher( this, type );
2469 void OCCViewer_ViewWindow::initSketchers()
2471 if ( mySketchers.isEmpty() )
2473 mySketchers.append( createSketcher( Rect ) );
2474 mySketchers.append( createSketcher( Polygon ) );
2478 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
2480 OCCViewer_ViewSketcher* sketcher = 0;
2481 QList<OCCViewer_ViewSketcher*>::Iterator it;
2482 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
2484 OCCViewer_ViewSketcher* sk = (*it);
2485 if ( sk->type() == typ )
2492 Handles requests for sketching in the active view. [ virtual public ]
2494 void OCCViewer_ViewWindow::activateSketching( int type )
2496 OCCViewer_ViewPort3d* vp = getViewPort();
2500 if ( !vp->isSketchingEnabled() )
2503 /* Finish current sketching */
2504 if ( type == NoSketching )
2508 onSketchingFinished();
2509 mypSketcher->deactivate();
2513 /* Activate new sketching */
2516 activateSketching( NoSketching ); /* concurrency not suported */
2517 mypSketcher = getSketcher( type );
2520 mypSketcher->activate();
2521 onSketchingStarted();
2527 Unhilights detected entities. [ virtual protected ]
2529 void OCCViewer_ViewWindow::onSketchingStarted()
2534 Selection by rectangle or polygon. [ virtual protected ]
2536 void OCCViewer_ViewWindow::onSketchingFinished()
2538 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
2539 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
2541 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
2542 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
2543 switch( mypSketcher->type() )
2547 QRect* aRect = (QRect*)mypSketcher->data();
2550 int aLeft = aRect->left();
2551 int aRight = aRect->right();
2552 int aTop = aRect->top();
2553 int aBottom = aRect->bottom();
2557 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2559 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2565 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
2568 int size = aPolygon->size();
2569 TColgp_Array1OfPnt2d anArray( 1, size );
2571 QPolygon::Iterator it = aPolygon->begin();
2572 QPolygon::Iterator itEnd = aPolygon->end();
2573 for( int index = 1; it != itEnd; ++it, index++ )
2575 QPoint aPoint = *it;
2576 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
2580 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
2582 ic->Select( anArray, getViewPort()->getView(), Standard_False );
2590 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
2591 aViewMgr->getOCCViewer()->performSelectionChanged();
2595 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
2600 bool OCCViewer_ViewWindow::transformRequested() const
2602 return ( myOperation != NOTHING );
2605 bool OCCViewer_ViewWindow::transformInProcess() const
2607 return myEventStarted;
2610 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
2612 myEventStarted = bOn;
2616 Set enabled state of transformation (rotate, zoom, etc)
2618 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
2620 if ( id != NOTHING ) myStatus.insert( id, on );
2624 \return enabled state of transformation (rotate, zoom, etc)
2626 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
2628 return myStatus.contains( id ) ? myStatus[ id ] : true;
2631 void OCCViewer_ViewWindow::onMaximizedView()
2633 setMaximized(!isMaximized());
2636 void OCCViewer_ViewWindow::returnTo3dView()
2638 setReturnedTo3dView( true );
2641 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
2643 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
2644 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
2645 if ( !isVisible3dView )
2646 toolMgr()->show( ReturnTo3dViewId );
2648 toolMgr()->hide( ReturnTo3dViewId );
2649 if ( isVisible3dView ) emit returnedTo3d( );
2653 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
2655 QAction* anAction = toolMgr()->action( MaximizedId );
2656 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
2657 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
2659 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
2660 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
2661 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
2662 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
2663 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
2665 emit maximized( this, true );
2669 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
2670 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
2671 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
2672 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
2673 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
2675 emit maximized( this, false );
2680 bool OCCViewer_ViewWindow::isMaximized() const
2682 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
2685 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
2687 IsSketcherStyle = enable;
2690 bool OCCViewer_ViewWindow::isSketcherStyle() const
2692 return IsSketcherStyle;
2696 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
2702 QColor OCCViewer_ViewWindow::backgroundColor() const
2704 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
2708 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
2710 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
2713 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
2715 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
2718 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
2720 if ( myViewPort ) myViewPort->setBackground( theBackground );
2723 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
2725 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
2731 void OCCViewer_ViewWindow::clearViewAspects()
2733 myViewAspects.clear();
2737 \return const reference to list of view aspects
2739 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
2741 return myViewAspects;
2745 Appends new view aspect
2746 \param aParams - new view aspects
2748 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
2750 myViewAspects.append( aParams );
2754 Replaces old view aspects by new ones
2755 \param aViewList - list of new view aspects
2757 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
2759 myViewAspects = aViewList;
2763 Get camera properties for the OCC view window.
2764 \return shared pointer on camera properties.
2766 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
2768 SUIT_CameraProperties aProps;
2770 Handle(V3d_View) aSourceView = getViewPort()->getView();
2771 if ( aSourceView.IsNull() )
2774 if ( get2dMode() == No2dMode ) {
2775 aProps.setDimension( SUIT_CameraProperties::Dim3D );
2778 aProps.setDimension( SUIT_CameraProperties::Dim2D );
2779 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
2782 // read common properites of the view
2783 Standard_Real anUp[3];
2784 Standard_Real anAt[3];
2785 Standard_Real anEye[3];
2786 Standard_Real aProj[3];
2787 Standard_Real anAxialScale[3];
2789 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
2790 aSourceView->At( anAt[0], anAt[1], anAt[2] );
2791 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
2792 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2794 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2795 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
2797 #if OCC_VERSION_LARGE > 0x06070100
2798 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
2800 // store camera properties "as is": it is up to synchronized
2801 // view classes to provide necessary property conversion.
2802 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
2803 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
2805 if ( aSourceView->Camera()->IsOrthographic() )
2807 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
2808 aProps.setViewAngle( 0.0 );
2812 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
2813 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
2815 aProps.setMappingScale( aSourceView->Camera()->Scale() );
2817 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
2819 // generate view orientation matrix for transforming OCC projection reference point
2820 // into a camera (eye) position.
2821 gp_Dir aLeftDir = gp_Dir( anUp[0], anUp[1], anUp[2] ) ^ gp_Dir( aProj[0], aProj[1], aProj[2] );
2824 aTrsf.SetValue( 1, 1, aLeftDir.X() );
2825 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
2826 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
2828 aTrsf.SetValue( 1, 2, anUp[0] );
2829 aTrsf.SetValue( 2, 2, anUp[1] );
2830 aTrsf.SetValue( 3, 2, anUp[2] );
2832 aTrsf.SetValue( 1, 3, aProj[0] );
2833 aTrsf.SetValue( 2, 3, aProj[1] );
2834 aTrsf.SetValue( 3, 3, aProj[2] );
2836 aTrsf.SetValue( 1, 4, anAt[0] );
2837 aTrsf.SetValue( 2, 4, anAt[1] );
2838 aTrsf.SetValue( 3, 4, anAt[2] );
2840 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
2842 // transform to world-space coordinate system
2843 gp_XYZ aPosition( aProjRef.X(), aProjRef.Y(), aCameraDepth );
2844 aTrsf.Transforms( aPosition );
2846 // compute focal point
2847 double aFocalPoint[3];
2849 aFocalPoint[0] = aPosition.X() - aProj[0] * aCameraDepth;
2850 aFocalPoint[1] = aPosition.Y() - aProj[1] * aCameraDepth;
2851 aFocalPoint[2] = aPosition.Z() - aProj[2] * aCameraDepth;
2853 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2854 aProps.setPosition( aPosition.X(), aPosition.Y(), aPosition.Z() );
2856 Standard_Real aViewScale[2];
2857 aSourceView->Size( aViewScale[0], aViewScale[1] );
2858 aProps.setMappingScale( aViewScale[1] );
2866 This implementation synchronizes OCC view's camera propreties.
2868 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
2870 bool blocked = blockSignals( true );
2872 SUIT_CameraProperties aProps = theView->cameraProperties();
2873 if ( !cameraProperties().isCompatible( aProps ) ) {
2874 // other view, this one is being currently synchronized to, seems has become incompatible
2875 // we have to break synchronization
2880 Handle(V3d_View) aDestView = getViewPort()->getView();
2882 aDestView->SetImmediateUpdate( Standard_False );
2885 double aPosition[3];
2886 double aFocalPoint[3];
2887 double anAxialScale[3];
2889 // get common properties
2890 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2891 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
2892 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2893 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2895 #if OCC_VERSION_LARGE > 0x06070100
2896 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2897 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
2898 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2899 aDestView->Camera()->SetScale( aProps.getMappingScale() );
2901 gp_Dir aProjDir( aPosition[0] - aFocalPoint[0],
2902 aPosition[1] - aFocalPoint[1],
2903 aPosition[2] - aFocalPoint[2] );
2905 // get custom view translation
2906 Standard_Real aTranslation[3];
2907 aDestView->At( aTranslation[0], aTranslation[1], aTranslation[2] );
2909 gp_Dir aLeftDir = gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] )
2910 ^ gp_Dir( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
2913 aTrsf.SetValue( 1, 1, aLeftDir.X() );
2914 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
2915 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
2917 aTrsf.SetValue( 1, 2, anUpDir[0] );
2918 aTrsf.SetValue( 2, 2, anUpDir[1] );
2919 aTrsf.SetValue( 3, 2, anUpDir[2] );
2921 aTrsf.SetValue( 1, 3, aProjDir.X() );
2922 aTrsf.SetValue( 2, 3, aProjDir.Y() );
2923 aTrsf.SetValue( 3, 3, aProjDir.Z() );
2925 aTrsf.SetValue( 1, 4, aTranslation[0] );
2926 aTrsf.SetValue( 2, 4, aTranslation[1] );
2927 aTrsf.SetValue( 3, 4, aTranslation[2] );
2930 // transform to view-space coordinate system
2931 gp_XYZ aProjRef( aPosition[0], aPosition[1], aPosition[2] );
2932 aTrsf.Transforms( aProjRef );
2934 // set view camera properties using low-level approach. this is done
2935 // in order to avoid interference with static variables in v3d view used
2936 // when rotation is in process in another view.
2937 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
2938 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
2940 Graphic3d_Vector aMappingProj( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
2941 Graphic3d_Vector aMappingUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2943 aMappingProj.Normalize();
2944 aMappingUp.Normalize();
2946 anOrientation.SetViewReferencePlane( aMappingProj );
2947 anOrientation.SetViewReferenceUp( aMappingUp );
2949 aDestView->SetViewMapping( aMapping );
2950 aDestView->SetViewOrientation( anOrientation );
2953 aDestView->SetCenter( aProjRef.X(), aProjRef.Y() );
2955 // set mapping scale
2956 double aMapScaling = aProps.getMappingScale();
2957 Standard_Real aWidth, aHeight;
2958 aDestView->Size( aWidth, aHeight );
2959 aDestView->SetSize ( aWidth > aHeight ? aMapScaling * (aWidth / aHeight) : aMapScaling );
2962 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2964 aDestView->ZFitAll();
2965 aDestView->SetImmediateUpdate( Standard_True );
2966 aDestView->Redraw();
2968 blockSignals( blocked );
2972 \brief Indicates whether preselection is enabled
2973 \return true if preselection is enabled
2975 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
2977 return myPreselectionEnabled;
2981 \brief Enables/disables preselection
2982 \param theIsToEnable if true - preselection will be enabled
2984 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
2986 onSwitchPreselection( theIsToEnable );
2990 \brief Indicates whether selection is enabled
2991 \return true if selection is enabled
2993 bool OCCViewer_ViewWindow::isSelectionEnabled() const
2995 return mySelectionEnabled;
2999 \brief Enables/disables selection
3000 \param theIsToEnable if true - selection will be enabled
3002 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3004 onSwitchSelection( theIsToEnable );
3009 \brief called if clipping operation is activated / deactivated.
3011 Enables/disables clipping plane displaying.
3013 \parma on action state
3015 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3017 if(!myModel) return;
3018 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3021 if (!aClippingDlg) {
3022 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3023 myModel->setClippingDlg(aClippingDlg);
3025 if (!aClippingDlg->isVisible())
3026 aClippingDlg->show();
3028 if ( aClippingDlg ) {
3029 aClippingDlg->close();
3030 myModel->setClippingDlg(0);
3034 SUIT_ViewManager* mgr = getViewManager();
3036 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3037 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3038 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3039 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3041 QAction* a = toolMgr()->action( ClippingId );
3043 if(theIsOn != a->isChecked()){
3044 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3045 a->setChecked(theIsOn);
3046 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));