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