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