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