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