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