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