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