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