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