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, const bool isUseMultiAction)
156 : QFrame(parent), myShowTrihedron(true), myUseMultiAction(isUseMultiAction)
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 if (myUseMultiAction) {
174 myZoomBtns = new QtxMultiAction(aBtnBox);
175 myZoomBtns->setObjectName("zoomBtn");
176 myToolBar->addAction(myZoomBtns);
177 myPanBtns = new QtxMultiAction(aBtnBox);
178 myPanBtns->setObjectName("panBtn");
179 myToolBar->addAction(myPanBtns);
180 myProjBtns = new QtxMultiAction(aBtnBox);
181 myProjBtns->setObjectName("projectionBtn");
182 myToolBar->addAction(myProjBtns);
185 aBtnLay->addStretch(1);
186 anAnalLay->addWidget(aBtnBox, 0, 0, 1, 2);
188 myV3dViewer = OCCViewer_VService::CreateViewer((short*) "Viewer3d", "", "", 1000., V3d_XposYnegZpos, true, true);
189 //myV3dViewer->Init(); // to avoid creation of the useless perspective view (see OCCT issue 0024267)
191 #if OCC_VERSION_LARGE <= 0x06060000 // Porting to OCCT higher 6.6.0 version
192 myV3dCollector = OCCViewer_VService::CreateViewer((short*) "Collector3d", "", "", 1000., V3d_XposYnegZpos, true, true);
193 myV3dCollector->Init();
197 #if OCC_VERSION_LARGE <= 0x06060000
198 myAISContext = new AIS_InteractiveContext( myV3dViewer, myV3dCollector );
200 myAISContext = new AIS_InteractiveContext( myV3dViewer );
202 myAISContext->SelectionColor(Quantity_NOC_WHITE);
203 myAISContext->IsoOnPlane(true);
205 myViewPort = new OCCViewer_ViewPort3d(this, myV3dViewer, V3d_ORTHOGRAPHIC);
206 myViewPort->setBackgroundColor(Qt::black);
207 myViewPort->setMinimumHeight(300);
208 myViewPort->installEventFilter(this);
209 anAnalLay->addWidget(myViewPort, 1, 0, 1, 2);
211 Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(gp::XOY());
212 myTrihedron = new AIS_Trihedron(anAxis);
213 myTrihedron->SetInfiniteState(Standard_True);
215 Quantity_Color Col(193/255., 205/255., 193/255., Quantity_TOC_RGB);
216 myTrihedron->SetArrowColor(Col.Name());
217 myTrihedron->SetSize(100);
218 Handle(AIS_Drawer) drawer = myTrihedron->Attributes();
219 if (drawer->HasDatumAspect()) {
220 Handle(Prs3d_DatumAspect) daspect = drawer->DatumAspect();
221 daspect->FirstAxisAspect()->SetColor(Quantity_Color(1.0, 0.0, 0.0, Quantity_TOC_RGB));
222 daspect->SecondAxisAspect()->SetColor(Quantity_Color(0.0, 1.0, 0.0, Quantity_TOC_RGB));
223 daspect->ThirdAxisAspect()->SetColor(Quantity_Color(0.0, 0.0, 1.0, Quantity_TOC_RGB));
225 myAISContext->Display(myTrihedron);
226 myAISContext->Deactivate(myTrihedron);
228 myTrihedron->SetTransformPersistence(Graphic3d_TMF_TriedronPers, gp_Pnt(-1, -1, 200));
229 myTrihedron->SetSize(100);
232 myButsMap[TrihId]->setChecked(false);
238 OCCViewer_ViewWidget::~OCCViewer_ViewWidget()
242 myAISContext.Nullify();
243 myV3dViewer.Nullify();
244 #if OCC_VERSION_LARGE <= 0x06060000
245 myV3dCollector.Nullify();
249 OCCViewer_ViewPort3d* OCCViewer_ViewWidget::getViewPort()
254 void OCCViewer_ViewWidget::reset()
257 myOperation = NOTHING;
258 myCurrPointType = OCCViewer_ViewWindow::GRAVITY;
261 void OCCViewer_ViewWidget::Display(const TopoDS_Shape shape, const bool theShaded,
262 const QColor& shapeColor)
265 if (shape.IsNull()) {
266 myAISContext->UpdateCurrentViewer();
270 Handle(AIS_InteractiveObject) io = new AIS_Shape(shape);
271 io->UnsetSelectionMode();
272 io->UnsetHilightMode();
274 Quantity_Color aColor(shapeColor.red()/255., shapeColor.green()/255.,
275 shapeColor.blue()/255., Quantity_TOC_RGB);
276 io->SetColor(aColor);
278 myAISContext->Display(io, false);
280 myAISContext->SetDisplayMode(io, AIS_Shaded, false);
281 myAISContext->SetMaterial(io, Graphic3d_NOM_PLASTIC, false);
284 myAISContext->SetDisplayMode(io, AIS_WireFrame, false);
286 myAISContext->UpdateCurrentViewer();
289 void OCCViewer_ViewWidget::createActions()
291 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
295 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_FITALL")),
296 tr("MNU_FITALL"), 0, this);
297 aAction->setStatusTip(tr("DSC_FITALL"));
298 connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
299 myButsMap[ FitAllId ] = aAction;
302 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_FITAREA")),
303 tr("MNU_FITRECT"), 0, this);
304 aAction->setStatusTip(tr("DSC_FITRECT"));
305 connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
306 myButsMap[ FitRectId ] = aAction;
309 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_ZOOM")),
310 tr("MNU_ZOOM_VIEW"), 0, this);
311 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
312 connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
313 myButsMap[ ZoomId ] = aAction;
316 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_PAN")),
317 tr("MNU_PAN_VIEW"), 0, this);
318 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
319 connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
320 myButsMap[ PanId ] = aAction;
323 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_GLOBALPAN")),
324 tr("MNU_GLOBALPAN_VIEW"), 0, this);
325 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
326 connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
327 myButsMap[ GlobalPanId ] = aAction;
330 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_FRONT")),
331 tr("MNU_FRONT_VIEW"), 0, this);
332 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
333 connect(aAction, SIGNAL(activated()), this, SLOT(onFrontView()));
334 myButsMap[ FrontId ] = aAction;
336 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_BACK")),
337 tr("MNU_BACK_VIEW"), 0, this);
338 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
339 connect(aAction, SIGNAL(activated()), this, SLOT(onBackView()));
340 myButsMap[ BackId ] = aAction;
342 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_TOP")),
343 tr("MNU_TOP_VIEW"), 0, this);
344 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
345 connect(aAction, SIGNAL(activated()), this, SLOT(onTopView()));
346 myButsMap[ TopId ] = aAction;
348 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_BOTTOM")),
349 tr("MNU_BOTTOM_VIEW"), 0, this);
350 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
351 connect(aAction, SIGNAL(activated()), this, SLOT(onBottomView()));
352 myButsMap[ BottomId ] = aAction;
354 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_LEFT")),
355 tr("MNU_LEFT_VIEW"), 0, this);
356 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
357 connect(aAction, SIGNAL(activated()), this, SLOT(onLeftView()));
358 myButsMap[ LeftId ] = aAction;
360 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_RIGHT")),
361 tr("MNU_RIGHT_VIEW"), 0, this);
362 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
363 connect(aAction, SIGNAL(activated()), this, SLOT(onRightView()));
364 myButsMap[ RightId ] = aAction;
366 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_ROTATE")),
367 tr("MNU_ROTATE_VIEW"), 0, this);
368 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
369 connect(aAction, SIGNAL(triggered()), this, SLOT(onActivated()));
370 myToolBar->addAction(aAction);
371 myButsMap[ RotationId ] = aAction;
373 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_TRIHEDRON")),
374 tr("MNU_SHOW_TRIHEDRE"), 0, this);
375 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
376 aAction->setCheckable(true);
377 connect(aAction, SIGNAL(triggered()), this, SLOT(onTrihChanged()));
378 myToolBar->addAction(aAction);
379 myButsMap[ TrihId ] = aAction;
381 if (myUseMultiAction) {
382 myZoomBtns->insertAction(myButsMap[ FitAllId ]);
383 myZoomBtns->insertAction(myButsMap[ FitRectId ]);
384 myZoomBtns->insertAction(myButsMap[ ZoomId ]);
386 myPanBtns->insertAction(myButsMap[ PanId ]);
387 myPanBtns->insertAction(myButsMap[ GlobalPanId ]);
389 myProjBtns->insertAction(myButsMap[ FrontId ]);
390 myProjBtns->insertAction(myButsMap[ BackId ]);
391 myProjBtns->insertAction(myButsMap[ TopId ]);
392 myProjBtns->insertAction(myButsMap[ BottomId ]);
393 myProjBtns->insertAction(myButsMap[ LeftId ]);
394 myProjBtns->insertAction(myButsMap[ RightId ]);
397 myToolBar->addAction(myButsMap[ FitAllId ]);
398 myToolBar->addAction(myButsMap[ FitRectId ]);
399 myToolBar->addAction(myButsMap[ ZoomId ]);
401 myToolBar->addAction(myButsMap[ PanId ]);
402 myToolBar->addAction(myButsMap[ GlobalPanId ]);
404 myToolBar->addAction(myButsMap[ FrontId ]);
405 myToolBar->addAction(myButsMap[ BackId ]);
406 myToolBar->addAction(myButsMap[ TopId ]);
407 myToolBar->addAction(myButsMap[ BottomId ]);
408 myToolBar->addAction(myButsMap[ LeftId ]);
409 myToolBar->addAction(myButsMap[ RightId ]);
416 bool OCCViewer_ViewWidget::eventFilter(QObject* watched, QEvent* e)
418 if (e->type() == QEvent::ContextMenu)
423 if (watched == myViewPort) {
424 int aType = e->type();
426 case QEvent::MouseButtonPress:
427 vpMousePressEvent((QMouseEvent*) e);
431 case QEvent::MouseButtonRelease:
432 vpMouseReleaseEvent((QMouseEvent*) e);
436 case QEvent::MouseMove:
437 vpMouseMoveEvent((QMouseEvent*) e);
443 QWheelEvent* aEvent = (QWheelEvent*) e;
444 double aDelta = aEvent->delta();
445 double aScale = (aDelta < 0) ? 100./(-aDelta) : aDelta/100.;
446 myViewPort->getView()->SetZoom(aScale);
456 aRes = QFrame::eventFilter(watched, e);
458 if (watched == myViewPort && !myViewPort->getView().IsNull()) {
459 if (e->type() == QEvent::MouseButtonRelease)
466 void OCCViewer_ViewWidget::set2dMode(OCCViewer_ViewWidget::Mode2dType theType)
471 QAction* OCCViewer_ViewWidget::action( const ButtonsType& theId )
473 return myButsMap.contains( theId ) ? myButsMap[theId] : 0;
476 void OCCViewer_ViewWidget::onActivated()
478 if(!sender() || !sender()->inherits("QtxAction"))
480 QtxAction* anAction = (QtxAction*)sender();
481 ActionsMap::const_iterator anIt = myButsMap.begin(), last = myButsMap.end();
483 for (; anIt != last && aCurAction == -1; anIt++) {
484 if (anIt.value() != anAction)
486 aCurAction = anIt.key();
489 case RotationId: activateRotation(); return;
490 case FitAllId: viewerFitAll(); break;
491 case FitRectId: activateWindowFit(); break;
492 case ZoomId: activateZoom(); break;
493 case PanId: activatePanning(); break;
494 case GlobalPanId: activateGlPanning(); break;
499 void OCCViewer_ViewWidget::viewerFitAll(const bool theUpdate)
501 myViewPort->fitAll(false, true, theUpdate);
505 void OCCViewer_ViewWidget::onTrihChanged()
507 QtxAction* anAction = myButsMap[TrihId];
508 myShowTrihedron = anAction->isChecked();
509 if (myShowTrihedron) {
510 myAISContext->Display(myTrihedron);
511 myAISContext->Deactivate(myTrihedron);
514 myAISContext->Erase(myTrihedron);
517 Processes transformation "front view"
519 void OCCViewer_ViewWidget::onFrontView()
521 Handle(V3d_View) aView3d = myViewPort->getView();
522 if (!aView3d.IsNull()) aView3d->SetProj (V3d_Xpos);
527 Processes transformation "back view"
529 void OCCViewer_ViewWidget::onBackView()
531 Handle(V3d_View) aView3d = myViewPort->getView();
532 if (!aView3d.IsNull()) aView3d->SetProj (V3d_Xneg);
537 Processes transformation "top view"
539 void OCCViewer_ViewWidget::onTopView()
541 Handle(V3d_View) aView3d = myViewPort->getView();
542 if (!aView3d.IsNull()) aView3d->SetProj (V3d_Zpos);
547 Processes transformation "bottom view"
549 void OCCViewer_ViewWidget::onBottomView()
551 Handle(V3d_View) aView3d = myViewPort->getView();
552 if (!aView3d.IsNull()) aView3d->SetProj (V3d_Zneg);
557 Processes transformation "left view"
559 void OCCViewer_ViewWidget::onLeftView()
561 Handle(V3d_View) aView3d = myViewPort->getView();
562 if (!aView3d.IsNull()) aView3d->SetProj (V3d_Yneg);
567 Processes transformation "right view"
569 void OCCViewer_ViewWidget::onRightView()
571 Handle(V3d_View) aView3d = myViewPort->getView();
572 if (!aView3d.IsNull()) aView3d->SetProj (V3d_Ypos);
577 void OCCViewer_ViewWidget::viewZFitAll()
579 myViewPort->getView()->ZFitAll(Z_FIT_ALL_SIZE);
582 void OCCViewer_ViewWidget::activateZoom()
584 if (!transformRequested() && !myCursorIsHand)
585 myCursor = cursor(); /* save old cursor */
587 if (myOperation != ZOOMVIEW) {
588 QPixmap zoomPixmap (imageZoomCursor);
589 QCursor zoomCursor (zoomPixmap);
590 if(setTransformRequested (ZOOMVIEW))
591 setCursor(zoomCursor);
595 void OCCViewer_ViewWidget::activateWindowFit()
597 if (!transformRequested() && !myCursorIsHand)
598 myCursor = cursor(); /* save old cursor */
600 if (myOperation != WINDOWFIT) {
601 QCursor handCursor (Qt::PointingHandCursor);
602 if(setTransformRequested (WINDOWFIT))
603 setCursor (handCursor);
604 myCursorIsHand = true;
608 void OCCViewer_ViewWidget::activateRotation()
610 if (!transformRequested() && !myCursorIsHand)
611 myCursor = cursor(); // save old cursor
613 if (myOperation != ROTATE) {
614 QPixmap rotatePixmap (imageRotateCursor);
615 QCursor rotCursor (rotatePixmap);
616 if(setTransformRequested (ROTATE))
617 setCursor(rotCursor);
621 void OCCViewer_ViewWidget::activatePanning()
623 if (!transformRequested() && !myCursorIsHand)
624 myCursor = cursor(); // save old cursor
626 if (myOperation != PANVIEW) {
627 QCursor panCursor (Qt::SizeAllCursor);
628 if(setTransformRequested (PANVIEW))
629 setCursor(panCursor);
633 void OCCViewer_ViewWidget::activateGlPanning()
635 Handle(V3d_View) aView3d = myViewPort->getView();
636 if (!aView3d.IsNull()) {
637 QPixmap globalPanPixmap (imageCrossCursor);
638 QCursor glPanCursor (globalPanPixmap);
639 myCurScale = aView3d->Scale();
640 aView3d->FitAll(0.01, false);
641 myCursor = cursor(); // save old cursor
642 myViewPort->fitAll(); // fits view before selecting a new scene center
643 if(setTransformRequested(PANGLOBAL))
644 setCursor(glPanCursor);
648 void OCCViewer_ViewWidget::vpMousePressEvent(QMouseEvent* theEvent)
650 myStartX = theEvent->x();
651 myStartY = theEvent->y();
652 switch (myOperation) {
659 if (theEvent->button() == Qt::LeftButton) {
660 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
664 /* Try to activate a transformation */
665 switch (getButtonState(theEvent)) {
674 //myViewPort->startRotation(myStartX, myStartY);//, 0, mySelectedPoint);
677 emit mousePressed(theEvent);
682 OCCViewer_ViewWidget::OperationType OCCViewer_ViewWidget::getButtonState(QMouseEvent* theEvent)
684 OperationType aOp = NOTHING;
685 if((theEvent->modifiers() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::ZOOM]) &&
686 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::ZOOM]))
688 else if((theEvent->modifiers() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::PAN]) &&
689 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::PAN]))
691 else if((theEvent->modifiers() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::ROTATE]) &&
692 (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::ROTATE]) &&
693 (my2dMode == No2dMode))
699 void OCCViewer_ViewWidget::vpMouseReleaseEvent(QMouseEvent* theEvent)
701 switch (myOperation) {
703 emit mouseReleased(theEvent);
706 myViewPort->endRotation();
715 if (theEvent->button() == Qt::LeftButton) {
716 myViewPort->setCenter(theEvent->x(), theEvent->y());
717 myViewPort->getView()->SetScale(myCurScale);
723 if (theEvent->modifiers() == Qt::LeftButton) {
724 myCurrX = theEvent->x();
725 myCurrY = theEvent->y();
726 QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
727 if (!rect.isEmpty()) myViewPort->fitRect(rect);
733 // NOTE: viewer 3D detects a rectangle of selection using this event
734 // so we must emit it BEFORE resetting the selection rectangle
736 if (theEvent->button() == Qt::LeftButton && myDrawRect) {
740 myViewPort->update();
744 void OCCViewer_ViewWidget::vpMouseMoveEvent(QMouseEvent* theEvent)
746 myCurrX = theEvent->x();
747 myCurrY = theEvent->y();
748 switch (myOperation) {
750 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
753 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
759 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
768 int aState = theEvent->modifiers();
769 if (aState == Qt::LeftButton ||
770 aState == ((int) Qt::LeftButton | (int) Qt::ShiftModifier)) {
774 if (!myCursorIsHand) { // we are going to sketch a rectangle
775 QCursor handCursor (Qt::PointingHandCursor);
776 myCursorIsHand = true;
778 setCursor(handCursor);
783 emit mouseMoving( theEvent );
789 Sets the viewport to its initial state
790 (no transformations in process etc.)
792 void OCCViewer_ViewWidget::resetState()
798 /* make rectangle empty (left > right) */
799 if (transformRequested() || myCursorIsHand)
801 myCursorIsHand = false;
803 setTransformRequested(NOTHING);
806 void OCCViewer_ViewWidget::drawRect()
808 QPainter aPainter(myViewPort);
809 aPainter.setCompositionMode(QPainter::CompositionMode_Xor);
810 aPainter.setPen(Qt::white);
811 QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
812 if (!myRect.isEmpty())
813 aPainter.drawRect(myRect);
814 aPainter.drawRect(aRect);
818 bool OCCViewer_ViewWidget::setTransformRequested (OperationType op)
821 myViewPort->setMouseTracking(myOperation == NOTHING);
825 void OCCViewer_ViewWidget::clearViewer(const bool theUpdate)
827 // check if trihedron is displayed
828 Standard_Boolean isTrihedronDisplayed = myAISContext->IsDisplayed(myTrihedron);
830 // get objects to be erased (all currently displayed objects)
831 AIS_ListOfInteractive aList;
832 myAISContext->DisplayedObjects(aList);
833 AIS_ListIteratorOfListOfInteractive anIter(aList);
834 for (; anIter.More(); anIter.Next()) {
835 if (isTrihedronDisplayed && anIter.Value()->DynamicType() == STANDARD_TYPE(AIS_Trihedron))
838 Handle(AIS_InteractiveObject) anIO = anIter.Value();
839 #if OCC_VERSION_LARGE <= 0x06060000
840 myAISContext->Erase(anIO, false, false);
842 myAISContext->Erase(anIO, false);
846 // display trihedron if necessary
847 if (isTrihedronDisplayed)
848 myAISContext->Display(myTrihedron, theUpdate);
850 myV3dViewer->Update();
852 myAISContext->UpdateCurrentViewer();