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"
27 #include "OCCViewer_ClippingDlg.h"
29 #include "SUIT_Desktop.h"
30 #include "SUIT_Session.h"
31 #include "SUIT_ToolButton.h"
33 #include "SUIT_Tools.h"
34 #include "SUIT_ResourceMgr.h"
35 #include "SUIT_MessageBox.h"
42 #include <qapplication.h>
43 #include <qdatetime.h>
46 #include <V3d_Plane.hxx>
50 const char* imageZoomCursor[] = {
55 "................................",
56 "................................",
57 ".#######........................",
58 "..aaaaaaa.......................",
59 "................................",
60 ".............#####..............",
61 "...........##.aaaa##............",
62 "..........#.aa.....a#...........",
63 ".........#.a.........#..........",
64 ".........#a..........#a.........",
65 "........#.a...........#.........",
66 "........#a............#a........",
67 "........#a............#a........",
68 "........#a............#a........",
69 "........#a............#a........",
70 ".........#...........#.a........",
71 ".........#a..........#a.........",
72 ".........##.........#.a.........",
73 "........#####.....##.a..........",
74 ".......###aaa#####.aa...........",
75 "......###aa...aaaaa.......#.....",
76 ".....###aa................#a....",
77 "....###aa.................#a....",
78 "...###aa...............#######..",
79 "....#aa.................aa#aaaa.",
80 ".....a....................#a....",
81 "..........................#a....",
82 "...........................a....",
83 "................................",
84 "................................",
85 "................................",
86 "................................"};
88 const char* imageRotateCursor[] = {
93 "................................",
94 "................................",
95 "................................",
96 "................................",
97 "........#.......................",
98 ".......#.a......................",
99 "......#######...................",
100 ".......#aaaaa#####..............",
101 "........#..##.a#aa##........##..",
102 ".........a#.aa..#..a#.....##.aa.",
103 ".........#.a.....#...#..##.aa...",
104 ".........#a.......#..###.aa.....",
105 "........#.a.......#a..#aa.......",
106 "........#a.........#..#a........",
107 "........#a.........#a.#a........",
108 "........#a.........#a.#a........",
109 "........#a.........#a.#a........",
110 ".........#.........#a#.a........",
111 "........##a........#a#a.........",
112 "......##.a#.......#.#.a.........",
113 "....##.aa..##.....##.a..........",
114 "..##.aa.....a#####.aa...........",
115 "...aa.........aaa#a.............",
116 "................#.a.............",
117 "...............#.a..............",
118 "..............#.a...............",
119 "...............a................",
120 "................................",
121 "................................",
122 "................................",
123 "................................",
124 "................................"};
126 const char* imageCrossCursor[] = {
131 "................................",
132 "................................",
133 "................................",
134 "................................",
135 "................................",
136 "................................",
137 "................................",
138 "...............#................",
139 "...............#a...............",
140 "...............#a...............",
141 "...............#a...............",
142 "...............#a...............",
143 "...............#a...............",
144 "...............#a...............",
145 "...............#a...............",
146 ".......#################........",
147 "........aaaaaaa#aaaaaaaaa.......",
148 "...............#a...............",
149 "...............#a...............",
150 "...............#a...............",
151 "...............#a...............",
152 "...............#a...............",
153 "...............#a...............",
154 "...............#a...............",
155 "................a...............",
156 "................................",
157 "................................",
158 "................................",
159 "................................",
160 "................................",
161 "................................",
162 "................................"};
165 //////////////////////////////////////////////////////////////////////
166 // Construction/Destruction
167 //////////////////////////////////////////////////////////////////////
169 OCCViewer_ViewWindow::OCCViewer_ViewWindow(SUIT_Desktop* theDesktop, OCCViewer_Viewer* theModel)
170 : SUIT_ViewWindow(theDesktop)
174 myEnableDrawMode = false;
175 updateEnabledDrawMode();
179 //****************************************************************
180 void OCCViewer_ViewWindow::initLayout()
182 myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
183 myViewPort->setBackgroundColor(black);
184 myViewPort->installEventFilter(this);
185 setCentralWidget(myViewPort);
186 myOperation = NOTHING;
188 setTransformRequested ( NOTHING );
189 setTransformInProcess ( false );
191 myToolBar = new QToolBar(this);
192 myToolBar->setCloseMode(QDockWindow::Undocked);
193 myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
199 //****************************************************************
200 OCCViewer_ViewWindow::OperationType OCCViewer_ViewWindow::getButtonState(QMouseEvent* theEvent)
202 OperationType aOp = NOTHING;
203 if( (theEvent->state() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::ZOOM]) &&
204 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::ZOOM]) )
206 else if( (theEvent->state() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::PAN]) &&
207 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::PAN]) )
209 else if( (theEvent->state() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::ROTATE]) &&
210 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::ROTATE]) )
216 //****************************************************************
217 bool OCCViewer_ViewWindow::eventFilter(QObject* watched, QEvent* e)
219 if ( watched == myViewPort ) {
220 int aType = e->type();
222 case QEvent::MouseButtonPress:
223 vpMousePressEvent((QMouseEvent*) e);
226 case QEvent::MouseButtonRelease:
227 vpMouseReleaseEvent((QMouseEvent*) e);
230 case QEvent::MouseMove:
231 vpMouseMoveEvent((QMouseEvent*) e);
234 case QEvent::MouseButtonDblClick:
235 emit mouseDoubleClicked(this, (QMouseEvent*)e);
240 QWheelEvent* aEvent = (QWheelEvent*) e;
241 double aDelta = aEvent->delta();
242 double aScale = (aDelta < 0) ? 100./(-aDelta) : aDelta/100.;
243 myViewPort->getView()->SetZoom(aScale);
247 case QEvent::ContextMenu:
249 QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
250 if ( aEvent->reason() != QContextMenuEvent::Mouse )
251 emit contextMenuRequested( aEvent );
259 return SUIT_ViewWindow::eventFilter(watched, e);
262 void OCCViewer_ViewWindow::updateEnabledDrawMode()
265 myEnableDrawMode = myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
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 QPixmap zoomPixmap (imageZoomCursor);
335 QCursor zoomCursor (zoomPixmap);
336 setTransformRequested ( ZOOMVIEW );
337 setCursor( zoomCursor );
342 //****************************************************************
344 Activates 'panning' transformation
346 void OCCViewer_ViewWindow::activatePanning()
348 if ( !transformRequested() && !myCursorIsHand )
349 myCursor = cursor(); // save old cursor
351 if ( myOperation != PANVIEW ) {
352 QCursor panCursor (Qt::SizeAllCursor);
353 setTransformRequested ( PANVIEW );
354 setCursor( panCursor );
358 //****************************************************************
360 Activates 'rotation' transformation
362 void OCCViewer_ViewWindow::activateRotation()
364 if ( !transformRequested() && !myCursorIsHand )
365 myCursor = cursor(); // save old cursor
367 if ( myOperation != ROTATE ) {
368 QPixmap rotatePixmap (imageRotateCursor);
369 QCursor rotCursor (rotatePixmap);
370 setTransformRequested ( ROTATE );
371 setCursor( rotCursor );
375 //****************************************************************
376 void OCCViewer_ViewWindow::activateGlobalPanning()
378 Handle(V3d_View) aView3d = myViewPort->getView();
379 if ( !aView3d.IsNull() ) {
380 QPixmap globalPanPixmap (imageCrossCursor);
381 QCursor glPanCursor (globalPanPixmap);
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 QCursor handCursor (Qt::PointingHandCursor);
402 setTransformRequested ( WINDOWFIT );
403 setCursor ( handCursor );
404 myCursorIsHand = true;
408 //****************************************************************
410 Sets the active operation 'op'
412 void OCCViewer_ViewWindow::setTransformRequested ( OperationType op )
415 myViewPort->setMouseTracking( myOperation == NOTHING );
419 //****************************************************************/
420 void OCCViewer_ViewWindow::vpMouseMoveEvent(QMouseEvent* theEvent)
422 myCurrX = theEvent->x();
423 myCurrY = theEvent->y();
424 switch (myOperation) {
426 myViewPort->rotate(myCurrX, myCurrY);
430 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
436 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
450 int aState = theEvent->state();
451 //int aButton = theEvent->button();
452 if ( aState == Qt::LeftButton ||
453 aState == ( Qt::LeftButton | Qt::ShiftButton) ) {
454 myDrawRect = myEnableDrawMode;
457 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
458 QCursor handCursor (Qt::PointingHandCursor);
459 myCursorIsHand = true;
461 setCursor( handCursor );
466 emit mouseMoving( this, theEvent );
471 //****************************************************************/
472 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
474 switch ( myOperation ) {
477 emit mouseReleased(this, theEvent);
478 if(theEvent->button() == RightButton)
480 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
481 theEvent->pos(), theEvent->globalPos(),
483 emit contextMenuRequested( &aEvent );
488 myViewPort->endRotation();
498 if ( theEvent->button() == Qt::LeftButton ) {
499 myViewPort->setCenter( theEvent->x(), theEvent->y() );
500 myViewPort->getView()->SetScale(myCurScale);
506 if ( theEvent->state() == Qt::LeftButton ) {
507 myCurrX = theEvent->x();
508 myCurrY = theEvent->y();
509 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
510 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
516 // NOTE: viewer 3D detects a rectangle of selection using this event
517 // so we must emit it BEFORE resetting the selection rectangle
519 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
523 myViewPort->update();
527 //****************************************************************
529 Sets the viewport to its initial state
530 ( no transformations in process etc. )
532 void OCCViewer_ViewWindow::resetState()
536 /* make rectangle empty (left > right) */
540 if ( transformRequested() || myCursorIsHand )
541 setCursor( myCursor );
542 myCursorIsHand = false;
544 if ( transformRequested() )
545 emit vpTransformationFinished (myOperation);
547 setTransformInProcess( false );
548 setTransformRequested( NOTHING );
552 //****************************************************************/
553 void OCCViewer_ViewWindow::drawRect()
555 QPainter aPainter(myViewPort);
556 aPainter.setRasterOp(Qt::XorROP);
557 aPainter.setPen(Qt::white);
558 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
559 if ( !myRect.isEmpty() )
560 aPainter.drawRect( myRect );
561 aPainter.drawRect(aRect);
565 //****************************************************************/
566 void OCCViewer_ViewWindow::createActions()
568 if (!myActionsMap.isEmpty()) return;
570 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
575 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
576 tr( "MNU_DUMP_VIEW" ), 0, this);
577 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
578 connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView()));
579 myActionsMap[ DumpId ] = aAction;
582 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
583 tr( "MNU_FITALL" ), 0, this);
584 aAction->setStatusTip(tr("DSC_FITALL"));
585 connect(aAction, SIGNAL(activated()), this, SLOT(onFitAll()));
586 myActionsMap[ FitAllId ] = aAction;
589 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
590 tr( "MNU_FITRECT" ), 0, this);
591 aAction->setStatusTip(tr("DSC_FITRECT"));
592 connect(aAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
593 myActionsMap[ FitRectId ] = aAction;
596 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
597 tr( "MNU_ZOOM_VIEW" ), 0, this);
598 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
599 connect(aAction, SIGNAL(activated()), this, SLOT(activateZoom()));
600 myActionsMap[ ZoomId ] = aAction;
603 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
604 tr( "MNU_PAN_VIEW" ), 0, this);
605 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
606 connect(aAction, SIGNAL(activated()), this, SLOT(activatePanning()));
607 myActionsMap[ PanId ] = aAction;
610 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
611 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
612 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
613 connect(aAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
614 myActionsMap[ GlobalPanId ] = aAction;
617 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
618 tr( "MNU_ROTATE_VIEW" ), 0, this);
619 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
620 connect(aAction, SIGNAL(activated()), this, SLOT(activateRotation()));
621 myActionsMap[ RotationId ] = aAction;
624 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
625 tr( "MNU_FRONT_VIEW" ), 0, this);
626 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
627 connect(aAction, SIGNAL(activated()), this, SLOT(onFrontView()));
628 myActionsMap[ FrontId ] = aAction;
630 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
631 tr( "MNU_BACK_VIEW" ), 0, this);
632 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
633 connect(aAction, SIGNAL(activated()), this, SLOT(onBackView()));
634 myActionsMap[ BackId ] = aAction;
636 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
637 tr( "MNU_TOP_VIEW" ), 0, this);
638 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
639 connect(aAction, SIGNAL(activated()), this, SLOT(onTopView()));
640 myActionsMap[ TopId ] = aAction;
642 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
643 tr( "MNU_BOTTOM_VIEW" ), 0, this);
644 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
645 connect(aAction, SIGNAL(activated()), this, SLOT(onBottomView()));
646 myActionsMap[ BottomId ] = aAction;
648 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
649 tr( "MNU_LEFT_VIEW" ), 0, this);
650 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
651 connect(aAction, SIGNAL(activated()), this, SLOT(onLeftView()));
652 myActionsMap[ LeftId ] = aAction;
654 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
655 tr( "MNU_RIGHT_VIEW" ), 0, this);
656 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
657 connect(aAction, SIGNAL(activated()), this, SLOT(onRightView()));
658 myActionsMap[ RightId ] = aAction;
661 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
662 tr( "MNU_RESET_VIEW" ), 0, this);
663 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
664 connect(aAction, SIGNAL(activated()), this, SLOT(onResetView()));
665 myActionsMap[ ResetId ] = aAction;
668 aAction = new QtxAction(tr("MNU_CLONE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CLONE_VIEW" ) ),
669 tr( "MNU_CLONE_VIEW" ), 0, this);
670 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
671 connect(aAction, SIGNAL(activated()), this, SLOT(onCloneView()));
672 myActionsMap[ CloneId ] = aAction;
674 aAction = new QtxAction(tr("MNU_CLIPPING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CLIPPING" ) ),
675 tr( "MNU_CLIPPING" ), 0, this);
676 aAction->setStatusTip(tr("DSC_CLIPPING"));
677 aAction->setToggleAction( true );
678 connect(aAction, SIGNAL(toggled( bool )), this, SLOT(onClipping( bool )));
679 myActionsMap[ ClippingId ] = aAction;
681 aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
682 tr( "MNU_SHOOT_VIEW" ), 0, this);
683 aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
684 connect(aAction, SIGNAL(activated()), this, SLOT(onMemorizeView()));
685 myActionsMap[ MemId ] = aAction;
687 aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
688 tr( "MNU_PRESETS_VIEW" ), 0, this);
689 aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
690 connect(aAction, SIGNAL(activated()), this, SLOT(onRestoreView()));
691 myActionsMap[ RestoreId ] = aAction;
693 if (myModel->trihedronActivated()) {
694 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
695 tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
696 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
697 connect(aAction, SIGNAL(activated()), this, SLOT(onTrihedronShow()));
698 myActionsMap[ TrihedronShowId ] = aAction;
702 //****************************************************************
703 void OCCViewer_ViewWindow::createToolBar()
705 myActionsMap[DumpId]->addTo(myToolBar);
706 if ( myModel->trihedronActivated() )
707 myActionsMap[TrihedronShowId]->addTo(myToolBar);
709 SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar, "scale");
710 aScaleBtn->AddAction(myActionsMap[FitAllId]);
711 aScaleBtn->AddAction(myActionsMap[FitRectId]);
712 aScaleBtn->AddAction(myActionsMap[ZoomId]);
714 SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar, "pan");
715 aPanningBtn->AddAction(myActionsMap[PanId]);
716 aPanningBtn->AddAction(myActionsMap[GlobalPanId]);
718 myActionsMap[RotationId]->addTo(myToolBar);
720 SUIT_ToolButton* aViewsBtn = new SUIT_ToolButton(myToolBar, "projection");
721 aViewsBtn->AddAction(myActionsMap[FrontId]);
722 aViewsBtn->AddAction(myActionsMap[BackId]);
723 aViewsBtn->AddAction(myActionsMap[TopId]);
724 aViewsBtn->AddAction(myActionsMap[BottomId]);
725 aViewsBtn->AddAction(myActionsMap[LeftId]);
726 aViewsBtn->AddAction(myActionsMap[RightId]);
728 myActionsMap[ResetId]->addTo(myToolBar);
730 SUIT_ToolButton* aMemBtn = new SUIT_ToolButton(myToolBar, "view");
731 aMemBtn->AddAction(myActionsMap[MemId]);
732 aMemBtn->AddAction(myActionsMap[RestoreId]);
734 myToolBar->addSeparator();
735 myActionsMap[CloneId]->addTo(myToolBar);
737 myToolBar->addSeparator();
738 myActionsMap[ClippingId]->addTo(myToolBar);
741 //****************************************************************
742 void OCCViewer_ViewWindow::onViewFitAll()
744 myViewPort->fitAll();
747 //****************************************************************
748 void OCCViewer_ViewWindow::onFrontView()
750 emit vpTransformationStarted ( FRONTVIEW );
751 Handle(V3d_View) aView3d = myViewPort->getView();
752 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
756 //****************************************************************
757 void OCCViewer_ViewWindow::onBackView()
759 emit vpTransformationStarted ( BACKVIEW );
760 Handle(V3d_View) aView3d = myViewPort->getView();
761 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
765 //****************************************************************
766 void OCCViewer_ViewWindow::onTopView()
768 emit vpTransformationStarted ( TOPVIEW );
769 Handle(V3d_View) aView3d = myViewPort->getView();
770 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
774 //****************************************************************
775 void OCCViewer_ViewWindow::onBottomView()
777 emit vpTransformationStarted ( BOTTOMVIEW );
778 Handle(V3d_View) aView3d = myViewPort->getView();
779 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
783 //****************************************************************
784 void OCCViewer_ViewWindow::onLeftView()
786 emit vpTransformationStarted ( LEFTVIEW );
787 Handle(V3d_View) aView3d = myViewPort->getView();
788 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
792 //****************************************************************
793 void OCCViewer_ViewWindow::onRightView()
795 emit vpTransformationStarted ( RIGHTVIEW );
796 Handle(V3d_View) aView3d = myViewPort->getView();
797 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
801 //****************************************************************
802 void OCCViewer_ViewWindow::onResetView()
804 emit vpTransformationStarted( RESETVIEW );
805 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
806 myViewPort->getView()->Reset( false );
807 myViewPort->fitAll( false, true, false );
808 myViewPort->getView()->SetImmediateUpdate( upd );
809 myViewPort->getView()->Update();
812 //****************************************************************
813 void OCCViewer_ViewWindow::onFitAll()
815 emit vpTransformationStarted( FITALLVIEW );
816 myViewPort->fitAll();
819 //****************************************************************
820 void OCCViewer_ViewWindow::onCloneView()
822 SUIT_ViewWindow* vw = myManager->createViewWindow();
826 //****************************************************************
827 void OCCViewer_ViewWindow::onClipping( bool on )
829 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
831 myActionsMap[ ClippingId ]->setIconSet(aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CLIPPING_PRESSED" )));
833 myActionsMap[ ClippingId ]->setIconSet(aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CLIPPING" )));
837 if ( !myClippingDlg )
838 myClippingDlg = new OCCViewer_ClippingDlg( this, myDesktop );
840 if ( !myClippingDlg->isShown() )
841 myClippingDlg->show();
845 if ( myClippingDlg->isShown() )
846 myClippingDlg->hide();
847 setCuttingPlane(false);
851 //****************************************************************
852 void OCCViewer_ViewWindow::onMemorizeView()
854 double centerX, centerY, projX, projY, projZ, twist;
855 double atX, atY, atZ, eyeX, eyeY, eyeZ;
857 Handle(V3d_View) aView3d = myViewPort->getView();
859 aView3d->Center( centerX, centerY );
860 aView3d->Proj( projX, projY, projZ );
861 aView3d->At( atX, atY, atZ );
862 aView3d->Eye( eyeX, eyeY, eyeZ );
863 twist = aView3d->Twist();
866 QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
868 params.scale = aView3d->Scale();
869 params.centerX = centerX;
870 params.centerY = centerY;
871 params.projX = projX;
872 params.projY = projY;
873 params.projZ = projZ;
874 params.twist = twist;
883 myModel->appendViewAspect( params );
887 //****************************************************************
888 void OCCViewer_ViewWindow::onRestoreView()
890 OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), myModel );
891 connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
893 myModel->updateViewAspects( aDlg->parameters() );
894 if( myRestoreFlag && aDlg->parameters().count() )
895 performRestoring( aDlg->currentItem() );
898 //****************************************************************
900 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem )
902 Handle(V3d_View) aView3d = myViewPort->getView();
904 Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
905 aView3d->SetScale( anItem.scale );
906 aView3d->SetCenter( anItem.centerX, anItem.centerY );
907 aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
908 aView3d->SetTwist( anItem.twist );
909 aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
910 aView3d->SetImmediateUpdate( prev );
911 aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
916 void OCCViewer_ViewWindow::setRestoreFlag()
921 //****************************************************************
922 void OCCViewer_ViewWindow::onTrihedronShow()
924 myModel->toggleTrihedron();
927 //****************************************************************
928 QImage OCCViewer_ViewWindow::dumpView()
930 QPixmap px = QPixmap::grabWindow( myViewPort->winId() );
931 return px.convertToImage();
934 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const double y, const double z,
935 const double dx, const double dy, const double dz )
938 Handle(V3d_Viewer) viewer = myViewPort->getViewer();
939 Handle(V3d_View) view = myViewPort->getView();
941 // try to use already existing plane or create a new one
942 Handle(V3d_Plane) clipPlane;
943 view->InitActivePlanes();
944 if ( view->MoreActivePlanes() )
945 clipPlane = view->ActivePlane();
947 clipPlane = new V3d_Plane( viewer );
949 // set new a,b,c,d values for the plane
950 gp_Pln pln( gp_Pnt( x, y, z ), gp_Dir( dx, dy, dz ) );
952 pln.Coefficients( a, b, c, d );
953 clipPlane->SetPlane( a, b, c, d );
955 Handle(V3d_View) v = myViewPort->getView();
956 v->SetPlaneOn( clipPlane );
961 Handle(V3d_View) view = myViewPort->getView();
963 // try to use already existing plane
964 Handle(V3d_Plane) clipPlane;
965 view->InitActivePlanes();
966 if ( view->MoreActivePlanes() )
967 clipPlane = view->ActivePlane();
969 Handle(V3d_View) v = myViewPort->getView();
970 if ( !clipPlane.IsNull() )
971 v->SetPlaneOff( clipPlane );
979 Handle(V3d_View) v = myViewPort->getView();