1 // Copyright (C) 2007-2008 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
22 // File : OCCViewer_ViewWindow.cxx
25 #include "OCCViewer_ViewWindow.h"
26 #include "OCCViewer_ViewModel.h"
27 #include "OCCViewer_ViewPort3d.h"
28 #include "OCCViewer_ViewManager.h"
29 #include "OCCViewer_ViewSketcher.h"
30 #include "OCCViewer_CreateRestoreViewDlg.h"
31 #include "OCCViewer_ClippingDlg.h"
32 #include "OCCViewer_SetRotationPointDlg.h"
33 #include "OCCViewer_AxialScaleDlg.h"
35 #include <SUIT_Desktop.h>
36 #include <SUIT_Session.h>
37 #include <SUIT_ViewManager.h>
38 #include <SUIT_Tools.h>
39 #include <SUIT_ResourceMgr.h>
40 #include <SUIT_MessageBox.h>
42 #include <QtxActionToolMgr.h>
43 #include <QtxMultiAction.h>
44 #include <QtxRubberBand.h>
49 #include <QMouseEvent>
50 #include <QApplication>
52 #include <V3d_Plane.hxx>
55 #include <TColgp_Array1OfPnt2d.hxx>
57 #include <AIS_ListOfInteractive.hxx>
58 #include <AIS_ListIteratorOfListOfInteractive.hxx>
59 #include <AIS_Shape.hxx>
61 #include <BRep_Tool.hxx>
64 #include <BRepBndLib.hxx>
65 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
66 #include <Visual3d_View.hxx>
67 #include <Graphic3d_MapOfStructure.hxx>
68 #include <Graphic3d_Structure.hxx>
69 #include <Graphic3d_ExportFormat.hxx>
71 static QEvent* l_mbPressEvent = 0;
74 # include <QWindowsStyle>
77 const char* imageZoomCursor[] = {
82 "................................",
83 "................................",
84 ".#######........................",
85 "..aaaaaaa.......................",
86 "................................",
87 ".............#####..............",
88 "...........##.aaaa##............",
89 "..........#.aa.....a#...........",
90 ".........#.a.........#..........",
91 ".........#a..........#a.........",
92 "........#.a...........#.........",
93 "........#a............#a........",
94 "........#a............#a........",
95 "........#a............#a........",
96 "........#a............#a........",
97 ".........#...........#.a........",
98 ".........#a..........#a.........",
99 ".........##.........#.a.........",
100 "........#####.....##.a..........",
101 ".......###aaa#####.aa...........",
102 "......###aa...aaaaa.......#.....",
103 ".....###aa................#a....",
104 "....###aa.................#a....",
105 "...###aa...............#######..",
106 "....#aa.................aa#aaaa.",
107 ".....a....................#a....",
108 "..........................#a....",
109 "...........................a....",
110 "................................",
111 "................................",
112 "................................",
113 "................................"};
115 const char* imageRotateCursor[] = {
120 "................................",
121 "................................",
122 "................................",
123 "................................",
124 "........#.......................",
125 ".......#.a......................",
126 "......#######...................",
127 ".......#aaaaa#####..............",
128 "........#..##.a#aa##........##..",
129 ".........a#.aa..#..a#.....##.aa.",
130 ".........#.a.....#...#..##.aa...",
131 ".........#a.......#..###.aa.....",
132 "........#.a.......#a..#aa.......",
133 "........#a.........#..#a........",
134 "........#a.........#a.#a........",
135 "........#a.........#a.#a........",
136 "........#a.........#a.#a........",
137 ".........#.........#a#.a........",
138 "........##a........#a#a.........",
139 "......##.a#.......#.#.a.........",
140 "....##.aa..##.....##.a..........",
141 "..##.aa.....a#####.aa...........",
142 "...aa.........aaa#a.............",
143 "................#.a.............",
144 "...............#.a..............",
145 "..............#.a...............",
146 "...............a................",
147 "................................",
148 "................................",
149 "................................",
150 "................................",
151 "................................"};
153 const char* imageCrossCursor[] = {
158 "................................",
159 "................................",
160 "................................",
161 "................................",
162 "................................",
163 "................................",
164 "................................",
165 "...............#................",
166 "...............#a...............",
167 "...............#a...............",
168 "...............#a...............",
169 "...............#a...............",
170 "...............#a...............",
171 "...............#a...............",
172 "...............#a...............",
173 ".......#################........",
174 "........aaaaaaa#aaaaaaaaa.......",
175 "...............#a...............",
176 "...............#a...............",
177 "...............#a...............",
178 "...............#a...............",
179 "...............#a...............",
180 "...............#a...............",
181 "...............#a...............",
182 "................a...............",
183 "................................",
184 "................................",
185 "................................",
186 "................................",
187 "................................",
188 "................................",
189 "................................"};
194 \param theDesktop main window of application
195 \param theModel OCC 3D viewer
197 OCCViewer_ViewWindow::OCCViewer_ViewWindow( SUIT_Desktop* theDesktop,
198 OCCViewer_Viewer* theModel )
199 : SUIT_ViewWindow( theDesktop )
203 myEnableDrawMode = false;
204 updateEnabledDrawMode();
207 mySetRotationPointDlg = 0;
217 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
220 qDeleteAll( mySketchers );
224 \brief Internal initialization.
226 void OCCViewer_ViewWindow::initLayout()
228 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
229 myViewPort->setBackgroundColor(Qt::black);
230 myViewPort->installEventFilter(this);
231 setCentralWidget(myViewPort);
232 myOperation = NOTHING;
234 myCurrPointType = GRAVITY;
235 myPrevPointType = GRAVITY;
236 mySelectedPoint = gp_Pnt(0.,0.,0.);
237 myRotationPointSelection = false;
239 setTransformRequested ( NOTHING );
240 setTransformInProcess ( false );
247 \brief Detect viewer operation according the the mouse button pressed
248 and key modifiers used.
249 \param theEvent mouse event
250 \return type of the operation
252 OCCViewer_ViewWindow::OperationType
253 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent )
255 OperationType aOp = NOTHING;
256 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::ZOOM]) &&
257 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::ZOOM]) )
259 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::PAN]) &&
260 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::PAN]) )
262 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::ROTATE]) &&
263 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::ROTATE]) )
270 \brief Customize event handling
271 \param watched event receiver object
273 \return \c true if the event processing should be stopped
275 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
277 if ( watched == myViewPort ) {
278 int aType = e->type();
280 case QEvent::MouseButtonPress:
281 vpMousePressEvent((QMouseEvent*) e);
284 case QEvent::MouseButtonRelease:
285 vpMouseReleaseEvent((QMouseEvent*) e);
288 case QEvent::MouseMove:
289 vpMouseMoveEvent((QMouseEvent*) e);
292 case QEvent::MouseButtonDblClick:
293 emit mouseDoubleClicked(this, (QMouseEvent*)e);
298 QWheelEvent* aEvent = (QWheelEvent*) e;
299 double aDelta = aEvent->delta();
300 double aScale = (aDelta < 0) ? 100./(-aDelta) : aDelta/100.;
301 myViewPort->getView()->SetZoom(aScale);
305 case QEvent::ContextMenu:
307 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
308 if ( aEvent->reason() != QContextMenuEvent::Mouse )
309 emit contextMenuRequested( aEvent );
317 return SUIT_ViewWindow::eventFilter(watched, e);
321 \brief Update state of enable draw mode state.
323 void OCCViewer_ViewWindow::updateEnabledDrawMode()
326 myEnableDrawMode = myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
330 \brief Handle mouse press event
331 \param theEvent mouse event
333 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
335 myStartX = theEvent->x();
336 myStartY = theEvent->y();
337 switch ( myOperation ) {
339 if ( theEvent->button() == Qt::LeftButton )
340 emit vpTransformationStarted ( WINDOWFIT );
344 if ( theEvent->button() == Qt::LeftButton )
345 emit vpTransformationStarted ( PANGLOBAL );
349 if ( theEvent->button() == Qt::LeftButton )
350 emit vpTransformationStarted ( ZOOMVIEW );
354 if ( theEvent->button() == Qt::LeftButton )
355 emit vpTransformationStarted ( PANVIEW );
359 if ( theEvent->button() == Qt::LeftButton ) {
360 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
361 emit vpTransformationStarted ( ROTATE );
366 /* Try to activate a transformation */
367 switch ( getButtonState(theEvent) ) {
376 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
379 if ( myRotationPointSelection )
381 if ( theEvent->button() == Qt::LeftButton )
383 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
385 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
387 TopoDS_Shape aShape = ic->SelectedShape();
388 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
390 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
391 if ( mySetRotationPointDlg )
393 myRotationPointSelection = false;
394 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
399 myCurrPointType = myPrevPointType;
403 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
404 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
405 ic->CloseAllContexts();
406 myOperation = NOTHING;
407 myViewPort->setCursor( myCursor );
408 myCursorIsHand = false;
409 myRotationPointSelection = false;
413 emit mousePressed(this, theEvent);
416 /* notify that we start a transformation */
417 if ( transformRequested() )
418 emit vpTransformationStarted ( myOperation );
420 if ( transformRequested() )
421 setTransformInProcess( true );
423 /* we may need it for sketching... */
424 if ( l_mbPressEvent )
425 delete l_mbPressEvent;
426 l_mbPressEvent = new QMouseEvent( *theEvent );
431 \brief Start zooming operation.
433 Sets the corresponding cursor for the widget.
435 void OCCViewer_ViewWindow::activateZoom()
437 if ( !transformRequested() && !myCursorIsHand )
438 myCursor = cursor(); /* save old cursor */
440 if ( myOperation != ZOOMVIEW ) {
441 QPixmap zoomPixmap (imageZoomCursor);
442 QCursor zoomCursor (zoomPixmap);
443 setTransformRequested ( ZOOMVIEW );
444 myViewPort->setCursor( zoomCursor );
450 \brief Start panning operation.
452 Sets the corresponding cursor for the widget.
454 void OCCViewer_ViewWindow::activatePanning()
456 if ( !transformRequested() && !myCursorIsHand )
457 myCursor = cursor(); // save old cursor
459 if ( myOperation != PANVIEW ) {
460 QCursor panCursor (Qt::SizeAllCursor);
461 setTransformRequested ( PANVIEW );
462 myViewPort->setCursor( panCursor );
467 \brief Start rotation operation
469 Sets the corresponding cursor for the widget.
471 void OCCViewer_ViewWindow::activateRotation()
473 if ( !transformRequested() && !myCursorIsHand )
474 myCursor = cursor(); // save old cursor
476 if ( myOperation != ROTATE ) {
477 QPixmap rotatePixmap (imageRotateCursor);
478 QCursor rotCursor (rotatePixmap);
479 setTransformRequested ( ROTATE );
480 myViewPort->setCursor( rotCursor );
485 \brief Compute the gravity center.
486 \param theX used to return X coordinate of the gravity center
487 \param theY used to return Y coordinate of the gravity center
488 \param theZ used to return Z coordinate of the gravity center
489 \return \c true if the gravity center is computed
491 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
493 Handle(Visual3d_View) aView = myViewPort->getView()->View();
495 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W ;
496 Standard_Real Umin,Vmin,Umax,Vmax ;
497 Standard_Integer Nstruct,Npoint ;
498 Graphic3d_MapOfStructure MySetOfStructures;
500 aView->DisplayedStructures (MySetOfStructures);
501 Nstruct = MySetOfStructures.Extent() ;
503 Graphic3d_MapIteratorOfMapOfStructure MyIterator(MySetOfStructures) ;
504 aView->ViewMapping().WindowLimit(Umin,Vmin,Umax,Vmax) ;
505 Npoint = 0 ; theX = theY = theZ = 0. ;
506 for( ; MyIterator.More(); MyIterator.Next()) {
507 if (!(MyIterator.Key())->IsEmpty()) {
508 (MyIterator.Key())->MinMaxValues(Xmin,Ymin,Zmin,
511 Standard_Real LIM = ShortRealLast() -1.;
512 if (! (fabs(Xmin) > LIM || fabs(Ymin) > LIM || fabs(Zmin) > LIM
513 || fabs(Xmax) > LIM || fabs(Ymax) > LIM || fabs(Zmax) > LIM )) {
515 aView->Projects(Xmin,Ymin,Zmin,U,V,W) ;
516 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
517 Npoint++ ; theX += Xmin ; theY += Ymin ; theZ += Zmin ;
519 aView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
520 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
521 Npoint++ ; theX += Xmax ; theY += Ymin ; theZ += Zmin ;
523 aView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
524 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
525 Npoint++ ; theX += Xmin ; theY += Ymax ; theZ += Zmin ;
527 aView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
528 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
529 Npoint++ ; theX += Xmax ; theY += Ymax ; theZ += Zmin ;
531 aView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
532 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
533 Npoint++ ; theX += Xmin ; theY += Ymin ; theZ += Zmax ;
535 aView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
536 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
537 Npoint++ ; theX += Xmax ; theY += Ymin ; theZ += Zmax ;
539 aView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
540 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
541 Npoint++ ; theX += Xmin ; theY += Ymax ; theZ += Zmax ;
543 aView->Projects(Xmax,Ymax,Zmax,U,V,W) ;
544 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
545 Npoint++ ; theX += Xmax ; theY += Ymax ; theZ += Zmax ;
551 theX /= Npoint ; theY /= Npoint ; theZ /= Npoint ;
557 \brief Set the gravity center as a rotation point.
559 void OCCViewer_ViewWindow::activateSetRotationGravity()
561 if ( myRotationPointSelection )
563 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
564 ic->CloseAllContexts();
565 myOperation = NOTHING;
566 myViewPort->setCursor( myCursor );
567 myCursorIsHand = false;
568 myRotationPointSelection = false;
571 myPrevPointType = myCurrPointType;
572 myCurrPointType = GRAVITY;
574 Standard_Real Xcenter, Ycenter, Zcenter;
575 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
576 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
580 \brief Update gravity center in the "Set Rotation Point" dialog box.
581 \sa OCCViewer_SetRotationPointDlg class
583 void OCCViewer_ViewWindow::updateGravityCoords()
585 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == GRAVITY )
587 Standard_Real Xcenter, Ycenter, Zcenter;
588 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
589 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
594 \brief Set the point selected by the user as a rotation point.
595 \param theX X coordinate of the rotation point
596 \param theY Y coordinate of the rotation point
597 \param theZ Z coordinate of the rotation point
599 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
601 if ( myRotationPointSelection )
603 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
604 ic->CloseAllContexts();
605 myOperation = NOTHING;
606 myViewPort->setCursor( myCursor );
607 myCursorIsHand = false;
608 myRotationPointSelection = false;
611 myPrevPointType = myCurrPointType;
612 myCurrPointType = SELECTED;
613 mySelectedPoint.SetCoord(theX,theY,theZ);
617 \brief Start the point selection process.
619 void OCCViewer_ViewWindow::activateStartPointSelection()
621 myPrevPointType = myCurrPointType;
622 myCurrPointType = SELECTED;
624 // activate selection ------>
625 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
627 ic->OpenLocalContext();
629 AIS_ListOfInteractive aList;
630 ic->DisplayedObjects( aList );
631 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
633 Handle(AIS_InteractiveObject) anObj = it.Value();
634 if ( !anObj.IsNull() && anObj->HasPresentation() &&
635 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
638 ic->Activate(anObj,AIS_Shape::SelectionMode(TopAbs_VERTEX));
641 // activate selection <------
643 if ( !myCursorIsHand )
645 QCursor handCursor (Qt::PointingHandCursor);
646 myCursorIsHand = true;
648 myViewPort->setCursor( handCursor );
650 myRotationPointSelection = true;
654 \brief Start global panning operation
656 Sets the corresponding cursor for the widget.
658 void OCCViewer_ViewWindow::activateGlobalPanning()
660 Handle(V3d_View) aView3d = myViewPort->getView();
661 if ( !aView3d.IsNull() ) {
662 QPixmap globalPanPixmap (imageCrossCursor);
663 QCursor glPanCursor (globalPanPixmap);
664 myCurScale = aView3d->Scale();
665 aView3d->FitAll(0.01, false);
666 myCursor = cursor(); // save old cursor
667 myViewPort->fitAll(); // fits view before selecting a new scene center
668 setTransformRequested( PANGLOBAL );
669 myViewPort->setCursor( glPanCursor );
674 \brief Starts fit operation.
676 Sets the corresponding cursor for the widget.
678 void OCCViewer_ViewWindow::activateWindowFit()
680 if ( !transformRequested() && !myCursorIsHand )
681 myCursor = cursor(); /* save old cursor */
683 if ( myOperation != WINDOWFIT ) {
684 QCursor handCursor (Qt::PointingHandCursor);
685 setTransformRequested ( WINDOWFIT );
686 myViewPort->setCursor ( handCursor );
687 myCursorIsHand = true;
692 \brief Start delayed viewer operation.
694 void OCCViewer_ViewWindow::setTransformRequested( OperationType op )
697 myViewPort->setMouseTracking( myOperation == NOTHING );
702 \brief Handle mouse move event.
703 \param theEvent mouse event
705 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
707 myCurrX = theEvent->x();
708 myCurrY = theEvent->y();
709 switch (myOperation) {
711 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
715 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
721 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
735 if ( myRotationPointSelection )
736 emit mouseMoving( this, theEvent );
739 int aState = theEvent->modifiers();
740 int aButton = theEvent->buttons();
741 if ( aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) {
742 myDrawRect = myEnableDrawMode;
745 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
746 QCursor handCursor (Qt::PointingHandCursor);
747 myCursorIsHand = true;
749 myViewPort->setCursor( handCursor );
753 else if ( aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) {
754 OCCViewer_ViewSketcher* sketcher = 0;
755 QList<OCCViewer_ViewSketcher*>::Iterator it;
756 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
758 OCCViewer_ViewSketcher* sk = (*it);
759 if( sk->isDefault() && sk->sketchButton() == aButton )
762 if ( sketcher && myCurSketch == -1 )
764 activateSketching( sketcher->type() );
767 myCurSketch = mypSketcher->sketchButton();
769 if ( l_mbPressEvent )
771 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
772 delete l_mbPressEvent;
775 QApplication::sendEvent( getViewPort(), theEvent );
780 emit mouseMoving( this, theEvent );
786 \brief Handle mouse release event.
787 \param theEvent mouse event
789 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
791 switch ( myOperation ) {
794 int prevState = myCurSketch;
795 if(theEvent->button() == Qt::RightButton)
797 QList<OCCViewer_ViewSketcher*>::Iterator it;
798 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
800 OCCViewer_ViewSketcher* sk = (*it);
801 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
806 emit mouseReleased(this, theEvent);
807 if(theEvent->button() == Qt::RightButton && prevState == -1)
809 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
810 theEvent->pos(), theEvent->globalPos() );
811 emit contextMenuRequested( &aEvent );
816 myViewPort->endRotation();
826 if ( theEvent->button() == Qt::LeftButton ) {
827 myViewPort->setCenter( theEvent->x(), theEvent->y() );
828 myViewPort->getView()->SetScale(myCurScale);
834 if ( theEvent->button() == Qt::LeftButton ) {
835 myCurrX = theEvent->x();
836 myCurrY = theEvent->y();
838 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
839 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
846 // NOTE: viewer 3D detects a rectangle of selection using this event
847 // so we must emit it BEFORE resetting the selection rectangle
849 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
853 myViewPort->update();
856 if ( l_mbPressEvent )
858 delete l_mbPressEvent;
864 \brief Reset the viewport to its initial state
865 ( no transformations in process etc. )
867 void OCCViewer_ViewWindow::resetState()
871 if ( myRotationPointSelection )
873 QCursor handCursor (Qt::PointingHandCursor);
874 myViewPort->setCursor( handCursor );
878 if ( transformRequested() || myCursorIsHand )
879 myViewPort->setCursor( myCursor );
880 myCursorIsHand = false;
883 if ( transformRequested() )
884 emit vpTransformationFinished (myOperation);
886 setTransformInProcess( false );
887 setTransformRequested( NOTHING );
892 \brief Draw rubber band rectangle.
894 void OCCViewer_ViewWindow::drawRect()
897 myRectBand = new QtxRectRubberBand( myViewPort );
899 //palette.setColor(myRectBand->foregroundRole(), Qt::white);
900 //myRectBand->setPalette(palette);
902 //myRectBand->hide();
904 myRectBand->setUpdatesEnabled ( false );
905 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
906 myRectBand->initGeometry( aRect );
908 if ( !myRectBand->isVisible() )
911 myRectBand->setUpdatesEnabled ( true );
912 //myRectBand->repaint();
914 //myRectBand->setVisible( aRect.isValid() );
915 //if ( myRectBand->isVisible() )
916 // myRectBand->repaint();
918 // myRectBand->show();
919 //myRectBand->repaint();
923 \brief Clear rubber band rectangle on the end on the dragging operation.
925 void OCCViewer_ViewWindow::endDrawRect()
931 myRectBand->clearGeometry();
937 \brief Create actions.
939 void OCCViewer_ViewWindow::createActions()
941 if( !toolMgr()->isEmpty() )
944 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
949 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
950 tr( "MNU_DUMP_VIEW" ), 0, this);
951 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
952 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
953 toolMgr()->registerAction( aAction, DumpId );
956 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
957 tr( "MNU_FITALL" ), 0, this);
958 aAction->setStatusTip(tr("DSC_FITALL"));
959 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
960 toolMgr()->registerAction( aAction, FitAllId );
963 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
964 tr( "MNU_FITRECT" ), 0, this);
965 aAction->setStatusTip(tr("DSC_FITRECT"));
966 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
967 toolMgr()->registerAction( aAction, FitRectId );
970 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
971 tr( "MNU_ZOOM_VIEW" ), 0, this);
972 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
973 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
974 toolMgr()->registerAction( aAction, ZoomId );
977 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
978 tr( "MNU_PAN_VIEW" ), 0, this);
979 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
980 connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
981 toolMgr()->registerAction( aAction, PanId );
984 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
985 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
986 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
987 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
988 toolMgr()->registerAction( aAction, GlobalPanId );
991 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
992 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
993 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
994 mySetRotationPointAction->setCheckable( true );
995 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
996 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
999 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1000 tr( "MNU_ROTATE_VIEW" ), 0, this);
1001 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1002 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1003 toolMgr()->registerAction( aAction, RotationId );
1006 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1007 tr( "MNU_FRONT_VIEW" ), 0, this);
1008 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1009 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1010 toolMgr()->registerAction( aAction, FrontId );
1012 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1013 tr( "MNU_BACK_VIEW" ), 0, this);
1014 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1015 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1016 toolMgr()->registerAction( aAction, BackId );
1018 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1019 tr( "MNU_TOP_VIEW" ), 0, this);
1020 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1021 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1022 toolMgr()->registerAction( aAction, TopId );
1024 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1025 tr( "MNU_BOTTOM_VIEW" ), 0, this);
1026 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1027 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1028 toolMgr()->registerAction( aAction, BottomId );
1030 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1031 tr( "MNU_LEFT_VIEW" ), 0, this);
1032 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1033 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1034 toolMgr()->registerAction( aAction, LeftId );
1036 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1037 tr( "MNU_RIGHT_VIEW" ), 0, this);
1038 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1039 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1040 toolMgr()->registerAction( aAction, RightId );
1043 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1044 tr( "MNU_RESET_VIEW" ), 0, this);
1045 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1046 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1047 toolMgr()->registerAction( aAction, ResetId );
1050 aAction = new QtxAction(tr("MNU_CLONE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CLONE_VIEW" ) ),
1051 tr( "MNU_CLONE_VIEW" ), 0, this);
1052 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1053 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1054 toolMgr()->registerAction( aAction, CloneId );
1056 myClippingAction = new QtxAction(tr("MNU_CLIPPING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CLIPPING" ) ),
1057 tr( "MNU_CLIPPING" ), 0, this);
1058 myClippingAction->setStatusTip(tr("DSC_CLIPPING"));
1059 myClippingAction->setCheckable( true );
1060 connect(myClippingAction, SIGNAL(toggled( bool )), this, SLOT(onClipping( bool )));
1061 toolMgr()->registerAction( myClippingAction, ClippingId );
1063 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1064 tr( "MNU_SHOOT_VIEW" ), 0, this);
1065 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1066 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1067 toolMgr()->registerAction( aAction, MemId );
1069 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1070 tr( "MNU_PRESETS_VIEW" ), 0, this);
1071 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1072 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1073 toolMgr()->registerAction( aAction, RestoreId );
1075 if (myModel->trihedronActivated()) {
1076 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1077 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1078 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1079 connect(aAction, SIGNAL(triggered()), this, SLOT(onTrihedronShow()));
1080 toolMgr()->registerAction( aAction, TrihedronShowId );
1084 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1085 tr( "MNU_SCALING" ), 0, this);
1086 aAction->setStatusTip(tr("DSC_SCALING"));
1087 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1088 toolMgr()->registerAction( aAction, AxialScaleId );
1092 \brief Create toolbar.
1094 void OCCViewer_ViewWindow::createToolBar()
1096 int tid = toolMgr()->createToolBar( tr( "LBL_TOOLBAR_LABEL" ) );
1098 toolMgr()->append( DumpId, tid );
1099 if( myModel->trihedronActivated() )
1100 toolMgr()->append( TrihedronShowId, tid );
1102 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1103 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1104 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1105 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1106 toolMgr()->append( aScaleAction, tid );
1108 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1109 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1110 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1111 toolMgr()->append( aPanningAction, tid );
1113 toolMgr()->append( ChangeRotationPointId, tid );
1114 toolMgr()->append( RotationId, tid );
1116 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1117 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1118 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1119 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1120 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1121 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1122 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1123 toolMgr()->append( aViewsAction, tid );
1125 toolMgr()->append( ResetId, tid );
1127 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1128 aMemAction->insertAction( toolMgr()->action( MemId ) );
1129 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1130 toolMgr()->append( aMemAction, tid );
1132 toolMgr()->append( toolMgr()->separator(), tid );
1133 toolMgr()->append( CloneId, tid );
1135 toolMgr()->append( toolMgr()->separator(), tid );
1136 toolMgr()->append( ClippingId, tid );
1137 toolMgr()->append( AxialScaleId, tid );
1141 \brief Perform 'fit all' operation.
1143 void OCCViewer_ViewWindow::onViewFitAll()
1145 myViewPort->fitAll();
1149 \brief Perform "front view" transformation.
1151 void OCCViewer_ViewWindow::onFrontView()
1153 emit vpTransformationStarted ( FRONTVIEW );
1154 Handle(V3d_View) aView3d = myViewPort->getView();
1155 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
1160 \brief Perform "back view" transformation.
1162 void OCCViewer_ViewWindow::onBackView()
1164 emit vpTransformationStarted ( BACKVIEW );
1165 Handle(V3d_View) aView3d = myViewPort->getView();
1166 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
1171 \brief Perform "top view" transformation.
1173 void OCCViewer_ViewWindow::onTopView()
1175 emit vpTransformationStarted ( TOPVIEW );
1176 Handle(V3d_View) aView3d = myViewPort->getView();
1177 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
1182 \brief Perform "bottom view" transformation.
1184 void OCCViewer_ViewWindow::onBottomView()
1186 emit vpTransformationStarted ( BOTTOMVIEW );
1187 Handle(V3d_View) aView3d = myViewPort->getView();
1188 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
1193 \brief Perform "left view" transformation.
1195 void OCCViewer_ViewWindow::onLeftView()
1197 emit vpTransformationStarted ( LEFTVIEW );
1198 Handle(V3d_View) aView3d = myViewPort->getView();
1199 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
1204 \brief Perform "right view" transformation.
1206 void OCCViewer_ViewWindow::onRightView()
1208 emit vpTransformationStarted ( RIGHTVIEW );
1209 Handle(V3d_View) aView3d = myViewPort->getView();
1210 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
1215 \brief Perform "reset view" transformation.
1217 Sets default orientation of the viewport camera.
1219 void OCCViewer_ViewWindow::onResetView()
1221 emit vpTransformationStarted( RESETVIEW );
1222 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1223 myViewPort->getView()->Reset( false );
1224 myViewPort->fitAll( false, true, false );
1225 myViewPort->getView()->SetImmediateUpdate( upd );
1226 myViewPort->getView()->Update();
1230 \brief Perform "fit all" transformation.
1232 void OCCViewer_ViewWindow::onFitAll()
1234 emit vpTransformationStarted( FITALLVIEW );
1235 myViewPort->fitAll();
1239 \brief Called if 'change rotation point' operation is activated.
1240 \param on action state
1242 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1246 if ( !mySetRotationPointDlg )
1248 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg( this, myDesktop );
1249 mySetRotationPointDlg->SetAction( mySetRotationPointAction );
1252 if ( !mySetRotationPointDlg->isVisible() )
1254 if ( mySetRotationPointDlg->IsFirstShown() )
1256 Standard_Real Xcenter, Ycenter, Zcenter;
1257 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
1258 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
1260 mySetRotationPointDlg->show();
1265 if ( mySetRotationPointDlg->isVisible() )
1266 mySetRotationPointDlg->hide();
1271 \brief Create one more window with same content.
1273 void OCCViewer_ViewWindow::onCloneView()
1275 SUIT_ViewWindow* vw = myManager->createViewWindow();
1277 emit viewCloned( vw );
1281 \brief called if clipping operation is activated.
1283 Enables/disables clipping plane displaying.
1285 \parma on action state
1287 void OCCViewer_ViewWindow::onClipping( bool on )
1290 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1292 myActionsMap[ ClippingId ]->setIcon(aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CLIPPING_PRESSED" )));
1294 myActionsMap[ ClippingId ]->setIcon(aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CLIPPING" )));
1298 if ( !myClippingDlg )
1300 myClippingDlg = new OCCViewer_ClippingDlg( this, myDesktop );
1301 myClippingDlg->SetAction( myClippingAction );
1304 if ( !myClippingDlg->isVisible() )
1305 myClippingDlg->show();
1309 if ( myClippingDlg->isVisible() )
1310 myClippingDlg->hide();
1311 setCuttingPlane(false);
1316 Creates one more window with same content
1318 void OCCViewer_ViewWindow::onAxialScale()
1320 if ( !myScalingDlg )
1321 myScalingDlg = new OCCViewer_AxialScaleDlg( this, myDesktop );
1323 if ( !myScalingDlg->isVisible() )
1324 myScalingDlg->show();
1328 \brief Store view parameters.
1330 void OCCViewer_ViewWindow::onMemorizeView()
1332 myModel->appendViewAspect( getViewParams() );
1336 \brief Restore view parameters.
1338 void OCCViewer_ViewWindow::onRestoreView()
1340 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), myModel );
1341 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
1343 myModel->updateViewAspects( aDlg->parameters() );
1344 if( myRestoreFlag && aDlg->parameters().count() )
1345 performRestoring( aDlg->currentItem() );
1349 \brief Restore view parameters.
1350 \param anItem view parameters
1352 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem )
1354 Handle(V3d_View) aView3d = myViewPort->getView();
1356 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
1357 aView3d->SetScale( anItem.scale );
1358 aView3d->SetCenter( anItem.centerX, anItem.centerY );
1359 aView3d->SetTwist( anItem.twist );
1360 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
1361 aView3d->SetImmediateUpdate( prev );
1362 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1363 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1364 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
1365 myModel->setTrihedronShown( anItem.isVisible );
1366 myModel->setTrihedronSize( anItem.size );
1372 \brief Set restore flag.
1374 void OCCViewer_ViewWindow::setRestoreFlag()
1380 \brief Called when action "show/hide trihedron" is activated.
1382 void OCCViewer_ViewWindow::onTrihedronShow()
1384 myModel->toggleTrihedron();
1388 \brief Dump view window contents to the pixmap.
1389 \return pixmap containing all scene rendered in the window
1391 QImage OCCViewer_ViewWindow::dumpView()
1393 QPixmap px = QPixmap::grabWindow( myViewPort->winId() );
1394 return px.toImage();
1397 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
1398 const QString& fileName,
1399 const QString& format )
1401 if ( format != "PS" && format != "EPS")
1402 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
1404 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
1407 a3dView->Export(qPrintable(fileName), Graphic3d_EF_PostScript);
1408 else if (format == "EPS")
1409 a3dView->Export(qPrintable(fileName), Graphic3d_EF_EnhPostScript);
1415 QString OCCViewer_ViewWindow::filter() const
1417 return tr( "OCC_IMAGE_FILES" );
1422 \brief Set parameters of the cutting plane
1423 \param on if \c true, cutting plane is enabled
1424 \param x X position of plane point
1425 \param y Y position of plane point
1426 \param z Z position of plane point
1427 \param dx X coordinate of plane normal
1428 \param dy Y coordinate of plane normal
1429 \param dz Z coordinate of plane normal
1431 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
1432 const double dx, const double dy, const double dz )
1434 Handle(V3d_View) view = myViewPort->getView();
1435 if ( view.IsNull() )
1439 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
1441 // try to use already existing plane or create a new one
1442 Handle(V3d_Plane) clipPlane;
1443 view->InitActivePlanes();
1444 if ( view->MoreActivePlanes() )
1445 clipPlane = view->ActivePlane();
1447 clipPlane = new V3d_Plane( viewer );
1449 // set new a,b,c,d values for the plane
1450 gp_Pln pln( gp_Pnt( x, y, z ), gp_Dir( dx, dy, dz ) );
1452 pln.Coefficients( a, b, c, d );
1453 clipPlane->SetPlane( a, b, c, d );
1455 view->SetPlaneOn( clipPlane );
1458 view->SetPlaneOff();
1465 \brief Check if any cutting plane is enabled
1466 \return \c true if at least one cutting plane is enabled
1468 bool OCCViewer_ViewWindow::isCuttingPlane()
1470 Handle(V3d_View) view = myViewPort->getView();
1471 view->InitActivePlanes();
1472 return (view->MoreActivePlanes());
1476 \brief Get the visual parameters of the view window.
1477 \return visual parameters of view window
1479 viewAspect OCCViewer_ViewWindow::getViewParams() const
1481 double centerX, centerY, projX, projY, projZ, twist;
1482 double atX, atY, atZ, eyeX, eyeY, eyeZ;
1483 double aScaleX, aScaleY, aScaleZ;
1485 Handle(V3d_View) aView3d = myViewPort->getView();
1487 aView3d->Center( centerX, centerY );
1488 aView3d->Proj( projX, projY, projZ );
1489 aView3d->At( atX, atY, atZ );
1490 aView3d->Eye( eyeX, eyeY, eyeZ );
1491 twist = aView3d->Twist();
1493 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
1495 bool isShown = myModel->isTrihedronVisible();
1496 double size = myModel->trihedronSize();
1498 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
1501 params.scale = aView3d->Scale();
1502 params.centerX = centerX;
1503 params.centerY = centerY;
1504 params.projX = projX;
1505 params.projY = projY;
1506 params.projZ = projZ;
1507 params.twist = twist;
1514 params.scaleX = aScaleX;
1515 params.scaleY = aScaleY;
1516 params.scaleZ = aScaleZ;
1517 params.name = aName;
1518 params.isVisible= isShown;
1526 \brief Get visual parameters of this view window.
1527 \return visual parameters of view window
1529 QString OCCViewer_ViewWindow::getVisualParameters()
1531 viewAspect params = getViewParams();
1533 retStr.sprintf( "%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e", params.scale,
1534 params.centerX, params.centerY, params.projX, params.projY, params.projZ, params.twist,
1535 params.atX, params.atY, params.atZ, params.eyeX, params.eyeY, params.eyeZ,
1536 params.scaleX, params.scaleY, params.scaleZ );
1537 retStr += QString().sprintf("*%u*%.2f", params.isVisible, params.size );
1542 \brief Restore visual parameters of the view window.
1543 \param parameters visual parameters of view window
1545 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
1547 QStringList paramsLst = parameters.split( '*' );
1548 if ( paramsLst.size() >= 15 ) {
1550 params.scale = paramsLst[0].toDouble();
1551 params.centerX = paramsLst[1].toDouble();
1552 params.centerY = paramsLst[2].toDouble();
1553 params.projX = paramsLst[3].toDouble();
1554 params.projY = paramsLst[4].toDouble();
1555 params.projZ = paramsLst[5].toDouble();
1556 params.twist = paramsLst[6].toDouble();
1557 params.atX = paramsLst[7].toDouble();
1558 params.atY = paramsLst[8].toDouble();
1559 params.atZ = paramsLst[9].toDouble();
1560 params.eyeX = paramsLst[10].toDouble();
1561 params.eyeY = paramsLst[11].toDouble();
1562 params.eyeZ = paramsLst[12].toDouble();
1563 if ( paramsLst.size() == 18 ) {
1564 params.scaleX = paramsLst[13].toDouble();
1565 params.scaleY = paramsLst[14].toDouble();
1566 params.scaleZ = paramsLst[15].toDouble();
1567 params.isVisible = paramsLst[16].toDouble();
1568 params.size = paramsLst[17].toDouble();
1575 performRestoring( params );
1580 \brief Handle show event.
1582 Emits Show() signal.
1584 \param theEvent show event
1586 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
1588 emit Show( theEvent );
1592 \brief Handle hide event.
1594 Emits Hide() signal.
1596 \param theEvent hide event
1598 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
1600 emit Hide( theEvent );
1605 Creates default sketcher. [ virtual protected ]
1607 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
1610 return new OCCViewer_RectSketcher( this, type );
1611 if ( type == Polygon )
1612 return new OCCViewer_PolygonSketcher( this, type );
1616 void OCCViewer_ViewWindow::initSketchers()
1618 if ( mySketchers.isEmpty() )
1620 mySketchers.append( createSketcher( Rect ) );
1621 mySketchers.append( createSketcher( Polygon ) );
1625 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
1627 OCCViewer_ViewSketcher* sketcher = 0;
1628 QList<OCCViewer_ViewSketcher*>::Iterator it;
1629 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
1631 OCCViewer_ViewSketcher* sk = (*it);
1632 if ( sk->type() == typ )
1639 Handles requests for sketching in the active view. [ virtual public ]
1641 void OCCViewer_ViewWindow::activateSketching( int type )
1643 OCCViewer_ViewPort3d* vp = getViewPort();
1647 if ( !vp->isSketchingEnabled() )
1650 /* Finish current sketching */
1651 if ( type == NoSketching )
1655 onSketchingFinished();
1656 mypSketcher->deactivate();
1660 /* Activate new sketching */
1663 activateSketching( NoSketching ); /* concurrency not suported */
1664 mypSketcher = getSketcher( type );
1667 mypSketcher->activate();
1668 onSketchingStarted();
1674 Unhilights detected entities. [ virtual protected ]
1676 void OCCViewer_ViewWindow::onSketchingStarted()
1681 Selection by rectangle or polygon. [ virtual protected ]
1683 void OCCViewer_ViewWindow::onSketchingFinished()
1685 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
1687 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
1688 bool append = bool( mypSketcher->buttonState() & Qt::ShiftModifier );
1689 switch( mypSketcher->type() )
1693 QRect* aRect = (QRect*)mypSketcher->data();
1696 int aLeft = aRect->left();
1697 int aRight = aRect->right();
1698 int aTop = aRect->top();
1699 int aBottom = aRect->bottom();
1702 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
1704 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
1710 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
1713 int size = aPolygon->size();
1714 TColgp_Array1OfPnt2d anArray( 1, size );
1716 QPolygon::Iterator it = aPolygon->begin();
1717 QPolygon::Iterator itEnd = aPolygon->end();
1718 for( int index = 1; it != itEnd; ++it, index++ )
1720 QPoint aPoint = *it;
1721 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
1725 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
1727 ic->Select( anArray, getViewPort()->getView(), Standard_False );
1735 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
1736 aViewMgr->getOCCViewer()->performSelectionChanged();
1740 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
1745 bool OCCViewer_ViewWindow::transformRequested() const
1747 return ( myOperation != NOTHING );
1750 bool OCCViewer_ViewWindow::transformInProcess() const
1752 return myEventStarted;
1755 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
1757 myEventStarted = bOn;