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