1 // Copyright (C) 2007-2013 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.
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>
70 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
71 #include <Graphic3d_MapOfStructure.hxx>
72 #include <Graphic3d_Structure.hxx>
73 #include <Graphic3d_ExportFormat.hxx>
75 #include <Visual3d_View.hxx>
76 #include <V3d_Plane.hxx>
77 #include <V3d_Light.hxx>
81 #include <TColgp_Array1OfPnt2d.hxx>
83 #if OCC_VERSION_LARGE > 0x06060000
84 #include <Graphic3d_SequenceOfHClipPlane.hxx>
85 #include <Graphic3d_ClipPlane.hxx>
89 #include <Standard_Version.hxx>
91 #include "utilities.h"
95 // #include <highgui.h>
97 static QEvent* l_mbPressEvent = 0;
100 # include <QWindowsStyle>
105 const char* imageZoomCursor[] = {
110 "................................",
111 "................................",
112 ".#######........................",
113 "..aaaaaaa.......................",
114 "................................",
115 ".............#####..............",
116 "...........##.aaaa##............",
117 "..........#.aa.....a#...........",
118 ".........#.a.........#..........",
119 ".........#a..........#a.........",
120 "........#.a...........#.........",
121 "........#a............#a........",
122 "........#a............#a........",
123 "........#a............#a........",
124 "........#a............#a........",
125 ".........#...........#.a........",
126 ".........#a..........#a.........",
127 ".........##.........#.a.........",
128 "........#####.....##.a..........",
129 ".......###aaa#####.aa...........",
130 "......###aa...aaaaa.......#.....",
131 ".....###aa................#a....",
132 "....###aa.................#a....",
133 "...###aa...............#######..",
134 "....#aa.................aa#aaaa.",
135 ".....a....................#a....",
136 "..........................#a....",
137 "...........................a....",
138 "................................",
139 "................................",
140 "................................",
141 "................................"};
143 const char* imageRotateCursor[] = {
148 "................................",
149 "................................",
150 "................................",
151 "................................",
152 "........#.......................",
153 ".......#.a......................",
154 "......#######...................",
155 ".......#aaaaa#####..............",
156 "........#..##.a#aa##........##..",
157 ".........a#.aa..#..a#.....##.aa.",
158 ".........#.a.....#...#..##.aa...",
159 ".........#a.......#..###.aa.....",
160 "........#.a.......#a..#aa.......",
161 "........#a.........#..#a........",
162 "........#a.........#a.#a........",
163 "........#a.........#a.#a........",
164 "........#a.........#a.#a........",
165 ".........#.........#a#.a........",
166 "........##a........#a#a.........",
167 "......##.a#.......#.#.a.........",
168 "....##.aa..##.....##.a..........",
169 "..##.aa.....a#####.aa...........",
170 "...aa.........aaa#a.............",
171 "................#.a.............",
172 "...............#.a..............",
173 "..............#.a...............",
174 "...............a................",
175 "................................",
176 "................................",
177 "................................",
178 "................................",
179 "................................"};
181 const char* imageCrossCursor[] = {
186 "................................",
187 "................................",
188 "................................",
189 "................................",
190 "................................",
191 "................................",
192 "................................",
193 "...............#................",
194 "...............#a...............",
195 "...............#a...............",
196 "...............#a...............",
197 "...............#a...............",
198 "...............#a...............",
199 "...............#a...............",
200 "...............#a...............",
201 ".......#################........",
202 "........aaaaaaa#aaaaaaaaa.......",
203 "...............#a...............",
204 "...............#a...............",
205 "...............#a...............",
206 "...............#a...............",
207 "...............#a...............",
208 "...............#a...............",
209 "...............#a...............",
210 "................a...............",
211 "................................",
212 "................................",
213 "................................",
214 "................................",
215 "................................",
216 "................................",
217 "................................"};
222 \param theDesktop main window of application
223 \param theModel OCC 3D viewer
225 OCCViewer_ViewWindow::OCCViewer_ViewWindow( SUIT_Desktop* theDesktop,
226 OCCViewer_Viewer* theModel )
227 : SUIT_ViewWindow( theDesktop )
231 myEnableDrawMode = false;
233 updateEnabledDrawMode();
235 mySetRotationPointDlg = 0;
238 IsSketcherStyle = false;
245 myInteractionStyle = SUIT_ViewModel::STANDARD;
246 myPreselectionEnabled = true;
247 mySelectionEnabled = true;
257 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
260 qDeleteAll( mySketchers );
264 \brief Internal initialization.
266 void OCCViewer_ViewWindow::initLayout()
268 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
269 myViewPort->installEventFilter(this);
270 setCentralWidget(myViewPort);
271 myOperation = NOTHING;
273 myCurrPointType = GRAVITY;
274 myPrevPointType = GRAVITY;
275 mySelectedPoint = gp_Pnt(0.,0.,0.);
276 myRotationPointSelection = false;
278 setTransformRequested ( NOTHING );
279 setTransformInProcess ( false );
296 // Graduated axes dialog
297 QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
298 myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
299 myCubeAxesDlg->initialize();
301 connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
304 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
306 return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
310 \brief Detect viewer operation according the the mouse button pressed
311 and key modifiers used.
312 \param theEvent mouse event
313 \return type of the operation
315 OCCViewer_ViewWindow::OperationType
316 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
318 OperationType aOp = NOTHING;
319 SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
320 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
321 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
323 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
324 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
326 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
327 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
328 (my2dMode == No2dMode))
335 \brief Customize event handling
336 \param watched event receiver object
338 \return \c true if the event processing should be stopped
340 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
342 if ( watched == myViewPort ) {
343 int aType = e->type();
345 case QEvent::MouseButtonPress:
346 vpMousePressEvent((QMouseEvent*) e);
349 case QEvent::MouseButtonRelease:
350 vpMouseReleaseEvent((QMouseEvent*) e);
353 case QEvent::MouseMove:
354 vpMouseMoveEvent((QMouseEvent*) e);
357 case QEvent::MouseButtonDblClick:
358 emit mouseDoubleClicked(this, (QMouseEvent*)e);
363 QWheelEvent* aEvent = (QWheelEvent*) e;
364 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
365 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
368 int x1 = (int)( aEvent->x() + width()*delta/100 );
369 int y1 = (int)( aEvent->y() + height()*delta/100 );
370 myViewPort->zoom( x, y, x1, y1 );
374 case QEvent::ContextMenu:
376 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
377 if ( aEvent->reason() != QContextMenuEvent::Mouse )
378 emit contextMenuRequested( aEvent );
382 case QEvent::KeyPress:
383 emit keyPressed(this, (QKeyEvent*) e);
390 return SUIT_ViewWindow::eventFilter(watched, e);
394 \brief Update state of enable draw mode state.
396 void OCCViewer_ViewWindow::updateEnabledDrawMode()
399 myEnableDrawMode = myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
403 \brief Handle mouse press event
404 \param theEvent mouse event
406 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
408 myStartX = theEvent->x();
409 myStartY = theEvent->y();
410 int anInteractionStyle = interactionStyle();
412 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
413 // which are assigned for pan and rotate - these operations are activated immediately after pressing
414 // of the first button, so it is necessary to switch to zoom when the second button is pressed
415 bool aSwitchToZoom = false;
416 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
417 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
418 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
421 switch ( myOperation ) {
423 if ( theEvent->button() == Qt::LeftButton )
424 emit vpTransformationStarted ( WINDOWFIT );
428 if ( theEvent->button() == Qt::LeftButton )
429 emit vpTransformationStarted ( PANGLOBAL );
433 if ( theEvent->button() == Qt::LeftButton ) {
434 myViewPort->startZoomAtPoint( myStartX, myStartY );
435 emit vpTransformationStarted ( ZOOMVIEW );
440 if ( aSwitchToZoom ) {
441 myViewPort->startZoomAtPoint( myStartX, myStartY );
444 else if ( theEvent->button() == Qt::LeftButton )
445 emit vpTransformationStarted ( PANVIEW );
449 if ( aSwitchToZoom ) {
450 myViewPort->startZoomAtPoint( myStartX, myStartY );
453 else if ( theEvent->button() == Qt::LeftButton ) {
454 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
455 emit vpTransformationStarted ( ROTATE );
460 /* Try to activate a transformation */
461 OperationType aState;
462 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
463 aState = getButtonState(theEvent, anInteractionStyle);
465 aState = OCCViewer_ViewWindow::NOTHING;
470 myViewPort->startZoomAtPoint( myStartX, myStartY );
478 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
481 if ( myRotationPointSelection )
483 if ( theEvent->button() == Qt::LeftButton )
485 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
487 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
489 TopoDS_Shape aShape = ic->SelectedShape();
490 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
492 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
493 if ( mySetRotationPointDlg )
495 myRotationPointSelection = false;
496 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
501 myCurrPointType = myPrevPointType;
505 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
506 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
507 ic->CloseAllContexts();
508 myOperation = NOTHING;
509 myViewPort->setCursor( myCursor );
510 myCursorIsHand = false;
511 myRotationPointSelection = false;
515 emit mousePressed(this, theEvent);
518 /* notify that we start a transformation */
519 if ( transformRequested() )
520 emit vpTransformationStarted ( myOperation );
522 if ( transformRequested() )
523 setTransformInProcess( true );
525 /* we may need it for sketching... */
526 if ( l_mbPressEvent )
527 delete l_mbPressEvent;
528 l_mbPressEvent = new QMouseEvent( *theEvent );
533 \brief Start zooming operation.
535 Sets the corresponding cursor for the widget.
537 void OCCViewer_ViewWindow::activateZoom()
539 if ( !transformRequested() && !myCursorIsHand )
540 myCursor = cursor(); /* save old cursor */
542 if ( myOperation != ZOOMVIEW ) {
543 QPixmap zoomPixmap (imageZoomCursor);
544 QCursor zoomCursor (zoomPixmap);
545 if( setTransformRequested ( ZOOMVIEW ) )
546 myViewPort->setCursor( zoomCursor );
552 \brief Start panning operation.
554 Sets the corresponding cursor for the widget.
556 void OCCViewer_ViewWindow::activatePanning()
558 if ( !transformRequested() && !myCursorIsHand )
559 myCursor = cursor(); // save old cursor
561 if ( myOperation != PANVIEW ) {
562 QCursor panCursor (Qt::SizeAllCursor);
563 if( setTransformRequested ( PANVIEW ) )
564 myViewPort->setCursor( panCursor );
569 \brief Start rotation operation
571 Sets the corresponding cursor for the widget.
573 void OCCViewer_ViewWindow::activateRotation()
575 if ( !transformRequested() && !myCursorIsHand )
576 myCursor = cursor(); // save old cursor
578 if ( myOperation != ROTATE ) {
579 QPixmap rotatePixmap (imageRotateCursor);
580 QCursor rotCursor (rotatePixmap);
581 if( setTransformRequested ( ROTATE ) )
582 myViewPort->setCursor( rotCursor );
587 \brief Compute the gravity center.
588 \param theX used to return X coordinate of the gravity center
589 \param theY used to return Y coordinate of the gravity center
590 \param theZ used to return Z coordinate of the gravity center
591 \return \c true if the gravity center is computed
593 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
595 Handle(Visual3d_View) aView = myViewPort->getView()->View();
597 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W ;
598 Standard_Real Umin,Vmin,Umax,Vmax ;
599 Standard_Integer Nstruct,Npoint ;
600 Graphic3d_MapOfStructure MySetOfStructures;
602 aView->DisplayedStructures (MySetOfStructures);
603 Nstruct = MySetOfStructures.Extent() ;
605 Graphic3d_MapIteratorOfMapOfStructure MyIterator(MySetOfStructures) ;
606 aView->ViewMapping().WindowLimit(Umin,Vmin,Umax,Vmax) ;
607 Npoint = 0 ; theX = theY = theZ = 0. ;
608 for( ; MyIterator.More(); MyIterator.Next()) {
609 if (!(MyIterator.Key())->IsEmpty()) {
610 (MyIterator.Key())->MinMaxValues(Xmin,Ymin,Zmin,
613 Standard_Real LIM = ShortRealLast() -1.;
614 if (! (fabs(Xmin) > LIM || fabs(Ymin) > LIM || fabs(Zmin) > LIM
615 || fabs(Xmax) > LIM || fabs(Ymax) > LIM || fabs(Zmax) > LIM )) {
617 aView->Projects(Xmin,Ymin,Zmin,U,V,W) ;
618 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
619 Npoint++ ; theX += Xmin ; theY += Ymin ; theZ += Zmin ;
621 aView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
622 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
623 Npoint++ ; theX += Xmax ; theY += Ymin ; theZ += Zmin ;
625 aView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
626 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
627 Npoint++ ; theX += Xmin ; theY += Ymax ; theZ += Zmin ;
629 aView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
630 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
631 Npoint++ ; theX += Xmax ; theY += Ymax ; theZ += Zmin ;
633 aView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
634 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
635 Npoint++ ; theX += Xmin ; theY += Ymin ; theZ += Zmax ;
637 aView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
638 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
639 Npoint++ ; theX += Xmax ; theY += Ymin ; theZ += Zmax ;
641 aView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
642 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
643 Npoint++ ; theX += Xmin ; theY += Ymax ; theZ += Zmax ;
645 aView->Projects(Xmax,Ymax,Zmax,U,V,W) ;
646 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
647 Npoint++ ; theX += Xmax ; theY += Ymax ; theZ += Zmax ;
653 theX /= Npoint ; theY /= Npoint ; theZ /= Npoint ;
659 \brief Set the gravity center as a rotation point.
661 void OCCViewer_ViewWindow::activateSetRotationGravity()
663 if ( myRotationPointSelection )
665 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
666 ic->CloseAllContexts();
667 myOperation = NOTHING;
668 myViewPort->setCursor( myCursor );
669 myCursorIsHand = false;
670 myRotationPointSelection = false;
673 myPrevPointType = myCurrPointType;
674 myCurrPointType = GRAVITY;
676 Standard_Real Xcenter, Ycenter, Zcenter;
677 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
678 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
682 \brief Update gravity center in the "Set Rotation Point" dialog box.
683 \sa OCCViewer_SetRotationPointDlg class
685 void OCCViewer_ViewWindow::updateGravityCoords()
687 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == GRAVITY )
689 Standard_Real Xcenter, Ycenter, Zcenter;
690 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
691 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
696 \brief Set the point selected by the user as a rotation point.
697 \param theX X coordinate of the rotation point
698 \param theY Y coordinate of the rotation point
699 \param theZ Z coordinate of the rotation point
701 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
703 if ( myRotationPointSelection )
705 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
706 ic->CloseAllContexts();
707 myOperation = NOTHING;
708 myViewPort->setCursor( myCursor );
709 myCursorIsHand = false;
710 myRotationPointSelection = false;
713 myPrevPointType = myCurrPointType;
714 myCurrPointType = SELECTED;
715 mySelectedPoint.SetCoord(theX,theY,theZ);
719 \brief Start the point selection process.
721 void OCCViewer_ViewWindow::activateStartPointSelection()
723 myPrevPointType = myCurrPointType;
724 myCurrPointType = SELECTED;
726 // activate selection ------>
727 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
729 ic->OpenLocalContext();
731 AIS_ListOfInteractive aList;
732 ic->DisplayedObjects( aList );
733 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
735 Handle(AIS_InteractiveObject) anObj = it.Value();
736 if ( !anObj.IsNull() && anObj->HasPresentation() &&
737 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
740 ic->Activate(anObj,AIS_Shape::SelectionMode(TopAbs_VERTEX));
743 // activate selection <------
745 if ( !myCursorIsHand )
747 QCursor handCursor (Qt::PointingHandCursor);
748 myCursorIsHand = true;
750 myViewPort->setCursor( handCursor );
752 myRotationPointSelection = true;
756 \brief Start global panning operation
758 Sets the corresponding cursor for the widget.
760 void OCCViewer_ViewWindow::activateGlobalPanning()
762 Handle(V3d_View) aView3d = myViewPort->getView();
763 if ( !aView3d.IsNull() ) {
764 QPixmap globalPanPixmap (imageCrossCursor);
765 QCursor glPanCursor (globalPanPixmap);
766 myCurScale = aView3d->Scale();
767 aView3d->FitAll(0.01, false);
768 myCursor = cursor(); // save old cursor
769 myViewPort->fitAll(); // fits view before selecting a new scene center
770 if( setTransformRequested( PANGLOBAL ) )
771 myViewPort->setCursor( glPanCursor );
776 \brief Starts fit operation.
778 Sets the corresponding cursor for the widget.
780 void OCCViewer_ViewWindow::activateWindowFit()
782 if ( !transformRequested() && !myCursorIsHand )
783 myCursor = cursor(); /* save old cursor */
785 if ( myOperation != WINDOWFIT ) {
786 QCursor handCursor (Qt::PointingHandCursor);
787 if( setTransformRequested ( WINDOWFIT ) )
789 myViewPort->setCursor ( handCursor );
790 myCursorIsHand = true;
796 \brief Start delayed viewer operation.
798 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
800 bool ok = transformEnabled( op );
801 myOperation = ok ? op : NOTHING;
802 myViewPort->setMouseTracking( myOperation == NOTHING );
807 \brief Handle mouse move event.
808 \param theEvent mouse event
810 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
812 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
814 switch ( getButtonState( theEvent, interactionStyle() ) ) {
816 myViewPort->startZoomAtPoint( myStartX, myStartY );
824 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
831 myCurrX = theEvent->x();
832 myCurrY = theEvent->y();
833 switch (myOperation) {
835 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
839 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
845 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
859 if ( myRotationPointSelection || isSketcherStyle() )
861 emit mouseMoving( this, theEvent );
865 int aState = theEvent->modifiers();
866 int aButton = theEvent->buttons();
867 int anInteractionStyle = interactionStyle();
868 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
869 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
870 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
871 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
872 myDrawRect = myEnableDrawMode;
875 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
876 QCursor handCursor (Qt::PointingHandCursor);
877 myCursorIsHand = true;
879 myViewPort->setCursor( handCursor );
882 emit mouseMoving( this, theEvent );
884 else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
885 aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
886 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
887 aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
888 OCCViewer_ViewSketcher* sketcher = 0;
889 QList<OCCViewer_ViewSketcher*>::Iterator it;
890 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
892 OCCViewer_ViewSketcher* sk = (*it);
893 if( sk->isDefault() && sk->sketchButton() == aButton )
896 if ( sketcher && myCurSketch == -1 )
898 activateSketching( sketcher->type() );
901 myCurSketch = mypSketcher->sketchButton();
903 if ( l_mbPressEvent )
905 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
906 delete l_mbPressEvent;
909 QApplication::sendEvent( getViewPort(), theEvent );
914 emit mouseMoving( this, theEvent );
920 \brief Handle mouse release event.
921 \param theEvent mouse event
923 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
925 switch ( myOperation ) {
928 int prevState = myCurSketch;
929 if(theEvent->button() == Qt::RightButton)
931 QList<OCCViewer_ViewSketcher*>::Iterator it;
932 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
934 OCCViewer_ViewSketcher* sk = (*it);
935 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
940 emit mouseReleased(this, theEvent);
941 if(theEvent->button() == Qt::RightButton && prevState == -1)
943 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
944 theEvent->pos(), theEvent->globalPos() );
945 emit contextMenuRequested( &aEvent );
950 myViewPort->endRotation();
960 if ( theEvent->button() == Qt::LeftButton ) {
961 myViewPort->setCenter( theEvent->x(), theEvent->y() );
962 myViewPort->getView()->SetScale(myCurScale);
968 if ( theEvent->button() == Qt::LeftButton ) {
969 myCurrX = theEvent->x();
970 myCurrY = theEvent->y();
972 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
973 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
980 // NOTE: viewer 3D detects a rectangle of selection using this event
981 // so we must emit it BEFORE resetting the selection rectangle
983 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
987 myViewPort->update();
990 if ( l_mbPressEvent )
992 delete l_mbPressEvent;
998 \brief Reset the viewport to its initial state
999 ( no transformations in process etc. )
1001 void OCCViewer_ViewWindow::resetState()
1005 if ( myRotationPointSelection )
1007 QCursor handCursor (Qt::PointingHandCursor);
1008 myViewPort->setCursor( handCursor );
1012 if ( transformRequested() || myCursorIsHand )
1013 myViewPort->setCursor( myCursor );
1014 myCursorIsHand = false;
1017 if ( transformRequested() )
1018 emit vpTransformationFinished (myOperation);
1020 setTransformInProcess( false );
1021 setTransformRequested( NOTHING );
1026 \brief Draw rubber band rectangle.
1028 void OCCViewer_ViewWindow::drawRect()
1030 if ( !myRectBand ) {
1031 myRectBand = new QtxRectRubberBand( myViewPort );
1033 //palette.setColor(myRectBand->foregroundRole(), Qt::white);
1034 //myRectBand->setPalette(palette);
1036 //myRectBand->hide();
1038 myRectBand->setUpdatesEnabled ( false );
1039 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1040 myRectBand->initGeometry( aRect );
1042 if ( !myRectBand->isVisible() )
1045 myRectBand->setUpdatesEnabled ( true );
1046 //myRectBand->repaint();
1048 //myRectBand->setVisible( aRect.isValid() );
1049 //if ( myRectBand->isVisible() )
1050 // myRectBand->repaint();
1052 // myRectBand->show();
1053 //myRectBand->repaint();
1057 \brief Clear rubber band rectangle on the end on the dragging operation.
1059 void OCCViewer_ViewWindow::endDrawRect()
1061 //delete myRectBand;
1065 myRectBand->clearGeometry();
1071 \brief Create actions.
1073 void OCCViewer_ViewWindow::createActions()
1075 if( !toolMgr()->isEmpty() )
1078 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1083 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1084 tr( "MNU_DUMP_VIEW" ), 0, this);
1085 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1086 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1087 toolMgr()->registerAction( aAction, DumpId );
1090 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1091 tr( "MNU_FITALL" ), 0, this);
1092 aAction->setStatusTip(tr("DSC_FITALL"));
1093 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1094 toolMgr()->registerAction( aAction, FitAllId );
1097 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1098 tr( "MNU_FITRECT" ), 0, this);
1099 aAction->setStatusTip(tr("DSC_FITRECT"));
1100 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1101 toolMgr()->registerAction( aAction, FitRectId );
1104 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1105 tr( "MNU_ZOOM_VIEW" ), 0, this);
1106 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1107 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1108 toolMgr()->registerAction( aAction, ZoomId );
1111 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1112 tr( "MNU_PAN_VIEW" ), 0, this);
1113 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1114 connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
1115 toolMgr()->registerAction( aAction, PanId );
1118 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1119 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1120 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1121 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1122 toolMgr()->registerAction( aAction, GlobalPanId );
1125 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1126 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1127 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1128 mySetRotationPointAction->setCheckable( true );
1129 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1130 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1133 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1134 tr( "MNU_ROTATE_VIEW" ), 0, this);
1135 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1136 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1137 toolMgr()->registerAction( aAction, RotationId );
1140 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1141 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1142 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1143 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1144 this->addAction(aAction);
1145 toolMgr()->registerAction( aAction, FrontId );
1147 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1148 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1149 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1150 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1151 this->addAction(aAction);
1152 toolMgr()->registerAction( aAction, BackId );
1154 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1155 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1156 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1157 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1158 this->addAction(aAction);
1159 toolMgr()->registerAction( aAction, TopId );
1161 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1162 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1163 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1164 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1165 this->addAction(aAction);
1166 toolMgr()->registerAction( aAction, BottomId );
1168 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1169 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1170 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1171 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1172 this->addAction(aAction);
1173 toolMgr()->registerAction( aAction, LeftId );
1175 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1176 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1177 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1178 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1179 this->addAction(aAction);
1180 toolMgr()->registerAction( aAction, RightId );
1182 // rotate anticlockwise
1183 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1184 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1185 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1186 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1187 this->addAction(aAction);
1188 toolMgr()->registerAction( aAction, AntiClockWiseId );
1191 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1192 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1193 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1194 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1195 this->addAction(aAction);
1196 toolMgr()->registerAction( aAction, ClockWiseId );
1199 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1200 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1201 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1202 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1203 this->addAction(aAction);
1204 toolMgr()->registerAction( aAction, ResetId );
1207 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1208 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1209 tr("MNU_CLONE_VIEW"), 0, this);
1210 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1211 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1212 toolMgr()->registerAction( aAction, CloneId );
1214 aAction = new QtxAction (tr ("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr ("ICON_OCCVIEWER_CLIPPING")),
1215 tr ("MNU_CLIPPING"), 0, this);
1216 aAction->setStatusTip (tr ("DSC_CLIPPING"));
1217 aAction->setCheckable (true);
1218 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1219 toolMgr()->registerAction (aAction, ClippingId);
1221 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1222 tr( "MNU_SHOOT_VIEW" ), 0, this);
1223 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1224 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1225 toolMgr()->registerAction( aAction, MemId );
1227 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1228 tr( "MNU_PRESETS_VIEW" ), 0, this);
1229 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1230 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1231 toolMgr()->registerAction( aAction, RestoreId );
1233 if (myModel->trihedronActivated()) {
1234 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1235 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1236 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1237 connect(aAction, SIGNAL(triggered()), this, SLOT(onTrihedronShow()));
1238 toolMgr()->registerAction( aAction, TrihedronShowId );
1242 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1243 tr( "MNU_SCALING" ), 0, this);
1244 aAction->setStatusTip(tr("DSC_SCALING"));
1245 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1246 toolMgr()->registerAction( aAction, AxialScaleId );
1248 // Enable/disable preselection
1249 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1250 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1251 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1252 aAction->setCheckable(true);
1253 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1254 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1256 // Enable/disable selection
1257 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1258 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1259 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1260 aAction->setCheckable(true);
1261 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1262 toolMgr()->registerAction( aAction, SwitchSelectionId );
1265 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1266 tr( "MNU_GRADUATED_AXES" ), 0, this);
1267 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1268 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1269 toolMgr()->registerAction( aAction, GraduatedAxesId );
1271 // Active only ambient light or not
1272 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1273 tr( "MNU_AMBIENT" ), 0, this);
1274 aAction->setStatusTip(tr("DSC_AMBIENT"));
1275 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1276 toolMgr()->registerAction( aAction, AmbientId );
1278 // Switch between interaction styles
1279 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1280 tr( "MNU_STYLE_SWITCH" ), 0, this);
1281 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1282 aAction->setCheckable(true);
1283 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1284 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1286 // Switch between zooming styles
1287 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1288 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1289 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1290 aAction->setCheckable(true);
1291 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1292 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1295 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1296 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1297 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1298 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1299 toolMgr()->registerAction( aAction, MaximizedId );
1301 // Return to 3d view
1302 if (my2dMode!=No2dMode){
1303 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1304 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1305 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1306 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1307 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1311 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1315 \brief Create toolbar.
1317 void OCCViewer_ViewWindow::createToolBar()
1319 QString aToolbarName;
1322 aToolbarName = tr( "LBL_XYTOOLBAR_LABEL" );
1325 aToolbarName = tr( "LBL_XZTOOLBAR_LABEL" );
1328 aToolbarName = tr( "LBL_YZTOOLBAR_LABEL" );
1331 aToolbarName = tr( "LBL_3DTOOLBAR_LABEL" );
1334 int tid = toolMgr()->createToolBar( aToolbarName, false );
1335 if ( my2dMode != No2dMode ){
1336 toolMgr()->append( ReturnTo3dViewId, tid );
1337 toolMgr()->append( toolMgr()->separator(), tid );
1339 toolMgr()->append( DumpId, tid );
1340 toolMgr()->append( SwitchInteractionStyleId, tid );
1341 #if OCC_VERSION_LARGE > 0x0603000A // available only with OCC-6.3-sp11 and higher version
1342 toolMgr()->append( SwitchZoomingStyleId, tid );
1344 toolMgr()->append( SwitchPreselectionId, tid );
1345 toolMgr()->append( SwitchSelectionId, tid );
1346 if( myModel->trihedronActivated() )
1347 toolMgr()->append( TrihedronShowId, tid );
1349 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1350 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1351 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1352 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1353 toolMgr()->append( aScaleAction, tid );
1355 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1356 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1357 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1358 toolMgr()->append( aPanningAction, tid );
1360 if (my2dMode == No2dMode) {
1361 toolMgr()->append( ChangeRotationPointId, tid );
1362 toolMgr()->append( RotationId, tid );
1364 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1365 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1366 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1367 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1368 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1369 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1370 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1371 toolMgr()->append( aViewsAction, tid );
1373 toolMgr()->append( AntiClockWiseId, tid );
1374 toolMgr()->append( ClockWiseId, tid );
1376 toolMgr()->append( ResetId, tid );
1379 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1380 aMemAction->insertAction( toolMgr()->action( MemId ) );
1381 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1382 toolMgr()->append( aMemAction, tid );
1384 toolMgr()->append( toolMgr()->separator(), tid );
1385 toolMgr()->append( CloneId, tid );
1387 toolMgr()->append( toolMgr()->separator(), tid );
1388 toolMgr()->append( ClippingId, tid );
1389 toolMgr()->append( AxialScaleId, tid );
1390 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
1391 toolMgr()->append( GraduatedAxesId, tid );
1393 toolMgr()->append( AmbientId, tid );
1395 toolMgr()->append( MaximizedId, tid );
1396 toolMgr()->append( SynchronizeId, tid );
1400 \brief Perform 'fit all' operation.
1402 void OCCViewer_ViewWindow::onViewFitAll()
1404 myViewPort->fitAll();
1408 \brief Perform "front view" transformation.
1410 void OCCViewer_ViewWindow::onFrontView()
1412 emit vpTransformationStarted ( FRONTVIEW );
1413 Handle(V3d_View) aView3d = myViewPort->getView();
1414 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
1416 emit vpTransformationFinished ( FRONTVIEW );
1420 \brief Perform "back view" transformation.
1422 void OCCViewer_ViewWindow::onBackView()
1424 emit vpTransformationStarted ( BACKVIEW );
1425 Handle(V3d_View) aView3d = myViewPort->getView();
1426 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
1428 emit vpTransformationFinished ( BACKVIEW );
1432 \brief Perform "top view" transformation.
1434 void OCCViewer_ViewWindow::onTopView()
1436 emit vpTransformationStarted ( TOPVIEW );
1437 Handle(V3d_View) aView3d = myViewPort->getView();
1438 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
1440 emit vpTransformationFinished ( TOPVIEW );
1444 \brief Perform "bottom view" transformation.
1446 void OCCViewer_ViewWindow::onBottomView()
1448 emit vpTransformationStarted ( BOTTOMVIEW );
1449 Handle(V3d_View) aView3d = myViewPort->getView();
1450 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
1452 emit vpTransformationFinished ( BOTTOMVIEW );
1456 \brief Perform "left view" transformation.
1458 void OCCViewer_ViewWindow::onLeftView()
1460 emit vpTransformationStarted ( LEFTVIEW );
1461 Handle(V3d_View) aView3d = myViewPort->getView();
1462 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
1464 emit vpTransformationFinished ( LEFTVIEW );
1468 \brief Perform "right view" transformation.
1470 void OCCViewer_ViewWindow::onRightView()
1472 emit vpTransformationStarted ( RIGHTVIEW );
1473 Handle(V3d_View) aView3d = myViewPort->getView();
1474 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
1476 emit vpTransformationFinished ( RIGHTVIEW );
1480 \brief Rotate view 90 degrees clockwise
1482 void OCCViewer_ViewWindow::onClockWiseView()
1484 emit vpTransformationStarted ( CLOCKWISEVIEW );
1485 myViewPort->rotateXY( 90. );
1486 emit vpTransformationFinished ( CLOCKWISEVIEW );
1490 \brief Rotate view 90 degrees conterclockwise
1492 void OCCViewer_ViewWindow::onAntiClockWiseView()
1494 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1495 myViewPort->rotateXY( -90. );
1496 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1500 \brief Perform "reset view" transformation.
1502 Sets default orientation of the viewport camera.
1504 void OCCViewer_ViewWindow::onResetView()
1506 emit vpTransformationStarted( RESETVIEW );
1507 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1508 myViewPort->getView()->Reset( false );
1509 myViewPort->fitAll( false, true, false );
1510 myViewPort->getView()->SetImmediateUpdate( upd );
1511 myViewPort->getView()->Update();
1512 emit vpTransformationFinished( RESETVIEW );
1516 \brief Perform "fit all" transformation.
1518 void OCCViewer_ViewWindow::onFitAll()
1520 emit vpTransformationStarted( FITALLVIEW );
1521 myViewPort->fitAll();
1522 emit vpTransformationFinished( FITALLVIEW );
1526 \brief Called if 'change rotation point' operation is activated.
1527 \param on action state
1529 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1533 if (!mySetRotationPointDlg)
1535 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1536 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1539 if (!mySetRotationPointDlg->isVisible())
1541 //if (mySetRotationPointDlg->IsFirstShown())
1542 if (myCurrPointType == GRAVITY)
1544 Standard_Real Xcenter, Ycenter, Zcenter;
1545 if (computeGravityCenter(Xcenter, Ycenter, Zcenter))
1546 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1548 mySetRotationPointDlg->show();
1553 if (mySetRotationPointDlg->isVisible())
1554 mySetRotationPointDlg->hide();
1559 \brief Create one more window with same content.
1561 void OCCViewer_ViewWindow::onCloneView()
1563 SUIT_ViewWindow* vw = myManager->createViewWindow();
1565 emit viewCloned( vw );
1569 Creates one more window with same content
1571 void OCCViewer_ViewWindow::onAxialScale()
1573 if ( !myScalingDlg )
1574 myScalingDlg = new OCCViewer_AxialScaleDlg( this );
1576 if ( !myScalingDlg->isVisible() )
1578 myScalingDlg->Update();
1579 myScalingDlg->show();
1584 Shows Graduated Axes dialog
1586 void OCCViewer_ViewWindow::onGraduatedAxes()
1588 myCubeAxesDlg->Update();
1589 myCubeAxesDlg->show();
1592 void OCCViewer_ViewWindow::onAmbientToogle()
1594 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
1595 viewer->InitDefinedLights();
1596 while(viewer->MoreDefinedLights())
1598 Handle(V3d_Light) light = viewer->DefinedLight();
1599 if(light->Type() != V3d_AMBIENT)
1601 Handle(V3d_View) aView3d = myViewPort->getView();
1602 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
1603 else viewer->SetLightOn(light);
1605 viewer->NextDefinedLights();
1611 \brief Store view parameters.
1613 void OCCViewer_ViewWindow::onMemorizeView()
1615 appendViewAspect( getViewParams() );
1619 \brief Restore view parameters.
1621 void OCCViewer_ViewWindow::onRestoreView()
1623 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
1624 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
1626 updateViewAspects( aDlg->parameters() );
1627 if( myRestoreFlag && aDlg->parameters().count() )
1628 performRestoring( aDlg->currentItem() );
1632 \brief Restore view parameters.
1633 \param anItem view parameters
1635 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
1637 Handle(V3d_View) aView3d = myViewPort->getView();
1639 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
1640 aView3d->SetScale( anItem.scale );
1641 aView3d->SetCenter( anItem.centerX, anItem.centerY );
1642 aView3d->SetTwist( anItem.twist );
1643 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
1644 aView3d->SetImmediateUpdate( prev );
1645 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1646 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1647 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
1649 if ( !baseParamsOnly ) {
1651 myModel->setTrihedronShown( anItem.isVisible );
1652 myModel->setTrihedronSize( anItem.size );
1654 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
1655 // graduated trihedron
1656 bool anIsVisible = anItem.gtIsVisible;
1657 OCCViewer_AxisWidget::AxisData anAxisData[3];
1658 anAxisData[0].DrawName = anItem.gtDrawNameX;
1659 anAxisData[1].DrawName = anItem.gtDrawNameZ;
1660 anAxisData[2].DrawName = anItem.gtDrawNameZ;
1661 anAxisData[0].Name = anItem.gtNameX;
1662 anAxisData[1].Name = anItem.gtNameZ;
1663 anAxisData[2].Name = anItem.gtNameZ;
1664 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
1665 anItem.gtNameColorGX,
1666 anItem.gtNameColorBX );
1667 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
1668 anItem.gtNameColorGY,
1669 anItem.gtNameColorBY );
1670 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
1671 anItem.gtNameColorGZ,
1672 anItem.gtNameColorBZ );
1673 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
1674 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
1675 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
1676 anAxisData[0].NbValues = anItem.gtNbValuesX;
1677 anAxisData[1].NbValues = anItem.gtNbValuesY;
1678 anAxisData[2].NbValues = anItem.gtNbValuesZ;
1679 anAxisData[0].Offset = anItem.gtOffsetX;
1680 anAxisData[1].Offset = anItem.gtOffsetY;
1681 anAxisData[2].Offset = anItem.gtOffsetZ;
1682 anAxisData[0].Color = QColor( anItem.gtColorRX,
1685 anAxisData[1].Color = QColor( anItem.gtColorRY,
1688 anAxisData[2].Color = QColor( anItem.gtColorRZ,
1691 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
1692 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
1693 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
1694 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
1695 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
1696 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
1698 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
1699 myCubeAxesDlg->ApplyData( aView3d );
1702 } // if ( !baseParamsOnly )
1708 \brief Set restore flag.
1710 void OCCViewer_ViewWindow::setRestoreFlag()
1716 \brief Called when action "show/hide trihedron" is activated.
1718 void OCCViewer_ViewWindow::onTrihedronShow()
1720 myModel->toggleTrihedron();
1724 \brief Toggles preselection (highlighting) on/off
1726 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
1728 myPreselectionEnabled = on;
1729 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
1731 // unhighlight all highlighted objects
1733 myModel->unHighlightAll( true, false );
1736 // update action state if method is called outside
1737 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
1738 if ( a && a->isChecked() != on ) {
1739 a->setChecked( on );
1744 \brief Toggles selection on/off
1746 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
1748 mySelectionEnabled = on;
1749 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
1751 // update action state if method is called outside
1754 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
1756 a->setEnabled( on );
1760 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
1761 if ( a && a->isChecked() != on ) {
1762 a->setChecked( on );
1767 \brief Switches "keyboard free" interaction style on/off
1769 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
1771 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
1773 // update action state if method is called outside
1774 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
1775 if ( a->isChecked() != on )
1776 a->setChecked( on );
1780 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
1782 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
1784 myViewPort->setAdvancedZoomingEnabled( on );
1786 // update action state if method is called outside
1787 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
1788 if ( a->isChecked() != on )
1789 a->setChecked( on );
1793 \brief Get current interaction style
1794 \return interaction style
1796 int OCCViewer_ViewWindow::interactionStyle() const
1798 return myInteractionStyle;
1802 \brief Set current interaction style
1803 \param theStyle interaction style
1805 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
1807 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
1811 \brief Get current zooming style
1812 \return zooming style
1814 int OCCViewer_ViewWindow::zoomingStyle() const
1816 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
1820 \brief Set current zooming style
1821 \param theStyle zooming style
1823 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
1825 onSwitchZoomingStyle( theStyle == 1 );
1829 \brief Dump view window contents to the pixmap.
1830 \return pixmap containing all scene rendered in the window
1832 QImage OCCViewer_ViewWindow::dumpView()
1834 Handle(V3d_View) view = myViewPort->getView();
1835 if ( view.IsNull() )
1838 int aWidth = myViewPort->width();
1839 int aHeight = myViewPort->height();
1840 QApplication::syncX();
1841 view->Redraw(); // In order to reactivate GL context
1844 OpenGLUtils_FrameBuffer aFrameBuffer;
1845 if( aFrameBuffer.init( aWidth, aHeight ) )
1847 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
1849 glPushAttrib( GL_VIEWPORT_BIT );
1850 glViewport( 0, 0, aWidth, aHeight );
1851 aFrameBuffer.bind();
1856 aFrameBuffer.unbind();
1859 aFrameBuffer.bind();
1860 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
1861 aFrameBuffer.unbind();
1863 anImage = anImage.rgbSwapped();
1864 anImage = anImage.mirrored();
1867 // if frame buffers are unsupported, use old functionality
1870 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
1872 QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
1874 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
1877 QImage anImage( data, aWidth, aHeight, QImage::Format_ARGB32 );
1878 anImage = anImage.mirrored();
1879 anImage = anImage.rgbSwapped();
1883 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
1884 const QString& fileName,
1885 const QString& format )
1887 if ( format != "PS" && format != "EPS")
1888 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
1890 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
1893 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
1894 else if (format == "EPS")
1895 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
1901 QString OCCViewer_ViewWindow::filter() const
1903 return tr( "OCC_IMAGE_FILES" );
1908 \brief Set parameters of the cutting plane
1909 \param on if \c true, cutting plane is enabled
1910 \param x X position of plane point
1911 \param y Y position of plane point
1912 \param z Z position of plane point
1913 \param dx X coordinate of plane normal
1914 \param dy Y coordinate of plane normal
1915 \param dz Z coordinate of plane normal
1917 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
1918 const double dx, const double dy, const double dz )
1920 Handle(V3d_View) view = myViewPort->getView();
1921 if ( view.IsNull() )
1925 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
1927 // try to use already existing plane or create a new one
1928 Handle(V3d_Plane) clipPlane;
1930 // calculate new a,b,c,d values for the plane
1931 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
1933 pln.Coefficients(a, b, c, d);
1935 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
1936 Handle(Graphic3d_ClipPlane) aClipPlane;
1937 if(aPlanes.Size() > 0 ) {
1938 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
1939 aClipPlane = anIter.Value();
1940 aClipPlane->SetEquation(pln);
1941 aClipPlane->SetOn(Standard_True);
1943 aClipPlane = new Graphic3d_ClipPlane(pln);
1944 view->AddClipPlane(aClipPlane);
1945 aClipPlane->SetOn(Standard_True);
1949 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
1950 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
1951 for( ;anIter.More();anIter.Next() ){
1952 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
1953 aClipPlane->SetOn(Standard_False);
1961 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
1963 gp_Dir aDir = pln.Axis().Direction();
1964 gp_Pnt aPnt = pln.Location();
1965 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
1970 \brief Check if any cutting plane is enabled
1971 \return \c true if at least one cutting plane is enabled
1973 bool OCCViewer_ViewWindow::isCuttingPlane()
1975 Handle(V3d_View) view = myViewPort->getView();
1977 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
1978 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
1979 for( ;anIter.More();anIter.Next() ) {
1980 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
1981 if(aClipPlane->IsOn()) {
1990 \brief Get the visual parameters of the view window.
1991 \return visual parameters of view window
1993 viewAspect OCCViewer_ViewWindow::getViewParams() const
1995 double centerX, centerY, projX, projY, projZ, twist;
1996 double atX, atY, atZ, eyeX, eyeY, eyeZ;
1997 double aScaleX, aScaleY, aScaleZ;
1999 Handle(V3d_View) aView3d = myViewPort->getView();
2001 aView3d->Center( centerX, centerY );
2002 aView3d->Proj( projX, projY, projZ );
2003 aView3d->At( atX, atY, atZ );
2004 aView3d->Eye( eyeX, eyeY, eyeZ );
2005 twist = aView3d->Twist();
2007 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2009 bool isShown = myModel->isTrihedronVisible();
2010 double size = myModel->trihedronSize();
2012 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2015 params.scale = aView3d->Scale();
2016 params.centerX = centerX;
2017 params.centerY = centerY;
2018 params.projX = projX;
2019 params.projY = projY;
2020 params.projZ = projZ;
2021 params.twist = twist;
2028 params.scaleX = aScaleX;
2029 params.scaleY = aScaleY;
2030 params.scaleZ = aScaleZ;
2031 params.name = aName;
2032 params.isVisible= isShown;
2035 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
2036 // graduated trihedron
2037 bool anIsVisible = false;
2038 OCCViewer_AxisWidget::AxisData anAxisData[3];
2039 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2041 params.gtIsVisible = anIsVisible;
2042 params.gtDrawNameX = anAxisData[0].DrawName;
2043 params.gtDrawNameY = anAxisData[1].DrawName;
2044 params.gtDrawNameZ = anAxisData[2].DrawName;
2045 params.gtNameX = anAxisData[0].Name;
2046 params.gtNameY = anAxisData[1].Name;
2047 params.gtNameZ = anAxisData[2].Name;
2048 params.gtNameColorRX = anAxisData[0].NameColor.red();
2049 params.gtNameColorGX = anAxisData[0].NameColor.green();
2050 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2051 params.gtNameColorRY = anAxisData[1].NameColor.red();
2052 params.gtNameColorGY = anAxisData[1].NameColor.green();
2053 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2054 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2055 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2056 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2057 params.gtDrawValuesX = anAxisData[0].DrawValues;
2058 params.gtDrawValuesY = anAxisData[1].DrawValues;
2059 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2060 params.gtNbValuesX = anAxisData[0].NbValues;
2061 params.gtNbValuesY = anAxisData[1].NbValues;
2062 params.gtNbValuesZ = anAxisData[2].NbValues;
2063 params.gtOffsetX = anAxisData[0].Offset;
2064 params.gtOffsetY = anAxisData[1].Offset;
2065 params.gtOffsetZ = anAxisData[2].Offset;
2066 params.gtColorRX = anAxisData[0].Color.red();
2067 params.gtColorGX = anAxisData[0].Color.green();
2068 params.gtColorBX = anAxisData[0].Color.blue();
2069 params.gtColorRY = anAxisData[1].Color.red();
2070 params.gtColorGY = anAxisData[1].Color.green();
2071 params.gtColorBY = anAxisData[1].Color.blue();
2072 params.gtColorRZ = anAxisData[2].Color.red();
2073 params.gtColorGZ = anAxisData[2].Color.green();
2074 params.gtColorBZ = anAxisData[2].Color.blue();
2075 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2076 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2077 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2078 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2079 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2080 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2087 \brief Get visual parameters of this view window.
2088 \return visual parameters of view window
2090 QString OCCViewer_ViewWindow::getVisualParameters()
2092 viewAspect params = getViewParams();
2096 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2097 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
2098 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
2099 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2100 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2101 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2102 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2103 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2104 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2105 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2106 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2107 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2108 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2109 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2110 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2111 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2112 data << QString( "isVisible=%1" ).arg( params.isVisible );
2113 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2115 ClipPlanesList aPlanes = myModel->getClipPlanes();
2116 for ( int i=0; i < aPlanes.size(); i++ ) {
2117 OCCViewer_ClipPlane& aPlane = aPlanes[i];
2118 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2119 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.PlaneMode );
2120 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
2121 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.Orientation );
2122 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.IsInvert );
2123 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
2124 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
2125 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
2126 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.Dx );
2127 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.Dy );;
2128 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.Dz );
2129 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.RelativeMode.Orientation );
2130 ClippingPlane += QString( "Distance~%1;" ).arg( aPlane.RelativeMode.Distance );
2131 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeMode.Rotation1 );
2132 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeMode.Rotation2 );
2133 data << ClippingPlane;
2137 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 or newer version
2138 // graduated trihedron
2139 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2140 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2141 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2142 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2143 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2144 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2145 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2146 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2147 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2148 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2149 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2150 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2151 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2152 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2153 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2154 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2155 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2156 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2157 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2158 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2159 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2160 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2161 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2162 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2163 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2164 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2165 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2166 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2167 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2168 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2169 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2170 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2171 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2172 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2173 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2174 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2175 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2176 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2177 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2178 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2180 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2181 data << QString( "background=%1" ).arg( bg );
2183 return data.join("*");
2187 \brief Restore visual parameters of the view window.
2188 \param parameters visual parameters of view window
2190 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2193 ClipPlanesList aClipPlanes;
2194 QStringList data = parameters.split( '*' );
2195 Qtx::BackgroundData bgData;
2196 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2198 foreach( QString param, data ) {
2199 QString paramName = param.section( '=', 0, 0 ).trimmed();
2200 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2201 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2202 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2203 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2204 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2205 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2206 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2207 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2208 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2209 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2210 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2211 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2212 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2213 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2214 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2215 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2216 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2217 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2218 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2219 else if ( paramName.contains( "ClippingPlane" ) ) {
2220 QStringList ClipPlaneData = paramValue.split( ';' );
2221 OCCViewer_ClipPlane aPlane;
2222 foreach( QString ClipPlaneParam, ClipPlaneData ) {
2223 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2224 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2225 if ( ClipPlane_paramName == "Mode" ) aPlane.PlaneMode = ( ClipPlaneMode )ClipPlane_paramValue.toInt();
2226 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2227 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.Orientation = ClipPlane_paramValue.toInt();
2228 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.IsInvert = ClipPlane_paramValue.toInt();
2229 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
2230 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
2231 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
2232 else if ( ClipPlane_paramName == "Dx" ) aPlane.Dx = ClipPlane_paramValue.toDouble();
2233 else if ( ClipPlane_paramName == "Dy" ) aPlane.Dy = ClipPlane_paramValue.toDouble();
2234 else if ( ClipPlane_paramName == "Dz" ) aPlane.Dz = ClipPlane_paramValue.toDouble();
2235 else if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.RelativeMode.Orientation = ClipPlane_paramValue.toInt();
2236 else if ( ClipPlane_paramName == "Distance" ) aPlane.RelativeMode.Distance = ClipPlane_paramValue.toDouble();
2237 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeMode.Rotation1 = ClipPlane_paramValue.toDouble();
2238 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeMode.Rotation2 = ClipPlane_paramValue.toDouble();
2240 aClipPlanes.push_back(aPlane);
2242 // graduated trihedron
2243 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2244 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2245 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2246 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2247 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2248 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2249 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2250 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2251 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2252 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2253 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2254 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2255 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2256 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2257 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2258 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2259 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2260 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2261 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2262 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2263 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2264 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2265 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2266 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2267 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2268 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2269 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2270 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2271 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2272 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2273 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2274 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2275 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2276 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2277 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2278 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2279 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2280 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2281 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2282 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2283 else if ( paramName == "background" ) {
2284 QString bg = paramValue.replace( "$", "=" );
2285 bgData = Qtx::stringToBackground( bg );
2289 else // old format - "1.000e+00*0.000e+00..."
2292 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2293 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2294 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2295 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2296 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2297 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2298 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
2299 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2300 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2301 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
2302 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2303 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2304 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2305 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
2306 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
2307 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
2308 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
2309 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
2311 performRestoring( params );
2312 setBackground( bgData );
2313 myModel->setClipPlanes(aClipPlanes);
2317 \brief Handle show event.
2319 Emits Show() signal.
2321 \param theEvent show event
2323 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2325 emit Show( theEvent );
2329 \brief Handle hide event.
2331 Emits Hide() signal.
2333 \param theEvent hide event
2335 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
2337 emit Hide( theEvent );
2342 Creates default sketcher. [ virtual protected ]
2344 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
2347 return new OCCViewer_RectSketcher( this, type );
2348 if ( type == Polygon )
2349 return new OCCViewer_PolygonSketcher( this, type );
2353 void OCCViewer_ViewWindow::initSketchers()
2355 if ( mySketchers.isEmpty() )
2357 mySketchers.append( createSketcher( Rect ) );
2358 mySketchers.append( createSketcher( Polygon ) );
2362 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
2364 OCCViewer_ViewSketcher* sketcher = 0;
2365 QList<OCCViewer_ViewSketcher*>::Iterator it;
2366 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
2368 OCCViewer_ViewSketcher* sk = (*it);
2369 if ( sk->type() == typ )
2376 Handles requests for sketching in the active view. [ virtual public ]
2378 void OCCViewer_ViewWindow::activateSketching( int type )
2380 OCCViewer_ViewPort3d* vp = getViewPort();
2384 if ( !vp->isSketchingEnabled() )
2387 /* Finish current sketching */
2388 if ( type == NoSketching )
2392 onSketchingFinished();
2393 mypSketcher->deactivate();
2397 /* Activate new sketching */
2400 activateSketching( NoSketching ); /* concurrency not suported */
2401 mypSketcher = getSketcher( type );
2404 mypSketcher->activate();
2405 onSketchingStarted();
2411 Unhilights detected entities. [ virtual protected ]
2413 void OCCViewer_ViewWindow::onSketchingStarted()
2418 Selection by rectangle or polygon. [ virtual protected ]
2420 void OCCViewer_ViewWindow::onSketchingFinished()
2422 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
2423 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
2425 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
2426 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
2427 switch( mypSketcher->type() )
2431 QRect* aRect = (QRect*)mypSketcher->data();
2434 int aLeft = aRect->left();
2435 int aRight = aRect->right();
2436 int aTop = aRect->top();
2437 int aBottom = aRect->bottom();
2441 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2443 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2449 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
2452 int size = aPolygon->size();
2453 TColgp_Array1OfPnt2d anArray( 1, size );
2455 QPolygon::Iterator it = aPolygon->begin();
2456 QPolygon::Iterator itEnd = aPolygon->end();
2457 for( int index = 1; it != itEnd; ++it, index++ )
2459 QPoint aPoint = *it;
2460 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
2464 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
2466 ic->Select( anArray, getViewPort()->getView(), Standard_False );
2474 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
2475 aViewMgr->getOCCViewer()->performSelectionChanged();
2479 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
2484 bool OCCViewer_ViewWindow::transformRequested() const
2486 return ( myOperation != NOTHING );
2489 bool OCCViewer_ViewWindow::transformInProcess() const
2491 return myEventStarted;
2494 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
2496 myEventStarted = bOn;
2500 Set enabled state of transformation (rotate, zoom, etc)
2502 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
2504 if ( id != NOTHING ) myStatus.insert( id, on );
2508 \return enabled state of transformation (rotate, zoom, etc)
2510 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
2512 return myStatus.contains( id ) ? myStatus[ id ] : true;
2515 void OCCViewer_ViewWindow::onMaximizedView()
2517 setMaximized(!isMaximized());
2520 void OCCViewer_ViewWindow::returnTo3dView()
2522 setReturnedTo3dView( true );
2525 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
2527 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
2528 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
2529 if ( !isVisible3dView )
2530 toolMgr()->show( ReturnTo3dViewId );
2532 toolMgr()->hide( ReturnTo3dViewId );
2533 if ( isVisible3dView ) emit returnedTo3d( );
2537 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
2539 QAction* anAction = toolMgr()->action( MaximizedId );
2540 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
2541 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
2543 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
2544 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
2545 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
2546 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
2547 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
2549 emit maximized( this, true );
2553 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
2554 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
2555 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
2556 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
2557 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
2559 emit maximized( this, false );
2564 bool OCCViewer_ViewWindow::isMaximized() const
2566 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
2569 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
2571 IsSketcherStyle = enable;
2574 bool OCCViewer_ViewWindow::isSketcherStyle() const
2576 return IsSketcherStyle;
2580 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
2586 QColor OCCViewer_ViewWindow::backgroundColor() const
2588 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
2592 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
2594 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
2597 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
2599 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
2602 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
2604 if ( myViewPort ) myViewPort->setBackground( theBackground );
2610 void OCCViewer_ViewWindow::clearViewAspects()
2612 myViewAspects.clear();
2616 \return const reference to list of view aspects
2618 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
2620 return myViewAspects;
2624 Appends new view aspect
2625 \param aParams - new view aspects
2627 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
2629 myViewAspects.append( aParams );
2633 Replaces old view aspects by new ones
2634 \param aViewList - list of new view aspects
2636 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
2638 myViewAspects = aViewList;
2642 Get camera properties for the OCC view window.
2643 \return shared pointer on camera properties.
2645 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
2647 SUIT_CameraProperties aProps;
2649 Handle(V3d_View) aSourceView = getViewPort()->getView();
2650 if ( aSourceView.IsNull() )
2653 if ( get2dMode() == No2dMode ) {
2654 aProps.setDimension( SUIT_CameraProperties::Dim3D );
2657 aProps.setDimension( SUIT_CameraProperties::Dim2D );
2658 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
2661 // read common properites of the view
2662 Standard_Real anUpDir[3];
2663 Standard_Real aPrjDir[3];
2664 Standard_Real aMapScale[2];
2665 Standard_Real aTranslation[3];
2666 Standard_Real anAxialScale[3];
2668 aSourceView->Up(anUpDir[0], anUpDir[1], anUpDir[2]);
2669 aSourceView->Proj(aPrjDir[0], aPrjDir[1], aPrjDir[2]);
2670 aSourceView->At(aTranslation[0], aTranslation[1], aTranslation[2]);
2671 aSourceView->Size(aMapScale[0], aMapScale[1]);
2673 getViewPort()->getAxialScale(anAxialScale[0], anAxialScale[1], anAxialScale[2]);
2675 // we use similar depth to the one used in perspective projection
2676 // to proivde a convinience synchronization with other camera views that
2677 // can switch between orthogonal & perspective projection. otherwise,
2678 // the camera will get to close when switching from orthogonal to perspective.
2679 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
2681 // store common props
2682 aProps.setViewUp(anUpDir[0], anUpDir[1], anUpDir[2]);
2683 aProps.setMappingScale(aMapScale[1] / 2.0);
2684 aProps.setAxialScale(anAxialScale[0], anAxialScale[1], anAxialScale[2]);
2686 // generate view orientation matrix for transforming OCC projection reference point
2687 // into a camera (eye) position.
2688 gp_Dir aLeftDir = gp_Dir(anUpDir[0], anUpDir[1], anUpDir[2]).Crossed(
2689 gp_Dir(aPrjDir[0], aPrjDir[1], aPrjDir[2]));
2692 aTrsf.SetValues( aLeftDir.X(), anUpDir[0], aPrjDir[0], aTranslation[0],
2693 aLeftDir.Y(), anUpDir[1], aPrjDir[1], aTranslation[1],
2694 aLeftDir.Z(), anUpDir[2], aPrjDir[2], aTranslation[2],
2695 Precision::Confusion(),
2696 Precision::Confusion() );
2698 // get projection reference point in view coordinates
2699 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
2701 // transform to world-space coordinate system
2702 gp_Pnt aPosition = gp_Pnt(aProjRef.X(), aProjRef.Y(), aCameraDepth).Transformed(aTrsf);
2704 // compute focal point
2705 double aFocalPoint[3];
2707 aFocalPoint[0] = aPosition.X() - aPrjDir[0] * aCameraDepth;
2708 aFocalPoint[1] = aPosition.Y() - aPrjDir[1] * aCameraDepth;
2709 aFocalPoint[2] = aPosition.Z() - aPrjDir[2] * aCameraDepth;
2711 aProps.setFocalPoint(aFocalPoint[0], aFocalPoint[1], aFocalPoint[2]);
2712 aProps.setPosition(aPosition.X(), aPosition.Y(), aPosition.Z());
2719 This implementation synchronizes OCC view's camera propreties.
2721 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
2723 bool blocked = blockSignals( true );
2725 SUIT_CameraProperties aProps = theView->cameraProperties();
2726 if ( !cameraProperties().isCompatible( aProps ) ) {
2727 // other view, this one is being currently synchronized to, seems has become incompatible
2728 // we have to break synchronization
2733 Handle(V3d_View) aDestView = getViewPort()->getView();
2735 aDestView->SetImmediateUpdate( Standard_False );
2738 double aPosition[3];
2739 double aFocalPoint[3];
2741 double anAxialScale[3];
2743 // get common properties
2744 aProps.getFocalPoint(aFocalPoint[0], aFocalPoint[1], aFocalPoint[2]);
2745 aProps.getPosition(aPosition[0], aPosition[1], aPosition[2]);
2746 aProps.getViewUp(anUpDir[0], anUpDir[1], anUpDir[2]);
2747 aProps.getAxialScale(anAxialScale[0], anAxialScale[1], anAxialScale[2]);
2748 aMapScaling = aProps.getMappingScale() * 2.0;
2750 gp_Dir aProjDir(aPosition[0] - aFocalPoint[0],
2751 aPosition[1] - aFocalPoint[1],
2752 aPosition[2] - aFocalPoint[2]);
2754 // get custom view translation
2755 Standard_Real aTranslation[3];
2756 aDestView->At(aTranslation[0], aTranslation[1], aTranslation[2]);
2758 gp_Dir aLeftDir = gp_Dir(anUpDir[0], anUpDir[1], anUpDir[2]).Crossed(
2759 gp_Dir(aProjDir.X(), aProjDir.Y(), aProjDir.Z()));
2761 // convert camera position into a view reference point
2763 aTrsf.SetValues( aLeftDir.X(), anUpDir[0], aProjDir.X(), aTranslation[0],
2764 aLeftDir.Y(), anUpDir[1], aProjDir.Y(), aTranslation[1],
2765 aLeftDir.Z(), anUpDir[2], aProjDir.Z(), aTranslation[2],
2766 Precision::Confusion(),
2767 Precision::Confusion() );
2770 // transform to view-space coordinate system
2771 gp_Pnt aProjRef(aPosition[0], aPosition[1], aPosition[2]);
2772 aProjRef.Transform(aTrsf);
2774 // set view camera properties using low-level approach. this is done
2775 // in order to avoid interference with static variables in v3d view used
2776 // when rotation is in process in another view.
2777 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
2778 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
2780 Graphic3d_Vector aMappingProj(aProjDir.X(), aProjDir.Y(), aProjDir.Z());
2781 Graphic3d_Vector aMappingUp(anUpDir[0], anUpDir[1], anUpDir[2]);
2783 aMappingProj.Normalize();
2784 aMappingUp.Normalize();
2786 anOrientation.SetViewReferencePlane(aMappingProj);
2787 anOrientation.SetViewReferenceUp(aMappingUp);
2789 aDestView->SetViewMapping(aMapping);
2790 aDestView->SetViewOrientation(anOrientation);
2793 aDestView->SetCenter(aProjRef.X(), aProjRef.Y());
2795 // set mapping scale
2796 Standard_Real aWidth, aHeight;
2797 aDestView->Size(aWidth, aHeight);
2799 if ( aWidth > aHeight )
2800 aDestView->SetSize (aMapScaling * (aWidth / aHeight));
2802 aDestView->SetSize (aMapScaling);
2804 getViewPort()->setAxialScale(anAxialScale[0], anAxialScale[1], anAxialScale[2]);
2806 aDestView->ZFitAll();
2807 aDestView->SetImmediateUpdate( Standard_True );
2808 aDestView->Redraw();
2810 blockSignals( blocked );
2814 \brief Indicates whether preselection is enabled
2815 \return true if preselection is enabled
2817 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
2819 return myPreselectionEnabled;
2823 \brief Enables/disables preselection
2824 \param theIsToEnable if true - preselection will be enabled
2826 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
2828 onSwitchPreselection( theIsToEnable );
2832 \brief Indicates whether selection is enabled
2833 \return true if selection is enabled
2835 bool OCCViewer_ViewWindow::isSelectionEnabled() const
2837 return mySelectionEnabled;
2841 \brief Enables/disables selection
2842 \param theIsToEnable if true - selection will be enabled
2844 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
2846 onSwitchSelection( theIsToEnable );
2851 \brief called if clipping operation is activated / deactivated.
2853 Enables/disables clipping plane displaying.
2855 \parma on action state
2857 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
2859 if(!myModel) return;
2860 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
2863 if (!aClippingDlg) {
2864 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
2865 myModel->setClippingDlg(aClippingDlg);
2867 if (!aClippingDlg->isVisible())
2868 aClippingDlg->show();
2870 if ( aClippingDlg ) {
2871 aClippingDlg->close();
2872 myModel->setClippingDlg(0);
2876 SUIT_ViewManager* mgr = getViewManager();
2878 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
2879 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
2880 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
2881 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
2883 QAction* a = toolMgr()->action( ClippingId );
2885 if(theIsOn != a->isChecked()){
2886 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
2887 a->setChecked(theIsOn);
2888 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));