1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : OCCViewer_ViewWindow.cxx
26 #include "OCCViewer_ViewWindow.h"
27 #include "OCCViewer_ViewModel.h"
28 #include "OCCViewer_ViewPort3d.h"
29 #include "OCCViewer_ViewManager.h"
30 #include "OCCViewer_ViewSketcher.h"
31 #include "OCCViewer_CreateRestoreViewDlg.h"
32 #include "OCCViewer_ClipPlane.h"
33 #include "OCCViewer_SetRotationPointDlg.h"
34 #include "OCCViewer_AxialScaleDlg.h"
35 #include "OCCViewer_CubeAxesDlg.h"
36 #include "OCCViewer_ClippingDlg.h"
38 #include <Basics_OCCTVersion.hxx>
40 #include <SUIT_Desktop.h>
41 #include <SUIT_Session.h>
42 #include <SUIT_ViewManager.h>
43 #include <SUIT_Tools.h>
44 #include <SUIT_ResourceMgr.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_Application.h>
48 #include <QtxActionToolMgr.h>
49 #include <QtxMultiAction.h>
50 #include <QtxRubberBand.h>
52 #include <OpenGLUtils_FrameBuffer.h>
58 #include <QMouseEvent>
59 #include <QApplication>
62 #include <AIS_ListOfInteractive.hxx>
63 #include <AIS_ListIteratorOfListOfInteractive.hxx>
64 #include <AIS_Shape.hxx>
66 #include <BRep_Tool.hxx>
67 #include <BRepBndLib.hxx>
68 #include <BRepGProp.hxx>
69 #include <GProp_GProps.hxx>
72 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
73 #include <Graphic3d_MapOfStructure.hxx>
74 #include <Graphic3d_Structure.hxx>
75 #include <Graphic3d_ExportFormat.hxx>
77 #include <Visual3d_View.hxx>
78 #include <V3d_Plane.hxx>
79 #include <V3d_Light.hxx>
83 #include <gp_GTrsf.hxx>
84 #include <TColgp_Array1OfPnt2d.hxx>
86 #if OCC_VERSION_LARGE > 0x06060000
87 #include <Graphic3d_SequenceOfHClipPlane.hxx>
88 #include <Graphic3d_ClipPlane.hxx>
92 #include <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;
262 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
265 qDeleteAll( mySketchers );
269 \brief Internal initialization.
271 void OCCViewer_ViewWindow::initLayout()
273 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
274 myViewPort->installEventFilter(this);
275 setCentralWidget(myViewPort);
276 myOperation = NOTHING;
278 myCurrPointType = GRAVITY;
279 myPrevPointType = GRAVITY;
280 mySelectedPoint = gp_Pnt(0.,0.,0.);
281 myRotationPointSelection = false;
283 setTransformRequested ( NOTHING );
284 setTransformInProcess ( false );
301 // Graduated axes dialog
302 QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
303 myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
304 myCubeAxesDlg->initialize();
306 connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
309 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
311 return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
315 \brief Detect viewer operation according the the mouse button pressed
316 and key modifiers used.
317 \param theEvent mouse event
318 \return type of the operation
320 OCCViewer_ViewWindow::OperationType
321 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
323 OperationType aOp = NOTHING;
324 SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
325 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
326 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
328 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
329 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
331 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
332 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
333 (my2dMode == No2dMode))
340 \brief Customize event handling
341 \param watched event receiver object
343 \return \c true if the event processing should be stopped
345 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
347 if ( watched == myViewPort ) {
348 int aType = e->type();
350 case QEvent::MouseButtonPress:
351 vpMousePressEvent((QMouseEvent*) e);
354 case QEvent::MouseButtonRelease:
355 vpMouseReleaseEvent((QMouseEvent*) e);
358 case QEvent::MouseMove:
359 vpMouseMoveEvent((QMouseEvent*) e);
362 case QEvent::MouseButtonDblClick:
363 emit mouseDoubleClicked(this, (QMouseEvent*)e);
368 QWheelEvent* aEvent = (QWheelEvent*) e;
369 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
370 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
373 int x1 = (int)( aEvent->x() + width()*delta/100 );
374 int y1 = (int)( aEvent->y() + height()*delta/100 );
375 myViewPort->zoom( x, y, x1, y1 );
376 myViewPort->getView()->ZFitAll();
380 case QEvent::ContextMenu:
382 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
383 if ( aEvent->reason() != QContextMenuEvent::Mouse )
384 emit contextMenuRequested( aEvent );
388 case QEvent::KeyPress:
389 emit keyPressed(this, (QKeyEvent*) e);
396 return SUIT_ViewWindow::eventFilter(watched, e);
400 \brief Update state of enable draw mode state.
402 void OCCViewer_ViewWindow::updateEnabledDrawMode()
405 myEnableDrawMode = myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
409 \brief Handle mouse press event
410 \param theEvent mouse event
412 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
414 myStartX = theEvent->x();
415 myStartY = theEvent->y();
416 int anInteractionStyle = interactionStyle();
418 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
419 // which are assigned for pan and rotate - these operations are activated immediately after pressing
420 // of the first button, so it is necessary to switch to zoom when the second button is pressed
421 bool aSwitchToZoom = false;
422 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
423 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
424 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
427 switch ( myOperation ) {
429 if ( theEvent->button() == Qt::LeftButton )
430 emit vpTransformationStarted ( WINDOWFIT );
434 if ( theEvent->button() == Qt::LeftButton )
435 emit vpTransformationStarted ( PANGLOBAL );
439 if ( theEvent->button() == Qt::LeftButton ) {
440 myViewPort->startZoomAtPoint( myStartX, myStartY );
441 emit vpTransformationStarted ( ZOOMVIEW );
446 if ( aSwitchToZoom ) {
447 myViewPort->startZoomAtPoint( myStartX, myStartY );
450 else if ( theEvent->button() == Qt::LeftButton )
451 emit vpTransformationStarted ( PANVIEW );
455 if ( aSwitchToZoom ) {
456 myViewPort->startZoomAtPoint( myStartX, myStartY );
459 else if ( theEvent->button() == Qt::LeftButton ) {
460 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
461 emit vpTransformationStarted ( ROTATE );
466 /* Try to activate a transformation */
467 OperationType aState;
468 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
469 aState = getButtonState(theEvent, anInteractionStyle);
471 aState = OCCViewer_ViewWindow::NOTHING;
476 myViewPort->startZoomAtPoint( myStartX, myStartY );
484 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
487 if ( myRotationPointSelection )
489 if ( theEvent->button() == Qt::LeftButton )
491 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
493 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
495 TopoDS_Shape aShape = ic->SelectedShape();
496 GProp_GProps aSystem;
498 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
500 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
502 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE )
504 BRepGProp::LinearProperties( aShape, aSystem );
505 aPnt = aSystem.CentreOfMass();
507 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE )
509 BRepGProp::SurfaceProperties( aShape, aSystem );
510 aPnt = aSystem.CentreOfMass();
512 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID )
514 BRepGProp::VolumeProperties( aShape, aSystem );
515 aPnt = aSystem.CentreOfMass();
519 myCurrPointType = myPrevPointType;
523 if ( mySetRotationPointDlg )
525 myRotationPointSelection = false;
526 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
529 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
530 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
531 ic->CloseAllContexts();
532 myOperation = NOTHING;
533 myViewPort->setCursor( myCursor );
534 myCursorIsHand = false;
535 myRotationPointSelection = false;
539 emit mousePressed(this, theEvent);
542 /* notify that we start a transformation */
543 if ( transformRequested() )
544 emit vpTransformationStarted ( myOperation );
546 if ( transformRequested() )
547 setTransformInProcess( true );
549 /* we may need it for sketching... */
550 if ( l_mbPressEvent )
551 delete l_mbPressEvent;
552 l_mbPressEvent = new QMouseEvent( *theEvent );
557 \brief Start zooming operation.
559 Sets the corresponding cursor for the widget.
561 void OCCViewer_ViewWindow::activateZoom()
563 if ( !transformRequested() && !myCursorIsHand )
564 myCursor = cursor(); /* save old cursor */
566 if ( myOperation != ZOOMVIEW ) {
567 QPixmap zoomPixmap (imageZoomCursor);
568 QCursor zoomCursor (zoomPixmap);
569 if( setTransformRequested ( ZOOMVIEW ) )
570 myViewPort->setCursor( zoomCursor );
576 \brief Start panning operation.
578 Sets the corresponding cursor for the widget.
580 void OCCViewer_ViewWindow::activatePanning()
582 if ( !transformRequested() && !myCursorIsHand )
583 myCursor = cursor(); // save old cursor
585 if ( myOperation != PANVIEW ) {
586 QCursor panCursor (Qt::SizeAllCursor);
587 if( setTransformRequested ( PANVIEW ) )
588 myViewPort->setCursor( panCursor );
593 \brief Start rotation operation
595 Sets the corresponding cursor for the widget.
597 void OCCViewer_ViewWindow::activateRotation()
599 if ( !transformRequested() && !myCursorIsHand )
600 myCursor = cursor(); // save old cursor
602 if ( myOperation != ROTATE ) {
603 QPixmap rotatePixmap (imageRotateCursor);
604 QCursor rotCursor (rotatePixmap);
605 if( setTransformRequested ( ROTATE ) )
606 myViewPort->setCursor( rotCursor );
611 \brief Compute the gravity center.
612 \param theX used to return X coordinate of the gravity center
613 \param theY used to return Y coordinate of the gravity center
614 \param theZ used to return Z coordinate of the gravity center
615 \return \c true if the gravity center is computed
617 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
619 Handle(V3d_View) aView3d = myViewPort->getView();
621 // Project boundaries points and add to avergae gravity
622 // the ones which lie within the screen limits
623 Standard_Real aScreenLimits[4] = { 0.0, 0.0, 0.0, 0.0 };
625 #if OCC_VERSION_LARGE > 0x06070100
626 // NDC space screen limits
627 aScreenLimits[0] = -1.0;
628 aScreenLimits[1] = 1.0;
629 aScreenLimits[2] = -1.0;
630 aScreenLimits[3] = 1.0;
632 aView3d->View()->ViewMapping().WindowLimit( aScreenLimits[0],
638 Standard_Integer aPointsNb = 0;
640 Standard_Real aXmin = 0.0;
641 Standard_Real aYmin = 0.0;
642 Standard_Real aZmin = 0.0;
643 Standard_Real aXmax = 0.0;
644 Standard_Real aYmax = 0.0;
645 Standard_Real aZmax = 0.0;
647 Graphic3d_MapOfStructure aSetOfStructures;
648 aView3d->View()->DisplayedStructures( aSetOfStructures );
649 Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures );
651 for( ; aStructureIt.More(); aStructureIt.Next() ) {
652 const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key();
653 if ( aStructure->IsEmpty() ) {
657 aStructure->MinMaxValues( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
659 // Infinite structures are skipped
660 Standard_Real aLIM = ShortRealLast() - 1.0;
661 if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
662 || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
666 gp_Pnt aPoints[8] = {
667 gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
668 gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
669 gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
670 gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
673 for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
674 const gp_Pnt& aBBPoint = aPoints[aPointIt];
676 #if OCC_VERSION_LARGE > 0x06070100
677 gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
678 const Standard_Real& U = aProjected.X();
679 const Standard_Real& V = aProjected.Y();
681 Standard_Real U = 0.0;
682 Standard_Real V = 0.0;
683 Standard_Real W = 0.0;
684 aView3d->View()->Projects( aBBPoint.X(), aBBPoint.Y(), aBBPoint.Z(), U, V, W );
687 if (U >= aScreenLimits[0]
688 && U <= aScreenLimits[1]
689 && V >= aScreenLimits[2]
690 && V <= aScreenLimits[3])
693 theX += aBBPoint.X();
694 theY += aBBPoint.Y();
695 theZ += aBBPoint.Z();
710 \brief Set the gravity center as a rotation point.
712 void OCCViewer_ViewWindow::activateSetRotationGravity()
714 if ( myRotationPointSelection )
716 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
717 ic->CloseAllContexts();
718 myOperation = NOTHING;
719 myViewPort->setCursor( myCursor );
720 myCursorIsHand = false;
721 myRotationPointSelection = false;
724 myPrevPointType = myCurrPointType;
725 myCurrPointType = GRAVITY;
727 Standard_Real Xcenter, Ycenter, Zcenter;
728 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
729 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
733 \brief Update gravity center in the "Set Rotation Point" dialog box.
734 \sa OCCViewer_SetRotationPointDlg class
736 void OCCViewer_ViewWindow::updateGravityCoords()
738 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == GRAVITY )
740 Standard_Real Xcenter, Ycenter, Zcenter;
741 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
742 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
747 \brief Set the point selected by the user as a rotation point.
748 \param theX X coordinate of the rotation point
749 \param theY Y coordinate of the rotation point
750 \param theZ Z coordinate of the rotation point
752 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
754 if ( myRotationPointSelection )
756 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
757 ic->CloseAllContexts();
758 myOperation = NOTHING;
759 myViewPort->setCursor( myCursor );
760 myCursorIsHand = false;
761 myRotationPointSelection = false;
764 myPrevPointType = myCurrPointType;
765 myCurrPointType = SELECTED;
766 mySelectedPoint.SetCoord(theX,theY,theZ);
770 \brief Start the shape selection process.
772 void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
774 myPrevPointType = myCurrPointType;
775 myCurrPointType = SELECTED;
777 // activate selection ------>
778 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
780 ic->OpenLocalContext();
782 AIS_ListOfInteractive aList;
783 ic->DisplayedObjects( aList );
784 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
786 Handle(AIS_InteractiveObject) anObj = it.Value();
787 if ( !anObj.IsNull() && anObj->HasPresentation() &&
788 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
791 ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
794 // activate selection <------
796 if ( !myCursorIsHand )
798 QCursor handCursor (Qt::PointingHandCursor);
799 myCursorIsHand = true;
801 myViewPort->setCursor( handCursor );
803 myRotationPointSelection = true;
807 \brief Start global panning operation
809 Sets the corresponding cursor for the widget.
811 void OCCViewer_ViewWindow::activateGlobalPanning()
813 Handle(V3d_View) aView3d = myViewPort->getView();
814 if ( !aView3d.IsNull() ) {
815 QPixmap globalPanPixmap (imageCrossCursor);
816 QCursor glPanCursor (globalPanPixmap);
817 myCurScale = aView3d->Scale();
818 aView3d->FitAll(0.01, false);
819 myCursor = cursor(); // save old cursor
820 myViewPort->fitAll(); // fits view before selecting a new scene center
821 if( setTransformRequested( PANGLOBAL ) )
822 myViewPort->setCursor( glPanCursor );
827 \brief Starts fit operation.
829 Sets the corresponding cursor for the widget.
831 void OCCViewer_ViewWindow::activateWindowFit()
833 if ( !transformRequested() && !myCursorIsHand )
834 myCursor = cursor(); /* save old cursor */
836 if ( myOperation != WINDOWFIT ) {
837 QCursor handCursor (Qt::PointingHandCursor);
838 if( setTransformRequested ( WINDOWFIT ) )
840 myViewPort->setCursor ( handCursor );
841 myCursorIsHand = true;
847 \brief Start delayed viewer operation.
849 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
851 bool ok = transformEnabled( op );
852 myOperation = ok ? op : NOTHING;
853 myViewPort->setMouseTracking( myOperation == NOTHING );
858 \brief Handle mouse move event.
859 \param theEvent mouse event
861 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
863 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
865 switch ( getButtonState( theEvent, interactionStyle() ) ) {
867 myViewPort->startZoomAtPoint( myStartX, myStartY );
875 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
882 myCurrX = theEvent->x();
883 myCurrY = theEvent->y();
884 switch (myOperation) {
886 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
890 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
896 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
910 if ( myRotationPointSelection || isSketcherStyle() )
912 emit mouseMoving( this, theEvent );
916 int aState = theEvent->modifiers();
917 int aButton = theEvent->buttons();
918 int anInteractionStyle = interactionStyle();
919 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
920 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
921 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
922 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
923 myDrawRect = myEnableDrawMode;
926 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
927 QCursor handCursor (Qt::PointingHandCursor);
928 myCursorIsHand = true;
930 myViewPort->setCursor( handCursor );
933 emit mouseMoving( this, theEvent );
935 else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
936 aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
937 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
938 aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
939 OCCViewer_ViewSketcher* sketcher = 0;
940 QList<OCCViewer_ViewSketcher*>::Iterator it;
941 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
943 OCCViewer_ViewSketcher* sk = (*it);
944 if( sk->isDefault() && sk->sketchButton() == aButton )
947 if ( sketcher && myCurSketch == -1 )
949 activateSketching( sketcher->type() );
952 myCurSketch = mypSketcher->sketchButton();
954 if ( l_mbPressEvent )
956 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
957 delete l_mbPressEvent;
960 QApplication::sendEvent( getViewPort(), theEvent );
965 emit mouseMoving( this, theEvent );
971 \brief Handle mouse release event.
972 \param theEvent mouse event
974 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
976 switch ( myOperation ) {
979 int prevState = myCurSketch;
980 if(theEvent->button() == Qt::RightButton)
982 QList<OCCViewer_ViewSketcher*>::Iterator it;
983 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
985 OCCViewer_ViewSketcher* sk = (*it);
986 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
991 emit mouseReleased(this, theEvent);
992 if(theEvent->button() == Qt::RightButton && prevState == -1)
994 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
995 theEvent->pos(), theEvent->globalPos() );
996 emit contextMenuRequested( &aEvent );
1001 myViewPort->endRotation();
1007 myViewPort->getView()->ZFitAll();
1012 if ( theEvent->button() == Qt::LeftButton ) {
1013 myViewPort->setCenter( theEvent->x(), theEvent->y() );
1014 myViewPort->getView()->SetScale(myCurScale);
1020 if ( theEvent->button() == Qt::LeftButton ) {
1021 myCurrX = theEvent->x();
1022 myCurrY = theEvent->y();
1024 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1025 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1032 // NOTE: viewer 3D detects a rectangle of selection using this event
1033 // so we must emit it BEFORE resetting the selection rectangle
1035 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1039 myViewPort->update();
1042 if ( l_mbPressEvent )
1044 delete l_mbPressEvent;
1050 \brief Reset the viewport to its initial state
1051 ( no transformations in process etc. )
1053 void OCCViewer_ViewWindow::resetState()
1057 if ( myRotationPointSelection )
1059 QCursor handCursor (Qt::PointingHandCursor);
1060 myViewPort->setCursor( handCursor );
1064 if ( transformRequested() || myCursorIsHand )
1065 myViewPort->setCursor( myCursor );
1066 myCursorIsHand = false;
1069 if ( transformRequested() )
1070 emit vpTransformationFinished (myOperation);
1072 setTransformInProcess( false );
1073 setTransformRequested( NOTHING );
1078 \brief Draw rubber band rectangle.
1080 void OCCViewer_ViewWindow::drawRect()
1082 if ( !myRectBand ) {
1083 myRectBand = new QtxRectRubberBand( myViewPort );
1085 //palette.setColor(myRectBand->foregroundRole(), Qt::white);
1086 //myRectBand->setPalette(palette);
1088 //myRectBand->hide();
1090 myRectBand->setUpdatesEnabled ( false );
1091 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1092 myRectBand->initGeometry( aRect );
1094 if ( !myRectBand->isVisible() )
1097 myRectBand->setUpdatesEnabled ( true );
1098 //myRectBand->repaint();
1100 //myRectBand->setVisible( aRect.isValid() );
1101 //if ( myRectBand->isVisible() )
1102 // myRectBand->repaint();
1104 // myRectBand->show();
1105 //myRectBand->repaint();
1109 \brief Clear rubber band rectangle on the end on the dragging operation.
1111 void OCCViewer_ViewWindow::endDrawRect()
1113 //delete myRectBand;
1117 myRectBand->clearGeometry();
1123 \brief Create actions.
1125 void OCCViewer_ViewWindow::createActions()
1127 if( !toolMgr()->isEmpty() )
1130 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1135 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1136 tr( "MNU_DUMP_VIEW" ), 0, this);
1137 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1138 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1139 toolMgr()->registerAction( aAction, DumpId );
1142 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1143 tr( "MNU_FITALL" ), 0, this);
1144 aAction->setStatusTip(tr("DSC_FITALL"));
1145 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1146 toolMgr()->registerAction( aAction, FitAllId );
1149 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1150 tr( "MNU_FITRECT" ), 0, this);
1151 aAction->setStatusTip(tr("DSC_FITRECT"));
1152 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1153 toolMgr()->registerAction( aAction, FitRectId );
1156 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1157 tr( "MNU_ZOOM_VIEW" ), 0, this);
1158 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1159 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1160 toolMgr()->registerAction( aAction, ZoomId );
1163 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1164 tr( "MNU_PAN_VIEW" ), 0, this);
1165 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1166 connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
1167 toolMgr()->registerAction( aAction, PanId );
1170 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1171 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1172 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1173 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1174 toolMgr()->registerAction( aAction, GlobalPanId );
1177 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1178 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1179 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1180 mySetRotationPointAction->setCheckable( true );
1181 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1182 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1185 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1186 tr( "MNU_ROTATE_VIEW" ), 0, this);
1187 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1188 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1189 toolMgr()->registerAction( aAction, RotationId );
1192 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1193 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1194 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1195 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1196 this->addAction(aAction);
1197 toolMgr()->registerAction( aAction, FrontId );
1199 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1200 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1201 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1202 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1203 this->addAction(aAction);
1204 toolMgr()->registerAction( aAction, BackId );
1206 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1207 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1208 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1209 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1210 this->addAction(aAction);
1211 toolMgr()->registerAction( aAction, TopId );
1213 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1214 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1215 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1216 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1217 this->addAction(aAction);
1218 toolMgr()->registerAction( aAction, BottomId );
1220 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1221 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1222 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1223 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1224 this->addAction(aAction);
1225 toolMgr()->registerAction( aAction, LeftId );
1227 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1228 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1229 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1230 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1231 this->addAction(aAction);
1232 toolMgr()->registerAction( aAction, RightId );
1234 // rotate anticlockwise
1235 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1236 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1237 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1238 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1239 this->addAction(aAction);
1240 toolMgr()->registerAction( aAction, AntiClockWiseId );
1243 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1244 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1245 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1246 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1247 this->addAction(aAction);
1248 toolMgr()->registerAction( aAction, ClockWiseId );
1251 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1252 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1253 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1254 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1255 this->addAction(aAction);
1256 toolMgr()->registerAction( aAction, ResetId );
1259 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1260 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1261 tr("MNU_CLONE_VIEW"), 0, this);
1262 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1263 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1264 toolMgr()->registerAction( aAction, CloneId );
1266 aAction = new QtxAction (tr ("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr ("ICON_OCCVIEWER_CLIPPING")),
1267 tr ("MNU_CLIPPING"), 0, this);
1268 aAction->setStatusTip (tr ("DSC_CLIPPING"));
1269 aAction->setCheckable (true);
1270 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1271 toolMgr()->registerAction (aAction, ClippingId);
1273 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1274 tr( "MNU_SHOOT_VIEW" ), 0, this);
1275 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1276 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1277 toolMgr()->registerAction( aAction, MemId );
1279 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1280 tr( "MNU_PRESETS_VIEW" ), 0, this);
1281 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1282 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1283 toolMgr()->registerAction( aAction, RestoreId );
1285 if (myModel->trihedronActivated()) {
1286 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1287 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1288 aAction->setCheckable( true );
1289 aAction->setChecked( true );
1290 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1291 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1292 toolMgr()->registerAction( aAction, TrihedronShowId );
1296 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1297 tr( "MNU_SCALING" ), 0, this);
1298 aAction->setStatusTip(tr("DSC_SCALING"));
1299 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1300 toolMgr()->registerAction( aAction, AxialScaleId );
1302 // Enable/disable preselection
1303 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1304 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1305 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1306 aAction->setCheckable(true);
1307 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1308 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1310 // Enable/disable selection
1311 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1312 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1313 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1314 aAction->setCheckable(true);
1315 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1316 toolMgr()->registerAction( aAction, SwitchSelectionId );
1319 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1320 tr( "MNU_GRADUATED_AXES" ), 0, this);
1321 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1322 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1323 toolMgr()->registerAction( aAction, GraduatedAxesId );
1325 // Active only ambient light or not
1326 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1327 tr( "MNU_AMBIENT" ), 0, this);
1328 aAction->setStatusTip(tr("DSC_AMBIENT"));
1329 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1330 toolMgr()->registerAction( aAction, AmbientId );
1332 // Switch between interaction styles
1333 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1334 tr( "MNU_STYLE_SWITCH" ), 0, this);
1335 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1336 aAction->setCheckable(true);
1337 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1338 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1340 // Switch between zooming styles
1341 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1342 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1343 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1344 aAction->setCheckable(true);
1345 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1346 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1349 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1350 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1351 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1352 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1353 toolMgr()->registerAction( aAction, MaximizedId );
1355 // Return to 3d view
1356 if (my2dMode!=No2dMode){
1357 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1358 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1359 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1360 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1361 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1365 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1369 \brief Create toolbar.
1371 void OCCViewer_ViewWindow::createToolBar()
1373 QString aToolbarName;
1376 aToolbarName = tr( "LBL_XYTOOLBAR_LABEL" );
1379 aToolbarName = tr( "LBL_XZTOOLBAR_LABEL" );
1382 aToolbarName = tr( "LBL_YZTOOLBAR_LABEL" );
1385 aToolbarName = tr( "LBL_3DTOOLBAR_LABEL" );
1388 int tid = toolMgr()->createToolBar( aToolbarName, false );
1389 if ( my2dMode != No2dMode ){
1390 toolMgr()->append( ReturnTo3dViewId, tid );
1391 toolMgr()->append( toolMgr()->separator(), tid );
1393 toolMgr()->append( DumpId, tid );
1394 toolMgr()->append( SwitchInteractionStyleId, tid );
1395 #if OCC_VERSION_LARGE > 0x0603000A // available only with OCC-6.3-sp11 and higher version
1396 toolMgr()->append( SwitchZoomingStyleId, tid );
1398 toolMgr()->append( SwitchPreselectionId, tid );
1399 toolMgr()->append( SwitchSelectionId, tid );
1400 if( myModel->trihedronActivated() )
1401 toolMgr()->append( TrihedronShowId, tid );
1403 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1404 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1405 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1406 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1407 toolMgr()->append( aScaleAction, tid );
1409 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1410 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1411 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1412 toolMgr()->append( aPanningAction, tid );
1414 if (my2dMode == No2dMode) {
1415 toolMgr()->append( ChangeRotationPointId, tid );
1416 toolMgr()->append( RotationId, tid );
1418 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1419 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1420 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1421 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1422 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1423 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1424 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1425 toolMgr()->append( aViewsAction, tid );
1427 toolMgr()->append( AntiClockWiseId, tid );
1428 toolMgr()->append( ClockWiseId, tid );
1430 toolMgr()->append( ResetId, tid );
1433 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1434 aMemAction->insertAction( toolMgr()->action( MemId ) );
1435 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1436 toolMgr()->append( aMemAction, tid );
1438 toolMgr()->append( toolMgr()->separator(), tid );
1439 toolMgr()->append( CloneId, tid );
1441 toolMgr()->append( toolMgr()->separator(), tid );
1442 toolMgr()->append( ClippingId, tid );
1443 toolMgr()->append( AxialScaleId, tid );
1444 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
1445 toolMgr()->append( GraduatedAxesId, tid );
1447 toolMgr()->append( AmbientId, tid );
1449 toolMgr()->append( MaximizedId, tid );
1450 toolMgr()->append( SynchronizeId, tid );
1454 \brief Perform 'fit all' operation.
1456 void OCCViewer_ViewWindow::onViewFitAll()
1458 myViewPort->fitAll();
1462 \brief Perform "front view" transformation.
1464 void OCCViewer_ViewWindow::onFrontView()
1466 emit vpTransformationStarted ( FRONTVIEW );
1467 Handle(V3d_View) aView3d = myViewPort->getView();
1468 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
1470 emit vpTransformationFinished ( FRONTVIEW );
1474 \brief Perform "back view" transformation.
1476 void OCCViewer_ViewWindow::onBackView()
1478 emit vpTransformationStarted ( BACKVIEW );
1479 Handle(V3d_View) aView3d = myViewPort->getView();
1480 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
1482 emit vpTransformationFinished ( BACKVIEW );
1486 \brief Perform "top view" transformation.
1488 void OCCViewer_ViewWindow::onTopView()
1490 emit vpTransformationStarted ( TOPVIEW );
1491 Handle(V3d_View) aView3d = myViewPort->getView();
1492 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
1494 emit vpTransformationFinished ( TOPVIEW );
1498 \brief Perform "bottom view" transformation.
1500 void OCCViewer_ViewWindow::onBottomView()
1502 emit vpTransformationStarted ( BOTTOMVIEW );
1503 Handle(V3d_View) aView3d = myViewPort->getView();
1504 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
1506 emit vpTransformationFinished ( BOTTOMVIEW );
1510 \brief Perform "left view" transformation.
1512 void OCCViewer_ViewWindow::onLeftView()
1514 emit vpTransformationStarted ( LEFTVIEW );
1515 Handle(V3d_View) aView3d = myViewPort->getView();
1516 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
1518 emit vpTransformationFinished ( LEFTVIEW );
1522 \brief Perform "right view" transformation.
1524 void OCCViewer_ViewWindow::onRightView()
1526 emit vpTransformationStarted ( RIGHTVIEW );
1527 Handle(V3d_View) aView3d = myViewPort->getView();
1528 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
1530 emit vpTransformationFinished ( RIGHTVIEW );
1534 \brief Rotate view 90 degrees clockwise
1536 void OCCViewer_ViewWindow::onClockWiseView()
1538 emit vpTransformationStarted ( CLOCKWISEVIEW );
1539 myViewPort->rotateXY( 90. );
1540 emit vpTransformationFinished ( CLOCKWISEVIEW );
1544 \brief Rotate view 90 degrees conterclockwise
1546 void OCCViewer_ViewWindow::onAntiClockWiseView()
1548 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1549 myViewPort->rotateXY( -90. );
1550 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1554 \brief Perform "reset view" transformation.
1556 Sets default orientation of the viewport camera.
1558 void OCCViewer_ViewWindow::onResetView()
1560 emit vpTransformationStarted( RESETVIEW );
1561 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1562 myViewPort->getView()->Reset( false );
1563 myViewPort->fitAll( false, true, false );
1564 myViewPort->getView()->SetImmediateUpdate( upd );
1565 myViewPort->getView()->Update();
1566 emit vpTransformationFinished( RESETVIEW );
1570 \brief Perform "fit all" transformation.
1572 void OCCViewer_ViewWindow::onFitAll()
1574 emit vpTransformationStarted( FITALLVIEW );
1575 myViewPort->fitAll();
1576 emit vpTransformationFinished( FITALLVIEW );
1580 \brief Called if 'change rotation point' operation is activated.
1581 \param on action state
1583 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1587 if (!mySetRotationPointDlg)
1589 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1590 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1593 if (!mySetRotationPointDlg->isVisible())
1595 //if (mySetRotationPointDlg->IsFirstShown())
1596 if (myCurrPointType == GRAVITY)
1598 Standard_Real Xcenter, Ycenter, Zcenter;
1599 if (computeGravityCenter(Xcenter, Ycenter, Zcenter))
1600 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1602 mySetRotationPointDlg->show();
1607 if (mySetRotationPointDlg->isVisible())
1608 mySetRotationPointDlg->hide();
1613 \brief Create one more window with same content.
1615 void OCCViewer_ViewWindow::onCloneView()
1617 SUIT_ViewWindow* vw = myManager->createViewWindow();
1619 emit viewCloned( vw );
1623 Creates one more window with same content
1625 void OCCViewer_ViewWindow::onAxialScale()
1627 if ( !myScalingDlg )
1628 myScalingDlg = new OCCViewer_AxialScaleDlg( this );
1630 if ( !myScalingDlg->isVisible() )
1632 myScalingDlg->Update();
1633 myScalingDlg->show();
1638 Shows Graduated Axes dialog
1640 void OCCViewer_ViewWindow::onGraduatedAxes()
1642 myCubeAxesDlg->Update();
1643 myCubeAxesDlg->show();
1646 void OCCViewer_ViewWindow::onAmbientToogle()
1648 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
1649 viewer->InitDefinedLights();
1650 while(viewer->MoreDefinedLights())
1652 Handle(V3d_Light) light = viewer->DefinedLight();
1653 if(light->Type() != V3d_AMBIENT)
1655 Handle(V3d_View) aView3d = myViewPort->getView();
1656 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
1657 else viewer->SetLightOn(light);
1659 viewer->NextDefinedLights();
1665 \brief Store view parameters.
1667 void OCCViewer_ViewWindow::onMemorizeView()
1669 appendViewAspect( getViewParams() );
1673 \brief Restore view parameters.
1675 void OCCViewer_ViewWindow::onRestoreView()
1677 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
1678 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
1680 updateViewAspects( aDlg->parameters() );
1681 if( myRestoreFlag && aDlg->parameters().count() )
1682 performRestoring( aDlg->currentItem() );
1686 \brief Restore view parameters.
1687 \param anItem view parameters
1689 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
1691 Handle(V3d_View) aView3d = myViewPort->getView();
1693 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
1694 aView3d->SetScale( anItem.scale );
1695 aView3d->SetTwist( anItem.twist );
1696 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
1697 aView3d->SetImmediateUpdate( prev );
1698 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1699 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1700 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
1702 #if OCC_VERSION_LARGE > 0x06070100
1703 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
1705 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
1707 // "eye" and "at" require conversion to represent center panning
1708 // up direction is only available after setting angle of twist and
1709 // other view parameters
1710 aView3d->Up( anUpX, anUpY, anUpZ );
1712 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
1713 gp_Dir anUp( anUpX, anUpY, anUpZ );
1714 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
1715 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1716 gp_Dir aSide = aProj ^ anUp;
1718 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
1719 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
1721 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
1722 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1725 aView3d->SetCenter( anItem.centerX, anItem.centerY );
1728 if ( !baseParamsOnly ) {
1730 myModel->setTrihedronShown( anItem.isVisible );
1731 myModel->setTrihedronSize( anItem.size );
1733 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
1734 // graduated trihedron
1735 bool anIsVisible = anItem.gtIsVisible;
1736 OCCViewer_AxisWidget::AxisData anAxisData[3];
1737 anAxisData[0].DrawName = anItem.gtDrawNameX;
1738 anAxisData[1].DrawName = anItem.gtDrawNameZ;
1739 anAxisData[2].DrawName = anItem.gtDrawNameZ;
1740 anAxisData[0].Name = anItem.gtNameX;
1741 anAxisData[1].Name = anItem.gtNameZ;
1742 anAxisData[2].Name = anItem.gtNameZ;
1743 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
1744 anItem.gtNameColorGX,
1745 anItem.gtNameColorBX );
1746 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
1747 anItem.gtNameColorGY,
1748 anItem.gtNameColorBY );
1749 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
1750 anItem.gtNameColorGZ,
1751 anItem.gtNameColorBZ );
1752 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
1753 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
1754 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
1755 anAxisData[0].NbValues = anItem.gtNbValuesX;
1756 anAxisData[1].NbValues = anItem.gtNbValuesY;
1757 anAxisData[2].NbValues = anItem.gtNbValuesZ;
1758 anAxisData[0].Offset = anItem.gtOffsetX;
1759 anAxisData[1].Offset = anItem.gtOffsetY;
1760 anAxisData[2].Offset = anItem.gtOffsetZ;
1761 anAxisData[0].Color = QColor( anItem.gtColorRX,
1764 anAxisData[1].Color = QColor( anItem.gtColorRY,
1767 anAxisData[2].Color = QColor( anItem.gtColorRZ,
1770 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
1771 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
1772 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
1773 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
1774 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
1775 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
1777 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
1778 myCubeAxesDlg->ApplyData( aView3d );
1781 } // if ( !baseParamsOnly )
1787 \brief Set restore flag.
1789 void OCCViewer_ViewWindow::setRestoreFlag()
1795 \brief Called when action "show/hide trihedron" is activated.
1797 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
1799 myModel->setTrihedronShown(show);
1803 \brief Toggles preselection (highlighting) on/off
1805 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
1807 myPreselectionEnabled = on;
1808 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
1810 // unhighlight all highlighted objects
1812 myModel->unHighlightAll( true, false );
1815 // update action state if method is called outside
1816 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
1817 if ( a && a->isChecked() != on ) {
1818 a->setChecked( on );
1823 \brief Toggles selection on/off
1825 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
1827 mySelectionEnabled = on;
1828 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
1830 // update action state if method is called outside
1833 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
1835 a->setEnabled( on );
1839 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
1840 if ( a && a->isChecked() != on ) {
1841 a->setChecked( on );
1846 \brief Switches "keyboard free" interaction style on/off
1848 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
1850 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
1852 // update action state if method is called outside
1853 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
1854 if ( a->isChecked() != on )
1855 a->setChecked( on );
1859 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
1861 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
1863 myViewPort->setAdvancedZoomingEnabled( on );
1865 // update action state if method is called outside
1866 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
1867 if ( a->isChecked() != on )
1868 a->setChecked( on );
1872 \brief Get current interaction style
1873 \return interaction style
1875 int OCCViewer_ViewWindow::interactionStyle() const
1877 return myInteractionStyle;
1881 \brief Set current interaction style
1882 \param theStyle interaction style
1884 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
1886 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
1890 \brief Get current zooming style
1891 \return zooming style
1893 int OCCViewer_ViewWindow::zoomingStyle() const
1895 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
1899 \brief Set current zooming style
1900 \param theStyle zooming style
1902 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
1904 onSwitchZoomingStyle( theStyle == 1 );
1908 \brief Dump view window contents to the pixmap.
1909 \return pixmap containing all scene rendered in the window
1911 QImage OCCViewer_ViewWindow::dumpView()
1913 Handle(V3d_View) view = myViewPort->getView();
1914 if ( view.IsNull() )
1917 int aWidth = myViewPort->width();
1918 int aHeight = myViewPort->height();
1920 // rnv: An old approach to dump the OCCViewer content
1921 // Now used OCCT built-in procedure.
1923 QApplication::syncX();
1924 view->Redraw(); // In order to reactivate GL context
1927 OpenGLUtils_FrameBuffer aFrameBuffer;
1928 if( aFrameBuffer.init( aWidth, aHeight ) )
1930 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
1932 glPushAttrib( GL_VIEWPORT_BIT );
1933 glViewport( 0, 0, aWidth, aHeight );
1934 aFrameBuffer.bind();
1939 aFrameBuffer.unbind();
1942 aFrameBuffer.bind();
1943 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
1944 aFrameBuffer.unbind();
1946 anImage = anImage.rgbSwapped();
1947 anImage = anImage.mirrored();
1950 // if frame buffers are unsupported, use old functionality
1953 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
1955 QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
1957 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
1962 view->ToPixMap(aPix,aWidth, aHeight,Graphic3d_BT_RGBA);
1964 QImage anImage( aPix.Data(), aWidth, aHeight, QImage::Format_ARGB32 );
1965 anImage = anImage.mirrored();
1969 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
1970 const QString& fileName,
1971 const QString& format )
1973 if ( format != "PS" && format != "EPS")
1974 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
1976 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
1979 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
1980 else if (format == "EPS")
1981 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
1987 QString OCCViewer_ViewWindow::filter() const
1989 return tr( "OCC_IMAGE_FILES" );
1994 \brief Set parameters of the cutting plane
1995 \param on if \c true, cutting plane is enabled
1996 \param x X position of plane point
1997 \param y Y position of plane point
1998 \param z Z position of plane point
1999 \param dx X coordinate of plane normal
2000 \param dy Y coordinate of plane normal
2001 \param dz Z coordinate of plane normal
2003 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2004 const double dx, const double dy, const double dz )
2006 Handle(V3d_View) view = myViewPort->getView();
2007 if ( view.IsNull() )
2011 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2013 // try to use already existing plane or create a new one
2014 Handle(V3d_Plane) clipPlane;
2016 // calculate new a,b,c,d values for the plane
2017 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2019 pln.Coefficients(a, b, c, d);
2021 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2022 Handle(Graphic3d_ClipPlane) aClipPlane;
2023 if(aPlanes.Size() > 0 ) {
2024 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2025 aClipPlane = anIter.Value();
2026 aClipPlane->SetEquation(pln);
2027 aClipPlane->SetOn(Standard_True);
2029 aClipPlane = new Graphic3d_ClipPlane(pln);
2030 view->AddClipPlane(aClipPlane);
2031 aClipPlane->SetOn(Standard_True);
2035 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2036 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2037 for( ;anIter.More();anIter.Next() ){
2038 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2039 aClipPlane->SetOn(Standard_False);
2047 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2049 gp_Dir aDir = pln.Axis().Direction();
2050 gp_Pnt aPnt = pln.Location();
2051 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2056 \brief Check if any cutting plane is enabled
2057 \return \c true if at least one cutting plane is enabled
2059 bool OCCViewer_ViewWindow::isCuttingPlane()
2061 Handle(V3d_View) view = myViewPort->getView();
2063 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2064 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2065 for( ;anIter.More();anIter.Next() ) {
2066 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2067 if(aClipPlane->IsOn()) {
2076 \brief Get the visual parameters of the view window.
2077 \return visual parameters of view window
2079 viewAspect OCCViewer_ViewWindow::getViewParams() const
2081 double projX, projY, projZ, twist;
2082 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2083 double aScaleX, aScaleY, aScaleZ;
2085 Handle(V3d_View) aView3d = myViewPort->getView();
2087 aView3d->Proj( projX, projY, projZ );
2088 aView3d->At( atX, atY, atZ );
2089 aView3d->Eye( eyeX, eyeY, eyeZ );
2090 twist = aView3d->Twist();
2092 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2094 bool isShown = myModel->isTrihedronVisible();
2095 double size = myModel->trihedronSize();
2097 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2100 params.scale = aView3d->Scale();
2101 params.projX = projX;
2102 params.projY = projY;
2103 params.projZ = projZ;
2104 params.twist = twist;
2111 params.scaleX = aScaleX;
2112 params.scaleY = aScaleY;
2113 params.scaleZ = aScaleZ;
2114 params.name = aName;
2115 params.isVisible= isShown;
2118 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2119 aView3d->Center( params.centerX, params.centerY );
2122 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
2123 // graduated trihedron
2124 bool anIsVisible = false;
2125 OCCViewer_AxisWidget::AxisData anAxisData[3];
2126 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2128 params.gtIsVisible = anIsVisible;
2129 params.gtDrawNameX = anAxisData[0].DrawName;
2130 params.gtDrawNameY = anAxisData[1].DrawName;
2131 params.gtDrawNameZ = anAxisData[2].DrawName;
2132 params.gtNameX = anAxisData[0].Name;
2133 params.gtNameY = anAxisData[1].Name;
2134 params.gtNameZ = anAxisData[2].Name;
2135 params.gtNameColorRX = anAxisData[0].NameColor.red();
2136 params.gtNameColorGX = anAxisData[0].NameColor.green();
2137 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2138 params.gtNameColorRY = anAxisData[1].NameColor.red();
2139 params.gtNameColorGY = anAxisData[1].NameColor.green();
2140 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2141 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2142 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2143 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2144 params.gtDrawValuesX = anAxisData[0].DrawValues;
2145 params.gtDrawValuesY = anAxisData[1].DrawValues;
2146 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2147 params.gtNbValuesX = anAxisData[0].NbValues;
2148 params.gtNbValuesY = anAxisData[1].NbValues;
2149 params.gtNbValuesZ = anAxisData[2].NbValues;
2150 params.gtOffsetX = anAxisData[0].Offset;
2151 params.gtOffsetY = anAxisData[1].Offset;
2152 params.gtOffsetZ = anAxisData[2].Offset;
2153 params.gtColorRX = anAxisData[0].Color.red();
2154 params.gtColorGX = anAxisData[0].Color.green();
2155 params.gtColorBX = anAxisData[0].Color.blue();
2156 params.gtColorRY = anAxisData[1].Color.red();
2157 params.gtColorGY = anAxisData[1].Color.green();
2158 params.gtColorBY = anAxisData[1].Color.blue();
2159 params.gtColorRZ = anAxisData[2].Color.red();
2160 params.gtColorGZ = anAxisData[2].Color.green();
2161 params.gtColorBZ = anAxisData[2].Color.blue();
2162 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2163 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2164 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2165 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2166 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2167 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2174 \brief Get visual parameters of this view window.
2175 \return visual parameters of view window
2177 QString OCCViewer_ViewWindow::getVisualParameters()
2179 viewAspect params = getViewParams();
2183 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2184 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2185 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
2186 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
2188 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2189 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2190 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2191 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2192 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2193 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2194 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2195 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2196 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2197 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2198 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2199 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2200 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2201 data << QString( "isVisible=%1" ).arg( params.isVisible );
2202 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2204 ClipPlanesList aPlanes = myModel->getClipPlanes();
2205 for ( int i=0; i < aPlanes.size(); i++ )
2207 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2208 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2209 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2210 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2211 switch ( aPlane.Mode )
2213 case OCCViewer_ClipPlane::Absolute :
2215 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2217 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2219 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2220 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2221 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2225 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2230 case OCCViewer_ClipPlane::Relative :
2232 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2233 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2234 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2239 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2240 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2241 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2242 data << ClippingPlane;
2246 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 or newer version
2247 // graduated trihedron
2248 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2249 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2250 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2251 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2252 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2253 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2254 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2255 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2256 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2257 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2258 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2259 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2260 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2261 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2262 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2263 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2264 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2265 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2266 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2267 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2268 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2269 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2270 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2271 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2272 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2273 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2274 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2275 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2276 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2277 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2278 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2279 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2280 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2281 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2282 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2283 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2284 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2285 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2286 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2287 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2289 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2290 data << QString( "background=%1" ).arg( bg );
2292 return data.join("*");
2296 \brief Restore visual parameters of the view window.
2297 \param parameters visual parameters of view window
2299 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2302 ClipPlanesList aClipPlanes;
2303 QStringList data = parameters.split( '*' );
2304 Qtx::BackgroundData bgData;
2305 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2307 foreach( QString param, data ) {
2308 QString paramName = param.section( '=', 0, 0 ).trimmed();
2309 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2310 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2311 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2312 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2313 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2314 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2315 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2316 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2317 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2318 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2319 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2320 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2321 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2322 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2323 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2324 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2325 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2326 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2327 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2328 else if ( paramName.contains( "ClippingPlane" ) )
2330 QStringList ClipPlaneData = paramValue.split( ';' );
2331 OCCViewer_ClipPlane aPlane;
2332 foreach( QString ClipPlaneParam, ClipPlaneData )
2334 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2335 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2336 if ( ClipPlane_paramName == "Mode" )
2338 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2340 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2341 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2342 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2343 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2346 switch ( aPlane.Mode )
2348 case OCCViewer_ClipPlane::Absolute :
2349 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2350 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2351 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2352 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2353 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2356 case OCCViewer_ClipPlane::Relative :
2357 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2358 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2359 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2364 aClipPlanes.push_back(aPlane);
2366 // graduated trihedron
2367 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2368 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2369 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2370 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2371 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2372 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2373 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2374 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2375 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2376 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2377 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2378 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2379 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2380 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2381 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2382 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2383 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2384 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2385 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2386 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2387 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2388 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2389 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2390 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2391 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2392 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2393 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2394 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2395 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2396 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2397 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2398 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2399 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2400 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2401 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2402 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2403 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2404 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2405 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2406 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2407 else if ( paramName == "background" ) {
2408 QString bg = paramValue.replace( "$", "=" );
2409 bgData = Qtx::stringToBackground( bg );
2413 else // old format - "1.000e+00*0.000e+00..."
2416 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2417 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2418 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2419 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2420 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2421 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2422 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
2423 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2424 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2425 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
2426 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2427 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2428 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2429 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
2430 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
2431 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
2432 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
2433 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
2435 performRestoring( params );
2436 setBackground( bgData );
2437 myModel->setClipPlanes(aClipPlanes);
2441 \brief Handle show event.
2443 Emits Show() signal.
2445 \param theEvent show event
2447 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2449 emit Show( theEvent );
2453 \brief Handle hide event.
2455 Emits Hide() signal.
2457 \param theEvent hide event
2459 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
2461 emit Hide( theEvent );
2466 Creates default sketcher. [ virtual protected ]
2468 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
2471 return new OCCViewer_RectSketcher( this, type );
2472 if ( type == Polygon )
2473 return new OCCViewer_PolygonSketcher( this, type );
2477 void OCCViewer_ViewWindow::initSketchers()
2479 if ( mySketchers.isEmpty() )
2481 mySketchers.append( createSketcher( Rect ) );
2482 mySketchers.append( createSketcher( Polygon ) );
2486 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
2488 OCCViewer_ViewSketcher* sketcher = 0;
2489 QList<OCCViewer_ViewSketcher*>::Iterator it;
2490 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
2492 OCCViewer_ViewSketcher* sk = (*it);
2493 if ( sk->type() == typ )
2500 Handles requests for sketching in the active view. [ virtual public ]
2502 void OCCViewer_ViewWindow::activateSketching( int type )
2504 OCCViewer_ViewPort3d* vp = getViewPort();
2508 if ( !vp->isSketchingEnabled() )
2511 /* Finish current sketching */
2512 if ( type == NoSketching )
2516 onSketchingFinished();
2517 mypSketcher->deactivate();
2521 /* Activate new sketching */
2524 activateSketching( NoSketching ); /* concurrency not suported */
2525 mypSketcher = getSketcher( type );
2528 mypSketcher->activate();
2529 onSketchingStarted();
2535 Unhilights detected entities. [ virtual protected ]
2537 void OCCViewer_ViewWindow::onSketchingStarted()
2542 Selection by rectangle or polygon. [ virtual protected ]
2544 void OCCViewer_ViewWindow::onSketchingFinished()
2546 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
2547 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
2549 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
2550 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
2551 switch( mypSketcher->type() )
2555 QRect* aRect = (QRect*)mypSketcher->data();
2558 int aLeft = aRect->left();
2559 int aRight = aRect->right();
2560 int aTop = aRect->top();
2561 int aBottom = aRect->bottom();
2565 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2567 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2573 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
2576 int size = aPolygon->size();
2577 TColgp_Array1OfPnt2d anArray( 1, size );
2579 QPolygon::Iterator it = aPolygon->begin();
2580 QPolygon::Iterator itEnd = aPolygon->end();
2581 for( int index = 1; it != itEnd; ++it, index++ )
2583 QPoint aPoint = *it;
2584 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
2588 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
2590 ic->Select( anArray, getViewPort()->getView(), Standard_False );
2598 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
2599 aViewMgr->getOCCViewer()->performSelectionChanged();
2603 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
2608 bool OCCViewer_ViewWindow::transformRequested() const
2610 return ( myOperation != NOTHING );
2613 bool OCCViewer_ViewWindow::transformInProcess() const
2615 return myEventStarted;
2618 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
2620 myEventStarted = bOn;
2624 Set enabled state of transformation (rotate, zoom, etc)
2626 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
2628 if ( id != NOTHING ) myStatus.insert( id, on );
2632 \return enabled state of transformation (rotate, zoom, etc)
2634 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
2636 return myStatus.contains( id ) ? myStatus[ id ] : true;
2639 void OCCViewer_ViewWindow::onMaximizedView()
2641 setMaximized(!isMaximized());
2644 void OCCViewer_ViewWindow::returnTo3dView()
2646 setReturnedTo3dView( true );
2649 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
2651 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
2652 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
2653 if ( !isVisible3dView )
2654 toolMgr()->show( ReturnTo3dViewId );
2656 toolMgr()->hide( ReturnTo3dViewId );
2657 if ( isVisible3dView ) emit returnedTo3d( );
2661 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
2663 QAction* anAction = toolMgr()->action( MaximizedId );
2664 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
2665 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
2667 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
2668 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
2669 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
2670 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
2671 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
2673 emit maximized( this, true );
2677 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
2678 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
2679 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
2680 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
2681 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
2683 emit maximized( this, false );
2688 bool OCCViewer_ViewWindow::isMaximized() const
2690 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
2693 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
2695 IsSketcherStyle = enable;
2698 bool OCCViewer_ViewWindow::isSketcherStyle() const
2700 return IsSketcherStyle;
2704 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
2710 QColor OCCViewer_ViewWindow::backgroundColor() const
2712 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
2716 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
2718 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
2721 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
2723 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
2726 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
2728 if ( myViewPort ) myViewPort->setBackground( theBackground );
2731 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
2733 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
2739 void OCCViewer_ViewWindow::clearViewAspects()
2741 myViewAspects.clear();
2745 \return const reference to list of view aspects
2747 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
2749 return myViewAspects;
2753 Appends new view aspect
2754 \param aParams - new view aspects
2756 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
2758 myViewAspects.append( aParams );
2762 Replaces old view aspects by new ones
2763 \param aViewList - list of new view aspects
2765 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
2767 myViewAspects = aViewList;
2771 Get camera properties for the OCC view window.
2772 \return shared pointer on camera properties.
2774 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
2776 SUIT_CameraProperties aProps;
2778 Handle(V3d_View) aSourceView = getViewPort()->getView();
2779 if ( aSourceView.IsNull() )
2782 if ( get2dMode() == No2dMode ) {
2783 aProps.setDimension( SUIT_CameraProperties::Dim3D );
2786 aProps.setDimension( SUIT_CameraProperties::Dim2D );
2787 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
2790 // read common properites of the view
2791 Standard_Real anUp[3];
2792 Standard_Real anAt[3];
2793 Standard_Real anEye[3];
2794 Standard_Real aProj[3];
2795 Standard_Real anAxialScale[3];
2797 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
2798 aSourceView->At( anAt[0], anAt[1], anAt[2] );
2799 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
2800 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2802 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2803 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
2805 #if OCC_VERSION_LARGE > 0x06070100
2806 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
2808 // store camera properties "as is": it is up to synchronized
2809 // view classes to provide necessary property conversion.
2810 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
2811 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
2813 if ( aSourceView->Camera()->IsOrthographic() )
2815 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
2816 aProps.setViewAngle( 0.0 );
2820 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
2821 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
2823 aProps.setMappingScale( aSourceView->Camera()->Scale() );
2825 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
2827 // generate view orientation matrix for transforming OCC projection reference point
2828 // into a camera (eye) position.
2829 gp_Dir aLeftDir = gp_Dir( anUp[0], anUp[1], anUp[2] ) ^ gp_Dir( aProj[0], aProj[1], aProj[2] );
2832 aTrsf.SetValue( 1, 1, aLeftDir.X() );
2833 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
2834 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
2836 aTrsf.SetValue( 1, 2, anUp[0] );
2837 aTrsf.SetValue( 2, 2, anUp[1] );
2838 aTrsf.SetValue( 3, 2, anUp[2] );
2840 aTrsf.SetValue( 1, 3, aProj[0] );
2841 aTrsf.SetValue( 2, 3, aProj[1] );
2842 aTrsf.SetValue( 3, 3, aProj[2] );
2844 aTrsf.SetValue( 1, 4, anAt[0] );
2845 aTrsf.SetValue( 2, 4, anAt[1] );
2846 aTrsf.SetValue( 3, 4, anAt[2] );
2848 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
2850 // transform to world-space coordinate system
2851 gp_XYZ aPosition( aProjRef.X(), aProjRef.Y(), aCameraDepth );
2852 aTrsf.Transforms( aPosition );
2854 // compute focal point
2855 double aFocalPoint[3];
2857 aFocalPoint[0] = aPosition.X() - aProj[0] * aCameraDepth;
2858 aFocalPoint[1] = aPosition.Y() - aProj[1] * aCameraDepth;
2859 aFocalPoint[2] = aPosition.Z() - aProj[2] * aCameraDepth;
2861 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2862 aProps.setPosition( aPosition.X(), aPosition.Y(), aPosition.Z() );
2864 Standard_Real aViewScale[2];
2865 aSourceView->Size( aViewScale[0], aViewScale[1] );
2866 aProps.setMappingScale( aViewScale[1] );
2874 This implementation synchronizes OCC view's camera propreties.
2876 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
2878 bool blocked = blockSignals( true );
2880 SUIT_CameraProperties aProps = theView->cameraProperties();
2881 if ( !cameraProperties().isCompatible( aProps ) ) {
2882 // other view, this one is being currently synchronized to, seems has become incompatible
2883 // we have to break synchronization
2888 Handle(V3d_View) aDestView = getViewPort()->getView();
2890 aDestView->SetImmediateUpdate( Standard_False );
2893 double aPosition[3];
2894 double aFocalPoint[3];
2895 double anAxialScale[3];
2897 // get common properties
2898 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2899 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
2900 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2901 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2903 #if OCC_VERSION_LARGE > 0x06070100
2904 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2905 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
2906 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2907 aDestView->Camera()->SetScale( aProps.getMappingScale() );
2909 gp_Dir aProjDir( aPosition[0] - aFocalPoint[0],
2910 aPosition[1] - aFocalPoint[1],
2911 aPosition[2] - aFocalPoint[2] );
2913 // get custom view translation
2914 Standard_Real aTranslation[3];
2915 aDestView->At( aTranslation[0], aTranslation[1], aTranslation[2] );
2917 gp_Dir aLeftDir = gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] )
2918 ^ gp_Dir( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
2921 aTrsf.SetValue( 1, 1, aLeftDir.X() );
2922 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
2923 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
2925 aTrsf.SetValue( 1, 2, anUpDir[0] );
2926 aTrsf.SetValue( 2, 2, anUpDir[1] );
2927 aTrsf.SetValue( 3, 2, anUpDir[2] );
2929 aTrsf.SetValue( 1, 3, aProjDir.X() );
2930 aTrsf.SetValue( 2, 3, aProjDir.Y() );
2931 aTrsf.SetValue( 3, 3, aProjDir.Z() );
2933 aTrsf.SetValue( 1, 4, aTranslation[0] );
2934 aTrsf.SetValue( 2, 4, aTranslation[1] );
2935 aTrsf.SetValue( 3, 4, aTranslation[2] );
2938 // transform to view-space coordinate system
2939 gp_XYZ aProjRef( aPosition[0], aPosition[1], aPosition[2] );
2940 aTrsf.Transforms( aProjRef );
2942 // set view camera properties using low-level approach. this is done
2943 // in order to avoid interference with static variables in v3d view used
2944 // when rotation is in process in another view.
2945 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
2946 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
2948 Graphic3d_Vector aMappingProj( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
2949 Graphic3d_Vector aMappingUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2951 aMappingProj.Normalize();
2952 aMappingUp.Normalize();
2954 anOrientation.SetViewReferencePlane( aMappingProj );
2955 anOrientation.SetViewReferenceUp( aMappingUp );
2957 aDestView->SetViewMapping( aMapping );
2958 aDestView->SetViewOrientation( anOrientation );
2961 aDestView->SetCenter( aProjRef.X(), aProjRef.Y() );
2963 // set mapping scale
2964 double aMapScaling = aProps.getMappingScale();
2965 Standard_Real aWidth, aHeight;
2966 aDestView->Size( aWidth, aHeight );
2967 aDestView->SetSize ( aWidth > aHeight ? aMapScaling * (aWidth / aHeight) : aMapScaling );
2970 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2972 aDestView->ZFitAll();
2973 aDestView->SetImmediateUpdate( Standard_True );
2974 aDestView->Redraw();
2976 blockSignals( blocked );
2980 \brief Indicates whether preselection is enabled
2981 \return true if preselection is enabled
2983 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
2985 return myPreselectionEnabled;
2989 \brief Enables/disables preselection
2990 \param theIsToEnable if true - preselection will be enabled
2992 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
2994 onSwitchPreselection( theIsToEnable );
2998 \brief Indicates whether selection is enabled
2999 \return true if selection is enabled
3001 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3003 return mySelectionEnabled;
3007 \brief Enables/disables selection
3008 \param theIsToEnable if true - selection will be enabled
3010 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3012 onSwitchSelection( theIsToEnable );
3017 \brief called if clipping operation is activated / deactivated.
3019 Enables/disables clipping plane displaying.
3021 \parma on action state
3023 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3025 if(!myModel) return;
3026 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3029 if (!aClippingDlg) {
3030 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3031 myModel->setClippingDlg(aClippingDlg);
3033 if (!aClippingDlg->isVisible())
3034 aClippingDlg->show();
3036 if ( aClippingDlg ) {
3037 aClippingDlg->close();
3038 myModel->setClippingDlg(0);
3042 SUIT_ViewManager* mgr = getViewManager();
3044 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3045 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3046 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3047 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3049 QAction* a = toolMgr()->action( ClippingId );
3051 if(theIsOn != a->isChecked()){
3052 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3053 a->setChecked(theIsOn);
3054 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));