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 static const char* titles[] = {
1374 "LBL_3DTOOLBAR_LABEL",
1375 "LBL_XYTOOLBAR_LABEL",
1376 "LBL_XZTOOLBAR_LABEL",
1377 "LBL_YZTOOLBAR_LABEL",
1379 static const char* names[] = {
1380 "OCCViewer3DViewOperations",
1381 "OCCViewerXYViewOperations",
1382 "OCCViewerXZViewOperations",
1383 "OCCViewerYZViewOperations",
1385 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1386 QString( names[my2dMode] ), // name (language-independant)
1387 false ); // disable floatable toolbar
1388 if ( my2dMode != No2dMode ){
1389 toolMgr()->append( ReturnTo3dViewId, tid );
1390 toolMgr()->append( toolMgr()->separator(), tid );
1392 toolMgr()->append( DumpId, tid );
1393 toolMgr()->append( SwitchInteractionStyleId, tid );
1394 #if OCC_VERSION_LARGE > 0x0603000A // available only with OCC-6.3-sp11 and higher version
1395 toolMgr()->append( SwitchZoomingStyleId, tid );
1397 toolMgr()->append( SwitchPreselectionId, tid );
1398 toolMgr()->append( SwitchSelectionId, tid );
1399 if( myModel->trihedronActivated() )
1400 toolMgr()->append( TrihedronShowId, tid );
1402 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1403 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1404 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1405 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1406 toolMgr()->append( aScaleAction, tid );
1408 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1409 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1410 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1411 toolMgr()->append( aPanningAction, tid );
1413 if (my2dMode == No2dMode) {
1414 toolMgr()->append( ChangeRotationPointId, tid );
1415 toolMgr()->append( RotationId, tid );
1417 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1418 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1419 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1420 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1421 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1422 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1423 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1424 toolMgr()->append( aViewsAction, tid );
1426 toolMgr()->append( AntiClockWiseId, tid );
1427 toolMgr()->append( ClockWiseId, tid );
1429 toolMgr()->append( ResetId, tid );
1432 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1433 aMemAction->insertAction( toolMgr()->action( MemId ) );
1434 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1435 toolMgr()->append( aMemAction, tid );
1437 toolMgr()->append( toolMgr()->separator(), tid );
1438 toolMgr()->append( CloneId, tid );
1440 toolMgr()->append( toolMgr()->separator(), tid );
1441 toolMgr()->append( ClippingId, tid );
1442 toolMgr()->append( AxialScaleId, tid );
1443 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
1444 toolMgr()->append( GraduatedAxesId, tid );
1446 toolMgr()->append( AmbientId, tid );
1448 toolMgr()->append( MaximizedId, tid );
1449 toolMgr()->append( SynchronizeId, tid );
1453 \brief Perform 'fit all' operation.
1455 void OCCViewer_ViewWindow::onViewFitAll()
1457 myViewPort->fitAll();
1461 \brief Perform "front view" transformation.
1463 void OCCViewer_ViewWindow::onFrontView()
1465 emit vpTransformationStarted ( FRONTVIEW );
1466 Handle(V3d_View) aView3d = myViewPort->getView();
1467 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
1469 emit vpTransformationFinished ( FRONTVIEW );
1473 \brief Perform "back view" transformation.
1475 void OCCViewer_ViewWindow::onBackView()
1477 emit vpTransformationStarted ( BACKVIEW );
1478 Handle(V3d_View) aView3d = myViewPort->getView();
1479 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
1481 emit vpTransformationFinished ( BACKVIEW );
1485 \brief Perform "top view" transformation.
1487 void OCCViewer_ViewWindow::onTopView()
1489 emit vpTransformationStarted ( TOPVIEW );
1490 Handle(V3d_View) aView3d = myViewPort->getView();
1491 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
1493 emit vpTransformationFinished ( TOPVIEW );
1497 \brief Perform "bottom view" transformation.
1499 void OCCViewer_ViewWindow::onBottomView()
1501 emit vpTransformationStarted ( BOTTOMVIEW );
1502 Handle(V3d_View) aView3d = myViewPort->getView();
1503 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
1505 emit vpTransformationFinished ( BOTTOMVIEW );
1509 \brief Perform "left view" transformation.
1511 void OCCViewer_ViewWindow::onLeftView()
1513 emit vpTransformationStarted ( LEFTVIEW );
1514 Handle(V3d_View) aView3d = myViewPort->getView();
1515 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
1517 emit vpTransformationFinished ( LEFTVIEW );
1521 \brief Perform "right view" transformation.
1523 void OCCViewer_ViewWindow::onRightView()
1525 emit vpTransformationStarted ( RIGHTVIEW );
1526 Handle(V3d_View) aView3d = myViewPort->getView();
1527 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
1529 emit vpTransformationFinished ( RIGHTVIEW );
1533 \brief Rotate view 90 degrees clockwise
1535 void OCCViewer_ViewWindow::onClockWiseView()
1537 emit vpTransformationStarted ( CLOCKWISEVIEW );
1538 myViewPort->rotateXY( 90. );
1539 emit vpTransformationFinished ( CLOCKWISEVIEW );
1543 \brief Rotate view 90 degrees conterclockwise
1545 void OCCViewer_ViewWindow::onAntiClockWiseView()
1547 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1548 myViewPort->rotateXY( -90. );
1549 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1553 \brief Perform "reset view" transformation.
1555 Sets default orientation of the viewport camera.
1557 void OCCViewer_ViewWindow::onResetView()
1559 emit vpTransformationStarted( RESETVIEW );
1560 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1561 myViewPort->getView()->Reset( false );
1562 myViewPort->fitAll( false, true, false );
1563 myViewPort->getView()->SetImmediateUpdate( upd );
1564 myViewPort->getView()->Update();
1565 emit vpTransformationFinished( RESETVIEW );
1569 \brief Perform "fit all" transformation.
1571 void OCCViewer_ViewWindow::onFitAll()
1573 emit vpTransformationStarted( FITALLVIEW );
1574 myViewPort->fitAll();
1575 emit vpTransformationFinished( FITALLVIEW );
1579 \brief Called if 'change rotation point' operation is activated.
1580 \param on action state
1582 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1586 if (!mySetRotationPointDlg)
1588 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1589 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1592 if (!mySetRotationPointDlg->isVisible())
1594 //if (mySetRotationPointDlg->IsFirstShown())
1595 if (myCurrPointType == GRAVITY)
1597 Standard_Real Xcenter, Ycenter, Zcenter;
1598 if (computeGravityCenter(Xcenter, Ycenter, Zcenter))
1599 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1601 mySetRotationPointDlg->show();
1606 if (mySetRotationPointDlg->isVisible())
1607 mySetRotationPointDlg->hide();
1612 \brief Create one more window with same content.
1614 void OCCViewer_ViewWindow::onCloneView()
1616 SUIT_ViewWindow* vw = myManager->createViewWindow();
1618 emit viewCloned( vw );
1622 Creates one more window with same content
1624 void OCCViewer_ViewWindow::onAxialScale()
1626 if ( !myScalingDlg )
1627 myScalingDlg = new OCCViewer_AxialScaleDlg( this );
1629 if ( !myScalingDlg->isVisible() )
1631 myScalingDlg->Update();
1632 myScalingDlg->show();
1637 Shows Graduated Axes dialog
1639 void OCCViewer_ViewWindow::onGraduatedAxes()
1641 myCubeAxesDlg->Update();
1642 myCubeAxesDlg->show();
1645 void OCCViewer_ViewWindow::onAmbientToogle()
1647 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
1648 viewer->InitDefinedLights();
1649 while(viewer->MoreDefinedLights())
1651 Handle(V3d_Light) light = viewer->DefinedLight();
1652 if(light->Type() != V3d_AMBIENT)
1654 Handle(V3d_View) aView3d = myViewPort->getView();
1655 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
1656 else viewer->SetLightOn(light);
1658 viewer->NextDefinedLights();
1664 \brief Store view parameters.
1666 void OCCViewer_ViewWindow::onMemorizeView()
1668 appendViewAspect( getViewParams() );
1672 \brief Restore view parameters.
1674 void OCCViewer_ViewWindow::onRestoreView()
1676 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
1677 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
1679 updateViewAspects( aDlg->parameters() );
1680 if( myRestoreFlag && aDlg->parameters().count() )
1681 performRestoring( aDlg->currentItem() );
1685 \brief Restore view parameters.
1686 \param anItem view parameters
1688 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
1690 Handle(V3d_View) aView3d = myViewPort->getView();
1692 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
1693 aView3d->SetScale( anItem.scale );
1694 aView3d->SetTwist( anItem.twist );
1695 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
1696 aView3d->SetImmediateUpdate( prev );
1697 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1698 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1699 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
1701 #if OCC_VERSION_LARGE > 0x06070100
1702 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
1704 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
1706 // "eye" and "at" require conversion to represent center panning
1707 // up direction is only available after setting angle of twist and
1708 // other view parameters
1709 aView3d->Up( anUpX, anUpY, anUpZ );
1711 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
1712 gp_Dir anUp( anUpX, anUpY, anUpZ );
1713 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
1714 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1715 gp_Dir aSide = aProj ^ anUp;
1717 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
1718 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
1720 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
1721 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1724 aView3d->SetCenter( anItem.centerX, anItem.centerY );
1727 if ( !baseParamsOnly ) {
1729 myModel->setTrihedronShown( anItem.isVisible );
1730 myModel->setTrihedronSize( anItem.size );
1732 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
1733 // graduated trihedron
1734 bool anIsVisible = anItem.gtIsVisible;
1735 OCCViewer_AxisWidget::AxisData anAxisData[3];
1736 anAxisData[0].DrawName = anItem.gtDrawNameX;
1737 anAxisData[1].DrawName = anItem.gtDrawNameZ;
1738 anAxisData[2].DrawName = anItem.gtDrawNameZ;
1739 anAxisData[0].Name = anItem.gtNameX;
1740 anAxisData[1].Name = anItem.gtNameZ;
1741 anAxisData[2].Name = anItem.gtNameZ;
1742 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
1743 anItem.gtNameColorGX,
1744 anItem.gtNameColorBX );
1745 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
1746 anItem.gtNameColorGY,
1747 anItem.gtNameColorBY );
1748 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
1749 anItem.gtNameColorGZ,
1750 anItem.gtNameColorBZ );
1751 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
1752 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
1753 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
1754 anAxisData[0].NbValues = anItem.gtNbValuesX;
1755 anAxisData[1].NbValues = anItem.gtNbValuesY;
1756 anAxisData[2].NbValues = anItem.gtNbValuesZ;
1757 anAxisData[0].Offset = anItem.gtOffsetX;
1758 anAxisData[1].Offset = anItem.gtOffsetY;
1759 anAxisData[2].Offset = anItem.gtOffsetZ;
1760 anAxisData[0].Color = QColor( anItem.gtColorRX,
1763 anAxisData[1].Color = QColor( anItem.gtColorRY,
1766 anAxisData[2].Color = QColor( anItem.gtColorRZ,
1769 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
1770 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
1771 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
1772 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
1773 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
1774 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
1776 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
1777 myCubeAxesDlg->ApplyData( aView3d );
1780 } // if ( !baseParamsOnly )
1786 \brief Set restore flag.
1788 void OCCViewer_ViewWindow::setRestoreFlag()
1794 \brief Called when action "show/hide trihedron" is activated.
1796 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
1798 myModel->setTrihedronShown(show);
1802 \brief Toggles preselection (highlighting) on/off
1804 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
1806 myPreselectionEnabled = on;
1807 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
1809 // unhighlight all highlighted objects
1811 myModel->unHighlightAll( true, false );
1814 // update action state if method is called outside
1815 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
1816 if ( a && a->isChecked() != on ) {
1817 a->setChecked( on );
1822 \brief Toggles selection on/off
1824 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
1826 mySelectionEnabled = on;
1827 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
1829 // update action state if method is called outside
1832 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
1834 a->setEnabled( on );
1838 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
1839 if ( a && a->isChecked() != on ) {
1840 a->setChecked( on );
1845 \brief Switches "keyboard free" interaction style on/off
1847 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
1849 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
1851 // update action state if method is called outside
1852 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
1853 if ( a->isChecked() != on )
1854 a->setChecked( on );
1858 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
1860 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
1862 myViewPort->setAdvancedZoomingEnabled( on );
1864 // update action state if method is called outside
1865 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
1866 if ( a->isChecked() != on )
1867 a->setChecked( on );
1871 \brief Get current interaction style
1872 \return interaction style
1874 int OCCViewer_ViewWindow::interactionStyle() const
1876 return myInteractionStyle;
1880 \brief Set current interaction style
1881 \param theStyle interaction style
1883 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
1885 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
1889 \brief Get current zooming style
1890 \return zooming style
1892 int OCCViewer_ViewWindow::zoomingStyle() const
1894 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
1898 \brief Set current zooming style
1899 \param theStyle zooming style
1901 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
1903 onSwitchZoomingStyle( theStyle == 1 );
1907 \brief Dump view window contents to the pixmap.
1908 \return pixmap containing all scene rendered in the window
1910 QImage OCCViewer_ViewWindow::dumpView()
1912 Handle(V3d_View) view = myViewPort->getView();
1913 if ( view.IsNull() )
1916 int aWidth = myViewPort->width();
1917 int aHeight = myViewPort->height();
1919 // rnv: An old approach to dump the OCCViewer content
1920 // Now used OCCT built-in procedure.
1922 QApplication::syncX();
1923 view->Redraw(); // In order to reactivate GL context
1926 OpenGLUtils_FrameBuffer aFrameBuffer;
1927 if( aFrameBuffer.init( aWidth, aHeight ) )
1929 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
1931 glPushAttrib( GL_VIEWPORT_BIT );
1932 glViewport( 0, 0, aWidth, aHeight );
1933 aFrameBuffer.bind();
1938 aFrameBuffer.unbind();
1941 aFrameBuffer.bind();
1942 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
1943 aFrameBuffer.unbind();
1945 anImage = anImage.rgbSwapped();
1946 anImage = anImage.mirrored();
1949 // if frame buffers are unsupported, use old functionality
1952 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
1954 QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
1956 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
1961 view->ToPixMap(aPix,aWidth, aHeight,Graphic3d_BT_RGBA);
1963 QImage anImage( aPix.Data(), aWidth, aHeight, QImage::Format_ARGB32 );
1964 anImage = anImage.mirrored();
1968 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
1969 const QString& fileName,
1970 const QString& format )
1972 if ( format != "PS" && format != "EPS")
1973 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
1975 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
1978 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
1979 else if (format == "EPS")
1980 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
1986 QString OCCViewer_ViewWindow::filter() const
1988 return tr( "OCC_IMAGE_FILES" );
1993 \brief Set parameters of the cutting plane
1994 \param on if \c true, cutting plane is enabled
1995 \param x X position of plane point
1996 \param y Y position of plane point
1997 \param z Z position of plane point
1998 \param dx X coordinate of plane normal
1999 \param dy Y coordinate of plane normal
2000 \param dz Z coordinate of plane normal
2002 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2003 const double dx, const double dy, const double dz )
2005 Handle(V3d_View) view = myViewPort->getView();
2006 if ( view.IsNull() )
2010 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2012 // try to use already existing plane or create a new one
2013 Handle(V3d_Plane) clipPlane;
2015 // calculate new a,b,c,d values for the plane
2016 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2018 pln.Coefficients(a, b, c, d);
2020 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2021 if(aPlanes.Size() > 0 ) {
2022 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2023 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2024 aClipPlane->SetEquation(pln);
2025 aClipPlane->SetOn(Standard_True);
2027 view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2031 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2032 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2033 for( ;anIter.More();anIter.Next() ){
2034 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2035 aClipPlane->SetOn(Standard_False);
2043 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2045 gp_Dir aDir = pln.Axis().Direction();
2046 gp_Pnt aPnt = pln.Location();
2047 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2052 \brief Check if any cutting plane is enabled
2053 \return \c true if at least one cutting plane is enabled
2055 bool OCCViewer_ViewWindow::isCuttingPlane()
2057 Handle(V3d_View) view = myViewPort->getView();
2059 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2060 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2061 for( ;anIter.More();anIter.Next() ) {
2062 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2063 if(aClipPlane->IsOn()) {
2072 \brief Get the visual parameters of the view window.
2073 \return visual parameters of view window
2075 viewAspect OCCViewer_ViewWindow::getViewParams() const
2077 double projX, projY, projZ, twist;
2078 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2079 double aScaleX, aScaleY, aScaleZ;
2081 Handle(V3d_View) aView3d = myViewPort->getView();
2083 aView3d->Proj( projX, projY, projZ );
2084 aView3d->At( atX, atY, atZ );
2085 aView3d->Eye( eyeX, eyeY, eyeZ );
2086 twist = aView3d->Twist();
2088 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2090 bool isShown = myModel->isTrihedronVisible();
2091 double size = myModel->trihedronSize();
2093 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2096 params.scale = aView3d->Scale();
2097 params.projX = projX;
2098 params.projY = projY;
2099 params.projZ = projZ;
2100 params.twist = twist;
2107 params.scaleX = aScaleX;
2108 params.scaleY = aScaleY;
2109 params.scaleZ = aScaleZ;
2110 params.name = aName;
2111 params.isVisible= isShown;
2114 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2115 aView3d->Center( params.centerX, params.centerY );
2118 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
2119 // graduated trihedron
2120 bool anIsVisible = false;
2121 OCCViewer_AxisWidget::AxisData anAxisData[3];
2122 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2124 params.gtIsVisible = anIsVisible;
2125 params.gtDrawNameX = anAxisData[0].DrawName;
2126 params.gtDrawNameY = anAxisData[1].DrawName;
2127 params.gtDrawNameZ = anAxisData[2].DrawName;
2128 params.gtNameX = anAxisData[0].Name;
2129 params.gtNameY = anAxisData[1].Name;
2130 params.gtNameZ = anAxisData[2].Name;
2131 params.gtNameColorRX = anAxisData[0].NameColor.red();
2132 params.gtNameColorGX = anAxisData[0].NameColor.green();
2133 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2134 params.gtNameColorRY = anAxisData[1].NameColor.red();
2135 params.gtNameColorGY = anAxisData[1].NameColor.green();
2136 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2137 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2138 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2139 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2140 params.gtDrawValuesX = anAxisData[0].DrawValues;
2141 params.gtDrawValuesY = anAxisData[1].DrawValues;
2142 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2143 params.gtNbValuesX = anAxisData[0].NbValues;
2144 params.gtNbValuesY = anAxisData[1].NbValues;
2145 params.gtNbValuesZ = anAxisData[2].NbValues;
2146 params.gtOffsetX = anAxisData[0].Offset;
2147 params.gtOffsetY = anAxisData[1].Offset;
2148 params.gtOffsetZ = anAxisData[2].Offset;
2149 params.gtColorRX = anAxisData[0].Color.red();
2150 params.gtColorGX = anAxisData[0].Color.green();
2151 params.gtColorBX = anAxisData[0].Color.blue();
2152 params.gtColorRY = anAxisData[1].Color.red();
2153 params.gtColorGY = anAxisData[1].Color.green();
2154 params.gtColorBY = anAxisData[1].Color.blue();
2155 params.gtColorRZ = anAxisData[2].Color.red();
2156 params.gtColorGZ = anAxisData[2].Color.green();
2157 params.gtColorBZ = anAxisData[2].Color.blue();
2158 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2159 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2160 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2161 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2162 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2163 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2170 \brief Get visual parameters of this view window.
2171 \return visual parameters of view window
2173 QString OCCViewer_ViewWindow::getVisualParameters()
2175 viewAspect params = getViewParams();
2179 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2180 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2181 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
2182 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
2184 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2185 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2186 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2187 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2188 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2189 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2190 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2191 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2192 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2193 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2194 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2195 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2196 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2197 data << QString( "isVisible=%1" ).arg( params.isVisible );
2198 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2200 ClipPlanesList aPlanes = myModel->getClipPlanes();
2201 for ( int i=0; i < aPlanes.size(); i++ )
2203 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2204 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2205 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2206 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2207 switch ( aPlane.Mode )
2209 case OCCViewer_ClipPlane::Absolute :
2211 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2213 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2215 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2216 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2217 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2221 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2226 case OCCViewer_ClipPlane::Relative :
2228 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2229 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2230 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2235 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2236 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2237 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2238 data << ClippingPlane;
2242 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 or newer version
2243 // graduated trihedron
2244 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2245 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2246 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2247 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2248 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2249 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2250 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2251 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2252 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2253 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2254 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2255 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2256 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2257 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2258 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2259 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2260 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2261 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2262 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2263 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2264 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2265 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2266 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2267 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2268 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2269 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2270 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2271 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2272 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2273 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2274 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2275 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2276 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2277 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2278 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2279 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2280 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2281 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2282 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2283 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2285 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2286 data << QString( "background=%1" ).arg( bg );
2288 return data.join("*");
2292 \brief Restore visual parameters of the view window.
2293 \param parameters visual parameters of view window
2295 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2298 ClipPlanesList aClipPlanes;
2299 QStringList data = parameters.split( '*' );
2300 Qtx::BackgroundData bgData;
2301 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2303 foreach( QString param, data ) {
2304 QString paramName = param.section( '=', 0, 0 ).trimmed();
2305 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2306 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2307 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2308 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2309 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2310 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2311 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2312 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2313 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2314 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2315 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2316 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2317 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2318 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2319 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2320 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2321 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2322 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2323 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2324 else if ( paramName.contains( "ClippingPlane" ) )
2326 QStringList ClipPlaneData = paramValue.split( ';' );
2327 OCCViewer_ClipPlane aPlane;
2328 foreach( QString ClipPlaneParam, ClipPlaneData )
2330 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2331 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2332 if ( ClipPlane_paramName == "Mode" )
2334 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2336 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2337 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2338 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2339 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2342 switch ( aPlane.Mode )
2344 case OCCViewer_ClipPlane::Absolute :
2345 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2346 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2347 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2348 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2349 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2352 case OCCViewer_ClipPlane::Relative :
2353 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2354 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2355 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2360 aClipPlanes.push_back(aPlane);
2362 // graduated trihedron
2363 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2364 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2365 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2366 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2367 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2368 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2369 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2370 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2371 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2372 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2373 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2374 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2375 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2376 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2377 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2378 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2379 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2380 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2381 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2382 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2383 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2384 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2385 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2386 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2387 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2388 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2389 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2390 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2391 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2392 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2393 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2394 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2395 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2396 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2397 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2398 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2399 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2400 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2401 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2402 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2403 else if ( paramName == "background" ) {
2404 QString bg = paramValue.replace( "$", "=" );
2405 bgData = Qtx::stringToBackground( bg );
2409 else // old format - "1.000e+00*0.000e+00..."
2412 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2413 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2414 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2415 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2416 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2417 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2418 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
2419 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2420 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2421 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
2422 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2423 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2424 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2425 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
2426 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
2427 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
2428 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
2429 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
2431 performRestoring( params );
2432 setBackground( bgData );
2433 myModel->setClipPlanes(aClipPlanes);
2437 \brief Handle show event.
2439 Emits Show() signal.
2441 \param theEvent show event
2443 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2445 emit Show( theEvent );
2449 \brief Handle hide event.
2451 Emits Hide() signal.
2453 \param theEvent hide event
2455 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
2457 emit Hide( theEvent );
2462 Creates default sketcher. [ virtual protected ]
2464 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
2467 return new OCCViewer_RectSketcher( this, type );
2468 if ( type == Polygon )
2469 return new OCCViewer_PolygonSketcher( this, type );
2473 void OCCViewer_ViewWindow::initSketchers()
2475 if ( mySketchers.isEmpty() )
2477 mySketchers.append( createSketcher( Rect ) );
2478 mySketchers.append( createSketcher( Polygon ) );
2482 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
2484 OCCViewer_ViewSketcher* sketcher = 0;
2485 QList<OCCViewer_ViewSketcher*>::Iterator it;
2486 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
2488 OCCViewer_ViewSketcher* sk = (*it);
2489 if ( sk->type() == typ )
2496 Handles requests for sketching in the active view. [ virtual public ]
2498 void OCCViewer_ViewWindow::activateSketching( int type )
2500 OCCViewer_ViewPort3d* vp = getViewPort();
2504 if ( !vp->isSketchingEnabled() )
2507 /* Finish current sketching */
2508 if ( type == NoSketching )
2512 onSketchingFinished();
2513 mypSketcher->deactivate();
2517 /* Activate new sketching */
2520 activateSketching( NoSketching ); /* concurrency not suported */
2521 mypSketcher = getSketcher( type );
2524 mypSketcher->activate();
2525 onSketchingStarted();
2531 Unhilights detected entities. [ virtual protected ]
2533 void OCCViewer_ViewWindow::onSketchingStarted()
2538 Selection by rectangle or polygon. [ virtual protected ]
2540 void OCCViewer_ViewWindow::onSketchingFinished()
2542 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
2543 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
2545 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
2546 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
2547 switch( mypSketcher->type() )
2551 QRect* aRect = (QRect*)mypSketcher->data();
2554 int aLeft = aRect->left();
2555 int aRight = aRect->right();
2556 int aTop = aRect->top();
2557 int aBottom = aRect->bottom();
2561 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2563 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2569 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
2572 int size = aPolygon->size();
2573 TColgp_Array1OfPnt2d anArray( 1, size );
2575 QPolygon::Iterator it = aPolygon->begin();
2576 QPolygon::Iterator itEnd = aPolygon->end();
2577 for( int index = 1; it != itEnd; ++it, index++ )
2579 QPoint aPoint = *it;
2580 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
2584 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
2586 ic->Select( anArray, getViewPort()->getView(), Standard_False );
2594 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
2595 aViewMgr->getOCCViewer()->performSelectionChanged();
2599 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
2604 bool OCCViewer_ViewWindow::transformRequested() const
2606 return ( myOperation != NOTHING );
2609 bool OCCViewer_ViewWindow::transformInProcess() const
2611 return myEventStarted;
2614 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
2616 myEventStarted = bOn;
2620 Set enabled state of transformation (rotate, zoom, etc)
2622 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
2624 if ( id != NOTHING ) myStatus.insert( id, on );
2628 \return enabled state of transformation (rotate, zoom, etc)
2630 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
2632 return myStatus.contains( id ) ? myStatus[ id ] : true;
2635 void OCCViewer_ViewWindow::onMaximizedView()
2637 setMaximized(!isMaximized());
2640 void OCCViewer_ViewWindow::returnTo3dView()
2642 setReturnedTo3dView( true );
2645 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
2647 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
2648 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
2649 if ( !isVisible3dView )
2650 toolMgr()->show( ReturnTo3dViewId );
2652 toolMgr()->hide( ReturnTo3dViewId );
2653 if ( isVisible3dView ) emit returnedTo3d( );
2657 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
2659 QAction* anAction = toolMgr()->action( MaximizedId );
2660 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
2661 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
2663 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
2664 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
2665 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
2666 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
2667 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
2669 emit maximized( this, true );
2673 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
2674 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
2675 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
2676 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
2677 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
2679 emit maximized( this, false );
2684 bool OCCViewer_ViewWindow::isMaximized() const
2686 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
2689 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
2691 IsSketcherStyle = enable;
2694 bool OCCViewer_ViewWindow::isSketcherStyle() const
2696 return IsSketcherStyle;
2700 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
2706 QColor OCCViewer_ViewWindow::backgroundColor() const
2708 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
2712 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
2714 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
2717 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
2719 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
2722 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
2724 if ( myViewPort ) myViewPort->setBackground( theBackground );
2727 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
2729 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
2735 void OCCViewer_ViewWindow::clearViewAspects()
2737 myViewAspects.clear();
2741 \return const reference to list of view aspects
2743 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
2745 return myViewAspects;
2749 Appends new view aspect
2750 \param aParams - new view aspects
2752 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
2754 myViewAspects.append( aParams );
2758 Replaces old view aspects by new ones
2759 \param aViewList - list of new view aspects
2761 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
2763 myViewAspects = aViewList;
2767 Get camera properties for the OCC view window.
2768 \return shared pointer on camera properties.
2770 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
2772 SUIT_CameraProperties aProps;
2774 Handle(V3d_View) aSourceView = getViewPort()->getView();
2775 if ( aSourceView.IsNull() )
2778 if ( get2dMode() == No2dMode ) {
2779 aProps.setDimension( SUIT_CameraProperties::Dim3D );
2782 aProps.setDimension( SUIT_CameraProperties::Dim2D );
2783 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
2786 // read common properites of the view
2787 Standard_Real anUp[3];
2788 Standard_Real anAt[3];
2789 Standard_Real anEye[3];
2790 Standard_Real aProj[3];
2791 Standard_Real anAxialScale[3];
2793 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
2794 aSourceView->At( anAt[0], anAt[1], anAt[2] );
2795 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
2796 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2798 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2799 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
2801 #if OCC_VERSION_LARGE > 0x06070100
2802 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
2804 // store camera properties "as is": it is up to synchronized
2805 // view classes to provide necessary property conversion.
2806 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
2807 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
2809 if ( aSourceView->Camera()->IsOrthographic() )
2811 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
2812 aProps.setViewAngle( 0.0 );
2816 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
2817 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
2819 aProps.setMappingScale( aSourceView->Camera()->Scale() );
2821 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
2823 // generate view orientation matrix for transforming OCC projection reference point
2824 // into a camera (eye) position.
2825 gp_Dir aLeftDir = gp_Dir( anUp[0], anUp[1], anUp[2] ) ^ gp_Dir( aProj[0], aProj[1], aProj[2] );
2828 aTrsf.SetValue( 1, 1, aLeftDir.X() );
2829 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
2830 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
2832 aTrsf.SetValue( 1, 2, anUp[0] );
2833 aTrsf.SetValue( 2, 2, anUp[1] );
2834 aTrsf.SetValue( 3, 2, anUp[2] );
2836 aTrsf.SetValue( 1, 3, aProj[0] );
2837 aTrsf.SetValue( 2, 3, aProj[1] );
2838 aTrsf.SetValue( 3, 3, aProj[2] );
2840 aTrsf.SetValue( 1, 4, anAt[0] );
2841 aTrsf.SetValue( 2, 4, anAt[1] );
2842 aTrsf.SetValue( 3, 4, anAt[2] );
2844 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
2846 // transform to world-space coordinate system
2847 gp_XYZ aPosition( aProjRef.X(), aProjRef.Y(), aCameraDepth );
2848 aTrsf.Transforms( aPosition );
2850 // compute focal point
2851 double aFocalPoint[3];
2853 aFocalPoint[0] = aPosition.X() - aProj[0] * aCameraDepth;
2854 aFocalPoint[1] = aPosition.Y() - aProj[1] * aCameraDepth;
2855 aFocalPoint[2] = aPosition.Z() - aProj[2] * aCameraDepth;
2857 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2858 aProps.setPosition( aPosition.X(), aPosition.Y(), aPosition.Z() );
2860 Standard_Real aViewScale[2];
2861 aSourceView->Size( aViewScale[0], aViewScale[1] );
2862 aProps.setMappingScale( aViewScale[1] );
2870 This implementation synchronizes OCC view's camera propreties.
2872 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
2874 bool blocked = blockSignals( true );
2876 SUIT_CameraProperties aProps = theView->cameraProperties();
2877 if ( !cameraProperties().isCompatible( aProps ) ) {
2878 // other view, this one is being currently synchronized to, seems has become incompatible
2879 // we have to break synchronization
2884 Handle(V3d_View) aDestView = getViewPort()->getView();
2886 aDestView->SetImmediateUpdate( Standard_False );
2889 double aPosition[3];
2890 double aFocalPoint[3];
2891 double anAxialScale[3];
2893 // get common properties
2894 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2895 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
2896 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2897 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2899 #if OCC_VERSION_LARGE > 0x06070100
2900 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2901 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
2902 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2903 aDestView->Camera()->SetScale( aProps.getMappingScale() );
2905 gp_Dir aProjDir( aPosition[0] - aFocalPoint[0],
2906 aPosition[1] - aFocalPoint[1],
2907 aPosition[2] - aFocalPoint[2] );
2909 // get custom view translation
2910 Standard_Real aTranslation[3];
2911 aDestView->At( aTranslation[0], aTranslation[1], aTranslation[2] );
2913 gp_Dir aLeftDir = gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] )
2914 ^ gp_Dir( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
2917 aTrsf.SetValue( 1, 1, aLeftDir.X() );
2918 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
2919 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
2921 aTrsf.SetValue( 1, 2, anUpDir[0] );
2922 aTrsf.SetValue( 2, 2, anUpDir[1] );
2923 aTrsf.SetValue( 3, 2, anUpDir[2] );
2925 aTrsf.SetValue( 1, 3, aProjDir.X() );
2926 aTrsf.SetValue( 2, 3, aProjDir.Y() );
2927 aTrsf.SetValue( 3, 3, aProjDir.Z() );
2929 aTrsf.SetValue( 1, 4, aTranslation[0] );
2930 aTrsf.SetValue( 2, 4, aTranslation[1] );
2931 aTrsf.SetValue( 3, 4, aTranslation[2] );
2934 // transform to view-space coordinate system
2935 gp_XYZ aProjRef( aPosition[0], aPosition[1], aPosition[2] );
2936 aTrsf.Transforms( aProjRef );
2938 // set view camera properties using low-level approach. this is done
2939 // in order to avoid interference with static variables in v3d view used
2940 // when rotation is in process in another view.
2941 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
2942 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
2944 Graphic3d_Vector aMappingProj( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
2945 Graphic3d_Vector aMappingUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2947 aMappingProj.Normalize();
2948 aMappingUp.Normalize();
2950 anOrientation.SetViewReferencePlane( aMappingProj );
2951 anOrientation.SetViewReferenceUp( aMappingUp );
2953 aDestView->SetViewMapping( aMapping );
2954 aDestView->SetViewOrientation( anOrientation );
2957 aDestView->SetCenter( aProjRef.X(), aProjRef.Y() );
2959 // set mapping scale
2960 double aMapScaling = aProps.getMappingScale();
2961 Standard_Real aWidth, aHeight;
2962 aDestView->Size( aWidth, aHeight );
2963 aDestView->SetSize ( aWidth > aHeight ? aMapScaling * (aWidth / aHeight) : aMapScaling );
2966 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2968 aDestView->ZFitAll();
2969 aDestView->SetImmediateUpdate( Standard_True );
2970 aDestView->Redraw();
2972 blockSignals( blocked );
2976 \brief Indicates whether preselection is enabled
2977 \return true if preselection is enabled
2979 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
2981 return myPreselectionEnabled;
2985 \brief Enables/disables preselection
2986 \param theIsToEnable if true - preselection will be enabled
2988 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
2990 onSwitchPreselection( theIsToEnable );
2994 \brief Indicates whether selection is enabled
2995 \return true if selection is enabled
2997 bool OCCViewer_ViewWindow::isSelectionEnabled() const
2999 return mySelectionEnabled;
3003 \brief Enables/disables selection
3004 \param theIsToEnable if true - selection will be enabled
3006 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3008 onSwitchSelection( theIsToEnable );
3013 \brief called if clipping operation is activated / deactivated.
3015 Enables/disables clipping plane displaying.
3017 \parma on action state
3019 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3021 if(!myModel) return;
3022 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3025 if (!aClippingDlg) {
3026 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3027 myModel->setClippingDlg(aClippingDlg);
3029 if (!aClippingDlg->isVisible())
3030 aClippingDlg->show();
3032 if ( aClippingDlg ) {
3033 aClippingDlg->close();
3034 myModel->setClippingDlg(0);
3038 SUIT_ViewManager* mgr = getViewManager();
3040 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3041 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3042 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3043 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3045 QAction* a = toolMgr()->action( ClippingId );
3047 if(theIsOn != a->isChecked()){
3048 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3049 a->setChecked(theIsOn);
3050 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));