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