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