1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
\r
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
\r
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
\r
6 // This library is free software; you can redistribute it and/or
\r
7 // modify it under the terms of the GNU Lesser General Public
\r
8 // License as published by the Free Software Foundation; either
\r
9 // version 2.1 of the License, or (at your option) any later version.
\r
11 // This library is distributed in the hope that it will be useful,
\r
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
14 // Lesser General Public License for more details.
\r
16 // You should have received a copy of the GNU Lesser General Public
\r
17 // License along with this library; if not, write to the Free Software
\r
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
\r
23 // File : OCCViewer_ViewWindow.cxx
\r
26 #include "OCCViewer_ViewWindow.h"
\r
27 #include "OCCViewer_ViewModel.h"
\r
28 #include "OCCViewer_ViewPort3d.h"
\r
29 #include "OCCViewer_ViewManager.h"
\r
30 #include "OCCViewer_ViewSketcher.h"
\r
31 #include "OCCViewer_CreateRestoreViewDlg.h"
\r
32 #include "OCCViewer_ClipPlane.h"
\r
33 #include "OCCViewer_SetRotationPointDlg.h"
\r
34 #include "OCCViewer_AxialScaleDlg.h"
\r
35 #include "OCCViewer_CubeAxesDlg.h"
\r
36 #include "OCCViewer_ClippingDlg.h"
\r
38 #include <Basics_OCCTVersion.hxx>
\r
40 #include <SUIT_Desktop.h>
\r
41 #include <SUIT_Session.h>
\r
42 #include <SUIT_ViewManager.h>
\r
43 #include <SUIT_Tools.h>
\r
44 #include <SUIT_ResourceMgr.h>
\r
45 #include <SUIT_MessageBox.h>
\r
46 #include <SUIT_Application.h>
\r
48 #include <QtxActionToolMgr.h>
\r
49 #include <QtxMultiAction.h>
\r
50 #include <QtxRubberBand.h>
\r
52 #include <OpenGLUtils_FrameBuffer.h>
\r
57 #include <QKeyEvent>
\r
58 #include <QMouseEvent>
\r
59 #include <QApplication>
\r
62 #include <AIS_ListOfInteractive.hxx>
\r
63 #include <AIS_ListIteratorOfListOfInteractive.hxx>
\r
64 #include <AIS_Shape.hxx>
\r
66 #include <BRep_Tool.hxx>
\r
67 #include <BRepBndLib.hxx>
\r
68 #include <TopoDS.hxx>
\r
70 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
\r
71 #include <Graphic3d_MapOfStructure.hxx>
\r
72 #include <Graphic3d_Structure.hxx>
\r
73 #include <Graphic3d_ExportFormat.hxx>
\r
75 #include <Visual3d_View.hxx>
\r
76 #include <V3d_Plane.hxx>
\r
77 #include <V3d_Light.hxx>
\r
79 #include <gp_Dir.hxx>
\r
80 #include <gp_Pln.hxx>
\r
81 #include <TColgp_Array1OfPnt2d.hxx>
\r
83 #if OCC_VERSION_LARGE > 0x06060000
\r
84 #include <Graphic3d_SequenceOfHClipPlane.hxx>
\r
85 #include <Graphic3d_ClipPlane.hxx>
\r
89 #include <Standard_Version.hxx>
\r
91 #include "utilities.h"
\r
93 // // OpenCV includes
\r
95 // #include <highgui.h>
\r
97 static QEvent* l_mbPressEvent = 0;
\r
100 # include <QWindowsStyle>
\r
105 const char* imageZoomCursor[] = {
\r
110 "................................",
\r
111 "................................",
\r
112 ".#######........................",
\r
113 "..aaaaaaa.......................",
\r
114 "................................",
\r
115 ".............#####..............",
\r
116 "...........##.aaaa##............",
\r
117 "..........#.aa.....a#...........",
\r
118 ".........#.a.........#..........",
\r
119 ".........#a..........#a.........",
\r
120 "........#.a...........#.........",
\r
121 "........#a............#a........",
\r
122 "........#a............#a........",
\r
123 "........#a............#a........",
\r
124 "........#a............#a........",
\r
125 ".........#...........#.a........",
\r
126 ".........#a..........#a.........",
\r
127 ".........##.........#.a.........",
\r
128 "........#####.....##.a..........",
\r
129 ".......###aaa#####.aa...........",
\r
130 "......###aa...aaaaa.......#.....",
\r
131 ".....###aa................#a....",
\r
132 "....###aa.................#a....",
\r
133 "...###aa...............#######..",
\r
134 "....#aa.................aa#aaaa.",
\r
135 ".....a....................#a....",
\r
136 "..........................#a....",
\r
137 "...........................a....",
\r
138 "................................",
\r
139 "................................",
\r
140 "................................",
\r
141 "................................"};
\r
143 const char* imageRotateCursor[] = {
\r
148 "................................",
\r
149 "................................",
\r
150 "................................",
\r
151 "................................",
\r
152 "........#.......................",
\r
153 ".......#.a......................",
\r
154 "......#######...................",
\r
155 ".......#aaaaa#####..............",
\r
156 "........#..##.a#aa##........##..",
\r
157 ".........a#.aa..#..a#.....##.aa.",
\r
158 ".........#.a.....#...#..##.aa...",
\r
159 ".........#a.......#..###.aa.....",
\r
160 "........#.a.......#a..#aa.......",
\r
161 "........#a.........#..#a........",
\r
162 "........#a.........#a.#a........",
\r
163 "........#a.........#a.#a........",
\r
164 "........#a.........#a.#a........",
\r
165 ".........#.........#a#.a........",
\r
166 "........##a........#a#a.........",
\r
167 "......##.a#.......#.#.a.........",
\r
168 "....##.aa..##.....##.a..........",
\r
169 "..##.aa.....a#####.aa...........",
\r
170 "...aa.........aaa#a.............",
\r
171 "................#.a.............",
\r
172 "...............#.a..............",
\r
173 "..............#.a...............",
\r
174 "...............a................",
\r
175 "................................",
\r
176 "................................",
\r
177 "................................",
\r
178 "................................",
\r
179 "................................"};
\r
181 const char* imageCrossCursor[] = {
\r
186 "................................",
\r
187 "................................",
\r
188 "................................",
\r
189 "................................",
\r
190 "................................",
\r
191 "................................",
\r
192 "................................",
\r
193 "...............#................",
\r
194 "...............#a...............",
\r
195 "...............#a...............",
\r
196 "...............#a...............",
\r
197 "...............#a...............",
\r
198 "...............#a...............",
\r
199 "...............#a...............",
\r
200 "...............#a...............",
\r
201 ".......#################........",
\r
202 "........aaaaaaa#aaaaaaaaa.......",
\r
203 "...............#a...............",
\r
204 "...............#a...............",
\r
205 "...............#a...............",
\r
206 "...............#a...............",
\r
207 "...............#a...............",
\r
208 "...............#a...............",
\r
209 "...............#a...............",
\r
210 "................a...............",
\r
211 "................................",
\r
212 "................................",
\r
213 "................................",
\r
214 "................................",
\r
215 "................................",
\r
216 "................................",
\r
217 "................................"};
\r
222 \param theDesktop main window of application
\r
223 \param theModel OCC 3D viewer
\r
225 OCCViewer_ViewWindow::OCCViewer_ViewWindow( SUIT_Desktop* theDesktop,
\r
226 OCCViewer_Viewer* theModel )
\r
227 : SUIT_ViewWindow( theDesktop )
\r
229 myModel = theModel;
\r
231 myEnableDrawMode = false;
\r
233 updateEnabledDrawMode();
\r
235 mySetRotationPointDlg = 0;
\r
238 IsSketcherStyle = false;
\r
239 myIsKeyFree = false;
\r
243 my2dMode = No2dMode;
\r
245 myInteractionStyle = SUIT_ViewModel::STANDARD;
\r
246 myPreselectionEnabled = true;
\r
247 mySelectionEnabled = true;
\r
250 clearViewAspects();
\r
257 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
\r
260 qDeleteAll( mySketchers );
\r
264 \brief Internal initialization.
\r
266 void OCCViewer_ViewWindow::initLayout()
\r
268 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
\r
269 myViewPort->installEventFilter(this);
\r
270 setCentralWidget(myViewPort);
\r
271 myOperation = NOTHING;
\r
273 myCurrPointType = GRAVITY;
\r
274 myPrevPointType = GRAVITY;
\r
275 mySelectedPoint = gp_Pnt(0.,0.,0.);
\r
276 myRotationPointSelection = false;
\r
278 setTransformRequested ( NOTHING );
\r
279 setTransformInProcess ( false );
\r
284 switch (my2dMode) {
\r
296 // Graduated axes dialog
\r
297 QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
\r
298 myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
\r
299 myCubeAxesDlg->initialize();
\r
301 connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
\r
304 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
\r
306 return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
\r
310 \brief Detect viewer operation according the the mouse button pressed
\r
311 and key modifiers used.
\r
312 \param theEvent mouse event
\r
313 \return type of the operation
\r
315 OCCViewer_ViewWindow::OperationType
\r
316 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
\r
318 OperationType aOp = NOTHING;
\r
319 SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
\r
320 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
\r
321 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
\r
323 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
\r
324 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
\r
326 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
\r
327 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
\r
328 (my2dMode == No2dMode))
\r
335 \brief Customize event handling
\r
336 \param watched event receiver object
\r
338 \return \c true if the event processing should be stopped
\r
340 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
\r
342 if ( watched == myViewPort ) {
\r
343 int aType = e->type();
\r
345 case QEvent::MouseButtonPress:
\r
346 vpMousePressEvent((QMouseEvent*) e);
\r
349 case QEvent::MouseButtonRelease:
\r
350 vpMouseReleaseEvent((QMouseEvent*) e);
\r
353 case QEvent::MouseMove:
\r
354 vpMouseMoveEvent((QMouseEvent*) e);
\r
357 case QEvent::MouseButtonDblClick:
\r
358 emit mouseDoubleClicked(this, (QMouseEvent*)e);
\r
361 case QEvent::Wheel:
\r
363 QWheelEvent* aEvent = (QWheelEvent*) e;
\r
364 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
\r
365 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
\r
366 int x = aEvent->x();
\r
367 int y = aEvent->y();
\r
368 int x1 = (int)( aEvent->x() + width()*delta/100 );
\r
369 int y1 = (int)( aEvent->y() + height()*delta/100 );
\r
370 myViewPort->zoom( x, y, x1, y1 );
\r
374 case QEvent::ContextMenu:
\r
376 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
\r
377 if ( aEvent->reason() != QContextMenuEvent::Mouse )
\r
378 emit contextMenuRequested( aEvent );
\r
382 case QEvent::KeyPress:
\r
383 emit keyPressed(this, (QKeyEvent*) e);
\r
390 return SUIT_ViewWindow::eventFilter(watched, e);
\r
394 \brief Update state of enable draw mode state.
\r
396 void OCCViewer_ViewWindow::updateEnabledDrawMode()
\r
399 myEnableDrawMode = myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
\r
403 \brief Handle mouse press event
\r
404 \param theEvent mouse event
\r
406 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
\r
408 myStartX = theEvent->x();
\r
409 myStartY = theEvent->y();
\r
410 int anInteractionStyle = interactionStyle();
\r
412 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
\r
413 // which are assigned for pan and rotate - these operations are activated immediately after pressing
\r
414 // of the first button, so it is necessary to switch to zoom when the second button is pressed
\r
415 bool aSwitchToZoom = false;
\r
416 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
\r
417 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
\r
418 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
\r
421 switch ( myOperation ) {
\r
423 if ( theEvent->button() == Qt::LeftButton )
\r
424 emit vpTransformationStarted ( WINDOWFIT );
\r
428 if ( theEvent->button() == Qt::LeftButton )
\r
429 emit vpTransformationStarted ( PANGLOBAL );
\r
433 if ( theEvent->button() == Qt::LeftButton ) {
\r
434 myViewPort->startZoomAtPoint( myStartX, myStartY );
\r
435 emit vpTransformationStarted ( ZOOMVIEW );
\r
440 if ( aSwitchToZoom ) {
\r
441 myViewPort->startZoomAtPoint( myStartX, myStartY );
\r
444 else if ( theEvent->button() == Qt::LeftButton )
\r
445 emit vpTransformationStarted ( PANVIEW );
\r
449 if ( aSwitchToZoom ) {
\r
450 myViewPort->startZoomAtPoint( myStartX, myStartY );
\r
453 else if ( theEvent->button() == Qt::LeftButton ) {
\r
454 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
\r
455 emit vpTransformationStarted ( ROTATE );
\r
460 /* Try to activate a transformation */
\r
461 OperationType aState;
\r
462 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
\r
463 aState = getButtonState(theEvent, anInteractionStyle);
\r
465 aState = OCCViewer_ViewWindow::NOTHING;
\r
466 myIsKeyFree = true;
\r
468 switch ( aState ) {
\r
470 myViewPort->startZoomAtPoint( myStartX, myStartY );
\r
477 activateRotation();
\r
478 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
\r
481 if ( myRotationPointSelection )
\r
483 if ( theEvent->button() == Qt::LeftButton )
\r
485 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
\r
487 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
\r
489 TopoDS_Shape aShape = ic->SelectedShape();
\r
490 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
\r
492 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
\r
493 if ( mySetRotationPointDlg )
\r
495 myRotationPointSelection = false;
\r
496 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
\r
501 myCurrPointType = myPrevPointType;
\r
505 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
\r
506 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
\r
507 ic->CloseAllContexts();
\r
508 myOperation = NOTHING;
\r
509 myViewPort->setCursor( myCursor );
\r
510 myCursorIsHand = false;
\r
511 myRotationPointSelection = false;
\r
515 emit mousePressed(this, theEvent);
\r
518 /* notify that we start a transformation */
\r
519 if ( transformRequested() )
\r
520 emit vpTransformationStarted ( myOperation );
\r
522 if ( transformRequested() )
\r
523 setTransformInProcess( true );
\r
525 /* we may need it for sketching... */
\r
526 if ( l_mbPressEvent )
\r
527 delete l_mbPressEvent;
\r
528 l_mbPressEvent = new QMouseEvent( *theEvent );
\r
533 \brief Start zooming operation.
\r
535 Sets the corresponding cursor for the widget.
\r
537 void OCCViewer_ViewWindow::activateZoom()
\r
539 if ( !transformRequested() && !myCursorIsHand )
\r
540 myCursor = cursor(); /* save old cursor */
\r
542 if ( myOperation != ZOOMVIEW ) {
\r
543 QPixmap zoomPixmap (imageZoomCursor);
\r
544 QCursor zoomCursor (zoomPixmap);
\r
545 if( setTransformRequested ( ZOOMVIEW ) )
\r
546 myViewPort->setCursor( zoomCursor );
\r
552 \brief Start panning operation.
\r
554 Sets the corresponding cursor for the widget.
\r
556 void OCCViewer_ViewWindow::activatePanning()
\r
558 if ( !transformRequested() && !myCursorIsHand )
\r
559 myCursor = cursor(); // save old cursor
\r
561 if ( myOperation != PANVIEW ) {
\r
562 QCursor panCursor (Qt::SizeAllCursor);
\r
563 if( setTransformRequested ( PANVIEW ) )
\r
564 myViewPort->setCursor( panCursor );
\r
569 \brief Start rotation operation
\r
571 Sets the corresponding cursor for the widget.
\r
573 void OCCViewer_ViewWindow::activateRotation()
\r
575 if ( !transformRequested() && !myCursorIsHand )
\r
576 myCursor = cursor(); // save old cursor
\r
578 if ( myOperation != ROTATE ) {
\r
579 QPixmap rotatePixmap (imageRotateCursor);
\r
580 QCursor rotCursor (rotatePixmap);
\r
581 if( setTransformRequested ( ROTATE ) )
\r
582 myViewPort->setCursor( rotCursor );
\r
587 \brief Compute the gravity center.
\r
588 \param theX used to return X coordinate of the gravity center
\r
589 \param theY used to return Y coordinate of the gravity center
\r
590 \param theZ used to return Z coordinate of the gravity center
\r
591 \return \c true if the gravity center is computed
\r
593 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
\r
595 Handle(Visual3d_View) aView = myViewPort->getView()->View();
\r
597 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W ;
\r
598 Standard_Real Umin,Vmin,Umax,Vmax ;
\r
599 Standard_Integer Nstruct,Npoint ;
\r
600 Graphic3d_MapOfStructure MySetOfStructures;
\r
602 aView->DisplayedStructures (MySetOfStructures);
\r
603 Nstruct = MySetOfStructures.Extent() ;
\r
605 Graphic3d_MapIteratorOfMapOfStructure MyIterator(MySetOfStructures) ;
\r
606 #if OCC_VERSION_LARGE > 0x06070000
\r
607 aView->Camera()->WindowLimit(Umin,Vmin,Umax,Vmax);
\r
609 aView->ViewMapping().WindowLimit(Umin,Vmin,Umax,Vmax);
\r
611 Npoint = 0 ; theX = theY = theZ = 0. ;
\r
612 for( ; MyIterator.More(); MyIterator.Next()) {
\r
613 if (!(MyIterator.Key())->IsEmpty()) {
\r
614 (MyIterator.Key())->MinMaxValues(Xmin,Ymin,Zmin,
\r
617 Standard_Real LIM = ShortRealLast() -1.;
\r
618 if (! (fabs(Xmin) > LIM || fabs(Ymin) > LIM || fabs(Zmin) > LIM
\r
619 || fabs(Xmax) > LIM || fabs(Ymax) > LIM || fabs(Zmax) > LIM )) {
\r
621 aView->Projects(Xmin,Ymin,Zmin,U,V,W) ;
\r
622 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
\r
623 Npoint++ ; theX += Xmin ; theY += Ymin ; theZ += Zmin ;
\r
625 aView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
\r
626 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
\r
627 Npoint++ ; theX += Xmax ; theY += Ymin ; theZ += Zmin ;
\r
629 aView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
\r
630 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
\r
631 Npoint++ ; theX += Xmin ; theY += Ymax ; theZ += Zmin ;
\r
633 aView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
\r
634 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
\r
635 Npoint++ ; theX += Xmax ; theY += Ymax ; theZ += Zmin ;
\r
637 aView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
\r
638 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
\r
639 Npoint++ ; theX += Xmin ; theY += Ymin ; theZ += Zmax ;
\r
641 aView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
\r
642 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
\r
643 Npoint++ ; theX += Xmax ; theY += Ymin ; theZ += Zmax ;
\r
645 aView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
\r
646 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
\r
647 Npoint++ ; theX += Xmin ; theY += Ymax ; theZ += Zmax ;
\r
649 aView->Projects(Xmax,Ymax,Zmax,U,V,W) ;
\r
650 if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
\r
651 Npoint++ ; theX += Xmax ; theY += Ymax ; theZ += Zmax ;
\r
657 theX /= Npoint ; theY /= Npoint ; theZ /= Npoint ;
\r
663 \brief Set the gravity center as a rotation point.
\r
665 void OCCViewer_ViewWindow::activateSetRotationGravity()
\r
667 if ( myRotationPointSelection )
\r
669 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
\r
670 ic->CloseAllContexts();
\r
671 myOperation = NOTHING;
\r
672 myViewPort->setCursor( myCursor );
\r
673 myCursorIsHand = false;
\r
674 myRotationPointSelection = false;
\r
677 myPrevPointType = myCurrPointType;
\r
678 myCurrPointType = GRAVITY;
\r
680 Standard_Real Xcenter, Ycenter, Zcenter;
\r
681 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
\r
682 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
\r
686 \brief Update gravity center in the "Set Rotation Point" dialog box.
\r
687 \sa OCCViewer_SetRotationPointDlg class
\r
689 void OCCViewer_ViewWindow::updateGravityCoords()
\r
691 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == GRAVITY )
\r
693 Standard_Real Xcenter, Ycenter, Zcenter;
\r
694 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
\r
695 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
\r
700 \brief Set the point selected by the user as a rotation point.
\r
701 \param theX X coordinate of the rotation point
\r
702 \param theY Y coordinate of the rotation point
\r
703 \param theZ Z coordinate of the rotation point
\r
705 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
\r
707 if ( myRotationPointSelection )
\r
709 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
\r
710 ic->CloseAllContexts();
\r
711 myOperation = NOTHING;
\r
712 myViewPort->setCursor( myCursor );
\r
713 myCursorIsHand = false;
\r
714 myRotationPointSelection = false;
\r
717 myPrevPointType = myCurrPointType;
\r
718 myCurrPointType = SELECTED;
\r
719 mySelectedPoint.SetCoord(theX,theY,theZ);
\r
723 \brief Start the point selection process.
\r
725 void OCCViewer_ViewWindow::activateStartPointSelection()
\r
727 myPrevPointType = myCurrPointType;
\r
728 myCurrPointType = SELECTED;
\r
730 // activate selection ------>
\r
731 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
\r
733 ic->OpenLocalContext();
\r
735 AIS_ListOfInteractive aList;
\r
736 ic->DisplayedObjects( aList );
\r
737 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
\r
739 Handle(AIS_InteractiveObject) anObj = it.Value();
\r
740 if ( !anObj.IsNull() && anObj->HasPresentation() &&
\r
741 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
\r
743 ic->Load(anObj,-1);
\r
744 ic->Activate(anObj,AIS_Shape::SelectionMode(TopAbs_VERTEX));
\r
747 // activate selection <------
\r
749 if ( !myCursorIsHand )
\r
751 QCursor handCursor (Qt::PointingHandCursor);
\r
752 myCursorIsHand = true;
\r
753 myCursor = cursor();
\r
754 myViewPort->setCursor( handCursor );
\r
756 myRotationPointSelection = true;
\r
760 \brief Start global panning operation
\r
762 Sets the corresponding cursor for the widget.
\r
764 void OCCViewer_ViewWindow::activateGlobalPanning()
\r
766 Handle(V3d_View) aView3d = myViewPort->getView();
\r
767 if ( !aView3d.IsNull() ) {
\r
768 QPixmap globalPanPixmap (imageCrossCursor);
\r
769 QCursor glPanCursor (globalPanPixmap);
\r
770 myCurScale = aView3d->Scale();
\r
771 aView3d->FitAll(0.01, false);
\r
772 myCursor = cursor(); // save old cursor
\r
773 myViewPort->fitAll(); // fits view before selecting a new scene center
\r
774 if( setTransformRequested( PANGLOBAL ) )
\r
775 myViewPort->setCursor( glPanCursor );
\r
780 \brief Starts fit operation.
\r
782 Sets the corresponding cursor for the widget.
\r
784 void OCCViewer_ViewWindow::activateWindowFit()
\r
786 if ( !transformRequested() && !myCursorIsHand )
\r
787 myCursor = cursor(); /* save old cursor */
\r
789 if ( myOperation != WINDOWFIT ) {
\r
790 QCursor handCursor (Qt::PointingHandCursor);
\r
791 if( setTransformRequested ( WINDOWFIT ) )
\r
793 myViewPort->setCursor ( handCursor );
\r
794 myCursorIsHand = true;
\r
800 \brief Start delayed viewer operation.
\r
802 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
\r
804 bool ok = transformEnabled( op );
\r
805 myOperation = ok ? op : NOTHING;
\r
806 myViewPort->setMouseTracking( myOperation == NOTHING );
\r
811 \brief Handle mouse move event.
\r
812 \param theEvent mouse event
\r
814 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
\r
816 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
\r
817 myIsKeyFree = false;
\r
818 switch ( getButtonState( theEvent, interactionStyle() ) ) {
\r
820 myViewPort->startZoomAtPoint( myStartX, myStartY );
\r
827 activateRotation();
\r
828 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
\r
835 myCurrX = theEvent->x();
\r
836 myCurrY = theEvent->y();
\r
837 switch (myOperation) {
\r
839 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
\r
843 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
\r
844 myStartX = myCurrX;
\r
845 myStartY = myCurrY;
\r
849 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
\r
850 myStartX = myCurrX;
\r
851 myStartY = myCurrY;
\r
863 if ( myRotationPointSelection || isSketcherStyle() )
\r
865 emit mouseMoving( this, theEvent );
\r
869 int aState = theEvent->modifiers();
\r
870 int aButton = theEvent->buttons();
\r
871 int anInteractionStyle = interactionStyle();
\r
872 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
\r
873 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
\r
874 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
\r
875 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
\r
876 myDrawRect = myEnableDrawMode;
\r
877 if ( myDrawRect ) {
\r
879 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
\r
880 QCursor handCursor (Qt::PointingHandCursor);
\r
881 myCursorIsHand = true;
\r
882 myCursor = cursor();
\r
883 myViewPort->setCursor( handCursor );
\r
886 emit mouseMoving( this, theEvent );
\r
888 else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
\r
889 aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
\r
890 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
\r
891 aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
\r
892 OCCViewer_ViewSketcher* sketcher = 0;
\r
893 QList<OCCViewer_ViewSketcher*>::Iterator it;
\r
894 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
\r
896 OCCViewer_ViewSketcher* sk = (*it);
\r
897 if( sk->isDefault() && sk->sketchButton() == aButton )
\r
900 if ( sketcher && myCurSketch == -1 )
\r
902 activateSketching( sketcher->type() );
\r
905 myCurSketch = mypSketcher->sketchButton();
\r
907 if ( l_mbPressEvent )
\r
909 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
\r
910 delete l_mbPressEvent;
\r
911 l_mbPressEvent = 0;
\r
913 QApplication::sendEvent( getViewPort(), theEvent );
\r
918 emit mouseMoving( this, theEvent );
\r
924 \brief Handle mouse release event.
\r
925 \param theEvent mouse event
\r
927 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
\r
929 switch ( myOperation ) {
\r
932 int prevState = myCurSketch;
\r
933 if(theEvent->button() == Qt::RightButton)
\r
935 QList<OCCViewer_ViewSketcher*>::Iterator it;
\r
936 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
\r
938 OCCViewer_ViewSketcher* sk = (*it);
\r
939 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
\r
944 emit mouseReleased(this, theEvent);
\r
945 if(theEvent->button() == Qt::RightButton && prevState == -1)
\r
947 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
\r
948 theEvent->pos(), theEvent->globalPos() );
\r
949 emit contextMenuRequested( &aEvent );
\r
954 myViewPort->endRotation();
\r
964 if ( theEvent->button() == Qt::LeftButton ) {
\r
965 myViewPort->setCenter( theEvent->x(), theEvent->y() );
\r
966 myViewPort->getView()->SetScale(myCurScale);
\r
972 if ( theEvent->button() == Qt::LeftButton ) {
\r
973 myCurrX = theEvent->x();
\r
974 myCurrY = theEvent->y();
\r
976 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
\r
977 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
\r
984 // NOTE: viewer 3D detects a rectangle of selection using this event
\r
985 // so we must emit it BEFORE resetting the selection rectangle
\r
987 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
\r
991 myViewPort->update();
\r
994 if ( l_mbPressEvent )
\r
996 delete l_mbPressEvent;
\r
997 l_mbPressEvent = 0;
\r
1002 \brief Reset the viewport to its initial state
\r
1003 ( no transformations in process etc. )
\r
1005 void OCCViewer_ViewWindow::resetState()
\r
1007 myDrawRect = false;
\r
1009 if ( myRotationPointSelection )
\r
1011 QCursor handCursor (Qt::PointingHandCursor);
\r
1012 myViewPort->setCursor( handCursor );
\r
1016 if ( transformRequested() || myCursorIsHand )
\r
1017 myViewPort->setCursor( myCursor );
\r
1018 myCursorIsHand = false;
\r
1021 if ( transformRequested() )
\r
1022 emit vpTransformationFinished (myOperation);
\r
1024 setTransformInProcess( false );
\r
1025 setTransformRequested( NOTHING );
\r
1030 \brief Draw rubber band rectangle.
\r
1032 void OCCViewer_ViewWindow::drawRect()
\r
1034 if ( !myRectBand ) {
\r
1035 myRectBand = new QtxRectRubberBand( myViewPort );
\r
1036 //QPalette palette;
\r
1037 //palette.setColor(myRectBand->foregroundRole(), Qt::white);
\r
1038 //myRectBand->setPalette(palette);
\r
1040 //myRectBand->hide();
\r
1042 myRectBand->setUpdatesEnabled ( false );
\r
1043 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
\r
1044 myRectBand->initGeometry( aRect );
\r
1046 if ( !myRectBand->isVisible() )
\r
1047 myRectBand->show();
\r
1049 myRectBand->setUpdatesEnabled ( true );
\r
1050 //myRectBand->repaint();
\r
1052 //myRectBand->setVisible( aRect.isValid() );
\r
1053 //if ( myRectBand->isVisible() )
\r
1054 // myRectBand->repaint();
\r
1056 // myRectBand->show();
\r
1057 //myRectBand->repaint();
\r
1061 \brief Clear rubber band rectangle on the end on the dragging operation.
\r
1063 void OCCViewer_ViewWindow::endDrawRect()
\r
1065 //delete myRectBand;
\r
1069 myRectBand->clearGeometry();
\r
1070 myRectBand->hide();
\r
1075 \brief Create actions.
\r
1077 void OCCViewer_ViewWindow::createActions()
\r
1079 if( !toolMgr()->isEmpty() )
\r
1082 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
\r
1084 QtxAction* aAction;
\r
1087 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
\r
1088 tr( "MNU_DUMP_VIEW" ), 0, this);
\r
1089 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
\r
1090 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
\r
1091 toolMgr()->registerAction( aAction, DumpId );
\r
1094 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
\r
1095 tr( "MNU_FITALL" ), 0, this);
\r
1096 aAction->setStatusTip(tr("DSC_FITALL"));
\r
1097 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
\r
1098 toolMgr()->registerAction( aAction, FitAllId );
\r
1101 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
\r
1102 tr( "MNU_FITRECT" ), 0, this);
\r
1103 aAction->setStatusTip(tr("DSC_FITRECT"));
\r
1104 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
\r
1105 toolMgr()->registerAction( aAction, FitRectId );
\r
1108 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
\r
1109 tr( "MNU_ZOOM_VIEW" ), 0, this);
\r
1110 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
\r
1111 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
\r
1112 toolMgr()->registerAction( aAction, ZoomId );
\r
1115 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
\r
1116 tr( "MNU_PAN_VIEW" ), 0, this);
\r
1117 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
\r
1118 connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
\r
1119 toolMgr()->registerAction( aAction, PanId );
\r
1122 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
\r
1123 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
\r
1124 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
\r
1125 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
\r
1126 toolMgr()->registerAction( aAction, GlobalPanId );
\r
1129 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
\r
1130 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
\r
1131 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
\r
1132 mySetRotationPointAction->setCheckable( true );
\r
1133 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
\r
1134 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
\r
1137 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
\r
1138 tr( "MNU_ROTATE_VIEW" ), 0, this);
\r
1139 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
\r
1140 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
\r
1141 toolMgr()->registerAction( aAction, RotationId );
\r
1144 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
\r
1145 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
\r
1146 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
\r
1147 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
\r
1148 this->addAction(aAction);
\r
1149 toolMgr()->registerAction( aAction, FrontId );
\r
1151 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
\r
1152 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
\r
1153 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
\r
1154 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
\r
1155 this->addAction(aAction);
\r
1156 toolMgr()->registerAction( aAction, BackId );
\r
1158 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
\r
1159 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
\r
1160 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
\r
1161 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
\r
1162 this->addAction(aAction);
\r
1163 toolMgr()->registerAction( aAction, TopId );
\r
1165 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
\r
1166 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
\r
1167 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
\r
1168 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
\r
1169 this->addAction(aAction);
\r
1170 toolMgr()->registerAction( aAction, BottomId );
\r
1172 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
\r
1173 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
\r
1174 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
\r
1175 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
\r
1176 this->addAction(aAction);
\r
1177 toolMgr()->registerAction( aAction, LeftId );
\r
1179 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
\r
1180 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
\r
1181 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
\r
1182 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
\r
1183 this->addAction(aAction);
\r
1184 toolMgr()->registerAction( aAction, RightId );
\r
1186 // rotate anticlockwise
\r
1187 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
\r
1188 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
\r
1189 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
\r
1190 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
\r
1191 this->addAction(aAction);
\r
1192 toolMgr()->registerAction( aAction, AntiClockWiseId );
\r
1194 // rotate clockwise
\r
1195 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
\r
1196 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
\r
1197 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
\r
1198 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
\r
1199 this->addAction(aAction);
\r
1200 toolMgr()->registerAction( aAction, ClockWiseId );
\r
1203 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
\r
1204 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
\r
1205 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
\r
1206 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
\r
1207 this->addAction(aAction);
\r
1208 toolMgr()->registerAction( aAction, ResetId );
\r
1211 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
\r
1212 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
\r
1213 tr("MNU_CLONE_VIEW"), 0, this);
\r
1214 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
\r
1215 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
\r
1216 toolMgr()->registerAction( aAction, CloneId );
\r
1218 aAction = new QtxAction (tr ("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr ("ICON_OCCVIEWER_CLIPPING")),
\r
1219 tr ("MNU_CLIPPING"), 0, this);
\r
1220 aAction->setStatusTip (tr ("DSC_CLIPPING"));
\r
1221 aAction->setCheckable (true);
\r
1222 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
\r
1223 toolMgr()->registerAction (aAction, ClippingId);
\r
1225 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
\r
1226 tr( "MNU_SHOOT_VIEW" ), 0, this);
\r
1227 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
\r
1228 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
\r
1229 toolMgr()->registerAction( aAction, MemId );
\r
1231 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
\r
1232 tr( "MNU_PRESETS_VIEW" ), 0, this);
\r
1233 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
\r
1234 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
\r
1235 toolMgr()->registerAction( aAction, RestoreId );
\r
1237 if (myModel->trihedronActivated()) {
\r
1238 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
\r
1239 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
\r
1240 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
\r
1241 connect(aAction, SIGNAL(triggered()), this, SLOT(onTrihedronShow()));
\r
1242 toolMgr()->registerAction( aAction, TrihedronShowId );
\r
1246 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
\r
1247 tr( "MNU_SCALING" ), 0, this);
\r
1248 aAction->setStatusTip(tr("DSC_SCALING"));
\r
1249 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
\r
1250 toolMgr()->registerAction( aAction, AxialScaleId );
\r
1252 // Enable/disable preselection
\r
1253 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
\r
1254 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
\r
1255 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
\r
1256 aAction->setCheckable(true);
\r
1257 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
\r
1258 toolMgr()->registerAction( aAction, SwitchPreselectionId );
\r
1260 // Enable/disable selection
\r
1261 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
\r
1262 tr( "MNU_ENABLE_SELECTION" ), 0, this);
\r
1263 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
\r
1264 aAction->setCheckable(true);
\r
1265 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
\r
1266 toolMgr()->registerAction( aAction, SwitchSelectionId );
\r
1268 // Graduated axes
\r
1269 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
\r
1270 tr( "MNU_GRADUATED_AXES" ), 0, this);
\r
1271 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
\r
1272 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
\r
1273 toolMgr()->registerAction( aAction, GraduatedAxesId );
\r
1275 // Active only ambient light or not
\r
1276 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
\r
1277 tr( "MNU_AMBIENT" ), 0, this);
\r
1278 aAction->setStatusTip(tr("DSC_AMBIENT"));
\r
1279 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
\r
1280 toolMgr()->registerAction( aAction, AmbientId );
\r
1282 // Switch between interaction styles
\r
1283 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
\r
1284 tr( "MNU_STYLE_SWITCH" ), 0, this);
\r
1285 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
\r
1286 aAction->setCheckable(true);
\r
1287 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
\r
1288 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
\r
1290 // Switch between zooming styles
\r
1291 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
\r
1292 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
\r
1293 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
\r
1294 aAction->setCheckable(true);
\r
1295 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
\r
1296 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
\r
1299 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
\r
1300 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
\r
1301 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
\r
1302 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
\r
1303 toolMgr()->registerAction( aAction, MaximizedId );
\r
1305 // Return to 3d view
\r
1306 if (my2dMode!=No2dMode){
\r
1307 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
\r
1308 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
\r
1309 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
\r
1310 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
\r
1311 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
\r
1314 // Synchronize View
\r
1315 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
\r
1319 \brief Create toolbar.
\r
1321 void OCCViewer_ViewWindow::createToolBar()
\r
1323 QString aToolbarName;
\r
1324 switch (my2dMode) {
\r
1326 aToolbarName = tr( "LBL_XYTOOLBAR_LABEL" );
\r
1329 aToolbarName = tr( "LBL_XZTOOLBAR_LABEL" );
\r
1332 aToolbarName = tr( "LBL_YZTOOLBAR_LABEL" );
\r
1335 aToolbarName = tr( "LBL_3DTOOLBAR_LABEL" );
\r
1338 int tid = toolMgr()->createToolBar( aToolbarName, false );
\r
1339 if ( my2dMode != No2dMode ){
\r
1340 toolMgr()->append( ReturnTo3dViewId, tid );
\r
1341 toolMgr()->append( toolMgr()->separator(), tid );
\r
1343 toolMgr()->append( DumpId, tid );
\r
1344 toolMgr()->append( SwitchInteractionStyleId, tid );
\r
1345 #if OCC_VERSION_LARGE > 0x0603000A // available only with OCC-6.3-sp11 and higher version
\r
1346 toolMgr()->append( SwitchZoomingStyleId, tid );
\r
1348 toolMgr()->append( SwitchPreselectionId, tid );
\r
1349 toolMgr()->append( SwitchSelectionId, tid );
\r
1350 if( myModel->trihedronActivated() )
\r
1351 toolMgr()->append( TrihedronShowId, tid );
\r
1353 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
\r
1354 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
\r
1355 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
\r
1356 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
\r
1357 toolMgr()->append( aScaleAction, tid );
\r
1359 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
\r
1360 aPanningAction->insertAction( toolMgr()->action( PanId ) );
\r
1361 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
\r
1362 toolMgr()->append( aPanningAction, tid );
\r
1364 if (my2dMode == No2dMode) {
\r
1365 toolMgr()->append( ChangeRotationPointId, tid );
\r
1366 toolMgr()->append( RotationId, tid );
\r
1368 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
\r
1369 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
\r
1370 aViewsAction->insertAction( toolMgr()->action( BackId ) );
\r
1371 aViewsAction->insertAction( toolMgr()->action( TopId ) );
\r
1372 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
\r
1373 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
\r
1374 aViewsAction->insertAction( toolMgr()->action( RightId ) );
\r
1375 toolMgr()->append( aViewsAction, tid );
\r
1377 toolMgr()->append( AntiClockWiseId, tid );
\r
1378 toolMgr()->append( ClockWiseId, tid );
\r
1380 toolMgr()->append( ResetId, tid );
\r
1383 QtxMultiAction* aMemAction = new QtxMultiAction( this );
\r
1384 aMemAction->insertAction( toolMgr()->action( MemId ) );
\r
1385 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
\r
1386 toolMgr()->append( aMemAction, tid );
\r
1388 toolMgr()->append( toolMgr()->separator(), tid );
\r
1389 toolMgr()->append( CloneId, tid );
\r
1391 toolMgr()->append( toolMgr()->separator(), tid );
\r
1392 toolMgr()->append( ClippingId, tid );
\r
1393 toolMgr()->append( AxialScaleId, tid );
\r
1394 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
\r
1395 toolMgr()->append( GraduatedAxesId, tid );
\r
1397 toolMgr()->append( AmbientId, tid );
\r
1399 toolMgr()->append( MaximizedId, tid );
\r
1400 toolMgr()->append( SynchronizeId, tid );
\r
1404 \brief Perform 'fit all' operation.
\r
1406 void OCCViewer_ViewWindow::onViewFitAll()
\r
1408 myViewPort->fitAll();
\r
1412 \brief Perform "front view" transformation.
\r
1414 void OCCViewer_ViewWindow::onFrontView()
\r
1416 emit vpTransformationStarted ( FRONTVIEW );
\r
1417 Handle(V3d_View) aView3d = myViewPort->getView();
\r
1418 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
\r
1420 emit vpTransformationFinished ( FRONTVIEW );
\r
1424 \brief Perform "back view" transformation.
\r
1426 void OCCViewer_ViewWindow::onBackView()
\r
1428 emit vpTransformationStarted ( BACKVIEW );
\r
1429 Handle(V3d_View) aView3d = myViewPort->getView();
\r
1430 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
\r
1432 emit vpTransformationFinished ( BACKVIEW );
\r
1436 \brief Perform "top view" transformation.
\r
1438 void OCCViewer_ViewWindow::onTopView()
\r
1440 emit vpTransformationStarted ( TOPVIEW );
\r
1441 Handle(V3d_View) aView3d = myViewPort->getView();
\r
1442 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
\r
1444 emit vpTransformationFinished ( TOPVIEW );
\r
1448 \brief Perform "bottom view" transformation.
\r
1450 void OCCViewer_ViewWindow::onBottomView()
\r
1452 emit vpTransformationStarted ( BOTTOMVIEW );
\r
1453 Handle(V3d_View) aView3d = myViewPort->getView();
\r
1454 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
\r
1456 emit vpTransformationFinished ( BOTTOMVIEW );
\r
1460 \brief Perform "left view" transformation.
\r
1462 void OCCViewer_ViewWindow::onLeftView()
\r
1464 emit vpTransformationStarted ( LEFTVIEW );
\r
1465 Handle(V3d_View) aView3d = myViewPort->getView();
\r
1466 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
\r
1468 emit vpTransformationFinished ( LEFTVIEW );
\r
1472 \brief Perform "right view" transformation.
\r
1474 void OCCViewer_ViewWindow::onRightView()
\r
1476 emit vpTransformationStarted ( RIGHTVIEW );
\r
1477 Handle(V3d_View) aView3d = myViewPort->getView();
\r
1478 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
\r
1480 emit vpTransformationFinished ( RIGHTVIEW );
\r
1484 \brief Rotate view 90 degrees clockwise
\r
1486 void OCCViewer_ViewWindow::onClockWiseView()
\r
1488 emit vpTransformationStarted ( CLOCKWISEVIEW );
\r
1489 myViewPort->rotateXY( 90. );
\r
1490 emit vpTransformationFinished ( CLOCKWISEVIEW );
\r
1494 \brief Rotate view 90 degrees conterclockwise
\r
1496 void OCCViewer_ViewWindow::onAntiClockWiseView()
\r
1498 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
\r
1499 myViewPort->rotateXY( -90. );
\r
1500 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
\r
1504 \brief Perform "reset view" transformation.
\r
1506 Sets default orientation of the viewport camera.
\r
1508 void OCCViewer_ViewWindow::onResetView()
\r
1510 emit vpTransformationStarted( RESETVIEW );
\r
1511 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
\r
1512 myViewPort->getView()->Reset( false );
\r
1513 myViewPort->fitAll( false, true, false );
\r
1514 myViewPort->getView()->SetImmediateUpdate( upd );
\r
1515 myViewPort->getView()->Update();
\r
1516 emit vpTransformationFinished( RESETVIEW );
\r
1520 \brief Perform "fit all" transformation.
\r
1522 void OCCViewer_ViewWindow::onFitAll()
\r
1524 emit vpTransformationStarted( FITALLVIEW );
\r
1525 myViewPort->fitAll();
\r
1526 emit vpTransformationFinished( FITALLVIEW );
\r
1530 \brief Called if 'change rotation point' operation is activated.
\r
1531 \param on action state
\r
1533 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
\r
1537 if (!mySetRotationPointDlg)
\r
1539 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
\r
1540 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
\r
1543 if (!mySetRotationPointDlg->isVisible())
\r
1545 //if (mySetRotationPointDlg->IsFirstShown())
\r
1546 if (myCurrPointType == GRAVITY)
\r
1548 Standard_Real Xcenter, Ycenter, Zcenter;
\r
1549 if (computeGravityCenter(Xcenter, Ycenter, Zcenter))
\r
1550 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
\r
1552 mySetRotationPointDlg->show();
\r
1557 if (mySetRotationPointDlg->isVisible())
\r
1558 mySetRotationPointDlg->hide();
\r
1563 \brief Create one more window with same content.
\r
1565 void OCCViewer_ViewWindow::onCloneView()
\r
1567 SUIT_ViewWindow* vw = myManager->createViewWindow();
\r
1569 emit viewCloned( vw );
\r
1573 Creates one more window with same content
\r
1575 void OCCViewer_ViewWindow::onAxialScale()
\r
1577 if ( !myScalingDlg )
\r
1578 myScalingDlg = new OCCViewer_AxialScaleDlg( this );
\r
1580 if ( !myScalingDlg->isVisible() )
\r
1582 myScalingDlg->Update();
\r
1583 myScalingDlg->show();
\r
1588 Shows Graduated Axes dialog
\r
1590 void OCCViewer_ViewWindow::onGraduatedAxes()
\r
1592 myCubeAxesDlg->Update();
\r
1593 myCubeAxesDlg->show();
\r
1596 void OCCViewer_ViewWindow::onAmbientToogle()
\r
1598 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
\r
1599 viewer->InitDefinedLights();
\r
1600 while(viewer->MoreDefinedLights())
\r
1602 Handle(V3d_Light) light = viewer->DefinedLight();
\r
1603 if(light->Type() != V3d_AMBIENT)
\r
1605 Handle(V3d_View) aView3d = myViewPort->getView();
\r
1606 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
\r
1607 else viewer->SetLightOn(light);
\r
1609 viewer->NextDefinedLights();
\r
1615 \brief Store view parameters.
\r
1617 void OCCViewer_ViewWindow::onMemorizeView()
\r
1619 appendViewAspect( getViewParams() );
\r
1623 \brief Restore view parameters.
\r
1625 void OCCViewer_ViewWindow::onRestoreView()
\r
1627 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
\r
1628 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
\r
1630 updateViewAspects( aDlg->parameters() );
\r
1631 if( myRestoreFlag && aDlg->parameters().count() )
\r
1632 performRestoring( aDlg->currentItem() );
\r
1636 \brief Restore view parameters.
\r
1637 \param anItem view parameters
\r
1639 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
\r
1641 Handle(V3d_View) aView3d = myViewPort->getView();
\r
1643 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
\r
1644 aView3d->SetScale( anItem.scale );
\r
1645 aView3d->SetCenter( anItem.centerX, anItem.centerY );
\r
1646 aView3d->SetTwist( anItem.twist );
\r
1647 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
\r
1648 aView3d->SetImmediateUpdate( prev );
\r
1649 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
\r
1650 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
\r
1651 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
\r
1653 if ( !baseParamsOnly ) {
\r
1655 myModel->setTrihedronShown( anItem.isVisible );
\r
1656 myModel->setTrihedronSize( anItem.size );
\r
1658 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
\r
1659 // graduated trihedron
\r
1660 bool anIsVisible = anItem.gtIsVisible;
\r
1661 OCCViewer_AxisWidget::AxisData anAxisData[3];
\r
1662 anAxisData[0].DrawName = anItem.gtDrawNameX;
\r
1663 anAxisData[1].DrawName = anItem.gtDrawNameZ;
\r
1664 anAxisData[2].DrawName = anItem.gtDrawNameZ;
\r
1665 anAxisData[0].Name = anItem.gtNameX;
\r
1666 anAxisData[1].Name = anItem.gtNameZ;
\r
1667 anAxisData[2].Name = anItem.gtNameZ;
\r
1668 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
\r
1669 anItem.gtNameColorGX,
\r
1670 anItem.gtNameColorBX );
\r
1671 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
\r
1672 anItem.gtNameColorGY,
\r
1673 anItem.gtNameColorBY );
\r
1674 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
\r
1675 anItem.gtNameColorGZ,
\r
1676 anItem.gtNameColorBZ );
\r
1677 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
\r
1678 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
\r
1679 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
\r
1680 anAxisData[0].NbValues = anItem.gtNbValuesX;
\r
1681 anAxisData[1].NbValues = anItem.gtNbValuesY;
\r
1682 anAxisData[2].NbValues = anItem.gtNbValuesZ;
\r
1683 anAxisData[0].Offset = anItem.gtOffsetX;
\r
1684 anAxisData[1].Offset = anItem.gtOffsetY;
\r
1685 anAxisData[2].Offset = anItem.gtOffsetZ;
\r
1686 anAxisData[0].Color = QColor( anItem.gtColorRX,
\r
1688 anItem.gtColorBX );
\r
1689 anAxisData[1].Color = QColor( anItem.gtColorRY,
\r
1691 anItem.gtColorBY );
\r
1692 anAxisData[2].Color = QColor( anItem.gtColorRZ,
\r
1694 anItem.gtColorBZ );
\r
1695 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
\r
1696 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
\r
1697 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
\r
1698 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
\r
1699 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
\r
1700 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
\r
1702 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
\r
1703 myCubeAxesDlg->ApplyData( aView3d );
\r
1706 } // if ( !baseParamsOnly )
\r
1708 myRestoreFlag = 0;
\r
1712 \brief Set restore flag.
\r
1714 void OCCViewer_ViewWindow::setRestoreFlag()
\r
1716 myRestoreFlag = 1;
\r
1720 \brief Called when action "show/hide trihedron" is activated.
\r
1722 void OCCViewer_ViewWindow::onTrihedronShow()
\r
1724 myModel->toggleTrihedron();
\r
1728 \brief Toggles preselection (highlighting) on/off
\r
1730 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
\r
1732 myPreselectionEnabled = on;
\r
1733 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
\r
1735 // unhighlight all highlighted objects
\r
1737 myModel->unHighlightAll( true, false );
\r
1740 // update action state if method is called outside
\r
1741 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
\r
1742 if ( a && a->isChecked() != on ) {
\r
1743 a->setChecked( on );
\r
1748 \brief Toggles selection on/off
\r
1750 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
\r
1752 mySelectionEnabled = on;
\r
1753 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
\r
1755 // update action state if method is called outside
\r
1758 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
\r
1760 a->setEnabled( on );
\r
1764 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
\r
1765 if ( a && a->isChecked() != on ) {
\r
1766 a->setChecked( on );
\r
1771 \brief Switches "keyboard free" interaction style on/off
\r
1773 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
\r
1775 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
\r
1777 // update action state if method is called outside
\r
1778 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
\r
1779 if ( a->isChecked() != on )
\r
1780 a->setChecked( on );
\r
1784 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
\r
1786 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
\r
1788 myViewPort->setAdvancedZoomingEnabled( on );
\r
1790 // update action state if method is called outside
\r
1791 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
\r
1792 if ( a->isChecked() != on )
\r
1793 a->setChecked( on );
\r
1797 \brief Get current interaction style
\r
1798 \return interaction style
\r
1800 int OCCViewer_ViewWindow::interactionStyle() const
\r
1802 return myInteractionStyle;
\r
1806 \brief Set current interaction style
\r
1807 \param theStyle interaction style
\r
1809 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
\r
1811 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
\r
1815 \brief Get current zooming style
\r
1816 \return zooming style
\r
1818 int OCCViewer_ViewWindow::zoomingStyle() const
\r
1820 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
\r
1824 \brief Set current zooming style
\r
1825 \param theStyle zooming style
\r
1827 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
\r
1829 onSwitchZoomingStyle( theStyle == 1 );
\r
1833 \brief Dump view window contents to the pixmap.
\r
1834 \return pixmap containing all scene rendered in the window
\r
1836 QImage OCCViewer_ViewWindow::dumpView()
\r
1838 Handle(V3d_View) view = myViewPort->getView();
\r
1839 if ( view.IsNull() )
\r
1842 int aWidth = myViewPort->width();
\r
1843 int aHeight = myViewPort->height();
\r
1844 QApplication::syncX();
\r
1845 view->Redraw(); // In order to reactivate GL context
\r
1848 OpenGLUtils_FrameBuffer aFrameBuffer;
\r
1849 if( aFrameBuffer.init( aWidth, aHeight ) )
\r
1851 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
\r
1853 glPushAttrib( GL_VIEWPORT_BIT );
\r
1854 glViewport( 0, 0, aWidth, aHeight );
\r
1855 aFrameBuffer.bind();
\r
1860 aFrameBuffer.unbind();
\r
1863 aFrameBuffer.bind();
\r
1864 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
\r
1865 aFrameBuffer.unbind();
\r
1867 anImage = anImage.rgbSwapped();
\r
1868 anImage = anImage.mirrored();
\r
1871 // if frame buffers are unsupported, use old functionality
\r
1874 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
\r
1876 QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
\r
1878 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
\r
1881 QImage anImage( data, aWidth, aHeight, QImage::Format_ARGB32 );
\r
1882 anImage = anImage.mirrored();
\r
1883 anImage = anImage.rgbSwapped();
\r
1887 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
\r
1888 const QString& fileName,
\r
1889 const QString& format )
\r
1891 if ( format != "PS" && format != "EPS")
\r
1892 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
\r
1894 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
\r
1896 if (format == "PS")
\r
1897 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
\r
1898 else if (format == "EPS")
\r
1899 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
\r
1905 QString OCCViewer_ViewWindow::filter() const
\r
1907 return tr( "OCC_IMAGE_FILES" );
\r
1912 \brief Set parameters of the cutting plane
\r
1913 \param on if \c true, cutting plane is enabled
\r
1914 \param x X position of plane point
\r
1915 \param y Y position of plane point
\r
1916 \param z Z position of plane point
\r
1917 \param dx X coordinate of plane normal
\r
1918 \param dy Y coordinate of plane normal
\r
1919 \param dz Z coordinate of plane normal
\r
1921 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
\r
1922 const double dx, const double dy, const double dz )
\r
1924 Handle(V3d_View) view = myViewPort->getView();
\r
1925 if ( view.IsNull() )
\r
1929 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
\r
1931 // try to use already existing plane or create a new one
\r
1932 Handle(V3d_Plane) clipPlane;
\r
1934 // calculate new a,b,c,d values for the plane
\r
1935 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
\r
1936 double a, b, c, d;
\r
1937 pln.Coefficients(a, b, c, d);
\r
1939 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
\r
1940 Handle(Graphic3d_ClipPlane) aClipPlane;
\r
1941 if(aPlanes.Size() > 0 ) {
\r
1942 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
\r
1943 aClipPlane = anIter.Value();
\r
1944 aClipPlane->SetEquation(pln);
\r
1945 aClipPlane->SetOn(Standard_True);
\r
1947 aClipPlane = new Graphic3d_ClipPlane(pln);
\r
1948 view->AddClipPlane(aClipPlane);
\r
1949 aClipPlane->SetOn(Standard_True);
\r
1953 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
\r
1954 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
\r
1955 for( ;anIter.More();anIter.Next() ){
\r
1956 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
\r
1957 aClipPlane->SetOn(Standard_False);
\r
1965 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
\r
1967 gp_Dir aDir = pln.Axis().Direction();
\r
1968 gp_Pnt aPnt = pln.Location();
\r
1969 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
\r
1974 \brief Check if any cutting plane is enabled
\r
1975 \return \c true if at least one cutting plane is enabled
\r
1977 bool OCCViewer_ViewWindow::isCuttingPlane()
\r
1979 Handle(V3d_View) view = myViewPort->getView();
\r
1981 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
\r
1982 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
\r
1983 for( ;anIter.More();anIter.Next() ) {
\r
1984 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
\r
1985 if(aClipPlane->IsOn()) {
\r
1994 \brief Get the visual parameters of the view window.
\r
1995 \return visual parameters of view window
\r
1997 viewAspect OCCViewer_ViewWindow::getViewParams() const
\r
1999 double centerX, centerY, projX, projY, projZ, twist;
\r
2000 double atX, atY, atZ, eyeX, eyeY, eyeZ;
\r
2001 double aScaleX, aScaleY, aScaleZ;
\r
2003 Handle(V3d_View) aView3d = myViewPort->getView();
\r
2005 aView3d->Center( centerX, centerY );
\r
2006 aView3d->Proj( projX, projY, projZ );
\r
2007 aView3d->At( atX, atY, atZ );
\r
2008 aView3d->Eye( eyeX, eyeY, eyeZ );
\r
2009 twist = aView3d->Twist();
\r
2011 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
\r
2013 bool isShown = myModel->isTrihedronVisible();
\r
2014 double size = myModel->trihedronSize();
\r
2016 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
\r
2018 viewAspect params;
\r
2019 params.scale = aView3d->Scale();
\r
2020 params.centerX = centerX;
\r
2021 params.centerY = centerY;
\r
2022 params.projX = projX;
\r
2023 params.projY = projY;
\r
2024 params.projZ = projZ;
\r
2025 params.twist = twist;
\r
2029 params.eyeX = eyeX;
\r
2030 params.eyeY = eyeY;
\r
2031 params.eyeZ = eyeZ;
\r
2032 params.scaleX = aScaleX;
\r
2033 params.scaleY = aScaleY;
\r
2034 params.scaleZ = aScaleZ;
\r
2035 params.name = aName;
\r
2036 params.isVisible= isShown;
\r
2037 params.size = size;
\r
2039 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
\r
2040 // graduated trihedron
\r
2041 bool anIsVisible = false;
\r
2042 OCCViewer_AxisWidget::AxisData anAxisData[3];
\r
2043 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
\r
2045 params.gtIsVisible = anIsVisible;
\r
2046 params.gtDrawNameX = anAxisData[0].DrawName;
\r
2047 params.gtDrawNameY = anAxisData[1].DrawName;
\r
2048 params.gtDrawNameZ = anAxisData[2].DrawName;
\r
2049 params.gtNameX = anAxisData[0].Name;
\r
2050 params.gtNameY = anAxisData[1].Name;
\r
2051 params.gtNameZ = anAxisData[2].Name;
\r
2052 params.gtNameColorRX = anAxisData[0].NameColor.red();
\r
2053 params.gtNameColorGX = anAxisData[0].NameColor.green();
\r
2054 params.gtNameColorBX = anAxisData[0].NameColor.blue();
\r
2055 params.gtNameColorRY = anAxisData[1].NameColor.red();
\r
2056 params.gtNameColorGY = anAxisData[1].NameColor.green();
\r
2057 params.gtNameColorBY = anAxisData[1].NameColor.blue();
\r
2058 params.gtNameColorRZ = anAxisData[2].NameColor.red();
\r
2059 params.gtNameColorGZ = anAxisData[2].NameColor.green();
\r
2060 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
\r
2061 params.gtDrawValuesX = anAxisData[0].DrawValues;
\r
2062 params.gtDrawValuesY = anAxisData[1].DrawValues;
\r
2063 params.gtDrawValuesZ = anAxisData[2].DrawValues;
\r
2064 params.gtNbValuesX = anAxisData[0].NbValues;
\r
2065 params.gtNbValuesY = anAxisData[1].NbValues;
\r
2066 params.gtNbValuesZ = anAxisData[2].NbValues;
\r
2067 params.gtOffsetX = anAxisData[0].Offset;
\r
2068 params.gtOffsetY = anAxisData[1].Offset;
\r
2069 params.gtOffsetZ = anAxisData[2].Offset;
\r
2070 params.gtColorRX = anAxisData[0].Color.red();
\r
2071 params.gtColorGX = anAxisData[0].Color.green();
\r
2072 params.gtColorBX = anAxisData[0].Color.blue();
\r
2073 params.gtColorRY = anAxisData[1].Color.red();
\r
2074 params.gtColorGY = anAxisData[1].Color.green();
\r
2075 params.gtColorBY = anAxisData[1].Color.blue();
\r
2076 params.gtColorRZ = anAxisData[2].Color.red();
\r
2077 params.gtColorGZ = anAxisData[2].Color.green();
\r
2078 params.gtColorBZ = anAxisData[2].Color.blue();
\r
2079 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
\r
2080 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
\r
2081 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
\r
2082 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
\r
2083 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
\r
2084 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
\r
2091 \brief Get visual parameters of this view window.
\r
2092 \return visual parameters of view window
\r
2094 QString OCCViewer_ViewWindow::getVisualParameters()
\r
2096 viewAspect params = getViewParams();
\r
2100 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
\r
2101 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
\r
2102 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
\r
2103 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
\r
2104 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
\r
2105 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
\r
2106 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
\r
2107 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
\r
2108 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
\r
2109 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
\r
2110 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
\r
2111 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
\r
2112 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
\r
2113 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
\r
2114 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
\r
2115 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
\r
2116 data << QString( "isVisible=%1" ).arg( params.isVisible );
\r
2117 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
\r
2119 ClipPlanesList aPlanes = myModel->getClipPlanes();
\r
2120 for ( int i=0; i < aPlanes.size(); i++ )
\r
2122 OCCViewer_ClipPlane& aPlane = aPlanes[i];
\r
2123 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
\r
2124 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
\r
2125 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
\r
2126 switch ( aPlane.Mode )
\r
2128 case OCCViewer_ClipPlane::Absolute :
\r
2130 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
\r
2132 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
\r
2134 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
\r
2135 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
\r
2136 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
\r
2140 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
\r
2145 case OCCViewer_ClipPlane::Relative :
\r
2147 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
\r
2148 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
\r
2149 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
\r
2154 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
\r
2155 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
\r
2156 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
\r
2157 data << ClippingPlane;
\r
2161 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 or newer version
\r
2162 // graduated trihedron
\r
2163 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
\r
2164 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
\r
2165 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
\r
2166 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
\r
2167 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
\r
2168 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
\r
2169 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
\r
2170 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
\r
2171 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
\r
2172 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
\r
2173 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
\r
2174 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
\r
2175 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
\r
2176 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
\r
2177 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
\r
2178 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
\r
2179 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
\r
2180 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
\r
2181 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
\r
2182 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
\r
2183 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
\r
2184 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
\r
2185 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
\r
2186 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
\r
2187 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
\r
2188 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
\r
2189 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
\r
2190 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
\r
2191 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
\r
2192 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
\r
2193 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
\r
2194 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
\r
2195 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
\r
2196 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
\r
2197 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
\r
2198 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
\r
2199 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
\r
2200 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
\r
2201 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
\r
2202 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
\r
2204 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
\r
2205 data << QString( "background=%1" ).arg( bg );
\r
2207 return data.join("*");
\r
2211 \brief Restore visual parameters of the view window.
\r
2212 \param parameters visual parameters of view window
\r
2214 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
\r
2216 viewAspect params;
\r
2217 ClipPlanesList aClipPlanes;
\r
2218 QStringList data = parameters.split( '*' );
\r
2219 Qtx::BackgroundData bgData;
\r
2220 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
\r
2222 foreach( QString param, data ) {
\r
2223 QString paramName = param.section( '=', 0, 0 ).trimmed();
\r
2224 QString paramValue = param.section( '=', 1, 1 ).trimmed();
\r
2225 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
\r
2226 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
\r
2227 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
\r
2228 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
\r
2229 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
\r
2230 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
\r
2231 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
\r
2232 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
\r
2233 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
\r
2234 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
\r
2235 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
\r
2236 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
\r
2237 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
\r
2238 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
\r
2239 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
\r
2240 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
\r
2241 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
\r
2242 else if ( paramName == "size" ) params.size = paramValue.toDouble();
\r
2243 else if ( paramName.contains( "ClippingPlane" ) )
\r
2245 QStringList ClipPlaneData = paramValue.split( ';' );
\r
2246 OCCViewer_ClipPlane aPlane;
\r
2247 foreach( QString ClipPlaneParam, ClipPlaneData )
\r
2249 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
\r
2250 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
\r
2251 if ( ClipPlane_paramName == "Mode" )
\r
2253 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
\r
2255 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
\r
2256 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
\r
2257 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
\r
2258 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
\r
2261 switch ( aPlane.Mode )
\r
2263 case OCCViewer_ClipPlane::Absolute :
\r
2264 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
\r
2265 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
\r
2266 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
\r
2267 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
\r
2268 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
\r
2271 case OCCViewer_ClipPlane::Relative :
\r
2272 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
\r
2273 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
\r
2274 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
\r
2279 aClipPlanes.push_back(aPlane);
\r
2281 // graduated trihedron
\r
2282 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
\r
2283 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
\r
2284 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
\r
2285 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
\r
2286 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
\r
2287 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
\r
2288 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
\r
2289 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
\r
2290 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
\r
2291 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
\r
2292 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
\r
2293 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
\r
2294 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
\r
2295 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
\r
2296 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
\r
2297 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
\r
2298 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
\r
2299 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
\r
2300 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
\r
2301 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
\r
2302 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
\r
2303 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
\r
2304 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
\r
2305 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
\r
2306 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
\r
2307 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
\r
2308 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
\r
2309 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
\r
2310 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
\r
2311 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
\r
2312 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
\r
2313 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
\r
2314 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
\r
2315 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
\r
2316 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
\r
2317 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
\r
2318 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
\r
2319 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
\r
2320 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
\r
2321 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
\r
2322 else if ( paramName == "background" ) {
\r
2323 QString bg = paramValue.replace( "$", "=" );
\r
2324 bgData = Qtx::stringToBackground( bg );
\r
2328 else // old format - "1.000e+00*0.000e+00..."
\r
2331 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
\r
2332 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
\r
2333 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
\r
2334 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
\r
2335 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
\r
2336 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
\r
2337 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
\r
2338 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
\r
2339 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
\r
2340 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
\r
2341 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
\r
2342 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
\r
2343 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
\r
2344 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
\r
2345 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
\r
2346 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
\r
2347 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
\r
2348 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
\r
2350 performRestoring( params );
\r
2351 setBackground( bgData );
\r
2352 myModel->setClipPlanes(aClipPlanes);
\r
2356 \brief Handle show event.
\r
2358 Emits Show() signal.
\r
2360 \param theEvent show event
\r
2362 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
\r
2364 emit Show( theEvent );
\r
2368 \brief Handle hide event.
\r
2370 Emits Hide() signal.
\r
2372 \param theEvent hide event
\r
2374 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
\r
2376 emit Hide( theEvent );
\r
2381 Creates default sketcher. [ virtual protected ]
\r
2383 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
\r
2385 if ( type == Rect )
\r
2386 return new OCCViewer_RectSketcher( this, type );
\r
2387 if ( type == Polygon )
\r
2388 return new OCCViewer_PolygonSketcher( this, type );
\r
2392 void OCCViewer_ViewWindow::initSketchers()
\r
2394 if ( mySketchers.isEmpty() )
\r
2396 mySketchers.append( createSketcher( Rect ) );
\r
2397 mySketchers.append( createSketcher( Polygon ) );
\r
2401 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
\r
2403 OCCViewer_ViewSketcher* sketcher = 0;
\r
2404 QList<OCCViewer_ViewSketcher*>::Iterator it;
\r
2405 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
\r
2407 OCCViewer_ViewSketcher* sk = (*it);
\r
2408 if ( sk->type() == typ )
\r
2415 Handles requests for sketching in the active view. [ virtual public ]
\r
2417 void OCCViewer_ViewWindow::activateSketching( int type )
\r
2419 OCCViewer_ViewPort3d* vp = getViewPort();
\r
2423 if ( !vp->isSketchingEnabled() )
\r
2426 /* Finish current sketching */
\r
2427 if ( type == NoSketching )
\r
2429 if ( mypSketcher )
\r
2431 onSketchingFinished();
\r
2432 mypSketcher->deactivate();
\r
2436 /* Activate new sketching */
\r
2439 activateSketching( NoSketching ); /* concurrency not suported */
\r
2440 mypSketcher = getSketcher( type );
\r
2441 if ( mypSketcher )
\r
2443 mypSketcher->activate();
\r
2444 onSketchingStarted();
\r
2450 Unhilights detected entities. [ virtual protected ]
\r
2452 void OCCViewer_ViewWindow::onSketchingStarted()
\r
2457 Selection by rectangle or polygon. [ virtual protected ]
\r
2459 void OCCViewer_ViewWindow::onSketchingFinished()
\r
2461 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
\r
2462 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
\r
2464 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
\r
2465 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
\r
2466 switch( mypSketcher->type() )
\r
2470 QRect* aRect = (QRect*)mypSketcher->data();
\r
2473 int aLeft = aRect->left();
\r
2474 int aRight = aRect->right();
\r
2475 int aTop = aRect->top();
\r
2476 int aBottom = aRect->bottom();
\r
2477 // myRect = aRect;
\r
2480 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
\r
2482 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
\r
2488 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
\r
2491 int size = aPolygon->size();
\r
2492 TColgp_Array1OfPnt2d anArray( 1, size );
\r
2494 QPolygon::Iterator it = aPolygon->begin();
\r
2495 QPolygon::Iterator itEnd = aPolygon->end();
\r
2496 for( int index = 1; it != itEnd; ++it, index++ )
\r
2498 QPoint aPoint = *it;
\r
2499 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
\r
2503 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
\r
2505 ic->Select( anArray, getViewPort()->getView(), Standard_False );
\r
2513 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
\r
2514 aViewMgr->getOCCViewer()->performSelectionChanged();
\r
2518 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
\r
2520 return myViewPort;
\r
2523 bool OCCViewer_ViewWindow::transformRequested() const
\r
2525 return ( myOperation != NOTHING );
\r
2528 bool OCCViewer_ViewWindow::transformInProcess() const
\r
2530 return myEventStarted;
\r
2533 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
\r
2535 myEventStarted = bOn;
\r
2539 Set enabled state of transformation (rotate, zoom, etc)
\r
2541 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
\r
2543 if ( id != NOTHING ) myStatus.insert( id, on );
\r
2547 \return enabled state of transformation (rotate, zoom, etc)
\r
2549 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
\r
2551 return myStatus.contains( id ) ? myStatus[ id ] : true;
\r
2554 void OCCViewer_ViewWindow::onMaximizedView()
\r
2556 setMaximized(!isMaximized());
\r
2559 void OCCViewer_ViewWindow::returnTo3dView()
\r
2561 setReturnedTo3dView( true );
\r
2564 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
\r
2566 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
\r
2567 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
\r
2568 if ( !isVisible3dView )
\r
2569 toolMgr()->show( ReturnTo3dViewId );
\r
2571 toolMgr()->hide( ReturnTo3dViewId );
\r
2572 if ( isVisible3dView ) emit returnedTo3d( );
\r
2576 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
\r
2578 QAction* anAction = toolMgr()->action( MaximizedId );
\r
2579 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
\r
2580 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
\r
2581 if ( toMaximize ) {
\r
2582 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
\r
2583 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
\r
2584 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
\r
2585 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
\r
2586 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
\r
2587 if (toSendSignal) {
\r
2588 emit maximized( this, true );
\r
2592 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
\r
2593 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
\r
2594 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
\r
2595 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
\r
2596 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
\r
2597 if (toSendSignal) {
\r
2598 emit maximized( this, false );
\r
2603 bool OCCViewer_ViewWindow::isMaximized() const
\r
2605 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
\r
2608 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
\r
2610 IsSketcherStyle = enable;
\r
2613 bool OCCViewer_ViewWindow::isSketcherStyle() const
\r
2615 return IsSketcherStyle;
\r
2619 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
\r
2621 my2dMode = theType;
\r
2625 QColor OCCViewer_ViewWindow::backgroundColor() const
\r
2627 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
\r
2631 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
\r
2633 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
\r
2636 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
\r
2638 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
\r
2641 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
\r
2643 if ( myViewPort ) myViewPort->setBackground( theBackground );
\r
2647 Clears view aspects
\r
2649 void OCCViewer_ViewWindow::clearViewAspects()
\r
2651 myViewAspects.clear();
\r
2655 \return const reference to list of view aspects
\r
2657 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
\r
2659 return myViewAspects;
\r
2663 Appends new view aspect
\r
2664 \param aParams - new view aspects
\r
2666 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
\r
2668 myViewAspects.append( aParams );
\r
2672 Replaces old view aspects by new ones
\r
2673 \param aViewList - list of new view aspects
\r
2675 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
\r
2677 myViewAspects = aViewList;
\r
2681 Get camera properties for the OCC view window.
\r
2682 \return shared pointer on camera properties.
\r
2684 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
\r
2686 SUIT_CameraProperties aProps;
\r
2688 Handle(V3d_View) aSourceView = getViewPort()->getView();
\r
2689 if ( aSourceView.IsNull() )
\r
2692 if ( get2dMode() == No2dMode ) {
\r
2693 aProps.setDimension( SUIT_CameraProperties::Dim3D );
\r
2696 aProps.setDimension( SUIT_CameraProperties::Dim2D );
\r
2697 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
\r
2700 // read common properites of the view
\r
2701 Standard_Real anUpDir[3];
\r
2702 Standard_Real aPrjDir[3];
\r
2703 Standard_Real aMapScale[2];
\r
2704 Standard_Real aTranslation[3];
\r
2705 Standard_Real anAxialScale[3];
\r
2707 aSourceView->Up(anUpDir[0], anUpDir[1], anUpDir[2]);
\r
2708 aSourceView->Proj(aPrjDir[0], aPrjDir[1], aPrjDir[2]);
\r
2709 aSourceView->At(aTranslation[0], aTranslation[1], aTranslation[2]);
\r
2710 aSourceView->Size(aMapScale[0], aMapScale[1]);
\r
2712 getViewPort()->getAxialScale(anAxialScale[0], anAxialScale[1], anAxialScale[2]);
\r
2714 // we use similar depth to the one used in perspective projection
\r
2715 // to proivde a convinience synchronization with other camera views that
\r
2716 // can switch between orthogonal & perspective projection. otherwise,
\r
2717 // the camera will get to close when switching from orthogonal to perspective.
\r
2718 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
\r
2720 // store common props
\r
2721 aProps.setViewUp(anUpDir[0], anUpDir[1], anUpDir[2]);
\r
2722 aProps.setMappingScale(aMapScale[1] / 2.0);
\r
2723 aProps.setAxialScale(anAxialScale[0], anAxialScale[1], anAxialScale[2]);
\r
2725 // generate view orientation matrix for transforming OCC projection reference point
\r
2726 // into a camera (eye) position.
\r
2727 gp_Dir aLeftDir = gp_Dir(anUpDir[0], anUpDir[1], anUpDir[2]).Crossed(
\r
2728 gp_Dir(aPrjDir[0], aPrjDir[1], aPrjDir[2]));
\r
2731 aTrsf.SetValues( aLeftDir.X(), anUpDir[0], aPrjDir[0], aTranslation[0],
\r
2732 aLeftDir.Y(), anUpDir[1], aPrjDir[1], aTranslation[1],
\r
2733 aLeftDir.Z(), anUpDir[2], aPrjDir[2], aTranslation[2],
\r
2734 Precision::Confusion(),
\r
2735 Precision::Confusion() );
\r
2737 // get projection reference point in view coordinates
\r
2738 #if OCC_VERSION_LARGE > 0x06070000
\r
2739 gp_Pnt aProjRef = aSourceView->Camera()->ProjectionShift();
\r
2740 aProjRef.SetX( -aProjRef.X() );
\r
2741 aProjRef.SetY( -aProjRef.Y() );
\r
2743 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
\r
2746 // transform to world-space coordinate system
\r
2747 gp_Pnt aPosition = gp_Pnt(aProjRef.X(), aProjRef.Y(), aCameraDepth).Transformed(aTrsf);
\r
2749 // compute focal point
\r
2750 double aFocalPoint[3];
\r
2752 aFocalPoint[0] = aPosition.X() - aPrjDir[0] * aCameraDepth;
\r
2753 aFocalPoint[1] = aPosition.Y() - aPrjDir[1] * aCameraDepth;
\r
2754 aFocalPoint[2] = aPosition.Z() - aPrjDir[2] * aCameraDepth;
\r
2756 aProps.setFocalPoint(aFocalPoint[0], aFocalPoint[1], aFocalPoint[2]);
\r
2757 aProps.setPosition(aPosition.X(), aPosition.Y(), aPosition.Z());
\r
2763 Synchronize views.
\r
2764 This implementation synchronizes OCC view's camera propreties.
\r
2766 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
\r
2768 bool blocked = blockSignals( true );
\r
2770 SUIT_CameraProperties aProps = theView->cameraProperties();
\r
2771 if ( !cameraProperties().isCompatible( aProps ) ) {
\r
2772 // other view, this one is being currently synchronized to, seems has become incompatible
\r
2773 // we have to break synchronization
\r
2774 updateSyncViews();
\r
2778 Handle(V3d_View) aDestView = getViewPort()->getView();
\r
2780 aDestView->SetImmediateUpdate( Standard_False );
\r
2782 double anUpDir[3];
\r
2783 double aPosition[3];
\r
2784 double aFocalPoint[3];
\r
2785 double aMapScaling;
\r
2786 double anAxialScale[3];
\r
2788 // get common properties
\r
2789 aProps.getFocalPoint(aFocalPoint[0], aFocalPoint[1], aFocalPoint[2]);
\r
2790 aProps.getPosition(aPosition[0], aPosition[1], aPosition[2]);
\r
2791 aProps.getViewUp(anUpDir[0], anUpDir[1], anUpDir[2]);
\r
2792 aProps.getAxialScale(anAxialScale[0], anAxialScale[1], anAxialScale[2]);
\r
2793 aMapScaling = aProps.getMappingScale() * 2.0;
\r
2795 gp_Dir aProjDir(aPosition[0] - aFocalPoint[0],
\r
2796 aPosition[1] - aFocalPoint[1],
\r
2797 aPosition[2] - aFocalPoint[2]);
\r
2799 // get custom view translation
\r
2800 Standard_Real aTranslation[3];
\r
2801 aDestView->At(aTranslation[0], aTranslation[1], aTranslation[2]);
\r
2803 gp_Dir aLeftDir = gp_Dir(anUpDir[0], anUpDir[1], anUpDir[2]).Crossed(
\r
2804 gp_Dir(aProjDir.X(), aProjDir.Y(), aProjDir.Z()));
\r
2806 // convert camera position into a view reference point
\r
2808 aTrsf.SetValues( aLeftDir.X(), anUpDir[0], aProjDir.X(), aTranslation[0],
\r
2809 aLeftDir.Y(), anUpDir[1], aProjDir.Y(), aTranslation[1],
\r
2810 aLeftDir.Z(), anUpDir[2], aProjDir.Z(), aTranslation[2],
\r
2811 Precision::Confusion(),
\r
2812 Precision::Confusion() );
\r
2815 // transform to view-space coordinate system
\r
2816 gp_Pnt aProjRef(aPosition[0], aPosition[1], aPosition[2]);
\r
2817 aProjRef.Transform(aTrsf);
\r
2819 #if OCC_VERSION_LARGE > 0x06070000
\r
2820 aDestView->Camera()->SetDirection( -aProjDir );
\r
2821 aDestView->Camera()->SetUp( gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] ) );
\r
2822 aDestView->Camera()->SetProjectionShift( gp_Pnt( -aProjRef.X(), -aProjRef.Y(), 0.0 ) );
\r
2824 // set view camera properties using low-level approach. this is done
\r
2825 // in order to avoid interference with static variables in v3d view used
\r
2826 // when rotation is in process in another view.
\r
2827 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
\r
2828 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
\r
2830 Graphic3d_Vector aMappingProj(aProjDir.X(), aProjDir.Y(), aProjDir.Z());
\r
2831 Graphic3d_Vector aMappingUp(anUpDir[0], anUpDir[1], anUpDir[2]);
\r
2833 aMappingProj.Normalize();
\r
2834 aMappingUp.Normalize();
\r
2836 anOrientation.SetViewReferencePlane(aMappingProj);
\r
2837 anOrientation.SetViewReferenceUp(aMappingUp);
\r
2839 aDestView->SetViewMapping(aMapping);
\r
2840 aDestView->SetViewOrientation(anOrientation);
\r
2843 aDestView->SetCenter(aProjRef.X(), aProjRef.Y());
\r
2846 // set mapping scale
\r
2847 Standard_Real aWidth, aHeight;
\r
2848 aDestView->Size(aWidth, aHeight);
\r
2850 if ( aWidth > aHeight )
\r
2851 aDestView->SetSize (aMapScaling * (aWidth / aHeight));
\r
2853 aDestView->SetSize (aMapScaling);
\r
2855 getViewPort()->setAxialScale(anAxialScale[0], anAxialScale[1], anAxialScale[2]);
\r
2857 aDestView->ZFitAll();
\r
2858 aDestView->SetImmediateUpdate( Standard_True );
\r
2859 aDestView->Redraw();
\r
2861 blockSignals( blocked );
\r
2865 \brief Indicates whether preselection is enabled
\r
2866 \return true if preselection is enabled
\r
2868 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
\r
2870 return myPreselectionEnabled;
\r
2874 \brief Enables/disables preselection
\r
2875 \param theIsToEnable if true - preselection will be enabled
\r
2877 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
\r
2879 onSwitchPreselection( theIsToEnable );
\r
2883 \brief Indicates whether selection is enabled
\r
2884 \return true if selection is enabled
\r
2886 bool OCCViewer_ViewWindow::isSelectionEnabled() const
\r
2888 return mySelectionEnabled;
\r
2892 \brief Enables/disables selection
\r
2893 \param theIsToEnable if true - selection will be enabled
\r
2895 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
\r
2897 onSwitchSelection( theIsToEnable );
\r
2902 \brief called if clipping operation is activated / deactivated.
\r
2904 Enables/disables clipping plane displaying.
\r
2906 \parma on action state
\r
2908 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
\r
2910 if(!myModel) return;
\r
2911 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
\r
2914 if (!aClippingDlg) {
\r
2915 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
\r
2916 myModel->setClippingDlg(aClippingDlg);
\r
2918 if (!aClippingDlg->isVisible())
\r
2919 aClippingDlg->show();
\r
2921 if ( aClippingDlg ) {
\r
2922 aClippingDlg->close();
\r
2923 myModel->setClippingDlg(0);
\r
2927 SUIT_ViewManager* mgr = getViewManager();
\r
2929 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
\r
2930 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
\r
2931 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
\r
2932 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
\r
2933 if(!mgr) continue;
\r
2934 QAction* a = toolMgr()->action( ClippingId );
\r
2936 if(theIsOn != a->isChecked()){
\r
2937 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
\r
2938 a->setChecked(theIsOn);
\r
2939 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
\r