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