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