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 ViewerToolbar::ViewerToolbar(QWidget* theParent, XGUI_ViewPort* thePort)
83 : QToolBar(theParent), myVPort(thePort), myResize(false)
85 connect(myVPort, SIGNAL(resized()), this, SLOT(onViewPortResized()));
88 void ViewerToolbar::paintEvent(QPaintEvent* theEvent)
90 //QToolBar::paintEvent(theEvent);
92 QPainter aPainter(this);
94 QRect aVPRect = myVPort->rect();
95 QPoint aGlobPnt = mapToGlobal(aRect.topLeft());
96 QPoint aPnt = myVPort->mapFromGlobal(aGlobPnt);
98 QRect aImgRect(QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(),
99 aRect.width(), aRect.height()));
100 QImage aImg = myVPort->dumpView(aImgRect, myResize);
102 aPainter.drawImage(aRect, aImg);
106 QStyle *style = this->style();
107 QStyleOptionToolBar aOpt;
108 initStyleOption(&aOpt);
110 aOpt.rect = style->subElementRect(QStyle::SE_ToolBarHandle, &aOpt, this);
111 if (aOpt.rect.isValid())
112 style->drawPrimitive(QStyle::PE_IndicatorToolBarHandle, &aOpt, &aPainter, this);
115 //**************************************************************************
116 ViewerLabel::ViewerLabel(QWidget* theParent, XGUI_ViewPort* thePort)
117 : QLabel(theParent), myVPort(thePort), myResize(false)
119 connect(myVPort, SIGNAL(resized()), this, SLOT(onViewPortResized()));
122 void ViewerLabel::paintEvent(QPaintEvent* theEvent)
124 QRect aRect = rect();
125 QRect aVPRect = myVPort->rect();
126 QPoint aGlobPnt = mapToGlobal(aRect.topLeft());
127 QPoint aPnt = myVPort->mapFromGlobal(aGlobPnt);
129 QRect aImgRect(QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(),
130 aRect.width(), aRect.height()));
131 QImage aImg = myVPort->dumpView(aImgRect, myResize);
133 QPainter(this).drawImage(aRect, aImg);
134 QLabel::paintEvent(theEvent);
137 //**************************************************************************
138 //**************************************************************************
139 //**************************************************************************
140 XGUI_ViewWindow::XGUI_ViewWindow(XGUI_Viewer* theViewer, V3d_TypeOfView theType)
144 MinimizeIco(":pictures/wnd_minimize.png"),
145 MaximizeIco(":pictures/wnd_maximize.png"),
146 CloseIco(":pictures/wnd_close.png"),
147 RestoreIco(":pictures/wnd_restore.png"),
148 myInteractionStyle(XGUI::STANDARD),
151 my2dMode(XGUI::No2dMode),
152 myCurrPointType(XGUI::GRAVITY),
153 myPrevPointType(XGUI::GRAVITY),
154 myRotationPointSelection(false),
156 myStartX(0), myStartY(0), myCurrX(0), myCurrY(0), myCurScale(0.0), myCurSketch(0),
157 myDrawRect(false), myEnableDrawMode(true), myCursorIsHand(false), myEventStarted(false),
159 myLastState(WindowNormalState), myOperation(NOTHING)
161 mySelectedPoint = gp_Pnt(0., 0., 0.);
162 setFrameStyle(QFrame::Raised);
163 setFrameShape(QFrame::Panel);
164 setLineWidth(BORDER_SIZE);
165 setMouseTracking(true);
167 QVBoxLayout* aLay = new QVBoxLayout(this);
168 aLay->setContentsMargins(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE);
169 myViewPort = new XGUI_ViewPort(this, myViewer->v3dViewer(), theType);
170 myViewPort->installEventFilter(this);
171 myViewPort->setCursor(Qt::ArrowCursor);
172 aLay->addWidget(myViewPort);
174 myPicture = new QLabel(this);
175 myPicture->setFrameStyle(QFrame::Sunken);
176 myPicture->setFrameShape(QFrame::Panel);
177 myPicture->setMouseTracking(true);
178 myPicture->installEventFilter(this);
179 aLay->addWidget(myPicture);
182 QVBoxLayout* aVPLay = new QVBoxLayout(myViewPort);
183 aVPLay->setMargin(0);
184 aVPLay->setSpacing(0);
185 aVPLay->setContentsMargins(0,0,0,0);
187 QHBoxLayout* aToolLay = new QHBoxLayout();
188 aToolLay->setMargin(0);
189 aToolLay->setSpacing(0);
190 aToolLay->setContentsMargins(0,0,0,0);
191 aVPLay->addLayout(aToolLay);
192 aVPLay->addStretch();
194 myGripWgt = new ViewerLabel(this, myViewPort);
195 myGripWgt->setPixmap(QPixmap(":pictures/wnd_grip.png"));
196 myGripWgt->setMouseTracking(true);
197 myGripWgt->installEventFilter(this);
198 myGripWgt->setCursor(Qt::OpenHandCursor);
199 aToolLay->addWidget(myGripWgt);
201 // Create Viewer management buttons
202 myViewBar = new ViewerToolbar(this, myViewPort);
203 myViewBar->setCursor(Qt::PointingHandCursor);
204 aToolLay->addWidget(myViewBar);
205 aToolLay->addStretch();
210 aBtn = new QAction(QIcon(":pictures/occ_view_camera_dump.png"), tr("Dump view"), myViewBar);
211 connect(aBtn, SIGNAL(triggered()), SLOT(dumpView()));
212 myViewBar->addAction(aBtn);
214 aBtn = new QAction(QIcon(":pictures/occ_view_fitall.png"), tr("Fit all"), myViewBar);
215 connect(aBtn, SIGNAL(triggered()), SLOT(fitAll()));
216 myViewBar->addAction(aBtn);
218 aBtn = new QAction(QIcon(":pictures/occ_view_fitarea.png"), tr("Fit area"), myViewBar);
219 connect(aBtn, SIGNAL(triggered()), SLOT(activateWindowFit()));
220 myViewBar->addAction(aBtn);
222 aBtn = new QAction(QIcon(":pictures/occ_view_zoom.png"), tr("Zoom"), myViewBar);
223 connect(aBtn, SIGNAL(triggered()), SLOT(activateZoom()));
224 myViewBar->addAction(aBtn);
226 aBtn = new QAction(QIcon(":pictures/occ_view_pan.png"), tr("Panning"), myViewBar);
227 connect(aBtn, SIGNAL(triggered()), SLOT(activatePanning()));
228 myViewBar->addAction(aBtn);
230 aBtn = new QAction(QIcon(":pictures/occ_view_glpan.png"), tr("Global panning"), myViewBar);
231 connect(aBtn, SIGNAL(triggered()), SLOT(activateGlobalPanning()));
232 myViewBar->addAction(aBtn);
234 aBtn = new QAction(QIcon(":pictures/occ_view_rotate.png"), tr("Rotate"), myViewBar);
235 connect(aBtn, SIGNAL(triggered()), SLOT(activateRotation()));
236 myViewBar->addAction(aBtn);
238 aBtn = new QAction(QIcon(":pictures/occ_view_reset.png"), tr("Reset"), myViewBar);
239 connect(aBtn, SIGNAL(triggered()), SLOT(reset()));
240 myViewBar->addAction(aBtn);
242 aBtn = new QAction(QIcon(":pictures/occ_view_front.png"), tr("Front"), myViewBar);
243 connect(aBtn, SIGNAL(triggered()), SLOT(frontView()));
244 myViewBar->addAction(aBtn);
246 aBtn = new QAction(QIcon(":pictures/occ_view_back.png"), tr("Back"), myViewBar);
247 connect(aBtn, SIGNAL(triggered()), SLOT(backView()));
248 myViewBar->addAction(aBtn);
250 aBtn = new QAction(QIcon(":pictures/occ_view_top.png"), tr("Top"), myViewBar);
251 connect(aBtn, SIGNAL(triggered()), SLOT(topView()));
252 myViewBar->addAction(aBtn);
254 aBtn = new QAction(QIcon(":pictures/occ_view_bottom.png"), tr("Bottom"), myViewBar);
255 connect(aBtn, SIGNAL(triggered()), SLOT(bottomView()));
256 myViewBar->addAction(aBtn);
258 aBtn = new QAction(QIcon(":pictures/occ_view_left.png"), tr("Left"), myViewBar);
259 connect(aBtn, SIGNAL(triggered()), SLOT(leftView()));
260 myViewBar->addAction(aBtn);
262 aBtn = new QAction(QIcon(":pictures/occ_view_right.png"), tr("Right"), myViewBar);
263 connect(aBtn, SIGNAL(triggered()), SLOT(rightView()));
264 myViewBar->addAction(aBtn);
266 aBtn = new QAction(QIcon(":pictures/occ_view_clone.png"), tr("Clone"), myViewBar);
267 connect(aBtn, SIGNAL(triggered()), SLOT(cloneView()));
268 myViewBar->addAction(aBtn);
270 // Create Window management buttons
271 myWindowBar = new ViewerToolbar(this, myViewPort);
272 myWindowBar->setCursor(Qt::PointingHandCursor);
273 aToolLay->addWidget(myWindowBar);
275 myMinimizeBtn = new QAction(myWindowBar);
276 myMinimizeBtn->setIcon(MinimizeIco);
277 myWindowBar->addAction(myMinimizeBtn);
278 connect(myMinimizeBtn, SIGNAL(triggered()), SLOT(onMinimize()));
280 myMaximizeBtn = new QAction(myWindowBar);
281 myMaximizeBtn->setIcon(MaximizeIco);
282 myWindowBar->addAction(myMaximizeBtn);
283 connect(myMaximizeBtn, SIGNAL(triggered()), SLOT(onMaximize()));
285 aBtn = new QAction(myWindowBar);
286 aBtn->setIcon(CloseIco);
287 myWindowBar->addAction(aBtn);
288 connect(aBtn, SIGNAL(triggered()), SLOT(onClose()));
290 //Support copy of background on updating of viewer
291 connect(myViewPort, SIGNAL(vpTransformed()), this, SLOT(updateToolBar()));
292 connect(myViewPort, SIGNAL(vpUpdated()), this, SLOT(updateToolBar()));
293 connect(this, SIGNAL(vpTransformationFinished(XGUI_ViewWindow::OperationType)),
294 this, SLOT(updateToolBar()));
298 //****************************************************************
299 XGUI_ViewWindow::~XGUI_ViewWindow()
304 //****************************************************************
305 void XGUI_ViewWindow::showEvent(QShowEvent* theEvent)
307 QFrame::showEvent(theEvent);
308 myWindowBar->setFixedSize(myWindowBar->sizeHint());
311 //****************************************************************
312 void XGUI_ViewWindow::changeEvent(QEvent* theEvent)
315 if (theEvent->type() == QEvent::WindowStateChange) {
317 if (myPicture->isHidden()) {
325 if (myPicture->isVisible()) {
330 myMinimizeBtn->setIcon(MinimizeIco);
331 myMaximizeBtn->setIcon(RestoreIco);
333 myViewBar->setVisible(myIsActive);
334 myWindowBar->setVisible(myIsActive);
335 myGripWgt->setVisible(myIsActive && (!isMaximized()));
338 QWidget::changeEvent(theEvent);
343 //****************************************************************
344 void XGUI_ViewWindow::windowActivated()
346 if (!(isMinimized() || parentWidget()->isMinimized())) {
348 if (isMaximized() || parentWidget()->isMaximized()) {
349 myMaximizeBtn->setIcon(RestoreIco);
351 myMaximizeBtn->setIcon(MaximizeIco);
355 myGripWgt->setVisible(!(isMaximized() || isMinimized()));
360 //****************************************************************
361 void XGUI_ViewWindow::windowDeactivated()
364 if (!(isMinimized() || parentWidget()->isMinimized())) {
365 if (isMaximized() || parentWidget()->isMaximized()) {
366 myMaximizeBtn->setIcon(RestoreIco);
368 myMaximizeBtn->setIcon(MaximizeIco);
377 //****************************************************************
378 void XGUI_ViewWindow::onClose()
380 if (parentWidget()) {
381 emit tryClosing(this);
383 emit closed(static_cast<QMdiSubWindow*>(parentWidget()));
384 parentWidget()->close();
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;
401 parentWidget()->showMinimized();
402 parentWidget()->setGeometry(parentWidget()->x(), parentWidget()->y(), 100, aNewH);
403 parentWidget()->lower();
405 myViewer->onWindowMinimized((QMdiSubWindow*)parentWidget());
408 //****************************************************************
409 void XGUI_ViewWindow::onMaximize()
411 if (isMaximized() || parentWidget()->isMaximized()) {
412 myMaximizeBtn->setIcon(MaximizeIco);
415 parentWidget()->showNormal();
417 myMaximizeBtn->setIcon(RestoreIco);
420 parentWidget()->showMaximized();
422 parentWidget()->activateWindow();
423 myMinimizeBtn->setIcon(MinimizeIco);
425 // In order to avoid frosen background in toolbars when it shown as a second view
426 QTimer::singleShot(50, parentWidget(), SLOT(setFocus()));
429 //****************************************************************
430 bool XGUI_ViewWindow::processWindowControls(QObject *theObj, QEvent *theEvent)
432 switch(theEvent->type()) {
433 case QEvent::MouseButtonPress: {
434 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
435 if ((aEvent->button() == Qt::LeftButton) && (!myMoving)) {
437 myMousePnt = aEvent->globalPos();
442 case QEvent::MouseButtonRelease: {
443 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
444 if ((aEvent->button() == Qt::LeftButton) && myMoving) {
450 case QEvent::MouseMove: {
451 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
453 QMdiSubWindow* aParent = static_cast<QMdiSubWindow*>(parentWidget());
454 QMdiArea* aMDIArea = aParent->mdiArea();
456 QPoint aPnt = aEvent->globalPos();
457 QPoint aMDIPnt = aMDIArea->mapFromGlobal(aPnt);
458 if (aMDIArea->rect().contains(aMDIPnt)) {
459 int aX = aParent->x() + (aPnt.x() - myMousePnt.x());
460 int aY = aParent->y() + (aPnt.y() - myMousePnt.y());
461 aParent->move(aX, aY);
468 case QEvent::MouseButtonDblClick:
469 if (theObj == myPicture) {
471 if (myLastState == MaximizedState) {
476 myViewer->onWindowActivated((QMdiSubWindow*)parentWidget());
478 // In order to avoid frosen background in toolbars when it shown as a second view
479 QTimer::singleShot(20, parentWidget(), SLOT(setFocus()));
487 //****************************************************************
488 bool XGUI_ViewWindow::processViewPort(QEvent *theEvent)
490 switch(theEvent->type()) {
491 case QEvent::MouseButtonPress:
492 vpMousePressEvent((QMouseEvent*) theEvent);
495 case QEvent::MouseButtonRelease:
496 vpMouseReleaseEvent((QMouseEvent*) theEvent);
499 case QEvent::MouseMove:
500 vpMouseMoveEvent((QMouseEvent*) theEvent);
503 case QEvent::MouseButtonDblClick:
504 emit mouseDoubleClicked(this, (QMouseEvent*) theEvent);
508 QWheelEvent* aEvent = (QWheelEvent*) theEvent;
509 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
510 double aDelta = (double)( aEvent->delta() ) / ( 15 * 8 );
513 int x1 = (int)( aEvent->x() + width()*aDelta/100 );
514 int y1 = (int)( aEvent->y() + height()*aDelta/100 );
515 myViewPort->zoom( x, y, x1, y1 );
522 //****************************************************************
523 bool XGUI_ViewWindow::eventFilter(QObject *theObj, QEvent *theEvent)
525 if ((theObj == myGripWgt) || (theObj == myPicture)) {
526 if (processWindowControls(theObj, theEvent))
528 } else if (theObj == myViewPort) {
529 if (processViewPort(theEvent)) {
533 return QFrame::eventFilter(theObj, theEvent);
536 //****************************************************************
537 XGUI_ViewWindow::OperationType XGUI_ViewWindow::getButtonState(
538 QMouseEvent* theEvent, XGUI::InteractionStyle theInteractionStyle)
540 OperationType aOp = NOTHING;
541 XGUI::InteractionStyle aStyle = (XGUI::InteractionStyle) theInteractionStyle;
542 if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::ZOOM])
543 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::ZOOM]))
545 else if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::PAN])
546 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::PAN]))
548 else if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::ROTATE])
549 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::ROTATE])
550 && (my2dMode == XGUI::No2dMode))
556 //****************************************************************
557 void XGUI_ViewWindow::vpMousePressEvent(QMouseEvent* theEvent)
559 myStartX = theEvent->x();
560 myStartY = theEvent->y();
561 XGUI::InteractionStyle anInteractionStyle = interactionStyle();
563 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
564 // which are assigned for pan and rotate - these operations are activated immediately after pressing
565 // of the first button, so it is necessary to switch to zoom when the second button is pressed
566 bool aSwitchToZoom = false;
567 if ((anInteractionStyle == XGUI::KEY_FREE) && (myOperation == PANVIEW || myOperation == ROTATE)) {
568 aSwitchToZoom = getButtonState(theEvent, anInteractionStyle) == ZOOMVIEW;
571 switch(myOperation) {
573 if (theEvent->button() == Qt::LeftButton)
574 emit vpTransformationStarted(WINDOWFIT);
578 if (theEvent->button() == Qt::LeftButton)
579 emit vpTransformationStarted(PANGLOBAL);
583 if (theEvent->button() == Qt::LeftButton) {
584 myViewPort->startZoomAtPoint(myStartX, myStartY);
585 emit vpTransformationStarted(ZOOMVIEW);
591 myViewPort->startZoomAtPoint(myStartX, myStartY);
593 } else if (theEvent->button() == Qt::LeftButton)
594 emit vpTransformationStarted(PANVIEW);
599 myViewPort->startZoomAtPoint(myStartX, myStartY);
601 } else if (theEvent->button() == Qt::LeftButton) {
602 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
603 emit vpTransformationStarted(ROTATE);
608 /* Try to activate a transformation */
609 OperationType aState;
610 if (interactionStyle() == XGUI::STANDARD)
611 aState = getButtonState(theEvent, anInteractionStyle);
613 aState = XGUI_ViewWindow::NOTHING;
618 myViewPort->startZoomAtPoint(myStartX, myStartY);
626 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
629 if (myRotationPointSelection) {
630 if (theEvent->button() == Qt::LeftButton) {
631 Handle(AIS_InteractiveContext) ic = myViewer->AISContext();
633 for(ic->InitSelected(); ic->MoreSelected(); ic->NextSelected()) {
634 TopoDS_Shape aShape = ic->SelectedShape();
635 if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX) {
636 gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(ic->SelectedShape()));
637 /*if ( mySetRotationPointDlg ) {
638 myRotationPointSelection = false;
639 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
642 myCurrPointType = myPrevPointType;
646 if (ic->NbSelected() == 0)
647 myCurrPointType = myPrevPointType;
648 //if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
649 ic->CloseAllContexts();
650 myOperation = NOTHING;
651 myViewPort->setCursor(myCursor);
652 myCursorIsHand = false;
653 myRotationPointSelection = false;
656 emit mousePressed(this, theEvent);
659 /* notify that we start a transformation */
660 if (transformRequested())
661 emit vpTransformationStarted(myOperation);
663 if (transformRequested())
664 setTransformInProcess(true);
666 /* we may need it for sketching... */
667 /* if ( l_mbPressEvent )
668 delete l_mbPressEvent;
669 l_mbPressEvent = new QMouseEvent( *theEvent );*/
672 //****************************************************************
673 void XGUI_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
675 switch(myOperation) {
677 int prevState = myCurSketch;
678 /* if(theEvent->button() == Qt::RightButton) {
679 QList<OCCViewer_ViewSketcher*>::Iterator it;
680 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it ) {
681 OCCViewer_ViewSketcher* sk = (*it);
682 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
687 emit mouseReleased(this, theEvent);
688 if (theEvent->button() == Qt::RightButton && prevState == -1) {
689 QContextMenuEvent aEvent(QContextMenuEvent::Mouse, theEvent->pos(), theEvent->globalPos());
690 emit contextMenuRequested(&aEvent);
695 myViewPort->endRotation();
705 if (theEvent->button() == Qt::LeftButton) {
706 myViewPort->setCenter(theEvent->x(), theEvent->y());
707 myViewPort->getView()->SetScale(myCurScale);
713 if (theEvent->button() == Qt::LeftButton) {
714 myCurrX = theEvent->x();
715 myCurrY = theEvent->y();
717 QRect rect = makeRect(myStartX, myStartY, myCurrX, myCurrY);
719 myViewPort->fitRect(rect);
726 // NOTE: viewer 3D detects a rectangle of selection using this event
727 // so we must emit it BEFORE resetting the selection rectangle
728 if (theEvent->button() == Qt::LeftButton && myDrawRect) {
732 myViewPort->update();
734 /* if ( l_mbPressEvent ) {
735 delete l_mbPressEvent;
740 //****************************************************************
741 void XGUI_ViewWindow::vpMouseMoveEvent(QMouseEvent* theEvent)
743 if (myIsKeyFree && interactionStyle() == XGUI::KEY_FREE) {
745 switch(getButtonState(theEvent, interactionStyle())) {
747 myViewPort->startZoomAtPoint(myStartX, myStartY);
755 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
762 myCurrX = theEvent->x();
763 myCurrY = theEvent->y();
764 switch(myOperation) {
766 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
770 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
776 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
785 if (myRotationPointSelection /*|| isSketcherStyle()*/) {
786 emit mouseMoving(this, theEvent);
788 int aState = theEvent->modifiers();
789 int aButton = theEvent->buttons();
790 int anInteractionStyle = interactionStyle();
791 if (((anInteractionStyle == XGUI::STANDARD) && (aButton == Qt::LeftButton)
792 && (aState == Qt::NoModifier || Qt::ShiftModifier))
793 || ((anInteractionStyle == XGUI::KEY_FREE) && (aButton == Qt::LeftButton)
794 && (aState == Qt::ControlModifier
795 || aState == (Qt::ControlModifier | Qt::ShiftModifier)))) {
796 myDrawRect = myEnableDrawMode;
799 if (!myCursorIsHand) { // we are going to sketch a rectangle
800 QCursor handCursor(Qt::PointingHandCursor);
801 myCursorIsHand = true;
803 myViewPort->setCursor(handCursor);
806 emit mouseMoving(this, theEvent);
807 } /* else if ( ( (anInteractionStyle == XGUI::STANDARD) &&
808 (aButton == Qt::RightButton) &&
809 ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
810 ( (anInteractionStyle == XGUI::KEY_FREE) &&
811 (aButton == Qt::RightButton) &&
812 ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
813 OCCViewer_ViewSketcher* sketcher = 0;
814 QList<OCCViewer_ViewSketcher*>::Iterator it;
815 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it ) {
816 OCCViewer_ViewSketcher* sk = (*it);
817 if( sk->isDefault() && sk->sketchButton() == aButton )
820 if ( sketcher && myCurSketch == -1 ) {
821 activateSketching( sketcher->type() );
823 myCurSketch = mypSketcher->sketchButton();
825 if ( l_mbPressEvent ) {
826 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
827 delete l_mbPressEvent;
830 QApplication::sendEvent( getViewPort(), theEvent );
834 emit mouseMoving(this, theEvent);
840 \brief Draw rubber band rectangle.
842 void XGUI_ViewWindow::drawRect()
845 myRectBand = new XGUI_RectRubberBand(myViewPort);
848 myRectBand->setUpdatesEnabled(false);
849 QRect aRect = makeRect(myStartX, myStartY, myCurrX, myCurrY);
850 myRectBand->initGeometry(aRect);
852 if (!myRectBand->isVisible())
855 myRectBand->setUpdatesEnabled(true);
859 \brief Clear rubber band rectangle on the end on the dragging operation.
861 void XGUI_ViewWindow::endDrawRect()
864 myRectBand->clearGeometry();
869 void XGUI_ViewWindow::activateZoom()
871 if (!transformRequested() && !myCursorIsHand)
872 myCursor = cursor(); /* save old cursor */
874 if (myOperation != ZOOMVIEW) {
875 QPixmap zoomPixmap(imageZoomCursor);
876 QCursor zoomCursor(zoomPixmap);
877 if (setTransformRequested(ZOOMVIEW))
878 myViewPort->setCursor(zoomCursor);
882 bool XGUI_ViewWindow::transformRequested() const
884 return (myOperation != NOTHING);
888 \brief Start delayed viewer operation.
890 bool XGUI_ViewWindow::setTransformRequested(OperationType op)
892 bool ok = transformEnabled(op);
893 myOperation = ok ? op : NOTHING;
894 myViewPort->setMouseTracking(myOperation == NOTHING);
899 Set enabled state of transformation (rotate, zoom, etc)
901 void XGUI_ViewWindow::setTransformEnabled(const OperationType id, const bool on)
904 myStatus.insert(id, on);
908 \return enabled state of transformation (rotate, zoom, etc)
910 bool XGUI_ViewWindow::transformEnabled(const OperationType id) const
912 return myStatus.contains(id) ? myStatus[id] : true;
916 \brief Start panning operation.
918 Sets the corresponding cursor for the widget.
920 void XGUI_ViewWindow::activatePanning()
922 if (!transformRequested() && !myCursorIsHand)
923 myCursor = cursor(); // save old cursor
925 if (myOperation != PANVIEW) {
926 QCursor panCursor(Qt::SizeAllCursor);
927 if (setTransformRequested(PANVIEW))
928 myViewPort->setCursor(panCursor);
933 \brief Start global panning operation
935 Sets the corresponding cursor for the widget.
937 void XGUI_ViewWindow::activateGlobalPanning()
939 Handle(V3d_View) aView3d = myViewPort->getView();
940 if ( !aView3d.IsNull() ) {
941 QPixmap globalPanPixmap (imageCrossCursor);
942 QCursor glPanCursor (globalPanPixmap);
943 myCurScale = aView3d->Scale();
944 aView3d->FitAll(0.01, false);
945 myCursor = cursor(); // save old cursor
946 myViewPort->fitAll(); // fits view before selecting a new scene center
947 if( setTransformRequested( PANGLOBAL ) )
948 myViewPort->setCursor( glPanCursor );
953 \brief Start rotation operation
955 Sets the corresponding cursor for the widget.
957 void XGUI_ViewWindow::activateRotation()
959 if (!transformRequested() && !myCursorIsHand)
960 myCursor = cursor(); // save old cursor
962 if (myOperation != ROTATE) {
963 QPixmap rotatePixmap(imageRotateCursor);
964 QCursor rotCursor(rotatePixmap);
965 if (setTransformRequested(ROTATE))
966 myViewPort->setCursor(rotCursor);
971 \brief Reset the viewport to its initial state
972 ( no transformations in process etc. )
974 void XGUI_ViewWindow::resetState()
978 if (myRotationPointSelection) {
979 QCursor handCursor(Qt::PointingHandCursor);
980 myViewPort->setCursor(handCursor);
982 if (transformRequested() || myCursorIsHand)
983 myViewPort->setCursor(myCursor);
984 myCursorIsHand = false;
987 if (transformRequested())
988 emit vpTransformationFinished(myOperation);
990 setTransformInProcess(false);
991 setTransformRequested(NOTHING);
994 XGUI_ViewBackground XGUI_ViewWindow::background() const
996 return myViewPort ? myViewPort->background() : XGUI_ViewBackground();
999 void XGUI_ViewWindow::setBackground(const XGUI_ViewBackground& theBackground)
1002 myViewPort->setBackground( theBackground );
1006 \brief Create one more window with same content.
1008 void XGUI_ViewWindow::cloneView()
1010 QMdiSubWindow* vw = myViewer->createView();
1011 XGUI_ViewWindow* aNewWnd = static_cast<XGUI_ViewWindow*>(vw->widget());
1012 aNewWnd->viewPort()->syncronizeWith(myViewPort);
1014 emit viewCloned( vw );
1016 // In order to avoid frosen background in toolbars when it shown as a second view
1017 QTimer::singleShot(20, vw, SLOT(setFocus()));
1020 void XGUI_ViewWindow::dumpView()
1022 QString aFilter(tr("Images Files (*.bmp *.png *.jpg *.jpeg *.eps *.ps)"));
1023 QString aSelectedFilter;
1024 QString aFileName = QFileDialog::getSaveFileName(this, "Save picture", QString(), aFilter, &aSelectedFilter);
1025 if (!aFileName.isNull()) {
1026 QApplication::setOverrideCursor( Qt::WaitCursor );
1027 QImage aPicture = myViewPort->dumpView();
1029 QString aFmt = extension(aFileName).toUpper();
1030 if( aFmt.isEmpty() )
1031 aFmt = QString( "BMP" ); // default format
1032 else if( aFmt == "JPG" )
1035 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
1037 a3dView->Export(strdup(qPrintable(aFileName)), Graphic3d_EF_PostScript);
1038 else if (aFmt == "EPS")
1039 a3dView->Export(strdup(qPrintable(aFileName)), Graphic3d_EF_EnhPostScript);
1041 aPicture.save( aFileName, aFmt.toLatin1() );
1042 QApplication::restoreOverrideCursor();
1046 void XGUI_ViewWindow::fitAll()
1048 emit vpTransformationStarted( FITALLVIEW );
1049 myViewPort->fitAll();
1050 emit vpTransformationFinished( FITALLVIEW );
1054 \brief Starts fit operation.
1056 Sets the corresponding cursor for the widget.
1058 void XGUI_ViewWindow::activateWindowFit()
1060 if ( !transformRequested() && !myCursorIsHand )
1061 myCursor = cursor(); /* save old cursor */
1063 if ( myOperation != WINDOWFIT ) {
1064 QCursor handCursor (Qt::PointingHandCursor);
1065 if( setTransformRequested ( WINDOWFIT ) ) {
1066 myViewPort->setCursor ( handCursor );
1067 myCursorIsHand = true;
1074 \brief Perform "front view" transformation.
1076 void XGUI_ViewWindow::frontView()
1078 emit vpTransformationStarted ( FRONTVIEW );
1079 Handle(V3d_View) aView3d = myViewPort->getView();
1080 if ( !aView3d.IsNull() )
1081 aView3d->SetProj (V3d_Xpos);
1082 myViewPort->fitAll();
1083 emit vpTransformationFinished ( FRONTVIEW );
1087 \brief Perform "back view" transformation.
1089 void XGUI_ViewWindow::backView()
1091 emit vpTransformationStarted ( BACKVIEW );
1092 Handle(V3d_View) aView3d = myViewPort->getView();
1093 if ( !aView3d.IsNull() )
1094 aView3d->SetProj (V3d_Xneg);
1095 myViewPort->fitAll();
1096 emit vpTransformationFinished ( BACKVIEW );
1100 \brief Perform "top view" transformation.
1102 void XGUI_ViewWindow::topView()
1104 emit vpTransformationStarted ( TOPVIEW );
1105 Handle(V3d_View) aView3d = myViewPort->getView();
1106 if ( !aView3d.IsNull() )
1107 aView3d->SetProj (V3d_Zpos);
1108 myViewPort->fitAll();
1109 emit vpTransformationFinished ( TOPVIEW );
1113 \brief Perform "bottom view" transformation.
1115 void XGUI_ViewWindow::bottomView()
1117 emit vpTransformationStarted ( BOTTOMVIEW );
1118 Handle(V3d_View) aView3d = myViewPort->getView();
1119 if ( !aView3d.IsNull() )
1120 aView3d->SetProj (V3d_Zneg);
1121 myViewPort->fitAll();
1122 emit vpTransformationFinished ( BOTTOMVIEW );
1126 \brief Perform "left view" transformation.
1128 void XGUI_ViewWindow::leftView()
1130 emit vpTransformationStarted ( LEFTVIEW );
1131 Handle(V3d_View) aView3d = myViewPort->getView();
1132 if ( !aView3d.IsNull() )
1133 aView3d->SetProj (V3d_Yneg);
1134 myViewPort->fitAll();
1135 emit vpTransformationFinished ( LEFTVIEW );
1139 \brief Perform "right view" transformation.
1141 void XGUI_ViewWindow::rightView()
1143 emit vpTransformationStarted ( RIGHTVIEW );
1144 Handle(V3d_View) aView3d = myViewPort->getView();
1145 if ( !aView3d.IsNull() )
1146 aView3d->SetProj (V3d_Ypos);
1147 myViewPort->fitAll();
1148 emit vpTransformationFinished ( RIGHTVIEW );
1151 void XGUI_ViewWindow::reset()
1153 emit vpTransformationStarted( RESETVIEW );
1154 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1155 myViewPort->getView()->Reset( false );
1156 myViewPort->fitAll( false, true, false );
1157 myViewPort->getView()->SetImmediateUpdate( upd );
1158 myViewPort->getView()->Update();
1159 emit vpTransformationFinished( RESETVIEW );
1163 void XGUI_ViewWindow::updateToolBar()
1165 myGripWgt->update();
1166 myViewBar->update();
1167 myWindowBar->update();
1168 //QTimer::singleShot(50, Qt::VeryCoarseTimer, this, SLOT(repaintToolBar()));
1171 /*void XGUI_ViewWindow::repaintToolBar()
1173 QApplication::sync();
1174 myGripWgt->repaint();
1175 myViewBar->repaint();
1176 myWindowBar->repaint();