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