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