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