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();
1155 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1156 tr( "MNU_DUMP_VIEW" ), 0, this);
1157 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1158 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1159 toolMgr()->registerAction( aAction, DumpId );
1162 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1163 tr( "MNU_FITALL" ), 0, this);
1164 aAction->setStatusTip(tr("DSC_FITALL"));
1165 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1166 toolMgr()->registerAction( aAction, FitAllId );
1169 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1170 tr( "MNU_FITRECT" ), 0, this);
1171 aAction->setStatusTip(tr("DSC_FITRECT"));
1172 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1173 toolMgr()->registerAction( aAction, FitRectId );
1176 aAction = new QtxAction(tr("MNU_FITSELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITSELECTION" ) ),
1177 tr( "MNU_FITSELECTION" ), 0, this);
1178 aAction->setStatusTip(tr("DSC_FITSELECTION"));
1179 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
1180 toolMgr()->registerAction( aAction, FitSelectionId );
1183 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1184 tr( "MNU_ZOOM_VIEW" ), 0, this);
1185 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1186 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1187 toolMgr()->registerAction( aAction, ZoomId );
1190 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1191 tr( "MNU_PAN_VIEW" ), 0, this);
1192 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1193 connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
1194 toolMgr()->registerAction( aAction, PanId );
1197 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1198 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1199 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1200 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1201 toolMgr()->registerAction( aAction, GlobalPanId );
1204 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1205 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1206 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1207 mySetRotationPointAction->setCheckable( true );
1208 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1209 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1212 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1213 tr( "MNU_ROTATE_VIEW" ), 0, this);
1214 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1215 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1216 toolMgr()->registerAction( aAction, RotationId );
1219 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1220 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1221 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1222 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1223 this->addAction(aAction);
1224 toolMgr()->registerAction( aAction, FrontId );
1226 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1227 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1228 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1229 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1230 this->addAction(aAction);
1231 toolMgr()->registerAction( aAction, BackId );
1233 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1234 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1235 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1236 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1237 this->addAction(aAction);
1238 toolMgr()->registerAction( aAction, TopId );
1240 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1241 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1242 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1243 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1244 this->addAction(aAction);
1245 toolMgr()->registerAction( aAction, BottomId );
1247 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1248 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1249 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1250 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1251 this->addAction(aAction);
1252 toolMgr()->registerAction( aAction, LeftId );
1254 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1255 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1256 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1257 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1258 this->addAction(aAction);
1259 toolMgr()->registerAction( aAction, RightId );
1261 // rotate anticlockwise
1262 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1263 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1264 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1265 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1266 this->addAction(aAction);
1267 toolMgr()->registerAction( aAction, AntiClockWiseId );
1270 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1271 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1272 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1273 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1274 this->addAction(aAction);
1275 toolMgr()->registerAction( aAction, ClockWiseId );
1278 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1279 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1280 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1281 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1282 this->addAction(aAction);
1283 toolMgr()->registerAction( aAction, ResetId );
1286 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1287 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1288 tr("MNU_CLONE_VIEW"), 0, this);
1289 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1290 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1291 toolMgr()->registerAction( aAction, CloneId );
1293 aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
1294 tr("MNU_CLIPPING"), 0, this);
1295 aAction->setStatusTip (tr("DSC_CLIPPING"));
1296 aAction->setCheckable (true);
1297 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1298 toolMgr()->registerAction (aAction, ClippingId);
1300 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1301 tr( "MNU_SHOOT_VIEW" ), 0, this);
1302 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1303 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1304 toolMgr()->registerAction( aAction, MemId );
1306 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1307 tr( "MNU_PRESETS_VIEW" ), 0, this);
1308 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1309 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1310 toolMgr()->registerAction( aAction, RestoreId );
1312 if (myModel->trihedronActivated()) {
1313 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1314 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1315 aAction->setCheckable( true );
1316 aAction->setChecked( true );
1317 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1318 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1319 toolMgr()->registerAction( aAction, TrihedronShowId );
1323 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1324 tr( "MNU_SCALING" ), 0, this);
1325 aAction->setStatusTip(tr("DSC_SCALING"));
1326 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1327 toolMgr()->registerAction( aAction, AxialScaleId );
1329 // Enable/disable preselection
1330 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1331 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1332 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1333 aAction->setCheckable(true);
1334 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1335 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1337 // Enable/disable selection
1338 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1339 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1340 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1341 aAction->setCheckable(true);
1342 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1343 toolMgr()->registerAction( aAction, SwitchSelectionId );
1346 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1347 tr( "MNU_GRADUATED_AXES" ), 0, this);
1348 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1349 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1350 toolMgr()->registerAction( aAction, GraduatedAxesId );
1352 // Active only ambient light or not
1353 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1354 tr( "MNU_AMBIENT" ), 0, this);
1355 aAction->setStatusTip(tr("DSC_AMBIENT"));
1356 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1357 toolMgr()->registerAction( aAction, AmbientId );
1359 // Switch between interaction styles
1360 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1361 tr( "MNU_STYLE_SWITCH" ), 0, this);
1362 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1363 aAction->setCheckable(true);
1364 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1365 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1367 // Switch between zooming styles
1368 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1369 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1370 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1371 aAction->setCheckable(true);
1372 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1373 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1376 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1377 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1378 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1379 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1380 toolMgr()->registerAction( aAction, MaximizedId );
1382 // Return to 3d view
1383 if (my2dMode!=No2dMode){
1384 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1385 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1386 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1387 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1388 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1392 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1396 \brief Create toolbar.
1398 void OCCViewer_ViewWindow::createToolBar()
1400 static const char* titles[] = {
1401 "LBL_3DTOOLBAR_LABEL",
1402 "LBL_XYTOOLBAR_LABEL",
1403 "LBL_XZTOOLBAR_LABEL",
1404 "LBL_YZTOOLBAR_LABEL",
1406 static const char* names[] = {
1407 "OCCViewer3DViewOperations",
1408 "OCCViewerXYViewOperations",
1409 "OCCViewerXZViewOperations",
1410 "OCCViewerYZViewOperations",
1412 int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ), // title (language-dependant)
1413 QString( names[my2dMode] ), // name (language-independant)
1414 false ); // disable floatable toolbar
1415 if ( my2dMode != No2dMode ){
1416 toolMgr()->append( ReturnTo3dViewId, tid );
1417 toolMgr()->append( toolMgr()->separator(), tid );
1419 toolMgr()->append( DumpId, tid );
1420 toolMgr()->append( SwitchInteractionStyleId, tid );
1421 toolMgr()->append( SwitchZoomingStyleId, tid );
1422 toolMgr()->append( SwitchPreselectionId, tid );
1423 toolMgr()->append( SwitchSelectionId, tid );
1424 if( myModel->trihedronActivated() )
1425 toolMgr()->append( TrihedronShowId, tid );
1427 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1428 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1429 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1430 #if OCC_VERSION_LARGE > 0x06090000
1431 aScaleAction->insertAction( toolMgr()->action( FitSelectionId ) );
1433 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1434 toolMgr()->append( aScaleAction, tid );
1436 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1437 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1438 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1439 toolMgr()->append( aPanningAction, tid );
1441 if (my2dMode == No2dMode) {
1442 toolMgr()->append( ChangeRotationPointId, tid );
1443 toolMgr()->append( RotationId, tid );
1445 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1446 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1447 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1448 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1449 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1450 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1451 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1452 toolMgr()->append( aViewsAction, tid );
1454 toolMgr()->append( AntiClockWiseId, tid );
1455 toolMgr()->append( ClockWiseId, tid );
1457 toolMgr()->append( ResetId, tid );
1460 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1461 aMemAction->insertAction( toolMgr()->action( MemId ) );
1462 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1463 toolMgr()->append( aMemAction, tid );
1465 toolMgr()->append( toolMgr()->separator(), tid );
1466 toolMgr()->append( CloneId, tid );
1468 toolMgr()->append( toolMgr()->separator(), tid );
1469 toolMgr()->append( ClippingId, tid );
1470 toolMgr()->append( AxialScaleId, tid );
1471 toolMgr()->append( GraduatedAxesId, tid );
1472 toolMgr()->append( AmbientId, tid );
1474 toolMgr()->append( MaximizedId, tid );
1475 toolMgr()->append( SynchronizeId, tid );
1479 \brief Perform 'fit all' operation.
1481 void OCCViewer_ViewWindow::onViewFitAll()
1483 myViewPort->fitAll();
1487 \brief Perform "front view" transformation.
1489 void OCCViewer_ViewWindow::onFrontView()
1491 emit vpTransformationStarted ( FRONTVIEW );
1492 Handle(V3d_View) aView3d = myViewPort->getView();
1493 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
1495 emit vpTransformationFinished ( FRONTVIEW );
1499 \brief Perform "back view" transformation.
1501 void OCCViewer_ViewWindow::onBackView()
1503 emit vpTransformationStarted ( BACKVIEW );
1504 Handle(V3d_View) aView3d = myViewPort->getView();
1505 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
1507 emit vpTransformationFinished ( BACKVIEW );
1511 \brief Perform "top view" transformation.
1513 void OCCViewer_ViewWindow::onTopView()
1515 emit vpTransformationStarted ( TOPVIEW );
1516 Handle(V3d_View) aView3d = myViewPort->getView();
1517 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
1519 emit vpTransformationFinished ( TOPVIEW );
1523 \brief Perform "bottom view" transformation.
1525 void OCCViewer_ViewWindow::onBottomView()
1527 emit vpTransformationStarted ( BOTTOMVIEW );
1528 Handle(V3d_View) aView3d = myViewPort->getView();
1529 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
1531 emit vpTransformationFinished ( BOTTOMVIEW );
1535 \brief Perform "left view" transformation.
1537 void OCCViewer_ViewWindow::onLeftView()
1539 emit vpTransformationStarted ( LEFTVIEW );
1540 Handle(V3d_View) aView3d = myViewPort->getView();
1541 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
1543 emit vpTransformationFinished ( LEFTVIEW );
1547 \brief Perform "right view" transformation.
1549 void OCCViewer_ViewWindow::onRightView()
1551 emit vpTransformationStarted ( RIGHTVIEW );
1552 Handle(V3d_View) aView3d = myViewPort->getView();
1553 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
1555 emit vpTransformationFinished ( RIGHTVIEW );
1559 \brief Rotate view 90 degrees clockwise
1561 void OCCViewer_ViewWindow::onClockWiseView()
1563 emit vpTransformationStarted ( CLOCKWISEVIEW );
1564 myViewPort->rotateXY( 90. );
1565 emit vpTransformationFinished ( CLOCKWISEVIEW );
1569 \brief Rotate view 90 degrees conterclockwise
1571 void OCCViewer_ViewWindow::onAntiClockWiseView()
1573 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1574 myViewPort->rotateXY( -90. );
1575 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1579 \brief Perform "reset view" transformation.
1581 Sets default orientation of the viewport camera.
1583 void OCCViewer_ViewWindow::onResetView()
1585 emit vpTransformationStarted( RESETVIEW );
1586 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1587 myViewPort->getView()->Reset( false );
1588 myViewPort->fitAll( false, true, false );
1589 myViewPort->getView()->SetImmediateUpdate( upd );
1590 myViewPort->getView()->Update();
1591 emit vpTransformationFinished( RESETVIEW );
1595 \brief Perform "fit all" transformation.
1597 void OCCViewer_ViewWindow::onFitAll()
1599 emit vpTransformationStarted( FITALLVIEW );
1600 myViewPort->fitAll();
1601 emit vpTransformationFinished( FITALLVIEW );
1605 \brief Perform "fit selection" transformation.
1607 void OCCViewer_ViewWindow::onFitSelection()
1609 emit vpTransformationStarted( FITSELECTION );
1610 #if OCC_VERSION_LARGE > 0x06090000
1611 myModel->getAISContext()->FitSelected( getViewPort()->getView() );
1613 emit vpTransformationFinished( FITSELECTION );
1617 \brief Called if 'change rotation point' operation is activated.
1618 \param on action state
1620 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1624 if (!mySetRotationPointDlg)
1626 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1627 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1630 if (!mySetRotationPointDlg->isVisible())
1632 //if (mySetRotationPointDlg->IsFirstShown())
1633 if (myCurrPointType == GRAVITY)
1635 Standard_Real Xcenter, Ycenter, Zcenter;
1636 if (computeGravityCenter(Xcenter, Ycenter, Zcenter))
1637 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1639 mySetRotationPointDlg->show();
1644 if (mySetRotationPointDlg->isVisible())
1645 mySetRotationPointDlg->hide();
1650 \brief Create one more window with same content.
1652 void OCCViewer_ViewWindow::onCloneView()
1654 SUIT_ViewWindow* vw = myManager->createViewWindow();
1656 emit viewCloned( vw );
1660 Creates one more window with same content
1662 void OCCViewer_ViewWindow::onAxialScale()
1664 if ( !myScalingDlg )
1665 myScalingDlg = new OCCViewer_AxialScaleDlg( this );
1667 if ( !myScalingDlg->isVisible() )
1669 myScalingDlg->Update();
1670 myScalingDlg->show();
1675 Shows Graduated Axes dialog
1677 void OCCViewer_ViewWindow::onGraduatedAxes()
1679 myCubeAxesDlg->Update();
1680 myCubeAxesDlg->show();
1683 void OCCViewer_ViewWindow::onAmbientToogle()
1685 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
1686 viewer->InitDefinedLights();
1687 while(viewer->MoreDefinedLights())
1689 Handle(V3d_Light) light = viewer->DefinedLight();
1690 if(light->Type() != V3d_AMBIENT)
1692 Handle(V3d_View) aView3d = myViewPort->getView();
1693 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
1694 else viewer->SetLightOn(light);
1696 viewer->NextDefinedLights();
1702 \brief Store view parameters.
1704 void OCCViewer_ViewWindow::onMemorizeView()
1706 appendViewAspect( getViewParams() );
1710 \brief Restore view parameters.
1712 void OCCViewer_ViewWindow::onRestoreView()
1714 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
1715 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
1717 updateViewAspects( aDlg->parameters() );
1718 if( myRestoreFlag && aDlg->parameters().count() )
1719 performRestoring( aDlg->currentItem() );
1723 \brief Restore view parameters.
1724 \param anItem view parameters
1726 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
1728 Handle(V3d_View) aView3d = myViewPort->getView();
1730 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
1731 aView3d->SetScale( anItem.scale );
1732 aView3d->SetTwist( anItem.twist );
1733 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
1734 aView3d->SetImmediateUpdate( prev );
1735 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1736 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1737 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
1739 #if OCC_VERSION_LARGE > 0x06070100
1740 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
1742 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
1744 // "eye" and "at" require conversion to represent center panning
1745 // up direction is only available after setting angle of twist and
1746 // other view parameters
1747 aView3d->Up( anUpX, anUpY, anUpZ );
1749 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
1750 gp_Dir anUp( anUpX, anUpY, anUpZ );
1751 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
1752 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1753 gp_Dir aSide = aProj ^ anUp;
1755 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
1756 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
1758 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
1759 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1762 aView3d->SetCenter( anItem.centerX, anItem.centerY );
1765 if ( !baseParamsOnly ) {
1767 myModel->setTrihedronShown( anItem.isVisible );
1768 myModel->setTrihedronSize( anItem.size );
1770 // graduated trihedron
1771 bool anIsVisible = anItem.gtIsVisible;
1772 OCCViewer_AxisWidget::AxisData anAxisData[3];
1773 anAxisData[0].DrawName = anItem.gtDrawNameX;
1774 anAxisData[1].DrawName = anItem.gtDrawNameZ;
1775 anAxisData[2].DrawName = anItem.gtDrawNameZ;
1776 anAxisData[0].Name = anItem.gtNameX;
1777 anAxisData[1].Name = anItem.gtNameZ;
1778 anAxisData[2].Name = anItem.gtNameZ;
1779 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
1780 anItem.gtNameColorGX,
1781 anItem.gtNameColorBX );
1782 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
1783 anItem.gtNameColorGY,
1784 anItem.gtNameColorBY );
1785 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
1786 anItem.gtNameColorGZ,
1787 anItem.gtNameColorBZ );
1788 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
1789 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
1790 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
1791 anAxisData[0].NbValues = anItem.gtNbValuesX;
1792 anAxisData[1].NbValues = anItem.gtNbValuesY;
1793 anAxisData[2].NbValues = anItem.gtNbValuesZ;
1794 anAxisData[0].Offset = anItem.gtOffsetX;
1795 anAxisData[1].Offset = anItem.gtOffsetY;
1796 anAxisData[2].Offset = anItem.gtOffsetZ;
1797 anAxisData[0].Color = QColor( anItem.gtColorRX,
1800 anAxisData[1].Color = QColor( anItem.gtColorRY,
1803 anAxisData[2].Color = QColor( anItem.gtColorRZ,
1806 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
1807 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
1808 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
1809 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
1810 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
1811 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
1813 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
1814 myCubeAxesDlg->ApplyData( aView3d );
1816 } // if ( !baseParamsOnly )
1822 \brief Set restore flag.
1824 void OCCViewer_ViewWindow::setRestoreFlag()
1830 \brief Called when action "show/hide trihedron" is activated.
1832 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
1834 myModel->setTrihedronShown(show);
1838 \brief Toggles preselection (highlighting) on/off
1840 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
1842 myPreselectionEnabled = on;
1843 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
1845 // unhighlight all highlighted objects
1847 myModel->unHighlightAll( true, false );
1850 // update action state if method is called outside
1851 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
1852 if ( a && a->isChecked() != on ) {
1853 a->setChecked( on );
1858 \brief Toggles selection on/off
1860 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
1862 mySelectionEnabled = on;
1863 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
1865 // update action state if method is called outside
1868 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
1870 a->setEnabled( on );
1874 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
1875 if ( a && a->isChecked() != on ) {
1876 a->setChecked( on );
1881 \brief Switches "keyboard free" interaction style on/off
1883 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
1885 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
1887 // update action state if method is called outside
1888 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
1889 if ( a->isChecked() != on )
1890 a->setChecked( on );
1894 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
1896 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
1898 myViewPort->setAdvancedZoomingEnabled( on );
1900 // update action state if method is called outside
1901 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
1902 if ( a->isChecked() != on )
1903 a->setChecked( on );
1907 \brief Get current interaction style
1908 \return interaction style
1910 int OCCViewer_ViewWindow::interactionStyle() const
1912 return myInteractionStyle;
1916 \brief Set current interaction style
1917 \param theStyle interaction style
1919 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
1921 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
1925 \brief Get current zooming style
1926 \return zooming style
1928 int OCCViewer_ViewWindow::zoomingStyle() const
1930 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
1934 \brief Set current zooming style
1935 \param theStyle zooming style
1937 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
1939 onSwitchZoomingStyle( theStyle == 1 );
1943 \brief Dump view window contents to the pixmap.
1944 \return pixmap containing all scene rendered in the window
1946 QImage OCCViewer_ViewWindow::dumpView()
1948 Handle(V3d_View) view = myViewPort->getView();
1949 if ( view.IsNull() )
1952 int aWidth = myViewPort->width();
1953 int aHeight = myViewPort->height();
1955 // rnv: An old approach to dump the OCCViewer content
1956 // Now used OCCT built-in procedure.
1958 QApplication::syncX();
1959 view->Redraw(); // In order to reactivate GL context
1962 OpenGLUtils_FrameBuffer aFrameBuffer;
1963 if( aFrameBuffer.init( aWidth, aHeight ) )
1965 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
1967 glPushAttrib( GL_VIEWPORT_BIT );
1968 glViewport( 0, 0, aWidth, aHeight );
1969 aFrameBuffer.bind();
1974 aFrameBuffer.unbind();
1977 aFrameBuffer.bind();
1978 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
1979 aFrameBuffer.unbind();
1981 anImage = anImage.rgbSwapped();
1982 anImage = anImage.mirrored();
1985 // if frame buffers are unsupported, use old functionality
1988 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
1990 QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
1992 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
1997 view->ToPixMap(aPix,aWidth, aHeight,Graphic3d_BT_RGBA);
1999 QImage anImage( aPix.Data(), aWidth, aHeight, QImage::Format_ARGB32 );
2000 anImage = anImage.mirrored();
2004 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
2005 const QString& fileName,
2006 const QString& format )
2008 if ( format != "PS" && format != "EPS")
2009 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
2011 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
2014 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
2015 else if (format == "EPS")
2016 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
2022 QString OCCViewer_ViewWindow::filter() const
2024 return tr( "OCC_IMAGE_FILES" );
2029 \brief Set parameters of the cutting plane
2030 \param on if \c true, cutting plane is enabled
2031 \param x X position of plane point
2032 \param y Y position of plane point
2033 \param z Z position of plane point
2034 \param dx X coordinate of plane normal
2035 \param dy Y coordinate of plane normal
2036 \param dz Z coordinate of plane normal
2038 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
2039 const double dx, const double dy, const double dz )
2041 Handle(V3d_View) view = myViewPort->getView();
2042 if ( view.IsNull() )
2046 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2048 // try to use already existing plane or create a new one
2049 Handle(V3d_Plane) clipPlane;
2051 // calculate new a,b,c,d values for the plane
2052 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2054 pln.Coefficients(a, b, c, d);
2056 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2057 if(aPlanes.Size() > 0 ) {
2058 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2059 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2060 aClipPlane->SetEquation(pln);
2061 aClipPlane->SetOn(Standard_True);
2063 view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2067 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2068 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2069 for( ;anIter.More();anIter.Next() ){
2070 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2071 aClipPlane->SetOn(Standard_False);
2079 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2081 gp_Dir aDir = pln.Axis().Direction();
2082 gp_Pnt aPnt = pln.Location();
2083 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2088 \brief Check if any cutting plane is enabled
2089 \return \c true if at least one cutting plane is enabled
2091 bool OCCViewer_ViewWindow::isCuttingPlane()
2093 Handle(V3d_View) view = myViewPort->getView();
2095 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
2096 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
2097 for( ;anIter.More();anIter.Next() ) {
2098 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2099 if(aClipPlane->IsOn()) {
2108 \brief Get the visual parameters of the view window.
2109 \return visual parameters of view window
2111 viewAspect OCCViewer_ViewWindow::getViewParams() const
2113 double projX, projY, projZ, twist;
2114 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2115 double aScaleX, aScaleY, aScaleZ;
2117 Handle(V3d_View) aView3d = myViewPort->getView();
2119 aView3d->Proj( projX, projY, projZ );
2120 aView3d->At( atX, atY, atZ );
2121 aView3d->Eye( eyeX, eyeY, eyeZ );
2122 twist = aView3d->Twist();
2124 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2126 bool isShown = myModel->isTrihedronVisible();
2127 double size = myModel->trihedronSize();
2129 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2132 params.scale = aView3d->Scale();
2133 params.projX = projX;
2134 params.projY = projY;
2135 params.projZ = projZ;
2136 params.twist = twist;
2143 params.scaleX = aScaleX;
2144 params.scaleY = aScaleY;
2145 params.scaleZ = aScaleZ;
2146 params.name = aName;
2147 params.isVisible= isShown;
2150 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2151 aView3d->Center( params.centerX, params.centerY );
2154 // graduated trihedron
2155 bool anIsVisible = false;
2156 OCCViewer_AxisWidget::AxisData anAxisData[3];
2157 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2159 params.gtIsVisible = anIsVisible;
2160 params.gtDrawNameX = anAxisData[0].DrawName;
2161 params.gtDrawNameY = anAxisData[1].DrawName;
2162 params.gtDrawNameZ = anAxisData[2].DrawName;
2163 params.gtNameX = anAxisData[0].Name;
2164 params.gtNameY = anAxisData[1].Name;
2165 params.gtNameZ = anAxisData[2].Name;
2166 params.gtNameColorRX = anAxisData[0].NameColor.red();
2167 params.gtNameColorGX = anAxisData[0].NameColor.green();
2168 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2169 params.gtNameColorRY = anAxisData[1].NameColor.red();
2170 params.gtNameColorGY = anAxisData[1].NameColor.green();
2171 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2172 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2173 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2174 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2175 params.gtDrawValuesX = anAxisData[0].DrawValues;
2176 params.gtDrawValuesY = anAxisData[1].DrawValues;
2177 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2178 params.gtNbValuesX = anAxisData[0].NbValues;
2179 params.gtNbValuesY = anAxisData[1].NbValues;
2180 params.gtNbValuesZ = anAxisData[2].NbValues;
2181 params.gtOffsetX = anAxisData[0].Offset;
2182 params.gtOffsetY = anAxisData[1].Offset;
2183 params.gtOffsetZ = anAxisData[2].Offset;
2184 params.gtColorRX = anAxisData[0].Color.red();
2185 params.gtColorGX = anAxisData[0].Color.green();
2186 params.gtColorBX = anAxisData[0].Color.blue();
2187 params.gtColorRY = anAxisData[1].Color.red();
2188 params.gtColorGY = anAxisData[1].Color.green();
2189 params.gtColorBY = anAxisData[1].Color.blue();
2190 params.gtColorRZ = anAxisData[2].Color.red();
2191 params.gtColorGZ = anAxisData[2].Color.green();
2192 params.gtColorBZ = anAxisData[2].Color.blue();
2193 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2194 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2195 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2196 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2197 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2198 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2204 \brief Get visual parameters of this view window.
2205 \return visual parameters of view window
2207 QString OCCViewer_ViewWindow::getVisualParameters()
2209 viewAspect params = getViewParams();
2213 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2214 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
2215 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
2216 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
2218 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2219 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2220 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2221 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2222 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2223 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2224 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2225 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2226 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2227 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2228 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2229 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2230 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2231 data << QString( "isVisible=%1" ).arg( params.isVisible );
2232 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2234 ClipPlanesList aPlanes = myModel->getClipPlanes();
2235 for ( int i=0; i < aPlanes.size(); i++ )
2237 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2238 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2239 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
2240 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2241 switch ( aPlane.Mode )
2243 case OCCViewer_ClipPlane::Absolute :
2245 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2247 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2249 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2250 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2251 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2255 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2260 case OCCViewer_ClipPlane::Relative :
2262 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2263 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2264 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2269 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2270 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2271 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2272 data << ClippingPlane;
2275 // graduated trihedron
2276 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2277 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2278 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2279 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2280 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2281 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2282 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2283 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2284 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2285 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2286 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2287 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2288 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2289 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2290 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2291 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2292 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2293 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2294 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2295 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2296 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2297 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2298 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2299 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2300 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2301 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2302 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2303 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2304 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2305 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2306 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2307 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2308 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2309 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2310 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2311 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2312 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2313 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2314 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2315 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2316 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2317 data << QString( "background=%1" ).arg( bg );
2319 return data.join("*");
2323 \brief Restore visual parameters of the view window.
2324 \param parameters visual parameters of view window
2326 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2329 ClipPlanesList aClipPlanes;
2330 QStringList data = parameters.split( '*' );
2331 Qtx::BackgroundData bgData;
2332 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2334 foreach( QString param, data ) {
2335 QString paramName = param.section( '=', 0, 0 ).trimmed();
2336 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2337 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2338 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2339 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2340 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2341 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2342 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2343 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2344 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2345 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2346 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2347 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2348 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2349 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2350 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2351 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2352 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2353 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2354 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2355 else if ( paramName.contains( "ClippingPlane" ) )
2357 QStringList ClipPlaneData = paramValue.split( ';' );
2358 OCCViewer_ClipPlane aPlane;
2359 foreach( QString ClipPlaneParam, ClipPlaneData )
2361 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2362 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2363 if ( ClipPlane_paramName == "Mode" )
2365 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2367 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2368 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2369 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2370 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2373 switch ( aPlane.Mode )
2375 case OCCViewer_ClipPlane::Absolute :
2376 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2377 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2378 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2379 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2380 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2383 case OCCViewer_ClipPlane::Relative :
2384 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2385 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2386 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2391 aClipPlanes.push_back(aPlane);
2393 // graduated trihedron
2394 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2395 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2396 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2397 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2398 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2399 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2400 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2401 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2402 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2403 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2404 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2405 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2406 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2407 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2408 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2409 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2410 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2411 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2412 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2413 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2414 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2415 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2416 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2417 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2418 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2419 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2420 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2421 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2422 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2423 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2424 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2425 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2426 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2427 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2428 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2429 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2430 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2431 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2432 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2433 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2434 else if ( paramName == "background" ) {
2435 QString bg = paramValue.replace( "$", "=" );
2436 bgData = Qtx::stringToBackground( bg );
2440 else // old format - "1.000e+00*0.000e+00..."
2443 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2444 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2445 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2446 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2447 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2448 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2449 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
2450 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2451 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2452 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
2453 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2454 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2455 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2456 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
2457 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
2458 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
2459 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
2460 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
2462 performRestoring( params );
2463 setBackground( bgData );
2464 myModel->setClipPlanes(aClipPlanes);
2468 \brief Handle show event.
2470 Emits Show() signal.
2472 \param theEvent show event
2474 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2476 emit Show( theEvent );
2480 \brief Handle hide event.
2482 Emits Hide() signal.
2484 \param theEvent hide event
2486 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
2488 emit Hide( theEvent );
2493 Save old cursor. [ protected ]
2495 void OCCViewer_ViewWindow::saveCursor()
2497 QCursor* aCursor = NULL;
2499 aCursor = myViewPort->getDefaultCursor();
2500 myCursor = ( aCursor ? *aCursor : cursor() );
2505 Creates default sketcher. [ virtual protected ]
2507 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
2510 return new OCCViewer_RectSketcher( this, type );
2511 if ( type == Polygon )
2512 return new OCCViewer_PolygonSketcher( this, type );
2516 void OCCViewer_ViewWindow::initSketchers()
2518 if ( mySketchers.isEmpty() )
2520 mySketchers.append( createSketcher( Rect ) );
2521 mySketchers.append( createSketcher( Polygon ) );
2525 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
2527 OCCViewer_ViewSketcher* sketcher = 0;
2528 QList<OCCViewer_ViewSketcher*>::Iterator it;
2529 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
2531 OCCViewer_ViewSketcher* sk = (*it);
2532 if ( sk->type() == typ )
2539 Handles requests for sketching in the active view. [ virtual public ]
2541 void OCCViewer_ViewWindow::activateSketching( int type )
2543 OCCViewer_ViewPort3d* vp = getViewPort();
2547 if ( !vp->isSketchingEnabled() )
2550 /* Finish current sketching */
2551 if ( type == NoSketching )
2555 onSketchingFinished();
2556 mypSketcher->deactivate();
2560 /* Activate new sketching */
2563 activateSketching( NoSketching ); /* concurrency not suported */
2564 mypSketcher = getSketcher( type );
2567 mypSketcher->activate();
2568 onSketchingStarted();
2574 Unhilights detected entities. [ virtual protected ]
2576 void OCCViewer_ViewWindow::onSketchingStarted()
2581 Selection by rectangle or polygon. [ virtual protected ]
2583 void OCCViewer_ViewWindow::onSketchingFinished()
2585 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
2586 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
2588 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
2589 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
2590 switch( mypSketcher->type() )
2594 QRect* aRect = (QRect*)mypSketcher->data();
2597 int aLeft = aRect->left();
2598 int aRight = aRect->right();
2599 int aTop = aRect->top();
2600 int aBottom = aRect->bottom();
2604 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2606 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2612 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
2615 int size = aPolygon->size();
2616 TColgp_Array1OfPnt2d anArray( 1, size );
2618 QPolygon::Iterator it = aPolygon->begin();
2619 QPolygon::Iterator itEnd = aPolygon->end();
2620 for( int index = 1; it != itEnd; ++it, index++ )
2622 QPoint aPoint = *it;
2623 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
2627 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
2629 ic->Select( anArray, getViewPort()->getView(), Standard_False );
2637 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
2638 aViewMgr->getOCCViewer()->performSelectionChanged();
2642 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
2647 bool OCCViewer_ViewWindow::transformRequested() const
2649 return ( myOperation != NOTHING );
2652 bool OCCViewer_ViewWindow::transformInProcess() const
2654 return myEventStarted;
2657 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
2659 myEventStarted = bOn;
2663 Set enabled state of transformation (rotate, zoom, etc)
2665 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
2667 if ( id != NOTHING ) myStatus.insert( id, on );
2671 \return enabled state of transformation (rotate, zoom, etc)
2673 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
2675 return myStatus.contains( id ) ? myStatus[ id ] : true;
2678 void OCCViewer_ViewWindow::onMaximizedView()
2680 setMaximized(!isMaximized());
2683 void OCCViewer_ViewWindow::returnTo3dView()
2685 setReturnedTo3dView( true );
2688 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
2690 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
2691 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
2692 if ( !isVisible3dView )
2693 toolMgr()->show( ReturnTo3dViewId );
2695 toolMgr()->hide( ReturnTo3dViewId );
2696 if ( isVisible3dView ) emit returnedTo3d( );
2700 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
2702 QAction* anAction = toolMgr()->action( MaximizedId );
2703 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
2704 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
2706 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
2707 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
2708 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
2709 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
2710 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
2712 emit maximized( this, true );
2716 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
2717 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
2718 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
2719 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
2720 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
2722 emit maximized( this, false );
2727 bool OCCViewer_ViewWindow::isMaximized() const
2729 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
2732 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
2734 IsSketcherStyle = enable;
2737 bool OCCViewer_ViewWindow::isSketcherStyle() const
2739 return IsSketcherStyle;
2743 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
2749 QColor OCCViewer_ViewWindow::backgroundColor() const
2751 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
2755 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
2757 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
2760 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
2762 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
2765 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
2767 if ( myViewPort ) myViewPort->setBackground( theBackground );
2770 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
2772 if ( myViewPort ) myViewPort->showStaticTrihedron( on );
2778 void OCCViewer_ViewWindow::clearViewAspects()
2780 myViewAspects.clear();
2784 \return const reference to list of view aspects
2786 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
2788 return myViewAspects;
2792 Appends new view aspect
2793 \param aParams - new view aspects
2795 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
2797 myViewAspects.append( aParams );
2801 Replaces old view aspects by new ones
2802 \param aViewList - list of new view aspects
2804 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
2806 myViewAspects = aViewList;
2810 Get camera properties for the OCC view window.
2811 \return shared pointer on camera properties.
2813 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
2815 SUIT_CameraProperties aProps;
2817 Handle(V3d_View) aSourceView = getViewPort()->getView();
2818 if ( aSourceView.IsNull() )
2821 if ( get2dMode() == No2dMode ) {
2822 aProps.setDimension( SUIT_CameraProperties::Dim3D );
2825 aProps.setDimension( SUIT_CameraProperties::Dim2D );
2826 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
2829 // read common properites of the view
2830 Standard_Real anUp[3];
2831 Standard_Real anAt[3];
2832 Standard_Real anEye[3];
2833 Standard_Real aProj[3];
2834 Standard_Real anAxialScale[3];
2836 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
2837 aSourceView->At( anAt[0], anAt[1], anAt[2] );
2838 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
2839 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2841 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2842 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
2844 #if OCC_VERSION_LARGE > 0x06070100
2845 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
2847 // store camera properties "as is": it is up to synchronized
2848 // view classes to provide necessary property conversion.
2849 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
2850 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
2852 if ( aSourceView->Camera()->IsOrthographic() )
2854 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
2855 aProps.setViewAngle( 0.0 );
2859 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
2860 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
2862 aProps.setMappingScale( aSourceView->Camera()->Scale() );
2864 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
2866 // generate view orientation matrix for transforming OCC projection reference point
2867 // into a camera (eye) position.
2868 gp_Dir aLeftDir = gp_Dir( anUp[0], anUp[1], anUp[2] ) ^ gp_Dir( aProj[0], aProj[1], aProj[2] );
2871 aTrsf.SetValue( 1, 1, aLeftDir.X() );
2872 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
2873 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
2875 aTrsf.SetValue( 1, 2, anUp[0] );
2876 aTrsf.SetValue( 2, 2, anUp[1] );
2877 aTrsf.SetValue( 3, 2, anUp[2] );
2879 aTrsf.SetValue( 1, 3, aProj[0] );
2880 aTrsf.SetValue( 2, 3, aProj[1] );
2881 aTrsf.SetValue( 3, 3, aProj[2] );
2883 aTrsf.SetValue( 1, 4, anAt[0] );
2884 aTrsf.SetValue( 2, 4, anAt[1] );
2885 aTrsf.SetValue( 3, 4, anAt[2] );
2887 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
2889 // transform to world-space coordinate system
2890 gp_XYZ aPosition( aProjRef.X(), aProjRef.Y(), aCameraDepth );
2891 aTrsf.Transforms( aPosition );
2893 // compute focal point
2894 double aFocalPoint[3];
2896 aFocalPoint[0] = aPosition.X() - aProj[0] * aCameraDepth;
2897 aFocalPoint[1] = aPosition.Y() - aProj[1] * aCameraDepth;
2898 aFocalPoint[2] = aPosition.Z() - aProj[2] * aCameraDepth;
2900 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2901 aProps.setPosition( aPosition.X(), aPosition.Y(), aPosition.Z() );
2903 Standard_Real aViewScale[2];
2904 aSourceView->Size( aViewScale[0], aViewScale[1] );
2905 aProps.setMappingScale( aViewScale[1] );
2913 This implementation synchronizes OCC view's camera propreties.
2915 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
2917 bool blocked = blockSignals( true );
2919 SUIT_CameraProperties aProps = theView->cameraProperties();
2920 if ( !cameraProperties().isCompatible( aProps ) ) {
2921 // other view, this one is being currently synchronized to, seems has become incompatible
2922 // we have to break synchronization
2927 Handle(V3d_View) aDestView = getViewPort()->getView();
2929 aDestView->SetImmediateUpdate( Standard_False );
2932 double aPosition[3];
2933 double aFocalPoint[3];
2934 double anAxialScale[3];
2936 // get common properties
2937 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2938 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
2939 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2940 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2942 #if OCC_VERSION_LARGE > 0x06070100
2943 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2944 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
2945 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2946 aDestView->Camera()->SetScale( aProps.getMappingScale() );
2948 gp_Dir aProjDir( aPosition[0] - aFocalPoint[0],
2949 aPosition[1] - aFocalPoint[1],
2950 aPosition[2] - aFocalPoint[2] );
2952 // get custom view translation
2953 Standard_Real aTranslation[3];
2954 aDestView->At( aTranslation[0], aTranslation[1], aTranslation[2] );
2956 gp_Dir aLeftDir = gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] )
2957 ^ gp_Dir( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
2960 aTrsf.SetValue( 1, 1, aLeftDir.X() );
2961 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
2962 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
2964 aTrsf.SetValue( 1, 2, anUpDir[0] );
2965 aTrsf.SetValue( 2, 2, anUpDir[1] );
2966 aTrsf.SetValue( 3, 2, anUpDir[2] );
2968 aTrsf.SetValue( 1, 3, aProjDir.X() );
2969 aTrsf.SetValue( 2, 3, aProjDir.Y() );
2970 aTrsf.SetValue( 3, 3, aProjDir.Z() );
2972 aTrsf.SetValue( 1, 4, aTranslation[0] );
2973 aTrsf.SetValue( 2, 4, aTranslation[1] );
2974 aTrsf.SetValue( 3, 4, aTranslation[2] );
2977 // transform to view-space coordinate system
2978 gp_XYZ aProjRef( aPosition[0], aPosition[1], aPosition[2] );
2979 aTrsf.Transforms( aProjRef );
2981 // set view camera properties using low-level approach. this is done
2982 // in order to avoid interference with static variables in v3d view used
2983 // when rotation is in process in another view.
2984 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
2985 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
2987 Graphic3d_Vector aMappingProj( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
2988 Graphic3d_Vector aMappingUp( anUpDir[0], anUpDir[1], anUpDir[2] );
2990 aMappingProj.Normalize();
2991 aMappingUp.Normalize();
2993 anOrientation.SetViewReferencePlane( aMappingProj );
2994 anOrientation.SetViewReferenceUp( aMappingUp );
2996 aDestView->SetViewMapping( aMapping );
2997 aDestView->SetViewOrientation( anOrientation );
3000 aDestView->SetCenter( aProjRef.X(), aProjRef.Y() );
3002 // set mapping scale
3003 double aMapScaling = aProps.getMappingScale();
3004 Standard_Real aWidth, aHeight;
3005 aDestView->Size( aWidth, aHeight );
3006 aDestView->SetSize ( aWidth > aHeight ? aMapScaling * (aWidth / aHeight) : aMapScaling );
3009 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3011 aDestView->ZFitAll();
3012 aDestView->SetImmediateUpdate( Standard_True );
3013 aDestView->Redraw();
3015 blockSignals( blocked );
3019 \brief Indicates whether preselection is enabled
3020 \return true if preselection is enabled
3022 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
3024 return myPreselectionEnabled;
3028 \brief Enables/disables preselection
3029 \param theIsToEnable if true - preselection will be enabled
3031 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
3033 onSwitchPreselection( theIsToEnable );
3037 \brief Indicates whether selection is enabled
3038 \return true if selection is enabled
3040 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3042 return mySelectionEnabled;
3046 \brief Enables/disables selection
3047 \param theIsToEnable if true - selection will be enabled
3049 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3051 onSwitchSelection( theIsToEnable );
3056 \brief called if clipping operation is activated / deactivated.
3058 Enables/disables clipping plane displaying.
3060 \parma on action state
3062 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3064 if(!myModel) return;
3065 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3068 if (!aClippingDlg) {
3069 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3070 myModel->setClippingDlg(aClippingDlg);
3072 if (!aClippingDlg->isVisible())
3073 aClippingDlg->show();
3075 if ( aClippingDlg ) {
3076 aClippingDlg->close();
3077 myModel->setClippingDlg(0);
3081 SUIT_ViewManager* mgr = getViewManager();
3083 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3084 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3085 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3086 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3088 QAction* a = toolMgr()->action( ClippingId );
3090 if(theIsOn != a->isChecked()){
3091 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3092 a->setChecked(theIsOn);
3093 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));