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 <Standard_Version.hxx>
94 #include "utilities.h"
98 // #include <highgui.h>
100 static QEvent* l_mbPressEvent = 0;
103 # include <QWindowsStyle>
108 const char* imageZoomCursor[] = {
113 "................................",
114 "................................",
115 ".#######........................",
116 "..aaaaaaa.......................",
117 "................................",
118 ".............#####..............",
119 "...........##.aaaa##............",
120 "..........#.aa.....a#...........",
121 ".........#.a.........#..........",
122 ".........#a..........#a.........",
123 "........#.a...........#.........",
124 "........#a............#a........",
125 "........#a............#a........",
126 "........#a............#a........",
127 "........#a............#a........",
128 ".........#...........#.a........",
129 ".........#a..........#a.........",
130 ".........##.........#.a.........",
131 "........#####.....##.a..........",
132 ".......###aaa#####.aa...........",
133 "......###aa...aaaaa.......#.....",
134 ".....###aa................#a....",
135 "....###aa.................#a....",
136 "...###aa...............#######..",
137 "....#aa.................aa#aaaa.",
138 ".....a....................#a....",
139 "..........................#a....",
140 "...........................a....",
141 "................................",
142 "................................",
143 "................................",
144 "................................"};
146 const char* imageRotateCursor[] = {
151 "................................",
152 "................................",
153 "................................",
154 "................................",
155 "........#.......................",
156 ".......#.a......................",
157 "......#######...................",
158 ".......#aaaaa#####..............",
159 "........#..##.a#aa##........##..",
160 ".........a#.aa..#..a#.....##.aa.",
161 ".........#.a.....#...#..##.aa...",
162 ".........#a.......#..###.aa.....",
163 "........#.a.......#a..#aa.......",
164 "........#a.........#..#a........",
165 "........#a.........#a.#a........",
166 "........#a.........#a.#a........",
167 "........#a.........#a.#a........",
168 ".........#.........#a#.a........",
169 "........##a........#a#a.........",
170 "......##.a#.......#.#.a.........",
171 "....##.aa..##.....##.a..........",
172 "..##.aa.....a#####.aa...........",
173 "...aa.........aaa#a.............",
174 "................#.a.............",
175 "...............#.a..............",
176 "..............#.a...............",
177 "...............a................",
178 "................................",
179 "................................",
180 "................................",
181 "................................",
182 "................................"};
184 const char* imageCrossCursor[] = {
189 "................................",
190 "................................",
191 "................................",
192 "................................",
193 "................................",
194 "................................",
195 "................................",
196 "...............#................",
197 "...............#a...............",
198 "...............#a...............",
199 "...............#a...............",
200 "...............#a...............",
201 "...............#a...............",
202 "...............#a...............",
203 "...............#a...............",
204 ".......#################........",
205 "........aaaaaaa#aaaaaaaaa.......",
206 "...............#a...............",
207 "...............#a...............",
208 "...............#a...............",
209 "...............#a...............",
210 "...............#a...............",
211 "...............#a...............",
212 "...............#a...............",
213 "................a...............",
214 "................................",
215 "................................",
216 "................................",
217 "................................",
218 "................................",
219 "................................",
220 "................................"};
225 \param theDesktop main window of application
226 \param theModel OCC 3D viewer
228 OCCViewer_ViewWindow::OCCViewer_ViewWindow( SUIT_Desktop* theDesktop,
229 OCCViewer_Viewer* theModel )
230 : SUIT_ViewWindow( theDesktop )
234 myEnableDrawMode = false;
236 updateEnabledDrawMode();
238 mySetRotationPointDlg = 0;
241 IsSketcherStyle = false;
248 myInteractionStyle = SUIT_ViewModel::STANDARD;
249 myPreselectionEnabled = true;
250 mySelectionEnabled = true;
260 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
263 qDeleteAll( mySketchers );
267 \brief Internal initialization.
269 void OCCViewer_ViewWindow::initLayout()
271 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
272 myViewPort->installEventFilter(this);
273 setCentralWidget(myViewPort);
274 myOperation = NOTHING;
276 myCurrPointType = GRAVITY;
277 myPrevPointType = GRAVITY;
278 mySelectedPoint = gp_Pnt(0.,0.,0.);
279 myRotationPointSelection = false;
281 setTransformRequested ( NOTHING );
282 setTransformInProcess ( false );
299 // Graduated axes dialog
300 QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
301 myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
302 myCubeAxesDlg->initialize();
304 connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
307 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
309 return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
313 \brief Detect viewer operation according the the mouse button pressed
314 and key modifiers used.
315 \param theEvent mouse event
316 \return type of the operation
318 OCCViewer_ViewWindow::OperationType
319 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
321 OperationType aOp = NOTHING;
322 SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
323 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
324 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
326 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
327 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
329 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
330 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
331 (my2dMode == No2dMode))
338 \brief Customize event handling
339 \param watched event receiver object
341 \return \c true if the event processing should be stopped
343 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
345 if ( watched == myViewPort ) {
346 int aType = e->type();
348 case QEvent::MouseButtonPress:
349 vpMousePressEvent((QMouseEvent*) e);
352 case QEvent::MouseButtonRelease:
353 vpMouseReleaseEvent((QMouseEvent*) e);
356 case QEvent::MouseMove:
357 vpMouseMoveEvent((QMouseEvent*) e);
360 case QEvent::MouseButtonDblClick:
361 emit mouseDoubleClicked(this, (QMouseEvent*)e);
366 QWheelEvent* aEvent = (QWheelEvent*) e;
367 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
368 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
371 int x1 = (int)( aEvent->x() + width()*delta/100 );
372 int y1 = (int)( aEvent->y() + height()*delta/100 );
373 myViewPort->zoom( x, y, x1, y1 );
377 case QEvent::ContextMenu:
379 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
380 if ( aEvent->reason() != QContextMenuEvent::Mouse )
381 emit contextMenuRequested( aEvent );
385 case QEvent::KeyPress:
386 emit keyPressed(this, (QKeyEvent*) e);
393 return SUIT_ViewWindow::eventFilter(watched, e);
397 \brief Update state of enable draw mode state.
399 void OCCViewer_ViewWindow::updateEnabledDrawMode()
402 myEnableDrawMode = myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
406 \brief Handle mouse press event
407 \param theEvent mouse event
409 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
411 myStartX = theEvent->x();
412 myStartY = theEvent->y();
413 int anInteractionStyle = interactionStyle();
415 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
416 // which are assigned for pan and rotate - these operations are activated immediately after pressing
417 // of the first button, so it is necessary to switch to zoom when the second button is pressed
418 bool aSwitchToZoom = false;
419 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
420 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
421 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
424 switch ( myOperation ) {
426 if ( theEvent->button() == Qt::LeftButton )
427 emit vpTransformationStarted ( WINDOWFIT );
431 if ( theEvent->button() == Qt::LeftButton )
432 emit vpTransformationStarted ( PANGLOBAL );
436 if ( theEvent->button() == Qt::LeftButton ) {
437 myViewPort->startZoomAtPoint( myStartX, myStartY );
438 emit vpTransformationStarted ( ZOOMVIEW );
443 if ( aSwitchToZoom ) {
444 myViewPort->startZoomAtPoint( myStartX, myStartY );
447 else if ( theEvent->button() == Qt::LeftButton )
448 emit vpTransformationStarted ( PANVIEW );
452 if ( aSwitchToZoom ) {
453 myViewPort->startZoomAtPoint( myStartX, myStartY );
456 else if ( theEvent->button() == Qt::LeftButton ) {
457 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
458 emit vpTransformationStarted ( ROTATE );
463 /* Try to activate a transformation */
464 OperationType aState;
465 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
466 aState = getButtonState(theEvent, anInteractionStyle);
468 aState = OCCViewer_ViewWindow::NOTHING;
473 myViewPort->startZoomAtPoint( myStartX, myStartY );
481 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
484 if ( myRotationPointSelection )
486 if ( theEvent->button() == Qt::LeftButton )
488 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
490 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
492 TopoDS_Shape aShape = ic->SelectedShape();
493 GProp_GProps aSystem;
495 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
497 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
499 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE )
501 BRepGProp::LinearProperties( aShape, aSystem );
502 aPnt = aSystem.CentreOfMass();
504 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE )
506 BRepGProp::SurfaceProperties( aShape, aSystem );
507 aPnt = aSystem.CentreOfMass();
509 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID )
511 BRepGProp::VolumeProperties( aShape, aSystem );
512 aPnt = aSystem.CentreOfMass();
516 myCurrPointType = myPrevPointType;
520 if ( mySetRotationPointDlg )
522 myRotationPointSelection = false;
523 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
526 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
527 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
528 ic->CloseAllContexts();
529 myOperation = NOTHING;
530 myViewPort->setCursor( myCursor );
531 myCursorIsHand = false;
532 myRotationPointSelection = false;
536 emit mousePressed(this, theEvent);
539 /* notify that we start a transformation */
540 if ( transformRequested() )
541 emit vpTransformationStarted ( myOperation );
543 if ( transformRequested() )
544 setTransformInProcess( true );
546 /* we may need it for sketching... */
547 if ( l_mbPressEvent )
548 delete l_mbPressEvent;
549 l_mbPressEvent = new QMouseEvent( *theEvent );
554 \brief Start zooming operation.
556 Sets the corresponding cursor for the widget.
558 void OCCViewer_ViewWindow::activateZoom()
560 if ( !transformRequested() && !myCursorIsHand )
561 myCursor = cursor(); /* save old cursor */
563 if ( myOperation != ZOOMVIEW ) {
564 QPixmap zoomPixmap (imageZoomCursor);
565 QCursor zoomCursor (zoomPixmap);
566 if( setTransformRequested ( ZOOMVIEW ) )
567 myViewPort->setCursor( zoomCursor );
573 \brief Start panning operation.
575 Sets the corresponding cursor for the widget.
577 void OCCViewer_ViewWindow::activatePanning()
579 if ( !transformRequested() && !myCursorIsHand )
580 myCursor = cursor(); // save old cursor
582 if ( myOperation != PANVIEW ) {
583 QCursor panCursor (Qt::SizeAllCursor);
584 if( setTransformRequested ( PANVIEW ) )
585 myViewPort->setCursor( panCursor );
590 \brief Start rotation operation
592 Sets the corresponding cursor for the widget.
594 void OCCViewer_ViewWindow::activateRotation()
596 if ( !transformRequested() && !myCursorIsHand )
597 myCursor = cursor(); // save old cursor
599 if ( myOperation != ROTATE ) {
600 QPixmap rotatePixmap (imageRotateCursor);
601 QCursor rotCursor (rotatePixmap);
602 if( setTransformRequested ( ROTATE ) )
603 myViewPort->setCursor( rotCursor );
608 \brief Compute the gravity center.
609 \param theX used to return X coordinate of the gravity center
610 \param theY used to return Y coordinate of the gravity center
611 \param theZ used to return Z coordinate of the gravity center
612 \return \c true if the gravity center is computed
614 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
616 Handle(V3d_View) aView3d = myViewPort->getView();
618 // Project boundaries points and add to avergae gravity
619 // the ones which lie within the screen limits
620 Standard_Real aScreenLimits[4] = { 0.0, 0.0, 0.0, 0.0 };
622 #if OCC_VERSION_LARGE > 0x06070100
623 // NDC space screen limits
624 aScreenLimits[0] = -1.0;
625 aScreenLimits[1] = 1.0;
626 aScreenLimits[2] = -1.0;
627 aScreenLimits[3] = 1.0;
629 aView3d->View()->ViewMapping().WindowLimit( aScreenLimits[0],
635 Standard_Integer aPointsNb = 0;
637 Standard_Real aXmin = 0.0;
638 Standard_Real aYmin = 0.0;
639 Standard_Real aZmin = 0.0;
640 Standard_Real aXmax = 0.0;
641 Standard_Real aYmax = 0.0;
642 Standard_Real aZmax = 0.0;
644 Graphic3d_MapOfStructure aSetOfStructures;
645 aView3d->View()->DisplayedStructures( aSetOfStructures );
646 Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures );
648 for( ; aStructureIt.More(); aStructureIt.Next() ) {
649 const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key();
650 if ( aStructure->IsEmpty() ) {
654 aStructure->MinMaxValues( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
656 // Infinite structures are skipped
657 Standard_Real aLIM = ShortRealLast() - 1.0;
658 if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
659 || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
663 gp_Pnt aPoints[8] = {
664 gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
665 gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
666 gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
667 gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
670 for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
671 const gp_Pnt& aBBPoint = aPoints[aPointIt];
673 #if OCC_VERSION_LARGE > 0x06070100
674 gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
675 const Standard_Real& U = aProjected.X();
676 const Standard_Real& V = aProjected.Y();
678 Standard_Real U = 0.0;
679 Standard_Real V = 0.0;
680 Standard_Real W = 0.0;
681 aView3d->View()->Projects( aBBPoint.X(), aBBPoint.Y(), aBBPoint.Z(), U, V, W );
684 if (U >= aScreenLimits[0]
685 && U <= aScreenLimits[1]
686 && V >= aScreenLimits[2]
687 && V <= aScreenLimits[3])
690 theX += aBBPoint.X();
691 theY += aBBPoint.Y();
692 theZ += aBBPoint.Z();
707 \brief Set the gravity center as a rotation point.
709 void OCCViewer_ViewWindow::activateSetRotationGravity()
711 if ( myRotationPointSelection )
713 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
714 ic->CloseAllContexts();
715 myOperation = NOTHING;
716 myViewPort->setCursor( myCursor );
717 myCursorIsHand = false;
718 myRotationPointSelection = false;
721 myPrevPointType = myCurrPointType;
722 myCurrPointType = GRAVITY;
724 Standard_Real Xcenter, Ycenter, Zcenter;
725 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
726 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
730 \brief Update gravity center in the "Set Rotation Point" dialog box.
731 \sa OCCViewer_SetRotationPointDlg class
733 void OCCViewer_ViewWindow::updateGravityCoords()
735 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == GRAVITY )
737 Standard_Real Xcenter, Ycenter, Zcenter;
738 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
739 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
744 \brief Set the point selected by the user as a rotation point.
745 \param theX X coordinate of the rotation point
746 \param theY Y coordinate of the rotation point
747 \param theZ Z coordinate of the rotation point
749 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
751 if ( myRotationPointSelection )
753 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
754 ic->CloseAllContexts();
755 myOperation = NOTHING;
756 myViewPort->setCursor( myCursor );
757 myCursorIsHand = false;
758 myRotationPointSelection = false;
761 myPrevPointType = myCurrPointType;
762 myCurrPointType = SELECTED;
763 mySelectedPoint.SetCoord(theX,theY,theZ);
767 \brief Start the shape selection process.
769 void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
771 myPrevPointType = myCurrPointType;
772 myCurrPointType = SELECTED;
774 // activate selection ------>
775 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
777 ic->OpenLocalContext();
779 AIS_ListOfInteractive aList;
780 ic->DisplayedObjects( aList );
781 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
783 Handle(AIS_InteractiveObject) anObj = it.Value();
784 if ( !anObj.IsNull() && anObj->HasPresentation() &&
785 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
788 ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
791 // activate selection <------
793 if ( !myCursorIsHand )
795 QCursor handCursor (Qt::PointingHandCursor);
796 myCursorIsHand = true;
798 myViewPort->setCursor( handCursor );
800 myRotationPointSelection = true;
804 \brief Start global panning operation
806 Sets the corresponding cursor for the widget.
808 void OCCViewer_ViewWindow::activateGlobalPanning()
810 Handle(V3d_View) aView3d = myViewPort->getView();
811 if ( !aView3d.IsNull() ) {
812 QPixmap globalPanPixmap (imageCrossCursor);
813 QCursor glPanCursor (globalPanPixmap);
814 myCurScale = aView3d->Scale();
815 aView3d->FitAll(0.01, false);
816 myCursor = cursor(); // save old cursor
817 myViewPort->fitAll(); // fits view before selecting a new scene center
818 if( setTransformRequested( PANGLOBAL ) )
819 myViewPort->setCursor( glPanCursor );
824 \brief Starts fit operation.
826 Sets the corresponding cursor for the widget.
828 void OCCViewer_ViewWindow::activateWindowFit()
830 if ( !transformRequested() && !myCursorIsHand )
831 myCursor = cursor(); /* save old cursor */
833 if ( myOperation != WINDOWFIT ) {
834 QCursor handCursor (Qt::PointingHandCursor);
835 if( setTransformRequested ( WINDOWFIT ) )
837 myViewPort->setCursor ( handCursor );
838 myCursorIsHand = true;
844 \brief Start delayed viewer operation.
846 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
848 bool ok = transformEnabled( op );
849 myOperation = ok ? op : NOTHING;
850 myViewPort->setMouseTracking( myOperation == NOTHING );
855 \brief Handle mouse move event.
856 \param theEvent mouse event
858 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
860 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
862 switch ( getButtonState( theEvent, interactionStyle() ) ) {
864 myViewPort->startZoomAtPoint( myStartX, myStartY );
872 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
879 myCurrX = theEvent->x();
880 myCurrY = theEvent->y();
881 switch (myOperation) {
883 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
887 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
893 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
907 if ( myRotationPointSelection || isSketcherStyle() )
909 emit mouseMoving( this, theEvent );
913 int aState = theEvent->modifiers();
914 int aButton = theEvent->buttons();
915 int anInteractionStyle = interactionStyle();
916 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
917 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
918 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
919 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
920 myDrawRect = myEnableDrawMode;
923 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
924 QCursor handCursor (Qt::PointingHandCursor);
925 myCursorIsHand = true;
927 myViewPort->setCursor( handCursor );
930 emit mouseMoving( this, theEvent );
932 else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
933 aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
934 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
935 aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
936 OCCViewer_ViewSketcher* sketcher = 0;
937 QList<OCCViewer_ViewSketcher*>::Iterator it;
938 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
940 OCCViewer_ViewSketcher* sk = (*it);
941 if( sk->isDefault() && sk->sketchButton() == aButton )
944 if ( sketcher && myCurSketch == -1 )
946 activateSketching( sketcher->type() );
949 myCurSketch = mypSketcher->sketchButton();
951 if ( l_mbPressEvent )
953 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
954 delete l_mbPressEvent;
957 QApplication::sendEvent( getViewPort(), theEvent );
962 emit mouseMoving( this, theEvent );
968 \brief Handle mouse release event.
969 \param theEvent mouse event
971 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
973 switch ( myOperation ) {
976 int prevState = myCurSketch;
977 if(theEvent->button() == Qt::RightButton)
979 QList<OCCViewer_ViewSketcher*>::Iterator it;
980 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
982 OCCViewer_ViewSketcher* sk = (*it);
983 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
988 emit mouseReleased(this, theEvent);
989 if(theEvent->button() == Qt::RightButton && prevState == -1)
991 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
992 theEvent->pos(), theEvent->globalPos() );
993 emit contextMenuRequested( &aEvent );
998 myViewPort->endRotation();
1008 if ( theEvent->button() == Qt::LeftButton ) {
1009 myViewPort->setCenter( theEvent->x(), theEvent->y() );
1010 myViewPort->getView()->SetScale(myCurScale);
1016 if ( theEvent->button() == Qt::LeftButton ) {
1017 myCurrX = theEvent->x();
1018 myCurrY = theEvent->y();
1020 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1021 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1028 // NOTE: viewer 3D detects a rectangle of selection using this event
1029 // so we must emit it BEFORE resetting the selection rectangle
1031 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1035 myViewPort->update();
1038 if ( l_mbPressEvent )
1040 delete l_mbPressEvent;
1046 \brief Reset the viewport to its initial state
1047 ( no transformations in process etc. )
1049 void OCCViewer_ViewWindow::resetState()
1053 if ( myRotationPointSelection )
1055 QCursor handCursor (Qt::PointingHandCursor);
1056 myViewPort->setCursor( handCursor );
1060 if ( transformRequested() || myCursorIsHand )
1061 myViewPort->setCursor( myCursor );
1062 myCursorIsHand = false;
1065 if ( transformRequested() )
1066 emit vpTransformationFinished (myOperation);
1068 setTransformInProcess( false );
1069 setTransformRequested( NOTHING );
1074 \brief Draw rubber band rectangle.
1076 void OCCViewer_ViewWindow::drawRect()
1078 if ( !myRectBand ) {
1079 myRectBand = new QtxRectRubberBand( myViewPort );
1081 //palette.setColor(myRectBand->foregroundRole(), Qt::white);
1082 //myRectBand->setPalette(palette);
1084 //myRectBand->hide();
1086 myRectBand->setUpdatesEnabled ( false );
1087 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1088 myRectBand->initGeometry( aRect );
1090 if ( !myRectBand->isVisible() )
1093 myRectBand->setUpdatesEnabled ( true );
1094 //myRectBand->repaint();
1096 //myRectBand->setVisible( aRect.isValid() );
1097 //if ( myRectBand->isVisible() )
1098 // myRectBand->repaint();
1100 // myRectBand->show();
1101 //myRectBand->repaint();
1105 \brief Clear rubber band rectangle on the end on the dragging operation.
1107 void OCCViewer_ViewWindow::endDrawRect()
1109 //delete myRectBand;
1113 myRectBand->clearGeometry();
1119 \brief Create actions.
1121 void OCCViewer_ViewWindow::createActions()
1123 if( !toolMgr()->isEmpty() )
1126 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1131 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1132 tr( "MNU_DUMP_VIEW" ), 0, this);
1133 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1134 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1135 toolMgr()->registerAction( aAction, DumpId );
1138 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1139 tr( "MNU_FITALL" ), 0, this);
1140 aAction->setStatusTip(tr("DSC_FITALL"));
1141 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1142 toolMgr()->registerAction( aAction, FitAllId );
1145 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1146 tr( "MNU_FITRECT" ), 0, this);
1147 aAction->setStatusTip(tr("DSC_FITRECT"));
1148 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1149 toolMgr()->registerAction( aAction, FitRectId );
1152 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1153 tr( "MNU_ZOOM_VIEW" ), 0, this);
1154 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1155 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1156 toolMgr()->registerAction( aAction, ZoomId );
1159 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1160 tr( "MNU_PAN_VIEW" ), 0, this);
1161 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1162 connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
1163 toolMgr()->registerAction( aAction, PanId );
1166 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1167 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1168 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1169 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1170 toolMgr()->registerAction( aAction, GlobalPanId );
1173 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1174 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1175 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1176 mySetRotationPointAction->setCheckable( true );
1177 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1178 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1181 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1182 tr( "MNU_ROTATE_VIEW" ), 0, this);
1183 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1184 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1185 toolMgr()->registerAction( aAction, RotationId );
1188 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1189 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1190 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1191 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1192 this->addAction(aAction);
1193 toolMgr()->registerAction( aAction, FrontId );
1195 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1196 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1197 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1198 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1199 this->addAction(aAction);
1200 toolMgr()->registerAction( aAction, BackId );
1202 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1203 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1204 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1205 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1206 this->addAction(aAction);
1207 toolMgr()->registerAction( aAction, TopId );
1209 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1210 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1211 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1212 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1213 this->addAction(aAction);
1214 toolMgr()->registerAction( aAction, BottomId );
1216 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1217 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1218 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1219 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1220 this->addAction(aAction);
1221 toolMgr()->registerAction( aAction, LeftId );
1223 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1224 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1225 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1226 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1227 this->addAction(aAction);
1228 toolMgr()->registerAction( aAction, RightId );
1230 // rotate anticlockwise
1231 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1232 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1233 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1234 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1235 this->addAction(aAction);
1236 toolMgr()->registerAction( aAction, AntiClockWiseId );
1239 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1240 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1241 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1242 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1243 this->addAction(aAction);
1244 toolMgr()->registerAction( aAction, ClockWiseId );
1247 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1248 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1249 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1250 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1251 this->addAction(aAction);
1252 toolMgr()->registerAction( aAction, ResetId );
1255 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1256 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1257 tr("MNU_CLONE_VIEW"), 0, this);
1258 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1259 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1260 toolMgr()->registerAction( aAction, CloneId );
1262 aAction = new QtxAction (tr ("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr ("ICON_OCCVIEWER_CLIPPING")),
1263 tr ("MNU_CLIPPING"), 0, this);
1264 aAction->setStatusTip (tr ("DSC_CLIPPING"));
1265 aAction->setCheckable (true);
1266 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1267 toolMgr()->registerAction (aAction, ClippingId);
1269 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1270 tr( "MNU_SHOOT_VIEW" ), 0, this);
1271 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1272 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1273 toolMgr()->registerAction( aAction, MemId );
1275 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1276 tr( "MNU_PRESETS_VIEW" ), 0, this);
1277 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1278 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1279 toolMgr()->registerAction( aAction, RestoreId );
1281 if (myModel->trihedronActivated()) {
1282 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1283 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1284 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1285 connect(aAction, SIGNAL(triggered()), this, SLOT(onTrihedronShow()));
1286 toolMgr()->registerAction( aAction, TrihedronShowId );
1290 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1291 tr( "MNU_SCALING" ), 0, this);
1292 aAction->setStatusTip(tr("DSC_SCALING"));
1293 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1294 toolMgr()->registerAction( aAction, AxialScaleId );
1296 // Enable/disable preselection
1297 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1298 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1299 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1300 aAction->setCheckable(true);
1301 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1302 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1304 // Enable/disable selection
1305 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1306 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1307 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1308 aAction->setCheckable(true);
1309 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1310 toolMgr()->registerAction( aAction, SwitchSelectionId );
1313 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1314 tr( "MNU_GRADUATED_AXES" ), 0, this);
1315 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1316 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1317 toolMgr()->registerAction( aAction, GraduatedAxesId );
1319 // Active only ambient light or not
1320 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1321 tr( "MNU_AMBIENT" ), 0, this);
1322 aAction->setStatusTip(tr("DSC_AMBIENT"));
1323 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1324 toolMgr()->registerAction( aAction, AmbientId );
1326 // Switch between interaction styles
1327 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1328 tr( "MNU_STYLE_SWITCH" ), 0, this);
1329 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1330 aAction->setCheckable(true);
1331 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1332 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1334 // Switch between zooming styles
1335 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1336 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1337 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1338 aAction->setCheckable(true);
1339 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1340 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1343 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1344 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1345 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1346 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1347 toolMgr()->registerAction( aAction, MaximizedId );
1349 // Return to 3d view
1350 if (my2dMode!=No2dMode){
1351 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1352 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1353 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1354 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1355 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1359 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1363 \brief Create toolbar.
1365 void OCCViewer_ViewWindow::createToolBar()
1367 QString aToolbarName;
1370 aToolbarName = tr( "LBL_XYTOOLBAR_LABEL" );
1373 aToolbarName = tr( "LBL_XZTOOLBAR_LABEL" );
1376 aToolbarName = tr( "LBL_YZTOOLBAR_LABEL" );
1379 aToolbarName = tr( "LBL_3DTOOLBAR_LABEL" );
1382 int tid = toolMgr()->createToolBar( aToolbarName, false );
1383 if ( my2dMode != No2dMode ){
1384 toolMgr()->append( ReturnTo3dViewId, tid );
1385 toolMgr()->append( toolMgr()->separator(), tid );
1387 toolMgr()->append( DumpId, tid );
1388 toolMgr()->append( SwitchInteractionStyleId, tid );
1389 #if OCC_VERSION_LARGE > 0x0603000A // available only with OCC-6.3-sp11 and higher version
1390 toolMgr()->append( SwitchZoomingStyleId, tid );
1392 toolMgr()->append( SwitchPreselectionId, tid );
1393 toolMgr()->append( SwitchSelectionId, tid );
1394 if( myModel->trihedronActivated() )
1395 toolMgr()->append( TrihedronShowId, tid );
1397 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1398 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1399 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1400 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1401 toolMgr()->append( aScaleAction, tid );
1403 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1404 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1405 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1406 toolMgr()->append( aPanningAction, tid );
1408 if (my2dMode == No2dMode) {
1409 toolMgr()->append( ChangeRotationPointId, tid );
1410 toolMgr()->append( RotationId, tid );
1412 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1413 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1414 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1415 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1416 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1417 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1418 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1419 toolMgr()->append( aViewsAction, tid );
1421 toolMgr()->append( AntiClockWiseId, tid );
1422 toolMgr()->append( ClockWiseId, tid );
1424 toolMgr()->append( ResetId, tid );
1427 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1428 aMemAction->insertAction( toolMgr()->action( MemId ) );
1429 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1430 toolMgr()->append( aMemAction, tid );
1432 toolMgr()->append( toolMgr()->separator(), tid );
1433 toolMgr()->append( CloneId, tid );
1435 toolMgr()->append( toolMgr()->separator(), tid );
1436 toolMgr()->append( ClippingId, tid );
1437 toolMgr()->append( AxialScaleId, tid );
1438 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
1439 toolMgr()->append( GraduatedAxesId, tid );
1441 toolMgr()->append( AmbientId, tid );
1443 toolMgr()->append( MaximizedId, tid );
1444 toolMgr()->append( SynchronizeId, tid );
1448 \brief Perform 'fit all' operation.
1450 void OCCViewer_ViewWindow::onViewFitAll()
1452 myViewPort->fitAll();
1456 \brief Perform "front view" transformation.
1458 void OCCViewer_ViewWindow::onFrontView()
1460 emit vpTransformationStarted ( FRONTVIEW );
1461 Handle(V3d_View) aView3d = myViewPort->getView();
1462 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
1464 emit vpTransformationFinished ( FRONTVIEW );
1468 \brief Perform "back view" transformation.
1470 void OCCViewer_ViewWindow::onBackView()
1472 emit vpTransformationStarted ( BACKVIEW );
1473 Handle(V3d_View) aView3d = myViewPort->getView();
1474 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
1476 emit vpTransformationFinished ( BACKVIEW );
1480 \brief Perform "top view" transformation.
1482 void OCCViewer_ViewWindow::onTopView()
1484 emit vpTransformationStarted ( TOPVIEW );
1485 Handle(V3d_View) aView3d = myViewPort->getView();
1486 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
1488 emit vpTransformationFinished ( TOPVIEW );
1492 \brief Perform "bottom view" transformation.
1494 void OCCViewer_ViewWindow::onBottomView()
1496 emit vpTransformationStarted ( BOTTOMVIEW );
1497 Handle(V3d_View) aView3d = myViewPort->getView();
1498 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
1500 emit vpTransformationFinished ( BOTTOMVIEW );
1504 \brief Perform "left view" transformation.
1506 void OCCViewer_ViewWindow::onLeftView()
1508 emit vpTransformationStarted ( LEFTVIEW );
1509 Handle(V3d_View) aView3d = myViewPort->getView();
1510 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
1512 emit vpTransformationFinished ( LEFTVIEW );
1516 \brief Perform "right view" transformation.
1518 void OCCViewer_ViewWindow::onRightView()
1520 emit vpTransformationStarted ( RIGHTVIEW );
1521 Handle(V3d_View) aView3d = myViewPort->getView();
1522 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
1524 emit vpTransformationFinished ( RIGHTVIEW );
1528 \brief Rotate view 90 degrees clockwise
1530 void OCCViewer_ViewWindow::onClockWiseView()
1532 emit vpTransformationStarted ( CLOCKWISEVIEW );
1533 myViewPort->rotateXY( 90. );
1534 emit vpTransformationFinished ( CLOCKWISEVIEW );
1538 \brief Rotate view 90 degrees conterclockwise
1540 void OCCViewer_ViewWindow::onAntiClockWiseView()
1542 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1543 myViewPort->rotateXY( -90. );
1544 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1548 \brief Perform "reset view" transformation.
1550 Sets default orientation of the viewport camera.
1552 void OCCViewer_ViewWindow::onResetView()
1554 emit vpTransformationStarted( RESETVIEW );
1555 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1556 myViewPort->getView()->Reset( false );
1557 myViewPort->fitAll( false, true, false );
1558 myViewPort->getView()->SetImmediateUpdate( upd );
1559 myViewPort->getView()->Update();
1560 emit vpTransformationFinished( RESETVIEW );
1564 \brief Perform "fit all" transformation.
1566 void OCCViewer_ViewWindow::onFitAll()
1568 emit vpTransformationStarted( FITALLVIEW );
1569 myViewPort->fitAll();
1570 emit vpTransformationFinished( FITALLVIEW );
1574 \brief Called if 'change rotation point' operation is activated.
1575 \param on action state
1577 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1581 if (!mySetRotationPointDlg)
1583 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1584 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1587 if (!mySetRotationPointDlg->isVisible())
1589 //if (mySetRotationPointDlg->IsFirstShown())
1590 if (myCurrPointType == GRAVITY)
1592 Standard_Real Xcenter, Ycenter, Zcenter;
1593 if (computeGravityCenter(Xcenter, Ycenter, Zcenter))
1594 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1596 mySetRotationPointDlg->show();
1601 if (mySetRotationPointDlg->isVisible())
1602 mySetRotationPointDlg->hide();
1607 \brief Create one more window with same content.
1609 void OCCViewer_ViewWindow::onCloneView()
1611 SUIT_ViewWindow* vw = myManager->createViewWindow();
1613 emit viewCloned( vw );
1617 Creates one more window with same content
1619 void OCCViewer_ViewWindow::onAxialScale()
1621 if ( !myScalingDlg )
1622 myScalingDlg = new OCCViewer_AxialScaleDlg( this );
1624 if ( !myScalingDlg->isVisible() )
1626 myScalingDlg->Update();
1627 myScalingDlg->show();
1632 Shows Graduated Axes dialog
1634 void OCCViewer_ViewWindow::onGraduatedAxes()
1636 myCubeAxesDlg->Update();
1637 myCubeAxesDlg->show();
1640 void OCCViewer_ViewWindow::onAmbientToogle()
1642 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
1643 viewer->InitDefinedLights();
1644 while(viewer->MoreDefinedLights())
1646 Handle(V3d_Light) light = viewer->DefinedLight();
1647 if(light->Type() != V3d_AMBIENT)
1649 Handle(V3d_View) aView3d = myViewPort->getView();
1650 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
1651 else viewer->SetLightOn(light);
1653 viewer->NextDefinedLights();
1659 \brief Store view parameters.
1661 void OCCViewer_ViewWindow::onMemorizeView()
1663 appendViewAspect( getViewParams() );
1667 \brief Restore view parameters.
1669 void OCCViewer_ViewWindow::onRestoreView()
1671 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
1672 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
1674 updateViewAspects( aDlg->parameters() );
1675 if( myRestoreFlag && aDlg->parameters().count() )
1676 performRestoring( aDlg->currentItem() );
1680 \brief Restore view parameters.
1681 \param anItem view parameters
1683 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
1685 Handle(V3d_View) aView3d = myViewPort->getView();
1687 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
1688 aView3d->SetScale( anItem.scale );
1689 aView3d->SetTwist( anItem.twist );
1690 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
1691 aView3d->SetImmediateUpdate( prev );
1692 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1693 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1694 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
1696 #if OCC_VERSION_LARGE > 0x06070100
1697 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
1699 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
1701 // "eye" and "at" require conversion to represent center panning
1702 // up direction is only available after setting angle of twist and
1703 // other view parameters
1704 aView3d->Up( anUpX, anUpY, anUpZ );
1706 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
1707 gp_Dir anUp( anUpX, anUpY, anUpZ );
1708 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
1709 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1710 gp_Dir aSide = aProj ^ anUp;
1712 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
1713 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
1715 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
1716 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1719 aView3d->SetCenter( anItem.centerX, anItem.centerY );
1722 if ( !baseParamsOnly ) {
1724 myModel->setTrihedronShown( anItem.isVisible );
1725 myModel->setTrihedronSize( anItem.size );
1727 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
1728 // graduated trihedron
1729 bool anIsVisible = anItem.gtIsVisible;
1730 OCCViewer_AxisWidget::AxisData anAxisData[3];
1731 anAxisData[0].DrawName = anItem.gtDrawNameX;
1732 anAxisData[1].DrawName = anItem.gtDrawNameZ;
1733 anAxisData[2].DrawName = anItem.gtDrawNameZ;
1734 anAxisData[0].Name = anItem.gtNameX;
1735 anAxisData[1].Name = anItem.gtNameZ;
1736 anAxisData[2].Name = anItem.gtNameZ;
1737 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
1738 anItem.gtNameColorGX,
1739 anItem.gtNameColorBX );
1740 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
1741 anItem.gtNameColorGY,
1742 anItem.gtNameColorBY );
1743 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
1744 anItem.gtNameColorGZ,
1745 anItem.gtNameColorBZ );
1746 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
1747 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
1748 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
1749 anAxisData[0].NbValues = anItem.gtNbValuesX;
1750 anAxisData[1].NbValues = anItem.gtNbValuesY;
1751 anAxisData[2].NbValues = anItem.gtNbValuesZ;
1752 anAxisData[0].Offset = anItem.gtOffsetX;
1753 anAxisData[1].Offset = anItem.gtOffsetY;
1754 anAxisData[2].Offset = anItem.gtOffsetZ;
1755 anAxisData[0].Color = QColor( anItem.gtColorRX,
1758 anAxisData[1].Color = QColor( anItem.gtColorRY,
1761 anAxisData[2].Color = QColor( anItem.gtColorRZ,
1764 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
1765 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
1766 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
1767 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
1768 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
1769 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
1771 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
1772 myCubeAxesDlg->ApplyData( aView3d );
1775 } // if ( !baseParamsOnly )
1781 \brief Set restore flag.
1783 void OCCViewer_ViewWindow::setRestoreFlag()
1789 \brief Called when action "show/hide trihedron" is activated.
1791 void OCCViewer_ViewWindow::onTrihedronShow()
1793 myModel->toggleTrihedron();
1797 \brief Toggles preselection (highlighting) on/off
1799 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
1801 myPreselectionEnabled = on;
1802 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
1804 // unhighlight all highlighted objects
1806 myModel->unHighlightAll( true, false );
1809 // update action state if method is called outside
1810 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
1811 if ( a && a->isChecked() != on ) {
1812 a->setChecked( on );
1817 \brief Toggles selection on/off
1819 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
1821 mySelectionEnabled = on;
1822 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
1824 // update action state if method is called outside
1827 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
1829 a->setEnabled( on );
1833 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
1834 if ( a && a->isChecked() != on ) {
1835 a->setChecked( on );
1840 \brief Switches "keyboard free" interaction style on/off
1842 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
1844 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
1846 // update action state if method is called outside
1847 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
1848 if ( a->isChecked() != on )
1849 a->setChecked( on );
1853 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
1855 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
1857 myViewPort->setAdvancedZoomingEnabled( on );
1859 // update action state if method is called outside
1860 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
1861 if ( a->isChecked() != on )
1862 a->setChecked( on );
1866 \brief Get current interaction style
1867 \return interaction style
1869 int OCCViewer_ViewWindow::interactionStyle() const
1871 return myInteractionStyle;
1875 \brief Set current interaction style
1876 \param theStyle interaction style
1878 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
1880 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
1884 \brief Get current zooming style
1885 \return zooming style
1887 int OCCViewer_ViewWindow::zoomingStyle() const
1889 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
1893 \brief Set current zooming style
1894 \param theStyle zooming style
1896 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
1898 onSwitchZoomingStyle( theStyle == 1 );
1902 \brief Dump view window contents to the pixmap.
1903 \return pixmap containing all scene rendered in the window
1905 QImage OCCViewer_ViewWindow::dumpView()
1907 Handle(V3d_View) view = myViewPort->getView();
1908 if ( view.IsNull() )
1911 int aWidth = myViewPort->width();
1912 int aHeight = myViewPort->height();
1913 QApplication::syncX();
1914 view->Redraw(); // In order to reactivate GL context
1917 OpenGLUtils_FrameBuffer aFrameBuffer;
1918 if( aFrameBuffer.init( aWidth, aHeight ) )
1920 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
1922 glPushAttrib( GL_VIEWPORT_BIT );
1923 glViewport( 0, 0, aWidth, aHeight );
1924 aFrameBuffer.bind();
1929 aFrameBuffer.unbind();
1932 aFrameBuffer.bind();
1933 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
1934 aFrameBuffer.unbind();
1936 anImage = anImage.rgbSwapped();
1937 anImage = anImage.mirrored();
1940 // if frame buffers are unsupported, use old functionality
1943 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
1945 QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
1947 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
1950 QImage anImage( data, aWidth, aHeight, QImage::Format_ARGB32 );
1951 anImage = anImage.mirrored();
1952 anImage = anImage.rgbSwapped();
1956 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
1957 const QString& fileName,
1958 const QString& format )
1960 if ( format != "PS" && format != "EPS")
1961 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
1963 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
1966 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
1967 else if (format == "EPS")
1968 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
1974 QString OCCViewer_ViewWindow::filter() const
1976 return tr( "OCC_IMAGE_FILES" );
1981 \brief Set parameters of the cutting plane
1982 \param on if \c true, cutting plane is enabled
1983 \param x X position of plane point
1984 \param y Y position of plane point
1985 \param z Z position of plane point
1986 \param dx X coordinate of plane normal
1987 \param dy Y coordinate of plane normal
1988 \param dz Z coordinate of plane normal
1990 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
1991 const double dx, const double dy, const double dz )
1993 Handle(V3d_View) view = myViewPort->getView();
1994 if ( view.IsNull() )
1998 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2000 // try to use already existing plane or create a new one
2001 Handle(V3d_Plane) clipPlane;
2003 // calculate new a,b,c,d values for the plane
2004 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2006 pln.Coefficients(a, b, c, d);
2008 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2009 Handle(Graphic3d_ClipPlane) aClipPlane;
2010 if(aPlanes.Size() > 0 ) {
2011 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2012 aClipPlane = anIter.Value();
2013 aClipPlane->SetEquation(pln);
2014 aClipPlane->SetOn(Standard_True);
2016 aClipPlane = new Graphic3d_ClipPlane(pln);
2017 view->AddClipPlane(aClipPlane);
2018 aClipPlane->SetOn(Standard_True);
2022 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2023 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2024 for( ;anIter.More();anIter.Next() ){
2025 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2026 aClipPlane->SetOn(Standard_False);
2034 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2036 gp_Dir aDir = pln.Axis().Direction();
2037 gp_Pnt aPnt = pln.Location();
2038 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2043 \brief Check if any cutting plane is enabled
2044 \return \c true if at least one cutting plane is enabled
2046 bool OCCViewer_ViewWindow::isCuttingPlane()
2048 Handle(V3d_View) view = myViewPort->getView();
2050 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2051 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2052 for( ;anIter.More();anIter.Next() ) {
2053 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2054 if(aClipPlane->IsOn()) {
2063 \brief Get the visual parameters of the view window.
2064 \return visual parameters of view window
2066 viewAspect OCCViewer_ViewWindow::getViewParams() const
2068 double projX, projY, projZ, twist;
2069 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2070 double aScaleX, aScaleY, aScaleZ;
2072 Handle(V3d_View) aView3d = myViewPort->getView();
2074 aView3d->Proj( projX, projY, projZ );
2075 aView3d->At( atX, atY, atZ );
2076 aView3d->Eye( eyeX, eyeY, eyeZ );
2077 twist = aView3d->Twist();
2079 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2081 bool isShown = myModel->isTrihedronVisible();
2082 double size = myModel->trihedronSize();
2084 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2087 params.scale = aView3d->Scale();
2088 params.projX = projX;
2089 params.projY = projY;
2090 params.projZ = projZ;
2091 params.twist = twist;
2098 params.scaleX = aScaleX;
2099 params.scaleY = aScaleY;
2100 params.scaleZ = aScaleZ;
2101 params.name = aName;
2102 params.isVisible= isShown;
2105 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2106 aView3d->Center( params.centerX, params.centerY );
2109 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
2110 // graduated trihedron
2111 bool anIsVisible = false;
2112 OCCViewer_AxisWidget::AxisData anAxisData[3];
2113 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2115 params.gtIsVisible = anIsVisible;
2116 params.gtDrawNameX = anAxisData[0].DrawName;
2117 params.gtDrawNameY = anAxisData[1].DrawName;
2118 params.gtDrawNameZ = anAxisData[2].DrawName;
2119 params.gtNameX = anAxisData[0].Name;
2120 params.gtNameY = anAxisData[1].Name;
2121 params.gtNameZ = anAxisData[2].Name;
2122 params.gtNameColorRX = anAxisData[0].NameColor.red();
2123 params.gtNameColorGX = anAxisData[0].NameColor.green();
2124 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2125 params.gtNameColorRY = anAxisData[1].NameColor.red();
2126 params.gtNameColorGY = anAxisData[1].NameColor.green();
2127 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2128 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2129 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2130 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2131 params.gtDrawValuesX = anAxisData[0].DrawValues;
2132 params.gtDrawValuesY = anAxisData[1].DrawValues;
2133 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2134 params.gtNbValuesX = anAxisData[0].NbValues;
2135 params.gtNbValuesY = anAxisData[1].NbValues;
2136 params.gtNbValuesZ = anAxisData[2].NbValues;
2137 params.gtOffsetX = anAxisData[0].Offset;
2138 params.gtOffsetY = anAxisData[1].Offset;
2139 params.gtOffsetZ = anAxisData[2].Offset;
2140 params.gtColorRX = anAxisData[0].Color.red();
2141 params.gtColorGX = anAxisData[0].Color.green();
2142 params.gtColorBX = anAxisData[0].Color.blue();
2143 params.gtColorRY = anAxisData[1].Color.red();
2144 params.gtColorGY = anAxisData[1].Color.green();
2145 params.gtColorBY = anAxisData[1].Color.blue();
2146 params.gtColorRZ = anAxisData[2].Color.red();
2147 params.gtColorGZ = anAxisData[2].Color.green();
2148 params.gtColorBZ = anAxisData[2].Color.blue();
2149 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2150 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2151 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2152 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2153 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2154 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2161 \brief Get visual parameters of this view window.
2162 \return visual parameters of view window
2164 QString OCCViewer_ViewWindow::getVisualParameters()
2166 viewAspect params = getViewParams();
2170 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2171 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2172 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
2173 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
2175 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2176 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2177 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2178 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2179 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2180 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2181 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2182 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2183 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2184 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2185 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2186 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2187 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2188 data << QString( "isVisible=%1" ).arg( params.isVisible );
2189 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2191 ClipPlanesList aPlanes = myModel->getClipPlanes();
2192 for ( int i=0; i < aPlanes.size(); i++ )
2194 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2195 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2196 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2197 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2198 switch ( aPlane.Mode )
2200 case OCCViewer_ClipPlane::Absolute :
2202 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2204 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2206 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2207 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2208 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2212 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2217 case OCCViewer_ClipPlane::Relative :
2219 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2220 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2221 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2226 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2227 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2228 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2229 data << ClippingPlane;
2233 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 or newer version
2234 // graduated trihedron
2235 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2236 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2237 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2238 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2239 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2240 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2241 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2242 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2243 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2244 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2245 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2246 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2247 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2248 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2249 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2250 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2251 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2252 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2253 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2254 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2255 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2256 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2257 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2258 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2259 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2260 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2261 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2262 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2263 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2264 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2265 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2266 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2267 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2268 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2269 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2270 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2271 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2272 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2273 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2274 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2276 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2277 data << QString( "background=%1" ).arg( bg );
2279 return data.join("*");
2283 \brief Restore visual parameters of the view window.
2284 \param parameters visual parameters of view window
2286 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2289 ClipPlanesList aClipPlanes;
2290 QStringList data = parameters.split( '*' );
2291 Qtx::BackgroundData bgData;
2292 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2294 foreach( QString param, data ) {
2295 QString paramName = param.section( '=', 0, 0 ).trimmed();
2296 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2297 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2298 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2299 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2300 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2301 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2302 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2303 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2304 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2305 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2306 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2307 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2308 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2309 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2310 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2311 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2312 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2313 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2314 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2315 else if ( paramName.contains( "ClippingPlane" ) )
2317 QStringList ClipPlaneData = paramValue.split( ';' );
2318 OCCViewer_ClipPlane aPlane;
2319 foreach( QString ClipPlaneParam, ClipPlaneData )
2321 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2322 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2323 if ( ClipPlane_paramName == "Mode" )
2325 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2327 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2328 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2329 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2330 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2333 switch ( aPlane.Mode )
2335 case OCCViewer_ClipPlane::Absolute :
2336 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2337 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2338 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2339 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2340 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2343 case OCCViewer_ClipPlane::Relative :
2344 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2345 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2346 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2351 aClipPlanes.push_back(aPlane);
2353 // graduated trihedron
2354 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2355 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2356 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2357 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2358 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2359 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2360 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2361 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2362 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2363 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2364 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2365 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2366 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2367 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2368 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2369 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2370 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2371 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2372 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2373 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2374 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2375 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2376 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2377 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2378 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2379 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2380 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2381 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2382 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2383 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2384 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2385 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2386 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2387 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2388 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2389 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2390 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2391 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2392 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2393 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2394 else if ( paramName == "background" ) {
2395 QString bg = paramValue.replace( "$", "=" );
2396 bgData = Qtx::stringToBackground( bg );
2400 else // old format - "1.000e+00*0.000e+00..."
2403 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2404 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2405 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2406 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2407 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2408 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2409 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
2410 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2411 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2412 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
2413 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2414 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2415 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2416 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
2417 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
2418 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
2419 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
2420 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
2422 performRestoring( params );
2423 setBackground( bgData );
2424 myModel->setClipPlanes(aClipPlanes);
2428 \brief Handle show event.
2430 Emits Show() signal.
2432 \param theEvent show event
2434 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2436 emit Show( theEvent );
2440 \brief Handle hide event.
2442 Emits Hide() signal.
2444 \param theEvent hide event
2446 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
2448 emit Hide( theEvent );
2453 Creates default sketcher. [ virtual protected ]
2455 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
2458 return new OCCViewer_RectSketcher( this, type );
2459 if ( type == Polygon )
2460 return new OCCViewer_PolygonSketcher( this, type );
2464 void OCCViewer_ViewWindow::initSketchers()
2466 if ( mySketchers.isEmpty() )
2468 mySketchers.append( createSketcher( Rect ) );
2469 mySketchers.append( createSketcher( Polygon ) );
2473 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
2475 OCCViewer_ViewSketcher* sketcher = 0;
2476 QList<OCCViewer_ViewSketcher*>::Iterator it;
2477 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
2479 OCCViewer_ViewSketcher* sk = (*it);
2480 if ( sk->type() == typ )
2487 Handles requests for sketching in the active view. [ virtual public ]
2489 void OCCViewer_ViewWindow::activateSketching( int type )
2491 OCCViewer_ViewPort3d* vp = getViewPort();
2495 if ( !vp->isSketchingEnabled() )
2498 /* Finish current sketching */
2499 if ( type == NoSketching )
2503 onSketchingFinished();
2504 mypSketcher->deactivate();
2508 /* Activate new sketching */
2511 activateSketching( NoSketching ); /* concurrency not suported */
2512 mypSketcher = getSketcher( type );
2515 mypSketcher->activate();
2516 onSketchingStarted();
2522 Unhilights detected entities. [ virtual protected ]
2524 void OCCViewer_ViewWindow::onSketchingStarted()
2529 Selection by rectangle or polygon. [ virtual protected ]
2531 void OCCViewer_ViewWindow::onSketchingFinished()
2533 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
2534 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
2536 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
2537 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
2538 switch( mypSketcher->type() )
2542 QRect* aRect = (QRect*)mypSketcher->data();
2545 int aLeft = aRect->left();
2546 int aRight = aRect->right();
2547 int aTop = aRect->top();
2548 int aBottom = aRect->bottom();
2552 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2554 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2560 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
2563 int size = aPolygon->size();
2564 TColgp_Array1OfPnt2d anArray( 1, size );
2566 QPolygon::Iterator it = aPolygon->begin();
2567 QPolygon::Iterator itEnd = aPolygon->end();
2568 for( int index = 1; it != itEnd; ++it, index++ )
2570 QPoint aPoint = *it;
2571 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
2575 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
2577 ic->Select( anArray, getViewPort()->getView(), Standard_False );
2585 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
2586 aViewMgr->getOCCViewer()->performSelectionChanged();
2590 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
2595 bool OCCViewer_ViewWindow::transformRequested() const
2597 return ( myOperation != NOTHING );
2600 bool OCCViewer_ViewWindow::transformInProcess() const
2602 return myEventStarted;
2605 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
2607 myEventStarted = bOn;
2611 Set enabled state of transformation (rotate, zoom, etc)
2613 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
2615 if ( id != NOTHING ) myStatus.insert( id, on );
2619 \return enabled state of transformation (rotate, zoom, etc)
2621 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
2623 return myStatus.contains( id ) ? myStatus[ id ] : true;
2626 void OCCViewer_ViewWindow::onMaximizedView()
2628 setMaximized(!isMaximized());
2631 void OCCViewer_ViewWindow::returnTo3dView()
2633 setReturnedTo3dView( true );
2636 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
2638 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
2639 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
2640 if ( !isVisible3dView )
2641 toolMgr()->show( ReturnTo3dViewId );
2643 toolMgr()->hide( ReturnTo3dViewId );
2644 if ( isVisible3dView ) emit returnedTo3d( );
2648 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
2650 QAction* anAction = toolMgr()->action( MaximizedId );
2651 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
2652 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
2654 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
2655 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
2656 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
2657 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
2658 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
2660 emit maximized( this, true );
2664 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
2665 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
2666 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
2667 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
2668 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
2670 emit maximized( this, false );
2675 bool OCCViewer_ViewWindow::isMaximized() const
2677 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
2680 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
2682 IsSketcherStyle = enable;
2685 bool OCCViewer_ViewWindow::isSketcherStyle() const
2687 return IsSketcherStyle;
2691 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
2697 QColor OCCViewer_ViewWindow::backgroundColor() const
2699 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
2703 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
2705 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
2708 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
2710 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
2713 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
2715 if ( myViewPort ) myViewPort->setBackground( theBackground );
2718 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
2720 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
2726 void OCCViewer_ViewWindow::clearViewAspects()
2728 myViewAspects.clear();
2732 \return const reference to list of view aspects
2734 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
2736 return myViewAspects;
2740 Appends new view aspect
2741 \param aParams - new view aspects
2743 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
2745 myViewAspects.append( aParams );
2749 Replaces old view aspects by new ones
2750 \param aViewList - list of new view aspects
2752 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
2754 myViewAspects = aViewList;
2758 Get camera properties for the OCC view window.
2759 \return shared pointer on camera properties.
2761 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
2763 SUIT_CameraProperties aProps;
2765 Handle(V3d_View) aSourceView = getViewPort()->getView();
2766 if ( aSourceView.IsNull() )
2769 if ( get2dMode() == No2dMode ) {
2770 aProps.setDimension( SUIT_CameraProperties::Dim3D );
2773 aProps.setDimension( SUIT_CameraProperties::Dim2D );
2774 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
2777 // read common properites of the view
2778 Standard_Real anUp[3];
2779 Standard_Real anAt[3];
2780 Standard_Real anEye[3];
2781 Standard_Real aProj[3];
2782 Standard_Real anAxialScale[3];
2784 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
2785 aSourceView->At( anAt[0], anAt[1], anAt[2] );
2786 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
2787 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2789 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2790 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
2792 #if OCC_VERSION_LARGE > 0x06070100
2793 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
2795 // store camera properties "as is": it is up to synchronized
2796 // view classes to provide necessary property conversion.
2797 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
2798 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
2800 if ( aSourceView->Camera()->IsOrthographic() )
2802 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
2803 aProps.setViewAngle( 0.0 );
2807 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
2808 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
2810 aProps.setMappingScale( aSourceView->Camera()->Scale() );
2812 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
2814 // generate view orientation matrix for transforming OCC projection reference point
2815 // into a camera (eye) position.
2816 gp_Dir aLeftDir = gp_Dir( anUp[0], anUp[1], anUp[2] ) ^ gp_Dir( aProj[0], aProj[1], aProj[2] );
2819 aTrsf.SetValue( 1, 1, aLeftDir.X() );
2820 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
2821 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
2823 aTrsf.SetValue( 1, 2, anUp[0] );
2824 aTrsf.SetValue( 2, 2, anUp[1] );
2825 aTrsf.SetValue( 3, 2, anUp[2] );
2827 aTrsf.SetValue( 1, 3, aProj[0] );
2828 aTrsf.SetValue( 2, 3, aProj[1] );
2829 aTrsf.SetValue( 3, 3, aProj[2] );
2831 aTrsf.SetValue( 1, 4, anAt[0] );
2832 aTrsf.SetValue( 2, 4, anAt[1] );
2833 aTrsf.SetValue( 3, 4, anAt[2] );
2835 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
2837 // transform to world-space coordinate system
2838 gp_XYZ aPosition( aProjRef.X(), aProjRef.Y(), aCameraDepth );
2839 aTrsf.Transforms( aPosition );
2841 // compute focal point
2842 double aFocalPoint[3];
2844 aFocalPoint[0] = aPosition.X() - aProj[0] * aCameraDepth;
2845 aFocalPoint[1] = aPosition.Y() - aProj[1] * aCameraDepth;
2846 aFocalPoint[2] = aPosition.Z() - aProj[2] * aCameraDepth;
2848 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2849 aProps.setPosition( aPosition.X(), aPosition.Y(), aPosition.Z() );
2851 Standard_Real aViewScale[2];
2852 aSourceView->Size( aViewScale[0], aViewScale[1] );
2853 aProps.setMappingScale( aViewScale[1] );
2861 This implementation synchronizes OCC view's camera propreties.
2863 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
2865 bool blocked = blockSignals( true );
2867 SUIT_CameraProperties aProps = theView->cameraProperties();
2868 if ( !cameraProperties().isCompatible( aProps ) ) {
2869 // other view, this one is being currently synchronized to, seems has become incompatible
2870 // we have to break synchronization
2875 Handle(V3d_View) aDestView = getViewPort()->getView();
2877 aDestView->SetImmediateUpdate( Standard_False );
2880 double aPosition[3];
2881 double aFocalPoint[3];
2882 double anAxialScale[3];
2884 // get common properties
2885 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2886 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
2887 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2888 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2890 #if OCC_VERSION_LARGE > 0x06070100
2891 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2892 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
2893 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2894 aDestView->Camera()->SetScale( aProps.getMappingScale() );
2896 gp_Dir aProjDir( aPosition[0] - aFocalPoint[0],
2897 aPosition[1] - aFocalPoint[1],
2898 aPosition[2] - aFocalPoint[2] );
2900 // get custom view translation
2901 Standard_Real aTranslation[3];
2902 aDestView->At( aTranslation[0], aTranslation[1], aTranslation[2] );
2904 gp_Dir aLeftDir = gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] )
2905 ^ gp_Dir( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
2908 aTrsf.SetValue( 1, 1, aLeftDir.X() );
2909 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
2910 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
2912 aTrsf.SetValue( 1, 2, anUpDir[0] );
2913 aTrsf.SetValue( 2, 2, anUpDir[1] );
2914 aTrsf.SetValue( 3, 2, anUpDir[2] );
2916 aTrsf.SetValue( 1, 3, aProjDir.X() );
2917 aTrsf.SetValue( 2, 3, aProjDir.Y() );
2918 aTrsf.SetValue( 3, 3, aProjDir.Z() );
2920 aTrsf.SetValue( 1, 4, aTranslation[0] );
2921 aTrsf.SetValue( 2, 4, aTranslation[1] );
2922 aTrsf.SetValue( 3, 4, aTranslation[2] );
2925 // transform to view-space coordinate system
2926 gp_XYZ aProjRef( aPosition[0], aPosition[1], aPosition[2] );
2927 aTrsf.Transforms( aProjRef );
2929 // set view camera properties using low-level approach. this is done
2930 // in order to avoid interference with static variables in v3d view used
2931 // when rotation is in process in another view.
2932 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
2933 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
2935 Graphic3d_Vector aMappingProj( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
2936 Graphic3d_Vector aMappingUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2938 aMappingProj.Normalize();
2939 aMappingUp.Normalize();
2941 anOrientation.SetViewReferencePlane( aMappingProj );
2942 anOrientation.SetViewReferenceUp( aMappingUp );
2944 aDestView->SetViewMapping( aMapping );
2945 aDestView->SetViewOrientation( anOrientation );
2948 aDestView->SetCenter( aProjRef.X(), aProjRef.Y() );
2950 // set mapping scale
2951 double aMapScaling = aProps.getMappingScale();
2952 Standard_Real aWidth, aHeight;
2953 aDestView->Size( aWidth, aHeight );
2954 aDestView->SetSize ( aWidth > aHeight ? aMapScaling * (aWidth / aHeight) : aMapScaling );
2957 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2959 aDestView->ZFitAll();
2960 aDestView->SetImmediateUpdate( Standard_True );
2961 aDestView->Redraw();
2963 blockSignals( blocked );
2967 \brief Indicates whether preselection is enabled
2968 \return true if preselection is enabled
2970 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
2972 return myPreselectionEnabled;
2976 \brief Enables/disables preselection
2977 \param theIsToEnable if true - preselection will be enabled
2979 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
2981 onSwitchPreselection( theIsToEnable );
2985 \brief Indicates whether selection is enabled
2986 \return true if selection is enabled
2988 bool OCCViewer_ViewWindow::isSelectionEnabled() const
2990 return mySelectionEnabled;
2994 \brief Enables/disables selection
2995 \param theIsToEnable if true - selection will be enabled
2997 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
2999 onSwitchSelection( theIsToEnable );
3004 \brief called if clipping operation is activated / deactivated.
3006 Enables/disables clipping plane displaying.
3008 \parma on action state
3010 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3012 if(!myModel) return;
3013 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3016 if (!aClippingDlg) {
3017 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3018 myModel->setClippingDlg(aClippingDlg);
3020 if (!aClippingDlg->isVisible())
3021 aClippingDlg->show();
3023 if ( aClippingDlg ) {
3024 aClippingDlg->close();
3025 myModel->setClippingDlg(0);
3029 SUIT_ViewManager* mgr = getViewManager();
3031 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3032 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3033 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3034 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3036 QAction* a = toolMgr()->action( ClippingId );
3038 if(theIsOn != a->isChecked()){
3039 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3040 a->setChecked(theIsOn);
3041 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));