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_MessageBox.h"
23 #include <qapplication.h>
24 #include <qdatetime.h>
26 const char* imageZoomCursor[] = {
31 "................................",
32 "................................",
33 ".#######........................",
34 "..aaaaaaa.......................",
35 "................................",
36 ".............#####..............",
37 "...........##.aaaa##............",
38 "..........#.aa.....a#...........",
39 ".........#.a.........#..........",
40 ".........#a..........#a.........",
41 "........#.a...........#.........",
42 "........#a............#a........",
43 "........#a............#a........",
44 "........#a............#a........",
45 "........#a............#a........",
46 ".........#...........#.a........",
47 ".........#a..........#a.........",
48 ".........##.........#.a.........",
49 "........#####.....##.a..........",
50 ".......###aaa#####.aa...........",
51 "......###aa...aaaaa.......#.....",
52 ".....###aa................#a....",
53 "....###aa.................#a....",
54 "...###aa...............#######..",
55 "....#aa.................aa#aaaa.",
56 ".....a....................#a....",
57 "..........................#a....",
58 "...........................a....",
59 "................................",
60 "................................",
61 "................................",
62 "................................"};
64 const char* imageRotateCursor[] = {
69 "................................",
70 "................................",
71 "................................",
72 "................................",
73 "........#.......................",
74 ".......#.a......................",
75 "......#######...................",
76 ".......#aaaaa#####..............",
77 "........#..##.a#aa##........##..",
78 ".........a#.aa..#..a#.....##.aa.",
79 ".........#.a.....#...#..##.aa...",
80 ".........#a.......#..###.aa.....",
81 "........#.a.......#a..#aa.......",
82 "........#a.........#..#a........",
83 "........#a.........#a.#a........",
84 "........#a.........#a.#a........",
85 "........#a.........#a.#a........",
86 ".........#.........#a#.a........",
87 "........##a........#a#a.........",
88 "......##.a#.......#.#.a.........",
89 "....##.aa..##.....##.a..........",
90 "..##.aa.....a#####.aa...........",
91 "...aa.........aaa#a.............",
92 "................#.a.............",
93 "...............#.a..............",
94 "..............#.a...............",
95 "...............a................",
96 "................................",
97 "................................",
98 "................................",
99 "................................",
100 "................................"};
102 const char* imageCrossCursor[] = {
107 "................................",
108 "................................",
109 "................................",
110 "................................",
111 "................................",
112 "................................",
113 "................................",
114 "...............#................",
115 "...............#a...............",
116 "...............#a...............",
117 "...............#a...............",
118 "...............#a...............",
119 "...............#a...............",
120 "...............#a...............",
121 "...............#a...............",
122 ".......#################........",
123 "........aaaaaaa#aaaaaaaaa.......",
124 "...............#a...............",
125 "...............#a...............",
126 "...............#a...............",
127 "...............#a...............",
128 "...............#a...............",
129 "...............#a...............",
130 "...............#a...............",
131 "................a...............",
132 "................................",
133 "................................",
134 "................................",
135 "................................",
136 "................................",
137 "................................",
138 "................................"};
141 QPixmap zoomPixmap(imageZoomCursor);
142 QPixmap rotatePixmap(imageRotateCursor);
143 QPixmap globalPanPixmap(imageCrossCursor);
145 QCursor defCursor(Qt::ArrowCursor);
146 QCursor handCursor(Qt::PointingHandCursor);
147 QCursor panCursor(Qt::SizeAllCursor);
148 QCursor zoomCursor(zoomPixmap);
149 QCursor rotCursor(rotatePixmap);
150 QCursor glPanCursor(globalPanPixmap);
154 //////////////////////////////////////////////////////////////////////
155 // Construction/Destruction
156 //////////////////////////////////////////////////////////////////////
158 OCCViewer_ViewWindow::OCCViewer_ViewWindow(SUIT_Desktop* theDesktop, OCCViewer_Viewer* theModel)
159 : SUIT_ViewWindow(theDesktop)
162 myEnableDrawMode = true;
166 //****************************************************************
167 void OCCViewer_ViewWindow::initLayout()
169 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
170 myViewPort->setBackgroundColor(black);
171 myViewPort->installEventFilter(this);
172 setCentralWidget(myViewPort);
173 myOperation = NOTHING;
175 setTransformRequested ( NOTHING );
176 setTransformInProcess ( false );
178 myToolBar = new QToolBar(this);
179 myToolBar->setCloseMode(QDockWindow::Undocked);
180 myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
186 //****************************************************************
187 OCCViewer_ViewWindow::OperationType OCCViewer_ViewWindow::getButtonState(QMouseEvent* theEvent)
189 OperationType aOp = NOTHING;
190 if( (theEvent->state() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::ZOOM]) &&
191 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::ZOOM]) )
193 else if( (theEvent->state() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::PAN]) &&
194 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::PAN]) )
196 else if( (theEvent->state() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::ROTATE]) &&
197 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::ROTATE]) )
203 //****************************************************************
204 bool OCCViewer_ViewWindow::eventFilter(QObject* watched, QEvent* e)
206 if ( watched == myViewPort ) {
207 int aType = e->type();
209 case QEvent::MouseButtonPress:
210 vpMousePressEvent((QMouseEvent*) e);
213 case QEvent::MouseButtonRelease:
214 vpMouseReleaseEvent((QMouseEvent*) e);
217 case QEvent::MouseMove:
218 vpMouseMoveEvent((QMouseEvent*) e);
221 case QEvent::MouseButtonDblClick:
222 emit mouseDoubleClicked(this, (QMouseEvent*)e);
227 QWheelEvent* aEvent = (QWheelEvent*) e;
228 double aDelta = aEvent->delta();
229 double aScale = (aDelta < 0) ? 100./(-aDelta) : aDelta/100.;
230 myViewPort->getView()->SetZoom(aScale);
234 case QEvent::ContextMenu:
236 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
237 if ( aEvent->reason() != QContextMenuEvent::Mouse )
238 emit contextMenuRequested( aEvent );
246 return SUIT_ViewWindow::eventFilter(watched, e);
250 //****************************************************************
251 void OCCViewer_ViewWindow::vpMousePressEvent(QMouseEvent* theEvent)
253 myStartX = theEvent->x();
254 myStartY = theEvent->y();
255 switch ( myOperation ) {
257 if ( theEvent->button() == Qt::LeftButton )
258 emit vpTransformationStarted ( WINDOWFIT );
262 if ( theEvent->button() == Qt::LeftButton )
263 emit vpTransformationStarted ( PANGLOBAL );
267 if ( theEvent->button() == Qt::LeftButton )
268 emit vpTransformationStarted ( ZOOMVIEW );
272 if ( theEvent->button() == Qt::LeftButton )
273 emit vpTransformationStarted ( PANVIEW );
277 if ( theEvent->button() == Qt::LeftButton ) {
278 myViewPort->startRotation(myStartX, myStartY);
279 emit vpTransformationStarted ( ROTATE );
284 /* Try to activate a transformation */
285 switch ( getButtonState(theEvent) ) {
294 myViewPort->startRotation(myStartX, myStartY);
297 emit mousePressed(this, theEvent);
300 /* notify that we start a transformation */
301 if ( transformRequested() )
302 emit vpTransformationStarted ( myOperation );
304 if ( transformRequested() )
305 setTransformInProcess( true );
309 //****************************************************************
310 void OCCViewer_ViewWindow::activateZoom()
312 if ( !transformRequested() && !myCursorIsHand )
313 myCursor = cursor(); /* save old cursor */
315 if ( myOperation != ZOOMVIEW ) {
316 setTransformRequested ( ZOOMVIEW );
317 setCursor( zoomCursor );
322 //****************************************************************
324 Activates 'panning' transformation
326 void OCCViewer_ViewWindow::activatePanning()
328 if ( !transformRequested() && !myCursorIsHand )
329 myCursor = cursor(); // save old cursor
331 if ( myOperation != PANVIEW ) {
332 setTransformRequested ( PANVIEW );
333 setCursor( panCursor );
337 //****************************************************************
339 Activates 'rotation' transformation
341 void OCCViewer_ViewWindow::activateRotation()
343 if ( !transformRequested() && !myCursorIsHand )
344 myCursor = cursor(); // save old cursor
346 if ( myOperation != ROTATE ) {
347 setTransformRequested ( ROTATE );
348 setCursor( rotCursor );
352 //****************************************************************
353 void OCCViewer_ViewWindow::activateGlobalPanning()
355 Handle(V3d_View) aView3d = myViewPort->getView();
356 if ( !aView3d.IsNull() ) {
357 myCurScale = aView3d->Scale();
358 aView3d->FitAll(0.01, false);
359 myCursor = cursor(); // save old cursor
360 myViewPort->fitAll(); // fits view before selecting a new scene center
361 setTransformRequested( PANGLOBAL );
362 setCursor( glPanCursor );
366 //****************************************************************
368 Activates 'fit' transformation
370 void OCCViewer_ViewWindow::activateWindowFit()
372 if ( !transformRequested() && !myCursorIsHand )
373 myCursor = cursor(); /* save old cursor */
375 if ( myOperation != WINDOWFIT ) {
376 setTransformRequested ( WINDOWFIT );
377 setCursor ( handCursor );
378 myCursorIsHand = true;
382 //****************************************************************
384 Sets the active operation 'op'
386 void OCCViewer_ViewWindow::setTransformRequested ( OperationType op )
389 myViewPort->setMouseTracking( myOperation == NOTHING );
393 //****************************************************************/
394 void OCCViewer_ViewWindow::vpMouseMoveEvent(QMouseEvent* theEvent)
396 myCurrX = theEvent->x();
397 myCurrY = theEvent->y();
398 switch (myOperation) {
400 myViewPort->rotate(myCurrX, myCurrY);
404 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
410 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
424 int aState = theEvent->state();
425 //int aButton = theEvent->button();
426 if ( aState == Qt::LeftButton ||
427 aState == ( Qt::LeftButton | Qt::ShiftButton) ) {
428 myDrawRect = myEnableDrawMode;
431 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
432 myCursorIsHand = true;
434 setCursor( handCursor );
439 emit mouseMoving( this, theEvent );
444 //****************************************************************/
445 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
447 switch ( myOperation ) {
450 emit mouseReleased(this, theEvent);
451 if(theEvent->button() == RightButton)
453 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
454 theEvent->pos(), theEvent->globalPos(),
456 emit contextMenuRequested( &aEvent );
461 myViewPort->endRotation();
471 if ( theEvent->button() == Qt::LeftButton ) {
472 myViewPort->setCenter( theEvent->x(), theEvent->y() );
473 myViewPort->getView()->SetScale(myCurScale);
479 if ( theEvent->state() == Qt::LeftButton ) {
480 myCurrX = theEvent->x();
481 myCurrY = theEvent->y();
482 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
483 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
489 // NOTE: viewer 3D detects a rectangle of selection using this event
490 // so we must emit it BEFORE resetting the selection rectangle
492 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
496 myViewPort->update();
500 //****************************************************************
502 Sets the viewport to its initial state
503 ( no transformations in process etc. )
505 void OCCViewer_ViewWindow::resetState()
509 /* make rectangle empty (left > right) */
513 if ( transformRequested() || myCursorIsHand )
514 setCursor( myCursor );
515 myCursorIsHand = false;
517 if ( transformRequested() )
518 emit vpTransformationFinished (myOperation);
520 setTransformInProcess( false );
521 setTransformRequested( NOTHING );
525 //****************************************************************/
526 void OCCViewer_ViewWindow::drawRect()
528 QPainter aPainter(myViewPort);
529 aPainter.setRasterOp(Qt::XorROP);
530 aPainter.setPen(Qt::white);
531 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
532 if ( !myRect.isEmpty() )
533 aPainter.drawRect( myRect );
534 aPainter.drawRect(aRect);
538 //****************************************************************/
539 void OCCViewer_ViewWindow::createActions()
541 if (!myActionsMap.isEmpty()) return;
543 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
548 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
549 tr( "MNU_DUMP_VIEW" ), 0, this);
550 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
551 connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView()));
552 myActionsMap[ DumpId ] = aAction;
555 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
556 tr( "MNU_FITALL" ), 0, this);
557 aAction->setStatusTip(tr("DSC_FITALL"));
558 connect(aAction, SIGNAL(activated()), this, SLOT(onFitAll()));
559 myActionsMap[ FitAllId ] = aAction;
562 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
563 tr( "MNU_FITRECT" ), 0, this);
564 aAction->setStatusTip(tr("DSC_FITRECT"));
565 connect(aAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
566 myActionsMap[ FitRectId ] = aAction;
569 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
570 tr( "MNU_ZOOM_VIEW" ), 0, this);
571 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
572 connect(aAction, SIGNAL(activated()), this, SLOT(activateZoom()));
573 myActionsMap[ ZoomId ] = aAction;
576 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
577 tr( "MNU_PAN_VIEW" ), 0, this);
578 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
579 connect(aAction, SIGNAL(activated()), this, SLOT(activatePanning()));
580 myActionsMap[ PanId ] = aAction;
583 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
584 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
585 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
586 connect(aAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
587 myActionsMap[ GlobalPanId ] = aAction;
590 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
591 tr( "MNU_ROTATE_VIEW" ), 0, this);
592 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
593 connect(aAction, SIGNAL(activated()), this, SLOT(activateRotation()));
594 myActionsMap[ RotationId ] = aAction;
597 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
598 tr( "MNU_FRONT_VIEW" ), 0, this);
599 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
600 connect(aAction, SIGNAL(activated()), this, SLOT(onFrontView()));
601 myActionsMap[ FrontId ] = aAction;
603 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
604 tr( "MNU_BACK_VIEW" ), 0, this);
605 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
606 connect(aAction, SIGNAL(activated()), this, SLOT(onBackView()));
607 myActionsMap[ BackId ] = aAction;
609 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
610 tr( "MNU_TOP_VIEW" ), 0, this);
611 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
612 connect(aAction, SIGNAL(activated()), this, SLOT(onTopView()));
613 myActionsMap[ TopId ] = aAction;
615 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
616 tr( "MNU_BOTTOM_VIEW" ), 0, this);
617 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
618 connect(aAction, SIGNAL(activated()), this, SLOT(onBottomView()));
619 myActionsMap[ BottomId ] = aAction;
621 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
622 tr( "MNU_LEFT_VIEW" ), 0, this);
623 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
624 connect(aAction, SIGNAL(activated()), this, SLOT(onLeftView()));
625 myActionsMap[ LeftId ] = aAction;
627 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
628 tr( "MNU_RIGHT_VIEW" ), 0, this);
629 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
630 connect(aAction, SIGNAL(activated()), this, SLOT(onRightView()));
631 myActionsMap[ RightId ] = aAction;
634 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
635 tr( "MNU_RESET_VIEW" ), 0, this);
636 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
637 connect(aAction, SIGNAL(activated()), this, SLOT(onResetView()));
638 myActionsMap[ ResetId ] = aAction;
641 aAction = new QtxAction(tr("MNU_CLONE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CLONE_VIEW" ) ),
642 tr( "MNU_CLONE_VIEW" ), 0, this);
643 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
644 connect(aAction, SIGNAL(activated()), this, SLOT(onCloneView()));
645 myActionsMap[ CloneId ] = aAction;
647 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
648 tr( "MNU_SHOOT_VIEW" ), 0, this);
649 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
650 connect(aAction, SIGNAL(activated()), this, SLOT(onMemorizeView()));
651 myActionsMap[ MemId ] = aAction;
653 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
654 tr( "MNU_PRESETS_VIEW" ), 0, this);
655 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
656 connect(aAction, SIGNAL(activated()), this, SLOT(onRestoreView()));
657 myActionsMap[ RestoreId ] = aAction;
659 if (myModel->trihedronActivated()) {
660 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
661 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
662 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
663 connect(aAction, SIGNAL(activated()), this, SLOT(onTrihedronShow()));
664 myActionsMap[ TrihedronShowId ] = aAction;
668 //****************************************************************
669 void OCCViewer_ViewWindow::createToolBar()
671 myActionsMap[DumpId]->addTo(myToolBar);
672 myActionsMap[TrihedronShowId]->addTo(myToolBar);
674 SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar, "scale");
675 aScaleBtn->AddAction(myActionsMap[FitAllId]);
676 aScaleBtn->AddAction(myActionsMap[FitRectId]);
677 aScaleBtn->AddAction(myActionsMap[ZoomId]);
679 SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar, "pan");
680 aPanningBtn->AddAction(myActionsMap[PanId]);
681 aPanningBtn->AddAction(myActionsMap[GlobalPanId]);
683 myActionsMap[RotationId]->addTo(myToolBar);
685 SUIT_ToolButton* aViewsBtn = new SUIT_ToolButton(myToolBar, "projection");
686 aViewsBtn->AddAction(myActionsMap[FrontId]);
687 aViewsBtn->AddAction(myActionsMap[BackId]);
688 aViewsBtn->AddAction(myActionsMap[TopId]);
689 aViewsBtn->AddAction(myActionsMap[BottomId]);
690 aViewsBtn->AddAction(myActionsMap[LeftId]);
691 aViewsBtn->AddAction(myActionsMap[RightId]);
693 myActionsMap[ResetId]->addTo(myToolBar);
695 SUIT_ToolButton* aMemBtn = new SUIT_ToolButton(myToolBar, "view");
696 aMemBtn->AddAction(myActionsMap[MemId]);
697 aMemBtn->AddAction(myActionsMap[RestoreId]);
699 myToolBar->addSeparator();
700 myActionsMap[CloneId]->addTo(myToolBar);
703 //****************************************************************
704 void OCCViewer_ViewWindow::onViewFitAll()
706 myViewPort->fitAll();
709 //****************************************************************
710 void OCCViewer_ViewWindow::onFrontView()
712 emit vpTransformationStarted ( FRONTVIEW );
713 Handle(V3d_View) aView3d = myViewPort->getView();
714 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
718 //****************************************************************
719 void OCCViewer_ViewWindow::onBackView()
721 emit vpTransformationStarted ( BACKVIEW );
722 Handle(V3d_View) aView3d = myViewPort->getView();
723 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
727 //****************************************************************
728 void OCCViewer_ViewWindow::onTopView()
730 emit vpTransformationStarted ( TOPVIEW );
731 Handle(V3d_View) aView3d = myViewPort->getView();
732 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
736 //****************************************************************
737 void OCCViewer_ViewWindow::onBottomView()
739 emit vpTransformationStarted ( BOTTOMVIEW );
740 Handle(V3d_View) aView3d = myViewPort->getView();
741 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
745 //****************************************************************
746 void OCCViewer_ViewWindow::onLeftView()
748 emit vpTransformationStarted ( LEFTVIEW );
749 Handle(V3d_View) aView3d = myViewPort->getView();
750 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
754 //****************************************************************
755 void OCCViewer_ViewWindow::onRightView()
757 emit vpTransformationStarted ( RIGHTVIEW );
758 Handle(V3d_View) aView3d = myViewPort->getView();
759 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
763 //****************************************************************
764 void OCCViewer_ViewWindow::onResetView()
766 emit vpTransformationStarted( RESETVIEW );
767 myViewPort->getView()->Reset();
768 myViewPort->fitAll();
771 //****************************************************************
772 void OCCViewer_ViewWindow::onFitAll()
774 emit vpTransformationStarted( FITALLVIEW );
775 myViewPort->fitAll();
778 //****************************************************************
779 void OCCViewer_ViewWindow::onCloneView()
781 myManager->createView();
784 //****************************************************************
785 void OCCViewer_ViewWindow::onMemorizeView()
787 double centerX, centerY, projX, projY, projZ, twist;
788 double atX, atY, atZ, eyeX, eyeY, eyeZ;
790 Handle(V3d_View) aView3d = myViewPort->getView();
792 aView3d->Center( centerX, centerY );
793 aView3d->Proj( projX, projY, projZ );
794 aView3d->At( atX, atY, atZ );
795 aView3d->Eye( eyeX, eyeY, eyeZ );
796 twist = aView3d->Twist();
799 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
801 params.scale = aView3d->Scale();
802 params.centerX = centerX;
803 params.centerY = centerY;
804 params.projX = projX;
805 params.projY = projY;
806 params.projZ = projZ;
807 params.twist = twist;
816 myModel->appendViewAspect( params );
820 //****************************************************************
821 void OCCViewer_ViewWindow::onRestoreView()
823 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), myModel );
824 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
826 myModel->updateViewAspects( aDlg->parameters() );
827 if( myRestoreFlag && aDlg->parameters().count() )
828 performRestoring( aDlg->currentItem() );
831 //****************************************************************
833 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem )
835 Handle(V3d_View) aView3d = myViewPort->getView();
837 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
838 aView3d->SetScale( anItem.scale );
839 aView3d->SetCenter( anItem.centerX, anItem.centerY );
840 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
841 aView3d->SetTwist( anItem.twist );
842 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
843 aView3d->SetImmediateUpdate( prev );
844 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
849 void OCCViewer_ViewWindow::setRestoreFlag()
854 //****************************************************************
855 void OCCViewer_ViewWindow::onTrihedronShow()
857 myModel->toggleTrihedron();
860 //****************************************************************
861 QImage OCCViewer_ViewWindow::dumpView()
863 QPixmap px = QPixmap::grabWindow( myViewPort->winId() );
864 return px.convertToImage();