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