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>
45 const char* imageZoomCursor[] = {
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 "................................"};
83 const char* imageRotateCursor[] = {
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 "................................"};
121 const char* imageCrossCursor[] = {
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 "................................"};
160 QPixmap zoomPixmap(imageZoomCursor);
161 QPixmap rotatePixmap(imageRotateCursor);
162 QPixmap globalPanPixmap(imageCrossCursor);
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);
173 //////////////////////////////////////////////////////////////////////
174 // Construction/Destruction
175 //////////////////////////////////////////////////////////////////////
177 OCCViewer_ViewWindow::OCCViewer_ViewWindow(SUIT_Desktop* theDesktop, OCCViewer_Viewer* theModel)
178 : SUIT_ViewWindow(theDesktop)
182 myEnableDrawMode = false;
183 updateEnabledDrawMode();
186 //****************************************************************
187 void OCCViewer_ViewWindow::initLayout()
189 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
190 myViewPort->setBackgroundColor(black);
191 myViewPort->installEventFilter(this);
192 setCentralWidget(myViewPort);
193 myOperation = NOTHING;
195 setTransformRequested ( NOTHING );
196 setTransformInProcess ( false );
198 myToolBar = new QToolBar(this);
199 myToolBar->setCloseMode(QDockWindow::Undocked);
200 myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
206 //****************************************************************
207 OCCViewer_ViewWindow::OperationType OCCViewer_ViewWindow::getButtonState(QMouseEvent* theEvent)
209 OperationType aOp = NOTHING;
210 if( (theEvent->state() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::ZOOM]) &&
211 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::ZOOM]) )
213 else if( (theEvent->state() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::PAN]) &&
214 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::PAN]) )
216 else if( (theEvent->state() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::ROTATE]) &&
217 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::ROTATE]) )
223 //****************************************************************
224 bool OCCViewer_ViewWindow::eventFilter(QObject* watched, QEvent* e)
226 if ( watched == myViewPort ) {
227 int aType = e->type();
229 case QEvent::MouseButtonPress:
230 vpMousePressEvent((QMouseEvent*) e);
233 case QEvent::MouseButtonRelease:
234 vpMouseReleaseEvent((QMouseEvent*) e);
237 case QEvent::MouseMove:
238 vpMouseMoveEvent((QMouseEvent*) e);
241 case QEvent::MouseButtonDblClick:
242 emit mouseDoubleClicked(this, (QMouseEvent*)e);
247 QWheelEvent* aEvent = (QWheelEvent*) e;
248 double aDelta = aEvent->delta();
249 double aScale = (aDelta < 0) ? 100./(-aDelta) : aDelta/100.;
250 myViewPort->getView()->SetZoom(aScale);
254 case QEvent::ContextMenu:
256 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
257 if ( aEvent->reason() != QContextMenuEvent::Mouse )
258 emit contextMenuRequested( aEvent );
266 return SUIT_ViewWindow::eventFilter(watched, e);
269 void OCCViewer_ViewWindow::updateEnabledDrawMode()
272 myEnableDrawMode = myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
275 //****************************************************************
276 void OCCViewer_ViewWindow::vpMousePressEvent(QMouseEvent* theEvent)
278 myStartX = theEvent->x();
279 myStartY = theEvent->y();
280 switch ( myOperation ) {
282 if ( theEvent->button() == Qt::LeftButton )
283 emit vpTransformationStarted ( WINDOWFIT );
287 if ( theEvent->button() == Qt::LeftButton )
288 emit vpTransformationStarted ( PANGLOBAL );
292 if ( theEvent->button() == Qt::LeftButton )
293 emit vpTransformationStarted ( ZOOMVIEW );
297 if ( theEvent->button() == Qt::LeftButton )
298 emit vpTransformationStarted ( PANVIEW );
302 if ( theEvent->button() == Qt::LeftButton ) {
303 myViewPort->startRotation(myStartX, myStartY);
304 emit vpTransformationStarted ( ROTATE );
309 /* Try to activate a transformation */
310 switch ( getButtonState(theEvent) ) {
319 myViewPort->startRotation(myStartX, myStartY);
322 emit mousePressed(this, theEvent);
325 /* notify that we start a transformation */
326 if ( transformRequested() )
327 emit vpTransformationStarted ( myOperation );
329 if ( transformRequested() )
330 setTransformInProcess( true );
334 //****************************************************************
335 void OCCViewer_ViewWindow::activateZoom()
337 if ( !transformRequested() && !myCursorIsHand )
338 myCursor = cursor(); /* save old cursor */
340 if ( myOperation != ZOOMVIEW ) {
341 setTransformRequested ( ZOOMVIEW );
342 setCursor( zoomCursor );
347 //****************************************************************
349 Activates 'panning' transformation
351 void OCCViewer_ViewWindow::activatePanning()
353 if ( !transformRequested() && !myCursorIsHand )
354 myCursor = cursor(); // save old cursor
356 if ( myOperation != PANVIEW ) {
357 setTransformRequested ( PANVIEW );
358 setCursor( panCursor );
362 //****************************************************************
364 Activates 'rotation' transformation
366 void OCCViewer_ViewWindow::activateRotation()
368 if ( !transformRequested() && !myCursorIsHand )
369 myCursor = cursor(); // save old cursor
371 if ( myOperation != ROTATE ) {
372 setTransformRequested ( ROTATE );
373 setCursor( rotCursor );
377 //****************************************************************
378 void OCCViewer_ViewWindow::activateGlobalPanning()
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 );
391 //****************************************************************
393 Activates 'fit' transformation
395 void OCCViewer_ViewWindow::activateWindowFit()
397 if ( !transformRequested() && !myCursorIsHand )
398 myCursor = cursor(); /* save old cursor */
400 if ( myOperation != WINDOWFIT ) {
401 setTransformRequested ( WINDOWFIT );
402 setCursor ( handCursor );
403 myCursorIsHand = true;
407 //****************************************************************
409 Sets the active operation 'op'
411 void OCCViewer_ViewWindow::setTransformRequested ( OperationType op )
414 myViewPort->setMouseTracking( myOperation == NOTHING );
418 //****************************************************************/
419 void OCCViewer_ViewWindow::vpMouseMoveEvent(QMouseEvent* theEvent)
421 myCurrX = theEvent->x();
422 myCurrY = theEvent->y();
423 switch (myOperation) {
425 myViewPort->rotate(myCurrX, myCurrY);
429 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
435 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
449 int aState = theEvent->state();
450 //int aButton = theEvent->button();
451 if ( aState == Qt::LeftButton ||
452 aState == ( Qt::LeftButton | Qt::ShiftButton) ) {
453 myDrawRect = myEnableDrawMode;
456 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
457 myCursorIsHand = true;
459 setCursor( handCursor );
464 emit mouseMoving( this, theEvent );
469 //****************************************************************/
470 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
472 switch ( myOperation ) {
475 emit mouseReleased(this, theEvent);
476 if(theEvent->button() == RightButton)
478 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
479 theEvent->pos(), theEvent->globalPos(),
481 emit contextMenuRequested( &aEvent );
486 myViewPort->endRotation();
496 if ( theEvent->button() == Qt::LeftButton ) {
497 myViewPort->setCenter( theEvent->x(), theEvent->y() );
498 myViewPort->getView()->SetScale(myCurScale);
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);
514 // NOTE: viewer 3D detects a rectangle of selection using this event
515 // so we must emit it BEFORE resetting the selection rectangle
517 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
521 myViewPort->update();
525 //****************************************************************
527 Sets the viewport to its initial state
528 ( no transformations in process etc. )
530 void OCCViewer_ViewWindow::resetState()
534 /* make rectangle empty (left > right) */
538 if ( transformRequested() || myCursorIsHand )
539 setCursor( myCursor );
540 myCursorIsHand = false;
542 if ( transformRequested() )
543 emit vpTransformationFinished (myOperation);
545 setTransformInProcess( false );
546 setTransformRequested( NOTHING );
550 //****************************************************************/
551 void OCCViewer_ViewWindow::drawRect()
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);
563 //****************************************************************/
564 void OCCViewer_ViewWindow::createActions()
566 if (!myActionsMap.isEmpty()) return;
568 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
693 //****************************************************************
694 void OCCViewer_ViewWindow::createToolBar()
696 myActionsMap[DumpId]->addTo(myToolBar);
697 if ( myModel->trihedronActivated() )
698 myActionsMap[TrihedronShowId]->addTo(myToolBar);
700 SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar, "scale");
701 aScaleBtn->AddAction(myActionsMap[FitAllId]);
702 aScaleBtn->AddAction(myActionsMap[FitRectId]);
703 aScaleBtn->AddAction(myActionsMap[ZoomId]);
705 SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar, "pan");
706 aPanningBtn->AddAction(myActionsMap[PanId]);
707 aPanningBtn->AddAction(myActionsMap[GlobalPanId]);
709 myActionsMap[RotationId]->addTo(myToolBar);
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]);
719 myActionsMap[ResetId]->addTo(myToolBar);
721 SUIT_ToolButton* aMemBtn = new SUIT_ToolButton(myToolBar, "view");
722 aMemBtn->AddAction(myActionsMap[MemId]);
723 aMemBtn->AddAction(myActionsMap[RestoreId]);
725 myToolBar->addSeparator();
726 myActionsMap[CloneId]->addTo(myToolBar);
729 //****************************************************************
730 void OCCViewer_ViewWindow::onViewFitAll()
732 myViewPort->fitAll();
735 //****************************************************************
736 void OCCViewer_ViewWindow::onFrontView()
738 emit vpTransformationStarted ( FRONTVIEW );
739 Handle(V3d_View) aView3d = myViewPort->getView();
740 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
744 //****************************************************************
745 void OCCViewer_ViewWindow::onBackView()
747 emit vpTransformationStarted ( BACKVIEW );
748 Handle(V3d_View) aView3d = myViewPort->getView();
749 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
753 //****************************************************************
754 void OCCViewer_ViewWindow::onTopView()
756 emit vpTransformationStarted ( TOPVIEW );
757 Handle(V3d_View) aView3d = myViewPort->getView();
758 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
762 //****************************************************************
763 void OCCViewer_ViewWindow::onBottomView()
765 emit vpTransformationStarted ( BOTTOMVIEW );
766 Handle(V3d_View) aView3d = myViewPort->getView();
767 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
771 //****************************************************************
772 void OCCViewer_ViewWindow::onLeftView()
774 emit vpTransformationStarted ( LEFTVIEW );
775 Handle(V3d_View) aView3d = myViewPort->getView();
776 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
780 //****************************************************************
781 void OCCViewer_ViewWindow::onRightView()
783 emit vpTransformationStarted ( RIGHTVIEW );
784 Handle(V3d_View) aView3d = myViewPort->getView();
785 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
789 //****************************************************************
790 void OCCViewer_ViewWindow::onResetView()
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();
800 //****************************************************************
801 void OCCViewer_ViewWindow::onFitAll()
803 emit vpTransformationStarted( FITALLVIEW );
804 myViewPort->fitAll();
807 //****************************************************************
808 void OCCViewer_ViewWindow::onCloneView()
810 SUIT_ViewWindow* vw = myManager->createViewWindow();
814 //****************************************************************
815 void OCCViewer_ViewWindow::onMemorizeView()
817 double centerX, centerY, projX, projY, projZ, twist;
818 double atX, atY, atZ, eyeX, eyeY, eyeZ;
820 Handle(V3d_View) aView3d = myViewPort->getView();
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();
829 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
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;
846 myModel->appendViewAspect( params );
850 //****************************************************************
851 void OCCViewer_ViewWindow::onRestoreView()
853 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), myModel );
854 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
856 myModel->updateViewAspects( aDlg->parameters() );
857 if( myRestoreFlag && aDlg->parameters().count() )
858 performRestoring( aDlg->currentItem() );
861 //****************************************************************
863 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem )
865 Handle(V3d_View) aView3d = myViewPort->getView();
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 );
879 void OCCViewer_ViewWindow::setRestoreFlag()
884 //****************************************************************
885 void OCCViewer_ViewWindow::onTrihedronShow()
887 myModel->toggleTrihedron();
890 //****************************************************************
891 QImage OCCViewer_ViewWindow::dumpView()
893 QPixmap px = QPixmap::grabWindow( myViewPort->winId() );
894 return px.convertToImage();