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 <BRepGProp.hxx>
\r
69 #include <GProp_GProps.hxx>
\r
70 #include <TopoDS.hxx>
\r
72 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
\r
73 #include <Graphic3d_MapOfStructure.hxx>
\r
74 #include <Graphic3d_Structure.hxx>
\r
75 #include <Graphic3d_ExportFormat.hxx>
\r
77 #include <Visual3d_View.hxx>
\r
78 #include <V3d_Plane.hxx>
\r
79 #include <V3d_Light.hxx>
\r
81 #include <gp_Dir.hxx>
\r
82 #include <gp_Pln.hxx>
\r
83 #include <gp_GTrsf.hxx>
\r
84 #include <TColgp_Array1OfPnt2d.hxx>
\r
86 #if OCC_VERSION_LARGE > 0x06060000
\r
87 #include <Graphic3d_SequenceOfHClipPlane.hxx>
\r
88 #include <Graphic3d_ClipPlane.hxx>
\r
92 #include <Standard_Version.hxx>
\r
94 #include "utilities.h"
\r
96 // // OpenCV includes
\r
98 // #include <highgui.h>
\r
100 static QEvent* l_mbPressEvent = 0;
\r
103 # include <QWindowsStyle>
\r
108 const char* imageZoomCursor[] = {
\r
113 "................................",
\r
114 "................................",
\r
115 ".#######........................",
\r
116 "..aaaaaaa.......................",
\r
117 "................................",
\r
118 ".............#####..............",
\r
119 "...........##.aaaa##............",
\r
120 "..........#.aa.....a#...........",
\r
121 ".........#.a.........#..........",
\r
122 ".........#a..........#a.........",
\r
123 "........#.a...........#.........",
\r
124 "........#a............#a........",
\r
125 "........#a............#a........",
\r
126 "........#a............#a........",
\r
127 "........#a............#a........",
\r
128 ".........#...........#.a........",
\r
129 ".........#a..........#a.........",
\r
130 ".........##.........#.a.........",
\r
131 "........#####.....##.a..........",
\r
132 ".......###aaa#####.aa...........",
\r
133 "......###aa...aaaaa.......#.....",
\r
134 ".....###aa................#a....",
\r
135 "....###aa.................#a....",
\r
136 "...###aa...............#######..",
\r
137 "....#aa.................aa#aaaa.",
\r
138 ".....a....................#a....",
\r
139 "..........................#a....",
\r
140 "...........................a....",
\r
141 "................................",
\r
142 "................................",
\r
143 "................................",
\r
144 "................................"};
\r
146 const char* imageRotateCursor[] = {
\r
151 "................................",
\r
152 "................................",
\r
153 "................................",
\r
154 "................................",
\r
155 "........#.......................",
\r
156 ".......#.a......................",
\r
157 "......#######...................",
\r
158 ".......#aaaaa#####..............",
\r
159 "........#..##.a#aa##........##..",
\r
160 ".........a#.aa..#..a#.....##.aa.",
\r
161 ".........#.a.....#...#..##.aa...",
\r
162 ".........#a.......#..###.aa.....",
\r
163 "........#.a.......#a..#aa.......",
\r
164 "........#a.........#..#a........",
\r
165 "........#a.........#a.#a........",
\r
166 "........#a.........#a.#a........",
\r
167 "........#a.........#a.#a........",
\r
168 ".........#.........#a#.a........",
\r
169 "........##a........#a#a.........",
\r
170 "......##.a#.......#.#.a.........",
\r
171 "....##.aa..##.....##.a..........",
\r
172 "..##.aa.....a#####.aa...........",
\r
173 "...aa.........aaa#a.............",
\r
174 "................#.a.............",
\r
175 "...............#.a..............",
\r
176 "..............#.a...............",
\r
177 "...............a................",
\r
178 "................................",
\r
179 "................................",
\r
180 "................................",
\r
181 "................................",
\r
182 "................................"};
\r
184 const char* imageCrossCursor[] = {
\r
189 "................................",
\r
190 "................................",
\r
191 "................................",
\r
192 "................................",
\r
193 "................................",
\r
194 "................................",
\r
195 "................................",
\r
196 "...............#................",
\r
197 "...............#a...............",
\r
198 "...............#a...............",
\r
199 "...............#a...............",
\r
200 "...............#a...............",
\r
201 "...............#a...............",
\r
202 "...............#a...............",
\r
203 "...............#a...............",
\r
204 ".......#################........",
\r
205 "........aaaaaaa#aaaaaaaaa.......",
\r
206 "...............#a...............",
\r
207 "...............#a...............",
\r
208 "...............#a...............",
\r
209 "...............#a...............",
\r
210 "...............#a...............",
\r
211 "...............#a...............",
\r
212 "...............#a...............",
\r
213 "................a...............",
\r
214 "................................",
\r
215 "................................",
\r
216 "................................",
\r
217 "................................",
\r
218 "................................",
\r
219 "................................",
\r
220 "................................"};
\r
225 \param theDesktop main window of application
\r
226 \param theModel OCC 3D viewer
\r
228 OCCViewer_ViewWindow::OCCViewer_ViewWindow( SUIT_Desktop* theDesktop,
\r
229 OCCViewer_Viewer* theModel )
\r
230 : SUIT_ViewWindow( theDesktop )
\r
232 myModel = theModel;
\r
234 myEnableDrawMode = false;
\r
236 updateEnabledDrawMode();
\r
238 mySetRotationPointDlg = 0;
\r
241 IsSketcherStyle = false;
\r
242 myIsKeyFree = false;
\r
246 my2dMode = No2dMode;
\r
248 myInteractionStyle = SUIT_ViewModel::STANDARD;
\r
249 myPreselectionEnabled = true;
\r
250 mySelectionEnabled = true;
\r
253 clearViewAspects();
\r
260 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
\r
263 qDeleteAll( mySketchers );
\r
267 \brief Internal initialization.
\r
269 void OCCViewer_ViewWindow::initLayout()
\r
271 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
\r
272 myViewPort->installEventFilter(this);
\r
273 setCentralWidget(myViewPort);
\r
274 myOperation = NOTHING;
\r
276 myCurrPointType = GRAVITY;
\r
277 myPrevPointType = GRAVITY;
\r
278 mySelectedPoint = gp_Pnt(0.,0.,0.);
\r
279 myRotationPointSelection = false;
\r
281 setTransformRequested ( NOTHING );
\r
282 setTransformInProcess ( false );
\r
287 switch (my2dMode) {
\r
299 // Graduated axes dialog
\r
300 QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
\r
301 myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
\r
302 myCubeAxesDlg->initialize();
\r
304 connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
\r
307 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
\r
309 return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
\r
313 \brief Detect viewer operation according the the mouse button pressed
\r
314 and key modifiers used.
\r
315 \param theEvent mouse event
\r
316 \return type of the operation
\r
318 OCCViewer_ViewWindow::OperationType
\r
319 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
\r
321 OperationType aOp = NOTHING;
\r
322 SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
\r
323 if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
\r
324 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
\r
326 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
\r
327 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
\r
329 else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
\r
330 (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
\r
331 (my2dMode == No2dMode))
\r
338 \brief Customize event handling
\r
339 \param watched event receiver object
\r
341 \return \c true if the event processing should be stopped
\r
343 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
\r
345 if ( watched == myViewPort ) {
\r
346 int aType = e->type();
\r
348 case QEvent::MouseButtonPress:
\r
349 vpMousePressEvent((QMouseEvent*) e);
\r
352 case QEvent::MouseButtonRelease:
\r
353 vpMouseReleaseEvent((QMouseEvent*) e);
\r
356 case QEvent::MouseMove:
\r
357 vpMouseMoveEvent((QMouseEvent*) e);
\r
360 case QEvent::MouseButtonDblClick:
\r
361 emit mouseDoubleClicked(this, (QMouseEvent*)e);
\r
364 case QEvent::Wheel:
\r
366 QWheelEvent* aEvent = (QWheelEvent*) e;
\r
367 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
\r
368 double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
\r
369 int x = aEvent->x();
\r
370 int y = aEvent->y();
\r
371 int x1 = (int)( aEvent->x() + width()*delta/100 );
\r
372 int y1 = (int)( aEvent->y() + height()*delta/100 );
\r
373 myViewPort->zoom( x, y, x1, y1 );
\r
377 case QEvent::ContextMenu:
\r
379 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
\r
380 if ( aEvent->reason() != QContextMenuEvent::Mouse )
\r
381 emit contextMenuRequested( aEvent );
\r
385 case QEvent::KeyPress:
\r
386 emit keyPressed(this, (QKeyEvent*) e);
\r
393 return SUIT_ViewWindow::eventFilter(watched, e);
\r
397 \brief Update state of enable draw mode state.
\r
399 void OCCViewer_ViewWindow::updateEnabledDrawMode()
\r
402 myEnableDrawMode = myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
\r
406 \brief Handle mouse press event
\r
407 \param theEvent mouse event
\r
409 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
\r
411 myStartX = theEvent->x();
\r
412 myStartY = theEvent->y();
\r
413 int anInteractionStyle = interactionStyle();
\r
415 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
\r
416 // which are assigned for pan and rotate - these operations are activated immediately after pressing
\r
417 // of the first button, so it is necessary to switch to zoom when the second button is pressed
\r
418 bool aSwitchToZoom = false;
\r
419 if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
\r
420 ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
\r
421 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
\r
424 switch ( myOperation ) {
\r
426 if ( theEvent->button() == Qt::LeftButton )
\r
427 emit vpTransformationStarted ( WINDOWFIT );
\r
431 if ( theEvent->button() == Qt::LeftButton )
\r
432 emit vpTransformationStarted ( PANGLOBAL );
\r
436 if ( theEvent->button() == Qt::LeftButton ) {
\r
437 myViewPort->startZoomAtPoint( myStartX, myStartY );
\r
438 emit vpTransformationStarted ( ZOOMVIEW );
\r
443 if ( aSwitchToZoom ) {
\r
444 myViewPort->startZoomAtPoint( myStartX, myStartY );
\r
447 else if ( theEvent->button() == Qt::LeftButton )
\r
448 emit vpTransformationStarted ( PANVIEW );
\r
452 if ( aSwitchToZoom ) {
\r
453 myViewPort->startZoomAtPoint( myStartX, myStartY );
\r
456 else if ( theEvent->button() == Qt::LeftButton ) {
\r
457 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
\r
458 emit vpTransformationStarted ( ROTATE );
\r
463 /* Try to activate a transformation */
\r
464 OperationType aState;
\r
465 if ( interactionStyle() == SUIT_ViewModel::STANDARD )
\r
466 aState = getButtonState(theEvent, anInteractionStyle);
\r
468 aState = OCCViewer_ViewWindow::NOTHING;
\r
469 myIsKeyFree = true;
\r
471 switch ( aState ) {
\r
473 myViewPort->startZoomAtPoint( myStartX, myStartY );
\r
480 activateRotation();
\r
481 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
\r
484 if ( myRotationPointSelection )
\r
486 if ( theEvent->button() == Qt::LeftButton )
\r
488 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
\r
490 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
\r
492 TopoDS_Shape aShape = ic->SelectedShape();
\r
493 GProp_GProps aSystem;
\r
495 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
\r
497 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
\r
499 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE )
\r
501 BRepGProp::LinearProperties( aShape, aSystem );
\r
502 aPnt = aSystem.CentreOfMass();
\r
504 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE )
\r
506 BRepGProp::SurfaceProperties( aShape, aSystem );
\r
507 aPnt = aSystem.CentreOfMass();
\r
509 else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID )
\r
511 BRepGProp::VolumeProperties( aShape, aSystem );
\r
512 aPnt = aSystem.CentreOfMass();
\r
516 myCurrPointType = myPrevPointType;
\r
520 if ( mySetRotationPointDlg )
\r
522 myRotationPointSelection = false;
\r
523 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
\r
526 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
\r
527 if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
\r
528 ic->CloseAllContexts();
\r
529 myOperation = NOTHING;
\r
530 myViewPort->setCursor( myCursor );
\r
531 myCursorIsHand = false;
\r
532 myRotationPointSelection = false;
\r
536 emit mousePressed(this, theEvent);
\r
539 /* notify that we start a transformation */
\r
540 if ( transformRequested() )
\r
541 emit vpTransformationStarted ( myOperation );
\r
543 if ( transformRequested() )
\r
544 setTransformInProcess( true );
\r
546 /* we may need it for sketching... */
\r
547 if ( l_mbPressEvent )
\r
548 delete l_mbPressEvent;
\r
549 l_mbPressEvent = new QMouseEvent( *theEvent );
\r
554 \brief Start zooming operation.
\r
556 Sets the corresponding cursor for the widget.
\r
558 void OCCViewer_ViewWindow::activateZoom()
\r
560 if ( !transformRequested() && !myCursorIsHand )
\r
561 myCursor = cursor(); /* save old cursor */
\r
563 if ( myOperation != ZOOMVIEW ) {
\r
564 QPixmap zoomPixmap (imageZoomCursor);
\r
565 QCursor zoomCursor (zoomPixmap);
\r
566 if( setTransformRequested ( ZOOMVIEW ) )
\r
567 myViewPort->setCursor( zoomCursor );
\r
573 \brief Start panning operation.
\r
575 Sets the corresponding cursor for the widget.
\r
577 void OCCViewer_ViewWindow::activatePanning()
\r
579 if ( !transformRequested() && !myCursorIsHand )
\r
580 myCursor = cursor(); // save old cursor
\r
582 if ( myOperation != PANVIEW ) {
\r
583 QCursor panCursor (Qt::SizeAllCursor);
\r
584 if( setTransformRequested ( PANVIEW ) )
\r
585 myViewPort->setCursor( panCursor );
\r
590 \brief Start rotation operation
\r
592 Sets the corresponding cursor for the widget.
\r
594 void OCCViewer_ViewWindow::activateRotation()
\r
596 if ( !transformRequested() && !myCursorIsHand )
\r
597 myCursor = cursor(); // save old cursor
\r
599 if ( myOperation != ROTATE ) {
\r
600 QPixmap rotatePixmap (imageRotateCursor);
\r
601 QCursor rotCursor (rotatePixmap);
\r
602 if( setTransformRequested ( ROTATE ) )
\r
603 myViewPort->setCursor( rotCursor );
\r
608 \brief Compute the gravity center.
\r
609 \param theX used to return X coordinate of the gravity center
\r
610 \param theY used to return Y coordinate of the gravity center
\r
611 \param theZ used to return Z coordinate of the gravity center
\r
612 \return \c true if the gravity center is computed
\r
614 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
\r
616 Handle(V3d_View) aView3d = myViewPort->getView();
\r
618 // Project boundaries points and add to avergae gravity
\r
619 // the ones which lie within the screen limits
\r
620 Standard_Real aScreenLimits[4] = { 0.0, 0.0, 0.0, 0.0 };
\r
622 #if OCC_VERSION_LARGE > 0x06070100
\r
623 // NDC space screen limits
\r
624 aScreenLimits[0] = -1.0;
\r
625 aScreenLimits[1] = 1.0;
\r
626 aScreenLimits[2] = -1.0;
\r
627 aScreenLimits[3] = 1.0;
\r
629 aView3d->View()->ViewMapping().WindowLimit( aScreenLimits[0],
\r
632 aScreenLimits[3] );
\r
635 Standard_Integer aPointsNb = 0;
\r
637 Standard_Real aXmin = 0.0;
\r
638 Standard_Real aYmin = 0.0;
\r
639 Standard_Real aZmin = 0.0;
\r
640 Standard_Real aXmax = 0.0;
\r
641 Standard_Real aYmax = 0.0;
\r
642 Standard_Real aZmax = 0.0;
\r
644 Graphic3d_MapOfStructure aSetOfStructures;
\r
645 aView3d->View()->DisplayedStructures( aSetOfStructures );
\r
646 Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures );
\r
648 for( ; aStructureIt.More(); aStructureIt.Next() ) {
\r
649 const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key();
\r
650 if ( aStructure->IsEmpty() ) {
\r
654 aStructure->MinMaxValues( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
\r
656 // Infinite structures are skipped
\r
657 Standard_Real aLIM = ShortRealLast() - 1.0;
\r
658 if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
\r
659 || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
\r
663 gp_Pnt aPoints[8] = {
664 gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
665 gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
666 gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
667 gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
670 for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
\r
671 const gp_Pnt& aBBPoint = aPoints[aPointIt];
673 #if OCC_VERSION_LARGE > 0x06070100
674 gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
675 const Standard_Real& U = aProjected.X();
676 const Standard_Real& V = aProjected.Y();
678 Standard_Real U = 0.0;
679 Standard_Real V = 0.0;
680 Standard_Real W = 0.0;
681 aView3d->View()->Projects( aBBPoint.X(), aBBPoint.Y(), aBBPoint.Z(), U, V, W );
684 if (U >= aScreenLimits[0]
685 && U <= aScreenLimits[1]
686 && V >= aScreenLimits[2]
687 && V <= aScreenLimits[3])
690 theX += aBBPoint.X();
691 theY += aBBPoint.Y();
692 theZ += aBBPoint.Z();
697 if ( aPointsNb > 0 )
\r
707 \brief Set the gravity center as a rotation point.
\r
709 void OCCViewer_ViewWindow::activateSetRotationGravity()
\r
711 if ( myRotationPointSelection )
\r
713 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
\r
714 ic->CloseAllContexts();
\r
715 myOperation = NOTHING;
\r
716 myViewPort->setCursor( myCursor );
\r
717 myCursorIsHand = false;
\r
718 myRotationPointSelection = false;
\r
721 myPrevPointType = myCurrPointType;
\r
722 myCurrPointType = GRAVITY;
\r
724 Standard_Real Xcenter, Ycenter, Zcenter;
\r
725 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
\r
726 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
\r
730 \brief Update gravity center in the "Set Rotation Point" dialog box.
\r
731 \sa OCCViewer_SetRotationPointDlg class
\r
733 void OCCViewer_ViewWindow::updateGravityCoords()
\r
735 if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == GRAVITY )
\r
737 Standard_Real Xcenter, Ycenter, Zcenter;
\r
738 if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
\r
739 mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
\r
744 \brief Set the point selected by the user as a rotation point.
\r
745 \param theX X coordinate of the rotation point
\r
746 \param theY Y coordinate of the rotation point
\r
747 \param theZ Z coordinate of the rotation point
\r
749 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
\r
751 if ( myRotationPointSelection )
\r
753 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
\r
754 ic->CloseAllContexts();
\r
755 myOperation = NOTHING;
\r
756 myViewPort->setCursor( myCursor );
\r
757 myCursorIsHand = false;
\r
758 myRotationPointSelection = false;
\r
761 myPrevPointType = myCurrPointType;
\r
762 myCurrPointType = SELECTED;
\r
763 mySelectedPoint.SetCoord(theX,theY,theZ);
\r
767 \brief Start the shape selection process.
\r
769 void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
\r
771 myPrevPointType = myCurrPointType;
\r
772 myCurrPointType = SELECTED;
\r
774 // activate selection ------>
\r
775 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
\r
777 ic->OpenLocalContext();
\r
779 AIS_ListOfInteractive aList;
\r
780 ic->DisplayedObjects( aList );
\r
781 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
\r
783 Handle(AIS_InteractiveObject) anObj = it.Value();
\r
784 if ( !anObj.IsNull() && anObj->HasPresentation() &&
\r
785 anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
\r
787 ic->Load(anObj,-1);
\r
788 ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
\r
791 // activate selection <------
\r
793 if ( !myCursorIsHand )
\r
795 QCursor handCursor (Qt::PointingHandCursor);
\r
796 myCursorIsHand = true;
\r
797 myCursor = cursor();
\r
798 myViewPort->setCursor( handCursor );
\r
800 myRotationPointSelection = true;
\r
804 \brief Start global panning operation
\r
806 Sets the corresponding cursor for the widget.
\r
808 void OCCViewer_ViewWindow::activateGlobalPanning()
\r
810 Handle(V3d_View) aView3d = myViewPort->getView();
\r
811 if ( !aView3d.IsNull() ) {
\r
812 QPixmap globalPanPixmap (imageCrossCursor);
\r
813 QCursor glPanCursor (globalPanPixmap);
\r
814 myCurScale = aView3d->Scale();
\r
815 aView3d->FitAll(0.01, false);
\r
816 myCursor = cursor(); // save old cursor
\r
817 myViewPort->fitAll(); // fits view before selecting a new scene center
\r
818 if( setTransformRequested( PANGLOBAL ) )
\r
819 myViewPort->setCursor( glPanCursor );
\r
824 \brief Starts fit operation.
\r
826 Sets the corresponding cursor for the widget.
\r
828 void OCCViewer_ViewWindow::activateWindowFit()
\r
830 if ( !transformRequested() && !myCursorIsHand )
\r
831 myCursor = cursor(); /* save old cursor */
\r
833 if ( myOperation != WINDOWFIT ) {
\r
834 QCursor handCursor (Qt::PointingHandCursor);
\r
835 if( setTransformRequested ( WINDOWFIT ) )
\r
837 myViewPort->setCursor ( handCursor );
\r
838 myCursorIsHand = true;
\r
844 \brief Start delayed viewer operation.
\r
846 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
\r
848 bool ok = transformEnabled( op );
\r
849 myOperation = ok ? op : NOTHING;
\r
850 myViewPort->setMouseTracking( myOperation == NOTHING );
\r
855 \brief Handle mouse move event.
\r
856 \param theEvent mouse event
\r
858 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
\r
860 if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
\r
861 myIsKeyFree = false;
\r
862 switch ( getButtonState( theEvent, interactionStyle() ) ) {
\r
864 myViewPort->startZoomAtPoint( myStartX, myStartY );
\r
871 activateRotation();
\r
872 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
\r
879 myCurrX = theEvent->x();
\r
880 myCurrY = theEvent->y();
\r
881 switch (myOperation) {
\r
883 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
\r
887 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
\r
888 myStartX = myCurrX;
\r
889 myStartY = myCurrY;
\r
893 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
\r
894 myStartX = myCurrX;
\r
895 myStartY = myCurrY;
\r
907 if ( myRotationPointSelection || isSketcherStyle() )
\r
909 emit mouseMoving( this, theEvent );
\r
913 int aState = theEvent->modifiers();
\r
914 int aButton = theEvent->buttons();
\r
915 int anInteractionStyle = interactionStyle();
\r
916 if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
\r
917 aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
\r
918 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
\r
919 aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
\r
920 myDrawRect = myEnableDrawMode;
\r
921 if ( myDrawRect ) {
\r
923 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
\r
924 QCursor handCursor (Qt::PointingHandCursor);
\r
925 myCursorIsHand = true;
\r
926 myCursor = cursor();
\r
927 myViewPort->setCursor( handCursor );
\r
930 emit mouseMoving( this, theEvent );
\r
932 else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
\r
933 aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
\r
934 ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
\r
935 aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
\r
936 OCCViewer_ViewSketcher* sketcher = 0;
\r
937 QList<OCCViewer_ViewSketcher*>::Iterator it;
\r
938 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
\r
940 OCCViewer_ViewSketcher* sk = (*it);
\r
941 if( sk->isDefault() && sk->sketchButton() == aButton )
\r
944 if ( sketcher && myCurSketch == -1 )
\r
946 activateSketching( sketcher->type() );
\r
949 myCurSketch = mypSketcher->sketchButton();
\r
951 if ( l_mbPressEvent )
\r
953 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
\r
954 delete l_mbPressEvent;
\r
955 l_mbPressEvent = 0;
\r
957 QApplication::sendEvent( getViewPort(), theEvent );
\r
962 emit mouseMoving( this, theEvent );
\r
968 \brief Handle mouse release event.
\r
969 \param theEvent mouse event
\r
971 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
\r
973 switch ( myOperation ) {
\r
976 int prevState = myCurSketch;
\r
977 if(theEvent->button() == Qt::RightButton)
\r
979 QList<OCCViewer_ViewSketcher*>::Iterator it;
\r
980 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
\r
982 OCCViewer_ViewSketcher* sk = (*it);
\r
983 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
\r
988 emit mouseReleased(this, theEvent);
\r
989 if(theEvent->button() == Qt::RightButton && prevState == -1)
\r
991 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
\r
992 theEvent->pos(), theEvent->globalPos() );
\r
993 emit contextMenuRequested( &aEvent );
\r
998 myViewPort->endRotation();
\r
1008 if ( theEvent->button() == Qt::LeftButton ) {
\r
1009 myViewPort->setCenter( theEvent->x(), theEvent->y() );
\r
1010 myViewPort->getView()->SetScale(myCurScale);
\r
1016 if ( theEvent->button() == Qt::LeftButton ) {
\r
1017 myCurrX = theEvent->x();
\r
1018 myCurrY = theEvent->y();
\r
1020 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
\r
1021 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
\r
1028 // NOTE: viewer 3D detects a rectangle of selection using this event
\r
1029 // so we must emit it BEFORE resetting the selection rectangle
\r
1031 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
\r
1035 myViewPort->update();
\r
1038 if ( l_mbPressEvent )
\r
1040 delete l_mbPressEvent;
\r
1041 l_mbPressEvent = 0;
\r
1046 \brief Reset the viewport to its initial state
\r
1047 ( no transformations in process etc. )
\r
1049 void OCCViewer_ViewWindow::resetState()
\r
1051 myDrawRect = false;
\r
1053 if ( myRotationPointSelection )
\r
1055 QCursor handCursor (Qt::PointingHandCursor);
\r
1056 myViewPort->setCursor( handCursor );
\r
1060 if ( transformRequested() || myCursorIsHand )
\r
1061 myViewPort->setCursor( myCursor );
\r
1062 myCursorIsHand = false;
\r
1065 if ( transformRequested() )
\r
1066 emit vpTransformationFinished (myOperation);
\r
1068 setTransformInProcess( false );
\r
1069 setTransformRequested( NOTHING );
\r
1074 \brief Draw rubber band rectangle.
\r
1076 void OCCViewer_ViewWindow::drawRect()
\r
1078 if ( !myRectBand ) {
\r
1079 myRectBand = new QtxRectRubberBand( myViewPort );
\r
1080 //QPalette palette;
\r
1081 //palette.setColor(myRectBand->foregroundRole(), Qt::white);
\r
1082 //myRectBand->setPalette(palette);
\r
1084 //myRectBand->hide();
\r
1086 myRectBand->setUpdatesEnabled ( false );
\r
1087 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
\r
1088 myRectBand->initGeometry( aRect );
\r
1090 if ( !myRectBand->isVisible() )
\r
1091 myRectBand->show();
\r
1093 myRectBand->setUpdatesEnabled ( true );
\r
1094 //myRectBand->repaint();
\r
1096 //myRectBand->setVisible( aRect.isValid() );
\r
1097 //if ( myRectBand->isVisible() )
\r
1098 // myRectBand->repaint();
\r
1100 // myRectBand->show();
\r
1101 //myRectBand->repaint();
\r
1105 \brief Clear rubber band rectangle on the end on the dragging operation.
\r
1107 void OCCViewer_ViewWindow::endDrawRect()
\r
1109 //delete myRectBand;
\r
1113 myRectBand->clearGeometry();
\r
1114 myRectBand->hide();
\r
1119 \brief Create actions.
\r
1121 void OCCViewer_ViewWindow::createActions()
\r
1123 if( !toolMgr()->isEmpty() )
\r
1126 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
\r
1128 QtxAction* aAction;
\r
1131 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
\r
1132 tr( "MNU_DUMP_VIEW" ), 0, this);
\r
1133 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
\r
1134 connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
\r
1135 toolMgr()->registerAction( aAction, DumpId );
\r
1138 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
\r
1139 tr( "MNU_FITALL" ), 0, this);
\r
1140 aAction->setStatusTip(tr("DSC_FITALL"));
\r
1141 connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
\r
1142 toolMgr()->registerAction( aAction, FitAllId );
\r
1145 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
\r
1146 tr( "MNU_FITRECT" ), 0, this);
\r
1147 aAction->setStatusTip(tr("DSC_FITRECT"));
\r
1148 connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
\r
1149 toolMgr()->registerAction( aAction, FitRectId );
\r
1152 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
\r
1153 tr( "MNU_ZOOM_VIEW" ), 0, this);
\r
1154 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
\r
1155 connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
\r
1156 toolMgr()->registerAction( aAction, ZoomId );
\r
1159 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
\r
1160 tr( "MNU_PAN_VIEW" ), 0, this);
\r
1161 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
\r
1162 connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
\r
1163 toolMgr()->registerAction( aAction, PanId );
\r
1166 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
\r
1167 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
\r
1168 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
\r
1169 connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
\r
1170 toolMgr()->registerAction( aAction, GlobalPanId );
\r
1173 mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
\r
1174 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
\r
1175 mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
\r
1176 mySetRotationPointAction->setCheckable( true );
\r
1177 connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
\r
1178 toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
\r
1181 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
\r
1182 tr( "MNU_ROTATE_VIEW" ), 0, this);
\r
1183 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
\r
1184 connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
\r
1185 toolMgr()->registerAction( aAction, RotationId );
\r
1188 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
\r
1189 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
\r
1190 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
\r
1191 connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
\r
1192 this->addAction(aAction);
\r
1193 toolMgr()->registerAction( aAction, FrontId );
\r
1195 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
\r
1196 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
\r
1197 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
\r
1198 connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
\r
1199 this->addAction(aAction);
\r
1200 toolMgr()->registerAction( aAction, BackId );
\r
1202 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
\r
1203 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
\r
1204 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
\r
1205 connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
\r
1206 this->addAction(aAction);
\r
1207 toolMgr()->registerAction( aAction, TopId );
\r
1209 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
\r
1210 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
\r
1211 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
\r
1212 connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
\r
1213 this->addAction(aAction);
\r
1214 toolMgr()->registerAction( aAction, BottomId );
\r
1216 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
\r
1217 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
\r
1218 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
\r
1219 connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
\r
1220 this->addAction(aAction);
\r
1221 toolMgr()->registerAction( aAction, LeftId );
\r
1223 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
\r
1224 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
\r
1225 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
\r
1226 connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
\r
1227 this->addAction(aAction);
\r
1228 toolMgr()->registerAction( aAction, RightId );
\r
1230 // rotate anticlockwise
\r
1231 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
\r
1232 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
\r
1233 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
\r
1234 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
\r
1235 this->addAction(aAction);
\r
1236 toolMgr()->registerAction( aAction, AntiClockWiseId );
\r
1238 // rotate clockwise
\r
1239 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
\r
1240 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
\r
1241 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
\r
1242 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
\r
1243 this->addAction(aAction);
\r
1244 toolMgr()->registerAction( aAction, ClockWiseId );
\r
1247 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
\r
1248 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
\r
1249 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
\r
1250 connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
\r
1251 this->addAction(aAction);
\r
1252 toolMgr()->registerAction( aAction, ResetId );
\r
1255 aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
\r
1256 aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
\r
1257 tr("MNU_CLONE_VIEW"), 0, this);
\r
1258 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
\r
1259 connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
\r
1260 toolMgr()->registerAction( aAction, CloneId );
\r
1262 aAction = new QtxAction (tr ("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr ("ICON_OCCVIEWER_CLIPPING")),
\r
1263 tr ("MNU_CLIPPING"), 0, this);
\r
1264 aAction->setStatusTip (tr ("DSC_CLIPPING"));
\r
1265 aAction->setCheckable (true);
\r
1266 connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
\r
1267 toolMgr()->registerAction (aAction, ClippingId);
\r
1269 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
\r
1270 tr( "MNU_SHOOT_VIEW" ), 0, this);
\r
1271 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
\r
1272 connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
\r
1273 toolMgr()->registerAction( aAction, MemId );
\r
1275 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
\r
1276 tr( "MNU_PRESETS_VIEW" ), 0, this);
\r
1277 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
\r
1278 connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
\r
1279 toolMgr()->registerAction( aAction, RestoreId );
\r
1281 if (myModel->trihedronActivated()) {
\r
1282 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
\r
1283 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
\r
1284 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
\r
1285 connect(aAction, SIGNAL(triggered()), this, SLOT(onTrihedronShow()));
\r
1286 toolMgr()->registerAction( aAction, TrihedronShowId );
\r
1290 aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
\r
1291 tr( "MNU_SCALING" ), 0, this);
\r
1292 aAction->setStatusTip(tr("DSC_SCALING"));
\r
1293 connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
\r
1294 toolMgr()->registerAction( aAction, AxialScaleId );
\r
1296 // Enable/disable preselection
\r
1297 aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
\r
1298 tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
\r
1299 aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
\r
1300 aAction->setCheckable(true);
\r
1301 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
\r
1302 toolMgr()->registerAction( aAction, SwitchPreselectionId );
\r
1304 // Enable/disable selection
\r
1305 aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
\r
1306 tr( "MNU_ENABLE_SELECTION" ), 0, this);
\r
1307 aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
\r
1308 aAction->setCheckable(true);
\r
1309 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
\r
1310 toolMgr()->registerAction( aAction, SwitchSelectionId );
\r
1312 // Graduated axes
\r
1313 aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
\r
1314 tr( "MNU_GRADUATED_AXES" ), 0, this);
\r
1315 aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
\r
1316 connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
\r
1317 toolMgr()->registerAction( aAction, GraduatedAxesId );
\r
1319 // Active only ambient light or not
\r
1320 aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
\r
1321 tr( "MNU_AMBIENT" ), 0, this);
\r
1322 aAction->setStatusTip(tr("DSC_AMBIENT"));
\r
1323 connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
\r
1324 toolMgr()->registerAction( aAction, AmbientId );
\r
1326 // Switch between interaction styles
\r
1327 aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
\r
1328 tr( "MNU_STYLE_SWITCH" ), 0, this);
\r
1329 aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
\r
1330 aAction->setCheckable(true);
\r
1331 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
\r
1332 toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
\r
1334 // Switch between zooming styles
\r
1335 aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
\r
1336 tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
\r
1337 aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
\r
1338 aAction->setCheckable(true);
\r
1339 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
\r
1340 toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
\r
1343 aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
\r
1344 tr( "MNU_MINIMIZE_VIEW" ), 0, this );
\r
1345 aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
\r
1346 connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
\r
1347 toolMgr()->registerAction( aAction, MaximizedId );
\r
1349 // Return to 3d view
\r
1350 if (my2dMode!=No2dMode){
\r
1351 aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
\r
1352 tr( "MNU_RETURN_3D_VIEW" ), 0, this );
\r
1353 aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
\r
1354 connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
\r
1355 toolMgr()->registerAction( aAction, ReturnTo3dViewId );
\r
1358 // Synchronize View
\r
1359 toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
\r
1363 \brief Create toolbar.
\r
1365 void OCCViewer_ViewWindow::createToolBar()
\r
1367 QString aToolbarName;
\r
1368 switch (my2dMode) {
\r
1370 aToolbarName = tr( "LBL_XYTOOLBAR_LABEL" );
\r
1373 aToolbarName = tr( "LBL_XZTOOLBAR_LABEL" );
\r
1376 aToolbarName = tr( "LBL_YZTOOLBAR_LABEL" );
\r
1379 aToolbarName = tr( "LBL_3DTOOLBAR_LABEL" );
\r
1382 int tid = toolMgr()->createToolBar( aToolbarName, false );
\r
1383 if ( my2dMode != No2dMode ){
\r
1384 toolMgr()->append( ReturnTo3dViewId, tid );
\r
1385 toolMgr()->append( toolMgr()->separator(), tid );
\r
1387 toolMgr()->append( DumpId, tid );
\r
1388 toolMgr()->append( SwitchInteractionStyleId, tid );
\r
1389 #if OCC_VERSION_LARGE > 0x0603000A // available only with OCC-6.3-sp11 and higher version
\r
1390 toolMgr()->append( SwitchZoomingStyleId, tid );
\r
1392 toolMgr()->append( SwitchPreselectionId, tid );
\r
1393 toolMgr()->append( SwitchSelectionId, tid );
\r
1394 if( myModel->trihedronActivated() )
\r
1395 toolMgr()->append( TrihedronShowId, tid );
\r
1397 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
\r
1398 aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
\r
1399 aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
\r
1400 aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
\r
1401 toolMgr()->append( aScaleAction, tid );
\r
1403 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
\r
1404 aPanningAction->insertAction( toolMgr()->action( PanId ) );
\r
1405 aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
\r
1406 toolMgr()->append( aPanningAction, tid );
\r
1408 if (my2dMode == No2dMode) {
\r
1409 toolMgr()->append( ChangeRotationPointId, tid );
\r
1410 toolMgr()->append( RotationId, tid );
\r
1412 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
\r
1413 aViewsAction->insertAction( toolMgr()->action( FrontId ) );
\r
1414 aViewsAction->insertAction( toolMgr()->action( BackId ) );
\r
1415 aViewsAction->insertAction( toolMgr()->action( TopId ) );
\r
1416 aViewsAction->insertAction( toolMgr()->action( BottomId ) );
\r
1417 aViewsAction->insertAction( toolMgr()->action( LeftId ) );
\r
1418 aViewsAction->insertAction( toolMgr()->action( RightId ) );
\r
1419 toolMgr()->append( aViewsAction, tid );
\r
1421 toolMgr()->append( AntiClockWiseId, tid );
\r
1422 toolMgr()->append( ClockWiseId, tid );
\r
1424 toolMgr()->append( ResetId, tid );
\r
1427 QtxMultiAction* aMemAction = new QtxMultiAction( this );
\r
1428 aMemAction->insertAction( toolMgr()->action( MemId ) );
\r
1429 aMemAction->insertAction( toolMgr()->action( RestoreId ) );
\r
1430 toolMgr()->append( aMemAction, tid );
\r
1432 toolMgr()->append( toolMgr()->separator(), tid );
\r
1433 toolMgr()->append( CloneId, tid );
\r
1435 toolMgr()->append( toolMgr()->separator(), tid );
\r
1436 toolMgr()->append( ClippingId, tid );
\r
1437 toolMgr()->append( AxialScaleId, tid );
\r
1438 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
\r
1439 toolMgr()->append( GraduatedAxesId, tid );
\r
1441 toolMgr()->append( AmbientId, tid );
\r
1443 toolMgr()->append( MaximizedId, tid );
\r
1444 toolMgr()->append( SynchronizeId, tid );
\r
1448 \brief Perform 'fit all' operation.
\r
1450 void OCCViewer_ViewWindow::onViewFitAll()
\r
1452 myViewPort->fitAll();
\r
1456 \brief Perform "front view" transformation.
\r
1458 void OCCViewer_ViewWindow::onFrontView()
\r
1460 emit vpTransformationStarted ( FRONTVIEW );
\r
1461 Handle(V3d_View) aView3d = myViewPort->getView();
\r
1462 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
\r
1464 emit vpTransformationFinished ( FRONTVIEW );
\r
1468 \brief Perform "back view" transformation.
\r
1470 void OCCViewer_ViewWindow::onBackView()
\r
1472 emit vpTransformationStarted ( BACKVIEW );
\r
1473 Handle(V3d_View) aView3d = myViewPort->getView();
\r
1474 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
\r
1476 emit vpTransformationFinished ( BACKVIEW );
\r
1480 \brief Perform "top view" transformation.
\r
1482 void OCCViewer_ViewWindow::onTopView()
\r
1484 emit vpTransformationStarted ( TOPVIEW );
\r
1485 Handle(V3d_View) aView3d = myViewPort->getView();
\r
1486 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
\r
1488 emit vpTransformationFinished ( TOPVIEW );
\r
1492 \brief Perform "bottom view" transformation.
\r
1494 void OCCViewer_ViewWindow::onBottomView()
\r
1496 emit vpTransformationStarted ( BOTTOMVIEW );
\r
1497 Handle(V3d_View) aView3d = myViewPort->getView();
\r
1498 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
\r
1500 emit vpTransformationFinished ( BOTTOMVIEW );
\r
1504 \brief Perform "left view" transformation.
\r
1506 void OCCViewer_ViewWindow::onLeftView()
\r
1508 emit vpTransformationStarted ( LEFTVIEW );
\r
1509 Handle(V3d_View) aView3d = myViewPort->getView();
\r
1510 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
\r
1512 emit vpTransformationFinished ( LEFTVIEW );
\r
1516 \brief Perform "right view" transformation.
\r
1518 void OCCViewer_ViewWindow::onRightView()
\r
1520 emit vpTransformationStarted ( RIGHTVIEW );
\r
1521 Handle(V3d_View) aView3d = myViewPort->getView();
\r
1522 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
\r
1524 emit vpTransformationFinished ( RIGHTVIEW );
\r
1528 \brief Rotate view 90 degrees clockwise
\r
1530 void OCCViewer_ViewWindow::onClockWiseView()
\r
1532 emit vpTransformationStarted ( CLOCKWISEVIEW );
\r
1533 myViewPort->rotateXY( 90. );
\r
1534 emit vpTransformationFinished ( CLOCKWISEVIEW );
\r
1538 \brief Rotate view 90 degrees conterclockwise
\r
1540 void OCCViewer_ViewWindow::onAntiClockWiseView()
\r
1542 emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
\r
1543 myViewPort->rotateXY( -90. );
\r
1544 emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
\r
1548 \brief Perform "reset view" transformation.
\r
1550 Sets default orientation of the viewport camera.
\r
1552 void OCCViewer_ViewWindow::onResetView()
\r
1554 emit vpTransformationStarted( RESETVIEW );
\r
1555 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
\r
1556 myViewPort->getView()->Reset( false );
\r
1557 myViewPort->fitAll( false, true, false );
\r
1558 myViewPort->getView()->SetImmediateUpdate( upd );
\r
1559 myViewPort->getView()->Update();
\r
1560 emit vpTransformationFinished( RESETVIEW );
\r
1564 \brief Perform "fit all" transformation.
\r
1566 void OCCViewer_ViewWindow::onFitAll()
\r
1568 emit vpTransformationStarted( FITALLVIEW );
\r
1569 myViewPort->fitAll();
\r
1570 emit vpTransformationFinished( FITALLVIEW );
\r
1574 \brief Called if 'change rotation point' operation is activated.
\r
1575 \param on action state
\r
1577 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
\r
1581 if (!mySetRotationPointDlg)
\r
1583 mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
\r
1584 mySetRotationPointDlg->SetAction(mySetRotationPointAction);
\r
1587 if (!mySetRotationPointDlg->isVisible())
\r
1589 //if (mySetRotationPointDlg->IsFirstShown())
\r
1590 if (myCurrPointType == GRAVITY)
\r
1592 Standard_Real Xcenter, Ycenter, Zcenter;
\r
1593 if (computeGravityCenter(Xcenter, Ycenter, Zcenter))
\r
1594 mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
\r
1596 mySetRotationPointDlg->show();
\r
1601 if (mySetRotationPointDlg->isVisible())
\r
1602 mySetRotationPointDlg->hide();
\r
1607 \brief Create one more window with same content.
\r
1609 void OCCViewer_ViewWindow::onCloneView()
\r
1611 SUIT_ViewWindow* vw = myManager->createViewWindow();
\r
1613 emit viewCloned( vw );
\r
1617 Creates one more window with same content
\r
1619 void OCCViewer_ViewWindow::onAxialScale()
\r
1621 if ( !myScalingDlg )
\r
1622 myScalingDlg = new OCCViewer_AxialScaleDlg( this );
\r
1624 if ( !myScalingDlg->isVisible() )
\r
1626 myScalingDlg->Update();
\r
1627 myScalingDlg->show();
\r
1632 Shows Graduated Axes dialog
\r
1634 void OCCViewer_ViewWindow::onGraduatedAxes()
\r
1636 myCubeAxesDlg->Update();
\r
1637 myCubeAxesDlg->show();
\r
1640 void OCCViewer_ViewWindow::onAmbientToogle()
\r
1642 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
\r
1643 viewer->InitDefinedLights();
\r
1644 while(viewer->MoreDefinedLights())
\r
1646 Handle(V3d_Light) light = viewer->DefinedLight();
\r
1647 if(light->Type() != V3d_AMBIENT)
\r
1649 Handle(V3d_View) aView3d = myViewPort->getView();
\r
1650 if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
\r
1651 else viewer->SetLightOn(light);
\r
1653 viewer->NextDefinedLights();
\r
1659 \brief Store view parameters.
\r
1661 void OCCViewer_ViewWindow::onMemorizeView()
\r
1663 appendViewAspect( getViewParams() );
\r
1667 \brief Restore view parameters.
\r
1669 void OCCViewer_ViewWindow::onRestoreView()
\r
1671 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
\r
1672 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
\r
1674 updateViewAspects( aDlg->parameters() );
\r
1675 if( myRestoreFlag && aDlg->parameters().count() )
\r
1676 performRestoring( aDlg->currentItem() );
\r
1680 \brief Restore view parameters.
\r
1681 \param anItem view parameters
\r
1683 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
\r
1685 Handle(V3d_View) aView3d = myViewPort->getView();
\r
1687 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
\r
1688 aView3d->SetScale( anItem.scale );
\r
1689 aView3d->SetTwist( anItem.twist );
\r
1690 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
\r
1691 aView3d->SetImmediateUpdate( prev );
\r
1692 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
\r
1693 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
\r
1694 aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
\r
1696 #if OCC_VERSION_LARGE > 0x06070100
\r
1697 if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
\r
1699 double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
\r
1701 // "eye" and "at" require conversion to represent center panning
\r
1702 // up direction is only available after setting angle of twist and
\r
1703 // other view parameters
\r
1704 aView3d->Up( anUpX, anUpY, anUpZ );
\r
1706 gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
\r
1707 gp_Dir anUp( anUpX, anUpY, anUpZ );
\r
1708 gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
\r
1709 gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
\r
1710 gp_Dir aSide = aProj ^ anUp;
\r
1712 anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
\r
1713 anAt.Translate( gp_Vec( anUp ) * anItem.centerY );
\r
1715 aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
\r
1716 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
\r
1719 aView3d->SetCenter( anItem.centerX, anItem.centerY );
\r
1722 if ( !baseParamsOnly ) {
\r
1724 myModel->setTrihedronShown( anItem.isVisible );
\r
1725 myModel->setTrihedronSize( anItem.size );
\r
1727 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
\r
1728 // graduated trihedron
\r
1729 bool anIsVisible = anItem.gtIsVisible;
\r
1730 OCCViewer_AxisWidget::AxisData anAxisData[3];
\r
1731 anAxisData[0].DrawName = anItem.gtDrawNameX;
\r
1732 anAxisData[1].DrawName = anItem.gtDrawNameZ;
\r
1733 anAxisData[2].DrawName = anItem.gtDrawNameZ;
\r
1734 anAxisData[0].Name = anItem.gtNameX;
\r
1735 anAxisData[1].Name = anItem.gtNameZ;
\r
1736 anAxisData[2].Name = anItem.gtNameZ;
\r
1737 anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
\r
1738 anItem.gtNameColorGX,
\r
1739 anItem.gtNameColorBX );
\r
1740 anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
\r
1741 anItem.gtNameColorGY,
\r
1742 anItem.gtNameColorBY );
\r
1743 anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
\r
1744 anItem.gtNameColorGZ,
\r
1745 anItem.gtNameColorBZ );
\r
1746 anAxisData[0].DrawValues = anItem.gtDrawValuesX;
\r
1747 anAxisData[1].DrawValues = anItem.gtDrawValuesY;
\r
1748 anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
\r
1749 anAxisData[0].NbValues = anItem.gtNbValuesX;
\r
1750 anAxisData[1].NbValues = anItem.gtNbValuesY;
\r
1751 anAxisData[2].NbValues = anItem.gtNbValuesZ;
\r
1752 anAxisData[0].Offset = anItem.gtOffsetX;
\r
1753 anAxisData[1].Offset = anItem.gtOffsetY;
\r
1754 anAxisData[2].Offset = anItem.gtOffsetZ;
\r
1755 anAxisData[0].Color = QColor( anItem.gtColorRX,
\r
1757 anItem.gtColorBX );
\r
1758 anAxisData[1].Color = QColor( anItem.gtColorRY,
\r
1760 anItem.gtColorBY );
\r
1761 anAxisData[2].Color = QColor( anItem.gtColorRZ,
\r
1763 anItem.gtColorBZ );
\r
1764 anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
\r
1765 anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
\r
1766 anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
\r
1767 anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
\r
1768 anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
\r
1769 anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
\r
1771 myCubeAxesDlg->SetData( anIsVisible, anAxisData );
\r
1772 myCubeAxesDlg->ApplyData( aView3d );
\r
1775 } // if ( !baseParamsOnly )
\r
1777 myRestoreFlag = 0;
\r
1781 \brief Set restore flag.
\r
1783 void OCCViewer_ViewWindow::setRestoreFlag()
\r
1785 myRestoreFlag = 1;
\r
1789 \brief Called when action "show/hide trihedron" is activated.
\r
1791 void OCCViewer_ViewWindow::onTrihedronShow()
\r
1793 myModel->toggleTrihedron();
\r
1797 \brief Toggles preselection (highlighting) on/off
\r
1799 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
\r
1801 myPreselectionEnabled = on;
\r
1802 myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
\r
1804 // unhighlight all highlighted objects
\r
1806 myModel->unHighlightAll( true, false );
\r
1809 // update action state if method is called outside
\r
1810 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
\r
1811 if ( a && a->isChecked() != on ) {
\r
1812 a->setChecked( on );
\r
1817 \brief Toggles selection on/off
\r
1819 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
\r
1821 mySelectionEnabled = on;
\r
1822 myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
\r
1824 // update action state if method is called outside
\r
1827 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
\r
1829 a->setEnabled( on );
\r
1833 a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
\r
1834 if ( a && a->isChecked() != on ) {
\r
1835 a->setChecked( on );
\r
1840 \brief Switches "keyboard free" interaction style on/off
\r
1842 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
\r
1844 myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
\r
1846 // update action state if method is called outside
\r
1847 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
\r
1848 if ( a->isChecked() != on )
\r
1849 a->setChecked( on );
\r
1853 \brief Toogles advanced zooming style (relatively to the cursor position) on/off
\r
1855 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
\r
1857 myViewPort->setAdvancedZoomingEnabled( on );
\r
1859 // update action state if method is called outside
\r
1860 QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
\r
1861 if ( a->isChecked() != on )
\r
1862 a->setChecked( on );
\r
1866 \brief Get current interaction style
\r
1867 \return interaction style
\r
1869 int OCCViewer_ViewWindow::interactionStyle() const
\r
1871 return myInteractionStyle;
\r
1875 \brief Set current interaction style
\r
1876 \param theStyle interaction style
\r
1878 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
\r
1880 onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
\r
1884 \brief Get current zooming style
\r
1885 \return zooming style
\r
1887 int OCCViewer_ViewWindow::zoomingStyle() const
\r
1889 return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
\r
1893 \brief Set current zooming style
\r
1894 \param theStyle zooming style
\r
1896 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
\r
1898 onSwitchZoomingStyle( theStyle == 1 );
\r
1902 \brief Dump view window contents to the pixmap.
\r
1903 \return pixmap containing all scene rendered in the window
\r
1905 QImage OCCViewer_ViewWindow::dumpView()
\r
1907 Handle(V3d_View) view = myViewPort->getView();
\r
1908 if ( view.IsNull() )
\r
1911 int aWidth = myViewPort->width();
\r
1912 int aHeight = myViewPort->height();
\r
1913 QApplication::syncX();
\r
1914 view->Redraw(); // In order to reactivate GL context
\r
1917 OpenGLUtils_FrameBuffer aFrameBuffer;
\r
1918 if( aFrameBuffer.init( aWidth, aHeight ) )
\r
1920 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
\r
1922 glPushAttrib( GL_VIEWPORT_BIT );
\r
1923 glViewport( 0, 0, aWidth, aHeight );
\r
1924 aFrameBuffer.bind();
\r
1929 aFrameBuffer.unbind();
\r
1932 aFrameBuffer.bind();
\r
1933 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
\r
1934 aFrameBuffer.unbind();
\r
1936 anImage = anImage.rgbSwapped();
\r
1937 anImage = anImage.mirrored();
\r
1940 // if frame buffers are unsupported, use old functionality
\r
1943 unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
\r
1945 QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
\r
1947 glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
\r
1950 QImage anImage( data, aWidth, aHeight, QImage::Format_ARGB32 );
\r
1951 anImage = anImage.mirrored();
\r
1952 anImage = anImage.rgbSwapped();
\r
1956 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
\r
1957 const QString& fileName,
\r
1958 const QString& format )
\r
1960 if ( format != "PS" && format != "EPS")
\r
1961 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
\r
1963 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
\r
1965 if (format == "PS")
\r
1966 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
\r
1967 else if (format == "EPS")
\r
1968 a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
\r
1974 QString OCCViewer_ViewWindow::filter() const
\r
1976 return tr( "OCC_IMAGE_FILES" );
\r
1981 \brief Set parameters of the cutting plane
\r
1982 \param on if \c true, cutting plane is enabled
\r
1983 \param x X position of plane point
\r
1984 \param y Y position of plane point
\r
1985 \param z Z position of plane point
\r
1986 \param dx X coordinate of plane normal
\r
1987 \param dy Y coordinate of plane normal
\r
1988 \param dz Z coordinate of plane normal
\r
1990 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
\r
1991 const double dx, const double dy, const double dz )
\r
1993 Handle(V3d_View) view = myViewPort->getView();
\r
1994 if ( view.IsNull() )
\r
1998 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
\r
2000 // try to use already existing plane or create a new one
\r
2001 Handle(V3d_Plane) clipPlane;
\r
2003 // calculate new a,b,c,d values for the plane
\r
2004 gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
\r
2005 double a, b, c, d;
\r
2006 pln.Coefficients(a, b, c, d);
\r
2008 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
\r
2009 Handle(Graphic3d_ClipPlane) aClipPlane;
\r
2010 if(aPlanes.Size() > 0 ) {
\r
2011 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
\r
2012 aClipPlane = anIter.Value();
\r
2013 aClipPlane->SetEquation(pln);
\r
2014 aClipPlane->SetOn(Standard_True);
\r
2016 aClipPlane = new Graphic3d_ClipPlane(pln);
\r
2017 view->AddClipPlane(aClipPlane);
\r
2018 aClipPlane->SetOn(Standard_True);
\r
2022 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
\r
2023 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
\r
2024 for( ;anIter.More();anIter.Next() ){
\r
2025 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
\r
2026 aClipPlane->SetOn(Standard_False);
\r
2034 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
\r
2036 gp_Dir aDir = pln.Axis().Direction();
\r
2037 gp_Pnt aPnt = pln.Location();
\r
2038 setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
\r
2043 \brief Check if any cutting plane is enabled
\r
2044 \return \c true if at least one cutting plane is enabled
\r
2046 bool OCCViewer_ViewWindow::isCuttingPlane()
\r
2048 Handle(V3d_View) view = myViewPort->getView();
\r
2050 Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
\r
2051 Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
\r
2052 for( ;anIter.More();anIter.Next() ) {
\r
2053 Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
\r
2054 if(aClipPlane->IsOn()) {
\r
2063 \brief Get the visual parameters of the view window.
\r
2064 \return visual parameters of view window
\r
2066 viewAspect OCCViewer_ViewWindow::getViewParams() const
\r
2068 double projX, projY, projZ, twist;
\r
2069 double atX, atY, atZ, eyeX, eyeY, eyeZ;
\r
2070 double aScaleX, aScaleY, aScaleZ;
\r
2072 Handle(V3d_View) aView3d = myViewPort->getView();
\r
2074 aView3d->Proj( projX, projY, projZ );
\r
2075 aView3d->At( atX, atY, atZ );
\r
2076 aView3d->Eye( eyeX, eyeY, eyeZ );
\r
2077 twist = aView3d->Twist();
\r
2079 aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
\r
2081 bool isShown = myModel->isTrihedronVisible();
\r
2082 double size = myModel->trihedronSize();
\r
2084 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
\r
2086 viewAspect params;
\r
2087 params.scale = aView3d->Scale();
\r
2088 params.projX = projX;
\r
2089 params.projY = projY;
\r
2090 params.projZ = projZ;
\r
2091 params.twist = twist;
\r
2095 params.eyeX = eyeX;
\r
2096 params.eyeY = eyeY;
\r
2097 params.eyeZ = eyeZ;
\r
2098 params.scaleX = aScaleX;
\r
2099 params.scaleY = aScaleY;
\r
2100 params.scaleZ = aScaleZ;
\r
2101 params.name = aName;
\r
2102 params.isVisible= isShown;
\r
2103 params.size = size;
\r
2105 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
\r
2106 aView3d->Center( params.centerX, params.centerY );
\r
2109 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
\r
2110 // graduated trihedron
\r
2111 bool anIsVisible = false;
\r
2112 OCCViewer_AxisWidget::AxisData anAxisData[3];
\r
2113 myCubeAxesDlg->GetData( anIsVisible, anAxisData );
\r
2115 params.gtIsVisible = anIsVisible;
\r
2116 params.gtDrawNameX = anAxisData[0].DrawName;
\r
2117 params.gtDrawNameY = anAxisData[1].DrawName;
\r
2118 params.gtDrawNameZ = anAxisData[2].DrawName;
\r
2119 params.gtNameX = anAxisData[0].Name;
\r
2120 params.gtNameY = anAxisData[1].Name;
\r
2121 params.gtNameZ = anAxisData[2].Name;
\r
2122 params.gtNameColorRX = anAxisData[0].NameColor.red();
\r
2123 params.gtNameColorGX = anAxisData[0].NameColor.green();
\r
2124 params.gtNameColorBX = anAxisData[0].NameColor.blue();
\r
2125 params.gtNameColorRY = anAxisData[1].NameColor.red();
\r
2126 params.gtNameColorGY = anAxisData[1].NameColor.green();
\r
2127 params.gtNameColorBY = anAxisData[1].NameColor.blue();
\r
2128 params.gtNameColorRZ = anAxisData[2].NameColor.red();
\r
2129 params.gtNameColorGZ = anAxisData[2].NameColor.green();
\r
2130 params.gtNameColorBZ = anAxisData[2].NameColor.blue();
\r
2131 params.gtDrawValuesX = anAxisData[0].DrawValues;
\r
2132 params.gtDrawValuesY = anAxisData[1].DrawValues;
\r
2133 params.gtDrawValuesZ = anAxisData[2].DrawValues;
\r
2134 params.gtNbValuesX = anAxisData[0].NbValues;
\r
2135 params.gtNbValuesY = anAxisData[1].NbValues;
\r
2136 params.gtNbValuesZ = anAxisData[2].NbValues;
\r
2137 params.gtOffsetX = anAxisData[0].Offset;
\r
2138 params.gtOffsetY = anAxisData[1].Offset;
\r
2139 params.gtOffsetZ = anAxisData[2].Offset;
\r
2140 params.gtColorRX = anAxisData[0].Color.red();
\r
2141 params.gtColorGX = anAxisData[0].Color.green();
\r
2142 params.gtColorBX = anAxisData[0].Color.blue();
\r
2143 params.gtColorRY = anAxisData[1].Color.red();
\r
2144 params.gtColorGY = anAxisData[1].Color.green();
\r
2145 params.gtColorBY = anAxisData[1].Color.blue();
\r
2146 params.gtColorRZ = anAxisData[2].Color.red();
\r
2147 params.gtColorGZ = anAxisData[2].Color.green();
\r
2148 params.gtColorBZ = anAxisData[2].Color.blue();
\r
2149 params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
\r
2150 params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
\r
2151 params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
\r
2152 params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
\r
2153 params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
\r
2154 params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
\r
2161 \brief Get visual parameters of this view window.
\r
2162 \return visual parameters of view window
\r
2164 QString OCCViewer_ViewWindow::getVisualParameters()
\r
2166 viewAspect params = getViewParams();
\r
2170 data << QString( "scale=%1" ) .arg( params.scale, 0, 'e', 12 );
\r
2171 #if OCC_VERSION_LARGE <= 0x06070100 // the property is deprecated after OCCT 6.7.1
\r
2172 data << QString( "centerX=%1" ) .arg( params.centerX, 0, 'e', 12 );
\r
2173 data << QString( "centerY=%1" ) .arg( params.centerY, 0, 'e', 12 );
\r
2175 data << QString( "projX=%1" ) .arg( params.projX, 0, 'e', 12 );
\r
2176 data << QString( "projY=%1" ) .arg( params.projY, 0, 'e', 12 );
\r
2177 data << QString( "projZ=%1" ) .arg( params.projZ, 0, 'e', 12 );
\r
2178 data << QString( "twist=%1" ) .arg( params.twist, 0, 'e', 12 );
\r
2179 data << QString( "atX=%1" ) .arg( params.atX, 0, 'e', 12 );
\r
2180 data << QString( "atY=%1" ) .arg( params.atY, 0, 'e', 12 );
\r
2181 data << QString( "atZ=%1" ) .arg( params.atZ, 0, 'e', 12 );
\r
2182 data << QString( "eyeX=%1" ) .arg( params.eyeX, 0, 'e', 12 );
\r
2183 data << QString( "eyeY=%1" ) .arg( params.eyeY, 0, 'e', 12 );
\r
2184 data << QString( "eyeZ=%1" ) .arg( params.eyeZ, 0, 'e', 12 );
\r
2185 data << QString( "scaleX=%1" ) .arg( params.scaleX, 0, 'e', 12 );
\r
2186 data << QString( "scaleY=%1" ) .arg( params.scaleY, 0, 'e', 12 );
\r
2187 data << QString( "scaleZ=%1" ) .arg( params.scaleZ, 0, 'e', 12 );
\r
2188 data << QString( "isVisible=%1" ).arg( params.isVisible );
\r
2189 data << QString( "size=%1" ) .arg( params.size, 0, 'f', 2 );
\r
2191 ClipPlanesList aPlanes = myModel->getClipPlanes();
\r
2192 for ( int i=0; i < aPlanes.size(); i++ )
\r
2194 OCCViewer_ClipPlane& aPlane = aPlanes[i];
\r
2195 QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
\r
2196 ClippingPlane += QString( "Mode~%1;").arg( (int)aPlane.Mode );
\r
2197 ClippingPlane += QString( "IsActive~%1;").arg( aPlane.IsOn );
\r
2198 switch ( aPlane.Mode )
\r
2200 case OCCViewer_ClipPlane::Absolute :
\r
2202 ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
\r
2204 if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
\r
2206 ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
\r
2207 ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
\r
2208 ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
\r
2212 ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
\r
2217 case OCCViewer_ClipPlane::Relative :
\r
2219 ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
\r
2220 ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
\r
2221 ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
\r
2226 ClippingPlane += QString( "X~%1;" ).arg( aPlane.X );
\r
2227 ClippingPlane += QString( "Y~%1;" ).arg( aPlane.Y );
\r
2228 ClippingPlane += QString( "Z~%1;" ).arg( aPlane.Z );
\r
2229 data << ClippingPlane;
\r
2233 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 or newer version
\r
2234 // graduated trihedron
\r
2235 data << QString( "gtIsVisible=%1" ) .arg( params.gtIsVisible );
\r
2236 data << QString( "gtDrawNameX=%1" ) .arg( params.gtDrawNameX );
\r
2237 data << QString( "gtDrawNameY=%1" ) .arg( params.gtDrawNameY );
\r
2238 data << QString( "gtDrawNameZ=%1" ) .arg( params.gtDrawNameZ );
\r
2239 data << QString( "gtNameX=%1" ) .arg( params.gtNameX );
\r
2240 data << QString( "gtNameY=%1" ) .arg( params.gtNameY );
\r
2241 data << QString( "gtNameZ=%1" ) .arg( params.gtNameZ );
\r
2242 data << QString( "gtNameColorRX=%1" ) .arg( params.gtNameColorRX );
\r
2243 data << QString( "gtNameColorGX=%1" ) .arg( params.gtNameColorGX );
\r
2244 data << QString( "gtNameColorBX=%1" ) .arg( params.gtNameColorBX );
\r
2245 data << QString( "gtNameColorRY=%1" ) .arg( params.gtNameColorRY );
\r
2246 data << QString( "gtNameColorGY=%1" ) .arg( params.gtNameColorGY );
\r
2247 data << QString( "gtNameColorBY=%1" ) .arg( params.gtNameColorBY );
\r
2248 data << QString( "gtNameColorRZ=%1" ) .arg( params.gtNameColorRZ );
\r
2249 data << QString( "gtNameColorGZ=%1" ) .arg( params.gtNameColorGZ );
\r
2250 data << QString( "gtNameColorBZ=%1" ) .arg( params.gtNameColorBZ );
\r
2251 data << QString( "gtDrawValuesX=%1" ) .arg( params.gtDrawValuesX );
\r
2252 data << QString( "gtDrawValuesY=%1" ) .arg( params.gtDrawValuesY );
\r
2253 data << QString( "gtDrawValuesZ=%1" ) .arg( params.gtDrawValuesZ );
\r
2254 data << QString( "gtNbValuesX=%1" ) .arg( params.gtNbValuesX );
\r
2255 data << QString( "gtNbValuesY=%1" ) .arg( params.gtNbValuesY );
\r
2256 data << QString( "gtNbValuesZ=%1" ) .arg( params.gtNbValuesZ );
\r
2257 data << QString( "gtOffsetX=%1" ) .arg( params.gtOffsetX );
\r
2258 data << QString( "gtOffsetY=%1" ) .arg( params.gtOffsetY );
\r
2259 data << QString( "gtOffsetZ=%1" ) .arg( params.gtOffsetZ );
\r
2260 data << QString( "gtColorRX=%1" ) .arg( params.gtColorRX );
\r
2261 data << QString( "gtColorGX=%1" ) .arg( params.gtColorGX );
\r
2262 data << QString( "gtColorBX=%1" ) .arg( params.gtColorBX );
\r
2263 data << QString( "gtColorRY=%1" ) .arg( params.gtColorRY );
\r
2264 data << QString( "gtColorGY=%1" ) .arg( params.gtColorGY );
\r
2265 data << QString( "gtColorBY=%1" ) .arg( params.gtColorBY );
\r
2266 data << QString( "gtColorRZ=%1" ) .arg( params.gtColorRZ );
\r
2267 data << QString( "gtColorGZ=%1" ) .arg( params.gtColorGZ );
\r
2268 data << QString( "gtColorBZ=%1" ) .arg( params.gtColorBZ );
\r
2269 data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
\r
2270 data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
\r
2271 data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
\r
2272 data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
\r
2273 data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
\r
2274 data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
\r
2276 QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
\r
2277 data << QString( "background=%1" ).arg( bg );
\r
2279 return data.join("*");
\r
2283 \brief Restore visual parameters of the view window.
\r
2284 \param parameters visual parameters of view window
\r
2286 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
\r
2288 viewAspect params;
\r
2289 ClipPlanesList aClipPlanes;
\r
2290 QStringList data = parameters.split( '*' );
\r
2291 Qtx::BackgroundData bgData;
\r
2292 if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
\r
2294 foreach( QString param, data ) {
\r
2295 QString paramName = param.section( '=', 0, 0 ).trimmed();
\r
2296 QString paramValue = param.section( '=', 1, 1 ).trimmed();
\r
2297 if ( paramName == "scale" ) params.scale = paramValue.toDouble();
\r
2298 else if ( paramName == "centerX" ) params.centerX = paramValue.toDouble();
\r
2299 else if ( paramName == "centerY" ) params.centerY = paramValue.toDouble();
\r
2300 else if ( paramName == "projX" ) params.projX = paramValue.toDouble();
\r
2301 else if ( paramName == "projY" ) params.projY = paramValue.toDouble();
\r
2302 else if ( paramName == "projZ" ) params.projZ = paramValue.toDouble();
\r
2303 else if ( paramName == "twist" ) params.twist = paramValue.toDouble();
\r
2304 else if ( paramName == "atX" ) params.atX = paramValue.toDouble();
\r
2305 else if ( paramName == "atY" ) params.atY = paramValue.toDouble();
\r
2306 else if ( paramName == "atZ" ) params.atZ = paramValue.toDouble();
\r
2307 else if ( paramName == "eyeX" ) params.eyeX = paramValue.toDouble();
\r
2308 else if ( paramName == "eyeY" ) params.eyeY = paramValue.toDouble();
\r
2309 else if ( paramName == "eyeZ" ) params.eyeZ = paramValue.toDouble();
\r
2310 else if ( paramName == "scaleX" ) params.scaleX = paramValue.toDouble();
\r
2311 else if ( paramName == "scaleY" ) params.scaleY = paramValue.toDouble();
\r
2312 else if ( paramName == "scaleZ" ) params.scaleZ = paramValue.toDouble();
\r
2313 else if ( paramName == "isVisible" ) params.isVisible = paramValue.toInt();
\r
2314 else if ( paramName == "size" ) params.size = paramValue.toDouble();
\r
2315 else if ( paramName.contains( "ClippingPlane" ) )
\r
2317 QStringList ClipPlaneData = paramValue.split( ';' );
\r
2318 OCCViewer_ClipPlane aPlane;
\r
2319 foreach( QString ClipPlaneParam, ClipPlaneData )
\r
2321 QString ClipPlane_paramName = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
\r
2322 QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
\r
2323 if ( ClipPlane_paramName == "Mode" )
\r
2325 aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
\r
2327 else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
\r
2328 else if ( ClipPlane_paramName == "X" ) aPlane.X = ClipPlane_paramValue.toDouble();
\r
2329 else if ( ClipPlane_paramName == "Y" ) aPlane.Y = ClipPlane_paramValue.toDouble();
\r
2330 else if ( ClipPlane_paramName == "Z" ) aPlane.Z = ClipPlane_paramValue.toDouble();
\r
2333 switch ( aPlane.Mode )
\r
2335 case OCCViewer_ClipPlane::Absolute :
\r
2336 if ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
\r
2337 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
\r
2338 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
\r
2339 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
\r
2340 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
\r
2343 case OCCViewer_ClipPlane::Relative :
\r
2344 if ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
\r
2345 else if ( ClipPlane_paramName == "Rotation1" ) aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
\r
2346 else if ( ClipPlane_paramName == "Rotation2" ) aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
\r
2351 aClipPlanes.push_back(aPlane);
\r
2353 // graduated trihedron
\r
2354 else if ( paramName == "gtIsVisible" ) params.gtIsVisible = paramValue.toInt();
\r
2355 else if ( paramName == "gtDrawNameX" ) params.gtDrawNameX = paramValue.toInt();
\r
2356 else if ( paramName == "gtDrawNameY" ) params.gtDrawNameY = paramValue.toInt();
\r
2357 else if ( paramName == "gtDrawNameZ" ) params.gtDrawNameZ = paramValue.toInt();
\r
2358 else if ( paramName == "gtNameX" ) params.gtNameX = paramValue;
\r
2359 else if ( paramName == "gtNameY" ) params.gtNameY = paramValue;
\r
2360 else if ( paramName == "gtNameZ" ) params.gtNameZ = paramValue;
\r
2361 else if ( paramName == "gtNameColorRX" ) params.gtNameColorRX = paramValue.toInt();
\r
2362 else if ( paramName == "gtNameColorGX" ) params.gtNameColorGX = paramValue.toInt();
\r
2363 else if ( paramName == "gtNameColorBX" ) params.gtNameColorBX = paramValue.toInt();
\r
2364 else if ( paramName == "gtNameColorRY" ) params.gtNameColorRY = paramValue.toInt();
\r
2365 else if ( paramName == "gtNameColorGY" ) params.gtNameColorGY = paramValue.toInt();
\r
2366 else if ( paramName == "gtNameColorBY" ) params.gtNameColorBY = paramValue.toInt();
\r
2367 else if ( paramName == "gtNameColorRZ" ) params.gtNameColorRZ = paramValue.toInt();
\r
2368 else if ( paramName == "gtNameColorGZ" ) params.gtNameColorGZ = paramValue.toInt();
\r
2369 else if ( paramName == "gtNameColorBZ" ) params.gtNameColorBZ = paramValue.toInt();
\r
2370 else if ( paramName == "gtDrawValuesX" ) params.gtDrawValuesX = paramValue.toInt();
\r
2371 else if ( paramName == "gtDrawValuesY" ) params.gtDrawValuesY = paramValue.toInt();
\r
2372 else if ( paramName == "gtDrawValuesZ" ) params.gtDrawValuesZ = paramValue.toInt();
\r
2373 else if ( paramName == "gtNbValuesX" ) params.gtNbValuesX = paramValue.toInt();
\r
2374 else if ( paramName == "gtNbValuesY" ) params.gtNbValuesY = paramValue.toInt();
\r
2375 else if ( paramName == "gtNbValuesZ" ) params.gtNbValuesZ = paramValue.toInt();
\r
2376 else if ( paramName == "gtOffsetX" ) params.gtOffsetX = paramValue.toInt();
\r
2377 else if ( paramName == "gtOffsetY" ) params.gtOffsetY = paramValue.toInt();
\r
2378 else if ( paramName == "gtOffsetZ" ) params.gtOffsetZ = paramValue.toInt();
\r
2379 else if ( paramName == "gtColorRX" ) params.gtColorRX = paramValue.toInt();
\r
2380 else if ( paramName == "gtColorGX" ) params.gtColorGX = paramValue.toInt();
\r
2381 else if ( paramName == "gtColorBX" ) params.gtColorBX = paramValue.toInt();
\r
2382 else if ( paramName == "gtColorRY" ) params.gtColorRY = paramValue.toInt();
\r
2383 else if ( paramName == "gtColorGY" ) params.gtColorGY = paramValue.toInt();
\r
2384 else if ( paramName == "gtColorBY" ) params.gtColorBY = paramValue.toInt();
\r
2385 else if ( paramName == "gtColorRZ" ) params.gtColorRZ = paramValue.toInt();
\r
2386 else if ( paramName == "gtColorGZ" ) params.gtColorGZ = paramValue.toInt();
\r
2387 else if ( paramName == "gtColorBZ" ) params.gtColorBZ = paramValue.toInt();
\r
2388 else if ( paramName == "gtDrawTickmarksX" ) params.gtDrawTickmarksX = paramValue.toInt();
\r
2389 else if ( paramName == "gtDrawTickmarksY" ) params.gtDrawTickmarksY = paramValue.toInt();
\r
2390 else if ( paramName == "gtDrawTickmarksZ" ) params.gtDrawTickmarksZ = paramValue.toInt();
\r
2391 else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
\r
2392 else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
\r
2393 else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
\r
2394 else if ( paramName == "background" ) {
\r
2395 QString bg = paramValue.replace( "$", "=" );
\r
2396 bgData = Qtx::stringToBackground( bg );
\r
2400 else // old format - "1.000e+00*0.000e+00..."
\r
2403 params.scale = data.count() > idx ? data[idx++].toDouble() : 1.0;
\r
2404 params.centerX = data.count() > idx ? data[idx++].toDouble() : 0.0;
\r
2405 params.centerY = data.count() > idx ? data[idx++].toDouble() : 0.0;
\r
2406 params.projX = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
\r
2407 params.projY = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
\r
2408 params.projZ = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
\r
2409 params.twist = data.count() > idx ? data[idx++].toDouble() : 0.0;
\r
2410 params.atX = data.count() > idx ? data[idx++].toDouble() : 0.0;
\r
2411 params.atY = data.count() > idx ? data[idx++].toDouble() : 0.0;
\r
2412 params.atZ = data.count() > idx ? data[idx++].toDouble() : 0.0;
\r
2413 params.eyeX = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
\r
2414 params.eyeY = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
\r
2415 params.eyeZ = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
\r
2416 params.scaleX = data.count() > idx ? data[idx++].toDouble() : 1.0;
\r
2417 params.scaleY = data.count() > idx ? data[idx++].toDouble() : 1.0;
\r
2418 params.scaleZ = data.count() > idx ? data[idx++].toDouble() : 1.0;
\r
2419 params.isVisible = data.count() > idx ? data[idx++].toInt() : 1;
\r
2420 params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
\r
2422 performRestoring( params );
\r
2423 setBackground( bgData );
\r
2424 myModel->setClipPlanes(aClipPlanes);
\r
2428 \brief Handle show event.
\r
2430 Emits Show() signal.
\r
2432 \param theEvent show event
\r
2434 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
\r
2436 emit Show( theEvent );
\r
2440 \brief Handle hide event.
\r
2442 Emits Hide() signal.
\r
2444 \param theEvent hide event
\r
2446 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
\r
2448 emit Hide( theEvent );
\r
2453 Creates default sketcher. [ virtual protected ]
\r
2455 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
\r
2457 if ( type == Rect )
\r
2458 return new OCCViewer_RectSketcher( this, type );
\r
2459 if ( type == Polygon )
\r
2460 return new OCCViewer_PolygonSketcher( this, type );
\r
2464 void OCCViewer_ViewWindow::initSketchers()
\r
2466 if ( mySketchers.isEmpty() )
\r
2468 mySketchers.append( createSketcher( Rect ) );
\r
2469 mySketchers.append( createSketcher( Polygon ) );
\r
2473 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
\r
2475 OCCViewer_ViewSketcher* sketcher = 0;
\r
2476 QList<OCCViewer_ViewSketcher*>::Iterator it;
\r
2477 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
\r
2479 OCCViewer_ViewSketcher* sk = (*it);
\r
2480 if ( sk->type() == typ )
\r
2487 Handles requests for sketching in the active view. [ virtual public ]
\r
2489 void OCCViewer_ViewWindow::activateSketching( int type )
\r
2491 OCCViewer_ViewPort3d* vp = getViewPort();
\r
2495 if ( !vp->isSketchingEnabled() )
\r
2498 /* Finish current sketching */
\r
2499 if ( type == NoSketching )
\r
2501 if ( mypSketcher )
\r
2503 onSketchingFinished();
\r
2504 mypSketcher->deactivate();
\r
2508 /* Activate new sketching */
\r
2511 activateSketching( NoSketching ); /* concurrency not suported */
\r
2512 mypSketcher = getSketcher( type );
\r
2513 if ( mypSketcher )
\r
2515 mypSketcher->activate();
\r
2516 onSketchingStarted();
\r
2522 Unhilights detected entities. [ virtual protected ]
\r
2524 void OCCViewer_ViewWindow::onSketchingStarted()
\r
2529 Selection by rectangle or polygon. [ virtual protected ]
\r
2531 void OCCViewer_ViewWindow::onSketchingFinished()
\r
2533 MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
\r
2534 if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
\r
2536 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
\r
2537 bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
\r
2538 switch( mypSketcher->type() )
\r
2542 QRect* aRect = (QRect*)mypSketcher->data();
\r
2545 int aLeft = aRect->left();
\r
2546 int aRight = aRect->right();
\r
2547 int aTop = aRect->top();
\r
2548 int aBottom = aRect->bottom();
\r
2549 // myRect = aRect;
\r
2552 ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
\r
2554 ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
\r
2560 QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
\r
2563 int size = aPolygon->size();
\r
2564 TColgp_Array1OfPnt2d anArray( 1, size );
\r
2566 QPolygon::Iterator it = aPolygon->begin();
\r
2567 QPolygon::Iterator itEnd = aPolygon->end();
\r
2568 for( int index = 1; it != itEnd; ++it, index++ )
\r
2570 QPoint aPoint = *it;
\r
2571 anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
\r
2575 ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
\r
2577 ic->Select( anArray, getViewPort()->getView(), Standard_False );
\r
2585 OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
\r
2586 aViewMgr->getOCCViewer()->performSelectionChanged();
\r
2590 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
\r
2592 return myViewPort;
\r
2595 bool OCCViewer_ViewWindow::transformRequested() const
\r
2597 return ( myOperation != NOTHING );
\r
2600 bool OCCViewer_ViewWindow::transformInProcess() const
\r
2602 return myEventStarted;
\r
2605 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
\r
2607 myEventStarted = bOn;
\r
2611 Set enabled state of transformation (rotate, zoom, etc)
\r
2613 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
\r
2615 if ( id != NOTHING ) myStatus.insert( id, on );
\r
2619 \return enabled state of transformation (rotate, zoom, etc)
\r
2621 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
\r
2623 return myStatus.contains( id ) ? myStatus[ id ] : true;
\r
2626 void OCCViewer_ViewWindow::onMaximizedView()
\r
2628 setMaximized(!isMaximized());
\r
2631 void OCCViewer_ViewWindow::returnTo3dView()
\r
2633 setReturnedTo3dView( true );
\r
2636 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
\r
2638 if ( !toolMgr()->action( ReturnTo3dViewId ) ||
\r
2639 toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
\r
2640 if ( !isVisible3dView )
\r
2641 toolMgr()->show( ReturnTo3dViewId );
\r
2643 toolMgr()->hide( ReturnTo3dViewId );
\r
2644 if ( isVisible3dView ) emit returnedTo3d( );
\r
2648 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
\r
2650 QAction* anAction = toolMgr()->action( MaximizedId );
\r
2651 QAction* anAction2 = toolMgr()->action( ReturnTo3dViewId );
\r
2652 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
\r
2653 if ( toMaximize ) {
\r
2654 anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
\r
2655 anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
\r
2656 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
\r
2657 anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
\r
2658 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
\r
2659 if (toSendSignal) {
\r
2660 emit maximized( this, true );
\r
2664 anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
\r
2665 anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
\r
2666 anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
\r
2667 anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
\r
2668 if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
\r
2669 if (toSendSignal) {
\r
2670 emit maximized( this, false );
\r
2675 bool OCCViewer_ViewWindow::isMaximized() const
\r
2677 return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
\r
2680 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
\r
2682 IsSketcherStyle = enable;
\r
2685 bool OCCViewer_ViewWindow::isSketcherStyle() const
\r
2687 return IsSketcherStyle;
\r
2691 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
\r
2693 my2dMode = theType;
\r
2697 QColor OCCViewer_ViewWindow::backgroundColor() const
\r
2699 return myViewPort ? myViewPort->backgroundColor() : Qt::black;
\r
2703 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
\r
2705 if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
\r
2708 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
\r
2710 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
\r
2713 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
\r
2715 if ( myViewPort ) myViewPort->setBackground( theBackground );
\r
2719 Clears view aspects
\r
2721 void OCCViewer_ViewWindow::clearViewAspects()
\r
2723 myViewAspects.clear();
\r
2727 \return const reference to list of view aspects
\r
2729 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
\r
2731 return myViewAspects;
\r
2735 Appends new view aspect
\r
2736 \param aParams - new view aspects
\r
2738 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
\r
2740 myViewAspects.append( aParams );
\r
2744 Replaces old view aspects by new ones
\r
2745 \param aViewList - list of new view aspects
\r
2747 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
\r
2749 myViewAspects = aViewList;
\r
2753 Get camera properties for the OCC view window.
\r
2754 \return shared pointer on camera properties.
\r
2756 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
\r
2758 SUIT_CameraProperties aProps;
\r
2760 Handle(V3d_View) aSourceView = getViewPort()->getView();
\r
2761 if ( aSourceView.IsNull() )
\r
2764 if ( get2dMode() == No2dMode ) {
\r
2765 aProps.setDimension( SUIT_CameraProperties::Dim3D );
\r
2768 aProps.setDimension( SUIT_CameraProperties::Dim2D );
\r
2769 aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
\r
2772 // read common properites of the view
\r
2773 Standard_Real anUp[3];
\r
2774 Standard_Real anAt[3];
\r
2775 Standard_Real anEye[3];
\r
2776 Standard_Real aProj[3];
\r
2777 Standard_Real anAxialScale[3];
\r
2779 aSourceView->Up( anUp[0], anUp[1], anUp[2] );
\r
2780 aSourceView->At( anAt[0], anAt[1], anAt[2] );
\r
2781 aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
\r
2782 getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
\r
2784 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
\r
2785 aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
\r
2787 #if OCC_VERSION_LARGE > 0x06070100
\r
2788 aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
\r
2790 // store camera properties "as is": it is up to synchronized
\r
2791 // view classes to provide necessary property conversion.
\r
2792 aProps.setPosition( anEye[0], anEye[1], anEye[2] );
\r
2793 aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
\r
2795 if ( aSourceView->Camera()->IsOrthographic() )
\r
2797 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
\r
2798 aProps.setViewAngle( 0.0 );
\r
2802 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
\r
2803 aProps.setViewAngle( aSourceView->Camera()->FOVy() );
\r
2805 aProps.setMappingScale( aSourceView->Camera()->Scale() );
\r
2807 Standard_Real aCameraDepth = aSourceView->Depth() + aSourceView->ZSize() * 0.5;
\r
2809 // generate view orientation matrix for transforming OCC projection reference point
\r
2810 // into a camera (eye) position.
\r
2811 gp_Dir aLeftDir = gp_Dir( anUp[0], anUp[1], anUp[2] ) ^ gp_Dir( aProj[0], aProj[1], aProj[2] );
\r
2814 aTrsf.SetValue( 1, 1, aLeftDir.X() );
\r
2815 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
\r
2816 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
\r
2818 aTrsf.SetValue( 1, 2, anUp[0] );
\r
2819 aTrsf.SetValue( 2, 2, anUp[1] );
\r
2820 aTrsf.SetValue( 3, 2, anUp[2] );
\r
2822 aTrsf.SetValue( 1, 3, aProj[0] );
\r
2823 aTrsf.SetValue( 2, 3, aProj[1] );
\r
2824 aTrsf.SetValue( 3, 3, aProj[2] );
\r
2826 aTrsf.SetValue( 1, 4, anAt[0] );
\r
2827 aTrsf.SetValue( 2, 4, anAt[1] );
\r
2828 aTrsf.SetValue( 3, 4, anAt[2] );
\r
2830 Graphic3d_Vertex aProjRef = aSourceView->ViewMapping().ProjectionReferencePoint();
\r
2832 // transform to world-space coordinate system
\r
2833 gp_XYZ aPosition( aProjRef.X(), aProjRef.Y(), aCameraDepth );
\r
2834 aTrsf.Transforms( aPosition );
\r
2836 // compute focal point
\r
2837 double aFocalPoint[3];
\r
2839 aFocalPoint[0] = aPosition.X() - aProj[0] * aCameraDepth;
\r
2840 aFocalPoint[1] = aPosition.Y() - aProj[1] * aCameraDepth;
\r
2841 aFocalPoint[2] = aPosition.Z() - aProj[2] * aCameraDepth;
\r
2843 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
\r
2844 aProps.setPosition( aPosition.X(), aPosition.Y(), aPosition.Z() );
\r
2846 Standard_Real aViewScale[2];
\r
2847 aSourceView->Size( aViewScale[0], aViewScale[1] );
\r
2848 aProps.setMappingScale( aViewScale[1] );
\r
2855 Synchronize views.
\r
2856 This implementation synchronizes OCC view's camera propreties.
\r
2858 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
\r
2860 bool blocked = blockSignals( true );
\r
2862 SUIT_CameraProperties aProps = theView->cameraProperties();
\r
2863 if ( !cameraProperties().isCompatible( aProps ) ) {
\r
2864 // other view, this one is being currently synchronized to, seems has become incompatible
\r
2865 // we have to break synchronization
\r
2866 updateSyncViews();
\r
2870 Handle(V3d_View) aDestView = getViewPort()->getView();
\r
2872 aDestView->SetImmediateUpdate( Standard_False );
\r
2874 double anUpDir[3];
\r
2875 double aPosition[3];
\r
2876 double aFocalPoint[3];
\r
2877 double anAxialScale[3];
\r
2879 // get common properties
\r
2880 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
\r
2881 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
\r
2882 aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
\r
2883 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
\r
2885 #if OCC_VERSION_LARGE > 0x06070100
\r
2886 aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
\r
2887 aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
\r
2888 aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
\r
2889 aDestView->Camera()->SetScale( aProps.getMappingScale() );
\r
2891 gp_Dir aProjDir( aPosition[0] - aFocalPoint[0],
\r
2892 aPosition[1] - aFocalPoint[1],
\r
2893 aPosition[2] - aFocalPoint[2] );
\r
2895 // get custom view translation
\r
2896 Standard_Real aTranslation[3];
\r
2897 aDestView->At( aTranslation[0], aTranslation[1], aTranslation[2] );
\r
2899 gp_Dir aLeftDir = gp_Dir( anUpDir[0], anUpDir[1], anUpDir[2] )
\r
2900 ^ gp_Dir( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
\r
2903 aTrsf.SetValue( 1, 1, aLeftDir.X() );
\r
2904 aTrsf.SetValue( 2, 1, aLeftDir.Y() );
\r
2905 aTrsf.SetValue( 3, 1, aLeftDir.Z() );
\r
2907 aTrsf.SetValue( 1, 2, anUpDir[0] );
\r
2908 aTrsf.SetValue( 2, 2, anUpDir[1] );
\r
2909 aTrsf.SetValue( 3, 2, anUpDir[2] );
\r
2911 aTrsf.SetValue( 1, 3, aProjDir.X() );
\r
2912 aTrsf.SetValue( 2, 3, aProjDir.Y() );
\r
2913 aTrsf.SetValue( 3, 3, aProjDir.Z() );
\r
2915 aTrsf.SetValue( 1, 4, aTranslation[0] );
\r
2916 aTrsf.SetValue( 2, 4, aTranslation[1] );
\r
2917 aTrsf.SetValue( 3, 4, aTranslation[2] );
\r
2920 // transform to view-space coordinate system
\r
2921 gp_XYZ aProjRef( aPosition[0], aPosition[1], aPosition[2] );
\r
2922 aTrsf.Transforms( aProjRef );
\r
2924 // set view camera properties using low-level approach. this is done
\r
2925 // in order to avoid interference with static variables in v3d view used
\r
2926 // when rotation is in process in another view.
\r
2927 Visual3d_ViewMapping aMapping = aDestView->View()->ViewMapping();
\r
2928 Visual3d_ViewOrientation anOrientation = aDestView->View()->ViewOrientation();
\r
2930 Graphic3d_Vector aMappingProj( aProjDir.X(), aProjDir.Y(), aProjDir.Z() );
\r
2931 Graphic3d_Vector aMappingUp( anUpDir[0], anUpDir[1], anUpDir[2] );
\r
2933 aMappingProj.Normalize();
\r
2934 aMappingUp.Normalize();
\r
2936 anOrientation.SetViewReferencePlane( aMappingProj );
\r
2937 anOrientation.SetViewReferenceUp( aMappingUp );
\r
2939 aDestView->SetViewMapping( aMapping );
\r
2940 aDestView->SetViewOrientation( anOrientation );
\r
2943 aDestView->SetCenter( aProjRef.X(), aProjRef.Y() );
\r
2945 // set mapping scale
\r
2946 double aMapScaling = aProps.getMappingScale();
\r
2947 Standard_Real aWidth, aHeight;
\r
2948 aDestView->Size( aWidth, aHeight );
\r
2949 aDestView->SetSize ( aWidth > aHeight ? aMapScaling * (aWidth / aHeight) : aMapScaling );
\r
2952 getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
\r
2954 aDestView->ZFitAll();
\r
2955 aDestView->SetImmediateUpdate( Standard_True );
\r
2956 aDestView->Redraw();
\r
2958 blockSignals( blocked );
\r
2962 \brief Indicates whether preselection is enabled
\r
2963 \return true if preselection is enabled
\r
2965 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
\r
2967 return myPreselectionEnabled;
\r
2971 \brief Enables/disables preselection
\r
2972 \param theIsToEnable if true - preselection will be enabled
\r
2974 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
\r
2976 onSwitchPreselection( theIsToEnable );
\r
2980 \brief Indicates whether selection is enabled
\r
2981 \return true if selection is enabled
\r
2983 bool OCCViewer_ViewWindow::isSelectionEnabled() const
\r
2985 return mySelectionEnabled;
\r
2989 \brief Enables/disables selection
\r
2990 \param theIsToEnable if true - selection will be enabled
\r
2992 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
\r
2994 onSwitchSelection( theIsToEnable );
\r
2999 \brief called if clipping operation is activated / deactivated.
\r
3001 Enables/disables clipping plane displaying.
\r
3003 \parma on action state
\r
3005 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
\r
3007 if(!myModel) return;
\r
3008 OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
\r
3011 if (!aClippingDlg) {
\r
3012 aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
\r
3013 myModel->setClippingDlg(aClippingDlg);
\r
3015 if (!aClippingDlg->isVisible())
\r
3016 aClippingDlg->show();
\r
3018 if ( aClippingDlg ) {
\r
3019 aClippingDlg->close();
\r
3020 myModel->setClippingDlg(0);
\r
3024 SUIT_ViewManager* mgr = getViewManager();
\r
3026 QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
\r
3027 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
\r
3028 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
\r
3029 QtxActionToolMgr* mgr = aViewWindow->toolMgr();
\r
3030 if(!mgr) continue;
\r
3031 QAction* a = toolMgr()->action( ClippingId );
\r
3033 if(theIsOn != a->isChecked()){
\r
3034 disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
\r
3035 a->setChecked(theIsOn);
\r
3036 connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
\r