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