1 // OCCViewer_ViewWindow.cxx: implementation of the OCCViewer_ViewWindow class.
3 //////////////////////////////////////////////////////////////////////
5 #include "OCCViewer_ViewWindow.h"
6 #include "OCCViewer_ViewModel.h"
7 #include "OCCViewer_ViewPort3d.h"
8 #include "OCCViewer_CreateRestoreViewDlg.h"
10 #include "SUIT_Desktop.h"
11 #include "SUIT_Session.h"
12 #include "SUIT_ToolButton.h"
14 #include "SUIT_Tools.h"
15 #include "SUIT_ResourceMgr.h"
16 #include "SUIT_FileDlg.h"
17 #include "SUIT_MessageBox.h"
24 #include <qapplication.h>
27 const char* imageZoomCursor[] = {
32 "................................",
33 "................................",
34 ".#######........................",
35 "..aaaaaaa.......................",
36 "................................",
37 ".............#####..............",
38 "...........##.aaaa##............",
39 "..........#.aa.....a#...........",
40 ".........#.a.........#..........",
41 ".........#a..........#a.........",
42 "........#.a...........#.........",
43 "........#a............#a........",
44 "........#a............#a........",
45 "........#a............#a........",
46 "........#a............#a........",
47 ".........#...........#.a........",
48 ".........#a..........#a.........",
49 ".........##.........#.a.........",
50 "........#####.....##.a..........",
51 ".......###aaa#####.aa...........",
52 "......###aa...aaaaa.......#.....",
53 ".....###aa................#a....",
54 "....###aa.................#a....",
55 "...###aa...............#######..",
56 "....#aa.................aa#aaaa.",
57 ".....a....................#a....",
58 "..........................#a....",
59 "...........................a....",
60 "................................",
61 "................................",
62 "................................",
63 "................................"};
65 const char* imageRotateCursor[] = {
70 "................................",
71 "................................",
72 "................................",
73 "................................",
74 "........#.......................",
75 ".......#.a......................",
76 "......#######...................",
77 ".......#aaaaa#####..............",
78 "........#..##.a#aa##........##..",
79 ".........a#.aa..#..a#.....##.aa.",
80 ".........#.a.....#...#..##.aa...",
81 ".........#a.......#..###.aa.....",
82 "........#.a.......#a..#aa.......",
83 "........#a.........#..#a........",
84 "........#a.........#a.#a........",
85 "........#a.........#a.#a........",
86 "........#a.........#a.#a........",
87 ".........#.........#a#.a........",
88 "........##a........#a#a.........",
89 "......##.a#.......#.#.a.........",
90 "....##.aa..##.....##.a..........",
91 "..##.aa.....a#####.aa...........",
92 "...aa.........aaa#a.............",
93 "................#.a.............",
94 "...............#.a..............",
95 "..............#.a...............",
96 "...............a................",
97 "................................",
98 "................................",
99 "................................",
100 "................................",
101 "................................"};
103 const char* imageCrossCursor[] = {
108 "................................",
109 "................................",
110 "................................",
111 "................................",
112 "................................",
113 "................................",
114 "................................",
115 "...............#................",
116 "...............#a...............",
117 "...............#a...............",
118 "...............#a...............",
119 "...............#a...............",
120 "...............#a...............",
121 "...............#a...............",
122 "...............#a...............",
123 ".......#################........",
124 "........aaaaaaa#aaaaaaaaa.......",
125 "...............#a...............",
126 "...............#a...............",
127 "...............#a...............",
128 "...............#a...............",
129 "...............#a...............",
130 "...............#a...............",
131 "...............#a...............",
132 "................a...............",
133 "................................",
134 "................................",
135 "................................",
136 "................................",
137 "................................",
138 "................................",
139 "................................"};
142 QPixmap zoomPixmap(imageZoomCursor);
143 QPixmap rotatePixmap(imageRotateCursor);
144 QPixmap globalPanPixmap(imageCrossCursor);
146 QCursor defCursor(Qt::ArrowCursor);
147 QCursor handCursor(Qt::PointingHandCursor);
148 QCursor panCursor(Qt::SizeAllCursor);
149 QCursor zoomCursor(zoomPixmap);
150 QCursor rotCursor(rotatePixmap);
151 QCursor glPanCursor(globalPanPixmap);
155 //////////////////////////////////////////////////////////////////////
156 // Construction/Destruction
157 //////////////////////////////////////////////////////////////////////
159 OCCViewer_ViewWindow::OCCViewer_ViewWindow(SUIT_Desktop* theDesktop, OCCViewer_Viewer* theModel)
160 : SUIT_ViewWindow(theDesktop)
163 myEnableDrawMode = true;
167 //****************************************************************
168 void OCCViewer_ViewWindow::initLayout()
170 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
171 myViewPort->setBackgroundColor(black);
172 myViewPort->installEventFilter(this);
173 setCentralWidget(myViewPort);
174 myOperation = NOTHING;
176 setTransformRequested ( NOTHING );
177 setTransformInProcess ( false );
179 myToolBar = new QToolBar(this);
180 myToolBar->setCloseMode(QDockWindow::Undocked);
181 myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
187 //****************************************************************
188 OCCViewer_ViewWindow::OperationType OCCViewer_ViewWindow::getButtonState(QMouseEvent* theEvent)
190 OperationType aOp = NOTHING;
191 if( (theEvent->state() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::ZOOM]) &&
192 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::ZOOM]) )
194 else if( (theEvent->state() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::PAN]) &&
195 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::PAN]) )
197 else if( (theEvent->state() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::ROTATE]) &&
198 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::ROTATE]) )
204 //****************************************************************
205 bool OCCViewer_ViewWindow::eventFilter(QObject* watched, QEvent* e)
207 if ( watched == myViewPort ) {
208 int aType = e->type();
210 case QEvent::MouseButtonPress:
211 vpMousePressEvent((QMouseEvent*) e);
214 case QEvent::MouseButtonRelease:
215 vpMouseReleaseEvent((QMouseEvent*) e);
218 case QEvent::MouseMove:
219 vpMouseMoveEvent((QMouseEvent*) e);
222 case QEvent::MouseButtonDblClick:
223 emit mouseDoubleClicked(this, (QMouseEvent*)e);
228 QWheelEvent* aEvent = (QWheelEvent*) e;
229 double aDelta = aEvent->delta();
230 double aScale = (aDelta < 0) ? 100./(-aDelta) : aDelta/100.;
231 myViewPort->getView()->SetZoom(aScale);
235 case QEvent::ContextMenu:
237 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
238 if ( aEvent->reason() != QContextMenuEvent::Mouse )
239 emit contextMenuRequested( aEvent );
247 return SUIT_ViewWindow::eventFilter(watched, e);
251 //****************************************************************
252 void OCCViewer_ViewWindow::vpMousePressEvent(QMouseEvent* theEvent)
254 myStartX = theEvent->x();
255 myStartY = theEvent->y();
256 switch ( myOperation ) {
258 if ( theEvent->button() == Qt::LeftButton )
259 emit vpTransformationStarted ( WINDOWFIT );
263 if ( theEvent->button() == Qt::LeftButton )
264 emit vpTransformationStarted ( PANGLOBAL );
268 if ( theEvent->button() == Qt::LeftButton )
269 emit vpTransformationStarted ( ZOOMVIEW );
273 if ( theEvent->button() == Qt::LeftButton )
274 emit vpTransformationStarted ( PANVIEW );
278 if ( theEvent->button() == Qt::LeftButton ) {
279 myViewPort->startRotation(myStartX, myStartY);
280 emit vpTransformationStarted ( ROTATE );
285 /* Try to activate a transformation */
286 switch ( getButtonState(theEvent) ) {
295 myViewPort->startRotation(myStartX, myStartY);
298 emit mousePressed(this, theEvent);
301 /* notify that we start a transformation */
302 if ( transformRequested() )
303 emit vpTransformationStarted ( myOperation );
305 if ( transformRequested() )
306 setTransformInProcess( true );
310 //****************************************************************
311 void OCCViewer_ViewWindow::activateZoom()
313 if ( !transformRequested() && !myCursorIsHand )
314 myCursor = cursor(); /* save old cursor */
316 if ( myOperation != ZOOMVIEW ) {
317 setTransformRequested ( ZOOMVIEW );
318 setCursor( zoomCursor );
323 //****************************************************************
325 Activates 'panning' transformation
327 void OCCViewer_ViewWindow::activatePanning()
329 if ( !transformRequested() && !myCursorIsHand )
330 myCursor = cursor(); // save old cursor
332 if ( myOperation != PANVIEW ) {
333 setTransformRequested ( PANVIEW );
334 setCursor( panCursor );
338 //****************************************************************
340 Activates 'rotation' transformation
342 void OCCViewer_ViewWindow::activateRotation()
344 if ( !transformRequested() && !myCursorIsHand )
345 myCursor = cursor(); // save old cursor
347 if ( myOperation != ROTATE ) {
348 setTransformRequested ( ROTATE );
349 setCursor( rotCursor );
353 //****************************************************************
354 void OCCViewer_ViewWindow::activateGlobalPanning()
356 Handle(V3d_View) aView3d = myViewPort->getView();
357 if ( !aView3d.IsNull() ) {
358 myCurScale = aView3d->Scale();
359 aView3d->FitAll(0.01, false);
360 myCursor = cursor(); // save old cursor
361 myViewPort->fitAll(); // fits view before selecting a new scene center
362 setTransformRequested( PANGLOBAL );
363 setCursor( glPanCursor );
367 //****************************************************************
369 Activates 'fit' transformation
371 void OCCViewer_ViewWindow::activateWindowFit()
373 if ( !transformRequested() && !myCursorIsHand )
374 myCursor = cursor(); /* save old cursor */
376 if ( myOperation != WINDOWFIT ) {
377 setTransformRequested ( WINDOWFIT );
378 setCursor ( handCursor );
379 myCursorIsHand = true;
383 //****************************************************************
385 Sets the active operation 'op'
387 void OCCViewer_ViewWindow::setTransformRequested ( OperationType op )
390 myViewPort->setMouseTracking( myOperation == NOTHING );
394 //****************************************************************/
395 void OCCViewer_ViewWindow::vpMouseMoveEvent(QMouseEvent* theEvent)
397 myCurrX = theEvent->x();
398 myCurrY = theEvent->y();
399 switch (myOperation) {
401 myViewPort->rotate(myCurrX, myCurrY);
405 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
411 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
425 int aState = theEvent->state();
426 //int aButton = theEvent->button();
427 if ( aState == Qt::LeftButton ||
428 aState == ( Qt::LeftButton | Qt::ShiftButton) ) {
429 myDrawRect = myEnableDrawMode;
432 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
433 myCursorIsHand = true;
435 setCursor( handCursor );
440 emit mouseMoving( this, theEvent );
445 //****************************************************************/
446 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
448 switch ( myOperation ) {
451 emit mouseReleased(this, theEvent);
452 if(theEvent->button() == RightButton)
454 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
455 theEvent->pos(), theEvent->globalPos(),
457 emit contextMenuRequested( &aEvent );
462 myViewPort->endRotation();
472 if ( theEvent->button() == Qt::LeftButton ) {
473 myViewPort->setCenter( theEvent->x(), theEvent->y() );
474 myViewPort->getView()->SetScale(myCurScale);
480 if ( theEvent->state() == Qt::LeftButton ) {
481 myCurrX = theEvent->x();
482 myCurrY = theEvent->y();
483 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
484 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
490 // NOTE: viewer 3D detects a rectangle of selection using this event
491 // so we must emit it BEFORE resetting the selection rectangle
493 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
497 myViewPort->update();
501 //****************************************************************
503 Sets the viewport to its initial state
504 ( no transformations in process etc. )
506 void OCCViewer_ViewWindow::resetState()
510 /* make rectangle empty (left > right) */
514 if ( transformRequested() || myCursorIsHand )
515 setCursor( myCursor );
516 myCursorIsHand = false;
518 if ( transformRequested() )
519 emit vpTransformationFinished (myOperation);
521 setTransformInProcess( false );
522 setTransformRequested( NOTHING );
526 //****************************************************************/
527 void OCCViewer_ViewWindow::drawRect()
529 QPainter aPainter(myViewPort);
530 aPainter.setRasterOp(Qt::XorROP);
531 aPainter.setPen(Qt::white);
532 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
533 if ( !myRect.isEmpty() )
534 aPainter.drawRect( myRect );
535 aPainter.drawRect(aRect);
539 //****************************************************************/
540 void OCCViewer_ViewWindow::createActions()
542 if (!myActionsMap.isEmpty()) return;
544 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
549 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
550 tr( "MNU_DUMP_VIEW" ), 0, this);
551 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
552 connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView()));
553 myActionsMap[ DumpId ] = aAction;
556 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
557 tr( "MNU_FITALL" ), 0, this);
558 aAction->setStatusTip(tr("DSC_FITALL"));
559 connect(aAction, SIGNAL(activated()), this, SLOT(onFitAll()));
560 myActionsMap[ FitAllId ] = aAction;
563 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
564 tr( "MNU_FITRECT" ), 0, this);
565 aAction->setStatusTip(tr("DSC_FITRECT"));
566 connect(aAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
567 myActionsMap[ FitRectId ] = aAction;
570 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
571 tr( "MNU_ZOOM_VIEW" ), 0, this);
572 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
573 connect(aAction, SIGNAL(activated()), this, SLOT(activateZoom()));
574 myActionsMap[ ZoomId ] = aAction;
577 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
578 tr( "MNU_PAN_VIEW" ), 0, this);
579 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
580 connect(aAction, SIGNAL(activated()), this, SLOT(activatePanning()));
581 myActionsMap[ PanId ] = aAction;
584 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
585 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
586 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
587 connect(aAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
588 myActionsMap[ GlobalPanId ] = aAction;
591 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
592 tr( "MNU_ROTATE_VIEW" ), 0, this);
593 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
594 connect(aAction, SIGNAL(activated()), this, SLOT(activateRotation()));
595 myActionsMap[ RotationId ] = aAction;
598 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
599 tr( "MNU_FRONT_VIEW" ), 0, this);
600 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
601 connect(aAction, SIGNAL(activated()), this, SLOT(onFrontView()));
602 myActionsMap[ FrontId ] = aAction;
604 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
605 tr( "MNU_BACK_VIEW" ), 0, this);
606 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
607 connect(aAction, SIGNAL(activated()), this, SLOT(onBackView()));
608 myActionsMap[ BackId ] = aAction;
610 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
611 tr( "MNU_TOP_VIEW" ), 0, this);
612 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
613 connect(aAction, SIGNAL(activated()), this, SLOT(onTopView()));
614 myActionsMap[ TopId ] = aAction;
616 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
617 tr( "MNU_BOTTOM_VIEW" ), 0, this);
618 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
619 connect(aAction, SIGNAL(activated()), this, SLOT(onBottomView()));
620 myActionsMap[ BottomId ] = aAction;
622 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
623 tr( "MNU_LEFT_VIEW" ), 0, this);
624 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
625 connect(aAction, SIGNAL(activated()), this, SLOT(onLeftView()));
626 myActionsMap[ LeftId ] = aAction;
628 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
629 tr( "MNU_RIGHT_VIEW" ), 0, this);
630 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
631 connect(aAction, SIGNAL(activated()), this, SLOT(onRightView()));
632 myActionsMap[ RightId ] = aAction;
635 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
636 tr( "MNU_RESET_VIEW" ), 0, this);
637 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
638 connect(aAction, SIGNAL(activated()), this, SLOT(onResetView()));
639 myActionsMap[ ResetId ] = aAction;
642 aAction = new QtxAction(tr("MNU_CLONE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CLONE_VIEW" ) ),
643 tr( "MNU_CLONE_VIEW" ), 0, this);
644 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
645 connect(aAction, SIGNAL(activated()), this, SLOT(onCloneView()));
646 myActionsMap[ CloneId ] = aAction;
648 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
649 tr( "MNU_SHOOT_VIEW" ), 0, this);
650 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
651 connect(aAction, SIGNAL(activated()), this, SLOT(onMemorizeView()));
652 myActionsMap[ MemId ] = aAction;
654 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
655 tr( "MNU_PRESETS_VIEW" ), 0, this);
656 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
657 connect(aAction, SIGNAL(activated()), this, SLOT(onRestoreView()));
658 myActionsMap[ RestoreId ] = aAction;
661 //****************************************************************
662 void OCCViewer_ViewWindow::createToolBar()
664 myActionsMap[DumpId]->addTo(myToolBar);
666 SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar, "scale");
667 aScaleBtn->AddAction(myActionsMap[FitAllId]);
668 aScaleBtn->AddAction(myActionsMap[FitRectId]);
669 aScaleBtn->AddAction(myActionsMap[ZoomId]);
671 SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar, "pan");
672 aPanningBtn->AddAction(myActionsMap[PanId]);
673 aPanningBtn->AddAction(myActionsMap[GlobalPanId]);
675 myActionsMap[RotationId]->addTo(myToolBar);
677 SUIT_ToolButton* aViewsBtn = new SUIT_ToolButton(myToolBar, "projection");
678 aViewsBtn->AddAction(myActionsMap[FrontId]);
679 aViewsBtn->AddAction(myActionsMap[BackId]);
680 aViewsBtn->AddAction(myActionsMap[TopId]);
681 aViewsBtn->AddAction(myActionsMap[BottomId]);
682 aViewsBtn->AddAction(myActionsMap[LeftId]);
683 aViewsBtn->AddAction(myActionsMap[RightId]);
685 myActionsMap[ResetId]->addTo(myToolBar);
687 SUIT_ToolButton* aMemBtn = new SUIT_ToolButton(myToolBar, "view");
688 aMemBtn->AddAction(myActionsMap[MemId]);
689 aMemBtn->AddAction(myActionsMap[RestoreId]);
691 myToolBar->addSeparator();
692 myActionsMap[CloneId]->addTo(myToolBar);
695 //****************************************************************
696 void OCCViewer_ViewWindow::onViewFitAll()
698 myViewPort->fitAll();
701 //****************************************************************
702 void OCCViewer_ViewWindow::onFrontView()
704 emit vpTransformationStarted ( FRONTVIEW );
705 Handle(V3d_View) aView3d = myViewPort->getView();
706 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
710 //****************************************************************
711 void OCCViewer_ViewWindow::onBackView()
713 emit vpTransformationStarted ( BACKVIEW );
714 Handle(V3d_View) aView3d = myViewPort->getView();
715 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
719 //****************************************************************
720 void OCCViewer_ViewWindow::onTopView()
722 emit vpTransformationStarted ( TOPVIEW );
723 Handle(V3d_View) aView3d = myViewPort->getView();
724 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
728 //****************************************************************
729 void OCCViewer_ViewWindow::onBottomView()
731 emit vpTransformationStarted ( BOTTOMVIEW );
732 Handle(V3d_View) aView3d = myViewPort->getView();
733 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
737 //****************************************************************
738 void OCCViewer_ViewWindow::onLeftView()
740 emit vpTransformationStarted ( LEFTVIEW );
741 Handle(V3d_View) aView3d = myViewPort->getView();
742 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
746 //****************************************************************
747 void OCCViewer_ViewWindow::onRightView()
749 emit vpTransformationStarted ( RIGHTVIEW );
750 Handle(V3d_View) aView3d = myViewPort->getView();
751 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
755 //****************************************************************
756 void OCCViewer_ViewWindow::onResetView()
758 emit vpTransformationStarted( RESETVIEW );
759 myViewPort->getView()->Reset();
760 myViewPort->fitAll();
763 //****************************************************************
764 void OCCViewer_ViewWindow::onFitAll()
766 emit vpTransformationStarted( FITALLVIEW );
767 myViewPort->fitAll();
770 //****************************************************************
772 Dumps 3d-Viewer contents into image file
773 File format is defined by file's extension; supported formats : PNG, BMP, GIF, JPG
775 void OCCViewer_ViewWindow::onDumpView()
777 QApplication::setOverrideCursor( Qt::waitCursor );
778 QPixmap px = QPixmap::grabWindow(myViewPort->winId());
779 QApplication::restoreOverrideCursor();
781 QString fileName = SUIT_FileDlg::getFileName(this,
783 tr("OCC_IMAGE_FILES"),
784 tr("INF_APP_DUMP_VIEW"),
786 if (!fileName.isNull()) {
787 QApplication::setOverrideCursor( Qt::waitCursor );
788 QString fmt = SUIT_Tools::extension(fileName).upper();
790 fmt = QString("BMP"); // default format
793 bool bOk = px.save(fileName, fmt.latin1());
794 QApplication::restoreOverrideCursor();
796 SUIT_MessageBox::error1(this, tr("ERROR"), tr("ERR_DOC_CANT_SAVE_FILE"), tr("BUT_OK"));
801 //****************************************************************
802 void OCCViewer_ViewWindow::onCloneView()
804 myManager->createView();
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()