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 <gp_GTrsf.hxx>
\r
82 #include <TColgp_Array1OfPnt2d.hxx>
\r
84 #if OCC_VERSION_LARGE > 0x06060000
\r
85 #include <Graphic3d_SequenceOfHClipPlane.hxx>
\r
86 #include <Graphic3d_ClipPlane.hxx>
\r
90 #include <Standard_Version.hxx>
\r
92 #include "utilities.h"
\r
94 // // OpenCV includes
\r
96 // #include <highgui.h>
\r
98 static QEvent* l_mbPressEvent = 0;
\r
101 # include <QWindowsStyle>
\r
106 const char* imageZoomCursor[] = {
\r
111 "................................",
\r
112 "................................",
\r
113 ".#######........................",
\r
114 "..aaaaaaa.......................",
\r
115 "................................",
\r
116 ".............#####..............",
\r
117 "...........##.aaaa##............",
\r
118 "..........#.aa.....a#...........",
\r
119 ".........#.a.........#..........",
\r
120 ".........#a..........#a.........",
\r
121 "........#.a...........#.........",
\r
122 "........#a............#a........",
\r
123 "........#a............#a........",
\r
124 "........#a............#a........",
\r
125 "........#a............#a........",
\r
126 ".........#...........#.a........",
\r
127 ".........#a..........#a.........",
\r
128 ".........##.........#.a.........",
\r
129 "........#####.....##.a..........",
\r
130 ".......###aaa#####.aa...........",
\r
131 "......###aa...aaaaa.......#.....",
\r
132 ".....###aa................#a....",
\r
133 "....###aa.................#a....",
\r
134 "...###aa...............#######..",
\r
135 "....#aa.................aa#aaaa.",
\r
136 ".....a....................#a....",
\r
137 "..........................#a....",
\r
138 "...........................a....",
\r
139 "................................",
\r
140 "................................",
\r
141 "................................",
\r
142 "................................"};
\r
144 const char* imageRotateCursor[] = {
\r
149 "................................",
\r
150 "................................",
\r
151 "................................",
\r
152 "................................",
\r
153 "........#.......................",
\r
154 ".......#.a......................",
\r
155 "......#######...................",
\r
156 ".......#aaaaa#####..............",
\r
157 "........#..##.a#aa##........##..",
\r
158 ".........a#.aa..#..a#.....##.aa.",
\r
159 ".........#.a.....#...#..##.aa...",
\r
160 ".........#a.......#..###.aa.....",
\r
161 "........#.a.......#a..#aa.......",
\r
162 "........#a.........#..#a........",
\r
163 "........#a.........#a.#a........",
\r
164 "........#a.........#a.#a........",
\r
165 "........#a.........#a.#a........",
\r
166 ".........#.........#a#.a........",
\r
167 "........##a........#a#a.........",
\r
168 "......##.a#.......#.#.a.........",
\r
169 "....##.aa..##.....##.a..........",
\r
170 "..##.aa.....a#####.aa...........",
\r
171 "...aa.........aaa#a.............",
\r
172 "................#.a.............",
\r
173 "...............#.a..............",
\r
174 "..............#.a...............",
\r
175 "...............a................",
\r
176 "................................",
\r
177 "................................",
\r
178 "................................",
\r
179 "................................",
\r
180 "................................"};
\r
182 const char* imageCrossCursor[] = {
\r
187 "................................",
\r
188 "................................",
\r
189 "................................",
\r
190 "................................",
\r
191 "................................",
\r
192 "................................",
\r
193 "................................",
\r
194 "...............#................",
\r
195 "...............#a...............",
\r
196 "...............#a...............",
\r
197 "...............#a...............",
\r
198 "...............#a...............",
\r
199 "...............#a...............",
\r
200 "...............#a...............",
\r
201 "...............#a...............",
\r
202 ".......#################........",
\r
203 "........aaaaaaa#aaaaaaaaa.......",
\r
204 "...............#a...............",
\r
205 "...............#a...............",
\r
206 "...............#a...............",
\r
207 "...............#a...............",
\r
208 "...............#a...............",
\r
209 "...............#a...............",
\r
210 "...............#a...............",
\r
211 "................a...............",
\r
212 "................................",
\r
213 "................................",
\r
214 "................................",
\r
215 "................................",
\r
216 "................................",
\r
217 "................................",
\r
218 "................................"};
\r
223 \param theDesktop main window of application
\r
224 \param theModel OCC 3D viewer
\r
226 OCCViewer_ViewWindow::OCCViewer_ViewWindow( SUIT_Desktop* theDesktop,
\r
227 OCCViewer_Viewer* theModel )
\r
228 : SUIT_ViewWindow( theDesktop )
\r
230 myModel = theModel;
\r
232 myEnableDrawMode = false;
\r
234 updateEnabledDrawMode();
\r
236 mySetRotationPointDlg = 0;
\r
239 IsSketcherStyle = false;
\r
240 myIsKeyFree = false;
\r
244 my2dMode = No2dMode;
\r
246 myInteractionStyle = SUIT_ViewModel::STANDARD;
\r
247 myPreselectionEnabled = true;
\r
248 mySelectionEnabled = true;
\r
251 clearViewAspects();
\r
258 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
\r
261 qDeleteAll( mySketchers );
\r
265 \brief Internal initialization.
\r
267 void OCCViewer_ViewWindow::initLayout()
\r
269 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
\r
270 myViewPort->installEventFilter(this);
\r
271 setCentralWidget(myViewPort);
\r
272 myOperation = NOTHING;
\r
274 myCurrPointType = GRAVITY;
\r
275 myPrevPointType = GRAVITY;
\r
276 mySelectedPoint = gp_Pnt(0.,0.,0.);
\r
277 myRotationPointSelection = false;
\r
279 setTransformRequested ( NOTHING );
\r
280 setTransformInProcess ( false );
\r
285 switch (my2dMode) {
\r
297 // Graduated axes dialog
\r
298 QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
\r
299 myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
\r
300 myCubeAxesDlg->initialize();
\r
302 connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
\r
305 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
\r
307 return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
\r
311 \brief Detect viewer operation according the the mouse button pressed
\r
312 and key modifiers used.
\r
313 \param theEvent mouse event
\r
314 \return type of the operation
\r
316 OCCViewer_ViewWindow::OperationType
\r
317 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
\r
319 OperationType aOp = NOTHING;
\r
320 SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
\r
321 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
\r
322 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
\r
324 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
\r
325 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
\r
327 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
\r
328 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
\r
329 (my2dMode == No2dMode))
\r
336 \brief Customize event handling
\r
337 \param watched event receiver object
\r
339 \return \c true if the event processing should be stopped
\r
341 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
\r
343 if ( watched == myViewPort ) {
\r
344 int aType = e->type();
\r
346 case QEvent::MouseButtonPress:
\r
347 vpMousePressEvent((QMouseEvent*) e);
\r
350 case QEvent::MouseButtonRelease:
\r
351 vpMouseReleaseEvent((QMouseEvent*) e);
\r
354 case QEvent::MouseMove:
\r
355 vpMouseMoveEvent((QMouseEvent*) e);
\r
358 case QEvent::MouseButtonDblClick:
\r
359 emit mouseDoubleClicked(this, (QMouseEvent*)e);
\r
362 case QEvent::Wheel:
\r
364 QWheelEvent* aEvent = (QWheelEvent*) e;
\r
365 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
\r
366 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
\r
367 int x = aEvent->x();
\r
368 int y = aEvent->y();
\r
369 int x1 = (int)( aEvent->x() + width()*delta/100 );
\r
370 int y1 = (int)( aEvent->y() + height()*delta/100 );
\r
371 myViewPort->zoom( x, y, x1, y1 );
\r
375 case QEvent::ContextMenu:
\r
377 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
\r
378 if ( aEvent->reason() != QContextMenuEvent::Mouse )
\r
379 emit contextMenuRequested( aEvent );
\r
383 case QEvent::KeyPress:
\r
384 emit keyPressed(this, (QKeyEvent*) e);
\r
391 return SUIT_ViewWindow::eventFilter(watched, e);
\r
395 \brief Update state of enable draw mode state.
\r
397 void OCCViewer_ViewWindow::updateEnabledDrawMode()
\r
400 myEnableDrawMode = myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
\r
404 \brief Handle mouse press event
\r
405 \param theEvent mouse event
\r
407 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
\r
409 myStartX = theEvent->x();
\r
410 myStartY = theEvent->y();
\r
411 int anInteractionStyle = interactionStyle();
\r
413 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
\r
414 // which are assigned for pan and rotate - these operations are activated immediately after pressing
\r
415 // of the first button, so it is necessary to switch to zoom when the second button is pressed
\r
416 bool aSwitchToZoom = false;
\r
417 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
\r
418 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
\r
419 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
\r
422 switch ( myOperation ) {
\r
424 if ( theEvent->button() == Qt::LeftButton )
\r
425 emit vpTransformationStarted ( WINDOWFIT );
\r
429 if ( theEvent->button() == Qt::LeftButton )
\r
430 emit vpTransformationStarted ( PANGLOBAL );
\r
434 if ( theEvent->button() == Qt::LeftButton ) {
\r
435 myViewPort->startZoomAtPoint( myStartX, myStartY );
\r
436 emit vpTransformationStarted ( ZOOMVIEW );
\r
441 if ( aSwitchToZoom ) {
\r
442 myViewPort->startZoomAtPoint( myStartX, myStartY );
\r
445 else if ( theEvent->button() == Qt::LeftButton )
\r
446 emit vpTransformationStarted ( PANVIEW );
\r
450 if ( aSwitchToZoom ) {
\r
451 myViewPort->startZoomAtPoint( myStartX, myStartY );
\r
454 else if ( theEvent->button() == Qt::LeftButton ) {
\r
455 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
\r
456 emit vpTransformationStarted ( ROTATE );
\r
461 /* Try to activate a transformation */
\r
462 OperationType aState;
\r
463 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
\r
464 aState = getButtonState(theEvent, anInteractionStyle);
\r
466 aState = OCCViewer_ViewWindow::NOTHING;
\r
467 myIsKeyFree = true;
\r
469 switch ( aState ) {
\r
471 myViewPort->startZoomAtPoint( myStartX, myStartY );
\r
478 activateRotation();
\r
479 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
\r
482 if ( myRotationPointSelection )
\r
484 if ( theEvent->button() == Qt::LeftButton )
\r
486 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
\r
488 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
\r
490 TopoDS_Shape aShape = ic->SelectedShape();
\r
491 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
\r
493 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
\r
494 if ( mySetRotationPointDlg )
\r
496 myRotationPointSelection = false;
\r
497 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
\r
502 myCurrPointType = myPrevPointType;
\r
506 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
\r
507 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
\r
508 ic->CloseAllContexts();
\r
509 myOperation = NOTHING;
\r
510 myViewPort->setCursor( myCursor );
\r
511 myCursorIsHand = false;
\r
512 myRotationPointSelection = false;
\r
516 emit mousePressed(this, theEvent);
\r
519 /* notify that we start a transformation */
\r
520 if ( transformRequested() )
\r
521 emit vpTransformationStarted ( myOperation );
\r
523 if ( transformRequested() )
\r
524 setTransformInProcess( true );
\r
526 /* we may need it for sketching... */
\r
527 if ( l_mbPressEvent )
\r
528 delete l_mbPressEvent;
\r
529 l_mbPressEvent = new QMouseEvent( *theEvent );
\r
534 \brief Start zooming operation.
\r
536 Sets the corresponding cursor for the widget.
\r
538 void OCCViewer_ViewWindow::activateZoom()
\r
540 if ( !transformRequested() && !myCursorIsHand )
\r
541 myCursor = cursor(); /* save old cursor */
\r
543 if ( myOperation != ZOOMVIEW ) {
\r
544 QPixmap zoomPixmap (imageZoomCursor);
\r
545 QCursor zoomCursor (zoomPixmap);
\r
546 if( setTransformRequested ( ZOOMVIEW ) )
\r
547 myViewPort->setCursor( zoomCursor );
\r
553 \brief Start panning operation.
\r
555 Sets the corresponding cursor for the widget.
\r
557 void OCCViewer_ViewWindow::activatePanning()
\r
559 if ( !transformRequested() && !myCursorIsHand )
\r
560 myCursor = cursor(); // save old cursor
\r
562 if ( myOperation != PANVIEW ) {
\r
563 QCursor panCursor (Qt::SizeAllCursor);
\r
564 if( setTransformRequested ( PANVIEW ) )
\r
565 myViewPort->setCursor( panCursor );
\r
570 \brief Start rotation operation
\r
572 Sets the corresponding cursor for the widget.
\r
574 void OCCViewer_ViewWindow::activateRotation()
\r
576 if ( !transformRequested() && !myCursorIsHand )
\r
577 myCursor = cursor(); // save old cursor
\r
579 if ( myOperation != ROTATE ) {
\r
580 QPixmap rotatePixmap (imageRotateCursor);
\r
581 QCursor rotCursor (rotatePixmap);
\r
582 if( setTransformRequested ( ROTATE ) )
\r
583 myViewPort->setCursor( rotCursor );
\r
588 \brief Compute the gravity center.
\r
589 \param theX used to return X coordinate of the gravity center
\r
590 \param theY used to return Y coordinate of the gravity center
\r
591 \param theZ used to return Z coordinate of the gravity center
\r
592 \return \c true if the gravity center is computed
\r
594 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
\r
596 Handle(V3d_View) aView3d = myViewPort->getView();
\r
598 // Project boundaries points and add to avergae gravity
\r
599 // the ones which lie within the screen limits
\r
600 Standard_Real aScreenLimits[4] = { 0.0, 0.0, 0.0, 0.0 };
\r
602 #if OCC_VERSION_LARGE > 0x06070000
\r
603 // NDC space screen limits
\r
604 aScreenLimits[0] = -1.0;
\r
605 aScreenLimits[1] = 1.0;
\r
606 aScreenLimits[2] = -1.0;
\r
607 aScreenLimits[3] = 1.0;
\r
609 aView3d->View()->ViewMapping().WindowLimit( aScreenLimits[0],
\r
612 aScreenLimits[3] );
\r
615 Standard_Integer aPointsNb = 0;
\r
617 Standard_Real aXmin = 0.0;
\r
618 Standard_Real aYmin = 0.0;
\r
619 Standard_Real aZmin = 0.0;
\r
620 Standard_Real aXmax = 0.0;
\r
621 Standard_Real aYmax = 0.0;
\r
622 Standard_Real aZmax = 0.0;
\r
624 Graphic3d_MapOfStructure aSetOfStructures;
\r
625 aView3d->View()->DisplayedStructures( aSetOfStructures );
\r
626 Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures );
\r
628 for( ; aStructureIt.More(); aStructureIt.Next() ) {
\r
629 const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key();
\r
630 if ( aStructure->IsEmpty() ) {
\r
634 aStructure->MinMaxValues( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
\r
636 // Infinite structures are skipped
\r
637 Standard_Real aLIM = ShortRealLast() - 1.0;
\r
638 if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
\r
639 || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
\r
643 gp_Pnt aPoints[8] = {
644 gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
645 gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
646 gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
647 gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
650 for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
\r
651 const gp_Pnt& aBBPoint = aPoints[aPointIt];
653 #if OCC_VERSION_LARGE > 0x06070000
654 gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
655 const Standard_Real& U = aProjected.X();
656 const Standard_Real& V = aProjected.Y();
658 Standard_Real U = 0.0;
659 Standard_Real V = 0.0;
660 Standard_Real W = 0.0;
661 aView3d->View()->Projects( aBBPoint.X(), aBBPoint.Y(), aBBPoint.Z(), U, V, W );
664 if (U >= aScreenLimits[0]
665 && U <= aScreenLimits[1]
666 && V >= aScreenLimits[2]
667 && V <= aScreenLimits[3])
670 theX += aBBPoint.X();
671 theY += aBBPoint.Y();
672 theZ += aBBPoint.Z();
677 if ( aPointsNb > 0 )
\r
687 \brief Set the gravity center as a rotation point.
\r
689 void OCCViewer_ViewWindow::activateSetRotationGravity()
\r
691 if ( myRotationPointSelection )
\r
693 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
\r
694 ic->CloseAllContexts();
\r
695 myOperation = NOTHING;
\r
696 myViewPort->setCursor( myCursor );
\r
697 myCursorIsHand = false;
\r
698 myRotationPointSelection = false;
\r
701 myPrevPointType = myCurrPointType;
\r
702 myCurrPointType = GRAVITY;
\r
704 Standard_Real Xcenter, Ycenter, Zcenter;
\r
705 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
\r
706 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
\r
710 \brief Update gravity center in the "Set Rotation Point" dialog box.
\r
711 \sa OCCViewer_SetRotationPointDlg class
\r
713 void OCCViewer_ViewWindow::updateGravityCoords()
\r
715 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == GRAVITY )
\r
717 Standard_Real Xcenter, Ycenter, Zcenter;
\r
718 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
\r
719 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
\r
724 \brief Set the point selected by the user as a rotation point.
\r
725 \param theX X coordinate of the rotation point
\r
726 \param theY Y coordinate of the rotation point
\r
727 \param theZ Z coordinate of the rotation point
\r
729 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
\r
731 if ( myRotationPointSelection )
\r
733 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
\r
734 ic->CloseAllContexts();
\r
735 myOperation = NOTHING;
\r
736 myViewPort->setCursor( myCursor );
\r
737 myCursorIsHand = false;
\r
738 myRotationPointSelection = false;
\r
741 myPrevPointType = myCurrPointType;
\r
742 myCurrPointType = SELECTED;
\r
743 mySelectedPoint.SetCoord(theX,theY,theZ);
\r
747 \brief Start the point selection process.
\r
749 void OCCViewer_ViewWindow::activateStartPointSelection()
\r
751 myPrevPointType = myCurrPointType;
\r
752 myCurrPointType = SELECTED;
\r
754 // activate selection ------>
\r
755 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
\r
757 ic->OpenLocalContext();
\r
759 AIS_ListOfInteractive aList;
\r
760 ic->DisplayedObjects( aList );
\r
761 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
\r
763 Handle(AIS_InteractiveObject) anObj = it.Value();
\r
764 if ( !anObj.IsNull() && anObj->HasPresentation() &&
\r
765 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
\r
767 ic->Load(anObj,-1);
\r
768 ic->Activate(anObj,AIS_Shape::SelectionMode(TopAbs_VERTEX));
\r
771 // activate selection <------
\r
773 if ( !myCursorIsHand )
\r
775 QCursor handCursor (Qt::PointingHandCursor);
\r
776 myCursorIsHand = true;
\r
777 myCursor = cursor();
\r
778 myViewPort->setCursor( handCursor );
\r
780 myRotationPointSelection = true;
\r
784 \brief Start global panning operation
\r
786 Sets the corresponding cursor for the widget.
\r
788 void OCCViewer_ViewWindow::activateGlobalPanning()
\r
790 Handle(V3d_View) aView3d = myViewPort->getView();
\r
791 if ( !aView3d.IsNull() ) {
\r
792 QPixmap globalPanPixmap (imageCrossCursor);
\r
793 QCursor glPanCursor (globalPanPixmap);
\r
794 myCurScale = aView3d->Scale();
\r
795 aView3d->FitAll(0.01, false);
\r
796 myCursor = cursor(); // save old cursor
\r
797 myViewPort->fitAll(); // fits view before selecting a new scene center
\r
798 if( setTransformRequested( PANGLOBAL ) )
\r
799 myViewPort->setCursor( glPanCursor );
\r
804 \brief Starts fit operation.
\r
806 Sets the corresponding cursor for the widget.
\r
808 void OCCViewer_ViewWindow::activateWindowFit()
\r
810 if ( !transformRequested() && !myCursorIsHand )
\r
811 myCursor = cursor(); /* save old cursor */
\r
813 if ( myOperation != WINDOWFIT ) {
\r
814 QCursor handCursor (Qt::PointingHandCursor);
\r
815 if( setTransformRequested ( WINDOWFIT ) )
\r
817 myViewPort->setCursor ( handCursor );
\r
818 myCursorIsHand = true;
\r
824 \brief Start delayed viewer operation.
\r
826 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
\r
828 bool ok = transformEnabled( op );
\r
829 myOperation = ok ? op : NOTHING;
\r
830 myViewPort->setMouseTracking( myOperation == NOTHING );
\r
835 \brief Handle mouse move event.
\r
836 \param theEvent mouse event
\r
838 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
\r
840 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
\r
841 myIsKeyFree = false;
\r
842 switch ( getButtonState( theEvent, interactionStyle() ) ) {
\r
844 myViewPort->startZoomAtPoint( myStartX, myStartY );
\r
851 activateRotation();
\r
852 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
\r
859 myCurrX = theEvent->x();
\r
860 myCurrY = theEvent->y();
\r
861 switch (myOperation) {
\r
863 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
\r
867 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
\r
868 myStartX = myCurrX;
\r
869 myStartY = myCurrY;
\r
873 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
\r
874 myStartX = myCurrX;
\r
875 myStartY = myCurrY;
\r
887 if ( myRotationPointSelection || isSketcherStyle() )
\r
889 emit mouseMoving( this, theEvent );
\r
893 int aState = theEvent->modifiers();
\r
894 int aButton = theEvent->buttons();
\r
895 int anInteractionStyle = interactionStyle();
\r
896 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
\r
897 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
\r
898 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
\r
899 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
\r
900 myDrawRect = myEnableDrawMode;
\r
901 if ( myDrawRect ) {
\r
903 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
\r
904 QCursor handCursor (Qt::PointingHandCursor);
\r
905 myCursorIsHand = true;
\r
906 myCursor = cursor();
\r
907 myViewPort->setCursor( handCursor );
\r
910 emit mouseMoving( this, theEvent );
\r
912 else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
\r
913 aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
\r
914 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
\r
915 aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
\r
916 OCCViewer_ViewSketcher* sketcher = 0;
\r
917 QList<OCCViewer_ViewSketcher*>::Iterator it;
\r
918 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
\r
920 OCCViewer_ViewSketcher* sk = (*it);
\r
921 if( sk->isDefault() && sk->sketchButton() == aButton )
\r
924 if ( sketcher && myCurSketch == -1 )
\r
926 activateSketching( sketcher->type() );
\r
929 myCurSketch = mypSketcher->sketchButton();
\r
931 if ( l_mbPressEvent )
\r
933 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
\r
934 delete l_mbPressEvent;
\r
935 l_mbPressEvent = 0;
\r
937 QApplication::sendEvent( getViewPort(), theEvent );
\r
942 emit mouseMoving( this, theEvent );
\r
948 \brief Handle mouse release event.
\r
949 \param theEvent mouse event
\r
951 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
\r
953 switch ( myOperation ) {
\r
956 int prevState = myCurSketch;
\r
957 if(theEvent->button() == Qt::RightButton)
\r
959 QList<OCCViewer_ViewSketcher*>::Iterator it;
\r
960 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
\r
962 OCCViewer_ViewSketcher* sk = (*it);
\r
963 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
\r
968 emit mouseReleased(this, theEvent);
\r
969 if(theEvent->button() == Qt::RightButton && prevState == -1)
\r
971 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
\r
972 theEvent->pos(), theEvent->globalPos() );
\r
973 emit contextMenuRequested( &aEvent );
\r
978 myViewPort->endRotation();
\r
988 if ( theEvent->button() == Qt::LeftButton ) {
\r
989 myViewPort->setCenter( theEvent->x(), theEvent->y() );
\r
990 myViewPort->getView()->SetScale(myCurScale);
\r
996 if ( theEvent->button() == Qt::LeftButton ) {
\r
997 myCurrX = theEvent->x();
\r
998 myCurrY = theEvent->y();
\r
1000 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
\r
1001 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
\r
1008 // NOTE: viewer 3D detects a rectangle of selection using this event
\r
1009 // so we must emit it BEFORE resetting the selection rectangle
\r
1011 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
\r
1015 myViewPort->update();
\r
1018 if ( l_mbPressEvent )
\r
1020 delete l_mbPressEvent;
\r
1021 l_mbPressEvent = 0;
\r
1026 \brief Reset the viewport to its initial state
\r
1027 ( no transformations in process etc. )
\r
1029 void OCCViewer_ViewWindow::resetState()
\r
1031 myDrawRect = false;
\r
1033 if ( myRotationPointSelection )
\r
1035 QCursor handCursor (Qt::PointingHandCursor);
\r
1036 myViewPort->setCursor( handCursor );
\r
1040 if ( transformRequested() || myCursorIsHand )
\r
1041 myViewPort->setCursor( myCursor );
\r
1042 myCursorIsHand = false;
\r
1045 if ( transformRequested() )
\r
1046 emit vpTransformationFinished (myOperation);
\r
1048 setTransformInProcess( false );
\r
1049 setTransformRequested( NOTHING );
\r
1054 \brief Draw rubber band rectangle.
\r
1056 void OCCViewer_ViewWindow::drawRect()
\r
1058 if ( !myRectBand ) {
\r
1059 myRectBand = new QtxRectRubberBand( myViewPort );
\r
1060 //QPalette palette;
\r
1061 //palette.setColor(myRectBand->foregroundRole(), Qt::white);
\r
1062 //myRectBand->setPalette(palette);
\r
1064 //myRectBand->hide();
\r
1066 myRectBand->setUpdatesEnabled ( false );
\r
1067 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
\r
1068 myRectBand->initGeometry( aRect );
\r
1070 if ( !myRectBand->isVisible() )
\r
1071 myRectBand->show();
\r
1073 myRectBand->setUpdatesEnabled ( true );
\r
1074 //myRectBand->repaint();
\r
1076 //myRectBand->setVisible( aRect.isValid() );
\r
1077 //if ( myRectBand->isVisible() )
\r
1078 // myRectBand->repaint();
\r
1080 // myRectBand->show();
\r
1081 //myRectBand->repaint();
\r
1085 \brief Clear rubber band rectangle on the end on the dragging operation.
\r
1087 void OCCViewer_ViewWindow::endDrawRect()
\r
1089 //delete myRectBand;
\r
1093 myRectBand->clearGeometry();
\r
1094 myRectBand->hide();
\r
1099 \brief Create actions.
\r
1101 void OCCViewer_ViewWindow::createActions()
\r
1103 if( !toolMgr()->isEmpty() )
\r
1106 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
\r
1108 QtxAction* aAction;
\r
1111 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
\r
1112 tr( "MNU_DUMP_VIEW" ), 0, this);
\r
1113 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
\r
1114 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
\r
1115 toolMgr()->registerAction( aAction, DumpId );
\r
1118 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
\r
1119 tr( "MNU_FITALL" ), 0, this);
\r
1120 aAction->setStatusTip(tr("DSC_FITALL"));
\r
1121 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
\r
1122 toolMgr()->registerAction( aAction, FitAllId );
\r
1125 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
\r
1126 tr( "MNU_FITRECT" ), 0, this);
\r
1127 aAction->setStatusTip(tr("DSC_FITRECT"));
\r
1128 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
\r
1129 toolMgr()->registerAction( aAction, FitRectId );
\r
1132 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
\r
1133 tr( "MNU_ZOOM_VIEW" ), 0, this);
\r
1134 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
\r
1135 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
\r
1136 toolMgr()->registerAction( aAction, ZoomId );
\r
1139 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
\r
1140 tr( "MNU_PAN_VIEW" ), 0, this);
\r
1141 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
\r
1142 connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
\r
1143 toolMgr()->registerAction( aAction, PanId );
\r
1146 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
\r
1147 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
\r
1148 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
\r
1149 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
\r
1150 toolMgr()->registerAction( aAction, GlobalPanId );
\r
1153 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
\r
1154 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
\r
1155 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
\r
1156 mySetRotationPointAction->setCheckable( true );
\r
1157 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
\r
1158 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
\r
1161 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
\r
1162 tr( "MNU_ROTATE_VIEW" ), 0, this);
\r
1163 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
\r
1164 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
\r
1165 toolMgr()->registerAction( aAction, RotationId );
\r
1168 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
\r
1169 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
\r
1170 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
\r
1171 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
\r
1172 this->addAction(aAction);
\r
1173 toolMgr()->registerAction( aAction, FrontId );
\r
1175 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
\r
1176 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
\r
1177 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
\r
1178 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
\r
1179 this->addAction(aAction);
\r
1180 toolMgr()->registerAction( aAction, BackId );
\r
1182 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
\r
1183 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
\r
1184 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
\r
1185 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
\r
1186 this->addAction(aAction);
\r
1187 toolMgr()->registerAction( aAction, TopId );
\r
1189 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
\r
1190 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
\r
1191 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
\r
1192 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
\r
1193 this->addAction(aAction);
\r
1194 toolMgr()->registerAction( aAction, BottomId );
\r
1196 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
\r
1197 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
\r
1198 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
\r
1199 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
\r
1200 this->addAction(aAction);
\r
1201 toolMgr()->registerAction( aAction, LeftId );
\r
1203 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
\r
1204 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
\r
1205 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
\r
1206 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
\r
1207 this->addAction(aAction);
\r
1208 toolMgr()->registerAction( aAction, RightId );
\r
1210 // rotate anticlockwise
\r
1211 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
\r
1212 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
\r
1213 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
\r
1214 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
\r
1215 this->addAction(aAction);
\r
1216 toolMgr()->registerAction( aAction, AntiClockWiseId );
\r
1218 // rotate clockwise
\r
1219 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
\r
1220 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
\r
1221 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
\r
1222 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
\r
1223 this->addAction(aAction);
\r
1224 toolMgr()->registerAction( aAction, ClockWiseId );
\r
1227 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
\r
1228 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
\r
1229 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
\r
1230 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
\r
1231 this->addAction(aAction);
\r
1232 toolMgr()->registerAction( aAction, ResetId );
\r
1235 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
\r
1236 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
\r
1237 tr("MNU_CLONE_VIEW"), 0, this);
\r
1238 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
\r
1239 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
\r
1240 toolMgr()->registerAction( aAction, CloneId );
\r
1242 aAction = new QtxAction (tr ("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr ("ICON_OCCVIEWER_CLIPPING")),
\r
1243 tr ("MNU_CLIPPING"), 0, this);
\r
1244 aAction->setStatusTip (tr ("DSC_CLIPPING"));
\r
1245 aAction->setCheckable (true);
\r
1246 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
\r
1247 toolMgr()->registerAction (aAction, ClippingId);
\r
1249 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
\r
1250 tr( "MNU_SHOOT_VIEW" ), 0, this);
\r
1251 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
\r
1252 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
\r
1253 toolMgr()->registerAction( aAction, MemId );
\r
1255 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
\r
1256 tr( "MNU_PRESETS_VIEW" ), 0, this);
\r
1257 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
\r
1258 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
\r
1259 toolMgr()->registerAction( aAction, RestoreId );
\r
1261 if (myModel->trihedronActivated()) {
\r
1262 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
\r
1263 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
\r
1264 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
\r
1265 connect(aAction, SIGNAL(triggered()), this, SLOT(onTrihedronShow()));
\r
1266 toolMgr()->registerAction( aAction, TrihedronShowId );
\r
1270 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
\r
1271 tr( "MNU_SCALING" ), 0, this);
\r
1272 aAction->setStatusTip(tr("DSC_SCALING"));
\r
1273 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
\r
1274 toolMgr()->registerAction( aAction, AxialScaleId );
\r
1276 // Enable/disable preselection
\r
1277 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
\r
1278 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
\r
1279 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
\r
1280 aAction->setCheckable(true);
\r
1281 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
\r
1282 toolMgr()->registerAction( aAction, SwitchPreselectionId );
\r
1284 // Enable/disable selection
\r
1285 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
\r
1286 tr( "MNU_ENABLE_SELECTION" ), 0, this);
\r
1287 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
\r
1288 aAction->setCheckable(true);
\r
1289 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
\r
1290 toolMgr()->registerAction( aAction, SwitchSelectionId );
\r
1292 // Graduated axes
\r
1293 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
\r
1294 tr( "MNU_GRADUATED_AXES" ), 0, this);
\r
1295 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
\r
1296 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
\r
1297 toolMgr()->registerAction( aAction, GraduatedAxesId );
\r
1299 // Active only ambient light or not
\r
1300 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
\r
1301 tr( "MNU_AMBIENT" ), 0, this);
\r
1302 aAction->setStatusTip(tr("DSC_AMBIENT"));
\r
1303 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
\r
1304 toolMgr()->registerAction( aAction, AmbientId );
\r
1306 // Switch between interaction styles
\r
1307 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
\r
1308 tr( "MNU_STYLE_SWITCH" ), 0, this);
\r
1309 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
\r
1310 aAction->setCheckable(true);
\r
1311 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
\r
1312 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
\r
1314 // Switch between zooming styles
\r
1315 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
\r
1316 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
\r
1317 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
\r
1318 aAction->setCheckable(true);
\r
1319 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
\r
1320 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
\r
1323 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
\r
1324 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
\r
1325 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
\r
1326 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
\r
1327 toolMgr()->registerAction( aAction, MaximizedId );
\r
1329 // Return to 3d view
\r
1330 if (my2dMode!=No2dMode){
\r
1331 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
\r
1332 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
\r
1333 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
\r
1334 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
\r
1335 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
\r
1338 // Synchronize View
\r
1339 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
\r
1343 \brief Create toolbar.
\r
1345 void OCCViewer_ViewWindow::createToolBar()
\r
1347 QString aToolbarName;
\r
1348 switch (my2dMode) {
\r
1350 aToolbarName = tr( "LBL_XYTOOLBAR_LABEL" );
\r
1353 aToolbarName = tr( "LBL_XZTOOLBAR_LABEL" );
\r
1356 aToolbarName = tr( "LBL_YZTOOLBAR_LABEL" );
\r
1359 aToolbarName = tr( "LBL_3DTOOLBAR_LABEL" );
\r
1362 int tid = toolMgr()->createToolBar( aToolbarName, false );
\r
1363 if ( my2dMode != No2dMode ){
\r
1364 toolMgr()->append( ReturnTo3dViewId, tid );
\r
1365 toolMgr()->append( toolMgr()->separator(), tid );
\r
1367 toolMgr()->append( DumpId, tid );
\r
1368 toolMgr()->append( SwitchInteractionStyleId, tid );
\r
1369 #if OCC_VERSION_LARGE > 0x0603000A // available only with OCC-6.3-sp11 and higher version
\r
1370 toolMgr()->append( SwitchZoomingStyleId, tid );
\r
1372 toolMgr()->append( SwitchPreselectionId, tid );
\r
1373 toolMgr()->append( SwitchSelectionId, tid );
\r
1374 if( myModel->trihedronActivated() )
\r
1375 toolMgr()->append( TrihedronShowId, tid );
\r
1377 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
\r
1378 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
\r
1379 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
\r
1380 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
\r
1381 toolMgr()->append( aScaleAction, tid );
\r
1383 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
\r
1384 aPanningAction->insertAction( toolMgr()->action( PanId ) );
\r
1385 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
\r
1386 toolMgr()->append( aPanningAction, tid );
\r
1388 if (my2dMode == No2dMode) {
\r
1389 toolMgr()->append( ChangeRotationPointId, tid );
\r
1390 toolMgr()->append( RotationId, tid );
\r
1392 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
\r
1393 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
\r
1394 aViewsAction->insertAction( toolMgr()->action( BackId ) );
\r
1395 aViewsAction->insertAction( toolMgr()->action( TopId ) );
\r
1396 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
\r
1397 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
\r
1398 aViewsAction->insertAction( toolMgr()->action( RightId ) );
\r
1399 toolMgr()->append( aViewsAction, tid );
\r
1401 toolMgr()->append( AntiClockWiseId, tid );
\r
1402 toolMgr()->append( ClockWiseId, tid );
\r
1404 toolMgr()->append( ResetId, tid );
\r
1407 QtxMultiAction* aMemAction = new QtxMultiAction( this );
\r
1408 aMemAction->insertAction( toolMgr()->action( MemId ) );
\r
1409 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
\r
1410 toolMgr()->append( aMemAction, tid );
\r
1412 toolMgr()->append( toolMgr()->separator(), tid );
\r
1413 toolMgr()->append( CloneId, tid );
\r
1415 toolMgr()->append( toolMgr()->separator(), tid );
\r
1416 toolMgr()->append( ClippingId, tid );
\r
1417 toolMgr()->append( AxialScaleId, tid );
\r
1418 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
\r
1419 toolMgr()->append( GraduatedAxesId, tid );
\r
1421 toolMgr()->append( AmbientId, tid );
\r
1423 toolMgr()->append( MaximizedId, tid );
\r
1424 toolMgr()->append( SynchronizeId, tid );
\r
1428 \brief Perform 'fit all' operation.
\r
1430 void OCCViewer_ViewWindow::onViewFitAll()
\r
1432 myViewPort->fitAll();
\r
1436 \brief Perform "front view" transformation.
\r
1438 void OCCViewer_ViewWindow::onFrontView()
\r
1440 emit vpTransformationStarted ( FRONTVIEW );
\r
1441 Handle(V3d_View) aView3d = myViewPort->getView();
\r
1442 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
\r
1444 emit vpTransformationFinished ( FRONTVIEW );
\r
1448 \brief Perform "back view" transformation.
\r
1450 void OCCViewer_ViewWindow::onBackView()
\r
1452 emit vpTransformationStarted ( BACKVIEW );
\r
1453 Handle(V3d_View) aView3d = myViewPort->getView();
\r
1454 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
\r
1456 emit vpTransformationFinished ( BACKVIEW );
\r
1460 \brief Perform "top view" transformation.
\r
1462 void OCCViewer_ViewWindow::onTopView()
\r
1464 emit vpTransformationStarted ( TOPVIEW );
\r
1465 Handle(V3d_View) aView3d = myViewPort->getView();
\r
1466 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
\r
1468 emit vpTransformationFinished ( TOPVIEW );
\r
1472 \brief Perform "bottom view" transformation.
\r
1474 void OCCViewer_ViewWindow::onBottomView()
\r
1476 emit vpTransformationStarted ( BOTTOMVIEW );
\r
1477 Handle(V3d_View) aView3d = myViewPort->getView();
\r
1478 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
\r
1480 emit vpTransformationFinished ( BOTTOMVIEW );
\r
1484 \brief Perform "left view" transformation.
\r
1486 void OCCViewer_ViewWindow::onLeftView()
\r
1488 emit vpTransformationStarted ( LEFTVIEW );
\r
1489 Handle(V3d_View) aView3d = myViewPort->getView();
\r
1490 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
\r
1492 emit vpTransformationFinished ( LEFTVIEW );
\r
1496 \brief Perform "right view" transformation.
\r
1498 void OCCViewer_ViewWindow::onRightView()
\r
1500 emit vpTransformationStarted ( RIGHTVIEW );
\r
1501 Handle(V3d_View) aView3d = myViewPort->getView();
\r
1502 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
\r
1504 emit vpTransformationFinished ( RIGHTVIEW );
\r
1508 \brief Rotate view 90 degrees clockwise
\r
1510 void OCCViewer_ViewWindow::onClockWiseView()
\r
1512 emit vpTransformationStarted ( CLOCKWISEVIEW );
\r
1513 myViewPort->rotateXY( 90. );
\r
1514 emit vpTransformationFinished ( CLOCKWISEVIEW );
\r
1518 \brief Rotate view 90 degrees conterclockwise
\r
1520 void OCCViewer_ViewWindow::onAntiClockWiseView()
\r
1522 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
\r
1523 myViewPort->rotateXY( -90. );
\r
1524 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
\r
1528 \brief Perform "reset view" transformation.
\r
1530 Sets default orientation of the viewport camera.
\r
1532 void OCCViewer_ViewWindow::onResetView()
\r
1534 emit vpTransformationStarted( RESETVIEW );
\r
1535 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
\r
1536 myViewPort->getView()->Reset( false );
\r
1537 myViewPort->fitAll( false, true, false );
\r
1538 myViewPort->getView()->SetImmediateUpdate( upd );
\r
1539 myViewPort->getView()->Update();
\r
1540 emit vpTransformationFinished( RESETVIEW );
\r
1544 \brief Perform "fit all" transformation.
\r
1546 void OCCViewer_ViewWindow::onFitAll()
\r
1548 emit vpTransformationStarted( FITALLVIEW );
\r
1549 myViewPort->fitAll();
\r
1550 emit vpTransformationFinished( FITALLVIEW );
\r
1554 \brief Called if 'change rotation point' operation is activated.
\r
1555 \param on action state
\r
1557 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
\r
1561 if (!mySetRotationPointDlg)
\r
1563 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
\r
1564 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
\r
1567 if (!mySetRotationPointDlg->isVisible())
\r
1569 //if (mySetRotationPointDlg->IsFirstShown())
\r
1570 if (myCurrPointType == GRAVITY)
\r
1572 Standard_Real Xcenter, Ycenter, Zcenter;
\r
1573 if (computeGravityCenter(Xcenter, Ycenter, Zcenter))
\r
1574 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
\r
1576 mySetRotationPointDlg->show();
\r
1581 if (mySetRotationPointDlg->isVisible())
\r
1582 mySetRotationPointDlg->hide();
\r
1587 \brief Create one more window with same content.
\r
1589 void OCCViewer_ViewWindow::onCloneView()
\r
1591 SUIT_ViewWindow* vw = myManager->createViewWindow();
\r
1593 emit viewCloned( vw );
\r
1597 Creates one more window with same content
\r
1599 void OCCViewer_ViewWindow::onAxialScale()
\r
1601 if ( !myScalingDlg )
\r
1602 myScalingDlg = new OCCViewer_AxialScaleDlg( this );
\r
1604 if ( !myScalingDlg->isVisible() )
\r
1606 myScalingDlg->Update();
\r
1607 myScalingDlg->show();
\r
1612 Shows Graduated Axes dialog
\r
1614 void OCCViewer_ViewWindow::onGraduatedAxes()
\r
1616 myCubeAxesDlg->Update();
\r
1617 myCubeAxesDlg->show();
\r
1620 void OCCViewer_ViewWindow::onAmbientToogle()
\r
1622 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
\r
1623 viewer->InitDefinedLights();
\r
1624 while(viewer->MoreDefinedLights())
\r
1626 Handle(V3d_Light) light = viewer->DefinedLight();
\r
1627 if(light->Type() != V3d_AMBIENT)
\r
1629 Handle(V3d_View) aView3d = myViewPort->getView();
\r
1630 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
\r
1631 else viewer->SetLightOn(light);
\r
1633 viewer->NextDefinedLights();
\r
1639 \brief Store view parameters.
\r
1641 void OCCViewer_ViewWindow::onMemorizeView()
\r
1643 appendViewAspect( getViewParams() );
\r
1647 \brief Restore view parameters.
\r
1649 void OCCViewer_ViewWindow::onRestoreView()
\r
1651 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
\r
1652 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
\r
1654 updateViewAspects( aDlg->parameters() );
\r
1655 if( myRestoreFlag && aDlg->parameters().count() )
\r
1656 performRestoring( aDlg->currentItem() );
\r
1660 \brief Restore view parameters.
\r
1661 \param anItem view parameters
\r
1663 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
\r
1665 Handle(V3d_View) aView3d = myViewPort->getView();
\r
1667 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
\r
1668 aView3d->SetScale( anItem.scale );
\r
1669 aView3d->SetTwist( anItem.twist );
\r
1670 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
\r
1671 aView3d->SetImmediateUpdate( prev );
\r
1672 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
\r
1673 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
\r
1674 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
\r
1676 #if OCC_VERSION_LARGE > 0x06070000
\r
1677 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
\r
1679 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
\r
1681 // "eye" and "at" require conversion to represent center panning
\r
1682 // up direction is only available after setting angle of twist and
\r
1683 // other view parameters
\r
1684 aView3d->Up( anUpX, anUpY, anUpZ );
\r
1686 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
\r
1687 gp_Dir anUp( anUpX, anUpY, anUpZ );
\r
1688 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
\r
1689 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
\r
1690 gp_Dir aSide = aProj ^ anUp;
\r
1692 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
\r
1693 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
\r
1695 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
\r
1696 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
\r
1699 aView3d->SetCenter( anItem.centerX, anItem.centerY );
\r
1702 if ( !baseParamsOnly ) {
\r
1704 myModel->setTrihedronShown( anItem.isVisible );
\r
1705 myModel->setTrihedronSize( anItem.size );
\r
1707 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
\r
1708 // graduated trihedron
\r
1709 bool anIsVisible = anItem.gtIsVisible;
\r
1710 OCCViewer_AxisWidget::AxisData anAxisData[3];
\r
1711 anAxisData[0].DrawName = anItem.gtDrawNameX;
\r
1712 anAxisData[1].DrawName = anItem.gtDrawNameZ;
\r
1713 anAxisData[2].DrawName = anItem.gtDrawNameZ;
\r
1714 anAxisData[0].Name = anItem.gtNameX;
\r
1715 anAxisData[1].Name = anItem.gtNameZ;
\r
1716 anAxisData[2].Name = anItem.gtNameZ;
\r
1717 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
\r
1718 anItem.gtNameColorGX,
\r
1719 anItem.gtNameColorBX );
\r
1720 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
\r
1721 anItem.gtNameColorGY,
\r
1722 anItem.gtNameColorBY );
\r
1723 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
\r
1724 anItem.gtNameColorGZ,
\r
1725 anItem.gtNameColorBZ );
\r
1726 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
\r
1727 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
\r
1728 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
\r
1729 anAxisData[0].NbValues = anItem.gtNbValuesX;
\r
1730 anAxisData[1].NbValues = anItem.gtNbValuesY;
\r
1731 anAxisData[2].NbValues = anItem.gtNbValuesZ;
\r
1732 anAxisData[0].Offset = anItem.gtOffsetX;
\r
1733 anAxisData[1].Offset = anItem.gtOffsetY;
\r
1734 anAxisData[2].Offset = anItem.gtOffsetZ;
\r
1735 anAxisData[0].Color = QColor( anItem.gtColorRX,
\r
1737 anItem.gtColorBX );
\r
1738 anAxisData[1].Color = QColor( anItem.gtColorRY,
\r
1740 anItem.gtColorBY );
\r
1741 anAxisData[2].Color = QColor( anItem.gtColorRZ,
\r
1743 anItem.gtColorBZ );
\r
1744 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
\r
1745 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
\r
1746 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
\r
1747 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
\r
1748 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
\r
1749 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
\r
1751 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
\r
1752 myCubeAxesDlg->ApplyData( aView3d );
\r
1755 } // if ( !baseParamsOnly )
\r
1757 myRestoreFlag = 0;
\r
1761 \brief Set restore flag.
\r
1763 void OCCViewer_ViewWindow::setRestoreFlag()
\r
1765 myRestoreFlag = 1;
\r
1769 \brief Called when action "show/hide trihedron" is activated.
\r
1771 void OCCViewer_ViewWindow::onTrihedronShow()
\r
1773 myModel->toggleTrihedron();
\r
1777 \brief Toggles preselection (highlighting) on/off
\r
1779 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
\r
1781 myPreselectionEnabled = on;
\r
1782 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
\r
1784 // unhighlight all highlighted objects
\r
1786 myModel->unHighlightAll( true, false );
\r
1789 // update action state if method is called outside
\r
1790 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
\r
1791 if ( a && a->isChecked() != on ) {
\r
1792 a->setChecked( on );
\r
1797 \brief Toggles selection on/off
\r
1799 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
\r
1801 mySelectionEnabled = on;
\r
1802 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
\r
1804 // update action state if method is called outside
\r
1807 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
\r
1809 a->setEnabled( on );
\r
1813 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
\r
1814 if ( a && a->isChecked() != on ) {
\r
1815 a->setChecked( on );
\r
1820 \brief Switches "keyboard free" interaction style on/off
\r
1822 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
\r
1824 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
\r
1826 // update action state if method is called outside
\r
1827 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
\r
1828 if ( a->isChecked() != on )
\r
1829 a->setChecked( on );
\r
1833 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
\r
1835 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
\r
1837 myViewPort->setAdvancedZoomingEnabled( on );
\r
1839 // update action state if method is called outside
\r
1840 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
\r
1841 if ( a->isChecked() != on )
\r
1842 a->setChecked( on );
\r
1846 \brief Get current interaction style
\r
1847 \return interaction style
\r
1849 int OCCViewer_ViewWindow::interactionStyle() const
\r
1851 return myInteractionStyle;
\r
1855 \brief Set current interaction style
\r
1856 \param theStyle interaction style
\r
1858 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
\r
1860 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
\r
1864 \brief Get current zooming style
\r
1865 \return zooming style
\r
1867 int OCCViewer_ViewWindow::zoomingStyle() const
\r
1869 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
\r
1873 \brief Set current zooming style
\r
1874 \param theStyle zooming style
\r
1876 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
\r
1878 onSwitchZoomingStyle( theStyle == 1 );
\r
1882 \brief Dump view window contents to the pixmap.
\r
1883 \return pixmap containing all scene rendered in the window
\r
1885 QImage OCCViewer_ViewWindow::dumpView()
\r
1887 Handle(V3d_View) view = myViewPort->getView();
\r
1888 if ( view.IsNull() )
\r
1891 int aWidth = myViewPort->width();
\r
1892 int aHeight = myViewPort->height();
\r
1893 QApplication::syncX();
\r
1894 view->Redraw(); // In order to reactivate GL context
\r
1897 OpenGLUtils_FrameBuffer aFrameBuffer;
\r
1898 if( aFrameBuffer.init( aWidth, aHeight ) )
\r
1900 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
\r
1902 glPushAttrib( GL_VIEWPORT_BIT );
\r
1903 glViewport( 0, 0, aWidth, aHeight );
\r
1904 aFrameBuffer.bind();
\r
1909 aFrameBuffer.unbind();
\r
1912 aFrameBuffer.bind();
\r
1913 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
\r
1914 aFrameBuffer.unbind();
\r
1916 anImage = anImage.rgbSwapped();
\r
1917 anImage = anImage.mirrored();
\r
1920 // if frame buffers are unsupported, use old functionality
\r
1923 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
\r
1925 QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
\r
1927 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
\r
1930 QImage anImage( data, aWidth, aHeight, QImage::Format_ARGB32 );
\r
1931 anImage = anImage.mirrored();
\r
1932 anImage = anImage.rgbSwapped();
\r
1936 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
\r
1937 const QString& fileName,
\r
1938 const QString& format )
\r
1940 if ( format != "PS" && format != "EPS")
\r
1941 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
\r
1943 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
\r
1945 if (format == "PS")
\r
1946 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
\r
1947 else if (format == "EPS")
\r
1948 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
\r
1954 QString OCCViewer_ViewWindow::filter() const
\r
1956 return tr( "OCC_IMAGE_FILES" );
\r
1961 \brief Set parameters of the cutting plane
\r
1962 \param on if \c true, cutting plane is enabled
\r
1963 \param x X position of plane point
\r
1964 \param y Y position of plane point
\r
1965 \param z Z position of plane point
\r
1966 \param dx X coordinate of plane normal
\r
1967 \param dy Y coordinate of plane normal
\r
1968 \param dz Z coordinate of plane normal
\r
1970 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
\r
1971 const double dx, const double dy, const double dz )
\r
1973 Handle(V3d_View) view = myViewPort->getView();
\r
1974 if ( view.IsNull() )
\r
1978 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
\r
1980 // try to use already existing plane or create a new one
\r
1981 Handle(V3d_Plane) clipPlane;
\r
1983 // calculate new a,b,c,d values for the plane
\r
1984 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
\r
1985 double a, b, c, d;
\r
1986 pln.Coefficients(a, b, c, d);
\r
1988 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
\r
1989 Handle(Graphic3d_ClipPlane) aClipPlane;
\r
1990 if(aPlanes.Size() > 0 ) {
\r
1991 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
\r
1992 aClipPlane = anIter.Value();
\r
1993 aClipPlane->SetEquation(pln);
\r
1994 aClipPlane->SetOn(Standard_True);
\r
1996 aClipPlane = new Graphic3d_ClipPlane(pln);
\r
1997 view->AddClipPlane(aClipPlane);
\r
1998 aClipPlane->SetOn(Standard_True);
\r
2002 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
\r
2003 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
\r
2004 for( ;anIter.More();anIter.Next() ){
\r
2005 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
\r
2006 aClipPlane->SetOn(Standard_False);
\r
2014 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
\r
2016 gp_Dir aDir = pln.Axis().Direction();
\r
2017 gp_Pnt aPnt = pln.Location();
\r
2018 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
\r
2023 \brief Check if any cutting plane is enabled
\r
2024 \return \c true if at least one cutting plane is enabled
\r
2026 bool OCCViewer_ViewWindow::isCuttingPlane()
\r
2028 Handle(V3d_View) view = myViewPort->getView();
\r
2030 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
\r
2031 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
\r
2032 for( ;anIter.More();anIter.Next() ) {
\r
2033 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
\r
2034 if(aClipPlane->IsOn()) {
\r
2043 \brief Get the visual parameters of the view window.
\r
2044 \return visual parameters of view window
\r
2046 viewAspect OCCViewer_ViewWindow::getViewParams() const
\r
2048 double projX, projY, projZ, twist;
\r
2049 double atX, atY, atZ, eyeX, eyeY, eyeZ;
\r
2050 double aScaleX, aScaleY, aScaleZ;
\r
2052 Handle(V3d_View) aView3d = myViewPort->getView();
\r
2054 aView3d->Proj( projX, projY, projZ );
\r
2055 aView3d->At( atX, atY, atZ );
\r
2056 aView3d->Eye( eyeX, eyeY, eyeZ );
\r
2057 twist = aView3d->Twist();
\r
2059 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
\r
2061 bool isShown = myModel->isTrihedronVisible();
\r
2062 double size = myModel->trihedronSize();
\r
2064 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
\r
2066 viewAspect params;
\r
2067 params.scale = aView3d->Scale();
\r
2068 params.projX = projX;
\r
2069 params.projY = projY;
\r
2070 params.projZ = projZ;
\r
2071 params.twist = twist;
\r
2075 params.eyeX = eyeX;
\r
2076 params.eyeY = eyeY;
\r
2077 params.eyeZ = eyeZ;
\r
2078 params.scaleX = aScaleX;
\r
2079 params.scaleY = aScaleY;
\r
2080 params.scaleZ = aScaleZ;
\r
2081 params.name = aName;
\r
2082 params.isVisible= isShown;
\r
2083 params.size = size;
\r
2085 #if OCC_VERSION_LARGE <= 0x06070000 // the property is deprecated in OCCT 6.7.1
\r
2086 aView3d->Center( params.centerX, params.centerY );
\r
2089 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
\r
2090 // graduated trihedron
\r
2091 bool anIsVisible = false;
\r
2092 OCCViewer_AxisWidget::AxisData anAxisData[3];
\r
2093 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
\r
2095 params.gtIsVisible = anIsVisible;
\r
2096 params.gtDrawNameX = anAxisData[0].DrawName;
\r
2097 params.gtDrawNameY = anAxisData[1].DrawName;
\r
2098 params.gtDrawNameZ = anAxisData[2].DrawName;
\r
2099 params.gtNameX = anAxisData[0].Name;
\r
2100 params.gtNameY = anAxisData[1].Name;
\r
2101 params.gtNameZ = anAxisData[2].Name;
\r
2102 params.gtNameColorRX = anAxisData[0].NameColor.red();
\r
2103 params.gtNameColorGX = anAxisData[0].NameColor.green();
\r
2104 params.gtNameColorBX = anAxisData[0].NameColor.blue();
\r
2105 params.gtNameColorRY = anAxisData[1].NameColor.red();
\r
2106 params.gtNameColorGY = anAxisData[1].NameColor.green();
\r
2107 params.gtNameColorBY = anAxisData[1].NameColor.blue();
\r
2108 params.gtNameColorRZ = anAxisData[2].NameColor.red();
\r
2109 params.gtNameColorGZ = anAxisData[2].NameColor.green();
\r
2110 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
\r
2111 params.gtDrawValuesX = anAxisData[0].DrawValues;
\r
2112 params.gtDrawValuesY = anAxisData[1].DrawValues;
\r
2113 params.gtDrawValuesZ = anAxisData[2].DrawValues;
\r
2114 params.gtNbValuesX = anAxisData[0].NbValues;
\r
2115 params.gtNbValuesY = anAxisData[1].NbValues;
\r
2116 params.gtNbValuesZ = anAxisData[2].NbValues;
\r
2117 params.gtOffsetX = anAxisData[0].Offset;
\r
2118 params.gtOffsetY = anAxisData[1].Offset;
\r
2119 params.gtOffsetZ = anAxisData[2].Offset;
\r
2120 params.gtColorRX = anAxisData[0].Color.red();
\r
2121 params.gtColorGX = anAxisData[0].Color.green();
\r
2122 params.gtColorBX = anAxisData[0].Color.blue();
\r
2123 params.gtColorRY = anAxisData[1].Color.red();
\r
2124 params.gtColorGY = anAxisData[1].Color.green();
\r
2125 params.gtColorBY = anAxisData[1].Color.blue();
\r
2126 params.gtColorRZ = anAxisData[2].Color.red();
\r
2127 params.gtColorGZ = anAxisData[2].Color.green();
\r
2128 params.gtColorBZ = anAxisData[2].Color.blue();
\r
2129 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
\r
2130 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
\r
2131 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
\r
2132 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
\r
2133 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
\r
2134 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
\r
2141 \brief Get visual parameters of this view window.
\r
2142 \return visual parameters of view window
\r
2144 QString OCCViewer_ViewWindow::getVisualParameters()
\r
2146 viewAspect params = getViewParams();
\r
2150 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
\r
2151 #if OCC_VERSION_LARGE <= 0x06070000 // the property is deprecated in OCCT 6.7.1
\r
2152 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
\r
2153 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
\r
2155 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
\r
2156 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
\r
2157 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
\r
2158 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
\r
2159 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
\r
2160 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
\r
2161 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
\r
2162 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
\r
2163 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
\r
2164 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
\r
2165 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
\r
2166 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
\r
2167 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
\r
2168 data << QString( "isVisible=%1" ).arg( params.isVisible );
\r
2169 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
\r
2171 ClipPlanesList aPlanes = myModel->getClipPlanes();
\r
2172 for ( int i=0; i < aPlanes.size(); i++ )
\r
2174 OCCViewer_ClipPlane& aPlane = aPlanes[i];
\r
2175 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
\r
2176 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
\r
2177 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
\r
2178 switch ( aPlane.Mode )
\r
2180 case OCCViewer_ClipPlane::Absolute :
\r
2182 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
\r
2184 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
\r
2186 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
\r
2187 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
\r
2188 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
\r
2192 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
\r
2197 case OCCViewer_ClipPlane::Relative :
\r
2199 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
\r
2200 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
\r
2201 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
\r
2206 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
\r
2207 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
\r
2208 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
\r
2209 data << ClippingPlane;
\r
2213 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 or newer version
\r
2214 // graduated trihedron
\r
2215 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
\r
2216 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
\r
2217 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
\r
2218 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
\r
2219 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
\r
2220 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
\r
2221 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
\r
2222 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
\r
2223 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
\r
2224 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
\r
2225 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
\r
2226 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
\r
2227 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
\r
2228 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
\r
2229 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
\r
2230 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
\r
2231 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
\r
2232 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
\r
2233 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
\r
2234 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
\r
2235 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
\r
2236 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
\r
2237 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
\r
2238 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
\r
2239 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
\r
2240 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
\r
2241 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
\r
2242 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
\r
2243 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
\r
2244 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
\r
2245 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
\r
2246 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
\r
2247 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
\r
2248 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
\r
2249 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
\r
2250 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
\r
2251 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
\r
2252 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
\r
2253 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
\r
2254 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
\r
2256 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
\r
2257 data << QString( "background=%1" ).arg( bg );
\r
2259 return data.join("*");
\r
2263 \brief Restore visual parameters of the view window.
\r
2264 \param parameters visual parameters of view window
\r
2266 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
\r
2268 viewAspect params;
\r
2269 ClipPlanesList aClipPlanes;
\r
2270 QStringList data = parameters.split( '*' );
\r
2271 Qtx::BackgroundData bgData;
\r
2272 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
\r
2274 foreach( QString param, data ) {
\r
2275 QString paramName = param.section( '=', 0, 0 ).trimmed();
\r
2276 QString paramValue = param.section( '=', 1, 1 ).trimmed();
\r
2277 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
\r
2278 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
\r
2279 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
\r
2280 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
\r
2281 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
\r
2282 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
\r
2283 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
\r
2284 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
\r
2285 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
\r
2286 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
\r
2287 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
\r
2288 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
\r
2289 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
\r
2290 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
\r
2291 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
\r
2292 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
\r
2293 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
\r
2294 else if ( paramName == "size" ) params.size = paramValue.toDouble();
\r
2295 else if ( paramName.contains( "ClippingPlane" ) )
\r
2297 QStringList ClipPlaneData = paramValue.split( ';' );
\r
2298 OCCViewer_ClipPlane aPlane;
\r
2299 foreach( QString ClipPlaneParam, ClipPlaneData )
\r
2301 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
\r
2302 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
\r
2303 if ( ClipPlane_paramName == "Mode" )
\r
2305 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
\r
2307 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
\r
2308 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
\r
2309 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
\r
2310 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
\r
2313 switch ( aPlane.Mode )
\r
2315 case OCCViewer_ClipPlane::Absolute :
\r
2316 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
\r
2317 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
\r
2318 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
\r
2319 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
\r
2320 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
\r
2323 case OCCViewer_ClipPlane::Relative :
\r
2324 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
\r
2325 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
\r
2326 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
\r
2331 aClipPlanes.push_back(aPlane);
\r
2333 // graduated trihedron
\r
2334 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
\r
2335 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
\r
2336 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
\r
2337 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
\r
2338 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
\r
2339 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
\r
2340 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
\r
2341 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
\r
2342 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
\r
2343 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
\r
2344 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
\r
2345 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
\r
2346 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
\r
2347 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
\r
2348 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
\r
2349 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
\r
2350 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
\r
2351 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
\r
2352 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
\r
2353 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
\r
2354 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
\r
2355 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
\r
2356 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
\r
2357 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
\r
2358 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
\r
2359 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
\r
2360 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
\r
2361 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
\r
2362 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
\r
2363 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
\r
2364 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
\r
2365 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
\r
2366 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
\r
2367 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
\r
2368 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
\r
2369 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
\r
2370 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
\r
2371 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
\r
2372 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
\r
2373 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
\r
2374 else if ( paramName == "background" ) {
\r
2375 QString bg = paramValue.replace( "$", "=" );
\r
2376 bgData = Qtx::stringToBackground( bg );
\r
2380 else // old format - "1.000e+00*0.000e+00..."
\r
2383 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
\r
2384 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
\r
2385 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
\r
2386 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
\r
2387 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
\r
2388 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
\r
2389 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
\r
2390 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
\r
2391 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
\r
2392 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
\r
2393 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
\r
2394 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
\r
2395 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
\r
2396 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
\r
2397 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
\r
2398 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
\r
2399 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
\r
2400 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
\r
2402 performRestoring( params );
\r
2403 setBackground( bgData );
\r
2404 myModel->setClipPlanes(aClipPlanes);
\r
2408 \brief Handle show event.
\r
2410 Emits Show() signal.
\r
2412 \param theEvent show event
\r
2414 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
\r
2416 emit Show( theEvent );
\r
2420 \brief Handle hide event.
\r
2422 Emits Hide() signal.
\r
2424 \param theEvent hide event
\r
2426 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
\r
2428 emit Hide( theEvent );
\r
2433 Creates default sketcher. [ virtual protected ]
\r
2435 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
\r
2437 if ( type == Rect )
\r
2438 return new OCCViewer_RectSketcher( this, type );
\r
2439 if ( type == Polygon )
\r
2440 return new OCCViewer_PolygonSketcher( this, type );
\r
2444 void OCCViewer_ViewWindow::initSketchers()
\r
2446 if ( mySketchers.isEmpty() )
\r
2448 mySketchers.append( createSketcher( Rect ) );
\r
2449 mySketchers.append( createSketcher( Polygon ) );
\r
2453 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
\r
2455 OCCViewer_ViewSketcher* sketcher = 0;
\r
2456 QList<OCCViewer_ViewSketcher*>::Iterator it;
\r
2457 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
\r
2459 OCCViewer_ViewSketcher* sk = (*it);
\r
2460 if ( sk->type() == typ )
\r
2467 Handles requests for sketching in the active view. [ virtual public ]
\r
2469 void OCCViewer_ViewWindow::activateSketching( int type )
\r
2471 OCCViewer_ViewPort3d* vp = getViewPort();
\r
2475 if ( !vp->isSketchingEnabled() )
\r
2478 /* Finish current sketching */
\r
2479 if ( type == NoSketching )
\r
2481 if ( mypSketcher )
\r
2483 onSketchingFinished();
\r
2484 mypSketcher->deactivate();
\r
2488 /* Activate new sketching */
\r
2491 activateSketching( NoSketching ); /* concurrency not suported */
\r
2492 mypSketcher = getSketcher( type );
\r
2493 if ( mypSketcher )
\r
2495 mypSketcher->activate();
\r
2496 onSketchingStarted();
\r
2502 Unhilights detected entities. [ virtual protected ]
\r
2504 void OCCViewer_ViewWindow::onSketchingStarted()
\r
2509 Selection by rectangle or polygon. [ virtual protected ]
\r
2511 void OCCViewer_ViewWindow::onSketchingFinished()
\r
2513 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
\r
2514 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
\r
2516 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
\r
2517 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
\r
2518 switch( mypSketcher->type() )
\r
2522 QRect* aRect = (QRect*)mypSketcher->data();
\r
2525 int aLeft = aRect->left();
\r
2526 int aRight = aRect->right();
\r
2527 int aTop = aRect->top();
\r
2528 int aBottom = aRect->bottom();
\r
2529 // myRect = aRect;
\r
2532 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
\r
2534 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
\r
2540 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
\r
2543 int size = aPolygon->size();
\r
2544 TColgp_Array1OfPnt2d anArray( 1, size );
\r
2546 QPolygon::Iterator it = aPolygon->begin();
\r
2547 QPolygon::Iterator itEnd = aPolygon->end();
\r
2548 for( int index = 1; it != itEnd; ++it, index++ )
\r
2550 QPoint aPoint = *it;
\r
2551 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
\r
2555 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
\r
2557 ic->Select( anArray, getViewPort()->getView(), Standard_False );
\r
2565 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
\r
2566 aViewMgr->getOCCViewer()->performSelectionChanged();
\r
2570 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
\r
2572 return myViewPort;
\r
2575 bool OCCViewer_ViewWindow::transformRequested() const
\r
2577 return ( myOperation != NOTHING );
\r
2580 bool OCCViewer_ViewWindow::transformInProcess() const
\r
2582 return myEventStarted;
\r
2585 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
\r
2587 myEventStarted = bOn;
\r
2591 Set enabled state of transformation (rotate, zoom, etc)
\r
2593 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
\r
2595 if ( id != NOTHING ) myStatus.insert( id, on );
\r
2599 \return enabled state of transformation (rotate, zoom, etc)
\r
2601 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
\r
2603 return myStatus.contains( id ) ? myStatus[ id ] : true;
\r
2606 void OCCViewer_ViewWindow::onMaximizedView()
\r
2608 setMaximized(!isMaximized());
\r
2611 void OCCViewer_ViewWindow::returnTo3dView()
\r
2613 setReturnedTo3dView( true );
\r
2616 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
\r
2618 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
\r
2619 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
\r
2620 if ( !isVisible3dView )
\r
2621 toolMgr()->show( ReturnTo3dViewId );
\r
2623 toolMgr()->hide( ReturnTo3dViewId );
\r
2624 if ( isVisible3dView ) emit returnedTo3d( );
\r
2628 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
\r
2630 QAction* anAction = toolMgr()->action( MaximizedId );
\r
2631 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
\r
2632 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
\r
2633 if ( toMaximize ) {
\r
2634 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
\r
2635 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
\r
2636 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
\r
2637 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
\r
2638 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
\r
2639 if (toSendSignal) {
\r
2640 emit maximized( this, true );
\r
2644 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
\r
2645 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
\r
2646 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
\r
2647 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
\r
2648 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
\r
2649 if (toSendSignal) {
\r
2650 emit maximized( this, false );
\r
2655 bool OCCViewer_ViewWindow::isMaximized() const
\r
2657 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
\r
2660 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
\r
2662 IsSketcherStyle = enable;
\r
2665 bool OCCViewer_ViewWindow::isSketcherStyle() const
\r
2667 return IsSketcherStyle;
\r
2671 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
\r
2673 my2dMode = theType;
\r
2677 QColor OCCViewer_ViewWindow::backgroundColor() const
\r
2679 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
\r
2683 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
\r
2685 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
\r
2688 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
\r
2690 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
\r
2693 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
\r
2695 if ( myViewPort ) myViewPort->setBackground( theBackground );
\r
2699 Clears view aspects
\r
2701 void OCCViewer_ViewWindow::clearViewAspects()
\r
2703 myViewAspects.clear();
\r
2707 \return const reference to list of view aspects
\r
2709 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
\r
2711 return myViewAspects;
\r
2715 Appends new view aspect
\r
2716 \param aParams - new view aspects
\r
2718 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
\r
2720 myViewAspects.append( aParams );
\r
2724 Replaces old view aspects by new ones
\r
2725 \param aViewList - list of new view aspects
\r
2727 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
\r
2729 myViewAspects = aViewList;
\r
2733 Get camera properties for the OCC view window.
\r
2734 \return shared pointer on camera properties.
\r
2736 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
\r
2738 SUIT_CameraProperties aProps;
\r
2740 Handle(V3d_View) aSourceView = getViewPort()->getView();
\r
2741 if ( aSourceView.IsNull() )
\r
2744 if ( get2dMode() == No2dMode ) {
\r
2745 aProps.setDimension( SUIT_CameraProperties::Dim3D );
\r
2748 aProps.setDimension( SUIT_CameraProperties::Dim2D );
\r
2749 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
\r
2752 // read common properites of the view
\r
2753 Standard_Real anUp[3];
\r
2754 Standard_Real anAt[3];
\r
2755 Standard_Real anEye[3];
\r
2756 Standard_Real aProj[3];
\r
2757 Standard_Real anAxialScale[3];
\r
2759 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
\r
2760 aSourceView->At( anAt[0], anAt[1], anAt[2] );
\r
2761 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
\r
2762 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
\r
2764 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
\r
2765 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
\r
2767 #if OCC_VERSION_LARGE > 0x06070000
\r
2768 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
\r
2770 // store camera properties "as is": it is up to synchronized
\r
2771 // view classes to provide necessary property conversion.
\r
2772 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
\r
2773 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
\r
2775 if ( aSourceView->Camera()->IsOrthographic() )
\r
2777 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
\r
2778 aProps.setViewAngle( 0.0 );
\r
2782 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
\r
2783 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
\r
2785 aProps.setMappingScale( aSourceView->Camera()->Scale() );
\r
2787 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
\r
2789 // generate view orientation matrix for transforming OCC projection reference point
\r
2790 // into a camera (eye) position.
\r
2791 gp_Dir aLeftDir = gp_Dir( anUp[0], anUp[1], anUp[2] ) ^ gp_Dir( aProj[0], aProj[1], aProj[2] );
\r
2794 aTrsf.SetValue( 1, 1, aLeftDir.X() );
\r
2795 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
\r
2796 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
\r
2798 aTrsf.SetValue( 1, 2, anUp[0] );
\r
2799 aTrsf.SetValue( 2, 2, anUp[1] );
\r
2800 aTrsf.SetValue( 3, 2, anUp[2] );
\r
2802 aTrsf.SetValue( 1, 3, aProj[0] );
\r
2803 aTrsf.SetValue( 2, 3, aProj[1] );
\r
2804 aTrsf.SetValue( 3, 3, aProj[2] );
\r
2806 aTrsf.SetValue( 1, 4, anAt[0] );
\r
2807 aTrsf.SetValue( 2, 4, anAt[1] );
\r
2808 aTrsf.SetValue( 3, 4, anAt[2] );
\r
2810 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
\r
2812 // transform to world-space coordinate system
\r
2813 gp_XYZ aPosition( aProjRef.X(), aProjRef.Y(), aCameraDepth );
\r
2814 aTrsf.Transforms( aPosition );
\r
2816 // compute focal point
\r
2817 double aFocalPoint[3];
\r
2819 aFocalPoint[0] = aPosition.X() - aProj[0] * aCameraDepth;
\r
2820 aFocalPoint[1] = aPosition.Y() - aProj[1] * aCameraDepth;
\r
2821 aFocalPoint[2] = aPosition.Z() - aProj[2] * aCameraDepth;
\r
2823 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
\r
2824 aProps.setPosition( aPosition.X(), aPosition.Y(), aPosition.Z() );
\r
2826 Standard_Real aViewScale[2];
\r
2827 aSourceView->Size( aViewScale[0], aViewScale[1] );
\r
2828 aProps.setMappingScale( aViewScale[1] );
\r
2835 Synchronize views.
\r
2836 This implementation synchronizes OCC view's camera propreties.
\r
2838 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
\r
2840 bool blocked = blockSignals( true );
\r
2842 SUIT_CameraProperties aProps = theView->cameraProperties();
\r
2843 if ( !cameraProperties().isCompatible( aProps ) ) {
\r
2844 // other view, this one is being currently synchronized to, seems has become incompatible
\r
2845 // we have to break synchronization
\r
2846 updateSyncViews();
\r
2850 Handle(V3d_View) aDestView = getViewPort()->getView();
\r
2852 aDestView->SetImmediateUpdate( Standard_False );
\r
2854 double anUpDir[3];
\r
2855 double aPosition[3];
\r
2856 double aFocalPoint[3];
\r
2857 double anAxialScale[3];
\r
2859 // get common properties
\r
2860 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
\r
2861 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
\r
2862 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
\r
2863 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
\r
2865 #if OCC_VERSION_LARGE > 0x06070000
\r
2866 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
\r
2867 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
\r
2868 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
\r
2869 aDestView->Camera()->SetScale( aProps.getMappingScale() );
\r
2871 gp_Dir aProjDir( aPosition[0] - aFocalPoint[0],
\r
2872 aPosition[1] - aFocalPoint[1],
\r
2873 aPosition[2] - aFocalPoint[2] );
\r
2875 // get custom view translation
\r
2876 Standard_Real aTranslation[3];
\r
2877 aDestView->At( aTranslation[0], aTranslation[1], aTranslation[2] );
\r
2879 gp_Dir aLeftDir = gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] )
\r
2880 ^ gp_Dir( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
\r
2883 aTrsf.SetValue( 1, 1, aLeftDir.X() );
\r
2884 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
\r
2885 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
\r
2887 aTrsf.SetValue( 1, 2, anUpDir[0] );
\r
2888 aTrsf.SetValue( 2, 2, anUpDir[1] );
\r
2889 aTrsf.SetValue( 3, 2, anUpDir[2] );
\r
2891 aTrsf.SetValue( 1, 3, aProjDir.X() );
\r
2892 aTrsf.SetValue( 2, 3, aProjDir.Y() );
\r
2893 aTrsf.SetValue( 3, 3, aProjDir.Z() );
\r
2895 aTrsf.SetValue( 1, 4, aTranslation[0] );
\r
2896 aTrsf.SetValue( 2, 4, aTranslation[1] );
\r
2897 aTrsf.SetValue( 3, 4, aTranslation[2] );
\r
2900 // transform to view-space coordinate system
\r
2901 gp_XYZ aProjRef( aPosition[0], aPosition[1], aPosition[2] );
\r
2902 aTrsf.Transforms( aProjRef );
\r
2904 // set view camera properties using low-level approach. this is done
\r
2905 // in order to avoid interference with static variables in v3d view used
\r
2906 // when rotation is in process in another view.
\r
2907 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
\r
2908 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
\r
2910 Graphic3d_Vector aMappingProj( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
\r
2911 Graphic3d_Vector aMappingUp( anUpDir[0], anUpDir[1], anUpDir[2] );
\r
2913 aMappingProj.Normalize();
\r
2914 aMappingUp.Normalize();
\r
2916 anOrientation.SetViewReferencePlane( aMappingProj );
\r
2917 anOrientation.SetViewReferenceUp( aMappingUp );
\r
2919 aDestView->SetViewMapping( aMapping );
\r
2920 aDestView->SetViewOrientation( anOrientation );
\r
2923 aDestView->SetCenter( aProjRef.X(), aProjRef.Y() );
\r
2925 // set mapping scale
\r
2926 double aMapScaling = aProps.getMappingScale();
\r
2927 Standard_Real aWidth, aHeight;
\r
2928 aDestView->Size( aWidth, aHeight );
\r
2929 aDestView->SetSize ( aWidth > aHeight ? aMapScaling * (aWidth / aHeight) : aMapScaling );
\r
2932 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
\r
2934 aDestView->ZFitAll();
\r
2935 aDestView->SetImmediateUpdate( Standard_True );
\r
2936 aDestView->Redraw();
\r
2938 blockSignals( blocked );
\r
2942 \brief Indicates whether preselection is enabled
\r
2943 \return true if preselection is enabled
\r
2945 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
\r
2947 return myPreselectionEnabled;
\r
2951 \brief Enables/disables preselection
\r
2952 \param theIsToEnable if true - preselection will be enabled
\r
2954 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
\r
2956 onSwitchPreselection( theIsToEnable );
\r
2960 \brief Indicates whether selection is enabled
\r
2961 \return true if selection is enabled
\r
2963 bool OCCViewer_ViewWindow::isSelectionEnabled() const
\r
2965 return mySelectionEnabled;
\r
2969 \brief Enables/disables selection
\r
2970 \param theIsToEnable if true - selection will be enabled
\r
2972 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
\r
2974 onSwitchSelection( theIsToEnable );
\r
2979 \brief called if clipping operation is activated / deactivated.
\r
2981 Enables/disables clipping plane displaying.
\r
2983 \parma on action state
\r
2985 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
\r
2987 if(!myModel) return;
\r
2988 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
\r
2991 if (!aClippingDlg) {
\r
2992 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
\r
2993 myModel->setClippingDlg(aClippingDlg);
\r
2995 if (!aClippingDlg->isVisible())
\r
2996 aClippingDlg->show();
\r
2998 if ( aClippingDlg ) {
\r
2999 aClippingDlg->close();
\r
3000 myModel->setClippingDlg(0);
\r
3004 SUIT_ViewManager* mgr = getViewManager();
\r
3006 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
\r
3007 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
\r
3008 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
\r
3009 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
\r
3010 if(!mgr) continue;
\r
3011 QAction* a = toolMgr()->action( ClippingId );
\r
3013 if(theIsOn != a->isChecked()){
\r
3014 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
\r
3015 a->setChecked(theIsOn);
\r
3016 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
\r