Salome HOME
Second integration of PV3D viewer:
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewWindow.cxx
1 // Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File   : OCCViewer_ViewWindow.cxx
24 // Author :
25
26 #include "OCCViewer_ViewWindow.h"
27 #include "OCCViewer_ViewFrame.h"
28 #include "OCCViewer_ViewModel.h"
29 #include "OCCViewer_ViewPort3d.h"
30 #include "OCCViewer_ViewManager.h"
31 #include "OCCViewer_ViewSketcher.h"
32 #include "OCCViewer_CreateRestoreViewDlg.h"
33 #include "OCCViewer_ClipPlane.h"
34 #include "OCCViewer_SetRotationPointDlg.h"
35 #include "OCCViewer_AutoRotate.h"
36 #include "OCCViewer_AxialScaleDlg.h"
37 #include "OCCViewer_CubeAxesDlg.h"
38 #include "OCCViewer_ClippingDlg.h"
39 #include "OCCViewer_RayTracingDlg.h"
40 #include "OCCViewer_EnvTextureDlg.h"
41 #include "OCCViewer_LightSourceDlg.h"
42 #include "OCCViewer_Utilities.h"
43 #include "ViewerTools_ScreenScaling.h"
44
45 #include <SUIT_Desktop.h>
46 #include <SUIT_Session.h>
47 #include <SUIT_ViewManager.h>
48 #include <SUIT_Tools.h>
49 #include <SUIT_ResourceMgr.h>
50 #include <SUIT_MessageBox.h>
51 #include <SUIT_Application.h>
52
53 #include <QtxActionToolMgr.h>
54 #include <QtxMultiAction.h>
55 #include <QtxRubberBand.h>
56
57 #include <QPainter>
58 #include <QTime>
59 #include <QImage>
60 #include <QKeyEvent>
61 #include <QMouseEvent>
62 #include <QApplication>
63 #include <QActionGroup>
64 #include <QMenu>
65
66 #include <AIS_ListOfInteractive.hxx>
67 #include <AIS_ListIteratorOfListOfInteractive.hxx>
68 #include <AIS_Shape.hxx>
69
70 #include <BRep_Tool.hxx>
71 #include <BRepBndLib.hxx>
72 #include <BRepGProp.hxx>
73 #include <GProp_GProps.hxx>
74 #include <TopoDS.hxx>
75
76 #include <Graphic3d_SequenceOfHClipPlane.hxx>
77 #include <Graphic3d_ClipPlane.hxx>
78 #include <OpenGl_GraphicDriver.hxx>
79 #include <OpenGLUtils_FrameBuffer.h>
80 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
81 #include <Graphic3d_MapOfStructure.hxx>
82 #include <Graphic3d_Structure.hxx>
83 #include <Graphic3d_StereoMode.hxx>
84 #include <Graphic3d_RenderingParams.hxx>
85 #include <Graphic3d_BndBox3d.hxx>
86
87 #include <V3d_Plane.hxx>
88 #include <V3d_Light.hxx>
89
90 #include <gp_Dir.hxx>
91 #include <gp_Pln.hxx>
92 #include <gp_GTrsf.hxx>
93 #include <TColgp_Array1OfPnt2d.hxx>
94
95 #include <Image_PixMap.hxx>
96
97 #include <Standard_Version.hxx>
98 #include <Standard_Failure.hxx>
99
100 #include "utilities.h"
101
102 // // OpenCV includes
103 // #include <cv.h>
104 // #include <highgui.h>
105
106 static QEvent* l_mbPressEvent = 0;
107
108 //#ifdef WIN32
109 //# include <QWindowsStyle>
110 //#endif
111
112 #ifdef __APPLE__
113 #include <OpenGL/gl.h>
114 #else
115 #include <GL/gl.h>
116 #endif
117
118 // To avoid conflict between KeyPress from the X.h (define KeyPress 2)
119 // and QEvent::KeyPress (qevent.h)
120 #ifdef KeyPress
121 #undef KeyPress
122 #endif
123
124 #ifdef KeyRelease
125 #undef KeyRelease
126 #endif
127
128
129 // Enable ray tracing features
130 #define ENABLE_RAY_TRACING
131
132 const char* imageZoomCursor[] = {
133 "32 32 3 1",
134 ". c None",
135 "a c #000000",
136 "# c #ffffff",
137 "................................",
138 "................................",
139 ".#######........................",
140 "..aaaaaaa.......................",
141 "................................",
142 ".............#####..............",
143 "...........##.aaaa##............",
144 "..........#.aa.....a#...........",
145 ".........#.a.........#..........",
146 ".........#a..........#a.........",
147 "........#.a...........#.........",
148 "........#a............#a........",
149 "........#a............#a........",
150 "........#a............#a........",
151 "........#a............#a........",
152 ".........#...........#.a........",
153 ".........#a..........#a.........",
154 ".........##.........#.a.........",
155 "........#####.....##.a..........",
156 ".......###aaa#####.aa...........",
157 "......###aa...aaaaa.......#.....",
158 ".....###aa................#a....",
159 "....###aa.................#a....",
160 "...###aa...............#######..",
161 "....#aa.................aa#aaaa.",
162 ".....a....................#a....",
163 "..........................#a....",
164 "...........................a....",
165 "................................",
166 "................................",
167 "................................",
168 "................................"};
169
170 const char* imageRotateCursor[] = {
171 "32 32 3 1",
172 ". c None",
173 "a c #000000",
174 "# c #ffffff",
175 "................................",
176 "................................",
177 "................................",
178 "................................",
179 "........#.......................",
180 ".......#.a......................",
181 "......#######...................",
182 ".......#aaaaa#####..............",
183 "........#..##.a#aa##........##..",
184 ".........a#.aa..#..a#.....##.aa.",
185 ".........#.a.....#...#..##.aa...",
186 ".........#a.......#..###.aa.....",
187 "........#.a.......#a..#aa.......",
188 "........#a.........#..#a........",
189 "........#a.........#a.#a........",
190 "........#a.........#a.#a........",
191 "........#a.........#a.#a........",
192 ".........#.........#a#.a........",
193 "........##a........#a#a.........",
194 "......##.a#.......#.#.a.........",
195 "....##.aa..##.....##.a..........",
196 "..##.aa.....a#####.aa...........",
197 "...aa.........aaa#a.............",
198 "................#.a.............",
199 "...............#.a..............",
200 "..............#.a...............",
201 "...............a................",
202 "................................",
203 "................................",
204 "................................",
205 "................................",
206 "................................"};
207
208 const char* imageCrossCursor[] = {
209   "32 32 3 1",
210   ". c None",
211   "a c #000000",
212   "# c #ffffff",
213   "................................",
214   "................................",
215   "................................",
216   "................................",
217   "................................",
218   "................................",
219   "................................",
220   "...............#................",
221   "...............#a...............",
222   "...............#a...............",
223   "...............#a...............",
224   "...............#a...............",
225   "...............#a...............",
226   "...............#a...............",
227   "...............#a...............",
228   ".......#################........",
229   "........aaaaaaa#aaaaaaaaa.......",
230   "...............#a...............",
231   "...............#a...............",
232   "...............#a...............",
233   "...............#a...............",
234   "...............#a...............",
235   "...............#a...............",
236   "...............#a...............",
237   "................a...............",
238   "................................",
239   "................................",
240   "................................",
241   "................................",
242   "................................",
243   "................................",
244   "................................"};
245
246
247   /*!
248   \brief Constructor
249   \param theDesktop main window of application
250   \param theModel OCC 3D viewer
251 */
252 OCCViewer_ViewWindow::OCCViewer_ViewWindow( SUIT_Desktop*     theDesktop,
253                                             OCCViewer_Viewer* theModel )
254 : SUIT_ViewWindow( theDesktop )
255 , myAutoRotate( 0 )
256 {
257   myModel = theModel;
258   myRestoreFlag = 0;
259   myEnableDrawMode = false;
260   myDrawRectEnabled = true;
261   myDrawRect=false;
262   updateEnabledDrawMode();
263   myScalingDlg = 0;
264   mySetRotationPointDlg = 0;
265   myRectBand = 0;
266
267   IsSketcherStyle = false;
268   myIsKeyFree = false;
269
270   mypSketcher = 0;
271   myCurSketch = -1;
272   my2dMode = No2dMode;
273
274   myInteractionStyle = SUIT_ViewModel::STANDARD;
275   myPreselectionEnabled = true;
276   mySelectionEnabled = true;
277
278   myCursorIsHand = false;
279   myPanningByBtn = false;
280   myAutomaticZoom = true;
281
282   clearViewAspects();
283 }
284
285 /*!
286   \brief Destructor.
287 */
288 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
289 {
290   if (myAutoRotate) delete myAutoRotate;
291   endDrawRect();
292   qDeleteAll( mySketchers );
293 }
294
295 /*!
296   \brief Internal initialization.
297 */
298 void OCCViewer_ViewWindow::initLayout()
299 {
300   myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
301   myViewPort->installEventFilter(this);
302   setCentralWidget(myViewPort);
303   myOperation = NOVIEWOP;
304
305   myCurrPointType = BBCENTER;
306   myPrevPointType = BBCENTER;
307   mySelectedPoint = gp_Pnt(0.,0.,0.);
308   myRotationPointSelection = false;
309
310   setTransformRequested ( NOVIEWOP );
311   setTransformInProcess ( false );
312
313   createActions();
314   createToolBar();
315
316   switch (my2dMode) {
317   case XYPlane:
318     onTopView();
319     break;
320   case XZPlane:
321     onLeftView();
322     break;
323   case YZPlane:
324     onFrontView();
325     break;
326   default:
327     break;
328   }
329
330   // Graduated axes dialog
331   QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
332   myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
333   myCubeAxesDlg->initialize();
334
335   connect( myViewPort, SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), this, SLOT( emitViewModified() ) );
336 }
337
338 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
339 {
340   return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
341 }
342
343 /*!
344   \brief Detect viewer operation according the the mouse button pressed
345   and key modifiers used.
346   \param theEvent mouse event
347   \return type of the operation
348 */
349 OCCViewer_ViewWindow::OperationType
350 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
351 {
352   OperationType aOp = NOVIEWOP;
353   SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
354   if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
355       (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
356     aOp = ZOOMVIEW;
357   else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
358            (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
359     aOp = PANVIEW;
360   else if( (theEvent->modifiers()  == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
361            (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
362            (my2dMode == No2dMode))
363     aOp = ROTATE;
364
365   return aOp;
366 }
367
368 /*!
369   \brief Customize event handling
370   \param watched event receiver object
371   \param e event
372   \return \c true if the event processing should be stopped
373 */
374 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
375 {
376   if ( watched == myViewPort ) {
377     // Makes a copy event with updated coordinates if we need so
378     e = ViewerTools_ScreenScaling::getDpiAwareEvent(e);
379
380     int aType = e->type();
381     switch(aType) {
382     case QEvent::MouseButtonPress:
383       vpMousePressEvent((QMouseEvent*) e);
384       return true;
385
386     case QEvent::MouseButtonRelease:
387       vpMouseReleaseEvent((QMouseEvent*) e);
388       return true;
389
390     case QEvent::MouseMove:
391       vpMouseMoveEvent((QMouseEvent*) e);
392       return true;
393
394     case QEvent::MouseButtonDblClick:
395       emit mouseDoubleClicked(this, (QMouseEvent*)e);
396       return true;
397
398     case QEvent::Wheel:
399       {
400         QWheelEvent* aEvent = (QWheelEvent*) e;
401
402         if ( aEvent->modifiers().testFlag(Qt::ControlModifier) ) {
403           Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
404           if ( isPreselectionEnabled() ) {
405             if ( aEvent->delta() > 0 ) {
406               ic->HilightNextDetected( myViewPort->getView() );
407             } else {
408               ic->HilightPreviousDetected( myViewPort->getView() );
409             }
410           }
411         }
412         else {
413           emit vpTransformationStarted ( ZOOMVIEW );
414           myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
415           double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
416           int x  = aEvent->x();
417           int y  = aEvent->y();
418           int x1 = (int)( aEvent->x() + width()*delta/100 );
419           int y1 = (int)( aEvent->y() + height()*delta/100 );
420           myViewPort->zoom( x, y, x1, y1 );
421           emit vpTransformationFinished ( ZOOMVIEW );
422         }
423       }
424       return true;
425
426     case QEvent::ContextMenu:
427       {
428         QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
429         if ( aEvent->reason() != QContextMenuEvent::Mouse )
430           emit contextMenuRequested( aEvent );
431       }
432       return true;
433
434     case QEvent::KeyPress:
435       emit keyPressed(this, (QKeyEvent*) e);
436       return true;
437
438     case QEvent::KeyRelease:
439       emit keyReleased(this, (QKeyEvent*) e);
440       return true;
441
442     default:
443       break;
444     }
445   }
446   return SUIT_ViewWindow::eventFilter(watched, e);
447 }
448
449 /*!
450   \brief Enable / disable draw rect (rubber band) mode
451 */
452 bool OCCViewer_ViewWindow::enableDrawMode( bool on )
453 {
454   bool prev = myDrawRectEnabled;
455   myDrawRectEnabled = on;
456   updateEnabledDrawMode();
457   return prev;
458 }
459
460 /*!
461   \brief Update state of enable draw mode state.
462 */
463 void OCCViewer_ViewWindow::updateEnabledDrawMode()
464 {
465   myEnableDrawMode = myDrawRectEnabled;
466   if ( myModel )
467     myEnableDrawMode = myEnableDrawMode && myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
468 }
469
470 /*!
471   \brief Handle mouse press event
472   \param theEvent mouse event
473 */
474 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
475 {
476   myStartX = theEvent->x();
477   myStartY = theEvent->y();
478   myStartTime = QDateTime::currentMSecsSinceEpoch();
479   int anInteractionStyle = interactionStyle();
480
481   // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
482   // which are assigned for pan and rotate - these operations are activated immediately after pressing
483   // of the first button, so it is necessary to switch to zoom when the second button is pressed
484   bool aSwitchToZoom = false;
485   if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
486        ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
487     aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
488   }
489
490   switch ( myOperation ) {
491   case WINDOWFIT:
492     if ( theEvent->button() == Qt::LeftButton )
493       emit vpTransformationStarted ( WINDOWFIT );
494     break;
495
496   case PANGLOBAL:
497     if ( theEvent->button() == Qt::LeftButton )
498       emit vpTransformationStarted ( PANGLOBAL );
499     break;
500
501   case ZOOMVIEW:
502     if ( theEvent->button() == Qt::LeftButton ) {
503       myViewPort->startZoomAtPoint( myStartX, myStartY );
504       emit vpTransformationStarted ( ZOOMVIEW );
505     }
506     break;
507
508   case PANVIEW:
509     if ( aSwitchToZoom ) {
510       myViewPort->startZoomAtPoint( myStartX, myStartY );
511       activateZoom();
512     }
513     else if ( theEvent->button() == Qt::LeftButton )
514       emit vpTransformationStarted ( PANVIEW );
515     break;
516
517   case ROTATE:
518     if ( aSwitchToZoom ) {
519       myViewPort->startZoomAtPoint( myStartX, myStartY );
520       activateZoom();
521     }
522     else if ( theEvent->button() == Qt::LeftButton ) {
523       myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
524       emit vpTransformationStarted ( ROTATE );
525       emit vpStartRotate(myStartX, myStartY, myStartTime);
526     }
527     break;
528
529   default:
530   /*  Try to activate a transformation */
531     OperationType aState;
532     if ( interactionStyle() == SUIT_ViewModel::STANDARD )
533       aState = getButtonState(theEvent, anInteractionStyle);
534     else {
535       aState = OCCViewer_ViewWindow::NOVIEWOP;
536       myIsKeyFree = true;
537     }
538     switch ( aState ) {
539     case ZOOMVIEW:
540       myViewPort->startZoomAtPoint( myStartX, myStartY );
541       activateZoom();
542       break;
543     case PANVIEW:
544       activatePanning();
545       break;
546     case ROTATE:
547       activateRotation();
548       myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
549       emit vpStartRotate(myStartX, myStartY, myStartTime);
550       break;
551     default:
552       if ( myRotationPointSelection )
553       {
554         if ( theEvent->button() == Qt::LeftButton )
555         {
556           Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
557           ic->Select( Standard_True );
558           for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
559           {
560             TopoDS_Shape aShape = ic->SelectedShape();
561             GProp_GProps aSystem;
562             gp_Pnt aPnt;
563             if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
564             {
565               aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
566             }
567             else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE )
568             {
569               BRepGProp::LinearProperties( aShape, aSystem );
570               aPnt = aSystem.CentreOfMass();
571             }
572             else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_FACE )
573             {
574               BRepGProp::SurfaceProperties( aShape, aSystem );
575               aPnt = aSystem.CentreOfMass();
576             }
577             else if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID )
578             {
579               BRepGProp::VolumeProperties( aShape, aSystem );
580               aPnt = aSystem.CentreOfMass();
581             }
582             else
583             {
584               myCurrPointType = myPrevPointType;
585               break;
586             }
587
588             if ( mySetRotationPointDlg )
589             {
590               myRotationPointSelection = false;
591               mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
592             }
593           }
594           if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
595           if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
596           ic->Deactivate();
597           ic->Activate(0);
598           myOperation = NOVIEWOP;
599           myViewPort->setCursor( myCursor );
600           myCursorIsHand = false;
601           myRotationPointSelection = false;
602         }
603       }
604       else
605         emit mousePressed(this, theEvent);
606       break;
607     }
608     /* notify that we start a transformation */
609     if ( transformRequested() )
610       emit vpTransformationStarted ( myOperation );
611   }
612   if ( transformRequested() )
613     setTransformInProcess( true );
614
615   /* we may need it for sketching... */
616   if ( l_mbPressEvent )
617     delete l_mbPressEvent;
618   l_mbPressEvent = new QMouseEvent( *theEvent );
619 }
620
621
622 /*!
623   \brief Start zooming operation.
624
625   Sets the corresponding cursor for the widget.
626 */
627 void OCCViewer_ViewWindow::activateZoom()
628 {
629   if ( !transformRequested() && !myCursorIsHand )
630     saveCursor();                /* save old cursor */
631
632   if ( myOperation != ZOOMVIEW ) {
633     QPixmap zoomPixmap (imageZoomCursor);
634     QCursor zoomCursor (zoomPixmap);
635     if( setTransformRequested ( ZOOMVIEW ) )
636       myViewPort->setCursor( zoomCursor );
637   }
638 }
639
640
641 void OCCViewer_ViewWindow::onPanning()
642 {
643   OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( getViewManager() );
644   bool isChained = aMgr->isChainedOperations();
645   bool isReset = ( myPanningByBtn && isChained );
646   if( isReset )
647   {
648     resetState();
649   }
650   else
651   {
652     myPanningByBtn = true;
653     activatePanning();
654   }
655 }
656
657 /*!
658   \brief Start panning operation.
659
660   Sets the corresponding cursor for the widget.
661 */
662 void OCCViewer_ViewWindow::activatePanning()
663 {
664   if ( !transformRequested() && !myCursorIsHand )
665     saveCursor();                // save old cursor
666
667   if ( myOperation != PANVIEW ) {
668     QCursor panCursor (Qt::SizeAllCursor);
669     if( setTransformRequested ( PANVIEW ) )
670       myViewPort->setCursor( panCursor );
671   }
672 }
673
674 /*!
675   \brief Start rotation operation
676
677   Sets the corresponding cursor for the widget.
678 */
679 void OCCViewer_ViewWindow::activateRotation()
680 {
681   if ( !transformRequested() && !myCursorIsHand )
682     saveCursor();                // save old cursor
683
684   if ( myOperation != ROTATE ) {
685     QPixmap rotatePixmap (imageRotateCursor);
686     QCursor rotCursor (rotatePixmap);
687     if( setTransformRequested ( ROTATE ) )
688       myViewPort->setCursor( rotCursor );
689   }
690 }
691
692 /*!
693   \brief Compute the gravity center.
694   \param theX used to return X coordinate of the gravity center
695   \param theY used to return Y coordinate of the gravity center
696   \param theZ used to return Z coordinate of the gravity center
697   \return \c true if the gravity center is computed
698 */
699 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
700 {
701   Handle(V3d_View) aView3d = myViewPort->getView();
702
703   // Project boundaries points and add to avergae gravity
704   // the ones which lie within the screen limits
705   Standard_Real aScreenLimits[4] = { 0.0, 0.0, 0.0, 0.0 };
706
707   // NDC space screen limits
708   aScreenLimits[0] = -1.0;
709   aScreenLimits[1] =  1.0;
710   aScreenLimits[2] = -1.0;
711   aScreenLimits[3] =  1.0;
712
713   Standard_Integer aPointsNb = 0;
714
715   Standard_Real aXmin = 0.0;
716   Standard_Real aYmin = 0.0;
717   Standard_Real aZmin = 0.0;
718   Standard_Real aXmax = 0.0;
719   Standard_Real aYmax = 0.0;
720   Standard_Real aZmax = 0.0;
721
722   Graphic3d_MapOfStructure aSetOfStructures;
723   aView3d->View()->DisplayedStructures( aSetOfStructures );
724   Graphic3d_MapIteratorOfMapOfStructure aStructureIt( aSetOfStructures );
725
726   for( ; aStructureIt.More(); aStructureIt.Next() ) {
727     const Handle(Graphic3d_Structure)& aStructure = aStructureIt.Key();
728     if ( aStructure->IsEmpty() || !aStructure->IsVisible() || aStructure->CStructure()->IsForHighlight )
729       continue;
730
731     const Graphic3d_BndBox3d& aBox = aStructure->CStructure()->BoundingBox();
732     if (!aBox.IsValid())
733       continue;
734     aXmin = /*aBox.IsVoid() ? RealFirst() : */aBox.CornerMin().x();
735     aYmin = /*aBox.IsVoid() ? RealFirst() : */aBox.CornerMin().y();
736     aZmin = /*aBox.IsVoid() ? RealFirst() : */aBox.CornerMin().z();
737     aXmax = /*aBox.IsVoid() ? RealLast()  : */aBox.CornerMax().x();
738     aYmax = /*aBox.IsVoid() ? RealLast()  : */aBox.CornerMax().y();
739     aZmax = /*aBox.IsVoid() ? RealLast()  : */aBox.CornerMax().z();
740
741     // Infinite structures are skipped
742     Standard_Real aLIM = ShortRealLast() - 1.0;
743     if ( Abs( aXmin ) > aLIM || Abs( aYmin ) > aLIM || Abs( aZmin ) > aLIM
744       || Abs( aXmax ) > aLIM || Abs( aYmax ) > aLIM || Abs( aZmax ) > aLIM ) {
745       continue;
746     }
747
748     gp_Pnt aPoints[8] = {
749       gp_Pnt( aXmin, aYmin, aZmin ), gp_Pnt( aXmin, aYmin, aZmax ),
750       gp_Pnt( aXmin, aYmax, aZmin ), gp_Pnt( aXmin, aYmax, aZmax ),
751       gp_Pnt( aXmax, aYmin, aZmin ), gp_Pnt( aXmax, aYmin, aZmax ),
752       gp_Pnt( aXmax, aYmax, aZmin ), gp_Pnt( aXmax, aYmax, aZmax )
753     };
754
755     for ( Standard_Integer aPointIt = 0; aPointIt < 8; ++aPointIt ) {
756       const gp_Pnt& aBBPoint = aPoints[aPointIt];
757
758       gp_Pnt aProjected = aView3d->Camera()->Project( aBBPoint );
759       const Standard_Real& U = aProjected.X();
760       const Standard_Real& V = aProjected.Y();
761
762       if (U >= aScreenLimits[0]
763        && U <= aScreenLimits[1]
764        && V >= aScreenLimits[2]
765        && V <= aScreenLimits[3])
766       {
767         aPointsNb++;
768         theX += aBBPoint.X();
769         theY += aBBPoint.Y();
770         theZ += aBBPoint.Z();
771       }
772     }
773   }
774
775   if ( aPointsNb > 0 )
776   {
777     theX /= aPointsNb;
778     theY /= aPointsNb;
779     theZ /= aPointsNb;
780     return true;
781   }
782   else
783     return false;
784 }
785
786 /*!
787   \brief Set the gravity center as a rotation point.
788 */
789 void OCCViewer_ViewWindow::activateSetRotationGravity()
790 {
791   if ( myRotationPointSelection )
792   {
793     Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
794     ic->Deactivate();
795     ic->Activate(0);
796     myOperation = NOVIEWOP;
797     myViewPort->setCursor( myCursor );
798     myCursorIsHand = false;
799     myRotationPointSelection = false;
800   }
801
802   myPrevPointType = myCurrPointType;
803   myCurrPointType = BBCENTER;
804
805   Standard_Real Xcenter, Ycenter, Zcenter;
806   if ( OCCViewer_Utilities::computeVisibleBBCenter( myViewPort->getView(), Xcenter, Ycenter, Zcenter ) )
807     mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
808 }
809
810 /*!
811   \brief Update gravity center in the "Set Rotation Point" dialog box.
812   \sa OCCViewer_SetRotationPointDlg class
813 */
814 void OCCViewer_ViewWindow::updateGravityCoords()
815 {
816   if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == BBCENTER )
817   {
818     Standard_Real Xcenter, Ycenter, Zcenter;
819     if ( OCCViewer_Utilities::computeVisibleBBCenter( myViewPort->getView(), Xcenter, Ycenter, Zcenter ) )
820       mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
821   }
822 }
823
824 /*!
825   \brief Set the point selected by the user as a rotation point.
826   \param theX X coordinate of the rotation point
827   \param theY Y coordinate of the rotation point
828   \param theZ Z coordinate of the rotation point
829 */
830 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
831 {
832   if ( myRotationPointSelection )
833   {
834     Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
835     ic->Deactivate();
836     ic->Activate(0);
837     myOperation = NOVIEWOP;
838     myViewPort->setCursor( myCursor );
839     myCursorIsHand = false;
840     myRotationPointSelection = false;
841   }
842
843   myPrevPointType = myCurrPointType;
844   myCurrPointType = SELECTED;
845   mySelectedPoint.SetCoord(theX,theY,theZ);
846 }
847
848 /*!
849   \brief Start the shape selection process.
850 */
851 void OCCViewer_ViewWindow::activateStartPointSelection( TopAbs_ShapeEnum theShapeType )
852 {
853   myPrevPointType = myCurrPointType;
854   myCurrPointType = SELECTED;
855
856   // activate selection ------>
857   Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
858   ic->Deactivate();
859
860   AIS_ListOfInteractive aList;
861   ic->DisplayedObjects( aList );
862   for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
863   {
864     Handle(AIS_InteractiveObject) anObj = it.Value();
865     if ( !anObj.IsNull() && anObj->HasPresentation() &&
866          anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
867     {
868       ic->Load(anObj,-1);
869       ic->Activate(anObj,AIS_Shape::SelectionMode(theShapeType));
870      }
871   }
872   // activate selection <------
873
874   if ( !myCursorIsHand )
875   {
876     QCursor handCursor (Qt::PointingHandCursor);
877     myCursorIsHand = true;
878     saveCursor();
879     myViewPort->setCursor( handCursor );
880   }
881   myRotationPointSelection = true;
882 }
883
884 /*!
885   \brief Start global panning operation
886
887   Sets the corresponding cursor for the widget.
888 */
889 void OCCViewer_ViewWindow::activateGlobalPanning()
890 {
891   Handle(V3d_View) aView3d = myViewPort->getView();
892   if ( !aView3d.IsNull() ) {
893     QPixmap globalPanPixmap (imageCrossCursor);
894     QCursor glPanCursor (globalPanPixmap);
895     myCurScale = aView3d->Scale();
896     aView3d->FitAll(0.01, false);
897     saveCursor();                // save old cursor
898     myViewPort->fitAll(); // fits view before selecting a new scene center
899     if( setTransformRequested( PANGLOBAL ) )
900       myViewPort->setCursor( glPanCursor );
901   }
902 }
903
904 /*!
905   \brief Starts fit operation.
906
907   Sets the corresponding cursor for the widget.
908 */
909 void OCCViewer_ViewWindow::activateWindowFit()
910 {
911   if ( !transformRequested() && !myCursorIsHand )
912     saveCursor();                /* save old cursor */
913
914   if ( myOperation != WINDOWFIT ) {
915     QCursor handCursor (Qt::PointingHandCursor);
916     if( setTransformRequested ( WINDOWFIT ) )
917     {
918       myViewPort->setCursor ( handCursor );
919       myCursorIsHand = true;
920     }
921   }
922 }
923
924 /*!
925   \brief Start delayed viewer operation.
926 */
927 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
928 {
929   bool ok = transformEnabled( op );
930   myOperation = ok ? op : NOVIEWOP;
931   myViewPort->setMouseTracking( myOperation == NOVIEWOP );
932   return ok;
933 }
934
935 /*!
936   \brief Handle mouse move event.
937   \param theEvent mouse event
938 */
939 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
940 {
941   if ( myIsKeyFree && interactionStyle() == SUIT_ViewModel::KEY_FREE ) {
942     myIsKeyFree = false;
943     switch ( getButtonState( theEvent, interactionStyle() ) ) {
944     case ZOOMVIEW:
945       myViewPort->startZoomAtPoint( myStartX, myStartY );
946       activateZoom();
947       break;
948     case PANVIEW:
949       activatePanning();
950       break;
951     case ROTATE:
952       activateRotation();
953       myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
954       emit vpStartRotate(myStartX, myStartY, myStartTime);
955       break;
956     default:
957       break;
958     }
959   }
960
961   myCurrX = theEvent->x();
962   myCurrY = theEvent->y();
963   myCurrTime = QDateTime::currentMSecsSinceEpoch();
964   switch (myOperation) {
965   case ROTATE:
966     myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
967     emit vpRotate(myCurrX, myCurrY, myCurrTime);
968     break;
969
970   case ZOOMVIEW:
971     myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
972     myStartX = myCurrX;
973     myStartY = myCurrY;
974     break;
975
976   case PANVIEW:
977     myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
978     myStartX = myCurrX;
979     myStartY = myCurrY;
980     break;
981
982 /*    case WINDOWFIT:
983     myDrawRect = true;
984     repaint();
985     break;
986 */
987   case PANGLOBAL:
988     break;
989
990   default:
991     if ( myRotationPointSelection || isSketcherStyle() )
992     {
993       emit mouseMoving( this, theEvent );
994     }
995     else
996     {
997       int aState = theEvent->modifiers();
998       int aButton = theEvent->buttons();
999       int anInteractionStyle = interactionStyle();
1000       if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
1001            aButton == Qt::LeftButton && ( aState == Qt::NoModifier || aState == Qt::ShiftModifier ) ) ||
1002          ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
1003          aButton == Qt::LeftButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
1004         myDrawRect = myEnableDrawMode;
1005         if ( myDrawRect ) {
1006           //drawRect();
1007           //if ( !myCursorIsHand )        {   // we are going to sketch a rectangle
1008           //  QCursor handCursor (Qt::PointingHandCursor);
1009           //  myCursorIsHand = true;
1010           //  saveCursor();
1011           //  myViewPort->setCursor( handCursor );
1012           //}
1013           if (!mypSketcher) {
1014             SelectionStyle aStyle = selectionStyle();
1015             activateSketching(aStyle == RectStyle ? Rect : Polygon);
1016           }
1017           if (mypSketcher) {
1018             if (l_mbPressEvent) {
1019               QApplication::sendEvent(getViewPort(), l_mbPressEvent);
1020               delete l_mbPressEvent;
1021               l_mbPressEvent = 0;
1022             }
1023             QApplication::sendEvent(getViewPort(), theEvent);
1024           }
1025         }
1026         emit mouseMoving( this, theEvent );
1027       }
1028       //else if ( ( anInteractionStyle == SUIT_ViewModel::STANDARD &&
1029       //          aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
1030       //          ( anInteractionStyle == SUIT_ViewModel::KEY_FREE &&
1031       //          aButton == Qt::RightButton && ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
1032       //  OCCViewer_ViewSketcher* sketcher = 0;
1033       //  QList<OCCViewer_ViewSketcher*>::Iterator it;
1034       //  for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
1035       //  {
1036       //    OCCViewer_ViewSketcher* sk = (*it);
1037       //    if( sk->isDefault() && sk->sketchButton() == aButton )
1038       //      sketcher = sk;
1039       //  }
1040       //  if ( sketcher && myCurSketch == -1 )
1041       //  {
1042       //    activateSketching( sketcher->type() );
1043       //    if ( mypSketcher )
1044       //    {
1045       //      myCurSketch = mypSketcher->sketchButton();
1046
1047       //      if ( l_mbPressEvent )
1048       //      {
1049       //        QApplication::sendEvent( getViewPort(), l_mbPressEvent );
1050       //        delete l_mbPressEvent;
1051       //        l_mbPressEvent = 0;
1052       //      }
1053       //      QApplication::sendEvent( getViewPort(), theEvent );
1054       //    }
1055       //  }
1056       //}
1057       else
1058         emit mouseMoving( this, theEvent );
1059     }
1060   }
1061 }
1062
1063 /*!
1064   \brief Handle mouse release event.
1065   \param theEvent mouse event
1066 */
1067 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
1068 {
1069   switch ( myOperation ) {
1070   case NOVIEWOP:
1071     {
1072       int prevState = myCurSketch;
1073       if(theEvent->button() == Qt::RightButton)
1074       {
1075         QList<OCCViewer_ViewSketcher*>::Iterator it;
1076         for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
1077         {
1078           OCCViewer_ViewSketcher* sk = (*it);
1079           if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
1080             myCurSketch = -1;
1081         }
1082       }
1083
1084       emit mouseReleased(this, theEvent);
1085       if(theEvent->button() == Qt::RightButton && prevState == -1)
1086       {
1087         // We need to pass unscaled coordinates to get a menu painted in a right place.
1088         const double pixelRatio = ViewerTools_ScreenScaling::getPR();
1089         QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1090                                   theEvent->pos() / pixelRatio, theEvent->globalPos() / pixelRatio );
1091         emit contextMenuRequested( &aEvent );
1092       }
1093     }
1094     break;
1095   case ROTATE:
1096     myCurrX = theEvent->x();
1097     myCurrY = theEvent->y(),
1098     myCurrTime = QDateTime::currentMSecsSinceEpoch();
1099     myViewPort->endRotation();
1100     emit vpEndRotate(myCurrX, myCurrY, myCurrTime);
1101     resetState();
1102     break;
1103
1104   case PANVIEW:
1105   case ZOOMVIEW:
1106     {
1107       OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( getViewManager() );
1108       bool isChained = aMgr->isChainedOperations();
1109       bool isReset = !( myOperation==PANVIEW && myPanningByBtn && isChained ) || theEvent->button() == Qt::RightButton;
1110       if( isReset )
1111         resetState();
1112       break;
1113     }
1114
1115   case PANGLOBAL:
1116     if ( theEvent->button() == Qt::LeftButton ) {
1117       myViewPort->setCenter( theEvent->x(), theEvent->y() );
1118       myViewPort->getView()->SetScale(myCurScale);
1119       resetState();
1120     }
1121     break;
1122
1123   case WINDOWFIT:
1124     if ( theEvent->button() == Qt::LeftButton ) {
1125       myCurrX = theEvent->x();
1126       myCurrY = theEvent->y();
1127       drawRect();
1128       QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1129       if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
1130       endDrawRect();
1131       resetState();
1132     }
1133     break;
1134   default:
1135     break;
1136   }
1137
1138   // NOTE: viewer 3D detects a rectangle of selection using this event
1139   // so we must emit it BEFORE resetting the selection rectangle
1140
1141   if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
1142     drawRect();
1143     endDrawRect();
1144     resetState();
1145     myViewPort->update();
1146   }
1147
1148   if ( l_mbPressEvent ) {
1149     delete l_mbPressEvent;
1150     l_mbPressEvent = 0;
1151   }
1152 }
1153
1154 /*!
1155   \brief Reset the viewport to its initial state
1156   ( no transformations in process etc. )
1157 */
1158 void OCCViewer_ViewWindow::resetState()
1159 {
1160   myDrawRect = false;
1161
1162   if ( myRotationPointSelection )
1163   {
1164     QCursor handCursor (Qt::PointingHandCursor);
1165     myViewPort->setCursor( handCursor );
1166   }
1167   else
1168   {
1169     if ( transformRequested() || myCursorIsHand )
1170       myViewPort->setCursor( myCursor );
1171     myCursorIsHand = false;
1172   }
1173
1174   if ( transformRequested() )
1175     emit vpTransformationFinished (myOperation);
1176
1177   setTransformInProcess( false );
1178   setTransformRequested( NOVIEWOP );
1179
1180   myPanningByBtn = false;
1181 }
1182
1183
1184 /*!
1185   \brief Draw rubber band rectangle.
1186 */
1187 void OCCViewer_ViewWindow::drawRect()
1188 {
1189   if ( !myRectBand ) {
1190     myRectBand = new QtxRectRubberBand( myViewPort );
1191   }
1192
1193   myRectBand->setUpdatesEnabled ( false );
1194   QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
1195   myRectBand->initGeometry( aRect );
1196
1197   if ( !myRectBand->isVisible() )
1198     myRectBand->show();
1199
1200   myRectBand->setUpdatesEnabled ( true );
1201 }
1202
1203 /*!
1204   \brief Clear rubber band rectangle on the end on the dragging operation.
1205 */
1206 void OCCViewer_ViewWindow::endDrawRect()
1207 {
1208   if ( myRectBand ) {
1209     myRectBand->clearGeometry();
1210     myRectBand->hide();
1211   }
1212 }
1213
1214 /*!
1215   \brief Create actions.
1216 */
1217 void OCCViewer_ViewWindow::createActions()
1218 {
1219   if( !toolMgr()->isEmpty() )
1220     return;
1221
1222   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1223   if( !aResMgr )
1224     return;
1225
1226   QtxAction* aAction;
1227
1228   // Dump view
1229   aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
1230                            tr( "MNU_DUMP_VIEW" ), 0, this);
1231   aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1232   connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
1233   toolMgr()->registerAction( aAction, DumpId );
1234
1235   // FitAll
1236   aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
1237                            tr( "MNU_FITALL" ), 0, this);
1238   aAction->setStatusTip(tr("DSC_FITALL"));
1239   connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
1240   toolMgr()->registerAction( aAction, FitAllId );
1241
1242   // FitRect
1243   aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
1244                            tr( "MNU_FITRECT" ), 0, this);
1245   aAction->setStatusTip(tr("DSC_FITRECT"));
1246   connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
1247   toolMgr()->registerAction( aAction, FitRectId );
1248
1249   // FitSelection
1250   aAction = new QtxAction(tr("MNU_FITSELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITSELECTION" ) ),
1251                            tr( "MNU_FITSELECTION" ), 0, this);
1252   aAction->setStatusTip(tr("DSC_FITSELECTION"));
1253   connect(aAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
1254   toolMgr()->registerAction( aAction, FitSelectionId );
1255
1256   // Zoom
1257   aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
1258                            tr( "MNU_ZOOM_VIEW" ), 0, this);
1259   aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1260   connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
1261   toolMgr()->registerAction( aAction, ZoomId );
1262
1263   // Panning
1264   aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
1265                            tr( "MNU_PAN_VIEW" ), 0, this);
1266   aAction->setStatusTip(tr("DSC_PAN_VIEW"));
1267   connect(aAction, SIGNAL(triggered()), this, SLOT(onPanning()));
1268   toolMgr()->registerAction( aAction, PanId );
1269
1270   // Global Panning
1271   aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
1272                            tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1273   aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1274   connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
1275   toolMgr()->registerAction( aAction, GlobalPanId );
1276
1277   // Rotation Point
1278   mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
1279                            tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1280   mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1281   mySetRotationPointAction->setCheckable( true );
1282   connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
1283   toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
1284
1285   // Rotation
1286   aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
1287                            tr( "MNU_ROTATE_VIEW" ), 0, this);
1288   aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1289   connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
1290   toolMgr()->registerAction( aAction, RotationId );
1291
1292   // Projections
1293   aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
1294                            tr( "MNU_FRONT_VIEW" ), 0, this, false, "/#Viewers/View/Set X-");
1295   aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1296   connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
1297   this->addAction(aAction);
1298   toolMgr()->registerAction( aAction, FrontId );
1299
1300   aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
1301                            tr( "MNU_BACK_VIEW" ), 0, this, false, "/#Viewers/View/Set X+");
1302   aAction->setStatusTip(tr("DSC_BACK_VIEW"));
1303   connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
1304   this->addAction(aAction);
1305   toolMgr()->registerAction( aAction, BackId );
1306
1307   aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
1308                            tr( "MNU_TOP_VIEW" ), 0, this, false, "/#Viewers/View/Set Z-");
1309   aAction->setStatusTip(tr("DSC_TOP_VIEW"));
1310   connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
1311   this->addAction(aAction);
1312   toolMgr()->registerAction( aAction, TopId );
1313
1314   aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
1315                            tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "/#Viewers/View/Set Z+");
1316   aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1317   connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
1318   this->addAction(aAction);
1319   toolMgr()->registerAction( aAction, BottomId );
1320
1321   aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
1322                            tr( "MNU_LEFT_VIEW" ), 0, this, false, "/#Viewers/View/Set Y+");
1323   aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1324   connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
1325   this->addAction(aAction);
1326   toolMgr()->registerAction( aAction, LeftId );
1327
1328   aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
1329                            tr( "MNU_RIGHT_VIEW" ), 0, this, false, "/#Viewers/View/Set Y-");
1330   aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1331   connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
1332   this->addAction(aAction);
1333   toolMgr()->registerAction( aAction, RightId );
1334
1335   // rotate anticlockwise
1336   aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
1337                            tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "/#Viewers/View/Rotate anticlockwise");
1338   aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1339   connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1340   this->addAction(aAction);
1341   toolMgr()->registerAction( aAction, AntiClockWiseId );
1342
1343   // rotate clockwise
1344   aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
1345                            tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "/#Viewers/View/Rotate clockwise");
1346   aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1347   connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1348   this->addAction(aAction);
1349   toolMgr()->registerAction( aAction, ClockWiseId );
1350
1351   // Projection mode group
1352
1353   // - orthographic projection
1354   aAction = new QtxAction(tr("MNU_ORTHOGRAPHIC_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ORTHOGRAPHIC" ) ),
1355                           tr( "MNU_ORTHOGRAPHIC_MODE" ), 0, this);
1356   aAction->setStatusTip(tr("DSC_ORTHOGRAPHIC_MODE"));
1357   aAction->setCheckable(true);
1358   toolMgr()->registerAction( aAction, OrthographicId );
1359
1360   // - perspective projection
1361   aAction = new QtxAction(tr("MNU_PERSPECTIVE_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PERSPECTIVE" ) ),
1362                           tr( "MNU_PERSPECTIVE_MODE" ), 0, this);
1363   aAction->setStatusTip(tr("DSC_PERSPECTIVE_MODE"));
1364   aAction->setCheckable(true);
1365   toolMgr()->registerAction( aAction, PerspectiveId );
1366
1367   // - stereo projection
1368   aAction = new QtxAction(tr("MNU_STEREO_MODE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STEREO" ) ),
1369                           tr( "MNU_STEREO_MODE" ), 0, this);
1370   aAction->setStatusTip(tr("DSC_STEREO_MODE"));
1371   aAction->setCheckable(true);
1372   toolMgr()->registerAction( aAction, StereoId );
1373   connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onStereoType(bool)));
1374
1375   // - add exclusive action group
1376   QActionGroup* aProjectionGroup = new QActionGroup( this );
1377   aProjectionGroup->addAction( toolMgr()->action( OrthographicId ) );
1378   aProjectionGroup->addAction( toolMgr()->action( PerspectiveId ) );
1379   connect(aProjectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProjectionType(QAction*)));
1380
1381   // Reset
1382   aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
1383                            tr( "MNU_RESET_VIEW" ), 0, this, false, "/#Viewers/View/Reset");
1384   aAction->setStatusTip(tr("DSC_RESET_VIEW"));
1385   connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
1386   this->addAction(aAction);
1387   toolMgr()->registerAction( aAction, ResetId );
1388
1389   // Clone
1390   aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
1391                           aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
1392                           tr("MNU_CLONE_VIEW"), 0, this);
1393   aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
1394   connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
1395   toolMgr()->registerAction( aAction, CloneId );
1396
1397   aAction = new QtxAction (tr("MNU_CLIPPING"), aResMgr->loadPixmap ("OCCViewer", tr("ICON_OCCVIEWER_CLIPPING")),
1398                                       tr("MNU_CLIPPING"), 0, this);
1399   aAction->setStatusTip (tr("DSC_CLIPPING"));
1400   aAction->setCheckable (true);
1401   connect (aAction, SIGNAL (toggled (bool)), this, SLOT (onClipping (bool)));
1402   toolMgr()->registerAction (aAction, ClippingId);
1403
1404   aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
1405                            tr( "MNU_SHOOT_VIEW" ), 0, this);
1406   aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
1407   connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
1408   toolMgr()->registerAction( aAction, MemId );
1409
1410   aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
1411                            tr( "MNU_PRESETS_VIEW" ), 0, this);
1412   aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
1413   connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
1414   toolMgr()->registerAction( aAction, RestoreId );
1415
1416   if (myModel->trihedronActivated()) {
1417     aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
1418                              tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
1419     aAction->setCheckable( true );
1420     aAction->setChecked( true );
1421     aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
1422     connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onTrihedronShow(bool)));
1423     toolMgr()->registerAction( aAction, TrihedronShowId );
1424   }
1425
1426   if (myModel->viewCubeActivated()) {
1427     aAction = new QtxAction(tr("MNU_SHOW_VIEWCUBE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_VIEWCUBE" ) ),
1428                              tr( "MNU_SHOW_VIEWCUBE" ), 0, this);
1429     aAction->setCheckable( true );
1430     aAction->setChecked( aResMgr->booleanValue( "OCCViewer", "viewcube_show", true ) );
1431     aAction->setStatusTip(tr("DSC_SHOW_VIEWCUBE"));
1432     connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onViewCubeShow(bool)));
1433     toolMgr()->registerAction( aAction, ViewCubeShowId );
1434   }
1435
1436   // Scale
1437   aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1438                            tr( "MNU_SCALING" ), 0, this);
1439   aAction->setStatusTip(tr("DSC_SCALING"));
1440   connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1441   toolMgr()->registerAction( aAction, AxialScaleId );
1442
1443   // Enable/disable preselection
1444   aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1445                           tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1446   aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1447   aAction->setCheckable(true);
1448   connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1449   toolMgr()->registerAction( aAction, SwitchPreselectionId );
1450
1451   // Enable/disable selection
1452   aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1453                           tr( "MNU_ENABLE_SELECTION" ), 0, this);
1454   aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1455   aAction->setCheckable(true);
1456   connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1457   toolMgr()->registerAction( aAction, SwitchSelectionId );
1458
1459   // Graduated axes
1460   aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1461                            tr( "MNU_GRADUATED_AXES" ), 0, this);
1462   aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1463   connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1464   toolMgr()->registerAction( aAction, GraduatedAxesId );
1465
1466   // Active only ambient light or not
1467   aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1468                            tr( "MNU_AMBIENT" ), 0, this);
1469   aAction->setStatusTip(tr("DSC_AMBIENT"));
1470   connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1471   toolMgr()->registerAction( aAction, AmbientId );
1472
1473   // Switch between interaction styles
1474   aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1475                           tr( "MNU_STYLE_SWITCH" ), 0, this);
1476   aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1477   aAction->setCheckable(true);
1478   connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1479   toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1480
1481   // Switch between zooming styles
1482   aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1483                           tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1484   aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1485   aAction->setCheckable(true);
1486   connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1487   toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1488
1489   // Switch advanced selection style (poligone/circle)
1490   aAction = new QtxAction(tr("MNU_RECTANGLE_SELECTION_STYLE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RECT_STYLE" ) ),
1491                           tr( "MNU_RECTANGLE_SELECTION_STYLE" ), 0, this);
1492   aAction->setStatusTip(tr("DSC_RECTANGLE_SELECTION_STYLE"));
1493   aAction->setCheckable(true);
1494   toolMgr()->registerAction( aAction, RectangleSelectionStyleId);
1495
1496   aAction = new QtxAction(tr("MNU_POLYGON_SELECTION_STYLE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_POLY_STYLE" ) ),
1497                           tr( "MNU_POLYGON_SELECTION_STYLE" ), 0, this);
1498   aAction->setStatusTip(tr("DSC_POLYGON_SELECTION_STYLE"));
1499   aAction->setCheckable(true);
1500   toolMgr()->registerAction( aAction, PolygonSelectionStyleId);
1501
1502   aAction = new QtxAction(tr("MNU_CIRCLE_SELECTION_STYLE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CIRCLE_STYLE" ) ),
1503                           tr( "MNU_CIRCLE_SELECTION_STYLE" ), 0, this);
1504   aAction->setStatusTip(tr("DSC_CIRCLE_SELECTION_STYLE"));
1505   aAction->setCheckable(true);
1506   toolMgr()->registerAction( aAction, CircleSelectionStyleId);
1507
1508   // - add exclusive action group
1509   QActionGroup* aSelectionGroup = new QActionGroup(this);
1510   aSelectionGroup->addAction(toolMgr()->action(RectangleSelectionStyleId));
1511   aSelectionGroup->addAction(toolMgr()->action(PolygonSelectionStyleId));
1512   aSelectionGroup->addAction(toolMgr()->action(CircleSelectionStyleId));
1513   connect(aSelectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onSwitchSelectionStyle(QAction*)));
1514
1515   // Maximized view
1516   aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1517                           tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1518   aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1519   connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1520   toolMgr()->registerAction( aAction, MaximizedId );
1521
1522   // Return to 3d view
1523   if (my2dMode!=No2dMode){
1524     aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1525                             tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1526     aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1527     connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1528     toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1529   }
1530
1531   // Synchronize View
1532   toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1533 #ifdef ENABLE_RAY_TRACING
1534   // Ray tracing
1535   aAction = new QtxAction( tr("MNU_RAY_TRACING"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_RAY_TRACING") ),
1536                            tr("MNU_RAY_TRACING"), 0, this );
1537   aAction->setStatusTip( tr("DSC_RAY_TRACING") );
1538   connect( aAction, SIGNAL( triggered() ), this, SLOT( onRayTracing() ) );
1539   toolMgr()->registerAction( aAction, RayTracingId );
1540
1541   // Environment texture
1542   aAction = new QtxAction( tr("MNU_ENV_TEXTURE"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_ENV_TEXTURE") ),
1543                            tr("MNU_ENV_TEXTURE"), 0, this );
1544   aAction->setStatusTip( tr("DSC_ENV_TEXTURE") );
1545   connect( aAction, SIGNAL( triggered() ), this, SLOT( onEnvTexture() ) );
1546   toolMgr()->registerAction( aAction, EnvTextureId );
1547
1548   // Light source
1549   aAction = new QtxAction( tr("MNU_LIGHT_SOURCE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_LIGHT_SOURCE" ) ),
1550                            tr( "MNU_LIGHT_SOURCE" ), 0, this );
1551   aAction->setStatusTip( tr("DSC_LIGHT_SOURCE") );
1552   connect( aAction, SIGNAL( triggered() ), this, SLOT( onLightSource() ) );
1553   toolMgr()->registerAction( aAction, LightSourceId );
1554 #endif
1555 }
1556
1557 /*!
1558   \brief Create toolbar.
1559 */
1560 void OCCViewer_ViewWindow::createToolBar()
1561 {
1562   static const char* titles[] = {
1563     "LBL_3DTOOLBAR_LABEL",
1564     "LBL_XYTOOLBAR_LABEL",
1565     "LBL_XZTOOLBAR_LABEL",
1566     "LBL_YZTOOLBAR_LABEL",
1567   };
1568   static const char* names[] = {
1569     "OCCViewer3DViewOperations",
1570     "OCCViewerXYViewOperations",
1571     "OCCViewerXZViewOperations",
1572     "OCCViewerYZViewOperations",
1573   };
1574   int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ),        // title (language-dependant)
1575                                       QString( names[my2dMode] ),    // name (language-independant)
1576                                       false );                       // disable floatable toolbar
1577   if ( my2dMode != No2dMode ){
1578     toolMgr()->append( ReturnTo3dViewId, tid );
1579     toolMgr()->append( toolMgr()->separator(), tid );
1580   }
1581   toolMgr()->append( DumpId, tid );
1582   toolMgr()->append( SwitchInteractionStyleId, tid );
1583   toolMgr()->append( SwitchZoomingStyleId, tid );
1584   toolMgr()->append( SwitchPreselectionId, tid );
1585   toolMgr()->append( SwitchSelectionId, tid );
1586
1587   QtxMultiAction* aSelectionAction = new QtxMultiAction(this);
1588   aSelectionAction->insertAction(toolMgr()->action(RectangleSelectionStyleId));
1589   aSelectionAction->insertAction(toolMgr()->action(PolygonSelectionStyleId));
1590   aSelectionAction->insertAction(toolMgr()->action(CircleSelectionStyleId));
1591   toolMgr()->append(aSelectionAction, tid );
1592
1593   if( myModel->trihedronActivated() )
1594     toolMgr()->append( TrihedronShowId, tid );
1595
1596   if( myModel->viewCubeActivated() )
1597     toolMgr()->append( ViewCubeShowId, tid );
1598
1599   QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1600   aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1601   aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1602   aScaleAction->insertAction( toolMgr()->action( FitSelectionId ) );
1603   aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1604   toolMgr()->append( aScaleAction, tid );
1605
1606   QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1607   aPanningAction->insertAction( toolMgr()->action( PanId ) );
1608   aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1609   toolMgr()->append( aPanningAction, tid );
1610
1611   if (my2dMode == No2dMode) {
1612     toolMgr()->append( ChangeRotationPointId, tid );
1613     toolMgr()->append( RotationId, tid );
1614
1615     QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1616     aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1617     aViewsAction->insertAction( toolMgr()->action( BackId ) );
1618     aViewsAction->insertAction( toolMgr()->action( TopId ) );
1619     aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1620     aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1621     aViewsAction->insertAction( toolMgr()->action( RightId ) );
1622     toolMgr()->append( aViewsAction, tid );
1623
1624     toolMgr()->append( AntiClockWiseId, tid );
1625     toolMgr()->append( ClockWiseId, tid );
1626
1627     toolMgr()->append( OrthographicId, tid );
1628     toolMgr()->append( PerspectiveId, tid );
1629     toolMgr()->append( StereoId, tid );
1630
1631     toolMgr()->append( ResetId, tid );
1632   }
1633
1634   QtxMultiAction* aMemAction = new QtxMultiAction( this );
1635   aMemAction->insertAction( toolMgr()->action( MemId ) );
1636   aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1637   toolMgr()->append( aMemAction, tid );
1638
1639   toolMgr()->append( toolMgr()->separator(), tid );
1640   toolMgr()->append( CloneId, tid );
1641
1642   toolMgr()->append( toolMgr()->separator(), tid );
1643   toolMgr()->append( ClippingId, tid );
1644   toolMgr()->append( AxialScaleId, tid );
1645   toolMgr()->append( GraduatedAxesId, tid );
1646   toolMgr()->append( AmbientId, tid );
1647
1648   toolMgr()->append( MaximizedId, tid );
1649   toolMgr()->append( SynchronizeId, tid );
1650 #ifdef ENABLE_RAY_TRACING
1651   toolMgr()->append( RayTracingId, tid );
1652   toolMgr()->append( EnvTextureId, tid );
1653   toolMgr()->append( LightSourceId, tid );
1654 #endif
1655 }
1656
1657 /*!
1658   \brief Perform 'fit all' operation.
1659 */
1660 void OCCViewer_ViewWindow::onViewFitAll()
1661 {
1662   myViewPort->fitAll();
1663 }
1664
1665 /*!
1666   \brief Perform "front view" transformation.
1667 */
1668 void OCCViewer_ViewWindow::onFrontView()
1669 {
1670   emit vpTransformationStarted ( FRONTVIEW );
1671   Handle(V3d_View) aView3d = myViewPort->getView();
1672   if (myAutomaticZoom)
1673   {
1674     if ( !aView3d.IsNull() )
1675       aView3d->SetProj (V3d_Xpos);
1676     onViewFitAll();
1677   }
1678   else
1679     projAndPanToGravity(V3d_Xpos);
1680   emit vpTransformationFinished ( FRONTVIEW );
1681 }
1682
1683 /*!
1684   \brief Perform "back view" transformation.
1685 */
1686 void OCCViewer_ViewWindow::onBackView()
1687 {
1688   emit vpTransformationStarted ( BACKVIEW );
1689   Handle(V3d_View) aView3d = myViewPort->getView();
1690   if (myAutomaticZoom)
1691   {
1692     if ( !aView3d.IsNull() )
1693       aView3d->SetProj (V3d_Xneg);
1694     onViewFitAll();
1695   }
1696   else
1697     projAndPanToGravity(V3d_Xneg);
1698   emit vpTransformationFinished ( BACKVIEW );
1699 }
1700
1701 /*!
1702   \brief Perform "top view" transformation.
1703 */
1704 void OCCViewer_ViewWindow::onTopView()
1705 {
1706   emit vpTransformationStarted ( TOPVIEW );
1707   Handle(V3d_View) aView3d = myViewPort->getView();
1708   if (myAutomaticZoom)
1709   {
1710     if ( !aView3d.IsNull() )
1711       aView3d->SetProj (V3d_Zpos);
1712     onViewFitAll();
1713   }
1714   else
1715     projAndPanToGravity(V3d_Zpos);
1716   emit vpTransformationFinished ( TOPVIEW );
1717 }
1718
1719 /*!
1720   \brief Perform "bottom view" transformation.
1721 */
1722 void OCCViewer_ViewWindow::onBottomView()
1723 {
1724   emit vpTransformationStarted ( BOTTOMVIEW );
1725   Handle(V3d_View) aView3d = myViewPort->getView();
1726   if (myAutomaticZoom)
1727   {
1728     if ( !aView3d.IsNull() )
1729       aView3d->SetProj (V3d_Zneg);
1730     onViewFitAll();
1731   }
1732   else
1733     projAndPanToGravity(V3d_Zneg);
1734   emit vpTransformationFinished ( BOTTOMVIEW );
1735 }
1736
1737 /*!
1738   \brief Perform "left view" transformation.
1739 */
1740 void OCCViewer_ViewWindow::onLeftView()
1741 {
1742   emit vpTransformationStarted ( LEFTVIEW );
1743   Handle(V3d_View) aView3d = myViewPort->getView();
1744   if (myAutomaticZoom)
1745   {
1746     if ( !aView3d.IsNull() )
1747       aView3d->SetProj (V3d_Yneg);
1748     onViewFitAll();
1749   }
1750   else
1751     projAndPanToGravity(V3d_Yneg);
1752   emit vpTransformationFinished ( LEFTVIEW );
1753 }
1754
1755 /*!
1756   \brief Perform "right view" transformation.
1757 */
1758 void OCCViewer_ViewWindow::onRightView()
1759 {
1760   emit vpTransformationStarted ( RIGHTVIEW );
1761   Handle(V3d_View) aView3d = myViewPort->getView();
1762   if (myAutomaticZoom)
1763   {
1764     if ( !aView3d.IsNull() )
1765       aView3d->SetProj (V3d_Ypos);
1766     onViewFitAll();
1767   }
1768   else
1769     projAndPanToGravity(V3d_Ypos);
1770   emit vpTransformationFinished ( RIGHTVIEW );
1771 }
1772
1773 /*!
1774   \brief Rotate view 90 degrees clockwise
1775 */
1776 void OCCViewer_ViewWindow::onClockWiseView()
1777 {
1778   emit vpTransformationStarted ( CLOCKWISEVIEW );
1779   myViewPort->rotateXY( 90. );
1780   emit vpTransformationFinished ( CLOCKWISEVIEW );
1781 }
1782
1783 /*!
1784   \brief Rotate view 90 degrees conterclockwise
1785 */
1786 void OCCViewer_ViewWindow::onAntiClockWiseView()
1787 {
1788   emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1789   myViewPort->rotateXY( -90. );
1790   emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1791 }
1792
1793 /*!
1794   \brief Perform "reset view" transformation.
1795
1796   Sets default orientation of the viewport camera.
1797 */
1798 void OCCViewer_ViewWindow::onResetView()
1799 {
1800   emit vpTransformationStarted( RESETVIEW );
1801   bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1802   myViewPort->getView()->Reset( false );
1803   myViewPort->fitAll( false, true, false );
1804   myViewPort->getView()->SetImmediateUpdate( upd );
1805   onProjectionType(); // needed to apply projection type properly after reset
1806   myViewPort->getView()->Update();
1807   emit vpTransformationFinished( RESETVIEW );
1808 }
1809
1810 /*!
1811   \brief Set the given projection mode.
1812
1813   Set the given projection mode: Orthographic or Perspective.
1814 */
1815 void OCCViewer_ViewWindow::onProjectionType( QAction* theAction )
1816 {
1817   Handle(V3d_View) aView3d = myViewPort->getView();
1818   if ( !aView3d.IsNull() ) {
1819     Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1820     if (theAction == toolMgr()->action( OrthographicId )) {
1821       myModel->setProjectionType(Orthographic);
1822       aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Orthographic );
1823       aCamera->SetFOVy(45.0);
1824     }
1825     else if (theAction == toolMgr()->action( PerspectiveId )) {
1826       myModel->setProjectionType(Perspective);
1827       aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Perspective );
1828       aCamera->SetFOVy(30.0);
1829     }
1830     if (toolMgr()->action( StereoId )->isChecked()) {
1831       aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1832       aCamera->SetFOVy(30.0);
1833     }
1834     aView3d->Redraw();
1835     onViewFitAll();
1836   }
1837 }
1838
1839 /*!
1840   \brief Sets Stereo projection mode.
1841
1842   Sets Stereo projection mode.
1843 */
1844 void OCCViewer_ViewWindow::onStereoType( bool activate )
1845 {
1846   Handle(V3d_View) aView3d = myViewPort->getView();
1847   if ( !aView3d.IsNull() ) {
1848     Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1849     if (activate) {
1850       toolMgr()->action( PerspectiveId )->setChecked(true);
1851       aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1852       toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(false);
1853
1854       aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1855       SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1856       setStereoType( aResMgr->integerValue( "OCCViewer", "stereo_type", 0 ) );
1857       setAnaglyphFilter( aResMgr->integerValue( "OCCViewer", "anaglyph_filter", 0 ) );
1858       setReverseStereo( aResMgr->booleanValue( "OCCViewer", "reverse_stereo", false ) );
1859       setVSync( aResMgr->booleanValue( "OCCViewer", "enable_vsync", true ) );
1860       setQuadBufferSupport( aResMgr->booleanValue( "OCCViewer", "enable_quad_buffer_support", false ) );
1861     }
1862     else {
1863       toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(true);
1864       if (myModel->projectionType() == Orthographic) {
1865         toolMgr()->action( OrthographicId )->setChecked(true);
1866         aCamera->SetProjectionType(Graphic3d_Camera::Projection_Orthographic);
1867       }
1868       else if (myModel->projectionType() == Perspective) {
1869         toolMgr()->action( PerspectiveId )->setChecked(true);
1870         aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1871       }
1872     }
1873     aView3d->Redraw();
1874     onViewFitAll();
1875   }
1876
1877   if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1878        toolMgr()->action( StereoId )->isChecked() )
1879     SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ),  tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1880 }
1881
1882 /*!
1883   \brief Restore the view.
1884
1885   Restore the projection mode based on tool-buttons states.
1886 */
1887 void OCCViewer_ViewWindow::onProjectionType()
1888 {
1889   emit vpTransformationStarted( PROJECTION );
1890   if (toolMgr()->action( OrthographicId )->isChecked())
1891     setProjectionType( Orthographic );
1892   if (toolMgr()->action( PerspectiveId )->isChecked())
1893     setProjectionType( Perspective );
1894   if (toolMgr()->action( StereoId )->isChecked())
1895     setProjectionType( Stereo );
1896   emit vpTransformationFinished( PROJECTION );
1897 }
1898
1899 void OCCViewer_ViewWindow::setProjectionType( int mode )
1900 {
1901   QtxAction* anOrthographicAction = dynamic_cast<QtxAction*>( toolMgr()->action( OrthographicId ) );
1902   QtxAction* aPerspectiveAction = dynamic_cast<QtxAction*>( toolMgr()->action( PerspectiveId ) );
1903   QtxAction* aStereoAction = dynamic_cast<QtxAction*>( toolMgr()->action( StereoId ) );
1904   switch ( mode ) {
1905     case Orthographic:
1906       onProjectionType( anOrthographicAction );
1907       break;
1908     case Perspective:
1909       onProjectionType( aPerspectiveAction );
1910       break;
1911     case Stereo:
1912       onStereoType( true );
1913       break;
1914   }
1915   // update action state if method is called outside
1916   if ( mode == Orthographic && !anOrthographicAction->isChecked() ) {
1917           anOrthographicAction->setChecked( true );
1918           aStereoAction->setChecked( false );
1919   }
1920   if ( mode == Perspective && !aPerspectiveAction->isChecked() ) {
1921           aPerspectiveAction->setChecked( true );
1922           aStereoAction->setChecked( false );
1923   }
1924   if ( mode == Stereo ) {
1925     aStereoAction->setChecked( true );
1926     if ( anOrthographicAction->isEnabled() ) {
1927       anOrthographicAction->setEnabled( false );
1928       anOrthographicAction->setChecked( false );
1929       aStereoAction->setChecked( false );
1930     }
1931     else {
1932       anOrthographicAction->setEnabled( true );
1933       aStereoAction->setChecked( false );
1934       anOrthographicAction->setChecked(myModel->projectionType() == Orthographic);
1935     }
1936     if ( aPerspectiveAction->isEnabled() ) {
1937       aPerspectiveAction->setEnabled( false );
1938       aPerspectiveAction->setChecked( true );
1939       if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1940            toolMgr()->action( StereoId )->isChecked() )
1941         SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ),  tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1942     }
1943     else {
1944       aPerspectiveAction->setEnabled( true );
1945       aStereoAction->setChecked( false );
1946       aPerspectiveAction->setChecked(myModel->projectionType() == Perspective);
1947       onProjectionType();
1948     }
1949   }
1950   else {
1951     if ( !anOrthographicAction->isEnabled() )
1952       anOrthographicAction->setEnabled( true );
1953     if ( !aPerspectiveAction->isEnabled() )
1954       aPerspectiveAction->setEnabled( true );
1955   }
1956 }
1957
1958 /*!
1959   \brief Perform "fit all" transformation.
1960 */
1961 void OCCViewer_ViewWindow::onFitAll()
1962 {
1963   emit vpTransformationStarted( FITALLVIEW );
1964   if (myModel->fitter())
1965     myModel->fitter()->fitAll(myViewPort->getView());
1966   else
1967     myViewPort->fitAll();
1968   emit vpTransformationFinished( FITALLVIEW );
1969 }
1970
1971 /*!
1972   \brief Perform "fit selection" transformation.
1973 */
1974 void OCCViewer_ViewWindow::onFitSelection()
1975 {
1976   emit vpTransformationStarted( FITSELECTION );
1977   myModel->getAISContext()->FitSelected( getViewPort()->getView() );
1978   emit vpTransformationFinished( FITSELECTION );
1979 }
1980
1981 /*!
1982   \brief Called if 'change rotation point' operation is activated.
1983   \param on action state
1984 */
1985 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1986 {
1987   if (on)
1988   {
1989     if (!mySetRotationPointDlg)
1990     {
1991       mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1992       mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1993     }
1994
1995     if (!mySetRotationPointDlg->isVisible())
1996     {
1997       //if (mySetRotationPointDlg->IsFirstShown())
1998       if (myCurrPointType == BBCENTER)
1999       {
2000         Standard_Real Xcenter, Ycenter, Zcenter;
2001         if (OCCViewer_Utilities::computeVisibleBBCenter(myViewPort->getView(), Xcenter, Ycenter, Zcenter))
2002           mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
2003       }
2004       mySetRotationPointDlg->show();
2005     }
2006   }
2007   else
2008   {
2009     if (mySetRotationPointDlg->isVisible())
2010       mySetRotationPointDlg->hide();
2011   }
2012 }
2013
2014 /*!
2015    \brief Create one more window with same content.
2016 */
2017 void OCCViewer_ViewWindow::onCloneView()
2018 {
2019   SUIT_ViewWindow* vw = myManager->createViewWindow();
2020   //vw->show();
2021   emit viewCloned( vw );
2022   OCCViewer_ViewWindow* occVw = dynamic_cast<OCCViewer_ViewWindow*> (vw);
2023   if(occVw && occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)) {
2024     occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)->synchronize(this);
2025   }
2026 }
2027
2028 /*!
2029   Creates one more window with same content
2030 */
2031 void OCCViewer_ViewWindow::onAxialScale()
2032 {
2033   if ( !myScalingDlg )
2034     myScalingDlg = new OCCViewer_AxialScaleDlg( this , myModel );
2035
2036   if ( !myScalingDlg->isVisible() )
2037   {
2038     myScalingDlg->Update();
2039     myScalingDlg->show();
2040   }
2041 }
2042
2043 /*!
2044   Shows Graduated Axes dialog
2045 */
2046 void OCCViewer_ViewWindow::onGraduatedAxes()
2047 {
2048   myCubeAxesDlg->Update();
2049   myCubeAxesDlg->show();
2050 }
2051
2052 void OCCViewer_ViewWindow::onAmbientToogle()
2053 {
2054   Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2055   viewer->InitDefinedLights();
2056   while(viewer->MoreDefinedLights())
2057     {
2058       Handle(V3d_Light) light = viewer->DefinedLight();
2059       if(light->Type() != V3d_AMBIENT)
2060         {
2061           Handle(V3d_View) aView3d = myViewPort->getView();
2062           if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
2063           else viewer->SetLightOn(light);
2064         }
2065       viewer->NextDefinedLights();
2066     }
2067   viewer->Update();
2068 }
2069
2070 /*!
2071   \brief Store view parameters.
2072 */
2073 void OCCViewer_ViewWindow::onMemorizeView()
2074 {
2075   appendViewAspect( getViewParams() );
2076 }
2077
2078 /*!
2079   \brief Restore view parameters.
2080 */
2081 void OCCViewer_ViewWindow::onRestoreView()
2082 {
2083   OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
2084   connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
2085   aDlg->exec();
2086   updateViewAspects( aDlg->parameters() );
2087   if( myRestoreFlag && aDlg->parameters().count() )
2088     performRestoring( aDlg->currentItem() );
2089 }
2090
2091 /*!
2092   \brief Restore view parameters.
2093   \param anItem view parameters
2094 */
2095 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
2096 {
2097   Handle(V3d_View) aView3d = myViewPort->getView();
2098
2099   Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
2100   aView3d->SetScale( anItem.scale );
2101   aView3d->SetTwist( anItem.twist );
2102   aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
2103   aView3d->SetImmediateUpdate( prev );
2104   aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2105   aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2106   aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
2107
2108   if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
2109   {
2110     double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
2111
2112     // "eye" and "at" require conversion to represent center panning
2113     // up direction is only available after setting angle of twist and
2114     // other view parameters
2115     aView3d->Up( anUpX, anUpY, anUpZ );
2116
2117     gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
2118     gp_Dir anUp( anUpX, anUpY, anUpZ );
2119     gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
2120     gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2121     gp_Dir aSide = aProj ^ anUp;
2122
2123     anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
2124     anAt.Translate( gp_Vec( anUp  ) * anItem.centerY );
2125
2126     aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
2127     aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2128   }
2129
2130   if ( !baseParamsOnly ) {
2131
2132     myModel->setTrihedronShown( anItem.isVisible );
2133     myModel->setTrihedronSize( anItem.size );
2134
2135     myModel->setViewCubeShown( anItem.vcIsVisible );
2136
2137     // graduated trihedron
2138     bool anIsVisible = anItem.gtIsVisible;
2139     OCCViewer_AxisWidget::AxisData anAxisData[3];
2140     anAxisData[0].DrawName = anItem.gtDrawNameX;
2141     anAxisData[1].DrawName = anItem.gtDrawNameZ;
2142     anAxisData[2].DrawName = anItem.gtDrawNameZ;
2143     anAxisData[0].Name = anItem.gtNameX;
2144     anAxisData[1].Name = anItem.gtNameZ;
2145     anAxisData[2].Name = anItem.gtNameZ;
2146     anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
2147               anItem.gtNameColorGX,
2148               anItem.gtNameColorBX );
2149     anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
2150               anItem.gtNameColorGY,
2151               anItem.gtNameColorBY );
2152     anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
2153               anItem.gtNameColorGZ,
2154               anItem.gtNameColorBZ );
2155     anAxisData[0].DrawValues = anItem.gtDrawValuesX;
2156     anAxisData[1].DrawValues = anItem.gtDrawValuesY;
2157     anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
2158     anAxisData[0].NbValues = anItem.gtNbValuesX;
2159     anAxisData[1].NbValues = anItem.gtNbValuesY;
2160     anAxisData[2].NbValues = anItem.gtNbValuesZ;
2161     anAxisData[0].Offset = anItem.gtOffsetX;
2162     anAxisData[1].Offset = anItem.gtOffsetY;
2163     anAxisData[2].Offset = anItem.gtOffsetZ;
2164     anAxisData[0].Color = QColor( anItem.gtColorRX,
2165           anItem.gtColorGX,
2166           anItem.gtColorBX );
2167     anAxisData[1].Color = QColor( anItem.gtColorRY,
2168           anItem.gtColorGY,
2169           anItem.gtColorBY );
2170     anAxisData[2].Color = QColor( anItem.gtColorRZ,
2171           anItem.gtColorGZ,
2172           anItem.gtColorBZ );
2173     anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
2174     anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
2175     anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
2176     anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
2177     anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
2178     anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
2179
2180     myCubeAxesDlg->SetData( anIsVisible, anAxisData );
2181     myCubeAxesDlg->ApplyData( aView3d );
2182
2183   } // if ( !baseParamsOnly )
2184
2185   myRestoreFlag = 0;
2186 }
2187
2188 /*!
2189   \brief Set restore flag.
2190 */
2191 void OCCViewer_ViewWindow::setRestoreFlag()
2192 {
2193   myRestoreFlag = 1;
2194 }
2195
2196 /*!
2197   \brief Called when action "show/hide trihedron" is activated.
2198 */
2199 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
2200 {
2201   myModel->setTrihedronShown(show);
2202 }
2203
2204 /*!
2205   \brief Called when action "show/hide view cube" is activated.
2206 */
2207 void OCCViewer_ViewWindow::onViewCubeShow(bool show)
2208 {
2209   myModel->setViewCubeShown(show);
2210 }
2211
2212 /*!
2213   \brief Toggles preselection (highlighting) on/off
2214 */
2215 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
2216 {
2217   myPreselectionEnabled = on;
2218   myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
2219
2220   // unhighlight all highlighted objects
2221   /*if ( !on ) {
2222     myModel->unHighlightAll( true, false );
2223   }*/
2224
2225   // update action state if method is called outside
2226   QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2227   if ( a && a->isChecked() != on ) {
2228     a->setChecked( on );
2229   }
2230 }
2231
2232 /*!
2233   \brief Toggles selection on/off
2234 */
2235 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
2236 {
2237   mySelectionEnabled = on;
2238   myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
2239
2240   // update action state if method is called outside
2241
2242   // preselection
2243   QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2244   if ( a ) {
2245     a->setEnabled( on );
2246   }
2247
2248   // selection
2249   a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
2250   if ( a && a->isChecked() != on ) {
2251     a->setChecked( on );
2252   }
2253 }
2254
2255 /*!
2256   \brief Switches style of advanced multiple selection by Poligon/Circle
2257 */
2258 void OCCViewer_ViewWindow::onSwitchSelectionStyle(QAction* theAction)
2259 {
2260   // selection
2261   OCCViewer_ViewSketcher* aSkecher = getSketcher(Polygon);
2262   if (aSkecher) {
2263     if (theAction == toolMgr()->action(PolygonSelectionStyleId)) {
2264       aSkecher->setSketcherMode(OCCViewer_PolygonSketcher::Poligone);
2265     }
2266     else if (theAction == toolMgr()->action(CircleSelectionStyleId)) {
2267       aSkecher->setSketcherMode(OCCViewer_PolygonSketcher::Circle);
2268     }
2269   }
2270 }
2271
2272 /*!
2273 Returns currently selected selection style
2274 */
2275 OCCViewer_ViewWindow::SelectionStyle OCCViewer_ViewWindow::selectionStyle() const
2276 {
2277   if (toolMgr()->action(PolygonSelectionStyleId)->isChecked())
2278     return PolygonStyle;
2279   if (toolMgr()->action(CircleSelectionStyleId)->isChecked())
2280     return CyrcleStyle;
2281   return RectStyle;
2282 }
2283
2284 void OCCViewer_ViewWindow::setSelectionStyle(SelectionStyle theMode)
2285 {
2286   toolMgr()->action(RectangleSelectionStyleId)->setChecked(false);
2287   toolMgr()->action(PolygonSelectionStyleId)->setChecked(false);
2288   toolMgr()->action(CircleSelectionStyleId)->setChecked(false);
2289   switch (theMode) {
2290   case RectStyle:
2291     toolMgr()->action(RectangleSelectionStyleId)->setChecked(true);
2292     break;
2293   case PolygonStyle:
2294     toolMgr()->action(PolygonSelectionStyleId)->setChecked(true);
2295     break;
2296   case CyrcleStyle:
2297     toolMgr()->action(CircleSelectionStyleId)->setChecked(true);
2298   }
2299 }
2300
2301 /*!
2302   \brief Switches "keyboard free" interaction style on/off
2303 */
2304 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
2305 {
2306   myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
2307
2308   // update action state if method is called outside
2309   QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
2310   if ( a && a->isChecked() != on )
2311     a->setChecked( on );
2312 }
2313
2314 /*!
2315   \brief Toogles advanced zooming style (relatively to the cursor position) on/off
2316 */
2317 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
2318 {
2319   myViewPort->setAdvancedZoomingEnabled( on );
2320
2321   // update action state if method is called outside
2322   QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
2323   if ( a && a->isChecked() != on )
2324     a->setChecked( on );
2325 }
2326
2327 /*!
2328   \brief Get current interaction style
2329   \return interaction style
2330 */
2331 int OCCViewer_ViewWindow::interactionStyle() const
2332 {
2333   return myInteractionStyle;
2334 }
2335
2336 /*!
2337   \brief Set current interaction style
2338   \param theStyle interaction style
2339 */
2340 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
2341 {
2342   onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
2343 }
2344
2345 /*!
2346   \brief Get current zooming style
2347   \return zooming style
2348 */
2349 int OCCViewer_ViewWindow::zoomingStyle() const
2350 {
2351   return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
2352 }
2353
2354 /*!
2355   \brief Set current zooming style
2356   \param theStyle zooming style
2357 */
2358 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
2359 {
2360   onSwitchZoomingStyle( theStyle == 1 );
2361 }
2362
2363 /*!
2364   \brief Dump view window contents to the pixmap.
2365   \return pixmap containing all scene rendered in the window
2366 */
2367 //#define USE_OLD_IMPLEMENTATION
2368 QImage OCCViewer_ViewWindow::dumpView()
2369 {
2370   Handle(V3d_View) view = myViewPort->getView();
2371   if ( view.IsNull() )
2372     return QImage();
2373
2374   int aWidth = myViewPort->width();
2375   int aHeight = myViewPort->height();
2376
2377 #ifdef USE_OLD_IMPLEMENTATION
2378   // rnv: Old approach to dump the OCCViewer content via Frame Buffer Object
2379
2380   view->Redraw();
2381
2382 #ifndef DISABLE_GLVIEWER
2383   OpenGLUtils_FrameBuffer aFrameBuffer;
2384   if ( aFrameBuffer.init( aWidth, aHeight ) )
2385   {
2386     glPushAttrib( GL_VIEWPORT_BIT );
2387     glViewport( 0, 0, aWidth, aHeight );
2388     aFrameBuffer.bind();
2389
2390     // draw scene
2391     view->Redraw();
2392
2393     aFrameBuffer.unbind();
2394     glPopAttrib();
2395
2396     QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
2397
2398     aFrameBuffer.bind();
2399     glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
2400     aFrameBuffer.unbind();
2401
2402     anImage = anImage.rgbSwapped();
2403     anImage = anImage.mirrored();
2404     return anImage;
2405   }
2406
2407   // if frame buffers are unsupported, use old approach
2408
2409   unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
2410   QPoint p = myViewPort->mapFromParent( myViewPort->geometry().topLeft() );
2411   glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
2412                 data);
2413   QImage anImage( data, aWidth, aHeight, QImage::Format_ARGB32 );
2414   anImage = anImage.mirrored();
2415   anImage = anImage.rgbSwapped();
2416   return anImage;
2417
2418 #else // DISABLE_GLVIEWER
2419
2420   return QImage();
2421
2422 #endif // DISABLE_GLVIEWER
2423
2424 #else // USE_OLD_IMPLEMENTATION
2425   // rnv: New approach is to use OCCT built-in procedure
2426
2427   Image_PixMap aPix;
2428   view->ToPixMap(aPix, aWidth, aHeight, Graphic3d_BT_RGB);
2429
2430   QImage anImage( aWidth, aHeight, QImage::Format_ARGB32 );
2431   for ( int i = 0; i < aWidth; i++ ) {
2432     for ( int j = 0; j < aHeight; j++ ) {
2433       Quantity_Color pixel = aPix.PixelColor( i, j ).GetRGB();
2434       QColor color = QColor::fromRgbF( pixel.Red(), pixel.Green(), pixel.Blue() );
2435       anImage.setPixelColor( i, j, color );
2436     }
2437   }
2438
2439   if ( aPix.IsTopDown() )
2440     anImage = anImage.mirrored();
2441   return anImage;
2442
2443 #endif // USE_OLD_IMPLEMENTATION
2444 }
2445
2446 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& /*img*/,
2447                                              const QString& fileName,
2448                                              const QString& /*format*/ )
2449 {
2450   bool res = false;
2451   QApplication::setOverrideCursor( Qt::WaitCursor );
2452
2453   res = myViewPort->getView()->Dump( fileName.toStdString().c_str() );
2454
2455   QApplication::restoreOverrideCursor();
2456   return res;
2457 }
2458
2459
2460 QString OCCViewer_ViewWindow::filter() const
2461 {
2462   // OCCT version > 7.3.0 is not support export to PS and EPS
2463   QString formats = tr( "OCC_IMAGE_FILES" );
2464   return formats.remove(" *.eps *.ps");
2465 }
2466
2467
2468 /*!
2469   \brief Set parameters of the cutting plane
2470   \param on if \c true, cutting plane is enabled
2471   \param x X position of plane point
2472   \param y Y position of plane point
2473   \param z Z position of plane point
2474   \param dx X coordinate of plane normal
2475   \param dy Y coordinate of plane normal
2476   \param dz Z coordinate of plane normal
2477 */
2478 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x,  const double y,  const double z,
2479                                             const double dx, const double dy, const double dz )
2480 {
2481   Handle(V3d_View) view = myViewPort->getView();
2482   if ( view.IsNull() )
2483     return;
2484
2485   if ( on ) {
2486     Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2487
2488     // try to use already existing plane or create a new one
2489     Handle(V3d_Plane) clipPlane;
2490
2491     // calculate new a,b,c,d values for the plane
2492     gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2493     double a, b, c, d;
2494     pln.Coefficients(a, b, c, d);
2495     Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2496     Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2497     if(aPlanes->Size() > 0 ) {
2498       Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2499       aClipPlane->SetEquation(pln);
2500       aClipPlane->SetOn(Standard_True);
2501       aClipPlane->SetUseObjectMaterial(true);
2502     } else {
2503       view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2504     }
2505   }
2506   else {
2507     Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2508     Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2509     for( ;anIter.More();anIter.Next() ){
2510       Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2511       aClipPlane->SetOn(Standard_False);
2512     }
2513   }
2514
2515   view->Update();
2516   view->Redraw();
2517 }
2518
2519 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2520 {
2521   gp_Dir aDir = pln.Axis().Direction();
2522   gp_Pnt aPnt = pln.Location();
2523   setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2524 }
2525
2526
2527 /*!
2528   \brief Check if any cutting plane is enabled
2529   \return \c true if at least one cutting plane is enabled
2530 */
2531 bool OCCViewer_ViewWindow::isCuttingPlane()
2532 {
2533   Handle(V3d_View) view = myViewPort->getView();
2534   bool res = false;
2535   Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2536   Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2537   for( ;anIter.More();anIter.Next() ) {
2538     Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2539     if(aClipPlane->IsOn()) {
2540       res = true;
2541       break;
2542     }
2543   }
2544   return res;
2545 }
2546
2547 /*!
2548   \brief Get the visual parameters of the view window.
2549   \return visual parameters of view window
2550 */
2551 viewAspect OCCViewer_ViewWindow::getViewParams() const
2552 {
2553   double projX, projY, projZ, twist;
2554   double atX, atY, atZ, eyeX, eyeY, eyeZ;
2555   double aScaleX, aScaleY, aScaleZ;
2556
2557   Handle(V3d_View) aView3d = myViewPort->getView();
2558
2559   aView3d->Proj( projX, projY, projZ );
2560   aView3d->At( atX, atY, atZ );
2561   aView3d->Eye( eyeX, eyeY, eyeZ );
2562   twist = aView3d->Twist();
2563
2564   aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2565
2566   bool isShown = myModel->isTrihedronVisible();
2567   double size = myModel->trihedronSize();
2568
2569   bool isVCShown = myModel->isViewCubeVisible();
2570
2571   QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2572
2573   viewAspect params;
2574   params.scale    = aView3d->Scale();
2575   params.projX    = projX;
2576   params.projY    = projY;
2577   params.projZ    = projZ;
2578   params.twist    = twist;
2579   params.atX      = atX;
2580   params.atY      = atY;
2581   params.atZ      = atZ;
2582   params.eyeX     = eyeX;
2583   params.eyeY     = eyeY;
2584   params.eyeZ     = eyeZ;
2585   params.scaleX   = aScaleX;
2586   params.scaleY   = aScaleY;
2587   params.scaleZ   = aScaleZ;
2588   params.name     = aName;
2589
2590   // trihedron
2591   params.isVisible= isShown;
2592   params.size     = size;
2593
2594   // view cube
2595   params.vcIsVisible= isVCShown;
2596
2597   // graduated trihedron
2598   bool anIsVisible = false;
2599   OCCViewer_AxisWidget::AxisData anAxisData[3];
2600   myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2601
2602   params.gtIsVisible = anIsVisible;
2603   params.gtDrawNameX = anAxisData[0].DrawName;
2604   params.gtDrawNameY = anAxisData[1].DrawName;
2605   params.gtDrawNameZ = anAxisData[2].DrawName;
2606   params.gtNameX = anAxisData[0].Name;
2607   params.gtNameY = anAxisData[1].Name;
2608   params.gtNameZ = anAxisData[2].Name;
2609   params.gtNameColorRX = anAxisData[0].NameColor.red();
2610   params.gtNameColorGX = anAxisData[0].NameColor.green();
2611   params.gtNameColorBX = anAxisData[0].NameColor.blue();
2612   params.gtNameColorRY = anAxisData[1].NameColor.red();
2613   params.gtNameColorGY = anAxisData[1].NameColor.green();
2614   params.gtNameColorBY = anAxisData[1].NameColor.blue();
2615   params.gtNameColorRZ = anAxisData[2].NameColor.red();
2616   params.gtNameColorGZ = anAxisData[2].NameColor.green();
2617   params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2618   params.gtDrawValuesX = anAxisData[0].DrawValues;
2619   params.gtDrawValuesY = anAxisData[1].DrawValues;
2620   params.gtDrawValuesZ = anAxisData[2].DrawValues;
2621   params.gtNbValuesX = anAxisData[0].NbValues;
2622   params.gtNbValuesY = anAxisData[1].NbValues;
2623   params.gtNbValuesZ = anAxisData[2].NbValues;
2624   params.gtOffsetX = anAxisData[0].Offset;
2625   params.gtOffsetY = anAxisData[1].Offset;
2626   params.gtOffsetZ = anAxisData[2].Offset;
2627   params.gtColorRX = anAxisData[0].Color.red();
2628   params.gtColorGX = anAxisData[0].Color.green();
2629   params.gtColorBX = anAxisData[0].Color.blue();
2630   params.gtColorRY = anAxisData[1].Color.red();
2631   params.gtColorGY = anAxisData[1].Color.green();
2632   params.gtColorBY = anAxisData[1].Color.blue();
2633   params.gtColorRZ = anAxisData[2].Color.red();
2634   params.gtColorGZ = anAxisData[2].Color.green();
2635   params.gtColorBZ = anAxisData[2].Color.blue();
2636   params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2637   params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2638   params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2639   params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2640   params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2641   params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2642
2643   return params;
2644 }
2645
2646 /*!
2647   \brief Get visual parameters of this view window.
2648   \return visual parameters of view window
2649 */
2650 QString OCCViewer_ViewWindow::getVisualParameters()
2651 {
2652   viewAspect params = getViewParams();
2653
2654   QStringList data;
2655
2656   data << QString( "scale=%1" )    .arg( params.scale,   0, 'e', 12 );
2657   data << QString( "projX=%1" )    .arg( params.projX,   0, 'e', 12 );
2658   data << QString( "projY=%1" )    .arg( params.projY,   0, 'e', 12 );
2659   data << QString( "projZ=%1" )    .arg( params.projZ,   0, 'e', 12 );
2660   data << QString( "twist=%1" )    .arg( params.twist,   0, 'e', 12 );
2661   data << QString( "atX=%1" )      .arg( params.atX,     0, 'e', 12 );
2662   data << QString( "atY=%1" )      .arg( params.atY,     0, 'e', 12 );
2663   data << QString( "atZ=%1" )      .arg( params.atZ,     0, 'e', 12 );
2664   data << QString( "eyeX=%1" )     .arg( params.eyeX,    0, 'e', 12 );
2665   data << QString( "eyeY=%1" )     .arg( params.eyeY,    0, 'e', 12 );
2666   data << QString( "eyeZ=%1" )     .arg( params.eyeZ,    0, 'e', 12 );
2667   data << QString( "scaleX=%1" )   .arg( params.scaleX,  0, 'e', 12 );
2668   data << QString( "scaleY=%1" )   .arg( params.scaleY,  0, 'e', 12 );
2669   data << QString( "scaleZ=%1" )   .arg( params.scaleZ,  0, 'e', 12 );
2670   data << QString( "isVisible=%1" ).arg( params.isVisible );
2671   data << QString( "size=%1" )     .arg( params.size,    0, 'f',  2 );
2672
2673   ClipPlanesList aPlanes =  myModel->getClipPlanes();
2674   for ( int i=0; i < (int)aPlanes.size(); i++ )
2675   {
2676     OCCViewer_ClipPlane& aPlane = aPlanes[i];
2677     QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2678     ClippingPlane +=  QString( "Mode~%1;").arg( (int)aPlane.Mode );
2679     ClippingPlane +=  QString( "IsActive~%1;").arg( aPlane.IsOn );
2680     switch ( aPlane.Mode )
2681     {
2682       case OCCViewer_ClipPlane::Absolute :
2683       {
2684         ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2685
2686         if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2687         {
2688           ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2689           ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2690           ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2691         }
2692         else
2693         {
2694           ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2695         }
2696       }
2697       break;
2698
2699       case OCCViewer_ClipPlane::Relative :
2700       {
2701         ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2702         ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2703         ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2704       }
2705       break;
2706     }
2707
2708     ClippingPlane +=  QString( "X~%1;" ).arg( aPlane.X );
2709     ClippingPlane +=  QString( "Y~%1;" ).arg( aPlane.Y );
2710     ClippingPlane +=  QString( "Z~%1;" ).arg( aPlane.Z );
2711     data << ClippingPlane;
2712   }
2713
2714   // graduated trihedron
2715   data << QString( "gtIsVisible=%1" )      .arg( params.gtIsVisible );
2716   data << QString( "gtDrawNameX=%1" )      .arg( params.gtDrawNameX );
2717   data << QString( "gtDrawNameY=%1" )      .arg( params.gtDrawNameY );
2718   data << QString( "gtDrawNameZ=%1" )      .arg( params.gtDrawNameZ );
2719   data << QString( "gtNameX=%1" )          .arg( params.gtNameX );
2720   data << QString( "gtNameY=%1" )          .arg( params.gtNameY );
2721   data << QString( "gtNameZ=%1" )          .arg( params.gtNameZ );
2722   data << QString( "gtNameColorRX=%1" )    .arg( params.gtNameColorRX );
2723   data << QString( "gtNameColorGX=%1" )    .arg( params.gtNameColorGX );
2724   data << QString( "gtNameColorBX=%1" )    .arg( params.gtNameColorBX );
2725   data << QString( "gtNameColorRY=%1" )    .arg( params.gtNameColorRY );
2726   data << QString( "gtNameColorGY=%1" )    .arg( params.gtNameColorGY );
2727   data << QString( "gtNameColorBY=%1" )    .arg( params.gtNameColorBY );
2728   data << QString( "gtNameColorRZ=%1" )    .arg( params.gtNameColorRZ );
2729   data << QString( "gtNameColorGZ=%1" )    .arg( params.gtNameColorGZ );
2730   data << QString( "gtNameColorBZ=%1" )    .arg( params.gtNameColorBZ );
2731   data << QString( "gtDrawValuesX=%1" )    .arg( params.gtDrawValuesX );
2732   data << QString( "gtDrawValuesY=%1" )    .arg( params.gtDrawValuesY );
2733   data << QString( "gtDrawValuesZ=%1" )    .arg( params.gtDrawValuesZ );
2734   data << QString( "gtNbValuesX=%1" )      .arg( params.gtNbValuesX );
2735   data << QString( "gtNbValuesY=%1" )      .arg( params.gtNbValuesY );
2736   data << QString( "gtNbValuesZ=%1" )      .arg( params.gtNbValuesZ );
2737   data << QString( "gtOffsetX=%1" )        .arg( params.gtOffsetX );
2738   data << QString( "gtOffsetY=%1" )        .arg( params.gtOffsetY );
2739   data << QString( "gtOffsetZ=%1" )        .arg( params.gtOffsetZ );
2740   data << QString( "gtColorRX=%1" )        .arg( params.gtColorRX );
2741   data << QString( "gtColorGX=%1" )        .arg( params.gtColorGX );
2742   data << QString( "gtColorBX=%1" )        .arg( params.gtColorBX );
2743   data << QString( "gtColorRY=%1" )        .arg( params.gtColorRY );
2744   data << QString( "gtColorGY=%1" )        .arg( params.gtColorGY );
2745   data << QString( "gtColorBY=%1" )        .arg( params.gtColorBY );
2746   data << QString( "gtColorRZ=%1" )        .arg( params.gtColorRZ );
2747   data << QString( "gtColorGZ=%1" )        .arg( params.gtColorGZ );
2748   data << QString( "gtColorBZ=%1" )        .arg( params.gtColorBZ );
2749   data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2750   data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2751   data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2752   data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2753   data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2754   data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2755
2756   // ray tracing parameters
2757   Graphic3d_RenderingParams rendParams = this->getViewPort()->getView()->RenderingParams();
2758   if ( rendParams.Method == Graphic3d_RM_RAYTRACING ) {
2759     QString RayTracing = "rayTracing=";
2760     RayTracing += QString( "rtDepth~%1;" ).arg( rendParams.RaytracingDepth );
2761     RayTracing += QString( "rtReflection~%1;" ).arg( rendParams.IsReflectionEnabled );
2762     RayTracing += QString( "rtAntialiasing~%1;" ).arg( rendParams.IsAntialiasingEnabled );
2763     RayTracing += QString( "rtShadow~%1;" ).arg( rendParams.IsShadowEnabled );
2764     RayTracing += QString( "rtTransShadow~%1;" ).arg( rendParams.IsTransparentShadowEnabled );
2765     data << RayTracing;
2766   }
2767
2768   // environment texture parameters
2769   Handle(Graphic3d_TextureEnv) aTexture = this->getViewPort()->getView()->TextureEnv();
2770   if ( !aTexture.IsNull() ) {
2771     QString EnvTexture = "envTexture=";
2772     if ( aTexture->Name() == Graphic3d_NOT_ENV_UNKNOWN ) {
2773       TCollection_AsciiString aFileName;
2774       aTexture->Path().SystemName( aFileName );
2775       EnvTexture += QString( "etFile~%1;" ).arg( aFileName.ToCString() );
2776     }
2777     else
2778       EnvTexture += QString( "etNumber~%1;" ).arg( aTexture->Name() );
2779     data << EnvTexture;
2780   }
2781
2782   // light source parameters
2783   myModel->getViewer3d()->InitDefinedLights();
2784   while ( myModel->getViewer3d()->MoreDefinedLights() )
2785   {
2786     Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2787     if ( aLight->Type() != V3d_AMBIENT ) {
2788       QString LightSource = QString( "lightSource=" );
2789       LightSource += QString( "lightType~%1;" ).arg( aLight->Type() );
2790       double aX, aY, aZ;
2791       if ( aLight->Type() == V3d_DIRECTIONAL )
2792         Handle(V3d_DirectionalLight)::DownCast( aLight )->Direction( aX, aY, aZ );
2793       else if ( aLight->Type() == V3d_POSITIONAL )
2794         Handle(V3d_PositionalLight)::DownCast( aLight )->Position( aX, aY, aZ );
2795       else
2796         continue; // not supported type of light source
2797       LightSource += QString( "lightX~%1;" ).arg( aX );
2798       LightSource += QString( "lightY~%1;" ).arg( aY );
2799       LightSource += QString( "lightZ~%1;" ).arg( aZ );
2800       LightSource += QString( "lightColorR~%1;" ).arg( aLight->Color().Red() );
2801       LightSource += QString( "lightColorG~%1;" ).arg( aLight->Color().Green() );
2802       LightSource += QString( "lightColorB~%1;" ).arg( aLight->Color().Blue() );
2803       LightSource += QString( "lightHeadlight~%1;" ).arg( aLight->Headlight() );
2804       data << LightSource;
2805     }
2806     myModel->getViewer3d()->NextDefinedLights();
2807   }
2808
2809   QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2810   data << QString( "background=%1" ).arg( bg );
2811
2812   return data.join("*");
2813 }
2814
2815 /*!
2816   \brief Restore visual parameters of the view window.
2817   \param parameters visual parameters of view window
2818 */
2819 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2820 {
2821   viewAspect params;
2822   ClipPlanesList aClipPlanes;
2823   QStringList data = parameters.split( '*' );
2824   Qtx::BackgroundData bgData;
2825   if ( parameters.contains( '=' )  ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2826   {
2827     foreach( QString param, data ) {
2828       QString paramName  = param.section( '=', 0, 0 ).trimmed();
2829       QString paramValue = param.section( '=', 1, 1 ).trimmed();
2830       if      ( paramName == "scale" )             params.scale             = paramValue.toDouble();
2831       else if ( paramName == "centerX" )           params.centerX           = paramValue.toDouble();
2832       else if ( paramName == "centerY" )           params.centerY           = paramValue.toDouble();
2833       else if ( paramName == "projX" )             params.projX             = paramValue.toDouble();
2834       else if ( paramName == "projY" )             params.projY             = paramValue.toDouble();
2835       else if ( paramName == "projZ" )             params.projZ             = paramValue.toDouble();
2836       else if ( paramName == "twist" )             params.twist             = paramValue.toDouble();
2837       else if ( paramName == "atX" )               params.atX               = paramValue.toDouble();
2838       else if ( paramName == "atY" )               params.atY               = paramValue.toDouble();
2839       else if ( paramName == "atZ" )               params.atZ               = paramValue.toDouble();
2840       else if ( paramName == "eyeX" )              params.eyeX              = paramValue.toDouble();
2841       else if ( paramName == "eyeY" )              params.eyeY              = paramValue.toDouble();
2842       else if ( paramName == "eyeZ" )              params.eyeZ              = paramValue.toDouble();
2843       else if ( paramName == "scaleX" )            params.scaleX            = paramValue.toDouble();
2844       else if ( paramName == "scaleY" )            params.scaleY            = paramValue.toDouble();
2845       else if ( paramName == "scaleZ" )            params.scaleZ            = paramValue.toDouble();
2846       else if ( paramName == "isVisible" )         params.isVisible         = paramValue.toInt();
2847       else if ( paramName == "size" )              params.size              = paramValue.toDouble();
2848       else if ( paramName.contains( "ClippingPlane" ) )
2849       {
2850         QStringList ClipPlaneData = paramValue.split( ';' );
2851         OCCViewer_ClipPlane aPlane;
2852         foreach( QString ClipPlaneParam, ClipPlaneData )
2853         {
2854           QString ClipPlane_paramName  = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2855           QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2856           if ( ClipPlane_paramName == "Mode" )
2857           {
2858             aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2859           }
2860           else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2861           else if ( ClipPlane_paramName == "X" )        aPlane.X    = ClipPlane_paramValue.toDouble();
2862           else if ( ClipPlane_paramName == "Y" )        aPlane.Y    = ClipPlane_paramValue.toDouble();
2863           else if ( ClipPlane_paramName == "Z" )        aPlane.Z    = ClipPlane_paramValue.toDouble();
2864           else
2865           {
2866             switch ( aPlane.Mode )
2867             {
2868               case OCCViewer_ClipPlane::Absolute :
2869                 if      ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2870                 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2871                 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2872                 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2873                 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2874                 break;
2875
2876               case OCCViewer_ClipPlane::Relative :
2877                 if      ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2878                 else if ( ClipPlane_paramName == "Rotation1" )           aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2879                 else if ( ClipPlane_paramName == "Rotation2" )           aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2880                 break;
2881             }
2882           }
2883         }
2884         aClipPlanes.push_back(aPlane);
2885       }
2886       // graduated trihedron
2887       else if ( paramName == "gtIsVisible" )       params.gtIsVisible       = paramValue.toInt();
2888       else if ( paramName == "gtDrawNameX" )       params.gtDrawNameX       = paramValue.toInt();
2889       else if ( paramName == "gtDrawNameY" )       params.gtDrawNameY       = paramValue.toInt();
2890       else if ( paramName == "gtDrawNameZ" )       params.gtDrawNameZ       = paramValue.toInt();
2891       else if ( paramName == "gtNameX" )           params.gtNameX           = paramValue;
2892       else if ( paramName == "gtNameY" )           params.gtNameY           = paramValue;
2893       else if ( paramName == "gtNameZ" )           params.gtNameZ           = paramValue;
2894       else if ( paramName == "gtNameColorRX" )     params.gtNameColorRX     = paramValue.toInt();
2895       else if ( paramName == "gtNameColorGX" )     params.gtNameColorGX     = paramValue.toInt();
2896       else if ( paramName == "gtNameColorBX" )     params.gtNameColorBX     = paramValue.toInt();
2897       else if ( paramName == "gtNameColorRY" )     params.gtNameColorRY     = paramValue.toInt();
2898       else if ( paramName == "gtNameColorGY" )     params.gtNameColorGY     = paramValue.toInt();
2899       else if ( paramName == "gtNameColorBY" )     params.gtNameColorBY     = paramValue.toInt();
2900       else if ( paramName == "gtNameColorRZ" )     params.gtNameColorRZ     = paramValue.toInt();
2901       else if ( paramName == "gtNameColorGZ" )     params.gtNameColorGZ     = paramValue.toInt();
2902       else if ( paramName == "gtNameColorBZ" )     params.gtNameColorBZ     = paramValue.toInt();
2903       else if ( paramName == "gtDrawValuesX" )     params.gtDrawValuesX     = paramValue.toInt();
2904       else if ( paramName == "gtDrawValuesY" )     params.gtDrawValuesY     = paramValue.toInt();
2905       else if ( paramName == "gtDrawValuesZ" )     params.gtDrawValuesZ     = paramValue.toInt();
2906       else if ( paramName == "gtNbValuesX" )       params.gtNbValuesX       = paramValue.toInt();
2907       else if ( paramName == "gtNbValuesY" )       params.gtNbValuesY       = paramValue.toInt();
2908       else if ( paramName == "gtNbValuesZ" )       params.gtNbValuesZ       = paramValue.toInt();
2909       else if ( paramName == "gtOffsetX" )         params.gtOffsetX         = paramValue.toInt();
2910       else if ( paramName == "gtOffsetY" )         params.gtOffsetY         = paramValue.toInt();
2911       else if ( paramName == "gtOffsetZ" )         params.gtOffsetZ         = paramValue.toInt();
2912       else if ( paramName == "gtColorRX" )         params.gtColorRX         = paramValue.toInt();
2913       else if ( paramName == "gtColorGX" )         params.gtColorGX         = paramValue.toInt();
2914       else if ( paramName == "gtColorBX" )         params.gtColorBX         = paramValue.toInt();
2915       else if ( paramName == "gtColorRY" )         params.gtColorRY         = paramValue.toInt();
2916       else if ( paramName == "gtColorGY" )         params.gtColorGY         = paramValue.toInt();
2917       else if ( paramName == "gtColorBY" )         params.gtColorBY         = paramValue.toInt();
2918       else if ( paramName == "gtColorRZ" )         params.gtColorRZ         = paramValue.toInt();
2919       else if ( paramName == "gtColorGZ" )         params.gtColorGZ         = paramValue.toInt();
2920       else if ( paramName == "gtColorBZ" )         params.gtColorBZ         = paramValue.toInt();
2921       else if ( paramName == "gtDrawTickmarksX" )  params.gtDrawTickmarksX  = paramValue.toInt();
2922       else if ( paramName == "gtDrawTickmarksY" )  params.gtDrawTickmarksY  = paramValue.toInt();
2923       else if ( paramName == "gtDrawTickmarksZ" )  params.gtDrawTickmarksZ  = paramValue.toInt();
2924       else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2925       else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2926       else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2927       else if ( paramName == "rayTracing" )
2928       {
2929         Graphic3d_RenderingParams& rendParams = this->getViewPort()->getView()->ChangeRenderingParams();
2930         rendParams.Method = Graphic3d_RM_RAYTRACING;
2931         QStringList rtData = paramValue.split( ';' );
2932         foreach( QString rtParam, rtData )
2933         {
2934           QString rt_paramName  = rtParam.section( '~', 0, 0 ).trimmed();
2935           QString rt_paramValue = rtParam.section( '~', 1, 1 ).trimmed();
2936           if ( rt_paramName == "rtDepth" ) rendParams.RaytracingDepth = rt_paramValue.toInt();
2937           else if ( rt_paramName == "rtReflection" ) rendParams.IsReflectionEnabled = rt_paramValue.toInt();
2938           else if ( rt_paramName == "rtAntialiasing" ) rendParams.IsAntialiasingEnabled = rt_paramValue.toInt();
2939           else if ( rt_paramName == "rtShadow" ) rendParams.IsShadowEnabled = rt_paramValue.toInt();
2940           else if ( rt_paramName == "rtTransShadow" ) rendParams.IsTransparentShadowEnabled = rt_paramValue.toInt();
2941         }
2942       }
2943       else if ( paramName == "envTexture" )
2944       {
2945         Handle(Graphic3d_TextureEnv) aTexture;
2946         QStringList etData = paramValue.split( ';' );
2947         foreach( QString etParam, etData )
2948         {
2949           QString et_paramName  = etParam.section( '~', 0, 0 ).trimmed();
2950           QString et_paramValue = etParam.section( '~', 1, 1 ).trimmed();
2951           if ( et_paramName == "etNumber" )
2952             aTexture = new Graphic3d_TextureEnv( Graphic3d_NameOfTextureEnv( et_paramValue.toInt() ) );
2953           else if ( et_paramName == "etFile" )
2954             aTexture = new Graphic3d_TextureEnv( TCollection_AsciiString( et_paramValue.toStdString().c_str() ) );
2955           Handle(V3d_View) aView = this->getViewPort()->getView();
2956           aView->SetTextureEnv( aTexture );
2957         }
2958       }
2959       else if ( paramName == "lightSource" )
2960       {
2961         myModel->getViewer3d()->InitDefinedLights();
2962         while ( myModel->getViewer3d()->MoreDefinedLights() )
2963         {
2964           Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2965           if( aLight->Type() != V3d_AMBIENT ) {
2966             myModel->getViewer3d()->DelLight( aLight );
2967             myModel->getViewer3d()->InitDefinedLights();
2968           } else {
2969             myModel->getViewer3d()->NextDefinedLights();
2970           }
2971         }
2972         double aX = 0., aY = 0., aZ = 0.;
2973         double cR = 0., cG = 0., cB = 0.;
2974         V3d_TypeOfLight aType = (V3d_TypeOfLight)-1; // not specified
2975         bool isHeadlight = false;
2976         QStringList lsData = paramValue.split( ';' );
2977         foreach( QString lsParam, lsData )
2978         {
2979           QString ls_paramName  = lsParam.section( '~', 0, 0 ).trimmed();
2980           QString ls_paramValue = lsParam.section( '~', 1, 1 ).trimmed();
2981           if ( ls_paramName == "lightType" ) aType = V3d_TypeOfLight( ls_paramValue.toInt() );
2982           else if ( ls_paramName == "lightX" ) aX = ls_paramValue.toDouble();
2983           else if ( ls_paramName == "lightY" ) aY = ls_paramValue.toDouble();
2984           else if ( ls_paramName == "lightZ" ) aZ = ls_paramValue.toDouble();
2985           else if ( ls_paramName == "lightColorR" ) cR = ls_paramValue.toDouble();
2986           else if ( ls_paramName == "lightColorG" ) cG = ls_paramValue.toDouble();
2987           else if ( ls_paramName == "lightColorB" ) cB = ls_paramValue.toDouble();
2988           else if ( ls_paramName == "lightHeadlight" ) isHeadlight = ls_paramValue.toInt();
2989         }
2990         Quantity_Color aColor = Quantity_Color( cR, cG, cB, Quantity_TOC_RGB );
2991         if( aType == V3d_DIRECTIONAL ) {
2992           Handle(V3d_DirectionalLight) aLight = new V3d_DirectionalLight();
2993           myModel->getViewer3d()->AddLight( aLight );
2994           aLight->SetDirection( aX, aY, aZ );
2995           aLight->SetColor( aColor );
2996           aLight->SetHeadlight( isHeadlight );
2997           myModel->getViewer3d()->SetLightOn( aLight );
2998         }
2999         else if( aType == V3d_POSITIONAL ) {
3000           Handle(V3d_PositionalLight) aLight = new V3d_PositionalLight( gp_Pnt(aX, aY, aZ), aColor.Name() );
3001           myModel->getViewer3d()->AddLight( aLight );
3002           aLight->SetHeadlight( isHeadlight );
3003           myModel->getViewer3d()->SetLightOn( aLight );
3004         }
3005       }
3006       else if ( paramName == "background" )        {
3007   QString bg = paramValue.replace( "$", "=" );
3008   bgData = Qtx::stringToBackground( bg );
3009       }
3010     }
3011   }
3012   else // old format - "1.000e+00*0.000e+00..."
3013   {
3014     int idx = 0;
3015     params.scale     = data.count() > idx ? data[idx++].toDouble() : 1.0;
3016     params.centerX   = data.count() > idx ? data[idx++].toDouble() : 0.0;
3017     params.centerY   = data.count() > idx ? data[idx++].toDouble() : 0.0;
3018     params.projX     = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
3019     params.projY     = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
3020     params.projZ     = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
3021     params.twist     = data.count() > idx ? data[idx++].toDouble() : 0.0;
3022     params.atX       = data.count() > idx ? data[idx++].toDouble() : 0.0;
3023     params.atY       = data.count() > idx ? data[idx++].toDouble() : 0.0;
3024     params.atZ       = data.count() > idx ? data[idx++].toDouble() : 0.0;
3025     params.eyeX      = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
3026     params.eyeY      = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
3027     params.eyeZ      = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
3028     params.scaleX    = data.count() > idx ? data[idx++].toDouble() : 1.0;
3029     params.scaleY    = data.count() > idx ? data[idx++].toDouble() : 1.0;
3030     params.scaleZ    = data.count() > idx ? data[idx++].toDouble() : 1.0;
3031     params.isVisible = data.count() > idx ? data[idx++].toInt()    : 1;
3032     params.size      = data.count() > idx ? data[idx++].toDouble() : 100.0;
3033   }
3034   performRestoring( params );
3035   setBackground( bgData );
3036   myModel->setClipPlanes(aClipPlanes);
3037 }
3038
3039 /*!
3040   \brief Handle show event.
3041
3042   Emits Show() signal.
3043
3044   \param theEvent show event
3045 */
3046 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
3047 {
3048   emit Show( theEvent );
3049 }
3050
3051 /*!
3052   \brief Handle hide event.
3053
3054   Emits Hide() signal.
3055
3056   \param theEvent hide event
3057 */
3058 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
3059 {
3060   emit Hide( theEvent );
3061 }
3062
3063
3064 /*!
3065     Save old cursor. [ protected ]
3066 */
3067 void OCCViewer_ViewWindow::saveCursor()
3068 {
3069   QCursor* aCursor = NULL;
3070   if ( myViewPort )
3071     aCursor = myViewPort->getDefaultCursor();
3072   myCursor = ( aCursor ? *aCursor : cursor() );
3073 }
3074
3075
3076 /*!
3077     Creates default sketcher. [ virtual protected ]
3078 */
3079 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
3080 {
3081   if ( type == Rect )
3082     return new OCCViewer_RectSketcher( this, type );
3083   if ( type == Polygon )
3084     return new OCCViewer_PolygonSketcher( this, type );
3085   return 0;
3086 }
3087
3088 void OCCViewer_ViewWindow::initSketchers()
3089 {
3090   if ( mySketchers.isEmpty() )
3091   {
3092     mySketchers.append( createSketcher( Rect ) );
3093     mySketchers.append( createSketcher( Polygon ) );
3094   }
3095 }
3096
3097 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ ) const
3098 {
3099   OCCViewer_ViewSketcher* sketcher = 0;
3100   QList<OCCViewer_ViewSketcher*>::ConstIterator it;
3101   for ( it = mySketchers.cbegin(); it != mySketchers.cend() && !sketcher; ++it )
3102   {
3103     OCCViewer_ViewSketcher* sk = (*it);
3104     if ( sk->type() == typ )
3105       sketcher = sk;
3106   }
3107   return sketcher;
3108 }
3109
3110 /*!
3111     Handles requests for sketching in the active view. [ virtual public ]
3112 */
3113 void OCCViewer_ViewWindow::activateSketching( int type )
3114 {
3115   OCCViewer_ViewPort3d* vp = getViewPort();
3116   if ( !vp )
3117     return;
3118
3119   if ( !vp->isSketchingEnabled() )
3120     return;
3121
3122   /* Finish current sketching */
3123   if ( type == NoSketching )
3124   {
3125     if ( mypSketcher )
3126     {
3127       onSketchingFinished();
3128       mypSketcher->deactivate();
3129       mypSketcher = 0;
3130     }
3131   }
3132   /* Activate new sketching */
3133   else
3134   {
3135     activateSketching( NoSketching );  /* concurrency not suported */
3136     mypSketcher = getSketcher( type );
3137     if ( mypSketcher )
3138     {
3139       mypSketcher->activate();
3140       onSketchingStarted();
3141     }
3142   }
3143 }
3144
3145 /*!
3146     Unhilights detected entities. [ virtual protected ]
3147 */
3148 void OCCViewer_ViewWindow::onSketchingStarted()
3149 {
3150 }
3151
3152 /*!
3153     Selection by rectangle or polygon. [ virtual protected ]
3154 */
3155 void OCCViewer_ViewWindow::onSketchingFinished()
3156 {
3157   MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()");
3158   if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
3159   {
3160     Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
3161     bool append = mypSketcher->isHasShift();
3162
3163     // Sketcher uses unscaled coordinates to draw a rubber band,
3164     // then we need to scale them here for proper selection.
3165     const double pixelRatio = ViewerTools_ScreenScaling::getPR();
3166
3167     switch( mypSketcher->type() )
3168     {
3169     case Rect:
3170       {
3171         QRect* aRect = (QRect*)mypSketcher->data();
3172         if ( aRect )
3173         {
3174           int aLeft = aRect->left() * pixelRatio;
3175           int aRight = aRect->right() * pixelRatio;
3176           int aTop = aRect->top() * pixelRatio;
3177           int aBottom = aRect->bottom() * pixelRatio;
3178 //           myRect = aRect;
3179
3180           if( append )
3181             ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False);
3182           else
3183             ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False);
3184         }
3185       }
3186       break;
3187     case Polygon:
3188       {
3189         QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
3190         if( aPolygon && (aPolygon->size() > 2))
3191         {
3192           int size = aPolygon->size();
3193           TColgp_Array1OfPnt2d anArray(1, size);
3194
3195           QPolygon::Iterator it = aPolygon->begin();
3196           QPolygon::Iterator itEnd = aPolygon->end();
3197           for (int index = 1; it != itEnd; ++it, index++)
3198           {
3199             QPoint aPoint = *it;
3200             anArray.SetValue(index, gp_Pnt2d(aPoint.x() * pixelRatio, aPoint.y() * pixelRatio));
3201           }
3202
3203           if (append)
3204             ic->ShiftSelect(anArray, getViewPort()->getView(), Standard_False);
3205           else
3206             ic->Select(anArray, getViewPort()->getView(), Standard_False);
3207         }
3208       }
3209       break;
3210     default:
3211       break;
3212     }
3213
3214     OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
3215     aViewMgr->getOCCViewer()->performSelectionChanged();
3216   }
3217 }
3218
3219 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
3220 {
3221   return myViewPort;
3222 }
3223
3224 bool OCCViewer_ViewWindow::transformRequested() const
3225 {
3226   return ( myOperation != NOVIEWOP );
3227 }
3228
3229 bool OCCViewer_ViewWindow::transformInProcess() const
3230 {
3231   return myEventStarted;
3232 }
3233
3234 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
3235 {
3236   myEventStarted = bOn;
3237 }
3238
3239 /*!
3240   Set enabled state of transformation (rotate, zoom, etc)
3241 */
3242 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
3243 {
3244   if ( id != NOVIEWOP ) myStatus.insert( id, on );
3245 }
3246
3247 /*!
3248   \return enabled state of transformation (rotate, zoom, etc)
3249 */
3250 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
3251 {
3252   return myStatus.contains( id ) ? myStatus[ id ] : true;
3253 }
3254
3255 void OCCViewer_ViewWindow::onMaximizedView()
3256 {
3257   setMaximized(!isMaximized());
3258 }
3259
3260 void OCCViewer_ViewWindow::returnTo3dView()
3261 {
3262   setReturnedTo3dView( true );
3263 }
3264
3265 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
3266 {
3267   if ( !toolMgr()->action( ReturnTo3dViewId ) ||
3268     toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
3269   if ( !isVisible3dView )
3270     toolMgr()->show( ReturnTo3dViewId );
3271   else
3272     toolMgr()->hide( ReturnTo3dViewId );
3273   if ( isVisible3dView ) emit returnedTo3d( );
3274 }
3275
3276
3277 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
3278 {
3279   QAction* anAction =  toolMgr()->action( MaximizedId );
3280   QAction* anAction2 =  toolMgr()->action( ReturnTo3dViewId );
3281   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
3282   if ( toMaximize ) {
3283     anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
3284     anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
3285     anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
3286     anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
3287     if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
3288     if (toSendSignal) {
3289       emit maximized( this, true );
3290     }
3291   }
3292   else {
3293     anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
3294     anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
3295     anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
3296     anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
3297     if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
3298     if (toSendSignal) {
3299       emit maximized( this, false );
3300     }
3301   }
3302 }
3303
3304 bool OCCViewer_ViewWindow::isMaximized() const
3305 {
3306   return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
3307 }
3308
3309 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
3310 {
3311   IsSketcherStyle = enable;
3312 }
3313
3314 bool OCCViewer_ViewWindow::isSketcherStyle() const
3315 {
3316   return IsSketcherStyle;
3317 }
3318
3319
3320 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
3321 {
3322   my2dMode = theType;
3323 }
3324
3325 int OCCViewer_ViewWindow::projectionType() const
3326 {
3327   int mode = Orthographic;
3328   Handle(V3d_View) aView3d = myViewPort->getView();
3329   if ( !aView3d.IsNull() ) {
3330     Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3331     if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Perspective)
3332       mode = Perspective;
3333     if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Orthographic)
3334       mode = Orthographic;
3335     if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
3336       mode = Stereo;
3337   }
3338   return mode;
3339 }
3340
3341 void OCCViewer_ViewWindow::setStereoType( int type )
3342 {
3343   Handle(V3d_View) aView3d = myViewPort->getView();
3344   if ( !aView3d.IsNull() ) {
3345     Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3346     aParams->StereoMode = (Graphic3d_StereoMode)type;
3347   }
3348 }
3349
3350 int OCCViewer_ViewWindow::stereoType() const
3351 {
3352   int type = QuadBuffer;
3353   Handle(V3d_View) aView3d = myViewPort->getView();
3354   if ( !aView3d.IsNull() ) {
3355     Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3356     type = (OCCViewer_ViewWindow::StereoType)aParams->StereoMode;
3357   }
3358   return type;
3359 }
3360
3361 void OCCViewer_ViewWindow::setAnaglyphFilter( int type )
3362 {
3363   Handle(V3d_View) aView3d = myViewPort->getView();
3364   if ( !aView3d.IsNull() ) {
3365     Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3366     if (type == RedCyan)
3367       aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
3368     if (type == YellowBlue)
3369       aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
3370     if (type == GreenMagenta)
3371       aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
3372   }
3373 }
3374
3375 int OCCViewer_ViewWindow::anaglyphFilter() const
3376 {
3377   int type = RedCyan;
3378   Handle(V3d_View) aView3d = myViewPort->getView();
3379   if ( !aView3d.IsNull() ) {
3380     Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3381     if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized)
3382       type = RedCyan;
3383     if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized)
3384       type = YellowBlue;
3385     if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple)
3386       type = GreenMagenta;
3387   }
3388   return type;
3389 }
3390
3391 void OCCViewer_ViewWindow::setStereographicFocus( int type, double value )
3392 {
3393   Handle(V3d_View) aView3d = myViewPort->getView();
3394   if ( !aView3d.IsNull() ) {
3395     Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3396     aCamera->SetZFocus( (Graphic3d_Camera::FocusType) type, value );
3397   }
3398 }
3399
3400 int OCCViewer_ViewWindow::stereographicFocusType() const
3401 {
3402   int type = Relative;
3403   Handle(V3d_View) aView3d = myViewPort->getView();
3404   if ( !aView3d.IsNull() ) {
3405     Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3406     type = (OCCViewer_ViewWindow::FocusIODType)aCamera->ZFocusType();
3407   }
3408   return type;
3409 }
3410
3411 double OCCViewer_ViewWindow::stereographicFocusValue() const
3412 {
3413   double value = 1.0;
3414   Handle(V3d_View) aView3d = myViewPort->getView();
3415   if ( !aView3d.IsNull() ) {
3416     Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3417     value = aCamera->ZFocus();
3418   }
3419   return value;
3420 }
3421
3422 void OCCViewer_ViewWindow::setInterocularDistance( int type, double value )
3423 {
3424   Handle(V3d_View) aView3d = myViewPort->getView();
3425   if ( !aView3d.IsNull() ) {
3426     Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3427     aCamera->SetIOD( (Graphic3d_Camera::IODType) type, value );
3428   }
3429 }
3430
3431 int OCCViewer_ViewWindow::interocularDistanceType() const
3432 {
3433   int type = Relative;
3434   Handle(V3d_View) aView3d = myViewPort->getView();
3435   if ( !aView3d.IsNull() ) {
3436     Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3437     type = (OCCViewer_ViewWindow::FocusIODType)aCamera->GetIODType();
3438   }
3439   return type;
3440 }
3441
3442 double OCCViewer_ViewWindow::interocularDistanceValue() const
3443 {
3444   double value = 0.05;
3445   Handle(V3d_View) aView3d = myViewPort->getView();
3446   if ( !aView3d.IsNull() ) {
3447     Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3448     value = aCamera->IOD();
3449   }
3450   return value;
3451 }
3452
3453 void OCCViewer_ViewWindow::setReverseStereo( bool reverse )
3454 {
3455   Handle(V3d_View) aView3d = myViewPort->getView();
3456   if ( !aView3d.IsNull() ) {
3457     Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3458     aParams->ToReverseStereo = reverse;
3459   }
3460 }
3461
3462 bool OCCViewer_ViewWindow::isReverseStereo() const
3463 {
3464   int reverse = false;
3465   Handle(V3d_View) aView3d = myViewPort->getView();
3466   if ( !aView3d.IsNull() ) {
3467     Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3468     reverse = aParams->ToReverseStereo;
3469   }
3470   return reverse;
3471 }
3472
3473 void OCCViewer_ViewWindow::setVSync( bool enable )
3474 {
3475   Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3476   if ( !anIntCont.IsNull() ) {
3477     Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3478     OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3479     aCaps->swapInterval = enable;
3480   }
3481 }
3482
3483 bool OCCViewer_ViewWindow::isVSync() const
3484 {
3485   int enable = true;
3486   Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3487   if ( !anIntCont.IsNull() ) {
3488     Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3489     OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3490     enable = aCaps->swapInterval;
3491   }
3492   return enable;
3493 }
3494
3495 void OCCViewer_ViewWindow::setQuadBufferSupport( bool enable )
3496 {
3497   Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3498   if ( !anIntCont.IsNull() ) {
3499     Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3500     OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3501     aCaps->contextStereo = enable;
3502   }
3503 }
3504
3505 bool OCCViewer_ViewWindow::isQuadBufferSupport() const
3506 {
3507   int enable = true;
3508   Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3509   if ( !anIntCont.IsNull() ) {
3510     Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3511     OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3512     enable = aCaps->contextStereo;
3513   }
3514   return enable;
3515 }
3516
3517 bool OCCViewer_ViewWindow::isOpenGlStereoSupport() const
3518 {
3519   GLboolean support[1];
3520   glGetBooleanv (GL_STEREO, support);
3521   if ( support[0] )
3522     return true;
3523   return false;
3524 }
3525
3526 // obsolete
3527 QColor OCCViewer_ViewWindow::backgroundColor() const
3528 {
3529   return myViewPort ? myViewPort->backgroundColor() : Qt::black;
3530 }
3531
3532 // obsolete
3533 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
3534 {
3535   if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
3536 }
3537
3538 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
3539 {
3540   return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
3541 }
3542
3543 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
3544 {
3545   if ( myViewPort ) myViewPort->setBackground( theBackground );
3546 }
3547
3548 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
3549 {
3550   if ( myViewPort ) myViewPort->showStaticTrihedron( on );
3551 }
3552
3553 /*!
3554   Clears view aspects
3555 */
3556 void OCCViewer_ViewWindow::clearViewAspects()
3557 {
3558   myViewAspects.clear();
3559 }
3560
3561 /*!
3562   \return const reference to list of view aspects
3563 */
3564 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
3565 {
3566   return myViewAspects;
3567 }
3568
3569 /*!
3570   Appends new view aspect
3571   \param aParams - new view aspects
3572 */
3573 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
3574 {
3575   myViewAspects.append( aParams );
3576 }
3577
3578 /*!
3579   Replaces old view aspects by new ones
3580   \param aViewList - list of new view aspects
3581 */
3582 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
3583 {
3584   myViewAspects = aViewList;
3585 }
3586
3587 /*!
3588   Get camera properties for the OCC view window.
3589   \return shared pointer on camera properties.
3590 */
3591 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
3592 {
3593   SUIT_CameraProperties aProps;
3594
3595   Handle(V3d_View) aSourceView = getViewPort()->getView();
3596   if ( aSourceView.IsNull() )
3597     return aProps;
3598
3599   if ( get2dMode() == No2dMode ) {
3600     aProps.setDimension( SUIT_CameraProperties::Dim3D );
3601   }
3602   else {
3603     aProps.setDimension( SUIT_CameraProperties::Dim2D );
3604     aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
3605   }
3606
3607   // read common properites of the view
3608   Standard_Real anUp[3];
3609   Standard_Real anAt[3];
3610   Standard_Real anEye[3];
3611   Standard_Real aProj[3];
3612   Standard_Real anAxialScale[3];
3613
3614   aSourceView->Up( anUp[0], anUp[1], anUp[2] );
3615   aSourceView->At( anAt[0], anAt[1], anAt[2] );
3616   aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
3617   getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3618
3619   aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3620   aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
3621
3622   aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
3623
3624   // store camera properties "as is": it is up to synchronized
3625   // view classes to provide necessary property conversion.
3626   aProps.setPosition( anEye[0], anEye[1], anEye[2] );
3627   aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
3628
3629   if ( aSourceView->Camera()->IsOrthographic() )
3630   {
3631     aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
3632     aProps.setViewAngle( 0.0 );
3633   }
3634   else
3635   {
3636     aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
3637     aProps.setViewAngle( aSourceView->Camera()->FOVy() );
3638   }
3639   aProps.setMappingScale( aSourceView->Camera()->Scale() );
3640
3641   return aProps;
3642 }
3643
3644 /*!
3645   Synchronize views.
3646   This implementation synchronizes OCC view's camera propreties.
3647 */
3648 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
3649 {
3650   bool blocked = blockSignals( true );
3651
3652   SUIT_CameraProperties aProps = theView->cameraProperties();
3653   if ( !cameraProperties().isCompatible( aProps ) ) {
3654     // other view, this one is being currently synchronized to, seems has become incompatible
3655     // we have to break synchronization
3656     updateSyncViews();
3657     return;
3658   }
3659
3660   Handle(V3d_View) aDestView = getViewPort()->getView();
3661
3662   aDestView->SetImmediateUpdate( Standard_False );
3663
3664   double anUpDir[3];
3665   double aPosition[3];
3666   double aFocalPoint[3];
3667   double anAxialScale[3];
3668
3669   // get common properties
3670   aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3671   aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
3672   aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3673   aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3674
3675   try {
3676     aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3677     aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
3678     aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3679     aDestView->Camera()->SetScale( aProps.getMappingScale() );
3680
3681     getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3682     aDestView->SetImmediateUpdate( Standard_True );
3683     aDestView->Redraw();
3684   }
3685   catch (Standard_Failure&) {
3686   }
3687
3688   blockSignals( blocked );
3689 }
3690
3691 /*!
3692   \brief Indicates whether preselection is enabled
3693   \return true if preselection is enabled
3694 */
3695 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
3696 {
3697   return myPreselectionEnabled;
3698 }
3699
3700 /*!
3701   \brief Enables/disables preselection
3702   \param theIsToEnable if true - preselection will be enabled
3703 */
3704 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
3705 {
3706   onSwitchPreselection( theIsToEnable );
3707 }
3708
3709 /*!
3710   \brief Indicates whether selection is enabled
3711   \return true if selection is enabled
3712 */
3713 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3714 {
3715   return mySelectionEnabled;
3716 }
3717
3718 /*!
3719   \brief Enables/disables selection
3720   \param theIsToEnable if true - selection will be enabled
3721 */
3722 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3723 {
3724   onSwitchSelection( theIsToEnable );
3725 }
3726
3727
3728 /*!
3729   \brief called if clipping operation is activated / deactivated.
3730
3731   Enables/disables clipping plane displaying.
3732
3733   \parma on action state
3734 */
3735 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3736 {
3737   if(!myModel) return;
3738   OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3739
3740   if (theIsOn) {
3741     if (!aClippingDlg) {
3742       aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3743       myModel->setClippingDlg(aClippingDlg);
3744     }
3745     if (!aClippingDlg->isVisible())
3746       aClippingDlg->show();
3747   } else {
3748     if ( aClippingDlg ) {
3749       aClippingDlg->close();
3750       myModel->setClippingDlg(0);
3751     }
3752   }
3753
3754   SUIT_ViewManager* mgr = getViewManager();
3755   if( mgr ) {
3756     QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3757     for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3758       if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3759         QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3760         if(!mgr) continue;
3761         QAction* a = toolMgr()->action( ClippingId );
3762         if(!a) continue;
3763         if(theIsOn != a->isChecked()){
3764           disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3765           a->setChecked(theIsOn);
3766           connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3767         }
3768       }
3769     }
3770   }
3771 }
3772
3773 void OCCViewer_ViewWindow::onRayTracing()
3774 {
3775   if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_RayTracingDlg::getName() ) ) {
3776     QDialog* aDlg = new OCCViewer_RayTracingDlg( this );
3777     if ( aDlg != NULL )
3778       aDlg->show();
3779   }
3780 }
3781
3782 void OCCViewer_ViewWindow::onEnvTexture()
3783 {
3784   if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_EnvTextureDlg::getName() ) ) {
3785     QDialog* aDlg = new OCCViewer_EnvTextureDlg( this );
3786     if ( aDlg != NULL )
3787       aDlg->show();
3788   }
3789 }
3790
3791 void OCCViewer_ViewWindow::onLightSource()
3792 {
3793   if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_LightSourceDlg::getName() ) ) {
3794     QDialog* aDlg = new OCCViewer_LightSourceDlg( this, myModel );
3795     if ( aDlg != NULL )
3796       aDlg->show();
3797   }
3798 }
3799
3800 bool OCCViewer_ViewWindow::isActionVisible( ActionId theId ) const
3801 {
3802   QAction* a = toolMgr()->action( theId );
3803   return a && a->isVisible();
3804 }
3805
3806 void OCCViewer_ViewWindow::setActionVisible( ActionId theId, bool isVisible )
3807 {
3808   QAction* a = toolMgr()->action( theId );
3809   if( a )
3810     a->setVisible( isVisible );
3811 }
3812
3813 void OCCViewer_ViewWindow::projAndPanToGravity(V3d_TypeOfOrientation CamOri)
3814 {
3815   const bool USE_XY = true;
3816
3817   Handle(V3d_View) aView3d = myViewPort->getView();
3818   if (aView3d.IsNull())
3819     return;
3820
3821   bool IsGr = false;
3822   double X = 0, Y = 0, Z = 0;
3823   if( USE_XY )
3824   {
3825     const double EPS = 1E-6;
3826     int xp = myViewPort->width()/2, yp = myViewPort->height()/2;
3827     aView3d->Convert( xp, yp, X, Y, Z );
3828
3829     gp_Dir d = aView3d->Camera()->Direction();
3830     if( fabs( d.Z() ) > EPS )
3831     {
3832       double t = -Z/d.Z();
3833       X += t*d.X();
3834       Y += t*d.Y();
3835       Z += t*d.Z();
3836     }
3837   }
3838
3839   // It is really necessary to compute gravity center even if it is not used in part of code below.
3840   // Without this calculation the SetProj() method and other methods are not correct.
3841   double X2, Y2, Z2;
3842   IsGr = computeGravityCenter(X2, Y2, Z2);
3843   if ( !IsGr )
3844     IsGr = OCCViewer_Utilities::computeSceneBBCenter(aView3d, X2, Y2, Z2);
3845
3846   aView3d->SetProj(CamOri);
3847   if (IsGr)
3848   {
3849     //aView3d->Update();
3850     Handle(Graphic3d_Camera) Cam = aView3d->Camera();
3851     gp_XYZ gp(X, Y, Z);
3852     gp_Vec dir (Cam->Direction());
3853     gp_Pnt eye = Cam->Eye();
3854     gp_Vec V1(eye, gp);
3855     Standard_Real D = dir.Dot(V1);
3856     gp_Pnt ppdir = eye.Translated(D*dir);
3857     gp_Vec V2(ppdir, gp);
3858     gp_XYZ trEye = eye.XYZ() + V2.XYZ();
3859
3860     double xat, yat, zat;
3861     aView3d->At(xat, yat, zat);
3862     gp_Pnt At(xat, yat, zat);
3863     gp_XYZ trAt = At.XYZ() + V2.XYZ();
3864     aView3d->SetEye(trEye.X(), trEye.Y(), trEye.Z());
3865     aView3d->SetAt(trAt.X(), trAt.Y(), trAt.Z());
3866   }
3867 }
3868
3869
3870 bool OCCViewer_ViewWindow::isAutomaticZoom() const
3871 {
3872   return myAutomaticZoom;
3873 }
3874
3875 void OCCViewer_ViewWindow::setAutomaticZoom(const bool isOn)
3876 {
3877   myAutomaticZoom = isOn;
3878 }
3879
3880
3881 void OCCViewer_ViewWindow::enableAutoRotation( const bool isEnable )
3882 {
3883   SUIT_ViewWindow::enableAutoRotation(isEnable);
3884   if (myAutoRotate) {
3885     delete myAutoRotate;
3886     myAutoRotate = nullptr;
3887   }
3888   if (isEnable) {
3889     myAutoRotate = new OCCViewer_AutoRotate(this);
3890   }
3891 }