Salome HOME
Unicode support: correct handling of unicode on GUI level
[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
2252   Handle(Graphic3d_CView) a3dView = myViewPort->getView()->View();
2253
2254   if (format == "PS") {
2255     Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(myViewPort->getViewer()->Driver());
2256     OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
2257     int prev = aCaps->ffpEnable;
2258     aCaps->ffpEnable = 1;
2259     res = a3dView->Export(strdup(qUtf8Printable(fileName)), Graphic3d_EF_PostScript);
2260     aCaps->ffpEnable = prev;
2261   }
2262   else if (format == "EPS") {
2263     Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(myViewPort->getViewer()->Driver());
2264     OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
2265     int prev = aCaps->ffpEnable;
2266     aCaps->ffpEnable = 1;
2267     res = a3dView->Export(strdup(qUtf8Printable(fileName)), Graphic3d_EF_EnhPostScript);
2268     aCaps->ffpEnable = prev;
2269   }
2270   else {
2271     res = myViewPort->getView()->Dump( fileName.toStdString().c_str() );
2272   }
2273
2274   QApplication::restoreOverrideCursor();
2275   return res;
2276 }
2277
2278
2279 QString OCCViewer_ViewWindow::filter() const
2280 {
2281   return tr( "OCC_IMAGE_FILES" );
2282 }
2283
2284
2285 /*!
2286   \brief Set parameters of the cutting plane
2287   \param on if \c true, cutting plane is enabled
2288   \param x X position of plane point
2289   \param y Y position of plane point
2290   \param z Z position of plane point
2291   \param dx X coordinate of plane normal
2292   \param dy Y coordinate of plane normal
2293   \param dz Z coordinate of plane normal
2294 */
2295 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x,  const double y,  const double z,
2296                                             const double dx, const double dy, const double dz )
2297 {
2298   Handle(V3d_View) view = myViewPort->getView();
2299   if ( view.IsNull() )
2300     return;
2301
2302   if ( on ) {
2303     Handle(V3d_Viewer) viewer = myViewPort->getViewer();
2304
2305     // try to use already existing plane or create a new one
2306     Handle(V3d_Plane) clipPlane;
2307
2308     // calculate new a,b,c,d values for the plane
2309     gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
2310     double a, b, c, d;
2311     pln.Coefficients(a, b, c, d);
2312     Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2313     Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2314     if(aPlanes->Size() > 0 ) {
2315       Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2316       aClipPlane->SetEquation(pln);
2317       aClipPlane->SetOn(Standard_True);
2318     } else {
2319       view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) );
2320     }
2321   }
2322   else {
2323     Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2324     Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2325     for( ;anIter.More();anIter.Next() ){
2326       Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2327       aClipPlane->SetOn(Standard_False);
2328     }
2329   }
2330
2331   view->Update();
2332   view->Redraw();
2333 }
2334
2335 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
2336 {
2337   gp_Dir aDir = pln.Axis().Direction();
2338   gp_Pnt aPnt = pln.Location();
2339   setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
2340 }
2341
2342
2343 /*!
2344   \brief Check if any cutting plane is enabled
2345   \return \c true if at least one cutting plane is enabled
2346 */
2347 bool OCCViewer_ViewWindow::isCuttingPlane()
2348 {
2349   Handle(V3d_View) view = myViewPort->getView();
2350   bool res = false;
2351   Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
2352   Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
2353   for( ;anIter.More();anIter.Next() ) {
2354     Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
2355     if(aClipPlane->IsOn()) {
2356       res = true;
2357       break;
2358     }
2359   }
2360   return res;
2361 }
2362
2363 /*!
2364   \brief Get the visual parameters of the view window.
2365   \return visual parameters of view window
2366 */
2367 viewAspect OCCViewer_ViewWindow::getViewParams() const
2368 {
2369   double projX, projY, projZ, twist;
2370   double atX, atY, atZ, eyeX, eyeY, eyeZ;
2371   double aScaleX, aScaleY, aScaleZ;
2372
2373   Handle(V3d_View) aView3d = myViewPort->getView();
2374
2375   aView3d->Proj( projX, projY, projZ );
2376   aView3d->At( atX, atY, atZ );
2377   aView3d->Eye( eyeX, eyeY, eyeZ );
2378   twist = aView3d->Twist();
2379
2380   aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
2381
2382   bool isShown = myModel->isTrihedronVisible();
2383   double size = myModel->trihedronSize();
2384
2385   QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
2386
2387   viewAspect params;
2388   params.scale    = aView3d->Scale();
2389   params.projX    = projX;
2390   params.projY    = projY;
2391   params.projZ    = projZ;
2392   params.twist    = twist;
2393   params.atX      = atX;
2394   params.atY      = atY;
2395   params.atZ      = atZ;
2396   params.eyeX     = eyeX;
2397   params.eyeY     = eyeY;
2398   params.eyeZ     = eyeZ;
2399   params.scaleX   = aScaleX;
2400   params.scaleY   = aScaleY;
2401   params.scaleZ   = aScaleZ;
2402   params.name     = aName;
2403   params.isVisible= isShown;
2404   params.size     = size;
2405
2406   // graduated trihedron
2407   bool anIsVisible = false;
2408   OCCViewer_AxisWidget::AxisData anAxisData[3];
2409   myCubeAxesDlg->GetData( anIsVisible, anAxisData );
2410
2411   params.gtIsVisible = anIsVisible;
2412   params.gtDrawNameX = anAxisData[0].DrawName;
2413   params.gtDrawNameY = anAxisData[1].DrawName;
2414   params.gtDrawNameZ = anAxisData[2].DrawName;
2415   params.gtNameX = anAxisData[0].Name;
2416   params.gtNameY = anAxisData[1].Name;
2417   params.gtNameZ = anAxisData[2].Name;
2418   params.gtNameColorRX = anAxisData[0].NameColor.red();
2419   params.gtNameColorGX = anAxisData[0].NameColor.green();
2420   params.gtNameColorBX = anAxisData[0].NameColor.blue();
2421   params.gtNameColorRY = anAxisData[1].NameColor.red();
2422   params.gtNameColorGY = anAxisData[1].NameColor.green();
2423   params.gtNameColorBY = anAxisData[1].NameColor.blue();
2424   params.gtNameColorRZ = anAxisData[2].NameColor.red();
2425   params.gtNameColorGZ = anAxisData[2].NameColor.green();
2426   params.gtNameColorBZ = anAxisData[2].NameColor.blue();
2427   params.gtDrawValuesX = anAxisData[0].DrawValues;
2428   params.gtDrawValuesY = anAxisData[1].DrawValues;
2429   params.gtDrawValuesZ = anAxisData[2].DrawValues;
2430   params.gtNbValuesX = anAxisData[0].NbValues;
2431   params.gtNbValuesY = anAxisData[1].NbValues;
2432   params.gtNbValuesZ = anAxisData[2].NbValues;
2433   params.gtOffsetX = anAxisData[0].Offset;
2434   params.gtOffsetY = anAxisData[1].Offset;
2435   params.gtOffsetZ = anAxisData[2].Offset;
2436   params.gtColorRX = anAxisData[0].Color.red();
2437   params.gtColorGX = anAxisData[0].Color.green();
2438   params.gtColorBX = anAxisData[0].Color.blue();
2439   params.gtColorRY = anAxisData[1].Color.red();
2440   params.gtColorGY = anAxisData[1].Color.green();
2441   params.gtColorBY = anAxisData[1].Color.blue();
2442   params.gtColorRZ = anAxisData[2].Color.red();
2443   params.gtColorGZ = anAxisData[2].Color.green();
2444   params.gtColorBZ = anAxisData[2].Color.blue();
2445   params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
2446   params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
2447   params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
2448   params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
2449   params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
2450   params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
2451
2452   return params;
2453 }
2454
2455 /*!
2456   \brief Get visual parameters of this view window.
2457   \return visual parameters of view window
2458 */
2459 QString OCCViewer_ViewWindow::getVisualParameters()
2460 {
2461   viewAspect params = getViewParams();
2462
2463   QStringList data;
2464
2465   data << QString( "scale=%1" )    .arg( params.scale,   0, 'e', 12 );
2466   data << QString( "projX=%1" )    .arg( params.projX,   0, 'e', 12 );
2467   data << QString( "projY=%1" )    .arg( params.projY,   0, 'e', 12 );
2468   data << QString( "projZ=%1" )    .arg( params.projZ,   0, 'e', 12 );
2469   data << QString( "twist=%1" )    .arg( params.twist,   0, 'e', 12 );
2470   data << QString( "atX=%1" )      .arg( params.atX,     0, 'e', 12 );
2471   data << QString( "atY=%1" )      .arg( params.atY,     0, 'e', 12 );
2472   data << QString( "atZ=%1" )      .arg( params.atZ,     0, 'e', 12 );
2473   data << QString( "eyeX=%1" )     .arg( params.eyeX,    0, 'e', 12 );
2474   data << QString( "eyeY=%1" )     .arg( params.eyeY,    0, 'e', 12 );
2475   data << QString( "eyeZ=%1" )     .arg( params.eyeZ,    0, 'e', 12 );
2476   data << QString( "scaleX=%1" )   .arg( params.scaleX,  0, 'e', 12 );
2477   data << QString( "scaleY=%1" )   .arg( params.scaleY,  0, 'e', 12 );
2478   data << QString( "scaleZ=%1" )   .arg( params.scaleZ,  0, 'e', 12 );
2479   data << QString( "isVisible=%1" ).arg( params.isVisible );
2480   data << QString( "size=%1" )     .arg( params.size,    0, 'f',  2 );
2481
2482   ClipPlanesList aPlanes =  myModel->getClipPlanes();
2483   for ( int i=0; i < aPlanes.size(); i++ )
2484   {
2485     OCCViewer_ClipPlane& aPlane = aPlanes[i];
2486     QString ClippingPlane = QString( "ClippingPlane%1=").arg( i+1 );
2487     ClippingPlane +=  QString( "Mode~%1;").arg( (int)aPlane.Mode );
2488     ClippingPlane +=  QString( "IsActive~%1;").arg( aPlane.IsOn );
2489     switch ( aPlane.Mode )
2490     {
2491       case OCCViewer_ClipPlane::Absolute :
2492       {
2493         ClippingPlane += QString( "AbsoluteOrientation~%1;" ).arg( aPlane.OrientationType );
2494
2495         if ( aPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
2496         {
2497           ClippingPlane += QString( "Dx~%1;" ).arg( aPlane.AbsoluteOrientation.Dx );
2498           ClippingPlane += QString( "Dy~%1;" ).arg( aPlane.AbsoluteOrientation.Dy );
2499           ClippingPlane += QString( "Dz~%1;" ).arg( aPlane.AbsoluteOrientation.Dz );
2500         }
2501         else
2502         {
2503           ClippingPlane += QString( "IsInvert~%1;" ).arg( aPlane.AbsoluteOrientation.IsInvert );
2504         }
2505       }
2506       break;
2507
2508       case OCCViewer_ClipPlane::Relative :
2509       {
2510         ClippingPlane += QString( "RelativeOrientation~%1;" ).arg( aPlane.OrientationType );
2511         ClippingPlane += QString( "Rotation1~%1;" ).arg( aPlane.RelativeOrientation.Rotation1 );
2512         ClippingPlane += QString( "Rotation2~%1" ).arg( aPlane.RelativeOrientation.Rotation2 );
2513       }
2514       break;
2515     }
2516
2517     ClippingPlane +=  QString( "X~%1;" ).arg( aPlane.X );
2518     ClippingPlane +=  QString( "Y~%1;" ).arg( aPlane.Y );
2519     ClippingPlane +=  QString( "Z~%1;" ).arg( aPlane.Z );
2520     data << ClippingPlane;
2521   }
2522
2523   // graduated trihedron
2524   data << QString( "gtIsVisible=%1" )      .arg( params.gtIsVisible );
2525   data << QString( "gtDrawNameX=%1" )      .arg( params.gtDrawNameX );
2526   data << QString( "gtDrawNameY=%1" )      .arg( params.gtDrawNameY );
2527   data << QString( "gtDrawNameZ=%1" )      .arg( params.gtDrawNameZ );
2528   data << QString( "gtNameX=%1" )          .arg( params.gtNameX );
2529   data << QString( "gtNameY=%1" )          .arg( params.gtNameY );
2530   data << QString( "gtNameZ=%1" )          .arg( params.gtNameZ );
2531   data << QString( "gtNameColorRX=%1" )    .arg( params.gtNameColorRX );
2532   data << QString( "gtNameColorGX=%1" )    .arg( params.gtNameColorGX );
2533   data << QString( "gtNameColorBX=%1" )    .arg( params.gtNameColorBX );
2534   data << QString( "gtNameColorRY=%1" )    .arg( params.gtNameColorRY );
2535   data << QString( "gtNameColorGY=%1" )    .arg( params.gtNameColorGY );
2536   data << QString( "gtNameColorBY=%1" )    .arg( params.gtNameColorBY );
2537   data << QString( "gtNameColorRZ=%1" )    .arg( params.gtNameColorRZ );
2538   data << QString( "gtNameColorGZ=%1" )    .arg( params.gtNameColorGZ );
2539   data << QString( "gtNameColorBZ=%1" )    .arg( params.gtNameColorBZ );
2540   data << QString( "gtDrawValuesX=%1" )    .arg( params.gtDrawValuesX );
2541   data << QString( "gtDrawValuesY=%1" )    .arg( params.gtDrawValuesY );
2542   data << QString( "gtDrawValuesZ=%1" )    .arg( params.gtDrawValuesZ );
2543   data << QString( "gtNbValuesX=%1" )      .arg( params.gtNbValuesX );
2544   data << QString( "gtNbValuesY=%1" )      .arg( params.gtNbValuesY );
2545   data << QString( "gtNbValuesZ=%1" )      .arg( params.gtNbValuesZ );
2546   data << QString( "gtOffsetX=%1" )        .arg( params.gtOffsetX );
2547   data << QString( "gtOffsetY=%1" )        .arg( params.gtOffsetY );
2548   data << QString( "gtOffsetZ=%1" )        .arg( params.gtOffsetZ );
2549   data << QString( "gtColorRX=%1" )        .arg( params.gtColorRX );
2550   data << QString( "gtColorGX=%1" )        .arg( params.gtColorGX );
2551   data << QString( "gtColorBX=%1" )        .arg( params.gtColorBX );
2552   data << QString( "gtColorRY=%1" )        .arg( params.gtColorRY );
2553   data << QString( "gtColorGY=%1" )        .arg( params.gtColorGY );
2554   data << QString( "gtColorBY=%1" )        .arg( params.gtColorBY );
2555   data << QString( "gtColorRZ=%1" )        .arg( params.gtColorRZ );
2556   data << QString( "gtColorGZ=%1" )        .arg( params.gtColorGZ );
2557   data << QString( "gtColorBZ=%1" )        .arg( params.gtColorBZ );
2558   data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
2559   data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
2560   data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
2561   data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
2562   data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
2563   data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
2564
2565   // ray tracing parameters
2566   Graphic3d_RenderingParams rendParams = this->getViewPort()->getView()->RenderingParams();
2567   if ( rendParams.Method == Graphic3d_RM_RAYTRACING ) {
2568     QString RayTracing = "rayTracing=";
2569     RayTracing += QString( "rtDepth~%1;" ).arg( rendParams.RaytracingDepth );
2570     RayTracing += QString( "rtReflection~%1;" ).arg( rendParams.IsReflectionEnabled );
2571     RayTracing += QString( "rtAntialiasing~%1;" ).arg( rendParams.IsAntialiasingEnabled );
2572     RayTracing += QString( "rtShadow~%1;" ).arg( rendParams.IsShadowEnabled );
2573     RayTracing += QString( "rtTransShadow~%1;" ).arg( rendParams.IsTransparentShadowEnabled );
2574     data << RayTracing;
2575   }
2576
2577   // environment texture parameters
2578   Handle(Graphic3d_TextureEnv) aTexture = this->getViewPort()->getView()->TextureEnv();
2579   if ( !aTexture.IsNull() ) {
2580     QString EnvTexture = "envTexture=";
2581     if ( aTexture->Name() == Graphic3d_NOT_ENV_UNKNOWN ) {
2582       TCollection_AsciiString aFileName;
2583       aTexture->Path().SystemName( aFileName );
2584       EnvTexture += QString( "etFile~%1;" ).arg( aFileName.ToCString() );
2585     }
2586     else
2587       EnvTexture += QString( "etNumber~%1;" ).arg( aTexture->Name() );
2588     data << EnvTexture;
2589   }
2590
2591   // light source parameters
2592   myModel->getViewer3d()->InitDefinedLights();
2593   while ( myModel->getViewer3d()->MoreDefinedLights() )
2594   {
2595     Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2596     if ( aLight->Type() != V3d_AMBIENT ) {
2597       QString LightSource = QString( "lightSource=" );
2598       LightSource += QString( "lightType~%1;" ).arg( aLight->Type() );
2599       double aX, aY, aZ;
2600       if ( aLight->Type() == V3d_DIRECTIONAL )
2601         Handle(V3d_DirectionalLight)::DownCast( aLight )->Direction( aX, aY, aZ );
2602       else if ( aLight->Type() == V3d_POSITIONAL )
2603         Handle(V3d_PositionalLight)::DownCast( aLight )->Position( aX, aY, aZ );
2604       LightSource += QString( "lightX~%1;" ).arg( aX );
2605       LightSource += QString( "lightY~%1;" ).arg( aY );
2606       LightSource += QString( "lightZ~%1;" ).arg( aZ );
2607       LightSource += QString( "lightColorR~%1;" ).arg( aLight->Color().Red() );
2608       LightSource += QString( "lightColorG~%1;" ).arg( aLight->Color().Green() );
2609       LightSource += QString( "lightColorB~%1;" ).arg( aLight->Color().Blue() );
2610       LightSource += QString( "lightHeadlight~%1;" ).arg( aLight->Headlight() );
2611       data << LightSource;
2612     }
2613     myModel->getViewer3d()->NextDefinedLights();
2614   }
2615
2616   QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
2617   data << QString( "background=%1" ).arg( bg );
2618
2619   return data.join("*");
2620 }
2621
2622 /*!
2623   \brief Restore visual parameters of the view window.
2624   \param parameters visual parameters of view window
2625 */
2626 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
2627 {
2628   viewAspect params;
2629   ClipPlanesList aClipPlanes;
2630   QStringList data = parameters.split( '*' );
2631   Qtx::BackgroundData bgData;
2632   if ( parameters.contains( '=' )  ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
2633   {
2634     foreach( QString param, data ) {
2635       QString paramName  = param.section( '=', 0, 0 ).trimmed();
2636       QString paramValue = param.section( '=', 1, 1 ).trimmed();
2637       if      ( paramName == "scale" )             params.scale             = paramValue.toDouble();
2638       else if ( paramName == "centerX" )           params.centerX           = paramValue.toDouble();
2639       else if ( paramName == "centerY" )           params.centerY           = paramValue.toDouble();
2640       else if ( paramName == "projX" )             params.projX             = paramValue.toDouble();
2641       else if ( paramName == "projY" )             params.projY             = paramValue.toDouble();
2642       else if ( paramName == "projZ" )             params.projZ             = paramValue.toDouble();
2643       else if ( paramName == "twist" )             params.twist             = paramValue.toDouble();
2644       else if ( paramName == "atX" )               params.atX               = paramValue.toDouble();
2645       else if ( paramName == "atY" )               params.atY               = paramValue.toDouble();
2646       else if ( paramName == "atZ" )               params.atZ               = paramValue.toDouble();
2647       else if ( paramName == "eyeX" )              params.eyeX              = paramValue.toDouble();
2648       else if ( paramName == "eyeY" )              params.eyeY              = paramValue.toDouble();
2649       else if ( paramName == "eyeZ" )              params.eyeZ              = paramValue.toDouble();
2650       else if ( paramName == "scaleX" )            params.scaleX            = paramValue.toDouble();
2651       else if ( paramName == "scaleY" )            params.scaleY            = paramValue.toDouble();
2652       else if ( paramName == "scaleZ" )            params.scaleZ            = paramValue.toDouble();
2653       else if ( paramName == "isVisible" )         params.isVisible         = paramValue.toInt();
2654       else if ( paramName == "size" )              params.size              = paramValue.toDouble();
2655       else if ( paramName.contains( "ClippingPlane" ) )
2656       {
2657         QStringList ClipPlaneData = paramValue.split( ';' );
2658         OCCViewer_ClipPlane aPlane;
2659         foreach( QString ClipPlaneParam, ClipPlaneData )
2660         {
2661           QString ClipPlane_paramName  = ClipPlaneParam.section( '~', 0, 0 ).trimmed();
2662           QString ClipPlane_paramValue = ClipPlaneParam.section( '~', 1, 1 ).trimmed();
2663           if ( ClipPlane_paramName == "Mode" )
2664           {
2665             aPlane.Mode = ( OCCViewer_ClipPlane::PlaneMode ) ClipPlane_paramValue.toInt();
2666           }
2667           else if ( ClipPlane_paramName == "IsActive" ) aPlane.IsOn = ClipPlane_paramValue.toInt();
2668           else if ( ClipPlane_paramName == "X" )        aPlane.X    = ClipPlane_paramValue.toDouble();
2669           else if ( ClipPlane_paramName == "Y" )        aPlane.Y    = ClipPlane_paramValue.toDouble();
2670           else if ( ClipPlane_paramName == "Z" )        aPlane.Z    = ClipPlane_paramValue.toDouble();
2671           else
2672           {
2673             switch ( aPlane.Mode )
2674             {
2675               case OCCViewer_ClipPlane::Absolute :
2676                 if      ( ClipPlane_paramName == "Dx" ) aPlane.AbsoluteOrientation.Dx = ClipPlane_paramValue.toDouble();
2677                 else if ( ClipPlane_paramName == "Dy" ) aPlane.AbsoluteOrientation.Dy = ClipPlane_paramValue.toDouble();
2678                 else if ( ClipPlane_paramName == "Dz" ) aPlane.AbsoluteOrientation.Dz = ClipPlane_paramValue.toDouble();
2679                 else if ( ClipPlane_paramName == "IsInvert" ) aPlane.AbsoluteOrientation.IsInvert = ClipPlane_paramValue.toInt();
2680                 else if ( ClipPlane_paramName == "AbsoluteOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2681                 break;
2682
2683               case OCCViewer_ClipPlane::Relative :
2684                 if      ( ClipPlane_paramName == "RelativeOrientation" ) aPlane.OrientationType = ClipPlane_paramValue.toInt();
2685                 else if ( ClipPlane_paramName == "Rotation1" )           aPlane.RelativeOrientation.Rotation1 = ClipPlane_paramValue.toDouble();
2686                 else if ( ClipPlane_paramName == "Rotation2" )           aPlane.RelativeOrientation.Rotation2 = ClipPlane_paramValue.toDouble();
2687                 break;
2688             }
2689           }
2690         }
2691         aClipPlanes.push_back(aPlane);
2692       }
2693       // graduated trihedron
2694       else if ( paramName == "gtIsVisible" )       params.gtIsVisible       = paramValue.toInt();
2695       else if ( paramName == "gtDrawNameX" )       params.gtDrawNameX       = paramValue.toInt();
2696       else if ( paramName == "gtDrawNameY" )       params.gtDrawNameY       = paramValue.toInt();
2697       else if ( paramName == "gtDrawNameZ" )       params.gtDrawNameZ       = paramValue.toInt();
2698       else if ( paramName == "gtNameX" )           params.gtNameX           = paramValue;
2699       else if ( paramName == "gtNameY" )           params.gtNameY           = paramValue;
2700       else if ( paramName == "gtNameZ" )           params.gtNameZ           = paramValue;
2701       else if ( paramName == "gtNameColorRX" )     params.gtNameColorRX     = paramValue.toInt();
2702       else if ( paramName == "gtNameColorGX" )     params.gtNameColorGX     = paramValue.toInt();
2703       else if ( paramName == "gtNameColorBX" )     params.gtNameColorBX     = paramValue.toInt();
2704       else if ( paramName == "gtNameColorRY" )     params.gtNameColorRY     = paramValue.toInt();
2705       else if ( paramName == "gtNameColorGY" )     params.gtNameColorGY     = paramValue.toInt();
2706       else if ( paramName == "gtNameColorBY" )     params.gtNameColorBY     = paramValue.toInt();
2707       else if ( paramName == "gtNameColorRZ" )     params.gtNameColorRZ     = paramValue.toInt();
2708       else if ( paramName == "gtNameColorGZ" )     params.gtNameColorGZ     = paramValue.toInt();
2709       else if ( paramName == "gtNameColorBZ" )     params.gtNameColorBZ     = paramValue.toInt();
2710       else if ( paramName == "gtDrawValuesX" )     params.gtDrawValuesX     = paramValue.toInt();
2711       else if ( paramName == "gtDrawValuesY" )     params.gtDrawValuesY     = paramValue.toInt();
2712       else if ( paramName == "gtDrawValuesZ" )     params.gtDrawValuesZ     = paramValue.toInt();
2713       else if ( paramName == "gtNbValuesX" )       params.gtNbValuesX       = paramValue.toInt();
2714       else if ( paramName == "gtNbValuesY" )       params.gtNbValuesY       = paramValue.toInt();
2715       else if ( paramName == "gtNbValuesZ" )       params.gtNbValuesZ       = paramValue.toInt();
2716       else if ( paramName == "gtOffsetX" )         params.gtOffsetX         = paramValue.toInt();
2717       else if ( paramName == "gtOffsetY" )         params.gtOffsetY         = paramValue.toInt();
2718       else if ( paramName == "gtOffsetZ" )         params.gtOffsetZ         = paramValue.toInt();
2719       else if ( paramName == "gtColorRX" )         params.gtColorRX         = paramValue.toInt();
2720       else if ( paramName == "gtColorGX" )         params.gtColorGX         = paramValue.toInt();
2721       else if ( paramName == "gtColorBX" )         params.gtColorBX         = paramValue.toInt();
2722       else if ( paramName == "gtColorRY" )         params.gtColorRY         = paramValue.toInt();
2723       else if ( paramName == "gtColorGY" )         params.gtColorGY         = paramValue.toInt();
2724       else if ( paramName == "gtColorBY" )         params.gtColorBY         = paramValue.toInt();
2725       else if ( paramName == "gtColorRZ" )         params.gtColorRZ         = paramValue.toInt();
2726       else if ( paramName == "gtColorGZ" )         params.gtColorGZ         = paramValue.toInt();
2727       else if ( paramName == "gtColorBZ" )         params.gtColorBZ         = paramValue.toInt();
2728       else if ( paramName == "gtDrawTickmarksX" )  params.gtDrawTickmarksX  = paramValue.toInt();
2729       else if ( paramName == "gtDrawTickmarksY" )  params.gtDrawTickmarksY  = paramValue.toInt();
2730       else if ( paramName == "gtDrawTickmarksZ" )  params.gtDrawTickmarksZ  = paramValue.toInt();
2731       else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
2732       else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
2733       else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
2734       else if ( paramName == "rayTracing" )
2735       {
2736         Graphic3d_RenderingParams& rendParams = this->getViewPort()->getView()->ChangeRenderingParams();
2737         rendParams.Method = Graphic3d_RM_RAYTRACING;
2738         QStringList rtData = paramValue.split( ';' );
2739         foreach( QString rtParam, rtData )
2740         {
2741           QString rt_paramName  = rtParam.section( '~', 0, 0 ).trimmed();
2742           QString rt_paramValue = rtParam.section( '~', 1, 1 ).trimmed();
2743           if ( rt_paramName == "rtDepth" ) rendParams.RaytracingDepth = rt_paramValue.toInt();
2744           else if ( rt_paramName == "rtReflection" ) rendParams.IsReflectionEnabled = rt_paramValue.toInt();
2745           else if ( rt_paramName == "rtAntialiasing" ) rendParams.IsAntialiasingEnabled = rt_paramValue.toInt();
2746           else if ( rt_paramName == "rtShadow" ) rendParams.IsShadowEnabled = rt_paramValue.toInt();
2747           else if ( rt_paramName == "rtTransShadow" ) rendParams.IsTransparentShadowEnabled = rt_paramValue.toInt();
2748         }
2749       }
2750       else if ( paramName == "envTexture" )
2751       {
2752         Handle(Graphic3d_TextureEnv) aTexture;
2753         QStringList etData = paramValue.split( ';' );
2754         foreach( QString etParam, etData )
2755         {
2756           QString et_paramName  = etParam.section( '~', 0, 0 ).trimmed();
2757           QString et_paramValue = etParam.section( '~', 1, 1 ).trimmed();
2758           if ( et_paramName == "etNumber" )
2759             aTexture = new Graphic3d_TextureEnv( Graphic3d_NameOfTextureEnv( et_paramValue.toInt() ) );
2760           else if ( et_paramName == "etFile" )
2761             aTexture = new Graphic3d_TextureEnv( TCollection_AsciiString( et_paramValue.toStdString().c_str() ) );
2762           Handle(V3d_View) aView = this->getViewPort()->getView();
2763           aView->SetTextureEnv( aTexture );
2764         }
2765       }
2766       else if ( paramName == "lightSource" )
2767       {
2768         myModel->getViewer3d()->InitDefinedLights();
2769         while ( myModel->getViewer3d()->MoreDefinedLights() )
2770         {
2771           Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
2772           if( aLight->Type() != V3d_AMBIENT ) {
2773             myModel->getViewer3d()->DelLight( aLight );
2774             myModel->getViewer3d()->InitDefinedLights();
2775           } else {
2776             myModel->getViewer3d()->NextDefinedLights();
2777           }
2778         }
2779         double aX, aY, aZ;
2780         double cR, cG, cB;
2781         V3d_TypeOfLight aType;
2782         bool isHeadlight;
2783         QStringList lsData = paramValue.split( ';' );
2784         foreach( QString lsParam, lsData )
2785         {
2786           QString ls_paramName  = lsParam.section( '~', 0, 0 ).trimmed();
2787           QString ls_paramValue = lsParam.section( '~', 1, 1 ).trimmed();
2788           if ( ls_paramName == "lightType" ) aType = V3d_TypeOfLight( ls_paramValue.toInt() );
2789           else if ( ls_paramName == "lightX" ) aX = ls_paramValue.toDouble();
2790           else if ( ls_paramName == "lightY" ) aY = ls_paramValue.toDouble();
2791           else if ( ls_paramName == "lightZ" ) aZ = ls_paramValue.toDouble();
2792           else if ( ls_paramName == "lightColorR" ) cR = ls_paramValue.toDouble();
2793           else if ( ls_paramName == "lightColorG" ) cG = ls_paramValue.toDouble();
2794           else if ( ls_paramName == "lightColorB" ) cB = ls_paramValue.toDouble();
2795           else if ( ls_paramName == "lightHeadlight" ) isHeadlight = ls_paramValue.toInt();
2796         }
2797         Quantity_Color aColor = Quantity_Color( cR, cG, cB, Quantity_TOC_RGB );
2798         if( aType == V3d_DIRECTIONAL ) {
2799           Handle(V3d_DirectionalLight) aLight = new V3d_DirectionalLight( myModel->getViewer3d() );
2800           aLight->SetDirection( aX, aY, aZ );
2801           aLight->SetColor( aColor );
2802           aLight->SetHeadlight( isHeadlight );
2803           myModel->getViewer3d()->SetLightOn( aLight );
2804         }
2805         else if( aType == V3d_POSITIONAL ) {
2806           Handle(V3d_PositionalLight) aLight = new V3d_PositionalLight( myModel->getViewer3d(), aX, aY, aZ, aColor.Name() );
2807           aLight->SetHeadlight( isHeadlight );
2808           myModel->getViewer3d()->SetLightOn( aLight );
2809         }
2810       }
2811       else if ( paramName == "background" )        {
2812   QString bg = paramValue.replace( "$", "=" );
2813   bgData = Qtx::stringToBackground( bg );
2814       }
2815     }
2816   }
2817   else // old format - "1.000e+00*0.000e+00..."
2818   {
2819     int idx = 0;
2820     params.scale     = data.count() > idx ? data[idx++].toDouble() : 1.0;
2821     params.centerX   = data.count() > idx ? data[idx++].toDouble() : 0.0;
2822     params.centerY   = data.count() > idx ? data[idx++].toDouble() : 0.0;
2823     params.projX     = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2824     params.projY     = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
2825     params.projZ     = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
2826     params.twist     = data.count() > idx ? data[idx++].toDouble() : 0.0;
2827     params.atX       = data.count() > idx ? data[idx++].toDouble() : 0.0;
2828     params.atY       = data.count() > idx ? data[idx++].toDouble() : 0.0;
2829     params.atZ       = data.count() > idx ? data[idx++].toDouble() : 0.0;
2830     params.eyeX      = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2831     params.eyeY      = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
2832     params.eyeZ      = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
2833     params.scaleX    = data.count() > idx ? data[idx++].toDouble() : 1.0;
2834     params.scaleY    = data.count() > idx ? data[idx++].toDouble() : 1.0;
2835     params.scaleZ    = data.count() > idx ? data[idx++].toDouble() : 1.0;
2836     params.isVisible = data.count() > idx ? data[idx++].toInt()    : 1;
2837     params.size      = data.count() > idx ? data[idx++].toDouble() : 100.0;
2838   }
2839   performRestoring( params );
2840   setBackground( bgData );
2841   myModel->setClipPlanes(aClipPlanes);
2842 }
2843
2844 /*!
2845   \brief Handle show event.
2846
2847   Emits Show() signal.
2848
2849   \param theEvent show event
2850 */
2851 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
2852 {
2853   emit Show( theEvent );
2854 }
2855
2856 /*!
2857   \brief Handle hide event.
2858
2859   Emits Hide() signal.
2860
2861   \param theEvent hide event
2862 */
2863 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
2864 {
2865   emit Hide( theEvent );
2866 }
2867
2868
2869 /*!
2870     Save old cursor. [ protected ]
2871 */
2872 void OCCViewer_ViewWindow::saveCursor()
2873 {
2874   QCursor* aCursor = NULL;
2875   if ( myViewPort )
2876     aCursor = myViewPort->getDefaultCursor();
2877   myCursor = ( aCursor ? *aCursor : cursor() );
2878 }
2879
2880
2881 /*!
2882     Creates default sketcher. [ virtual protected ]
2883 */
2884 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
2885 {
2886   if ( type == Rect )
2887     return new OCCViewer_RectSketcher( this, type );
2888   if ( type == Polygon )
2889     return new OCCViewer_PolygonSketcher( this, type );
2890   return 0;
2891 }
2892
2893 void OCCViewer_ViewWindow::initSketchers()
2894 {
2895   if ( mySketchers.isEmpty() )
2896   {
2897     mySketchers.append( createSketcher( Rect ) );
2898     mySketchers.append( createSketcher( Polygon ) );
2899   }
2900 }
2901
2902 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
2903 {
2904   OCCViewer_ViewSketcher* sketcher = 0;
2905   QList<OCCViewer_ViewSketcher*>::Iterator it;
2906   for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
2907   {
2908     OCCViewer_ViewSketcher* sk = (*it);
2909     if ( sk->type() == typ )
2910       sketcher = sk;
2911   }
2912   return sketcher;
2913 }
2914
2915 /*!
2916     Handles requests for sketching in the active view. [ virtual public ]
2917 */
2918 void OCCViewer_ViewWindow::activateSketching( int type )
2919 {
2920   OCCViewer_ViewPort3d* vp = getViewPort();
2921   if ( !vp )
2922     return;
2923
2924   if ( !vp->isSketchingEnabled() )
2925     return;
2926
2927   /* Finish current sketching */
2928   if ( type == NoSketching )
2929   {
2930     if ( mypSketcher )
2931     {
2932       onSketchingFinished();
2933       mypSketcher->deactivate();
2934       mypSketcher = 0;
2935     }
2936   }
2937   /* Activate new sketching */
2938   else
2939   {
2940     activateSketching( NoSketching );  /* concurrency not suported */
2941     mypSketcher = getSketcher( type );
2942     if ( mypSketcher )
2943     {
2944       mypSketcher->activate();
2945       onSketchingStarted();
2946     }
2947   }
2948 }
2949
2950 /*!
2951     Unhilights detected entities. [ virtual protected ]
2952 */
2953 void OCCViewer_ViewWindow::onSketchingStarted()
2954 {
2955 }
2956
2957 /*!
2958     Selection by rectangle or polygon. [ virtual protected ]
2959 */
2960 void OCCViewer_ViewWindow::onSketchingFinished()
2961 {
2962   MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
2963   if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
2964   {
2965     Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
2966     bool append = bool( mypSketcher->buttonState() && mypSketcher->isHasShift() );
2967     switch( mypSketcher->type() )
2968     {
2969     case Rect:
2970       {
2971         QRect* aRect = (QRect*)mypSketcher->data();
2972         if( aRect )
2973         {
2974           int aLeft = aRect->left();
2975           int aRight = aRect->right();
2976           int aTop = aRect->top();
2977           int aBottom = aRect->bottom();
2978 //           myRect = aRect;
2979
2980           if( append )
2981             ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2982           else
2983             ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
2984         }
2985       }
2986       break;
2987     case Polygon:
2988       {
2989         QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
2990         if( aPolygon )
2991         {
2992           int size = aPolygon->size();
2993           TColgp_Array1OfPnt2d anArray( 1, size );
2994
2995           QPolygon::Iterator it = aPolygon->begin();
2996           QPolygon::Iterator itEnd = aPolygon->end();
2997           for( int index = 1; it != itEnd; ++it, index++ )
2998           {
2999             QPoint aPoint = *it;
3000             anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
3001           }
3002
3003           if( append )
3004             ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
3005           else
3006             ic->Select( anArray, getViewPort()->getView(), Standard_False );
3007         }
3008       }
3009       break;
3010     default:
3011       break;
3012     }
3013
3014     OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
3015     aViewMgr->getOCCViewer()->performSelectionChanged();
3016   }
3017 }
3018
3019 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
3020 {
3021   return myViewPort;
3022 }
3023
3024 bool OCCViewer_ViewWindow::transformRequested() const
3025 {
3026   return ( myOperation != NOTHING );
3027 }
3028
3029 bool OCCViewer_ViewWindow::transformInProcess() const
3030 {
3031   return myEventStarted;
3032 }
3033
3034 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
3035 {
3036   myEventStarted = bOn;
3037 }
3038
3039 /*!
3040   Set enabled state of transformation (rotate, zoom, etc)
3041 */
3042 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
3043 {
3044   if ( id != NOTHING ) myStatus.insert( id, on );
3045 }
3046
3047 /*!
3048   \return enabled state of transformation (rotate, zoom, etc)
3049 */
3050 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
3051 {
3052   return myStatus.contains( id ) ? myStatus[ id ] : true;
3053 }
3054
3055 void OCCViewer_ViewWindow::onMaximizedView()
3056 {
3057   setMaximized(!isMaximized());
3058 }
3059
3060 void OCCViewer_ViewWindow::returnTo3dView()
3061 {
3062   setReturnedTo3dView( true );
3063 }
3064
3065 void OCCViewer_ViewWindow::setReturnedTo3dView(bool isVisible3dView)
3066 {
3067   if ( !toolMgr()->action( ReturnTo3dViewId ) ||
3068     toolMgr()->isShown(ReturnTo3dViewId) != isVisible3dView ) return;
3069   if ( !isVisible3dView )
3070     toolMgr()->show( ReturnTo3dViewId );
3071   else
3072     toolMgr()->hide( ReturnTo3dViewId );
3073   if ( isVisible3dView ) emit returnedTo3d( );
3074 }
3075
3076
3077 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
3078 {
3079   QAction* anAction =  toolMgr()->action( MaximizedId );
3080   QAction* anAction2 =  toolMgr()->action( ReturnTo3dViewId );
3081   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
3082   if ( toMaximize ) {
3083     anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );
3084     anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );
3085     anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
3086     anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
3087     if ( anAction2 && my2dMode != No2dMode ) toolMgr()->show( ReturnTo3dViewId );
3088     if (toSendSignal) {
3089       emit maximized( this, true );
3090     }
3091   }
3092   else {
3093     anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );
3094     anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );
3095     anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
3096     anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
3097     if ( anAction2 && my2dMode != No2dMode ) toolMgr()->hide( ReturnTo3dViewId );
3098     if (toSendSignal) {
3099       emit maximized( this, false );
3100     }
3101   }
3102 }
3103
3104 bool OCCViewer_ViewWindow::isMaximized() const
3105 {
3106   return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
3107 }
3108
3109 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
3110 {
3111   IsSketcherStyle = enable;
3112 }
3113
3114 bool OCCViewer_ViewWindow::isSketcherStyle() const
3115 {
3116   return IsSketcherStyle;
3117 }
3118
3119
3120 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
3121 {
3122   my2dMode = theType;
3123 }
3124
3125 int OCCViewer_ViewWindow::projectionType() const
3126 {
3127   int mode = Orthographic;
3128   Handle(V3d_View) aView3d = myViewPort->getView();
3129   if ( !aView3d.IsNull() ) {
3130     Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3131     if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Perspective)
3132       mode = Perspective;
3133     if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Orthographic)
3134       mode = Orthographic;
3135     if (aCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
3136       mode = Stereo;
3137   }
3138   return mode;
3139 }
3140
3141 void OCCViewer_ViewWindow::setStereoType( int type )
3142 {
3143   Handle(V3d_View) aView3d = myViewPort->getView();
3144   if ( !aView3d.IsNull() ) {
3145     Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3146     aParams->StereoMode = (Graphic3d_StereoMode)type;
3147   }
3148 }
3149
3150 int OCCViewer_ViewWindow::stereoType() const
3151 {
3152   int type = QuadBuffer;
3153   Handle(V3d_View) aView3d = myViewPort->getView();
3154   if ( !aView3d.IsNull() ) {
3155     Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3156     type = (OCCViewer_ViewWindow::StereoType)aParams->StereoMode;
3157   }
3158   return type;
3159 }
3160
3161 void OCCViewer_ViewWindow::setAnaglyphFilter( int type )
3162 {
3163   Handle(V3d_View) aView3d = myViewPort->getView();
3164   if ( !aView3d.IsNull() ) {
3165     Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3166     if (type == RedCyan)
3167       aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized;
3168     if (type == YellowBlue)
3169       aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized;
3170     if (type == GreenMagenta)
3171       aParams->AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple;
3172   }
3173 }
3174
3175 int OCCViewer_ViewWindow::anaglyphFilter() const
3176 {
3177   int type = RedCyan;
3178   Handle(V3d_View) aView3d = myViewPort->getView();
3179   if ( !aView3d.IsNull() ) {
3180     Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3181     if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized)
3182       type = RedCyan;
3183     if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized)
3184       type = YellowBlue;
3185     if (aParams->AnaglyphFilter == Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple)
3186       type = GreenMagenta;
3187   }
3188   return type;
3189 }
3190
3191 void OCCViewer_ViewWindow::setStereographicFocus( int type, double value )
3192 {
3193   Handle(V3d_View) aView3d = myViewPort->getView();
3194   if ( !aView3d.IsNull() ) {
3195     Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3196     aCamera->SetZFocus( (Graphic3d_Camera::FocusType) type, value );
3197   }
3198 }
3199
3200 int OCCViewer_ViewWindow::stereographicFocusType() const
3201 {
3202   int type = Relative;
3203   Handle(V3d_View) aView3d = myViewPort->getView();
3204   if ( !aView3d.IsNull() ) {
3205     Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3206     type = (OCCViewer_ViewWindow::FocusIODType)aCamera->ZFocusType();
3207   }
3208   return type;
3209 }
3210
3211 double OCCViewer_ViewWindow::stereographicFocusValue() const
3212 {
3213   double value = 1.0;
3214   Handle(V3d_View) aView3d = myViewPort->getView();
3215   if ( !aView3d.IsNull() ) {
3216     Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3217     value = aCamera->ZFocus();
3218   }
3219   return value;
3220 }
3221
3222 void OCCViewer_ViewWindow::setInterocularDistance( int type, double value )
3223 {
3224   Handle(V3d_View) aView3d = myViewPort->getView();
3225   if ( !aView3d.IsNull() ) {
3226     Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3227     aCamera->SetIOD( (Graphic3d_Camera::IODType) type, value );
3228   }
3229 }
3230
3231 int OCCViewer_ViewWindow::interocularDistanceType() const
3232 {
3233   int type = Relative;
3234   Handle(V3d_View) aView3d = myViewPort->getView();
3235   if ( !aView3d.IsNull() ) {
3236     Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3237     type = (OCCViewer_ViewWindow::FocusIODType)aCamera->GetIODType();
3238   }
3239   return type;
3240 }
3241
3242 double OCCViewer_ViewWindow::interocularDistanceValue() const
3243 {
3244   double value = 0.05;
3245   Handle(V3d_View) aView3d = myViewPort->getView();
3246   if ( !aView3d.IsNull() ) {
3247     Handle(Graphic3d_Camera) aCamera = aView3d->Camera();
3248     value = aCamera->IOD();
3249   }
3250   return value;
3251 }
3252
3253 void OCCViewer_ViewWindow::setReverseStereo( bool reverse )
3254 {
3255   Handle(V3d_View) aView3d = myViewPort->getView();
3256   if ( !aView3d.IsNull() ) {
3257     Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3258     aParams->ToReverseStereo = reverse;
3259   }
3260 }
3261
3262 bool OCCViewer_ViewWindow::isReverseStereo() const
3263 {
3264   int reverse = false;
3265   Handle(V3d_View) aView3d = myViewPort->getView();
3266   if ( !aView3d.IsNull() ) {
3267     Graphic3d_RenderingParams* aParams = &aView3d->ChangeRenderingParams();
3268     reverse = aParams->ToReverseStereo;
3269   }
3270   return reverse;
3271 }
3272
3273 void OCCViewer_ViewWindow::setVSync( bool enable )
3274 {
3275   Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3276   if ( !anIntCont.IsNull() ) {
3277     Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3278     OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3279     aCaps->swapInterval = enable;
3280   }
3281 }
3282
3283 bool OCCViewer_ViewWindow::isVSync() const
3284 {
3285   int enable = true;
3286   Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3287   if ( !anIntCont.IsNull() ) {
3288     Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3289     OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3290     enable = aCaps->swapInterval;
3291   }
3292   return enable;
3293 }
3294
3295 void OCCViewer_ViewWindow::setQuadBufferSupport( bool enable )
3296 {
3297   Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3298   if ( !anIntCont.IsNull() ) {
3299     Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3300     OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3301     aCaps->contextStereo = enable;
3302   }
3303 }
3304
3305 bool OCCViewer_ViewWindow::isQuadBufferSupport() const
3306 {
3307   int enable = true;
3308   Handle(AIS_InteractiveContext) anIntCont = myModel->getAISContext();
3309   if ( !anIntCont.IsNull() ) {
3310     Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(anIntCont->CurrentViewer()->Driver());
3311     OpenGl_Caps* aCaps = &aDriver->ChangeOptions();
3312     enable = aCaps->contextStereo;
3313   }
3314   return enable;
3315 }
3316
3317
3318 bool OCCViewer_ViewWindow::isOpenGlStereoSupport() const
3319 {
3320   GLboolean support[1];
3321   glGetBooleanv (GL_STEREO, support);
3322   if ( support[0] )
3323     return true;
3324   return false;
3325 }
3326
3327 // obsolete
3328 QColor OCCViewer_ViewWindow::backgroundColor() const
3329 {
3330   return myViewPort ? myViewPort->backgroundColor() : Qt::black;
3331 }
3332
3333 // obsolete
3334 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
3335 {
3336   if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
3337 }
3338
3339 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
3340 {
3341   return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
3342 }
3343
3344 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
3345 {
3346   if ( myViewPort ) myViewPort->setBackground( theBackground );
3347 }
3348
3349 void OCCViewer_ViewWindow::showStaticTrihedron( bool on )
3350 {
3351   if ( myViewPort ) myViewPort->showStaticTrihedron( on );
3352 }
3353
3354 /*!
3355   Clears view aspects
3356 */
3357 void OCCViewer_ViewWindow::clearViewAspects()
3358 {
3359   myViewAspects.clear();
3360 }
3361
3362 /*!
3363   \return const reference to list of view aspects
3364 */
3365 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
3366 {
3367   return myViewAspects;
3368 }
3369
3370 /*!
3371   Appends new view aspect
3372   \param aParams - new view aspects
3373 */
3374 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
3375 {
3376   myViewAspects.append( aParams );
3377 }
3378
3379 /*!
3380   Replaces old view aspects by new ones
3381   \param aViewList - list of new view aspects
3382 */
3383 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
3384 {
3385   myViewAspects = aViewList;
3386 }
3387
3388 /*!
3389   Get camera properties for the OCC view window.
3390   \return shared pointer on camera properties.
3391 */
3392 SUIT_CameraProperties OCCViewer_ViewWindow::cameraProperties()
3393 {
3394   SUIT_CameraProperties aProps;
3395
3396   Handle(V3d_View) aSourceView = getViewPort()->getView();
3397   if ( aSourceView.IsNull() )
3398     return aProps;
3399
3400   if ( get2dMode() == No2dMode ) {
3401     aProps.setDimension( SUIT_CameraProperties::Dim3D );
3402   }
3403   else {
3404     aProps.setDimension( SUIT_CameraProperties::Dim2D );
3405     aProps.setViewSide( (SUIT_CameraProperties::ViewSide)(int)get2dMode() );
3406   }
3407
3408   // read common properites of the view
3409   Standard_Real anUp[3];
3410   Standard_Real anAt[3];
3411   Standard_Real anEye[3];
3412   Standard_Real aProj[3];
3413   Standard_Real anAxialScale[3];
3414
3415   aSourceView->Up( anUp[0], anUp[1], anUp[2] );
3416   aSourceView->At( anAt[0], anAt[1], anAt[2] );
3417   aSourceView->Proj( aProj[0], aProj[1], aProj[2] );
3418   getViewPort()->getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3419
3420   aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3421   aProps.setViewUp( anUp[0], anUp[1], anUp[2] );
3422
3423   aSourceView->Eye( anEye[0], anEye[1], anEye[2] );
3424
3425   // store camera properties "as is": it is up to synchronized
3426   // view classes to provide necessary property conversion.
3427   aProps.setPosition( anEye[0], anEye[1], anEye[2] );
3428   aProps.setFocalPoint( anAt[0], anAt[1], anAt[2] );
3429
3430   if ( aSourceView->Camera()->IsOrthographic() )
3431   {
3432     aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
3433     aProps.setViewAngle( 0.0 );
3434   }
3435   else
3436   {
3437     aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
3438     aProps.setViewAngle( aSourceView->Camera()->FOVy() );
3439   }
3440   aProps.setMappingScale( aSourceView->Camera()->Scale() );
3441
3442   return aProps;
3443 }
3444
3445 /*!
3446   Synchronize views.
3447   This implementation synchronizes OCC view's camera propreties.
3448 */
3449 void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
3450 {
3451   bool blocked = blockSignals( true );
3452
3453   SUIT_CameraProperties aProps = theView->cameraProperties();
3454   if ( !cameraProperties().isCompatible( aProps ) ) {
3455     // other view, this one is being currently synchronized to, seems has become incompatible
3456     // we have to break synchronization
3457     updateSyncViews();
3458     return;
3459   }
3460
3461   Handle(V3d_View) aDestView = getViewPort()->getView();
3462
3463   aDestView->SetImmediateUpdate( Standard_False );
3464
3465   double anUpDir[3];
3466   double aPosition[3];
3467   double aFocalPoint[3];
3468   double anAxialScale[3];
3469
3470   // get common properties
3471   aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3472   aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
3473   aProps.getViewUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3474   aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3475
3476   aDestView->SetAt( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
3477   aDestView->SetEye( aPosition[0], aPosition[1], aPosition[2] );
3478   aDestView->SetUp( anUpDir[0], anUpDir[1], anUpDir[2] );
3479   aDestView->Camera()->SetScale( aProps.getMappingScale() );
3480
3481   getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
3482   aDestView->SetImmediateUpdate( Standard_True );
3483   aDestView->Redraw();
3484
3485   blockSignals( blocked );
3486 }
3487
3488 /*!
3489   \brief Indicates whether preselection is enabled
3490   \return true if preselection is enabled
3491 */
3492 bool OCCViewer_ViewWindow::isPreselectionEnabled() const
3493 {
3494   return myPreselectionEnabled;
3495 }
3496
3497 /*!
3498   \brief Enables/disables preselection
3499   \param theIsToEnable if true - preselection will be enabled
3500 */
3501 void OCCViewer_ViewWindow::enablePreselection( bool theIsToEnable )
3502 {
3503   onSwitchPreselection( theIsToEnable );
3504 }
3505
3506 /*!
3507   \brief Indicates whether selection is enabled
3508   \return true if selection is enabled
3509 */
3510 bool OCCViewer_ViewWindow::isSelectionEnabled() const
3511 {
3512   return mySelectionEnabled;
3513 }
3514
3515 /*!
3516   \brief Enables/disables selection
3517   \param theIsToEnable if true - selection will be enabled
3518 */
3519 void OCCViewer_ViewWindow::enableSelection( bool theIsToEnable )
3520 {
3521   onSwitchSelection( theIsToEnable );
3522 }
3523
3524
3525 /*!
3526   \brief called if clipping operation is activated / deactivated.
3527
3528   Enables/disables clipping plane displaying.
3529
3530   \parma on action state
3531 */
3532 void OCCViewer_ViewWindow::onClipping (bool theIsOn)
3533 {
3534   if(!myModel) return;
3535   OCCViewer_ClippingDlg* aClippingDlg = myModel->getClippingDlg();
3536
3537   if (theIsOn) {
3538     if (!aClippingDlg) {
3539       aClippingDlg = new OCCViewer_ClippingDlg (this, myModel);
3540       myModel->setClippingDlg(aClippingDlg);
3541     }
3542     if (!aClippingDlg->isVisible())
3543       aClippingDlg->show();
3544   } else {
3545     if ( aClippingDlg ) {
3546       aClippingDlg->close();
3547       myModel->setClippingDlg(0);
3548     }
3549   }
3550
3551   SUIT_ViewManager* mgr = getViewManager();
3552   if( mgr ) {
3553     QVector<SUIT_ViewWindow*> aViews = mgr->getViews();
3554     for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
3555       if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
3556         QtxActionToolMgr* mgr = aViewWindow->toolMgr();
3557         if(!mgr) continue;
3558         QAction* a = toolMgr()->action( ClippingId );
3559         if(!a) continue;
3560         if(theIsOn != a->isChecked()){
3561           disconnect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3562           a->setChecked(theIsOn);
3563           connect (a, SIGNAL (toggled (bool)), aViewWindow, SLOT (onClipping (bool)));
3564         }
3565       }
3566     }
3567   }
3568 }
3569
3570 void OCCViewer_ViewWindow::onRayTracing()
3571 {
3572   if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_RayTracingDlg::getName() ) ) {
3573     QDialog* aDlg = new OCCViewer_RayTracingDlg( this );
3574     if ( aDlg != NULL )
3575       aDlg->show();
3576   }
3577 }
3578
3579 void OCCViewer_ViewWindow::onEnvTexture()
3580 {
3581   if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_EnvTextureDlg::getName() ) ) {
3582     QDialog* aDlg = new OCCViewer_EnvTextureDlg( this );
3583     if ( aDlg != NULL )
3584       aDlg->show();
3585   }
3586 }
3587
3588 void OCCViewer_ViewWindow::onLightSource()
3589 {
3590   if( !OCCViewer_Utilities::isDialogOpened( this, OCCViewer_LightSourceDlg::getName() ) ) {
3591     QDialog* aDlg = new OCCViewer_LightSourceDlg( this, myModel );
3592     if ( aDlg != NULL )
3593       aDlg->show();
3594   }
3595 }