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