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