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