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