1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : OCCViewer_ViewWindow.cxx
26 #include "OCCViewer_ViewWindow.h"
27 #include "OCCViewer_ViewModel.h"
28 #include "OCCViewer_ViewPort3d.h"
29 #include "OCCViewer_ViewManager.h"
30 #include "OCCViewer_ViewSketcher.h"
31 #include "OCCViewer_CreateRestoreViewDlg.h"
32 #include "OCCViewer_ClipPlane.h"
33 #include "OCCViewer_SetRotationPointDlg.h"
34 #include "OCCViewer_AxialScaleDlg.h"
35 #include "OCCViewer_CubeAxesDlg.h"
36 #include "OCCViewer_ClippingDlg.h"
38 #include <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 #ifndef DISABLE_GLVIEWER
53 #include <OpenGLUtils_FrameBuffer.h>
60 #include <QMouseEvent>
61 #include <QApplication>
62 #include <QActionGroup>
65 #include <AIS_ListOfInteractive.hxx>
66 #include <AIS_ListIteratorOfListOfInteractive.hxx>
67 #include <AIS_Shape.hxx>
69 #include <BRep_Tool.hxx>
70 #include <BRepBndLib.hxx>
71 #include <BRepGProp.hxx>
72 #include <GProp_GProps.hxx>
75 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
76 #include <Graphic3d_MapOfStructure.hxx>
77 #include <Graphic3d_Structure.hxx>
78 #include <Graphic3d_ExportFormat.hxx>
80 #include <Visual3d_View.hxx>
81 #include <V3d_Plane.hxx>
82 #include <V3d_Light.hxx>
86 #include <gp_GTrsf.hxx>
87 #include <TColgp_Array1OfPnt2d.hxx>
89 #include <Graphic3d_SequenceOfHClipPlane.hxx>
90 #include <Graphic3d_ClipPlane.hxx>
92 #include <Image_PixMap.hxx>
94 #include <Standard_Version.hxx>
96 #include "utilities.h"
100 // #include <highgui.h>
102 static QEvent* l_mbPressEvent = 0;
105 # include <QWindowsStyle>
110 const char* imageZoomCursor[] = {
115 "................................",
116 "................................",
117 ".#######........................",
118 "..aaaaaaa.......................",
119 "................................",
120 ".............#####..............",
121 "...........##.aaaa##............",
122 "..........#.aa.....a#...........",
123 ".........#.a.........#..........",
124 ".........#a..........#a.........",
125 "........#.a...........#.........",
126 "........#a............#a........",
127 "........#a............#a........",
128 "........#a............#a........",
129 "........#a............#a........",
130 ".........#...........#.a........",
131 ".........#a..........#a.........",
132 ".........##.........#.a.........",
133 "........#####.....##.a..........",
134 ".......###aaa#####.aa...........",
135 "......###aa...aaaaa.......#.....",
136 ".....###aa................#a....",
137 "....###aa.................#a....",
138 "...###aa...............#######..",
139 "....#aa.................aa#aaaa.",
140 ".....a....................#a....",
141 "..........................#a....",
142 "...........................a....",
143 "................................",
144 "................................",
145 "................................",
146 "................................"};
148 const char* imageRotateCursor[] = {
153 "................................",
154 "................................",
155 "................................",
156 "................................",
157 "........#.......................",
158 ".......#.a......................",
159 "......#######...................",
160 ".......#aaaaa#####..............",
161 "........#..##.a#aa##........##..",
162 ".........a#.aa..#..a#.....##.aa.",
163 ".........#.a.....#...#..##.aa...",
164 ".........#a.......#..###.aa.....",
165 "........#.a.......#a..#aa.......",
166 "........#a.........#..#a........",
167 "........#a.........#a.#a........",
168 "........#a.........#a.#a........",
169 "........#a.........#a.#a........",
170 ".........#.........#a#.a........",
171 "........##a........#a#a.........",
172 "......##.a#.......#.#.a.........",
173 "....##.aa..##.....##.a..........",
174 "..##.aa.....a#####.aa...........",
175 "...aa.........aaa#a.............",
176 "................#.a.............",
177 "...............#.a..............",
178 "..............#.a...............",
179 "...............a................",
180 "................................",
181 "................................",
182 "................................",
183 "................................",
184 "................................"};
186 const char* imageCrossCursor[] = {
191 "................................",
192 "................................",
193 "................................",
194 "................................",
195 "................................",
196 "................................",
197 "................................",
198 "...............#................",
199 "...............#a...............",
200 "...............#a...............",
201 "...............#a...............",
202 "...............#a...............",
203 "...............#a...............",
204 "...............#a...............",
205 "...............#a...............",
206 ".......#################........",
207 "........aaaaaaa#aaaaaaaaa.......",
208 "...............#a...............",
209 "...............#a...............",
210 "...............#a...............",
211 "...............#a...............",
212 "...............#a...............",
213 "...............#a...............",
214 "...............#a...............",
215 "................a...............",
216 "................................",
217 "................................",
218 "................................",
219 "................................",
220 "................................",
221 "................................",
222 "................................"};
227 \param theDesktop main window of application
228 \param theModel OCC 3D viewer
230 OCCViewer_ViewWindow::OCCViewer_ViewWindow( SUIT_Desktop* theDesktop,
231 OCCViewer_Viewer* theModel )
232 : SUIT_ViewWindow( theDesktop )
236 myEnableDrawMode = false;
238 updateEnabledDrawMode();
240 mySetRotationPointDlg = 0;
243 IsSketcherStyle = false;
250 myInteractionStyle = SUIT_ViewModel::STANDARD;
251 myPreselectionEnabled = true;
252 mySelectionEnabled = true;
254 myCursorIsHand = false;
263 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
266 qDeleteAll( mySketchers );
270 \brief Internal initialization.
272 void OCCViewer_ViewWindow::initLayout()
274 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
275 myViewPort->installEventFilter(this);
276 setCentralWidget(myViewPort);
277 myOperation = NOTHING;
279 myCurrPointType = GRAVITY;
280 myPrevPointType = GRAVITY;
281 mySelectedPoint = gp_Pnt(0.,0.,0.);
282 myRotationPointSelection = false;
284 setTransformRequested ( NOTHING );
285 setTransformInProcess ( false );
302 // Graduated axes dialog
303 QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
304 myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
305 myCubeAxesDlg->initialize();
307 connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
310 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
312 return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
316 \brief Detect viewer operation according the the mouse button pressed
317 and key modifiers used.
318 \param theEvent mouse event
319 \return type of the operation
321 OCCViewer_ViewWindow::OperationType
322 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
324 OperationType aOp = NOTHING;
325 SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
326 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
327 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
329 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
330 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
332 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
333 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
334 (my2dMode == No2dMode))
341 \brief Customize event handling
342 \param watched event receiver object
344 \return \c true if the event processing should be stopped
346 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
348 if ( watched == myViewPort ) {
349 int aType = e->type();
351 case QEvent::MouseButtonPress:
352 vpMousePressEvent((QMouseEvent*) e);
355 case QEvent::MouseButtonRelease:
356 vpMouseReleaseEvent((QMouseEvent*) e);
359 case QEvent::MouseMove:
360 vpMouseMoveEvent((QMouseEvent*) e);
363 case QEvent::MouseButtonDblClick:
364 emit mouseDoubleClicked(this, (QMouseEvent*)e);
369 QWheelEvent* aEvent = (QWheelEvent*) e;
371 if ( aEvent->modifiers().testFlag(Qt::ControlModifier) ) {
372 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
373 if ( isPreselectionEnabled() && ic->HasOpenedContext() ) {
374 if ( aEvent->delta() > 0 ) {
375 ic->HilightNextDetected( myViewPort->getView() );
377 ic->HilightPreviousDetected( myViewPort->getView() );
381 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
382 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
385 int x1 = (int)( aEvent->x() + width()*delta/100 );
386 int y1 = (int)( aEvent->y() + height()*delta/100 );
387 myViewPort->zoom( x, y, x1, y1 );
388 myViewPort->getView()->ZFitAll();
393 case QEvent::ContextMenu:
395 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
396 if ( aEvent->reason() != QContextMenuEvent::Mouse )
397 emit contextMenuRequested( aEvent );
401 case QEvent::KeyPress:
402 emit keyPressed(this, (QKeyEvent*) e);
409 return SUIT_ViewWindow::eventFilter(watched, e);
413 \brief Update state of enable draw mode state.
415 void OCCViewer_ViewWindow::updateEnabledDrawMode()
418 myEnableDrawMode = myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
422 \brief Handle mouse press event
423 \param theEvent mouse event
425 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
427 myStartX = theEvent->x();
428 myStartY = theEvent->y();
429 int anInteractionStyle = interactionStyle();
431 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
432 // which are assigned for pan and rotate - these operations are activated immediately after pressing
433 // of the first button, so it is necessary to switch to zoom when the second button is pressed
434 bool aSwitchToZoom = false;
435 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
436 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
437 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
440 switch ( myOperation ) {
442 if ( theEvent->button() == Qt::LeftButton )
443 emit vpTransformationStarted ( WINDOWFIT );
447 if ( theEvent->button() == Qt::LeftButton )
448 emit vpTransformationStarted ( PANGLOBAL );
452 if ( theEvent->button() == Qt::LeftButton ) {
453 myViewPort->startZoomAtPoint( myStartX, myStartY );
454 emit vpTransformationStarted ( ZOOMVIEW );
459 if ( aSwitchToZoom ) {
460 myViewPort->startZoomAtPoint( myStartX, myStartY );
463 else if ( theEvent->button() == Qt::LeftButton )
464 emit vpTransformationStarted ( PANVIEW );
468 if ( aSwitchToZoom ) {
469 myViewPort->startZoomAtPoint( myStartX, myStartY );
472 else if ( theEvent->button() == Qt::LeftButton ) {
473 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
474 emit vpTransformationStarted ( ROTATE );
479 /* Try to activate a transformation */
480 OperationType aState;
481 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
482 aState = getButtonState(theEvent, anInteractionStyle);
484 aState = OCCViewer_ViewWindow::NOTHING;
489 myViewPort->startZoomAtPoint( myStartX, myStartY );
497 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
500 if ( myRotationPointSelection )
502 if ( theEvent->button() == Qt::LeftButton )
504 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
506 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
508 TopoDS_Shape aShape = ic->SelectedShape();
509 GProp_GProps aSystem;
511 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
513 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
515 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE )
517 BRepGProp::LinearProperties( aShape, aSystem );
518 aPnt = aSystem.CentreOfMass();
520 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE )
522 BRepGProp::SurfaceProperties( aShape, aSystem );
523 aPnt = aSystem.CentreOfMass();
525 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID )
527 BRepGProp::VolumeProperties( aShape, aSystem );
528 aPnt = aSystem.CentreOfMass();
532 myCurrPointType = myPrevPointType;
536 if ( mySetRotationPointDlg )
538 myRotationPointSelection = false;
539 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
542 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
543 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
544 ic->CloseAllContexts();
545 myOperation = NOTHING;
546 myViewPort->setCursor( myCursor );
547 myCursorIsHand = false;
548 myRotationPointSelection = false;
552 emit mousePressed(this, theEvent);
555 /* notify that we start a transformation */
556 if ( transformRequested() )
557 emit vpTransformationStarted ( myOperation );
559 if ( transformRequested() )
560 setTransformInProcess( true );
562 /* we may need it for sketching... */
563 if ( l_mbPressEvent )
564 delete l_mbPressEvent;
565 l_mbPressEvent = new QMouseEvent( *theEvent );
570 \brief Start zooming operation.
572 Sets the corresponding cursor for the widget.
574 void OCCViewer_ViewWindow::activateZoom()
576 if ( !transformRequested() && !myCursorIsHand )
577 saveCursor(); /* save old cursor */
579 if ( myOperation != ZOOMVIEW ) {
580 QPixmap zoomPixmap (imageZoomCursor);
581 QCursor zoomCursor (zoomPixmap);
582 if( setTransformRequested ( ZOOMVIEW ) )
583 myViewPort->setCursor( zoomCursor );
589 \brief Start panning operation.
591 Sets the corresponding cursor for the widget.
593 void OCCViewer_ViewWindow::activatePanning()
595 if ( !transformRequested() && !myCursorIsHand )
596 saveCursor(); // save old cursor
598 if ( myOperation != PANVIEW ) {
599 QCursor panCursor (Qt::SizeAllCursor);
600 if( setTransformRequested ( PANVIEW ) )
601 myViewPort->setCursor( panCursor );
606 \brief Start rotation operation
608 Sets the corresponding cursor for the widget.
610 void OCCViewer_ViewWindow::activateRotation()
612 if ( !transformRequested() && !myCursorIsHand )
613 saveCursor(); // save old cursor
615 if ( myOperation != ROTATE ) {
616 QPixmap rotatePixmap (imageRotateCursor);
617 QCursor rotCursor (rotatePixmap);
618 if( setTransformRequested ( ROTATE ) )
619 myViewPort->setCursor( rotCursor );
624 \brief Compute the gravity center.
625 \param theX used to return X coordinate of the gravity center
626 \param theY used to return Y coordinate of the gravity center
627 \param theZ used to return Z coordinate of the gravity center
628 \return \c true if the gravity center is computed
630 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
632 Handle(V3d_View) aView3d = myViewPort->getView();
634 // Project boundaries points and add to avergae gravity
635 // the ones which lie within the screen limits
636 Standard_Real aScreenLimits[4] = { 0.0, 0.0, 0.0, 0.0 };
638 #if OCC_VERSION_LARGE > 0x06070100
639 // NDC space screen limits
640 aScreenLimits[0] = -1.0;
641 aScreenLimits[1] = 1.0;
642 aScreenLimits[2] = -1.0;
643 aScreenLimits[3] = 1.0;
645 aView3d->View()->ViewMapping().WindowLimit( aScreenLimits[0],
651 Standard_Integer aPointsNb = 0;
653 Standard_Real aXmin = 0.0;
654 Standard_Real aYmin = 0.0;
655 Standard_Real aZmin = 0.0;
656 Standard_Real aXmax = 0.0;
657 Standard_Real aYmax = 0.0;
658 Standard_Real aZmax = 0.0;
660 Graphic3d_MapOfStructure aSetOfStructures;
661 aView3d->View()->DisplayedStructures( aSetOfStructures );
662 Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures );
664 for( ; aStructureIt.More(); aStructureIt.Next() ) {
665 const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key();
666 if ( aStructure->IsEmpty() ) {
670 #if OCC_VERSION_LARGE > 0x06070100
671 Bnd_Box aBox = aStructure->MinMaxValues();
672 aXmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().X();
673 aYmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Y();
674 aZmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Z();
675 aXmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().X();
676 aYmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Y();
677 aZmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Z();
679 aStructure->MinMaxValues( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
682 // Infinite structures are skipped
683 Standard_Real aLIM = ShortRealLast() - 1.0;
684 if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
685 || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
689 gp_Pnt aPoints[8] = {
690 gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
691 gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
692 gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
693 gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
696 for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
697 const gp_Pnt& aBBPoint = aPoints[aPointIt];
699 #if OCC_VERSION_LARGE > 0x06070100
700 gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
701 const Standard_Real& U = aProjected.X();
702 const Standard_Real& V = aProjected.Y();
704 Standard_Real U = 0.0;
705 Standard_Real V = 0.0;
706 Standard_Real W = 0.0;
707 aView3d->View()->Projects( aBBPoint.X(), aBBPoint.Y(), aBBPoint.Z(), U, V, W );
710 if (U >= aScreenLimits[0]
711 && U <= aScreenLimits[1]
712 && V >= aScreenLimits[2]
713 && V <= aScreenLimits[3])
716 theX += aBBPoint.X();
717 theY += aBBPoint.Y();
718 theZ += aBBPoint.Z();
733 \brief Set the gravity center as a rotation point.
735 void OCCViewer_ViewWindow::activateSetRotationGravity()
737 if ( myRotationPointSelection )
739 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
740 ic->CloseAllContexts();
741 myOperation = NOTHING;
742 myViewPort->setCursor( myCursor );
743 myCursorIsHand = false;
744 myRotationPointSelection = false;
747 myPrevPointType = myCurrPointType;
748 myCurrPointType = GRAVITY;
750 Standard_Real Xcenter, Ycenter, Zcenter;
751 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
752 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
756 \brief Update gravity center in the "Set Rotation Point" dialog box.
757 \sa OCCViewer_SetRotationPointDlg class
759 void OCCViewer_ViewWindow::updateGravityCoords()
761 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == GRAVITY )
763 Standard_Real Xcenter, Ycenter, Zcenter;
764 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
765 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
770 \brief Set the point selected by the user as a rotation point.
771 \param theX X coordinate of the rotation point
772 \param theY Y coordinate of the rotation point
773 \param theZ Z coordinate of the rotation point
775 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
777 if ( myRotationPointSelection )
779 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
780 ic->CloseAllContexts();
781 myOperation = NOTHING;
782 myViewPort->setCursor( myCursor );
783 myCursorIsHand = false;
784 myRotationPointSelection = false;
787 myPrevPointType = myCurrPointType;
788 myCurrPointType = SELECTED;
789 mySelectedPoint.SetCoord(theX,theY,theZ);
793 \brief Start the shape selection process.
795 void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
797 myPrevPointType = myCurrPointType;
798 myCurrPointType = SELECTED;
800 // activate selection ------>
801 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
803 ic->OpenLocalContext();
805 AIS_ListOfInteractive aList;
806 ic->DisplayedObjects( aList );
807 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
809 Handle(AIS_InteractiveObject) anObj = it.Value();
810 if ( !anObj.IsNull() && anObj->HasPresentation() &&
811 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
814 ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
817 // activate selection <------
819 if ( !myCursorIsHand )
821 QCursor handCursor (Qt::PointingHandCursor);
822 myCursorIsHand = true;
824 myViewPort->setCursor( handCursor );
826 myRotationPointSelection = true;
830 \brief Start global panning operation
832 Sets the corresponding cursor for the widget.
834 void OCCViewer_ViewWindow::activateGlobalPanning()
836 Handle(V3d_View) aView3d = myViewPort->getView();
837 if ( !aView3d.IsNull() ) {
838 QPixmap globalPanPixmap (imageCrossCursor);
839 QCursor glPanCursor (globalPanPixmap);
840 myCurScale = aView3d->Scale();
841 aView3d->FitAll(0.01, false);
842 saveCursor(); // save old cursor
843 myViewPort->fitAll(); // fits view before selecting a new scene center
844 if( setTransformRequested( PANGLOBAL ) )
845 myViewPort->setCursor( glPanCursor );
850 \brief Starts fit operation.
852 Sets the corresponding cursor for the widget.
854 void OCCViewer_ViewWindow::activateWindowFit()
856 if ( !transformRequested() && !myCursorIsHand )
857 saveCursor(); /* save old cursor */
859 if ( myOperation != WINDOWFIT ) {
860 QCursor handCursor (Qt::PointingHandCursor);
861 if( setTransformRequested ( WINDOWFIT ) )
863 myViewPort->setCursor ( handCursor );
864 myCursorIsHand = true;
870 \brief Start delayed viewer operation.
872 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
874 bool ok = transformEnabled( op );
875 myOperation = ok ? op : NOTHING;
876 myViewPort->setMouseTracking( myOperation == NOTHING );
881 \brief Handle mouse move event.
882 \param theEvent mouse event
884 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
886 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
888 switch ( getButtonState( theEvent, interactionStyle() ) ) {
890 myViewPort->startZoomAtPoint( myStartX, myStartY );
898 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
905 myCurrX = theEvent->x();
906 myCurrY = theEvent->y();
907 switch (myOperation) {
909 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
913 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
919 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
933 if ( myRotationPointSelection || isSketcherStyle() )
935 emit mouseMoving( this, theEvent );
939 int aState = theEvent->modifiers();
940 int aButton = theEvent->buttons();
941 int anInteractionStyle = interactionStyle();
942 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
943 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
944 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
945 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
946 myDrawRect = myEnableDrawMode;
949 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
950 QCursor handCursor (Qt::PointingHandCursor);
951 myCursorIsHand = true;
953 myViewPort->setCursor( handCursor );
956 emit mouseMoving( this, theEvent );
958 else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
959 aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
960 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
961 aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
962 OCCViewer_ViewSketcher* sketcher = 0;
963 QList<OCCViewer_ViewSketcher*>::Iterator it;
964 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
966 OCCViewer_ViewSketcher* sk = (*it);
967 if( sk->isDefault() && sk->sketchButton() == aButton )
970 if ( sketcher && myCurSketch == -1 )
972 activateSketching( sketcher->type() );
975 myCurSketch = mypSketcher->sketchButton();
977 if ( l_mbPressEvent )
979 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
980 delete l_mbPressEvent;
983 QApplication::sendEvent( getViewPort(), theEvent );
988 emit mouseMoving( this, theEvent );
994 \brief Handle mouse release event.
995 \param theEvent mouse event
997 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
999 switch ( myOperation ) {
1002 int prevState = myCurSketch;
1003 if(theEvent->button() == Qt::RightButton)
1005 QList<OCCViewer_ViewSketcher*>::Iterator it;
1006 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
1008 OCCViewer_ViewSketcher* sk = (*it);
1009 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
1014 emit mouseReleased(this, theEvent);
1015 if(theEvent->button() == Qt::RightButton && prevState == -1)
1017 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1018 theEvent->pos(), theEvent->globalPos() );
1019 emit contextMenuRequested( &aEvent );
1024 myViewPort->endRotation();
1030 myViewPort->getView()->ZFitAll();
1035 if ( theEvent->button() == Qt::LeftButton ) {
1036 myViewPort->setCenter( theEvent->x(), theEvent->y() );
1037 myViewPort->getView()->SetScale(myCurScale);
1043 if ( theEvent->button() == Qt::LeftButton ) {
1044 myCurrX = theEvent->x();
1045 myCurrY = theEvent->y();
1047 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1048 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1055 // NOTE: viewer 3D detects a rectangle of selection using this event
1056 // so we must emit it BEFORE resetting the selection rectangle
1058 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1062 myViewPort->update();
1065 if ( l_mbPressEvent )
1067 delete l_mbPressEvent;
1073 \brief Reset the viewport to its initial state
1074 ( no transformations in process etc. )
1076 void OCCViewer_ViewWindow::resetState()
1080 if ( myRotationPointSelection )
1082 QCursor handCursor (Qt::PointingHandCursor);
1083 myViewPort->setCursor( handCursor );
1087 if ( transformRequested() || myCursorIsHand )
1088 myViewPort->setCursor( myCursor );
1089 myCursorIsHand = false;
1092 if ( transformRequested() )
1093 emit vpTransformationFinished (myOperation);
1095 setTransformInProcess( false );
1096 setTransformRequested( NOTHING );
1101 \brief Draw rubber band rectangle.
1103 void OCCViewer_ViewWindow::drawRect()
1105 if ( !myRectBand ) {
1106 myRectBand = new QtxRectRubberBand( myViewPort );
1108 //palette.setColor(myRectBand->foregroundRole(), Qt::white);
1109 //myRectBand->setPalette(palette);
1111 //myRectBand->hide();
1113 myRectBand->setUpdatesEnabled ( false );
1114 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1115 myRectBand->initGeometry( aRect );
1117 if ( !myRectBand->isVisible() )
1120 myRectBand->setUpdatesEnabled ( true );
1121 //myRectBand->repaint();
1123 //myRectBand->setVisible( aRect.isValid() );
1124 //if ( myRectBand->isVisible() )
1125 // myRectBand->repaint();
1127 // myRectBand->show();
1128 //myRectBand->repaint();
1132 \brief Clear rubber band rectangle on the end on the dragging operation.
1134 void OCCViewer_ViewWindow::endDrawRect()
1136 //delete myRectBand;
1140 myRectBand->clearGeometry();
1146 \brief Create actions.
1148 void OCCViewer_ViewWindow::createActions()
1150 if( !toolMgr()->isEmpty() )
1153 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1158 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1159 tr( "MNU_DUMP_VIEW" ), 0, this);
1160 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1161 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1162 toolMgr()->registerAction( aAction, DumpId );
1165 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1166 tr( "MNU_FITALL" ), 0, this);
1167 aAction->setStatusTip(tr("DSC_FITALL"));
1168 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1169 toolMgr()->registerAction( aAction, FitAllId );
1172 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1173 tr( "MNU_FITRECT" ), 0, this);
1174 aAction->setStatusTip(tr("DSC_FITRECT"));
1175 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1176 toolMgr()->registerAction( aAction, FitRectId );
1179 aAction = new QtxAction(tr("MNU_FITSELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITSELECTION" ) ),
1180 tr( "MNU_FITSELECTION" ), 0, this);
1181 aAction->setStatusTip(tr("DSC_FITSELECTION"));
1182 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
1183 toolMgr()->registerAction( aAction, FitSelectionId );
1186 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1187 tr( "MNU_ZOOM_VIEW" ), 0, this);
1188 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1189 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1190 toolMgr()->registerAction( aAction, ZoomId );
1193 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1194 tr( "MNU_PAN_VIEW" ), 0, this);
1195 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1196 connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
1197 toolMgr()->registerAction( aAction, PanId );
1200 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1201 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1202 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1203 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1204 toolMgr()->registerAction( aAction, GlobalPanId );
1207 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1208 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1209 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1210 mySetRotationPointAction->setCheckable( true );
1211 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1212 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1215 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1216 tr( "MNU_ROTATE_VIEW" ), 0, this);
1217 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1218 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1219 toolMgr()->registerAction( aAction, RotationId );
1222 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1223 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1224 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1225 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1226 this->addAction(aAction);
1227 toolMgr()->registerAction( aAction, FrontId );
1229 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1230 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1231 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1232 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1233 this->addAction(aAction);
1234 toolMgr()->registerAction( aAction, BackId );
1236 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1237 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1238 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1239 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1240 this->addAction(aAction);
1241 toolMgr()->registerAction( aAction, TopId );
1243 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1244 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1245 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1246 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1247 this->addAction(aAction);
1248 toolMgr()->registerAction( aAction, BottomId );
1250 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1251 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1252 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1253 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1254 this->addAction(aAction);
1255 toolMgr()->registerAction( aAction, LeftId );
1257 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1258 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1259 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1260 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1261 this->addAction(aAction);
1262 toolMgr()->registerAction( aAction, RightId );
1264 // rotate anticlockwise
1265 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1266 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1267 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1268 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1269 this->addAction(aAction);
1270 toolMgr()->registerAction( aAction, AntiClockWiseId );
1273 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1274 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1275 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1276 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1277 this->addAction(aAction);
1278 toolMgr()->registerAction( aAction, ClockWiseId );
1280 // Projection mode group
1282 // - orthographic projection
1283 aAction = new QtxAction(tr("MNU_ORTHOGRAPHIC_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ORTHOGRAPHIC" ) ),
1284 tr( "MNU_ORTHOGRAPHIC_MODE" ), 0, this);
1285 aAction->setStatusTip(tr("DSC_ORTHOGRAPHIC_MODE"));
1286 aAction->setCheckable(true);
1287 //connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onProjectionType()));
1288 toolMgr()->registerAction( aAction, OrthographicId );
1290 // - perspective projection
1291 aAction = new QtxAction(tr("MNU_PERSPECTIVE_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PERSPECTIVE" ) ),
1292 tr( "MNU_PERSPECTIVE_MODE" ), 0, this);
1293 aAction->setStatusTip(tr("DSC_PERSPECTIVE_MODE"));
1294 aAction->setCheckable(true);
1295 //connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onProjectionType()));
1296 toolMgr()->registerAction( aAction, PerspectiveId );
1298 // - add exclusive action group
1299 QActionGroup* aProjectionGroup = new QActionGroup( this );
1300 aProjectionGroup->addAction( toolMgr()->action( OrthographicId ) );
1301 aProjectionGroup->addAction( toolMgr()->action( PerspectiveId ) );
1302 connect(aProjectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProjectionType()));
1305 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1306 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1307 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1308 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1309 this->addAction(aAction);
1310 toolMgr()->registerAction( aAction, ResetId );
1313 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1314 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1315 tr("MNU_CLONE_VIEW"), 0, this);
1316 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1317 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1318 toolMgr()->registerAction( aAction, CloneId );
1320 aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
1321 tr("MNU_CLIPPING"), 0, this);
1322 aAction->setStatusTip (tr("DSC_CLIPPING"));
1323 aAction->setCheckable (true);
1324 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1325 toolMgr()->registerAction (aAction, ClippingId);
1327 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1328 tr( "MNU_SHOOT_VIEW" ), 0, this);
1329 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1330 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1331 toolMgr()->registerAction( aAction, MemId );
1333 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1334 tr( "MNU_PRESETS_VIEW" ), 0, this);
1335 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1336 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1337 toolMgr()->registerAction( aAction, RestoreId );
1339 if (myModel->trihedronActivated()) {
1340 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1341 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1342 aAction->setCheckable( true );
1343 aAction->setChecked( true );
1344 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1345 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1346 toolMgr()->registerAction( aAction, TrihedronShowId );
1350 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1351 tr( "MNU_SCALING" ), 0, this);
1352 aAction->setStatusTip(tr("DSC_SCALING"));
1353 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1354 toolMgr()->registerAction( aAction, AxialScaleId );
1356 // Enable/disable preselection
1357 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1358 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1359 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1360 aAction->setCheckable(true);
1361 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1362 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1364 // Enable/disable selection
1365 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1366 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1367 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1368 aAction->setCheckable(true);
1369 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1370 toolMgr()->registerAction( aAction, SwitchSelectionId );
1373 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1374 tr( "MNU_GRADUATED_AXES" ), 0, this);
1375 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1376 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1377 toolMgr()->registerAction( aAction, GraduatedAxesId );
1379 // Active only ambient light or not
1380 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1381 tr( "MNU_AMBIENT" ), 0, this);
1382 aAction->setStatusTip(tr("DSC_AMBIENT"));
1383 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1384 toolMgr()->registerAction( aAction, AmbientId );
1386 // Switch between interaction styles
1387 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1388 tr( "MNU_STYLE_SWITCH" ), 0, this);
1389 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1390 aAction->setCheckable(true);
1391 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1392 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1394 // Switch between zooming styles
1395 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1396 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1397 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1398 aAction->setCheckable(true);
1399 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1400 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1403 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1404 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1405 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1406 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1407 toolMgr()->registerAction( aAction, MaximizedId );
1409 // Return to 3d view
1410 if (my2dMode!=No2dMode){
1411 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1412 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1413 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1414 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1415 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1419 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1423 \brief Create toolbar.
1425 void OCCViewer_ViewWindow::createToolBar()
1427 static const char* titles[] = {
1428 "LBL_3DTOOLBAR_LABEL",
1429 "LBL_XYTOOLBAR_LABEL",
1430 "LBL_XZTOOLBAR_LABEL",
1431 "LBL_YZTOOLBAR_LABEL",
1433 static const char* names[] = {
1434 "OCCViewer3DViewOperations",
1435 "OCCViewerXYViewOperations",
1436 "OCCViewerXZViewOperations",
1437 "OCCViewerYZViewOperations",
1439 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1440 QString( names[my2dMode] ), // name (language-independant)
1441 false ); // disable floatable toolbar
1442 if ( my2dMode != No2dMode ){
1443 toolMgr()->append( ReturnTo3dViewId, tid );
1444 toolMgr()->append( toolMgr()->separator(), tid );
1446 toolMgr()->append( DumpId, tid );
1447 toolMgr()->append( SwitchInteractionStyleId, tid );
1448 toolMgr()->append( SwitchZoomingStyleId, tid );
1449 toolMgr()->append( SwitchPreselectionId, tid );
1450 toolMgr()->append( SwitchSelectionId, tid );
1451 if( myModel->trihedronActivated() )
1452 toolMgr()->append( TrihedronShowId, tid );
1454 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1455 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1456 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1457 #if OCC_VERSION_LARGE > 0x06090000
1458 aScaleAction->insertAction( toolMgr()->action( FitSelectionId ) );
1460 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1461 toolMgr()->append( aScaleAction, tid );
1463 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1464 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1465 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1466 toolMgr()->append( aPanningAction, tid );
1468 if (my2dMode == No2dMode) {
1469 toolMgr()->append( ChangeRotationPointId, tid );
1470 toolMgr()->append( RotationId, tid );
1472 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1473 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1474 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1475 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1476 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1477 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1478 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1479 toolMgr()->append( aViewsAction, tid );
1481 toolMgr()->append( AntiClockWiseId, tid );
1482 toolMgr()->append( ClockWiseId, tid );
1484 toolMgr()->append( OrthographicId, tid );
1485 toolMgr()->append( PerspectiveId, tid );
1487 toolMgr()->append( ResetId, tid );
1490 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1491 aMemAction->insertAction( toolMgr()->action( MemId ) );
1492 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1493 toolMgr()->append( aMemAction, tid );
1495 toolMgr()->append( toolMgr()->separator(), tid );
1496 toolMgr()->append( CloneId, tid );
1498 toolMgr()->append( toolMgr()->separator(), tid );
1499 toolMgr()->append( ClippingId, tid );
1500 toolMgr()->append( AxialScaleId, tid );
1501 toolMgr()->append( GraduatedAxesId, tid );
1502 toolMgr()->append( AmbientId, tid );
1504 toolMgr()->append( MaximizedId, tid );
1505 toolMgr()->append( SynchronizeId, tid );
1509 \brief Perform 'fit all' operation.
1511 void OCCViewer_ViewWindow::onViewFitAll()
1513 myViewPort->fitAll();
1517 \brief Perform "front view" transformation.
1519 void OCCViewer_ViewWindow::onFrontView()
1521 emit vpTransformationStarted ( FRONTVIEW );
1522 Handle(V3d_View) aView3d = myViewPort->getView();
1523 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
1525 emit vpTransformationFinished ( FRONTVIEW );
1529 \brief Perform "back view" transformation.
1531 void OCCViewer_ViewWindow::onBackView()
1533 emit vpTransformationStarted ( BACKVIEW );
1534 Handle(V3d_View) aView3d = myViewPort->getView();
1535 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
1537 emit vpTransformationFinished ( BACKVIEW );
1541 \brief Perform "top view" transformation.
1543 void OCCViewer_ViewWindow::onTopView()
1545 emit vpTransformationStarted ( TOPVIEW );
1546 Handle(V3d_View) aView3d = myViewPort->getView();
1547 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
1549 emit vpTransformationFinished ( TOPVIEW );
1553 \brief Perform "bottom view" transformation.
1555 void OCCViewer_ViewWindow::onBottomView()
1557 emit vpTransformationStarted ( BOTTOMVIEW );
1558 Handle(V3d_View) aView3d = myViewPort->getView();
1559 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
1561 emit vpTransformationFinished ( BOTTOMVIEW );
1565 \brief Perform "left view" transformation.
1567 void OCCViewer_ViewWindow::onLeftView()
1569 emit vpTransformationStarted ( LEFTVIEW );
1570 Handle(V3d_View) aView3d = myViewPort->getView();
1571 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
1573 emit vpTransformationFinished ( LEFTVIEW );
1577 \brief Perform "right view" transformation.
1579 void OCCViewer_ViewWindow::onRightView()
1581 emit vpTransformationStarted ( RIGHTVIEW );
1582 Handle(V3d_View) aView3d = myViewPort->getView();
1583 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
1585 emit vpTransformationFinished ( RIGHTVIEW );
1589 \brief Rotate view 90 degrees clockwise
1591 void OCCViewer_ViewWindow::onClockWiseView()
1593 emit vpTransformationStarted ( CLOCKWISEVIEW );
1594 myViewPort->rotateXY( 90. );
1595 emit vpTransformationFinished ( CLOCKWISEVIEW );
1599 \brief Rotate view 90 degrees conterclockwise
1601 void OCCViewer_ViewWindow::onAntiClockWiseView()
1603 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1604 myViewPort->rotateXY( -90. );
1605 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1609 \brief Perform "reset view" transformation.
1611 Sets default orientation of the viewport camera.
1613 void OCCViewer_ViewWindow::onResetView()
1615 emit vpTransformationStarted( RESETVIEW );
1616 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1617 myViewPort->getView()->Reset( false );
1618 myViewPort->fitAll( false, true, false );
1619 myViewPort->getView()->SetImmediateUpdate( upd );
1620 onProjectionType(); // needed to apply projection type properly after reset
1621 myViewPort->getView()->Update();
1622 emit vpTransformationFinished( RESETVIEW );
1626 \brief Perform "reset view" transformation.
1628 Sets default orientation of the viewport camera.
1630 void OCCViewer_ViewWindow::onProjectionType()
1632 emit vpTransformationStarted( PROJECTION );
1633 setProjectionType( toolMgr()->action( OrthographicId )->isChecked() ? Orthographic : Perspective );
1634 emit vpTransformationFinished( PROJECTION );
1638 \brief Perform "fit all" transformation.
1640 void OCCViewer_ViewWindow::onFitAll()
1642 emit vpTransformationStarted( FITALLVIEW );
1643 myViewPort->fitAll();
1644 emit vpTransformationFinished( FITALLVIEW );
1648 \brief Perform "fit selection" transformation.
1650 void OCCViewer_ViewWindow::onFitSelection()
1652 emit vpTransformationStarted( FITSELECTION );
1653 #if OCC_VERSION_LARGE > 0x06090000
1654 myModel->getAISContext()->FitSelected( getViewPort()->getView() );
1656 emit vpTransformationFinished( FITSELECTION );
1660 \brief Called if 'change rotation point' operation is activated.
1661 \param on action state
1663 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1667 if (!mySetRotationPointDlg)
1669 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1670 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1673 if (!mySetRotationPointDlg->isVisible())
1675 //if (mySetRotationPointDlg->IsFirstShown())
1676 if (myCurrPointType == GRAVITY)
1678 Standard_Real Xcenter, Ycenter, Zcenter;
1679 if (computeGravityCenter(Xcenter, Ycenter, Zcenter))
1680 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1682 mySetRotationPointDlg->show();
1687 if (mySetRotationPointDlg->isVisible())
1688 mySetRotationPointDlg->hide();
1693 \brief Create one more window with same content.
1695 void OCCViewer_ViewWindow::onCloneView()
1697 SUIT_ViewWindow* vw = myManager->createViewWindow();
1699 emit viewCloned( vw );
1703 Creates one more window with same content
1705 void OCCViewer_ViewWindow::onAxialScale()
1707 if ( !myScalingDlg )
1708 myScalingDlg = new OCCViewer_AxialScaleDlg( this );
1710 if ( !myScalingDlg->isVisible() )
1712 myScalingDlg->Update();
1713 myScalingDlg->show();
1718 Shows Graduated Axes dialog
1720 void OCCViewer_ViewWindow::onGraduatedAxes()
1722 myCubeAxesDlg->Update();
1723 myCubeAxesDlg->show();
1726 void OCCViewer_ViewWindow::onAmbientToogle()
1728 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
1729 viewer->InitDefinedLights();
1730 while(viewer->MoreDefinedLights())
1732 Handle(V3d_Light) light = viewer->DefinedLight();
1733 if(light->Type() != V3d_AMBIENT)
1735 Handle(V3d_View) aView3d = myViewPort->getView();
1736 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
1737 else viewer->SetLightOn(light);
1739 viewer->NextDefinedLights();
1745 \brief Store view parameters.
1747 void OCCViewer_ViewWindow::onMemorizeView()
1749 appendViewAspect( getViewParams() );
1753 \brief Restore view parameters.
1755 void OCCViewer_ViewWindow::onRestoreView()
1757 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
1758 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
1760 updateViewAspects( aDlg->parameters() );
1761 if( myRestoreFlag && aDlg->parameters().count() )
1762 performRestoring( aDlg->currentItem() );
1766 \brief Restore view parameters.
1767 \param anItem view parameters
1769 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
1771 Handle(V3d_View) aView3d = myViewPort->getView();
1773 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
1774 aView3d->SetScale( anItem.scale );
1775 aView3d->SetTwist( anItem.twist );
1776 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
1777 aView3d->SetImmediateUpdate( prev );
1778 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1779 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1780 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
1782 #if OCC_VERSION_LARGE > 0x06070100
1783 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
1785 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
1787 // "eye" and "at" require conversion to represent center panning
1788 // up direction is only available after setting angle of twist and
1789 // other view parameters
1790 aView3d->Up( anUpX, anUpY, anUpZ );
1792 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
1793 gp_Dir anUp( anUpX, anUpY, anUpZ );
1794 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
1795 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1796 gp_Dir aSide = aProj ^ anUp;
1798 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
1799 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
1801 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
1802 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1805 aView3d->SetCenter( anItem.centerX, anItem.centerY );
1808 if ( !baseParamsOnly ) {
1810 myModel->setTrihedronShown( anItem.isVisible );
1811 myModel->setTrihedronSize( anItem.size );
1813 // graduated trihedron
1814 bool anIsVisible = anItem.gtIsVisible;
1815 OCCViewer_AxisWidget::AxisData anAxisData[3];
1816 anAxisData[0].DrawName = anItem.gtDrawNameX;
1817 anAxisData[1].DrawName = anItem.gtDrawNameZ;
1818 anAxisData[2].DrawName = anItem.gtDrawNameZ;
1819 anAxisData[0].Name = anItem.gtNameX;
1820 anAxisData[1].Name = anItem.gtNameZ;
1821 anAxisData[2].Name = anItem.gtNameZ;
1822 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
1823 anItem.gtNameColorGX,
1824 anItem.gtNameColorBX );
1825 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
1826 anItem.gtNameColorGY,
1827 anItem.gtNameColorBY );
1828 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
1829 anItem.gtNameColorGZ,
1830 anItem.gtNameColorBZ );
1831 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
1832 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
1833 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
1834 anAxisData[0].NbValues = anItem.gtNbValuesX;
1835 anAxisData[1].NbValues = anItem.gtNbValuesY;
1836 anAxisData[2].NbValues = anItem.gtNbValuesZ;
1837 anAxisData[0].Offset = anItem.gtOffsetX;
1838 anAxisData[1].Offset = anItem.gtOffsetY;
1839 anAxisData[2].Offset = anItem.gtOffsetZ;
1840 anAxisData[0].Color = QColor( anItem.gtColorRX,
1843 anAxisData[1].Color = QColor( anItem.gtColorRY,
1846 anAxisData[2].Color = QColor( anItem.gtColorRZ,
1849 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
1850 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
1851 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
1852 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
1853 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
1854 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
1856 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
1857 myCubeAxesDlg->ApplyData( aView3d );
1859 } // if ( !baseParamsOnly )
1865 \brief Set restore flag.
1867 void OCCViewer_ViewWindow::setRestoreFlag()
1873 \brief Called when action "show/hide trihedron" is activated.
1875 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
1877 myModel->setTrihedronShown(show);
1881 \brief Toggles preselection (highlighting) on/off
1883 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
1885 myPreselectionEnabled = on;
1886 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
1888 // unhighlight all highlighted objects
1890 myModel->unHighlightAll( true, false );
1893 // update action state if method is called outside
1894 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
1895 if ( a && a->isChecked() != on ) {
1896 a->setChecked( on );
1901 \brief Toggles selection on/off
1903 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
1905 mySelectionEnabled = on;
1906 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
1908 // update action state if method is called outside
1911 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
1913 a->setEnabled( on );
1917 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
1918 if ( a && a->isChecked() != on ) {
1919 a->setChecked( on );
1924 \brief Switches "keyboard free" interaction style on/off
1926 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
1928 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
1930 // update action state if method is called outside
1931 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
1932 if ( a->isChecked() != on )
1933 a->setChecked( on );
1937 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
1939 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
1941 myViewPort->setAdvancedZoomingEnabled( on );
1943 // update action state if method is called outside
1944 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
1945 if ( a->isChecked() != on )
1946 a->setChecked( on );
1950 \brief Get current interaction style
1951 \return interaction style
1953 int OCCViewer_ViewWindow::interactionStyle() const
1955 return myInteractionStyle;
1959 \brief Set current interaction style
1960 \param theStyle interaction style
1962 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
1964 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
1968 \brief Get current zooming style
1969 \return zooming style
1971 int OCCViewer_ViewWindow::zoomingStyle() const
1973 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
1977 \brief Set current zooming style
1978 \param theStyle zooming style
1980 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
1982 onSwitchZoomingStyle( theStyle == 1 );
1986 \brief Dump view window contents to the pixmap.
1987 \return pixmap containing all scene rendered in the window
1989 QImage OCCViewer_ViewWindow::dumpView()
1991 Handle(V3d_View) view = myViewPort->getView();
1992 if ( view.IsNull() )
1995 int aWidth = myViewPort->width();
1996 int aHeight = myViewPort->height();
1998 // rnv: An old approach to dump the OCCViewer content
1999 // Now used OCCT built-in procedure.
2001 QApplication::syncX();
2002 view->Redraw(); // In order to reactivate GL context
2005 #ifndef DISABLE_GLVIEWER
2006 OpenGLUtils_FrameBuffer aFrameBuffer;
2007 if( aFrameBuffer.init( aWidth, aHeight ) )
2009 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
2011 glPushAttrib( GL_VIEWPORT_BIT );
2012 glViewport( 0, 0, aWidth, aHeight );
2013 aFrameBuffer.bind();
2018 aFrameBuffer.unbind();
2021 aFrameBuffer.bind();
2022 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
2023 aFrameBuffer.unbind();
2025 anImage = anImage.rgbSwapped();
2026 anImage = anImage.mirrored();
2029 // if frame buffers are unsupported, use old functionality
2032 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
2034 QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
2036 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
2042 view->ToPixMap(aPix,aWidth, aHeight,Graphic3d_BT_RGBA);
2044 QImage anImage( aPix.Data(), aWidth, aHeight, QImage::Format_ARGB32 );
2045 anImage = anImage.mirrored();
2049 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
2050 const QString& fileName,
2051 const QString& format )
2053 if ( format != "PS" && format != "EPS")
2054 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
2056 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
2059 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
2060 else if (format == "EPS")
2061 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
2067 QString OCCViewer_ViewWindow::filter() const
2069 return tr( "OCC_IMAGE_FILES" );
2074 \brief Set parameters of the cutting plane
2075 \param on if \c true, cutting plane is enabled
2076 \param x X position of plane point
2077 \param y Y position of plane point
2078 \param z Z position of plane point
2079 \param dx X coordinate of plane normal
2080 \param dy Y coordinate of plane normal
2081 \param dz Z coordinate of plane normal
2083 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2084 const double dx, const double dy, const double dz )
2086 Handle(V3d_View) view = myViewPort->getView();
2087 if ( view.IsNull() )
2091 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2093 // try to use already existing plane or create a new one
2094 Handle(V3d_Plane) clipPlane;
2096 // calculate new a,b,c,d values for the plane
2097 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2099 pln.Coefficients(a, b, c, d);
2101 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2102 if(aPlanes.Size() > 0 ) {
2103 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2104 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2105 aClipPlane->SetEquation(pln);
2106 aClipPlane->SetOn(Standard_True);
2108 view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2112 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2113 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2114 for( ;anIter.More();anIter.Next() ){
2115 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2116 aClipPlane->SetOn(Standard_False);
2124 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2126 gp_Dir aDir = pln.Axis().Direction();
2127 gp_Pnt aPnt = pln.Location();
2128 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2133 \brief Check if any cutting plane is enabled
2134 \return \c true if at least one cutting plane is enabled
2136 bool OCCViewer_ViewWindow::isCuttingPlane()
2138 Handle(V3d_View) view = myViewPort->getView();
2140 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2141 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2142 for( ;anIter.More();anIter.Next() ) {
2143 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2144 if(aClipPlane->IsOn()) {
2153 \brief Get the visual parameters of the view window.
2154 \return visual parameters of view window
2156 viewAspect OCCViewer_ViewWindow::getViewParams() const
2158 double projX, projY, projZ, twist;
2159 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2160 double aScaleX, aScaleY, aScaleZ;
2162 Handle(V3d_View) aView3d = myViewPort->getView();
2164 aView3d->Proj( projX, projY, projZ );
2165 aView3d->At( atX, atY, atZ );
2166 aView3d->Eye( eyeX, eyeY, eyeZ );
2167 twist = aView3d->Twist();
2169 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2171 bool isShown = myModel->isTrihedronVisible();
2172 double size = myModel->trihedronSize();
2174 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2177 params.scale = aView3d->Scale();
2178 params.projX = projX;
2179 params.projY = projY;
2180 params.projZ = projZ;
2181 params.twist = twist;
2188 params.scaleX = aScaleX;
2189 params.scaleY = aScaleY;
2190 params.scaleZ = aScaleZ;
2191 params.name = aName;
2192 params.isVisible= isShown;
2195 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2196 aView3d->Center( params.centerX, params.centerY );
2199 // graduated trihedron
2200 bool anIsVisible = false;
2201 OCCViewer_AxisWidget::AxisData anAxisData[3];
2202 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2204 params.gtIsVisible = anIsVisible;
2205 params.gtDrawNameX = anAxisData[0].DrawName;
2206 params.gtDrawNameY = anAxisData[1].DrawName;
2207 params.gtDrawNameZ = anAxisData[2].DrawName;
2208 params.gtNameX = anAxisData[0].Name;
2209 params.gtNameY = anAxisData[1].Name;
2210 params.gtNameZ = anAxisData[2].Name;
2211 params.gtNameColorRX = anAxisData[0].NameColor.red();
2212 params.gtNameColorGX = anAxisData[0].NameColor.green();
2213 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2214 params.gtNameColorRY = anAxisData[1].NameColor.red();
2215 params.gtNameColorGY = anAxisData[1].NameColor.green();
2216 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2217 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2218 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2219 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2220 params.gtDrawValuesX = anAxisData[0].DrawValues;
2221 params.gtDrawValuesY = anAxisData[1].DrawValues;
2222 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2223 params.gtNbValuesX = anAxisData[0].NbValues;
2224 params.gtNbValuesY = anAxisData[1].NbValues;
2225 params.gtNbValuesZ = anAxisData[2].NbValues;
2226 params.gtOffsetX = anAxisData[0].Offset;
2227 params.gtOffsetY = anAxisData[1].Offset;
2228 params.gtOffsetZ = anAxisData[2].Offset;
2229 params.gtColorRX = anAxisData[0].Color.red();
2230 params.gtColorGX = anAxisData[0].Color.green();
2231 params.gtColorBX = anAxisData[0].Color.blue();
2232 params.gtColorRY = anAxisData[1].Color.red();
2233 params.gtColorGY = anAxisData[1].Color.green();
2234 params.gtColorBY = anAxisData[1].Color.blue();
2235 params.gtColorRZ = anAxisData[2].Color.red();
2236 params.gtColorGZ = anAxisData[2].Color.green();
2237 params.gtColorBZ = anAxisData[2].Color.blue();
2238 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2239 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2240 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2241 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2242 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2243 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2249 \brief Get visual parameters of this view window.
2250 \return visual parameters of view window
2252 QString OCCViewer_ViewWindow::getVisualParameters()
2254 viewAspect params = getViewParams();
2258 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2259 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2260 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
2261 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
2263 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2264 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2265 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2266 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2267 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2268 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2269 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2270 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2271 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2272 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2273 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2274 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2275 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2276 data << QString( "isVisible=%1" ).arg( params.isVisible );
2277 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2279 ClipPlanesList aPlanes = myModel->getClipPlanes();
2280 for ( int i=0; i < aPlanes.size(); i++ )
2282 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2283 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2284 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2285 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2286 switch ( aPlane.Mode )
2288 case OCCViewer_ClipPlane::Absolute :
2290 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2292 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2294 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2295 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2296 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2300 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2305 case OCCViewer_ClipPlane::Relative :
2307 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2308 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2309 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2314 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2315 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2316 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2317 data << ClippingPlane;
2320 // graduated trihedron
2321 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2322 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2323 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2324 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2325 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2326 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2327 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2328 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2329 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2330 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2331 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2332 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2333 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2334 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2335 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2336 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2337 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2338 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2339 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2340 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2341 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2342 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2343 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2344 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2345 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2346 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2347 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2348 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2349 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2350 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2351 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2352 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2353 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2354 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2355 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2356 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2357 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2358 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2359 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2360 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2361 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2362 data << QString( "background=%1" ).arg( bg );
2364 return data.join("*");
2368 \brief Restore visual parameters of the view window.
2369 \param parameters visual parameters of view window
2371 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2374 ClipPlanesList aClipPlanes;
2375 QStringList data = parameters.split( '*' );
2376 Qtx::BackgroundData bgData;
2377 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2379 foreach( QString param, data ) {
2380 QString paramName = param.section( '=', 0, 0 ).trimmed();
2381 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2382 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2383 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2384 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2385 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2386 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2387 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2388 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2389 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2390 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2391 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2392 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2393 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2394 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2395 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2396 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2397 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2398 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2399 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2400 else if ( paramName.contains( "ClippingPlane" ) )
2402 QStringList ClipPlaneData = paramValue.split( ';' );
2403 OCCViewer_ClipPlane aPlane;
2404 foreach( QString ClipPlaneParam, ClipPlaneData )
2406 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2407 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2408 if ( ClipPlane_paramName == "Mode" )
2410 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2412 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2413 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2414 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2415 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2418 switch ( aPlane.Mode )
2420 case OCCViewer_ClipPlane::Absolute :
2421 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2422 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2423 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2424 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2425 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2428 case OCCViewer_ClipPlane::Relative :
2429 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2430 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2431 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2436 aClipPlanes.push_back(aPlane);
2438 // graduated trihedron
2439 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2440 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2441 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2442 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2443 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2444 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2445 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2446 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2447 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2448 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2449 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2450 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2451 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2452 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2453 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2454 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2455 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2456 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2457 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2458 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2459 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2460 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2461 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2462 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2463 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2464 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2465 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2466 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2467 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2468 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2469 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2470 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2471 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2472 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2473 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2474 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2475 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2476 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2477 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2478 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2479 else if ( paramName == "background" ) {
2480 QString bg = paramValue.replace( "$", "=" );
2481 bgData = Qtx::stringToBackground( bg );
2485 else // old format - "1.000e+00*0.000e+00..."
2488 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2489 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2490 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2491 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2492 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2493 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2494 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
2495 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2496 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2497 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
2498 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2499 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2500 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2501 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
2502 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
2503 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
2504 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
2505 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
2507 performRestoring( params );
2508 setBackground( bgData );
2509 myModel->setClipPlanes(aClipPlanes);
2513 \brief Handle show event.
2515 Emits Show() signal.
2517 \param theEvent show event
2519 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2521 emit Show( theEvent );
2525 \brief Handle hide event.
2527 Emits Hide() signal.
2529 \param theEvent hide event
2531 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
2533 emit Hide( theEvent );
2538 Save old cursor. [ protected ]
2540 void OCCViewer_ViewWindow::saveCursor()
2542 QCursor* aCursor = NULL;
2544 aCursor = myViewPort->getDefaultCursor();
2545 myCursor = ( aCursor ? *aCursor : cursor() );
2550 Creates default sketcher. [ virtual protected ]
2552 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
2555 return new OCCViewer_RectSketcher( this, type );
2556 if ( type == Polygon )
2557 return new OCCViewer_PolygonSketcher( this, type );
2561 void OCCViewer_ViewWindow::initSketchers()
2563 if ( mySketchers.isEmpty() )
2565 mySketchers.append( createSketcher( Rect ) );
2566 mySketchers.append( createSketcher( Polygon ) );
2570 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
2572 OCCViewer_ViewSketcher* sketcher = 0;
2573 QList<OCCViewer_ViewSketcher*>::Iterator it;
2574 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
2576 OCCViewer_ViewSketcher* sk = (*it);
2577 if ( sk->type() == typ )
2584 Handles requests for sketching in the active view. [ virtual public ]
2586 void OCCViewer_ViewWindow::activateSketching( int type )
2588 OCCViewer_ViewPort3d* vp = getViewPort();
2592 if ( !vp->isSketchingEnabled() )
2595 /* Finish current sketching */
2596 if ( type == NoSketching )
2600 onSketchingFinished();
2601 mypSketcher->deactivate();
2605 /* Activate new sketching */
2608 activateSketching( NoSketching ); /* concurrency not suported */
2609 mypSketcher = getSketcher( type );
2612 mypSketcher->activate();
2613 onSketchingStarted();
2619 Unhilights detected entities. [ virtual protected ]
2621 void OCCViewer_ViewWindow::onSketchingStarted()
2626 Selection by rectangle or polygon. [ virtual protected ]
2628 void OCCViewer_ViewWindow::onSketchingFinished()
2630 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
2631 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
2633 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
2634 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
2635 switch( mypSketcher->type() )
2639 QRect* aRect = (QRect*)mypSketcher->data();
2642 int aLeft = aRect->left();
2643 int aRight = aRect->right();
2644 int aTop = aRect->top();
2645 int aBottom = aRect->bottom();
2649 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2651 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2657 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
2660 int size = aPolygon->size();
2661 TColgp_Array1OfPnt2d anArray( 1, size );
2663 QPolygon::Iterator it = aPolygon->begin();
2664 QPolygon::Iterator itEnd = aPolygon->end();
2665 for( int index = 1; it != itEnd; ++it, index++ )
2667 QPoint aPoint = *it;
2668 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
2672 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
2674 ic->Select( anArray, getViewPort()->getView(), Standard_False );
2682 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
2683 aViewMgr->getOCCViewer()->performSelectionChanged();
2687 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
2692 bool OCCViewer_ViewWindow::transformRequested() const
2694 return ( myOperation != NOTHING );
2697 bool OCCViewer_ViewWindow::transformInProcess() const
2699 return myEventStarted;
2702 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
2704 myEventStarted = bOn;
2708 Set enabled state of transformation (rotate, zoom, etc)
2710 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
2712 if ( id != NOTHING ) myStatus.insert( id, on );
2716 \return enabled state of transformation (rotate, zoom, etc)
2718 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
2720 return myStatus.contains( id ) ? myStatus[ id ] : true;
2723 void OCCViewer_ViewWindow::onMaximizedView()
2725 setMaximized(!isMaximized());
2728 void OCCViewer_ViewWindow::returnTo3dView()
2730 setReturnedTo3dView( true );
2733 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
2735 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
2736 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
2737 if ( !isVisible3dView )
2738 toolMgr()->show( ReturnTo3dViewId );
2740 toolMgr()->hide( ReturnTo3dViewId );
2741 if ( isVisible3dView ) emit returnedTo3d( );
2745 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
2747 QAction* anAction = toolMgr()->action( MaximizedId );
2748 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
2749 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
2751 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
2752 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
2753 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
2754 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
2755 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
2757 emit maximized( this, true );
2761 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
2762 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
2763 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
2764 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
2765 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
2767 emit maximized( this, false );
2772 bool OCCViewer_ViewWindow::isMaximized() const
2774 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
2777 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
2779 IsSketcherStyle = enable;
2782 bool OCCViewer_ViewWindow::isSketcherStyle() const
2784 return IsSketcherStyle;
2788 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
2793 void OCCViewer_ViewWindow::setProjectionType( int mode )
2795 Handle(V3d_View) aView3d = myViewPort->getView();
2796 if ( !aView3d.IsNull() ) {
2797 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
2798 aCamera->SetProjectionType( mode == Perspective ? Graphic3d_Camera::Projection_Perspective : Graphic3d_Camera::Projection_Orthographic );
2801 // update action state if method is called outside
2802 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( mode == Orthographic ? OrthographicId : PerspectiveId ) );
2803 if ( ! a->isChecked() )
2804 a->setChecked( true );
2807 int OCCViewer_ViewWindow::projectionType() const
2809 int mode = Orthographic;
2810 Handle(V3d_View) aView3d = myViewPort->getView();
2811 if ( !aView3d.IsNull() ) {
2812 Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
2813 mode = aCamera->ProjectionType() == Graphic3d_Camera::Projection_Perspective ? Perspective : Orthographic;
2819 QColor OCCViewer_ViewWindow::backgroundColor() const
2821 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
2825 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
2827 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
2830 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
2832 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
2835 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
2837 if ( myViewPort ) myViewPort->setBackground( theBackground );
2840 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
2842 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
2848 void OCCViewer_ViewWindow::clearViewAspects()
2850 myViewAspects.clear();
2854 \return const reference to list of view aspects
2856 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
2858 return myViewAspects;
2862 Appends new view aspect
2863 \param aParams - new view aspects
2865 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
2867 myViewAspects.append( aParams );
2871 Replaces old view aspects by new ones
2872 \param aViewList - list of new view aspects
2874 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
2876 myViewAspects = aViewList;
2880 Get camera properties for the OCC view window.
2881 \return shared pointer on camera properties.
2883 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
2885 SUIT_CameraProperties aProps;
2887 Handle(V3d_View) aSourceView = getViewPort()->getView();
2888 if ( aSourceView.IsNull() )
2891 if ( get2dMode() == No2dMode ) {
2892 aProps.setDimension( SUIT_CameraProperties::Dim3D );
2895 aProps.setDimension( SUIT_CameraProperties::Dim2D );
2896 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
2899 // read common properites of the view
2900 Standard_Real anUp[3];
2901 Standard_Real anAt[3];
2902 Standard_Real anEye[3];
2903 Standard_Real aProj[3];
2904 Standard_Real anAxialScale[3];
2906 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
2907 aSourceView->At( anAt[0], anAt[1], anAt[2] );
2908 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
2909 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2911 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2912 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
2914 #if OCC_VERSION_LARGE > 0x06070100
2915 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
2917 // store camera properties "as is": it is up to synchronized
2918 // view classes to provide necessary property conversion.
2919 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
2920 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
2922 if ( aSourceView->Camera()->IsOrthographic() )
2924 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
2925 aProps.setViewAngle( 0.0 );
2929 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
2930 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
2932 aProps.setMappingScale( aSourceView->Camera()->Scale() );
2934 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
2936 // generate view orientation matrix for transforming OCC projection reference point
2937 // into a camera (eye) position.
2938 gp_Dir aLeftDir = gp_Dir( anUp[0], anUp[1], anUp[2] ) ^ gp_Dir( aProj[0], aProj[1], aProj[2] );
2941 aTrsf.SetValue( 1, 1, aLeftDir.X() );
2942 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
2943 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
2945 aTrsf.SetValue( 1, 2, anUp[0] );
2946 aTrsf.SetValue( 2, 2, anUp[1] );
2947 aTrsf.SetValue( 3, 2, anUp[2] );
2949 aTrsf.SetValue( 1, 3, aProj[0] );
2950 aTrsf.SetValue( 2, 3, aProj[1] );
2951 aTrsf.SetValue( 3, 3, aProj[2] );
2953 aTrsf.SetValue( 1, 4, anAt[0] );
2954 aTrsf.SetValue( 2, 4, anAt[1] );
2955 aTrsf.SetValue( 3, 4, anAt[2] );
2957 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
2959 // transform to world-space coordinate system
2960 gp_XYZ aPosition( aProjRef.X(), aProjRef.Y(), aCameraDepth );
2961 aTrsf.Transforms( aPosition );
2963 // compute focal point
2964 double aFocalPoint[3];
2966 aFocalPoint[0] = aPosition.X() - aProj[0] * aCameraDepth;
2967 aFocalPoint[1] = aPosition.Y() - aProj[1] * aCameraDepth;
2968 aFocalPoint[2] = aPosition.Z() - aProj[2] * aCameraDepth;
2970 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2971 aProps.setPosition( aPosition.X(), aPosition.Y(), aPosition.Z() );
2973 Standard_Real aViewScale[2];
2974 aSourceView->Size( aViewScale[0], aViewScale[1] );
2975 aProps.setMappingScale( aViewScale[1] );
2983 This implementation synchronizes OCC view's camera propreties.
2985 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
2987 bool blocked = blockSignals( true );
2989 SUIT_CameraProperties aProps = theView->cameraProperties();
2990 if ( !cameraProperties().isCompatible( aProps ) ) {
2991 // other view, this one is being currently synchronized to, seems has become incompatible
2992 // we have to break synchronization
2997 Handle(V3d_View) aDestView = getViewPort()->getView();
2999 aDestView->SetImmediateUpdate( Standard_False );
3002 double aPosition[3];
3003 double aFocalPoint[3];
3004 double anAxialScale[3];
3006 // get common properties
3007 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3008 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
3009 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3010 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3012 #if OCC_VERSION_LARGE > 0x06070100
3013 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3014 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
3015 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3016 aDestView->Camera()->SetScale( aProps.getMappingScale() );
3018 gp_Dir aProjDir( aPosition[0] - aFocalPoint[0],
3019 aPosition[1] - aFocalPoint[1],
3020 aPosition[2] - aFocalPoint[2] );
3022 // get custom view translation
3023 Standard_Real aTranslation[3];
3024 aDestView->At( aTranslation[0], aTranslation[1], aTranslation[2] );
3026 gp_Dir aLeftDir = gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] )
3027 ^ gp_Dir( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
3030 aTrsf.SetValue( 1, 1, aLeftDir.X() );
3031 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
3032 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
3034 aTrsf.SetValue( 1, 2, anUpDir[0] );
3035 aTrsf.SetValue( 2, 2, anUpDir[1] );
3036 aTrsf.SetValue( 3, 2, anUpDir[2] );
3038 aTrsf.SetValue( 1, 3, aProjDir.X() );
3039 aTrsf.SetValue( 2, 3, aProjDir.Y() );
3040 aTrsf.SetValue( 3, 3, aProjDir.Z() );
3042 aTrsf.SetValue( 1, 4, aTranslation[0] );
3043 aTrsf.SetValue( 2, 4, aTranslation[1] );
3044 aTrsf.SetValue( 3, 4, aTranslation[2] );
3047 // transform to view-space coordinate system
3048 gp_XYZ aProjRef( aPosition[0], aPosition[1], aPosition[2] );
3049 aTrsf.Transforms( aProjRef );
3051 // set view camera properties using low-level approach. this is done
3052 // in order to avoid interference with static variables in v3d view used
3053 // when rotation is in process in another view.
3054 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
3055 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
3057 Graphic3d_Vector aMappingProj( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
3058 Graphic3d_Vector aMappingUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3060 aMappingProj.Normalize();
3061 aMappingUp.Normalize();
3063 anOrientation.SetViewReferencePlane( aMappingProj );
3064 anOrientation.SetViewReferenceUp( aMappingUp );
3066 aDestView->SetViewMapping( aMapping );
3067 aDestView->SetViewOrientation( anOrientation );
3070 aDestView->SetCenter( aProjRef.X(), aProjRef.Y() );
3072 // set mapping scale
3073 double aMapScaling = aProps.getMappingScale();
3074 Standard_Real aWidth, aHeight;
3075 aDestView->Size( aWidth, aHeight );
3076 aDestView->SetSize ( aWidth > aHeight ? aMapScaling * (aWidth / aHeight) : aMapScaling );
3079 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3081 aDestView->ZFitAll();
3082 aDestView->SetImmediateUpdate( Standard_True );
3083 aDestView->Redraw();
3085 blockSignals( blocked );
3089 \brief Indicates whether preselection is enabled
3090 \return true if preselection is enabled
3092 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
3094 return myPreselectionEnabled;
3098 \brief Enables/disables preselection
3099 \param theIsToEnable if true - preselection will be enabled
3101 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
3103 onSwitchPreselection( theIsToEnable );
3107 \brief Indicates whether selection is enabled
3108 \return true if selection is enabled
3110 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3112 return mySelectionEnabled;
3116 \brief Enables/disables selection
3117 \param theIsToEnable if true - selection will be enabled
3119 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3121 onSwitchSelection( theIsToEnable );
3126 \brief called if clipping operation is activated / deactivated.
3128 Enables/disables clipping plane displaying.
3130 \parma on action state
3132 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3134 if(!myModel) return;
3135 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3138 if (!aClippingDlg) {
3139 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3140 myModel->setClippingDlg(aClippingDlg);
3142 if (!aClippingDlg->isVisible())
3143 aClippingDlg->show();
3145 if ( aClippingDlg ) {
3146 aClippingDlg->close();
3147 myModel->setClippingDlg(0);
3151 SUIT_ViewManager* mgr = getViewManager();
3153 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3154 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3155 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3156 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3158 QAction* a = toolMgr()->action( ClippingId );
3160 if(theIsOn != a->isChecked()){
3161 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3162 a->setChecked(theIsOn);
3163 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));