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>
18 #include <QStyleOptionToolBar>
20 #include <TopoDS_Shape.hxx>
21 #include <BRep_Tool.hxx>
23 #include <Visual3d_View.hxx>
27 const char* imageZoomCursor[] = { "32 32 3 1", ". c None", "a c #000000", "# c #ffffff",
28 "................................", "................................",
29 ".#######........................", "..aaaaaaa.......................",
30 "................................", ".............#####..............",
31 "...........##.aaaa##............", "..........#.aa.....a#...........",
32 ".........#.a.........#..........", ".........#a..........#a.........",
33 "........#.a...........#.........", "........#a............#a........",
34 "........#a............#a........", "........#a............#a........",
35 "........#a............#a........", ".........#...........#.a........",
36 ".........#a..........#a.........", ".........##.........#.a.........",
37 "........#####.....##.a..........", ".......###aaa#####.aa...........",
38 "......###aa...aaaaa.......#.....", ".....###aa................#a....",
39 "....###aa.................#a....", "...###aa...............#######..",
40 "....#aa.................aa#aaaa.", ".....a....................#a....",
41 "..........................#a....", "...........................a....",
42 "................................", "................................",
43 "................................", "................................" };
45 const char* imageRotateCursor[] = { "32 32 3 1", ". c None", "a c #000000", "# c #ffffff",
46 "................................", "................................",
47 "................................", "................................",
48 "........#.......................", ".......#.a......................",
49 "......#######...................", ".......#aaaaa#####..............",
50 "........#..##.a#aa##........##..", ".........a#.aa..#..a#.....##.aa.",
51 ".........#.a.....#...#..##.aa...", ".........#a.......#..###.aa.....",
52 "........#.a.......#a..#aa.......", "........#a.........#..#a........",
53 "........#a.........#a.#a........", "........#a.........#a.#a........",
54 "........#a.........#a.#a........", ".........#.........#a#.a........",
55 "........##a........#a#a.........", "......##.a#.......#.#.a.........",
56 "....##.aa..##.....##.a..........", "..##.aa.....a#####.aa...........",
57 "...aa.........aaa#a.............", "................#.a.............",
58 "...............#.a..............", "..............#.a...............",
59 "...............a................", "................................",
60 "................................", "................................",
61 "................................", "................................" };
63 const char* imageCrossCursor[] = { "32 32 3 1", ". c None", "a c #000000", "# c #ffffff",
64 "................................", "................................",
65 "................................", "................................",
66 "................................", "................................",
67 "................................", "...............#................",
68 "...............#a...............", "...............#a...............",
69 "...............#a...............", "...............#a...............",
70 "...............#a...............", "...............#a...............",
71 "...............#a...............", ".......#################........",
72 "........aaaaaaa#aaaaaaaaa.......", "...............#a...............",
73 "...............#a...............", "...............#a...............",
74 "...............#a...............", "...............#a...............",
75 "...............#a...............", "...............#a...............",
76 "................a...............", "................................",
77 "................................", "................................",
78 "................................", "................................",
79 "................................", "................................" };
82 void ViewerToolbar::paintEvent(QPaintEvent* theEvent)
84 //QApplication::syncX();
85 //printf("### ViewerToolbar::paintEvent\n");
86 //QToolBar::paintEvent(theEvent);
88 QPainter aPainter(this);
90 QRect aVPRect = myVPort->rect();
91 QPoint aGlobPnt = mapToGlobal(aRect.topLeft());
92 QPoint aPnt = myVPort->mapFromGlobal(aGlobPnt);
94 QRect aImgRect(QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(),
95 aRect.width(), aRect.height()));
96 aPainter.drawImage(aRect, myVPort->dumpView(aImgRect, false));
99 QStyle *style = this->style();
100 QStyleOptionToolBar aOpt;
101 initStyleOption(&aOpt);
103 aOpt.rect = style->subElementRect(QStyle::SE_ToolBarHandle, &aOpt, this);
104 if (aOpt.rect.isValid())
105 style->drawPrimitive(QStyle::PE_IndicatorToolBarHandle, &aOpt, &aPainter, this);
108 //**************************************************************************
109 void ViewerLabel::repaintBackground()
111 QRect aRect = rect();
112 QRect aVPRect = myVPort->rect();
113 QPoint aGlobPnt = mapToGlobal(aRect.topLeft());
114 QPoint aPnt = myVPort->mapFromGlobal(aGlobPnt);
116 QRect aImgRect(QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(),
117 aRect.width(), aRect.height()));
118 QPainter(this).drawImage(aRect, myVPort->dumpView(aImgRect, false));
121 void ViewerLabel::paintEvent(QPaintEvent* theEvent)
124 QLabel::paintEvent(theEvent);
127 //**************************************************************************
128 //**************************************************************************
129 //**************************************************************************
130 XGUI_ViewWindow::XGUI_ViewWindow(XGUI_Viewer* theViewer, V3d_TypeOfView theType)
134 MinimizeIco(":pictures/wnd_minimize.png"),
135 MaximizeIco(":pictures/wnd_maximize.png"),
136 CloseIco(":pictures/wnd_close.png"),
137 RestoreIco(":pictures/wnd_restore.png"),
138 myInteractionStyle(XGUI::STANDARD),
141 my2dMode(XGUI::No2dMode),
142 myCurrPointType(XGUI::GRAVITY),
143 myPrevPointType(XGUI::GRAVITY),
144 myRotationPointSelection(false),
146 myStartX(0), myStartY(0), myCurrX(0), myCurrY(0), myCurScale(0.0), myCurSketch(0),
147 myDrawRect(false), myEnableDrawMode(false), myCursorIsHand(false), myEventStarted(false),
149 myLastState(WindowNormalState), myOperation(NOTHING)
151 mySelectedPoint = gp_Pnt(0., 0., 0.);
152 setFrameStyle(QFrame::Raised);
153 setFrameShape(QFrame::Panel);
154 setLineWidth(BORDER_SIZE);
155 setMouseTracking(true);
157 QVBoxLayout* aLay = new QVBoxLayout(this);
158 aLay->setContentsMargins(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE);
159 myViewPort = new XGUI_ViewPort(this, myViewer->v3dViewer(), theType);
160 myViewPort->installEventFilter(this);
161 aLay->addWidget(myViewPort);
163 myPicture = new QLabel(this);
164 myPicture->setFrameStyle(QFrame::Sunken);
165 myPicture->setFrameShape(QFrame::Panel);
166 myPicture->setMouseTracking(true);
167 myPicture->installEventFilter(this);
168 aLay->addWidget(myPicture);
171 myGripWgt = new ViewerLabel(this, myViewPort);
172 myGripWgt->setPixmap(QPixmap(":pictures/wnd_grip.png"));
173 myGripWgt->setGeometry(BORDER_SIZE + 2, BORDER_SIZE + 2, 19, 32);
174 myGripWgt->setMouseTracking(true);
175 myGripWgt->installEventFilter(this);
177 // Create Viewer management buttons
178 myViewBar = new ViewerToolbar(this, myViewPort);
183 aBtn = new QAction(QIcon(":pictures/occ_view_camera_dump.png"), tr("Dump view"), myViewBar);
184 connect(aBtn, SIGNAL(triggered()), SLOT(dumpView()));
185 myViewBar->addAction(aBtn);
187 aBtn = new QAction(QIcon(":pictures/occ_view_fitall.png"), tr("Fit all"), myViewBar);
188 connect(aBtn, SIGNAL(triggered()), SLOT(fitAll()));
189 myViewBar->addAction(aBtn);
191 aBtn = new QAction(QIcon(":pictures/occ_view_fitarea.png"), tr("Fit area"), myViewBar);
192 connect(aBtn, SIGNAL(triggered()), SLOT(activateWindowFit()));
193 myViewBar->addAction(aBtn);
195 aBtn = new QAction(QIcon(":pictures/occ_view_zoom.png"), tr("Zoom"), myViewBar);
196 connect(aBtn, SIGNAL(triggered()), SLOT(activateZoom()));
197 myViewBar->addAction(aBtn);
199 aBtn = new QAction(QIcon(":pictures/occ_view_pan.png"), tr("Panning"), myViewBar);
200 connect(aBtn, SIGNAL(triggered()), SLOT(activatePanning()));
201 myViewBar->addAction(aBtn);
203 aBtn = new QAction(QIcon(":pictures/occ_view_glpan.png"), tr("Global panning"), myViewBar);
204 connect(aBtn, SIGNAL(triggered()), SLOT(activateGlobalPanning()));
205 myViewBar->addAction(aBtn);
207 aBtn = new QAction(QIcon(":pictures/occ_view_rotate.png"), tr("Rotate"), myViewBar);
208 connect(aBtn, SIGNAL(triggered()), SLOT(activateRotation()));
209 myViewBar->addAction(aBtn);
211 aBtn = new QAction(QIcon(":pictures/occ_view_reset.png"), tr("Reset"), myViewBar);
212 connect(aBtn, SIGNAL(triggered()), SLOT(reset()));
213 myViewBar->addAction(aBtn);
215 aBtn = new QAction(QIcon(":pictures/occ_view_front.png"), tr("Front"), myViewBar);
216 connect(aBtn, SIGNAL(triggered()), SLOT(frontView()));
217 myViewBar->addAction(aBtn);
219 aBtn = new QAction(QIcon(":pictures/occ_view_back.png"), tr("Back"), myViewBar);
220 connect(aBtn, SIGNAL(triggered()), SLOT(backView()));
221 myViewBar->addAction(aBtn);
223 aBtn = new QAction(QIcon(":pictures/occ_view_top.png"), tr("Top"), myViewBar);
224 connect(aBtn, SIGNAL(triggered()), SLOT(topView()));
225 myViewBar->addAction(aBtn);
227 aBtn = new QAction(QIcon(":pictures/occ_view_bottom.png"), tr("Bottom"), myViewBar);
228 connect(aBtn, SIGNAL(triggered()), SLOT(bottomView()));
229 myViewBar->addAction(aBtn);
231 aBtn = new QAction(QIcon(":pictures/occ_view_left.png"), tr("Left"), myViewBar);
232 connect(aBtn, SIGNAL(triggered()), SLOT(leftView()));
233 myViewBar->addAction(aBtn);
235 aBtn = new QAction(QIcon(":pictures/occ_view_right.png"), tr("Right"), myViewBar);
236 connect(aBtn, SIGNAL(triggered()), SLOT(rightView()));
237 myViewBar->addAction(aBtn);
239 aBtn = new QAction(QIcon(":pictures/occ_view_clone.png"), tr("Clone"), myViewBar);
240 connect(aBtn, SIGNAL(triggered()), SLOT(cloneView()));
241 myViewBar->addAction(aBtn);
243 // Create Window management buttons
244 myWindowBar = new ViewerToolbar(this, myViewPort);
246 myMinimizeBtn = new QAction(myWindowBar);
247 myMinimizeBtn->setIcon(MinimizeIco);
248 myWindowBar->addAction(myMinimizeBtn);
249 connect(myMinimizeBtn, SIGNAL(triggered()), SLOT(onMinimize()));
251 myMaximizeBtn = new QAction(myWindowBar);
252 myMaximizeBtn->setIcon(MaximizeIco);
253 myWindowBar->addAction(myMaximizeBtn);
254 connect(myMaximizeBtn, SIGNAL(triggered()), SLOT(onMaximize()));
256 aBtn = new QAction(myWindowBar);
257 aBtn->setIcon(CloseIco);
258 myWindowBar->addAction(aBtn);
259 connect(aBtn, SIGNAL(triggered()), SLOT(onClose()));
262 //myWindowBar->hide();
265 //Support copy of background on updating of viewer
266 connect(myViewPort, SIGNAL(vpTransformed()), this, SLOT(updateToolBar()));
267 connect(myViewPort, SIGNAL(vpUpdated()), this, SLOT(updateToolBar()));
268 connect(this, SIGNAL(vpTransformationFinished(XGUI_ViewWindow::OperationType)),
269 this, SLOT(updateToolBar()));
273 //****************************************************************
274 XGUI_ViewWindow::~XGUI_ViewWindow()
278 //****************************************************************
279 void XGUI_ViewWindow::resizeEvent(QResizeEvent* theEvent)
281 QSize aSize = theEvent->size();
282 QSize aWndBarSize = myWindowBar->sizeHint();
283 QSize myViewBarSize = myViewBar->sizeHint();
285 myWindowBar->setGeometry(aSize.width() - aWndBarSize.width() - BORDER_SIZE - 4, BORDER_SIZE + 2,
286 aWndBarSize.width(), aWndBarSize.height());
287 int aViewBarWidth = aSize.width() - aWndBarSize.width() - myGripWgt->width() - 8;
288 if (aViewBarWidth > myViewBarSize.width())
289 aViewBarWidth = myViewBarSize.width();
290 myViewBar->setGeometry(BORDER_SIZE + 18, BORDER_SIZE + 2, aViewBarWidth, myViewBarSize.height());
293 //****************************************************************
294 void XGUI_ViewWindow::changeEvent(QEvent* theEvent)
297 if (theEvent->type() == QEvent::WindowStateChange) {
299 if (myPicture->isHidden()) {
307 if (myPicture->isVisible()) {
312 myMinimizeBtn->setIcon(MinimizeIco);
313 myMaximizeBtn->setIcon(RestoreIco);
315 myViewBar->setVisible(myIsActive);
316 myWindowBar->setVisible(myIsActive);
317 myGripWgt->setVisible(myIsActive && (!isMaximized()));
320 QWidget::changeEvent(theEvent);
325 //****************************************************************
326 void XGUI_ViewWindow::windowActivated()
329 if (!isMinimized()) {
332 myGripWgt->setVisible(!(isMaximized() || isMinimized()));
334 myMaximizeBtn->setIcon(RestoreIco);
336 myMaximizeBtn->setIcon(MaximizeIco);
341 //****************************************************************
342 void XGUI_ViewWindow::windowDeactivated()
345 if (!isMinimized()) {
350 myMaximizeBtn->setIcon(RestoreIco);
352 myMaximizeBtn->setIcon(MaximizeIco);
358 //****************************************************************
359 void XGUI_ViewWindow::onClose()
361 if (parentWidget()) {
362 emit tryClosing(this);
364 emit closed(static_cast<QMdiSubWindow*>(parentWidget()));
365 parentWidget()->close();
370 //****************************************************************
371 /*void XGUI_ViewWindow::enterEvent(QEvent* theEvent)
373 if (!isMinimized()) {
381 //****************************************************************
382 void XGUI_ViewWindow::leaveEvent(QEvent* theEvent)
389 //****************************************************************
390 void XGUI_ViewWindow::onMinimize()
392 QPixmap aPMap = QPixmap::fromImage(myViewPort->dumpView());
395 double aR = aW / 100.;
396 int aNewH = int(aH / aR);
397 myPicture->setPixmap(aPMap.scaled(100, aNewH));
399 myLastState = (isMaximized() || parentWidget()->isMaximized()) ? MaximizedState : WindowNormalState;
400 //parentWidget()->showMinimized();
402 parentWidget()->setGeometry(parentWidget()->x(), parentWidget()->y(), 100, aNewH);
405 //****************************************************************
406 void XGUI_ViewWindow::onMaximize()
408 if (isMaximized() || parentWidget()->isMaximized()) {
409 myMaximizeBtn->setIcon(MaximizeIco);
412 parentWidget()->showNormal();
414 myMaximizeBtn->setIcon(RestoreIco);
418 myMinimizeBtn->setIcon(MinimizeIco);
421 //****************************************************************
422 bool XGUI_ViewWindow::processWindowControls(QObject *theObj, QEvent *theEvent)
424 switch(theEvent->type()) {
425 case QEvent::MouseButtonPress: {
426 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
427 if ((aEvent->button() == Qt::LeftButton) && (!myMoving)) {
429 myMousePnt = aEvent->globalPos();
434 case QEvent::MouseButtonRelease: {
435 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
436 if ((aEvent->button() == Qt::LeftButton) && myMoving) {
442 case QEvent::MouseMove: {
443 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
445 QMdiSubWindow* aParent = static_cast<QMdiSubWindow*>(parentWidget());
446 QMdiArea* aMDIArea = aParent->mdiArea();
448 QPoint aPnt = aEvent->globalPos();
449 QPoint aMDIPnt = aMDIArea->mapFromGlobal(aPnt);
450 if (aMDIArea->rect().contains(aMDIPnt)) {
451 int aX = aParent->x() + (aPnt.x() - myMousePnt.x());
452 int aY = aParent->y() + (aPnt.y() - myMousePnt.y());
453 aParent->move(aX, aY);
460 case QEvent::MouseButtonDblClick:
461 if (theObj == myPicture) {
463 if (myLastState == MaximizedState)
473 //****************************************************************
474 bool XGUI_ViewWindow::processViewPort(QEvent *theEvent)
476 switch(theEvent->type()) {
477 case QEvent::MouseButtonPress:
478 vpMousePressEvent((QMouseEvent*) theEvent);
481 case QEvent::MouseButtonRelease:
482 vpMouseReleaseEvent((QMouseEvent*) theEvent);
485 case QEvent::MouseMove:
486 vpMouseMoveEvent((QMouseEvent*) theEvent);
489 case QEvent::MouseButtonDblClick:
490 emit mouseDoubleClicked(this, (QMouseEvent*) theEvent);
494 QWheelEvent* aEvent = (QWheelEvent*) theEvent;
495 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
496 double aDelta = (double)( aEvent->delta() ) / ( 15 * 8 );
499 int x1 = (int)( aEvent->x() + width()*aDelta/100 );
500 int y1 = (int)( aEvent->y() + height()*aDelta/100 );
501 myViewPort->zoom( x, y, x1, y1 );
508 //****************************************************************
509 bool XGUI_ViewWindow::eventFilter(QObject *theObj, QEvent *theEvent)
511 if ((theObj == myGripWgt) || (theObj == myPicture)) {
512 if (processWindowControls(theObj, theEvent))
514 } else if (theObj == myViewPort) {
515 if (processViewPort(theEvent)) {
519 return QFrame::eventFilter(theObj, theEvent);
522 //****************************************************************
523 XGUI_ViewWindow::OperationType XGUI_ViewWindow::getButtonState(
524 QMouseEvent* theEvent, XGUI::InteractionStyle theInteractionStyle)
526 OperationType aOp = NOTHING;
527 XGUI::InteractionStyle aStyle = (XGUI::InteractionStyle) theInteractionStyle;
528 if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::ZOOM])
529 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::ZOOM]))
531 else if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::PAN])
532 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::PAN]))
534 else if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::ROTATE])
535 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::ROTATE])
536 && (my2dMode == XGUI::No2dMode))
542 //****************************************************************
543 void XGUI_ViewWindow::vpMousePressEvent(QMouseEvent* theEvent)
545 myStartX = theEvent->x();
546 myStartY = theEvent->y();
547 XGUI::InteractionStyle anInteractionStyle = interactionStyle();
549 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
550 // which are assigned for pan and rotate - these operations are activated immediately after pressing
551 // of the first button, so it is necessary to switch to zoom when the second button is pressed
552 bool aSwitchToZoom = false;
553 if ((anInteractionStyle == XGUI::KEY_FREE) && (myOperation == PANVIEW || myOperation == ROTATE)) {
554 aSwitchToZoom = getButtonState(theEvent, anInteractionStyle) == ZOOMVIEW;
557 switch(myOperation) {
559 if (theEvent->button() == Qt::LeftButton)
560 emit vpTransformationStarted(WINDOWFIT);
564 if (theEvent->button() == Qt::LeftButton)
565 emit vpTransformationStarted(PANGLOBAL);
569 if (theEvent->button() == Qt::LeftButton) {
570 myViewPort->startZoomAtPoint(myStartX, myStartY);
571 emit vpTransformationStarted(ZOOMVIEW);
577 myViewPort->startZoomAtPoint(myStartX, myStartY);
579 } else if (theEvent->button() == Qt::LeftButton)
580 emit vpTransformationStarted(PANVIEW);
585 myViewPort->startZoomAtPoint(myStartX, myStartY);
587 } else if (theEvent->button() == Qt::LeftButton) {
588 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
589 emit vpTransformationStarted(ROTATE);
594 /* Try to activate a transformation */
595 OperationType aState;
596 if (interactionStyle() == XGUI::STANDARD)
597 aState = getButtonState(theEvent, anInteractionStyle);
599 aState = XGUI_ViewWindow::NOTHING;
604 myViewPort->startZoomAtPoint(myStartX, myStartY);
612 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
615 if (myRotationPointSelection) {
616 if (theEvent->button() == Qt::LeftButton) {
617 Handle(AIS_InteractiveContext) ic = myViewer->AISContext();
619 for(ic->InitSelected(); ic->MoreSelected(); ic->NextSelected()) {
620 TopoDS_Shape aShape = ic->SelectedShape();
621 if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX) {
622 gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(ic->SelectedShape()));
623 /*if ( mySetRotationPointDlg ) {
624 myRotationPointSelection = false;
625 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
628 myCurrPointType = myPrevPointType;
632 if (ic->NbSelected() == 0)
633 myCurrPointType = myPrevPointType;
634 //if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
635 ic->CloseAllContexts();
636 myOperation = NOTHING;
637 myViewPort->setCursor(myCursor);
638 myCursorIsHand = false;
639 myRotationPointSelection = false;
642 emit mousePressed(this, theEvent);
645 /* notify that we start a transformation */
646 if (transformRequested())
647 emit vpTransformationStarted(myOperation);
649 if (transformRequested())
650 setTransformInProcess(true);
652 /* we may need it for sketching... */
653 /* if ( l_mbPressEvent )
654 delete l_mbPressEvent;
655 l_mbPressEvent = new QMouseEvent( *theEvent );*/
658 //****************************************************************
659 void XGUI_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
661 switch(myOperation) {
663 int prevState = myCurSketch;
664 /* if(theEvent->button() == Qt::RightButton) {
665 QList<OCCViewer_ViewSketcher*>::Iterator it;
666 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it ) {
667 OCCViewer_ViewSketcher* sk = (*it);
668 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
673 emit mouseReleased(this, theEvent);
674 if (theEvent->button() == Qt::RightButton && prevState == -1) {
675 QContextMenuEvent aEvent(QContextMenuEvent::Mouse, theEvent->pos(), theEvent->globalPos());
676 emit contextMenuRequested(&aEvent);
681 myViewPort->endRotation();
691 if (theEvent->button() == Qt::LeftButton) {
692 myViewPort->setCenter(theEvent->x(), theEvent->y());
693 myViewPort->getView()->SetScale(myCurScale);
699 if (theEvent->button() == Qt::LeftButton) {
700 myCurrX = theEvent->x();
701 myCurrY = theEvent->y();
703 QRect rect = makeRect(myStartX, myStartY, myCurrX, myCurrY);
705 myViewPort->fitRect(rect);
712 // NOTE: viewer 3D detects a rectangle of selection using this event
713 // so we must emit it BEFORE resetting the selection rectangle
714 if (theEvent->button() == Qt::LeftButton && myDrawRect) {
718 myViewPort->update();
720 /* if ( l_mbPressEvent ) {
721 delete l_mbPressEvent;
726 //****************************************************************
727 void XGUI_ViewWindow::vpMouseMoveEvent(QMouseEvent* theEvent)
729 if (myIsKeyFree && interactionStyle() == XGUI::KEY_FREE) {
731 switch(getButtonState(theEvent, interactionStyle())) {
733 myViewPort->startZoomAtPoint(myStartX, myStartY);
741 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
748 myCurrX = theEvent->x();
749 myCurrY = theEvent->y();
750 switch(myOperation) {
752 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
756 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
762 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
771 if (myRotationPointSelection /*|| isSketcherStyle()*/) {
772 emit mouseMoving(this, theEvent);
774 int aState = theEvent->modifiers();
775 int aButton = theEvent->buttons();
776 int anInteractionStyle = interactionStyle();
777 if (((anInteractionStyle == XGUI::STANDARD) && (aButton == Qt::LeftButton)
778 && (aState == Qt::NoModifier || Qt::ShiftModifier))
779 || ((anInteractionStyle == XGUI::KEY_FREE) && (aButton == Qt::LeftButton)
780 && (aState == Qt::ControlModifier
781 || aState == (Qt::ControlModifier | Qt::ShiftModifier)))) {
782 myDrawRect = myEnableDrawMode;
785 if (!myCursorIsHand) { // we are going to sketch a rectangle
786 QCursor handCursor(Qt::PointingHandCursor);
787 myCursorIsHand = true;
789 myViewPort->setCursor(handCursor);
792 emit mouseMoving(this, theEvent);
793 } /* else if ( ( (anInteractionStyle == XGUI::STANDARD) &&
794 (aButton == Qt::RightButton) &&
795 ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
796 ( (anInteractionStyle == XGUI::KEY_FREE) &&
797 (aButton == Qt::RightButton) &&
798 ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
799 OCCViewer_ViewSketcher* sketcher = 0;
800 QList<OCCViewer_ViewSketcher*>::Iterator it;
801 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it ) {
802 OCCViewer_ViewSketcher* sk = (*it);
803 if( sk->isDefault() && sk->sketchButton() == aButton )
806 if ( sketcher && myCurSketch == -1 ) {
807 activateSketching( sketcher->type() );
809 myCurSketch = mypSketcher->sketchButton();
811 if ( l_mbPressEvent ) {
812 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
813 delete l_mbPressEvent;
816 QApplication::sendEvent( getViewPort(), theEvent );
820 emit mouseMoving(this, theEvent);
826 \brief Draw rubber band rectangle.
828 void XGUI_ViewWindow::drawRect()
831 myRectBand = new XGUI_RectRubberBand(myViewPort);
834 myRectBand->setUpdatesEnabled(false);
835 QRect aRect = makeRect(myStartX, myStartY, myCurrX, myCurrY);
836 myRectBand->initGeometry(aRect);
838 if (!myRectBand->isVisible())
841 myRectBand->setUpdatesEnabled(true);
845 \brief Clear rubber band rectangle on the end on the dragging operation.
847 void XGUI_ViewWindow::endDrawRect()
850 myRectBand->clearGeometry();
855 void XGUI_ViewWindow::activateZoom()
857 if (!transformRequested() && !myCursorIsHand)
858 myCursor = cursor(); /* save old cursor */
860 if (myOperation != ZOOMVIEW) {
861 QPixmap zoomPixmap(imageZoomCursor);
862 QCursor zoomCursor(zoomPixmap);
863 if (setTransformRequested(ZOOMVIEW))
864 myViewPort->setCursor(zoomCursor);
868 bool XGUI_ViewWindow::transformRequested() const
870 return (myOperation != NOTHING);
874 \brief Start delayed viewer operation.
876 bool XGUI_ViewWindow::setTransformRequested(OperationType op)
878 bool ok = transformEnabled(op);
879 myOperation = ok ? op : NOTHING;
880 myViewPort->setMouseTracking(myOperation == NOTHING);
885 Set enabled state of transformation (rotate, zoom, etc)
887 void XGUI_ViewWindow::setTransformEnabled(const OperationType id, const bool on)
890 myStatus.insert(id, on);
894 \return enabled state of transformation (rotate, zoom, etc)
896 bool XGUI_ViewWindow::transformEnabled(const OperationType id) const
898 return myStatus.contains(id) ? myStatus[id] : true;
902 \brief Start panning operation.
904 Sets the corresponding cursor for the widget.
906 void XGUI_ViewWindow::activatePanning()
908 if (!transformRequested() && !myCursorIsHand)
909 myCursor = cursor(); // save old cursor
911 if (myOperation != PANVIEW) {
912 QCursor panCursor(Qt::SizeAllCursor);
913 if (setTransformRequested(PANVIEW))
914 myViewPort->setCursor(panCursor);
919 \brief Start global panning operation
921 Sets the corresponding cursor for the widget.
923 void XGUI_ViewWindow::activateGlobalPanning()
925 Handle(V3d_View) aView3d = myViewPort->getView();
926 if ( !aView3d.IsNull() ) {
927 QPixmap globalPanPixmap (imageCrossCursor);
928 QCursor glPanCursor (globalPanPixmap);
929 myCurScale = aView3d->Scale();
930 aView3d->FitAll(0.01, false);
931 myCursor = cursor(); // save old cursor
932 myViewPort->fitAll(); // fits view before selecting a new scene center
933 if( setTransformRequested( PANGLOBAL ) )
934 myViewPort->setCursor( glPanCursor );
939 \brief Start rotation operation
941 Sets the corresponding cursor for the widget.
943 void XGUI_ViewWindow::activateRotation()
945 if (!transformRequested() && !myCursorIsHand)
946 myCursor = cursor(); // save old cursor
948 if (myOperation != ROTATE) {
949 QPixmap rotatePixmap(imageRotateCursor);
950 QCursor rotCursor(rotatePixmap);
951 if (setTransformRequested(ROTATE))
952 myViewPort->setCursor(rotCursor);
957 \brief Reset the viewport to its initial state
958 ( no transformations in process etc. )
960 void XGUI_ViewWindow::resetState()
964 if (myRotationPointSelection) {
965 QCursor handCursor(Qt::PointingHandCursor);
966 myViewPort->setCursor(handCursor);
968 if (transformRequested() || myCursorIsHand)
969 myViewPort->setCursor(myCursor);
970 myCursorIsHand = false;
973 if (transformRequested())
974 emit vpTransformationFinished(myOperation);
976 setTransformInProcess(false);
977 setTransformRequested(NOTHING);
980 XGUI_ViewBackground XGUI_ViewWindow::background() const
982 return myViewPort ? myViewPort->background() : XGUI_ViewBackground();
985 void XGUI_ViewWindow::setBackground(const XGUI_ViewBackground& theBackground)
988 myViewPort->setBackground( theBackground );
992 \brief Create one more window with same content.
994 void XGUI_ViewWindow::cloneView()
996 QMdiSubWindow* vw = myViewer->createView();
997 XGUI_ViewWindow* aNewWnd = static_cast<XGUI_ViewWindow*>(vw->widget());
998 aNewWnd->viewPort()->syncronizeWith(myViewPort);
999 emit viewCloned( vw );
1002 void XGUI_ViewWindow::dumpView()
1004 QString aFilter(tr("Images Files (*.bmp *.png *.jpg *.jpeg *.eps *.ps)"));
1005 QString aSelectedFilter;
1006 QString aFileName = QFileDialog::getSaveFileName(this, "Save picture", QString(), aFilter, &aSelectedFilter);
1007 if (!aFileName.isNull()) {
1008 QApplication::setOverrideCursor( Qt::WaitCursor );
1009 QImage aPicture = myViewPort->dumpView();
1011 QString aFmt = extension(aFileName).toUpper();
1012 if( aFmt.isEmpty() )
1013 aFmt = QString( "BMP" ); // default format
1014 else if( aFmt == "JPG" )
1017 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
1019 a3dView->Export(strdup(qPrintable(aFileName)), Graphic3d_EF_PostScript);
1020 else if (aFmt == "EPS")
1021 a3dView->Export(strdup(qPrintable(aFileName)), Graphic3d_EF_EnhPostScript);
1023 aPicture.save( aFileName, aFmt.toLatin1() );
1024 QApplication::restoreOverrideCursor();
1028 void XGUI_ViewWindow::fitAll()
1030 emit vpTransformationStarted( FITALLVIEW );
1031 myViewPort->fitAll();
1032 emit vpTransformationFinished( FITALLVIEW );
1036 \brief Starts fit operation.
1038 Sets the corresponding cursor for the widget.
1040 void XGUI_ViewWindow::activateWindowFit()
1042 if ( !transformRequested() && !myCursorIsHand )
1043 myCursor = cursor(); /* save old cursor */
1045 if ( myOperation != WINDOWFIT ) {
1046 QCursor handCursor (Qt::PointingHandCursor);
1047 if( setTransformRequested ( WINDOWFIT ) ) {
1048 myViewPort->setCursor ( handCursor );
1049 myCursorIsHand = true;
1056 \brief Perform "front view" transformation.
1058 void XGUI_ViewWindow::frontView()
1060 emit vpTransformationStarted ( FRONTVIEW );
1061 Handle(V3d_View) aView3d = myViewPort->getView();
1062 if ( !aView3d.IsNull() )
1063 aView3d->SetProj (V3d_Xpos);
1064 myViewPort->fitAll();
1065 emit vpTransformationFinished ( FRONTVIEW );
1069 \brief Perform "back view" transformation.
1071 void XGUI_ViewWindow::backView()
1073 emit vpTransformationStarted ( BACKVIEW );
1074 Handle(V3d_View) aView3d = myViewPort->getView();
1075 if ( !aView3d.IsNull() )
1076 aView3d->SetProj (V3d_Xneg);
1077 myViewPort->fitAll();
1078 emit vpTransformationFinished ( BACKVIEW );
1082 \brief Perform "top view" transformation.
1084 void XGUI_ViewWindow::topView()
1086 emit vpTransformationStarted ( TOPVIEW );
1087 Handle(V3d_View) aView3d = myViewPort->getView();
1088 if ( !aView3d.IsNull() )
1089 aView3d->SetProj (V3d_Zpos);
1090 myViewPort->fitAll();
1091 emit vpTransformationFinished ( TOPVIEW );
1095 \brief Perform "bottom view" transformation.
1097 void XGUI_ViewWindow::bottomView()
1099 emit vpTransformationStarted ( BOTTOMVIEW );
1100 Handle(V3d_View) aView3d = myViewPort->getView();
1101 if ( !aView3d.IsNull() )
1102 aView3d->SetProj (V3d_Zneg);
1103 myViewPort->fitAll();
1104 emit vpTransformationFinished ( BOTTOMVIEW );
1108 \brief Perform "left view" transformation.
1110 void XGUI_ViewWindow::leftView()
1112 emit vpTransformationStarted ( LEFTVIEW );
1113 Handle(V3d_View) aView3d = myViewPort->getView();
1114 if ( !aView3d.IsNull() )
1115 aView3d->SetProj (V3d_Yneg);
1116 myViewPort->fitAll();
1117 emit vpTransformationFinished ( LEFTVIEW );
1121 \brief Perform "right view" transformation.
1123 void XGUI_ViewWindow::rightView()
1125 emit vpTransformationStarted ( RIGHTVIEW );
1126 Handle(V3d_View) aView3d = myViewPort->getView();
1127 if ( !aView3d.IsNull() )
1128 aView3d->SetProj (V3d_Ypos);
1129 myViewPort->fitAll();
1130 emit vpTransformationFinished ( RIGHTVIEW );
1133 void XGUI_ViewWindow::reset()
1135 emit vpTransformationStarted( RESETVIEW );
1136 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1137 myViewPort->getView()->Reset( false );
1138 myViewPort->fitAll( false, true, false );
1139 myViewPort->getView()->SetImmediateUpdate( upd );
1140 myViewPort->getView()->Update();
1141 emit vpTransformationFinished( RESETVIEW );
1145 void XGUI_ViewWindow::updateToolBar()
1147 myGripWgt->update();
1148 myViewBar->update();
1149 myWindowBar->update();
1150 //QTimer::singleShot(50, Qt::VeryCoarseTimer, this, SLOT(repaintToolBar()));
1153 /*void XGUI_ViewWindow::repaintToolBar()
1155 QApplication::sync();
1156 myGripWgt->repaint();
1157 myViewBar->repaint();
1158 myWindowBar->repaint();