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_ClippingDlg.h"
33 #include "OCCViewer_SetRotationPointDlg.h"
34 #include "OCCViewer_AxialScaleDlg.h"
35 #include "OCCViewer_CubeAxesDlg.h"
37 #include <Basics_OCCTVersion.hxx>
39 #include <SUIT_Desktop.h>
40 #include <SUIT_Session.h>
41 #include <SUIT_ViewManager.h>
42 #include <SUIT_Tools.h>
43 #include <SUIT_ResourceMgr.h>
44 #include <SUIT_MessageBox.h>
45 #include <SUIT_Application.h>
47 #include <QtxActionToolMgr.h>
48 #include <QtxMultiAction.h>
49 #include <QtxRubberBand.h>
51 #include <OpenGLUtils_FrameBuffer.h>
57 #include <QMouseEvent>
58 #include <QApplication>
61 #include <AIS_ListOfInteractive.hxx>
62 #include <AIS_ListIteratorOfListOfInteractive.hxx>
63 #include <AIS_Shape.hxx>
65 #include <BRep_Tool.hxx>
66 #include <BRepBndLib.hxx>
69 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
70 #include <Graphic3d_MapOfStructure.hxx>
71 #include <Graphic3d_Structure.hxx>
72 #include <Graphic3d_ExportFormat.hxx>
74 #include <Visual3d_View.hxx>
75 #include <V3d_Plane.hxx>
76 #include <V3d_Light.hxx>
80 #include <TColgp_Array1OfPnt2d.hxx>
82 #include <Standard_Version.hxx>
84 #include "utilities.h"
88 // #include <highgui.h>
90 static QEvent* l_mbPressEvent = 0;
93 # include <QWindowsStyle>
98 const char* imageZoomCursor[] = {
103 "................................",
104 "................................",
105 ".#######........................",
106 "..aaaaaaa.......................",
107 "................................",
108 ".............#####..............",
109 "...........##.aaaa##............",
110 "..........#.aa.....a#...........",
111 ".........#.a.........#..........",
112 ".........#a..........#a.........",
113 "........#.a...........#.........",
114 "........#a............#a........",
115 "........#a............#a........",
116 "........#a............#a........",
117 "........#a............#a........",
118 ".........#...........#.a........",
119 ".........#a..........#a.........",
120 ".........##.........#.a.........",
121 "........#####.....##.a..........",
122 ".......###aaa#####.aa...........",
123 "......###aa...aaaaa.......#.....",
124 ".....###aa................#a....",
125 "....###aa.................#a....",
126 "...###aa...............#######..",
127 "....#aa.................aa#aaaa.",
128 ".....a....................#a....",
129 "..........................#a....",
130 "...........................a....",
131 "................................",
132 "................................",
133 "................................",
134 "................................"};
136 const char* imageRotateCursor[] = {
141 "................................",
142 "................................",
143 "................................",
144 "................................",
145 "........#.......................",
146 ".......#.a......................",
147 "......#######...................",
148 ".......#aaaaa#####..............",
149 "........#..##.a#aa##........##..",
150 ".........a#.aa..#..a#.....##.aa.",
151 ".........#.a.....#...#..##.aa...",
152 ".........#a.......#..###.aa.....",
153 "........#.a.......#a..#aa.......",
154 "........#a.........#..#a........",
155 "........#a.........#a.#a........",
156 "........#a.........#a.#a........",
157 "........#a.........#a.#a........",
158 ".........#.........#a#.a........",
159 "........##a........#a#a.........",
160 "......##.a#.......#.#.a.........",
161 "....##.aa..##.....##.a..........",
162 "..##.aa.....a#####.aa...........",
163 "...aa.........aaa#a.............",
164 "................#.a.............",
165 "...............#.a..............",
166 "..............#.a...............",
167 "...............a................",
168 "................................",
169 "................................",
170 "................................",
171 "................................",
172 "................................"};
174 const char* imageCrossCursor[] = {
179 "................................",
180 "................................",
181 "................................",
182 "................................",
183 "................................",
184 "................................",
185 "................................",
186 "...............#................",
187 "...............#a...............",
188 "...............#a...............",
189 "...............#a...............",
190 "...............#a...............",
191 "...............#a...............",
192 "...............#a...............",
193 "...............#a...............",
194 ".......#################........",
195 "........aaaaaaa#aaaaaaaaa.......",
196 "...............#a...............",
197 "...............#a...............",
198 "...............#a...............",
199 "...............#a...............",
200 "...............#a...............",
201 "...............#a...............",
202 "...............#a...............",
203 "................a...............",
204 "................................",
205 "................................",
206 "................................",
207 "................................",
208 "................................",
209 "................................",
210 "................................"};
215 \param theDesktop main window of application
216 \param theModel OCC 3D viewer
218 OCCViewer_ViewWindow::OCCViewer_ViewWindow( SUIT_Desktop* theDesktop,
219 OCCViewer_Viewer* theModel )
220 : SUIT_ViewWindow( theDesktop )
224 myEnableDrawMode = false;
226 updateEnabledDrawMode();
229 mySetRotationPointDlg = 0;
232 IsSketcherStyle = false;
239 myInteractionStyle = SUIT_ViewModel::STANDARD;
240 myPreselectionEnabled = true;
241 mySelectionEnabled = true;
251 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
254 qDeleteAll( mySketchers );
258 \brief Internal initialization.
260 void OCCViewer_ViewWindow::initLayout()
262 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
263 myViewPort->installEventFilter(this);
264 setCentralWidget(myViewPort);
265 myOperation = NOTHING;
267 myCurrPointType = GRAVITY;
268 myPrevPointType = GRAVITY;
269 mySelectedPoint = gp_Pnt(0.,0.,0.);
270 myRotationPointSelection = false;
272 setTransformRequested ( NOTHING );
273 setTransformInProcess ( false );
290 // Graduated axes dialog
291 QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
292 myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
293 myCubeAxesDlg->initialize();
295 connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
298 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
300 return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
304 \brief Detect viewer operation according the the mouse button pressed
305 and key modifiers used.
306 \param theEvent mouse event
307 \return type of the operation
309 OCCViewer_ViewWindow::OperationType
310 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
312 OperationType aOp = NOTHING;
313 SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
314 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
315 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
317 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
318 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
320 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
321 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
322 (my2dMode == No2dMode))
329 \brief Customize event handling
330 \param watched event receiver object
332 \return \c true if the event processing should be stopped
334 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
336 if ( watched == myViewPort ) {
337 int aType = e->type();
339 case QEvent::MouseButtonPress:
340 vpMousePressEvent((QMouseEvent*) e);
343 case QEvent::MouseButtonRelease:
344 vpMouseReleaseEvent((QMouseEvent*) e);
347 case QEvent::MouseMove:
348 vpMouseMoveEvent((QMouseEvent*) e);
351 case QEvent::MouseButtonDblClick:
352 emit mouseDoubleClicked(this, (QMouseEvent*)e);
357 QWheelEvent* aEvent = (QWheelEvent*) e;
358 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
359 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
362 int x1 = (int)( aEvent->x() + width()*delta/100 );
363 int y1 = (int)( aEvent->y() + height()*delta/100 );
364 myViewPort->zoom( x, y, x1, y1 );
368 case QEvent::ContextMenu:
370 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
371 if ( aEvent->reason() != QContextMenuEvent::Mouse )
372 emit contextMenuRequested( aEvent );
376 case QEvent::KeyPress:
377 emit keyPressed(this, (QKeyEvent*) e);
384 return SUIT_ViewWindow::eventFilter(watched, e);
388 \brief Update state of enable draw mode state.
390 void OCCViewer_ViewWindow::updateEnabledDrawMode()
393 myEnableDrawMode = myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
397 \brief Handle mouse press event
398 \param theEvent mouse event
400 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
402 myStartX = theEvent->x();
403 myStartY = theEvent->y();
404 int anInteractionStyle = interactionStyle();
406 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
407 // which are assigned for pan and rotate - these operations are activated immediately after pressing
408 // of the first button, so it is necessary to switch to zoom when the second button is pressed
409 bool aSwitchToZoom = false;
410 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
411 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
412 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
415 switch ( myOperation ) {
417 if ( theEvent->button() == Qt::LeftButton )
418 emit vpTransformationStarted ( WINDOWFIT );
422 if ( theEvent->button() == Qt::LeftButton )
423 emit vpTransformationStarted ( PANGLOBAL );
427 if ( theEvent->button() == Qt::LeftButton ) {
428 myViewPort->startZoomAtPoint( myStartX, myStartY );
429 emit vpTransformationStarted ( ZOOMVIEW );
434 if ( aSwitchToZoom ) {
435 myViewPort->startZoomAtPoint( myStartX, myStartY );
438 else if ( theEvent->button() == Qt::LeftButton )
439 emit vpTransformationStarted ( PANVIEW );
443 if ( aSwitchToZoom ) {
444 myViewPort->startZoomAtPoint( myStartX, myStartY );
447 else if ( theEvent->button() == Qt::LeftButton ) {
448 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
449 emit vpTransformationStarted ( ROTATE );
454 /* Try to activate a transformation */
455 OperationType aState;
456 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
457 aState = getButtonState(theEvent, anInteractionStyle);
459 aState = OCCViewer_ViewWindow::NOTHING;
464 myViewPort->startZoomAtPoint( myStartX, myStartY );
472 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
475 if ( myRotationPointSelection )
477 if ( theEvent->button() == Qt::LeftButton )
479 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
481 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
483 TopoDS_Shape aShape = ic->SelectedShape();
484 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
486 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
487 if ( mySetRotationPointDlg )
489 myRotationPointSelection = false;
490 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
495 myCurrPointType = myPrevPointType;
499 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
500 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
501 ic->CloseAllContexts();
502 myOperation = NOTHING;
503 myViewPort->setCursor( myCursor );
504 myCursorIsHand = false;
505 myRotationPointSelection = false;
509 emit mousePressed(this, theEvent);
512 /* notify that we start a transformation */
513 if ( transformRequested() )
514 emit vpTransformationStarted ( myOperation );
516 if ( transformRequested() )
517 setTransformInProcess( true );
519 /* we may need it for sketching... */
520 if ( l_mbPressEvent )
521 delete l_mbPressEvent;
522 l_mbPressEvent = new QMouseEvent( *theEvent );
527 \brief Start zooming operation.
529 Sets the corresponding cursor for the widget.
531 void OCCViewer_ViewWindow::activateZoom()
533 if ( !transformRequested() && !myCursorIsHand )
534 myCursor = cursor(); /* save old cursor */
536 if ( myOperation != ZOOMVIEW ) {
537 QPixmap zoomPixmap (imageZoomCursor);
538 QCursor zoomCursor (zoomPixmap);
539 if( setTransformRequested ( ZOOMVIEW ) )
540 myViewPort->setCursor( zoomCursor );
546 \brief Start panning operation.
548 Sets the corresponding cursor for the widget.
550 void OCCViewer_ViewWindow::activatePanning()
552 if ( !transformRequested() && !myCursorIsHand )
553 myCursor = cursor(); // save old cursor
555 if ( myOperation != PANVIEW ) {
556 QCursor panCursor (Qt::SizeAllCursor);
557 if( setTransformRequested ( PANVIEW ) )
558 myViewPort->setCursor( panCursor );
563 \brief Start rotation operation
565 Sets the corresponding cursor for the widget.
567 void OCCViewer_ViewWindow::activateRotation()
569 if ( !transformRequested() && !myCursorIsHand )
570 myCursor = cursor(); // save old cursor
572 if ( myOperation != ROTATE ) {
573 QPixmap rotatePixmap (imageRotateCursor);
574 QCursor rotCursor (rotatePixmap);
575 if( setTransformRequested ( ROTATE ) )
576 myViewPort->setCursor( rotCursor );
581 \brief Compute the gravity center.
582 \param theX used to return X coordinate of the gravity center
583 \param theY used to return Y coordinate of the gravity center
584 \param theZ used to return Z coordinate of the gravity center
585 \return \c true if the gravity center is computed
587 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
589 Handle(Visual3d_View) aView = myViewPort->getView()->View();
591 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W ;
592 Standard_Real Umin,Vmin,Umax,Vmax ;
593 Standard_Integer Nstruct,Npoint ;
594 Graphic3d_MapOfStructure MySetOfStructures;
596 aView->DisplayedStructures (MySetOfStructures);
597 Nstruct = MySetOfStructures.Extent() ;
599 Graphic3d_MapIteratorOfMapOfStructure MyIterator(MySetOfStructures) ;
600 aView->ViewMapping().WindowLimit(Umin,Vmin,Umax,Vmax) ;
601 Npoint = 0 ; theX = theY = theZ = 0. ;
602 for( ; MyIterator.More(); MyIterator.Next()) {
603 if (!(MyIterator.Key())->IsEmpty()) {
604 (MyIterator.Key())->MinMaxValues(Xmin,Ymin,Zmin,
607 Standard_Real LIM = ShortRealLast() -1.;
608 if (! (fabs(Xmin) > LIM || fabs(Ymin) > LIM || fabs(Zmin) > LIM
609 || fabs(Xmax) > LIM || fabs(Ymax) > LIM || fabs(Zmax) > LIM )) {
611 aView->Projects(Xmin,Ymin,Zmin,U,V,W) ;
612 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
613 Npoint++ ; theX += Xmin ; theY += Ymin ; theZ += Zmin ;
615 aView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
616 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
617 Npoint++ ; theX += Xmax ; theY += Ymin ; theZ += Zmin ;
619 aView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
620 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
621 Npoint++ ; theX += Xmin ; theY += Ymax ; theZ += Zmin ;
623 aView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
624 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
625 Npoint++ ; theX += Xmax ; theY += Ymax ; theZ += Zmin ;
627 aView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
628 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
629 Npoint++ ; theX += Xmin ; theY += Ymin ; theZ += Zmax ;
631 aView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
632 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
633 Npoint++ ; theX += Xmax ; theY += Ymin ; theZ += Zmax ;
635 aView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
636 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
637 Npoint++ ; theX += Xmin ; theY += Ymax ; theZ += Zmax ;
639 aView->Projects(Xmax,Ymax,Zmax,U,V,W) ;
640 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
641 Npoint++ ; theX += Xmax ; theY += Ymax ; theZ += Zmax ;
647 theX /= Npoint ; theY /= Npoint ; theZ /= Npoint ;
653 \brief Set the gravity center as a rotation point.
655 void OCCViewer_ViewWindow::activateSetRotationGravity()
657 if ( myRotationPointSelection )
659 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
660 ic->CloseAllContexts();
661 myOperation = NOTHING;
662 myViewPort->setCursor( myCursor );
663 myCursorIsHand = false;
664 myRotationPointSelection = false;
667 myPrevPointType = myCurrPointType;
668 myCurrPointType = GRAVITY;
670 Standard_Real Xcenter, Ycenter, Zcenter;
671 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
672 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
676 \brief Update gravity center in the "Set Rotation Point" dialog box.
677 \sa OCCViewer_SetRotationPointDlg class
679 void OCCViewer_ViewWindow::updateGravityCoords()
681 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == GRAVITY )
683 Standard_Real Xcenter, Ycenter, Zcenter;
684 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
685 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
690 \brief Set the point selected by the user as a rotation point.
691 \param theX X coordinate of the rotation point
692 \param theY Y coordinate of the rotation point
693 \param theZ Z coordinate of the rotation point
695 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
697 if ( myRotationPointSelection )
699 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
700 ic->CloseAllContexts();
701 myOperation = NOTHING;
702 myViewPort->setCursor( myCursor );
703 myCursorIsHand = false;
704 myRotationPointSelection = false;
707 myPrevPointType = myCurrPointType;
708 myCurrPointType = SELECTED;
709 mySelectedPoint.SetCoord(theX,theY,theZ);
713 \brief Start the point selection process.
715 void OCCViewer_ViewWindow::activateStartPointSelection()
717 myPrevPointType = myCurrPointType;
718 myCurrPointType = SELECTED;
720 // activate selection ------>
721 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
723 ic->OpenLocalContext();
725 AIS_ListOfInteractive aList;
726 ic->DisplayedObjects( aList );
727 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
729 Handle(AIS_InteractiveObject) anObj = it.Value();
730 if ( !anObj.IsNull() && anObj->HasPresentation() &&
731 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
734 ic->Activate(anObj,AIS_Shape::SelectionMode(TopAbs_VERTEX));
737 // activate selection <------
739 if ( !myCursorIsHand )
741 QCursor handCursor (Qt::PointingHandCursor);
742 myCursorIsHand = true;
744 myViewPort->setCursor( handCursor );
746 myRotationPointSelection = true;
750 \brief Start global panning operation
752 Sets the corresponding cursor for the widget.
754 void OCCViewer_ViewWindow::activateGlobalPanning()
756 Handle(V3d_View) aView3d = myViewPort->getView();
757 if ( !aView3d.IsNull() ) {
758 QPixmap globalPanPixmap (imageCrossCursor);
759 QCursor glPanCursor (globalPanPixmap);
760 myCurScale = aView3d->Scale();
761 aView3d->FitAll(0.01, false);
762 myCursor = cursor(); // save old cursor
763 myViewPort->fitAll(); // fits view before selecting a new scene center
764 if( setTransformRequested( PANGLOBAL ) )
765 myViewPort->setCursor( glPanCursor );
770 \brief Starts fit operation.
772 Sets the corresponding cursor for the widget.
774 void OCCViewer_ViewWindow::activateWindowFit()
776 if ( !transformRequested() && !myCursorIsHand )
777 myCursor = cursor(); /* save old cursor */
779 if ( myOperation != WINDOWFIT ) {
780 QCursor handCursor (Qt::PointingHandCursor);
781 if( setTransformRequested ( WINDOWFIT ) )
783 myViewPort->setCursor ( handCursor );
784 myCursorIsHand = true;
790 \brief Start delayed viewer operation.
792 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
794 bool ok = transformEnabled( op );
795 myOperation = ok ? op : NOTHING;
796 myViewPort->setMouseTracking( myOperation == NOTHING );
801 \brief Handle mouse move event.
802 \param theEvent mouse event
804 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
806 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
808 switch ( getButtonState( theEvent, interactionStyle() ) ) {
810 myViewPort->startZoomAtPoint( myStartX, myStartY );
818 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
825 myCurrX = theEvent->x();
826 myCurrY = theEvent->y();
827 switch (myOperation) {
829 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
833 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
839 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
853 if ( myRotationPointSelection || isSketcherStyle() )
855 emit mouseMoving( this, theEvent );
859 int aState = theEvent->modifiers();
860 int aButton = theEvent->buttons();
861 int anInteractionStyle = interactionStyle();
862 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
863 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
864 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
865 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
866 myDrawRect = myEnableDrawMode;
869 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
870 QCursor handCursor (Qt::PointingHandCursor);
871 myCursorIsHand = true;
873 myViewPort->setCursor( handCursor );
876 emit mouseMoving( this, theEvent );
878 else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
879 aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
880 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
881 aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
882 OCCViewer_ViewSketcher* sketcher = 0;
883 QList<OCCViewer_ViewSketcher*>::Iterator it;
884 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
886 OCCViewer_ViewSketcher* sk = (*it);
887 if( sk->isDefault() && sk->sketchButton() == aButton )
890 if ( sketcher && myCurSketch == -1 )
892 activateSketching( sketcher->type() );
895 myCurSketch = mypSketcher->sketchButton();
897 if ( l_mbPressEvent )
899 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
900 delete l_mbPressEvent;
903 QApplication::sendEvent( getViewPort(), theEvent );
908 emit mouseMoving( this, theEvent );
914 \brief Handle mouse release event.
915 \param theEvent mouse event
917 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
919 switch ( myOperation ) {
922 int prevState = myCurSketch;
923 if(theEvent->button() == Qt::RightButton)
925 QList<OCCViewer_ViewSketcher*>::Iterator it;
926 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
928 OCCViewer_ViewSketcher* sk = (*it);
929 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
934 emit mouseReleased(this, theEvent);
935 if(theEvent->button() == Qt::RightButton && prevState == -1)
937 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
938 theEvent->pos(), theEvent->globalPos() );
939 emit contextMenuRequested( &aEvent );
944 myViewPort->endRotation();
954 if ( theEvent->button() == Qt::LeftButton ) {
955 myViewPort->setCenter( theEvent->x(), theEvent->y() );
956 myViewPort->getView()->SetScale(myCurScale);
962 if ( theEvent->button() == Qt::LeftButton ) {
963 myCurrX = theEvent->x();
964 myCurrY = theEvent->y();
966 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
967 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
974 // NOTE: viewer 3D detects a rectangle of selection using this event
975 // so we must emit it BEFORE resetting the selection rectangle
977 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
981 myViewPort->update();
984 if ( l_mbPressEvent )
986 delete l_mbPressEvent;
992 \brief Reset the viewport to its initial state
993 ( no transformations in process etc. )
995 void OCCViewer_ViewWindow::resetState()
999 if ( myRotationPointSelection )
1001 QCursor handCursor (Qt::PointingHandCursor);
1002 myViewPort->setCursor( handCursor );
1006 if ( transformRequested() || myCursorIsHand )
1007 myViewPort->setCursor( myCursor );
1008 myCursorIsHand = false;
1011 if ( transformRequested() )
1012 emit vpTransformationFinished (myOperation);
1014 setTransformInProcess( false );
1015 setTransformRequested( NOTHING );
1020 \brief Draw rubber band rectangle.
1022 void OCCViewer_ViewWindow::drawRect()
1024 if ( !myRectBand ) {
1025 myRectBand = new QtxRectRubberBand( myViewPort );
1027 //palette.setColor(myRectBand->foregroundRole(), Qt::white);
1028 //myRectBand->setPalette(palette);
1030 //myRectBand->hide();
1032 myRectBand->setUpdatesEnabled ( false );
1033 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1034 myRectBand->initGeometry( aRect );
1036 if ( !myRectBand->isVisible() )
1039 myRectBand->setUpdatesEnabled ( true );
1040 //myRectBand->repaint();
1042 //myRectBand->setVisible( aRect.isValid() );
1043 //if ( myRectBand->isVisible() )
1044 // myRectBand->repaint();
1046 // myRectBand->show();
1047 //myRectBand->repaint();
1051 \brief Clear rubber band rectangle on the end on the dragging operation.
1053 void OCCViewer_ViewWindow::endDrawRect()
1055 //delete myRectBand;
1059 myRectBand->clearGeometry();
1065 \brief Create actions.
1067 void OCCViewer_ViewWindow::createActions()
1069 if( !toolMgr()->isEmpty() )
1072 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1077 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1078 tr( "MNU_DUMP_VIEW" ), 0, this);
1079 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1080 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1081 toolMgr()->registerAction( aAction, DumpId );
1084 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1085 tr( "MNU_FITALL" ), 0, this);
1086 aAction->setStatusTip(tr("DSC_FITALL"));
1087 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1088 toolMgr()->registerAction( aAction, FitAllId );
1091 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1092 tr( "MNU_FITRECT" ), 0, this);
1093 aAction->setStatusTip(tr("DSC_FITRECT"));
1094 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1095 toolMgr()->registerAction( aAction, FitRectId );
1098 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1099 tr( "MNU_ZOOM_VIEW" ), 0, this);
1100 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1101 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1102 toolMgr()->registerAction( aAction, ZoomId );
1105 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1106 tr( "MNU_PAN_VIEW" ), 0, this);
1107 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1108 connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
1109 toolMgr()->registerAction( aAction, PanId );
1112 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1113 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1114 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1115 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1116 toolMgr()->registerAction( aAction, GlobalPanId );
1119 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1120 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1121 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1122 mySetRotationPointAction->setCheckable( true );
1123 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1124 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1127 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1128 tr( "MNU_ROTATE_VIEW" ), 0, this);
1129 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1130 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1131 toolMgr()->registerAction( aAction, RotationId );
1134 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1135 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1136 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1137 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1138 this->addAction(aAction);
1139 toolMgr()->registerAction( aAction, FrontId );
1141 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1142 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1143 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1144 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1145 this->addAction(aAction);
1146 toolMgr()->registerAction( aAction, BackId );
1148 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1149 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1150 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1151 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1152 this->addAction(aAction);
1153 toolMgr()->registerAction( aAction, TopId );
1155 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1156 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1157 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1158 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1159 this->addAction(aAction);
1160 toolMgr()->registerAction( aAction, BottomId );
1162 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1163 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1164 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1165 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1166 this->addAction(aAction);
1167 toolMgr()->registerAction( aAction, LeftId );
1169 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1170 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1171 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1172 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1173 this->addAction(aAction);
1174 toolMgr()->registerAction( aAction, RightId );
1176 // rotate anticlockwise
1177 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1178 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1179 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1180 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1181 this->addAction(aAction);
1182 toolMgr()->registerAction( aAction, AntiClockWiseId );
1185 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1186 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1187 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1188 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1189 this->addAction(aAction);
1190 toolMgr()->registerAction( aAction, ClockWiseId );
1193 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1194 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1195 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1196 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1197 this->addAction(aAction);
1198 toolMgr()->registerAction( aAction, ResetId );
1201 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1202 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1203 tr("MNU_CLONE_VIEW"), 0, this);
1204 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1205 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1206 toolMgr()->registerAction( aAction, CloneId );
1208 myClippingAction = new QtxAction(tr("MNU_CLIPPING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CLIPPING" ) ),
1209 tr( "MNU_CLIPPING" ), 0, this);
1210 myClippingAction->setStatusTip(tr("DSC_CLIPPING"));
1211 myClippingAction->setCheckable( true );
1212 connect(myClippingAction, SIGNAL(toggled( bool )), this, SLOT(onClipping( bool )));
1213 toolMgr()->registerAction( myClippingAction, ClippingId );
1215 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1216 tr( "MNU_SHOOT_VIEW" ), 0, this);
1217 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1218 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1219 toolMgr()->registerAction( aAction, MemId );
1221 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1222 tr( "MNU_PRESETS_VIEW" ), 0, this);
1223 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1224 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1225 toolMgr()->registerAction( aAction, RestoreId );
1227 if (myModel->trihedronActivated()) {
1228 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1229 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1230 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1231 connect(aAction, SIGNAL(triggered()), this, SLOT(onTrihedronShow()));
1232 toolMgr()->registerAction( aAction, TrihedronShowId );
1236 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1237 tr( "MNU_SCALING" ), 0, this);
1238 aAction->setStatusTip(tr("DSC_SCALING"));
1239 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1240 toolMgr()->registerAction( aAction, AxialScaleId );
1242 // Enable/disable preselection
1243 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1244 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1245 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1246 aAction->setCheckable(true);
1247 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1248 toolMgr()->registerAction( aAction, SwitchPreselectionId );
1250 // Enable/disable selection
1251 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1252 tr( "MNU_ENABLE_SELECTION" ), 0, this);
1253 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1254 aAction->setCheckable(true);
1255 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1256 toolMgr()->registerAction( aAction, SwitchSelectionId );
1259 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1260 tr( "MNU_GRADUATED_AXES" ), 0, this);
1261 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1262 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1263 toolMgr()->registerAction( aAction, GraduatedAxesId );
1265 // Active only ambient light or not
1266 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1267 tr( "MNU_AMBIENT" ), 0, this);
1268 aAction->setStatusTip(tr("DSC_AMBIENT"));
1269 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1270 toolMgr()->registerAction( aAction, AmbientId );
1272 // Switch between interaction styles
1273 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1274 tr( "MNU_STYLE_SWITCH" ), 0, this);
1275 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1276 aAction->setCheckable(true);
1277 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1278 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1280 // Switch between zooming styles
1281 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1282 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1283 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1284 aAction->setCheckable(true);
1285 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1286 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1289 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1290 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1291 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1292 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1293 toolMgr()->registerAction( aAction, MaximizedId );
1296 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1300 \brief Create toolbar.
1302 void OCCViewer_ViewWindow::createToolBar()
1304 QString aToolbarName;
1307 aToolbarName = tr( "LBL_XYTOOLBAR_LABEL" );
1310 aToolbarName = tr( "LBL_XZTOOLBAR_LABEL" );
1313 aToolbarName = tr( "LBL_YZTOOLBAR_LABEL" );
1316 aToolbarName = tr( "LBL_3DTOOLBAR_LABEL" );
1319 int tid = toolMgr()->createToolBar( aToolbarName, false );
1321 toolMgr()->append( DumpId, tid );
1322 toolMgr()->append( SwitchInteractionStyleId, tid );
1323 #if OCC_VERSION_LARGE > 0x0603000A // available only with OCC-6.3-sp11 and higher version
1324 toolMgr()->append( SwitchZoomingStyleId, tid );
1326 toolMgr()->append( SwitchPreselectionId, tid );
1327 toolMgr()->append( SwitchSelectionId, tid );
1328 if( myModel->trihedronActivated() )
1329 toolMgr()->append( TrihedronShowId, tid );
1331 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1332 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1333 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1334 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1335 toolMgr()->append( aScaleAction, tid );
1337 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1338 aPanningAction->insertAction( toolMgr()->action( PanId ) );
1339 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1340 toolMgr()->append( aPanningAction, tid );
1342 if (my2dMode == No2dMode) {
1343 toolMgr()->append( ChangeRotationPointId, tid );
1344 toolMgr()->append( RotationId, tid );
1346 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1347 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1348 aViewsAction->insertAction( toolMgr()->action( BackId ) );
1349 aViewsAction->insertAction( toolMgr()->action( TopId ) );
1350 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1351 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1352 aViewsAction->insertAction( toolMgr()->action( RightId ) );
1353 toolMgr()->append( aViewsAction, tid );
1355 toolMgr()->append( AntiClockWiseId, tid );
1356 toolMgr()->append( ClockWiseId, tid );
1358 toolMgr()->append( ResetId, tid );
1361 QtxMultiAction* aMemAction = new QtxMultiAction( this );
1362 aMemAction->insertAction( toolMgr()->action( MemId ) );
1363 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1364 toolMgr()->append( aMemAction, tid );
1366 toolMgr()->append( toolMgr()->separator(), tid );
1367 toolMgr()->append( CloneId, tid );
1369 toolMgr()->append( toolMgr()->separator(), tid );
1370 toolMgr()->append( ClippingId, tid );
1371 toolMgr()->append( AxialScaleId, tid );
1372 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
1373 toolMgr()->append( GraduatedAxesId, tid );
1375 toolMgr()->append( AmbientId, tid );
1377 toolMgr()->append( MaximizedId, tid );
1378 toolMgr()->append( SynchronizeId, tid );
1382 \brief Perform 'fit all' operation.
1384 void OCCViewer_ViewWindow::onViewFitAll()
1386 myViewPort->fitAll();
1390 \brief Perform "front view" transformation.
1392 void OCCViewer_ViewWindow::onFrontView()
1394 emit vpTransformationStarted ( FRONTVIEW );
1395 Handle(V3d_View) aView3d = myViewPort->getView();
1396 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
1398 emit vpTransformationFinished ( FRONTVIEW );
1402 \brief Perform "back view" transformation.
1404 void OCCViewer_ViewWindow::onBackView()
1406 emit vpTransformationStarted ( BACKVIEW );
1407 Handle(V3d_View) aView3d = myViewPort->getView();
1408 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
1410 emit vpTransformationFinished ( BACKVIEW );
1414 \brief Perform "top view" transformation.
1416 void OCCViewer_ViewWindow::onTopView()
1418 emit vpTransformationStarted ( TOPVIEW );
1419 Handle(V3d_View) aView3d = myViewPort->getView();
1420 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
1422 emit vpTransformationFinished ( TOPVIEW );
1426 \brief Perform "bottom view" transformation.
1428 void OCCViewer_ViewWindow::onBottomView()
1430 emit vpTransformationStarted ( BOTTOMVIEW );
1431 Handle(V3d_View) aView3d = myViewPort->getView();
1432 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
1434 emit vpTransformationFinished ( BOTTOMVIEW );
1438 \brief Perform "left view" transformation.
1440 void OCCViewer_ViewWindow::onLeftView()
1442 emit vpTransformationStarted ( LEFTVIEW );
1443 Handle(V3d_View) aView3d = myViewPort->getView();
1444 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
1446 emit vpTransformationFinished ( LEFTVIEW );
1450 \brief Perform "right view" transformation.
1452 void OCCViewer_ViewWindow::onRightView()
1454 emit vpTransformationStarted ( RIGHTVIEW );
1455 Handle(V3d_View) aView3d = myViewPort->getView();
1456 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
1458 emit vpTransformationFinished ( RIGHTVIEW );
1462 \brief Rotate view 90 degrees clockwise
1464 void OCCViewer_ViewWindow::onClockWiseView()
1466 emit vpTransformationStarted ( CLOCKWISEVIEW );
1467 myViewPort->rotateXY( 90. );
1468 emit vpTransformationFinished ( CLOCKWISEVIEW );
1472 \brief Rotate view 90 degrees conterclockwise
1474 void OCCViewer_ViewWindow::onAntiClockWiseView()
1476 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1477 myViewPort->rotateXY( -90. );
1478 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1482 \brief Perform "reset view" transformation.
1484 Sets default orientation of the viewport camera.
1486 void OCCViewer_ViewWindow::onResetView()
1488 emit vpTransformationStarted( RESETVIEW );
1489 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1490 myViewPort->getView()->Reset( false );
1491 myViewPort->fitAll( false, true, false );
1492 myViewPort->getView()->SetImmediateUpdate( upd );
1493 myViewPort->getView()->Update();
1494 emit vpTransformationFinished( RESETVIEW );
1498 \brief Perform "fit all" transformation.
1500 void OCCViewer_ViewWindow::onFitAll()
1502 emit vpTransformationStarted( FITALLVIEW );
1503 myViewPort->fitAll();
1504 emit vpTransformationFinished( FITALLVIEW );
1508 \brief Called if 'change rotation point' operation is activated.
1509 \param on action state
1511 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1515 if (!mySetRotationPointDlg)
1517 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1518 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1521 if (!mySetRotationPointDlg->isVisible())
1523 //if (mySetRotationPointDlg->IsFirstShown())
1524 if (myCurrPointType == GRAVITY)
1526 Standard_Real Xcenter, Ycenter, Zcenter;
1527 if (computeGravityCenter(Xcenter, Ycenter, Zcenter))
1528 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1530 mySetRotationPointDlg->show();
1535 if (mySetRotationPointDlg->isVisible())
1536 mySetRotationPointDlg->hide();
1541 \brief Create one more window with same content.
1543 void OCCViewer_ViewWindow::onCloneView()
1545 SUIT_ViewWindow* vw = myManager->createViewWindow();
1547 emit viewCloned( vw );
1551 \brief called if clipping operation is activated.
1553 Enables/disables clipping plane displaying.
1555 \parma on action state
1557 void OCCViewer_ViewWindow::onClipping( bool on )
1560 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1562 myActionsMap[ ClippingId ]->setIcon(aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CLIPPING_PRESSED" )));
1564 myActionsMap[ ClippingId ]->setIcon(aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CLIPPING" )));
1566 OCCViewer_ViewWindow* aParent = dynamic_cast<OCCViewer_ViewWindow*>(parent()->parent());
1571 if ( !myClippingDlg )
1573 myClippingDlg = new OCCViewer_ClippingDlg( aParent );
1574 myClippingDlg->SetAction( myClippingAction );
1577 if ( !myClippingDlg->isVisible() )
1578 myClippingDlg->show();
1582 if ( myClippingDlg->isVisible() )
1583 myClippingDlg->hide();
1584 aParent->setCuttingPlane(false);
1589 Creates one more window with same content
1591 void OCCViewer_ViewWindow::onAxialScale()
1593 if ( !myScalingDlg )
1594 myScalingDlg = new OCCViewer_AxialScaleDlg( this );
1596 if ( !myScalingDlg->isVisible() )
1598 myScalingDlg->Update();
1599 myScalingDlg->show();
1604 Shows Graduated Axes dialog
1606 void OCCViewer_ViewWindow::onGraduatedAxes()
1608 myCubeAxesDlg->Update();
1609 myCubeAxesDlg->show();
1612 void OCCViewer_ViewWindow::onAmbientToogle()
1614 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
1615 viewer->InitDefinedLights();
1616 while(viewer->MoreDefinedLights())
1618 Handle(V3d_Light) light = viewer->DefinedLight();
1619 if(light->Type() != V3d_AMBIENT)
1621 Handle(V3d_View) aView3d = myViewPort->getView();
1622 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
1623 else viewer->SetLightOn(light);
1625 viewer->NextDefinedLights();
1631 \brief Store view parameters.
1633 void OCCViewer_ViewWindow::onMemorizeView()
1635 appendViewAspect( getViewParams() );
1639 \brief Restore view parameters.
1641 void OCCViewer_ViewWindow::onRestoreView()
1643 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
1644 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
1646 updateViewAspects( aDlg->parameters() );
1647 if( myRestoreFlag && aDlg->parameters().count() )
1648 performRestoring( aDlg->currentItem() );
1652 \brief Restore view parameters.
1653 \param anItem view parameters
1655 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
1657 Handle(V3d_View) aView3d = myViewPort->getView();
1659 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
1660 aView3d->SetScale( anItem.scale );
1661 aView3d->SetCenter( anItem.centerX, anItem.centerY );
1662 aView3d->SetTwist( anItem.twist );
1663 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
1664 aView3d->SetImmediateUpdate( prev );
1665 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
1666 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
1667 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
1669 if ( !baseParamsOnly ) {
1671 myModel->setTrihedronShown( anItem.isVisible );
1672 myModel->setTrihedronSize( anItem.size );
1674 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
1675 // graduated trihedron
1676 bool anIsVisible = anItem.gtIsVisible;
1677 OCCViewer_AxisWidget::AxisData anAxisData[3];
1678 anAxisData[0].DrawName = anItem.gtDrawNameX;
1679 anAxisData[1].DrawName = anItem.gtDrawNameZ;
1680 anAxisData[2].DrawName = anItem.gtDrawNameZ;
1681 anAxisData[0].Name = anItem.gtNameX;
1682 anAxisData[1].Name = anItem.gtNameZ;
1683 anAxisData[2].Name = anItem.gtNameZ;
1684 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
1685 anItem.gtNameColorGX,
1686 anItem.gtNameColorBX );
1687 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
1688 anItem.gtNameColorGY,
1689 anItem.gtNameColorBY );
1690 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
1691 anItem.gtNameColorGZ,
1692 anItem.gtNameColorBZ );
1693 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
1694 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
1695 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
1696 anAxisData[0].NbValues = anItem.gtNbValuesX;
1697 anAxisData[1].NbValues = anItem.gtNbValuesY;
1698 anAxisData[2].NbValues = anItem.gtNbValuesZ;
1699 anAxisData[0].Offset = anItem.gtOffsetX;
1700 anAxisData[1].Offset = anItem.gtOffsetY;
1701 anAxisData[2].Offset = anItem.gtOffsetZ;
1702 anAxisData[0].Color = QColor( anItem.gtColorRX,
1705 anAxisData[1].Color = QColor( anItem.gtColorRY,
1708 anAxisData[2].Color = QColor( anItem.gtColorRZ,
1711 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
1712 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
1713 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
1714 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
1715 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
1716 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
1718 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
1719 myCubeAxesDlg->ApplyData( aView3d );
1722 } // if ( !baseParamsOnly )
1728 \brief Set restore flag.
1730 void OCCViewer_ViewWindow::setRestoreFlag()
1736 \brief Called when action "show/hide trihedron" is activated.
1738 void OCCViewer_ViewWindow::onTrihedronShow()
1740 myModel->toggleTrihedron();
1744 \brief Toggles preselection (highlighting) on/off
1746 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
1748 myPreselectionEnabled = on;
1749 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
1751 // unhighlight all highlighted objects
1753 myModel->unHighlightAll( true, false );
1756 // update action state if method is called outside
1757 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
1758 if ( a && a->isChecked() != on ) {
1759 a->setChecked( on );
1764 \brief Toggles selection on/off
1766 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
1768 mySelectionEnabled = on;
1769 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
1771 // update action state if method is called outside
1774 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
1776 a->setEnabled( on );
1780 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
1781 if ( a && a->isChecked() != on ) {
1782 a->setChecked( on );
1787 \brief Switches "keyboard free" interaction style on/off
1789 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
1791 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
1793 // update action state if method is called outside
1794 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
1795 if ( a->isChecked() != on )
1796 a->setChecked( on );
1800 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
1802 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
1804 myViewPort->setAdvancedZoomingEnabled( on );
1806 // update action state if method is called outside
1807 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
1808 if ( a->isChecked() != on )
1809 a->setChecked( on );
1813 \brief Get current interaction style
1814 \return interaction style
1816 int OCCViewer_ViewWindow::interactionStyle() const
1818 return myInteractionStyle;
1822 \brief Set current interaction style
1823 \param theStyle interaction style
1825 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
1827 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
1831 \brief Get current zooming style
1832 \return zooming style
1834 int OCCViewer_ViewWindow::zoomingStyle() const
1836 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
1840 \brief Set current zooming style
1841 \param theStyle zooming style
1843 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
1845 onSwitchZoomingStyle( theStyle == 1 );
1849 \brief Dump view window contents to the pixmap.
1850 \return pixmap containing all scene rendered in the window
1852 QImage OCCViewer_ViewWindow::dumpView()
1854 Handle(V3d_View) view = myViewPort->getView();
1855 if ( view.IsNull() )
1858 int aWidth = myViewPort->width();
1859 int aHeight = myViewPort->height();
1860 QApplication::syncX();
1861 view->Redraw(); // In order to reactivate GL context
1864 OpenGLUtils_FrameBuffer aFrameBuffer;
1865 if( aFrameBuffer.init( aWidth, aHeight ) )
1867 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
1869 glPushAttrib( GL_VIEWPORT_BIT );
1870 glViewport( 0, 0, aWidth, aHeight );
1871 aFrameBuffer.bind();
1876 aFrameBuffer.unbind();
1879 aFrameBuffer.bind();
1880 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
1881 aFrameBuffer.unbind();
1883 anImage = anImage.rgbSwapped();
1884 anImage = anImage.mirrored();
1887 // if frame buffers are unsupported, use old functionality
1890 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
1892 QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
1894 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
1897 QImage anImage( data, aWidth, aHeight, QImage::Format_ARGB32 );
1898 anImage = anImage.mirrored();
1899 anImage = anImage.rgbSwapped();
1903 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
1904 const QString& fileName,
1905 const QString& format )
1907 if ( format != "PS" && format != "EPS")
1908 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
1910 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
1913 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
1914 else if (format == "EPS")
1915 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
1921 QString OCCViewer_ViewWindow::filter() const
1923 return tr( "OCC_IMAGE_FILES" );
1928 \brief Set parameters of the cutting plane
1929 \param on if \c true, cutting plane is enabled
1930 \param x X position of plane point
1931 \param y Y position of plane point
1932 \param z Z position of plane point
1933 \param dx X coordinate of plane normal
1934 \param dy Y coordinate of plane normal
1935 \param dz Z coordinate of plane normal
1937 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
1938 const double dx, const double dy, const double dz )
1940 Handle(V3d_View) view = myViewPort->getView();
1941 if ( view.IsNull() )
1945 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
1947 // try to use already existing plane or create a new one
1948 Handle(V3d_Plane) clipPlane;
1949 view->InitActivePlanes();
1951 // calculate new a,b,c,d values for the plane
1952 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
1954 pln.Coefficients(a, b, c, d);
1956 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
1957 if (view->MoreActivePlanes()) {
1958 clipPlane = view->ActivePlane();
1959 clipPlane->SetPlane(a, b, c, d);
1962 clipPlane = new V3d_Plane (a, b, c, d);
1964 if (view->MoreActivePlanes())
1965 clipPlane = view->ActivePlane();
1967 clipPlane = new V3d_Plane (viewer);
1969 clipPlane->SetPlane(a, b, c, d);
1972 view->SetPlaneOn(clipPlane);
1975 view->SetPlaneOff();
1981 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
1983 gp_Dir aDir = pln.Axis().Direction();
1984 gp_Pnt aPnt = pln.Location();
1985 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
1990 \brief Check if any cutting plane is enabled
1991 \return \c true if at least one cutting plane is enabled
1993 bool OCCViewer_ViewWindow::isCuttingPlane()
1995 Handle(V3d_View) view = myViewPort->getView();
1996 view->InitActivePlanes();
1997 return (view->MoreActivePlanes());
2001 \brief Get the visual parameters of the view window.
2002 \return visual parameters of view window
2004 viewAspect OCCViewer_ViewWindow::getViewParams() const
2006 double centerX, centerY, projX, projY, projZ, twist;
2007 double atX, atY, atZ, eyeX, eyeY, eyeZ;
2008 double aScaleX, aScaleY, aScaleZ;
2010 Handle(V3d_View) aView3d = myViewPort->getView();
2012 aView3d->Center( centerX, centerY );
2013 aView3d->Proj( projX, projY, projZ );
2014 aView3d->At( atX, atY, atZ );
2015 aView3d->Eye( eyeX, eyeY, eyeZ );
2016 twist = aView3d->Twist();
2018 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2020 bool isShown = myModel->isTrihedronVisible();
2021 double size = myModel->trihedronSize();
2023 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2026 params.scale = aView3d->Scale();
2027 params.centerX = centerX;
2028 params.centerY = centerY;
2029 params.projX = projX;
2030 params.projY = projY;
2031 params.projZ = projZ;
2032 params.twist = twist;
2039 params.scaleX = aScaleX;
2040 params.scaleY = aScaleY;
2041 params.scaleZ = aScaleZ;
2042 params.name = aName;
2043 params.isVisible= isShown;
2046 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
2047 // graduated trihedron
2048 bool anIsVisible = false;
2049 OCCViewer_AxisWidget::AxisData anAxisData[3];
2050 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2052 params.gtIsVisible = anIsVisible;
2053 params.gtDrawNameX = anAxisData[0].DrawName;
2054 params.gtDrawNameY = anAxisData[1].DrawName;
2055 params.gtDrawNameZ = anAxisData[2].DrawName;
2056 params.gtNameX = anAxisData[0].Name;
2057 params.gtNameY = anAxisData[1].Name;
2058 params.gtNameZ = anAxisData[2].Name;
2059 params.gtNameColorRX = anAxisData[0].NameColor.red();
2060 params.gtNameColorGX = anAxisData[0].NameColor.green();
2061 params.gtNameColorBX = anAxisData[0].NameColor.blue();
2062 params.gtNameColorRY = anAxisData[1].NameColor.red();
2063 params.gtNameColorGY = anAxisData[1].NameColor.green();
2064 params.gtNameColorBY = anAxisData[1].NameColor.blue();
2065 params.gtNameColorRZ = anAxisData[2].NameColor.red();
2066 params.gtNameColorGZ = anAxisData[2].NameColor.green();
2067 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2068 params.gtDrawValuesX = anAxisData[0].DrawValues;
2069 params.gtDrawValuesY = anAxisData[1].DrawValues;
2070 params.gtDrawValuesZ = anAxisData[2].DrawValues;
2071 params.gtNbValuesX = anAxisData[0].NbValues;
2072 params.gtNbValuesY = anAxisData[1].NbValues;
2073 params.gtNbValuesZ = anAxisData[2].NbValues;
2074 params.gtOffsetX = anAxisData[0].Offset;
2075 params.gtOffsetY = anAxisData[1].Offset;
2076 params.gtOffsetZ = anAxisData[2].Offset;
2077 params.gtColorRX = anAxisData[0].Color.red();
2078 params.gtColorGX = anAxisData[0].Color.green();
2079 params.gtColorBX = anAxisData[0].Color.blue();
2080 params.gtColorRY = anAxisData[1].Color.red();
2081 params.gtColorGY = anAxisData[1].Color.green();
2082 params.gtColorBY = anAxisData[1].Color.blue();
2083 params.gtColorRZ = anAxisData[2].Color.red();
2084 params.gtColorGZ = anAxisData[2].Color.green();
2085 params.gtColorBZ = anAxisData[2].Color.blue();
2086 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2087 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2088 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2089 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2090 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2091 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2099 \brief Get visual parameters of this view window.
2100 \return visual parameters of view window
2102 QString OCCViewer_ViewWindow::getVisualParameters()
2104 viewAspect params = getViewParams();
2108 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
2109 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
2110 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
2111 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
2112 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
2113 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
2114 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
2115 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
2116 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
2117 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
2118 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
2119 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
2120 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
2121 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
2122 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
2123 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
2124 data << QString( "isVisible=%1" ).arg( params.isVisible );
2125 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
2127 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 or newer version
2128 // graduated trihedron
2129 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
2130 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
2131 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
2132 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
2133 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
2134 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
2135 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
2136 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
2137 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
2138 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
2139 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
2140 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
2141 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
2142 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
2143 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
2144 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
2145 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
2146 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
2147 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
2148 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
2149 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
2150 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
2151 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
2152 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
2153 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
2154 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
2155 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
2156 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
2157 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
2158 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
2159 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
2160 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
2161 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
2162 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
2163 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2164 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2165 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2166 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2167 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2168 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2170 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2171 data << QString( "background=%1" ).arg( bg );
2173 return data.join("*");
2177 \brief Restore visual parameters of the view window.
2178 \param parameters visual parameters of view window
2180 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2184 QStringList data = parameters.split( '*' );
2185 Qtx::BackgroundData bgData;
2186 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2188 foreach( QString param, data ) {
2189 QString paramName = param.section( '=', 0, 0 ).trimmed();
2190 QString paramValue = param.section( '=', 1, 1 ).trimmed();
2191 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
2192 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
2193 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
2194 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
2195 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
2196 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
2197 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
2198 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
2199 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
2200 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
2201 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
2202 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
2203 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
2204 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
2205 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
2206 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
2207 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
2208 else if ( paramName == "size" ) params.size = paramValue.toDouble();
2209 // graduated trihedron
2210 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
2211 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
2212 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
2213 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
2214 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
2215 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
2216 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
2217 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
2218 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
2219 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
2220 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
2221 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
2222 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
2223 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
2224 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
2225 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
2226 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
2227 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
2228 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
2229 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
2230 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
2231 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
2232 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
2233 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
2234 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
2235 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
2236 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
2237 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
2238 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
2239 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
2240 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
2241 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
2242 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
2243 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
2244 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
2245 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
2246 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
2247 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2248 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2249 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2250 else if ( paramName == "background" ) {
2251 QString bg = paramValue.replace( "$", "=" );
2252 bgData = Qtx::stringToBackground( bg );
2256 else // old format - "1.000e+00*0.000e+00..."
2259 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
2260 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2261 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2262 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2263 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2264 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2265 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
2266 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
2267 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
2268 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
2269 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2270 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2271 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2272 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
2273 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
2274 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
2275 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
2276 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
2278 performRestoring( params );
2279 setBackground( bgData );
2283 \brief Handle show event.
2285 Emits Show() signal.
2287 \param theEvent show event
2289 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2291 emit Show( theEvent );
2295 \brief Handle hide event.
2297 Emits Hide() signal.
2299 \param theEvent hide event
2301 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
2303 emit Hide( theEvent );
2308 Creates default sketcher. [ virtual protected ]
2310 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
2313 return new OCCViewer_RectSketcher( this, type );
2314 if ( type == Polygon )
2315 return new OCCViewer_PolygonSketcher( this, type );
2319 void OCCViewer_ViewWindow::initSketchers()
2321 if ( mySketchers.isEmpty() )
2323 mySketchers.append( createSketcher( Rect ) );
2324 mySketchers.append( createSketcher( Polygon ) );
2328 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
2330 OCCViewer_ViewSketcher* sketcher = 0;
2331 QList<OCCViewer_ViewSketcher*>::Iterator it;
2332 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
2334 OCCViewer_ViewSketcher* sk = (*it);
2335 if ( sk->type() == typ )
2342 Handles requests for sketching in the active view. [ virtual public ]
2344 void OCCViewer_ViewWindow::activateSketching( int type )
2346 OCCViewer_ViewPort3d* vp = getViewPort();
2350 if ( !vp->isSketchingEnabled() )
2353 /* Finish current sketching */
2354 if ( type == NoSketching )
2358 onSketchingFinished();
2359 mypSketcher->deactivate();
2363 /* Activate new sketching */
2366 activateSketching( NoSketching ); /* concurrency not suported */
2367 mypSketcher = getSketcher( type );
2370 mypSketcher->activate();
2371 onSketchingStarted();
2377 Unhilights detected entities. [ virtual protected ]
2379 void OCCViewer_ViewWindow::onSketchingStarted()
2384 Selection by rectangle or polygon. [ virtual protected ]
2386 void OCCViewer_ViewWindow::onSketchingFinished()
2388 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
2389 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
2391 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
2392 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
2393 switch( mypSketcher->type() )
2397 QRect* aRect = (QRect*)mypSketcher->data();
2400 int aLeft = aRect->left();
2401 int aRight = aRect->right();
2402 int aTop = aRect->top();
2403 int aBottom = aRect->bottom();
2407 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2409 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2415 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
2418 int size = aPolygon->size();
2419 TColgp_Array1OfPnt2d anArray( 1, size );
2421 QPolygon::Iterator it = aPolygon->begin();
2422 QPolygon::Iterator itEnd = aPolygon->end();
2423 for( int index = 1; it != itEnd; ++it, index++ )
2425 QPoint aPoint = *it;
2426 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
2430 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
2432 ic->Select( anArray, getViewPort()->getView(), Standard_False );
2440 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
2441 aViewMgr->getOCCViewer()->performSelectionChanged();
2445 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
2450 bool OCCViewer_ViewWindow::transformRequested() const
2452 return ( myOperation != NOTHING );
2455 bool OCCViewer_ViewWindow::transformInProcess() const
2457 return myEventStarted;
2460 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
2462 myEventStarted = bOn;
2466 Set enabled state of transformation (rotate, zoom, etc)
2468 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
2470 if ( id != NOTHING ) myStatus.insert( id, on );
2474 \return enabled state of transformation (rotate, zoom, etc)
2476 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
2478 return myStatus.contains( id ) ? myStatus[ id ] : true;
2481 void OCCViewer_ViewWindow::onMaximizedView()
2483 setMaximized(!isMaximized());
2487 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
2489 QAction* anAction = toolMgr()->action( MaximizedId );
2490 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
2492 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
2493 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
2494 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
2495 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
2497 emit maximized( this, true );
2501 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
2502 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
2503 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
2504 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
2506 emit maximized( this, false );
2512 bool OCCViewer_ViewWindow::isMaximized() const
2514 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
2517 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
2519 IsSketcherStyle = enable;
2522 bool OCCViewer_ViewWindow::isSketcherStyle() const
2524 return IsSketcherStyle;
2528 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
2534 QColor OCCViewer_ViewWindow::backgroundColor() const
2536 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
2540 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
2542 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
2545 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
2547 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
2550 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
2552 if ( myViewPort ) myViewPort->setBackground( theBackground );
2558 void OCCViewer_ViewWindow::clearViewAspects()
2560 myViewAspects.clear();
2564 \return const reference to list of view aspects
2566 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
2568 return myViewAspects;
2572 Appends new view aspect
2573 \param aParams - new view aspects
2575 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
2577 myViewAspects.append( aParams );
2581 Replaces old view aspects by new ones
2582 \param aViewList - list of new view aspects
2584 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
2586 myViewAspects = aViewList;
2590 Get camera properties for the OCC view window.
2591 \return shared pointer on camera properties.
2593 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
2595 SUIT_CameraProperties aProps;
2597 Handle(V3d_View) aSourceView = getViewPort()->getView();
2598 if ( aSourceView.IsNull() )
2601 if ( get2dMode() == No2dMode ) {
2602 aProps.setDimension( SUIT_CameraProperties::Dim3D );
2605 aProps.setDimension( SUIT_CameraProperties::Dim2D );
2606 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
2609 // read common properites of the view
2610 Standard_Real anUpDir[3];
2611 Standard_Real aPrjDir[3];
2612 Standard_Real aMapScale[2];
2613 Standard_Real aTranslation[3];
2614 Standard_Real anAxialScale[3];
2616 aSourceView->Up(anUpDir[0], anUpDir[1], anUpDir[2]);
2617 aSourceView->Proj(aPrjDir[0], aPrjDir[1], aPrjDir[2]);
2618 aSourceView->At(aTranslation[0], aTranslation[1], aTranslation[2]);
2619 aSourceView->Size(aMapScale[0], aMapScale[1]);
2621 getViewPort()->getAxialScale(anAxialScale[0], anAxialScale[1], anAxialScale[2]);
2623 // we use similar depth to the one used in perspective projection
2624 // to proivde a convinience synchronization with other camera views that
2625 // can switch between orthogonal & perspective projection. otherwise,
2626 // the camera will get to close when switching from orthogonal to perspective.
2627 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
2629 // store common props
2630 aProps.setViewUp(anUpDir[0], anUpDir[1], anUpDir[2]);
2631 aProps.setMappingScale(aMapScale[1] / 2.0);
2632 aProps.setAxialScale(anAxialScale[0], anAxialScale[1], anAxialScale[2]);
2634 // generate view orientation matrix for transforming OCC projection reference point
2635 // into a camera (eye) position.
2636 gp_Dir aLeftDir = gp_Dir(anUpDir[0], anUpDir[1], anUpDir[2]).Crossed(
2637 gp_Dir(aPrjDir[0], aPrjDir[1], aPrjDir[2]));
2640 aTrsf.SetValues( aLeftDir.X(), anUpDir[0], aPrjDir[0], aTranslation[0],
2641 aLeftDir.Y(), anUpDir[1], aPrjDir[1], aTranslation[1],
2642 aLeftDir.Z(), anUpDir[2], aPrjDir[2], aTranslation[2],
2643 Precision::Confusion(),
2644 Precision::Confusion() );
2646 // get projection reference point in view coordinates
2647 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
2649 // transform to world-space coordinate system
2650 gp_Pnt aPosition = gp_Pnt(aProjRef.X(), aProjRef.Y(), aCameraDepth).Transformed(aTrsf);
2652 // compute focal point
2653 double aFocalPoint[3];
2655 aFocalPoint[0] = aPosition.X() - aPrjDir[0] * aCameraDepth;
2656 aFocalPoint[1] = aPosition.Y() - aPrjDir[1] * aCameraDepth;
2657 aFocalPoint[2] = aPosition.Z() - aPrjDir[2] * aCameraDepth;
2659 aProps.setFocalPoint(aFocalPoint[0], aFocalPoint[1], aFocalPoint[2]);
2660 aProps.setPosition(aPosition.X(), aPosition.Y(), aPosition.Z());
2667 This implementation synchronizes OCC view's camera propreties.
2669 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
2671 bool blocked = blockSignals( true );
2673 SUIT_CameraProperties aProps = theView->cameraProperties();
2674 if ( !cameraProperties().isCompatible( aProps ) ) {
2675 // other view, this one is being currently synchronized to, seems has become incompatible
2676 // we have to break synchronization
2681 Handle(V3d_View) aDestView = getViewPort()->getView();
2683 aDestView->SetImmediateUpdate( Standard_False );
2686 double aPosition[3];
2687 double aFocalPoint[3];
2689 double anAxialScale[3];
2691 // get common properties
2692 aProps.getFocalPoint(aFocalPoint[0], aFocalPoint[1], aFocalPoint[2]);
2693 aProps.getPosition(aPosition[0], aPosition[1], aPosition[2]);
2694 aProps.getViewUp(anUpDir[0], anUpDir[1], anUpDir[2]);
2695 aProps.getAxialScale(anAxialScale[0], anAxialScale[1], anAxialScale[2]);
2696 aMapScaling = aProps.getMappingScale() * 2.0;
2698 gp_Dir aProjDir(aPosition[0] - aFocalPoint[0],
2699 aPosition[1] - aFocalPoint[1],
2700 aPosition[2] - aFocalPoint[2]);
2702 // get custom view translation
2703 Standard_Real aTranslation[3];
2704 aDestView->At(aTranslation[0], aTranslation[1], aTranslation[2]);
2706 gp_Dir aLeftDir = gp_Dir(anUpDir[0], anUpDir[1], anUpDir[2]).Crossed(
2707 gp_Dir(aProjDir.X(), aProjDir.Y(), aProjDir.Z()));
2709 // convert camera position into a view reference point
2711 aTrsf.SetValues( aLeftDir.X(), anUpDir[0], aProjDir.X(), aTranslation[0],
2712 aLeftDir.Y(), anUpDir[1], aProjDir.Y(), aTranslation[1],
2713 aLeftDir.Z(), anUpDir[2], aProjDir.Z(), aTranslation[2],
2714 Precision::Confusion(),
2715 Precision::Confusion() );
2718 // transform to view-space coordinate system
2719 gp_Pnt aProjRef(aPosition[0], aPosition[1], aPosition[2]);
2720 aProjRef.Transform(aTrsf);
2722 // set view camera properties using low-level approach. this is done
2723 // in order to avoid interference with static variables in v3d view used
2724 // when rotation is in process in another view.
2725 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
2726 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
2728 Graphic3d_Vector aMappingProj(aProjDir.X(), aProjDir.Y(), aProjDir.Z());
2729 Graphic3d_Vector aMappingUp(anUpDir[0], anUpDir[1], anUpDir[2]);
2731 aMappingProj.Normalize();
2732 aMappingUp.Normalize();
2734 anOrientation.SetViewReferencePlane(aMappingProj);
2735 anOrientation.SetViewReferenceUp(aMappingUp);
2737 aDestView->SetViewMapping(aMapping);
2738 aDestView->SetViewOrientation(anOrientation);
2741 aDestView->SetCenter(aProjRef.X(), aProjRef.Y());
2743 // set mapping scale
2744 Standard_Real aWidth, aHeight;
2745 aDestView->Size(aWidth, aHeight);
2747 if ( aWidth > aHeight )
2748 aDestView->SetSize (aMapScaling * (aWidth / aHeight));
2750 aDestView->SetSize (aMapScaling);
2752 getViewPort()->setAxialScale(anAxialScale[0], anAxialScale[1], anAxialScale[2]);
2754 aDestView->ZFitAll();
2755 aDestView->SetImmediateUpdate( Standard_True );
2756 aDestView->Redraw();
2758 blockSignals( blocked );
2762 \brief Indicates whether preselection is enabled
2763 \return true if preselection is enabled
2765 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
2767 return myPreselectionEnabled;
2771 \brief Enables/disables preselection
2772 \param theIsToEnable if true - preselection will be enabled
2774 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
2776 onSwitchPreselection( theIsToEnable );
2780 \brief Indicates whether selection is enabled
2781 \return true if selection is enabled
2783 bool OCCViewer_ViewWindow::isSelectionEnabled() const
2785 return mySelectionEnabled;
2789 \brief Enables/disables selection
2790 \param theIsToEnable if true - selection will be enabled
2792 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
2794 onSwitchSelection( theIsToEnable );