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