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