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