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