1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : OCCViewer_ViewWindow.cxx
26 #include "OCCViewer_ViewWindow.h"
27 #include "OCCViewer_ViewModel.h"
28 #include "OCCViewer_ViewPort3d.h"
29 #include "OCCViewer_ViewManager.h"
30 #include "OCCViewer_ViewSketcher.h"
31 #include "OCCViewer_CreateRestoreViewDlg.h"
32 #include "OCCViewer_ClipPlane.h"
33 #include "OCCViewer_SetRotationPointDlg.h"
34 #include "OCCViewer_AxialScaleDlg.h"
35 #include "OCCViewer_CubeAxesDlg.h"
36 #include "OCCViewer_ClippingDlg.h"
38 #include <Basics_OCCTVersion.hxx>
40 #include <SUIT_Desktop.h>
41 #include <SUIT_Session.h>
42 #include <SUIT_ViewManager.h>
43 #include <SUIT_Tools.h>
44 #include <SUIT_ResourceMgr.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_Application.h>
48 #include <QtxActionToolMgr.h>
49 #include <QtxMultiAction.h>
50 #include <QtxRubberBand.h>
52 #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;
367 if ( aEvent->modifiers().testFlag(Qt::ControlModifier) ) {
368 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
369 if ( isPreselectionEnabled() && ic->HasOpenedContext() ) {
370 if ( aEvent->delta() > 0 ) {
371 ic->HilightNextDetected( myViewPort->getView() );
373 ic->HilightPreviousDetected( myViewPort->getView() );
377 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
378 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
381 int x1 = (int)( aEvent->x() + width()*delta/100 );
382 int y1 = (int)( aEvent->y() + height()*delta/100 );
383 myViewPort->zoom( x, y, x1, y1 );
384 myViewPort->getView()->ZFitAll();
389 case QEvent::ContextMenu:
391 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
392 if ( aEvent->reason() != QContextMenuEvent::Mouse )
393 emit contextMenuRequested( aEvent );
397 case QEvent::KeyPress:
398 emit keyPressed(this, (QKeyEvent*) e);
405 return SUIT_ViewWindow::eventFilter(watched, e);
409 \brief Update state of enable draw mode state.
411 void OCCViewer_ViewWindow::updateEnabledDrawMode()
414 myEnableDrawMode = myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
418 \brief Handle mouse press event
419 \param theEvent mouse event
421 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
423 myStartX = theEvent->x();
424 myStartY = theEvent->y();
425 int anInteractionStyle = interactionStyle();
427 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
428 // which are assigned for pan and rotate - these operations are activated immediately after pressing
429 // of the first button, so it is necessary to switch to zoom when the second button is pressed
430 bool aSwitchToZoom = false;
431 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
432 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
433 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
436 switch ( myOperation ) {
438 if ( theEvent->button() == Qt::LeftButton )
439 emit vpTransformationStarted ( WINDOWFIT );
443 if ( theEvent->button() == Qt::LeftButton )
444 emit vpTransformationStarted ( PANGLOBAL );
448 if ( theEvent->button() == Qt::LeftButton ) {
449 myViewPort->startZoomAtPoint( myStartX, myStartY );
450 emit vpTransformationStarted ( ZOOMVIEW );
455 if ( aSwitchToZoom ) {
456 myViewPort->startZoomAtPoint( myStartX, myStartY );
459 else if ( theEvent->button() == Qt::LeftButton )
460 emit vpTransformationStarted ( PANVIEW );
464 if ( aSwitchToZoom ) {
465 myViewPort->startZoomAtPoint( myStartX, myStartY );
468 else if ( theEvent->button() == Qt::LeftButton ) {
469 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
470 emit vpTransformationStarted ( ROTATE );
475 /* Try to activate a transformation */
476 OperationType aState;
477 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
478 aState = getButtonState(theEvent, anInteractionStyle);
480 aState = OCCViewer_ViewWindow::NOTHING;
485 myViewPort->startZoomAtPoint( myStartX, myStartY );
493 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
496 if ( myRotationPointSelection )
498 if ( theEvent->button() == Qt::LeftButton )
500 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
502 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
504 TopoDS_Shape aShape = ic->SelectedShape();
505 GProp_GProps aSystem;
507 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
509 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
511 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE )
513 BRepGProp::LinearProperties( aShape, aSystem );
514 aPnt = aSystem.CentreOfMass();
516 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE )
518 BRepGProp::SurfaceProperties( aShape, aSystem );
519 aPnt = aSystem.CentreOfMass();
521 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID )
523 BRepGProp::VolumeProperties( aShape, aSystem );
524 aPnt = aSystem.CentreOfMass();
528 myCurrPointType = myPrevPointType;
532 if ( mySetRotationPointDlg )
534 myRotationPointSelection = false;
535 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
538 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
539 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
540 ic->CloseAllContexts();
541 myOperation = NOTHING;
542 myViewPort->setCursor( myCursor );
543 myCursorIsHand = false;
544 myRotationPointSelection = false;
548 emit mousePressed(this, theEvent);
551 /* notify that we start a transformation */
552 if ( transformRequested() )
553 emit vpTransformationStarted ( myOperation );
555 if ( transformRequested() )
556 setTransformInProcess( true );
558 /* we may need it for sketching... */
559 if ( l_mbPressEvent )
560 delete l_mbPressEvent;
561 l_mbPressEvent = new QMouseEvent( *theEvent );
566 \brief Start zooming operation.
568 Sets the corresponding cursor for the widget.
570 void OCCViewer_ViewWindow::activateZoom()
572 if ( !transformRequested() && !myCursorIsHand )
573 myCursor = cursor(); /* save old cursor */
575 if ( myOperation != ZOOMVIEW ) {
576 QPixmap zoomPixmap (imageZoomCursor);
577 QCursor zoomCursor (zoomPixmap);
578 if( setTransformRequested ( ZOOMVIEW ) )
579 myViewPort->setCursor( zoomCursor );
585 \brief Start panning operation.
587 Sets the corresponding cursor for the widget.
589 void OCCViewer_ViewWindow::activatePanning()
591 if ( !transformRequested() && !myCursorIsHand )
592 myCursor = cursor(); // save old cursor
594 if ( myOperation != PANVIEW ) {
595 QCursor panCursor (Qt::SizeAllCursor);
596 if( setTransformRequested ( PANVIEW ) )
597 myViewPort->setCursor( panCursor );
602 \brief Start rotation operation
604 Sets the corresponding cursor for the widget.
606 void OCCViewer_ViewWindow::activateRotation()
608 if ( !transformRequested() && !myCursorIsHand )
609 myCursor = cursor(); // save old cursor
611 if ( myOperation != ROTATE ) {
612 QPixmap rotatePixmap (imageRotateCursor);
613 QCursor rotCursor (rotatePixmap);
614 if( setTransformRequested ( ROTATE ) )
615 myViewPort->setCursor( rotCursor );
620 \brief Compute the gravity center.
621 \param theX used to return X coordinate of the gravity center
622 \param theY used to return Y coordinate of the gravity center
623 \param theZ used to return Z coordinate of the gravity center
624 \return \c true if the gravity center is computed
626 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
628 Handle(V3d_View) aView3d = myViewPort->getView();
630 // Project boundaries points and add to avergae gravity
631 // the ones which lie within the screen limits
632 Standard_Real aScreenLimits[4] = { 0.0, 0.0, 0.0, 0.0 };
634 #if OCC_VERSION_LARGE > 0x06070100
635 // NDC space screen limits
636 aScreenLimits[0] = -1.0;
637 aScreenLimits[1] = 1.0;
638 aScreenLimits[2] = -1.0;
639 aScreenLimits[3] = 1.0;
641 aView3d->View()->ViewMapping().WindowLimit( aScreenLimits[0],
647 Standard_Integer aPointsNb = 0;
649 Standard_Real aXmin = 0.0;
650 Standard_Real aYmin = 0.0;
651 Standard_Real aZmin = 0.0;
652 Standard_Real aXmax = 0.0;
653 Standard_Real aYmax = 0.0;
654 Standard_Real aZmax = 0.0;
656 Graphic3d_MapOfStructure aSetOfStructures;
657 aView3d->View()->DisplayedStructures( aSetOfStructures );
658 Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures );
660 for( ; aStructureIt.More(); aStructureIt.Next() ) {
661 const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key();
662 if ( aStructure->IsEmpty() ) {
666 #if OCC_VERSION_LARGE > 0x06070100
667 Bnd_Box aBox = aStructure->MinMaxValues();
668 aXmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().X();
669 aYmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Y();
670 aZmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Z();
671 aXmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().X();
672 aYmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Y();
673 aZmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Z();
675 aStructure->MinMaxValues( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
678 // Infinite structures are skipped
679 Standard_Real aLIM = ShortRealLast() - 1.0;
680 if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
681 || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
685 gp_Pnt aPoints[8] = {
686 gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
687 gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
688 gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
689 gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
692 for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
693 const gp_Pnt& aBBPoint = aPoints[aPointIt];
695 #if OCC_VERSION_LARGE > 0x06070100
696 gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
697 const Standard_Real& U = aProjected.X();
698 const Standard_Real& V = aProjected.Y();
700 Standard_Real U = 0.0;
701 Standard_Real V = 0.0;
702 Standard_Real W = 0.0;
703 aView3d->View()->Projects( aBBPoint.X(), aBBPoint.Y(), aBBPoint.Z(), U, V, W );
706 if (U >= aScreenLimits[0]
707 && U <= aScreenLimits[1]
708 && V >= aScreenLimits[2]
709 && V <= aScreenLimits[3])
712 theX += aBBPoint.X();
713 theY += aBBPoint.Y();
714 theZ += aBBPoint.Z();
729 \brief Set the gravity center as a rotation point.
731 void OCCViewer_ViewWindow::activateSetRotationGravity()
733 if ( myRotationPointSelection )
735 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
736 ic->CloseAllContexts();
737 myOperation = NOTHING;
738 myViewPort->setCursor( myCursor );
739 myCursorIsHand = false;
740 myRotationPointSelection = false;
743 myPrevPointType = myCurrPointType;
744 myCurrPointType = GRAVITY;
746 Standard_Real Xcenter, Ycenter, Zcenter;
747 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
748 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
752 \brief Update gravity center in the "Set Rotation Point" dialog box.
753 \sa OCCViewer_SetRotationPointDlg class
755 void OCCViewer_ViewWindow::updateGravityCoords()
757 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == GRAVITY )
759 Standard_Real Xcenter, Ycenter, Zcenter;
760 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
761 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
766 \brief Set the point selected by the user as a rotation point.
767 \param theX X coordinate of the rotation point
768 \param theY Y coordinate of the rotation point
769 \param theZ Z coordinate of the rotation point
771 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
773 if ( myRotationPointSelection )
775 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
776 ic->CloseAllContexts();
777 myOperation = NOTHING;
778 myViewPort->setCursor( myCursor );
779 myCursorIsHand = false;
780 myRotationPointSelection = false;
783 myPrevPointType = myCurrPointType;
784 myCurrPointType = SELECTED;
785 mySelectedPoint.SetCoord(theX,theY,theZ);
789 \brief Start the shape selection process.
791 void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
793 myPrevPointType = myCurrPointType;
794 myCurrPointType = SELECTED;
796 // activate selection ------>
797 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
799 ic->OpenLocalContext();
801 AIS_ListOfInteractive aList;
802 ic->DisplayedObjects( aList );
803 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
805 Handle(AIS_InteractiveObject) anObj = it.Value();
806 if ( !anObj.IsNull() && anObj->HasPresentation() &&
807 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
810 ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
813 // activate selection <------
815 if ( !myCursorIsHand )
817 QCursor handCursor (Qt::PointingHandCursor);
818 myCursorIsHand = true;
820 myViewPort->setCursor( handCursor );
822 myRotationPointSelection = true;
826 \brief Start global panning operation
828 Sets the corresponding cursor for the widget.
830 void OCCViewer_ViewWindow::activateGlobalPanning()
832 Handle(V3d_View) aView3d = myViewPort->getView();
833 if ( !aView3d.IsNull() ) {
834 QPixmap globalPanPixmap (imageCrossCursor);
835 QCursor glPanCursor (globalPanPixmap);
836 myCurScale = aView3d->Scale();
837 aView3d->FitAll(0.01, false);
838 myCursor = cursor(); // save old cursor
839 myViewPort->fitAll(); // fits view before selecting a new scene center
840 if( setTransformRequested( PANGLOBAL ) )
841 myViewPort->setCursor( glPanCursor );
846 \brief Starts fit operation.
848 Sets the corresponding cursor for the widget.
850 void OCCViewer_ViewWindow::activateWindowFit()
852 if ( !transformRequested() && !myCursorIsHand )
853 myCursor = cursor(); /* save old cursor */
855 if ( myOperation != WINDOWFIT ) {
856 QCursor handCursor (Qt::PointingHandCursor);
857 if( setTransformRequested ( WINDOWFIT ) )
859 myViewPort->setCursor ( handCursor );
860 myCursorIsHand = true;
866 \brief Start delayed viewer operation.
868 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
870 bool ok = transformEnabled( op );
871 myOperation = ok ? op : NOTHING;
872 myViewPort->setMouseTracking( myOperation == NOTHING );
877 \brief Handle mouse move event.
878 \param theEvent mouse event
880 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
882 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
884 switch ( getButtonState( theEvent, interactionStyle() ) ) {
886 myViewPort->startZoomAtPoint( myStartX, myStartY );
894 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
901 myCurrX = theEvent->x();
902 myCurrY = theEvent->y();
903 switch (myOperation) {
905 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
909 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
915 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
929 if ( myRotationPointSelection || isSketcherStyle() )
931 emit mouseMoving( this, theEvent );
935 int aState = theEvent->modifiers();
936 int aButton = theEvent->buttons();
937 int anInteractionStyle = interactionStyle();
938 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
939 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
940 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
941 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
942 myDrawRect = myEnableDrawMode;
945 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
946 QCursor handCursor (Qt::PointingHandCursor);
947 myCursorIsHand = true;
949 myViewPort->setCursor( handCursor );
952 emit mouseMoving( this, theEvent );
954 else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
955 aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
956 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
957 aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
958 OCCViewer_ViewSketcher* sketcher = 0;
959 QList<OCCViewer_ViewSketcher*>::Iterator it;
960 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
962 OCCViewer_ViewSketcher* sk = (*it);
963 if( sk->isDefault() && sk->sketchButton() == aButton )
966 if ( sketcher && myCurSketch == -1 )
968 activateSketching( sketcher->type() );
971 myCurSketch = mypSketcher->sketchButton();
973 if ( l_mbPressEvent )
975 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
976 delete l_mbPressEvent;
979 QApplication::sendEvent( getViewPort(), theEvent );
984 emit mouseMoving( this, theEvent );
990 \brief Handle mouse release event.
991 \param theEvent mouse event
993 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
995 switch ( myOperation ) {
998 int prevState = myCurSketch;
999 if(theEvent->button() == Qt::RightButton)
1001 QList<OCCViewer_ViewSketcher*>::Iterator it;
1002 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
1004 OCCViewer_ViewSketcher* sk = (*it);
1005 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
1010 emit mouseReleased(this, theEvent);
1011 if(theEvent->button() == Qt::RightButton && prevState == -1)
1013 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1014 theEvent->pos(), theEvent->globalPos() );
1015 emit contextMenuRequested( &aEvent );
1020 myViewPort->endRotation();
1026 myViewPort->getView()->ZFitAll();
1031 if ( theEvent->button() == Qt::LeftButton ) {
1032 myViewPort->setCenter( theEvent->x(), theEvent->y() );
1033 myViewPort->getView()->SetScale(myCurScale);
1039 if ( theEvent->button() == Qt::LeftButton ) {
1040 myCurrX = theEvent->x();
1041 myCurrY = theEvent->y();
1043 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1044 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1051 // NOTE: viewer 3D detects a rectangle of selection using this event
1052 // so we must emit it BEFORE resetting the selection rectangle
1054 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1058 myViewPort->update();
1061 if ( l_mbPressEvent )
1063 delete l_mbPressEvent;
1069 \brief Reset the viewport to its initial state
1070 ( no transformations in process etc. )
1072 void OCCViewer_ViewWindow::resetState()
1076 if ( myRotationPointSelection )
1078 QCursor handCursor (Qt::PointingHandCursor);
1079 myViewPort->setCursor( handCursor );
1083 if ( transformRequested() || myCursorIsHand )
1084 myViewPort->setCursor( myCursor );
1085 myCursorIsHand = false;
1088 if ( transformRequested() )
1089 emit vpTransformationFinished (myOperation);
1091 setTransformInProcess( false );
1092 setTransformRequested( NOTHING );
1097 \brief Draw rubber band rectangle.
1099 void OCCViewer_ViewWindow::drawRect()
1101 if ( !myRectBand ) {
1102 myRectBand = new QtxRectRubberBand( myViewPort );
1104 //palette.setColor(myRectBand->foregroundRole(), Qt::white);
1105 //myRectBand->setPalette(palette);
1107 //myRectBand->hide();
1109 myRectBand->setUpdatesEnabled ( false );
1110 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1111 myRectBand->initGeometry( aRect );
1113 if ( !myRectBand->isVisible() )
1116 myRectBand->setUpdatesEnabled ( true );
1117 //myRectBand->repaint();
1119 //myRectBand->setVisible( aRect.isValid() );
1120 //if ( myRectBand->isVisible() )
1121 // myRectBand->repaint();
1123 // myRectBand->show();
1124 //myRectBand->repaint();
1128 \brief Clear rubber band rectangle on the end on the dragging operation.
1130 void OCCViewer_ViewWindow::endDrawRect()
1132 //delete myRectBand;
1136 myRectBand->clearGeometry();
1142 \brief Create actions.
1144 void OCCViewer_ViewWindow::createActions()
1146 if( !toolMgr()->isEmpty() )
1149 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1154 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1155 tr( "MNU_DUMP_VIEW" ), 0, this);
1156 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1157 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1158 toolMgr()->registerAction( aAction, DumpId );
1161 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1162 tr( "MNU_FITALL" ), 0, this);
1163 aAction->setStatusTip(tr("DSC_FITALL"));
1164 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1165 toolMgr()->registerAction( aAction, FitAllId );
1168 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1169 tr( "MNU_FITRECT" ), 0, this);
1170 aAction->setStatusTip(tr("DSC_FITRECT"));
1171 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1172 toolMgr()->registerAction( aAction, FitRectId );
1175 aAction = new QtxAction(tr("MNU_FITSELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITSELECTION" ) ),
1176 tr( "MNU_FITSELECTION" ), 0, this);
1177 aAction->setStatusTip(tr("DSC_FITSELECTION"));
1178 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
1179 toolMgr()->registerAction( aAction, FitSelectionId );
1182 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1183 tr( "MNU_ZOOM_VIEW" ), 0, this);
1184 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1185 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1186 toolMgr()->registerAction( aAction, ZoomId );
1189 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1190 tr( "MNU_PAN_VIEW" ), 0, this);
1191 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1192 connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
1193 toolMgr()->registerAction( aAction, PanId );
1196 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1197 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1198 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1199 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1200 toolMgr()->registerAction( aAction, GlobalPanId );
1203 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1204 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1205 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1206 mySetRotationPointAction->setCheckable( true );
1207 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1208 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1211 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1212 tr( "MNU_ROTATE_VIEW" ), 0, this);
1213 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1214 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1215 toolMgr()->registerAction( aAction, RotationId );
1218 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1219 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1220 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1221 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1222 this->addAction(aAction);
1223 toolMgr()->registerAction( aAction, FrontId );
1225 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1226 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1227 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1228 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1229 this->addAction(aAction);
1230 toolMgr()->registerAction( aAction, BackId );
1232 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1233 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1234 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1235 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1236 this->addAction(aAction);
1237 toolMgr()->registerAction( aAction, TopId );
1239 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1240 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1241 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1242 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1243 this->addAction(aAction);
1244 toolMgr()->registerAction( aAction, BottomId );
1246 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1247 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1248 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1249 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1250 this->addAction(aAction);
1251 toolMgr()->registerAction( aAction, LeftId );
1253 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1254 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1255 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1256 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1257 this->addAction(aAction);
1258 toolMgr()->registerAction( aAction, RightId );
1260 // rotate anticlockwise
1261 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1262 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1263 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1264 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1265 this->addAction(aAction);
1266 toolMgr()->registerAction( aAction, AntiClockWiseId );
1269 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1270 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1271 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1272 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1273 this->addAction(aAction);
1274 toolMgr()->registerAction( aAction, ClockWiseId );
1277 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1278 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1279 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1280 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1281 this->addAction(aAction);
1282 toolMgr()->registerAction( aAction, ResetId );
1285 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1286 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1287 tr("MNU_CLONE_VIEW"), 0, this);
1288 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1289 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1290 toolMgr()->registerAction( aAction, CloneId );
1292 aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
1293 tr("MNU_CLIPPING"), 0, this);
1294 aAction->setStatusTip (tr("DSC_CLIPPING"));
1295 aAction->setCheckable (true);
1296 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1297 toolMgr()->registerAction (aAction, ClippingId);
1299 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1300 tr( "MNU_SHOOT_VIEW" ), 0, this);
1301 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1302 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1303 toolMgr()->registerAction( aAction, MemId );
1305 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1306 tr( "MNU_PRESETS_VIEW" ), 0, this);
1307 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1308 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1309 toolMgr()->registerAction( aAction, RestoreId );
1311 if (myModel->trihedronActivated()) {
1312 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1313 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1314 aAction->setCheckable( true );
1315 aAction->setChecked( true );
1316 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1317 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1318 toolMgr()->registerAction( aAction, TrihedronShowId );
1322 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1323 tr( "MNU_SCALING" ), 0, this);
1324 aAction->setStatusTip(tr("DSC_SCALING"));
1325 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1326 toolMgr()->registerAction( aAction, AxialScaleId );
1328 // Enable/disable preselection
1329 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1330 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1331 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1332 aAction->setCheckable(true);
1333 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1334 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1336 // Enable/disable selection
1337 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1338 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1339 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1340 aAction->setCheckable(true);
1341 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1342 toolMgr()->registerAction( aAction, SwitchSelectionId );
1345 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1346 tr( "MNU_GRADUATED_AXES" ), 0, this);
1347 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1348 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1349 toolMgr()->registerAction( aAction, GraduatedAxesId );
1351 // Active only ambient light or not
1352 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1353 tr( "MNU_AMBIENT" ), 0, this);
1354 aAction->setStatusTip(tr("DSC_AMBIENT"));
1355 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1356 toolMgr()->registerAction( aAction, AmbientId );
1358 // Switch between interaction styles
1359 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1360 tr( "MNU_STYLE_SWITCH" ), 0, this);
1361 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1362 aAction->setCheckable(true);
1363 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1364 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1366 // Switch between zooming styles
1367 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1368 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1369 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1370 aAction->setCheckable(true);
1371 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1372 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1375 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1376 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1377 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1378 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1379 toolMgr()->registerAction( aAction, MaximizedId );
1381 // Return to 3d view
1382 if (my2dMode!=No2dMode){
1383 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1384 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1385 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1386 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1387 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1391 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1395 \brief Create toolbar.
1397 void OCCViewer_ViewWindow::createToolBar()
1399 static const char* titles[] = {
1400 "LBL_3DTOOLBAR_LABEL",
1401 "LBL_XYTOOLBAR_LABEL",
1402 "LBL_XZTOOLBAR_LABEL",
1403 "LBL_YZTOOLBAR_LABEL",
1405 static const char* names[] = {
1406 "OCCViewer3DViewOperations",
1407 "OCCViewerXYViewOperations",
1408 "OCCViewerXZViewOperations",
1409 "OCCViewerYZViewOperations",
1411 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1412 QString( names[my2dMode] ), // name (language-independant)
1413 false ); // disable floatable toolbar
1414 if ( my2dMode != No2dMode ){
1415 toolMgr()->append( ReturnTo3dViewId, tid );
1416 toolMgr()->append( toolMgr()->separator(), tid );
1418 toolMgr()->append( DumpId, tid );
1419 toolMgr()->append( SwitchInteractionStyleId, tid );
1420 toolMgr()->append( SwitchZoomingStyleId, tid );
1421 toolMgr()->append( SwitchPreselectionId, tid );
1422 toolMgr()->append( SwitchSelectionId, tid );
1423 if( myModel->trihedronActivated() )
1424 toolMgr()->append( TrihedronShowId, tid );
1426 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1427 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1428 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1429 #if OCC_VERSION_LARGE > 0x06090000
1430 aScaleAction->insertAction( toolMgr()->action( FitSelectionId ) );
1432 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1433 toolMgr()->append( aScaleAction, tid );
1435 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1436 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1437 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1438 toolMgr()->append( aPanningAction, tid );
1440 if (my2dMode == No2dMode) {
1441 toolMgr()->append( ChangeRotationPointId, tid );
1442 toolMgr()->append( RotationId, tid );
1444 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1445 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1446 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1447 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1448 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1449 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1450 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1451 toolMgr()->append( aViewsAction, tid );
1453 toolMgr()->append( AntiClockWiseId, tid );
1454 toolMgr()->append( ClockWiseId, tid );
1456 toolMgr()->append( ResetId, tid );
1459 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1460 aMemAction->insertAction( toolMgr()->action( MemId ) );
1461 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1462 toolMgr()->append( aMemAction, tid );
1464 toolMgr()->append( toolMgr()->separator(), tid );
1465 toolMgr()->append( CloneId, tid );
1467 toolMgr()->append( toolMgr()->separator(), tid );
1468 toolMgr()->append( ClippingId, tid );
1469 toolMgr()->append( AxialScaleId, tid );
1470 toolMgr()->append( GraduatedAxesId, tid );
1471 toolMgr()->append( AmbientId, tid );
1473 toolMgr()->append( MaximizedId, tid );
1474 toolMgr()->append( SynchronizeId, tid );
1478 \brief Perform 'fit all' operation.
1480 void OCCViewer_ViewWindow::onViewFitAll()
1482 myViewPort->fitAll();
1486 \brief Perform "front view" transformation.
1488 void OCCViewer_ViewWindow::onFrontView()
1490 emit vpTransformationStarted ( FRONTVIEW );
1491 Handle(V3d_View) aView3d = myViewPort->getView();
1492 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
1494 emit vpTransformationFinished ( FRONTVIEW );
1498 \brief Perform "back view" transformation.
1500 void OCCViewer_ViewWindow::onBackView()
1502 emit vpTransformationStarted ( BACKVIEW );
1503 Handle(V3d_View) aView3d = myViewPort->getView();
1504 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
1506 emit vpTransformationFinished ( BACKVIEW );
1510 \brief Perform "top view" transformation.
1512 void OCCViewer_ViewWindow::onTopView()
1514 emit vpTransformationStarted ( TOPVIEW );
1515 Handle(V3d_View) aView3d = myViewPort->getView();
1516 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
1518 emit vpTransformationFinished ( TOPVIEW );
1522 \brief Perform "bottom view" transformation.
1524 void OCCViewer_ViewWindow::onBottomView()
1526 emit vpTransformationStarted ( BOTTOMVIEW );
1527 Handle(V3d_View) aView3d = myViewPort->getView();
1528 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
1530 emit vpTransformationFinished ( BOTTOMVIEW );
1534 \brief Perform "left view" transformation.
1536 void OCCViewer_ViewWindow::onLeftView()
1538 emit vpTransformationStarted ( LEFTVIEW );
1539 Handle(V3d_View) aView3d = myViewPort->getView();
1540 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
1542 emit vpTransformationFinished ( LEFTVIEW );
1546 \brief Perform "right view" transformation.
1548 void OCCViewer_ViewWindow::onRightView()
1550 emit vpTransformationStarted ( RIGHTVIEW );
1551 Handle(V3d_View) aView3d = myViewPort->getView();
1552 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
1554 emit vpTransformationFinished ( RIGHTVIEW );
1558 \brief Rotate view 90 degrees clockwise
1560 void OCCViewer_ViewWindow::onClockWiseView()
1562 emit vpTransformationStarted ( CLOCKWISEVIEW );
1563 myViewPort->rotateXY( 90. );
1564 emit vpTransformationFinished ( CLOCKWISEVIEW );
1568 \brief Rotate view 90 degrees conterclockwise
1570 void OCCViewer_ViewWindow::onAntiClockWiseView()
1572 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1573 myViewPort->rotateXY( -90. );
1574 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1578 \brief Perform "reset view" transformation.
1580 Sets default orientation of the viewport camera.
1582 void OCCViewer_ViewWindow::onResetView()
1584 emit vpTransformationStarted( RESETVIEW );
1585 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1586 myViewPort->getView()->Reset( false );
1587 myViewPort->fitAll( false, true, false );
1588 myViewPort->getView()->SetImmediateUpdate( upd );
1589 myViewPort->getView()->Update();
1590 emit vpTransformationFinished( RESETVIEW );
1594 \brief Perform "fit all" transformation.
1596 void OCCViewer_ViewWindow::onFitAll()
1598 emit vpTransformationStarted( FITALLVIEW );
1599 myViewPort->fitAll();
1600 emit vpTransformationFinished( FITALLVIEW );
1604 \brief Perform "fit selection" transformation.
1606 void OCCViewer_ViewWindow::onFitSelection()
1608 emit vpTransformationStarted( FITSELECTION );
1609 #if OCC_VERSION_LARGE > 0x06090000
1610 myModel->getAISContext()->FitSelected( getViewPort()->getView() );
1612 emit vpTransformationFinished( FITSELECTION );
1616 \brief Called if 'change rotation point' operation is activated.
1617 \param on action state
1619 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1623 if (!mySetRotationPointDlg)
1625 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1626 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1629 if (!mySetRotationPointDlg->isVisible())
1631 //if (mySetRotationPointDlg->IsFirstShown())
1632 if (myCurrPointType == GRAVITY)
1634 Standard_Real Xcenter, Ycenter, Zcenter;
1635 if (computeGravityCenter(Xcenter, Ycenter, Zcenter))
1636 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1638 mySetRotationPointDlg->show();
1643 if (mySetRotationPointDlg->isVisible())
1644 mySetRotationPointDlg->hide();
1649 \brief Create one more window with same content.
1651 void OCCViewer_ViewWindow::onCloneView()
1653 SUIT_ViewWindow* vw = myManager->createViewWindow();
1655 emit viewCloned( vw );
1659 Creates one more window with same content
1661 void OCCViewer_ViewWindow::onAxialScale()
1663 if ( !myScalingDlg )
1664 myScalingDlg = new OCCViewer_AxialScaleDlg( this );
1666 if ( !myScalingDlg->isVisible() )
1668 myScalingDlg->Update();
1669 myScalingDlg->show();
1674 Shows Graduated Axes dialog
1676 void OCCViewer_ViewWindow::onGraduatedAxes()
1678 myCubeAxesDlg->Update();
1679 myCubeAxesDlg->show();
1682 void OCCViewer_ViewWindow::onAmbientToogle()
1684 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
1685 viewer->InitDefinedLights();
1686 while(viewer->MoreDefinedLights())
1688 Handle(V3d_Light) light = viewer->DefinedLight();
1689 if(light->Type() != V3d_AMBIENT)
1691 Handle(V3d_View) aView3d = myViewPort->getView();
1692 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
1693 else viewer->SetLightOn(light);
1695 viewer->NextDefinedLights();
1701 \brief Store view parameters.
1703 void OCCViewer_ViewWindow::onMemorizeView()
1705 appendViewAspect( getViewParams() );
1709 \brief Restore view parameters.
1711 void OCCViewer_ViewWindow::onRestoreView()
1713 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
1714 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
1716 updateViewAspects( aDlg->parameters() );
1717 if( myRestoreFlag && aDlg->parameters().count() )
1718 performRestoring( aDlg->currentItem() );
1722 \brief Restore view parameters.
1723 \param anItem view parameters
1725 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
1727 Handle(V3d_View) aView3d = myViewPort->getView();
1729 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
1730 aView3d->SetScale( anItem.scale );
1731 aView3d->SetTwist( anItem.twist );
1732 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
1733 aView3d->SetImmediateUpdate( prev );
1734 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1735 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1736 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
1738 #if OCC_VERSION_LARGE > 0x06070100
1739 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
1741 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
1743 // "eye" and "at" require conversion to represent center panning
1744 // up direction is only available after setting angle of twist and
1745 // other view parameters
1746 aView3d->Up( anUpX, anUpY, anUpZ );
1748 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
1749 gp_Dir anUp( anUpX, anUpY, anUpZ );
1750 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
1751 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1752 gp_Dir aSide = aProj ^ anUp;
1754 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
1755 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
1757 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
1758 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1761 aView3d->SetCenter( anItem.centerX, anItem.centerY );
1764 if ( !baseParamsOnly ) {
1766 myModel->setTrihedronShown( anItem.isVisible );
1767 myModel->setTrihedronSize( anItem.size );
1769 // graduated trihedron
1770 bool anIsVisible = anItem.gtIsVisible;
1771 OCCViewer_AxisWidget::AxisData anAxisData[3];
1772 anAxisData[0].DrawName = anItem.gtDrawNameX;
1773 anAxisData[1].DrawName = anItem.gtDrawNameZ;
1774 anAxisData[2].DrawName = anItem.gtDrawNameZ;
1775 anAxisData[0].Name = anItem.gtNameX;
1776 anAxisData[1].Name = anItem.gtNameZ;
1777 anAxisData[2].Name = anItem.gtNameZ;
1778 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
1779 anItem.gtNameColorGX,
1780 anItem.gtNameColorBX );
1781 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
1782 anItem.gtNameColorGY,
1783 anItem.gtNameColorBY );
1784 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
1785 anItem.gtNameColorGZ,
1786 anItem.gtNameColorBZ );
1787 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
1788 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
1789 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
1790 anAxisData[0].NbValues = anItem.gtNbValuesX;
1791 anAxisData[1].NbValues = anItem.gtNbValuesY;
1792 anAxisData[2].NbValues = anItem.gtNbValuesZ;
1793 anAxisData[0].Offset = anItem.gtOffsetX;
1794 anAxisData[1].Offset = anItem.gtOffsetY;
1795 anAxisData[2].Offset = anItem.gtOffsetZ;
1796 anAxisData[0].Color = QColor( anItem.gtColorRX,
1799 anAxisData[1].Color = QColor( anItem.gtColorRY,
1802 anAxisData[2].Color = QColor( anItem.gtColorRZ,
1805 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
1806 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
1807 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
1808 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
1809 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
1810 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
1812 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
1813 myCubeAxesDlg->ApplyData( aView3d );
1815 } // if ( !baseParamsOnly )
1821 \brief Set restore flag.
1823 void OCCViewer_ViewWindow::setRestoreFlag()
1829 \brief Called when action "show/hide trihedron" is activated.
1831 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
1833 myModel->setTrihedronShown(show);
1837 \brief Toggles preselection (highlighting) on/off
1839 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
1841 myPreselectionEnabled = on;
1842 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
1844 // unhighlight all highlighted objects
1846 myModel->unHighlightAll( true, false );
1849 // update action state if method is called outside
1850 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
1851 if ( a && a->isChecked() != on ) {
1852 a->setChecked( on );
1857 \brief Toggles selection on/off
1859 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
1861 mySelectionEnabled = on;
1862 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
1864 // update action state if method is called outside
1867 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
1869 a->setEnabled( on );
1873 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
1874 if ( a && a->isChecked() != on ) {
1875 a->setChecked( on );
1880 \brief Switches "keyboard free" interaction style on/off
1882 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
1884 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
1886 // update action state if method is called outside
1887 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
1888 if ( a->isChecked() != on )
1889 a->setChecked( on );
1893 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
1895 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
1897 myViewPort->setAdvancedZoomingEnabled( on );
1899 // update action state if method is called outside
1900 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
1901 if ( a->isChecked() != on )
1902 a->setChecked( on );
1906 \brief Get current interaction style
1907 \return interaction style
1909 int OCCViewer_ViewWindow::interactionStyle() const
1911 return myInteractionStyle;
1915 \brief Set current interaction style
1916 \param theStyle interaction style
1918 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
1920 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
1924 \brief Get current zooming style
1925 \return zooming style
1927 int OCCViewer_ViewWindow::zoomingStyle() const
1929 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
1933 \brief Set current zooming style
1934 \param theStyle zooming style
1936 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
1938 onSwitchZoomingStyle( theStyle == 1 );
1942 \brief Dump view window contents to the pixmap.
1943 \return pixmap containing all scene rendered in the window
1945 QImage OCCViewer_ViewWindow::dumpView()
1947 Handle(V3d_View) view = myViewPort->getView();
1948 if ( view.IsNull() )
1951 int aWidth = myViewPort->width();
1952 int aHeight = myViewPort->height();
1954 // rnv: An old approach to dump the OCCViewer content
1955 // Now used OCCT built-in procedure.
1957 QApplication::syncX();
1958 view->Redraw(); // In order to reactivate GL context
1961 OpenGLUtils_FrameBuffer aFrameBuffer;
1962 if( aFrameBuffer.init( aWidth, aHeight ) )
1964 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
1966 glPushAttrib( GL_VIEWPORT_BIT );
1967 glViewport( 0, 0, aWidth, aHeight );
1968 aFrameBuffer.bind();
1973 aFrameBuffer.unbind();
1976 aFrameBuffer.bind();
1977 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
1978 aFrameBuffer.unbind();
1980 anImage = anImage.rgbSwapped();
1981 anImage = anImage.mirrored();
1984 // if frame buffers are unsupported, use old functionality
1987 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
1989 QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
1991 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
1996 view->ToPixMap(aPix,aWidth, aHeight,Graphic3d_BT_RGBA);
1998 QImage anImage( aPix.Data(), aWidth, aHeight, QImage::Format_ARGB32 );
1999 anImage = anImage.mirrored();
2003 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
2004 const QString& fileName,
2005 const QString& format )
2007 if ( format != "PS" && format != "EPS")
2008 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
2010 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
2013 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
2014 else if (format == "EPS")
2015 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
2021 QString OCCViewer_ViewWindow::filter() const
2023 return tr( "OCC_IMAGE_FILES" );
2028 \brief Set parameters of the cutting plane
2029 \param on if \c true, cutting plane is enabled
2030 \param x X position of plane point
2031 \param y Y position of plane point
2032 \param z Z position of plane point
2033 \param dx X coordinate of plane normal
2034 \param dy Y coordinate of plane normal
2035 \param dz Z coordinate of plane normal
2037 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2038 const double dx, const double dy, const double dz )
2040 Handle(V3d_View) view = myViewPort->getView();
2041 if ( view.IsNull() )
2045 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2047 // try to use already existing plane or create a new one
2048 Handle(V3d_Plane) clipPlane;
2050 // calculate new a,b,c,d values for the plane
2051 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2053 pln.Coefficients(a, b, c, d);
2055 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2056 if(aPlanes.Size() > 0 ) {
2057 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2058 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2059 aClipPlane->SetEquation(pln);
2060 aClipPlane->SetOn(Standard_True);
2062 view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2066 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2067 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2068 for( ;anIter.More();anIter.Next() ){
2069 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2070 aClipPlane->SetOn(Standard_False);
2078 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2080 gp_Dir aDir = pln.Axis().Direction();
2081 gp_Pnt aPnt = pln.Location();
2082 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2087 \brief Check if any cutting plane is enabled
2088 \return \c true if at least one cutting plane is enabled
2090 bool OCCViewer_ViewWindow::isCuttingPlane()
2092 Handle(V3d_View) view = myViewPort->getView();
2094 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2095 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2096 for( ;anIter.More();anIter.Next() ) {
2097 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2098 if(aClipPlane->IsOn()) {
2107 \brief Get the visual parameters of the view window.
2108 \return visual parameters of view window
2110 viewAspect OCCViewer_ViewWindow::getViewParams() const
2112 double projX, projY, projZ, twist;
2113 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2114 double aScaleX, aScaleY, aScaleZ;
2116 Handle(V3d_View) aView3d = myViewPort->getView();
2118 aView3d->Proj( projX, projY, projZ );
2119 aView3d->At( atX, atY, atZ );
2120 aView3d->Eye( eyeX, eyeY, eyeZ );
2121 twist = aView3d->Twist();
2123 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2125 bool isShown = myModel->isTrihedronVisible();
2126 double size = myModel->trihedronSize();
2128 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2131 params.scale = aView3d->Scale();
2132 params.projX = projX;
2133 params.projY = projY;
2134 params.projZ = projZ;
2135 params.twist = twist;
2142 params.scaleX = aScaleX;
2143 params.scaleY = aScaleY;
2144 params.scaleZ = aScaleZ;
2145 params.name = aName;
2146 params.isVisible= isShown;
2149 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2150 aView3d->Center( params.centerX, params.centerY );
2153 // graduated trihedron
2154 bool anIsVisible = false;
2155 OCCViewer_AxisWidget::AxisData anAxisData[3];
2156 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2158 params.gtIsVisible = anIsVisible;
2159 params.gtDrawNameX = anAxisData[0].DrawName;
2160 params.gtDrawNameY = anAxisData[1].DrawName;
2161 params.gtDrawNameZ = anAxisData[2].DrawName;
2162 params.gtNameX = anAxisData[0].Name;
2163 params.gtNameY = anAxisData[1].Name;
2164 params.gtNameZ = anAxisData[2].Name;
2165 params.gtNameColorRX = anAxisData[0].NameColor.red();
2166 params.gtNameColorGX = anAxisData[0].NameColor.green();
2167 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2168 params.gtNameColorRY = anAxisData[1].NameColor.red();
2169 params.gtNameColorGY = anAxisData[1].NameColor.green();
2170 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2171 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2172 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2173 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2174 params.gtDrawValuesX = anAxisData[0].DrawValues;
2175 params.gtDrawValuesY = anAxisData[1].DrawValues;
2176 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2177 params.gtNbValuesX = anAxisData[0].NbValues;
2178 params.gtNbValuesY = anAxisData[1].NbValues;
2179 params.gtNbValuesZ = anAxisData[2].NbValues;
2180 params.gtOffsetX = anAxisData[0].Offset;
2181 params.gtOffsetY = anAxisData[1].Offset;
2182 params.gtOffsetZ = anAxisData[2].Offset;
2183 params.gtColorRX = anAxisData[0].Color.red();
2184 params.gtColorGX = anAxisData[0].Color.green();
2185 params.gtColorBX = anAxisData[0].Color.blue();
2186 params.gtColorRY = anAxisData[1].Color.red();
2187 params.gtColorGY = anAxisData[1].Color.green();
2188 params.gtColorBY = anAxisData[1].Color.blue();
2189 params.gtColorRZ = anAxisData[2].Color.red();
2190 params.gtColorGZ = anAxisData[2].Color.green();
2191 params.gtColorBZ = anAxisData[2].Color.blue();
2192 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2193 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2194 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2195 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2196 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2197 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2203 \brief Get visual parameters of this view window.
2204 \return visual parameters of view window
2206 QString OCCViewer_ViewWindow::getVisualParameters()
2208 viewAspect params = getViewParams();
2212 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2213 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2214 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
2215 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
2217 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2218 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2219 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2220 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2221 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2222 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2223 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2224 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2225 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2226 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2227 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2228 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2229 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2230 data << QString( "isVisible=%1" ).arg( params.isVisible );
2231 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2233 ClipPlanesList aPlanes = myModel->getClipPlanes();
2234 for ( int i=0; i < aPlanes.size(); i++ )
2236 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2237 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2238 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2239 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2240 switch ( aPlane.Mode )
2242 case OCCViewer_ClipPlane::Absolute :
2244 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2246 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2248 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2249 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2250 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2254 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2259 case OCCViewer_ClipPlane::Relative :
2261 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2262 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2263 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2268 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2269 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2270 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2271 data << ClippingPlane;
2274 // graduated trihedron
2275 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2276 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2277 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2278 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2279 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2280 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2281 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2282 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2283 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2284 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2285 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2286 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2287 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2288 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2289 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2290 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2291 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2292 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2293 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2294 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2295 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2296 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2297 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2298 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2299 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2300 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2301 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2302 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2303 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2304 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2305 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2306 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2307 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2308 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2309 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2310 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2311 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2312 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2313 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2314 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2315 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2316 data << QString( "background=%1" ).arg( bg );
2318 return data.join("*");
2322 \brief Restore visual parameters of the view window.
2323 \param parameters visual parameters of view window
2325 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2328 ClipPlanesList aClipPlanes;
2329 QStringList data = parameters.split( '*' );
2330 Qtx::BackgroundData bgData;
2331 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2333 foreach( QString param, data ) {
2334 QString paramName = param.section( '=', 0, 0 ).trimmed();
2335 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2336 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2337 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2338 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2339 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2340 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2341 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2342 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2343 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2344 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2345 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2346 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2347 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2348 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2349 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2350 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2351 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2352 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2353 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2354 else if ( paramName.contains( "ClippingPlane" ) )
2356 QStringList ClipPlaneData = paramValue.split( ';' );
2357 OCCViewer_ClipPlane aPlane;
2358 foreach( QString ClipPlaneParam, ClipPlaneData )
2360 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2361 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2362 if ( ClipPlane_paramName == "Mode" )
2364 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2366 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2367 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2368 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2369 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2372 switch ( aPlane.Mode )
2374 case OCCViewer_ClipPlane::Absolute :
2375 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2376 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2377 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2378 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2379 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2382 case OCCViewer_ClipPlane::Relative :
2383 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2384 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2385 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2390 aClipPlanes.push_back(aPlane);
2392 // graduated trihedron
2393 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2394 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2395 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2396 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2397 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2398 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2399 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2400 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2401 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2402 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2403 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2404 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2405 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2406 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2407 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2408 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2409 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2410 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2411 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2412 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2413 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2414 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2415 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2416 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2417 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2418 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2419 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2420 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2421 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2422 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2423 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2424 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2425 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2426 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2427 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2428 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2429 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2430 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2431 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2432 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2433 else if ( paramName == "background" ) {
2434 QString bg = paramValue.replace( "$", "=" );
2435 bgData = Qtx::stringToBackground( bg );
2439 else // old format - "1.000e+00*0.000e+00..."
2442 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2443 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2444 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2445 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2446 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2447 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2448 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
2449 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2450 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2451 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
2452 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2453 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2454 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2455 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
2456 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
2457 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
2458 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
2459 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
2461 performRestoring( params );
2462 setBackground( bgData );
2463 myModel->setClipPlanes(aClipPlanes);
2467 \brief Handle show event.
2469 Emits Show() signal.
2471 \param theEvent show event
2473 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2475 emit Show( theEvent );
2479 \brief Handle hide event.
2481 Emits Hide() signal.
2483 \param theEvent hide event
2485 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
2487 emit Hide( theEvent );
2492 Creates default sketcher. [ virtual protected ]
2494 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
2497 return new OCCViewer_RectSketcher( this, type );
2498 if ( type == Polygon )
2499 return new OCCViewer_PolygonSketcher( this, type );
2503 void OCCViewer_ViewWindow::initSketchers()
2505 if ( mySketchers.isEmpty() )
2507 mySketchers.append( createSketcher( Rect ) );
2508 mySketchers.append( createSketcher( Polygon ) );
2512 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
2514 OCCViewer_ViewSketcher* sketcher = 0;
2515 QList<OCCViewer_ViewSketcher*>::Iterator it;
2516 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
2518 OCCViewer_ViewSketcher* sk = (*it);
2519 if ( sk->type() == typ )
2526 Handles requests for sketching in the active view. [ virtual public ]
2528 void OCCViewer_ViewWindow::activateSketching( int type )
2530 OCCViewer_ViewPort3d* vp = getViewPort();
2534 if ( !vp->isSketchingEnabled() )
2537 /* Finish current sketching */
2538 if ( type == NoSketching )
2542 onSketchingFinished();
2543 mypSketcher->deactivate();
2547 /* Activate new sketching */
2550 activateSketching( NoSketching ); /* concurrency not suported */
2551 mypSketcher = getSketcher( type );
2554 mypSketcher->activate();
2555 onSketchingStarted();
2561 Unhilights detected entities. [ virtual protected ]
2563 void OCCViewer_ViewWindow::onSketchingStarted()
2568 Selection by rectangle or polygon. [ virtual protected ]
2570 void OCCViewer_ViewWindow::onSketchingFinished()
2572 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
2573 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
2575 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
2576 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
2577 switch( mypSketcher->type() )
2581 QRect* aRect = (QRect*)mypSketcher->data();
2584 int aLeft = aRect->left();
2585 int aRight = aRect->right();
2586 int aTop = aRect->top();
2587 int aBottom = aRect->bottom();
2591 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2593 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2599 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
2602 int size = aPolygon->size();
2603 TColgp_Array1OfPnt2d anArray( 1, size );
2605 QPolygon::Iterator it = aPolygon->begin();
2606 QPolygon::Iterator itEnd = aPolygon->end();
2607 for( int index = 1; it != itEnd; ++it, index++ )
2609 QPoint aPoint = *it;
2610 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
2614 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
2616 ic->Select( anArray, getViewPort()->getView(), Standard_False );
2624 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
2625 aViewMgr->getOCCViewer()->performSelectionChanged();
2629 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
2634 bool OCCViewer_ViewWindow::transformRequested() const
2636 return ( myOperation != NOTHING );
2639 bool OCCViewer_ViewWindow::transformInProcess() const
2641 return myEventStarted;
2644 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
2646 myEventStarted = bOn;
2650 Set enabled state of transformation (rotate, zoom, etc)
2652 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
2654 if ( id != NOTHING ) myStatus.insert( id, on );
2658 \return enabled state of transformation (rotate, zoom, etc)
2660 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
2662 return myStatus.contains( id ) ? myStatus[ id ] : true;
2665 void OCCViewer_ViewWindow::onMaximizedView()
2667 setMaximized(!isMaximized());
2670 void OCCViewer_ViewWindow::returnTo3dView()
2672 setReturnedTo3dView( true );
2675 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
2677 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
2678 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
2679 if ( !isVisible3dView )
2680 toolMgr()->show( ReturnTo3dViewId );
2682 toolMgr()->hide( ReturnTo3dViewId );
2683 if ( isVisible3dView ) emit returnedTo3d( );
2687 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
2689 QAction* anAction = toolMgr()->action( MaximizedId );
2690 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
2691 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
2693 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
2694 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
2695 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
2696 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
2697 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
2699 emit maximized( this, true );
2703 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
2704 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
2705 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
2706 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
2707 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
2709 emit maximized( this, false );
2714 bool OCCViewer_ViewWindow::isMaximized() const
2716 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
2719 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
2721 IsSketcherStyle = enable;
2724 bool OCCViewer_ViewWindow::isSketcherStyle() const
2726 return IsSketcherStyle;
2730 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
2736 QColor OCCViewer_ViewWindow::backgroundColor() const
2738 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
2742 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
2744 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
2747 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
2749 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
2752 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
2754 if ( myViewPort ) myViewPort->setBackground( theBackground );
2757 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
2759 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
2765 void OCCViewer_ViewWindow::clearViewAspects()
2767 myViewAspects.clear();
2771 \return const reference to list of view aspects
2773 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
2775 return myViewAspects;
2779 Appends new view aspect
2780 \param aParams - new view aspects
2782 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
2784 myViewAspects.append( aParams );
2788 Replaces old view aspects by new ones
2789 \param aViewList - list of new view aspects
2791 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
2793 myViewAspects = aViewList;
2797 Get camera properties for the OCC view window.
2798 \return shared pointer on camera properties.
2800 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
2802 SUIT_CameraProperties aProps;
2804 Handle(V3d_View) aSourceView = getViewPort()->getView();
2805 if ( aSourceView.IsNull() )
2808 if ( get2dMode() == No2dMode ) {
2809 aProps.setDimension( SUIT_CameraProperties::Dim3D );
2812 aProps.setDimension( SUIT_CameraProperties::Dim2D );
2813 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
2816 // read common properites of the view
2817 Standard_Real anUp[3];
2818 Standard_Real anAt[3];
2819 Standard_Real anEye[3];
2820 Standard_Real aProj[3];
2821 Standard_Real anAxialScale[3];
2823 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
2824 aSourceView->At( anAt[0], anAt[1], anAt[2] );
2825 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
2826 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2828 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2829 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
2831 #if OCC_VERSION_LARGE > 0x06070100
2832 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
2834 // store camera properties "as is": it is up to synchronized
2835 // view classes to provide necessary property conversion.
2836 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
2837 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
2839 if ( aSourceView->Camera()->IsOrthographic() )
2841 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
2842 aProps.setViewAngle( 0.0 );
2846 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
2847 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
2849 aProps.setMappingScale( aSourceView->Camera()->Scale() );
2851 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
2853 // generate view orientation matrix for transforming OCC projection reference point
2854 // into a camera (eye) position.
2855 gp_Dir aLeftDir = gp_Dir( anUp[0], anUp[1], anUp[2] ) ^ gp_Dir( aProj[0], aProj[1], aProj[2] );
2858 aTrsf.SetValue( 1, 1, aLeftDir.X() );
2859 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
2860 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
2862 aTrsf.SetValue( 1, 2, anUp[0] );
2863 aTrsf.SetValue( 2, 2, anUp[1] );
2864 aTrsf.SetValue( 3, 2, anUp[2] );
2866 aTrsf.SetValue( 1, 3, aProj[0] );
2867 aTrsf.SetValue( 2, 3, aProj[1] );
2868 aTrsf.SetValue( 3, 3, aProj[2] );
2870 aTrsf.SetValue( 1, 4, anAt[0] );
2871 aTrsf.SetValue( 2, 4, anAt[1] );
2872 aTrsf.SetValue( 3, 4, anAt[2] );
2874 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
2876 // transform to world-space coordinate system
2877 gp_XYZ aPosition( aProjRef.X(), aProjRef.Y(), aCameraDepth );
2878 aTrsf.Transforms( aPosition );
2880 // compute focal point
2881 double aFocalPoint[3];
2883 aFocalPoint[0] = aPosition.X() - aProj[0] * aCameraDepth;
2884 aFocalPoint[1] = aPosition.Y() - aProj[1] * aCameraDepth;
2885 aFocalPoint[2] = aPosition.Z() - aProj[2] * aCameraDepth;
2887 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2888 aProps.setPosition( aPosition.X(), aPosition.Y(), aPosition.Z() );
2890 Standard_Real aViewScale[2];
2891 aSourceView->Size( aViewScale[0], aViewScale[1] );
2892 aProps.setMappingScale( aViewScale[1] );
2900 This implementation synchronizes OCC view's camera propreties.
2902 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
2904 bool blocked = blockSignals( true );
2906 SUIT_CameraProperties aProps = theView->cameraProperties();
2907 if ( !cameraProperties().isCompatible( aProps ) ) {
2908 // other view, this one is being currently synchronized to, seems has become incompatible
2909 // we have to break synchronization
2914 Handle(V3d_View) aDestView = getViewPort()->getView();
2916 aDestView->SetImmediateUpdate( Standard_False );
2919 double aPosition[3];
2920 double aFocalPoint[3];
2921 double anAxialScale[3];
2923 // get common properties
2924 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2925 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
2926 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2927 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2929 #if OCC_VERSION_LARGE > 0x06070100
2930 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2931 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
2932 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2933 aDestView->Camera()->SetScale( aProps.getMappingScale() );
2935 gp_Dir aProjDir( aPosition[0] - aFocalPoint[0],
2936 aPosition[1] - aFocalPoint[1],
2937 aPosition[2] - aFocalPoint[2] );
2939 // get custom view translation
2940 Standard_Real aTranslation[3];
2941 aDestView->At( aTranslation[0], aTranslation[1], aTranslation[2] );
2943 gp_Dir aLeftDir = gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] )
2944 ^ gp_Dir( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
2947 aTrsf.SetValue( 1, 1, aLeftDir.X() );
2948 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
2949 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
2951 aTrsf.SetValue( 1, 2, anUpDir[0] );
2952 aTrsf.SetValue( 2, 2, anUpDir[1] );
2953 aTrsf.SetValue( 3, 2, anUpDir[2] );
2955 aTrsf.SetValue( 1, 3, aProjDir.X() );
2956 aTrsf.SetValue( 2, 3, aProjDir.Y() );
2957 aTrsf.SetValue( 3, 3, aProjDir.Z() );
2959 aTrsf.SetValue( 1, 4, aTranslation[0] );
2960 aTrsf.SetValue( 2, 4, aTranslation[1] );
2961 aTrsf.SetValue( 3, 4, aTranslation[2] );
2964 // transform to view-space coordinate system
2965 gp_XYZ aProjRef( aPosition[0], aPosition[1], aPosition[2] );
2966 aTrsf.Transforms( aProjRef );
2968 // set view camera properties using low-level approach. this is done
2969 // in order to avoid interference with static variables in v3d view used
2970 // when rotation is in process in another view.
2971 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
2972 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
2974 Graphic3d_Vector aMappingProj( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
2975 Graphic3d_Vector aMappingUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2977 aMappingProj.Normalize();
2978 aMappingUp.Normalize();
2980 anOrientation.SetViewReferencePlane( aMappingProj );
2981 anOrientation.SetViewReferenceUp( aMappingUp );
2983 aDestView->SetViewMapping( aMapping );
2984 aDestView->SetViewOrientation( anOrientation );
2987 aDestView->SetCenter( aProjRef.X(), aProjRef.Y() );
2989 // set mapping scale
2990 double aMapScaling = aProps.getMappingScale();
2991 Standard_Real aWidth, aHeight;
2992 aDestView->Size( aWidth, aHeight );
2993 aDestView->SetSize ( aWidth > aHeight ? aMapScaling * (aWidth / aHeight) : aMapScaling );
2996 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2998 aDestView->ZFitAll();
2999 aDestView->SetImmediateUpdate( Standard_True );
3000 aDestView->Redraw();
3002 blockSignals( blocked );
3006 \brief Indicates whether preselection is enabled
3007 \return true if preselection is enabled
3009 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
3011 return myPreselectionEnabled;
3015 \brief Enables/disables preselection
3016 \param theIsToEnable if true - preselection will be enabled
3018 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
3020 onSwitchPreselection( theIsToEnable );
3024 \brief Indicates whether selection is enabled
3025 \return true if selection is enabled
3027 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3029 return mySelectionEnabled;
3033 \brief Enables/disables selection
3034 \param theIsToEnable if true - selection will be enabled
3036 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3038 onSwitchSelection( theIsToEnable );
3043 \brief called if clipping operation is activated / deactivated.
3045 Enables/disables clipping plane displaying.
3047 \parma on action state
3049 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3051 if(!myModel) return;
3052 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3055 if (!aClippingDlg) {
3056 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3057 myModel->setClippingDlg(aClippingDlg);
3059 if (!aClippingDlg->isVisible())
3060 aClippingDlg->show();
3062 if ( aClippingDlg ) {
3063 aClippingDlg->close();
3064 myModel->setClippingDlg(0);
3068 SUIT_ViewManager* mgr = getViewManager();
3070 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3071 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3072 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3073 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3075 QAction* a = toolMgr()->action( ClippingId );
3077 if(theIsOn != a->isChecked()){
3078 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3079 a->setChecked(theIsOn);
3080 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));