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