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