Salome HOME
updated copyright message
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewWindow.cxx
1 // Copyright (C) 2007-2023  CEA, EDF, 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   if (myModel->viewCubeActivated()) {
1408     aAction = new QtxAction(tr("MNU_SHOW_VIEWCUBE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_VIEWCUBE" ) ),
1409                              tr( "MNU_SHOW_VIEWCUBE" ), 0, this);
1410     aAction->setCheckable( true );
1411     aAction->setChecked( aResMgr->booleanValue( "OCCViewer", "viewcube_show", true ) );
1412     aAction->setStatusTip(tr("DSC_SHOW_VIEWCUBE"));
1413     connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onViewCubeShow(bool)));
1414     toolMgr()->registerAction( aAction, ViewCubeShowId );
1415   }
1416
1417   // Scale
1418   aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
1419                            tr( "MNU_SCALING" ), 0, this);
1420   aAction->setStatusTip(tr("DSC_SCALING"));
1421   connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
1422   toolMgr()->registerAction( aAction, AxialScaleId );
1423
1424   // Enable/disable preselection
1425   aAction = new QtxAction(tr("MNU_ENABLE_PRESELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESELECTION" ) ),
1426                           tr( "MNU_ENABLE_PRESELECTION" ), 0, this);
1427   aAction->setStatusTip(tr("DSC_ENABLE_PRESELECTION"));
1428   aAction->setCheckable(true);
1429   connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchPreselection(bool)));
1430   toolMgr()->registerAction( aAction, SwitchPreselectionId );
1431
1432   // Enable/disable selection
1433   aAction = new QtxAction(tr("MNU_ENABLE_SELECTION"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SELECTION" ) ),
1434                           tr( "MNU_ENABLE_SELECTION" ), 0, this);
1435   aAction->setStatusTip(tr("DSC_ENABLE_SELECTION"));
1436   aAction->setCheckable(true);
1437   connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchSelection(bool)));
1438   toolMgr()->registerAction( aAction, SwitchSelectionId );
1439
1440   // Graduated axes
1441   aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
1442                            tr( "MNU_GRADUATED_AXES" ), 0, this);
1443   aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
1444   connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
1445   toolMgr()->registerAction( aAction, GraduatedAxesId );
1446
1447   // Active only ambient light or not
1448   aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
1449                            tr( "MNU_AMBIENT" ), 0, this);
1450   aAction->setStatusTip(tr("DSC_AMBIENT"));
1451   connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
1452   toolMgr()->registerAction( aAction, AmbientId );
1453
1454   // Switch between interaction styles
1455   aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
1456                           tr( "MNU_STYLE_SWITCH" ), 0, this);
1457   aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
1458   aAction->setCheckable(true);
1459   connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
1460   toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
1461
1462   // Switch between zooming styles
1463   aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
1464                           tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
1465   aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
1466   aAction->setCheckable(true);
1467   connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
1468   toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
1469
1470   // Switch advanced selection style (poligone/circle)
1471   aAction = new QtxAction(tr("MNU_RECTANGLE_SELECTION_STYLE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RECT_STYLE" ) ),
1472                           tr( "MNU_RECTANGLE_SELECTION_STYLE" ), 0, this);
1473   aAction->setStatusTip(tr("DSC_RECTANGLE_SELECTION_STYLE"));
1474   aAction->setCheckable(true);
1475   toolMgr()->registerAction( aAction, RectangleSelectionStyleId);
1476
1477   aAction = new QtxAction(tr("MNU_POLYGON_SELECTION_STYLE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_POLY_STYLE" ) ),
1478                           tr( "MNU_POLYGON_SELECTION_STYLE" ), 0, this);
1479   aAction->setStatusTip(tr("DSC_POLYGON_SELECTION_STYLE"));
1480   aAction->setCheckable(true);
1481   toolMgr()->registerAction( aAction, PolygonSelectionStyleId);
1482
1483   aAction = new QtxAction(tr("MNU_CIRCLE_SELECTION_STYLE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CIRCLE_STYLE" ) ),
1484                           tr( "MNU_CIRCLE_SELECTION_STYLE" ), 0, this);
1485   aAction->setStatusTip(tr("DSC_CIRCLE_SELECTION_STYLE"));
1486   aAction->setCheckable(true);
1487   toolMgr()->registerAction( aAction, CircleSelectionStyleId);
1488
1489   // - add exclusive action group
1490   QActionGroup* aSelectionGroup = new QActionGroup(this);
1491   aSelectionGroup->addAction(toolMgr()->action(RectangleSelectionStyleId));
1492   aSelectionGroup->addAction(toolMgr()->action(PolygonSelectionStyleId));
1493   aSelectionGroup->addAction(toolMgr()->action(CircleSelectionStyleId));
1494   connect(aSelectionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onSwitchSelectionStyle(QAction*)));
1495
1496   // Maximized view
1497   aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
1498                           tr( "MNU_MINIMIZE_VIEW" ), 0, this );
1499   aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
1500   connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
1501   toolMgr()->registerAction( aAction, MaximizedId );
1502
1503   // Return to 3d view
1504   if (my2dMode!=No2dMode){
1505     aAction = new QtxAction(tr("MNU_RETURN_3D_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_RETURN_3D_VIEW" ) ),
1506                             tr( "MNU_RETURN_3D_VIEW" ), 0, this );
1507     aAction->setStatusTip(tr("DSC_RETURN_3D_VIEW"));
1508     connect(aAction, SIGNAL(triggered()), this, SLOT(returnTo3dView()));
1509     toolMgr()->registerAction( aAction, ReturnTo3dViewId );
1510   }
1511
1512   // Synchronize View
1513   toolMgr()->registerAction( synchronizeAction(), SynchronizeId );
1514 #ifdef ENABLE_RAY_TRACING
1515   // Ray tracing
1516   aAction = new QtxAction( tr("MNU_RAY_TRACING"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_RAY_TRACING") ),
1517                            tr("MNU_RAY_TRACING"), 0, this );
1518   aAction->setStatusTip( tr("DSC_RAY_TRACING") );
1519   connect( aAction, SIGNAL( triggered() ), this, SLOT( onRayTracing() ) );
1520   toolMgr()->registerAction( aAction, RayTracingId );
1521
1522   // Environment texture
1523   aAction = new QtxAction( tr("MNU_ENV_TEXTURE"), aResMgr->loadPixmap( "OCCViewer", tr("ICON_OCCVIEWER_ENV_TEXTURE") ),
1524                            tr("MNU_ENV_TEXTURE"), 0, this );
1525   aAction->setStatusTip( tr("DSC_ENV_TEXTURE") );
1526   connect( aAction, SIGNAL( triggered() ), this, SLOT( onEnvTexture() ) );
1527   toolMgr()->registerAction( aAction, EnvTextureId );
1528
1529   // Light source
1530   aAction = new QtxAction( tr("MNU_LIGHT_SOURCE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_LIGHT_SOURCE" ) ),
1531                            tr( "MNU_LIGHT_SOURCE" ), 0, this );
1532   aAction->setStatusTip( tr("DSC_LIGHT_SOURCE") );
1533   connect( aAction, SIGNAL( triggered() ), this, SLOT( onLightSource() ) );
1534   toolMgr()->registerAction( aAction, LightSourceId );
1535 #endif
1536 }
1537
1538 /*!
1539   \brief Create toolbar.
1540 */
1541 void OCCViewer_ViewWindow::createToolBar()
1542 {
1543   static const char* titles[] = {
1544     "LBL_3DTOOLBAR_LABEL",
1545     "LBL_XYTOOLBAR_LABEL",
1546     "LBL_XZTOOLBAR_LABEL",
1547     "LBL_YZTOOLBAR_LABEL",
1548   };
1549   static const char* names[] = {
1550     "OCCViewer3DViewOperations",
1551     "OCCViewerXYViewOperations",
1552     "OCCViewerXZViewOperations",
1553     "OCCViewerYZViewOperations",
1554   };
1555   int tid = toolMgr()->createToolBar( tr( titles[my2dMode] ),        // title (language-dependant)
1556                                       QString( names[my2dMode] ),    // name (language-independant)
1557                                       false );                       // disable floatable toolbar
1558   if ( my2dMode != No2dMode ){
1559     toolMgr()->append( ReturnTo3dViewId, tid );
1560     toolMgr()->append( toolMgr()->separator(), tid );
1561   }
1562   toolMgr()->append( DumpId, tid );
1563   toolMgr()->append( SwitchInteractionStyleId, tid );
1564   toolMgr()->append( SwitchZoomingStyleId, tid );
1565   toolMgr()->append( SwitchPreselectionId, tid );
1566   toolMgr()->append( SwitchSelectionId, tid );
1567
1568   QtxMultiAction* aSelectionAction = new QtxMultiAction(this);
1569   aSelectionAction->insertAction(toolMgr()->action(RectangleSelectionStyleId));
1570   aSelectionAction->insertAction(toolMgr()->action(PolygonSelectionStyleId));
1571   aSelectionAction->insertAction(toolMgr()->action(CircleSelectionStyleId));
1572   toolMgr()->append(aSelectionAction, tid );
1573
1574   if( myModel->trihedronActivated() )
1575     toolMgr()->append( TrihedronShowId, tid );
1576
1577   if( myModel->viewCubeActivated() )
1578     toolMgr()->append( ViewCubeShowId, tid );
1579
1580   QtxMultiAction* aScaleAction = new QtxMultiAction( this );
1581   aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
1582   aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
1583   aScaleAction->insertAction( toolMgr()->action( FitSelectionId ) );
1584   aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
1585   toolMgr()->append( aScaleAction, tid );
1586
1587   QtxMultiAction* aPanningAction = new QtxMultiAction( this );
1588   aPanningAction->insertAction( toolMgr()->action( PanId ) );
1589   aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
1590   toolMgr()->append( aPanningAction, tid );
1591
1592   if (my2dMode == No2dMode) {
1593     toolMgr()->append( ChangeRotationPointId, tid );
1594     toolMgr()->append( RotationId, tid );
1595
1596     QtxMultiAction* aViewsAction = new QtxMultiAction( this );
1597     aViewsAction->insertAction( toolMgr()->action( FrontId ) );
1598     aViewsAction->insertAction( toolMgr()->action( BackId ) );
1599     aViewsAction->insertAction( toolMgr()->action( TopId ) );
1600     aViewsAction->insertAction( toolMgr()->action( BottomId ) );
1601     aViewsAction->insertAction( toolMgr()->action( LeftId ) );
1602     aViewsAction->insertAction( toolMgr()->action( RightId ) );
1603     toolMgr()->append( aViewsAction, tid );
1604
1605     toolMgr()->append( AntiClockWiseId, tid );
1606     toolMgr()->append( ClockWiseId, tid );
1607
1608     toolMgr()->append( OrthographicId, tid );
1609     toolMgr()->append( PerspectiveId, tid );
1610     toolMgr()->append( StereoId, tid );
1611
1612     toolMgr()->append( ResetId, tid );
1613   }
1614
1615   QtxMultiAction* aMemAction = new QtxMultiAction( this );
1616   aMemAction->insertAction( toolMgr()->action( MemId ) );
1617   aMemAction->insertAction( toolMgr()->action( RestoreId ) );
1618   toolMgr()->append( aMemAction, tid );
1619
1620   toolMgr()->append( toolMgr()->separator(), tid );
1621   toolMgr()->append( CloneId, tid );
1622
1623   toolMgr()->append( toolMgr()->separator(), tid );
1624   toolMgr()->append( ClippingId, tid );
1625   toolMgr()->append( AxialScaleId, tid );
1626   toolMgr()->append( GraduatedAxesId, tid );
1627   toolMgr()->append( AmbientId, tid );
1628
1629   toolMgr()->append( MaximizedId, tid );
1630   toolMgr()->append( SynchronizeId, tid );
1631 #ifdef ENABLE_RAY_TRACING
1632   toolMgr()->append( RayTracingId, tid );
1633   toolMgr()->append( EnvTextureId, tid );
1634   toolMgr()->append( LightSourceId, tid );
1635 #endif
1636 }
1637
1638 /*!
1639   \brief Perform 'fit all' operation.
1640 */
1641 void OCCViewer_ViewWindow::onViewFitAll()
1642 {
1643   myViewPort->fitAll();
1644 }
1645
1646 /*!
1647   \brief Perform "front view" transformation.
1648 */
1649 void OCCViewer_ViewWindow::onFrontView()
1650 {
1651   emit vpTransformationStarted ( FRONTVIEW );
1652   Handle(V3d_View) aView3d = myViewPort->getView();
1653   if (myAutomaticZoom)
1654   {
1655     if ( !aView3d.IsNull() ) 
1656       aView3d->SetProj (V3d_Xpos);
1657     onViewFitAll();
1658   }
1659   else
1660     projAndPanToGravity(V3d_Xpos);
1661   emit vpTransformationFinished ( FRONTVIEW );
1662 }
1663
1664 /*!
1665   \brief Perform "back view" transformation.
1666 */
1667 void OCCViewer_ViewWindow::onBackView()
1668 {
1669   emit vpTransformationStarted ( BACKVIEW );
1670   Handle(V3d_View) aView3d = myViewPort->getView();
1671   if (myAutomaticZoom)
1672   {
1673     if ( !aView3d.IsNull() ) 
1674       aView3d->SetProj (V3d_Xneg);
1675     onViewFitAll();
1676   }
1677   else
1678     projAndPanToGravity(V3d_Xneg);
1679   emit vpTransformationFinished ( BACKVIEW );
1680 }
1681
1682 /*!
1683   \brief Perform "top view" transformation.
1684 */
1685 void OCCViewer_ViewWindow::onTopView()
1686 {
1687   emit vpTransformationStarted ( TOPVIEW );
1688   Handle(V3d_View) aView3d = myViewPort->getView();
1689   if (myAutomaticZoom)
1690   {
1691     if ( !aView3d.IsNull() ) 
1692       aView3d->SetProj (V3d_Zpos);
1693     onViewFitAll();
1694   }
1695   else
1696     projAndPanToGravity(V3d_Zpos);
1697   emit vpTransformationFinished ( TOPVIEW );
1698 }
1699
1700 /*!
1701   \brief Perform "bottom view" transformation.
1702 */
1703 void OCCViewer_ViewWindow::onBottomView()
1704 {
1705   emit vpTransformationStarted ( BOTTOMVIEW );
1706   Handle(V3d_View) aView3d = myViewPort->getView();
1707   if (myAutomaticZoom)
1708   {
1709     if ( !aView3d.IsNull() ) 
1710       aView3d->SetProj (V3d_Zneg);
1711     onViewFitAll();
1712   }
1713   else
1714     projAndPanToGravity(V3d_Zneg);
1715   emit vpTransformationFinished ( BOTTOMVIEW );
1716 }
1717
1718 /*!
1719   \brief Perform "left view" transformation.
1720 */
1721 void OCCViewer_ViewWindow::onLeftView()
1722 {
1723   emit vpTransformationStarted ( LEFTVIEW );
1724   Handle(V3d_View) aView3d = myViewPort->getView();
1725   if (myAutomaticZoom)
1726   {
1727     if ( !aView3d.IsNull() ) 
1728       aView3d->SetProj (V3d_Yneg);
1729     onViewFitAll();
1730   }
1731   else
1732     projAndPanToGravity(V3d_Yneg);
1733   emit vpTransformationFinished ( LEFTVIEW );
1734 }
1735
1736 /*!
1737   \brief Perform "right view" transformation.
1738 */
1739 void OCCViewer_ViewWindow::onRightView()
1740 {
1741   emit vpTransformationStarted ( RIGHTVIEW );
1742   Handle(V3d_View) aView3d = myViewPort->getView();
1743   if (myAutomaticZoom)
1744   {
1745     if ( !aView3d.IsNull() ) 
1746       aView3d->SetProj (V3d_Ypos);
1747     onViewFitAll();
1748   }
1749   else
1750     projAndPanToGravity(V3d_Ypos);
1751   emit vpTransformationFinished ( RIGHTVIEW );
1752 }
1753
1754 /*!
1755   \brief Rotate view 90 degrees clockwise
1756 */
1757 void OCCViewer_ViewWindow::onClockWiseView()
1758 {
1759   emit vpTransformationStarted ( CLOCKWISEVIEW );
1760   myViewPort->rotateXY( 90. );
1761   emit vpTransformationFinished ( CLOCKWISEVIEW );
1762 }
1763
1764 /*!
1765   \brief Rotate view 90 degrees conterclockwise
1766 */
1767 void OCCViewer_ViewWindow::onAntiClockWiseView()
1768 {
1769   emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
1770   myViewPort->rotateXY( -90. );
1771   emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
1772 }
1773
1774 /*!
1775   \brief Perform "reset view" transformation.
1776
1777   Sets default orientation of the viewport camera.
1778 */
1779 void OCCViewer_ViewWindow::onResetView()
1780 {
1781   emit vpTransformationStarted( RESETVIEW );
1782   bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1783   myViewPort->getView()->Reset( false );
1784   myViewPort->fitAll( false, true, false );
1785   myViewPort->getView()->SetImmediateUpdate( upd );
1786   onProjectionType(); // needed to apply projection type properly after reset
1787   myViewPort->getView()->Update();
1788   emit vpTransformationFinished( RESETVIEW );
1789 }
1790
1791 /*!
1792   \brief Set the given projection mode.
1793
1794   Set the given projection mode: Orthographic or Perspective.
1795 */
1796 void OCCViewer_ViewWindow::onProjectionType( QAction* theAction )
1797 {
1798   Handle(V3d_View) aView3d = myViewPort->getView();
1799   if ( !aView3d.IsNull() ) {
1800     Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1801     if (theAction == toolMgr()->action( OrthographicId )) {
1802       myModel->setProjectionType(Orthographic);
1803       aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Orthographic );
1804       aCamera->SetFOVy(45.0);
1805     }
1806     else if (theAction == toolMgr()->action( PerspectiveId )) {
1807       myModel->setProjectionType(Perspective);
1808       aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Perspective );
1809       aCamera->SetFOVy(30.0);
1810     }
1811     if (toolMgr()->action( StereoId )->isChecked()) {
1812       aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1813       aCamera->SetFOVy(30.0);
1814     }
1815     aView3d->Redraw();
1816     onViewFitAll();
1817   }
1818 }
1819
1820 /*!
1821   \brief Sets Stereo projection mode.
1822
1823   Sets Stereo projection mode.
1824 */
1825 void OCCViewer_ViewWindow::onStereoType( bool activate )
1826 {
1827   Handle(V3d_View) aView3d = myViewPort->getView();
1828   if ( !aView3d.IsNull() ) {
1829     Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
1830     if (activate) {
1831       toolMgr()->action( PerspectiveId )->setChecked(true);
1832       aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1833       toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(false);
1834
1835       aCamera->SetProjectionType ( Graphic3d_Camera::Projection_Stereo );
1836       SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1837       setStereoType( aResMgr->integerValue( "OCCViewer", "stereo_type", 0 ) );
1838       setAnaglyphFilter( aResMgr->integerValue( "OCCViewer", "anaglyph_filter", 0 ) );
1839       setReverseStereo( aResMgr->booleanValue( "OCCViewer", "reverse_stereo", false ) );
1840       setVSync( aResMgr->booleanValue( "OCCViewer", "enable_vsync", true ) );
1841       setQuadBufferSupport( aResMgr->booleanValue( "OCCViewer", "enable_quad_buffer_support", false ) );
1842     }
1843     else {
1844       toolMgr()->action( PerspectiveId )->actionGroup()->setEnabled(true);
1845       if (myModel->projectionType() == Orthographic) {
1846         toolMgr()->action( OrthographicId )->setChecked(true);
1847         aCamera->SetProjectionType(Graphic3d_Camera::Projection_Orthographic);
1848       }
1849       else if (myModel->projectionType() == Perspective) {
1850         toolMgr()->action( PerspectiveId )->setChecked(true);
1851         aCamera->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
1852       }
1853     }
1854     aView3d->Redraw();
1855     onViewFitAll();
1856   }
1857
1858   if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1859        toolMgr()->action( StereoId )->isChecked() )
1860     SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ),  tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1861 }
1862
1863 /*!
1864   \brief Restore the view.
1865
1866   Restore the projection mode based on tool-buttons states.
1867 */
1868 void OCCViewer_ViewWindow::onProjectionType()
1869 {
1870   emit vpTransformationStarted( PROJECTION );
1871   if (toolMgr()->action( OrthographicId )->isChecked())
1872     setProjectionType( Orthographic );
1873   if (toolMgr()->action( PerspectiveId )->isChecked())
1874     setProjectionType( Perspective );
1875   if (toolMgr()->action( StereoId )->isChecked())
1876     setProjectionType( Stereo );
1877   emit vpTransformationFinished( PROJECTION );
1878 }
1879
1880 void OCCViewer_ViewWindow::setProjectionType( int mode )
1881 {
1882   QtxAction* anOrthographicAction = dynamic_cast<QtxAction*>( toolMgr()->action( OrthographicId ) );
1883   QtxAction* aPerspectiveAction = dynamic_cast<QtxAction*>( toolMgr()->action( PerspectiveId ) );
1884   QtxAction* aStereoAction = dynamic_cast<QtxAction*>( toolMgr()->action( StereoId ) );
1885   switch ( mode ) {
1886     case Orthographic:
1887       onProjectionType( anOrthographicAction );
1888       break;
1889     case Perspective:
1890       onProjectionType( aPerspectiveAction );
1891       break;
1892     case Stereo:
1893       onStereoType( true );
1894       break;
1895   }
1896   // update action state if method is called outside
1897   if ( mode == Orthographic && !anOrthographicAction->isChecked() ) {
1898           anOrthographicAction->setChecked( true );
1899           aStereoAction->setChecked( false );
1900   }
1901   if ( mode == Perspective && !aPerspectiveAction->isChecked() ) {
1902           aPerspectiveAction->setChecked( true );
1903           aStereoAction->setChecked( false );
1904   }
1905   if ( mode == Stereo ) {
1906     aStereoAction->setChecked( true );
1907     if ( anOrthographicAction->isEnabled() ) {
1908       anOrthographicAction->setEnabled( false );
1909       anOrthographicAction->setChecked( false );
1910       aStereoAction->setChecked( false );
1911     }
1912     else {
1913       anOrthographicAction->setEnabled( true );
1914       aStereoAction->setChecked( false );
1915       anOrthographicAction->setChecked(myModel->projectionType() == Orthographic);
1916     }
1917     if ( aPerspectiveAction->isEnabled() ) {
1918       aPerspectiveAction->setEnabled( false );
1919       aPerspectiveAction->setChecked( true );
1920       if ( isQuadBufferSupport() && !isOpenGlStereoSupport() && stereoType() == QuadBuffer &&
1921            toolMgr()->action( StereoId )->isChecked() )
1922         SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ),  tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
1923     }
1924     else {
1925       aPerspectiveAction->setEnabled( true );
1926       aStereoAction->setChecked( false );
1927       aPerspectiveAction->setChecked(myModel->projectionType() == Perspective);
1928       onProjectionType();
1929     }
1930   }
1931   else {
1932     if ( !anOrthographicAction->isEnabled() )
1933       anOrthographicAction->setEnabled( true );
1934     if ( !aPerspectiveAction->isEnabled() )
1935       aPerspectiveAction->setEnabled( true );
1936   }
1937 }
1938
1939 /*!
1940   \brief Perform "fit all" transformation.
1941 */
1942 void OCCViewer_ViewWindow::onFitAll()
1943 {
1944   emit vpTransformationStarted( FITALLVIEW );
1945   if (myModel->fitter())
1946     myModel->fitter()->fitAll(myViewPort->getView());
1947   else
1948     myViewPort->fitAll();
1949   emit vpTransformationFinished( FITALLVIEW );
1950 }
1951
1952 /*!
1953   \brief Perform "fit selection" transformation.
1954 */
1955 void OCCViewer_ViewWindow::onFitSelection()
1956 {
1957   emit vpTransformationStarted( FITSELECTION );
1958   myModel->getAISContext()->FitSelected( getViewPort()->getView() );
1959   emit vpTransformationFinished( FITSELECTION );
1960 }
1961
1962 /*!
1963   \brief Called if 'change rotation point' operation is activated.
1964   \param on action state
1965 */
1966 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
1967 {
1968   if (on)
1969   {
1970     if (!mySetRotationPointDlg)
1971     {
1972       mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
1973       mySetRotationPointDlg->SetAction(mySetRotationPointAction);
1974     }
1975
1976     if (!mySetRotationPointDlg->isVisible())
1977     {
1978       //if (mySetRotationPointDlg->IsFirstShown())
1979       if (myCurrPointType == BBCENTER)
1980       {
1981         Standard_Real Xcenter, Ycenter, Zcenter;
1982         if (OCCViewer_Utilities::computeVisibleBBCenter(myViewPort->getView(), Xcenter, Ycenter, Zcenter))
1983           mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
1984       }
1985       mySetRotationPointDlg->show();
1986     }
1987   }
1988   else
1989   {
1990     if (mySetRotationPointDlg->isVisible())
1991       mySetRotationPointDlg->hide();
1992   }
1993 }
1994
1995 /*!
1996    \brief Create one more window with same content.
1997 */
1998 void OCCViewer_ViewWindow::onCloneView()
1999 {
2000   SUIT_ViewWindow* vw = myManager->createViewWindow();
2001   //vw->show();
2002   emit viewCloned( vw );
2003   OCCViewer_ViewWindow* occVw = dynamic_cast<OCCViewer_ViewWindow*> (vw);
2004   if(occVw && occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)) {
2005     occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)->synchronize(this);
2006   }
2007 }
2008
2009 /*!
2010   Creates one more window with same content
2011 */
2012 void OCCViewer_ViewWindow::onAxialScale()
2013 {
2014   if ( !myScalingDlg )
2015     myScalingDlg = new OCCViewer_AxialScaleDlg( this , myModel );
2016
2017   if ( !myScalingDlg->isVisible() )
2018   {
2019     myScalingDlg->Update();
2020     myScalingDlg->show();
2021   }
2022 }
2023
2024 /*!
2025   Shows Graduated Axes dialog
2026 */
2027 void OCCViewer_ViewWindow::onGraduatedAxes()
2028 {
2029   myCubeAxesDlg->Update();
2030   myCubeAxesDlg->show();
2031 }
2032
2033 void OCCViewer_ViewWindow::onAmbientToogle()
2034 {
2035   Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2036   viewer->InitDefinedLights();
2037   while(viewer->MoreDefinedLights())
2038     {
2039       Handle(V3d_Light) light = viewer->DefinedLight();
2040       if(light->Type() != V3d_AMBIENT)
2041         {
2042           Handle(V3d_View) aView3d = myViewPort->getView();
2043           if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
2044           else viewer->SetLightOn(light);
2045         }
2046       viewer->NextDefinedLights();
2047     }
2048   viewer->Update();
2049 }
2050
2051 /*!
2052   \brief Store view parameters.
2053 */
2054 void OCCViewer_ViewWindow::onMemorizeView()
2055 {
2056   appendViewAspect( getViewParams() );
2057 }
2058
2059 /*!
2060   \brief Restore view parameters.
2061 */
2062 void OCCViewer_ViewWindow::onRestoreView()
2063 {
2064   OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
2065   connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
2066   aDlg->exec();
2067   updateViewAspects( aDlg->parameters() );
2068   if( myRestoreFlag && aDlg->parameters().count() )
2069     performRestoring( aDlg->currentItem() );
2070 }
2071
2072 /*!
2073   \brief Restore view parameters.
2074   \param anItem view parameters
2075 */
2076 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
2077 {
2078   Handle(V3d_View) aView3d = myViewPort->getView();
2079
2080   Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
2081   aView3d->SetScale( anItem.scale );
2082   aView3d->SetTwist( anItem.twist );
2083   aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
2084   aView3d->SetImmediateUpdate( prev );
2085   aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2086   aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2087   aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
2088
2089   if ( anItem.centerX != 0.0 || anItem.centerY != 0.0 )
2090   {
2091     double anUpX = 0.0, anUpY = 0.0, anUpZ = 0.0;
2092
2093     // "eye" and "at" require conversion to represent center panning
2094     // up direction is only available after setting angle of twist and
2095     // other view parameters
2096     aView3d->Up( anUpX, anUpY, anUpZ );
2097
2098     gp_Dir aProj( -anItem.projX, -anItem.projY, -anItem.projZ );
2099     gp_Dir anUp( anUpX, anUpY, anUpZ );
2100     gp_Pnt anAt( anItem.atX, anItem.atY, anItem.atZ );
2101     gp_Pnt anEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
2102     gp_Dir aSide = aProj ^ anUp;
2103
2104     anAt.Translate( gp_Vec( aSide ) * anItem.centerX );
2105     anAt.Translate( gp_Vec( anUp  ) * anItem.centerY );
2106
2107     aView3d->SetAt( anAt.X(), anAt.Y(), anAt.Z() );
2108     aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
2109   }
2110
2111   if ( !baseParamsOnly ) {
2112
2113     myModel->setTrihedronShown( anItem.isVisible );
2114     myModel->setTrihedronSize( anItem.size );
2115
2116     myModel->setViewCubeShown( anItem.vcIsVisible );
2117
2118     // graduated trihedron
2119     bool anIsVisible = anItem.gtIsVisible;
2120     OCCViewer_AxisWidget::AxisData anAxisData[3];
2121     anAxisData[0].DrawName = anItem.gtDrawNameX;
2122     anAxisData[1].DrawName = anItem.gtDrawNameZ;
2123     anAxisData[2].DrawName = anItem.gtDrawNameZ;
2124     anAxisData[0].Name = anItem.gtNameX;
2125     anAxisData[1].Name = anItem.gtNameZ;
2126     anAxisData[2].Name = anItem.gtNameZ;
2127     anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
2128               anItem.gtNameColorGX,
2129               anItem.gtNameColorBX );
2130     anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
2131               anItem.gtNameColorGY,
2132               anItem.gtNameColorBY );
2133     anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
2134               anItem.gtNameColorGZ,
2135               anItem.gtNameColorBZ );
2136     anAxisData[0].DrawValues = anItem.gtDrawValuesX;
2137     anAxisData[1].DrawValues = anItem.gtDrawValuesY;
2138     anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
2139     anAxisData[0].NbValues = anItem.gtNbValuesX;
2140     anAxisData[1].NbValues = anItem.gtNbValuesY;
2141     anAxisData[2].NbValues = anItem.gtNbValuesZ;
2142     anAxisData[0].Offset = anItem.gtOffsetX;
2143     anAxisData[1].Offset = anItem.gtOffsetY;
2144     anAxisData[2].Offset = anItem.gtOffsetZ;
2145     anAxisData[0].Color = QColor( anItem.gtColorRX,
2146           anItem.gtColorGX,
2147           anItem.gtColorBX );
2148     anAxisData[1].Color = QColor( anItem.gtColorRY,
2149           anItem.gtColorGY,
2150           anItem.gtColorBY );
2151     anAxisData[2].Color = QColor( anItem.gtColorRZ,
2152           anItem.gtColorGZ,
2153           anItem.gtColorBZ );
2154     anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
2155     anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
2156     anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
2157     anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
2158     anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
2159     anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
2160
2161     myCubeAxesDlg->SetData( anIsVisible, anAxisData );
2162     myCubeAxesDlg->ApplyData( aView3d );
2163
2164   } // if ( !baseParamsOnly )
2165
2166   myRestoreFlag = 0;
2167 }
2168
2169 /*!
2170   \brief Set restore flag.
2171 */
2172 void OCCViewer_ViewWindow::setRestoreFlag()
2173 {
2174   myRestoreFlag = 1;
2175 }
2176
2177 /*!
2178   \brief Called when action "show/hide trihedron" is activated.
2179 */
2180 void OCCViewer_ViewWindow::onTrihedronShow(bool show)
2181 {
2182   myModel->setTrihedronShown(show);
2183 }
2184
2185 /*!
2186   \brief Called when action "show/hide view cube" is activated.
2187 */
2188 void OCCViewer_ViewWindow::onViewCubeShow(bool show)
2189 {
2190   myModel->setViewCubeShown(show);
2191 }
2192
2193 /*!
2194   \brief Toggles preselection (highlighting) on/off
2195 */
2196 void OCCViewer_ViewWindow::onSwitchPreselection( bool on )
2197 {
2198   myPreselectionEnabled = on;
2199   myModel->setSelectionOptions( isPreselectionEnabled(), myModel->isSelectionEnabled() );
2200
2201   // unhighlight all highlighted objects
2202   /*if ( !on ) {
2203     myModel->unHighlightAll( true, false );
2204   }*/
2205
2206   // update action state if method is called outside
2207   QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2208   if ( a && a->isChecked() != on ) {
2209     a->setChecked( on );
2210   }
2211 }
2212
2213 /*!
2214   \brief Toggles selection on/off
2215 */
2216 void OCCViewer_ViewWindow::onSwitchSelection( bool on )
2217 {
2218   mySelectionEnabled = on;
2219   myModel->setSelectionOptions( myModel->isPreselectionEnabled(), isSelectionEnabled() );
2220
2221   // update action state if method is called outside
2222
2223   // preselection
2224   QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchPreselectionId ) );
2225   if ( a ) {
2226     a->setEnabled( on );
2227   }
2228
2229   // selection
2230   a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchSelectionId ) );
2231   if ( a && a->isChecked() != on ) {
2232     a->setChecked( on );
2233   }
2234 }
2235
2236 /*!
2237   \brief Switches style of advanced multiple selection by Poligon/Circle
2238 */
2239 void OCCViewer_ViewWindow::onSwitchSelectionStyle(QAction* theAction)
2240 {
2241   // selection
2242   OCCViewer_ViewSketcher* aSkecher = getSketcher(Polygon);
2243   if (aSkecher) {
2244     if (theAction == toolMgr()->action(PolygonSelectionStyleId)) {
2245       aSkecher->setSketcherMode(OCCViewer_PolygonSketcher::Poligone);
2246     }
2247     else if (theAction == toolMgr()->action(CircleSelectionStyleId)) {
2248       aSkecher->setSketcherMode(OCCViewer_PolygonSketcher::Circle);
2249     }
2250   }
2251 }
2252
2253 /*!
2254 Returns currently selected selection style
2255 */
2256 OCCViewer_ViewWindow::SelectionStyle OCCViewer_ViewWindow::selectionStyle() const
2257 {
2258   if (toolMgr()->action(PolygonSelectionStyleId)->isChecked())
2259     return PolygonStyle;
2260   if (toolMgr()->action(CircleSelectionStyleId)->isChecked())
2261     return CyrcleStyle;
2262   return RectStyle;
2263 }
2264
2265 void OCCViewer_ViewWindow::setSelectionStyle(SelectionStyle theMode)
2266 {
2267   toolMgr()->action(RectangleSelectionStyleId)->setChecked(false);
2268   toolMgr()->action(PolygonSelectionStyleId)->setChecked(false);
2269   toolMgr()->action(CircleSelectionStyleId)->setChecked(false);
2270   switch (theMode) {
2271   case RectStyle:
2272     toolMgr()->action(RectangleSelectionStyleId)->setChecked(true);
2273     break;
2274   case PolygonStyle:
2275     toolMgr()->action(PolygonSelectionStyleId)->setChecked(true);
2276     break;
2277   case CyrcleStyle:
2278     toolMgr()->action(CircleSelectionStyleId)->setChecked(true);
2279   }
2280 }
2281
2282 /*!
2283   \brief Switches "keyboard free" interaction style on/off
2284 */
2285 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
2286 {
2287   myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
2288
2289   // update action state if method is called outside
2290   QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
2291   if ( a && a->isChecked() != on )
2292     a->setChecked( on );
2293 }
2294
2295 /*!
2296   \brief Toogles advanced zooming style (relatively to the cursor position) on/off
2297 */
2298 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
2299 {
2300   myViewPort->setAdvancedZoomingEnabled( on );
2301
2302   // update action state if method is called outside
2303   QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
2304   if ( a && a->isChecked() != on )
2305     a->setChecked( on );
2306 }
2307
2308 /*!
2309   \brief Get current interaction style
2310   \return interaction style
2311 */
2312 int OCCViewer_ViewWindow::interactionStyle() const
2313 {
2314   return myInteractionStyle;
2315 }
2316
2317 /*!
2318   \brief Set current interaction style
2319   \param theStyle interaction style
2320 */
2321 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
2322 {
2323   onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
2324 }
2325
2326 /*!
2327   \brief Get current zooming style
2328   \return zooming style
2329 */
2330 int OCCViewer_ViewWindow::zoomingStyle() const
2331 {
2332   return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
2333 }
2334
2335 /*!
2336   \brief Set current zooming style
2337   \param theStyle zooming style
2338 */
2339 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
2340 {
2341   onSwitchZoomingStyle( theStyle == 1 );
2342 }
2343
2344 /*!
2345   \brief Dump view window contents to the pixmap.
2346   \return pixmap containing all scene rendered in the window
2347 */
2348 //#define USE_OLD_IMPLEMENTATION
2349 QImage OCCViewer_ViewWindow::dumpView()
2350 {
2351   Handle(V3d_View) view = myViewPort->getView();
2352   if ( view.IsNull() )
2353     return QImage();
2354
2355   int aWidth = myViewPort->width();
2356   int aHeight = myViewPort->height();
2357
2358 #ifdef USE_OLD_IMPLEMENTATION
2359   // rnv: Old approach to dump the OCCViewer content via Frame Buffer Object
2360
2361   view->Redraw();
2362
2363 #ifndef DISABLE_GLVIEWER
2364   OpenGLUtils_FrameBuffer aFrameBuffer;
2365   if ( aFrameBuffer.init( aWidth, aHeight ) )
2366   {
2367     glPushAttrib( GL_VIEWPORT_BIT );
2368     glViewport( 0, 0, aWidth, aHeight );
2369     aFrameBuffer.bind();
2370
2371     // draw scene
2372     view->Redraw();
2373
2374     aFrameBuffer.unbind();
2375     glPopAttrib();
2376
2377     QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
2378
2379     aFrameBuffer.bind();
2380     glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
2381     aFrameBuffer.unbind();
2382
2383     anImage = anImage.rgbSwapped();
2384     anImage = anImage.mirrored();
2385     return anImage;
2386   }
2387
2388   // if frame buffers are unsupported, use old approach
2389
2390   unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
2391   QPoint p = myViewPort->mapFromParent( myViewPort->geometry().topLeft() );
2392   glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
2393                 data);
2394   QImage anImage( data, aWidth, aHeight, QImage::Format_ARGB32 );
2395   anImage = anImage.mirrored();
2396   anImage = anImage.rgbSwapped();
2397   return anImage;
2398
2399 #else // DISABLE_GLVIEWER
2400
2401   return QImage();
2402
2403 #endif // DISABLE_GLVIEWER
2404
2405 #else // USE_OLD_IMPLEMENTATION
2406   // rnv: New approach is to use OCCT built-in procedure
2407
2408   Image_PixMap aPix;
2409   view->ToPixMap(aPix, aWidth, aHeight, Graphic3d_BT_RGB);
2410   
2411   QImage anImage( aWidth, aHeight, QImage::Format_ARGB32 );
2412   for ( int i = 0; i < aWidth; i++ ) {
2413     for ( int j = 0; j < aHeight; j++ ) {
2414       Quantity_Color pixel = aPix.PixelColor( i, j ).GetRGB();
2415       QColor color = QColor::fromRgbF( pixel.Red(), pixel.Green(), pixel.Blue() );
2416       anImage.setPixelColor( i, j, color );
2417     }
2418   }
2419     
2420   if ( aPix.IsTopDown() )
2421     anImage = anImage.mirrored();
2422   return anImage;
2423
2424 #endif // USE_OLD_IMPLEMENTATION
2425 }
2426
2427 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& /*img*/,
2428                                              const QString& fileName,
2429                                              const QString& /*format*/ )
2430 {
2431   bool res = false;
2432   QApplication::setOverrideCursor( Qt::WaitCursor );
2433
2434   res = myViewPort->getView()->Dump( fileName.toStdString().c_str() );
2435
2436   QApplication::restoreOverrideCursor();
2437   return res;
2438 }
2439
2440
2441 QString OCCViewer_ViewWindow::filter() const
2442 {
2443   // OCCT version > 7.3.0 is not support export to PS and EPS
2444   QString formats = tr( "OCC_IMAGE_FILES" );
2445   return formats.remove(" *.eps *.ps");
2446 }
2447
2448
2449 /*!
2450   \brief Set parameters of the cutting plane
2451   \param on if \c true, cutting plane is enabled
2452   \param x X position of plane point
2453   \param y Y position of plane point
2454   \param z Z position of plane point
2455   \param dx X coordinate of plane normal
2456   \param dy Y coordinate of plane normal
2457   \param dz Z coordinate of plane normal
2458 */
2459 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x,  const double y,  const double z,
2460                                             const double dx, const double dy, const double dz )
2461 {
2462   Handle(V3d_View) view = myViewPort->getView();
2463   if ( view.IsNull() )
2464     return;
2465
2466   if ( on ) {
2467     Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2468
2469     // try to use already existing plane or create a new one
2470     Handle(V3d_Plane) clipPlane;
2471
2472     // calculate new a,b,c,d values for the plane
2473     gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2474     double a, b, c, d;
2475     pln.Coefficients(a, b, c, d);
2476     Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2477     Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2478     if(aPlanes->Size() > 0 ) {
2479       Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2480       aClipPlane->SetEquation(pln);
2481       aClipPlane->SetOn(Standard_True);
2482     } else {
2483       view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2484     }
2485   }
2486   else {
2487     Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2488     Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2489     for( ;anIter.More();anIter.Next() ){
2490       Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2491       aClipPlane->SetOn(Standard_False);
2492     }
2493   }
2494
2495   view->Update();
2496   view->Redraw();
2497 }
2498
2499 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2500 {
2501   gp_Dir aDir = pln.Axis().Direction();
2502   gp_Pnt aPnt = pln.Location();
2503   setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2504 }
2505
2506
2507 /*!
2508   \brief Check if any cutting plane is enabled
2509   \return \c true if at least one cutting plane is enabled
2510 */
2511 bool OCCViewer_ViewWindow::isCuttingPlane()
2512 {
2513   Handle(V3d_View) view = myViewPort->getView();
2514   bool res = false;
2515   Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2516   Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2517   for( ;anIter.More();anIter.Next() ) {
2518     Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2519     if(aClipPlane->IsOn()) {
2520       res = true;
2521       break;
2522     }
2523   }
2524   return res;
2525 }
2526
2527 /*!
2528   \brief Get the visual parameters of the view window.
2529   \return visual parameters of view window
2530 */
2531 viewAspect OCCViewer_ViewWindow::getViewParams() const
2532 {
2533   double projX, projY, projZ, twist;
2534   double atX, atY, atZ, eyeX, eyeY, eyeZ;
2535   double aScaleX, aScaleY, aScaleZ;
2536
2537   Handle(V3d_View) aView3d = myViewPort->getView();
2538
2539   aView3d->Proj( projX, projY, projZ );
2540   aView3d->At( atX, atY, atZ );
2541   aView3d->Eye( eyeX, eyeY, eyeZ );
2542   twist = aView3d->Twist();
2543
2544   aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2545
2546   bool isShown = myModel->isTrihedronVisible();
2547   double size = myModel->trihedronSize();
2548
2549   bool isVCShown = myModel->isViewCubeVisible();
2550
2551   QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2552
2553   viewAspect params;
2554   params.scale    = aView3d->Scale();
2555   params.projX    = projX;
2556   params.projY    = projY;
2557   params.projZ    = projZ;
2558   params.twist    = twist;
2559   params.atX      = atX;
2560   params.atY      = atY;
2561   params.atZ      = atZ;
2562   params.eyeX     = eyeX;
2563   params.eyeY     = eyeY;
2564   params.eyeZ     = eyeZ;
2565   params.scaleX   = aScaleX;
2566   params.scaleY   = aScaleY;
2567   params.scaleZ   = aScaleZ;
2568   params.name     = aName;
2569
2570   // trihedron
2571   params.isVisible= isShown;
2572   params.size     = size;
2573
2574   // view cube
2575   params.vcIsVisible= isVCShown;
2576
2577   // graduated trihedron
2578   bool anIsVisible = false;
2579   OCCViewer_AxisWidget::AxisData anAxisData[3];
2580   myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2581
2582   params.gtIsVisible = anIsVisible;
2583   params.gtDrawNameX = anAxisData[0].DrawName;
2584   params.gtDrawNameY = anAxisData[1].DrawName;
2585   params.gtDrawNameZ = anAxisData[2].DrawName;
2586   params.gtNameX = anAxisData[0].Name;
2587   params.gtNameY = anAxisData[1].Name;
2588   params.gtNameZ = anAxisData[2].Name;
2589   params.gtNameColorRX = anAxisData[0].NameColor.red();
2590   params.gtNameColorGX = anAxisData[0].NameColor.green();
2591   params.gtNameColorBX = anAxisData[0].NameColor.blue();
2592   params.gtNameColorRY = anAxisData[1].NameColor.red();
2593   params.gtNameColorGY = anAxisData[1].NameColor.green();
2594   params.gtNameColorBY = anAxisData[1].NameColor.blue();
2595   params.gtNameColorRZ = anAxisData[2].NameColor.red();
2596   params.gtNameColorGZ = anAxisData[2].NameColor.green();
2597   params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2598   params.gtDrawValuesX = anAxisData[0].DrawValues;
2599   params.gtDrawValuesY = anAxisData[1].DrawValues;
2600   params.gtDrawValuesZ = anAxisData[2].DrawValues;
2601   params.gtNbValuesX = anAxisData[0].NbValues;
2602   params.gtNbValuesY = anAxisData[1].NbValues;
2603   params.gtNbValuesZ = anAxisData[2].NbValues;
2604   params.gtOffsetX = anAxisData[0].Offset;
2605   params.gtOffsetY = anAxisData[1].Offset;
2606   params.gtOffsetZ = anAxisData[2].Offset;
2607   params.gtColorRX = anAxisData[0].Color.red();
2608   params.gtColorGX = anAxisData[0].Color.green();
2609   params.gtColorBX = anAxisData[0].Color.blue();
2610   params.gtColorRY = anAxisData[1].Color.red();
2611   params.gtColorGY = anAxisData[1].Color.green();
2612   params.gtColorBY = anAxisData[1].Color.blue();
2613   params.gtColorRZ = anAxisData[2].Color.red();
2614   params.gtColorGZ = anAxisData[2].Color.green();
2615   params.gtColorBZ = anAxisData[2].Color.blue();
2616   params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2617   params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2618   params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2619   params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2620   params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2621   params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2622
2623   return params;
2624 }
2625
2626 /*!
2627   \brief Get visual parameters of this view window.
2628   \return visual parameters of view window
2629 */
2630 QString OCCViewer_ViewWindow::getVisualParameters()
2631 {
2632   viewAspect params = getViewParams();
2633
2634   QStringList data;
2635
2636   data << QString( "scale=%1" )    .arg( params.scale,   0, 'e', 12 );
2637   data << QString( "projX=%1" )    .arg( params.projX,   0, 'e', 12 );
2638   data << QString( "projY=%1" )    .arg( params.projY,   0, 'e', 12 );
2639   data << QString( "projZ=%1" )    .arg( params.projZ,   0, 'e', 12 );
2640   data << QString( "twist=%1" )    .arg( params.twist,   0, 'e', 12 );
2641   data << QString( "atX=%1" )      .arg( params.atX,     0, 'e', 12 );
2642   data << QString( "atY=%1" )      .arg( params.atY,     0, 'e', 12 );
2643   data << QString( "atZ=%1" )      .arg( params.atZ,     0, 'e', 12 );
2644   data << QString( "eyeX=%1" )     .arg( params.eyeX,    0, 'e', 12 );
2645   data << QString( "eyeY=%1" )     .arg( params.eyeY,    0, 'e', 12 );
2646   data << QString( "eyeZ=%1" )     .arg( params.eyeZ,    0, 'e', 12 );
2647   data << QString( "scaleX=%1" )   .arg( params.scaleX,  0, 'e', 12 );
2648   data << QString( "scaleY=%1" )   .arg( params.scaleY,  0, 'e', 12 );
2649   data << QString( "scaleZ=%1" )   .arg( params.scaleZ,  0, 'e', 12 );
2650   data << QString( "isVisible=%1" ).arg( params.isVisible );
2651   data << QString( "size=%1" )     .arg( params.size,    0, 'f',  2 );
2652
2653   ClipPlanesList aPlanes =  myModel->getClipPlanes();
2654   for ( int i=0; i < (int)aPlanes.size(); i++ )
2655   {
2656     OCCViewer_ClipPlane& aPlane = aPlanes[i];
2657     QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2658     ClippingPlane +=  QString( "Mode~%1;").arg( (int)aPlane.Mode );
2659     ClippingPlane +=  QString( "IsActive~%1;").arg( aPlane.IsOn );
2660     switch ( aPlane.Mode )
2661     {
2662       case OCCViewer_ClipPlane::Absolute :
2663       {
2664         ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2665
2666         if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2667         {
2668           ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2669           ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2670           ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2671         }
2672         else
2673         {
2674           ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2675         }
2676       }
2677       break;
2678
2679       case OCCViewer_ClipPlane::Relative :
2680       {
2681         ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2682         ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2683         ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2684       }
2685       break;
2686     }
2687
2688     ClippingPlane +=  QString( "X~%1;" ).arg( aPlane.X );
2689     ClippingPlane +=  QString( "Y~%1;" ).arg( aPlane.Y );
2690     ClippingPlane +=  QString( "Z~%1;" ).arg( aPlane.Z );
2691     data << ClippingPlane;
2692   }
2693
2694   // graduated trihedron
2695   data << QString( "gtIsVisible=%1" )      .arg( params.gtIsVisible );
2696   data << QString( "gtDrawNameX=%1" )      .arg( params.gtDrawNameX );
2697   data << QString( "gtDrawNameY=%1" )      .arg( params.gtDrawNameY );
2698   data << QString( "gtDrawNameZ=%1" )      .arg( params.gtDrawNameZ );
2699   data << QString( "gtNameX=%1" )          .arg( params.gtNameX );
2700   data << QString( "gtNameY=%1" )          .arg( params.gtNameY );
2701   data << QString( "gtNameZ=%1" )          .arg( params.gtNameZ );
2702   data << QString( "gtNameColorRX=%1" )    .arg( params.gtNameColorRX );
2703   data << QString( "gtNameColorGX=%1" )    .arg( params.gtNameColorGX );
2704   data << QString( "gtNameColorBX=%1" )    .arg( params.gtNameColorBX );
2705   data << QString( "gtNameColorRY=%1" )    .arg( params.gtNameColorRY );
2706   data << QString( "gtNameColorGY=%1" )    .arg( params.gtNameColorGY );
2707   data << QString( "gtNameColorBY=%1" )    .arg( params.gtNameColorBY );
2708   data << QString( "gtNameColorRZ=%1" )    .arg( params.gtNameColorRZ );
2709   data << QString( "gtNameColorGZ=%1" )    .arg( params.gtNameColorGZ );
2710   data << QString( "gtNameColorBZ=%1" )    .arg( params.gtNameColorBZ );
2711   data << QString( "gtDrawValuesX=%1" )    .arg( params.gtDrawValuesX );
2712   data << QString( "gtDrawValuesY=%1" )    .arg( params.gtDrawValuesY );
2713   data << QString( "gtDrawValuesZ=%1" )    .arg( params.gtDrawValuesZ );
2714   data << QString( "gtNbValuesX=%1" )      .arg( params.gtNbValuesX );
2715   data << QString( "gtNbValuesY=%1" )      .arg( params.gtNbValuesY );
2716   data << QString( "gtNbValuesZ=%1" )      .arg( params.gtNbValuesZ );
2717   data << QString( "gtOffsetX=%1" )        .arg( params.gtOffsetX );
2718   data << QString( "gtOffsetY=%1" )        .arg( params.gtOffsetY );
2719   data << QString( "gtOffsetZ=%1" )        .arg( params.gtOffsetZ );
2720   data << QString( "gtColorRX=%1" )        .arg( params.gtColorRX );
2721   data << QString( "gtColorGX=%1" )        .arg( params.gtColorGX );
2722   data << QString( "gtColorBX=%1" )        .arg( params.gtColorBX );
2723   data << QString( "gtColorRY=%1" )        .arg( params.gtColorRY );
2724   data << QString( "gtColorGY=%1" )        .arg( params.gtColorGY );
2725   data << QString( "gtColorBY=%1" )        .arg( params.gtColorBY );
2726   data << QString( "gtColorRZ=%1" )        .arg( params.gtColorRZ );
2727   data << QString( "gtColorGZ=%1" )        .arg( params.gtColorGZ );
2728   data << QString( "gtColorBZ=%1" )        .arg( params.gtColorBZ );
2729   data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2730   data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2731   data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2732   data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2733   data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2734   data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2735
2736   // ray tracing parameters
2737   Graphic3d_RenderingParams rendParams = this->getViewPort()->getView()->RenderingParams();
2738   if ( rendParams.Method == Graphic3d_RM_RAYTRACING ) {
2739     QString RayTracing = "rayTracing=";
2740     RayTracing += QString( "rtDepth~%1;" ).arg( rendParams.RaytracingDepth );
2741     RayTracing += QString( "rtReflection~%1;" ).arg( rendParams.IsReflectionEnabled );
2742     RayTracing += QString( "rtAntialiasing~%1;" ).arg( rendParams.IsAntialiasingEnabled );
2743     RayTracing += QString( "rtShadow~%1;" ).arg( rendParams.IsShadowEnabled );
2744     RayTracing += QString( "rtTransShadow~%1;" ).arg( rendParams.IsTransparentShadowEnabled );
2745     data << RayTracing;
2746   }
2747
2748   // environment texture parameters
2749   Handle(Graphic3d_TextureEnv) aTexture = this->getViewPort()->getView()->TextureEnv();
2750   if ( !aTexture.IsNull() ) {
2751     QString EnvTexture = "envTexture=";
2752     if ( aTexture->Name() == Graphic3d_NOT_ENV_UNKNOWN ) {
2753       TCollection_AsciiString aFileName;
2754       aTexture->Path().SystemName( aFileName );
2755       EnvTexture += QString( "etFile~%1;" ).arg( aFileName.ToCString() );
2756     }
2757     else
2758       EnvTexture += QString( "etNumber~%1;" ).arg( aTexture->Name() );
2759     data << EnvTexture;
2760   }
2761
2762   // light source parameters
2763   myModel->getViewer3d()->InitDefinedLights();
2764   while ( myModel->getViewer3d()->MoreDefinedLights() )
2765   {
2766     Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2767     if ( aLight->Type() != V3d_AMBIENT ) {
2768       QString LightSource = QString( "lightSource=" );
2769       LightSource += QString( "lightType~%1;" ).arg( aLight->Type() );
2770       double aX, aY, aZ;
2771       if ( aLight->Type() == V3d_DIRECTIONAL )
2772         Handle(V3d_DirectionalLight)::DownCast( aLight )->Direction( aX, aY, aZ );
2773       else if ( aLight->Type() == V3d_POSITIONAL )
2774         Handle(V3d_PositionalLight)::DownCast( aLight )->Position( aX, aY, aZ );
2775       else
2776         continue; // not supported type of light source
2777       LightSource += QString( "lightX~%1;" ).arg( aX );
2778       LightSource += QString( "lightY~%1;" ).arg( aY );
2779       LightSource += QString( "lightZ~%1;" ).arg( aZ );
2780       LightSource += QString( "lightColorR~%1;" ).arg( aLight->Color().Red() );
2781       LightSource += QString( "lightColorG~%1;" ).arg( aLight->Color().Green() );
2782       LightSource += QString( "lightColorB~%1;" ).arg( aLight->Color().Blue() );
2783       LightSource += QString( "lightHeadlight~%1;" ).arg( aLight->Headlight() );
2784       data << LightSource;
2785     }
2786     myModel->getViewer3d()->NextDefinedLights();
2787   }
2788
2789   QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2790   data << QString( "background=%1" ).arg( bg );
2791
2792   return data.join("*");
2793 }
2794
2795 /*!
2796   \brief Restore visual parameters of the view window.
2797   \param parameters visual parameters of view window
2798 */
2799 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2800 {
2801   viewAspect params;
2802   ClipPlanesList aClipPlanes;
2803   QStringList data = parameters.split( '*' );
2804   Qtx::BackgroundData bgData;
2805   if ( parameters.contains( '=' )  ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2806   {
2807     foreach( QString param, data ) {
2808       QString paramName  = param.section( '=', 0, 0 ).trimmed();
2809       QString paramValue = param.section( '=', 1, 1 ).trimmed();
2810       if      ( paramName == "scale" )             params.scale             = paramValue.toDouble();
2811       else if ( paramName == "centerX" )           params.centerX           = paramValue.toDouble();
2812       else if ( paramName == "centerY" )           params.centerY           = paramValue.toDouble();
2813       else if ( paramName == "projX" )             params.projX             = paramValue.toDouble();
2814       else if ( paramName == "projY" )             params.projY             = paramValue.toDouble();
2815       else if ( paramName == "projZ" )             params.projZ             = paramValue.toDouble();
2816       else if ( paramName == "twist" )             params.twist             = paramValue.toDouble();
2817       else if ( paramName == "atX" )               params.atX               = paramValue.toDouble();
2818       else if ( paramName == "atY" )               params.atY               = paramValue.toDouble();
2819       else if ( paramName == "atZ" )               params.atZ               = paramValue.toDouble();
2820       else if ( paramName == "eyeX" )              params.eyeX              = paramValue.toDouble();
2821       else if ( paramName == "eyeY" )              params.eyeY              = paramValue.toDouble();
2822       else if ( paramName == "eyeZ" )              params.eyeZ              = paramValue.toDouble();
2823       else if ( paramName == "scaleX" )            params.scaleX            = paramValue.toDouble();
2824       else if ( paramName == "scaleY" )            params.scaleY            = paramValue.toDouble();
2825       else if ( paramName == "scaleZ" )            params.scaleZ            = paramValue.toDouble();
2826       else if ( paramName == "isVisible" )         params.isVisible         = paramValue.toInt();
2827       else if ( paramName == "size" )              params.size              = paramValue.toDouble();
2828       else if ( paramName.contains( "ClippingPlane" ) )
2829       {
2830         QStringList ClipPlaneData = paramValue.split( ';' );
2831         OCCViewer_ClipPlane aPlane;
2832         foreach( QString ClipPlaneParam, ClipPlaneData )
2833         {
2834           QString ClipPlane_paramName  = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2835           QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2836           if ( ClipPlane_paramName == "Mode" )
2837           {
2838             aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2839           }
2840           else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2841           else if ( ClipPlane_paramName == "X" )        aPlane.X    = ClipPlane_paramValue.toDouble();
2842           else if ( ClipPlane_paramName == "Y" )        aPlane.Y    = ClipPlane_paramValue.toDouble();
2843           else if ( ClipPlane_paramName == "Z" )        aPlane.Z    = ClipPlane_paramValue.toDouble();
2844           else
2845           {
2846             switch ( aPlane.Mode )
2847             {
2848               case OCCViewer_ClipPlane::Absolute :
2849                 if      ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2850                 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2851                 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2852                 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2853                 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2854                 break;
2855
2856               case OCCViewer_ClipPlane::Relative :
2857                 if      ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2858                 else if ( ClipPlane_paramName == "Rotation1" )           aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2859                 else if ( ClipPlane_paramName == "Rotation2" )           aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2860                 break;
2861             }
2862           }
2863         }
2864         aClipPlanes.push_back(aPlane);
2865       }
2866       // graduated trihedron
2867       else if ( paramName == "gtIsVisible" )       params.gtIsVisible       = paramValue.toInt();
2868       else if ( paramName == "gtDrawNameX" )       params.gtDrawNameX       = paramValue.toInt();
2869       else if ( paramName == "gtDrawNameY" )       params.gtDrawNameY       = paramValue.toInt();
2870       else if ( paramName == "gtDrawNameZ" )       params.gtDrawNameZ       = paramValue.toInt();
2871       else if ( paramName == "gtNameX" )           params.gtNameX           = paramValue;
2872       else if ( paramName == "gtNameY" )           params.gtNameY           = paramValue;
2873       else if ( paramName == "gtNameZ" )           params.gtNameZ           = paramValue;
2874       else if ( paramName == "gtNameColorRX" )     params.gtNameColorRX     = paramValue.toInt();
2875       else if ( paramName == "gtNameColorGX" )     params.gtNameColorGX     = paramValue.toInt();
2876       else if ( paramName == "gtNameColorBX" )     params.gtNameColorBX     = paramValue.toInt();
2877       else if ( paramName == "gtNameColorRY" )     params.gtNameColorRY     = paramValue.toInt();
2878       else if ( paramName == "gtNameColorGY" )     params.gtNameColorGY     = paramValue.toInt();
2879       else if ( paramName == "gtNameColorBY" )     params.gtNameColorBY     = paramValue.toInt();
2880       else if ( paramName == "gtNameColorRZ" )     params.gtNameColorRZ     = paramValue.toInt();
2881       else if ( paramName == "gtNameColorGZ" )     params.gtNameColorGZ     = paramValue.toInt();
2882       else if ( paramName == "gtNameColorBZ" )     params.gtNameColorBZ     = paramValue.toInt();
2883       else if ( paramName == "gtDrawValuesX" )     params.gtDrawValuesX     = paramValue.toInt();
2884       else if ( paramName == "gtDrawValuesY" )     params.gtDrawValuesY     = paramValue.toInt();
2885       else if ( paramName == "gtDrawValuesZ" )     params.gtDrawValuesZ     = paramValue.toInt();
2886       else if ( paramName == "gtNbValuesX" )       params.gtNbValuesX       = paramValue.toInt();
2887       else if ( paramName == "gtNbValuesY" )       params.gtNbValuesY       = paramValue.toInt();
2888       else if ( paramName == "gtNbValuesZ" )       params.gtNbValuesZ       = paramValue.toInt();
2889       else if ( paramName == "gtOffsetX" )         params.gtOffsetX         = paramValue.toInt();
2890       else if ( paramName == "gtOffsetY" )         params.gtOffsetY         = paramValue.toInt();
2891       else if ( paramName == "gtOffsetZ" )         params.gtOffsetZ         = paramValue.toInt();
2892       else if ( paramName == "gtColorRX" )         params.gtColorRX         = paramValue.toInt();
2893       else if ( paramName == "gtColorGX" )         params.gtColorGX         = paramValue.toInt();
2894       else if ( paramName == "gtColorBX" )         params.gtColorBX         = paramValue.toInt();
2895       else if ( paramName == "gtColorRY" )         params.gtColorRY         = paramValue.toInt();
2896       else if ( paramName == "gtColorGY" )         params.gtColorGY         = paramValue.toInt();
2897       else if ( paramName == "gtColorBY" )         params.gtColorBY         = paramValue.toInt();
2898       else if ( paramName == "gtColorRZ" )         params.gtColorRZ         = paramValue.toInt();
2899       else if ( paramName == "gtColorGZ" )         params.gtColorGZ         = paramValue.toInt();
2900       else if ( paramName == "gtColorBZ" )         params.gtColorBZ         = paramValue.toInt();
2901       else if ( paramName == "gtDrawTickmarksX" )  params.gtDrawTickmarksX  = paramValue.toInt();
2902       else if ( paramName == "gtDrawTickmarksY" )  params.gtDrawTickmarksY  = paramValue.toInt();
2903       else if ( paramName == "gtDrawTickmarksZ" )  params.gtDrawTickmarksZ  = paramValue.toInt();
2904       else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2905       else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2906       else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2907       else if ( paramName == "rayTracing" )
2908       {
2909         Graphic3d_RenderingParams& rendParams = this->getViewPort()->getView()->ChangeRenderingParams();
2910         rendParams.Method = Graphic3d_RM_RAYTRACING;
2911         QStringList rtData = paramValue.split( ';' );
2912         foreach( QString rtParam, rtData )
2913         {
2914           QString rt_paramName  = rtParam.section( '~', 0, 0 ).trimmed();
2915           QString rt_paramValue = rtParam.section( '~', 1, 1 ).trimmed();
2916           if ( rt_paramName == "rtDepth" ) rendParams.RaytracingDepth = rt_paramValue.toInt();
2917           else if ( rt_paramName == "rtReflection" ) rendParams.IsReflectionEnabled = rt_paramValue.toInt();
2918           else if ( rt_paramName == "rtAntialiasing" ) rendParams.IsAntialiasingEnabled = rt_paramValue.toInt();
2919           else if ( rt_paramName == "rtShadow" ) rendParams.IsShadowEnabled = rt_paramValue.toInt();
2920           else if ( rt_paramName == "rtTransShadow" ) rendParams.IsTransparentShadowEnabled = rt_paramValue.toInt();
2921         }
2922       }
2923       else if ( paramName == "envTexture" )
2924       {
2925         Handle(Graphic3d_TextureEnv) aTexture;
2926         QStringList etData = paramValue.split( ';' );
2927         foreach( QString etParam, etData )
2928         {
2929           QString et_paramName  = etParam.section( '~', 0, 0 ).trimmed();
2930           QString et_paramValue = etParam.section( '~', 1, 1 ).trimmed();
2931           if ( et_paramName == "etNumber" )
2932             aTexture = new Graphic3d_TextureEnv( Graphic3d_NameOfTextureEnv( et_paramValue.toInt() ) );
2933           else if ( et_paramName == "etFile" )
2934             aTexture = new Graphic3d_TextureEnv( TCollection_AsciiString( et_paramValue.toStdString().c_str() ) );
2935           Handle(V3d_View) aView = this->getViewPort()->getView();
2936           aView->SetTextureEnv( aTexture );
2937         }
2938       }
2939       else if ( paramName == "lightSource" )
2940       {
2941         myModel->getViewer3d()->InitDefinedLights();
2942         while ( myModel->getViewer3d()->MoreDefinedLights() )
2943         {
2944           Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2945           if( aLight->Type() != V3d_AMBIENT ) {
2946             myModel->getViewer3d()->DelLight( aLight );
2947             myModel->getViewer3d()->InitDefinedLights();
2948           } else {
2949             myModel->getViewer3d()->NextDefinedLights();
2950           }
2951         }
2952         double aX = 0., aY = 0., aZ = 0.;
2953         double cR = 0., cG = 0., cB = 0.;
2954         V3d_TypeOfLight aType = (V3d_TypeOfLight)-1; // not specified
2955         bool isHeadlight = false;
2956         QStringList lsData = paramValue.split( ';' );
2957         foreach( QString lsParam, lsData )
2958         {
2959           QString ls_paramName  = lsParam.section( '~', 0, 0 ).trimmed();
2960           QString ls_paramValue = lsParam.section( '~', 1, 1 ).trimmed();
2961           if ( ls_paramName == "lightType" ) aType = V3d_TypeOfLight( ls_paramValue.toInt() );
2962           else if ( ls_paramName == "lightX" ) aX = ls_paramValue.toDouble();
2963           else if ( ls_paramName == "lightY" ) aY = ls_paramValue.toDouble();
2964           else if ( ls_paramName == "lightZ" ) aZ = ls_paramValue.toDouble();
2965           else if ( ls_paramName == "lightColorR" ) cR = ls_paramValue.toDouble();
2966           else if ( ls_paramName == "lightColorG" ) cG = ls_paramValue.toDouble();
2967           else if ( ls_paramName == "lightColorB" ) cB = ls_paramValue.toDouble();
2968           else if ( ls_paramName == "lightHeadlight" ) isHeadlight = ls_paramValue.toInt();
2969         }
2970         Quantity_Color aColor = Quantity_Color( cR, cG, cB, Quantity_TOC_RGB );
2971         if( aType == V3d_DIRECTIONAL ) {
2972           Handle(V3d_DirectionalLight) aLight = new V3d_DirectionalLight();
2973           myModel->getViewer3d()->AddLight( aLight );
2974           aLight->SetDirection( aX, aY, aZ );
2975           aLight->SetColor( aColor );
2976           aLight->SetHeadlight( isHeadlight );
2977           myModel->getViewer3d()->SetLightOn( aLight );
2978         }
2979         else if( aType == V3d_POSITIONAL ) {
2980           Handle(V3d_PositionalLight) aLight = new V3d_PositionalLight( gp_Pnt(aX, aY, aZ), aColor.Name() );
2981           myModel->getViewer3d()->AddLight( aLight );
2982           aLight->SetHeadlight( isHeadlight );
2983           myModel->getViewer3d()->SetLightOn( aLight );
2984         }
2985       }
2986       else if ( paramName == "background" )        {
2987   QString bg = paramValue.replace( "$", "=" );
2988   bgData = Qtx::stringToBackground( bg );
2989       }
2990     }
2991   }
2992   else // old format - "1.000e+00*0.000e+00..."
2993   {
2994     int idx = 0;
2995     params.scale     = data.count() > idx ? data[idx++].toDouble() : 1.0;
2996     params.centerX   = data.count() > idx ? data[idx++].toDouble() : 0.0;
2997     params.centerY   = data.count() > idx ? data[idx++].toDouble() : 0.0;
2998     params.projX     = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2999     params.projY     = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
3000     params.projZ     = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
3001     params.twist     = data.count() > idx ? data[idx++].toDouble() : 0.0;
3002     params.atX       = data.count() > idx ? data[idx++].toDouble() : 0.0;
3003     params.atY       = data.count() > idx ? data[idx++].toDouble() : 0.0;
3004     params.atZ       = data.count() > idx ? data[idx++].toDouble() : 0.0;
3005     params.eyeX      = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
3006     params.eyeY      = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
3007     params.eyeZ      = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
3008     params.scaleX    = data.count() > idx ? data[idx++].toDouble() : 1.0;
3009     params.scaleY    = data.count() > idx ? data[idx++].toDouble() : 1.0;
3010     params.scaleZ    = data.count() > idx ? data[idx++].toDouble() : 1.0;
3011     params.isVisible = data.count() > idx ? data[idx++].toInt()    : 1;
3012     params.size      = data.count() > idx ? data[idx++].toDouble() : 100.0;
3013   }
3014   performRestoring( params );
3015   setBackground( bgData );
3016   myModel->setClipPlanes(aClipPlanes);
3017 }
3018
3019 /*!
3020   \brief Handle show event.
3021
3022   Emits Show() signal.
3023
3024   \param theEvent show event
3025 */
3026 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
3027 {
3028   emit Show( theEvent );
3029 }
3030
3031 /*!
3032   \brief Handle hide event.
3033
3034   Emits Hide() signal.
3035
3036   \param theEvent hide event
3037 */
3038 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
3039 {
3040   emit Hide( theEvent );
3041 }
3042
3043
3044 /*!
3045     Save old cursor. [ protected ]
3046 */
3047 void OCCViewer_ViewWindow::saveCursor()
3048 {
3049   QCursor* aCursor = NULL;
3050   if ( myViewPort )
3051     aCursor = myViewPort->getDefaultCursor();
3052   myCursor = ( aCursor ? *aCursor : cursor() );
3053 }
3054
3055
3056 /*!
3057     Creates default sketcher. [ virtual protected ]
3058 */
3059 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
3060 {
3061   if ( type == Rect )
3062     return new OCCViewer_RectSketcher( this, type );
3063   if ( type == Polygon )
3064     return new OCCViewer_PolygonSketcher( this, type );
3065   return 0;
3066 }
3067
3068 void OCCViewer_ViewWindow::initSketchers()
3069 {
3070   if ( mySketchers.isEmpty() )
3071   {
3072     mySketchers.append( createSketcher( Rect ) );
3073     mySketchers.append( createSketcher( Polygon ) );
3074   }
3075 }
3076
3077 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ ) const
3078 {
3079   OCCViewer_ViewSketcher* sketcher = 0;
3080   QList<OCCViewer_ViewSketcher*>::ConstIterator it;
3081   for ( it = mySketchers.cbegin(); it != mySketchers.cend() && !sketcher; ++it )
3082   {
3083     OCCViewer_ViewSketcher* sk = (*it);
3084     if ( sk->type() == typ )
3085       sketcher = sk;
3086   }
3087   return sketcher;
3088 }
3089
3090 /*!
3091     Handles requests for sketching in the active view. [ virtual public ]
3092 */
3093 void OCCViewer_ViewWindow::activateSketching( int type )
3094 {
3095   OCCViewer_ViewPort3d* vp = getViewPort();
3096   if ( !vp )
3097     return;
3098
3099   if ( !vp->isSketchingEnabled() )
3100     return;
3101
3102   /* Finish current sketching */
3103   if ( type == NoSketching )
3104   {
3105     if ( mypSketcher )
3106     {
3107       onSketchingFinished();
3108       mypSketcher->deactivate();
3109       mypSketcher = 0;
3110     }
3111   }
3112   /* Activate new sketching */
3113   else
3114   {
3115     activateSketching( NoSketching );  /* concurrency not suported */
3116     mypSketcher = getSketcher( type );
3117     if ( mypSketcher )
3118     {
3119       mypSketcher->activate();
3120       onSketchingStarted();
3121     }
3122   }
3123 }
3124
3125 /*!
3126     Unhilights detected entities. [ virtual protected ]
3127 */
3128 void OCCViewer_ViewWindow::onSketchingStarted()
3129 {
3130 }
3131
3132 /*!
3133     Selection by rectangle or polygon. [ virtual protected ]
3134 */
3135 void OCCViewer_ViewWindow::onSketchingFinished()
3136 {
3137   MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()");
3138   if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
3139   {
3140     Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
3141     bool append = mypSketcher->isHasShift();
3142     switch( mypSketcher->type() )
3143     {
3144     case Rect:
3145       {
3146         QRect* aRect = (QRect*)mypSketcher->data();
3147         if ( aRect )
3148         {
3149           int aLeft = aRect->left();
3150           int aRight = aRect->right();
3151           int aTop = aRect->top();
3152           int aBottom = aRect->bottom();
3153 //           myRect = aRect;
3154
3155           if( append )
3156             ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False);
3157           else
3158             ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False);
3159         }
3160       }
3161       break;
3162     case Polygon:
3163       {
3164         QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
3165         if( aPolygon && (aPolygon->size() > 2))
3166         {
3167           int size = aPolygon->size();
3168           TColgp_Array1OfPnt2d anArray(1, size);
3169
3170           QPolygon::Iterator it = aPolygon->begin();
3171           QPolygon::Iterator itEnd = aPolygon->end();
3172           for (int index = 1; it != itEnd; ++it, index++)
3173           {
3174             QPoint aPoint = *it;
3175             anArray.SetValue(index, gp_Pnt2d(aPoint.x(), aPoint.y()));
3176           }
3177
3178           if (append)
3179             ic->ShiftSelect(anArray, getViewPort()->getView(), Standard_False);
3180           else
3181             ic->Select(anArray, getViewPort()->getView(), Standard_False);
3182         }
3183       }
3184       break;
3185     default:
3186       break;
3187     }
3188
3189     OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
3190     aViewMgr->getOCCViewer()->performSelectionChanged();
3191   }
3192 }
3193
3194 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
3195 {
3196   return myViewPort;
3197 }
3198
3199 bool OCCViewer_ViewWindow::transformRequested() const
3200 {
3201   return ( myOperation != NOVIEWOP );
3202 }
3203
3204 bool OCCViewer_ViewWindow::transformInProcess() const
3205 {
3206   return myEventStarted;
3207 }
3208
3209 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
3210 {
3211   myEventStarted = bOn;
3212 }
3213
3214 /*!
3215   Set enabled state of transformation (rotate, zoom, etc)
3216 */
3217 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
3218 {
3219   if ( id != NOVIEWOP ) myStatus.insert( id, on );
3220 }
3221
3222 /*!
3223   \return enabled state of transformation (rotate, zoom, etc)
3224 */
3225 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
3226 {
3227   return myStatus.contains( id ) ? myStatus[ id ] : true;
3228 }
3229
3230 void OCCViewer_ViewWindow::onMaximizedView()
3231 {
3232   setMaximized(!isMaximized());
3233 }
3234
3235 void OCCViewer_ViewWindow::returnTo3dView()
3236 {
3237   setReturnedTo3dView( true );
3238 }
3239
3240 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
3241 {
3242   if ( !toolMgr()->action( ReturnTo3dViewId ) ||
3243     toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
3244   if ( !isVisible3dView )
3245     toolMgr()->show( ReturnTo3dViewId );
3246   else
3247     toolMgr()->hide( ReturnTo3dViewId );
3248   if ( isVisible3dView ) emit returnedTo3d( );
3249 }
3250
3251
3252 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
3253 {
3254   QAction* anAction =  toolMgr()->action( MaximizedId );
3255   QAction* anAction2 =  toolMgr()->action( ReturnTo3dViewId );
3256   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
3257   if ( toMaximize ) {
3258     anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
3259     anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
3260     anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
3261     anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
3262     if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
3263     if (toSendSignal) {
3264       emit maximized( this, true );
3265     }
3266   }
3267   else {
3268     anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
3269     anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
3270     anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
3271     anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
3272     if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
3273     if (toSendSignal) {
3274       emit maximized( this, false );
3275     }
3276   }
3277 }
3278
3279 bool OCCViewer_ViewWindow::isMaximized() const
3280 {
3281   return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
3282 }
3283
3284 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
3285 {
3286   IsSketcherStyle = enable;
3287 }
3288
3289 bool OCCViewer_ViewWindow::isSketcherStyle() const
3290 {
3291   return IsSketcherStyle;
3292 }
3293
3294
3295 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
3296 {
3297   my2dMode = theType;
3298 }
3299
3300 int OCCViewer_ViewWindow::projectionType() const
3301 {
3302   int mode = Orthographic;
3303   Handle(V3d_View) aView3d = myViewPort->getView();
3304   if ( !aView3d.IsNull() ) {
3305     Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3306     if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Perspective)
3307       mode = Perspective;
3308     if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Orthographic)
3309       mode = Orthographic;
3310     if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
3311       mode = Stereo;
3312   }
3313   return mode;
3314 }
3315
3316 void OCCViewer_ViewWindow::setStereoType( int type )
3317 {
3318   Handle(V3d_View) aView3d = myViewPort->getView();
3319   if ( !aView3d.IsNull() ) {
3320     Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3321     aParams->StereoMode = (Graphic3d_StereoMode)type;
3322   }
3323 }
3324
3325 int OCCViewer_ViewWindow::stereoType() const
3326 {
3327   int type = QuadBuffer;
3328   Handle(V3d_View) aView3d = myViewPort->getView();
3329   if ( !aView3d.IsNull() ) {
3330     Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3331     type = (OCCViewer_ViewWindow::StereoType)aParams->StereoMode;
3332   }
3333   return type;
3334 }
3335
3336 void OCCViewer_ViewWindow::setAnaglyphFilter( int type )
3337 {
3338   Handle(V3d_View) aView3d = myViewPort->getView();
3339   if ( !aView3d.IsNull() ) {
3340     Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3341     if (type == RedCyan)
3342       aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
3343     if (type == YellowBlue)
3344       aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
3345     if (type == GreenMagenta)
3346       aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
3347   }
3348 }
3349
3350 int OCCViewer_ViewWindow::anaglyphFilter() const
3351 {
3352   int type = RedCyan;
3353   Handle(V3d_View) aView3d = myViewPort->getView();
3354   if ( !aView3d.IsNull() ) {
3355     Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3356     if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized)
3357       type = RedCyan;
3358     if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized)
3359       type = YellowBlue;
3360     if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple)
3361       type = GreenMagenta;
3362   }
3363   return type;
3364 }
3365
3366 void OCCViewer_ViewWindow::setStereographicFocus( int type, double value )
3367 {
3368   Handle(V3d_View) aView3d = myViewPort->getView();
3369   if ( !aView3d.IsNull() ) {
3370     Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3371     aCamera->SetZFocus( (Graphic3d_Camera::FocusType) type, value );
3372   }
3373 }
3374
3375 int OCCViewer_ViewWindow::stereographicFocusType() const
3376 {
3377   int type = Relative;
3378   Handle(V3d_View) aView3d = myViewPort->getView();
3379   if ( !aView3d.IsNull() ) {
3380     Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3381     type = (OCCViewer_ViewWindow::FocusIODType)aCamera->ZFocusType();
3382   }
3383   return type;
3384 }
3385
3386 double OCCViewer_ViewWindow::stereographicFocusValue() const
3387 {
3388   double value = 1.0;
3389   Handle(V3d_View) aView3d = myViewPort->getView();
3390   if ( !aView3d.IsNull() ) {
3391     Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3392     value = aCamera->ZFocus();
3393   }
3394   return value;
3395 }
3396
3397 void OCCViewer_ViewWindow::setInterocularDistance( int type, double value )
3398 {
3399   Handle(V3d_View) aView3d = myViewPort->getView();
3400   if ( !aView3d.IsNull() ) {
3401     Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3402     aCamera->SetIOD( (Graphic3d_Camera::IODType) type, value );
3403   }
3404 }
3405
3406 int OCCViewer_ViewWindow::interocularDistanceType() const
3407 {
3408   int type = Relative;
3409   Handle(V3d_View) aView3d = myViewPort->getView();
3410   if ( !aView3d.IsNull() ) {
3411     Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3412     type = (OCCViewer_ViewWindow::FocusIODType)aCamera->GetIODType();
3413   }
3414   return type;
3415 }
3416
3417 double OCCViewer_ViewWindow::interocularDistanceValue() const
3418 {
3419   double value = 0.05;
3420   Handle(V3d_View) aView3d = myViewPort->getView();
3421   if ( !aView3d.IsNull() ) {
3422     Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3423     value = aCamera->IOD();
3424   }
3425   return value;
3426 }
3427
3428 void OCCViewer_ViewWindow::setReverseStereo( bool reverse )
3429 {
3430   Handle(V3d_View) aView3d = myViewPort->getView();
3431   if ( !aView3d.IsNull() ) {
3432     Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3433     aParams->ToReverseStereo = reverse;
3434   }
3435 }
3436
3437 bool OCCViewer_ViewWindow::isReverseStereo() const
3438 {
3439   int reverse = false;
3440   Handle(V3d_View) aView3d = myViewPort->getView();
3441   if ( !aView3d.IsNull() ) {
3442     Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3443     reverse = aParams->ToReverseStereo;
3444   }
3445   return reverse;
3446 }
3447
3448 void OCCViewer_ViewWindow::setVSync( bool enable )
3449 {
3450   Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3451   if ( !anIntCont.IsNull() ) {
3452     Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3453     OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3454     aCaps->swapInterval = enable;
3455   }
3456 }
3457
3458 bool OCCViewer_ViewWindow::isVSync() const
3459 {
3460   int enable = true;
3461   Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3462   if ( !anIntCont.IsNull() ) {
3463     Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3464     OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3465     enable = aCaps->swapInterval;
3466   }
3467   return enable;
3468 }
3469
3470 void OCCViewer_ViewWindow::setQuadBufferSupport( bool enable )
3471 {
3472   Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3473   if ( !anIntCont.IsNull() ) {
3474     Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3475     OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3476     aCaps->contextStereo = enable;
3477   }
3478 }
3479
3480 bool OCCViewer_ViewWindow::isQuadBufferSupport() const
3481 {
3482   int enable = true;
3483   Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3484   if ( !anIntCont.IsNull() ) {
3485     Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3486     OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3487     enable = aCaps->contextStereo;
3488   }
3489   return enable;
3490 }
3491
3492 bool OCCViewer_ViewWindow::isOpenGlStereoSupport() const
3493 {
3494   GLboolean support[1];
3495   glGetBooleanv (GL_STEREO, support);
3496   if ( support[0] )
3497     return true;
3498   return false;
3499 }
3500
3501 // obsolete
3502 QColor OCCViewer_ViewWindow::backgroundColor() const
3503 {
3504   return myViewPort ? myViewPort->backgroundColor() : Qt::black;
3505 }
3506
3507 // obsolete
3508 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
3509 {
3510   if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
3511 }
3512
3513 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
3514 {
3515   return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
3516 }
3517
3518 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
3519 {
3520   if ( myViewPort ) myViewPort->setBackground( theBackground );
3521 }
3522
3523 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
3524 {
3525   if ( myViewPort ) myViewPort->showStaticTrihedron( on );
3526 }
3527
3528 /*!
3529   Clears view aspects
3530 */
3531 void OCCViewer_ViewWindow::clearViewAspects()
3532 {
3533   myViewAspects.clear();
3534 }
3535
3536 /*!
3537   \return const reference to list of view aspects
3538 */
3539 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
3540 {
3541   return myViewAspects;
3542 }
3543
3544 /*!
3545   Appends new view aspect
3546   \param aParams - new view aspects
3547 */
3548 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
3549 {
3550   myViewAspects.append( aParams );
3551 }
3552
3553 /*!
3554   Replaces old view aspects by new ones
3555   \param aViewList - list of new view aspects
3556 */
3557 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
3558 {
3559   myViewAspects = aViewList;
3560 }
3561
3562 /*!
3563   Get camera properties for the OCC view window.
3564   \return shared pointer on camera properties.
3565 */
3566 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
3567 {
3568   SUIT_CameraProperties aProps;
3569
3570   Handle(V3d_View) aSourceView = getViewPort()->getView();
3571   if ( aSourceView.IsNull() )
3572     return aProps;
3573
3574   if ( get2dMode() == No2dMode ) {
3575     aProps.setDimension( SUIT_CameraProperties::Dim3D );
3576   }
3577   else {
3578     aProps.setDimension( SUIT_CameraProperties::Dim2D );
3579     aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
3580   }
3581
3582   // read common properites of the view
3583   Standard_Real anUp[3];
3584   Standard_Real anAt[3];
3585   Standard_Real anEye[3];
3586   Standard_Real aProj[3];
3587   Standard_Real anAxialScale[3];
3588
3589   aSourceView->Up( anUp[0], anUp[1], anUp[2] );
3590   aSourceView->At( anAt[0], anAt[1], anAt[2] );
3591   aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
3592   getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3593
3594   aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3595   aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
3596
3597   aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
3598
3599   // store camera properties "as is": it is up to synchronized
3600   // view classes to provide necessary property conversion.
3601   aProps.setPosition( anEye[0], anEye[1], anEye[2] );
3602   aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
3603
3604   if ( aSourceView->Camera()->IsOrthographic() )
3605   {
3606     aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
3607     aProps.setViewAngle( 0.0 );
3608   }
3609   else
3610   {
3611     aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
3612     aProps.setViewAngle( aSourceView->Camera()->FOVy() );
3613   }
3614   aProps.setMappingScale( aSourceView->Camera()->Scale() );
3615
3616   return aProps;
3617 }
3618
3619 /*!
3620   Synchronize views.
3621   This implementation synchronizes OCC view's camera propreties.
3622 */
3623 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
3624 {
3625   bool blocked = blockSignals( true );
3626
3627   SUIT_CameraProperties aProps = theView->cameraProperties();
3628   if ( !cameraProperties().isCompatible( aProps ) ) {
3629     // other view, this one is being currently synchronized to, seems has become incompatible
3630     // we have to break synchronization
3631     updateSyncViews();
3632     return;
3633   }
3634
3635   Handle(V3d_View) aDestView = getViewPort()->getView();
3636
3637   aDestView->SetImmediateUpdate( Standard_False );
3638
3639   double anUpDir[3];
3640   double aPosition[3];
3641   double aFocalPoint[3];
3642   double anAxialScale[3];
3643
3644   // get common properties
3645   aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3646   aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
3647   aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3648   aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3649   
3650   try {
3651     aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3652     aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
3653     aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3654     aDestView->Camera()->SetScale( aProps.getMappingScale() );
3655
3656     getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3657     aDestView->SetImmediateUpdate( Standard_True );
3658     aDestView->Redraw();
3659   } 
3660   catch (Standard_Failure&) {
3661   }
3662
3663   blockSignals( blocked );
3664 }
3665
3666 /*!
3667   \brief Indicates whether preselection is enabled
3668   \return true if preselection is enabled
3669 */
3670 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
3671 {
3672   return myPreselectionEnabled;
3673 }
3674
3675 /*!
3676   \brief Enables/disables preselection
3677   \param theIsToEnable if true - preselection will be enabled
3678 */
3679 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
3680 {
3681   onSwitchPreselection( theIsToEnable );
3682 }
3683
3684 /*!
3685   \brief Indicates whether selection is enabled
3686   \return true if selection is enabled
3687 */
3688 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3689 {
3690   return mySelectionEnabled;
3691 }
3692
3693 /*!
3694   \brief Enables/disables selection
3695   \param theIsToEnable if true - selection will be enabled
3696 */
3697 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3698 {
3699   onSwitchSelection( theIsToEnable );
3700 }
3701
3702
3703 /*!
3704   \brief called if clipping operation is activated / deactivated.
3705
3706   Enables/disables clipping plane displaying.
3707
3708   \parma on action state
3709 */
3710 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3711 {
3712   if(!myModel) return;
3713   OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3714
3715   if (theIsOn) {
3716     if (!aClippingDlg) {
3717       aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3718       myModel->setClippingDlg(aClippingDlg);
3719     }
3720     if (!aClippingDlg->isVisible())
3721       aClippingDlg->show();
3722   } else {
3723     if ( aClippingDlg ) {
3724       aClippingDlg->close();
3725       myModel->setClippingDlg(0);
3726     }
3727   }
3728
3729   SUIT_ViewManager* mgr = getViewManager();
3730   if( mgr ) {
3731     QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3732     for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3733       if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3734         QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3735         if(!mgr) continue;
3736         QAction* a = toolMgr()->action( ClippingId );
3737         if(!a) continue;
3738         if(theIsOn != a->isChecked()){
3739           disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3740           a->setChecked(theIsOn);
3741           connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3742         }
3743       }
3744     }
3745   }
3746 }
3747
3748 void OCCViewer_ViewWindow::onRayTracing()
3749 {
3750   if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_RayTracingDlg::getName() ) ) {
3751     QDialog* aDlg = new OCCViewer_RayTracingDlg( this );
3752     if ( aDlg != NULL )
3753       aDlg->show();
3754   }
3755 }
3756
3757 void OCCViewer_ViewWindow::onEnvTexture()
3758 {
3759   if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_EnvTextureDlg::getName() ) ) {
3760     QDialog* aDlg = new OCCViewer_EnvTextureDlg( this );
3761     if ( aDlg != NULL )
3762       aDlg->show();
3763   }
3764 }
3765
3766 void OCCViewer_ViewWindow::onLightSource()
3767 {
3768   if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_LightSourceDlg::getName() ) ) {
3769     QDialog* aDlg = new OCCViewer_LightSourceDlg( this, myModel );
3770     if ( aDlg != NULL )
3771       aDlg->show();
3772   }
3773 }
3774
3775 bool OCCViewer_ViewWindow::isActionVisible( ActionId theId ) const
3776 {
3777   QAction* a = toolMgr()->action( theId );
3778   return a && a->isVisible();
3779 }
3780
3781 void OCCViewer_ViewWindow::setActionVisible( ActionId theId, bool isVisible )
3782 {
3783   QAction* a = toolMgr()->action( theId );
3784   if( a )
3785     a->setVisible( isVisible );
3786 }
3787
3788 void OCCViewer_ViewWindow::projAndPanToGravity(V3d_TypeOfOrientation CamOri)
3789 {
3790   const bool USE_XY = true;
3791
3792   Handle(V3d_View) aView3d = myViewPort->getView();
3793   if (aView3d.IsNull())
3794     return;
3795
3796   bool IsGr = false;
3797   double X = 0, Y = 0, Z = 0;
3798   if( USE_XY )
3799   {
3800     const double EPS = 1E-6;
3801     int xp = myViewPort->width()/2, yp = myViewPort->height()/2;
3802     aView3d->Convert( xp, yp, X, Y, Z );
3803
3804     gp_Dir d = aView3d->Camera()->Direction();
3805     if( fabs( d.Z() ) > EPS )
3806     {
3807       double t = -Z/d.Z();
3808       X += t*d.X();
3809       Y += t*d.Y();
3810       Z += t*d.Z();
3811     }
3812   }
3813
3814   // It is really necessary to compute gravity center even if it is not used in part of code below.
3815   // Without this calculation the SetProj() method and other methods are not correct.
3816   double X2, Y2, Z2;
3817   IsGr = computeGravityCenter(X2, Y2, Z2);
3818   if ( !IsGr )
3819     IsGr = OCCViewer_Utilities::computeSceneBBCenter(aView3d, X2, Y2, Z2);
3820
3821   aView3d->SetProj(CamOri);
3822   if (IsGr)
3823   {
3824     //aView3d->Update();
3825     Handle(Graphic3d_Camera) Cam = aView3d->Camera();
3826     gp_XYZ gp(X, Y, Z);
3827     gp_Vec dir (Cam->Direction());
3828     gp_Pnt eye = Cam->Eye();
3829     gp_Vec V1(eye, gp);
3830     Standard_Real D = dir.Dot(V1);
3831     gp_Pnt ppdir = eye.Translated(D*dir);
3832     gp_Vec V2(ppdir, gp);
3833     gp_XYZ trEye = eye.XYZ() + V2.XYZ();
3834
3835     double xat, yat, zat;
3836     aView3d->At(xat, yat, zat);
3837     gp_Pnt At(xat, yat, zat);
3838     gp_XYZ trAt = At.XYZ() + V2.XYZ();
3839     aView3d->SetEye(trEye.X(), trEye.Y(), trEye.Z());
3840     aView3d->SetAt(trAt.X(), trAt.Y(), trAt.Z());
3841   }
3842 }
3843
3844
3845 bool OCCViewer_ViewWindow::isAutomaticZoom() const
3846 {
3847   return myAutomaticZoom;
3848 }
3849
3850 void OCCViewer_ViewWindow::setAutomaticZoom(const bool isOn)
3851 {
3852   myAutomaticZoom = isOn;
3853 }
3854