1 #include "XGUI_ViewWindow.h"
2 #include "XGUI_ViewPort.h"
3 #include "XGUI_Viewer.h"
4 #include "XGUI_Tools.h"
5 #include "XGUI_RubberBand.h"
11 #include <QResizeEvent>
12 #include <QApplication>
14 #include <QMdiSubWindow>
17 #include <QFileDialog>
19 #include <TopoDS_Shape.hxx>
20 #include <BRep_Tool.hxx>
22 #include <Visual3d_View.hxx>
26 const char* imageZoomCursor[] = { "32 32 3 1", ". c None", "a c #000000", "# c #ffffff",
27 "................................", "................................",
28 ".#######........................", "..aaaaaaa.......................",
29 "................................", ".............#####..............",
30 "...........##.aaaa##............", "..........#.aa.....a#...........",
31 ".........#.a.........#..........", ".........#a..........#a.........",
32 "........#.a...........#.........", "........#a............#a........",
33 "........#a............#a........", "........#a............#a........",
34 "........#a............#a........", ".........#...........#.a........",
35 ".........#a..........#a.........", ".........##.........#.a.........",
36 "........#####.....##.a..........", ".......###aaa#####.aa...........",
37 "......###aa...aaaaa.......#.....", ".....###aa................#a....",
38 "....###aa.................#a....", "...###aa...............#######..",
39 "....#aa.................aa#aaaa.", ".....a....................#a....",
40 "..........................#a....", "...........................a....",
41 "................................", "................................",
42 "................................", "................................" };
44 const char* imageRotateCursor[] = { "32 32 3 1", ". c None", "a c #000000", "# c #ffffff",
45 "................................", "................................",
46 "................................", "................................",
47 "........#.......................", ".......#.a......................",
48 "......#######...................", ".......#aaaaa#####..............",
49 "........#..##.a#aa##........##..", ".........a#.aa..#..a#.....##.aa.",
50 ".........#.a.....#...#..##.aa...", ".........#a.......#..###.aa.....",
51 "........#.a.......#a..#aa.......", "........#a.........#..#a........",
52 "........#a.........#a.#a........", "........#a.........#a.#a........",
53 "........#a.........#a.#a........", ".........#.........#a#.a........",
54 "........##a........#a#a.........", "......##.a#.......#.#.a.........",
55 "....##.aa..##.....##.a..........", "..##.aa.....a#####.aa...........",
56 "...aa.........aaa#a.............", "................#.a.............",
57 "...............#.a..............", "..............#.a...............",
58 "...............a................", "................................",
59 "................................", "................................",
60 "................................", "................................" };
62 const char* imageCrossCursor[] = { "32 32 3 1", ". c None", "a c #000000", "# c #ffffff",
63 "................................", "................................",
64 "................................", "................................",
65 "................................", "................................",
66 "................................", "...............#................",
67 "...............#a...............", "...............#a...............",
68 "...............#a...............", "...............#a...............",
69 "...............#a...............", "...............#a...............",
70 "...............#a...............", ".......#################........",
71 "........aaaaaaa#aaaaaaaaa.......", "...............#a...............",
72 "...............#a...............", "...............#a...............",
73 "...............#a...............", "...............#a...............",
74 "...............#a...............", "...............#a...............",
75 "................a...............", "................................",
76 "................................", "................................",
77 "................................", "................................",
78 "................................", "................................" };
80 //**************************************************************************
81 void ViewerToolbar::paintEvent(QPaintEvent* theEvent)
86 QRect aVPRect = myVPort->rect();
87 QPoint aGlobPnt = mapToGlobal(aRect.topLeft());
88 QPoint aPnt = myVPort->mapFromGlobal(aGlobPnt);
91 QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(), aRect.width(), aRect.height()));
92 QPainter(this).drawImage(aRect, myVPort->dumpView(aImgRect, false));
93 //QString aMsg = QString("### Painted in %1").arg(aTime.elapsed());
94 //qDebug(qPrintable(aMsg));
97 //**************************************************************************
98 void ViewerLabel::paintEvent(QPaintEvent* theEvent)
100 QRect aRect = rect();
101 QRect aVPRect = myVPort->rect();
102 QPoint aGlobPnt = mapToGlobal(aRect.topLeft());
103 QPoint aPnt = myVPort->mapFromGlobal(aGlobPnt);
106 QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(), aRect.width(), aRect.height()));
107 QPainter(this).drawImage(aRect, myVPort->dumpView(aImgRect, false));
108 QLabel::paintEvent(theEvent);
111 //**************************************************************************
112 //**************************************************************************
113 //**************************************************************************
114 XGUI_ViewWindow::XGUI_ViewWindow(XGUI_Viewer* theViewer, V3d_TypeOfView theType)
118 MinimizeIco(":pictures/wnd_minimize.png"),
119 MaximizeIco(":pictures/wnd_maximize.png"),
120 CloseIco(":pictures/wnd_close.png"),
121 RestoreIco(":pictures/wnd_restore.png"),
122 myInteractionStyle(XGUI::STANDARD),
125 my2dMode(XGUI::No2dMode),
126 myCurrPointType(XGUI::GRAVITY),
127 myPrevPointType(XGUI::GRAVITY),
128 myRotationPointSelection(false),
131 mySelectedPoint = gp_Pnt(0., 0., 0.);
132 setFrameStyle(QFrame::Raised);
133 setFrameShape(QFrame::Panel);
134 setLineWidth(BORDER_SIZE);
135 setMouseTracking(true);
137 QVBoxLayout* aLay = new QVBoxLayout(this);
138 aLay->setContentsMargins(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE);
139 myViewPort = new XGUI_ViewPort(this, myViewer->v3dViewer(), theType);
140 myViewPort->installEventFilter(this);
141 aLay->addWidget(myViewPort);
143 myPicture = new QLabel(this);
144 myPicture->setFrameStyle(QFrame::Sunken);
145 myPicture->setFrameShape(QFrame::Panel);
146 myPicture->setMouseTracking(true);
147 myPicture->installEventFilter(this);
148 aLay->addWidget(myPicture);
151 myGripWgt = new ViewerLabel(this, myViewPort);
152 myGripWgt->setPixmap(QPixmap(":pictures/wnd_grip.png"));
153 myGripWgt->setGeometry(BORDER_SIZE + 2, BORDER_SIZE + 2, 19, 32);
154 myGripWgt->setMouseTracking(true);
155 myGripWgt->installEventFilter(this);
156 connect(myViewPort, SIGNAL(vpTransformed()), myGripWgt, SLOT(update()));
157 connect(myViewPort, SIGNAL(vpUpdated()), myGripWgt, SLOT(update()));
159 // Create Viewer management buttons
160 myViewBar = new ViewerToolbar(this, myViewPort);
165 aBtn = new QAction(QIcon(":pictures/occ_view_camera_dump.png"), tr("DUMP_VIEW"), myViewBar);
166 connect(aBtn, SIGNAL(triggered()), SLOT(dumpView()));
167 myViewBar->addAction(aBtn);
169 aBtn = new QAction(QIcon(":pictures/occ_view_fitall.png"), tr("FIT_ALL"), myViewBar);
170 connect(aBtn, SIGNAL(triggered()), SLOT(fitAll()));
171 myViewBar->addAction(aBtn);
173 aBtn = new QAction(QIcon(":pictures/occ_view_fitarea.png"), tr("FIT_AREA"), myViewBar);
174 connect(aBtn, SIGNAL(triggered()), SLOT(activateWindowFit()));
175 myViewBar->addAction(aBtn);
177 aBtn = new QAction(QIcon(":pictures/occ_view_zoom.png"), tr("ZOOM_VIEW"), myViewBar);
178 connect(aBtn, SIGNAL(triggered()), SLOT(activateZoom()));
179 myViewBar->addAction(aBtn);
181 aBtn = new QAction(QIcon(":pictures/occ_view_pan.png"), tr("PAN_VIEW"), myViewBar);
182 connect(aBtn, SIGNAL(triggered()), SLOT(activatePanning()));
183 myViewBar->addAction(aBtn);
185 aBtn = new QAction(QIcon(":pictures/occ_view_glpan.png"), tr("GLOB_PAN_VIEW"), myViewBar);
186 connect(aBtn, SIGNAL(triggered()), SLOT(activateGlobalPanning()));
187 myViewBar->addAction(aBtn);
189 aBtn = new QAction(QIcon(":pictures/occ_view_rotate.png"), tr("ROTATE_VIEW"), myViewBar);
190 connect(aBtn, SIGNAL(triggered()), SLOT(activateRotation()));
191 myViewBar->addAction(aBtn);
193 aBtn = new QAction(QIcon(":pictures/occ_view_front.png"), tr("FRONT_VIEW"), myViewBar);
194 connect(aBtn, SIGNAL(triggered()), SLOT(frontView()));
195 myViewBar->addAction(aBtn);
197 aBtn = new QAction(QIcon(":pictures/occ_view_back.png"), tr("BACK_VIEW"), myViewBar);
198 connect(aBtn, SIGNAL(triggered()), SLOT(backView()));
199 myViewBar->addAction(aBtn);
201 aBtn = new QAction(QIcon(":pictures/occ_view_top.png"), tr("TOP_VIEW"), myViewBar);
202 connect(aBtn, SIGNAL(triggered()), SLOT(topView()));
203 myViewBar->addAction(aBtn);
205 aBtn = new QAction(QIcon(":pictures/occ_view_bottom.png"), tr("BOTTOM_VIEW"), myViewBar);
206 connect(aBtn, SIGNAL(triggered()), SLOT(bottomView()));
207 myViewBar->addAction(aBtn);
209 aBtn = new QAction(QIcon(":pictures/occ_view_left.png"), tr("LEFT_VIEW"), myViewBar);
210 connect(aBtn, SIGNAL(triggered()), SLOT(leftView()));
211 myViewBar->addAction(aBtn);
213 aBtn = new QAction(QIcon(":pictures/occ_view_right.png"), tr("RIGHT_VIEW"), myViewBar);
214 connect(aBtn, SIGNAL(triggered()), SLOT(rightView()));
215 myViewBar->addAction(aBtn);
217 aBtn = new QAction(QIcon(":pictures/occ_view_clone.png"), tr("CLONE_VIEW"), myViewBar);
218 connect(aBtn, SIGNAL(triggered()), SLOT(cloneView()));
219 myViewBar->addAction(aBtn);
221 //Support copy of background on updating of viewer
222 connect(myViewPort, SIGNAL(vpTransformed()), myViewBar, SLOT(update()));
223 connect(myViewPort, SIGNAL(vpUpdated()), myViewBar, SLOT(update()));
225 // Create Window management buttons
226 myWindowBar = new ViewerToolbar(this, myViewPort);
227 connect(myViewPort, SIGNAL(vpTransformed()), myWindowBar, SLOT(update()));
228 connect(myViewPort, SIGNAL(vpUpdated()), myWindowBar, SLOT(update()));
230 myMinimizeBtn = new QAction(myWindowBar);
231 myMinimizeBtn->setIcon(MinimizeIco);
232 myWindowBar->addAction(myMinimizeBtn);
233 connect(myMinimizeBtn, SIGNAL(triggered()), SLOT(onMinimize()));
235 myMaximizeBtn = new QAction(myWindowBar);
236 myMaximizeBtn->setIcon(MaximizeIco);
237 myWindowBar->addAction(myMaximizeBtn);
238 connect(myMaximizeBtn, SIGNAL(triggered()), SLOT(onMaximize()));
240 aBtn = new QAction(myWindowBar);
241 aBtn->setIcon(CloseIco);
242 myWindowBar->addAction(aBtn);
243 connect(aBtn, SIGNAL(triggered()), SLOT(onClose()));
250 //****************************************************************
251 XGUI_ViewWindow::~XGUI_ViewWindow()
255 //****************************************************************
256 void XGUI_ViewWindow::resizeEvent(QResizeEvent* theEvent)
258 QSize aSize = theEvent->size();
259 QSize aWndBarSize = myWindowBar->sizeHint();
260 QSize myViewBarSize = myViewBar->sizeHint();
262 myWindowBar->move(aSize.width() - aWndBarSize.width() - BORDER_SIZE - 4,
264 int aViewBarWidth = aSize.width() - aWndBarSize.width() - myGripWgt->width() - 8;
265 if (aViewBarWidth > myViewBarSize.width())
266 aViewBarWidth = myViewBarSize.width();
267 myViewBar->setGeometry(BORDER_SIZE + 18, BORDER_SIZE + 2, aViewBarWidth, myViewBarSize.height());
270 //****************************************************************
271 void XGUI_ViewWindow::changeEvent(QEvent* theEvent)
274 if (theEvent->type() == QEvent::WindowStateChange) {
285 myMinimizeBtn->setIcon(MinimizeIco);
286 myMaximizeBtn->setIcon(RestoreIco);
290 QWidget::changeEvent(theEvent);
294 //****************************************************************
295 void XGUI_ViewWindow::onClose()
297 if (parentWidget()) {
298 emit tryClosing(this);
300 emit closed(static_cast<QMdiSubWindow*>(parentWidget()));
301 parentWidget()->close();
306 //****************************************************************
307 void XGUI_ViewWindow::enterEvent(QEvent* theEvent)
309 if (!isMinimized()) {
317 //****************************************************************
318 void XGUI_ViewWindow::leaveEvent(QEvent* theEvent)
325 //****************************************************************
326 void XGUI_ViewWindow::onMinimize()
328 QPixmap aPMap = QPixmap::fromImage(myViewPort->dumpView());
331 double aR = aW / 100.;
332 int aNewH = int(aH / aR);
333 myPicture->setPixmap(aPMap.scaled(100, aNewH));
335 myLastState = isMaximized() ? MaximizedState : NormalState;
337 parentWidget()->setGeometry(parentWidget()->x(), parentWidget()->y(),
341 //****************************************************************
342 void XGUI_ViewWindow::onMaximize()
345 myMaximizeBtn->setIcon(MaximizeIco);
349 myMaximizeBtn->setIcon(RestoreIco);
353 myMinimizeBtn->setIcon(MinimizeIco);
356 //****************************************************************
357 bool XGUI_ViewWindow::processWindowControls(QObject *theObj, QEvent *theEvent)
359 switch(theEvent->type()) {
360 case QEvent::MouseButtonPress: {
361 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
362 if ((aEvent->button() == Qt::LeftButton) && (!myMoving)) {
364 myMousePnt = aEvent->globalPos();
369 case QEvent::MouseButtonRelease: {
370 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
371 if ((aEvent->button() == Qt::LeftButton) && myMoving) {
377 case QEvent::MouseMove: {
378 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
380 QMdiSubWindow* aParent = static_cast<QMdiSubWindow*>(parentWidget());
381 QMdiArea* aMDIArea = aParent->mdiArea();
383 QPoint aPnt = aEvent->globalPos();
384 QPoint aMDIPnt = aMDIArea->mapFromGlobal(aPnt);
385 if (aMDIArea->rect().contains(aMDIPnt)) {
386 int aX = aParent->x() + (aPnt.x() - myMousePnt.x());
387 int aY = aParent->y() + (aPnt.y() - myMousePnt.y());
388 aParent->move(aX, aY);
395 case QEvent::MouseButtonDblClick:
396 if (theObj == myPicture) {
398 if (myLastState == MaximizedState)
408 //****************************************************************
409 bool XGUI_ViewWindow::processViewPort(QEvent *theEvent)
411 switch(theEvent->type()) {
412 case QEvent::MouseButtonPress:
413 vpMousePressEvent((QMouseEvent*) theEvent);
416 case QEvent::MouseButtonRelease:
417 vpMouseReleaseEvent((QMouseEvent*) theEvent);
420 case QEvent::MouseMove:
421 vpMouseMoveEvent((QMouseEvent*) theEvent);
424 case QEvent::MouseButtonDblClick:
425 emit mouseDoubleClicked(this, (QMouseEvent*) theEvent);
429 QWheelEvent* aEvent = (QWheelEvent*) theEvent;
430 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
431 double aDelta = (double)( aEvent->delta() ) / ( 15 * 8 );
434 int x1 = (int)( aEvent->x() + width()*aDelta/100 );
435 int y1 = (int)( aEvent->y() + height()*aDelta/100 );
436 myViewPort->zoom( x, y, x1, y1 );
443 //****************************************************************
444 bool XGUI_ViewWindow::eventFilter(QObject *theObj, QEvent *theEvent)
446 if ((theObj == myGripWgt) || (theObj == myPicture)) {
447 if (processWindowControls(theObj, theEvent))
449 } else if (theObj == myViewPort) {
450 if (processViewPort(theEvent))
453 return QFrame::eventFilter(theObj, theEvent);
456 //****************************************************************
457 XGUI_ViewWindow::OperationType XGUI_ViewWindow::getButtonState(
458 QMouseEvent* theEvent, XGUI::InteractionStyle theInteractionStyle)
460 OperationType aOp = NOTHING;
461 XGUI::InteractionStyle aStyle = (XGUI::InteractionStyle) theInteractionStyle;
462 if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::ZOOM])
463 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::ZOOM]))
465 else if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::PAN])
466 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::PAN]))
468 else if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::ROTATE])
469 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::ROTATE])
470 && (my2dMode == XGUI::No2dMode))
476 //****************************************************************
477 void XGUI_ViewWindow::vpMousePressEvent(QMouseEvent* theEvent)
479 myStartX = theEvent->x();
480 myStartY = theEvent->y();
481 XGUI::InteractionStyle anInteractionStyle = interactionStyle();
483 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
484 // which are assigned for pan and rotate - these operations are activated immediately after pressing
485 // of the first button, so it is necessary to switch to zoom when the second button is pressed
486 bool aSwitchToZoom = false;
487 if ((anInteractionStyle == XGUI::KEY_FREE) && (myOperation == PANVIEW || myOperation == ROTATE)) {
488 aSwitchToZoom = getButtonState(theEvent, anInteractionStyle) == ZOOMVIEW;
491 switch(myOperation) {
493 if (theEvent->button() == Qt::LeftButton)
494 emit vpTransformationStarted(WINDOWFIT);
498 if (theEvent->button() == Qt::LeftButton)
499 emit vpTransformationStarted(PANGLOBAL);
503 if (theEvent->button() == Qt::LeftButton) {
504 myViewPort->startZoomAtPoint(myStartX, myStartY);
505 emit vpTransformationStarted(ZOOMVIEW);
511 myViewPort->startZoomAtPoint(myStartX, myStartY);
513 } else if (theEvent->button() == Qt::LeftButton)
514 emit vpTransformationStarted(PANVIEW);
519 myViewPort->startZoomAtPoint(myStartX, myStartY);
521 } else if (theEvent->button() == Qt::LeftButton) {
522 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
523 emit vpTransformationStarted(ROTATE);
528 /* Try to activate a transformation */
529 OperationType aState;
530 if (interactionStyle() == XGUI::STANDARD)
531 aState = getButtonState(theEvent, anInteractionStyle);
533 aState = XGUI_ViewWindow::NOTHING;
538 myViewPort->startZoomAtPoint(myStartX, myStartY);
546 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
549 if (myRotationPointSelection) {
550 if (theEvent->button() == Qt::LeftButton) {
551 Handle(AIS_InteractiveContext) ic = myViewer->AISContext();
553 for(ic->InitSelected(); ic->MoreSelected(); ic->NextSelected()) {
554 TopoDS_Shape aShape = ic->SelectedShape();
555 if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX) {
556 gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(ic->SelectedShape()));
557 /*if ( mySetRotationPointDlg ) {
558 myRotationPointSelection = false;
559 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
562 myCurrPointType = myPrevPointType;
566 if (ic->NbSelected() == 0)
567 myCurrPointType = myPrevPointType;
568 //if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
569 ic->CloseAllContexts();
570 myOperation = NOTHING;
571 myViewPort->setCursor(myCursor);
572 myCursorIsHand = false;
573 myRotationPointSelection = false;
576 emit mousePressed(this, theEvent);
579 /* notify that we start a transformation */
580 if (transformRequested())
581 emit vpTransformationStarted(myOperation);
583 if (transformRequested())
584 setTransformInProcess(true);
586 /* we may need it for sketching... */
587 /* if ( l_mbPressEvent )
588 delete l_mbPressEvent;
589 l_mbPressEvent = new QMouseEvent( *theEvent );*/
592 //****************************************************************
593 void XGUI_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
595 switch(myOperation) {
597 int prevState = myCurSketch;
598 /* if(theEvent->button() == Qt::RightButton) {
599 QList<OCCViewer_ViewSketcher*>::Iterator it;
600 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it ) {
601 OCCViewer_ViewSketcher* sk = (*it);
602 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
607 emit mouseReleased(this, theEvent);
608 if (theEvent->button() == Qt::RightButton && prevState == -1) {
609 QContextMenuEvent aEvent(QContextMenuEvent::Mouse, theEvent->pos(), theEvent->globalPos());
610 emit contextMenuRequested(&aEvent);
615 myViewPort->endRotation();
625 if (theEvent->button() == Qt::LeftButton) {
626 myViewPort->setCenter(theEvent->x(), theEvent->y());
627 myViewPort->getView()->SetScale(myCurScale);
633 if (theEvent->button() == Qt::LeftButton) {
634 myCurrX = theEvent->x();
635 myCurrY = theEvent->y();
637 QRect rect = makeRect(myStartX, myStartY, myCurrX, myCurrY);
639 myViewPort->fitRect(rect);
646 // NOTE: viewer 3D detects a rectangle of selection using this event
647 // so we must emit it BEFORE resetting the selection rectangle
648 if (theEvent->button() == Qt::LeftButton && myDrawRect) {
652 myViewPort->update();
654 /* if ( l_mbPressEvent ) {
655 delete l_mbPressEvent;
660 //****************************************************************
661 void XGUI_ViewWindow::vpMouseMoveEvent(QMouseEvent* theEvent)
663 if (myIsKeyFree && interactionStyle() == XGUI::KEY_FREE) {
665 switch(getButtonState(theEvent, interactionStyle())) {
667 myViewPort->startZoomAtPoint(myStartX, myStartY);
675 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
682 myCurrX = theEvent->x();
683 myCurrY = theEvent->y();
684 switch(myOperation) {
686 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
690 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
696 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
705 if (myRotationPointSelection /*|| isSketcherStyle()*/) {
706 emit mouseMoving(this, theEvent);
708 int aState = theEvent->modifiers();
709 int aButton = theEvent->buttons();
710 int anInteractionStyle = interactionStyle();
711 if (((anInteractionStyle == XGUI::STANDARD) && (aButton == Qt::LeftButton)
712 && (aState == Qt::NoModifier || Qt::ShiftModifier))
713 || ((anInteractionStyle == XGUI::KEY_FREE) && (aButton == Qt::LeftButton)
714 && (aState == Qt::ControlModifier
715 || aState == (Qt::ControlModifier | Qt::ShiftModifier)))) {
716 myDrawRect = myEnableDrawMode;
719 if (!myCursorIsHand) { // we are going to sketch a rectangle
720 QCursor handCursor(Qt::PointingHandCursor);
721 myCursorIsHand = true;
723 myViewPort->setCursor(handCursor);
726 emit mouseMoving(this, theEvent);
727 } /* else if ( ( (anInteractionStyle == XGUI::STANDARD) &&
728 (aButton == Qt::RightButton) &&
729 ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
730 ( (anInteractionStyle == XGUI::KEY_FREE) &&
731 (aButton == Qt::RightButton) &&
732 ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
733 OCCViewer_ViewSketcher* sketcher = 0;
734 QList<OCCViewer_ViewSketcher*>::Iterator it;
735 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it ) {
736 OCCViewer_ViewSketcher* sk = (*it);
737 if( sk->isDefault() && sk->sketchButton() == aButton )
740 if ( sketcher && myCurSketch == -1 ) {
741 activateSketching( sketcher->type() );
743 myCurSketch = mypSketcher->sketchButton();
745 if ( l_mbPressEvent ) {
746 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
747 delete l_mbPressEvent;
750 QApplication::sendEvent( getViewPort(), theEvent );
754 emit mouseMoving(this, theEvent);
760 \brief Draw rubber band rectangle.
762 void XGUI_ViewWindow::drawRect()
765 myRectBand = new XGUI_RectRubberBand(myViewPort);
768 myRectBand->setUpdatesEnabled(false);
769 QRect aRect = makeRect(myStartX, myStartY, myCurrX, myCurrY);
770 myRectBand->initGeometry(aRect);
772 if (!myRectBand->isVisible())
775 myRectBand->setUpdatesEnabled(true);
779 \brief Clear rubber band rectangle on the end on the dragging operation.
781 void XGUI_ViewWindow::endDrawRect()
784 myRectBand->clearGeometry();
789 void XGUI_ViewWindow::activateZoom()
791 if (!transformRequested() && !myCursorIsHand)
792 myCursor = cursor(); /* save old cursor */
794 if (myOperation != ZOOMVIEW) {
795 QPixmap zoomPixmap(imageZoomCursor);
796 QCursor zoomCursor(zoomPixmap);
797 if (setTransformRequested(ZOOMVIEW))
798 myViewPort->setCursor(zoomCursor);
802 bool XGUI_ViewWindow::transformRequested() const
804 return (myOperation != NOTHING);
808 \brief Start delayed viewer operation.
810 bool XGUI_ViewWindow::setTransformRequested(OperationType op)
812 bool ok = transformEnabled(op);
813 myOperation = ok ? op : NOTHING;
814 myViewPort->setMouseTracking(myOperation == NOTHING);
819 Set enabled state of transformation (rotate, zoom, etc)
821 void XGUI_ViewWindow::setTransformEnabled(const OperationType id, const bool on)
824 myStatus.insert(id, on);
828 \return enabled state of transformation (rotate, zoom, etc)
830 bool XGUI_ViewWindow::transformEnabled(const OperationType id) const
832 return myStatus.contains(id) ? myStatus[id] : true;
836 \brief Start panning operation.
838 Sets the corresponding cursor for the widget.
840 void XGUI_ViewWindow::activatePanning()
842 if (!transformRequested() && !myCursorIsHand)
843 myCursor = cursor(); // save old cursor
845 if (myOperation != PANVIEW) {
846 QCursor panCursor(Qt::SizeAllCursor);
847 if (setTransformRequested(PANVIEW))
848 myViewPort->setCursor(panCursor);
853 \brief Start global panning operation
855 Sets the corresponding cursor for the widget.
857 void XGUI_ViewWindow::activateGlobalPanning()
859 Handle(V3d_View) aView3d = myViewPort->getView();
860 if ( !aView3d.IsNull() ) {
861 QPixmap globalPanPixmap (imageCrossCursor);
862 QCursor glPanCursor (globalPanPixmap);
863 myCurScale = aView3d->Scale();
864 aView3d->FitAll(0.01, false);
865 myCursor = cursor(); // save old cursor
866 myViewPort->fitAll(); // fits view before selecting a new scene center
867 if( setTransformRequested( PANGLOBAL ) )
868 myViewPort->setCursor( glPanCursor );
873 \brief Start rotation operation
875 Sets the corresponding cursor for the widget.
877 void XGUI_ViewWindow::activateRotation()
879 if (!transformRequested() && !myCursorIsHand)
880 myCursor = cursor(); // save old cursor
882 if (myOperation != ROTATE) {
883 QPixmap rotatePixmap(imageRotateCursor);
884 QCursor rotCursor(rotatePixmap);
885 if (setTransformRequested(ROTATE))
886 myViewPort->setCursor(rotCursor);
891 \brief Reset the viewport to its initial state
892 ( no transformations in process etc. )
894 void XGUI_ViewWindow::resetState()
898 if (myRotationPointSelection) {
899 QCursor handCursor(Qt::PointingHandCursor);
900 myViewPort->setCursor(handCursor);
902 if (transformRequested() || myCursorIsHand)
903 myViewPort->setCursor(myCursor);
904 myCursorIsHand = false;
907 if (transformRequested())
908 emit vpTransformationFinished(myOperation);
910 setTransformInProcess(false);
911 setTransformRequested(NOTHING);
914 XGUI_ViewBackground XGUI_ViewWindow::background() const
916 return myViewPort ? myViewPort->background() : XGUI_ViewBackground();
919 void XGUI_ViewWindow::setBackground(const XGUI_ViewBackground& theBackground)
922 myViewPort->setBackground( theBackground );
926 \brief Create one more window with same content.
928 void XGUI_ViewWindow::cloneView()
930 QMdiSubWindow* vw = myViewer->createView();
932 emit viewCloned( vw );
935 void XGUI_ViewWindow::dumpView()
937 QString aFilter(tr("OCC_IMAGE_FILES"));
938 QString aSelectedFilter;
939 QString aFileName = QFileDialog::getSaveFileName(this, "Save picture", QString(), aFilter, &aSelectedFilter);
940 if (!aFileName.isNull()) {
941 QApplication::setOverrideCursor( Qt::WaitCursor );
942 QImage aPicture = myViewPort->dumpView();
944 QString aFmt = extension(aFileName).toUpper();
946 aFmt = QString( "BMP" ); // default format
947 else if( aFmt == "JPG" )
950 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
952 a3dView->Export(strdup(qPrintable(aFileName)), Graphic3d_EF_PostScript);
953 else if (aFmt == "EPS")
954 a3dView->Export(strdup(qPrintable(aFileName)), Graphic3d_EF_EnhPostScript);
956 aPicture.save( aFileName, aFmt.toLatin1() );
957 QApplication::restoreOverrideCursor();
961 void XGUI_ViewWindow::fitAll()
963 emit vpTransformationStarted( FITALLVIEW );
964 myViewPort->fitAll();
965 emit vpTransformationFinished( FITALLVIEW );
969 \brief Starts fit operation.
971 Sets the corresponding cursor for the widget.
973 void XGUI_ViewWindow::activateWindowFit()
975 if ( !transformRequested() && !myCursorIsHand )
976 myCursor = cursor(); /* save old cursor */
978 if ( myOperation != WINDOWFIT ) {
979 QCursor handCursor (Qt::PointingHandCursor);
980 if( setTransformRequested ( WINDOWFIT ) )
982 myViewPort->setCursor ( handCursor );
983 myCursorIsHand = true;
990 \brief Perform "front view" transformation.
992 void XGUI_ViewWindow::frontView()
994 emit vpTransformationStarted ( FRONTVIEW );
995 Handle(V3d_View) aView3d = myViewPort->getView();
996 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
997 myViewPort->fitAll();
998 emit vpTransformationFinished ( FRONTVIEW );
1002 \brief Perform "back view" transformation.
1004 void XGUI_ViewWindow::backView()
1006 emit vpTransformationStarted ( BACKVIEW );
1007 Handle(V3d_View) aView3d = myViewPort->getView();
1008 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
1009 myViewPort->fitAll();
1010 emit vpTransformationFinished ( BACKVIEW );
1014 \brief Perform "top view" transformation.
1016 void XGUI_ViewWindow::topView()
1018 emit vpTransformationStarted ( TOPVIEW );
1019 Handle(V3d_View) aView3d = myViewPort->getView();
1020 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
1021 myViewPort->fitAll();
1022 emit vpTransformationFinished ( TOPVIEW );
1026 \brief Perform "bottom view" transformation.
1028 void XGUI_ViewWindow::bottomView()
1030 emit vpTransformationStarted ( BOTTOMVIEW );
1031 Handle(V3d_View) aView3d = myViewPort->getView();
1032 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
1033 myViewPort->fitAll();
1034 emit vpTransformationFinished ( BOTTOMVIEW );
1038 \brief Perform "left view" transformation.
1040 void XGUI_ViewWindow::leftView()
1042 emit vpTransformationStarted ( LEFTVIEW );
1043 Handle(V3d_View) aView3d = myViewPort->getView();
1044 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
1045 myViewPort->fitAll();
1046 emit vpTransformationFinished ( LEFTVIEW );
1050 \brief Perform "right view" transformation.
1052 void XGUI_ViewWindow::rightView()
1054 emit vpTransformationStarted ( RIGHTVIEW );
1055 Handle(V3d_View) aView3d = myViewPort->getView();
1056 if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
1057 myViewPort->fitAll();
1058 emit vpTransformationFinished ( RIGHTVIEW );