1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
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.
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.
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
17 // See http://www.salome-platform.org/
19 // OCCViewer_ViewWindow.cxx: implementation of the OCCViewer_ViewWindow class.
21 //////////////////////////////////////////////////////////////////////
23 #include "OCCViewer_ViewWindow.h"
24 #include "OCCViewer_ViewModel.h"
25 #include "OCCViewer_ViewPort3d.h"
26 #include "OCCViewer_CreateRestoreViewDlg.h"
28 #include "SUIT_Desktop.h"
29 #include "SUIT_Session.h"
30 #include "SUIT_ToolButton.h"
32 #include "SUIT_Tools.h"
33 #include "SUIT_ResourceMgr.h"
34 #include "SUIT_MessageBox.h"
41 #include <qapplication.h>
42 #include <qdatetime.h>
44 const char* imageZoomCursor[] = {
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 "................................"};
82 const char* imageRotateCursor[] = {
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 "................................"};
120 const char* imageCrossCursor[] = {
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 "................................"};
159 QPixmap zoomPixmap(imageZoomCursor);
160 QPixmap rotatePixmap(imageRotateCursor);
161 QPixmap globalPanPixmap(imageCrossCursor);
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);
172 //////////////////////////////////////////////////////////////////////
173 // Construction/Destruction
174 //////////////////////////////////////////////////////////////////////
176 OCCViewer_ViewWindow::OCCViewer_ViewWindow(SUIT_Desktop* theDesktop, OCCViewer_Viewer* theModel)
177 : SUIT_ViewWindow(theDesktop)
180 myEnableDrawMode = true;
184 //****************************************************************
185 void OCCViewer_ViewWindow::initLayout()
187 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
188 myViewPort->setBackgroundColor(black);
189 myViewPort->installEventFilter(this);
190 setCentralWidget(myViewPort);
191 myOperation = NOTHING;
193 setTransformRequested ( NOTHING );
194 setTransformInProcess ( false );
196 myToolBar = new QToolBar(this);
197 myToolBar->setCloseMode(QDockWindow::Undocked);
198 myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
204 //****************************************************************
205 OCCViewer_ViewWindow::OperationType OCCViewer_ViewWindow::getButtonState(QMouseEvent* theEvent)
207 OperationType aOp = NOTHING;
208 if( (theEvent->state() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::ZOOM]) &&
209 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::ZOOM]) )
211 else if( (theEvent->state() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::PAN]) &&
212 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::PAN]) )
214 else if( (theEvent->state() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::ROTATE]) &&
215 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::ROTATE]) )
221 //****************************************************************
222 bool OCCViewer_ViewWindow::eventFilter(QObject* watched, QEvent* e)
224 if ( watched == myViewPort ) {
225 int aType = e->type();
227 case QEvent::MouseButtonPress:
228 vpMousePressEvent((QMouseEvent*) e);
231 case QEvent::MouseButtonRelease:
232 vpMouseReleaseEvent((QMouseEvent*) e);
235 case QEvent::MouseMove:
236 vpMouseMoveEvent((QMouseEvent*) e);
239 case QEvent::MouseButtonDblClick:
240 emit mouseDoubleClicked(this, (QMouseEvent*)e);
245 QWheelEvent* aEvent = (QWheelEvent*) e;
246 double aDelta = aEvent->delta();
247 double aScale = (aDelta < 0) ? 100./(-aDelta) : aDelta/100.;
248 myViewPort->getView()->SetZoom(aScale);
252 case QEvent::ContextMenu:
254 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
255 if ( aEvent->reason() != QContextMenuEvent::Mouse )
256 emit contextMenuRequested( aEvent );
264 return SUIT_ViewWindow::eventFilter(watched, e);
268 //****************************************************************
269 void OCCViewer_ViewWindow::vpMousePressEvent(QMouseEvent* theEvent)
271 myStartX = theEvent->x();
272 myStartY = theEvent->y();
273 switch ( myOperation ) {
275 if ( theEvent->button() == Qt::LeftButton )
276 emit vpTransformationStarted ( WINDOWFIT );
280 if ( theEvent->button() == Qt::LeftButton )
281 emit vpTransformationStarted ( PANGLOBAL );
285 if ( theEvent->button() == Qt::LeftButton )
286 emit vpTransformationStarted ( ZOOMVIEW );
290 if ( theEvent->button() == Qt::LeftButton )
291 emit vpTransformationStarted ( PANVIEW );
295 if ( theEvent->button() == Qt::LeftButton ) {
296 myViewPort->startRotation(myStartX, myStartY);
297 emit vpTransformationStarted ( ROTATE );
302 /* Try to activate a transformation */
303 switch ( getButtonState(theEvent) ) {
312 myViewPort->startRotation(myStartX, myStartY);
315 emit mousePressed(this, theEvent);
318 /* notify that we start a transformation */
319 if ( transformRequested() )
320 emit vpTransformationStarted ( myOperation );
322 if ( transformRequested() )
323 setTransformInProcess( true );
327 //****************************************************************
328 void OCCViewer_ViewWindow::activateZoom()
330 if ( !transformRequested() && !myCursorIsHand )
331 myCursor = cursor(); /* save old cursor */
333 if ( myOperation != ZOOMVIEW ) {
334 setTransformRequested ( ZOOMVIEW );
335 setCursor( zoomCursor );
340 //****************************************************************
342 Activates 'panning' transformation
344 void OCCViewer_ViewWindow::activatePanning()
346 if ( !transformRequested() && !myCursorIsHand )
347 myCursor = cursor(); // save old cursor
349 if ( myOperation != PANVIEW ) {
350 setTransformRequested ( PANVIEW );
351 setCursor( panCursor );
355 //****************************************************************
357 Activates 'rotation' transformation
359 void OCCViewer_ViewWindow::activateRotation()
361 if ( !transformRequested() && !myCursorIsHand )
362 myCursor = cursor(); // save old cursor
364 if ( myOperation != ROTATE ) {
365 setTransformRequested ( ROTATE );
366 setCursor( rotCursor );
370 //****************************************************************
371 void OCCViewer_ViewWindow::activateGlobalPanning()
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 );
384 //****************************************************************
386 Activates 'fit' transformation
388 void OCCViewer_ViewWindow::activateWindowFit()
390 if ( !transformRequested() && !myCursorIsHand )
391 myCursor = cursor(); /* save old cursor */
393 if ( myOperation != WINDOWFIT ) {
394 setTransformRequested ( WINDOWFIT );
395 setCursor ( handCursor );
396 myCursorIsHand = true;
400 //****************************************************************
402 Sets the active operation 'op'
404 void OCCViewer_ViewWindow::setTransformRequested ( OperationType op )
407 myViewPort->setMouseTracking( myOperation == NOTHING );
411 //****************************************************************/
412 void OCCViewer_ViewWindow::vpMouseMoveEvent(QMouseEvent* theEvent)
414 myCurrX = theEvent->x();
415 myCurrY = theEvent->y();
416 switch (myOperation) {
418 myViewPort->rotate(myCurrX, myCurrY);
422 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
428 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
442 int aState = theEvent->state();
443 //int aButton = theEvent->button();
444 if ( aState == Qt::LeftButton ||
445 aState == ( Qt::LeftButton | Qt::ShiftButton) ) {
446 myDrawRect = myEnableDrawMode;
449 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
450 myCursorIsHand = true;
452 setCursor( handCursor );
457 emit mouseMoving( this, theEvent );
462 //****************************************************************/
463 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
465 switch ( myOperation ) {
468 emit mouseReleased(this, theEvent);
469 if(theEvent->button() == RightButton)
471 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
472 theEvent->pos(), theEvent->globalPos(),
474 emit contextMenuRequested( &aEvent );
479 myViewPort->endRotation();
489 if ( theEvent->button() == Qt::LeftButton ) {
490 myViewPort->setCenter( theEvent->x(), theEvent->y() );
491 myViewPort->getView()->SetScale(myCurScale);
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);
507 // NOTE: viewer 3D detects a rectangle of selection using this event
508 // so we must emit it BEFORE resetting the selection rectangle
510 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
514 myViewPort->update();
518 //****************************************************************
520 Sets the viewport to its initial state
521 ( no transformations in process etc. )
523 void OCCViewer_ViewWindow::resetState()
527 /* make rectangle empty (left > right) */
531 if ( transformRequested() || myCursorIsHand )
532 setCursor( myCursor );
533 myCursorIsHand = false;
535 if ( transformRequested() )
536 emit vpTransformationFinished (myOperation);
538 setTransformInProcess( false );
539 setTransformRequested( NOTHING );
543 //****************************************************************/
544 void OCCViewer_ViewWindow::drawRect()
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);
556 //****************************************************************/
557 void OCCViewer_ViewWindow::createActions()
559 if (!myActionsMap.isEmpty()) return;
561 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
686 //****************************************************************
687 void OCCViewer_ViewWindow::createToolBar()
689 myActionsMap[DumpId]->addTo(myToolBar);
690 if ( myModel->trihedronActivated() )
691 myActionsMap[TrihedronShowId]->addTo(myToolBar);
693 SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar, "scale");
694 aScaleBtn->AddAction(myActionsMap[FitAllId]);
695 aScaleBtn->AddAction(myActionsMap[FitRectId]);
696 aScaleBtn->AddAction(myActionsMap[ZoomId]);
698 SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar, "pan");
699 aPanningBtn->AddAction(myActionsMap[PanId]);
700 aPanningBtn->AddAction(myActionsMap[GlobalPanId]);
702 myActionsMap[RotationId]->addTo(myToolBar);
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]);
712 myActionsMap[ResetId]->addTo(myToolBar);
714 SUIT_ToolButton* aMemBtn = new SUIT_ToolButton(myToolBar, "view");
715 aMemBtn->AddAction(myActionsMap[MemId]);
716 aMemBtn->AddAction(myActionsMap[RestoreId]);
718 myToolBar->addSeparator();
719 myActionsMap[CloneId]->addTo(myToolBar);
722 //****************************************************************
723 void OCCViewer_ViewWindow::onViewFitAll()
725 myViewPort->fitAll();
728 //****************************************************************
729 void OCCViewer_ViewWindow::onFrontView()
731 emit vpTransformationStarted ( FRONTVIEW );
732 Handle(V3d_View) aView3d = myViewPort->getView();
733 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
737 //****************************************************************
738 void OCCViewer_ViewWindow::onBackView()
740 emit vpTransformationStarted ( BACKVIEW );
741 Handle(V3d_View) aView3d = myViewPort->getView();
742 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
746 //****************************************************************
747 void OCCViewer_ViewWindow::onTopView()
749 emit vpTransformationStarted ( TOPVIEW );
750 Handle(V3d_View) aView3d = myViewPort->getView();
751 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
755 //****************************************************************
756 void OCCViewer_ViewWindow::onBottomView()
758 emit vpTransformationStarted ( BOTTOMVIEW );
759 Handle(V3d_View) aView3d = myViewPort->getView();
760 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
764 //****************************************************************
765 void OCCViewer_ViewWindow::onLeftView()
767 emit vpTransformationStarted ( LEFTVIEW );
768 Handle(V3d_View) aView3d = myViewPort->getView();
769 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
773 //****************************************************************
774 void OCCViewer_ViewWindow::onRightView()
776 emit vpTransformationStarted ( RIGHTVIEW );
777 Handle(V3d_View) aView3d = myViewPort->getView();
778 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
782 //****************************************************************
783 void OCCViewer_ViewWindow::onResetView()
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();
793 //****************************************************************
794 void OCCViewer_ViewWindow::onFitAll()
796 emit vpTransformationStarted( FITALLVIEW );
797 myViewPort->fitAll();
800 //****************************************************************
801 void OCCViewer_ViewWindow::onCloneView()
803 SUIT_ViewWindow* vw = myManager->createViewWindow();
807 //****************************************************************
808 void OCCViewer_ViewWindow::onMemorizeView()
810 double centerX, centerY, projX, projY, projZ, twist;
811 double atX, atY, atZ, eyeX, eyeY, eyeZ;
813 Handle(V3d_View) aView3d = myViewPort->getView();
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();
822 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
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;
839 myModel->appendViewAspect( params );
843 //****************************************************************
844 void OCCViewer_ViewWindow::onRestoreView()
846 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), myModel );
847 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
849 myModel->updateViewAspects( aDlg->parameters() );
850 if( myRestoreFlag && aDlg->parameters().count() )
851 performRestoring( aDlg->currentItem() );
854 //****************************************************************
856 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem )
858 Handle(V3d_View) aView3d = myViewPort->getView();
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 );
872 void OCCViewer_ViewWindow::setRestoreFlag()
877 //****************************************************************
878 void OCCViewer_ViewWindow::onTrihedronShow()
880 myModel->toggleTrihedron();
883 //****************************************************************
884 QImage OCCViewer_ViewWindow::dumpView()
886 QPixmap px = QPixmap::grabWindow( myViewPort->winId() );
887 return px.convertToImage();