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() ? MaximizedState : WindowNormalState;
400 //parentWidget()->showMinimized();
402 parentWidget()->setGeometry(parentWidget()->x(), parentWidget()->y(), 100, aNewH);
405 //****************************************************************
406 void XGUI_ViewWindow::onMaximize()
409 myMaximizeBtn->setIcon(MaximizeIco);
413 myMaximizeBtn->setIcon(RestoreIco);
417 myMinimizeBtn->setIcon(MinimizeIco);
420 //****************************************************************
421 bool XGUI_ViewWindow::processWindowControls(QObject *theObj, QEvent *theEvent)
423 switch(theEvent->type()) {
424 case QEvent::MouseButtonPress: {
425 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
426 if ((aEvent->button() == Qt::LeftButton) && (!myMoving)) {
428 myMousePnt = aEvent->globalPos();
433 case QEvent::MouseButtonRelease: {
434 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
435 if ((aEvent->button() == Qt::LeftButton) && myMoving) {
441 case QEvent::MouseMove: {
442 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
444 QMdiSubWindow* aParent = static_cast<QMdiSubWindow*>(parentWidget());
445 QMdiArea* aMDIArea = aParent->mdiArea();
447 QPoint aPnt = aEvent->globalPos();
448 QPoint aMDIPnt = aMDIArea->mapFromGlobal(aPnt);
449 if (aMDIArea->rect().contains(aMDIPnt)) {
450 int aX = aParent->x() + (aPnt.x() - myMousePnt.x());
451 int aY = aParent->y() + (aPnt.y() - myMousePnt.y());
452 aParent->move(aX, aY);
459 case QEvent::MouseButtonDblClick:
460 if (theObj == myPicture) {
462 if (myLastState == MaximizedState)
472 //****************************************************************
473 bool XGUI_ViewWindow::processViewPort(QEvent *theEvent)
475 switch(theEvent->type()) {
476 case QEvent::MouseButtonPress:
477 vpMousePressEvent((QMouseEvent*) theEvent);
480 case QEvent::MouseButtonRelease:
481 vpMouseReleaseEvent((QMouseEvent*) theEvent);
484 case QEvent::MouseMove:
485 vpMouseMoveEvent((QMouseEvent*) theEvent);
488 case QEvent::MouseButtonDblClick:
489 emit mouseDoubleClicked(this, (QMouseEvent*) theEvent);
493 QWheelEvent* aEvent = (QWheelEvent*) theEvent;
494 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
495 double aDelta = (double)( aEvent->delta() ) / ( 15 * 8 );
498 int x1 = (int)( aEvent->x() + width()*aDelta/100 );
499 int y1 = (int)( aEvent->y() + height()*aDelta/100 );
500 myViewPort->zoom( x, y, x1, y1 );
507 //****************************************************************
508 bool XGUI_ViewWindow::eventFilter(QObject *theObj, QEvent *theEvent)
510 if ((theObj == myGripWgt) || (theObj == myPicture)) {
511 if (processWindowControls(theObj, theEvent))
513 } else if (theObj == myViewPort) {
514 if (processViewPort(theEvent)) {
518 return QFrame::eventFilter(theObj, theEvent);
521 //****************************************************************
522 XGUI_ViewWindow::OperationType XGUI_ViewWindow::getButtonState(
523 QMouseEvent* theEvent, XGUI::InteractionStyle theInteractionStyle)
525 OperationType aOp = NOTHING;
526 XGUI::InteractionStyle aStyle = (XGUI::InteractionStyle) theInteractionStyle;
527 if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::ZOOM])
528 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::ZOOM]))
530 else if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::PAN])
531 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::PAN]))
533 else if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::ROTATE])
534 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::ROTATE])
535 && (my2dMode == XGUI::No2dMode))
541 //****************************************************************
542 void XGUI_ViewWindow::vpMousePressEvent(QMouseEvent* theEvent)
544 myStartX = theEvent->x();
545 myStartY = theEvent->y();
546 XGUI::InteractionStyle anInteractionStyle = interactionStyle();
548 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
549 // which are assigned for pan and rotate - these operations are activated immediately after pressing
550 // of the first button, so it is necessary to switch to zoom when the second button is pressed
551 bool aSwitchToZoom = false;
552 if ((anInteractionStyle == XGUI::KEY_FREE) && (myOperation == PANVIEW || myOperation == ROTATE)) {
553 aSwitchToZoom = getButtonState(theEvent, anInteractionStyle) == ZOOMVIEW;
556 switch(myOperation) {
558 if (theEvent->button() == Qt::LeftButton)
559 emit vpTransformationStarted(WINDOWFIT);
563 if (theEvent->button() == Qt::LeftButton)
564 emit vpTransformationStarted(PANGLOBAL);
568 if (theEvent->button() == Qt::LeftButton) {
569 myViewPort->startZoomAtPoint(myStartX, myStartY);
570 emit vpTransformationStarted(ZOOMVIEW);
576 myViewPort->startZoomAtPoint(myStartX, myStartY);
578 } else if (theEvent->button() == Qt::LeftButton)
579 emit vpTransformationStarted(PANVIEW);
584 myViewPort->startZoomAtPoint(myStartX, myStartY);
586 } else if (theEvent->button() == Qt::LeftButton) {
587 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
588 emit vpTransformationStarted(ROTATE);
593 /* Try to activate a transformation */
594 OperationType aState;
595 if (interactionStyle() == XGUI::STANDARD)
596 aState = getButtonState(theEvent, anInteractionStyle);
598 aState = XGUI_ViewWindow::NOTHING;
603 myViewPort->startZoomAtPoint(myStartX, myStartY);
611 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
614 if (myRotationPointSelection) {
615 if (theEvent->button() == Qt::LeftButton) {
616 Handle(AIS_InteractiveContext) ic = myViewer->AISContext();
618 for(ic->InitSelected(); ic->MoreSelected(); ic->NextSelected()) {
619 TopoDS_Shape aShape = ic->SelectedShape();
620 if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX) {
621 gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(ic->SelectedShape()));
622 /*if ( mySetRotationPointDlg ) {
623 myRotationPointSelection = false;
624 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
627 myCurrPointType = myPrevPointType;
631 if (ic->NbSelected() == 0)
632 myCurrPointType = myPrevPointType;
633 //if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
634 ic->CloseAllContexts();
635 myOperation = NOTHING;
636 myViewPort->setCursor(myCursor);
637 myCursorIsHand = false;
638 myRotationPointSelection = false;
641 emit mousePressed(this, theEvent);
644 /* notify that we start a transformation */
645 if (transformRequested())
646 emit vpTransformationStarted(myOperation);
648 if (transformRequested())
649 setTransformInProcess(true);
651 /* we may need it for sketching... */
652 /* if ( l_mbPressEvent )
653 delete l_mbPressEvent;
654 l_mbPressEvent = new QMouseEvent( *theEvent );*/
657 //****************************************************************
658 void XGUI_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
660 switch(myOperation) {
662 int prevState = myCurSketch;
663 /* if(theEvent->button() == Qt::RightButton) {
664 QList<OCCViewer_ViewSketcher*>::Iterator it;
665 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it ) {
666 OCCViewer_ViewSketcher* sk = (*it);
667 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
672 emit mouseReleased(this, theEvent);
673 if (theEvent->button() == Qt::RightButton && prevState == -1) {
674 QContextMenuEvent aEvent(QContextMenuEvent::Mouse, theEvent->pos(), theEvent->globalPos());
675 emit contextMenuRequested(&aEvent);
680 myViewPort->endRotation();
690 if (theEvent->button() == Qt::LeftButton) {
691 myViewPort->setCenter(theEvent->x(), theEvent->y());
692 myViewPort->getView()->SetScale(myCurScale);
698 if (theEvent->button() == Qt::LeftButton) {
699 myCurrX = theEvent->x();
700 myCurrY = theEvent->y();
702 QRect rect = makeRect(myStartX, myStartY, myCurrX, myCurrY);
704 myViewPort->fitRect(rect);
711 // NOTE: viewer 3D detects a rectangle of selection using this event
712 // so we must emit it BEFORE resetting the selection rectangle
713 if (theEvent->button() == Qt::LeftButton && myDrawRect) {
717 myViewPort->update();
719 /* if ( l_mbPressEvent ) {
720 delete l_mbPressEvent;
725 //****************************************************************
726 void XGUI_ViewWindow::vpMouseMoveEvent(QMouseEvent* theEvent)
728 if (myIsKeyFree && interactionStyle() == XGUI::KEY_FREE) {
730 switch(getButtonState(theEvent, interactionStyle())) {
732 myViewPort->startZoomAtPoint(myStartX, myStartY);
740 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
747 myCurrX = theEvent->x();
748 myCurrY = theEvent->y();
749 switch(myOperation) {
751 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
755 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
761 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
770 if (myRotationPointSelection /*|| isSketcherStyle()*/) {
771 emit mouseMoving(this, theEvent);
773 int aState = theEvent->modifiers();
774 int aButton = theEvent->buttons();
775 int anInteractionStyle = interactionStyle();
776 if (((anInteractionStyle == XGUI::STANDARD) && (aButton == Qt::LeftButton)
777 && (aState == Qt::NoModifier || Qt::ShiftModifier))
778 || ((anInteractionStyle == XGUI::KEY_FREE) && (aButton == Qt::LeftButton)
779 && (aState == Qt::ControlModifier
780 || aState == (Qt::ControlModifier | Qt::ShiftModifier)))) {
781 myDrawRect = myEnableDrawMode;
784 if (!myCursorIsHand) { // we are going to sketch a rectangle
785 QCursor handCursor(Qt::PointingHandCursor);
786 myCursorIsHand = true;
788 myViewPort->setCursor(handCursor);
791 emit mouseMoving(this, theEvent);
792 } /* else if ( ( (anInteractionStyle == XGUI::STANDARD) &&
793 (aButton == Qt::RightButton) &&
794 ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
795 ( (anInteractionStyle == XGUI::KEY_FREE) &&
796 (aButton == Qt::RightButton) &&
797 ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
798 OCCViewer_ViewSketcher* sketcher = 0;
799 QList<OCCViewer_ViewSketcher*>::Iterator it;
800 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it ) {
801 OCCViewer_ViewSketcher* sk = (*it);
802 if( sk->isDefault() && sk->sketchButton() == aButton )
805 if ( sketcher && myCurSketch == -1 ) {
806 activateSketching( sketcher->type() );
808 myCurSketch = mypSketcher->sketchButton();
810 if ( l_mbPressEvent ) {
811 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
812 delete l_mbPressEvent;
815 QApplication::sendEvent( getViewPort(), theEvent );
819 emit mouseMoving(this, theEvent);
825 \brief Draw rubber band rectangle.
827 void XGUI_ViewWindow::drawRect()
830 myRectBand = new XGUI_RectRubberBand(myViewPort);
833 myRectBand->setUpdatesEnabled(false);
834 QRect aRect = makeRect(myStartX, myStartY, myCurrX, myCurrY);
835 myRectBand->initGeometry(aRect);
837 if (!myRectBand->isVisible())
840 myRectBand->setUpdatesEnabled(true);
844 \brief Clear rubber band rectangle on the end on the dragging operation.
846 void XGUI_ViewWindow::endDrawRect()
849 myRectBand->clearGeometry();
854 void XGUI_ViewWindow::activateZoom()
856 if (!transformRequested() && !myCursorIsHand)
857 myCursor = cursor(); /* save old cursor */
859 if (myOperation != ZOOMVIEW) {
860 QPixmap zoomPixmap(imageZoomCursor);
861 QCursor zoomCursor(zoomPixmap);
862 if (setTransformRequested(ZOOMVIEW))
863 myViewPort->setCursor(zoomCursor);
867 bool XGUI_ViewWindow::transformRequested() const
869 return (myOperation != NOTHING);
873 \brief Start delayed viewer operation.
875 bool XGUI_ViewWindow::setTransformRequested(OperationType op)
877 bool ok = transformEnabled(op);
878 myOperation = ok ? op : NOTHING;
879 myViewPort->setMouseTracking(myOperation == NOTHING);
884 Set enabled state of transformation (rotate, zoom, etc)
886 void XGUI_ViewWindow::setTransformEnabled(const OperationType id, const bool on)
889 myStatus.insert(id, on);
893 \return enabled state of transformation (rotate, zoom, etc)
895 bool XGUI_ViewWindow::transformEnabled(const OperationType id) const
897 return myStatus.contains(id) ? myStatus[id] : true;
901 \brief Start panning operation.
903 Sets the corresponding cursor for the widget.
905 void XGUI_ViewWindow::activatePanning()
907 if (!transformRequested() && !myCursorIsHand)
908 myCursor = cursor(); // save old cursor
910 if (myOperation != PANVIEW) {
911 QCursor panCursor(Qt::SizeAllCursor);
912 if (setTransformRequested(PANVIEW))
913 myViewPort->setCursor(panCursor);
918 \brief Start global panning operation
920 Sets the corresponding cursor for the widget.
922 void XGUI_ViewWindow::activateGlobalPanning()
924 Handle(V3d_View) aView3d = myViewPort->getView();
925 if ( !aView3d.IsNull() ) {
926 QPixmap globalPanPixmap (imageCrossCursor);
927 QCursor glPanCursor (globalPanPixmap);
928 myCurScale = aView3d->Scale();
929 aView3d->FitAll(0.01, false);
930 myCursor = cursor(); // save old cursor
931 myViewPort->fitAll(); // fits view before selecting a new scene center
932 if( setTransformRequested( PANGLOBAL ) )
933 myViewPort->setCursor( glPanCursor );
938 \brief Start rotation operation
940 Sets the corresponding cursor for the widget.
942 void XGUI_ViewWindow::activateRotation()
944 if (!transformRequested() && !myCursorIsHand)
945 myCursor = cursor(); // save old cursor
947 if (myOperation != ROTATE) {
948 QPixmap rotatePixmap(imageRotateCursor);
949 QCursor rotCursor(rotatePixmap);
950 if (setTransformRequested(ROTATE))
951 myViewPort->setCursor(rotCursor);
956 \brief Reset the viewport to its initial state
957 ( no transformations in process etc. )
959 void XGUI_ViewWindow::resetState()
963 if (myRotationPointSelection) {
964 QCursor handCursor(Qt::PointingHandCursor);
965 myViewPort->setCursor(handCursor);
967 if (transformRequested() || myCursorIsHand)
968 myViewPort->setCursor(myCursor);
969 myCursorIsHand = false;
972 if (transformRequested())
973 emit vpTransformationFinished(myOperation);
975 setTransformInProcess(false);
976 setTransformRequested(NOTHING);
979 XGUI_ViewBackground XGUI_ViewWindow::background() const
981 return myViewPort ? myViewPort->background() : XGUI_ViewBackground();
984 void XGUI_ViewWindow::setBackground(const XGUI_ViewBackground& theBackground)
987 myViewPort->setBackground( theBackground );
991 \brief Create one more window with same content.
993 void XGUI_ViewWindow::cloneView()
995 QMdiSubWindow* vw = myViewer->createView();
996 XGUI_ViewWindow* aNewWnd = static_cast<XGUI_ViewWindow*>(vw->widget());
997 aNewWnd->viewPort()->syncronizeWith(myViewPort);
998 emit viewCloned( vw );
1001 void XGUI_ViewWindow::dumpView()
1003 QString aFilter(tr("Images Files (*.bmp *.png *.jpg *.jpeg *.eps *.ps)"));
1004 QString aSelectedFilter;
1005 QString aFileName = QFileDialog::getSaveFileName(this, "Save picture", QString(), aFilter, &aSelectedFilter);
1006 if (!aFileName.isNull()) {
1007 QApplication::setOverrideCursor( Qt::WaitCursor );
1008 QImage aPicture = myViewPort->dumpView();
1010 QString aFmt = extension(aFileName).toUpper();
1011 if( aFmt.isEmpty() )
1012 aFmt = QString( "BMP" ); // default format
1013 else if( aFmt == "JPG" )
1016 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
1018 a3dView->Export(strdup(qPrintable(aFileName)), Graphic3d_EF_PostScript);
1019 else if (aFmt == "EPS")
1020 a3dView->Export(strdup(qPrintable(aFileName)), Graphic3d_EF_EnhPostScript);
1022 aPicture.save( aFileName, aFmt.toLatin1() );
1023 QApplication::restoreOverrideCursor();
1027 void XGUI_ViewWindow::fitAll()
1029 emit vpTransformationStarted( FITALLVIEW );
1030 myViewPort->fitAll();
1031 emit vpTransformationFinished( FITALLVIEW );
1035 \brief Starts fit operation.
1037 Sets the corresponding cursor for the widget.
1039 void XGUI_ViewWindow::activateWindowFit()
1041 if ( !transformRequested() && !myCursorIsHand )
1042 myCursor = cursor(); /* save old cursor */
1044 if ( myOperation != WINDOWFIT ) {
1045 QCursor handCursor (Qt::PointingHandCursor);
1046 if( setTransformRequested ( WINDOWFIT ) ) {
1047 myViewPort->setCursor ( handCursor );
1048 myCursorIsHand = true;
1055 \brief Perform "front view" transformation.
1057 void XGUI_ViewWindow::frontView()
1059 emit vpTransformationStarted ( FRONTVIEW );
1060 Handle(V3d_View) aView3d = myViewPort->getView();
1061 if ( !aView3d.IsNull() )
1062 aView3d->SetProj (V3d_Xpos);
1063 myViewPort->fitAll();
1064 emit vpTransformationFinished ( FRONTVIEW );
1068 \brief Perform "back view" transformation.
1070 void XGUI_ViewWindow::backView()
1072 emit vpTransformationStarted ( BACKVIEW );
1073 Handle(V3d_View) aView3d = myViewPort->getView();
1074 if ( !aView3d.IsNull() )
1075 aView3d->SetProj (V3d_Xneg);
1076 myViewPort->fitAll();
1077 emit vpTransformationFinished ( BACKVIEW );
1081 \brief Perform "top view" transformation.
1083 void XGUI_ViewWindow::topView()
1085 emit vpTransformationStarted ( TOPVIEW );
1086 Handle(V3d_View) aView3d = myViewPort->getView();
1087 if ( !aView3d.IsNull() )
1088 aView3d->SetProj (V3d_Zpos);
1089 myViewPort->fitAll();
1090 emit vpTransformationFinished ( TOPVIEW );
1094 \brief Perform "bottom view" transformation.
1096 void XGUI_ViewWindow::bottomView()
1098 emit vpTransformationStarted ( BOTTOMVIEW );
1099 Handle(V3d_View) aView3d = myViewPort->getView();
1100 if ( !aView3d.IsNull() )
1101 aView3d->SetProj (V3d_Zneg);
1102 myViewPort->fitAll();
1103 emit vpTransformationFinished ( BOTTOMVIEW );
1107 \brief Perform "left view" transformation.
1109 void XGUI_ViewWindow::leftView()
1111 emit vpTransformationStarted ( LEFTVIEW );
1112 Handle(V3d_View) aView3d = myViewPort->getView();
1113 if ( !aView3d.IsNull() )
1114 aView3d->SetProj (V3d_Yneg);
1115 myViewPort->fitAll();
1116 emit vpTransformationFinished ( LEFTVIEW );
1120 \brief Perform "right view" transformation.
1122 void XGUI_ViewWindow::rightView()
1124 emit vpTransformationStarted ( RIGHTVIEW );
1125 Handle(V3d_View) aView3d = myViewPort->getView();
1126 if ( !aView3d.IsNull() )
1127 aView3d->SetProj (V3d_Ypos);
1128 myViewPort->fitAll();
1129 emit vpTransformationFinished ( RIGHTVIEW );
1132 void XGUI_ViewWindow::reset()
1134 emit vpTransformationStarted( RESETVIEW );
1135 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1136 myViewPort->getView()->Reset( false );
1137 myViewPort->fitAll( false, true, false );
1138 myViewPort->getView()->SetImmediateUpdate( upd );
1139 myViewPort->getView()->Update();
1140 emit vpTransformationFinished( RESETVIEW );
1144 void XGUI_ViewWindow::updateToolBar()
1146 myGripWgt->update();
1147 myViewBar->update();
1148 myWindowBar->update();
1149 //QTimer::singleShot(50, Qt::VeryCoarseTimer, this, SLOT(repaintToolBar()));
1152 /*void XGUI_ViewWindow::repaintToolBar()
1154 QApplication::sync();
1155 myGripWgt->repaint();
1156 myViewBar->repaint();
1157 myWindowBar->repaint();