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;
367 if ( aEvent->modifiers().testFlag(Qt::ControlModifier) ) {
368 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
369 if ( ic->HasOpenedContext() ) {
370 if ( aEvent->delta() > 0 ) {
371 ic->HilightNextDetected( myViewPort->getView() );
373 ic->HilightPreviousDetected( myViewPort->getView() );
377 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
378 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
381 int x1 = (int)( aEvent->x() + width()*delta/100 );
382 int y1 = (int)( aEvent->y() + height()*delta/100 );
383 myViewPort->zoom( x, y, x1, y1 );
384 myViewPort->getView()->ZFitAll();
389 case QEvent::ContextMenu:
391 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
392 if ( aEvent->reason() != QContextMenuEvent::Mouse )
393 emit contextMenuRequested( aEvent );
397 case QEvent::KeyPress:
398 emit keyPressed(this, (QKeyEvent*) e);
405 return SUIT_ViewWindow::eventFilter(watched, e);
409 \brief Update state of enable draw mode state.
411 void OCCViewer_ViewWindow::updateEnabledDrawMode()
414 myEnableDrawMode = myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
418 \brief Handle mouse press event
419 \param theEvent mouse event
421 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
423 myStartX = theEvent->x();
424 myStartY = theEvent->y();
425 int anInteractionStyle = interactionStyle();
427 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
428 // which are assigned for pan and rotate - these operations are activated immediately after pressing
429 // of the first button, so it is necessary to switch to zoom when the second button is pressed
430 bool aSwitchToZoom = false;
431 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
432 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
433 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
436 switch ( myOperation ) {
438 if ( theEvent->button() == Qt::LeftButton )
439 emit vpTransformationStarted ( WINDOWFIT );
443 if ( theEvent->button() == Qt::LeftButton )
444 emit vpTransformationStarted ( PANGLOBAL );
448 if ( theEvent->button() == Qt::LeftButton ) {
449 myViewPort->startZoomAtPoint( myStartX, myStartY );
450 emit vpTransformationStarted ( ZOOMVIEW );
455 if ( aSwitchToZoom ) {
456 myViewPort->startZoomAtPoint( myStartX, myStartY );
459 else if ( theEvent->button() == Qt::LeftButton )
460 emit vpTransformationStarted ( PANVIEW );
464 if ( aSwitchToZoom ) {
465 myViewPort->startZoomAtPoint( myStartX, myStartY );
468 else if ( theEvent->button() == Qt::LeftButton ) {
469 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
470 emit vpTransformationStarted ( ROTATE );
475 /* Try to activate a transformation */
476 OperationType aState;
477 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
478 aState = getButtonState(theEvent, anInteractionStyle);
480 aState = OCCViewer_ViewWindow::NOTHING;
485 myViewPort->startZoomAtPoint( myStartX, myStartY );
493 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
496 if ( myRotationPointSelection )
498 if ( theEvent->button() == Qt::LeftButton )
500 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
502 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
504 TopoDS_Shape aShape = ic->SelectedShape();
505 GProp_GProps aSystem;
507 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
509 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
511 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE )
513 BRepGProp::LinearProperties( aShape, aSystem );
514 aPnt = aSystem.CentreOfMass();
516 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE )
518 BRepGProp::SurfaceProperties( aShape, aSystem );
519 aPnt = aSystem.CentreOfMass();
521 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID )
523 BRepGProp::VolumeProperties( aShape, aSystem );
524 aPnt = aSystem.CentreOfMass();
528 myCurrPointType = myPrevPointType;
532 if ( mySetRotationPointDlg )
534 myRotationPointSelection = false;
535 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
538 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
539 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
540 ic->CloseAllContexts();
541 myOperation = NOTHING;
542 myViewPort->setCursor( myCursor );
543 myCursorIsHand = false;
544 myRotationPointSelection = false;
548 emit mousePressed(this, theEvent);
551 /* notify that we start a transformation */
552 if ( transformRequested() )
553 emit vpTransformationStarted ( myOperation );
555 if ( transformRequested() )
556 setTransformInProcess( true );
558 /* we may need it for sketching... */
559 if ( l_mbPressEvent )
560 delete l_mbPressEvent;
561 l_mbPressEvent = new QMouseEvent( *theEvent );
566 \brief Start zooming operation.
568 Sets the corresponding cursor for the widget.
570 void OCCViewer_ViewWindow::activateZoom()
572 if ( !transformRequested() && !myCursorIsHand )
573 myCursor = cursor(); /* save old cursor */
575 if ( myOperation != ZOOMVIEW ) {
576 QPixmap zoomPixmap (imageZoomCursor);
577 QCursor zoomCursor (zoomPixmap);
578 if( setTransformRequested ( ZOOMVIEW ) )
579 myViewPort->setCursor( zoomCursor );
585 \brief Start panning operation.
587 Sets the corresponding cursor for the widget.
589 void OCCViewer_ViewWindow::activatePanning()
591 if ( !transformRequested() && !myCursorIsHand )
592 myCursor = cursor(); // save old cursor
594 if ( myOperation != PANVIEW ) {
595 QCursor panCursor (Qt::SizeAllCursor);
596 if( setTransformRequested ( PANVIEW ) )
597 myViewPort->setCursor( panCursor );
602 \brief Start rotation operation
604 Sets the corresponding cursor for the widget.
606 void OCCViewer_ViewWindow::activateRotation()
608 if ( !transformRequested() && !myCursorIsHand )
609 myCursor = cursor(); // save old cursor
611 if ( myOperation != ROTATE ) {
612 QPixmap rotatePixmap (imageRotateCursor);
613 QCursor rotCursor (rotatePixmap);
614 if( setTransformRequested ( ROTATE ) )
615 myViewPort->setCursor( rotCursor );
620 \brief Compute the gravity center.
621 \param theX used to return X coordinate of the gravity center
622 \param theY used to return Y coordinate of the gravity center
623 \param theZ used to return Z coordinate of the gravity center
624 \return \c true if the gravity center is computed
626 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
628 Handle(V3d_View) aView3d = myViewPort->getView();
630 // Project boundaries points and add to avergae gravity
631 // the ones which lie within the screen limits
632 Standard_Real aScreenLimits[4] = { 0.0, 0.0, 0.0, 0.0 };
634 #if OCC_VERSION_LARGE > 0x06070100
635 // NDC space screen limits
636 aScreenLimits[0] = -1.0;
637 aScreenLimits[1] = 1.0;
638 aScreenLimits[2] = -1.0;
639 aScreenLimits[3] = 1.0;
641 aView3d->View()->ViewMapping().WindowLimit( aScreenLimits[0],
647 Standard_Integer aPointsNb = 0;
649 Standard_Real aXmin = 0.0;
650 Standard_Real aYmin = 0.0;
651 Standard_Real aZmin = 0.0;
652 Standard_Real aXmax = 0.0;
653 Standard_Real aYmax = 0.0;
654 Standard_Real aZmax = 0.0;
656 Graphic3d_MapOfStructure aSetOfStructures;
657 aView3d->View()->DisplayedStructures( aSetOfStructures );
658 Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures );
660 for( ; aStructureIt.More(); aStructureIt.Next() ) {
661 const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key();
662 if ( aStructure->IsEmpty() ) {
666 #if OCC_VERSION_LARGE > 0x06070100
667 Bnd_Box aBox = aStructure->MinMaxValues();
668 aXmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().X();
669 aYmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Y();
670 aZmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Z();
671 aXmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().X();
672 aYmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Y();
673 aZmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Z();
675 aStructure->MinMaxValues( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
678 // Infinite structures are skipped
679 Standard_Real aLIM = ShortRealLast() - 1.0;
680 if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
681 || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
685 gp_Pnt aPoints[8] = {
686 gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
687 gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
688 gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
689 gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
692 for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
693 const gp_Pnt& aBBPoint = aPoints[aPointIt];
695 #if OCC_VERSION_LARGE > 0x06070100
696 gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
697 const Standard_Real& U = aProjected.X();
698 const Standard_Real& V = aProjected.Y();
700 Standard_Real U = 0.0;
701 Standard_Real V = 0.0;
702 Standard_Real W = 0.0;
703 aView3d->View()->Projects( aBBPoint.X(), aBBPoint.Y(), aBBPoint.Z(), U, V, W );
706 if (U >= aScreenLimits[0]
707 && U <= aScreenLimits[1]
708 && V >= aScreenLimits[2]
709 && V <= aScreenLimits[3])
712 theX += aBBPoint.X();
713 theY += aBBPoint.Y();
714 theZ += aBBPoint.Z();
729 \brief Set the gravity center as a rotation point.
731 void OCCViewer_ViewWindow::activateSetRotationGravity()
733 if ( myRotationPointSelection )
735 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
736 ic->CloseAllContexts();
737 myOperation = NOTHING;
738 myViewPort->setCursor( myCursor );
739 myCursorIsHand = false;
740 myRotationPointSelection = false;
743 myPrevPointType = myCurrPointType;
744 myCurrPointType = GRAVITY;
746 Standard_Real Xcenter, Ycenter, Zcenter;
747 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
748 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
752 \brief Update gravity center in the "Set Rotation Point" dialog box.
753 \sa OCCViewer_SetRotationPointDlg class
755 void OCCViewer_ViewWindow::updateGravityCoords()
757 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == GRAVITY )
759 Standard_Real Xcenter, Ycenter, Zcenter;
760 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
761 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
766 \brief Set the point selected by the user as a rotation point.
767 \param theX X coordinate of the rotation point
768 \param theY Y coordinate of the rotation point
769 \param theZ Z coordinate of the rotation point
771 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
773 if ( myRotationPointSelection )
775 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
776 ic->CloseAllContexts();
777 myOperation = NOTHING;
778 myViewPort->setCursor( myCursor );
779 myCursorIsHand = false;
780 myRotationPointSelection = false;
783 myPrevPointType = myCurrPointType;
784 myCurrPointType = SELECTED;
785 mySelectedPoint.SetCoord(theX,theY,theZ);
789 \brief Start the shape selection process.
791 void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
793 myPrevPointType = myCurrPointType;
794 myCurrPointType = SELECTED;
796 // activate selection ------>
797 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
799 ic->OpenLocalContext();
801 AIS_ListOfInteractive aList;
802 ic->DisplayedObjects( aList );
803 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
805 Handle(AIS_InteractiveObject) anObj = it.Value();
806 if ( !anObj.IsNull() && anObj->HasPresentation() &&
807 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
810 ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
813 // activate selection <------
815 if ( !myCursorIsHand )
817 QCursor handCursor (Qt::PointingHandCursor);
818 myCursorIsHand = true;
820 myViewPort->setCursor( handCursor );
822 myRotationPointSelection = true;
826 \brief Start global panning operation
828 Sets the corresponding cursor for the widget.
830 void OCCViewer_ViewWindow::activateGlobalPanning()
832 Handle(V3d_View) aView3d = myViewPort->getView();
833 if ( !aView3d.IsNull() ) {
834 QPixmap globalPanPixmap (imageCrossCursor);
835 QCursor glPanCursor (globalPanPixmap);
836 myCurScale = aView3d->Scale();
837 aView3d->FitAll(0.01, false);
838 myCursor = cursor(); // save old cursor
839 myViewPort->fitAll(); // fits view before selecting a new scene center
840 if( setTransformRequested( PANGLOBAL ) )
841 myViewPort->setCursor( glPanCursor );
846 \brief Starts fit operation.
848 Sets the corresponding cursor for the widget.
850 void OCCViewer_ViewWindow::activateWindowFit()
852 if ( !transformRequested() && !myCursorIsHand )
853 myCursor = cursor(); /* save old cursor */
855 if ( myOperation != WINDOWFIT ) {
856 QCursor handCursor (Qt::PointingHandCursor);
857 if( setTransformRequested ( WINDOWFIT ) )
859 myViewPort->setCursor ( handCursor );
860 myCursorIsHand = true;
866 \brief Start delayed viewer operation.
868 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
870 bool ok = transformEnabled( op );
871 myOperation = ok ? op : NOTHING;
872 myViewPort->setMouseTracking( myOperation == NOTHING );
877 \brief Handle mouse move event.
878 \param theEvent mouse event
880 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
882 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
884 switch ( getButtonState( theEvent, interactionStyle() ) ) {
886 myViewPort->startZoomAtPoint( myStartX, myStartY );
894 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
901 myCurrX = theEvent->x();
902 myCurrY = theEvent->y();
903 switch (myOperation) {
905 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
909 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
915 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
929 if ( myRotationPointSelection || isSketcherStyle() )
931 emit mouseMoving( this, theEvent );
935 int aState = theEvent->modifiers();
936 int aButton = theEvent->buttons();
937 int anInteractionStyle = interactionStyle();
938 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
939 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
940 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
941 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
942 myDrawRect = myEnableDrawMode;
945 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
946 QCursor handCursor (Qt::PointingHandCursor);
947 myCursorIsHand = true;
949 myViewPort->setCursor( handCursor );
952 emit mouseMoving( this, theEvent );
954 else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
955 aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
956 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
957 aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
958 OCCViewer_ViewSketcher* sketcher = 0;
959 QList<OCCViewer_ViewSketcher*>::Iterator it;
960 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
962 OCCViewer_ViewSketcher* sk = (*it);
963 if( sk->isDefault() && sk->sketchButton() == aButton )
966 if ( sketcher && myCurSketch == -1 )
968 activateSketching( sketcher->type() );
971 myCurSketch = mypSketcher->sketchButton();
973 if ( l_mbPressEvent )
975 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
976 delete l_mbPressEvent;
979 QApplication::sendEvent( getViewPort(), theEvent );
984 emit mouseMoving( this, theEvent );
990 \brief Handle mouse release event.
991 \param theEvent mouse event
993 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
995 switch ( myOperation ) {
998 int prevState = myCurSketch;
999 if(theEvent->button() == Qt::RightButton)
1001 QList<OCCViewer_ViewSketcher*>::Iterator it;
1002 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
1004 OCCViewer_ViewSketcher* sk = (*it);
1005 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
1010 emit mouseReleased(this, theEvent);
1011 if(theEvent->button() == Qt::RightButton && prevState == -1)
1013 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1014 theEvent->pos(), theEvent->globalPos() );
1015 emit contextMenuRequested( &aEvent );
1020 myViewPort->endRotation();
1026 myViewPort->getView()->ZFitAll();
1031 if ( theEvent->button() == Qt::LeftButton ) {
1032 myViewPort->setCenter( theEvent->x(), theEvent->y() );
1033 myViewPort->getView()->SetScale(myCurScale);
1039 if ( theEvent->button() == Qt::LeftButton ) {
1040 myCurrX = theEvent->x();
1041 myCurrY = theEvent->y();
1043 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1044 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1051 // NOTE: viewer 3D detects a rectangle of selection using this event
1052 // so we must emit it BEFORE resetting the selection rectangle
1054 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1058 myViewPort->update();
1061 if ( l_mbPressEvent )
1063 delete l_mbPressEvent;
1069 \brief Reset the viewport to its initial state
1070 ( no transformations in process etc. )
1072 void OCCViewer_ViewWindow::resetState()
1076 if ( myRotationPointSelection )
1078 QCursor handCursor (Qt::PointingHandCursor);
1079 myViewPort->setCursor( handCursor );
1083 if ( transformRequested() || myCursorIsHand )
1084 myViewPort->setCursor( myCursor );
1085 myCursorIsHand = false;
1088 if ( transformRequested() )
1089 emit vpTransformationFinished (myOperation);
1091 setTransformInProcess( false );
1092 setTransformRequested( NOTHING );
1097 \brief Draw rubber band rectangle.
1099 void OCCViewer_ViewWindow::drawRect()
1101 if ( !myRectBand ) {
1102 myRectBand = new QtxRectRubberBand( myViewPort );
1104 //palette.setColor(myRectBand->foregroundRole(), Qt::white);
1105 //myRectBand->setPalette(palette);
1107 //myRectBand->hide();
1109 myRectBand->setUpdatesEnabled ( false );
1110 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1111 myRectBand->initGeometry( aRect );
1113 if ( !myRectBand->isVisible() )
1116 myRectBand->setUpdatesEnabled ( true );
1117 //myRectBand->repaint();
1119 //myRectBand->setVisible( aRect.isValid() );
1120 //if ( myRectBand->isVisible() )
1121 // myRectBand->repaint();
1123 // myRectBand->show();
1124 //myRectBand->repaint();
1128 \brief Clear rubber band rectangle on the end on the dragging operation.
1130 void OCCViewer_ViewWindow::endDrawRect()
1132 //delete myRectBand;
1136 myRectBand->clearGeometry();
1142 \brief Create actions.
1144 void OCCViewer_ViewWindow::createActions()
1146 if( !toolMgr()->isEmpty() )
1149 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1154 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1155 tr( "MNU_DUMP_VIEW" ), 0, this);
1156 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1157 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1158 toolMgr()->registerAction( aAction, DumpId );
1161 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1162 tr( "MNU_FITALL" ), 0, this);
1163 aAction->setStatusTip(tr("DSC_FITALL"));
1164 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1165 toolMgr()->registerAction( aAction, FitAllId );
1168 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1169 tr( "MNU_FITRECT" ), 0, this);
1170 aAction->setStatusTip(tr("DSC_FITRECT"));
1171 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1172 toolMgr()->registerAction( aAction, FitRectId );
1175 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1176 tr( "MNU_ZOOM_VIEW" ), 0, this);
1177 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1178 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1179 toolMgr()->registerAction( aAction, ZoomId );
1182 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1183 tr( "MNU_PAN_VIEW" ), 0, this);
1184 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1185 connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
1186 toolMgr()->registerAction( aAction, PanId );
1189 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1190 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1191 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1192 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1193 toolMgr()->registerAction( aAction, GlobalPanId );
1196 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1197 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1198 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1199 mySetRotationPointAction->setCheckable( true );
1200 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1201 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1204 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1205 tr( "MNU_ROTATE_VIEW" ), 0, this);
1206 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1207 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1208 toolMgr()->registerAction( aAction, RotationId );
1211 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1212 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1213 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1214 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1215 this->addAction(aAction);
1216 toolMgr()->registerAction( aAction, FrontId );
1218 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1219 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1220 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1221 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1222 this->addAction(aAction);
1223 toolMgr()->registerAction( aAction, BackId );
1225 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1226 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1227 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1228 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1229 this->addAction(aAction);
1230 toolMgr()->registerAction( aAction, TopId );
1232 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1233 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1234 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1235 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1236 this->addAction(aAction);
1237 toolMgr()->registerAction( aAction, BottomId );
1239 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1240 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1241 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1242 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1243 this->addAction(aAction);
1244 toolMgr()->registerAction( aAction, LeftId );
1246 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1247 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1248 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1249 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1250 this->addAction(aAction);
1251 toolMgr()->registerAction( aAction, RightId );
1253 // rotate anticlockwise
1254 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1255 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1256 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1257 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1258 this->addAction(aAction);
1259 toolMgr()->registerAction( aAction, AntiClockWiseId );
1262 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1263 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1264 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1265 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1266 this->addAction(aAction);
1267 toolMgr()->registerAction( aAction, ClockWiseId );
1270 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1271 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1272 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1273 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1274 this->addAction(aAction);
1275 toolMgr()->registerAction( aAction, ResetId );
1278 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1279 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1280 tr("MNU_CLONE_VIEW"), 0, this);
1281 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1282 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1283 toolMgr()->registerAction( aAction, CloneId );
1285 aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
1286 tr("MNU_CLIPPING"), 0, this);
1287 aAction->setStatusTip (tr("DSC_CLIPPING"));
1288 aAction->setCheckable (true);
1289 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1290 toolMgr()->registerAction (aAction, ClippingId);
1292 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1293 tr( "MNU_SHOOT_VIEW" ), 0, this);
1294 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1295 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1296 toolMgr()->registerAction( aAction, MemId );
1298 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1299 tr( "MNU_PRESETS_VIEW" ), 0, this);
1300 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1301 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1302 toolMgr()->registerAction( aAction, RestoreId );
1304 if (myModel->trihedronActivated()) {
1305 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1306 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1307 aAction->setCheckable( true );
1308 aAction->setChecked( true );
1309 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1310 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1311 toolMgr()->registerAction( aAction, TrihedronShowId );
1315 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1316 tr( "MNU_SCALING" ), 0, this);
1317 aAction->setStatusTip(tr("DSC_SCALING"));
1318 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1319 toolMgr()->registerAction( aAction, AxialScaleId );
1321 // Enable/disable preselection
1322 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1323 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1324 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1325 aAction->setCheckable(true);
1326 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1327 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1329 // Enable/disable selection
1330 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1331 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1332 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1333 aAction->setCheckable(true);
1334 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1335 toolMgr()->registerAction( aAction, SwitchSelectionId );
1338 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1339 tr( "MNU_GRADUATED_AXES" ), 0, this);
1340 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1341 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1342 toolMgr()->registerAction( aAction, GraduatedAxesId );
1344 // Active only ambient light or not
1345 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1346 tr( "MNU_AMBIENT" ), 0, this);
1347 aAction->setStatusTip(tr("DSC_AMBIENT"));
1348 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1349 toolMgr()->registerAction( aAction, AmbientId );
1351 // Switch between interaction styles
1352 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1353 tr( "MNU_STYLE_SWITCH" ), 0, this);
1354 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1355 aAction->setCheckable(true);
1356 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1357 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1359 // Switch between zooming styles
1360 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1361 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1362 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1363 aAction->setCheckable(true);
1364 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1365 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1368 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1369 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1370 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1371 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1372 toolMgr()->registerAction( aAction, MaximizedId );
1374 // Return to 3d view
1375 if (my2dMode!=No2dMode){
1376 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1377 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1378 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1379 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1380 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1384 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1388 \brief Create toolbar.
1390 void OCCViewer_ViewWindow::createToolBar()
1392 static const char* titles[] = {
1393 "LBL_3DTOOLBAR_LABEL",
1394 "LBL_XYTOOLBAR_LABEL",
1395 "LBL_XZTOOLBAR_LABEL",
1396 "LBL_YZTOOLBAR_LABEL",
1398 static const char* names[] = {
1399 "OCCViewer3DViewOperations",
1400 "OCCViewerXYViewOperations",
1401 "OCCViewerXZViewOperations",
1402 "OCCViewerYZViewOperations",
1404 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1405 QString( names[my2dMode] ), // name (language-independant)
1406 false ); // disable floatable toolbar
1407 if ( my2dMode != No2dMode ){
1408 toolMgr()->append( ReturnTo3dViewId, tid );
1409 toolMgr()->append( toolMgr()->separator(), tid );
1411 toolMgr()->append( DumpId, tid );
1412 toolMgr()->append( SwitchInteractionStyleId, tid );
1413 toolMgr()->append( SwitchZoomingStyleId, tid );
1414 toolMgr()->append( SwitchPreselectionId, tid );
1415 toolMgr()->append( SwitchSelectionId, tid );
1416 if( myModel->trihedronActivated() )
1417 toolMgr()->append( TrihedronShowId, tid );
1419 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1420 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1421 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1422 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1423 toolMgr()->append( aScaleAction, tid );
1425 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1426 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1427 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1428 toolMgr()->append( aPanningAction, tid );
1430 if (my2dMode == No2dMode) {
1431 toolMgr()->append( ChangeRotationPointId, tid );
1432 toolMgr()->append( RotationId, tid );
1434 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1435 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1436 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1437 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1438 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1439 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1440 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1441 toolMgr()->append( aViewsAction, tid );
1443 toolMgr()->append( AntiClockWiseId, tid );
1444 toolMgr()->append( ClockWiseId, tid );
1446 toolMgr()->append( ResetId, tid );
1449 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1450 aMemAction->insertAction( toolMgr()->action( MemId ) );
1451 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1452 toolMgr()->append( aMemAction, tid );
1454 toolMgr()->append( toolMgr()->separator(), tid );
1455 toolMgr()->append( CloneId, tid );
1457 toolMgr()->append( toolMgr()->separator(), tid );
1458 toolMgr()->append( ClippingId, tid );
1459 toolMgr()->append( AxialScaleId, tid );
1460 toolMgr()->append( GraduatedAxesId, tid );
1461 toolMgr()->append( AmbientId, tid );
1463 toolMgr()->append( MaximizedId, tid );
1464 toolMgr()->append( SynchronizeId, tid );
1468 \brief Perform 'fit all' operation.
1470 void OCCViewer_ViewWindow::onViewFitAll()
1472 myViewPort->fitAll();
1476 \brief Perform "front view" transformation.
1478 void OCCViewer_ViewWindow::onFrontView()
1480 emit vpTransformationStarted ( FRONTVIEW );
1481 Handle(V3d_View) aView3d = myViewPort->getView();
1482 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
1484 emit vpTransformationFinished ( FRONTVIEW );
1488 \brief Perform "back view" transformation.
1490 void OCCViewer_ViewWindow::onBackView()
1492 emit vpTransformationStarted ( BACKVIEW );
1493 Handle(V3d_View) aView3d = myViewPort->getView();
1494 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
1496 emit vpTransformationFinished ( BACKVIEW );
1500 \brief Perform "top view" transformation.
1502 void OCCViewer_ViewWindow::onTopView()
1504 emit vpTransformationStarted ( TOPVIEW );
1505 Handle(V3d_View) aView3d = myViewPort->getView();
1506 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
1508 emit vpTransformationFinished ( TOPVIEW );
1512 \brief Perform "bottom view" transformation.
1514 void OCCViewer_ViewWindow::onBottomView()
1516 emit vpTransformationStarted ( BOTTOMVIEW );
1517 Handle(V3d_View) aView3d = myViewPort->getView();
1518 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
1520 emit vpTransformationFinished ( BOTTOMVIEW );
1524 \brief Perform "left view" transformation.
1526 void OCCViewer_ViewWindow::onLeftView()
1528 emit vpTransformationStarted ( LEFTVIEW );
1529 Handle(V3d_View) aView3d = myViewPort->getView();
1530 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
1532 emit vpTransformationFinished ( LEFTVIEW );
1536 \brief Perform "right view" transformation.
1538 void OCCViewer_ViewWindow::onRightView()
1540 emit vpTransformationStarted ( RIGHTVIEW );
1541 Handle(V3d_View) aView3d = myViewPort->getView();
1542 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
1544 emit vpTransformationFinished ( RIGHTVIEW );
1548 \brief Rotate view 90 degrees clockwise
1550 void OCCViewer_ViewWindow::onClockWiseView()
1552 emit vpTransformationStarted ( CLOCKWISEVIEW );
1553 myViewPort->rotateXY( 90. );
1554 emit vpTransformationFinished ( CLOCKWISEVIEW );
1558 \brief Rotate view 90 degrees conterclockwise
1560 void OCCViewer_ViewWindow::onAntiClockWiseView()
1562 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1563 myViewPort->rotateXY( -90. );
1564 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1568 \brief Perform "reset view" transformation.
1570 Sets default orientation of the viewport camera.
1572 void OCCViewer_ViewWindow::onResetView()
1574 emit vpTransformationStarted( RESETVIEW );
1575 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1576 myViewPort->getView()->Reset( false );
1577 myViewPort->fitAll( false, true, false );
1578 myViewPort->getView()->SetImmediateUpdate( upd );
1579 myViewPort->getView()->Update();
1580 emit vpTransformationFinished( RESETVIEW );
1584 \brief Perform "fit all" transformation.
1586 void OCCViewer_ViewWindow::onFitAll()
1588 emit vpTransformationStarted( FITALLVIEW );
1589 myViewPort->fitAll();
1590 emit vpTransformationFinished( FITALLVIEW );
1594 \brief Called if 'change rotation point' operation is activated.
1595 \param on action state
1597 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1601 if (!mySetRotationPointDlg)
1603 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1604 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1607 if (!mySetRotationPointDlg->isVisible())
1609 //if (mySetRotationPointDlg->IsFirstShown())
1610 if (myCurrPointType == GRAVITY)
1612 Standard_Real Xcenter, Ycenter, Zcenter;
1613 if (computeGravityCenter(Xcenter, Ycenter, Zcenter))
1614 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1616 mySetRotationPointDlg->show();
1621 if (mySetRotationPointDlg->isVisible())
1622 mySetRotationPointDlg->hide();
1627 \brief Create one more window with same content.
1629 void OCCViewer_ViewWindow::onCloneView()
1631 SUIT_ViewWindow* vw = myManager->createViewWindow();
1633 emit viewCloned( vw );
1637 Creates one more window with same content
1639 void OCCViewer_ViewWindow::onAxialScale()
1641 if ( !myScalingDlg )
1642 myScalingDlg = new OCCViewer_AxialScaleDlg( this );
1644 if ( !myScalingDlg->isVisible() )
1646 myScalingDlg->Update();
1647 myScalingDlg->show();
1652 Shows Graduated Axes dialog
1654 void OCCViewer_ViewWindow::onGraduatedAxes()
1656 myCubeAxesDlg->Update();
1657 myCubeAxesDlg->show();
1660 void OCCViewer_ViewWindow::onAmbientToogle()
1662 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
1663 viewer->InitDefinedLights();
1664 while(viewer->MoreDefinedLights())
1666 Handle(V3d_Light) light = viewer->DefinedLight();
1667 if(light->Type() != V3d_AMBIENT)
1669 Handle(V3d_View) aView3d = myViewPort->getView();
1670 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
1671 else viewer->SetLightOn(light);
1673 viewer->NextDefinedLights();
1679 \brief Store view parameters.
1681 void OCCViewer_ViewWindow::onMemorizeView()
1683 appendViewAspect( getViewParams() );
1687 \brief Restore view parameters.
1689 void OCCViewer_ViewWindow::onRestoreView()
1691 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
1692 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
1694 updateViewAspects( aDlg->parameters() );
1695 if( myRestoreFlag && aDlg->parameters().count() )
1696 performRestoring( aDlg->currentItem() );
1700 \brief Restore view parameters.
1701 \param anItem view parameters
1703 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
1705 Handle(V3d_View) aView3d = myViewPort->getView();
1707 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
1708 aView3d->SetScale( anItem.scale );
1709 aView3d->SetTwist( anItem.twist );
1710 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
1711 aView3d->SetImmediateUpdate( prev );
1712 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1713 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1714 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
1716 #if OCC_VERSION_LARGE > 0x06070100
1717 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
1719 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
1721 // "eye" and "at" require conversion to represent center panning
1722 // up direction is only available after setting angle of twist and
1723 // other view parameters
1724 aView3d->Up( anUpX, anUpY, anUpZ );
1726 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
1727 gp_Dir anUp( anUpX, anUpY, anUpZ );
1728 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
1729 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1730 gp_Dir aSide = aProj ^ anUp;
1732 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
1733 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
1735 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
1736 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1739 aView3d->SetCenter( anItem.centerX, anItem.centerY );
1742 if ( !baseParamsOnly ) {
1744 myModel->setTrihedronShown( anItem.isVisible );
1745 myModel->setTrihedronSize( anItem.size );
1747 // graduated trihedron
1748 bool anIsVisible = anItem.gtIsVisible;
1749 OCCViewer_AxisWidget::AxisData anAxisData[3];
1750 anAxisData[0].DrawName = anItem.gtDrawNameX;
1751 anAxisData[1].DrawName = anItem.gtDrawNameZ;
1752 anAxisData[2].DrawName = anItem.gtDrawNameZ;
1753 anAxisData[0].Name = anItem.gtNameX;
1754 anAxisData[1].Name = anItem.gtNameZ;
1755 anAxisData[2].Name = anItem.gtNameZ;
1756 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
1757 anItem.gtNameColorGX,
1758 anItem.gtNameColorBX );
1759 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
1760 anItem.gtNameColorGY,
1761 anItem.gtNameColorBY );
1762 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
1763 anItem.gtNameColorGZ,
1764 anItem.gtNameColorBZ );
1765 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
1766 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
1767 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
1768 anAxisData[0].NbValues = anItem.gtNbValuesX;
1769 anAxisData[1].NbValues = anItem.gtNbValuesY;
1770 anAxisData[2].NbValues = anItem.gtNbValuesZ;
1771 anAxisData[0].Offset = anItem.gtOffsetX;
1772 anAxisData[1].Offset = anItem.gtOffsetY;
1773 anAxisData[2].Offset = anItem.gtOffsetZ;
1774 anAxisData[0].Color = QColor( anItem.gtColorRX,
1777 anAxisData[1].Color = QColor( anItem.gtColorRY,
1780 anAxisData[2].Color = QColor( anItem.gtColorRZ,
1783 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
1784 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
1785 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
1786 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
1787 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
1788 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
1790 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
1791 myCubeAxesDlg->ApplyData( aView3d );
1793 } // if ( !baseParamsOnly )
1799 \brief Set restore flag.
1801 void OCCViewer_ViewWindow::setRestoreFlag()
1807 \brief Called when action "show/hide trihedron" is activated.
1809 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
1811 myModel->setTrihedronShown(show);
1815 \brief Toggles preselection (highlighting) on/off
1817 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
1819 myPreselectionEnabled = on;
1820 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
1822 // unhighlight all highlighted objects
1824 myModel->unHighlightAll( true, false );
1827 // update action state if method is called outside
1828 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
1829 if ( a && a->isChecked() != on ) {
1830 a->setChecked( on );
1835 \brief Toggles selection on/off
1837 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
1839 mySelectionEnabled = on;
1840 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
1842 // update action state if method is called outside
1845 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
1847 a->setEnabled( on );
1851 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
1852 if ( a && a->isChecked() != on ) {
1853 a->setChecked( on );
1858 \brief Switches "keyboard free" interaction style on/off
1860 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
1862 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
1864 // update action state if method is called outside
1865 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
1866 if ( a->isChecked() != on )
1867 a->setChecked( on );
1871 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
1873 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
1875 myViewPort->setAdvancedZoomingEnabled( on );
1877 // update action state if method is called outside
1878 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
1879 if ( a->isChecked() != on )
1880 a->setChecked( on );
1884 \brief Get current interaction style
1885 \return interaction style
1887 int OCCViewer_ViewWindow::interactionStyle() const
1889 return myInteractionStyle;
1893 \brief Set current interaction style
1894 \param theStyle interaction style
1896 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
1898 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
1902 \brief Get current zooming style
1903 \return zooming style
1905 int OCCViewer_ViewWindow::zoomingStyle() const
1907 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
1911 \brief Set current zooming style
1912 \param theStyle zooming style
1914 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
1916 onSwitchZoomingStyle( theStyle == 1 );
1920 \brief Dump view window contents to the pixmap.
1921 \return pixmap containing all scene rendered in the window
1923 QImage OCCViewer_ViewWindow::dumpView()
1925 Handle(V3d_View) view = myViewPort->getView();
1926 if ( view.IsNull() )
1929 int aWidth = myViewPort->width();
1930 int aHeight = myViewPort->height();
1932 // rnv: An old approach to dump the OCCViewer content
1933 // Now used OCCT built-in procedure.
1935 QApplication::syncX();
1936 view->Redraw(); // In order to reactivate GL context
1939 OpenGLUtils_FrameBuffer aFrameBuffer;
1940 if( aFrameBuffer.init( aWidth, aHeight ) )
1942 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
1944 glPushAttrib( GL_VIEWPORT_BIT );
1945 glViewport( 0, 0, aWidth, aHeight );
1946 aFrameBuffer.bind();
1951 aFrameBuffer.unbind();
1954 aFrameBuffer.bind();
1955 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
1956 aFrameBuffer.unbind();
1958 anImage = anImage.rgbSwapped();
1959 anImage = anImage.mirrored();
1962 // if frame buffers are unsupported, use old functionality
1965 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
1967 QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
1969 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
1974 view->ToPixMap(aPix,aWidth, aHeight,Graphic3d_BT_RGBA);
1976 QImage anImage( aPix.Data(), aWidth, aHeight, QImage::Format_ARGB32 );
1977 anImage = anImage.mirrored();
1981 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
1982 const QString& fileName,
1983 const QString& format )
1985 if ( format != "PS" && format != "EPS")
1986 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
1988 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
1991 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
1992 else if (format == "EPS")
1993 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
1999 QString OCCViewer_ViewWindow::filter() const
2001 return tr( "OCC_IMAGE_FILES" );
2006 \brief Set parameters of the cutting plane
2007 \param on if \c true, cutting plane is enabled
2008 \param x X position of plane point
2009 \param y Y position of plane point
2010 \param z Z position of plane point
2011 \param dx X coordinate of plane normal
2012 \param dy Y coordinate of plane normal
2013 \param dz Z coordinate of plane normal
2015 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2016 const double dx, const double dy, const double dz )
2018 Handle(V3d_View) view = myViewPort->getView();
2019 if ( view.IsNull() )
2023 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2025 // try to use already existing plane or create a new one
2026 Handle(V3d_Plane) clipPlane;
2028 // calculate new a,b,c,d values for the plane
2029 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2031 pln.Coefficients(a, b, c, d);
2033 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2034 if(aPlanes.Size() > 0 ) {
2035 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2036 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2037 aClipPlane->SetEquation(pln);
2038 aClipPlane->SetOn(Standard_True);
2040 view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2044 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2045 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2046 for( ;anIter.More();anIter.Next() ){
2047 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2048 aClipPlane->SetOn(Standard_False);
2056 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2058 gp_Dir aDir = pln.Axis().Direction();
2059 gp_Pnt aPnt = pln.Location();
2060 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2065 \brief Check if any cutting plane is enabled
2066 \return \c true if at least one cutting plane is enabled
2068 bool OCCViewer_ViewWindow::isCuttingPlane()
2070 Handle(V3d_View) view = myViewPort->getView();
2072 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2073 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2074 for( ;anIter.More();anIter.Next() ) {
2075 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2076 if(aClipPlane->IsOn()) {
2085 \brief Get the visual parameters of the view window.
2086 \return visual parameters of view window
2088 viewAspect OCCViewer_ViewWindow::getViewParams() const
2090 double projX, projY, projZ, twist;
2091 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2092 double aScaleX, aScaleY, aScaleZ;
2094 Handle(V3d_View) aView3d = myViewPort->getView();
2096 aView3d->Proj( projX, projY, projZ );
2097 aView3d->At( atX, atY, atZ );
2098 aView3d->Eye( eyeX, eyeY, eyeZ );
2099 twist = aView3d->Twist();
2101 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2103 bool isShown = myModel->isTrihedronVisible();
2104 double size = myModel->trihedronSize();
2106 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2109 params.scale = aView3d->Scale();
2110 params.projX = projX;
2111 params.projY = projY;
2112 params.projZ = projZ;
2113 params.twist = twist;
2120 params.scaleX = aScaleX;
2121 params.scaleY = aScaleY;
2122 params.scaleZ = aScaleZ;
2123 params.name = aName;
2124 params.isVisible= isShown;
2127 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2128 aView3d->Center( params.centerX, params.centerY );
2131 // graduated trihedron
2132 bool anIsVisible = false;
2133 OCCViewer_AxisWidget::AxisData anAxisData[3];
2134 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2136 params.gtIsVisible = anIsVisible;
2137 params.gtDrawNameX = anAxisData[0].DrawName;
2138 params.gtDrawNameY = anAxisData[1].DrawName;
2139 params.gtDrawNameZ = anAxisData[2].DrawName;
2140 params.gtNameX = anAxisData[0].Name;
2141 params.gtNameY = anAxisData[1].Name;
2142 params.gtNameZ = anAxisData[2].Name;
2143 params.gtNameColorRX = anAxisData[0].NameColor.red();
2144 params.gtNameColorGX = anAxisData[0].NameColor.green();
2145 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2146 params.gtNameColorRY = anAxisData[1].NameColor.red();
2147 params.gtNameColorGY = anAxisData[1].NameColor.green();
2148 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2149 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2150 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2151 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2152 params.gtDrawValuesX = anAxisData[0].DrawValues;
2153 params.gtDrawValuesY = anAxisData[1].DrawValues;
2154 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2155 params.gtNbValuesX = anAxisData[0].NbValues;
2156 params.gtNbValuesY = anAxisData[1].NbValues;
2157 params.gtNbValuesZ = anAxisData[2].NbValues;
2158 params.gtOffsetX = anAxisData[0].Offset;
2159 params.gtOffsetY = anAxisData[1].Offset;
2160 params.gtOffsetZ = anAxisData[2].Offset;
2161 params.gtColorRX = anAxisData[0].Color.red();
2162 params.gtColorGX = anAxisData[0].Color.green();
2163 params.gtColorBX = anAxisData[0].Color.blue();
2164 params.gtColorRY = anAxisData[1].Color.red();
2165 params.gtColorGY = anAxisData[1].Color.green();
2166 params.gtColorBY = anAxisData[1].Color.blue();
2167 params.gtColorRZ = anAxisData[2].Color.red();
2168 params.gtColorGZ = anAxisData[2].Color.green();
2169 params.gtColorBZ = anAxisData[2].Color.blue();
2170 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2171 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2172 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2173 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2174 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2175 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2181 \brief Get visual parameters of this view window.
2182 \return visual parameters of view window
2184 QString OCCViewer_ViewWindow::getVisualParameters()
2186 viewAspect params = getViewParams();
2190 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2191 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2192 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
2193 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
2195 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2196 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2197 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2198 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2199 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2200 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2201 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2202 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2203 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2204 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2205 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2206 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2207 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2208 data << QString( "isVisible=%1" ).arg( params.isVisible );
2209 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2211 ClipPlanesList aPlanes = myModel->getClipPlanes();
2212 for ( int i=0; i < aPlanes.size(); i++ )
2214 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2215 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2216 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2217 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2218 switch ( aPlane.Mode )
2220 case OCCViewer_ClipPlane::Absolute :
2222 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2224 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2226 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2227 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2228 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2232 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2237 case OCCViewer_ClipPlane::Relative :
2239 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2240 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2241 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2246 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2247 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2248 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2249 data << ClippingPlane;
2252 // graduated trihedron
2253 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2254 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2255 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2256 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2257 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2258 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2259 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2260 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2261 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2262 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2263 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2264 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2265 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2266 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2267 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2268 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2269 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2270 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2271 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2272 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2273 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2274 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2275 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2276 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2277 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2278 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2279 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2280 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2281 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2282 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2283 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2284 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2285 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2286 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2287 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2288 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2289 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2290 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2291 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2292 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2293 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2294 data << QString( "background=%1" ).arg( bg );
2296 return data.join("*");
2300 \brief Restore visual parameters of the view window.
2301 \param parameters visual parameters of view window
2303 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2306 ClipPlanesList aClipPlanes;
2307 QStringList data = parameters.split( '*' );
2308 Qtx::BackgroundData bgData;
2309 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2311 foreach( QString param, data ) {
2312 QString paramName = param.section( '=', 0, 0 ).trimmed();
2313 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2314 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2315 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2316 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2317 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2318 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2319 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2320 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2321 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2322 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2323 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2324 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2325 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2326 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2327 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2328 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2329 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2330 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2331 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2332 else if ( paramName.contains( "ClippingPlane" ) )
2334 QStringList ClipPlaneData = paramValue.split( ';' );
2335 OCCViewer_ClipPlane aPlane;
2336 foreach( QString ClipPlaneParam, ClipPlaneData )
2338 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2339 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2340 if ( ClipPlane_paramName == "Mode" )
2342 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2344 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2345 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2346 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2347 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2350 switch ( aPlane.Mode )
2352 case OCCViewer_ClipPlane::Absolute :
2353 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2354 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2355 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2356 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2357 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2360 case OCCViewer_ClipPlane::Relative :
2361 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2362 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2363 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2368 aClipPlanes.push_back(aPlane);
2370 // graduated trihedron
2371 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2372 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2373 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2374 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2375 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2376 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2377 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2378 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2379 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2380 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2381 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2382 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2383 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2384 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2385 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2386 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2387 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2388 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2389 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2390 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2391 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2392 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2393 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2394 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2395 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2396 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2397 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2398 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2399 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2400 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2401 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2402 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2403 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2404 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2405 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2406 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2407 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2408 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2409 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2410 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2411 else if ( paramName == "background" ) {
2412 QString bg = paramValue.replace( "$", "=" );
2413 bgData = Qtx::stringToBackground( bg );
2417 else // old format - "1.000e+00*0.000e+00..."
2420 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2421 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2422 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2423 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2424 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2425 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2426 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
2427 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2428 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2429 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
2430 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2431 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2432 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2433 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
2434 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
2435 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
2436 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
2437 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
2439 performRestoring( params );
2440 setBackground( bgData );
2441 myModel->setClipPlanes(aClipPlanes);
2445 \brief Handle show event.
2447 Emits Show() signal.
2449 \param theEvent show event
2451 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2453 emit Show( theEvent );
2457 \brief Handle hide event.
2459 Emits Hide() signal.
2461 \param theEvent hide event
2463 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
2465 emit Hide( theEvent );
2470 Creates default sketcher. [ virtual protected ]
2472 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
2475 return new OCCViewer_RectSketcher( this, type );
2476 if ( type == Polygon )
2477 return new OCCViewer_PolygonSketcher( this, type );
2481 void OCCViewer_ViewWindow::initSketchers()
2483 if ( mySketchers.isEmpty() )
2485 mySketchers.append( createSketcher( Rect ) );
2486 mySketchers.append( createSketcher( Polygon ) );
2490 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
2492 OCCViewer_ViewSketcher* sketcher = 0;
2493 QList<OCCViewer_ViewSketcher*>::Iterator it;
2494 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
2496 OCCViewer_ViewSketcher* sk = (*it);
2497 if ( sk->type() == typ )
2504 Handles requests for sketching in the active view. [ virtual public ]
2506 void OCCViewer_ViewWindow::activateSketching( int type )
2508 OCCViewer_ViewPort3d* vp = getViewPort();
2512 if ( !vp->isSketchingEnabled() )
2515 /* Finish current sketching */
2516 if ( type == NoSketching )
2520 onSketchingFinished();
2521 mypSketcher->deactivate();
2525 /* Activate new sketching */
2528 activateSketching( NoSketching ); /* concurrency not suported */
2529 mypSketcher = getSketcher( type );
2532 mypSketcher->activate();
2533 onSketchingStarted();
2539 Unhilights detected entities. [ virtual protected ]
2541 void OCCViewer_ViewWindow::onSketchingStarted()
2546 Selection by rectangle or polygon. [ virtual protected ]
2548 void OCCViewer_ViewWindow::onSketchingFinished()
2550 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
2551 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
2553 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
2554 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
2555 switch( mypSketcher->type() )
2559 QRect* aRect = (QRect*)mypSketcher->data();
2562 int aLeft = aRect->left();
2563 int aRight = aRect->right();
2564 int aTop = aRect->top();
2565 int aBottom = aRect->bottom();
2569 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2571 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2577 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
2580 int size = aPolygon->size();
2581 TColgp_Array1OfPnt2d anArray( 1, size );
2583 QPolygon::Iterator it = aPolygon->begin();
2584 QPolygon::Iterator itEnd = aPolygon->end();
2585 for( int index = 1; it != itEnd; ++it, index++ )
2587 QPoint aPoint = *it;
2588 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
2592 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
2594 ic->Select( anArray, getViewPort()->getView(), Standard_False );
2602 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
2603 aViewMgr->getOCCViewer()->performSelectionChanged();
2607 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
2612 bool OCCViewer_ViewWindow::transformRequested() const
2614 return ( myOperation != NOTHING );
2617 bool OCCViewer_ViewWindow::transformInProcess() const
2619 return myEventStarted;
2622 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
2624 myEventStarted = bOn;
2628 Set enabled state of transformation (rotate, zoom, etc)
2630 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
2632 if ( id != NOTHING ) myStatus.insert( id, on );
2636 \return enabled state of transformation (rotate, zoom, etc)
2638 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
2640 return myStatus.contains( id ) ? myStatus[ id ] : true;
2643 void OCCViewer_ViewWindow::onMaximizedView()
2645 setMaximized(!isMaximized());
2648 void OCCViewer_ViewWindow::returnTo3dView()
2650 setReturnedTo3dView( true );
2653 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
2655 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
2656 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
2657 if ( !isVisible3dView )
2658 toolMgr()->show( ReturnTo3dViewId );
2660 toolMgr()->hide( ReturnTo3dViewId );
2661 if ( isVisible3dView ) emit returnedTo3d( );
2665 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
2667 QAction* anAction = toolMgr()->action( MaximizedId );
2668 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
2669 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
2671 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
2672 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
2673 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
2674 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
2675 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
2677 emit maximized( this, true );
2681 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
2682 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
2683 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
2684 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
2685 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
2687 emit maximized( this, false );
2692 bool OCCViewer_ViewWindow::isMaximized() const
2694 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
2697 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
2699 IsSketcherStyle = enable;
2702 bool OCCViewer_ViewWindow::isSketcherStyle() const
2704 return IsSketcherStyle;
2708 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
2714 QColor OCCViewer_ViewWindow::backgroundColor() const
2716 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
2720 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
2722 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
2725 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
2727 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
2730 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
2732 if ( myViewPort ) myViewPort->setBackground( theBackground );
2735 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
2737 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
2743 void OCCViewer_ViewWindow::clearViewAspects()
2745 myViewAspects.clear();
2749 \return const reference to list of view aspects
2751 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
2753 return myViewAspects;
2757 Appends new view aspect
2758 \param aParams - new view aspects
2760 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
2762 myViewAspects.append( aParams );
2766 Replaces old view aspects by new ones
2767 \param aViewList - list of new view aspects
2769 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
2771 myViewAspects = aViewList;
2775 Get camera properties for the OCC view window.
2776 \return shared pointer on camera properties.
2778 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
2780 SUIT_CameraProperties aProps;
2782 Handle(V3d_View) aSourceView = getViewPort()->getView();
2783 if ( aSourceView.IsNull() )
2786 if ( get2dMode() == No2dMode ) {
2787 aProps.setDimension( SUIT_CameraProperties::Dim3D );
2790 aProps.setDimension( SUIT_CameraProperties::Dim2D );
2791 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
2794 // read common properites of the view
2795 Standard_Real anUp[3];
2796 Standard_Real anAt[3];
2797 Standard_Real anEye[3];
2798 Standard_Real aProj[3];
2799 Standard_Real anAxialScale[3];
2801 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
2802 aSourceView->At( anAt[0], anAt[1], anAt[2] );
2803 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
2804 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2806 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2807 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
2809 #if OCC_VERSION_LARGE > 0x06070100
2810 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
2812 // store camera properties "as is": it is up to synchronized
2813 // view classes to provide necessary property conversion.
2814 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
2815 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
2817 if ( aSourceView->Camera()->IsOrthographic() )
2819 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
2820 aProps.setViewAngle( 0.0 );
2824 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
2825 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
2827 aProps.setMappingScale( aSourceView->Camera()->Scale() );
2829 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
2831 // generate view orientation matrix for transforming OCC projection reference point
2832 // into a camera (eye) position.
2833 gp_Dir aLeftDir = gp_Dir( anUp[0], anUp[1], anUp[2] ) ^ gp_Dir( aProj[0], aProj[1], aProj[2] );
2836 aTrsf.SetValue( 1, 1, aLeftDir.X() );
2837 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
2838 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
2840 aTrsf.SetValue( 1, 2, anUp[0] );
2841 aTrsf.SetValue( 2, 2, anUp[1] );
2842 aTrsf.SetValue( 3, 2, anUp[2] );
2844 aTrsf.SetValue( 1, 3, aProj[0] );
2845 aTrsf.SetValue( 2, 3, aProj[1] );
2846 aTrsf.SetValue( 3, 3, aProj[2] );
2848 aTrsf.SetValue( 1, 4, anAt[0] );
2849 aTrsf.SetValue( 2, 4, anAt[1] );
2850 aTrsf.SetValue( 3, 4, anAt[2] );
2852 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
2854 // transform to world-space coordinate system
2855 gp_XYZ aPosition( aProjRef.X(), aProjRef.Y(), aCameraDepth );
2856 aTrsf.Transforms( aPosition );
2858 // compute focal point
2859 double aFocalPoint[3];
2861 aFocalPoint[0] = aPosition.X() - aProj[0] * aCameraDepth;
2862 aFocalPoint[1] = aPosition.Y() - aProj[1] * aCameraDepth;
2863 aFocalPoint[2] = aPosition.Z() - aProj[2] * aCameraDepth;
2865 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2866 aProps.setPosition( aPosition.X(), aPosition.Y(), aPosition.Z() );
2868 Standard_Real aViewScale[2];
2869 aSourceView->Size( aViewScale[0], aViewScale[1] );
2870 aProps.setMappingScale( aViewScale[1] );
2878 This implementation synchronizes OCC view's camera propreties.
2880 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
2882 bool blocked = blockSignals( true );
2884 SUIT_CameraProperties aProps = theView->cameraProperties();
2885 if ( !cameraProperties().isCompatible( aProps ) ) {
2886 // other view, this one is being currently synchronized to, seems has become incompatible
2887 // we have to break synchronization
2892 Handle(V3d_View) aDestView = getViewPort()->getView();
2894 aDestView->SetImmediateUpdate( Standard_False );
2897 double aPosition[3];
2898 double aFocalPoint[3];
2899 double anAxialScale[3];
2901 // get common properties
2902 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2903 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
2904 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2905 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2907 #if OCC_VERSION_LARGE > 0x06070100
2908 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2909 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
2910 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2911 aDestView->Camera()->SetScale( aProps.getMappingScale() );
2913 gp_Dir aProjDir( aPosition[0] - aFocalPoint[0],
2914 aPosition[1] - aFocalPoint[1],
2915 aPosition[2] - aFocalPoint[2] );
2917 // get custom view translation
2918 Standard_Real aTranslation[3];
2919 aDestView->At( aTranslation[0], aTranslation[1], aTranslation[2] );
2921 gp_Dir aLeftDir = gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] )
2922 ^ gp_Dir( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
2925 aTrsf.SetValue( 1, 1, aLeftDir.X() );
2926 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
2927 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
2929 aTrsf.SetValue( 1, 2, anUpDir[0] );
2930 aTrsf.SetValue( 2, 2, anUpDir[1] );
2931 aTrsf.SetValue( 3, 2, anUpDir[2] );
2933 aTrsf.SetValue( 1, 3, aProjDir.X() );
2934 aTrsf.SetValue( 2, 3, aProjDir.Y() );
2935 aTrsf.SetValue( 3, 3, aProjDir.Z() );
2937 aTrsf.SetValue( 1, 4, aTranslation[0] );
2938 aTrsf.SetValue( 2, 4, aTranslation[1] );
2939 aTrsf.SetValue( 3, 4, aTranslation[2] );
2942 // transform to view-space coordinate system
2943 gp_XYZ aProjRef( aPosition[0], aPosition[1], aPosition[2] );
2944 aTrsf.Transforms( aProjRef );
2946 // set view camera properties using low-level approach. this is done
2947 // in order to avoid interference with static variables in v3d view used
2948 // when rotation is in process in another view.
2949 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
2950 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
2952 Graphic3d_Vector aMappingProj( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
2953 Graphic3d_Vector aMappingUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2955 aMappingProj.Normalize();
2956 aMappingUp.Normalize();
2958 anOrientation.SetViewReferencePlane( aMappingProj );
2959 anOrientation.SetViewReferenceUp( aMappingUp );
2961 aDestView->SetViewMapping( aMapping );
2962 aDestView->SetViewOrientation( anOrientation );
2965 aDestView->SetCenter( aProjRef.X(), aProjRef.Y() );
2967 // set mapping scale
2968 double aMapScaling = aProps.getMappingScale();
2969 Standard_Real aWidth, aHeight;
2970 aDestView->Size( aWidth, aHeight );
2971 aDestView->SetSize ( aWidth > aHeight ? aMapScaling * (aWidth / aHeight) : aMapScaling );
2974 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2976 aDestView->ZFitAll();
2977 aDestView->SetImmediateUpdate( Standard_True );
2978 aDestView->Redraw();
2980 blockSignals( blocked );
2984 \brief Indicates whether preselection is enabled
2985 \return true if preselection is enabled
2987 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
2989 return myPreselectionEnabled;
2993 \brief Enables/disables preselection
2994 \param theIsToEnable if true - preselection will be enabled
2996 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
2998 onSwitchPreselection( theIsToEnable );
3002 \brief Indicates whether selection is enabled
3003 \return true if selection is enabled
3005 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3007 return mySelectionEnabled;
3011 \brief Enables/disables selection
3012 \param theIsToEnable if true - selection will be enabled
3014 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3016 onSwitchSelection( theIsToEnable );
3021 \brief called if clipping operation is activated / deactivated.
3023 Enables/disables clipping plane displaying.
3025 \parma on action state
3027 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3029 if(!myModel) return;
3030 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3033 if (!aClippingDlg) {
3034 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3035 myModel->setClippingDlg(aClippingDlg);
3037 if (!aClippingDlg->isVisible())
3038 aClippingDlg->show();
3040 if ( aClippingDlg ) {
3041 aClippingDlg->close();
3042 myModel->setClippingDlg(0);
3046 SUIT_ViewManager* mgr = getViewManager();
3048 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3049 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3050 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3051 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3053 QAction* a = toolMgr()->action( ClippingId );
3055 if(theIsOn != a->isChecked()){
3056 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3057 a->setChecked(theIsOn);
3058 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));