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