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;
251 myCursorIsHand = false;
260 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
263 qDeleteAll( mySketchers );
267 \brief Internal initialization.
269 void OCCViewer_ViewWindow::initLayout()
271 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
272 myViewPort->installEventFilter(this);
273 setCentralWidget(myViewPort);
274 myOperation = NOTHING;
276 myCurrPointType = GRAVITY;
277 myPrevPointType = GRAVITY;
278 mySelectedPoint = gp_Pnt(0.,0.,0.);
279 myRotationPointSelection = false;
281 setTransformRequested ( NOTHING );
282 setTransformInProcess ( false );
299 // Graduated axes dialog
300 QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
301 myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
302 myCubeAxesDlg->initialize();
304 connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
307 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
309 return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
313 \brief Detect viewer operation according the the mouse button pressed
314 and key modifiers used.
315 \param theEvent mouse event
316 \return type of the operation
318 OCCViewer_ViewWindow::OperationType
319 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
321 OperationType aOp = NOTHING;
322 SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
323 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
324 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
326 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
327 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
329 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
330 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
331 (my2dMode == No2dMode))
338 \brief Customize event handling
339 \param watched event receiver object
341 \return \c true if the event processing should be stopped
343 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
345 if ( watched == myViewPort ) {
346 int aType = e->type();
348 case QEvent::MouseButtonPress:
349 vpMousePressEvent((QMouseEvent*) e);
352 case QEvent::MouseButtonRelease:
353 vpMouseReleaseEvent((QMouseEvent*) e);
356 case QEvent::MouseMove:
357 vpMouseMoveEvent((QMouseEvent*) e);
360 case QEvent::MouseButtonDblClick:
361 emit mouseDoubleClicked(this, (QMouseEvent*)e);
366 QWheelEvent* aEvent = (QWheelEvent*) e;
368 if ( aEvent->modifiers().testFlag(Qt::ControlModifier) ) {
369 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
370 if ( isPreselectionEnabled() && ic->HasOpenedContext() ) {
371 if ( aEvent->delta() > 0 ) {
372 ic->HilightNextDetected( myViewPort->getView() );
374 ic->HilightPreviousDetected( myViewPort->getView() );
378 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
379 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
382 int x1 = (int)( aEvent->x() + width()*delta/100 );
383 int y1 = (int)( aEvent->y() + height()*delta/100 );
384 myViewPort->zoom( x, y, x1, y1 );
385 myViewPort->getView()->ZFitAll();
390 case QEvent::ContextMenu:
392 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
393 if ( aEvent->reason() != QContextMenuEvent::Mouse )
394 emit contextMenuRequested( aEvent );
398 case QEvent::KeyPress:
399 emit keyPressed(this, (QKeyEvent*) e);
406 return SUIT_ViewWindow::eventFilter(watched, e);
410 \brief Update state of enable draw mode state.
412 void OCCViewer_ViewWindow::updateEnabledDrawMode()
415 myEnableDrawMode = myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
419 \brief Handle mouse press event
420 \param theEvent mouse event
422 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
424 myStartX = theEvent->x();
425 myStartY = theEvent->y();
426 int anInteractionStyle = interactionStyle();
428 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
429 // which are assigned for pan and rotate - these operations are activated immediately after pressing
430 // of the first button, so it is necessary to switch to zoom when the second button is pressed
431 bool aSwitchToZoom = false;
432 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
433 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
434 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
437 switch ( myOperation ) {
439 if ( theEvent->button() == Qt::LeftButton )
440 emit vpTransformationStarted ( WINDOWFIT );
444 if ( theEvent->button() == Qt::LeftButton )
445 emit vpTransformationStarted ( PANGLOBAL );
449 if ( theEvent->button() == Qt::LeftButton ) {
450 myViewPort->startZoomAtPoint( myStartX, myStartY );
451 emit vpTransformationStarted ( ZOOMVIEW );
456 if ( aSwitchToZoom ) {
457 myViewPort->startZoomAtPoint( myStartX, myStartY );
460 else if ( theEvent->button() == Qt::LeftButton )
461 emit vpTransformationStarted ( PANVIEW );
465 if ( aSwitchToZoom ) {
466 myViewPort->startZoomAtPoint( myStartX, myStartY );
469 else if ( theEvent->button() == Qt::LeftButton ) {
470 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
471 emit vpTransformationStarted ( ROTATE );
476 /* Try to activate a transformation */
477 OperationType aState;
478 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
479 aState = getButtonState(theEvent, anInteractionStyle);
481 aState = OCCViewer_ViewWindow::NOTHING;
486 myViewPort->startZoomAtPoint( myStartX, myStartY );
494 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
497 if ( myRotationPointSelection )
499 if ( theEvent->button() == Qt::LeftButton )
501 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
503 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
505 TopoDS_Shape aShape = ic->SelectedShape();
506 GProp_GProps aSystem;
508 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
510 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
512 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE )
514 BRepGProp::LinearProperties( aShape, aSystem );
515 aPnt = aSystem.CentreOfMass();
517 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE )
519 BRepGProp::SurfaceProperties( aShape, aSystem );
520 aPnt = aSystem.CentreOfMass();
522 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID )
524 BRepGProp::VolumeProperties( aShape, aSystem );
525 aPnt = aSystem.CentreOfMass();
529 myCurrPointType = myPrevPointType;
533 if ( mySetRotationPointDlg )
535 myRotationPointSelection = false;
536 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
539 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
540 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
541 ic->CloseAllContexts();
542 myOperation = NOTHING;
543 myViewPort->setCursor( myCursor );
544 myCursorIsHand = false;
545 myRotationPointSelection = false;
549 emit mousePressed(this, theEvent);
552 /* notify that we start a transformation */
553 if ( transformRequested() )
554 emit vpTransformationStarted ( myOperation );
556 if ( transformRequested() )
557 setTransformInProcess( true );
559 /* we may need it for sketching... */
560 if ( l_mbPressEvent )
561 delete l_mbPressEvent;
562 l_mbPressEvent = new QMouseEvent( *theEvent );
567 \brief Start zooming operation.
569 Sets the corresponding cursor for the widget.
571 void OCCViewer_ViewWindow::activateZoom()
573 if ( !transformRequested() && !myCursorIsHand )
574 saveCursor(); /* save old cursor */
576 if ( myOperation != ZOOMVIEW ) {
577 QPixmap zoomPixmap (imageZoomCursor);
578 QCursor zoomCursor (zoomPixmap);
579 if( setTransformRequested ( ZOOMVIEW ) )
580 myViewPort->setCursor( zoomCursor );
586 \brief Start panning operation.
588 Sets the corresponding cursor for the widget.
590 void OCCViewer_ViewWindow::activatePanning()
592 if ( !transformRequested() && !myCursorIsHand )
593 saveCursor(); // save old cursor
595 if ( myOperation != PANVIEW ) {
596 QCursor panCursor (Qt::SizeAllCursor);
597 if( setTransformRequested ( PANVIEW ) )
598 myViewPort->setCursor( panCursor );
603 \brief Start rotation operation
605 Sets the corresponding cursor for the widget.
607 void OCCViewer_ViewWindow::activateRotation()
609 if ( !transformRequested() && !myCursorIsHand )
610 saveCursor(); // save old cursor
612 if ( myOperation != ROTATE ) {
613 QPixmap rotatePixmap (imageRotateCursor);
614 QCursor rotCursor (rotatePixmap);
615 if( setTransformRequested ( ROTATE ) )
616 myViewPort->setCursor( rotCursor );
621 \brief Compute the gravity center.
622 \param theX used to return X coordinate of the gravity center
623 \param theY used to return Y coordinate of the gravity center
624 \param theZ used to return Z coordinate of the gravity center
625 \return \c true if the gravity center is computed
627 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
629 Handle(V3d_View) aView3d = myViewPort->getView();
631 // Project boundaries points and add to avergae gravity
632 // the ones which lie within the screen limits
633 Standard_Real aScreenLimits[4] = { 0.0, 0.0, 0.0, 0.0 };
635 #if OCC_VERSION_LARGE > 0x06070100
636 // NDC space screen limits
637 aScreenLimits[0] = -1.0;
638 aScreenLimits[1] = 1.0;
639 aScreenLimits[2] = -1.0;
640 aScreenLimits[3] = 1.0;
642 aView3d->View()->ViewMapping().WindowLimit( aScreenLimits[0],
648 Standard_Integer aPointsNb = 0;
650 Standard_Real aXmin = 0.0;
651 Standard_Real aYmin = 0.0;
652 Standard_Real aZmin = 0.0;
653 Standard_Real aXmax = 0.0;
654 Standard_Real aYmax = 0.0;
655 Standard_Real aZmax = 0.0;
657 Graphic3d_MapOfStructure aSetOfStructures;
658 aView3d->View()->DisplayedStructures( aSetOfStructures );
659 Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures );
661 for( ; aStructureIt.More(); aStructureIt.Next() ) {
662 const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key();
663 if ( aStructure->IsEmpty() ) {
667 #if OCC_VERSION_LARGE > 0x06070100
668 Bnd_Box aBox = aStructure->MinMaxValues();
669 aXmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().X();
670 aYmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Y();
671 aZmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Z();
672 aXmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().X();
673 aYmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Y();
674 aZmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Z();
676 aStructure->MinMaxValues( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
679 // Infinite structures are skipped
680 Standard_Real aLIM = ShortRealLast() - 1.0;
681 if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
682 || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
686 gp_Pnt aPoints[8] = {
687 gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
688 gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
689 gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
690 gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
693 for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
694 const gp_Pnt& aBBPoint = aPoints[aPointIt];
696 #if OCC_VERSION_LARGE > 0x06070100
697 gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
698 const Standard_Real& U = aProjected.X();
699 const Standard_Real& V = aProjected.Y();
701 Standard_Real U = 0.0;
702 Standard_Real V = 0.0;
703 Standard_Real W = 0.0;
704 aView3d->View()->Projects( aBBPoint.X(), aBBPoint.Y(), aBBPoint.Z(), U, V, W );
707 if (U >= aScreenLimits[0]
708 && U <= aScreenLimits[1]
709 && V >= aScreenLimits[2]
710 && V <= aScreenLimits[3])
713 theX += aBBPoint.X();
714 theY += aBBPoint.Y();
715 theZ += aBBPoint.Z();
730 \brief Set the gravity center as a rotation point.
732 void OCCViewer_ViewWindow::activateSetRotationGravity()
734 if ( myRotationPointSelection )
736 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
737 ic->CloseAllContexts();
738 myOperation = NOTHING;
739 myViewPort->setCursor( myCursor );
740 myCursorIsHand = false;
741 myRotationPointSelection = false;
744 myPrevPointType = myCurrPointType;
745 myCurrPointType = GRAVITY;
747 Standard_Real Xcenter, Ycenter, Zcenter;
748 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
749 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
753 \brief Update gravity center in the "Set Rotation Point" dialog box.
754 \sa OCCViewer_SetRotationPointDlg class
756 void OCCViewer_ViewWindow::updateGravityCoords()
758 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == GRAVITY )
760 Standard_Real Xcenter, Ycenter, Zcenter;
761 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
762 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
767 \brief Set the point selected by the user as a rotation point.
768 \param theX X coordinate of the rotation point
769 \param theY Y coordinate of the rotation point
770 \param theZ Z coordinate of the rotation point
772 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
774 if ( myRotationPointSelection )
776 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
777 ic->CloseAllContexts();
778 myOperation = NOTHING;
779 myViewPort->setCursor( myCursor );
780 myCursorIsHand = false;
781 myRotationPointSelection = false;
784 myPrevPointType = myCurrPointType;
785 myCurrPointType = SELECTED;
786 mySelectedPoint.SetCoord(theX,theY,theZ);
790 \brief Start the shape selection process.
792 void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
794 myPrevPointType = myCurrPointType;
795 myCurrPointType = SELECTED;
797 // activate selection ------>
798 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
800 ic->OpenLocalContext();
802 AIS_ListOfInteractive aList;
803 ic->DisplayedObjects( aList );
804 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
806 Handle(AIS_InteractiveObject) anObj = it.Value();
807 if ( !anObj.IsNull() && anObj->HasPresentation() &&
808 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
811 ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
814 // activate selection <------
816 if ( !myCursorIsHand )
818 QCursor handCursor (Qt::PointingHandCursor);
819 myCursorIsHand = true;
821 myViewPort->setCursor( handCursor );
823 myRotationPointSelection = true;
827 \brief Start global panning operation
829 Sets the corresponding cursor for the widget.
831 void OCCViewer_ViewWindow::activateGlobalPanning()
833 Handle(V3d_View) aView3d = myViewPort->getView();
834 if ( !aView3d.IsNull() ) {
835 QPixmap globalPanPixmap (imageCrossCursor);
836 QCursor glPanCursor (globalPanPixmap);
837 myCurScale = aView3d->Scale();
838 aView3d->FitAll(0.01, false);
839 saveCursor(); // save old cursor
840 myViewPort->fitAll(); // fits view before selecting a new scene center
841 if( setTransformRequested( PANGLOBAL ) )
842 myViewPort->setCursor( glPanCursor );
847 \brief Starts fit operation.
849 Sets the corresponding cursor for the widget.
851 void OCCViewer_ViewWindow::activateWindowFit()
853 if ( !transformRequested() && !myCursorIsHand )
854 saveCursor(); /* save old cursor */
856 if ( myOperation != WINDOWFIT ) {
857 QCursor handCursor (Qt::PointingHandCursor);
858 if( setTransformRequested ( WINDOWFIT ) )
860 myViewPort->setCursor ( handCursor );
861 myCursorIsHand = true;
867 \brief Start delayed viewer operation.
869 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
871 bool ok = transformEnabled( op );
872 myOperation = ok ? op : NOTHING;
873 myViewPort->setMouseTracking( myOperation == NOTHING );
878 \brief Handle mouse move event.
879 \param theEvent mouse event
881 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
883 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
885 switch ( getButtonState( theEvent, interactionStyle() ) ) {
887 myViewPort->startZoomAtPoint( myStartX, myStartY );
895 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
902 myCurrX = theEvent->x();
903 myCurrY = theEvent->y();
904 switch (myOperation) {
906 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
910 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
916 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
930 if ( myRotationPointSelection || isSketcherStyle() )
932 emit mouseMoving( this, theEvent );
936 int aState = theEvent->modifiers();
937 int aButton = theEvent->buttons();
938 int anInteractionStyle = interactionStyle();
939 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
940 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
941 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
942 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
943 myDrawRect = myEnableDrawMode;
946 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
947 QCursor handCursor (Qt::PointingHandCursor);
948 myCursorIsHand = true;
950 myViewPort->setCursor( handCursor );
953 emit mouseMoving( this, theEvent );
955 else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
956 aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
957 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
958 aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
959 OCCViewer_ViewSketcher* sketcher = 0;
960 QList<OCCViewer_ViewSketcher*>::Iterator it;
961 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
963 OCCViewer_ViewSketcher* sk = (*it);
964 if( sk->isDefault() && sk->sketchButton() == aButton )
967 if ( sketcher && myCurSketch == -1 )
969 activateSketching( sketcher->type() );
972 myCurSketch = mypSketcher->sketchButton();
974 if ( l_mbPressEvent )
976 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
977 delete l_mbPressEvent;
980 QApplication::sendEvent( getViewPort(), theEvent );
985 emit mouseMoving( this, theEvent );
991 \brief Handle mouse release event.
992 \param theEvent mouse event
994 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
996 switch ( myOperation ) {
999 int prevState = myCurSketch;
1000 if(theEvent->button() == Qt::RightButton)
1002 QList<OCCViewer_ViewSketcher*>::Iterator it;
1003 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
1005 OCCViewer_ViewSketcher* sk = (*it);
1006 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
1011 emit mouseReleased(this, theEvent);
1012 if(theEvent->button() == Qt::RightButton && prevState == -1)
1014 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1015 theEvent->pos(), theEvent->globalPos() );
1016 emit contextMenuRequested( &aEvent );
1021 myViewPort->endRotation();
1027 myViewPort->getView()->ZFitAll();
1032 if ( theEvent->button() == Qt::LeftButton ) {
1033 myViewPort->setCenter( theEvent->x(), theEvent->y() );
1034 myViewPort->getView()->SetScale(myCurScale);
1040 if ( theEvent->button() == Qt::LeftButton ) {
1041 myCurrX = theEvent->x();
1042 myCurrY = theEvent->y();
1044 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1045 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1052 // NOTE: viewer 3D detects a rectangle of selection using this event
1053 // so we must emit it BEFORE resetting the selection rectangle
1055 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1059 myViewPort->update();
1062 if ( l_mbPressEvent )
1064 delete l_mbPressEvent;
1070 \brief Reset the viewport to its initial state
1071 ( no transformations in process etc. )
1073 void OCCViewer_ViewWindow::resetState()
1077 if ( myRotationPointSelection )
1079 QCursor handCursor (Qt::PointingHandCursor);
1080 myViewPort->setCursor( handCursor );
1084 if ( transformRequested() || myCursorIsHand )
1085 myViewPort->setCursor( myCursor );
1086 myCursorIsHand = false;
1089 if ( transformRequested() )
1090 emit vpTransformationFinished (myOperation);
1092 setTransformInProcess( false );
1093 setTransformRequested( NOTHING );
1098 \brief Draw rubber band rectangle.
1100 void OCCViewer_ViewWindow::drawRect()
1102 if ( !myRectBand ) {
1103 myRectBand = new QtxRectRubberBand( myViewPort );
1105 //palette.setColor(myRectBand->foregroundRole(), Qt::white);
1106 //myRectBand->setPalette(palette);
1108 //myRectBand->hide();
1110 myRectBand->setUpdatesEnabled ( false );
1111 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1112 myRectBand->initGeometry( aRect );
1114 if ( !myRectBand->isVisible() )
1117 myRectBand->setUpdatesEnabled ( true );
1118 //myRectBand->repaint();
1120 //myRectBand->setVisible( aRect.isValid() );
1121 //if ( myRectBand->isVisible() )
1122 // myRectBand->repaint();
1124 // myRectBand->show();
1125 //myRectBand->repaint();
1129 \brief Clear rubber band rectangle on the end on the dragging operation.
1131 void OCCViewer_ViewWindow::endDrawRect()
1133 //delete myRectBand;
1137 myRectBand->clearGeometry();
1143 \brief Create actions.
1145 void OCCViewer_ViewWindow::createActions()
1147 if( !toolMgr()->isEmpty() )
1150 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1157 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1158 tr( "MNU_DUMP_VIEW" ), 0, this);
1159 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1160 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1161 toolMgr()->registerAction( aAction, DumpId );
1164 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1165 tr( "MNU_FITALL" ), 0, this);
1166 aAction->setStatusTip(tr("DSC_FITALL"));
1167 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1168 toolMgr()->registerAction( aAction, FitAllId );
1171 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1172 tr( "MNU_FITRECT" ), 0, this);
1173 aAction->setStatusTip(tr("DSC_FITRECT"));
1174 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1175 toolMgr()->registerAction( aAction, FitRectId );
1178 aAction = new QtxAction(tr("MNU_FITSELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITSELECTION" ) ),
1179 tr( "MNU_FITSELECTION" ), 0, this);
1180 aAction->setStatusTip(tr("DSC_FITSELECTION"));
1181 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
1182 toolMgr()->registerAction( aAction, FitSelectionId );
1185 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1186 tr( "MNU_ZOOM_VIEW" ), 0, this);
1187 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1188 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1189 toolMgr()->registerAction( aAction, ZoomId );
1192 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1193 tr( "MNU_PAN_VIEW" ), 0, this);
1194 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1195 connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
1196 toolMgr()->registerAction( aAction, PanId );
1199 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1200 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1201 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1202 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1203 toolMgr()->registerAction( aAction, GlobalPanId );
1206 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1207 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1208 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1209 mySetRotationPointAction->setCheckable( true );
1210 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1211 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1214 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1215 tr( "MNU_ROTATE_VIEW" ), 0, this);
1216 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1217 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1218 toolMgr()->registerAction( aAction, RotationId );
1221 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1222 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1223 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1224 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1225 this->addAction(aAction);
1226 toolMgr()->registerAction( aAction, FrontId );
1228 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1229 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1230 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1231 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1232 this->addAction(aAction);
1233 toolMgr()->registerAction( aAction, BackId );
1235 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1236 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1237 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1238 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1239 this->addAction(aAction);
1240 toolMgr()->registerAction( aAction, TopId );
1242 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1243 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1244 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1245 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1246 this->addAction(aAction);
1247 toolMgr()->registerAction( aAction, BottomId );
1249 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1250 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1251 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1252 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1253 this->addAction(aAction);
1254 toolMgr()->registerAction( aAction, LeftId );
1256 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1257 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1258 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1259 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1260 this->addAction(aAction);
1261 toolMgr()->registerAction( aAction, RightId );
1263 // rotate anticlockwise
1264 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1265 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1266 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1267 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1268 this->addAction(aAction);
1269 toolMgr()->registerAction( aAction, AntiClockWiseId );
1272 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1273 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1274 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1275 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1276 this->addAction(aAction);
1277 toolMgr()->registerAction( aAction, ClockWiseId );
1280 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1281 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1282 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1283 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1284 this->addAction(aAction);
1285 toolMgr()->registerAction( aAction, ResetId );
1288 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1289 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1290 tr("MNU_CLONE_VIEW"), 0, this);
1291 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1292 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1293 toolMgr()->registerAction( aAction, CloneId );
1295 aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
1296 tr("MNU_CLIPPING"), 0, this);
1297 aAction->setStatusTip (tr("DSC_CLIPPING"));
1298 aAction->setCheckable (true);
1299 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1300 toolMgr()->registerAction (aAction, ClippingId);
1302 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1303 tr( "MNU_SHOOT_VIEW" ), 0, this);
1304 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1305 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1306 toolMgr()->registerAction( aAction, MemId );
1308 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1309 tr( "MNU_PRESETS_VIEW" ), 0, this);
1310 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1311 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1312 toolMgr()->registerAction( aAction, RestoreId );
1314 if (myModel->trihedronActivated()) {
1315 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1316 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1317 aAction->setCheckable( true );
1318 aAction->setChecked( true );
1319 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1320 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1321 toolMgr()->registerAction( aAction, TrihedronShowId );
1325 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1326 tr( "MNU_SCALING" ), 0, this);
1327 aAction->setStatusTip(tr("DSC_SCALING"));
1328 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1329 toolMgr()->registerAction( aAction, AxialScaleId );
1331 // Enable/disable preselection
1332 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1333 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1334 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1335 aAction->setCheckable(true);
1336 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1337 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1339 // Enable/disable selection
1340 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1341 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1342 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1343 aAction->setCheckable(true);
1344 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1345 toolMgr()->registerAction( aAction, SwitchSelectionId );
1348 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1349 tr( "MNU_GRADUATED_AXES" ), 0, this);
1350 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1351 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1352 toolMgr()->registerAction( aAction, GraduatedAxesId );
1354 // Active only ambient light or not
1355 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1356 tr( "MNU_AMBIENT" ), 0, this);
1357 aAction->setStatusTip(tr("DSC_AMBIENT"));
1358 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1359 toolMgr()->registerAction( aAction, AmbientId );
1361 // Switch between interaction styles
1362 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1363 tr( "MNU_STYLE_SWITCH" ), 0, this);
1364 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1365 aAction->setCheckable(true);
1366 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1367 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1369 // Switch between zooming styles
1370 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1371 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1372 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1373 aAction->setCheckable(true);
1374 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1375 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1378 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1379 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1380 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1381 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1382 toolMgr()->registerAction( aAction, MaximizedId );
1384 // Return to 3d view
1385 if (my2dMode!=No2dMode){
1386 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1387 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1388 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1389 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1390 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1394 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1398 \brief Create toolbar.
1400 void OCCViewer_ViewWindow::createToolBar()
1402 static const char* titles[] = {
1403 "LBL_3DTOOLBAR_LABEL",
1404 "LBL_XYTOOLBAR_LABEL",
1405 "LBL_XZTOOLBAR_LABEL",
1406 "LBL_YZTOOLBAR_LABEL",
1408 static const char* names[] = {
1409 "OCCViewer3DViewOperations",
1410 "OCCViewerXYViewOperations",
1411 "OCCViewerXZViewOperations",
1412 "OCCViewerYZViewOperations",
1414 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1415 QString( names[my2dMode] ), // name (language-independant)
1416 false ); // disable floatable toolbar
1417 if ( my2dMode != No2dMode ){
1418 toolMgr()->append( ReturnTo3dViewId, tid );
1419 toolMgr()->append( toolMgr()->separator(), tid );
1421 toolMgr()->append( DumpId, tid );
1422 toolMgr()->append( SwitchInteractionStyleId, tid );
1423 toolMgr()->append( SwitchZoomingStyleId, tid );
1424 toolMgr()->append( SwitchPreselectionId, tid );
1425 toolMgr()->append( SwitchSelectionId, tid );
1426 if( myModel->trihedronActivated() )
1427 toolMgr()->append( TrihedronShowId, tid );
1429 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1430 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1431 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1432 #if OCC_VERSION_LARGE > 0x06090000
1433 aScaleAction->insertAction( toolMgr()->action( FitSelectionId ) );
1435 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1436 toolMgr()->append( aScaleAction, tid );
1438 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1439 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1440 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1441 toolMgr()->append( aPanningAction, tid );
1443 if (my2dMode == No2dMode) {
1444 toolMgr()->append( ChangeRotationPointId, tid );
1445 toolMgr()->append( RotationId, tid );
1447 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1448 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1449 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1450 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1451 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1452 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1453 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1454 toolMgr()->append( aViewsAction, tid );
1456 toolMgr()->append( AntiClockWiseId, tid );
1457 toolMgr()->append( ClockWiseId, tid );
1459 toolMgr()->append( ResetId, tid );
1462 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1463 aMemAction->insertAction( toolMgr()->action( MemId ) );
1464 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1465 toolMgr()->append( aMemAction, tid );
1467 toolMgr()->append( toolMgr()->separator(), tid );
1468 toolMgr()->append( CloneId, tid );
1470 toolMgr()->append( toolMgr()->separator(), tid );
1471 toolMgr()->append( ClippingId, tid );
1472 toolMgr()->append( AxialScaleId, tid );
1473 toolMgr()->append( GraduatedAxesId, tid );
1474 toolMgr()->append( AmbientId, tid );
1476 toolMgr()->append( MaximizedId, tid );
1477 toolMgr()->append( SynchronizeId, tid );
1481 \brief Perform 'fit all' operation.
1483 void OCCViewer_ViewWindow::onViewFitAll()
1485 myViewPort->fitAll();
1489 \brief Perform "front view" transformation.
1491 void OCCViewer_ViewWindow::onFrontView()
1493 emit vpTransformationStarted ( FRONTVIEW );
1494 Handle(V3d_View) aView3d = myViewPort->getView();
1495 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
1497 emit vpTransformationFinished ( FRONTVIEW );
1501 \brief Perform "back view" transformation.
1503 void OCCViewer_ViewWindow::onBackView()
1505 emit vpTransformationStarted ( BACKVIEW );
1506 Handle(V3d_View) aView3d = myViewPort->getView();
1507 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
1509 emit vpTransformationFinished ( BACKVIEW );
1513 \brief Perform "top view" transformation.
1515 void OCCViewer_ViewWindow::onTopView()
1517 emit vpTransformationStarted ( TOPVIEW );
1518 Handle(V3d_View) aView3d = myViewPort->getView();
1519 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
1521 emit vpTransformationFinished ( TOPVIEW );
1525 \brief Perform "bottom view" transformation.
1527 void OCCViewer_ViewWindow::onBottomView()
1529 emit vpTransformationStarted ( BOTTOMVIEW );
1530 Handle(V3d_View) aView3d = myViewPort->getView();
1531 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
1533 emit vpTransformationFinished ( BOTTOMVIEW );
1537 \brief Perform "left view" transformation.
1539 void OCCViewer_ViewWindow::onLeftView()
1541 emit vpTransformationStarted ( LEFTVIEW );
1542 Handle(V3d_View) aView3d = myViewPort->getView();
1543 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
1545 emit vpTransformationFinished ( LEFTVIEW );
1549 \brief Perform "right view" transformation.
1551 void OCCViewer_ViewWindow::onRightView()
1553 emit vpTransformationStarted ( RIGHTVIEW );
1554 Handle(V3d_View) aView3d = myViewPort->getView();
1555 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
1557 emit vpTransformationFinished ( RIGHTVIEW );
1561 \brief Rotate view 90 degrees clockwise
1563 void OCCViewer_ViewWindow::onClockWiseView()
1565 emit vpTransformationStarted ( CLOCKWISEVIEW );
1566 myViewPort->rotateXY( 90. );
1567 emit vpTransformationFinished ( CLOCKWISEVIEW );
1571 \brief Rotate view 90 degrees conterclockwise
1573 void OCCViewer_ViewWindow::onAntiClockWiseView()
1575 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1576 myViewPort->rotateXY( -90. );
1577 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1581 \brief Perform "reset view" transformation.
1583 Sets default orientation of the viewport camera.
1585 void OCCViewer_ViewWindow::onResetView()
1587 emit vpTransformationStarted( RESETVIEW );
1588 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1589 myViewPort->getView()->Reset( false );
1590 myViewPort->fitAll( false, true, false );
1591 myViewPort->getView()->SetImmediateUpdate( upd );
1592 myViewPort->getView()->Update();
1593 emit vpTransformationFinished( RESETVIEW );
1597 \brief Perform "fit all" transformation.
1599 void OCCViewer_ViewWindow::onFitAll()
1601 emit vpTransformationStarted( FITALLVIEW );
1602 myViewPort->fitAll();
1603 emit vpTransformationFinished( FITALLVIEW );
1607 \brief Perform "fit selection" transformation.
1609 void OCCViewer_ViewWindow::onFitSelection()
1611 emit vpTransformationStarted( FITSELECTION );
1612 #if OCC_VERSION_LARGE > 0x06090000
1613 myModel->getAISContext()->FitSelected( getViewPort()->getView() );
1615 emit vpTransformationFinished( FITSELECTION );
1619 \brief Called if 'change rotation point' operation is activated.
1620 \param on action state
1622 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1626 if (!mySetRotationPointDlg)
1628 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1629 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1632 if (!mySetRotationPointDlg->isVisible())
1634 //if (mySetRotationPointDlg->IsFirstShown())
1635 if (myCurrPointType == GRAVITY)
1637 Standard_Real Xcenter, Ycenter, Zcenter;
1638 if (computeGravityCenter(Xcenter, Ycenter, Zcenter))
1639 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1641 mySetRotationPointDlg->show();
1646 if (mySetRotationPointDlg->isVisible())
1647 mySetRotationPointDlg->hide();
1652 \brief Create one more window with same content.
1654 void OCCViewer_ViewWindow::onCloneView()
1656 SUIT_ViewWindow* vw = myManager->createViewWindow();
1658 emit viewCloned( vw );
1662 Creates one more window with same content
1664 void OCCViewer_ViewWindow::onAxialScale()
1666 if ( !myScalingDlg )
1667 myScalingDlg = new OCCViewer_AxialScaleDlg( this );
1669 if ( !myScalingDlg->isVisible() )
1671 myScalingDlg->Update();
1672 myScalingDlg->show();
1677 Shows Graduated Axes dialog
1679 void OCCViewer_ViewWindow::onGraduatedAxes()
1681 myCubeAxesDlg->Update();
1682 myCubeAxesDlg->show();
1685 void OCCViewer_ViewWindow::onAmbientToogle()
1687 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
1688 viewer->InitDefinedLights();
1689 while(viewer->MoreDefinedLights())
1691 Handle(V3d_Light) light = viewer->DefinedLight();
1692 if(light->Type() != V3d_AMBIENT)
1694 Handle(V3d_View) aView3d = myViewPort->getView();
1695 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
1696 else viewer->SetLightOn(light);
1698 viewer->NextDefinedLights();
1704 \brief Store view parameters.
1706 void OCCViewer_ViewWindow::onMemorizeView()
1708 appendViewAspect( getViewParams() );
1712 \brief Restore view parameters.
1714 void OCCViewer_ViewWindow::onRestoreView()
1716 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
1717 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
1719 updateViewAspects( aDlg->parameters() );
1720 if( myRestoreFlag && aDlg->parameters().count() )
1721 performRestoring( aDlg->currentItem() );
1725 \brief Restore view parameters.
1726 \param anItem view parameters
1728 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
1730 Handle(V3d_View) aView3d = myViewPort->getView();
1732 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
1733 aView3d->SetScale( anItem.scale );
1734 aView3d->SetTwist( anItem.twist );
1735 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
1736 aView3d->SetImmediateUpdate( prev );
1737 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1738 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1739 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
1741 #if OCC_VERSION_LARGE > 0x06070100
1742 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
1744 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
1746 // "eye" and "at" require conversion to represent center panning
1747 // up direction is only available after setting angle of twist and
1748 // other view parameters
1749 aView3d->Up( anUpX, anUpY, anUpZ );
1751 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
1752 gp_Dir anUp( anUpX, anUpY, anUpZ );
1753 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
1754 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1755 gp_Dir aSide = aProj ^ anUp;
1757 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
1758 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
1760 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
1761 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1764 aView3d->SetCenter( anItem.centerX, anItem.centerY );
1767 if ( !baseParamsOnly ) {
1769 myModel->setTrihedronShown( anItem.isVisible );
1770 myModel->setTrihedronSize( anItem.size );
1772 // graduated trihedron
1773 bool anIsVisible = anItem.gtIsVisible;
1774 OCCViewer_AxisWidget::AxisData anAxisData[3];
1775 anAxisData[0].DrawName = anItem.gtDrawNameX;
1776 anAxisData[1].DrawName = anItem.gtDrawNameZ;
1777 anAxisData[2].DrawName = anItem.gtDrawNameZ;
1778 anAxisData[0].Name = anItem.gtNameX;
1779 anAxisData[1].Name = anItem.gtNameZ;
1780 anAxisData[2].Name = anItem.gtNameZ;
1781 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
1782 anItem.gtNameColorGX,
1783 anItem.gtNameColorBX );
1784 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
1785 anItem.gtNameColorGY,
1786 anItem.gtNameColorBY );
1787 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
1788 anItem.gtNameColorGZ,
1789 anItem.gtNameColorBZ );
1790 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
1791 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
1792 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
1793 anAxisData[0].NbValues = anItem.gtNbValuesX;
1794 anAxisData[1].NbValues = anItem.gtNbValuesY;
1795 anAxisData[2].NbValues = anItem.gtNbValuesZ;
1796 anAxisData[0].Offset = anItem.gtOffsetX;
1797 anAxisData[1].Offset = anItem.gtOffsetY;
1798 anAxisData[2].Offset = anItem.gtOffsetZ;
1799 anAxisData[0].Color = QColor( anItem.gtColorRX,
1802 anAxisData[1].Color = QColor( anItem.gtColorRY,
1805 anAxisData[2].Color = QColor( anItem.gtColorRZ,
1808 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
1809 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
1810 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
1811 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
1812 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
1813 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
1815 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
1816 myCubeAxesDlg->ApplyData( aView3d );
1818 } // if ( !baseParamsOnly )
1824 \brief Set restore flag.
1826 void OCCViewer_ViewWindow::setRestoreFlag()
1832 \brief Called when action "show/hide trihedron" is activated.
1834 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
1836 myModel->setTrihedronShown(show);
1840 \brief Toggles preselection (highlighting) on/off
1842 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
1844 myPreselectionEnabled = on;
1845 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
1847 // unhighlight all highlighted objects
1849 myModel->unHighlightAll( true, false );
1852 // update action state if method is called outside
1853 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
1854 if ( a && a->isChecked() != on ) {
1855 a->setChecked( on );
1860 \brief Toggles selection on/off
1862 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
1864 mySelectionEnabled = on;
1865 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
1867 // update action state if method is called outside
1870 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
1872 a->setEnabled( on );
1876 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
1877 if ( a && a->isChecked() != on ) {
1878 a->setChecked( on );
1883 \brief Switches "keyboard free" interaction style on/off
1885 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
1887 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
1889 // update action state if method is called outside
1890 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
1891 if ( a && a->isChecked() != on )
1892 a->setChecked( on );
1896 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
1898 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
1900 myViewPort->setAdvancedZoomingEnabled( on );
1902 // update action state if method is called outside
1903 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
1904 if ( a && a->isChecked() != on )
1905 a->setChecked( on );
1909 \brief Get current interaction style
1910 \return interaction style
1912 int OCCViewer_ViewWindow::interactionStyle() const
1914 return myInteractionStyle;
1918 \brief Set current interaction style
1919 \param theStyle interaction style
1921 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
1923 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
1927 \brief Get current zooming style
1928 \return zooming style
1930 int OCCViewer_ViewWindow::zoomingStyle() const
1932 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
1936 \brief Set current zooming style
1937 \param theStyle zooming style
1939 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
1941 onSwitchZoomingStyle( theStyle == 1 );
1945 \brief Dump view window contents to the pixmap.
1946 \return pixmap containing all scene rendered in the window
1948 QImage OCCViewer_ViewWindow::dumpView()
1950 Handle(V3d_View) view = myViewPort->getView();
1951 if ( view.IsNull() )
1954 int aWidth = myViewPort->width();
1955 int aHeight = myViewPort->height();
1957 // rnv: An old approach to dump the OCCViewer content
1958 // Now used OCCT built-in procedure.
1960 QApplication::syncX();
1961 view->Redraw(); // In order to reactivate GL context
1964 OpenGLUtils_FrameBuffer aFrameBuffer;
1965 if( aFrameBuffer.init( aWidth, aHeight ) )
1967 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
1969 glPushAttrib( GL_VIEWPORT_BIT );
1970 glViewport( 0, 0, aWidth, aHeight );
1971 aFrameBuffer.bind();
1976 aFrameBuffer.unbind();
1979 aFrameBuffer.bind();
1980 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
1981 aFrameBuffer.unbind();
1983 anImage = anImage.rgbSwapped();
1984 anImage = anImage.mirrored();
1987 // if frame buffers are unsupported, use old functionality
1990 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
1992 QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
1994 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
1999 view->ToPixMap(aPix,aWidth, aHeight,Graphic3d_BT_RGBA);
2001 QImage anImage( aPix.Data(), aWidth, aHeight, QImage::Format_ARGB32 );
2002 anImage = anImage.mirrored();
2006 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
2007 const QString& fileName,
2008 const QString& format )
2010 if ( format != "PS" && format != "EPS")
2011 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
2013 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
2016 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
2017 else if (format == "EPS")
2018 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
2024 QString OCCViewer_ViewWindow::filter() const
2026 return tr( "OCC_IMAGE_FILES" );
2031 \brief Set parameters of the cutting plane
2032 \param on if \c true, cutting plane is enabled
2033 \param x X position of plane point
2034 \param y Y position of plane point
2035 \param z Z position of plane point
2036 \param dx X coordinate of plane normal
2037 \param dy Y coordinate of plane normal
2038 \param dz Z coordinate of plane normal
2040 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2041 const double dx, const double dy, const double dz )
2043 Handle(V3d_View) view = myViewPort->getView();
2044 if ( view.IsNull() )
2048 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2050 // try to use already existing plane or create a new one
2051 Handle(V3d_Plane) clipPlane;
2053 // calculate new a,b,c,d values for the plane
2054 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2056 pln.Coefficients(a, b, c, d);
2058 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2059 if(aPlanes.Size() > 0 ) {
2060 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2061 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2062 aClipPlane->SetEquation(pln);
2063 aClipPlane->SetOn(Standard_True);
2065 view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2069 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2070 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2071 for( ;anIter.More();anIter.Next() ){
2072 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2073 aClipPlane->SetOn(Standard_False);
2081 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2083 gp_Dir aDir = pln.Axis().Direction();
2084 gp_Pnt aPnt = pln.Location();
2085 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2090 \brief Check if any cutting plane is enabled
2091 \return \c true if at least one cutting plane is enabled
2093 bool OCCViewer_ViewWindow::isCuttingPlane()
2095 Handle(V3d_View) view = myViewPort->getView();
2097 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2098 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2099 for( ;anIter.More();anIter.Next() ) {
2100 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2101 if(aClipPlane->IsOn()) {
2110 \brief Get the visual parameters of the view window.
2111 \return visual parameters of view window
2113 viewAspect OCCViewer_ViewWindow::getViewParams() const
2115 double projX, projY, projZ, twist;
2116 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2117 double aScaleX, aScaleY, aScaleZ;
2119 Handle(V3d_View) aView3d = myViewPort->getView();
2121 aView3d->Proj( projX, projY, projZ );
2122 aView3d->At( atX, atY, atZ );
2123 aView3d->Eye( eyeX, eyeY, eyeZ );
2124 twist = aView3d->Twist();
2126 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2128 bool isShown = myModel->isTrihedronVisible();
2129 double size = myModel->trihedronSize();
2131 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2134 params.scale = aView3d->Scale();
2135 params.projX = projX;
2136 params.projY = projY;
2137 params.projZ = projZ;
2138 params.twist = twist;
2145 params.scaleX = aScaleX;
2146 params.scaleY = aScaleY;
2147 params.scaleZ = aScaleZ;
2148 params.name = aName;
2149 params.isVisible= isShown;
2152 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2153 aView3d->Center( params.centerX, params.centerY );
2156 // graduated trihedron
2157 bool anIsVisible = false;
2158 OCCViewer_AxisWidget::AxisData anAxisData[3];
2159 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2161 params.gtIsVisible = anIsVisible;
2162 params.gtDrawNameX = anAxisData[0].DrawName;
2163 params.gtDrawNameY = anAxisData[1].DrawName;
2164 params.gtDrawNameZ = anAxisData[2].DrawName;
2165 params.gtNameX = anAxisData[0].Name;
2166 params.gtNameY = anAxisData[1].Name;
2167 params.gtNameZ = anAxisData[2].Name;
2168 params.gtNameColorRX = anAxisData[0].NameColor.red();
2169 params.gtNameColorGX = anAxisData[0].NameColor.green();
2170 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2171 params.gtNameColorRY = anAxisData[1].NameColor.red();
2172 params.gtNameColorGY = anAxisData[1].NameColor.green();
2173 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2174 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2175 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2176 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2177 params.gtDrawValuesX = anAxisData[0].DrawValues;
2178 params.gtDrawValuesY = anAxisData[1].DrawValues;
2179 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2180 params.gtNbValuesX = anAxisData[0].NbValues;
2181 params.gtNbValuesY = anAxisData[1].NbValues;
2182 params.gtNbValuesZ = anAxisData[2].NbValues;
2183 params.gtOffsetX = anAxisData[0].Offset;
2184 params.gtOffsetY = anAxisData[1].Offset;
2185 params.gtOffsetZ = anAxisData[2].Offset;
2186 params.gtColorRX = anAxisData[0].Color.red();
2187 params.gtColorGX = anAxisData[0].Color.green();
2188 params.gtColorBX = anAxisData[0].Color.blue();
2189 params.gtColorRY = anAxisData[1].Color.red();
2190 params.gtColorGY = anAxisData[1].Color.green();
2191 params.gtColorBY = anAxisData[1].Color.blue();
2192 params.gtColorRZ = anAxisData[2].Color.red();
2193 params.gtColorGZ = anAxisData[2].Color.green();
2194 params.gtColorBZ = anAxisData[2].Color.blue();
2195 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2196 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2197 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2198 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2199 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2200 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2206 \brief Get visual parameters of this view window.
2207 \return visual parameters of view window
2209 QString OCCViewer_ViewWindow::getVisualParameters()
2211 viewAspect params = getViewParams();
2215 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2216 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2217 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
2218 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
2220 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2221 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2222 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2223 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2224 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2225 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2226 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2227 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2228 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2229 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2230 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2231 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2232 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2233 data << QString( "isVisible=%1" ).arg( params.isVisible );
2234 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2236 ClipPlanesList aPlanes = myModel->getClipPlanes();
2237 for ( int i=0; i < aPlanes.size(); i++ )
2239 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2240 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2241 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2242 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2243 switch ( aPlane.Mode )
2245 case OCCViewer_ClipPlane::Absolute :
2247 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2249 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2251 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2252 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2253 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2257 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2262 case OCCViewer_ClipPlane::Relative :
2264 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2265 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2266 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2271 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2272 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2273 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2274 data << ClippingPlane;
2277 // graduated trihedron
2278 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2279 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2280 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2281 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2282 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2283 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2284 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2285 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2286 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2287 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2288 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2289 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2290 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2291 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2292 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2293 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2294 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2295 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2296 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2297 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2298 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2299 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2300 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2301 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2302 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2303 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2304 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2305 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2306 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2307 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2308 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2309 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2310 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2311 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2312 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2313 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2314 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2315 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2316 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2317 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2318 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2319 data << QString( "background=%1" ).arg( bg );
2321 return data.join("*");
2325 \brief Restore visual parameters of the view window.
2326 \param parameters visual parameters of view window
2328 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2331 ClipPlanesList aClipPlanes;
2332 QStringList data = parameters.split( '*' );
2333 Qtx::BackgroundData bgData;
2334 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2336 foreach( QString param, data ) {
2337 QString paramName = param.section( '=', 0, 0 ).trimmed();
2338 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2339 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2340 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2341 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2342 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2343 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2344 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2345 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2346 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2347 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2348 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2349 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2350 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2351 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2352 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2353 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2354 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2355 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2356 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2357 else if ( paramName.contains( "ClippingPlane" ) )
2359 QStringList ClipPlaneData = paramValue.split( ';' );
2360 OCCViewer_ClipPlane aPlane;
2361 foreach( QString ClipPlaneParam, ClipPlaneData )
2363 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2364 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2365 if ( ClipPlane_paramName == "Mode" )
2367 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2369 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2370 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2371 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2372 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2375 switch ( aPlane.Mode )
2377 case OCCViewer_ClipPlane::Absolute :
2378 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2379 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2380 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2381 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2382 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2385 case OCCViewer_ClipPlane::Relative :
2386 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2387 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2388 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2393 aClipPlanes.push_back(aPlane);
2395 // graduated trihedron
2396 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2397 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2398 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2399 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2400 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2401 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2402 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2403 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2404 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2405 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2406 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2407 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2408 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2409 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2410 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2411 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2412 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2413 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2414 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2415 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2416 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2417 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2418 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2419 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2420 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2421 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2422 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2423 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2424 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2425 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2426 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2427 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2428 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2429 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2430 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2431 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2432 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2433 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2434 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2435 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2436 else if ( paramName == "background" ) {
2437 QString bg = paramValue.replace( "$", "=" );
2438 bgData = Qtx::stringToBackground( bg );
2442 else // old format - "1.000e+00*0.000e+00..."
2445 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2446 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2447 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2448 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2449 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2450 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2451 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
2452 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2453 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2454 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
2455 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2456 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2457 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2458 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
2459 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
2460 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
2461 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
2462 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
2464 performRestoring( params );
2465 setBackground( bgData );
2466 myModel->setClipPlanes(aClipPlanes);
2470 \brief Handle show event.
2472 Emits Show() signal.
2474 \param theEvent show event
2476 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2478 emit Show( theEvent );
2482 \brief Handle hide event.
2484 Emits Hide() signal.
2486 \param theEvent hide event
2488 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
2490 emit Hide( theEvent );
2495 Save old cursor. [ protected ]
2497 void OCCViewer_ViewWindow::saveCursor()
2499 QCursor* aCursor = NULL;
2501 aCursor = myViewPort->getDefaultCursor();
2502 myCursor = ( aCursor ? *aCursor : cursor() );
2507 Creates default sketcher. [ virtual protected ]
2509 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
2512 return new OCCViewer_RectSketcher( this, type );
2513 if ( type == Polygon )
2514 return new OCCViewer_PolygonSketcher( this, type );
2518 void OCCViewer_ViewWindow::initSketchers()
2520 if ( mySketchers.isEmpty() )
2522 mySketchers.append( createSketcher( Rect ) );
2523 mySketchers.append( createSketcher( Polygon ) );
2527 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
2529 OCCViewer_ViewSketcher* sketcher = 0;
2530 QList<OCCViewer_ViewSketcher*>::Iterator it;
2531 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
2533 OCCViewer_ViewSketcher* sk = (*it);
2534 if ( sk->type() == typ )
2541 Handles requests for sketching in the active view. [ virtual public ]
2543 void OCCViewer_ViewWindow::activateSketching( int type )
2545 OCCViewer_ViewPort3d* vp = getViewPort();
2549 if ( !vp->isSketchingEnabled() )
2552 /* Finish current sketching */
2553 if ( type == NoSketching )
2557 onSketchingFinished();
2558 mypSketcher->deactivate();
2562 /* Activate new sketching */
2565 activateSketching( NoSketching ); /* concurrency not suported */
2566 mypSketcher = getSketcher( type );
2569 mypSketcher->activate();
2570 onSketchingStarted();
2576 Unhilights detected entities. [ virtual protected ]
2578 void OCCViewer_ViewWindow::onSketchingStarted()
2583 Selection by rectangle or polygon. [ virtual protected ]
2585 void OCCViewer_ViewWindow::onSketchingFinished()
2587 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
2588 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
2590 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
2591 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
2592 switch( mypSketcher->type() )
2596 QRect* aRect = (QRect*)mypSketcher->data();
2599 int aLeft = aRect->left();
2600 int aRight = aRect->right();
2601 int aTop = aRect->top();
2602 int aBottom = aRect->bottom();
2606 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2608 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2614 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
2617 int size = aPolygon->size();
2618 TColgp_Array1OfPnt2d anArray( 1, size );
2620 QPolygon::Iterator it = aPolygon->begin();
2621 QPolygon::Iterator itEnd = aPolygon->end();
2622 for( int index = 1; it != itEnd; ++it, index++ )
2624 QPoint aPoint = *it;
2625 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
2629 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
2631 ic->Select( anArray, getViewPort()->getView(), Standard_False );
2639 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
2640 aViewMgr->getOCCViewer()->performSelectionChanged();
2644 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
2649 bool OCCViewer_ViewWindow::transformRequested() const
2651 return ( myOperation != NOTHING );
2654 bool OCCViewer_ViewWindow::transformInProcess() const
2656 return myEventStarted;
2659 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
2661 myEventStarted = bOn;
2665 Set enabled state of transformation (rotate, zoom, etc)
2667 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
2669 if ( id != NOTHING ) myStatus.insert( id, on );
2673 \return enabled state of transformation (rotate, zoom, etc)
2675 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
2677 return myStatus.contains( id ) ? myStatus[ id ] : true;
2680 void OCCViewer_ViewWindow::onMaximizedView()
2682 setMaximized(!isMaximized());
2685 void OCCViewer_ViewWindow::returnTo3dView()
2687 setReturnedTo3dView( true );
2690 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
2692 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
2693 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
2694 if ( !isVisible3dView )
2695 toolMgr()->show( ReturnTo3dViewId );
2697 toolMgr()->hide( ReturnTo3dViewId );
2698 if ( isVisible3dView ) emit returnedTo3d( );
2702 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
2704 QAction* anAction = toolMgr()->action( MaximizedId );
2705 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
2706 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
2708 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
2709 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
2710 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
2711 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
2712 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
2714 emit maximized( this, true );
2718 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
2719 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
2720 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
2721 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
2722 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
2724 emit maximized( this, false );
2729 bool OCCViewer_ViewWindow::isMaximized() const
2731 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
2734 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
2736 IsSketcherStyle = enable;
2739 bool OCCViewer_ViewWindow::isSketcherStyle() const
2741 return IsSketcherStyle;
2745 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
2751 QColor OCCViewer_ViewWindow::backgroundColor() const
2753 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
2757 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
2759 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
2762 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
2764 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
2767 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
2769 if ( myViewPort ) myViewPort->setBackground( theBackground );
2772 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
2774 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
2780 void OCCViewer_ViewWindow::clearViewAspects()
2782 myViewAspects.clear();
2786 \return const reference to list of view aspects
2788 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
2790 return myViewAspects;
2794 Appends new view aspect
2795 \param aParams - new view aspects
2797 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
2799 myViewAspects.append( aParams );
2803 Replaces old view aspects by new ones
2804 \param aViewList - list of new view aspects
2806 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
2808 myViewAspects = aViewList;
2812 Get camera properties for the OCC view window.
2813 \return shared pointer on camera properties.
2815 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
2817 SUIT_CameraProperties aProps;
2819 Handle(V3d_View) aSourceView = getViewPort()->getView();
2820 if ( aSourceView.IsNull() )
2823 if ( get2dMode() == No2dMode ) {
2824 aProps.setDimension( SUIT_CameraProperties::Dim3D );
2827 aProps.setDimension( SUIT_CameraProperties::Dim2D );
2828 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
2831 // read common properites of the view
2832 Standard_Real anUp[3];
2833 Standard_Real anAt[3];
2834 Standard_Real anEye[3];
2835 Standard_Real aProj[3];
2836 Standard_Real anAxialScale[3];
2838 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
2839 aSourceView->At( anAt[0], anAt[1], anAt[2] );
2840 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
2841 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2843 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2844 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
2846 #if OCC_VERSION_LARGE > 0x06070100
2847 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
2849 // store camera properties "as is": it is up to synchronized
2850 // view classes to provide necessary property conversion.
2851 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
2852 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
2854 if ( aSourceView->Camera()->IsOrthographic() )
2856 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
2857 aProps.setViewAngle( 0.0 );
2861 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
2862 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
2864 aProps.setMappingScale( aSourceView->Camera()->Scale() );
2866 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
2868 // generate view orientation matrix for transforming OCC projection reference point
2869 // into a camera (eye) position.
2870 gp_Dir aLeftDir = gp_Dir( anUp[0], anUp[1], anUp[2] ) ^ gp_Dir( aProj[0], aProj[1], aProj[2] );
2873 aTrsf.SetValue( 1, 1, aLeftDir.X() );
2874 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
2875 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
2877 aTrsf.SetValue( 1, 2, anUp[0] );
2878 aTrsf.SetValue( 2, 2, anUp[1] );
2879 aTrsf.SetValue( 3, 2, anUp[2] );
2881 aTrsf.SetValue( 1, 3, aProj[0] );
2882 aTrsf.SetValue( 2, 3, aProj[1] );
2883 aTrsf.SetValue( 3, 3, aProj[2] );
2885 aTrsf.SetValue( 1, 4, anAt[0] );
2886 aTrsf.SetValue( 2, 4, anAt[1] );
2887 aTrsf.SetValue( 3, 4, anAt[2] );
2889 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
2891 // transform to world-space coordinate system
2892 gp_XYZ aPosition( aProjRef.X(), aProjRef.Y(), aCameraDepth );
2893 aTrsf.Transforms( aPosition );
2895 // compute focal point
2896 double aFocalPoint[3];
2898 aFocalPoint[0] = aPosition.X() - aProj[0] * aCameraDepth;
2899 aFocalPoint[1] = aPosition.Y() - aProj[1] * aCameraDepth;
2900 aFocalPoint[2] = aPosition.Z() - aProj[2] * aCameraDepth;
2902 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2903 aProps.setPosition( aPosition.X(), aPosition.Y(), aPosition.Z() );
2905 Standard_Real aViewScale[2];
2906 aSourceView->Size( aViewScale[0], aViewScale[1] );
2907 aProps.setMappingScale( aViewScale[1] );
2915 This implementation synchronizes OCC view's camera propreties.
2917 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
2919 bool blocked = blockSignals( true );
2921 SUIT_CameraProperties aProps = theView->cameraProperties();
2922 if ( !cameraProperties().isCompatible( aProps ) ) {
2923 // other view, this one is being currently synchronized to, seems has become incompatible
2924 // we have to break synchronization
2929 Handle(V3d_View) aDestView = getViewPort()->getView();
2931 aDestView->SetImmediateUpdate( Standard_False );
2934 double aPosition[3];
2935 double aFocalPoint[3];
2936 double anAxialScale[3];
2938 // get common properties
2939 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2940 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
2941 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2942 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2944 #if OCC_VERSION_LARGE > 0x06070100
2945 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2946 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
2947 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2948 aDestView->Camera()->SetScale( aProps.getMappingScale() );
2950 gp_Dir aProjDir( aPosition[0] - aFocalPoint[0],
2951 aPosition[1] - aFocalPoint[1],
2952 aPosition[2] - aFocalPoint[2] );
2954 // get custom view translation
2955 Standard_Real aTranslation[3];
2956 aDestView->At( aTranslation[0], aTranslation[1], aTranslation[2] );
2958 gp_Dir aLeftDir = gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] )
2959 ^ gp_Dir( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
2962 aTrsf.SetValue( 1, 1, aLeftDir.X() );
2963 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
2964 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
2966 aTrsf.SetValue( 1, 2, anUpDir[0] );
2967 aTrsf.SetValue( 2, 2, anUpDir[1] );
2968 aTrsf.SetValue( 3, 2, anUpDir[2] );
2970 aTrsf.SetValue( 1, 3, aProjDir.X() );
2971 aTrsf.SetValue( 2, 3, aProjDir.Y() );
2972 aTrsf.SetValue( 3, 3, aProjDir.Z() );
2974 aTrsf.SetValue( 1, 4, aTranslation[0] );
2975 aTrsf.SetValue( 2, 4, aTranslation[1] );
2976 aTrsf.SetValue( 3, 4, aTranslation[2] );
2979 // transform to view-space coordinate system
2980 gp_XYZ aProjRef( aPosition[0], aPosition[1], aPosition[2] );
2981 aTrsf.Transforms( aProjRef );
2983 // set view camera properties using low-level approach. this is done
2984 // in order to avoid interference with static variables in v3d view used
2985 // when rotation is in process in another view.
2986 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
2987 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
2989 Graphic3d_Vector aMappingProj( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
2990 Graphic3d_Vector aMappingUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2992 aMappingProj.Normalize();
2993 aMappingUp.Normalize();
2995 anOrientation.SetViewReferencePlane( aMappingProj );
2996 anOrientation.SetViewReferenceUp( aMappingUp );
2998 aDestView->SetViewMapping( aMapping );
2999 aDestView->SetViewOrientation( anOrientation );
3002 aDestView->SetCenter( aProjRef.X(), aProjRef.Y() );
3004 // set mapping scale
3005 double aMapScaling = aProps.getMappingScale();
3006 Standard_Real aWidth, aHeight;
3007 aDestView->Size( aWidth, aHeight );
3008 aDestView->SetSize ( aWidth > aHeight ? aMapScaling * (aWidth / aHeight) : aMapScaling );
3011 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3013 aDestView->ZFitAll();
3014 aDestView->SetImmediateUpdate( Standard_True );
3015 aDestView->Redraw();
3017 blockSignals( blocked );
3021 \brief Indicates whether preselection is enabled
3022 \return true if preselection is enabled
3024 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
3026 return myPreselectionEnabled;
3030 \brief Enables/disables preselection
3031 \param theIsToEnable if true - preselection will be enabled
3033 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
3035 onSwitchPreselection( theIsToEnable );
3039 \brief Indicates whether selection is enabled
3040 \return true if selection is enabled
3042 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3044 return mySelectionEnabled;
3048 \brief Enables/disables selection
3049 \param theIsToEnable if true - selection will be enabled
3051 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3053 onSwitchSelection( theIsToEnable );
3058 \brief called if clipping operation is activated / deactivated.
3060 Enables/disables clipping plane displaying.
3062 \parma on action state
3064 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3066 if(!myModel) return;
3067 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3070 if (!aClippingDlg) {
3071 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3072 myModel->setClippingDlg(aClippingDlg);
3074 if (!aClippingDlg->isVisible())
3075 aClippingDlg->show();
3077 if ( aClippingDlg ) {
3078 aClippingDlg->close();
3079 myModel->setClippingDlg(0);
3083 SUIT_ViewManager* mgr = getViewManager();
3085 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3086 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3087 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3088 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3090 QAction* a = toolMgr()->action( ClippingId );
3092 if(theIsOn != a->isChecked()){
3093 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3094 a->setChecked(theIsOn);
3095 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));