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::repaintBackground()
84 QRect aVPRect = myVPort->rect();
85 QPoint aGlobPnt = mapToGlobal(aRect.topLeft());
86 QPoint aPnt = myVPort->mapFromGlobal(aGlobPnt);
88 QRect aImgRect(QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(),
89 aRect.width(), aRect.height()));
90 QPainter(this).drawImage(aRect, myVPort->dumpView(aImgRect, false));
93 void ViewerToolbar::paintEvent(QPaintEvent* theEvent)
96 //QToolBar::paintEvent(theEvent);
99 //**************************************************************************
100 void ViewerLabel::repaintBackground()
102 QRect aRect = rect();
103 QRect aVPRect = myVPort->rect();
104 QPoint aGlobPnt = mapToGlobal(aRect.topLeft());
105 QPoint aPnt = myVPort->mapFromGlobal(aGlobPnt);
107 QRect aImgRect(QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(),
108 aRect.width(), aRect.height()));
109 QPainter(this).drawImage(aRect, myVPort->dumpView(aImgRect, false));
112 void ViewerLabel::paintEvent(QPaintEvent* theEvent)
115 QLabel::paintEvent(theEvent);
118 //**************************************************************************
119 //**************************************************************************
120 //**************************************************************************
121 XGUI_ViewWindow::XGUI_ViewWindow(XGUI_Viewer* theViewer, V3d_TypeOfView theType)
125 MinimizeIco(":pictures/wnd_minimize.png"),
126 MaximizeIco(":pictures/wnd_maximize.png"),
127 CloseIco(":pictures/wnd_close.png"),
128 RestoreIco(":pictures/wnd_restore.png"),
129 myInteractionStyle(XGUI::STANDARD),
132 my2dMode(XGUI::No2dMode),
133 myCurrPointType(XGUI::GRAVITY),
134 myPrevPointType(XGUI::GRAVITY),
135 myRotationPointSelection(false),
138 mySelectedPoint = gp_Pnt(0., 0., 0.);
139 setFrameStyle(QFrame::Raised);
140 setFrameShape(QFrame::Panel);
141 setLineWidth(BORDER_SIZE);
142 setMouseTracking(true);
144 QVBoxLayout* aLay = new QVBoxLayout(this);
145 aLay->setContentsMargins(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE);
146 myViewPort = new XGUI_ViewPort(this, myViewer->v3dViewer(), theType);
147 myViewPort->installEventFilter(this);
148 aLay->addWidget(myViewPort);
150 myPicture = new QLabel(this);
151 myPicture->setFrameStyle(QFrame::Sunken);
152 myPicture->setFrameShape(QFrame::Panel);
153 myPicture->setMouseTracking(true);
154 myPicture->installEventFilter(this);
155 aLay->addWidget(myPicture);
158 myGripWgt = new ViewerLabel(this, myViewPort);
159 myGripWgt->setPixmap(QPixmap(":pictures/wnd_grip.png"));
160 myGripWgt->setGeometry(BORDER_SIZE + 2, BORDER_SIZE + 2, 19, 32);
161 myGripWgt->setMouseTracking(true);
162 myGripWgt->installEventFilter(this);
164 // Create Viewer management buttons
165 myViewBar = new ViewerToolbar(this, myViewPort);
170 aBtn = new QAction(QIcon(":pictures/occ_view_camera_dump.png"), tr("Dump view"), myViewBar);
171 connect(aBtn, SIGNAL(triggered()), SLOT(dumpView()));
172 myViewBar->addAction(aBtn);
174 aBtn = new QAction(QIcon(":pictures/occ_view_fitall.png"), tr("Fit all"), myViewBar);
175 connect(aBtn, SIGNAL(triggered()), SLOT(fitAll()));
176 myViewBar->addAction(aBtn);
178 aBtn = new QAction(QIcon(":pictures/occ_view_fitarea.png"), tr("Fit area"), myViewBar);
179 connect(aBtn, SIGNAL(triggered()), SLOT(activateWindowFit()));
180 myViewBar->addAction(aBtn);
182 aBtn = new QAction(QIcon(":pictures/occ_view_zoom.png"), tr("Zoom"), myViewBar);
183 connect(aBtn, SIGNAL(triggered()), SLOT(activateZoom()));
184 myViewBar->addAction(aBtn);
186 aBtn = new QAction(QIcon(":pictures/occ_view_pan.png"), tr("Panning"), myViewBar);
187 connect(aBtn, SIGNAL(triggered()), SLOT(activatePanning()));
188 myViewBar->addAction(aBtn);
190 aBtn = new QAction(QIcon(":pictures/occ_view_glpan.png"), tr("Global panning"), myViewBar);
191 connect(aBtn, SIGNAL(triggered()), SLOT(activateGlobalPanning()));
192 myViewBar->addAction(aBtn);
194 aBtn = new QAction(QIcon(":pictures/occ_view_rotate.png"), tr("Rotate"), myViewBar);
195 connect(aBtn, SIGNAL(triggered()), SLOT(activateRotation()));
196 myViewBar->addAction(aBtn);
198 aBtn = new QAction(QIcon(":pictures/occ_view_reset.png"), tr("Reset"), myViewBar);
199 connect(aBtn, SIGNAL(triggered()), SLOT(reset()));
200 myViewBar->addAction(aBtn);
202 aBtn = new QAction(QIcon(":pictures/occ_view_front.png"), tr("Front"), myViewBar);
203 connect(aBtn, SIGNAL(triggered()), SLOT(frontView()));
204 myViewBar->addAction(aBtn);
206 aBtn = new QAction(QIcon(":pictures/occ_view_back.png"), tr("Back"), myViewBar);
207 connect(aBtn, SIGNAL(triggered()), SLOT(backView()));
208 myViewBar->addAction(aBtn);
210 aBtn = new QAction(QIcon(":pictures/occ_view_top.png"), tr("Top"), myViewBar);
211 connect(aBtn, SIGNAL(triggered()), SLOT(topView()));
212 myViewBar->addAction(aBtn);
214 aBtn = new QAction(QIcon(":pictures/occ_view_bottom.png"), tr("Bottom"), myViewBar);
215 connect(aBtn, SIGNAL(triggered()), SLOT(bottomView()));
216 myViewBar->addAction(aBtn);
218 aBtn = new QAction(QIcon(":pictures/occ_view_left.png"), tr("Left"), myViewBar);
219 connect(aBtn, SIGNAL(triggered()), SLOT(leftView()));
220 myViewBar->addAction(aBtn);
222 aBtn = new QAction(QIcon(":pictures/occ_view_right.png"), tr("Right"), myViewBar);
223 connect(aBtn, SIGNAL(triggered()), SLOT(rightView()));
224 myViewBar->addAction(aBtn);
226 aBtn = new QAction(QIcon(":pictures/occ_view_clone.png"), tr("Clone"), myViewBar);
227 connect(aBtn, SIGNAL(triggered()), SLOT(cloneView()));
228 myViewBar->addAction(aBtn);
230 // Create Window management buttons
231 myWindowBar = new ViewerToolbar(this, myViewPort);
233 myMinimizeBtn = new QAction(myWindowBar);
234 myMinimizeBtn->setIcon(MinimizeIco);
235 myWindowBar->addAction(myMinimizeBtn);
236 connect(myMinimizeBtn, SIGNAL(triggered()), SLOT(onMinimize()));
238 myMaximizeBtn = new QAction(myWindowBar);
239 myMaximizeBtn->setIcon(MaximizeIco);
240 myWindowBar->addAction(myMaximizeBtn);
241 connect(myMaximizeBtn, SIGNAL(triggered()), SLOT(onMaximize()));
243 aBtn = new QAction(myWindowBar);
244 aBtn->setIcon(CloseIco);
245 myWindowBar->addAction(aBtn);
246 connect(aBtn, SIGNAL(triggered()), SLOT(onClose()));
252 //Support copy of background on updating of viewer
253 connect(myViewPort, SIGNAL(vpTransformed()), this, SLOT(updateToolBar()));
254 connect(myViewPort, SIGNAL(vpUpdated()), this, SLOT(updateToolBar()));
255 connect(this, SIGNAL(vpTransformationFinished(XGUI_ViewWindow::OperationType)),
256 this, SLOT(updateToolBar()));
260 //****************************************************************
261 XGUI_ViewWindow::~XGUI_ViewWindow()
265 //****************************************************************
266 void XGUI_ViewWindow::resizeEvent(QResizeEvent* theEvent)
268 QSize aSize = theEvent->size();
269 QSize aWndBarSize = myWindowBar->sizeHint();
270 QSize myViewBarSize = myViewBar->sizeHint();
272 myWindowBar->move(aSize.width() - aWndBarSize.width() - BORDER_SIZE - 4,
274 int aViewBarWidth = aSize.width() - aWndBarSize.width() - myGripWgt->width() - 8;
275 if (aViewBarWidth > myViewBarSize.width())
276 aViewBarWidth = myViewBarSize.width();
277 myViewBar->setGeometry(BORDER_SIZE + 18, BORDER_SIZE + 2, aViewBarWidth, myViewBarSize.height());
280 //****************************************************************
281 void XGUI_ViewWindow::changeEvent(QEvent* theEvent)
284 if (theEvent->type() == QEvent::WindowStateChange) {
295 myMinimizeBtn->setIcon(MinimizeIco);
296 myMaximizeBtn->setIcon(RestoreIco);
300 QWidget::changeEvent(theEvent);
304 //****************************************************************
305 void XGUI_ViewWindow::onClose()
307 if (parentWidget()) {
308 emit tryClosing(this);
310 emit closed(static_cast<QMdiSubWindow*>(parentWidget()));
311 parentWidget()->close();
316 //****************************************************************
317 void XGUI_ViewWindow::enterEvent(QEvent* theEvent)
319 if (!isMinimized()) {
327 //****************************************************************
328 void XGUI_ViewWindow::leaveEvent(QEvent* theEvent)
335 //****************************************************************
336 void XGUI_ViewWindow::onMinimize()
338 QPixmap aPMap = QPixmap::fromImage(myViewPort->dumpView());
341 double aR = aW / 100.;
342 int aNewH = int(aH / aR);
343 myPicture->setPixmap(aPMap.scaled(100, aNewH));
345 myLastState = isMaximized() ? MaximizedState : NormalState;
347 parentWidget()->setGeometry(parentWidget()->x(), parentWidget()->y(),
351 //****************************************************************
352 void XGUI_ViewWindow::onMaximize()
355 myMaximizeBtn->setIcon(MaximizeIco);
359 myMaximizeBtn->setIcon(RestoreIco);
363 myMinimizeBtn->setIcon(MinimizeIco);
366 //****************************************************************
367 bool XGUI_ViewWindow::processWindowControls(QObject *theObj, QEvent *theEvent)
369 switch(theEvent->type()) {
370 case QEvent::MouseButtonPress: {
371 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
372 if ((aEvent->button() == Qt::LeftButton) && (!myMoving)) {
374 myMousePnt = aEvent->globalPos();
379 case QEvent::MouseButtonRelease: {
380 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
381 if ((aEvent->button() == Qt::LeftButton) && myMoving) {
387 case QEvent::MouseMove: {
388 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
390 QMdiSubWindow* aParent = static_cast<QMdiSubWindow*>(parentWidget());
391 QMdiArea* aMDIArea = aParent->mdiArea();
393 QPoint aPnt = aEvent->globalPos();
394 QPoint aMDIPnt = aMDIArea->mapFromGlobal(aPnt);
395 if (aMDIArea->rect().contains(aMDIPnt)) {
396 int aX = aParent->x() + (aPnt.x() - myMousePnt.x());
397 int aY = aParent->y() + (aPnt.y() - myMousePnt.y());
398 aParent->move(aX, aY);
405 case QEvent::MouseButtonDblClick:
406 if (theObj == myPicture) {
408 if (myLastState == MaximizedState)
418 //****************************************************************
419 bool XGUI_ViewWindow::processViewPort(QEvent *theEvent)
421 switch(theEvent->type()) {
422 case QEvent::MouseButtonPress:
423 vpMousePressEvent((QMouseEvent*) theEvent);
426 case QEvent::MouseButtonRelease:
427 vpMouseReleaseEvent((QMouseEvent*) theEvent);
430 case QEvent::MouseMove:
431 vpMouseMoveEvent((QMouseEvent*) theEvent);
434 case QEvent::MouseButtonDblClick:
435 emit mouseDoubleClicked(this, (QMouseEvent*) theEvent);
439 QWheelEvent* aEvent = (QWheelEvent*) theEvent;
440 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
441 double aDelta = (double)( aEvent->delta() ) / ( 15 * 8 );
444 int x1 = (int)( aEvent->x() + width()*aDelta/100 );
445 int y1 = (int)( aEvent->y() + height()*aDelta/100 );
446 myViewPort->zoom( x, y, x1, y1 );
453 //****************************************************************
454 bool XGUI_ViewWindow::eventFilter(QObject *theObj, QEvent *theEvent)
456 if ((theObj == myGripWgt) || (theObj == myPicture)) {
457 if (processWindowControls(theObj, theEvent))
459 } else if (theObj == myViewPort) {
460 if (processViewPort(theEvent)) {
464 return QFrame::eventFilter(theObj, theEvent);
467 //****************************************************************
468 XGUI_ViewWindow::OperationType XGUI_ViewWindow::getButtonState(
469 QMouseEvent* theEvent, XGUI::InteractionStyle theInteractionStyle)
471 OperationType aOp = NOTHING;
472 XGUI::InteractionStyle aStyle = (XGUI::InteractionStyle) theInteractionStyle;
473 if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::ZOOM])
474 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::ZOOM]))
476 else if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::PAN])
477 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::PAN]))
479 else if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::ROTATE])
480 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::ROTATE])
481 && (my2dMode == XGUI::No2dMode))
487 //****************************************************************
488 void XGUI_ViewWindow::vpMousePressEvent(QMouseEvent* theEvent)
490 myStartX = theEvent->x();
491 myStartY = theEvent->y();
492 XGUI::InteractionStyle anInteractionStyle = interactionStyle();
494 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
495 // which are assigned for pan and rotate - these operations are activated immediately after pressing
496 // of the first button, so it is necessary to switch to zoom when the second button is pressed
497 bool aSwitchToZoom = false;
498 if ((anInteractionStyle == XGUI::KEY_FREE) && (myOperation == PANVIEW || myOperation == ROTATE)) {
499 aSwitchToZoom = getButtonState(theEvent, anInteractionStyle) == ZOOMVIEW;
502 switch(myOperation) {
504 if (theEvent->button() == Qt::LeftButton)
505 emit vpTransformationStarted(WINDOWFIT);
509 if (theEvent->button() == Qt::LeftButton)
510 emit vpTransformationStarted(PANGLOBAL);
514 if (theEvent->button() == Qt::LeftButton) {
515 myViewPort->startZoomAtPoint(myStartX, myStartY);
516 emit vpTransformationStarted(ZOOMVIEW);
522 myViewPort->startZoomAtPoint(myStartX, myStartY);
524 } else if (theEvent->button() == Qt::LeftButton)
525 emit vpTransformationStarted(PANVIEW);
530 myViewPort->startZoomAtPoint(myStartX, myStartY);
532 } else if (theEvent->button() == Qt::LeftButton) {
533 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
534 emit vpTransformationStarted(ROTATE);
539 /* Try to activate a transformation */
540 OperationType aState;
541 if (interactionStyle() == XGUI::STANDARD)
542 aState = getButtonState(theEvent, anInteractionStyle);
544 aState = XGUI_ViewWindow::NOTHING;
549 myViewPort->startZoomAtPoint(myStartX, myStartY);
557 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
560 if (myRotationPointSelection) {
561 if (theEvent->button() == Qt::LeftButton) {
562 Handle(AIS_InteractiveContext) ic = myViewer->AISContext();
564 for(ic->InitSelected(); ic->MoreSelected(); ic->NextSelected()) {
565 TopoDS_Shape aShape = ic->SelectedShape();
566 if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX) {
567 gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(ic->SelectedShape()));
568 /*if ( mySetRotationPointDlg ) {
569 myRotationPointSelection = false;
570 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
573 myCurrPointType = myPrevPointType;
577 if (ic->NbSelected() == 0)
578 myCurrPointType = myPrevPointType;
579 //if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
580 ic->CloseAllContexts();
581 myOperation = NOTHING;
582 myViewPort->setCursor(myCursor);
583 myCursorIsHand = false;
584 myRotationPointSelection = false;
587 emit mousePressed(this, theEvent);
590 /* notify that we start a transformation */
591 if (transformRequested())
592 emit vpTransformationStarted(myOperation);
594 if (transformRequested())
595 setTransformInProcess(true);
597 /* we may need it for sketching... */
598 /* if ( l_mbPressEvent )
599 delete l_mbPressEvent;
600 l_mbPressEvent = new QMouseEvent( *theEvent );*/
603 //****************************************************************
604 void XGUI_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
606 switch(myOperation) {
608 int prevState = myCurSketch;
609 /* if(theEvent->button() == Qt::RightButton) {
610 QList<OCCViewer_ViewSketcher*>::Iterator it;
611 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it ) {
612 OCCViewer_ViewSketcher* sk = (*it);
613 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
618 emit mouseReleased(this, theEvent);
619 if (theEvent->button() == Qt::RightButton && prevState == -1) {
620 QContextMenuEvent aEvent(QContextMenuEvent::Mouse, theEvent->pos(), theEvent->globalPos());
621 emit contextMenuRequested(&aEvent);
626 myViewPort->endRotation();
636 if (theEvent->button() == Qt::LeftButton) {
637 myViewPort->setCenter(theEvent->x(), theEvent->y());
638 myViewPort->getView()->SetScale(myCurScale);
644 if (theEvent->button() == Qt::LeftButton) {
645 myCurrX = theEvent->x();
646 myCurrY = theEvent->y();
648 QRect rect = makeRect(myStartX, myStartY, myCurrX, myCurrY);
650 myViewPort->fitRect(rect);
657 // NOTE: viewer 3D detects a rectangle of selection using this event
658 // so we must emit it BEFORE resetting the selection rectangle
659 if (theEvent->button() == Qt::LeftButton && myDrawRect) {
663 myViewPort->update();
665 /* if ( l_mbPressEvent ) {
666 delete l_mbPressEvent;
671 //****************************************************************
672 void XGUI_ViewWindow::vpMouseMoveEvent(QMouseEvent* theEvent)
674 if (myIsKeyFree && interactionStyle() == XGUI::KEY_FREE) {
676 switch(getButtonState(theEvent, interactionStyle())) {
678 myViewPort->startZoomAtPoint(myStartX, myStartY);
686 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
693 myCurrX = theEvent->x();
694 myCurrY = theEvent->y();
695 switch(myOperation) {
697 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
701 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
707 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
716 if (myRotationPointSelection /*|| isSketcherStyle()*/) {
717 emit mouseMoving(this, theEvent);
719 int aState = theEvent->modifiers();
720 int aButton = theEvent->buttons();
721 int anInteractionStyle = interactionStyle();
722 if (((anInteractionStyle == XGUI::STANDARD) && (aButton == Qt::LeftButton)
723 && (aState == Qt::NoModifier || Qt::ShiftModifier))
724 || ((anInteractionStyle == XGUI::KEY_FREE) && (aButton == Qt::LeftButton)
725 && (aState == Qt::ControlModifier
726 || aState == (Qt::ControlModifier | Qt::ShiftModifier)))) {
727 myDrawRect = myEnableDrawMode;
730 if (!myCursorIsHand) { // we are going to sketch a rectangle
731 QCursor handCursor(Qt::PointingHandCursor);
732 myCursorIsHand = true;
734 myViewPort->setCursor(handCursor);
737 emit mouseMoving(this, theEvent);
738 } /* else if ( ( (anInteractionStyle == XGUI::STANDARD) &&
739 (aButton == Qt::RightButton) &&
740 ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
741 ( (anInteractionStyle == XGUI::KEY_FREE) &&
742 (aButton == Qt::RightButton) &&
743 ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
744 OCCViewer_ViewSketcher* sketcher = 0;
745 QList<OCCViewer_ViewSketcher*>::Iterator it;
746 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it ) {
747 OCCViewer_ViewSketcher* sk = (*it);
748 if( sk->isDefault() && sk->sketchButton() == aButton )
751 if ( sketcher && myCurSketch == -1 ) {
752 activateSketching( sketcher->type() );
754 myCurSketch = mypSketcher->sketchButton();
756 if ( l_mbPressEvent ) {
757 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
758 delete l_mbPressEvent;
761 QApplication::sendEvent( getViewPort(), theEvent );
765 emit mouseMoving(this, theEvent);
771 \brief Draw rubber band rectangle.
773 void XGUI_ViewWindow::drawRect()
776 myRectBand = new XGUI_RectRubberBand(myViewPort);
779 myRectBand->setUpdatesEnabled(false);
780 QRect aRect = makeRect(myStartX, myStartY, myCurrX, myCurrY);
781 myRectBand->initGeometry(aRect);
783 if (!myRectBand->isVisible())
786 myRectBand->setUpdatesEnabled(true);
790 \brief Clear rubber band rectangle on the end on the dragging operation.
792 void XGUI_ViewWindow::endDrawRect()
795 myRectBand->clearGeometry();
800 void XGUI_ViewWindow::activateZoom()
802 if (!transformRequested() && !myCursorIsHand)
803 myCursor = cursor(); /* save old cursor */
805 if (myOperation != ZOOMVIEW) {
806 QPixmap zoomPixmap(imageZoomCursor);
807 QCursor zoomCursor(zoomPixmap);
808 if (setTransformRequested(ZOOMVIEW))
809 myViewPort->setCursor(zoomCursor);
813 bool XGUI_ViewWindow::transformRequested() const
815 return (myOperation != NOTHING);
819 \brief Start delayed viewer operation.
821 bool XGUI_ViewWindow::setTransformRequested(OperationType op)
823 bool ok = transformEnabled(op);
824 myOperation = ok ? op : NOTHING;
825 myViewPort->setMouseTracking(myOperation == NOTHING);
830 Set enabled state of transformation (rotate, zoom, etc)
832 void XGUI_ViewWindow::setTransformEnabled(const OperationType id, const bool on)
835 myStatus.insert(id, on);
839 \return enabled state of transformation (rotate, zoom, etc)
841 bool XGUI_ViewWindow::transformEnabled(const OperationType id) const
843 return myStatus.contains(id) ? myStatus[id] : true;
847 \brief Start panning operation.
849 Sets the corresponding cursor for the widget.
851 void XGUI_ViewWindow::activatePanning()
853 if (!transformRequested() && !myCursorIsHand)
854 myCursor = cursor(); // save old cursor
856 if (myOperation != PANVIEW) {
857 QCursor panCursor(Qt::SizeAllCursor);
858 if (setTransformRequested(PANVIEW))
859 myViewPort->setCursor(panCursor);
864 \brief Start global panning operation
866 Sets the corresponding cursor for the widget.
868 void XGUI_ViewWindow::activateGlobalPanning()
870 Handle(V3d_View) aView3d = myViewPort->getView();
871 if ( !aView3d.IsNull() ) {
872 QPixmap globalPanPixmap (imageCrossCursor);
873 QCursor glPanCursor (globalPanPixmap);
874 myCurScale = aView3d->Scale();
875 aView3d->FitAll(0.01, false);
876 myCursor = cursor(); // save old cursor
877 myViewPort->fitAll(); // fits view before selecting a new scene center
878 if( setTransformRequested( PANGLOBAL ) )
879 myViewPort->setCursor( glPanCursor );
884 \brief Start rotation operation
886 Sets the corresponding cursor for the widget.
888 void XGUI_ViewWindow::activateRotation()
890 if (!transformRequested() && !myCursorIsHand)
891 myCursor = cursor(); // save old cursor
893 if (myOperation != ROTATE) {
894 QPixmap rotatePixmap(imageRotateCursor);
895 QCursor rotCursor(rotatePixmap);
896 if (setTransformRequested(ROTATE))
897 myViewPort->setCursor(rotCursor);
902 \brief Reset the viewport to its initial state
903 ( no transformations in process etc. )
905 void XGUI_ViewWindow::resetState()
909 if (myRotationPointSelection) {
910 QCursor handCursor(Qt::PointingHandCursor);
911 myViewPort->setCursor(handCursor);
913 if (transformRequested() || myCursorIsHand)
914 myViewPort->setCursor(myCursor);
915 myCursorIsHand = false;
918 if (transformRequested())
919 emit vpTransformationFinished(myOperation);
921 setTransformInProcess(false);
922 setTransformRequested(NOTHING);
925 XGUI_ViewBackground XGUI_ViewWindow::background() const
927 return myViewPort ? myViewPort->background() : XGUI_ViewBackground();
930 void XGUI_ViewWindow::setBackground(const XGUI_ViewBackground& theBackground)
933 myViewPort->setBackground( theBackground );
937 \brief Create one more window with same content.
939 void XGUI_ViewWindow::cloneView()
941 QMdiSubWindow* vw = myViewer->createView();
942 XGUI_ViewWindow* aNewWnd = static_cast<XGUI_ViewWindow*>(vw->widget());
943 aNewWnd->viewPort()->syncronizeWith(myViewPort);
944 emit viewCloned( vw );
947 void XGUI_ViewWindow::dumpView()
949 QString aFilter(tr("Images Files (*.bmp *.png *.jpg *.jpeg *.eps *.ps)"));
950 QString aSelectedFilter;
951 QString aFileName = QFileDialog::getSaveFileName(this, "Save picture", QString(), aFilter, &aSelectedFilter);
952 if (!aFileName.isNull()) {
953 QApplication::setOverrideCursor( Qt::WaitCursor );
954 QImage aPicture = myViewPort->dumpView();
956 QString aFmt = extension(aFileName).toUpper();
958 aFmt = QString( "BMP" ); // default format
959 else if( aFmt == "JPG" )
962 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
964 a3dView->Export(_strdup(qPrintable(aFileName)), Graphic3d_EF_PostScript);
965 else if (aFmt == "EPS")
966 a3dView->Export(_strdup(qPrintable(aFileName)), Graphic3d_EF_EnhPostScript);
968 aPicture.save( aFileName, aFmt.toLatin1() );
969 QApplication::restoreOverrideCursor();
973 void XGUI_ViewWindow::fitAll()
975 emit vpTransformationStarted( FITALLVIEW );
976 myViewPort->fitAll();
977 emit vpTransformationFinished( FITALLVIEW );
981 \brief Starts fit operation.
983 Sets the corresponding cursor for the widget.
985 void XGUI_ViewWindow::activateWindowFit()
987 if ( !transformRequested() && !myCursorIsHand )
988 myCursor = cursor(); /* save old cursor */
990 if ( myOperation != WINDOWFIT ) {
991 QCursor handCursor (Qt::PointingHandCursor);
992 if( setTransformRequested ( WINDOWFIT ) ) {
993 myViewPort->setCursor ( handCursor );
994 myCursorIsHand = true;
1001 \brief Perform "front view" transformation.
1003 void XGUI_ViewWindow::frontView()
1005 emit vpTransformationStarted ( FRONTVIEW );
1006 Handle(V3d_View) aView3d = myViewPort->getView();
1007 if ( !aView3d.IsNull() )
1008 aView3d->SetProj (V3d_Xpos);
1009 myViewPort->fitAll();
1010 emit vpTransformationFinished ( FRONTVIEW );
1014 \brief Perform "back view" transformation.
1016 void XGUI_ViewWindow::backView()
1018 emit vpTransformationStarted ( BACKVIEW );
1019 Handle(V3d_View) aView3d = myViewPort->getView();
1020 if ( !aView3d.IsNull() )
1021 aView3d->SetProj (V3d_Xneg);
1022 myViewPort->fitAll();
1023 emit vpTransformationFinished ( BACKVIEW );
1027 \brief Perform "top view" transformation.
1029 void XGUI_ViewWindow::topView()
1031 emit vpTransformationStarted ( TOPVIEW );
1032 Handle(V3d_View) aView3d = myViewPort->getView();
1033 if ( !aView3d.IsNull() )
1034 aView3d->SetProj (V3d_Zpos);
1035 myViewPort->fitAll();
1036 emit vpTransformationFinished ( TOPVIEW );
1040 \brief Perform "bottom view" transformation.
1042 void XGUI_ViewWindow::bottomView()
1044 emit vpTransformationStarted ( BOTTOMVIEW );
1045 Handle(V3d_View) aView3d = myViewPort->getView();
1046 if ( !aView3d.IsNull() )
1047 aView3d->SetProj (V3d_Zneg);
1048 myViewPort->fitAll();
1049 emit vpTransformationFinished ( BOTTOMVIEW );
1053 \brief Perform "left view" transformation.
1055 void XGUI_ViewWindow::leftView()
1057 emit vpTransformationStarted ( LEFTVIEW );
1058 Handle(V3d_View) aView3d = myViewPort->getView();
1059 if ( !aView3d.IsNull() )
1060 aView3d->SetProj (V3d_Yneg);
1061 myViewPort->fitAll();
1062 emit vpTransformationFinished ( LEFTVIEW );
1066 \brief Perform "right view" transformation.
1068 void XGUI_ViewWindow::rightView()
1070 emit vpTransformationStarted ( RIGHTVIEW );
1071 Handle(V3d_View) aView3d = myViewPort->getView();
1072 if ( !aView3d.IsNull() )
1073 aView3d->SetProj (V3d_Ypos);
1074 myViewPort->fitAll();
1075 emit vpTransformationFinished ( RIGHTVIEW );
1078 void XGUI_ViewWindow::reset()
1080 emit vpTransformationStarted( RESETVIEW );
1081 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1082 myViewPort->getView()->Reset( false );
1083 myViewPort->fitAll( false, true, false );
1084 myViewPort->getView()->SetImmediateUpdate( upd );
1085 myViewPort->getView()->Update();
1086 emit vpTransformationFinished( RESETVIEW );
1090 void XGUI_ViewWindow::updateToolBar()
1092 myGripWgt->update();
1093 myViewBar->update();
1094 myWindowBar->update();
1095 //QTimer::singleShot(50, Qt::VeryCoarseTimer, this, SLOT(repaintToolBar()));
1098 /*void XGUI_ViewWindow::repaintToolBar()
1100 QApplication::sync();
1101 myGripWgt->repaint();
1102 myViewBar->repaint();
1103 myWindowBar->repaint();