1 // File: OCCViewer_ViewWidget.h
2 // Created: 26 Jul 2012
3 // Author: Natalia ERMOLAEVA
6 //#include <MCGUIBase_Defs.h>
7 #include "OCCViewer_ViewWidget.h"
9 #include <Basics_OCCTVersion.hxx>
11 #include <SUIT_Desktop.h>
12 #include <SUIT_Session.h>
13 #include <SUIT_ResourceMgr.h>
14 #include <SUIT_MessageBox.h>
15 #include <OCCViewer_ViewPort3d.h>
16 #include <OCCViewer_VService.h>
17 #include <SUIT_ViewModel.h>
18 #include <SUIT_Tools.h>
20 #include <QtxAction.h>
22 #include <AIS_InteractiveObject.hxx>
23 #include <AIS_ListOfInteractive.hxx>
24 #include <V3d_Viewer.hxx>
25 #include <AIS_Shape.hxx>
26 #include <Prs3d_LineAspect.hxx>
28 #include <AIS_InteractiveContext.hxx>
29 #include <AIS_ListIteratorOfListOfInteractive.hxx>
30 #include <Geom_Axis2Placement.hxx>
31 #include <AIS_Drawer.hxx>
32 #include <Prs3d_DatumAspect.hxx>
36 #include <QHBoxLayout>
37 #include <QPushButton>
40 #include <QWheelEvent>
41 #include <QMouseEvent>
44 const int SPACING_SIZE = 5;
45 const int Z_FIT_ALL_SIZE = 1000;
47 const char* imageZoomCursor[] = {
52 "................................",
53 "................................",
54 ".#######........................",
55 "..aaaaaaa.......................",
56 "................................",
57 ".............#####..............",
58 "...........##.aaaa##............",
59 "..........#.aa.....a#...........",
60 ".........#.a.........#..........",
61 ".........#a..........#a.........",
62 "........#.a...........#.........",
63 "........#a............#a........",
64 "........#a............#a........",
65 "........#a............#a........",
66 "........#a............#a........",
67 ".........#...........#.a........",
68 ".........#a..........#a.........",
69 ".........##.........#.a.........",
70 "........#####.....##.a..........",
71 ".......###aaa#####.aa...........",
72 "......###aa...aaaaa.......#.....",
73 ".....###aa................#a....",
74 "....###aa.................#a....",
75 "...###aa...............#######..",
76 "....#aa.................aa#aaaa.",
77 ".....a....................#a....",
78 "..........................#a....",
79 "...........................a....",
80 "................................",
81 "................................",
82 "................................",
83 "................................"};
85 const char* imageRotateCursor[] = {
90 "................................",
91 "................................",
92 "................................",
93 "................................",
94 "........#.......................",
95 ".......#.a......................",
96 "......#######...................",
97 ".......#aaaaa#####..............",
98 "........#..##.a#aa##........##..",
99 ".........a#.aa..#..a#.....##.aa.",
100 ".........#.a.....#...#..##.aa...",
101 ".........#a.......#..###.aa.....",
102 "........#.a.......#a..#aa.......",
103 "........#a.........#..#a........",
104 "........#a.........#a.#a........",
105 "........#a.........#a.#a........",
106 "........#a.........#a.#a........",
107 ".........#.........#a#.a........",
108 "........##a........#a#a.........",
109 "......##.a#.......#.#.a.........",
110 "....##.aa..##.....##.a..........",
111 "..##.aa.....a#####.aa...........",
112 "...aa.........aaa#a.............",
113 "................#.a.............",
114 "...............#.a..............",
115 "..............#.a...............",
116 "...............a................",
117 "................................",
118 "................................",
119 "................................",
120 "................................",
121 "................................"};
123 const char* imageCrossCursor[] = {
128 "................................",
129 "................................",
130 "................................",
131 "................................",
132 "................................",
133 "................................",
134 "................................",
135 "...............#................",
136 "...............#a...............",
137 "...............#a...............",
138 "...............#a...............",
139 "...............#a...............",
140 "...............#a...............",
141 "...............#a...............",
142 "...............#a...............",
143 ".......#################........",
144 "........aaaaaaa#aaaaaaaaa.......",
145 "...............#a...............",
146 "...............#a...............",
147 "...............#a...............",
148 "...............#a...............",
149 "...............#a...............",
150 "...............#a...............",
151 "...............#a...............",
152 "................a...............",
153 "................................",
154 "................................",
155 "................................",
156 "................................",
157 "................................",
158 "................................",
159 "................................"};
161 // ---------------- OCC view widget --------
162 OCCViewer_ViewWidget::OCCViewer_ViewWidget(QWidget* parent)
163 : QFrame(parent), myShowTrihedron(true)
165 setObjectName("OCC_view_widget");
166 mySelectedPoint = gp_Pnt(0.,0.,0.);
167 setFrameStyle(QFrame::NoFrame);
169 QGridLayout* anAnalLay = new QGridLayout(this);
170 anAnalLay->setMargin(0);
171 anAnalLay->setSpacing(SPACING_SIZE);
173 QWidget* aBtnBox = new QWidget(this);
174 QHBoxLayout* aBtnLay = new QHBoxLayout(aBtnBox);
175 aBtnLay->setMargin(0);
176 aBtnLay->setSpacing(SPACING_SIZE);
178 myToolBar = new QToolBar(aBtnBox);
179 aBtnLay->addWidget(myToolBar);
180 myZoomBtns = new QtxMultiAction(aBtnBox);
181 myZoomBtns->setObjectName("zoomBtn");
182 myToolBar->addAction(myZoomBtns);
183 myPanBtns = new QtxMultiAction(aBtnBox);
184 myPanBtns->setObjectName("panBtn");
185 myToolBar->addAction(myPanBtns);
186 myProjBtns = new QtxMultiAction(aBtnBox);
187 myProjBtns->setObjectName("projectionBtn");
188 myToolBar->addAction(myProjBtns);
191 aBtnLay->addStretch(1);
192 anAnalLay->addWidget(aBtnBox, 0, 0, 1, 2);
194 myV3dViewer = OCCViewer_VService::CreateViewer((short*) "Viewer3d", "", "", 1000., V3d_XposYnegZpos, true, true);
197 #if OCC_VERSION_LARGE <= 0x06060000 // Porting to OCCT higher 6.6.0 version
198 myV3dCollector = OCCViewer_VService::CreateViewer((short*) "Collector3d", "", "", 1000., V3d_XposYnegZpos, true, true);
199 myV3dCollector->Init();
203 #if OCC_VERSION_LARGE <= 0x06060000
204 myAISContext = new AIS_InteractiveContext( myV3dViewer, myV3dCollector );
206 myAISContext = new AIS_InteractiveContext( myV3dViewer );
208 myAISContext->SelectionColor(Quantity_NOC_WHITE);
209 myAISContext->IsoOnPlane(true);
211 myViewPort = new OCCViewer_ViewPort3d(this, myV3dViewer, V3d_ORTHOGRAPHIC);
212 myViewPort->setBackgroundColor(Qt::black);
213 myViewPort->setMinimumHeight(300);
214 myViewPort->installEventFilter(this);
215 anAnalLay->addWidget(myViewPort, 1, 0, 1, 2);
217 Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(gp::XOY());
218 myTrihedron = new AIS_Trihedron(anAxis);
219 myTrihedron->SetInfiniteState(Standard_True);
221 Quantity_Color Col(193/255., 205/255., 193/255., Quantity_TOC_RGB);
222 myTrihedron->SetArrowColor(Col.Name());
223 myTrihedron->SetSize(100);
224 Handle(AIS_Drawer) drawer = myTrihedron->Attributes();
225 if (drawer->HasDatumAspect()) {
226 Handle(Prs3d_DatumAspect) daspect = drawer->DatumAspect();
227 daspect->FirstAxisAspect()->SetColor(Quantity_Color(1.0, 0.0, 0.0, Quantity_TOC_RGB));
228 daspect->SecondAxisAspect()->SetColor(Quantity_Color(0.0, 1.0, 0.0, Quantity_TOC_RGB));
229 daspect->ThirdAxisAspect()->SetColor(Quantity_Color(0.0, 0.0, 1.0, Quantity_TOC_RGB));
231 myAISContext->Display(myTrihedron);
232 myAISContext->Deactivate(myTrihedron);
234 myTrihedron->SetTransformPersistence(Graphic3d_TMF_TriedronPers, gp_Pnt(-1, -1, 200));
235 myTrihedron->SetSize(100);
238 myButsMap[TrihId]->setChecked(false);
242 OCCViewer_ViewWidget::~OCCViewer_ViewWidget()
244 #if OCC_VERSION_LARGE <= 0x06060000
245 myV3dCollector.Nullify();
249 void OCCViewer_ViewWidget::reset()
252 myOperation = NOTHING;
253 myCurrPointType = OCCViewer_ViewWindow::GRAVITY;
256 void OCCViewer_ViewWidget::Display(const TopoDS_Shape shape, const bool theShaded,
257 const QColor& shapeColor)
260 if (shape.IsNull()) {
261 myAISContext->UpdateCurrentViewer();
265 Handle(AIS_InteractiveObject) io = new AIS_Shape(shape);
266 io->UnsetSelectionMode();
267 io->UnsetHilightMode();
269 Quantity_Color aColor(shapeColor.red()/255., shapeColor.green()/255.,
270 shapeColor.blue()/255., Quantity_TOC_RGB);
271 io->SetColor(aColor);
273 myAISContext->Display(io, false);
275 myAISContext->SetDisplayMode(io, AIS_Shaded, false);
276 myAISContext->SetMaterial(io, Graphic3d_NOM_PLASTIC, false);
279 myAISContext->SetDisplayMode(io, AIS_WireFrame, false);
281 myAISContext->UpdateCurrentViewer();
284 void OCCViewer_ViewWidget::createActions()
286 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
290 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_FITALL")),
291 tr("MNU_FITALL"), 0, this);
292 aAction->setStatusTip(tr("DSC_FITALL"));
293 connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
294 myButsMap[ FitAllId ] = aAction;
297 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_FITAREA")),
298 tr("MNU_FITRECT"), 0, this);
299 aAction->setStatusTip(tr("DSC_FITRECT"));
300 connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
301 myButsMap[ FitRectId ] = aAction;
304 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_ZOOM")),
305 tr("MNU_ZOOM_VIEW"), 0, this);
306 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
307 connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
308 myButsMap[ ZoomId ] = aAction;
311 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_PAN")),
312 tr("MNU_PAN_VIEW"), 0, this);
313 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
314 connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
315 myButsMap[ PanId ] = aAction;
318 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_GLOBALPAN")),
319 tr("MNU_GLOBALPAN_VIEW"), 0, this);
320 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
321 connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
322 myButsMap[ GlobalPanId ] = aAction;
325 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_FRONT")),
326 tr("MNU_FRONT_VIEW"), 0, this);
327 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
328 connect(aAction, SIGNAL(activated()), this, SLOT(onFrontView()));
329 myButsMap[ FrontId ] = aAction;
331 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_BACK")),
332 tr("MNU_BACK_VIEW"), 0, this);
333 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
334 connect(aAction, SIGNAL(activated()), this, SLOT(onBackView()));
335 myButsMap[ BackId ] = aAction;
337 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_TOP")),
338 tr("MNU_TOP_VIEW"), 0, this);
339 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
340 connect(aAction, SIGNAL(activated()), this, SLOT(onTopView()));
341 myButsMap[ TopId ] = aAction;
343 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_BOTTOM")),
344 tr("MNU_BOTTOM_VIEW"), 0, this);
345 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
346 connect(aAction, SIGNAL(activated()), this, SLOT(onBottomView()));
347 myButsMap[ BottomId ] = aAction;
349 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_LEFT")),
350 tr("MNU_LEFT_VIEW"), 0, this);
351 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
352 connect(aAction, SIGNAL(activated()), this, SLOT(onLeftView()));
353 myButsMap[ LeftId ] = aAction;
355 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_RIGHT")),
356 tr("MNU_RIGHT_VIEW"), 0, this);
357 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
358 connect(aAction, SIGNAL(activated()), this, SLOT(onRightView()));
359 myButsMap[ RightId ] = aAction;
361 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_ROTATE")),
362 tr("MNU_ROTATE_VIEW"), 0, this);
363 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
364 connect(aAction, SIGNAL(triggered()), this, SLOT(onActivated()));
365 myToolBar->addAction(aAction);
366 myButsMap[ RotationId ] = aAction;
368 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_TRIHEDRON")),
369 tr("MNU_SHOW_TRIHEDRE"), 0, this);
370 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
371 aAction->setCheckable(true);
372 connect(aAction, SIGNAL(triggered()), this, SLOT(onTrihChanged()));
373 myToolBar->addAction(aAction);
374 myButsMap[ TrihId ] = aAction;
376 myZoomBtns->insertAction(myButsMap[ FitAllId ]);
377 myZoomBtns->insertAction(myButsMap[ FitRectId ]);
378 myZoomBtns->insertAction(myButsMap[ ZoomId ]);
380 myPanBtns->insertAction(myButsMap[ PanId ]);
381 myPanBtns->insertAction(myButsMap[ GlobalPanId ]);
383 myProjBtns->insertAction(myButsMap[ FrontId ]);
384 myProjBtns->insertAction(myButsMap[ BackId ]);
385 myProjBtns->insertAction(myButsMap[ TopId ]);
386 myProjBtns->insertAction(myButsMap[ BottomId ]);
387 myProjBtns->insertAction(myButsMap[ LeftId ]);
388 myProjBtns->insertAction(myButsMap[ RightId ]);
394 bool OCCViewer_ViewWidget::eventFilter(QObject* watched, QEvent* e)
396 if (e->type() == QEvent::ContextMenu)
401 if (watched == myViewPort) {
402 int aType = e->type();
404 case QEvent::MouseButtonPress:
405 vpMousePressEvent((QMouseEvent*) e);
409 case QEvent::MouseButtonRelease:
410 vpMouseReleaseEvent((QMouseEvent*) e);
414 case QEvent::MouseMove:
415 vpMouseMoveEvent((QMouseEvent*) e);
421 QWheelEvent* aEvent = (QWheelEvent*) e;
422 double aDelta = aEvent->delta();
423 double aScale = (aDelta < 0) ? 100./(-aDelta) : aDelta/100.;
424 myViewPort->getView()->SetZoom(aScale);
434 aRes = QFrame::eventFilter(watched, e);
436 if (watched == myViewPort && !myViewPort->getView().IsNull()) {
437 if (e->type() == QEvent::MouseButtonRelease)
444 void OCCViewer_ViewWidget::onActivated()
446 if(!sender() || !sender()->inherits("QtxAction"))
448 QtxAction* anAction = (QtxAction*)sender();
449 ActionsMap::const_iterator anIt = myButsMap.begin(), last = myButsMap.end();
451 for (; anIt != last && aCurAction == -1; anIt++) {
452 if (anIt.value() != anAction)
454 aCurAction = anIt.key();
457 case RotationId: activateRotation(); return;
458 case FitAllId: viewerFitAll(); break;
459 case FitRectId: activateWindowFit(); break;
460 case ZoomId: activateZoom(); break;
461 case PanId: activatePanning(); break;
462 case GlobalPanId: activateGlPanning(); break;
467 void OCCViewer_ViewWidget::viewerFitAll(const bool theUpdate)
469 myViewPort->fitAll(false, true, theUpdate);
473 void OCCViewer_ViewWidget::onTrihChanged()
475 QtxAction* anAction = myButsMap[TrihId];
476 myShowTrihedron = anAction->isChecked();
477 if (myShowTrihedron) {
478 myAISContext->Display(myTrihedron);
479 myAISContext->Deactivate(myTrihedron);
482 myAISContext->Erase(myTrihedron);
485 Processes transformation "front view"
487 void OCCViewer_ViewWidget::onFrontView()
489 Handle(V3d_View) aView3d = myViewPort->getView();
490 if (!aView3d.IsNull()) aView3d->SetProj (V3d_Xpos);
495 Processes transformation "back view"
497 void OCCViewer_ViewWidget::onBackView()
499 Handle(V3d_View) aView3d = myViewPort->getView();
500 if (!aView3d.IsNull()) aView3d->SetProj (V3d_Xneg);
505 Processes transformation "top view"
507 void OCCViewer_ViewWidget::onTopView()
509 Handle(V3d_View) aView3d = myViewPort->getView();
510 if (!aView3d.IsNull()) aView3d->SetProj (V3d_Zpos);
515 Processes transformation "bottom view"
517 void OCCViewer_ViewWidget::onBottomView()
519 Handle(V3d_View) aView3d = myViewPort->getView();
520 if (!aView3d.IsNull()) aView3d->SetProj (V3d_Zneg);
525 Processes transformation "left view"
527 void OCCViewer_ViewWidget::onLeftView()
529 Handle(V3d_View) aView3d = myViewPort->getView();
530 if (!aView3d.IsNull()) aView3d->SetProj (V3d_Yneg);
535 Processes transformation "right view"
537 void OCCViewer_ViewWidget::onRightView()
539 Handle(V3d_View) aView3d = myViewPort->getView();
540 if (!aView3d.IsNull()) aView3d->SetProj (V3d_Ypos);
545 void OCCViewer_ViewWidget::viewZFitAll()
547 myViewPort->getView()->ZFitAll(Z_FIT_ALL_SIZE);
550 void OCCViewer_ViewWidget::activateZoom()
552 if (!transformRequested() && !myCursorIsHand)
553 myCursor = cursor(); /* save old cursor */
555 if (myOperation != ZOOMVIEW) {
556 QPixmap zoomPixmap (imageZoomCursor);
557 QCursor zoomCursor (zoomPixmap);
558 if(setTransformRequested (ZOOMVIEW))
559 setCursor(zoomCursor);
563 void OCCViewer_ViewWidget::activateWindowFit()
565 if (!transformRequested() && !myCursorIsHand)
566 myCursor = cursor(); /* save old cursor */
568 if (myOperation != WINDOWFIT) {
569 QCursor handCursor (Qt::PointingHandCursor);
570 if(setTransformRequested (WINDOWFIT))
571 setCursor (handCursor);
572 myCursorIsHand = true;
576 void OCCViewer_ViewWidget::activateRotation()
578 if (!transformRequested() && !myCursorIsHand)
579 myCursor = cursor(); // save old cursor
581 if (myOperation != ROTATE) {
582 QPixmap rotatePixmap (imageRotateCursor);
583 QCursor rotCursor (rotatePixmap);
584 if(setTransformRequested (ROTATE))
585 setCursor(rotCursor);
589 void OCCViewer_ViewWidget::activatePanning()
591 if (!transformRequested() && !myCursorIsHand)
592 myCursor = cursor(); // save old cursor
594 if (myOperation != PANVIEW) {
595 QCursor panCursor (Qt::SizeAllCursor);
596 if(setTransformRequested (PANVIEW))
597 setCursor(panCursor);
601 void OCCViewer_ViewWidget::activateGlPanning()
603 Handle(V3d_View) aView3d = myViewPort->getView();
604 if (!aView3d.IsNull()) {
605 QPixmap globalPanPixmap (imageCrossCursor);
606 QCursor glPanCursor (globalPanPixmap);
607 myCurScale = aView3d->Scale();
608 aView3d->FitAll(0.01, false);
609 myCursor = cursor(); // save old cursor
610 myViewPort->fitAll(); // fits view before selecting a new scene center
611 if(setTransformRequested(PANGLOBAL))
612 setCursor(glPanCursor);
616 void OCCViewer_ViewWidget::vpMousePressEvent(QMouseEvent* theEvent)
618 myStartX = theEvent->x();
619 myStartY = theEvent->y();
620 switch (myOperation) {
627 if (theEvent->button() == Qt::LeftButton) {
628 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
632 /* Try to activate a transformation */
633 switch (getButtonState(theEvent)) {
642 //myViewPort->startRotation(myStartX, myStartY);//, 0, mySelectedPoint);
649 OCCViewer_ViewWidget::OperationType OCCViewer_ViewWidget::getButtonState(QMouseEvent* theEvent)
651 OperationType aOp = NOTHING;
652 if((theEvent->modifiers() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::ZOOM]) &&
653 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::ZOOM]))
655 else if((theEvent->modifiers() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::PAN]) &&
656 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::PAN]))
658 else if((theEvent->modifiers() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::ROTATE]) &&
659 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::ROTATE]))
665 void OCCViewer_ViewWidget::vpMouseReleaseEvent(QMouseEvent* theEvent)
667 switch (myOperation) {
671 myViewPort->endRotation();
680 if (theEvent->button() == Qt::LeftButton) {
681 myViewPort->setCenter(theEvent->x(), theEvent->y());
682 myViewPort->getView()->SetScale(myCurScale);
688 if (theEvent->modifiers() == Qt::LeftButton) {
689 myCurrX = theEvent->x();
690 myCurrY = theEvent->y();
691 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
692 if (!rect.isEmpty()) myViewPort->fitRect(rect);
698 // NOTE: viewer 3D detects a rectangle of selection using this event
699 // so we must emit it BEFORE resetting the selection rectangle
701 if (theEvent->button() == Qt::LeftButton && myDrawRect) {
705 myViewPort->update();
709 void OCCViewer_ViewWidget::vpMouseMoveEvent(QMouseEvent* theEvent)
711 myCurrX = theEvent->x();
712 myCurrY = theEvent->y();
713 switch (myOperation) {
715 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
718 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
724 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
733 int aState = theEvent->modifiers();
734 if (aState == Qt::LeftButton ||
735 aState == ((int) Qt::LeftButton | (int) Qt::ShiftModifier)) {
739 if (!myCursorIsHand) { // we are going to sketch a rectangle
740 QCursor handCursor (Qt::PointingHandCursor);
741 myCursorIsHand = true;
743 setCursor(handCursor);
752 Sets the viewport to its initial state
753 (no transformations in process etc.)
755 void OCCViewer_ViewWidget::resetState()
761 /* make rectangle empty (left > right) */
762 if (transformRequested() || myCursorIsHand)
764 myCursorIsHand = false;
766 setTransformRequested(NOTHING);
769 void OCCViewer_ViewWidget::drawRect()
771 QPainter aPainter(myViewPort);
772 aPainter.setCompositionMode(QPainter::CompositionMode_Xor);
773 aPainter.setPen(Qt::white);
774 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
775 if (!myRect.isEmpty())
776 aPainter.drawRect(myRect);
777 aPainter.drawRect(aRect);
781 bool OCCViewer_ViewWidget::setTransformRequested (OperationType op)
784 myViewPort->setMouseTracking(myOperation == NOTHING);
788 void OCCViewer_ViewWidget::clearViewer(const bool theUpdate)
790 // check if trihedron is displayed
791 Standard_Boolean isTrihedronDisplayed = myAISContext->IsDisplayed(myTrihedron);
793 // get objects to be erased (all currently displayed objects)
794 AIS_ListOfInteractive aList;
795 myAISContext->DisplayedObjects(aList);
796 AIS_ListIteratorOfListOfInteractive anIter(aList);
797 for (; anIter.More(); anIter.Next()) {
798 if (isTrihedronDisplayed && anIter.Value()->DynamicType() == STANDARD_TYPE(AIS_Trihedron))
801 Handle(AIS_InteractiveObject) anIO = anIter.Value();
802 #if OCC_VERSION_LARGE <= 0x06060000
803 myAISContext->Erase(anIO, false, false);
805 myAISContext->Erase(anIO, false);
809 // display trihedron if necessary
810 if (isTrihedronDisplayed)
811 myAISContext->Display(myTrihedron, theUpdate);
813 myV3dViewer->Update();
815 myAISContext->UpdateCurrentViewer();