1 #include "XGUI_ViewWindow.h"
2 #include "XGUI_ViewPort.h"
3 #include "XGUI_Viewer.h"
4 #include "XGUI_Tools.h"
5 #include "XGUI_RubberBand.h"
11 #include <QResizeEvent>
12 #include <QApplication>
14 #include <QMdiSubWindow>
17 #include <QFileDialog>
18 #include <QStyleOptionToolBar>
20 #include <TopoDS_Shape.hxx>
21 #include <BRep_Tool.hxx>
23 #include <Visual3d_View.hxx>
27 const char* imageZoomCursor[] = { "32 32 3 1", ". c None", "a c #000000", "# c #ffffff",
28 "................................", "................................",
29 ".#######........................", "..aaaaaaa.......................",
30 "................................", ".............#####..............",
31 "...........##.aaaa##............", "..........#.aa.....a#...........",
32 ".........#.a.........#..........", ".........#a..........#a.........",
33 "........#.a...........#.........", "........#a............#a........",
34 "........#a............#a........", "........#a............#a........",
35 "........#a............#a........", ".........#...........#.a........",
36 ".........#a..........#a.........", ".........##.........#.a.........",
37 "........#####.....##.a..........", ".......###aaa#####.aa...........",
38 "......###aa...aaaaa.......#.....", ".....###aa................#a....",
39 "....###aa.................#a....", "...###aa...............#######..",
40 "....#aa.................aa#aaaa.", ".....a....................#a....",
41 "..........................#a....", "...........................a....",
42 "................................", "................................",
43 "................................", "................................" };
45 const char* imageRotateCursor[] = { "32 32 3 1", ". c None", "a c #000000", "# c #ffffff",
46 "................................", "................................",
47 "................................", "................................",
48 "........#.......................", ".......#.a......................",
49 "......#######...................", ".......#aaaaa#####..............",
50 "........#..##.a#aa##........##..", ".........a#.aa..#..a#.....##.aa.",
51 ".........#.a.....#...#..##.aa...", ".........#a.......#..###.aa.....",
52 "........#.a.......#a..#aa.......", "........#a.........#..#a........",
53 "........#a.........#a.#a........", "........#a.........#a.#a........",
54 "........#a.........#a.#a........", ".........#.........#a#.a........",
55 "........##a........#a#a.........", "......##.a#.......#.#.a.........",
56 "....##.aa..##.....##.a..........", "..##.aa.....a#####.aa...........",
57 "...aa.........aaa#a.............", "................#.a.............",
58 "...............#.a..............", "..............#.a...............",
59 "...............a................", "................................",
60 "................................", "................................",
61 "................................", "................................" };
63 const char* imageCrossCursor[] = { "32 32 3 1", ". c None", "a c #000000", "# c #ffffff",
64 "................................", "................................",
65 "................................", "................................",
66 "................................", "................................",
67 "................................", "...............#................",
68 "...............#a...............", "...............#a...............",
69 "...............#a...............", "...............#a...............",
70 "...............#a...............", "...............#a...............",
71 "...............#a...............", ".......#################........",
72 "........aaaaaaa#aaaaaaaaa.......", "...............#a...............",
73 "...............#a...............", "...............#a...............",
74 "...............#a...............", "...............#a...............",
75 "...............#a...............", "...............#a...............",
76 "................a...............", "................................",
77 "................................", "................................",
78 "................................", "................................",
79 "................................", "................................" };
82 ViewerToolbar::ViewerToolbar(QWidget* theParent, XGUI_ViewPort* thePort)
83 : QToolBar(theParent), myVPort(thePort), myResize(false)
85 connect(myVPort, SIGNAL(resized()), this, SLOT(onViewPortResized()));
88 void ViewerToolbar::paintEvent(QPaintEvent* theEvent)
90 //QToolBar::paintEvent(theEvent);
92 QPainter aPainter(this);
94 QRect aVPRect = myVPort->rect();
95 QPoint aGlobPnt = mapToGlobal(aRect.topLeft());
96 QPoint aPnt = myVPort->mapFromGlobal(aGlobPnt);
98 QRect aImgRect(QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(),
99 aRect.width(), aRect.height()));
100 QImage aImg = myVPort->dumpView(aImgRect, myResize);
102 aPainter.drawImage(aRect, aImg);
106 QStyle *style = this->style();
107 QStyleOptionToolBar aOpt;
108 initStyleOption(&aOpt);
110 aOpt.rect = style->subElementRect(QStyle::SE_ToolBarHandle, &aOpt, this);
111 if (aOpt.rect.isValid())
112 style->drawPrimitive(QStyle::PE_IndicatorToolBarHandle, &aOpt, &aPainter, this);
115 //**************************************************************************
116 ViewerLabel::ViewerLabel(QWidget* theParent, XGUI_ViewPort* thePort)
117 : QLabel(theParent), myVPort(thePort), myResize(false)
119 connect(myVPort, SIGNAL(resized()), this, SLOT(onViewPortResized()));
122 void ViewerLabel::paintEvent(QPaintEvent* theEvent)
124 QRect aRect = rect();
125 QRect aVPRect = myVPort->rect();
126 QPoint aGlobPnt = mapToGlobal(aRect.topLeft());
127 QPoint aPnt = myVPort->mapFromGlobal(aGlobPnt);
129 QRect aImgRect(QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(),
130 aRect.width(), aRect.height()));
131 QImage aImg = myVPort->dumpView(aImgRect, myResize);
133 QPainter(this).drawImage(aRect, aImg);
134 QLabel::paintEvent(theEvent);
137 //**************************************************************************
138 //**************************************************************************
139 //**************************************************************************
140 XGUI_ViewWindow::XGUI_ViewWindow(XGUI_Viewer* theViewer, V3d_TypeOfView theType)
144 MinimizeIco(":pictures/wnd_minimize.png"),
145 MaximizeIco(":pictures/wnd_maximize.png"),
146 CloseIco(":pictures/wnd_close.png"),
147 RestoreIco(":pictures/wnd_restore.png"),
148 myInteractionStyle(XGUI::STANDARD),
151 my2dMode(XGUI::No2dMode),
152 myCurrPointType(XGUI::GRAVITY),
153 myPrevPointType(XGUI::GRAVITY),
154 myRotationPointSelection(false),
156 myStartX(0), myStartY(0), myCurrX(0), myCurrY(0), myCurScale(0.0), myCurSketch(0),
157 myDrawRect(false), myEnableDrawMode(true), myCursorIsHand(false), myEventStarted(false),
159 myLastState(WindowNormalState), myOperation(NOTHING)
161 mySelectedPoint = gp_Pnt(0., 0., 0.);
162 setFrameStyle(QFrame::Raised);
163 setFrameShape(QFrame::Panel);
164 setLineWidth(BORDER_SIZE);
165 setMouseTracking(true);
167 QVBoxLayout* aLay = new QVBoxLayout(this);
168 aLay->setContentsMargins(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE);
169 myViewPort = new XGUI_ViewPort(this, myViewer->v3dViewer(), theType);
170 myViewPort->installEventFilter(this);
171 myViewPort->setCursor(Qt::ArrowCursor);
172 aLay->addWidget(myViewPort);
174 myPicture = new QLabel(this);
175 myPicture->setFrameStyle(QFrame::Sunken);
176 myPicture->setFrameShape(QFrame::Panel);
177 myPicture->setMouseTracking(true);
178 myPicture->installEventFilter(this);
179 aLay->addWidget(myPicture);
182 QVBoxLayout* aVPLay = new QVBoxLayout(myViewPort);
183 aVPLay->setMargin(0);
184 aVPLay->setSpacing(0);
185 aVPLay->setContentsMargins(0,0,0,0);
187 QHBoxLayout* aToolLay = new QHBoxLayout();
188 aToolLay->setMargin(0);
189 aToolLay->setSpacing(0);
190 aToolLay->setContentsMargins(0,0,0,0);
191 aVPLay->addLayout(aToolLay);
192 aVPLay->addStretch();
194 myGripWgt = new ViewerLabel(this, myViewPort);
195 myGripWgt->setPixmap(QPixmap(":pictures/wnd_grip.png"));
196 myGripWgt->setMouseTracking(true);
197 myGripWgt->installEventFilter(this);
198 myGripWgt->setCursor(Qt::OpenHandCursor);
199 aToolLay->addWidget(myGripWgt);
201 // Create Viewer management buttons
202 myViewBar = new ViewerToolbar(this, myViewPort);
203 myViewBar->setCursor(Qt::PointingHandCursor);
204 aToolLay->addWidget(myViewBar);
205 aToolLay->addStretch();
210 aBtn = new QAction(QIcon(":pictures/occ_view_camera_dump.png"), tr("Dump view"), myViewBar);
211 connect(aBtn, SIGNAL(triggered()), SLOT(dumpView()));
212 myViewBar->addAction(aBtn);
214 aBtn = new QAction(QIcon(":pictures/occ_view_fitall.png"), tr("Fit all"), myViewBar);
215 connect(aBtn, SIGNAL(triggered()), SLOT(fitAll()));
216 myViewBar->addAction(aBtn);
218 aBtn = new QAction(QIcon(":pictures/occ_view_fitarea.png"), tr("Fit area"), myViewBar);
219 connect(aBtn, SIGNAL(triggered()), SLOT(activateWindowFit()));
220 myViewBar->addAction(aBtn);
222 aBtn = new QAction(QIcon(":pictures/occ_view_zoom.png"), tr("Zoom"), myViewBar);
223 connect(aBtn, SIGNAL(triggered()), SLOT(activateZoom()));
224 myViewBar->addAction(aBtn);
226 aBtn = new QAction(QIcon(":pictures/occ_view_pan.png"), tr("Panning"), myViewBar);
227 connect(aBtn, SIGNAL(triggered()), SLOT(activatePanning()));
228 myViewBar->addAction(aBtn);
230 aBtn = new QAction(QIcon(":pictures/occ_view_glpan.png"), tr("Global panning"), myViewBar);
231 connect(aBtn, SIGNAL(triggered()), SLOT(activateGlobalPanning()));
232 myViewBar->addAction(aBtn);
234 aBtn = new QAction(QIcon(":pictures/occ_view_rotate.png"), tr("Rotate"), myViewBar);
235 connect(aBtn, SIGNAL(triggered()), SLOT(activateRotation()));
236 myViewBar->addAction(aBtn);
238 aBtn = new QAction(QIcon(":pictures/occ_view_reset.png"), tr("Reset"), myViewBar);
239 connect(aBtn, SIGNAL(triggered()), SLOT(reset()));
240 myViewBar->addAction(aBtn);
242 aBtn = new QAction(QIcon(":pictures/occ_view_front.png"), tr("Front"), myViewBar);
243 connect(aBtn, SIGNAL(triggered()), SLOT(frontView()));
244 myViewBar->addAction(aBtn);
246 aBtn = new QAction(QIcon(":pictures/occ_view_back.png"), tr("Back"), myViewBar);
247 connect(aBtn, SIGNAL(triggered()), SLOT(backView()));
248 myViewBar->addAction(aBtn);
250 aBtn = new QAction(QIcon(":pictures/occ_view_top.png"), tr("Top"), myViewBar);
251 connect(aBtn, SIGNAL(triggered()), SLOT(topView()));
252 myViewBar->addAction(aBtn);
254 aBtn = new QAction(QIcon(":pictures/occ_view_bottom.png"), tr("Bottom"), myViewBar);
255 connect(aBtn, SIGNAL(triggered()), SLOT(bottomView()));
256 myViewBar->addAction(aBtn);
258 aBtn = new QAction(QIcon(":pictures/occ_view_left.png"), tr("Left"), myViewBar);
259 connect(aBtn, SIGNAL(triggered()), SLOT(leftView()));
260 myViewBar->addAction(aBtn);
262 aBtn = new QAction(QIcon(":pictures/occ_view_right.png"), tr("Right"), myViewBar);
263 connect(aBtn, SIGNAL(triggered()), SLOT(rightView()));
264 myViewBar->addAction(aBtn);
266 aBtn = new QAction(QIcon(":pictures/occ_view_clone.png"), tr("Clone"), myViewBar);
267 connect(aBtn, SIGNAL(triggered()), SLOT(cloneView()));
268 myViewBar->addAction(aBtn);
270 // Create Window management buttons
271 myWindowBar = new ViewerToolbar(this, myViewPort);
272 myWindowBar->setCursor(Qt::PointingHandCursor);
273 aToolLay->addWidget(myWindowBar);
275 myMinimizeBtn = new QAction(myWindowBar);
276 myMinimizeBtn->setIcon(MinimizeIco);
277 myWindowBar->addAction(myMinimizeBtn);
278 connect(myMinimizeBtn, SIGNAL(triggered()), SLOT(onMinimize()));
280 myMaximizeBtn = new QAction(myWindowBar);
281 myMaximizeBtn->setIcon(MaximizeIco);
282 myWindowBar->addAction(myMaximizeBtn);
283 connect(myMaximizeBtn, SIGNAL(triggered()), SLOT(onMaximize()));
285 aBtn = new QAction(myWindowBar);
286 aBtn->setIcon(CloseIco);
287 myWindowBar->addAction(aBtn);
288 connect(aBtn, SIGNAL(triggered()), SLOT(onClose()));
290 //Support copy of background on updating of viewer
291 connect(myViewPort, SIGNAL(vpTransformed()), this, SLOT(updateToolBar()));
292 connect(myViewPort, SIGNAL(vpUpdated()), this, SLOT(updateToolBar()));
293 connect(this, SIGNAL(vpTransformationFinished(XGUI_ViewWindow::OperationType)),
294 this, SLOT(updateToolBar()));
298 //****************************************************************
299 XGUI_ViewWindow::~XGUI_ViewWindow()
304 //****************************************************************
305 void XGUI_ViewWindow::showEvent(QShowEvent* theEvent)
307 QFrame::showEvent(theEvent);
308 myWindowBar->setFixedSize(myWindowBar->sizeHint());
311 //****************************************************************
312 void XGUI_ViewWindow::changeEvent(QEvent* theEvent)
315 if (theEvent->type() == QEvent::WindowStateChange) {
317 if (myPicture->isHidden()) {
325 if (myPicture->isVisible()) {
330 myMinimizeBtn->setIcon(MinimizeIco);
331 myMaximizeBtn->setIcon(RestoreIco);
333 myViewBar->setVisible(myIsActive);
334 myWindowBar->setVisible(myIsActive);
335 myGripWgt->setVisible(myIsActive && (!isMaximized()));
338 QWidget::changeEvent(theEvent);
343 //****************************************************************
344 void XGUI_ViewWindow::windowActivated()
346 if (!(isMinimized() || parentWidget()->isMinimized())) {
348 if (isMaximized() || parentWidget()->isMaximized()) {
349 myMaximizeBtn->setIcon(RestoreIco);
351 myMaximizeBtn->setIcon(MaximizeIco);
355 myGripWgt->setVisible(!(isMaximized() || isMinimized() ||
356 parentWidget()->isMaximized() || parentWidget()->isMinimized()));
361 //****************************************************************
362 void XGUI_ViewWindow::windowDeactivated()
365 if (!(isMinimized() || parentWidget()->isMinimized())) {
366 if (isMaximized() || parentWidget()->isMaximized()) {
367 myMaximizeBtn->setIcon(RestoreIco);
369 myMaximizeBtn->setIcon(MaximizeIco);
378 //****************************************************************
379 void XGUI_ViewWindow::onClose()
381 if (parentWidget()) {
382 emit tryClosing(this);
384 emit closed(static_cast<QMdiSubWindow*>(parentWidget()));
385 parentWidget()->close();
390 //****************************************************************
391 void XGUI_ViewWindow::onMinimize()
393 QPixmap aPMap = QPixmap::fromImage(myViewPort->dumpView());
396 double aR = aW / 100.;
397 int aNewH = int(aH / aR);
398 myPicture->setPixmap(aPMap.scaled(100, aNewH));
400 myLastState = (isMaximized() || parentWidget()->isMaximized()) ? MaximizedState : WindowNormalState;
402 parentWidget()->showMinimized();
403 parentWidget()->setGeometry(parentWidget()->x(), parentWidget()->y(), 100, aNewH);
404 parentWidget()->lower();
406 myViewer->onWindowMinimized((QMdiSubWindow*)parentWidget());
409 //****************************************************************
410 void XGUI_ViewWindow::onMaximize()
412 if (isMaximized() || parentWidget()->isMaximized()) {
413 myMaximizeBtn->setIcon(MaximizeIco);
416 parentWidget()->showNormal();
418 myMaximizeBtn->setIcon(RestoreIco);
421 parentWidget()->showMaximized();
423 parentWidget()->activateWindow();
424 myMinimizeBtn->setIcon(MinimizeIco);
426 // In order to avoid frosen background in toolbars when it shown as a second view
427 QTimer::singleShot(50, parentWidget(), SLOT(setFocus()));
430 //****************************************************************
431 bool XGUI_ViewWindow::processWindowControls(QObject *theObj, QEvent *theEvent)
433 switch(theEvent->type()) {
434 case QEvent::MouseButtonPress: {
435 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
436 if ((aEvent->button() == Qt::LeftButton) && (!myMoving)) {
438 myMousePnt = aEvent->globalPos();
443 case QEvent::MouseButtonRelease: {
444 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
445 if ((aEvent->button() == Qt::LeftButton) && myMoving) {
451 case QEvent::MouseMove: {
452 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
454 QMdiSubWindow* aParent = static_cast<QMdiSubWindow*>(parentWidget());
455 QMdiArea* aMDIArea = aParent->mdiArea();
457 QPoint aPnt = aEvent->globalPos();
458 QPoint aMDIPnt = aMDIArea->mapFromGlobal(aPnt);
459 if (aMDIArea->rect().contains(aMDIPnt)) {
460 int aX = aParent->x() + (aPnt.x() - myMousePnt.x());
461 int aY = aParent->y() + (aPnt.y() - myMousePnt.y());
462 aParent->move(aX, aY);
469 case QEvent::MouseButtonDblClick:
470 if (theObj == myPicture) {
472 if (myLastState == MaximizedState) {
477 myViewer->onWindowActivated((QMdiSubWindow*)parentWidget());
479 // In order to avoid frosen background in toolbars when it shown as a second view
480 QTimer::singleShot(20, parentWidget(), SLOT(setFocus()));
488 //****************************************************************
489 bool XGUI_ViewWindow::processViewPort(QEvent *theEvent)
491 switch(theEvent->type()) {
492 case QEvent::MouseButtonPress:
493 vpMousePressEvent((QMouseEvent*) theEvent);
496 case QEvent::MouseButtonRelease:
497 vpMouseReleaseEvent((QMouseEvent*) theEvent);
500 case QEvent::MouseMove:
501 vpMouseMoveEvent((QMouseEvent*) theEvent);
504 case QEvent::MouseButtonDblClick:
505 emit mouseDoubleClicked(this, (QMouseEvent*) theEvent);
509 QWheelEvent* aEvent = (QWheelEvent*) theEvent;
510 myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
511 double aDelta = (double)( aEvent->delta() ) / ( 15 * 8 );
514 int x1 = (int)( aEvent->x() + width()*aDelta/100 );
515 int y1 = (int)( aEvent->y() + height()*aDelta/100 );
516 myViewPort->zoom( x, y, x1, y1 );
523 //****************************************************************
524 bool XGUI_ViewWindow::eventFilter(QObject *theObj, QEvent *theEvent)
526 if ((theObj == myGripWgt) || (theObj == myPicture)) {
527 if (processWindowControls(theObj, theEvent))
529 } else if (theObj == myViewPort) {
530 if (processViewPort(theEvent)) {
534 return QFrame::eventFilter(theObj, theEvent);
537 //****************************************************************
538 XGUI_ViewWindow::OperationType XGUI_ViewWindow::getButtonState(
539 QMouseEvent* theEvent, XGUI::InteractionStyle theInteractionStyle)
541 OperationType aOp = NOTHING;
542 XGUI::InteractionStyle aStyle = (XGUI::InteractionStyle) theInteractionStyle;
543 if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::ZOOM])
544 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::ZOOM]))
546 else if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::PAN])
547 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::PAN]))
549 else if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::ROTATE])
550 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::ROTATE])
551 && (my2dMode == XGUI::No2dMode))
557 //****************************************************************
558 void XGUI_ViewWindow::vpMousePressEvent(QMouseEvent* theEvent)
560 myStartX = theEvent->x();
561 myStartY = theEvent->y();
562 XGUI::InteractionStyle anInteractionStyle = interactionStyle();
564 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
565 // which are assigned for pan and rotate - these operations are activated immediately after pressing
566 // of the first button, so it is necessary to switch to zoom when the second button is pressed
567 bool aSwitchToZoom = false;
568 if ((anInteractionStyle == XGUI::KEY_FREE) && (myOperation == PANVIEW || myOperation == ROTATE)) {
569 aSwitchToZoom = getButtonState(theEvent, anInteractionStyle) == ZOOMVIEW;
572 switch(myOperation) {
574 if (theEvent->button() == Qt::LeftButton)
575 emit vpTransformationStarted(WINDOWFIT);
579 if (theEvent->button() == Qt::LeftButton)
580 emit vpTransformationStarted(PANGLOBAL);
584 if (theEvent->button() == Qt::LeftButton) {
585 myViewPort->startZoomAtPoint(myStartX, myStartY);
586 emit vpTransformationStarted(ZOOMVIEW);
592 myViewPort->startZoomAtPoint(myStartX, myStartY);
594 } else if (theEvent->button() == Qt::LeftButton)
595 emit vpTransformationStarted(PANVIEW);
600 myViewPort->startZoomAtPoint(myStartX, myStartY);
602 } else if (theEvent->button() == Qt::LeftButton) {
603 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
604 emit vpTransformationStarted(ROTATE);
609 /* Try to activate a transformation */
610 OperationType aState;
611 if (interactionStyle() == XGUI::STANDARD)
612 aState = getButtonState(theEvent, anInteractionStyle);
614 aState = XGUI_ViewWindow::NOTHING;
619 myViewPort->startZoomAtPoint(myStartX, myStartY);
627 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
630 if (myRotationPointSelection) {
631 if (theEvent->button() == Qt::LeftButton) {
632 Handle(AIS_InteractiveContext) ic = myViewer->AISContext();
634 for(ic->InitSelected(); ic->MoreSelected(); ic->NextSelected()) {
635 TopoDS_Shape aShape = ic->SelectedShape();
636 if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX) {
637 gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(ic->SelectedShape()));
638 /*if ( mySetRotationPointDlg ) {
639 myRotationPointSelection = false;
640 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
643 myCurrPointType = myPrevPointType;
647 if (ic->NbSelected() == 0)
648 myCurrPointType = myPrevPointType;
649 //if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
650 ic->CloseAllContexts();
651 myOperation = NOTHING;
652 myViewPort->setCursor(myCursor);
653 myCursorIsHand = false;
654 myRotationPointSelection = false;
657 emit mousePressed(this, theEvent);
660 /* notify that we start a transformation */
661 if (transformRequested())
662 emit vpTransformationStarted(myOperation);
664 if (transformRequested())
665 setTransformInProcess(true);
667 /* we may need it for sketching... */
668 /* if ( l_mbPressEvent )
669 delete l_mbPressEvent;
670 l_mbPressEvent = new QMouseEvent( *theEvent );*/
673 //****************************************************************
674 void XGUI_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
676 switch(myOperation) {
678 int prevState = myCurSketch;
679 /* if(theEvent->button() == Qt::RightButton) {
680 QList<OCCViewer_ViewSketcher*>::Iterator it;
681 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it ) {
682 OCCViewer_ViewSketcher* sk = (*it);
683 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
688 emit mouseReleased(this, theEvent);
689 if (theEvent->button() == Qt::RightButton && prevState == -1) {
690 QContextMenuEvent aEvent(QContextMenuEvent::Mouse, theEvent->pos(), theEvent->globalPos());
691 emit contextMenuRequested(&aEvent);
696 myViewPort->endRotation();
706 if (theEvent->button() == Qt::LeftButton) {
707 myViewPort->setCenter(theEvent->x(), theEvent->y());
708 myViewPort->getView()->SetScale(myCurScale);
714 if (theEvent->button() == Qt::LeftButton) {
715 myCurrX = theEvent->x();
716 myCurrY = theEvent->y();
718 QRect rect = makeRect(myStartX, myStartY, myCurrX, myCurrY);
720 myViewPort->fitRect(rect);
727 // NOTE: viewer 3D detects a rectangle of selection using this event
728 // so we must emit it BEFORE resetting the selection rectangle
729 if (theEvent->button() == Qt::LeftButton && myDrawRect) {
733 myViewPort->update();
735 /* if ( l_mbPressEvent ) {
736 delete l_mbPressEvent;
741 //****************************************************************
742 void XGUI_ViewWindow::vpMouseMoveEvent(QMouseEvent* theEvent)
744 if (myIsKeyFree && interactionStyle() == XGUI::KEY_FREE) {
746 switch(getButtonState(theEvent, interactionStyle())) {
748 myViewPort->startZoomAtPoint(myStartX, myStartY);
756 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
763 myCurrX = theEvent->x();
764 myCurrY = theEvent->y();
765 switch(myOperation) {
767 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
771 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
777 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
786 if (myRotationPointSelection /*|| isSketcherStyle()*/) {
787 emit mouseMoving(this, theEvent);
789 int aState = theEvent->modifiers();
790 int aButton = theEvent->buttons();
791 int anInteractionStyle = interactionStyle();
792 if (((anInteractionStyle == XGUI::STANDARD) && (aButton == Qt::LeftButton)
793 && (aState == Qt::NoModifier || Qt::ShiftModifier))
794 || ((anInteractionStyle == XGUI::KEY_FREE) && (aButton == Qt::LeftButton)
795 && (aState == Qt::ControlModifier
796 || aState == (Qt::ControlModifier | Qt::ShiftModifier)))) {
797 myDrawRect = myEnableDrawMode;
800 if (!myCursorIsHand) { // we are going to sketch a rectangle
801 QCursor handCursor(Qt::PointingHandCursor);
802 myCursorIsHand = true;
804 myViewPort->setCursor(handCursor);
807 emit mouseMoving(this, theEvent);
808 } /* else if ( ( (anInteractionStyle == XGUI::STANDARD) &&
809 (aButton == Qt::RightButton) &&
810 ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
811 ( (anInteractionStyle == XGUI::KEY_FREE) &&
812 (aButton == Qt::RightButton) &&
813 ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
814 OCCViewer_ViewSketcher* sketcher = 0;
815 QList<OCCViewer_ViewSketcher*>::Iterator it;
816 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it ) {
817 OCCViewer_ViewSketcher* sk = (*it);
818 if( sk->isDefault() && sk->sketchButton() == aButton )
821 if ( sketcher && myCurSketch == -1 ) {
822 activateSketching( sketcher->type() );
824 myCurSketch = mypSketcher->sketchButton();
826 if ( l_mbPressEvent ) {
827 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
828 delete l_mbPressEvent;
831 QApplication::sendEvent( getViewPort(), theEvent );
835 emit mouseMoving(this, theEvent);
841 \brief Draw rubber band rectangle.
843 void XGUI_ViewWindow::drawRect()
846 myRectBand = new XGUI_RectRubberBand(myViewPort);
849 myRectBand->setUpdatesEnabled(false);
850 QRect aRect = makeRect(myStartX, myStartY, myCurrX, myCurrY);
851 myRectBand->initGeometry(aRect);
853 if (!myRectBand->isVisible())
856 myRectBand->setUpdatesEnabled(true);
860 \brief Clear rubber band rectangle on the end on the dragging operation.
862 void XGUI_ViewWindow::endDrawRect()
865 myRectBand->clearGeometry();
870 void XGUI_ViewWindow::activateZoom()
872 if (!transformRequested() && !myCursorIsHand)
873 myCursor = cursor(); /* save old cursor */
875 if (myOperation != ZOOMVIEW) {
876 QPixmap zoomPixmap(imageZoomCursor);
877 QCursor zoomCursor(zoomPixmap);
878 if (setTransformRequested(ZOOMVIEW))
879 myViewPort->setCursor(zoomCursor);
883 bool XGUI_ViewWindow::transformRequested() const
885 return (myOperation != NOTHING);
889 \brief Start delayed viewer operation.
891 bool XGUI_ViewWindow::setTransformRequested(OperationType op)
893 bool ok = transformEnabled(op);
894 myOperation = ok ? op : NOTHING;
895 myViewPort->setMouseTracking(myOperation == NOTHING);
900 Set enabled state of transformation (rotate, zoom, etc)
902 void XGUI_ViewWindow::setTransformEnabled(const OperationType id, const bool on)
905 myStatus.insert(id, on);
909 \return enabled state of transformation (rotate, zoom, etc)
911 bool XGUI_ViewWindow::transformEnabled(const OperationType id) const
913 return myStatus.contains(id) ? myStatus[id] : true;
917 \brief Start panning operation.
919 Sets the corresponding cursor for the widget.
921 void XGUI_ViewWindow::activatePanning()
923 if (!transformRequested() && !myCursorIsHand)
924 myCursor = cursor(); // save old cursor
926 if (myOperation != PANVIEW) {
927 QCursor panCursor(Qt::SizeAllCursor);
928 if (setTransformRequested(PANVIEW))
929 myViewPort->setCursor(panCursor);
934 \brief Start global panning operation
936 Sets the corresponding cursor for the widget.
938 void XGUI_ViewWindow::activateGlobalPanning()
940 Handle(V3d_View) aView3d = myViewPort->getView();
941 if ( !aView3d.IsNull() ) {
942 QPixmap globalPanPixmap (imageCrossCursor);
943 QCursor glPanCursor (globalPanPixmap);
944 myCurScale = aView3d->Scale();
945 aView3d->FitAll(0.01, false);
946 myCursor = cursor(); // save old cursor
947 myViewPort->fitAll(); // fits view before selecting a new scene center
948 if( setTransformRequested( PANGLOBAL ) )
949 myViewPort->setCursor( glPanCursor );
954 \brief Start rotation operation
956 Sets the corresponding cursor for the widget.
958 void XGUI_ViewWindow::activateRotation()
960 if (!transformRequested() && !myCursorIsHand)
961 myCursor = cursor(); // save old cursor
963 if (myOperation != ROTATE) {
964 QPixmap rotatePixmap(imageRotateCursor);
965 QCursor rotCursor(rotatePixmap);
966 if (setTransformRequested(ROTATE))
967 myViewPort->setCursor(rotCursor);
972 \brief Reset the viewport to its initial state
973 ( no transformations in process etc. )
975 void XGUI_ViewWindow::resetState()
979 if (myRotationPointSelection) {
980 QCursor handCursor(Qt::PointingHandCursor);
981 myViewPort->setCursor(handCursor);
983 if (transformRequested() || myCursorIsHand)
984 myViewPort->setCursor(myCursor);
985 myCursorIsHand = false;
988 if (transformRequested())
989 emit vpTransformationFinished(myOperation);
991 setTransformInProcess(false);
992 setTransformRequested(NOTHING);
995 XGUI_ViewBackground XGUI_ViewWindow::background() const
997 return myViewPort ? myViewPort->background() : XGUI_ViewBackground();
1000 void XGUI_ViewWindow::setBackground(const XGUI_ViewBackground& theBackground)
1003 myViewPort->setBackground( theBackground );
1007 \brief Create one more window with same content.
1009 void XGUI_ViewWindow::cloneView()
1011 QMdiSubWindow* vw = myViewer->createView();
1012 XGUI_ViewWindow* aNewWnd = static_cast<XGUI_ViewWindow*>(vw->widget());
1013 aNewWnd->viewPort()->syncronizeWith(myViewPort);
1015 emit viewCloned( vw );
1017 // In order to avoid frosen background in toolbars when it shown as a second view
1018 QTimer::singleShot(20, vw, SLOT(setFocus()));
1021 void XGUI_ViewWindow::dumpView()
1023 QString aFilter(tr("Images Files (*.bmp *.png *.jpg *.jpeg *.eps *.ps)"));
1024 QString aSelectedFilter;
1025 QString aFileName = QFileDialog::getSaveFileName(this, "Save picture", QString(), aFilter, &aSelectedFilter);
1026 if (!aFileName.isNull()) {
1027 QApplication::setOverrideCursor( Qt::WaitCursor );
1028 QImage aPicture = myViewPort->dumpView();
1030 QString aFmt = extension(aFileName).toUpper();
1031 if( aFmt.isEmpty() )
1032 aFmt = QString( "BMP" ); // default format
1033 else if( aFmt == "JPG" )
1036 Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
1038 a3dView->Export(strdup(qPrintable(aFileName)), Graphic3d_EF_PostScript);
1039 else if (aFmt == "EPS")
1040 a3dView->Export(strdup(qPrintable(aFileName)), Graphic3d_EF_EnhPostScript);
1042 aPicture.save( aFileName, aFmt.toLatin1() );
1043 QApplication::restoreOverrideCursor();
1047 void XGUI_ViewWindow::fitAll()
1049 emit vpTransformationStarted( FITALLVIEW );
1050 myViewPort->fitAll();
1051 emit vpTransformationFinished( FITALLVIEW );
1055 \brief Starts fit operation.
1057 Sets the corresponding cursor for the widget.
1059 void XGUI_ViewWindow::activateWindowFit()
1061 if ( !transformRequested() && !myCursorIsHand )
1062 myCursor = cursor(); /* save old cursor */
1064 if ( myOperation != WINDOWFIT ) {
1065 QCursor handCursor (Qt::PointingHandCursor);
1066 if( setTransformRequested ( WINDOWFIT ) ) {
1067 myViewPort->setCursor ( handCursor );
1068 myCursorIsHand = true;
1075 \brief Perform "front view" transformation.
1077 void XGUI_ViewWindow::frontView()
1079 emit vpTransformationStarted ( FRONTVIEW );
1080 Handle(V3d_View) aView3d = myViewPort->getView();
1081 if ( !aView3d.IsNull() )
1082 aView3d->SetProj (V3d_Xpos);
1083 myViewPort->fitAll();
1084 emit vpTransformationFinished ( FRONTVIEW );
1088 \brief Perform "back view" transformation.
1090 void XGUI_ViewWindow::backView()
1092 emit vpTransformationStarted ( BACKVIEW );
1093 Handle(V3d_View) aView3d = myViewPort->getView();
1094 if ( !aView3d.IsNull() )
1095 aView3d->SetProj (V3d_Xneg);
1096 myViewPort->fitAll();
1097 emit vpTransformationFinished ( BACKVIEW );
1101 \brief Perform "top view" transformation.
1103 void XGUI_ViewWindow::topView()
1105 emit vpTransformationStarted ( TOPVIEW );
1106 Handle(V3d_View) aView3d = myViewPort->getView();
1107 if ( !aView3d.IsNull() )
1108 aView3d->SetProj (V3d_Zpos);
1109 myViewPort->fitAll();
1110 emit vpTransformationFinished ( TOPVIEW );
1114 \brief Perform "bottom view" transformation.
1116 void XGUI_ViewWindow::bottomView()
1118 emit vpTransformationStarted ( BOTTOMVIEW );
1119 Handle(V3d_View) aView3d = myViewPort->getView();
1120 if ( !aView3d.IsNull() )
1121 aView3d->SetProj (V3d_Zneg);
1122 myViewPort->fitAll();
1123 emit vpTransformationFinished ( BOTTOMVIEW );
1127 \brief Perform "left view" transformation.
1129 void XGUI_ViewWindow::leftView()
1131 emit vpTransformationStarted ( LEFTVIEW );
1132 Handle(V3d_View) aView3d = myViewPort->getView();
1133 if ( !aView3d.IsNull() )
1134 aView3d->SetProj (V3d_Yneg);
1135 myViewPort->fitAll();
1136 emit vpTransformationFinished ( LEFTVIEW );
1140 \brief Perform "right view" transformation.
1142 void XGUI_ViewWindow::rightView()
1144 emit vpTransformationStarted ( RIGHTVIEW );
1145 Handle(V3d_View) aView3d = myViewPort->getView();
1146 if ( !aView3d.IsNull() )
1147 aView3d->SetProj (V3d_Ypos);
1148 myViewPort->fitAll();
1149 emit vpTransformationFinished ( RIGHTVIEW );
1152 void XGUI_ViewWindow::reset()
1154 emit vpTransformationStarted( RESETVIEW );
1155 bool upd = myViewPort->getView()->SetImmediateUpdate( false );
1156 myViewPort->getView()->Reset( false );
1157 myViewPort->fitAll( false, true, false );
1158 myViewPort->getView()->SetImmediateUpdate( upd );
1159 myViewPort->getView()->Update();
1160 emit vpTransformationFinished( RESETVIEW );
1164 void XGUI_ViewWindow::updateToolBar()
1166 myGripWgt->update();
1167 myViewBar->update();
1168 myWindowBar->update();