2 #include "OCCViewer_ViewWidget.h"
4 #include <SUIT_Desktop.h>
5 #include <SUIT_Session.h>
6 #include <SUIT_ResourceMgr.h>
7 #include <SUIT_MessageBox.h>
8 #include <OCCViewer_ViewPort3d.h>
9 #include <OCCViewer_VService.h>
10 #include <SUIT_ViewModel.h>
11 #include <SUIT_Tools.h>
13 #include <QtxAction.h>
15 #include <AIS_InteractiveObject.hxx>
16 #include <AIS_ListOfInteractive.hxx>
17 #include <V3d_Viewer.hxx>
18 #include <AIS_Shape.hxx>
19 #include <Prs3d_LineAspect.hxx>
21 #include <AIS_InteractiveContext.hxx>
22 #include <AIS_ListIteratorOfListOfInteractive.hxx>
23 #include <Geom_Axis2Placement.hxx>
24 #include <AIS_Drawer.hxx>
25 #include <Prs3d_DatumAspect.hxx>
29 #include <QHBoxLayout>
30 #include <QPushButton>
33 #include <QWheelEvent>
34 #include <QMouseEvent>
37 const int SPACING_SIZE = 5;
38 const int Z_FIT_ALL_SIZE = 1000;
40 const char* imageZoomCursor[] = {
45 "................................",
46 "................................",
47 ".#######........................",
48 "..aaaaaaa.......................",
49 "................................",
50 ".............#####..............",
51 "...........##.aaaa##............",
52 "..........#.aa.....a#...........",
53 ".........#.a.........#..........",
54 ".........#a..........#a.........",
55 "........#.a...........#.........",
56 "........#a............#a........",
57 "........#a............#a........",
58 "........#a............#a........",
59 "........#a............#a........",
60 ".........#...........#.a........",
61 ".........#a..........#a.........",
62 ".........##.........#.a.........",
63 "........#####.....##.a..........",
64 ".......###aaa#####.aa...........",
65 "......###aa...aaaaa.......#.....",
66 ".....###aa................#a....",
67 "....###aa.................#a....",
68 "...###aa...............#######..",
69 "....#aa.................aa#aaaa.",
70 ".....a....................#a....",
71 "..........................#a....",
72 "...........................a....",
73 "................................",
74 "................................",
75 "................................",
76 "................................"};
78 const char* imageRotateCursor[] = {
83 "................................",
84 "................................",
85 "................................",
86 "................................",
87 "........#.......................",
88 ".......#.a......................",
89 "......#######...................",
90 ".......#aaaaa#####..............",
91 "........#..##.a#aa##........##..",
92 ".........a#.aa..#..a#.....##.aa.",
93 ".........#.a.....#...#..##.aa...",
94 ".........#a.......#..###.aa.....",
95 "........#.a.......#a..#aa.......",
96 "........#a.........#..#a........",
97 "........#a.........#a.#a........",
98 "........#a.........#a.#a........",
99 "........#a.........#a.#a........",
100 ".........#.........#a#.a........",
101 "........##a........#a#a.........",
102 "......##.a#.......#.#.a.........",
103 "....##.aa..##.....##.a..........",
104 "..##.aa.....a#####.aa...........",
105 "...aa.........aaa#a.............",
106 "................#.a.............",
107 "...............#.a..............",
108 "..............#.a...............",
109 "...............a................",
110 "................................",
111 "................................",
112 "................................",
113 "................................",
114 "................................"};
116 const char* imageCrossCursor[] = {
121 "................................",
122 "................................",
123 "................................",
124 "................................",
125 "................................",
126 "................................",
127 "................................",
128 "...............#................",
129 "...............#a...............",
130 "...............#a...............",
131 "...............#a...............",
132 "...............#a...............",
133 "...............#a...............",
134 "...............#a...............",
135 "...............#a...............",
136 ".......#################........",
137 "........aaaaaaa#aaaaaaaaa.......",
138 "...............#a...............",
139 "...............#a...............",
140 "...............#a...............",
141 "...............#a...............",
142 "...............#a...............",
143 "...............#a...............",
144 "...............#a...............",
145 "................a...............",
146 "................................",
147 "................................",
148 "................................",
149 "................................",
150 "................................",
151 "................................",
152 "................................"};
154 // ---------------- OCC view widget --------
155 OCCViewer_ViewWidget::OCCViewer_ViewWidget(QWidget* parent)
156 : QFrame(parent), myShowTrihedron(true)
158 setObjectName("OCC_view_widget");
159 mySelectedPoint = gp_Pnt(0.,0.,0.);
160 setFrameStyle(QFrame::NoFrame);
162 QGridLayout* anAnalLay = new QGridLayout(this);
163 anAnalLay->setMargin(0);
164 anAnalLay->setSpacing(SPACING_SIZE);
166 QWidget* aBtnBox = new QWidget(this);
167 QHBoxLayout* aBtnLay = new QHBoxLayout(aBtnBox);
168 aBtnLay->setMargin(0);
169 aBtnLay->setSpacing(SPACING_SIZE);
171 myToolBar = new QToolBar(aBtnBox);
172 aBtnLay->addWidget(myToolBar);
173 myZoomBtns = new QtxMultiAction(aBtnBox);
174 myZoomBtns->setObjectName("zoomBtn");
175 myToolBar->addAction(myZoomBtns);
176 myPanBtns = new QtxMultiAction(aBtnBox);
177 myPanBtns->setObjectName("panBtn");
178 myToolBar->addAction(myPanBtns);
179 myProjBtns = new QtxMultiAction(aBtnBox);
180 myProjBtns->setObjectName("projectionBtn");
181 myToolBar->addAction(myProjBtns);
184 aBtnLay->addStretch(1);
185 anAnalLay->addWidget(aBtnBox, 0, 0, 1, 2);
187 myV3dViewer = OCCViewer_VService::CreateViewer((short*) "Viewer3d", "", "", 1000., V3d_XposYnegZpos, true, true);
188 //myV3dViewer->Init(); // to avoid creation of the useless perspective view (see OCCT issue 0024267)
190 #if OCC_VERSION_LARGE <= 0x06060000 // Porting to OCCT higher 6.6.0 version
191 myV3dCollector = OCCViewer_VService::CreateViewer((short*) "Collector3d", "", "", 1000., V3d_XposYnegZpos, true, true);
192 myV3dCollector->Init();
196 #if OCC_VERSION_LARGE <= 0x06060000
197 myAISContext = new AIS_InteractiveContext( myV3dViewer, myV3dCollector );
199 myAISContext = new AIS_InteractiveContext( myV3dViewer );
201 myAISContext->SelectionColor(Quantity_NOC_WHITE);
202 myAISContext->IsoOnPlane(true);
204 myViewPort = new OCCViewer_ViewPort3d(this, myV3dViewer, V3d_ORTHOGRAPHIC);
205 myViewPort->setBackgroundColor(Qt::black);
206 myViewPort->setMinimumHeight(300);
207 myViewPort->installEventFilter(this);
208 anAnalLay->addWidget(myViewPort, 1, 0, 1, 2);
210 Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(gp::XOY());
211 myTrihedron = new AIS_Trihedron(anAxis);
212 myTrihedron->SetInfiniteState(Standard_True);
214 Quantity_Color Col(193/255., 205/255., 193/255., Quantity_TOC_RGB);
215 myTrihedron->SetArrowColor(Col.Name());
216 myTrihedron->SetSize(100);
217 Handle(AIS_Drawer) drawer = myTrihedron->Attributes();
218 if (drawer->HasDatumAspect()) {
219 Handle(Prs3d_DatumAspect) daspect = drawer->DatumAspect();
220 daspect->FirstAxisAspect()->SetColor(Quantity_Color(1.0, 0.0, 0.0, Quantity_TOC_RGB));
221 daspect->SecondAxisAspect()->SetColor(Quantity_Color(0.0, 1.0, 0.0, Quantity_TOC_RGB));
222 daspect->ThirdAxisAspect()->SetColor(Quantity_Color(0.0, 0.0, 1.0, Quantity_TOC_RGB));
224 myAISContext->Display(myTrihedron);
225 myAISContext->Deactivate(myTrihedron);
227 myTrihedron->SetTransformPersistence(Graphic3d_TMF_TriedronPers, gp_Pnt(-1, -1, 200));
228 myTrihedron->SetSize(100);
231 myButsMap[TrihId]->setChecked(false);
235 OCCViewer_ViewWidget::~OCCViewer_ViewWidget()
239 myAISContext.Nullify();
240 myV3dViewer.Nullify();
241 #if OCC_VERSION_LARGE <= 0x06060000
242 myV3dCollector.Nullify();
246 void OCCViewer_ViewWidget::reset()
249 myOperation = NOTHING;
250 myCurrPointType = OCCViewer_ViewWindow::GRAVITY;
253 void OCCViewer_ViewWidget::Display(const TopoDS_Shape shape, const bool theShaded,
254 const QColor& shapeColor)
257 if (shape.IsNull()) {
258 myAISContext->UpdateCurrentViewer();
262 Handle(AIS_InteractiveObject) io = new AIS_Shape(shape);
263 io->UnsetSelectionMode();
264 io->UnsetHilightMode();
266 Quantity_Color aColor(shapeColor.red()/255., shapeColor.green()/255.,
267 shapeColor.blue()/255., Quantity_TOC_RGB);
268 io->SetColor(aColor);
270 myAISContext->Display(io, false);
272 myAISContext->SetDisplayMode(io, AIS_Shaded, false);
273 myAISContext->SetMaterial(io, Graphic3d_NOM_PLASTIC, false);
276 myAISContext->SetDisplayMode(io, AIS_WireFrame, false);
278 myAISContext->UpdateCurrentViewer();
281 void OCCViewer_ViewWidget::createActions()
283 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
287 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_FITALL")),
288 tr("MNU_FITALL"), 0, this);
289 aAction->setStatusTip(tr("DSC_FITALL"));
290 connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
291 myButsMap[ FitAllId ] = aAction;
294 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_FITAREA")),
295 tr("MNU_FITRECT"), 0, this);
296 aAction->setStatusTip(tr("DSC_FITRECT"));
297 connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
298 myButsMap[ FitRectId ] = aAction;
301 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_ZOOM")),
302 tr("MNU_ZOOM_VIEW"), 0, this);
303 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
304 connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
305 myButsMap[ ZoomId ] = aAction;
308 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_PAN")),
309 tr("MNU_PAN_VIEW"), 0, this);
310 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
311 connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
312 myButsMap[ PanId ] = aAction;
315 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_GLOBALPAN")),
316 tr("MNU_GLOBALPAN_VIEW"), 0, this);
317 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
318 connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
319 myButsMap[ GlobalPanId ] = aAction;
322 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_FRONT")),
323 tr("MNU_FRONT_VIEW"), 0, this);
324 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
325 connect(aAction, SIGNAL(activated()), this, SLOT(onFrontView()));
326 myButsMap[ FrontId ] = aAction;
328 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_BACK")),
329 tr("MNU_BACK_VIEW"), 0, this);
330 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
331 connect(aAction, SIGNAL(activated()), this, SLOT(onBackView()));
332 myButsMap[ BackId ] = aAction;
334 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_TOP")),
335 tr("MNU_TOP_VIEW"), 0, this);
336 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
337 connect(aAction, SIGNAL(activated()), this, SLOT(onTopView()));
338 myButsMap[ TopId ] = aAction;
340 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_BOTTOM")),
341 tr("MNU_BOTTOM_VIEW"), 0, this);
342 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
343 connect(aAction, SIGNAL(activated()), this, SLOT(onBottomView()));
344 myButsMap[ BottomId ] = aAction;
346 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_LEFT")),
347 tr("MNU_LEFT_VIEW"), 0, this);
348 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
349 connect(aAction, SIGNAL(activated()), this, SLOT(onLeftView()));
350 myButsMap[ LeftId ] = aAction;
352 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_RIGHT")),
353 tr("MNU_RIGHT_VIEW"), 0, this);
354 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
355 connect(aAction, SIGNAL(activated()), this, SLOT(onRightView()));
356 myButsMap[ RightId ] = aAction;
358 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_ROTATE")),
359 tr("MNU_ROTATE_VIEW"), 0, this);
360 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
361 connect(aAction, SIGNAL(triggered()), this, SLOT(onActivated()));
362 myToolBar->addAction(aAction);
363 myButsMap[ RotationId ] = aAction;
365 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_TRIHEDRON")),
366 tr("MNU_SHOW_TRIHEDRE"), 0, this);
367 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
368 aAction->setCheckable(true);
369 connect(aAction, SIGNAL(triggered()), this, SLOT(onTrihChanged()));
370 myToolBar->addAction(aAction);
371 myButsMap[ TrihId ] = aAction;
373 myZoomBtns->insertAction(myButsMap[ FitAllId ]);
374 myZoomBtns->insertAction(myButsMap[ FitRectId ]);
375 myZoomBtns->insertAction(myButsMap[ ZoomId ]);
377 myPanBtns->insertAction(myButsMap[ PanId ]);
378 myPanBtns->insertAction(myButsMap[ GlobalPanId ]);
380 myProjBtns->insertAction(myButsMap[ FrontId ]);
381 myProjBtns->insertAction(myButsMap[ BackId ]);
382 myProjBtns->insertAction(myButsMap[ TopId ]);
383 myProjBtns->insertAction(myButsMap[ BottomId ]);
384 myProjBtns->insertAction(myButsMap[ LeftId ]);
385 myProjBtns->insertAction(myButsMap[ RightId ]);
391 bool OCCViewer_ViewWidget::eventFilter(QObject* watched, QEvent* e)
393 if (e->type() == QEvent::ContextMenu)
398 if (watched == myViewPort) {
399 int aType = e->type();
401 case QEvent::MouseButtonPress:
402 vpMousePressEvent((QMouseEvent*) e);
406 case QEvent::MouseButtonRelease:
407 vpMouseReleaseEvent((QMouseEvent*) e);
411 case QEvent::MouseMove:
412 vpMouseMoveEvent((QMouseEvent*) e);
418 QWheelEvent* aEvent = (QWheelEvent*) e;
419 double aDelta = aEvent->delta();
420 double aScale = (aDelta < 0) ? 100./(-aDelta) : aDelta/100.;
421 myViewPort->getView()->SetZoom(aScale);
431 aRes = QFrame::eventFilter(watched, e);
433 if (watched == myViewPort && !myViewPort->getView().IsNull()) {
434 if (e->type() == QEvent::MouseButtonRelease)
441 void OCCViewer_ViewWidget::onActivated()
443 if(!sender() || !sender()->inherits("QtxAction"))
445 QtxAction* anAction = (QtxAction*)sender();
446 ActionsMap::const_iterator anIt = myButsMap.begin(), last = myButsMap.end();
448 for (; anIt != last && aCurAction == -1; anIt++) {
449 if (anIt.value() != anAction)
451 aCurAction = anIt.key();
454 case RotationId: activateRotation(); return;
455 case FitAllId: viewerFitAll(); break;
456 case FitRectId: activateWindowFit(); break;
457 case ZoomId: activateZoom(); break;
458 case PanId: activatePanning(); break;
459 case GlobalPanId: activateGlPanning(); break;
464 void OCCViewer_ViewWidget::viewerFitAll(const bool theUpdate)
466 myViewPort->fitAll(false, true, theUpdate);
470 void OCCViewer_ViewWidget::onTrihChanged()
472 QtxAction* anAction = myButsMap[TrihId];
473 myShowTrihedron = anAction->isChecked();
474 if (myShowTrihedron) {
475 myAISContext->Display(myTrihedron);
476 myAISContext->Deactivate(myTrihedron);
479 myAISContext->Erase(myTrihedron);
482 Processes transformation "front view"
484 void OCCViewer_ViewWidget::onFrontView()
486 Handle(V3d_View) aView3d = myViewPort->getView();
487 if (!aView3d.IsNull()) aView3d->SetProj (V3d_Xpos);
492 Processes transformation "back view"
494 void OCCViewer_ViewWidget::onBackView()
496 Handle(V3d_View) aView3d = myViewPort->getView();
497 if (!aView3d.IsNull()) aView3d->SetProj (V3d_Xneg);
502 Processes transformation "top view"
504 void OCCViewer_ViewWidget::onTopView()
506 Handle(V3d_View) aView3d = myViewPort->getView();
507 if (!aView3d.IsNull()) aView3d->SetProj (V3d_Zpos);
512 Processes transformation "bottom view"
514 void OCCViewer_ViewWidget::onBottomView()
516 Handle(V3d_View) aView3d = myViewPort->getView();
517 if (!aView3d.IsNull()) aView3d->SetProj (V3d_Zneg);
522 Processes transformation "left view"
524 void OCCViewer_ViewWidget::onLeftView()
526 Handle(V3d_View) aView3d = myViewPort->getView();
527 if (!aView3d.IsNull()) aView3d->SetProj (V3d_Yneg);
532 Processes transformation "right view"
534 void OCCViewer_ViewWidget::onRightView()
536 Handle(V3d_View) aView3d = myViewPort->getView();
537 if (!aView3d.IsNull()) aView3d->SetProj (V3d_Ypos);
542 void OCCViewer_ViewWidget::viewZFitAll()
544 myViewPort->getView()->ZFitAll(Z_FIT_ALL_SIZE);
547 void OCCViewer_ViewWidget::activateZoom()
549 if (!transformRequested() && !myCursorIsHand)
550 myCursor = cursor(); /* save old cursor */
552 if (myOperation != ZOOMVIEW) {
553 QPixmap zoomPixmap (imageZoomCursor);
554 QCursor zoomCursor (zoomPixmap);
555 if(setTransformRequested (ZOOMVIEW))
556 setCursor(zoomCursor);
560 void OCCViewer_ViewWidget::activateWindowFit()
562 if (!transformRequested() && !myCursorIsHand)
563 myCursor = cursor(); /* save old cursor */
565 if (myOperation != WINDOWFIT) {
566 QCursor handCursor (Qt::PointingHandCursor);
567 if(setTransformRequested (WINDOWFIT))
568 setCursor (handCursor);
569 myCursorIsHand = true;
573 void OCCViewer_ViewWidget::activateRotation()
575 if (!transformRequested() && !myCursorIsHand)
576 myCursor = cursor(); // save old cursor
578 if (myOperation != ROTATE) {
579 QPixmap rotatePixmap (imageRotateCursor);
580 QCursor rotCursor (rotatePixmap);
581 if(setTransformRequested (ROTATE))
582 setCursor(rotCursor);
586 void OCCViewer_ViewWidget::activatePanning()
588 if (!transformRequested() && !myCursorIsHand)
589 myCursor = cursor(); // save old cursor
591 if (myOperation != PANVIEW) {
592 QCursor panCursor (Qt::SizeAllCursor);
593 if(setTransformRequested (PANVIEW))
594 setCursor(panCursor);
598 void OCCViewer_ViewWidget::activateGlPanning()
600 Handle(V3d_View) aView3d = myViewPort->getView();
601 if (!aView3d.IsNull()) {
602 QPixmap globalPanPixmap (imageCrossCursor);
603 QCursor glPanCursor (globalPanPixmap);
604 myCurScale = aView3d->Scale();
605 aView3d->FitAll(0.01, false);
606 myCursor = cursor(); // save old cursor
607 myViewPort->fitAll(); // fits view before selecting a new scene center
608 if(setTransformRequested(PANGLOBAL))
609 setCursor(glPanCursor);
613 void OCCViewer_ViewWidget::vpMousePressEvent(QMouseEvent* theEvent)
615 myStartX = theEvent->x();
616 myStartY = theEvent->y();
617 switch (myOperation) {
624 if (theEvent->button() == Qt::LeftButton) {
625 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
629 /* Try to activate a transformation */
630 switch (getButtonState(theEvent)) {
639 //myViewPort->startRotation(myStartX, myStartY);//, 0, mySelectedPoint);
646 OCCViewer_ViewWidget::OperationType OCCViewer_ViewWidget::getButtonState(QMouseEvent* theEvent)
648 OperationType aOp = NOTHING;
649 if((theEvent->modifiers() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::ZOOM]) &&
650 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::ZOOM]))
652 else if((theEvent->modifiers() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::PAN]) &&
653 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::PAN]))
655 else if((theEvent->modifiers() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::ROTATE]) &&
656 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::ROTATE]))
662 void OCCViewer_ViewWidget::vpMouseReleaseEvent(QMouseEvent* theEvent)
664 switch (myOperation) {
668 myViewPort->endRotation();
677 if (theEvent->button() == Qt::LeftButton) {
678 myViewPort->setCenter(theEvent->x(), theEvent->y());
679 myViewPort->getView()->SetScale(myCurScale);
685 if (theEvent->modifiers() == Qt::LeftButton) {
686 myCurrX = theEvent->x();
687 myCurrY = theEvent->y();
688 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
689 if (!rect.isEmpty()) myViewPort->fitRect(rect);
695 // NOTE: viewer 3D detects a rectangle of selection using this event
696 // so we must emit it BEFORE resetting the selection rectangle
698 if (theEvent->button() == Qt::LeftButton && myDrawRect) {
702 myViewPort->update();
706 void OCCViewer_ViewWidget::vpMouseMoveEvent(QMouseEvent* theEvent)
708 myCurrX = theEvent->x();
709 myCurrY = theEvent->y();
710 switch (myOperation) {
712 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
715 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
721 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
730 int aState = theEvent->modifiers();
731 if (aState == Qt::LeftButton ||
732 aState == ((int) Qt::LeftButton | (int) Qt::ShiftModifier)) {
736 if (!myCursorIsHand) { // we are going to sketch a rectangle
737 QCursor handCursor (Qt::PointingHandCursor);
738 myCursorIsHand = true;
740 setCursor(handCursor);
749 Sets the viewport to its initial state
750 (no transformations in process etc.)
752 void OCCViewer_ViewWidget::resetState()
758 /* make rectangle empty (left > right) */
759 if (transformRequested() || myCursorIsHand)
761 myCursorIsHand = false;
763 setTransformRequested(NOTHING);
766 void OCCViewer_ViewWidget::drawRect()
768 QPainter aPainter(myViewPort);
769 aPainter.setCompositionMode(QPainter::CompositionMode_Xor);
770 aPainter.setPen(Qt::white);
771 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
772 if (!myRect.isEmpty())
773 aPainter.drawRect(myRect);
774 aPainter.drawRect(aRect);
778 bool OCCViewer_ViewWidget::setTransformRequested (OperationType op)
781 myViewPort->setMouseTracking(myOperation == NOTHING);
785 void OCCViewer_ViewWidget::clearViewer(const bool theUpdate)
787 // check if trihedron is displayed
788 Standard_Boolean isTrihedronDisplayed = myAISContext->IsDisplayed(myTrihedron);
790 // get objects to be erased (all currently displayed objects)
791 AIS_ListOfInteractive aList;
792 myAISContext->DisplayedObjects(aList);
793 AIS_ListIteratorOfListOfInteractive anIter(aList);
794 for (; anIter.More(); anIter.Next()) {
795 if (isTrihedronDisplayed && anIter.Value()->DynamicType() == STANDARD_TYPE(AIS_Trihedron))
798 Handle(AIS_InteractiveObject) anIO = anIter.Value();
799 #if OCC_VERSION_LARGE <= 0x06060000
800 myAISContext->Erase(anIO, false, false);
802 myAISContext->Erase(anIO, false);
806 // display trihedron if necessary
807 if (isTrihedronDisplayed)
808 myAISContext->Display(myTrihedron, theUpdate);
810 myV3dViewer->Update();
812 myAISContext->UpdateCurrentViewer();