1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : OCCViewer_ViewWindow.cxx
26 #include "OCCViewer_ViewWindow.h"
27 #include "OCCViewer_ViewModel.h"
28 #include "OCCViewer_ViewPort3d.h"
29 #include "OCCViewer_ViewManager.h"
30 #include "OCCViewer_ViewSketcher.h"
31 #include "OCCViewer_CreateRestoreViewDlg.h"
32 #include "OCCViewer_ClipPlane.h"
33 #include "OCCViewer_SetRotationPointDlg.h"
34 #include "OCCViewer_AxialScaleDlg.h"
35 #include "OCCViewer_CubeAxesDlg.h"
36 #include "OCCViewer_ClippingDlg.h"
38 #include <Basics_OCCTVersion.hxx>
40 #include <SUIT_Desktop.h>
41 #include <SUIT_Session.h>
42 #include <SUIT_ViewManager.h>
43 #include <SUIT_Tools.h>
44 #include <SUIT_ResourceMgr.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_Application.h>
48 #include <QtxActionToolMgr.h>
49 #include <QtxMultiAction.h>
50 #include <QtxRubberBand.h>
52 #include <OpenGLUtils_FrameBuffer.h>
58 #include <QMouseEvent>
59 #include <QApplication>
62 #include <AIS_ListOfInteractive.hxx>
63 #include <AIS_ListIteratorOfListOfInteractive.hxx>
64 #include <AIS_Shape.hxx>
66 #include <BRep_Tool.hxx>
67 #include <BRepBndLib.hxx>
68 #include <BRepGProp.hxx>
69 #include <GProp_GProps.hxx>
72 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
73 #include <Graphic3d_MapOfStructure.hxx>
74 #include <Graphic3d_Structure.hxx>
75 #include <Graphic3d_ExportFormat.hxx>
77 #include <Visual3d_View.hxx>
78 #include <V3d_Plane.hxx>
79 #include <V3d_Light.hxx>
83 #include <gp_GTrsf.hxx>
84 #include <TColgp_Array1OfPnt2d.hxx>
86 #include <Graphic3d_SequenceOfHClipPlane.hxx>
87 #include <Graphic3d_ClipPlane.hxx>
89 #include <Image_PixMap.hxx>
91 #include <Standard_Version.hxx>
93 #include "utilities.h"
97 // #include <highgui.h>
99 static QEvent* l_mbPressEvent = 0;
102 # include <QWindowsStyle>
107 const char* imageZoomCursor[] = {
112 "................................",
113 "................................",
114 ".#######........................",
115 "..aaaaaaa.......................",
116 "................................",
117 ".............#####..............",
118 "...........##.aaaa##............",
119 "..........#.aa.....a#...........",
120 ".........#.a.........#..........",
121 ".........#a..........#a.........",
122 "........#.a...........#.........",
123 "........#a............#a........",
124 "........#a............#a........",
125 "........#a............#a........",
126 "........#a............#a........",
127 ".........#...........#.a........",
128 ".........#a..........#a.........",
129 ".........##.........#.a.........",
130 "........#####.....##.a..........",
131 ".......###aaa#####.aa...........",
132 "......###aa...aaaaa.......#.....",
133 ".....###aa................#a....",
134 "....###aa.................#a....",
135 "...###aa...............#######..",
136 "....#aa.................aa#aaaa.",
137 ".....a....................#a....",
138 "..........................#a....",
139 "...........................a....",
140 "................................",
141 "................................",
142 "................................",
143 "................................"};
145 const char* imageRotateCursor[] = {
150 "................................",
151 "................................",
152 "................................",
153 "................................",
154 "........#.......................",
155 ".......#.a......................",
156 "......#######...................",
157 ".......#aaaaa#####..............",
158 "........#..##.a#aa##........##..",
159 ".........a#.aa..#..a#.....##.aa.",
160 ".........#.a.....#...#..##.aa...",
161 ".........#a.......#..###.aa.....",
162 "........#.a.......#a..#aa.......",
163 "........#a.........#..#a........",
164 "........#a.........#a.#a........",
165 "........#a.........#a.#a........",
166 "........#a.........#a.#a........",
167 ".........#.........#a#.a........",
168 "........##a........#a#a.........",
169 "......##.a#.......#.#.a.........",
170 "....##.aa..##.....##.a..........",
171 "..##.aa.....a#####.aa...........",
172 "...aa.........aaa#a.............",
173 "................#.a.............",
174 "...............#.a..............",
175 "..............#.a...............",
176 "...............a................",
177 "................................",
178 "................................",
179 "................................",
180 "................................",
181 "................................"};
183 const char* imageCrossCursor[] = {
188 "................................",
189 "................................",
190 "................................",
191 "................................",
192 "................................",
193 "................................",
194 "................................",
195 "...............#................",
196 "...............#a...............",
197 "...............#a...............",
198 "...............#a...............",
199 "...............#a...............",
200 "...............#a...............",
201 "...............#a...............",
202 "...............#a...............",
203 ".......#################........",
204 "........aaaaaaa#aaaaaaaaa.......",
205 "...............#a...............",
206 "...............#a...............",
207 "...............#a...............",
208 "...............#a...............",
209 "...............#a...............",
210 "...............#a...............",
211 "...............#a...............",
212 "................a...............",
213 "................................",
214 "................................",
215 "................................",
216 "................................",
217 "................................",
218 "................................",
219 "................................"};
224 \param theDesktop main window of application
225 \param theModel OCC 3D viewer
227 OCCViewer_ViewWindow::OCCViewer_ViewWindow( SUIT_Desktop* theDesktop,
228 OCCViewer_Viewer* theModel )
229 : SUIT_ViewWindow( theDesktop )
233 myEnableDrawMode = false;
235 updateEnabledDrawMode();
237 mySetRotationPointDlg = 0;
240 IsSketcherStyle = false;
247 myInteractionStyle = SUIT_ViewModel::STANDARD;
248 myPreselectionEnabled = true;
249 mySelectionEnabled = true;
259 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
262 qDeleteAll( mySketchers );
266 \brief Internal initialization.
268 void OCCViewer_ViewWindow::initLayout()
270 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
271 myViewPort->installEventFilter(this);
272 setCentralWidget(myViewPort);
273 myOperation = NOTHING;
275 myCurrPointType = GRAVITY;
276 myPrevPointType = GRAVITY;
277 mySelectedPoint = gp_Pnt(0.,0.,0.);
278 myRotationPointSelection = false;
280 setTransformRequested ( NOTHING );
281 setTransformInProcess ( false );
298 // Graduated axes dialog
299 QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
300 myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
301 myCubeAxesDlg->initialize();
303 connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
306 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
308 return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
312 \brief Detect viewer operation according the the mouse button pressed
313 and key modifiers used.
314 \param theEvent mouse event
315 \return type of the operation
317 OCCViewer_ViewWindow::OperationType
318 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
320 OperationType aOp = NOTHING;
321 SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
322 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
323 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
325 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
326 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
328 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
329 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
330 (my2dMode == No2dMode))
337 \brief Customize event handling
338 \param watched event receiver object
340 \return \c true if the event processing should be stopped
342 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
344 if ( watched == myViewPort ) {
345 int aType = e->type();
347 case QEvent::MouseButtonPress:
348 vpMousePressEvent((QMouseEvent*) e);
351 case QEvent::MouseButtonRelease:
352 vpMouseReleaseEvent((QMouseEvent*) e);
355 case QEvent::MouseMove:
356 vpMouseMoveEvent((QMouseEvent*) e);
359 case QEvent::MouseButtonDblClick:
360 emit mouseDoubleClicked(this, (QMouseEvent*)e);
365 QWheelEvent* aEvent = (QWheelEvent*) e;
366 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
367 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
370 int x1 = (int)( aEvent->x() + width()*delta/100 );
371 int y1 = (int)( aEvent->y() + height()*delta/100 );
372 myViewPort->zoom( x, y, x1, y1 );
373 myViewPort->getView()->ZFitAll();
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();
1004 myViewPort->getView()->ZFitAll();
1009 if ( theEvent->button() == Qt::LeftButton ) {
1010 myViewPort->setCenter( theEvent->x(), theEvent->y() );
1011 myViewPort->getView()->SetScale(myCurScale);
1017 if ( theEvent->button() == Qt::LeftButton ) {
1018 myCurrX = theEvent->x();
1019 myCurrY = theEvent->y();
1021 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1022 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1029 // NOTE: viewer 3D detects a rectangle of selection using this event
1030 // so we must emit it BEFORE resetting the selection rectangle
1032 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1036 myViewPort->update();
1039 if ( l_mbPressEvent )
1041 delete l_mbPressEvent;
1047 \brief Reset the viewport to its initial state
1048 ( no transformations in process etc. )
1050 void OCCViewer_ViewWindow::resetState()
1054 if ( myRotationPointSelection )
1056 QCursor handCursor (Qt::PointingHandCursor);
1057 myViewPort->setCursor( handCursor );
1061 if ( transformRequested() || myCursorIsHand )
1062 myViewPort->setCursor( myCursor );
1063 myCursorIsHand = false;
1066 if ( transformRequested() )
1067 emit vpTransformationFinished (myOperation);
1069 setTransformInProcess( false );
1070 setTransformRequested( NOTHING );
1075 \brief Draw rubber band rectangle.
1077 void OCCViewer_ViewWindow::drawRect()
1079 if ( !myRectBand ) {
1080 myRectBand = new QtxRectRubberBand( myViewPort );
1082 //palette.setColor(myRectBand->foregroundRole(), Qt::white);
1083 //myRectBand->setPalette(palette);
1085 //myRectBand->hide();
1087 myRectBand->setUpdatesEnabled ( false );
1088 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1089 myRectBand->initGeometry( aRect );
1091 if ( !myRectBand->isVisible() )
1094 myRectBand->setUpdatesEnabled ( true );
1095 //myRectBand->repaint();
1097 //myRectBand->setVisible( aRect.isValid() );
1098 //if ( myRectBand->isVisible() )
1099 // myRectBand->repaint();
1101 // myRectBand->show();
1102 //myRectBand->repaint();
1106 \brief Clear rubber band rectangle on the end on the dragging operation.
1108 void OCCViewer_ViewWindow::endDrawRect()
1110 //delete myRectBand;
1114 myRectBand->clearGeometry();
1120 \brief Create actions.
1122 void OCCViewer_ViewWindow::createActions()
1124 if( !toolMgr()->isEmpty() )
1127 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1132 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1133 tr( "MNU_DUMP_VIEW" ), 0, this);
1134 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1135 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1136 toolMgr()->registerAction( aAction, DumpId );
1139 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1140 tr( "MNU_FITALL" ), 0, this);
1141 aAction->setStatusTip(tr("DSC_FITALL"));
1142 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1143 toolMgr()->registerAction( aAction, FitAllId );
1146 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1147 tr( "MNU_FITRECT" ), 0, this);
1148 aAction->setStatusTip(tr("DSC_FITRECT"));
1149 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1150 toolMgr()->registerAction( aAction, FitRectId );
1153 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1154 tr( "MNU_ZOOM_VIEW" ), 0, this);
1155 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1156 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1157 toolMgr()->registerAction( aAction, ZoomId );
1160 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1161 tr( "MNU_PAN_VIEW" ), 0, this);
1162 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1163 connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
1164 toolMgr()->registerAction( aAction, PanId );
1167 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1168 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1169 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1170 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1171 toolMgr()->registerAction( aAction, GlobalPanId );
1174 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1175 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1176 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1177 mySetRotationPointAction->setCheckable( true );
1178 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1179 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1182 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1183 tr( "MNU_ROTATE_VIEW" ), 0, this);
1184 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1185 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1186 toolMgr()->registerAction( aAction, RotationId );
1189 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1190 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1191 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1192 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1193 this->addAction(aAction);
1194 toolMgr()->registerAction( aAction, FrontId );
1196 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1197 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1198 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1199 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1200 this->addAction(aAction);
1201 toolMgr()->registerAction( aAction, BackId );
1203 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1204 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1205 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1206 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1207 this->addAction(aAction);
1208 toolMgr()->registerAction( aAction, TopId );
1210 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1211 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1212 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1213 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1214 this->addAction(aAction);
1215 toolMgr()->registerAction( aAction, BottomId );
1217 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1218 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1219 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1220 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1221 this->addAction(aAction);
1222 toolMgr()->registerAction( aAction, LeftId );
1224 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1225 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1226 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1227 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1228 this->addAction(aAction);
1229 toolMgr()->registerAction( aAction, RightId );
1231 // rotate anticlockwise
1232 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1233 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1234 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1235 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1236 this->addAction(aAction);
1237 toolMgr()->registerAction( aAction, AntiClockWiseId );
1240 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1241 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1242 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1243 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1244 this->addAction(aAction);
1245 toolMgr()->registerAction( aAction, ClockWiseId );
1248 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1249 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1250 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1251 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1252 this->addAction(aAction);
1253 toolMgr()->registerAction( aAction, ResetId );
1256 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1257 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1258 tr("MNU_CLONE_VIEW"), 0, this);
1259 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1260 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1261 toolMgr()->registerAction( aAction, CloneId );
1263 aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
1264 tr("MNU_CLIPPING"), 0, this);
1265 aAction->setStatusTip (tr("DSC_CLIPPING"));
1266 aAction->setCheckable (true);
1267 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1268 toolMgr()->registerAction (aAction, ClippingId);
1270 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1271 tr( "MNU_SHOOT_VIEW" ), 0, this);
1272 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1273 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1274 toolMgr()->registerAction( aAction, MemId );
1276 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1277 tr( "MNU_PRESETS_VIEW" ), 0, this);
1278 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1279 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1280 toolMgr()->registerAction( aAction, RestoreId );
1282 if (myModel->trihedronActivated()) {
1283 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1284 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1285 aAction->setCheckable( true );
1286 aAction->setChecked( true );
1287 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1288 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1289 toolMgr()->registerAction( aAction, TrihedronShowId );
1293 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1294 tr( "MNU_SCALING" ), 0, this);
1295 aAction->setStatusTip(tr("DSC_SCALING"));
1296 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1297 toolMgr()->registerAction( aAction, AxialScaleId );
1299 // Enable/disable preselection
1300 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1301 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1302 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1303 aAction->setCheckable(true);
1304 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1305 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1307 // Enable/disable selection
1308 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1309 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1310 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1311 aAction->setCheckable(true);
1312 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1313 toolMgr()->registerAction( aAction, SwitchSelectionId );
1316 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1317 tr( "MNU_GRADUATED_AXES" ), 0, this);
1318 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1319 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1320 toolMgr()->registerAction( aAction, GraduatedAxesId );
1322 // Active only ambient light or not
1323 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1324 tr( "MNU_AMBIENT" ), 0, this);
1325 aAction->setStatusTip(tr("DSC_AMBIENT"));
1326 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1327 toolMgr()->registerAction( aAction, AmbientId );
1329 // Switch between interaction styles
1330 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1331 tr( "MNU_STYLE_SWITCH" ), 0, this);
1332 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1333 aAction->setCheckable(true);
1334 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1335 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1337 // Switch between zooming styles
1338 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1339 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1340 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1341 aAction->setCheckable(true);
1342 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1343 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1346 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1347 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1348 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1349 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1350 toolMgr()->registerAction( aAction, MaximizedId );
1352 // Return to 3d view
1353 if (my2dMode!=No2dMode){
1354 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1355 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1356 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1357 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1358 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1362 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1366 \brief Create toolbar.
1368 void OCCViewer_ViewWindow::createToolBar()
1370 static const char* titles[] = {
1371 "LBL_3DTOOLBAR_LABEL",
1372 "LBL_XYTOOLBAR_LABEL",
1373 "LBL_XZTOOLBAR_LABEL",
1374 "LBL_YZTOOLBAR_LABEL",
1376 static const char* names[] = {
1377 "OCCViewer3DViewOperations",
1378 "OCCViewerXYViewOperations",
1379 "OCCViewerXZViewOperations",
1380 "OCCViewerYZViewOperations",
1382 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1383 QString( names[my2dMode] ), // name (language-independant)
1384 false ); // disable floatable toolbar
1385 if ( my2dMode != No2dMode ){
1386 toolMgr()->append( ReturnTo3dViewId, tid );
1387 toolMgr()->append( toolMgr()->separator(), tid );
1389 toolMgr()->append( DumpId, tid );
1390 toolMgr()->append( SwitchInteractionStyleId, tid );
1391 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 toolMgr()->append( GraduatedAxesId, tid );
1439 toolMgr()->append( AmbientId, tid );
1441 toolMgr()->append( MaximizedId, tid );
1442 toolMgr()->append( SynchronizeId, tid );
1446 \brief Perform 'fit all' operation.
1448 void OCCViewer_ViewWindow::onViewFitAll()
1450 myViewPort->fitAll();
1454 \brief Perform "front view" transformation.
1456 void OCCViewer_ViewWindow::onFrontView()
1458 emit vpTransformationStarted ( FRONTVIEW );
1459 Handle(V3d_View) aView3d = myViewPort->getView();
1460 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
1462 emit vpTransformationFinished ( FRONTVIEW );
1466 \brief Perform "back view" transformation.
1468 void OCCViewer_ViewWindow::onBackView()
1470 emit vpTransformationStarted ( BACKVIEW );
1471 Handle(V3d_View) aView3d = myViewPort->getView();
1472 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
1474 emit vpTransformationFinished ( BACKVIEW );
1478 \brief Perform "top view" transformation.
1480 void OCCViewer_ViewWindow::onTopView()
1482 emit vpTransformationStarted ( TOPVIEW );
1483 Handle(V3d_View) aView3d = myViewPort->getView();
1484 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
1486 emit vpTransformationFinished ( TOPVIEW );
1490 \brief Perform "bottom view" transformation.
1492 void OCCViewer_ViewWindow::onBottomView()
1494 emit vpTransformationStarted ( BOTTOMVIEW );
1495 Handle(V3d_View) aView3d = myViewPort->getView();
1496 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
1498 emit vpTransformationFinished ( BOTTOMVIEW );
1502 \brief Perform "left view" transformation.
1504 void OCCViewer_ViewWindow::onLeftView()
1506 emit vpTransformationStarted ( LEFTVIEW );
1507 Handle(V3d_View) aView3d = myViewPort->getView();
1508 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
1510 emit vpTransformationFinished ( LEFTVIEW );
1514 \brief Perform "right view" transformation.
1516 void OCCViewer_ViewWindow::onRightView()
1518 emit vpTransformationStarted ( RIGHTVIEW );
1519 Handle(V3d_View) aView3d = myViewPort->getView();
1520 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
1522 emit vpTransformationFinished ( RIGHTVIEW );
1526 \brief Rotate view 90 degrees clockwise
1528 void OCCViewer_ViewWindow::onClockWiseView()
1530 emit vpTransformationStarted ( CLOCKWISEVIEW );
1531 myViewPort->rotateXY( 90. );
1532 emit vpTransformationFinished ( CLOCKWISEVIEW );
1536 \brief Rotate view 90 degrees conterclockwise
1538 void OCCViewer_ViewWindow::onAntiClockWiseView()
1540 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1541 myViewPort->rotateXY( -90. );
1542 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1546 \brief Perform "reset view" transformation.
1548 Sets default orientation of the viewport camera.
1550 void OCCViewer_ViewWindow::onResetView()
1552 emit vpTransformationStarted( RESETVIEW );
1553 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1554 myViewPort->getView()->Reset( false );
1555 myViewPort->fitAll( false, true, false );
1556 myViewPort->getView()->SetImmediateUpdate( upd );
1557 myViewPort->getView()->Update();
1558 emit vpTransformationFinished( RESETVIEW );
1562 \brief Perform "fit all" transformation.
1564 void OCCViewer_ViewWindow::onFitAll()
1566 emit vpTransformationStarted( FITALLVIEW );
1567 myViewPort->fitAll();
1568 emit vpTransformationFinished( FITALLVIEW );
1572 \brief Called if 'change rotation point' operation is activated.
1573 \param on action state
1575 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1579 if (!mySetRotationPointDlg)
1581 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1582 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1585 if (!mySetRotationPointDlg->isVisible())
1587 //if (mySetRotationPointDlg->IsFirstShown())
1588 if (myCurrPointType == GRAVITY)
1590 Standard_Real Xcenter, Ycenter, Zcenter;
1591 if (computeGravityCenter(Xcenter, Ycenter, Zcenter))
1592 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1594 mySetRotationPointDlg->show();
1599 if (mySetRotationPointDlg->isVisible())
1600 mySetRotationPointDlg->hide();
1605 \brief Create one more window with same content.
1607 void OCCViewer_ViewWindow::onCloneView()
1609 SUIT_ViewWindow* vw = myManager->createViewWindow();
1611 emit viewCloned( vw );
1615 Creates one more window with same content
1617 void OCCViewer_ViewWindow::onAxialScale()
1619 if ( !myScalingDlg )
1620 myScalingDlg = new OCCViewer_AxialScaleDlg( this );
1622 if ( !myScalingDlg->isVisible() )
1624 myScalingDlg->Update();
1625 myScalingDlg->show();
1630 Shows Graduated Axes dialog
1632 void OCCViewer_ViewWindow::onGraduatedAxes()
1634 myCubeAxesDlg->Update();
1635 myCubeAxesDlg->show();
1638 void OCCViewer_ViewWindow::onAmbientToogle()
1640 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
1641 viewer->InitDefinedLights();
1642 while(viewer->MoreDefinedLights())
1644 Handle(V3d_Light) light = viewer->DefinedLight();
1645 if(light->Type() != V3d_AMBIENT)
1647 Handle(V3d_View) aView3d = myViewPort->getView();
1648 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
1649 else viewer->SetLightOn(light);
1651 viewer->NextDefinedLights();
1657 \brief Store view parameters.
1659 void OCCViewer_ViewWindow::onMemorizeView()
1661 appendViewAspect( getViewParams() );
1665 \brief Restore view parameters.
1667 void OCCViewer_ViewWindow::onRestoreView()
1669 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
1670 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
1672 updateViewAspects( aDlg->parameters() );
1673 if( myRestoreFlag && aDlg->parameters().count() )
1674 performRestoring( aDlg->currentItem() );
1678 \brief Restore view parameters.
1679 \param anItem view parameters
1681 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
1683 Handle(V3d_View) aView3d = myViewPort->getView();
1685 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
1686 aView3d->SetScale( anItem.scale );
1687 aView3d->SetTwist( anItem.twist );
1688 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
1689 aView3d->SetImmediateUpdate( prev );
1690 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1691 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1692 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
1694 #if OCC_VERSION_LARGE > 0x06070100
1695 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
1697 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
1699 // "eye" and "at" require conversion to represent center panning
1700 // up direction is only available after setting angle of twist and
1701 // other view parameters
1702 aView3d->Up( anUpX, anUpY, anUpZ );
1704 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
1705 gp_Dir anUp( anUpX, anUpY, anUpZ );
1706 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
1707 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1708 gp_Dir aSide = aProj ^ anUp;
1710 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
1711 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
1713 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
1714 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1717 aView3d->SetCenter( anItem.centerX, anItem.centerY );
1720 if ( !baseParamsOnly ) {
1722 myModel->setTrihedronShown( anItem.isVisible );
1723 myModel->setTrihedronSize( anItem.size );
1725 // graduated trihedron
1726 bool anIsVisible = anItem.gtIsVisible;
1727 OCCViewer_AxisWidget::AxisData anAxisData[3];
1728 anAxisData[0].DrawName = anItem.gtDrawNameX;
1729 anAxisData[1].DrawName = anItem.gtDrawNameZ;
1730 anAxisData[2].DrawName = anItem.gtDrawNameZ;
1731 anAxisData[0].Name = anItem.gtNameX;
1732 anAxisData[1].Name = anItem.gtNameZ;
1733 anAxisData[2].Name = anItem.gtNameZ;
1734 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
1735 anItem.gtNameColorGX,
1736 anItem.gtNameColorBX );
1737 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
1738 anItem.gtNameColorGY,
1739 anItem.gtNameColorBY );
1740 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
1741 anItem.gtNameColorGZ,
1742 anItem.gtNameColorBZ );
1743 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
1744 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
1745 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
1746 anAxisData[0].NbValues = anItem.gtNbValuesX;
1747 anAxisData[1].NbValues = anItem.gtNbValuesY;
1748 anAxisData[2].NbValues = anItem.gtNbValuesZ;
1749 anAxisData[0].Offset = anItem.gtOffsetX;
1750 anAxisData[1].Offset = anItem.gtOffsetY;
1751 anAxisData[2].Offset = anItem.gtOffsetZ;
1752 anAxisData[0].Color = QColor( anItem.gtColorRX,
1755 anAxisData[1].Color = QColor( anItem.gtColorRY,
1758 anAxisData[2].Color = QColor( anItem.gtColorRZ,
1761 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
1762 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
1763 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
1764 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
1765 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
1766 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
1768 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
1769 myCubeAxesDlg->ApplyData( aView3d );
1771 } // if ( !baseParamsOnly )
1777 \brief Set restore flag.
1779 void OCCViewer_ViewWindow::setRestoreFlag()
1785 \brief Called when action "show/hide trihedron" is activated.
1787 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
1789 myModel->setTrihedronShown(show);
1793 \brief Toggles preselection (highlighting) on/off
1795 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
1797 myPreselectionEnabled = on;
1798 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
1800 // unhighlight all highlighted objects
1802 myModel->unHighlightAll( true, false );
1805 // update action state if method is called outside
1806 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
1807 if ( a && a->isChecked() != on ) {
1808 a->setChecked( on );
1813 \brief Toggles selection on/off
1815 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
1817 mySelectionEnabled = on;
1818 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
1820 // update action state if method is called outside
1823 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
1825 a->setEnabled( on );
1829 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
1830 if ( a && a->isChecked() != on ) {
1831 a->setChecked( on );
1836 \brief Switches "keyboard free" interaction style on/off
1838 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
1840 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
1842 // update action state if method is called outside
1843 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
1844 if ( a->isChecked() != on )
1845 a->setChecked( on );
1849 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
1851 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
1853 myViewPort->setAdvancedZoomingEnabled( on );
1855 // update action state if method is called outside
1856 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
1857 if ( a->isChecked() != on )
1858 a->setChecked( on );
1862 \brief Get current interaction style
1863 \return interaction style
1865 int OCCViewer_ViewWindow::interactionStyle() const
1867 return myInteractionStyle;
1871 \brief Set current interaction style
1872 \param theStyle interaction style
1874 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
1876 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
1880 \brief Get current zooming style
1881 \return zooming style
1883 int OCCViewer_ViewWindow::zoomingStyle() const
1885 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
1889 \brief Set current zooming style
1890 \param theStyle zooming style
1892 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
1894 onSwitchZoomingStyle( theStyle == 1 );
1898 \brief Dump view window contents to the pixmap.
1899 \return pixmap containing all scene rendered in the window
1901 QImage OCCViewer_ViewWindow::dumpView()
1903 Handle(V3d_View) view = myViewPort->getView();
1904 if ( view.IsNull() )
1907 int aWidth = myViewPort->width();
1908 int aHeight = myViewPort->height();
1910 // rnv: An old approach to dump the OCCViewer content
1911 // Now used OCCT built-in procedure.
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,
1952 view->ToPixMap(aPix,aWidth, aHeight,Graphic3d_BT_RGBA);
1954 QImage anImage( aPix.Data(), aWidth, aHeight, QImage::Format_ARGB32 );
1955 anImage = anImage.mirrored();
1959 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
1960 const QString& fileName,
1961 const QString& format )
1963 if ( format != "PS" && format != "EPS")
1964 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
1966 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
1969 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
1970 else if (format == "EPS")
1971 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
1977 QString OCCViewer_ViewWindow::filter() const
1979 return tr( "OCC_IMAGE_FILES" );
1984 \brief Set parameters of the cutting plane
1985 \param on if \c true, cutting plane is enabled
1986 \param x X position of plane point
1987 \param y Y position of plane point
1988 \param z Z position of plane point
1989 \param dx X coordinate of plane normal
1990 \param dy Y coordinate of plane normal
1991 \param dz Z coordinate of plane normal
1993 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
1994 const double dx, const double dy, const double dz )
1996 Handle(V3d_View) view = myViewPort->getView();
1997 if ( view.IsNull() )
2001 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2003 // try to use already existing plane or create a new one
2004 Handle(V3d_Plane) clipPlane;
2006 // calculate new a,b,c,d values for the plane
2007 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2009 pln.Coefficients(a, b, c, d);
2011 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2012 if(aPlanes.Size() > 0 ) {
2013 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2014 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2015 aClipPlane->SetEquation(pln);
2016 aClipPlane->SetOn(Standard_True);
2018 view->AddClipPlane( myModel->createClipPlane( pln, 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 // graduated trihedron
2110 bool anIsVisible = false;
2111 OCCViewer_AxisWidget::AxisData anAxisData[3];
2112 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2114 params.gtIsVisible = anIsVisible;
2115 params.gtDrawNameX = anAxisData[0].DrawName;
2116 params.gtDrawNameY = anAxisData[1].DrawName;
2117 params.gtDrawNameZ = anAxisData[2].DrawName;
2118 params.gtNameX = anAxisData[0].Name;
2119 params.gtNameY = anAxisData[1].Name;
2120 params.gtNameZ = anAxisData[2].Name;
2121 params.gtNameColorRX = anAxisData[0].NameColor.red();
2122 params.gtNameColorGX = anAxisData[0].NameColor.green();
2123 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2124 params.gtNameColorRY = anAxisData[1].NameColor.red();
2125 params.gtNameColorGY = anAxisData[1].NameColor.green();
2126 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2127 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2128 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2129 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2130 params.gtDrawValuesX = anAxisData[0].DrawValues;
2131 params.gtDrawValuesY = anAxisData[1].DrawValues;
2132 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2133 params.gtNbValuesX = anAxisData[0].NbValues;
2134 params.gtNbValuesY = anAxisData[1].NbValues;
2135 params.gtNbValuesZ = anAxisData[2].NbValues;
2136 params.gtOffsetX = anAxisData[0].Offset;
2137 params.gtOffsetY = anAxisData[1].Offset;
2138 params.gtOffsetZ = anAxisData[2].Offset;
2139 params.gtColorRX = anAxisData[0].Color.red();
2140 params.gtColorGX = anAxisData[0].Color.green();
2141 params.gtColorBX = anAxisData[0].Color.blue();
2142 params.gtColorRY = anAxisData[1].Color.red();
2143 params.gtColorGY = anAxisData[1].Color.green();
2144 params.gtColorBY = anAxisData[1].Color.blue();
2145 params.gtColorRZ = anAxisData[2].Color.red();
2146 params.gtColorGZ = anAxisData[2].Color.green();
2147 params.gtColorBZ = anAxisData[2].Color.blue();
2148 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2149 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2150 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2151 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2152 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2153 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2159 \brief Get visual parameters of this view window.
2160 \return visual parameters of view window
2162 QString OCCViewer_ViewWindow::getVisualParameters()
2164 viewAspect params = getViewParams();
2168 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2169 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2170 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
2171 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
2173 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2174 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2175 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2176 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2177 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2178 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2179 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2180 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2181 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2182 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2183 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2184 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2185 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2186 data << QString( "isVisible=%1" ).arg( params.isVisible );
2187 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2189 ClipPlanesList aPlanes = myModel->getClipPlanes();
2190 for ( int i=0; i < aPlanes.size(); i++ )
2192 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2193 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2194 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2195 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2196 switch ( aPlane.Mode )
2198 case OCCViewer_ClipPlane::Absolute :
2200 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2202 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2204 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2205 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2206 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2210 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2215 case OCCViewer_ClipPlane::Relative :
2217 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2218 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2219 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2224 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2225 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2226 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2227 data << ClippingPlane;
2230 // graduated trihedron
2231 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2232 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2233 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2234 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2235 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2236 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2237 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2238 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2239 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2240 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2241 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2242 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2243 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2244 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2245 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2246 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2247 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2248 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2249 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2250 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2251 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2252 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2253 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2254 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2255 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2256 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2257 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2258 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2259 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2260 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2261 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2262 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2263 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2264 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2265 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2266 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2267 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2268 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2269 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2270 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2271 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2272 data << QString( "background=%1" ).arg( bg );
2274 return data.join("*");
2278 \brief Restore visual parameters of the view window.
2279 \param parameters visual parameters of view window
2281 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2284 ClipPlanesList aClipPlanes;
2285 QStringList data = parameters.split( '*' );
2286 Qtx::BackgroundData bgData;
2287 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2289 foreach( QString param, data ) {
2290 QString paramName = param.section( '=', 0, 0 ).trimmed();
2291 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2292 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2293 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2294 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2295 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2296 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2297 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2298 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2299 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2300 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2301 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2302 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2303 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2304 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2305 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2306 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2307 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2308 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2309 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2310 else if ( paramName.contains( "ClippingPlane" ) )
2312 QStringList ClipPlaneData = paramValue.split( ';' );
2313 OCCViewer_ClipPlane aPlane;
2314 foreach( QString ClipPlaneParam, ClipPlaneData )
2316 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2317 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2318 if ( ClipPlane_paramName == "Mode" )
2320 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2322 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2323 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2324 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2325 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2328 switch ( aPlane.Mode )
2330 case OCCViewer_ClipPlane::Absolute :
2331 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2332 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2333 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2334 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2335 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2338 case OCCViewer_ClipPlane::Relative :
2339 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2340 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2341 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2346 aClipPlanes.push_back(aPlane);
2348 // graduated trihedron
2349 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2350 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2351 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2352 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2353 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2354 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2355 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2356 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2357 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2358 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2359 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2360 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2361 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2362 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2363 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2364 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2365 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2366 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2367 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2368 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2369 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2370 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2371 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2372 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2373 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2374 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2375 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2376 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2377 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2378 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2379 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2380 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2381 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2382 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2383 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2384 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2385 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2386 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2387 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2388 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2389 else if ( paramName == "background" ) {
2390 QString bg = paramValue.replace( "$", "=" );
2391 bgData = Qtx::stringToBackground( bg );
2395 else // old format - "1.000e+00*0.000e+00..."
2398 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2399 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2400 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2401 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2402 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2403 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2404 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
2405 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2406 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2407 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
2408 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2409 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2410 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2411 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
2412 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
2413 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
2414 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
2415 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
2417 performRestoring( params );
2418 setBackground( bgData );
2419 myModel->setClipPlanes(aClipPlanes);
2423 \brief Handle show event.
2425 Emits Show() signal.
2427 \param theEvent show event
2429 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2431 emit Show( theEvent );
2435 \brief Handle hide event.
2437 Emits Hide() signal.
2439 \param theEvent hide event
2441 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
2443 emit Hide( theEvent );
2448 Creates default sketcher. [ virtual protected ]
2450 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
2453 return new OCCViewer_RectSketcher( this, type );
2454 if ( type == Polygon )
2455 return new OCCViewer_PolygonSketcher( this, type );
2459 void OCCViewer_ViewWindow::initSketchers()
2461 if ( mySketchers.isEmpty() )
2463 mySketchers.append( createSketcher( Rect ) );
2464 mySketchers.append( createSketcher( Polygon ) );
2468 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
2470 OCCViewer_ViewSketcher* sketcher = 0;
2471 QList<OCCViewer_ViewSketcher*>::Iterator it;
2472 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
2474 OCCViewer_ViewSketcher* sk = (*it);
2475 if ( sk->type() == typ )
2482 Handles requests for sketching in the active view. [ virtual public ]
2484 void OCCViewer_ViewWindow::activateSketching( int type )
2486 OCCViewer_ViewPort3d* vp = getViewPort();
2490 if ( !vp->isSketchingEnabled() )
2493 /* Finish current sketching */
2494 if ( type == NoSketching )
2498 onSketchingFinished();
2499 mypSketcher->deactivate();
2503 /* Activate new sketching */
2506 activateSketching( NoSketching ); /* concurrency not suported */
2507 mypSketcher = getSketcher( type );
2510 mypSketcher->activate();
2511 onSketchingStarted();
2517 Unhilights detected entities. [ virtual protected ]
2519 void OCCViewer_ViewWindow::onSketchingStarted()
2524 Selection by rectangle or polygon. [ virtual protected ]
2526 void OCCViewer_ViewWindow::onSketchingFinished()
2528 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
2529 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
2531 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
2532 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
2533 switch( mypSketcher->type() )
2537 QRect* aRect = (QRect*)mypSketcher->data();
2540 int aLeft = aRect->left();
2541 int aRight = aRect->right();
2542 int aTop = aRect->top();
2543 int aBottom = aRect->bottom();
2547 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2549 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2555 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
2558 int size = aPolygon->size();
2559 TColgp_Array1OfPnt2d anArray( 1, size );
2561 QPolygon::Iterator it = aPolygon->begin();
2562 QPolygon::Iterator itEnd = aPolygon->end();
2563 for( int index = 1; it != itEnd; ++it, index++ )
2565 QPoint aPoint = *it;
2566 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
2570 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
2572 ic->Select( anArray, getViewPort()->getView(), Standard_False );
2580 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
2581 aViewMgr->getOCCViewer()->performSelectionChanged();
2585 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
2590 bool OCCViewer_ViewWindow::transformRequested() const
2592 return ( myOperation != NOTHING );
2595 bool OCCViewer_ViewWindow::transformInProcess() const
2597 return myEventStarted;
2600 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
2602 myEventStarted = bOn;
2606 Set enabled state of transformation (rotate, zoom, etc)
2608 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
2610 if ( id != NOTHING ) myStatus.insert( id, on );
2614 \return enabled state of transformation (rotate, zoom, etc)
2616 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
2618 return myStatus.contains( id ) ? myStatus[ id ] : true;
2621 void OCCViewer_ViewWindow::onMaximizedView()
2623 setMaximized(!isMaximized());
2626 void OCCViewer_ViewWindow::returnTo3dView()
2628 setReturnedTo3dView( true );
2631 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
2633 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
2634 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
2635 if ( !isVisible3dView )
2636 toolMgr()->show( ReturnTo3dViewId );
2638 toolMgr()->hide( ReturnTo3dViewId );
2639 if ( isVisible3dView ) emit returnedTo3d( );
2643 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
2645 QAction* anAction = toolMgr()->action( MaximizedId );
2646 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
2647 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
2649 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
2650 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
2651 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
2652 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
2653 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
2655 emit maximized( this, true );
2659 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
2660 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
2661 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
2662 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
2663 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
2665 emit maximized( this, false );
2670 bool OCCViewer_ViewWindow::isMaximized() const
2672 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
2675 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
2677 IsSketcherStyle = enable;
2680 bool OCCViewer_ViewWindow::isSketcherStyle() const
2682 return IsSketcherStyle;
2686 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
2692 QColor OCCViewer_ViewWindow::backgroundColor() const
2694 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
2698 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
2700 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
2703 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
2705 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
2708 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
2710 if ( myViewPort ) myViewPort->setBackground( theBackground );
2713 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
2715 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
2721 void OCCViewer_ViewWindow::clearViewAspects()
2723 myViewAspects.clear();
2727 \return const reference to list of view aspects
2729 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
2731 return myViewAspects;
2735 Appends new view aspect
2736 \param aParams - new view aspects
2738 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
2740 myViewAspects.append( aParams );
2744 Replaces old view aspects by new ones
2745 \param aViewList - list of new view aspects
2747 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
2749 myViewAspects = aViewList;
2753 Get camera properties for the OCC view window.
2754 \return shared pointer on camera properties.
2756 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
2758 SUIT_CameraProperties aProps;
2760 Handle(V3d_View) aSourceView = getViewPort()->getView();
2761 if ( aSourceView.IsNull() )
2764 if ( get2dMode() == No2dMode ) {
2765 aProps.setDimension( SUIT_CameraProperties::Dim3D );
2768 aProps.setDimension( SUIT_CameraProperties::Dim2D );
2769 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
2772 // read common properites of the view
2773 Standard_Real anUp[3];
2774 Standard_Real anAt[3];
2775 Standard_Real anEye[3];
2776 Standard_Real aProj[3];
2777 Standard_Real anAxialScale[3];
2779 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
2780 aSourceView->At( anAt[0], anAt[1], anAt[2] );
2781 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
2782 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2784 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2785 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
2787 #if OCC_VERSION_LARGE > 0x06070100
2788 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
2790 // store camera properties "as is": it is up to synchronized
2791 // view classes to provide necessary property conversion.
2792 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
2793 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
2795 if ( aSourceView->Camera()->IsOrthographic() )
2797 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
2798 aProps.setViewAngle( 0.0 );
2802 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
2803 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
2805 aProps.setMappingScale( aSourceView->Camera()->Scale() );
2807 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
2809 // generate view orientation matrix for transforming OCC projection reference point
2810 // into a camera (eye) position.
2811 gp_Dir aLeftDir = gp_Dir( anUp[0], anUp[1], anUp[2] ) ^ gp_Dir( aProj[0], aProj[1], aProj[2] );
2814 aTrsf.SetValue( 1, 1, aLeftDir.X() );
2815 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
2816 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
2818 aTrsf.SetValue( 1, 2, anUp[0] );
2819 aTrsf.SetValue( 2, 2, anUp[1] );
2820 aTrsf.SetValue( 3, 2, anUp[2] );
2822 aTrsf.SetValue( 1, 3, aProj[0] );
2823 aTrsf.SetValue( 2, 3, aProj[1] );
2824 aTrsf.SetValue( 3, 3, aProj[2] );
2826 aTrsf.SetValue( 1, 4, anAt[0] );
2827 aTrsf.SetValue( 2, 4, anAt[1] );
2828 aTrsf.SetValue( 3, 4, anAt[2] );
2830 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
2832 // transform to world-space coordinate system
2833 gp_XYZ aPosition( aProjRef.X(), aProjRef.Y(), aCameraDepth );
2834 aTrsf.Transforms( aPosition );
2836 // compute focal point
2837 double aFocalPoint[3];
2839 aFocalPoint[0] = aPosition.X() - aProj[0] * aCameraDepth;
2840 aFocalPoint[1] = aPosition.Y() - aProj[1] * aCameraDepth;
2841 aFocalPoint[2] = aPosition.Z() - aProj[2] * aCameraDepth;
2843 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2844 aProps.setPosition( aPosition.X(), aPosition.Y(), aPosition.Z() );
2846 Standard_Real aViewScale[2];
2847 aSourceView->Size( aViewScale[0], aViewScale[1] );
2848 aProps.setMappingScale( aViewScale[1] );
2856 This implementation synchronizes OCC view's camera propreties.
2858 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
2860 bool blocked = blockSignals( true );
2862 SUIT_CameraProperties aProps = theView->cameraProperties();
2863 if ( !cameraProperties().isCompatible( aProps ) ) {
2864 // other view, this one is being currently synchronized to, seems has become incompatible
2865 // we have to break synchronization
2870 Handle(V3d_View) aDestView = getViewPort()->getView();
2872 aDestView->SetImmediateUpdate( Standard_False );
2875 double aPosition[3];
2876 double aFocalPoint[3];
2877 double anAxialScale[3];
2879 // get common properties
2880 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2881 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
2882 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2883 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2885 #if OCC_VERSION_LARGE > 0x06070100
2886 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2887 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
2888 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2889 aDestView->Camera()->SetScale( aProps.getMappingScale() );
2891 gp_Dir aProjDir( aPosition[0] - aFocalPoint[0],
2892 aPosition[1] - aFocalPoint[1],
2893 aPosition[2] - aFocalPoint[2] );
2895 // get custom view translation
2896 Standard_Real aTranslation[3];
2897 aDestView->At( aTranslation[0], aTranslation[1], aTranslation[2] );
2899 gp_Dir aLeftDir = gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] )
2900 ^ gp_Dir( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
2903 aTrsf.SetValue( 1, 1, aLeftDir.X() );
2904 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
2905 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
2907 aTrsf.SetValue( 1, 2, anUpDir[0] );
2908 aTrsf.SetValue( 2, 2, anUpDir[1] );
2909 aTrsf.SetValue( 3, 2, anUpDir[2] );
2911 aTrsf.SetValue( 1, 3, aProjDir.X() );
2912 aTrsf.SetValue( 2, 3, aProjDir.Y() );
2913 aTrsf.SetValue( 3, 3, aProjDir.Z() );
2915 aTrsf.SetValue( 1, 4, aTranslation[0] );
2916 aTrsf.SetValue( 2, 4, aTranslation[1] );
2917 aTrsf.SetValue( 3, 4, aTranslation[2] );
2920 // transform to view-space coordinate system
2921 gp_XYZ aProjRef( aPosition[0], aPosition[1], aPosition[2] );
2922 aTrsf.Transforms( aProjRef );
2924 // set view camera properties using low-level approach. this is done
2925 // in order to avoid interference with static variables in v3d view used
2926 // when rotation is in process in another view.
2927 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
2928 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
2930 Graphic3d_Vector aMappingProj( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
2931 Graphic3d_Vector aMappingUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2933 aMappingProj.Normalize();
2934 aMappingUp.Normalize();
2936 anOrientation.SetViewReferencePlane( aMappingProj );
2937 anOrientation.SetViewReferenceUp( aMappingUp );
2939 aDestView->SetViewMapping( aMapping );
2940 aDestView->SetViewOrientation( anOrientation );
2943 aDestView->SetCenter( aProjRef.X(), aProjRef.Y() );
2945 // set mapping scale
2946 double aMapScaling = aProps.getMappingScale();
2947 Standard_Real aWidth, aHeight;
2948 aDestView->Size( aWidth, aHeight );
2949 aDestView->SetSize ( aWidth > aHeight ? aMapScaling * (aWidth / aHeight) : aMapScaling );
2952 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2954 aDestView->ZFitAll();
2955 aDestView->SetImmediateUpdate( Standard_True );
2956 aDestView->Redraw();
2958 blockSignals( blocked );
2962 \brief Indicates whether preselection is enabled
2963 \return true if preselection is enabled
2965 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
2967 return myPreselectionEnabled;
2971 \brief Enables/disables preselection
2972 \param theIsToEnable if true - preselection will be enabled
2974 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
2976 onSwitchPreselection( theIsToEnable );
2980 \brief Indicates whether selection is enabled
2981 \return true if selection is enabled
2983 bool OCCViewer_ViewWindow::isSelectionEnabled() const
2985 return mySelectionEnabled;
2989 \brief Enables/disables selection
2990 \param theIsToEnable if true - selection will be enabled
2992 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
2994 onSwitchSelection( theIsToEnable );
2999 \brief called if clipping operation is activated / deactivated.
3001 Enables/disables clipping plane displaying.
3003 \parma on action state
3005 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3007 if(!myModel) return;
3008 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3011 if (!aClippingDlg) {
3012 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3013 myModel->setClippingDlg(aClippingDlg);
3015 if (!aClippingDlg->isVisible())
3016 aClippingDlg->show();
3018 if ( aClippingDlg ) {
3019 aClippingDlg->close();
3020 myModel->setClippingDlg(0);
3024 SUIT_ViewManager* mgr = getViewManager();
3026 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3027 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3028 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3029 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3031 QAction* a = toolMgr()->action( ClippingId );
3033 if(theIsOn != a->isChecked()){
3034 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3035 a->setChecked(theIsOn);
3036 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));