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) {
298 if (parentWidget()->isMinimized()) {
307 if (parentWidget()->isMaximized()) {
308 myMinimizeBtn->setIcon(MinimizeIco);
309 myMaximizeBtn->setIcon(RestoreIco);
311 myViewBar->setVisible(myIsActive);
312 myWindowBar->setVisible(myIsActive);
313 myGripWgt->setVisible(myIsActive && (!parentWidget()->isMaximized()));
316 QWidget::changeEvent(theEvent);
321 //****************************************************************
322 void XGUI_ViewWindow::windowActivated()
327 myGripWgt->setVisible(!(parentWidget()->isMaximized() || parentWidget()->isMinimized()));
330 //****************************************************************
331 void XGUI_ViewWindow::windowDeactivated()
340 //****************************************************************
341 void XGUI_ViewWindow::onClose()
343 if (parentWidget()) {
344 emit tryClosing(this);
346 emit closed(static_cast<QMdiSubWindow*>(parentWidget()));
347 parentWidget()->close();
352 //****************************************************************
353 /*void XGUI_ViewWindow::enterEvent(QEvent* theEvent)
355 if (!isMinimized()) {
363 //****************************************************************
364 void XGUI_ViewWindow::leaveEvent(QEvent* theEvent)
371 //****************************************************************
372 void XGUI_ViewWindow::onMinimize()
374 QPixmap aPMap = QPixmap::fromImage(myViewPort->dumpView());
377 double aR = aW / 100.;
378 int aNewH = int(aH / aR);
379 myPicture->setPixmap(aPMap.scaled(100, aNewH));
381 myLastState = parentWidget()->isMaximized() ? MaximizedState : WindowNormalState;
382 parentWidget()->showMinimized();
383 parentWidget()->setGeometry(parentWidget()->x(), parentWidget()->y(), 100, aNewH);
386 //****************************************************************
387 void XGUI_ViewWindow::onMaximize()
389 if (parentWidget()->isMaximized()) {
390 myMaximizeBtn->setIcon(MaximizeIco);
392 parentWidget()->showNormal();
394 myMaximizeBtn->setIcon(RestoreIco);
396 parentWidget()->showMaximized();
398 myMinimizeBtn->setIcon(MinimizeIco);
401 //****************************************************************
402 bool XGUI_ViewWindow::processWindowControls(QObject *theObj, QEvent *theEvent)
404 switch(theEvent->type()) {
405 case QEvent::MouseButtonPress: {
406 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
407 if ((aEvent->button() == Qt::LeftButton) && (!myMoving)) {
409 myMousePnt = aEvent->globalPos();
414 case QEvent::MouseButtonRelease: {
415 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
416 if ((aEvent->button() == Qt::LeftButton) && myMoving) {
422 case QEvent::MouseMove: {
423 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
425 QMdiSubWindow* aParent = static_cast<QMdiSubWindow*>(parentWidget());
426 QMdiArea* aMDIArea = aParent->mdiArea();
428 QPoint aPnt = aEvent->globalPos();
429 QPoint aMDIPnt = aMDIArea->mapFromGlobal(aPnt);
430 if (aMDIArea->rect().contains(aMDIPnt)) {
431 int aX = aParent->x() + (aPnt.x() - myMousePnt.x());
432 int aY = aParent->y() + (aPnt.y() - myMousePnt.y());
433 aParent->move(aX, aY);
440 case QEvent::MouseButtonDblClick:
441 if (theObj == myPicture) {
443 if (myLastState == MaximizedState)
453 //****************************************************************
454 bool XGUI_ViewWindow::processViewPort(QEvent *theEvent)
456 switch(theEvent->type()) {
457 case QEvent::MouseButtonPress:
458 vpMousePressEvent((QMouseEvent*) theEvent);
461 case QEvent::MouseButtonRelease:
462 vpMouseReleaseEvent((QMouseEvent*) theEvent);
465 case QEvent::MouseMove:
466 vpMouseMoveEvent((QMouseEvent*) theEvent);
469 case QEvent::MouseButtonDblClick:
470 emit mouseDoubleClicked(this, (QMouseEvent*) theEvent);
474 QWheelEvent* aEvent = (QWheelEvent*) theEvent;
475 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
476 double aDelta = (double)( aEvent->delta() ) / ( 15 * 8 );
479 int x1 = (int)( aEvent->x() + width()*aDelta/100 );
480 int y1 = (int)( aEvent->y() + height()*aDelta/100 );
481 myViewPort->zoom( x, y, x1, y1 );
488 //****************************************************************
489 bool XGUI_ViewWindow::eventFilter(QObject *theObj, QEvent *theEvent)
491 if ((theObj == myGripWgt) || (theObj == myPicture)) {
492 if (processWindowControls(theObj, theEvent))
494 } else if (theObj == myViewPort) {
495 if (processViewPort(theEvent)) {
499 return QFrame::eventFilter(theObj, theEvent);
502 //****************************************************************
503 XGUI_ViewWindow::OperationType XGUI_ViewWindow::getButtonState(
504 QMouseEvent* theEvent, XGUI::InteractionStyle theInteractionStyle)
506 OperationType aOp = NOTHING;
507 XGUI::InteractionStyle aStyle = (XGUI::InteractionStyle) theInteractionStyle;
508 if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::ZOOM])
509 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::ZOOM]))
511 else if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::PAN])
512 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::PAN]))
514 else if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::ROTATE])
515 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::ROTATE])
516 && (my2dMode == XGUI::No2dMode))
522 //****************************************************************
523 void XGUI_ViewWindow::vpMousePressEvent(QMouseEvent* theEvent)
525 myStartX = theEvent->x();
526 myStartY = theEvent->y();
527 XGUI::InteractionStyle anInteractionStyle = interactionStyle();
529 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
530 // which are assigned for pan and rotate - these operations are activated immediately after pressing
531 // of the first button, so it is necessary to switch to zoom when the second button is pressed
532 bool aSwitchToZoom = false;
533 if ((anInteractionStyle == XGUI::KEY_FREE) && (myOperation == PANVIEW || myOperation == ROTATE)) {
534 aSwitchToZoom = getButtonState(theEvent, anInteractionStyle) == ZOOMVIEW;
537 switch(myOperation) {
539 if (theEvent->button() == Qt::LeftButton)
540 emit vpTransformationStarted(WINDOWFIT);
544 if (theEvent->button() == Qt::LeftButton)
545 emit vpTransformationStarted(PANGLOBAL);
549 if (theEvent->button() == Qt::LeftButton) {
550 myViewPort->startZoomAtPoint(myStartX, myStartY);
551 emit vpTransformationStarted(ZOOMVIEW);
557 myViewPort->startZoomAtPoint(myStartX, myStartY);
559 } else if (theEvent->button() == Qt::LeftButton)
560 emit vpTransformationStarted(PANVIEW);
565 myViewPort->startZoomAtPoint(myStartX, myStartY);
567 } else if (theEvent->button() == Qt::LeftButton) {
568 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
569 emit vpTransformationStarted(ROTATE);
574 /* Try to activate a transformation */
575 OperationType aState;
576 if (interactionStyle() == XGUI::STANDARD)
577 aState = getButtonState(theEvent, anInteractionStyle);
579 aState = XGUI_ViewWindow::NOTHING;
584 myViewPort->startZoomAtPoint(myStartX, myStartY);
592 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
595 if (myRotationPointSelection) {
596 if (theEvent->button() == Qt::LeftButton) {
597 Handle(AIS_InteractiveContext) ic = myViewer->AISContext();
599 for(ic->InitSelected(); ic->MoreSelected(); ic->NextSelected()) {
600 TopoDS_Shape aShape = ic->SelectedShape();
601 if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX) {
602 gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(ic->SelectedShape()));
603 /*if ( mySetRotationPointDlg ) {
604 myRotationPointSelection = false;
605 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
608 myCurrPointType = myPrevPointType;
612 if (ic->NbSelected() == 0)
613 myCurrPointType = myPrevPointType;
614 //if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
615 ic->CloseAllContexts();
616 myOperation = NOTHING;
617 myViewPort->setCursor(myCursor);
618 myCursorIsHand = false;
619 myRotationPointSelection = false;
622 emit mousePressed(this, theEvent);
625 /* notify that we start a transformation */
626 if (transformRequested())
627 emit vpTransformationStarted(myOperation);
629 if (transformRequested())
630 setTransformInProcess(true);
632 /* we may need it for sketching... */
633 /* if ( l_mbPressEvent )
634 delete l_mbPressEvent;
635 l_mbPressEvent = new QMouseEvent( *theEvent );*/
638 //****************************************************************
639 void XGUI_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
641 switch(myOperation) {
643 int prevState = myCurSketch;
644 /* if(theEvent->button() == Qt::RightButton) {
645 QList<OCCViewer_ViewSketcher*>::Iterator it;
646 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it ) {
647 OCCViewer_ViewSketcher* sk = (*it);
648 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
653 emit mouseReleased(this, theEvent);
654 if (theEvent->button() == Qt::RightButton && prevState == -1) {
655 QContextMenuEvent aEvent(QContextMenuEvent::Mouse, theEvent->pos(), theEvent->globalPos());
656 emit contextMenuRequested(&aEvent);
661 myViewPort->endRotation();
671 if (theEvent->button() == Qt::LeftButton) {
672 myViewPort->setCenter(theEvent->x(), theEvent->y());
673 myViewPort->getView()->SetScale(myCurScale);
679 if (theEvent->button() == Qt::LeftButton) {
680 myCurrX = theEvent->x();
681 myCurrY = theEvent->y();
683 QRect rect = makeRect(myStartX, myStartY, myCurrX, myCurrY);
685 myViewPort->fitRect(rect);
692 // NOTE: viewer 3D detects a rectangle of selection using this event
693 // so we must emit it BEFORE resetting the selection rectangle
694 if (theEvent->button() == Qt::LeftButton && myDrawRect) {
698 myViewPort->update();
700 /* if ( l_mbPressEvent ) {
701 delete l_mbPressEvent;
706 //****************************************************************
707 void XGUI_ViewWindow::vpMouseMoveEvent(QMouseEvent* theEvent)
709 if (myIsKeyFree && interactionStyle() == XGUI::KEY_FREE) {
711 switch(getButtonState(theEvent, interactionStyle())) {
713 myViewPort->startZoomAtPoint(myStartX, myStartY);
721 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
728 myCurrX = theEvent->x();
729 myCurrY = theEvent->y();
730 switch(myOperation) {
732 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
736 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
742 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
751 if (myRotationPointSelection /*|| isSketcherStyle()*/) {
752 emit mouseMoving(this, theEvent);
754 int aState = theEvent->modifiers();
755 int aButton = theEvent->buttons();
756 int anInteractionStyle = interactionStyle();
757 if (((anInteractionStyle == XGUI::STANDARD) && (aButton == Qt::LeftButton)
758 && (aState == Qt::NoModifier || Qt::ShiftModifier))
759 || ((anInteractionStyle == XGUI::KEY_FREE) && (aButton == Qt::LeftButton)
760 && (aState == Qt::ControlModifier
761 || aState == (Qt::ControlModifier | Qt::ShiftModifier)))) {
762 myDrawRect = myEnableDrawMode;
765 if (!myCursorIsHand) { // we are going to sketch a rectangle
766 QCursor handCursor(Qt::PointingHandCursor);
767 myCursorIsHand = true;
769 myViewPort->setCursor(handCursor);
772 emit mouseMoving(this, theEvent);
773 } /* else if ( ( (anInteractionStyle == XGUI::STANDARD) &&
774 (aButton == Qt::RightButton) &&
775 ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
776 ( (anInteractionStyle == XGUI::KEY_FREE) &&
777 (aButton == Qt::RightButton) &&
778 ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
779 OCCViewer_ViewSketcher* sketcher = 0;
780 QList<OCCViewer_ViewSketcher*>::Iterator it;
781 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it ) {
782 OCCViewer_ViewSketcher* sk = (*it);
783 if( sk->isDefault() && sk->sketchButton() == aButton )
786 if ( sketcher && myCurSketch == -1 ) {
787 activateSketching( sketcher->type() );
789 myCurSketch = mypSketcher->sketchButton();
791 if ( l_mbPressEvent ) {
792 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
793 delete l_mbPressEvent;
796 QApplication::sendEvent( getViewPort(), theEvent );
800 emit mouseMoving(this, theEvent);
806 \brief Draw rubber band rectangle.
808 void XGUI_ViewWindow::drawRect()
811 myRectBand = new XGUI_RectRubberBand(myViewPort);
814 myRectBand->setUpdatesEnabled(false);
815 QRect aRect = makeRect(myStartX, myStartY, myCurrX, myCurrY);
816 myRectBand->initGeometry(aRect);
818 if (!myRectBand->isVisible())
821 myRectBand->setUpdatesEnabled(true);
825 \brief Clear rubber band rectangle on the end on the dragging operation.
827 void XGUI_ViewWindow::endDrawRect()
830 myRectBand->clearGeometry();
835 void XGUI_ViewWindow::activateZoom()
837 if (!transformRequested() && !myCursorIsHand)
838 myCursor = cursor(); /* save old cursor */
840 if (myOperation != ZOOMVIEW) {
841 QPixmap zoomPixmap(imageZoomCursor);
842 QCursor zoomCursor(zoomPixmap);
843 if (setTransformRequested(ZOOMVIEW))
844 myViewPort->setCursor(zoomCursor);
848 bool XGUI_ViewWindow::transformRequested() const
850 return (myOperation != NOTHING);
854 \brief Start delayed viewer operation.
856 bool XGUI_ViewWindow::setTransformRequested(OperationType op)
858 bool ok = transformEnabled(op);
859 myOperation = ok ? op : NOTHING;
860 myViewPort->setMouseTracking(myOperation == NOTHING);
865 Set enabled state of transformation (rotate, zoom, etc)
867 void XGUI_ViewWindow::setTransformEnabled(const OperationType id, const bool on)
870 myStatus.insert(id, on);
874 \return enabled state of transformation (rotate, zoom, etc)
876 bool XGUI_ViewWindow::transformEnabled(const OperationType id) const
878 return myStatus.contains(id) ? myStatus[id] : true;
882 \brief Start panning operation.
884 Sets the corresponding cursor for the widget.
886 void XGUI_ViewWindow::activatePanning()
888 if (!transformRequested() && !myCursorIsHand)
889 myCursor = cursor(); // save old cursor
891 if (myOperation != PANVIEW) {
892 QCursor panCursor(Qt::SizeAllCursor);
893 if (setTransformRequested(PANVIEW))
894 myViewPort->setCursor(panCursor);
899 \brief Start global panning operation
901 Sets the corresponding cursor for the widget.
903 void XGUI_ViewWindow::activateGlobalPanning()
905 Handle(V3d_View) aView3d = myViewPort->getView();
906 if ( !aView3d.IsNull() ) {
907 QPixmap globalPanPixmap (imageCrossCursor);
908 QCursor glPanCursor (globalPanPixmap);
909 myCurScale = aView3d->Scale();
910 aView3d->FitAll(0.01, false);
911 myCursor = cursor(); // save old cursor
912 myViewPort->fitAll(); // fits view before selecting a new scene center
913 if( setTransformRequested( PANGLOBAL ) )
914 myViewPort->setCursor( glPanCursor );
919 \brief Start rotation operation
921 Sets the corresponding cursor for the widget.
923 void XGUI_ViewWindow::activateRotation()
925 if (!transformRequested() && !myCursorIsHand)
926 myCursor = cursor(); // save old cursor
928 if (myOperation != ROTATE) {
929 QPixmap rotatePixmap(imageRotateCursor);
930 QCursor rotCursor(rotatePixmap);
931 if (setTransformRequested(ROTATE))
932 myViewPort->setCursor(rotCursor);
937 \brief Reset the viewport to its initial state
938 ( no transformations in process etc. )
940 void XGUI_ViewWindow::resetState()
944 if (myRotationPointSelection) {
945 QCursor handCursor(Qt::PointingHandCursor);
946 myViewPort->setCursor(handCursor);
948 if (transformRequested() || myCursorIsHand)
949 myViewPort->setCursor(myCursor);
950 myCursorIsHand = false;
953 if (transformRequested())
954 emit vpTransformationFinished(myOperation);
956 setTransformInProcess(false);
957 setTransformRequested(NOTHING);
960 XGUI_ViewBackground XGUI_ViewWindow::background() const
962 return myViewPort ? myViewPort->background() : XGUI_ViewBackground();
965 void XGUI_ViewWindow::setBackground(const XGUI_ViewBackground& theBackground)
968 myViewPort->setBackground( theBackground );
972 \brief Create one more window with same content.
974 void XGUI_ViewWindow::cloneView()
976 QMdiSubWindow* vw = myViewer->createView();
977 XGUI_ViewWindow* aNewWnd = static_cast<XGUI_ViewWindow*>(vw->widget());
978 aNewWnd->viewPort()->syncronizeWith(myViewPort);
979 emit viewCloned( vw );
982 void XGUI_ViewWindow::dumpView()
984 QString aFilter(tr("Images Files (*.bmp *.png *.jpg *.jpeg *.eps *.ps)"));
985 QString aSelectedFilter;
986 QString aFileName = QFileDialog::getSaveFileName(this, "Save picture", QString(), aFilter, &aSelectedFilter);
987 if (!aFileName.isNull()) {
988 QApplication::setOverrideCursor( Qt::WaitCursor );
989 QImage aPicture = myViewPort->dumpView();
991 QString aFmt = extension(aFileName).toUpper();
993 aFmt = QString( "BMP" ); // default format
994 else if( aFmt == "JPG" )
997 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
999 a3dView->Export(strdup(qPrintable(aFileName)), Graphic3d_EF_PostScript);
1000 else if (aFmt == "EPS")
1001 a3dView->Export(strdup(qPrintable(aFileName)), Graphic3d_EF_EnhPostScript);
1003 aPicture.save( aFileName, aFmt.toLatin1() );
1004 QApplication::restoreOverrideCursor();
1008 void XGUI_ViewWindow::fitAll()
1010 emit vpTransformationStarted( FITALLVIEW );
1011 myViewPort->fitAll();
1012 emit vpTransformationFinished( FITALLVIEW );
1016 \brief Starts fit operation.
1018 Sets the corresponding cursor for the widget.
1020 void XGUI_ViewWindow::activateWindowFit()
1022 if ( !transformRequested() && !myCursorIsHand )
1023 myCursor = cursor(); /* save old cursor */
1025 if ( myOperation != WINDOWFIT ) {
1026 QCursor handCursor (Qt::PointingHandCursor);
1027 if( setTransformRequested ( WINDOWFIT ) ) {
1028 myViewPort->setCursor ( handCursor );
1029 myCursorIsHand = true;
1036 \brief Perform "front view" transformation.
1038 void XGUI_ViewWindow::frontView()
1040 emit vpTransformationStarted ( FRONTVIEW );
1041 Handle(V3d_View) aView3d = myViewPort->getView();
1042 if ( !aView3d.IsNull() )
1043 aView3d->SetProj (V3d_Xpos);
1044 myViewPort->fitAll();
1045 emit vpTransformationFinished ( FRONTVIEW );
1049 \brief Perform "back view" transformation.
1051 void XGUI_ViewWindow::backView()
1053 emit vpTransformationStarted ( BACKVIEW );
1054 Handle(V3d_View) aView3d = myViewPort->getView();
1055 if ( !aView3d.IsNull() )
1056 aView3d->SetProj (V3d_Xneg);
1057 myViewPort->fitAll();
1058 emit vpTransformationFinished ( BACKVIEW );
1062 \brief Perform "top view" transformation.
1064 void XGUI_ViewWindow::topView()
1066 emit vpTransformationStarted ( TOPVIEW );
1067 Handle(V3d_View) aView3d = myViewPort->getView();
1068 if ( !aView3d.IsNull() )
1069 aView3d->SetProj (V3d_Zpos);
1070 myViewPort->fitAll();
1071 emit vpTransformationFinished ( TOPVIEW );
1075 \brief Perform "bottom view" transformation.
1077 void XGUI_ViewWindow::bottomView()
1079 emit vpTransformationStarted ( BOTTOMVIEW );
1080 Handle(V3d_View) aView3d = myViewPort->getView();
1081 if ( !aView3d.IsNull() )
1082 aView3d->SetProj (V3d_Zneg);
1083 myViewPort->fitAll();
1084 emit vpTransformationFinished ( BOTTOMVIEW );
1088 \brief Perform "left view" transformation.
1090 void XGUI_ViewWindow::leftView()
1092 emit vpTransformationStarted ( LEFTVIEW );
1093 Handle(V3d_View) aView3d = myViewPort->getView();
1094 if ( !aView3d.IsNull() )
1095 aView3d->SetProj (V3d_Yneg);
1096 myViewPort->fitAll();
1097 emit vpTransformationFinished ( LEFTVIEW );
1101 \brief Perform "right view" transformation.
1103 void XGUI_ViewWindow::rightView()
1105 emit vpTransformationStarted ( RIGHTVIEW );
1106 Handle(V3d_View) aView3d = myViewPort->getView();
1107 if ( !aView3d.IsNull() )
1108 aView3d->SetProj (V3d_Ypos);
1109 myViewPort->fitAll();
1110 emit vpTransformationFinished ( RIGHTVIEW );
1113 void XGUI_ViewWindow::reset()
1115 emit vpTransformationStarted( RESETVIEW );
1116 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1117 myViewPort->getView()->Reset( false );
1118 myViewPort->fitAll( false, true, false );
1119 myViewPort->getView()->SetImmediateUpdate( upd );
1120 myViewPort->getView()->Update();
1121 emit vpTransformationFinished( RESETVIEW );
1125 void XGUI_ViewWindow::updateToolBar()
1127 myGripWgt->update();
1128 myViewBar->update();
1129 myWindowBar->update();
1130 //QTimer::singleShot(50, Qt::VeryCoarseTimer, this, SLOT(repaintToolBar()));
1133 /*void XGUI_ViewWindow::repaintToolBar()
1135 QApplication::sync();
1136 myGripWgt->repaint();
1137 myViewBar->repaint();
1138 myWindowBar->repaint();