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