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);
117 //**************************************************************************
118 ViewerLabel::ViewerLabel(QWidget* theParent, XGUI_ViewPort* thePort)
119 : QLabel(theParent), myVPort(thePort), myResize(false)
121 connect(myVPort, SIGNAL(resized()), this, SLOT(onViewPortResized()));
124 void ViewerLabel::paintEvent(QPaintEvent* theEvent)
126 QRect aRect = rect();
127 QRect aVPRect = myVPort->rect();
128 QPoint aGlobPnt = mapToGlobal(aRect.topLeft());
129 QPoint aPnt = myVPort->mapFromGlobal(aGlobPnt);
131 QRect aImgRect(QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(),
132 aRect.width(), aRect.height()));
133 QImage aImg = myVPort->dumpView(aImgRect, myResize);
135 QPainter(this).drawImage(aRect, aImg);
137 QLabel::paintEvent(theEvent);
140 //**************************************************************************
141 //**************************************************************************
142 //**************************************************************************
143 XGUI_ViewWindow::XGUI_ViewWindow(XGUI_Viewer* theViewer, V3d_TypeOfView theType)
147 MinimizeIco(":pictures/wnd_minimize.png"),
148 MaximizeIco(":pictures/wnd_maximize.png"),
149 CloseIco(":pictures/wnd_close.png"),
150 RestoreIco(":pictures/wnd_restore.png"),
151 myInteractionStyle(XGUI::STANDARD),
154 my2dMode(XGUI::No2dMode),
155 myCurrPointType(XGUI::GRAVITY),
156 myPrevPointType(XGUI::GRAVITY),
157 myRotationPointSelection(false),
159 myStartX(0), myStartY(0), myCurrX(0), myCurrY(0), myCurScale(0.0), myCurSketch(0),
160 myDrawRect(false), myEnableDrawMode(false), myCursorIsHand(false), myEventStarted(false),
162 myLastState(WindowNormalState), myOperation(NOTHING)
164 mySelectedPoint = gp_Pnt(0., 0., 0.);
165 setFrameStyle(QFrame::Raised);
166 setFrameShape(QFrame::Panel);
167 setLineWidth(BORDER_SIZE);
168 setMouseTracking(true);
170 QVBoxLayout* aLay = new QVBoxLayout(this);
171 aLay->setContentsMargins(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE);
172 myViewPort = new XGUI_ViewPort(this, myViewer->v3dViewer(), theType);
173 myViewPort->installEventFilter(this);
174 myViewPort->setCursor(Qt::ArrowCursor);
175 aLay->addWidget(myViewPort);
177 myPicture = new QLabel(this);
178 myPicture->setFrameStyle(QFrame::Sunken);
179 myPicture->setFrameShape(QFrame::Panel);
180 myPicture->setMouseTracking(true);
181 myPicture->installEventFilter(this);
182 aLay->addWidget(myPicture);
185 QVBoxLayout* aVPLay = new QVBoxLayout(myViewPort);
186 aVPLay->setMargin(0);
187 aVPLay->setSpacing(0);
188 aVPLay->setContentsMargins(0,0,0,0);
190 QHBoxLayout* aToolLay = new QHBoxLayout();
191 aToolLay->setMargin(0);
192 aToolLay->setSpacing(0);
193 aToolLay->setContentsMargins(0,0,0,0);
194 aVPLay->addLayout(aToolLay);
195 aVPLay->addStretch();
197 myGripWgt = new ViewerLabel(this, myViewPort);
198 myGripWgt->setPixmap(QPixmap(":pictures/wnd_grip.png"));
199 myGripWgt->setMouseTracking(true);
200 myGripWgt->installEventFilter(this);
201 myGripWgt->setCursor(Qt::OpenHandCursor);
202 aToolLay->addWidget(myGripWgt);
204 // Create Viewer management buttons
205 myViewBar = new ViewerToolbar(this, myViewPort);
206 myViewBar->setCursor(Qt::PointingHandCursor);
207 aToolLay->addWidget(myViewBar);
208 aToolLay->addStretch();
213 aBtn = new QAction(QIcon(":pictures/occ_view_camera_dump.png"), tr("Dump view"), myViewBar);
214 connect(aBtn, SIGNAL(triggered()), SLOT(dumpView()));
215 myViewBar->addAction(aBtn);
217 aBtn = new QAction(QIcon(":pictures/occ_view_fitall.png"), tr("Fit all"), myViewBar);
218 connect(aBtn, SIGNAL(triggered()), SLOT(fitAll()));
219 myViewBar->addAction(aBtn);
221 aBtn = new QAction(QIcon(":pictures/occ_view_fitarea.png"), tr("Fit area"), myViewBar);
222 connect(aBtn, SIGNAL(triggered()), SLOT(activateWindowFit()));
223 myViewBar->addAction(aBtn);
225 aBtn = new QAction(QIcon(":pictures/occ_view_zoom.png"), tr("Zoom"), myViewBar);
226 connect(aBtn, SIGNAL(triggered()), SLOT(activateZoom()));
227 myViewBar->addAction(aBtn);
229 aBtn = new QAction(QIcon(":pictures/occ_view_pan.png"), tr("Panning"), myViewBar);
230 connect(aBtn, SIGNAL(triggered()), SLOT(activatePanning()));
231 myViewBar->addAction(aBtn);
233 aBtn = new QAction(QIcon(":pictures/occ_view_glpan.png"), tr("Global panning"), myViewBar);
234 connect(aBtn, SIGNAL(triggered()), SLOT(activateGlobalPanning()));
235 myViewBar->addAction(aBtn);
237 aBtn = new QAction(QIcon(":pictures/occ_view_rotate.png"), tr("Rotate"), myViewBar);
238 connect(aBtn, SIGNAL(triggered()), SLOT(activateRotation()));
239 myViewBar->addAction(aBtn);
241 aBtn = new QAction(QIcon(":pictures/occ_view_reset.png"), tr("Reset"), myViewBar);
242 connect(aBtn, SIGNAL(triggered()), SLOT(reset()));
243 myViewBar->addAction(aBtn);
245 aBtn = new QAction(QIcon(":pictures/occ_view_front.png"), tr("Front"), myViewBar);
246 connect(aBtn, SIGNAL(triggered()), SLOT(frontView()));
247 myViewBar->addAction(aBtn);
249 aBtn = new QAction(QIcon(":pictures/occ_view_back.png"), tr("Back"), myViewBar);
250 connect(aBtn, SIGNAL(triggered()), SLOT(backView()));
251 myViewBar->addAction(aBtn);
253 aBtn = new QAction(QIcon(":pictures/occ_view_top.png"), tr("Top"), myViewBar);
254 connect(aBtn, SIGNAL(triggered()), SLOT(topView()));
255 myViewBar->addAction(aBtn);
257 aBtn = new QAction(QIcon(":pictures/occ_view_bottom.png"), tr("Bottom"), myViewBar);
258 connect(aBtn, SIGNAL(triggered()), SLOT(bottomView()));
259 myViewBar->addAction(aBtn);
261 aBtn = new QAction(QIcon(":pictures/occ_view_left.png"), tr("Left"), myViewBar);
262 connect(aBtn, SIGNAL(triggered()), SLOT(leftView()));
263 myViewBar->addAction(aBtn);
265 aBtn = new QAction(QIcon(":pictures/occ_view_right.png"), tr("Right"), myViewBar);
266 connect(aBtn, SIGNAL(triggered()), SLOT(rightView()));
267 myViewBar->addAction(aBtn);
269 aBtn = new QAction(QIcon(":pictures/occ_view_clone.png"), tr("Clone"), myViewBar);
270 connect(aBtn, SIGNAL(triggered()), SLOT(cloneView()));
271 myViewBar->addAction(aBtn);
273 // Create Window management buttons
274 myWindowBar = new ViewerToolbar(this, myViewPort);
275 myWindowBar->setCursor(Qt::PointingHandCursor);
276 aToolLay->addWidget(myWindowBar);
278 myMinimizeBtn = new QAction(myWindowBar);
279 myMinimizeBtn->setIcon(MinimizeIco);
280 myWindowBar->addAction(myMinimizeBtn);
281 connect(myMinimizeBtn, SIGNAL(triggered()), SLOT(onMinimize()));
283 myMaximizeBtn = new QAction(myWindowBar);
284 myMaximizeBtn->setIcon(MaximizeIco);
285 myWindowBar->addAction(myMaximizeBtn);
286 connect(myMaximizeBtn, SIGNAL(triggered()), SLOT(onMaximize()));
288 aBtn = new QAction(myWindowBar);
289 aBtn->setIcon(CloseIco);
290 myWindowBar->addAction(aBtn);
291 connect(aBtn, SIGNAL(triggered()), SLOT(onClose()));
293 //Support copy of background on updating of viewer
294 connect(myViewPort, SIGNAL(vpTransformed()), this, SLOT(updateToolBar()));
295 connect(myViewPort, SIGNAL(vpUpdated()), this, SLOT(updateToolBar()));
296 connect(this, SIGNAL(vpTransformationFinished(XGUI_ViewWindow::OperationType)),
297 this, SLOT(updateToolBar()));
300 //****************************************************************
301 XGUI_ViewWindow::~XGUI_ViewWindow()
306 //****************************************************************
307 void XGUI_ViewWindow::showEvent(QShowEvent* theEvent)
309 QFrame::showEvent(theEvent);
310 myWindowBar->setFixedSize(myWindowBar->sizeHint());
313 //****************************************************************
314 void XGUI_ViewWindow::changeEvent(QEvent* theEvent)
317 if (theEvent->type() == QEvent::WindowStateChange) {
319 if (myPicture->isHidden()) {
327 if (myPicture->isVisible()) {
332 myMinimizeBtn->setIcon(MinimizeIco);
333 myMaximizeBtn->setIcon(RestoreIco);
335 myViewBar->setVisible(myIsActive);
336 myWindowBar->setVisible(myIsActive);
337 myGripWgt->setVisible(myIsActive && (!isMaximized()));
340 QWidget::changeEvent(theEvent);
345 //****************************************************************
346 void XGUI_ViewWindow::windowActivated()
348 if (!(isMinimized() || parentWidget()->isMinimized())) {
350 if (isMaximized() || parentWidget()->isMaximized()) {
351 myMaximizeBtn->setIcon(RestoreIco);
353 myMaximizeBtn->setIcon(MaximizeIco);
357 myGripWgt->setVisible(!(isMaximized() || isMinimized() ||
358 parentWidget()->isMaximized() || parentWidget()->isMinimized()));
363 //****************************************************************
364 void XGUI_ViewWindow::windowDeactivated()
367 if (!(isMinimized() || parentWidget()->isMinimized())) {
368 if (isMaximized() || parentWidget()->isMaximized()) {
369 myMaximizeBtn->setIcon(RestoreIco);
371 myMaximizeBtn->setIcon(MaximizeIco);
380 //****************************************************************
381 void XGUI_ViewWindow::onClose()
383 if (parentWidget()) {
384 emit tryClosing(this);
386 emit closed(static_cast<QMdiSubWindow*>(parentWidget()));
387 parentWidget()->close();
392 //****************************************************************
393 void XGUI_ViewWindow::onMinimize()
395 QPixmap aPMap = QPixmap::fromImage(myViewPort->dumpView());
398 double aR = aW / 100.;
399 int aNewH = int(aH / aR);
400 myPicture->setPixmap(aPMap.scaled(100, aNewH));
402 myLastState = (isMaximized() || parentWidget()->isMaximized()) ? MaximizedState : WindowNormalState;
404 parentWidget()->showMinimized();
405 parentWidget()->setGeometry(parentWidget()->x(), parentWidget()->y(), 100, aNewH);
406 parentWidget()->lower();
408 myViewer->onWindowMinimized((QMdiSubWindow*)parentWidget());
411 //****************************************************************
412 void XGUI_ViewWindow::onMaximize()
414 if (isMaximized() || parentWidget()->isMaximized()) {
415 myMaximizeBtn->setIcon(MaximizeIco);
418 parentWidget()->showNormal();
420 myMaximizeBtn->setIcon(RestoreIco);
423 parentWidget()->showMaximized();
425 parentWidget()->activateWindow();
426 myMinimizeBtn->setIcon(MinimizeIco);
428 // In order to avoid frosen background in toolbars when it shown as a second view
429 QTimer::singleShot(50, parentWidget(), SLOT(setFocus()));
432 //****************************************************************
433 bool XGUI_ViewWindow::processWindowControls(QObject *theObj, QEvent *theEvent)
435 switch(theEvent->type()) {
436 case QEvent::MouseButtonPress: {
437 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
438 if ((aEvent->button() == Qt::LeftButton) && (!myMoving)) {
440 myMousePnt = aEvent->globalPos();
445 case QEvent::MouseButtonRelease: {
446 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
447 if ((aEvent->button() == Qt::LeftButton) && myMoving) {
453 case QEvent::MouseMove: {
454 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
456 QMdiSubWindow* aParent = static_cast<QMdiSubWindow*>(parentWidget());
457 QMdiArea* aMDIArea = aParent->mdiArea();
459 QPoint aPnt = aEvent->globalPos();
460 QPoint aMDIPnt = aMDIArea->mapFromGlobal(aPnt);
461 if (aMDIArea->rect().contains(aMDIPnt)) {
462 int aX = aParent->x() + (aPnt.x() - myMousePnt.x());
463 int aY = aParent->y() + (aPnt.y() - myMousePnt.y());
464 aParent->move(aX, aY);
471 case QEvent::MouseButtonDblClick:
472 if (theObj == myPicture) {
474 if (myLastState == MaximizedState) {
479 myViewer->onWindowActivated((QMdiSubWindow*)parentWidget());
481 // In order to avoid frosen background in toolbars when it shown as a second view
482 QTimer::singleShot(20, parentWidget(), SLOT(setFocus()));
490 //****************************************************************
491 bool XGUI_ViewWindow::processViewPort(QEvent *theEvent)
493 switch(theEvent->type()) {
494 case QEvent::MouseButtonPress:
495 vpMousePressEvent((QMouseEvent*) theEvent);
498 case QEvent::MouseButtonRelease:
499 vpMouseReleaseEvent((QMouseEvent*) theEvent);
502 case QEvent::MouseMove:
503 vpMouseMoveEvent((QMouseEvent*) theEvent);
506 case QEvent::MouseButtonDblClick:
507 emit mouseDoubleClicked(this, (QMouseEvent*) theEvent);
511 QWheelEvent* aEvent = (QWheelEvent*) theEvent;
512 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
513 double aDelta = (double)( aEvent->delta() ) / ( 15 * 8 );
516 int x1 = (int)( aEvent->x() + width()*aDelta/100 );
517 int y1 = (int)( aEvent->y() + height()*aDelta/100 );
518 myViewPort->zoom( x, y, x1, y1 );
525 //****************************************************************
526 bool XGUI_ViewWindow::eventFilter(QObject *theObj, QEvent *theEvent)
528 if ((theObj == myGripWgt) || (theObj == myPicture)) {
529 if (processWindowControls(theObj, theEvent))
531 } else if (theObj == myViewPort) {
532 if (processViewPort(theEvent)) {
535 if (theEvent->type() == QEvent::KeyRelease) {
536 emit keyReleased(this, (QKeyEvent*) theEvent);
540 return QFrame::eventFilter(theObj, theEvent);
543 //****************************************************************
544 XGUI_ViewWindow::OperationType XGUI_ViewWindow::getButtonState(
545 QMouseEvent* theEvent, XGUI::InteractionStyle theInteractionStyle)
547 OperationType aOp = NOTHING;
548 XGUI::InteractionStyle aStyle = (XGUI::InteractionStyle) theInteractionStyle;
549 if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::ZOOM])
550 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::ZOOM]))
552 else if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::PAN])
553 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::PAN]))
555 else if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::ROTATE])
556 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::ROTATE])
557 && (my2dMode == XGUI::No2dMode))
563 //****************************************************************
564 void XGUI_ViewWindow::vpMousePressEvent(QMouseEvent* theEvent)
566 myStartX = theEvent->x();
567 myStartY = theEvent->y();
568 XGUI::InteractionStyle anInteractionStyle = interactionStyle();
570 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
571 // which are assigned for pan and rotate - these operations are activated immediately after pressing
572 // of the first button, so it is necessary to switch to zoom when the second button is pressed
573 bool aSwitchToZoom = false;
574 if ((anInteractionStyle == XGUI::KEY_FREE) && (myOperation == PANVIEW || myOperation == ROTATE)) {
575 aSwitchToZoom = getButtonState(theEvent, anInteractionStyle) == ZOOMVIEW;
578 switch(myOperation) {
580 if (theEvent->button() == Qt::LeftButton)
581 emit vpTransformationStarted(WINDOWFIT);
585 if (theEvent->button() == Qt::LeftButton)
586 emit vpTransformationStarted(PANGLOBAL);
590 if (theEvent->button() == Qt::LeftButton) {
591 myViewPort->startZoomAtPoint(myStartX, myStartY);
592 emit vpTransformationStarted(ZOOMVIEW);
598 myViewPort->startZoomAtPoint(myStartX, myStartY);
600 } else if (theEvent->button() == Qt::LeftButton)
601 emit vpTransformationStarted(PANVIEW);
606 myViewPort->startZoomAtPoint(myStartX, myStartY);
608 } else if (theEvent->button() == Qt::LeftButton) {
609 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
610 emit vpTransformationStarted(ROTATE);
615 /* Try to activate a transformation */
616 OperationType aState;
617 if (interactionStyle() == XGUI::STANDARD)
618 aState = getButtonState(theEvent, anInteractionStyle);
620 aState = XGUI_ViewWindow::NOTHING;
625 myViewPort->startZoomAtPoint(myStartX, myStartY);
633 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
636 if (myRotationPointSelection) {
637 if (theEvent->button() == Qt::LeftButton) {
638 Handle(AIS_InteractiveContext) ic = myViewer->AISContext();
640 for(ic->InitSelected(); ic->MoreSelected(); ic->NextSelected()) {
641 TopoDS_Shape aShape = ic->SelectedShape();
642 if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX) {
643 gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(ic->SelectedShape()));
644 /*if ( mySetRotationPointDlg ) {
645 myRotationPointSelection = false;
646 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
649 myCurrPointType = myPrevPointType;
653 if (ic->NbSelected() == 0)
654 myCurrPointType = myPrevPointType;
655 //if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
656 ic->CloseAllContexts();
657 myOperation = NOTHING;
658 myViewPort->setCursor(myCursor);
659 myCursorIsHand = false;
660 myRotationPointSelection = false;
663 emit mousePressed(this, theEvent);
666 /* notify that we start a transformation */
667 if (transformRequested())
668 emit vpTransformationStarted(myOperation);
670 if (transformRequested())
671 setTransformInProcess(true);
673 /* we may need it for sketching... */
674 /* if ( l_mbPressEvent )
675 delete l_mbPressEvent;
676 l_mbPressEvent = new QMouseEvent( *theEvent );*/
679 //****************************************************************
680 void XGUI_ViewWindow::contextMenuEvent(QContextMenuEvent* theEvent)
682 if (theEvent->modifiers() == Qt::NoModifier) {
683 // Temporary: has to be removed when viewer popup will be defined
684 //QFrame::contextMenuEvent(theEvent);
685 emit contextMenuRequested(theEvent);
689 //****************************************************************
690 void XGUI_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
692 switch(myOperation) {
694 int prevState = myCurSketch;
695 /* if(theEvent->button() == Qt::RightButton) {
696 QList<OCCViewer_ViewSketcher*>::Iterator it;
697 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it ) {
698 OCCViewer_ViewSketcher* sk = (*it);
699 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
704 emit mouseReleased(this, theEvent);
708 myViewPort->endRotation();
718 if (theEvent->button() == Qt::LeftButton) {
719 myViewPort->setCenter(theEvent->x(), theEvent->y());
720 myViewPort->getView()->SetScale(myCurScale);
726 if (theEvent->button() == Qt::LeftButton) {
727 myCurrX = theEvent->x();
728 myCurrY = theEvent->y();
730 QRect rect = XGUI_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
732 myViewPort->fitRect(rect);
739 // NOTE: viewer 3D detects a rectangle of selection using this event
740 // so we must emit it BEFORE resetting the selection rectangle
741 if (theEvent->button() == Qt::LeftButton && myDrawRect) {
745 myViewPort->update();
747 /* if ( l_mbPressEvent ) {
748 delete l_mbPressEvent;
753 //****************************************************************
754 void XGUI_ViewWindow::vpMouseMoveEvent(QMouseEvent* theEvent)
756 if (myIsKeyFree && interactionStyle() == XGUI::KEY_FREE) {
758 switch(getButtonState(theEvent, interactionStyle())) {
760 myViewPort->startZoomAtPoint(myStartX, myStartY);
768 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
775 myCurrX = theEvent->x();
776 myCurrY = theEvent->y();
777 switch(myOperation) {
779 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
783 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
789 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
798 if (myRotationPointSelection /*|| isSketcherStyle()*/) {
799 emit mouseMoving(this, theEvent);
801 int aState = theEvent->modifiers();
802 int aButton = theEvent->buttons();
803 int anInteractionStyle = interactionStyle();
804 if (((anInteractionStyle == XGUI::STANDARD) && (aButton == Qt::LeftButton)
805 && (aState == Qt::NoModifier || Qt::ShiftModifier))
806 || ((anInteractionStyle == XGUI::KEY_FREE) && (aButton == Qt::LeftButton)
807 && (aState == Qt::ControlModifier
808 || aState == (Qt::ControlModifier | Qt::ShiftModifier)))) {
809 myDrawRect = myEnableDrawMode;
812 if (!myCursorIsHand) { // we are going to sketch a rectangle
813 QCursor handCursor(Qt::PointingHandCursor);
814 myCursorIsHand = true;
816 myViewPort->setCursor(handCursor);
819 emit mouseMoving(this, theEvent);
820 } /* else if ( ( (anInteractionStyle == XGUI::STANDARD) &&
821 (aButton == Qt::RightButton) &&
822 ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
823 ( (anInteractionStyle == XGUI::KEY_FREE) &&
824 (aButton == Qt::RightButton) &&
825 ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
826 OCCViewer_ViewSketcher* sketcher = 0;
827 QList<OCCViewer_ViewSketcher*>::Iterator it;
828 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it ) {
829 OCCViewer_ViewSketcher* sk = (*it);
830 if( sk->isDefault() && sk->sketchButton() == aButton )
833 if ( sketcher && myCurSketch == -1 ) {
834 activateSketching( sketcher->type() );
836 myCurSketch = mypSketcher->sketchButton();
838 if ( l_mbPressEvent ) {
839 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
840 delete l_mbPressEvent;
843 QApplication::sendEvent( getViewPort(), theEvent );
847 emit mouseMoving(this, theEvent);
853 \brief Draw rubber band rectangle.
855 void XGUI_ViewWindow::drawRect()
858 myRectBand = new XGUI_RectRubberBand(myViewPort);
861 myRectBand->setUpdatesEnabled(false);
862 QRect aRect = XGUI_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
863 myRectBand->initGeometry(aRect);
865 if (!myRectBand->isVisible())
868 myRectBand->setUpdatesEnabled(true);
872 \brief Clear rubber band rectangle on the end on the dragging operation.
874 void XGUI_ViewWindow::endDrawRect()
877 myRectBand->clearGeometry();
882 void XGUI_ViewWindow::activateZoom()
884 if (!transformRequested() && !myCursorIsHand)
885 myCursor = cursor(); /* save old cursor */
887 if (myOperation != ZOOMVIEW) {
888 QPixmap zoomPixmap(imageZoomCursor);
889 QCursor zoomCursor(zoomPixmap);
890 if (setTransformRequested(ZOOMVIEW))
891 myViewPort->setCursor(zoomCursor);
895 bool XGUI_ViewWindow::transformRequested() const
897 return (myOperation != NOTHING);
901 \brief Start delayed viewer operation.
903 bool XGUI_ViewWindow::setTransformRequested(OperationType op)
905 bool ok = transformEnabled(op);
906 myOperation = ok ? op : NOTHING;
907 myViewPort->setMouseTracking(myOperation == NOTHING);
912 Set enabled state of transformation (rotate, zoom, etc)
914 void XGUI_ViewWindow::setTransformEnabled(const OperationType id, const bool on)
917 myStatus.insert(id, on);
921 \return enabled state of transformation (rotate, zoom, etc)
923 bool XGUI_ViewWindow::transformEnabled(const OperationType id) const
925 return myStatus.contains(id) ? myStatus[id] : true;
929 \brief Start panning operation.
931 Sets the corresponding cursor for the widget.
933 void XGUI_ViewWindow::activatePanning()
935 if (!transformRequested() && !myCursorIsHand)
936 myCursor = cursor(); // save old cursor
938 if (myOperation != PANVIEW) {
939 QCursor panCursor(Qt::SizeAllCursor);
940 if (setTransformRequested(PANVIEW))
941 myViewPort->setCursor(panCursor);
946 \brief Start global panning operation
948 Sets the corresponding cursor for the widget.
950 void XGUI_ViewWindow::activateGlobalPanning()
952 Handle(V3d_View) aView3d = myViewPort->getView();
953 if ( !aView3d.IsNull() ) {
954 QPixmap globalPanPixmap (imageCrossCursor);
955 QCursor glPanCursor (globalPanPixmap);
956 myCurScale = aView3d->Scale();
957 aView3d->FitAll(0.01, false);
958 myCursor = cursor(); // save old cursor
959 myViewPort->fitAll(); // fits view before selecting a new scene center
960 if( setTransformRequested( PANGLOBAL ) )
961 myViewPort->setCursor( glPanCursor );
966 \brief Start rotation operation
968 Sets the corresponding cursor for the widget.
970 void XGUI_ViewWindow::activateRotation()
972 if (!transformRequested() && !myCursorIsHand)
973 myCursor = cursor(); // save old cursor
975 if (myOperation != ROTATE) {
976 QPixmap rotatePixmap(imageRotateCursor);
977 QCursor rotCursor(rotatePixmap);
978 if (setTransformRequested(ROTATE))
979 myViewPort->setCursor(rotCursor);
984 \brief Reset the viewport to its initial state
985 ( no transformations in process etc. )
987 void XGUI_ViewWindow::resetState()
991 if (myRotationPointSelection) {
992 QCursor handCursor(Qt::PointingHandCursor);
993 myViewPort->setCursor(handCursor);
995 if (transformRequested() || myCursorIsHand)
996 myViewPort->setCursor(myCursor);
997 myCursorIsHand = false;
1000 if (transformRequested())
1001 emit vpTransformationFinished(myOperation);
1003 setTransformInProcess(false);
1004 setTransformRequested(NOTHING);
1007 Qtx::BackgroundData XGUI_ViewWindow::background() const
1009 return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
1012 void XGUI_ViewWindow::setBackground(const Qtx::BackgroundData& theBackground)
1015 myViewPort->setBackground( theBackground );
1019 \brief Create one more window with same content.
1021 void XGUI_ViewWindow::cloneView()
1023 QMdiSubWindow* vw = myViewer->createView();
1024 XGUI_ViewWindow* aNewWnd = static_cast<XGUI_ViewWindow*>(vw->widget());
1025 aNewWnd->viewPort()->syncronizeWith(myViewPort);
1027 emit viewCloned( vw );
1029 // In order to avoid frosen background in toolbars when it shown as a second view
1030 QTimer::singleShot(20, vw, SLOT(setFocus()));
1033 void XGUI_ViewWindow::dumpView()
1035 QString aFilter(tr("Images Files (*.bmp *.png *.jpg *.jpeg *.eps *.ps)"));
1036 QString aSelectedFilter;
1037 QString aFileName = QFileDialog::getSaveFileName(this, "Save picture", QString(), aFilter, &aSelectedFilter);
1038 if (!aFileName.isNull()) {
1039 QApplication::setOverrideCursor( Qt::WaitCursor );
1040 QImage aPicture = myViewPort->dumpView();
1042 QString aFmt = XGUI_Tools::extension(aFileName).toUpper();
1043 if( aFmt.isEmpty() )
1044 aFmt = QString( "BMP" ); // default format
1045 else if( aFmt == "JPG" )
1048 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
1050 a3dView->Export(strdup(qPrintable(aFileName)), Graphic3d_EF_PostScript);
1051 else if (aFmt == "EPS")
1052 a3dView->Export(strdup(qPrintable(aFileName)), Graphic3d_EF_EnhPostScript);
1054 aPicture.save( aFileName, aFmt.toLatin1() );
1055 QApplication::restoreOverrideCursor();
1059 void XGUI_ViewWindow::fitAll()
1061 emit vpTransformationStarted( FITALLVIEW );
1062 myViewPort->fitAll();
1063 emit vpTransformationFinished( FITALLVIEW );
1067 \brief Starts fit operation.
1069 Sets the corresponding cursor for the widget.
1071 void XGUI_ViewWindow::activateWindowFit()
1073 if ( !transformRequested() && !myCursorIsHand )
1074 myCursor = cursor(); /* save old cursor */
1076 if ( myOperation != WINDOWFIT ) {
1077 QCursor handCursor (Qt::PointingHandCursor);
1078 if( setTransformRequested ( WINDOWFIT ) ) {
1079 myViewPort->setCursor ( handCursor );
1080 myCursorIsHand = true;
1087 \brief Perform "front view" transformation.
1089 void XGUI_ViewWindow::frontView()
1091 emit vpTransformationStarted ( FRONTVIEW );
1092 Handle(V3d_View) aView3d = myViewPort->getView();
1093 if ( !aView3d.IsNull() )
1094 aView3d->SetProj (V3d_Xpos);
1095 myViewPort->fitAll();
1096 emit vpTransformationFinished ( FRONTVIEW );
1100 \brief Perform "back view" transformation.
1102 void XGUI_ViewWindow::backView()
1104 emit vpTransformationStarted ( BACKVIEW );
1105 Handle(V3d_View) aView3d = myViewPort->getView();
1106 if ( !aView3d.IsNull() )
1107 aView3d->SetProj (V3d_Xneg);
1108 myViewPort->fitAll();
1109 emit vpTransformationFinished ( BACKVIEW );
1113 \brief Perform "top view" transformation.
1115 void XGUI_ViewWindow::topView()
1117 emit vpTransformationStarted ( TOPVIEW );
1118 Handle(V3d_View) aView3d = myViewPort->getView();
1119 if ( !aView3d.IsNull() )
1120 aView3d->SetProj (V3d_Zpos);
1121 myViewPort->fitAll();
1122 emit vpTransformationFinished ( TOPVIEW );
1126 \brief Perform "bottom view" transformation.
1128 void XGUI_ViewWindow::bottomView()
1130 emit vpTransformationStarted ( BOTTOMVIEW );
1131 Handle(V3d_View) aView3d = myViewPort->getView();
1132 if ( !aView3d.IsNull() )
1133 aView3d->SetProj (V3d_Zneg);
1134 myViewPort->fitAll();
1135 emit vpTransformationFinished ( BOTTOMVIEW );
1139 \brief Perform "left view" transformation.
1141 void XGUI_ViewWindow::leftView()
1143 emit vpTransformationStarted ( LEFTVIEW );
1144 Handle(V3d_View) aView3d = myViewPort->getView();
1145 if ( !aView3d.IsNull() )
1146 aView3d->SetProj (V3d_Yneg);
1147 myViewPort->fitAll();
1148 emit vpTransformationFinished ( LEFTVIEW );
1152 \brief Perform "right view" transformation.
1154 void XGUI_ViewWindow::rightView()
1156 emit vpTransformationStarted ( RIGHTVIEW );
1157 Handle(V3d_View) aView3d = myViewPort->getView();
1158 if ( !aView3d.IsNull() )
1159 aView3d->SetProj (V3d_Ypos);
1160 myViewPort->fitAll();
1161 emit vpTransformationFinished ( RIGHTVIEW );
1164 void XGUI_ViewWindow::reset()
1166 emit vpTransformationStarted( RESETVIEW );
1167 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1168 myViewPort->getView()->Reset( false );
1169 myViewPort->fitAll( false, true, false );
1170 myViewPort->getView()->SetImmediateUpdate( upd );
1171 myViewPort->getView()->Update();
1172 emit vpTransformationFinished( RESETVIEW );
1176 void XGUI_ViewWindow::updateToolBar()
1178 myGripWgt->update();
1179 myViewBar->update();
1180 myWindowBar->update();
1184 \brief Update state of enable draw mode state.
1186 void XGUI_ViewWindow::updateEnabledDrawMode()
1188 myEnableDrawMode = myViewer->isSelectionEnabled() &&
1189 myViewer->isMultiSelectionEnabled();