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