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 //qDebug("### ViewerToolbar::paintEvent %i\n", AA++);
86 QPainter aPainter(this);
88 QRect aVPRect = myVPort->rect();
89 QPoint aGlobPnt = mapToGlobal(aRect.topLeft());
90 QPoint aPnt = myVPort->mapFromGlobal(aGlobPnt);
92 QRect aImgRect(QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(),
93 aRect.width(), aRect.height()));
94 aPainter.drawImage(aRect, myVPort->dumpView(aImgRect, false));
97 QStyle *style = this->style();
98 QStyleOptionToolBar aOpt;
99 initStyleOption(&aOpt);
101 aOpt.rect = style->subElementRect(QStyle::SE_ToolBarHandle, &aOpt, this);
102 if (aOpt.rect.isValid())
103 style->drawPrimitive(QStyle::PE_IndicatorToolBarHandle, &aOpt, &aPainter, this);
106 //**************************************************************************
107 void ViewerLabel::repaintBackground()
109 QRect aRect = rect();
110 QRect aVPRect = myVPort->rect();
111 QPoint aGlobPnt = mapToGlobal(aRect.topLeft());
112 QPoint aPnt = myVPort->mapFromGlobal(aGlobPnt);
114 QRect aImgRect(QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(),
115 aRect.width(), aRect.height()));
116 QPainter(this).drawImage(aRect, myVPort->dumpView(aImgRect, false));
119 void ViewerLabel::paintEvent(QPaintEvent* theEvent)
122 QLabel::paintEvent(theEvent);
125 //**************************************************************************
126 //**************************************************************************
127 //**************************************************************************
128 XGUI_ViewWindow::XGUI_ViewWindow(XGUI_Viewer* theViewer, V3d_TypeOfView theType)
132 MinimizeIco(":pictures/wnd_minimize.png"),
133 MaximizeIco(":pictures/wnd_maximize.png"),
134 CloseIco(":pictures/wnd_close.png"),
135 RestoreIco(":pictures/wnd_restore.png"),
136 myInteractionStyle(XGUI::STANDARD),
139 my2dMode(XGUI::No2dMode),
140 myCurrPointType(XGUI::GRAVITY),
141 myPrevPointType(XGUI::GRAVITY),
142 myRotationPointSelection(false),
144 myStartX(0), myStartY(0), myCurrX(0), myCurrY(0), myCurScale(0.0), myCurSketch(0),
145 myDrawRect(false), myEnableDrawMode(true), myCursorIsHand(false), myEventStarted(false),
147 myLastState(WindowNormalState), myOperation(NOTHING)
149 mySelectedPoint = gp_Pnt(0., 0., 0.);
150 setFrameStyle(QFrame::Raised);
151 setFrameShape(QFrame::Panel);
152 setLineWidth(BORDER_SIZE);
153 setMouseTracking(true);
155 QVBoxLayout* aLay = new QVBoxLayout(this);
156 aLay->setContentsMargins(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE);
157 myViewPort = new XGUI_ViewPort(this, myViewer->v3dViewer(), theType);
158 myViewPort->installEventFilter(this);
159 myViewPort->setCursor(Qt::ArrowCursor);
160 aLay->addWidget(myViewPort);
162 myPicture = new QLabel(this);
163 myPicture->setFrameStyle(QFrame::Sunken);
164 myPicture->setFrameShape(QFrame::Panel);
165 myPicture->setMouseTracking(true);
166 myPicture->installEventFilter(this);
167 aLay->addWidget(myPicture);
170 QVBoxLayout* aVPLay = new QVBoxLayout(myViewPort);
171 aVPLay->setMargin(0);
172 aVPLay->setSpacing(0);
173 aVPLay->setContentsMargins(0,0,0,0);
175 QHBoxLayout* aToolLay = new QHBoxLayout();
176 aToolLay->setMargin(0);
177 aToolLay->setSpacing(0);
178 aVPLay->setContentsMargins(0,0,0,0);
179 aVPLay->addLayout(aToolLay);
180 aVPLay->addStretch();
182 myGripWgt = new ViewerLabel(this, myViewPort);
183 myGripWgt->setPixmap(QPixmap(":pictures/wnd_grip.png"));
184 myGripWgt->setMouseTracking(true);
185 myGripWgt->installEventFilter(this);
186 myGripWgt->setCursor(Qt::OpenHandCursor);
187 aToolLay->addWidget(myGripWgt);
189 // Create Viewer management buttons
190 myViewBar = new ViewerToolbar(this, myViewPort);
191 myViewBar->setCursor(Qt::PointingHandCursor);
192 aToolLay->addWidget(myViewBar);
193 aToolLay->addStretch();
198 aBtn = new QAction(QIcon(":pictures/occ_view_camera_dump.png"), tr("Dump view"), myViewBar);
199 connect(aBtn, SIGNAL(triggered()), SLOT(dumpView()));
200 myViewBar->addAction(aBtn);
202 aBtn = new QAction(QIcon(":pictures/occ_view_fitall.png"), tr("Fit all"), myViewBar);
203 connect(aBtn, SIGNAL(triggered()), SLOT(fitAll()));
204 myViewBar->addAction(aBtn);
206 aBtn = new QAction(QIcon(":pictures/occ_view_fitarea.png"), tr("Fit area"), myViewBar);
207 connect(aBtn, SIGNAL(triggered()), SLOT(activateWindowFit()));
208 myViewBar->addAction(aBtn);
210 aBtn = new QAction(QIcon(":pictures/occ_view_zoom.png"), tr("Zoom"), myViewBar);
211 connect(aBtn, SIGNAL(triggered()), SLOT(activateZoom()));
212 myViewBar->addAction(aBtn);
214 aBtn = new QAction(QIcon(":pictures/occ_view_pan.png"), tr("Panning"), myViewBar);
215 connect(aBtn, SIGNAL(triggered()), SLOT(activatePanning()));
216 myViewBar->addAction(aBtn);
218 aBtn = new QAction(QIcon(":pictures/occ_view_glpan.png"), tr("Global panning"), myViewBar);
219 connect(aBtn, SIGNAL(triggered()), SLOT(activateGlobalPanning()));
220 myViewBar->addAction(aBtn);
222 aBtn = new QAction(QIcon(":pictures/occ_view_rotate.png"), tr("Rotate"), myViewBar);
223 connect(aBtn, SIGNAL(triggered()), SLOT(activateRotation()));
224 myViewBar->addAction(aBtn);
226 aBtn = new QAction(QIcon(":pictures/occ_view_reset.png"), tr("Reset"), myViewBar);
227 connect(aBtn, SIGNAL(triggered()), SLOT(reset()));
228 myViewBar->addAction(aBtn);
230 aBtn = new QAction(QIcon(":pictures/occ_view_front.png"), tr("Front"), myViewBar);
231 connect(aBtn, SIGNAL(triggered()), SLOT(frontView()));
232 myViewBar->addAction(aBtn);
234 aBtn = new QAction(QIcon(":pictures/occ_view_back.png"), tr("Back"), myViewBar);
235 connect(aBtn, SIGNAL(triggered()), SLOT(backView()));
236 myViewBar->addAction(aBtn);
238 aBtn = new QAction(QIcon(":pictures/occ_view_top.png"), tr("Top"), myViewBar);
239 connect(aBtn, SIGNAL(triggered()), SLOT(topView()));
240 myViewBar->addAction(aBtn);
242 aBtn = new QAction(QIcon(":pictures/occ_view_bottom.png"), tr("Bottom"), myViewBar);
243 connect(aBtn, SIGNAL(triggered()), SLOT(bottomView()));
244 myViewBar->addAction(aBtn);
246 aBtn = new QAction(QIcon(":pictures/occ_view_left.png"), tr("Left"), myViewBar);
247 connect(aBtn, SIGNAL(triggered()), SLOT(leftView()));
248 myViewBar->addAction(aBtn);
250 aBtn = new QAction(QIcon(":pictures/occ_view_right.png"), tr("Right"), myViewBar);
251 connect(aBtn, SIGNAL(triggered()), SLOT(rightView()));
252 myViewBar->addAction(aBtn);
254 aBtn = new QAction(QIcon(":pictures/occ_view_clone.png"), tr("Clone"), myViewBar);
255 connect(aBtn, SIGNAL(triggered()), SLOT(cloneView()));
256 myViewBar->addAction(aBtn);
258 // Create Window management buttons
259 myWindowBar = new ViewerToolbar(this, myViewPort);
260 myWindowBar->setCursor(Qt::PointingHandCursor);
261 aToolLay->addWidget(myWindowBar);
263 myMinimizeBtn = new QAction(myWindowBar);
264 myMinimizeBtn->setIcon(MinimizeIco);
265 myWindowBar->addAction(myMinimizeBtn);
266 connect(myMinimizeBtn, SIGNAL(triggered()), SLOT(onMinimize()));
268 myMaximizeBtn = new QAction(myWindowBar);
269 myMaximizeBtn->setIcon(MaximizeIco);
270 myWindowBar->addAction(myMaximizeBtn);
271 connect(myMaximizeBtn, SIGNAL(triggered()), SLOT(onMaximize()));
273 aBtn = new QAction(myWindowBar);
274 aBtn->setIcon(CloseIco);
275 myWindowBar->addAction(aBtn);
276 connect(aBtn, SIGNAL(triggered()), SLOT(onClose()));
278 //Support copy of background on updating of viewer
279 connect(myViewPort, SIGNAL(vpTransformed()), this, SLOT(updateToolBar()));
280 connect(myViewPort, SIGNAL(vpUpdated()), this, SLOT(updateToolBar()));
281 connect(this, SIGNAL(vpTransformationFinished(XGUI_ViewWindow::OperationType)),
282 this, SLOT(updateToolBar()));
286 //****************************************************************
287 XGUI_ViewWindow::~XGUI_ViewWindow()
292 //****************************************************************
293 void XGUI_ViewWindow::showEvent(QShowEvent* theEvent)
295 QFrame::showEvent(theEvent);
296 myWindowBar->setFixedSize(myWindowBar->sizeHint());
299 //****************************************************************
300 void XGUI_ViewWindow::changeEvent(QEvent* theEvent)
303 if (theEvent->type() == QEvent::WindowStateChange) {
305 if (myPicture->isHidden()) {
313 if (myPicture->isVisible()) {
318 myMinimizeBtn->setIcon(MinimizeIco);
319 myMaximizeBtn->setIcon(RestoreIco);
321 myViewBar->setVisible(myIsActive);
322 myWindowBar->setVisible(myIsActive);
323 myGripWgt->setVisible(myIsActive && (!isMaximized()));
326 QWidget::changeEvent(theEvent);
331 //****************************************************************
332 void XGUI_ViewWindow::windowActivated()
334 if (!(isMinimized() || parentWidget()->isMinimized())) {
336 if (isMaximized() || parentWidget()->isMaximized()) {
337 myMaximizeBtn->setIcon(RestoreIco);
339 myMaximizeBtn->setIcon(MaximizeIco);
343 myGripWgt->setVisible(!(isMaximized() || isMinimized()));
348 //****************************************************************
349 void XGUI_ViewWindow::windowDeactivated()
352 if (!(isMinimized() || parentWidget()->isMinimized())) {
353 if (isMaximized() || parentWidget()->isMaximized()) {
354 myMaximizeBtn->setIcon(RestoreIco);
356 myMaximizeBtn->setIcon(MaximizeIco);
365 //****************************************************************
366 void XGUI_ViewWindow::onClose()
368 if (parentWidget()) {
369 emit tryClosing(this);
371 emit closed(static_cast<QMdiSubWindow*>(parentWidget()));
372 parentWidget()->close();
377 //****************************************************************
378 void XGUI_ViewWindow::onMinimize()
380 QPixmap aPMap = QPixmap::fromImage(myViewPort->dumpView());
383 double aR = aW / 100.;
384 int aNewH = int(aH / aR);
385 myPicture->setPixmap(aPMap.scaled(100, aNewH));
387 myLastState = (isMaximized() || parentWidget()->isMaximized()) ? MaximizedState : WindowNormalState;
389 parentWidget()->showMinimized();
390 parentWidget()->setGeometry(parentWidget()->x(), parentWidget()->y(), 100, aNewH);
391 parentWidget()->lower();
393 myViewer->onWindowMinimized((QMdiSubWindow*)parentWidget());
396 //****************************************************************
397 void XGUI_ViewWindow::onMaximize()
399 if (isMaximized() || parentWidget()->isMaximized()) {
400 myMaximizeBtn->setIcon(MaximizeIco);
403 parentWidget()->showNormal();
405 myMaximizeBtn->setIcon(RestoreIco);
408 parentWidget()->showMaximized();
410 parentWidget()->activateWindow();
411 myMinimizeBtn->setIcon(MinimizeIco);
414 //****************************************************************
415 bool XGUI_ViewWindow::processWindowControls(QObject *theObj, QEvent *theEvent)
417 switch(theEvent->type()) {
418 case QEvent::MouseButtonPress: {
419 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
420 if ((aEvent->button() == Qt::LeftButton) && (!myMoving)) {
422 myMousePnt = aEvent->globalPos();
427 case QEvent::MouseButtonRelease: {
428 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
429 if ((aEvent->button() == Qt::LeftButton) && myMoving) {
435 case QEvent::MouseMove: {
436 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
438 QMdiSubWindow* aParent = static_cast<QMdiSubWindow*>(parentWidget());
439 QMdiArea* aMDIArea = aParent->mdiArea();
441 QPoint aPnt = aEvent->globalPos();
442 QPoint aMDIPnt = aMDIArea->mapFromGlobal(aPnt);
443 if (aMDIArea->rect().contains(aMDIPnt)) {
444 int aX = aParent->x() + (aPnt.x() - myMousePnt.x());
445 int aY = aParent->y() + (aPnt.y() - myMousePnt.y());
446 aParent->move(aX, aY);
453 case QEvent::MouseButtonDblClick:
454 if (theObj == myPicture) {
456 if (myLastState == MaximizedState) {
462 myViewer->onWindowActivated((QMdiSubWindow*)parentWidget());
469 //****************************************************************
470 bool XGUI_ViewWindow::processViewPort(QEvent *theEvent)
472 switch(theEvent->type()) {
473 case QEvent::MouseButtonPress:
474 vpMousePressEvent((QMouseEvent*) theEvent);
477 case QEvent::MouseButtonRelease:
478 vpMouseReleaseEvent((QMouseEvent*) theEvent);
481 case QEvent::MouseMove:
482 vpMouseMoveEvent((QMouseEvent*) theEvent);
485 case QEvent::MouseButtonDblClick:
486 emit mouseDoubleClicked(this, (QMouseEvent*) theEvent);
490 QWheelEvent* aEvent = (QWheelEvent*) theEvent;
491 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
492 double aDelta = (double)( aEvent->delta() ) / ( 15 * 8 );
495 int x1 = (int)( aEvent->x() + width()*aDelta/100 );
496 int y1 = (int)( aEvent->y() + height()*aDelta/100 );
497 myViewPort->zoom( x, y, x1, y1 );
504 //****************************************************************
505 bool XGUI_ViewWindow::eventFilter(QObject *theObj, QEvent *theEvent)
507 if ((theObj == myGripWgt) || (theObj == myPicture)) {
508 if (processWindowControls(theObj, theEvent))
510 } else if (theObj == myViewPort) {
511 if (processViewPort(theEvent)) {
515 return QFrame::eventFilter(theObj, theEvent);
518 //****************************************************************
519 XGUI_ViewWindow::OperationType XGUI_ViewWindow::getButtonState(
520 QMouseEvent* theEvent, XGUI::InteractionStyle theInteractionStyle)
522 OperationType aOp = NOTHING;
523 XGUI::InteractionStyle aStyle = (XGUI::InteractionStyle) theInteractionStyle;
524 if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::ZOOM])
525 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::ZOOM]))
527 else if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::PAN])
528 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::PAN]))
530 else if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::ROTATE])
531 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::ROTATE])
532 && (my2dMode == XGUI::No2dMode))
538 //****************************************************************
539 void XGUI_ViewWindow::vpMousePressEvent(QMouseEvent* theEvent)
541 myStartX = theEvent->x();
542 myStartY = theEvent->y();
543 XGUI::InteractionStyle anInteractionStyle = interactionStyle();
545 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
546 // which are assigned for pan and rotate - these operations are activated immediately after pressing
547 // of the first button, so it is necessary to switch to zoom when the second button is pressed
548 bool aSwitchToZoom = false;
549 if ((anInteractionStyle == XGUI::KEY_FREE) && (myOperation == PANVIEW || myOperation == ROTATE)) {
550 aSwitchToZoom = getButtonState(theEvent, anInteractionStyle) == ZOOMVIEW;
553 switch(myOperation) {
555 if (theEvent->button() == Qt::LeftButton)
556 emit vpTransformationStarted(WINDOWFIT);
560 if (theEvent->button() == Qt::LeftButton)
561 emit vpTransformationStarted(PANGLOBAL);
565 if (theEvent->button() == Qt::LeftButton) {
566 myViewPort->startZoomAtPoint(myStartX, myStartY);
567 emit vpTransformationStarted(ZOOMVIEW);
573 myViewPort->startZoomAtPoint(myStartX, myStartY);
575 } else if (theEvent->button() == Qt::LeftButton)
576 emit vpTransformationStarted(PANVIEW);
581 myViewPort->startZoomAtPoint(myStartX, myStartY);
583 } else if (theEvent->button() == Qt::LeftButton) {
584 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
585 emit vpTransformationStarted(ROTATE);
590 /* Try to activate a transformation */
591 OperationType aState;
592 if (interactionStyle() == XGUI::STANDARD)
593 aState = getButtonState(theEvent, anInteractionStyle);
595 aState = XGUI_ViewWindow::NOTHING;
600 myViewPort->startZoomAtPoint(myStartX, myStartY);
608 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
611 if (myRotationPointSelection) {
612 if (theEvent->button() == Qt::LeftButton) {
613 Handle(AIS_InteractiveContext) ic = myViewer->AISContext();
615 for(ic->InitSelected(); ic->MoreSelected(); ic->NextSelected()) {
616 TopoDS_Shape aShape = ic->SelectedShape();
617 if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX) {
618 gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(ic->SelectedShape()));
619 /*if ( mySetRotationPointDlg ) {
620 myRotationPointSelection = false;
621 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
624 myCurrPointType = myPrevPointType;
628 if (ic->NbSelected() == 0)
629 myCurrPointType = myPrevPointType;
630 //if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
631 ic->CloseAllContexts();
632 myOperation = NOTHING;
633 myViewPort->setCursor(myCursor);
634 myCursorIsHand = false;
635 myRotationPointSelection = false;
638 emit mousePressed(this, theEvent);
641 /* notify that we start a transformation */
642 if (transformRequested())
643 emit vpTransformationStarted(myOperation);
645 if (transformRequested())
646 setTransformInProcess(true);
648 /* we may need it for sketching... */
649 /* if ( l_mbPressEvent )
650 delete l_mbPressEvent;
651 l_mbPressEvent = new QMouseEvent( *theEvent );*/
654 //****************************************************************
655 void XGUI_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
657 switch(myOperation) {
659 int prevState = myCurSketch;
660 /* if(theEvent->button() == Qt::RightButton) {
661 QList<OCCViewer_ViewSketcher*>::Iterator it;
662 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it ) {
663 OCCViewer_ViewSketcher* sk = (*it);
664 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
669 emit mouseReleased(this, theEvent);
670 if (theEvent->button() == Qt::RightButton && prevState == -1) {
671 QContextMenuEvent aEvent(QContextMenuEvent::Mouse, theEvent->pos(), theEvent->globalPos());
672 emit contextMenuRequested(&aEvent);
677 myViewPort->endRotation();
687 if (theEvent->button() == Qt::LeftButton) {
688 myViewPort->setCenter(theEvent->x(), theEvent->y());
689 myViewPort->getView()->SetScale(myCurScale);
695 if (theEvent->button() == Qt::LeftButton) {
696 myCurrX = theEvent->x();
697 myCurrY = theEvent->y();
699 QRect rect = makeRect(myStartX, myStartY, myCurrX, myCurrY);
701 myViewPort->fitRect(rect);
708 // NOTE: viewer 3D detects a rectangle of selection using this event
709 // so we must emit it BEFORE resetting the selection rectangle
710 if (theEvent->button() == Qt::LeftButton && myDrawRect) {
714 myViewPort->update();
716 /* if ( l_mbPressEvent ) {
717 delete l_mbPressEvent;
722 //****************************************************************
723 void XGUI_ViewWindow::vpMouseMoveEvent(QMouseEvent* theEvent)
725 if (myIsKeyFree && interactionStyle() == XGUI::KEY_FREE) {
727 switch(getButtonState(theEvent, interactionStyle())) {
729 myViewPort->startZoomAtPoint(myStartX, myStartY);
737 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
744 myCurrX = theEvent->x();
745 myCurrY = theEvent->y();
746 switch(myOperation) {
748 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
752 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
758 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
767 if (myRotationPointSelection /*|| isSketcherStyle()*/) {
768 emit mouseMoving(this, theEvent);
770 int aState = theEvent->modifiers();
771 int aButton = theEvent->buttons();
772 int anInteractionStyle = interactionStyle();
773 if (((anInteractionStyle == XGUI::STANDARD) && (aButton == Qt::LeftButton)
774 && (aState == Qt::NoModifier || Qt::ShiftModifier))
775 || ((anInteractionStyle == XGUI::KEY_FREE) && (aButton == Qt::LeftButton)
776 && (aState == Qt::ControlModifier
777 || aState == (Qt::ControlModifier | Qt::ShiftModifier)))) {
778 myDrawRect = myEnableDrawMode;
781 if (!myCursorIsHand) { // we are going to sketch a rectangle
782 QCursor handCursor(Qt::PointingHandCursor);
783 myCursorIsHand = true;
785 myViewPort->setCursor(handCursor);
788 emit mouseMoving(this, theEvent);
789 } /* else if ( ( (anInteractionStyle == XGUI::STANDARD) &&
790 (aButton == Qt::RightButton) &&
791 ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
792 ( (anInteractionStyle == XGUI::KEY_FREE) &&
793 (aButton == Qt::RightButton) &&
794 ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
795 OCCViewer_ViewSketcher* sketcher = 0;
796 QList<OCCViewer_ViewSketcher*>::Iterator it;
797 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it ) {
798 OCCViewer_ViewSketcher* sk = (*it);
799 if( sk->isDefault() && sk->sketchButton() == aButton )
802 if ( sketcher && myCurSketch == -1 ) {
803 activateSketching( sketcher->type() );
805 myCurSketch = mypSketcher->sketchButton();
807 if ( l_mbPressEvent ) {
808 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
809 delete l_mbPressEvent;
812 QApplication::sendEvent( getViewPort(), theEvent );
816 emit mouseMoving(this, theEvent);
822 \brief Draw rubber band rectangle.
824 void XGUI_ViewWindow::drawRect()
827 myRectBand = new XGUI_RectRubberBand(myViewPort);
830 myRectBand->setUpdatesEnabled(false);
831 QRect aRect = makeRect(myStartX, myStartY, myCurrX, myCurrY);
832 myRectBand->initGeometry(aRect);
834 if (!myRectBand->isVisible())
837 myRectBand->setUpdatesEnabled(true);
841 \brief Clear rubber band rectangle on the end on the dragging operation.
843 void XGUI_ViewWindow::endDrawRect()
846 myRectBand->clearGeometry();
851 void XGUI_ViewWindow::activateZoom()
853 if (!transformRequested() && !myCursorIsHand)
854 myCursor = cursor(); /* save old cursor */
856 if (myOperation != ZOOMVIEW) {
857 QPixmap zoomPixmap(imageZoomCursor);
858 QCursor zoomCursor(zoomPixmap);
859 if (setTransformRequested(ZOOMVIEW))
860 myViewPort->setCursor(zoomCursor);
864 bool XGUI_ViewWindow::transformRequested() const
866 return (myOperation != NOTHING);
870 \brief Start delayed viewer operation.
872 bool XGUI_ViewWindow::setTransformRequested(OperationType op)
874 bool ok = transformEnabled(op);
875 myOperation = ok ? op : NOTHING;
876 myViewPort->setMouseTracking(myOperation == NOTHING);
881 Set enabled state of transformation (rotate, zoom, etc)
883 void XGUI_ViewWindow::setTransformEnabled(const OperationType id, const bool on)
886 myStatus.insert(id, on);
890 \return enabled state of transformation (rotate, zoom, etc)
892 bool XGUI_ViewWindow::transformEnabled(const OperationType id) const
894 return myStatus.contains(id) ? myStatus[id] : true;
898 \brief Start panning operation.
900 Sets the corresponding cursor for the widget.
902 void XGUI_ViewWindow::activatePanning()
904 if (!transformRequested() && !myCursorIsHand)
905 myCursor = cursor(); // save old cursor
907 if (myOperation != PANVIEW) {
908 QCursor panCursor(Qt::SizeAllCursor);
909 if (setTransformRequested(PANVIEW))
910 myViewPort->setCursor(panCursor);
915 \brief Start global panning operation
917 Sets the corresponding cursor for the widget.
919 void XGUI_ViewWindow::activateGlobalPanning()
921 Handle(V3d_View) aView3d = myViewPort->getView();
922 if ( !aView3d.IsNull() ) {
923 QPixmap globalPanPixmap (imageCrossCursor);
924 QCursor glPanCursor (globalPanPixmap);
925 myCurScale = aView3d->Scale();
926 aView3d->FitAll(0.01, false);
927 myCursor = cursor(); // save old cursor
928 myViewPort->fitAll(); // fits view before selecting a new scene center
929 if( setTransformRequested( PANGLOBAL ) )
930 myViewPort->setCursor( glPanCursor );
935 \brief Start rotation operation
937 Sets the corresponding cursor for the widget.
939 void XGUI_ViewWindow::activateRotation()
941 if (!transformRequested() && !myCursorIsHand)
942 myCursor = cursor(); // save old cursor
944 if (myOperation != ROTATE) {
945 QPixmap rotatePixmap(imageRotateCursor);
946 QCursor rotCursor(rotatePixmap);
947 if (setTransformRequested(ROTATE))
948 myViewPort->setCursor(rotCursor);
953 \brief Reset the viewport to its initial state
954 ( no transformations in process etc. )
956 void XGUI_ViewWindow::resetState()
960 if (myRotationPointSelection) {
961 QCursor handCursor(Qt::PointingHandCursor);
962 myViewPort->setCursor(handCursor);
964 if (transformRequested() || myCursorIsHand)
965 myViewPort->setCursor(myCursor);
966 myCursorIsHand = false;
969 if (transformRequested())
970 emit vpTransformationFinished(myOperation);
972 setTransformInProcess(false);
973 setTransformRequested(NOTHING);
976 XGUI_ViewBackground XGUI_ViewWindow::background() const
978 return myViewPort ? myViewPort->background() : XGUI_ViewBackground();
981 void XGUI_ViewWindow::setBackground(const XGUI_ViewBackground& theBackground)
984 myViewPort->setBackground( theBackground );
988 \brief Create one more window with same content.
990 void XGUI_ViewWindow::cloneView()
992 QMdiSubWindow* vw = myViewer->createView();
993 XGUI_ViewWindow* aNewWnd = static_cast<XGUI_ViewWindow*>(vw->widget());
994 aNewWnd->viewPort()->syncronizeWith(myViewPort);
995 emit viewCloned( vw );
998 void XGUI_ViewWindow::dumpView()
1000 QString aFilter(tr("Images Files (*.bmp *.png *.jpg *.jpeg *.eps *.ps)"));
1001 QString aSelectedFilter;
1002 QString aFileName = QFileDialog::getSaveFileName(this, "Save picture", QString(), aFilter, &aSelectedFilter);
1003 if (!aFileName.isNull()) {
1004 QApplication::setOverrideCursor( Qt::WaitCursor );
1005 QImage aPicture = myViewPort->dumpView();
1007 QString aFmt = extension(aFileName).toUpper();
1008 if( aFmt.isEmpty() )
1009 aFmt = QString( "BMP" ); // default format
1010 else if( aFmt == "JPG" )
1013 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
1015 a3dView->Export(strdup(qPrintable(aFileName)), Graphic3d_EF_PostScript);
1016 else if (aFmt == "EPS")
1017 a3dView->Export(strdup(qPrintable(aFileName)), Graphic3d_EF_EnhPostScript);
1019 aPicture.save( aFileName, aFmt.toLatin1() );
1020 QApplication::restoreOverrideCursor();
1024 void XGUI_ViewWindow::fitAll()
1026 emit vpTransformationStarted( FITALLVIEW );
1027 myViewPort->fitAll();
1028 emit vpTransformationFinished( FITALLVIEW );
1032 \brief Starts fit operation.
1034 Sets the corresponding cursor for the widget.
1036 void XGUI_ViewWindow::activateWindowFit()
1038 if ( !transformRequested() && !myCursorIsHand )
1039 myCursor = cursor(); /* save old cursor */
1041 if ( myOperation != WINDOWFIT ) {
1042 QCursor handCursor (Qt::PointingHandCursor);
1043 if( setTransformRequested ( WINDOWFIT ) ) {
1044 myViewPort->setCursor ( handCursor );
1045 myCursorIsHand = true;
1052 \brief Perform "front view" transformation.
1054 void XGUI_ViewWindow::frontView()
1056 emit vpTransformationStarted ( FRONTVIEW );
1057 Handle(V3d_View) aView3d = myViewPort->getView();
1058 if ( !aView3d.IsNull() )
1059 aView3d->SetProj (V3d_Xpos);
1060 myViewPort->fitAll();
1061 emit vpTransformationFinished ( FRONTVIEW );
1065 \brief Perform "back view" transformation.
1067 void XGUI_ViewWindow::backView()
1069 emit vpTransformationStarted ( BACKVIEW );
1070 Handle(V3d_View) aView3d = myViewPort->getView();
1071 if ( !aView3d.IsNull() )
1072 aView3d->SetProj (V3d_Xneg);
1073 myViewPort->fitAll();
1074 emit vpTransformationFinished ( BACKVIEW );
1078 \brief Perform "top view" transformation.
1080 void XGUI_ViewWindow::topView()
1082 emit vpTransformationStarted ( TOPVIEW );
1083 Handle(V3d_View) aView3d = myViewPort->getView();
1084 if ( !aView3d.IsNull() )
1085 aView3d->SetProj (V3d_Zpos);
1086 myViewPort->fitAll();
1087 emit vpTransformationFinished ( TOPVIEW );
1091 \brief Perform "bottom view" transformation.
1093 void XGUI_ViewWindow::bottomView()
1095 emit vpTransformationStarted ( BOTTOMVIEW );
1096 Handle(V3d_View) aView3d = myViewPort->getView();
1097 if ( !aView3d.IsNull() )
1098 aView3d->SetProj (V3d_Zneg);
1099 myViewPort->fitAll();
1100 emit vpTransformationFinished ( BOTTOMVIEW );
1104 \brief Perform "left view" transformation.
1106 void XGUI_ViewWindow::leftView()
1108 emit vpTransformationStarted ( LEFTVIEW );
1109 Handle(V3d_View) aView3d = myViewPort->getView();
1110 if ( !aView3d.IsNull() )
1111 aView3d->SetProj (V3d_Yneg);
1112 myViewPort->fitAll();
1113 emit vpTransformationFinished ( LEFTVIEW );
1117 \brief Perform "right view" transformation.
1119 void XGUI_ViewWindow::rightView()
1121 emit vpTransformationStarted ( RIGHTVIEW );
1122 Handle(V3d_View) aView3d = myViewPort->getView();
1123 if ( !aView3d.IsNull() )
1124 aView3d->SetProj (V3d_Ypos);
1125 myViewPort->fitAll();
1126 emit vpTransformationFinished ( RIGHTVIEW );
1129 void XGUI_ViewWindow::reset()
1131 emit vpTransformationStarted( RESETVIEW );
1132 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1133 myViewPort->getView()->Reset( false );
1134 myViewPort->fitAll( false, true, false );
1135 myViewPort->getView()->SetImmediateUpdate( upd );
1136 myViewPort->getView()->Update();
1137 emit vpTransformationFinished( RESETVIEW );
1141 void XGUI_ViewWindow::updateToolBar()
1143 myGripWgt->update();
1144 myViewBar->update();
1145 myWindowBar->update();
1146 //QTimer::singleShot(50, Qt::VeryCoarseTimer, this, SLOT(repaintToolBar()));
1149 /*void XGUI_ViewWindow::repaintToolBar()
1151 QApplication::sync();
1152 myGripWgt->repaint();
1153 myViewBar->repaint();
1154 myWindowBar->repaint();