Salome HOME
Miltiple updates of viewer in onResetView()
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewWindow.cxx
1 // OCCViewer_ViewWindow.cxx: implementation of the OCCViewer_ViewWindow class.
2 //
3 //////////////////////////////////////////////////////////////////////
4
5 #include "OCCViewer_ViewWindow.h"
6 #include "OCCViewer_ViewModel.h"
7 #include "OCCViewer_ViewPort3d.h"
8 #include "OCCViewer_CreateRestoreViewDlg.h"
9
10 #include "SUIT_Desktop.h"
11 #include "SUIT_Session.h"
12 #include "SUIT_ToolButton.h"
13
14 #include "SUIT_Tools.h"
15 #include "SUIT_ResourceMgr.h"
16 #include "SUIT_MessageBox.h"
17
18 #include <qptrlist.h>
19 #include <qhbox.h>
20 #include <qlabel.h>
21 #include <qcolor.h>
22 #include <qpainter.h>
23 #include <qapplication.h>
24 #include <qdatetime.h>
25
26 const char* imageZoomCursor[] = { 
27 "32 32 3 1",
28 ". c None",
29 "a c #000000",
30 "# c #ffffff",
31 "................................",
32 "................................",
33 ".#######........................",
34 "..aaaaaaa.......................",
35 "................................",
36 ".............#####..............",
37 "...........##.aaaa##............",
38 "..........#.aa.....a#...........",
39 ".........#.a.........#..........",
40 ".........#a..........#a.........",
41 "........#.a...........#.........",
42 "........#a............#a........",
43 "........#a............#a........",
44 "........#a............#a........",
45 "........#a............#a........",
46 ".........#...........#.a........",
47 ".........#a..........#a.........",
48 ".........##.........#.a.........",
49 "........#####.....##.a..........",
50 ".......###aaa#####.aa...........",
51 "......###aa...aaaaa.......#.....",
52 ".....###aa................#a....",
53 "....###aa.................#a....",
54 "...###aa...............#######..",
55 "....#aa.................aa#aaaa.",
56 ".....a....................#a....",
57 "..........................#a....",
58 "...........................a....",
59 "................................",
60 "................................",
61 "................................",
62 "................................"};
63
64 const char* imageRotateCursor[] = { 
65 "32 32 3 1",
66 ". c None",
67 "a c #000000",
68 "# c #ffffff",
69 "................................",
70 "................................",
71 "................................",
72 "................................",
73 "........#.......................",
74 ".......#.a......................",
75 "......#######...................",
76 ".......#aaaaa#####..............",
77 "........#..##.a#aa##........##..",
78 ".........a#.aa..#..a#.....##.aa.",
79 ".........#.a.....#...#..##.aa...",
80 ".........#a.......#..###.aa.....",
81 "........#.a.......#a..#aa.......",
82 "........#a.........#..#a........",
83 "........#a.........#a.#a........",
84 "........#a.........#a.#a........",
85 "........#a.........#a.#a........",
86 ".........#.........#a#.a........",
87 "........##a........#a#a.........",
88 "......##.a#.......#.#.a.........",
89 "....##.aa..##.....##.a..........",
90 "..##.aa.....a#####.aa...........",
91 "...aa.........aaa#a.............",
92 "................#.a.............",
93 "...............#.a..............",
94 "..............#.a...............",
95 "...............a................",
96 "................................",
97 "................................",
98 "................................",
99 "................................",
100 "................................"};
101
102 const char* imageCrossCursor[] = { 
103   "32 32 3 1",
104   ". c None",
105   "a c #000000",
106   "# c #ffffff",
107   "................................",
108   "................................",
109   "................................",
110   "................................",
111   "................................",
112   "................................",
113   "................................",
114   "...............#................",
115   "...............#a...............",
116   "...............#a...............",
117   "...............#a...............",
118   "...............#a...............",
119   "...............#a...............",
120   "...............#a...............",
121   "...............#a...............",
122   ".......#################........",
123   "........aaaaaaa#aaaaaaaaa.......",
124   "...............#a...............",
125   "...............#a...............",
126   "...............#a...............",
127   "...............#a...............",
128   "...............#a...............",
129   "...............#a...............",
130   "...............#a...............",
131   "................a...............",
132   "................................",
133   "................................",
134   "................................",
135   "................................",
136   "................................",
137   "................................",
138   "................................"};
139   
140
141 QPixmap zoomPixmap(imageZoomCursor);
142 QPixmap rotatePixmap(imageRotateCursor);
143 QPixmap globalPanPixmap(imageCrossCursor);
144
145 QCursor defCursor(Qt::ArrowCursor);
146 QCursor handCursor(Qt::PointingHandCursor);
147 QCursor panCursor(Qt::SizeAllCursor);
148 QCursor zoomCursor(zoomPixmap);
149 QCursor rotCursor(rotatePixmap);
150 QCursor glPanCursor(globalPanPixmap);
151
152
153
154 //////////////////////////////////////////////////////////////////////
155 // Construction/Destruction
156 //////////////////////////////////////////////////////////////////////
157
158 OCCViewer_ViewWindow::OCCViewer_ViewWindow(SUIT_Desktop* theDesktop, OCCViewer_Viewer* theModel)
159 : SUIT_ViewWindow(theDesktop)
160 {
161   myModel = theModel;
162   myEnableDrawMode = true;
163   myRestoreFlag = 0;
164 }
165
166 //****************************************************************
167 void OCCViewer_ViewWindow::initLayout()
168 {
169   myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
170   myViewPort->setBackgroundColor(black);
171   myViewPort->installEventFilter(this);
172         setCentralWidget(myViewPort);
173   myOperation = NOTHING;
174
175   setTransformRequested ( NOTHING );
176   setTransformInProcess ( false );
177
178   myToolBar = new QToolBar(this);
179   myToolBar->setCloseMode(QDockWindow::Undocked);
180   myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
181
182   createActions();
183   createToolBar();
184 }
185
186 //****************************************************************
187 OCCViewer_ViewWindow::OperationType OCCViewer_ViewWindow::getButtonState(QMouseEvent* theEvent)
188 {
189   OperationType aOp = NOTHING;
190   if( (theEvent->state() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::ZOOM]) &&
191       (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::ZOOM]) )
192     aOp = ZOOMVIEW;
193   else if( (theEvent->state() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::PAN]) && 
194            (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::PAN]) )
195     aOp = PANVIEW;
196   else if( (theEvent->state()  == SUIT_ViewModel::myStateMap[SUIT_ViewModel::ROTATE]) &&
197            (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::ROTATE]) )
198     aOp = ROTATE;
199
200   return aOp;
201 }
202
203 //****************************************************************
204 bool OCCViewer_ViewWindow::eventFilter(QObject* watched, QEvent* e)
205 {
206   if ( watched == myViewPort ) {
207     int aType = e->type();
208     switch(aType) {
209     case QEvent::MouseButtonPress:
210       vpMousePressEvent((QMouseEvent*) e);
211       return true;
212
213     case QEvent::MouseButtonRelease:
214       vpMouseReleaseEvent((QMouseEvent*) e);
215       return true;
216
217     case QEvent::MouseMove:
218       vpMouseMoveEvent((QMouseEvent*) e);
219       return true;
220
221     case QEvent::MouseButtonDblClick:
222       emit mouseDoubleClicked(this, (QMouseEvent*)e);
223       return true;
224
225     case QEvent::Wheel:
226       {
227         QWheelEvent* aEvent = (QWheelEvent*) e;
228         double aDelta = aEvent->delta();
229         double aScale = (aDelta < 0) ? 100./(-aDelta) : aDelta/100.; 
230         myViewPort->getView()->SetZoom(aScale);
231       }
232       return true;
233
234     case QEvent::ContextMenu:
235       {
236         QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
237         if ( aEvent->reason() != QContextMenuEvent::Mouse )
238           emit contextMenuRequested( aEvent );
239       }
240       return true;
241
242     default:
243       break;
244     }
245   }
246   return SUIT_ViewWindow::eventFilter(watched, e);
247 }
248
249
250 //****************************************************************
251 void OCCViewer_ViewWindow::vpMousePressEvent(QMouseEvent* theEvent)
252 {
253   myStartX = theEvent->x();
254   myStartY = theEvent->y();
255   switch ( myOperation ) {
256   case WINDOWFIT:
257     if ( theEvent->button() == Qt::LeftButton )
258       emit vpTransformationStarted ( WINDOWFIT );
259     break;    
260    
261   case PANGLOBAL:
262     if ( theEvent->button() == Qt::LeftButton )
263       emit vpTransformationStarted ( PANGLOBAL );
264     break;    
265     
266   case ZOOMVIEW:
267     if ( theEvent->button() == Qt::LeftButton )
268       emit vpTransformationStarted ( ZOOMVIEW );
269     break;
270     
271   case PANVIEW:
272     if ( theEvent->button() == Qt::LeftButton )
273       emit vpTransformationStarted ( PANVIEW );
274     break;
275
276   case ROTATE:
277     if ( theEvent->button() == Qt::LeftButton ) {
278             myViewPort->startRotation(myStartX, myStartY);
279             emit vpTransformationStarted ( ROTATE );
280           }
281     break;
282       
283   default:
284   /*  Try to activate a transformation */
285     switch ( getButtonState(theEvent) ) {
286     case ZOOMVIEW:
287             activateZoom();
288       break;
289     case PANVIEW:
290             activatePanning();
291       break;
292     case ROTATE:
293             activateRotation();
294             myViewPort->startRotation(myStartX, myStartY);
295       break;
296     default:
297       emit mousePressed(this, theEvent);
298       break;
299     }
300     /* notify that we start a transformation */
301     if ( transformRequested() ) 
302             emit vpTransformationStarted ( myOperation );
303   }
304   if ( transformRequested() ) 
305     setTransformInProcess( true );               
306 }
307
308
309 //****************************************************************
310 void OCCViewer_ViewWindow::activateZoom()
311 {
312   if ( !transformRequested() && !myCursorIsHand )
313     myCursor = cursor();                /* save old cursor */
314   
315   if ( myOperation != ZOOMVIEW ) {
316     setTransformRequested ( ZOOMVIEW );         
317     setCursor( zoomCursor );
318   }
319 }
320
321
322 //****************************************************************
323 /*!
324     Activates 'panning' transformation
325 */
326 void OCCViewer_ViewWindow::activatePanning()
327 {
328   if ( !transformRequested() && !myCursorIsHand )
329     myCursor = cursor();                // save old cursor 
330   
331   if ( myOperation != PANVIEW ) {
332     setTransformRequested ( PANVIEW );
333     setCursor( panCursor );
334   }
335 }
336
337 //****************************************************************
338 /*!
339     Activates 'rotation' transformation
340 */
341 void OCCViewer_ViewWindow::activateRotation()
342 {
343   if ( !transformRequested() && !myCursorIsHand )
344     myCursor = cursor();                // save old cursor 
345   
346   if ( myOperation != ROTATE ) {
347     setTransformRequested ( ROTATE );
348     setCursor( rotCursor );     
349   }
350 }
351
352 //****************************************************************
353 void OCCViewer_ViewWindow::activateGlobalPanning()
354 {
355   Handle(V3d_View) aView3d = myViewPort->getView();
356   if ( !aView3d.IsNull() ) {
357     myCurScale = aView3d->Scale();
358     aView3d->FitAll(0.01, false);
359     myCursor = cursor();                // save old cursor 
360     myViewPort->fitAll(); // fits view before selecting a new scene center 
361     setTransformRequested( PANGLOBAL );
362     setCursor( glPanCursor );
363   }
364 }
365
366 //****************************************************************
367 /*!
368     Activates 'fit' transformation
369 */
370 void OCCViewer_ViewWindow::activateWindowFit()
371 {
372   if ( !transformRequested() && !myCursorIsHand )
373     myCursor = cursor();                /* save old cursor */
374
375   if ( myOperation != WINDOWFIT ) {
376     setTransformRequested ( WINDOWFIT );                
377     setCursor ( handCursor );
378     myCursorIsHand = true;
379   }
380 }
381
382 //****************************************************************
383 /*!
384     Sets the active operation 'op'
385 */
386 void OCCViewer_ViewWindow::setTransformRequested ( OperationType op )
387 {    
388   myOperation = op;
389   myViewPort->setMouseTracking( myOperation == NOTHING );  
390 }
391
392
393 //****************************************************************/
394 void OCCViewer_ViewWindow::vpMouseMoveEvent(QMouseEvent* theEvent)
395 {
396   myCurrX = theEvent->x();
397   myCurrY = theEvent->y();
398   switch (myOperation) {
399   case ROTATE:
400     myViewPort->rotate(myCurrX, myCurrY);
401     break;
402     
403   case ZOOMVIEW:
404     myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
405     myStartX = myCurrX;
406     myStartY = myCurrY;
407     break;
408     
409   case PANVIEW:
410     myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
411     myStartX = myCurrX;
412     myStartY = myCurrY;
413     break;
414     
415 /*    case WINDOWFIT:
416     myDrawRect = true;
417     repaint();
418     break;
419 */      
420   case PANGLOBAL:
421     break;
422     
423   default:
424     int aState = theEvent->state();
425     //int aButton = theEvent->button();
426     if ( aState == Qt::LeftButton ||
427         aState == ( Qt::LeftButton | Qt::ShiftButton) ) {
428       myDrawRect = myEnableDrawMode;
429       if ( myDrawRect ) {
430         drawRect();
431         if ( !myCursorIsHand )  {   // we are going to sketch a rectangle
432           myCursorIsHand = true;                
433           myCursor = cursor();
434           setCursor( handCursor );
435         }
436       }
437     } 
438     else {
439       emit mouseMoving( this, theEvent ); 
440     }           
441   }
442 }
443
444 //****************************************************************/
445 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
446 {
447   switch ( myOperation ) {
448   case NOTHING:
449     {
450       emit mouseReleased(this, theEvent);
451       if(theEvent->button() == RightButton)
452       {
453         QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
454                                   theEvent->pos(), theEvent->globalPos(),
455                                   theEvent->state() );
456         emit contextMenuRequested( &aEvent );
457         break;
458       }
459     }
460   case ROTATE:
461     myViewPort->endRotation();
462     resetState();
463     break;
464     
465   case PANVIEW:
466   case ZOOMVIEW:
467     resetState();
468     break;
469     
470   case PANGLOBAL:
471     if ( theEvent->button() == Qt::LeftButton ) {
472             myViewPort->setCenter( theEvent->x(), theEvent->y() );
473       myViewPort->getView()->SetScale(myCurScale);
474             resetState();
475           }
476     break;
477       
478   case WINDOWFIT:
479     if ( theEvent->state() == Qt::LeftButton ) {
480             myCurrX = theEvent->x();
481             myCurrY = theEvent->y();
482             QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
483             if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
484             resetState();
485           }
486     break;
487   }
488   
489   // NOTE: viewer 3D detects a rectangle of selection using this event
490   // so we must emit it BEFORE resetting the selection rectangle
491   
492   if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
493     myDrawRect = false;
494     drawRect();
495     resetState(); 
496     myViewPort->update();
497   }
498 }
499
500 //****************************************************************
501 /*!
502     Sets the viewport to its initial state
503     ( no transformations in process etc. )
504 */
505 void OCCViewer_ViewWindow::resetState()
506 {
507   myDrawRect = false;
508   
509   /* make rectangle empty (left > right) */
510   myRect.setLeft(2);
511   myRect.setRight(0);
512   
513   if ( transformRequested() || myCursorIsHand ) 
514     setCursor( myCursor );
515   myCursorIsHand = false;
516   
517   if ( transformRequested() ) 
518     emit vpTransformationFinished (myOperation);
519   
520   setTransformInProcess( false );               
521   setTransformRequested( NOTHING );     
522 }
523
524
525 //****************************************************************/
526 void OCCViewer_ViewWindow::drawRect()
527 {
528   QPainter aPainter(myViewPort);
529   aPainter.setRasterOp(Qt::XorROP);
530   aPainter.setPen(Qt::white);
531   QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
532   if ( !myRect.isEmpty() )
533           aPainter.drawRect( myRect );
534   aPainter.drawRect(aRect);
535   myRect = aRect;
536 }
537
538 //****************************************************************/
539 void OCCViewer_ViewWindow::createActions()
540 {
541   if (!myActionsMap.isEmpty()) return;
542   
543   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
544   
545   QtxAction* aAction;
546
547   // Dump view
548   aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
549                            tr( "MNU_DUMP_VIEW" ), 0, this);
550   aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
551   connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView()));
552         myActionsMap[ DumpId ] = aAction;
553
554   // FitAll
555   aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
556                            tr( "MNU_FITALL" ), 0, this);
557   aAction->setStatusTip(tr("DSC_FITALL"));
558   connect(aAction, SIGNAL(activated()), this, SLOT(onFitAll()));
559         myActionsMap[ FitAllId ] = aAction;
560
561   // FitRect
562   aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
563                            tr( "MNU_FITRECT" ), 0, this);
564   aAction->setStatusTip(tr("DSC_FITRECT"));
565   connect(aAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
566         myActionsMap[ FitRectId ] = aAction;
567
568   // Zoom
569   aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
570                            tr( "MNU_ZOOM_VIEW" ), 0, this);
571   aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
572   connect(aAction, SIGNAL(activated()), this, SLOT(activateZoom()));
573         myActionsMap[ ZoomId ] = aAction;
574
575   // Panning
576   aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
577                            tr( "MNU_PAN_VIEW" ), 0, this);
578   aAction->setStatusTip(tr("DSC_PAN_VIEW"));
579   connect(aAction, SIGNAL(activated()), this, SLOT(activatePanning()));
580         myActionsMap[ PanId ] = aAction;
581
582   // Global Panning
583   aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
584                            tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
585   aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
586   connect(aAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
587         myActionsMap[ GlobalPanId ] = aAction;
588
589   // Rotation
590   aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
591                            tr( "MNU_ROTATE_VIEW" ), 0, this);
592   aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
593   connect(aAction, SIGNAL(activated()), this, SLOT(activateRotation()));
594         myActionsMap[ RotationId ] = aAction;
595
596   // Projections
597   aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
598                            tr( "MNU_FRONT_VIEW" ), 0, this);
599   aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
600   connect(aAction, SIGNAL(activated()), this, SLOT(onFrontView()));
601         myActionsMap[ FrontId ] = aAction;
602
603   aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
604                            tr( "MNU_BACK_VIEW" ), 0, this);
605   aAction->setStatusTip(tr("DSC_BACK_VIEW"));
606   connect(aAction, SIGNAL(activated()), this, SLOT(onBackView()));
607         myActionsMap[ BackId ] = aAction;
608
609   aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
610                            tr( "MNU_TOP_VIEW" ), 0, this);
611   aAction->setStatusTip(tr("DSC_TOP_VIEW"));
612   connect(aAction, SIGNAL(activated()), this, SLOT(onTopView()));
613         myActionsMap[ TopId ] = aAction;
614
615   aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
616                            tr( "MNU_BOTTOM_VIEW" ), 0, this);
617   aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
618   connect(aAction, SIGNAL(activated()), this, SLOT(onBottomView()));
619         myActionsMap[ BottomId ] = aAction;
620
621   aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
622                            tr( "MNU_LEFT_VIEW" ), 0, this);
623   aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
624   connect(aAction, SIGNAL(activated()), this, SLOT(onLeftView()));
625         myActionsMap[ LeftId ] = aAction;
626
627   aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
628                            tr( "MNU_RIGHT_VIEW" ), 0, this);
629   aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
630   connect(aAction, SIGNAL(activated()), this, SLOT(onRightView()));
631         myActionsMap[ RightId ] = aAction;
632
633   // Reset
634   aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
635                            tr( "MNU_RESET_VIEW" ), 0, this);
636   aAction->setStatusTip(tr("DSC_RESET_VIEW"));
637   connect(aAction, SIGNAL(activated()), this, SLOT(onResetView()));
638         myActionsMap[ ResetId ] = aAction;
639
640   // Reset
641   aAction = new QtxAction(tr("MNU_CLONE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CLONE_VIEW" ) ),
642                            tr( "MNU_CLONE_VIEW" ), 0, this);
643   aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
644   connect(aAction, SIGNAL(activated()), this, SLOT(onCloneView()));
645         myActionsMap[ CloneId ] = aAction;
646
647   aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
648                            tr( "MNU_SHOOT_VIEW" ), 0, this);
649   aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
650   connect(aAction, SIGNAL(activated()), this, SLOT(onMemorizeView()));
651         myActionsMap[ MemId ] = aAction;
652
653   aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
654                            tr( "MNU_PRESETS_VIEW" ), 0, this);
655   aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
656   connect(aAction, SIGNAL(activated()), this, SLOT(onRestoreView()));
657         myActionsMap[ RestoreId ] = aAction;
658
659   if (myModel->trihedronActivated()) {
660     aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
661                              tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
662     aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
663     connect(aAction, SIGNAL(activated()), this, SLOT(onTrihedronShow()));
664           myActionsMap[ TrihedronShowId ] = aAction;
665   }
666 }
667
668 //****************************************************************
669 void OCCViewer_ViewWindow::createToolBar()
670 {
671   myActionsMap[DumpId]->addTo(myToolBar);  
672   if ( myModel->trihedronActivated() ) 
673     myActionsMap[TrihedronShowId]->addTo(myToolBar);
674
675   SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar, "scale");
676   aScaleBtn->AddAction(myActionsMap[FitAllId]);
677   aScaleBtn->AddAction(myActionsMap[FitRectId]);
678   aScaleBtn->AddAction(myActionsMap[ZoomId]);
679
680   SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar, "pan");
681   aPanningBtn->AddAction(myActionsMap[PanId]);
682   aPanningBtn->AddAction(myActionsMap[GlobalPanId]);
683
684   myActionsMap[RotationId]->addTo(myToolBar);
685
686   SUIT_ToolButton* aViewsBtn = new SUIT_ToolButton(myToolBar, "projection");
687   aViewsBtn->AddAction(myActionsMap[FrontId]);
688   aViewsBtn->AddAction(myActionsMap[BackId]);
689   aViewsBtn->AddAction(myActionsMap[TopId]);
690   aViewsBtn->AddAction(myActionsMap[BottomId]);
691   aViewsBtn->AddAction(myActionsMap[LeftId]);
692   aViewsBtn->AddAction(myActionsMap[RightId]);
693
694   myActionsMap[ResetId]->addTo(myToolBar);
695
696   SUIT_ToolButton* aMemBtn = new SUIT_ToolButton(myToolBar, "view");
697   aMemBtn->AddAction(myActionsMap[MemId]);
698   aMemBtn->AddAction(myActionsMap[RestoreId]);
699
700   myToolBar->addSeparator();
701   myActionsMap[CloneId]->addTo(myToolBar);
702 }
703
704 //****************************************************************
705 void OCCViewer_ViewWindow::onViewFitAll()
706 {
707   myViewPort->fitAll();
708 }
709
710 //****************************************************************
711 void OCCViewer_ViewWindow::onFrontView()
712 {
713   emit vpTransformationStarted ( FRONTVIEW );
714   Handle(V3d_View) aView3d = myViewPort->getView();
715   if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
716   onViewFitAll();
717 }
718
719 //****************************************************************
720 void OCCViewer_ViewWindow::onBackView()
721 {
722   emit vpTransformationStarted ( BACKVIEW );
723   Handle(V3d_View) aView3d = myViewPort->getView();
724   if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
725   onViewFitAll();
726 }
727
728 //****************************************************************
729 void OCCViewer_ViewWindow::onTopView()
730 {
731   emit vpTransformationStarted ( TOPVIEW );
732   Handle(V3d_View) aView3d = myViewPort->getView();
733   if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
734   onViewFitAll();
735 }
736
737 //****************************************************************
738 void OCCViewer_ViewWindow::onBottomView()
739 {
740   emit vpTransformationStarted ( BOTTOMVIEW );
741   Handle(V3d_View) aView3d = myViewPort->getView();
742   if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
743   onViewFitAll();
744 }
745
746 //****************************************************************
747 void OCCViewer_ViewWindow::onLeftView()
748 {
749   emit vpTransformationStarted ( LEFTVIEW );
750   Handle(V3d_View) aView3d = myViewPort->getView();
751   if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
752   onViewFitAll();
753 }
754
755 //****************************************************************
756 void OCCViewer_ViewWindow::onRightView()
757 {
758   emit vpTransformationStarted ( RIGHTVIEW );
759   Handle(V3d_View) aView3d = myViewPort->getView();
760   if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
761   onViewFitAll();
762 }
763
764 //****************************************************************
765 void OCCViewer_ViewWindow::onResetView()
766 {
767   emit vpTransformationStarted( RESETVIEW );
768   bool upd = myViewPort->getView()->SetImmediateUpdate( false );
769   myViewPort->getView()->Reset( false );
770   myViewPort->fitAll( false, true, false );
771   myViewPort->getView()->SetImmediateUpdate( upd );
772   myViewPort->getView()->Update();
773 }
774
775 //****************************************************************
776 void OCCViewer_ViewWindow::onFitAll()
777 {
778   emit vpTransformationStarted( FITALLVIEW );
779   myViewPort->fitAll();
780 }
781
782 //****************************************************************
783 void OCCViewer_ViewWindow::onCloneView()
784 {
785   SUIT_ViewWindow* vw = myManager->createViewWindow();
786   vw->show();
787 }
788
789 //****************************************************************
790 void OCCViewer_ViewWindow::onMemorizeView()
791 {
792   double centerX, centerY, projX, projY, projZ, twist;
793   double atX, atY, atZ, eyeX, eyeY, eyeZ;
794
795   Handle(V3d_View) aView3d = myViewPort->getView();
796
797   aView3d->Center( centerX, centerY );
798   aView3d->Proj( projX, projY, projZ );
799   aView3d->At( atX, atY, atZ );
800   aView3d->Eye( eyeX, eyeY, eyeZ );
801   twist = aView3d->Twist();
802
803   viewAspect params;
804   QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
805
806   params.scale    = aView3d->Scale();
807   params.centerX  = centerX;
808   params.centerY  = centerY;
809   params.projX    = projX;
810   params.projY    = projY;
811   params.projZ    = projZ;
812   params.twist    = twist;
813   params.atX      = atX;
814   params.atY      = atY;
815   params.atZ      = atZ;
816   params.eyeX     = eyeX;
817   params.eyeY     = eyeY;
818   params.eyeZ     = eyeZ;
819   params.name     = aName;
820
821   myModel->appendViewAspect( params );
822
823 }
824
825 //****************************************************************
826 void OCCViewer_ViewWindow::onRestoreView()
827 {
828         OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), myModel );
829         connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
830         aDlg->exec();
831         myModel->updateViewAspects( aDlg->parameters() );
832         if( myRestoreFlag && aDlg->parameters().count() )
833                 performRestoring( aDlg->currentItem() );
834 }
835
836 //****************************************************************
837
838 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem )
839 {
840         Handle(V3d_View) aView3d = myViewPort->getView();
841
842         Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
843         aView3d->SetScale( anItem.scale );
844         aView3d->SetCenter( anItem.centerX, anItem.centerY );
845         aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
846         aView3d->SetTwist( anItem.twist );
847         aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
848         aView3d->SetImmediateUpdate( prev );
849         aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
850                 
851         myRestoreFlag = 0;
852 }
853
854 void OCCViewer_ViewWindow::setRestoreFlag()
855 {
856         myRestoreFlag = 1;
857 }
858
859 //****************************************************************
860 void OCCViewer_ViewWindow::onTrihedronShow()
861 {
862   myModel->toggleTrihedron();
863 }
864
865 //****************************************************************
866 QImage OCCViewer_ViewWindow::dumpView()
867 {
868   QPixmap px = QPixmap::grabWindow( myViewPort->winId() );
869   return px.convertToImage();
870 }