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