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