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