2 #include "OCCViewer_ViewWidget.h"
4 #include <Basics_OCCTVersion.hxx>
6 #include <SUIT_Desktop.h>
7 #include <SUIT_Session.h>
8 #include <SUIT_ResourceMgr.h>
9 #include <SUIT_MessageBox.h>
10 #include <OCCViewer_ViewPort3d.h>
11 #include <OCCViewer_VService.h>
12 #include <SUIT_ViewModel.h>
13 #include <SUIT_Tools.h>
15 #include <QtxAction.h>
17 #include <AIS_InteractiveObject.hxx>
18 #include <AIS_ListOfInteractive.hxx>
19 #include <V3d_Viewer.hxx>
20 #include <AIS_Shape.hxx>
21 #include <Prs3d_LineAspect.hxx>
23 #include <AIS_InteractiveContext.hxx>
24 #include <AIS_ListIteratorOfListOfInteractive.hxx>
25 #include <Geom_Axis2Placement.hxx>
26 #include <AIS_Drawer.hxx>
27 #include <Prs3d_DatumAspect.hxx>
31 #include <QHBoxLayout>
32 #include <QPushButton>
35 #include <QWheelEvent>
36 #include <QMouseEvent>
39 const int SPACING_SIZE = 5;
40 const int Z_FIT_ALL_SIZE = 1000;
42 const char* imageZoomCursor[] = {
47 "................................",
48 "................................",
49 ".#######........................",
50 "..aaaaaaa.......................",
51 "................................",
52 ".............#####..............",
53 "...........##.aaaa##............",
54 "..........#.aa.....a#...........",
55 ".........#.a.........#..........",
56 ".........#a..........#a.........",
57 "........#.a...........#.........",
58 "........#a............#a........",
59 "........#a............#a........",
60 "........#a............#a........",
61 "........#a............#a........",
62 ".........#...........#.a........",
63 ".........#a..........#a.........",
64 ".........##.........#.a.........",
65 "........#####.....##.a..........",
66 ".......###aaa#####.aa...........",
67 "......###aa...aaaaa.......#.....",
68 ".....###aa................#a....",
69 "....###aa.................#a....",
70 "...###aa...............#######..",
71 "....#aa.................aa#aaaa.",
72 ".....a....................#a....",
73 "..........................#a....",
74 "...........................a....",
75 "................................",
76 "................................",
77 "................................",
78 "................................"};
80 const char* imageRotateCursor[] = {
85 "................................",
86 "................................",
87 "................................",
88 "................................",
89 "........#.......................",
90 ".......#.a......................",
91 "......#######...................",
92 ".......#aaaaa#####..............",
93 "........#..##.a#aa##........##..",
94 ".........a#.aa..#..a#.....##.aa.",
95 ".........#.a.....#...#..##.aa...",
96 ".........#a.......#..###.aa.....",
97 "........#.a.......#a..#aa.......",
98 "........#a.........#..#a........",
99 "........#a.........#a.#a........",
100 "........#a.........#a.#a........",
101 "........#a.........#a.#a........",
102 ".........#.........#a#.a........",
103 "........##a........#a#a.........",
104 "......##.a#.......#.#.a.........",
105 "....##.aa..##.....##.a..........",
106 "..##.aa.....a#####.aa...........",
107 "...aa.........aaa#a.............",
108 "................#.a.............",
109 "...............#.a..............",
110 "..............#.a...............",
111 "...............a................",
112 "................................",
113 "................................",
114 "................................",
115 "................................",
116 "................................"};
118 const char* imageCrossCursor[] = {
123 "................................",
124 "................................",
125 "................................",
126 "................................",
127 "................................",
128 "................................",
129 "................................",
130 "...............#................",
131 "...............#a...............",
132 "...............#a...............",
133 "...............#a...............",
134 "...............#a...............",
135 "...............#a...............",
136 "...............#a...............",
137 "...............#a...............",
138 ".......#################........",
139 "........aaaaaaa#aaaaaaaaa.......",
140 "...............#a...............",
141 "...............#a...............",
142 "...............#a...............",
143 "...............#a...............",
144 "...............#a...............",
145 "...............#a...............",
146 "...............#a...............",
147 "................a...............",
148 "................................",
149 "................................",
150 "................................",
151 "................................",
152 "................................",
153 "................................",
154 "................................"};
156 // ---------------- OCC view widget --------
157 OCCViewer_ViewWidget::OCCViewer_ViewWidget(QWidget* parent)
158 : QFrame(parent), myShowTrihedron(true)
160 setObjectName("OCC_view_widget");
161 mySelectedPoint = gp_Pnt(0.,0.,0.);
162 setFrameStyle(QFrame::NoFrame);
164 QGridLayout* anAnalLay = new QGridLayout(this);
165 anAnalLay->setMargin(0);
166 anAnalLay->setSpacing(SPACING_SIZE);
168 QWidget* aBtnBox = new QWidget(this);
169 QHBoxLayout* aBtnLay = new QHBoxLayout(aBtnBox);
170 aBtnLay->setMargin(0);
171 aBtnLay->setSpacing(SPACING_SIZE);
173 myToolBar = new QToolBar(aBtnBox);
174 aBtnLay->addWidget(myToolBar);
175 myZoomBtns = new QtxMultiAction(aBtnBox);
176 myZoomBtns->setObjectName("zoomBtn");
177 myToolBar->addAction(myZoomBtns);
178 myPanBtns = new QtxMultiAction(aBtnBox);
179 myPanBtns->setObjectName("panBtn");
180 myToolBar->addAction(myPanBtns);
181 myProjBtns = new QtxMultiAction(aBtnBox);
182 myProjBtns->setObjectName("projectionBtn");
183 myToolBar->addAction(myProjBtns);
186 aBtnLay->addStretch(1);
187 anAnalLay->addWidget(aBtnBox, 0, 0, 1, 2);
189 myV3dViewer = OCCViewer_VService::CreateViewer((short*) "Viewer3d", "", "", 1000., V3d_XposYnegZpos, true, true);
190 //myV3dViewer->Init(); // to avoid creation of the useless perspective view (see OCCT issue 0024267)
192 #if OCC_VERSION_LARGE <= 0x06060000 // Porting to OCCT higher 6.6.0 version
193 myV3dCollector = OCCViewer_VService::CreateViewer((short*) "Collector3d", "", "", 1000., V3d_XposYnegZpos, true, true);
194 myV3dCollector->Init();
198 #if OCC_VERSION_LARGE <= 0x06060000
199 myAISContext = new AIS_InteractiveContext( myV3dViewer, myV3dCollector );
201 myAISContext = new AIS_InteractiveContext( myV3dViewer );
203 myAISContext->SelectionColor(Quantity_NOC_WHITE);
204 myAISContext->IsoOnPlane(true);
206 myViewPort = new OCCViewer_ViewPort3d(this, myV3dViewer, V3d_ORTHOGRAPHIC);
207 myViewPort->setBackgroundColor(Qt::black);
208 myViewPort->setMinimumHeight(300);
209 myViewPort->installEventFilter(this);
210 anAnalLay->addWidget(myViewPort, 1, 0, 1, 2);
212 Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(gp::XOY());
213 myTrihedron = new AIS_Trihedron(anAxis);
214 myTrihedron->SetInfiniteState(Standard_True);
216 Quantity_Color Col(193/255., 205/255., 193/255., Quantity_TOC_RGB);
217 myTrihedron->SetArrowColor(Col.Name());
218 myTrihedron->SetSize(100);
219 Handle(AIS_Drawer) drawer = myTrihedron->Attributes();
220 if (drawer->HasDatumAspect()) {
221 Handle(Prs3d_DatumAspect) daspect = drawer->DatumAspect();
222 daspect->FirstAxisAspect()->SetColor(Quantity_Color(1.0, 0.0, 0.0, Quantity_TOC_RGB));
223 daspect->SecondAxisAspect()->SetColor(Quantity_Color(0.0, 1.0, 0.0, Quantity_TOC_RGB));
224 daspect->ThirdAxisAspect()->SetColor(Quantity_Color(0.0, 0.0, 1.0, Quantity_TOC_RGB));
226 myAISContext->Display(myTrihedron);
227 myAISContext->Deactivate(myTrihedron);
229 myTrihedron->SetTransformPersistence(Graphic3d_TMF_TriedronPers, gp_Pnt(-1, -1, 200));
230 myTrihedron->SetSize(100);
233 myButsMap[TrihId]->setChecked(false);
237 OCCViewer_ViewWidget::~OCCViewer_ViewWidget()
239 #if OCC_VERSION_LARGE <= 0x06060000
240 myV3dCollector.Nullify();
244 void OCCViewer_ViewWidget::reset()
247 myOperation = NOTHING;
248 myCurrPointType = OCCViewer_ViewWindow::GRAVITY;
251 void OCCViewer_ViewWidget::Display(const TopoDS_Shape shape, const bool theShaded,
252 const QColor& shapeColor)
255 if (shape.IsNull()) {
256 myAISContext->UpdateCurrentViewer();
260 Handle(AIS_InteractiveObject) io = new AIS_Shape(shape);
261 io->UnsetSelectionMode();
262 io->UnsetHilightMode();
264 Quantity_Color aColor(shapeColor.red()/255., shapeColor.green()/255.,
265 shapeColor.blue()/255., Quantity_TOC_RGB);
266 io->SetColor(aColor);
268 myAISContext->Display(io, false);
270 myAISContext->SetDisplayMode(io, AIS_Shaded, false);
271 myAISContext->SetMaterial(io, Graphic3d_NOM_PLASTIC, false);
274 myAISContext->SetDisplayMode(io, AIS_WireFrame, false);
276 myAISContext->UpdateCurrentViewer();
279 void OCCViewer_ViewWidget::createActions()
281 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
285 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_FITALL")),
286 tr("MNU_FITALL"), 0, this);
287 aAction->setStatusTip(tr("DSC_FITALL"));
288 connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
289 myButsMap[ FitAllId ] = aAction;
292 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_FITAREA")),
293 tr("MNU_FITRECT"), 0, this);
294 aAction->setStatusTip(tr("DSC_FITRECT"));
295 connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
296 myButsMap[ FitRectId ] = aAction;
299 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_ZOOM")),
300 tr("MNU_ZOOM_VIEW"), 0, this);
301 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
302 connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
303 myButsMap[ ZoomId ] = aAction;
306 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_PAN")),
307 tr("MNU_PAN_VIEW"), 0, this);
308 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
309 connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
310 myButsMap[ PanId ] = aAction;
313 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_GLOBALPAN")),
314 tr("MNU_GLOBALPAN_VIEW"), 0, this);
315 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
316 connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
317 myButsMap[ GlobalPanId ] = aAction;
320 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_FRONT")),
321 tr("MNU_FRONT_VIEW"), 0, this);
322 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
323 connect(aAction, SIGNAL(activated()), this, SLOT(onFrontView()));
324 myButsMap[ FrontId ] = aAction;
326 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_BACK")),
327 tr("MNU_BACK_VIEW"), 0, this);
328 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
329 connect(aAction, SIGNAL(activated()), this, SLOT(onBackView()));
330 myButsMap[ BackId ] = aAction;
332 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_TOP")),
333 tr("MNU_TOP_VIEW"), 0, this);
334 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
335 connect(aAction, SIGNAL(activated()), this, SLOT(onTopView()));
336 myButsMap[ TopId ] = aAction;
338 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_BOTTOM")),
339 tr("MNU_BOTTOM_VIEW"), 0, this);
340 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
341 connect(aAction, SIGNAL(activated()), this, SLOT(onBottomView()));
342 myButsMap[ BottomId ] = aAction;
344 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_LEFT")),
345 tr("MNU_LEFT_VIEW"), 0, this);
346 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
347 connect(aAction, SIGNAL(activated()), this, SLOT(onLeftView()));
348 myButsMap[ LeftId ] = aAction;
350 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_RIGHT")),
351 tr("MNU_RIGHT_VIEW"), 0, this);
352 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
353 connect(aAction, SIGNAL(activated()), this, SLOT(onRightView()));
354 myButsMap[ RightId ] = aAction;
356 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_ROTATE")),
357 tr("MNU_ROTATE_VIEW"), 0, this);
358 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
359 connect(aAction, SIGNAL(triggered()), this, SLOT(onActivated()));
360 myToolBar->addAction(aAction);
361 myButsMap[ RotationId ] = aAction;
363 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_TRIHEDRON")),
364 tr("MNU_SHOW_TRIHEDRE"), 0, this);
365 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
366 aAction->setCheckable(true);
367 connect(aAction, SIGNAL(triggered()), this, SLOT(onTrihChanged()));
368 myToolBar->addAction(aAction);
369 myButsMap[ TrihId ] = aAction;
371 myZoomBtns->insertAction(myButsMap[ FitAllId ]);
372 myZoomBtns->insertAction(myButsMap[ FitRectId ]);
373 myZoomBtns->insertAction(myButsMap[ ZoomId ]);
375 myPanBtns->insertAction(myButsMap[ PanId ]);
376 myPanBtns->insertAction(myButsMap[ GlobalPanId ]);
378 myProjBtns->insertAction(myButsMap[ FrontId ]);
379 myProjBtns->insertAction(myButsMap[ BackId ]);
380 myProjBtns->insertAction(myButsMap[ TopId ]);
381 myProjBtns->insertAction(myButsMap[ BottomId ]);
382 myProjBtns->insertAction(myButsMap[ LeftId ]);
383 myProjBtns->insertAction(myButsMap[ RightId ]);
389 bool OCCViewer_ViewWidget::eventFilter(QObject* watched, QEvent* e)
391 if (e->type() == QEvent::ContextMenu)
396 if (watched == myViewPort) {
397 int aType = e->type();
399 case QEvent::MouseButtonPress:
400 vpMousePressEvent((QMouseEvent*) e);
404 case QEvent::MouseButtonRelease:
405 vpMouseReleaseEvent((QMouseEvent*) e);
409 case QEvent::MouseMove:
410 vpMouseMoveEvent((QMouseEvent*) e);
416 QWheelEvent* aEvent = (QWheelEvent*) e;
417 double aDelta = aEvent->delta();
418 double aScale = (aDelta < 0) ? 100./(-aDelta) : aDelta/100.;
419 myViewPort->getView()->SetZoom(aScale);
429 aRes = QFrame::eventFilter(watched, e);
431 if (watched == myViewPort && !myViewPort->getView().IsNull()) {
432 if (e->type() == QEvent::MouseButtonRelease)
439 void OCCViewer_ViewWidget::onActivated()
441 if(!sender() || !sender()->inherits("QtxAction"))
443 QtxAction* anAction = (QtxAction*)sender();
444 ActionsMap::const_iterator anIt = myButsMap.begin(), last = myButsMap.end();
446 for (; anIt != last && aCurAction == -1; anIt++) {
447 if (anIt.value() != anAction)
449 aCurAction = anIt.key();
452 case RotationId: activateRotation(); return;
453 case FitAllId: viewerFitAll(); break;
454 case FitRectId: activateWindowFit(); break;
455 case ZoomId: activateZoom(); break;
456 case PanId: activatePanning(); break;
457 case GlobalPanId: activateGlPanning(); break;
462 void OCCViewer_ViewWidget::viewerFitAll(const bool theUpdate)
464 myViewPort->fitAll(false, true, theUpdate);
468 void OCCViewer_ViewWidget::onTrihChanged()
470 QtxAction* anAction = myButsMap[TrihId];
471 myShowTrihedron = anAction->isChecked();
472 if (myShowTrihedron) {
473 myAISContext->Display(myTrihedron);
474 myAISContext->Deactivate(myTrihedron);
477 myAISContext->Erase(myTrihedron);
480 Processes transformation "front view"
482 void OCCViewer_ViewWidget::onFrontView()
484 Handle(V3d_View) aView3d = myViewPort->getView();
485 if (!aView3d.IsNull()) aView3d->SetProj (V3d_Xpos);
490 Processes transformation "back view"
492 void OCCViewer_ViewWidget::onBackView()
494 Handle(V3d_View) aView3d = myViewPort->getView();
495 if (!aView3d.IsNull()) aView3d->SetProj (V3d_Xneg);
500 Processes transformation "top view"
502 void OCCViewer_ViewWidget::onTopView()
504 Handle(V3d_View) aView3d = myViewPort->getView();
505 if (!aView3d.IsNull()) aView3d->SetProj (V3d_Zpos);
510 Processes transformation "bottom view"
512 void OCCViewer_ViewWidget::onBottomView()
514 Handle(V3d_View) aView3d = myViewPort->getView();
515 if (!aView3d.IsNull()) aView3d->SetProj (V3d_Zneg);
520 Processes transformation "left view"
522 void OCCViewer_ViewWidget::onLeftView()
524 Handle(V3d_View) aView3d = myViewPort->getView();
525 if (!aView3d.IsNull()) aView3d->SetProj (V3d_Yneg);
530 Processes transformation "right view"
532 void OCCViewer_ViewWidget::onRightView()
534 Handle(V3d_View) aView3d = myViewPort->getView();
535 if (!aView3d.IsNull()) aView3d->SetProj (V3d_Ypos);
540 void OCCViewer_ViewWidget::viewZFitAll()
542 myViewPort->getView()->ZFitAll(Z_FIT_ALL_SIZE);
545 void OCCViewer_ViewWidget::activateZoom()
547 if (!transformRequested() && !myCursorIsHand)
548 myCursor = cursor(); /* save old cursor */
550 if (myOperation != ZOOMVIEW) {
551 QPixmap zoomPixmap (imageZoomCursor);
552 QCursor zoomCursor (zoomPixmap);
553 if(setTransformRequested (ZOOMVIEW))
554 setCursor(zoomCursor);
558 void OCCViewer_ViewWidget::activateWindowFit()
560 if (!transformRequested() && !myCursorIsHand)
561 myCursor = cursor(); /* save old cursor */
563 if (myOperation != WINDOWFIT) {
564 QCursor handCursor (Qt::PointingHandCursor);
565 if(setTransformRequested (WINDOWFIT))
566 setCursor (handCursor);
567 myCursorIsHand = true;
571 void OCCViewer_ViewWidget::activateRotation()
573 if (!transformRequested() && !myCursorIsHand)
574 myCursor = cursor(); // save old cursor
576 if (myOperation != ROTATE) {
577 QPixmap rotatePixmap (imageRotateCursor);
578 QCursor rotCursor (rotatePixmap);
579 if(setTransformRequested (ROTATE))
580 setCursor(rotCursor);
584 void OCCViewer_ViewWidget::activatePanning()
586 if (!transformRequested() && !myCursorIsHand)
587 myCursor = cursor(); // save old cursor
589 if (myOperation != PANVIEW) {
590 QCursor panCursor (Qt::SizeAllCursor);
591 if(setTransformRequested (PANVIEW))
592 setCursor(panCursor);
596 void OCCViewer_ViewWidget::activateGlPanning()
598 Handle(V3d_View) aView3d = myViewPort->getView();
599 if (!aView3d.IsNull()) {
600 QPixmap globalPanPixmap (imageCrossCursor);
601 QCursor glPanCursor (globalPanPixmap);
602 myCurScale = aView3d->Scale();
603 aView3d->FitAll(0.01, false);
604 myCursor = cursor(); // save old cursor
605 myViewPort->fitAll(); // fits view before selecting a new scene center
606 if(setTransformRequested(PANGLOBAL))
607 setCursor(glPanCursor);
611 void OCCViewer_ViewWidget::vpMousePressEvent(QMouseEvent* theEvent)
613 myStartX = theEvent->x();
614 myStartY = theEvent->y();
615 switch (myOperation) {
622 if (theEvent->button() == Qt::LeftButton) {
623 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
627 /* Try to activate a transformation */
628 switch (getButtonState(theEvent)) {
637 //myViewPort->startRotation(myStartX, myStartY);//, 0, mySelectedPoint);
644 OCCViewer_ViewWidget::OperationType OCCViewer_ViewWidget::getButtonState(QMouseEvent* theEvent)
646 OperationType aOp = NOTHING;
647 if((theEvent->modifiers() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::ZOOM]) &&
648 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::ZOOM]))
650 else if((theEvent->modifiers() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::PAN]) &&
651 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::PAN]))
653 else if((theEvent->modifiers() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::ROTATE]) &&
654 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::ROTATE]))
660 void OCCViewer_ViewWidget::vpMouseReleaseEvent(QMouseEvent* theEvent)
662 switch (myOperation) {
666 myViewPort->endRotation();
675 if (theEvent->button() == Qt::LeftButton) {
676 myViewPort->setCenter(theEvent->x(), theEvent->y());
677 myViewPort->getView()->SetScale(myCurScale);
683 if (theEvent->modifiers() == Qt::LeftButton) {
684 myCurrX = theEvent->x();
685 myCurrY = theEvent->y();
686 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
687 if (!rect.isEmpty()) myViewPort->fitRect(rect);
693 // NOTE: viewer 3D detects a rectangle of selection using this event
694 // so we must emit it BEFORE resetting the selection rectangle
696 if (theEvent->button() == Qt::LeftButton && myDrawRect) {
700 myViewPort->update();
704 void OCCViewer_ViewWidget::vpMouseMoveEvent(QMouseEvent* theEvent)
706 myCurrX = theEvent->x();
707 myCurrY = theEvent->y();
708 switch (myOperation) {
710 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
713 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
719 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
728 int aState = theEvent->modifiers();
729 if (aState == Qt::LeftButton ||
730 aState == ((int) Qt::LeftButton | (int) Qt::ShiftModifier)) {
734 if (!myCursorIsHand) { // we are going to sketch a rectangle
735 QCursor handCursor (Qt::PointingHandCursor);
736 myCursorIsHand = true;
738 setCursor(handCursor);
747 Sets the viewport to its initial state
748 (no transformations in process etc.)
750 void OCCViewer_ViewWidget::resetState()
756 /* make rectangle empty (left > right) */
757 if (transformRequested() || myCursorIsHand)
759 myCursorIsHand = false;
761 setTransformRequested(NOTHING);
764 void OCCViewer_ViewWidget::drawRect()
766 QPainter aPainter(myViewPort);
767 aPainter.setCompositionMode(QPainter::CompositionMode_Xor);
768 aPainter.setPen(Qt::white);
769 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
770 if (!myRect.isEmpty())
771 aPainter.drawRect(myRect);
772 aPainter.drawRect(aRect);
776 bool OCCViewer_ViewWidget::setTransformRequested (OperationType op)
779 myViewPort->setMouseTracking(myOperation == NOTHING);
783 void OCCViewer_ViewWidget::clearViewer(const bool theUpdate)
785 // check if trihedron is displayed
786 Standard_Boolean isTrihedronDisplayed = myAISContext->IsDisplayed(myTrihedron);
788 // get objects to be erased (all currently displayed objects)
789 AIS_ListOfInteractive aList;
790 myAISContext->DisplayedObjects(aList);
791 AIS_ListIteratorOfListOfInteractive anIter(aList);
792 for (; anIter.More(); anIter.Next()) {
793 if (isTrihedronDisplayed && anIter.Value()->DynamicType() == STANDARD_TYPE(AIS_Trihedron))
796 Handle(AIS_InteractiveObject) anIO = anIter.Value();
797 #if OCC_VERSION_LARGE <= 0x06060000
798 myAISContext->Erase(anIO, false, false);
800 myAISContext->Erase(anIO, false);
804 // display trihedron if necessary
805 if (isTrihedronDisplayed)
806 myAISContext->Display(myTrihedron, theUpdate);
808 myV3dViewer->Update();
810 myAISContext->UpdateCurrentViewer();