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