+++ /dev/null
-
-#include "OCCViewer_ViewWidget.h"
-
-#include <SUIT_Desktop.h>
-#include <SUIT_Session.h>
-#include <SUIT_ResourceMgr.h>
-#include <SUIT_MessageBox.h>
-#include <OCCViewer_ViewPort3d.h>
-#include <OCCViewer_VService.h>
-#include <SUIT_ViewModel.h>
-#include <SUIT_Tools.h>
-
-#include <QtxAction.h>
-
-#include <AIS_InteractiveObject.hxx>
-#include <AIS_ListOfInteractive.hxx>
-#include <V3d_Viewer.hxx>
-#include <AIS_Shape.hxx>
-#include <Prs3d_LineAspect.hxx>
-
-#include <AIS_InteractiveContext.hxx>
-#include <AIS_ListIteratorOfListOfInteractive.hxx>
-#include <Geom_Axis2Placement.hxx>
-#include <AIS_Drawer.hxx>
-#include <Prs3d_DatumAspect.hxx>
-
-#include <QLayout>
-#include <QCursor>
-#include <QHBoxLayout>
-#include <QPushButton>
-#include <QPainter>
-#include <QLabel>
-#include <QWheelEvent>
-#include <QMouseEvent>
-#include <QToolBar>
-
-const int SPACING_SIZE = 5;
-const int Z_FIT_ALL_SIZE = 1000;
-
-const char* imageZoomCursor[] = {
-"32 32 3 1",
-". c None",
-"a c #000000",
-"# c #ffffff",
-"................................",
-"................................",
-".#######........................",
-"..aaaaaaa.......................",
-"................................",
-".............#####..............",
-"...........##.aaaa##............",
-"..........#.aa.....a#...........",
-".........#.a.........#..........",
-".........#a..........#a.........",
-"........#.a...........#.........",
-"........#a............#a........",
-"........#a............#a........",
-"........#a............#a........",
-"........#a............#a........",
-".........#...........#.a........",
-".........#a..........#a.........",
-".........##.........#.a.........",
-"........#####.....##.a..........",
-".......###aaa#####.aa...........",
-"......###aa...aaaaa.......#.....",
-".....###aa................#a....",
-"....###aa.................#a....",
-"...###aa...............#######..",
-"....#aa.................aa#aaaa.",
-".....a....................#a....",
-"..........................#a....",
-"...........................a....",
-"................................",
-"................................",
-"................................",
-"................................"};
-
-const char* imageRotateCursor[] = {
-"32 32 3 1",
-". c None",
-"a c #000000",
-"# c #ffffff",
-"................................",
-"................................",
-"................................",
-"................................",
-"........#.......................",
-".......#.a......................",
-"......#######...................",
-".......#aaaaa#####..............",
-"........#..##.a#aa##........##..",
-".........a#.aa..#..a#.....##.aa.",
-".........#.a.....#...#..##.aa...",
-".........#a.......#..###.aa.....",
-"........#.a.......#a..#aa.......",
-"........#a.........#..#a........",
-"........#a.........#a.#a........",
-"........#a.........#a.#a........",
-"........#a.........#a.#a........",
-".........#.........#a#.a........",
-"........##a........#a#a.........",
-"......##.a#.......#.#.a.........",
-"....##.aa..##.....##.a..........",
-"..##.aa.....a#####.aa...........",
-"...aa.........aaa#a.............",
-"................#.a.............",
-"...............#.a..............",
-"..............#.a...............",
-"...............a................",
-"................................",
-"................................",
-"................................",
-"................................",
-"................................"};
-
-const char* imageCrossCursor[] = {
- "32 32 3 1",
- ". c None",
- "a c #000000",
- "# c #ffffff",
- "................................",
- "................................",
- "................................",
- "................................",
- "................................",
- "................................",
- "................................",
- "...............#................",
- "...............#a...............",
- "...............#a...............",
- "...............#a...............",
- "...............#a...............",
- "...............#a...............",
- "...............#a...............",
- "...............#a...............",
- ".......#################........",
- "........aaaaaaa#aaaaaaaaa.......",
- "...............#a...............",
- "...............#a...............",
- "...............#a...............",
- "...............#a...............",
- "...............#a...............",
- "...............#a...............",
- "...............#a...............",
- "................a...............",
- "................................",
- "................................",
- "................................",
- "................................",
- "................................",
- "................................",
- "................................"};
-
-// ---------------- OCC view widget --------
-OCCViewer_ViewWidget::OCCViewer_ViewWidget(QWidget* parent, const bool isUseMultiAction)
- : QFrame(parent), myShowTrihedron(true), myUseMultiAction(isUseMultiAction)
-{
- setObjectName("OCC_view_widget");
- mySelectedPoint = gp_Pnt(0.,0.,0.);
- setFrameStyle(QFrame::NoFrame);
-
- QGridLayout* anAnalLay = new QGridLayout(this);
- anAnalLay->setMargin(0);
- anAnalLay->setSpacing(SPACING_SIZE);
-
- QWidget* aBtnBox = new QWidget(this);
- QHBoxLayout* aBtnLay = new QHBoxLayout(aBtnBox);
- aBtnLay->setMargin(0);
- aBtnLay->setSpacing(SPACING_SIZE);
-
- myToolBar = new QToolBar(aBtnBox);
- aBtnLay->addWidget(myToolBar);
- if (myUseMultiAction) {
- myZoomBtns = new QtxMultiAction(aBtnBox);
- myZoomBtns->setObjectName("zoomBtn");
- myToolBar->addAction(myZoomBtns);
- myPanBtns = new QtxMultiAction(aBtnBox);
- myPanBtns->setObjectName("panBtn");
- myToolBar->addAction(myPanBtns);
- myProjBtns = new QtxMultiAction(aBtnBox);
- myProjBtns->setObjectName("projectionBtn");
- myToolBar->addAction(myProjBtns);
- }
- // Rotation
- aBtnLay->addStretch(1);
- anAnalLay->addWidget(aBtnBox, 0, 0, 1, 2);
-
- myV3dViewer = OCCViewer_VService::CreateViewer((short*) "Viewer3d", "", "", 1000., V3d_XposYnegZpos, true, true);
- //myV3dViewer->Init(); // to avoid creation of the useless perspective view (see OCCT issue 0024267)
-
-#if OCC_VERSION_LARGE <= 0x06060000 // Porting to OCCT higher 6.6.0 version
- myV3dCollector = OCCViewer_VService::CreateViewer((short*) "Collector3d", "", "", 1000., V3d_XposYnegZpos, true, true);
- myV3dCollector->Init();
-#endif
-
- // init selector
-#if OCC_VERSION_LARGE <= 0x06060000
- myAISContext = new AIS_InteractiveContext( myV3dViewer, myV3dCollector );
-#else
- myAISContext = new AIS_InteractiveContext( myV3dViewer );
-#endif
- myAISContext->SelectionColor(Quantity_NOC_WHITE);
- myAISContext->IsoOnPlane(true);
-
- myViewPort = new OCCViewer_ViewPort3d(this, myV3dViewer, V3d_ORTHOGRAPHIC);
- myViewPort->setBackgroundColor(Qt::black);
- myViewPort->setMinimumHeight(300);
- myViewPort->installEventFilter(this);
- anAnalLay->addWidget(myViewPort, 1, 0, 1, 2);
-
- Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(gp::XOY());
- myTrihedron = new AIS_Trihedron(anAxis);
- myTrihedron->SetInfiniteState(Standard_True);
-
- Quantity_Color Col(193/255., 205/255., 193/255., Quantity_TOC_RGB);
- myTrihedron->SetArrowColor(Col.Name());
- myTrihedron->SetSize(100);
- Handle(AIS_Drawer) drawer = myTrihedron->Attributes();
- if (drawer->HasDatumAspect()) {
- Handle(Prs3d_DatumAspect) daspect = drawer->DatumAspect();
- daspect->FirstAxisAspect()->SetColor(Quantity_Color(1.0, 0.0, 0.0, Quantity_TOC_RGB));
- daspect->SecondAxisAspect()->SetColor(Quantity_Color(0.0, 1.0, 0.0, Quantity_TOC_RGB));
- daspect->ThirdAxisAspect()->SetColor(Quantity_Color(0.0, 0.0, 1.0, Quantity_TOC_RGB));
- }
- myAISContext->Display(myTrihedron);
- myAISContext->Deactivate(myTrihedron);
-
- myTrihedron->SetTransformPersistence(Graphic3d_TMF_TriedronPers, gp_Pnt(-1, -1, 200));
- myTrihedron->SetSize(100);
-
- createActions();
- myButsMap[TrihId]->setChecked(false);
- onTrihChanged();
-
- my2dMode = No2dMode;
-}
-
-OCCViewer_ViewWidget::~OCCViewer_ViewWidget()
-{
- delete myViewPort;
-
- myAISContext.Nullify();
- myV3dViewer.Nullify();
- #if OCC_VERSION_LARGE <= 0x06060000
- myV3dCollector.Nullify();
- #endif
-}
-
-OCCViewer_ViewPort3d* OCCViewer_ViewWidget::getViewPort()
-{
- return myViewPort;
-}
-
-void OCCViewer_ViewWidget::reset()
-{
- clearViewer();
- myOperation = NOTHING;
- myCurrPointType = OCCViewer_ViewWindow::GRAVITY;
-}
-
-void OCCViewer_ViewWidget::Display(const TopoDS_Shape shape, const bool theShaded,
- const QColor& shapeColor)
-{
- clearViewer(false);
- if (shape.IsNull()) {
- myAISContext->UpdateCurrentViewer();
- return;
- }
-
- Handle(AIS_InteractiveObject) io = new AIS_Shape(shape);
- io->UnsetSelectionMode();
- io->UnsetHilightMode();
-
- Quantity_Color aColor(shapeColor.red()/255., shapeColor.green()/255.,
- shapeColor.blue()/255., Quantity_TOC_RGB);
- io->SetColor(aColor);
-
- myAISContext->Display(io, false);
- if (theShaded) {
- myAISContext->SetDisplayMode(io, AIS_Shaded, false);
- myAISContext->SetMaterial(io, Graphic3d_NOM_PLASTIC, false);
- }
- else
- myAISContext->SetDisplayMode(io, AIS_WireFrame, false);
- viewerFitAll(false);
- myAISContext->UpdateCurrentViewer();
-}
-
-void OCCViewer_ViewWidget::createActions()
-{
- SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
- QtxAction* aAction;
-
- // FitAll
- aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_FITALL")),
- tr("MNU_FITALL"), 0, this);
- aAction->setStatusTip(tr("DSC_FITALL"));
- connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
- myButsMap[ FitAllId ] = aAction;
-
- // FitRect
- aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_FITAREA")),
- tr("MNU_FITRECT"), 0, this);
- aAction->setStatusTip(tr("DSC_FITRECT"));
- connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
- myButsMap[ FitRectId ] = aAction;
-
- // Zoom
- aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_ZOOM")),
- tr("MNU_ZOOM_VIEW"), 0, this);
- aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
- connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
- myButsMap[ ZoomId ] = aAction;
-
- // Panning
- aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_PAN")),
- tr("MNU_PAN_VIEW"), 0, this);
- aAction->setStatusTip(tr("DSC_PAN_VIEW"));
- connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
- myButsMap[ PanId ] = aAction;
-
- // Global Panning
- aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_GLOBALPAN")),
- tr("MNU_GLOBALPAN_VIEW"), 0, this);
- aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
- connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
- myButsMap[ GlobalPanId ] = aAction;
-
- // Projections
- aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_FRONT")),
- tr("MNU_FRONT_VIEW"), 0, this);
- aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
- connect(aAction, SIGNAL(activated()), this, SLOT(onFrontView()));
- myButsMap[ FrontId ] = aAction;
-
- aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_BACK")),
- tr("MNU_BACK_VIEW"), 0, this);
- aAction->setStatusTip(tr("DSC_BACK_VIEW"));
- connect(aAction, SIGNAL(activated()), this, SLOT(onBackView()));
- myButsMap[ BackId ] = aAction;
-
- aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_TOP")),
- tr("MNU_TOP_VIEW"), 0, this);
- aAction->setStatusTip(tr("DSC_TOP_VIEW"));
- connect(aAction, SIGNAL(activated()), this, SLOT(onTopView()));
- myButsMap[ TopId ] = aAction;
-
- aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_BOTTOM")),
- tr("MNU_BOTTOM_VIEW"), 0, this);
- aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
- connect(aAction, SIGNAL(activated()), this, SLOT(onBottomView()));
- myButsMap[ BottomId ] = aAction;
-
- aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_LEFT")),
- tr("MNU_LEFT_VIEW"), 0, this);
- aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
- connect(aAction, SIGNAL(activated()), this, SLOT(onLeftView()));
- myButsMap[ LeftId ] = aAction;
-
- aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_RIGHT")),
- tr("MNU_RIGHT_VIEW"), 0, this);
- aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
- connect(aAction, SIGNAL(activated()), this, SLOT(onRightView()));
- myButsMap[ RightId ] = aAction;
-
- aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_ROTATE")),
- tr("MNU_ROTATE_VIEW"), 0, this);
- aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
- connect(aAction, SIGNAL(triggered()), this, SLOT(onActivated()));
- myToolBar->addAction(aAction);
- myButsMap[ RotationId ] = aAction;
-
- aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_TRIHEDRON")),
- tr("MNU_SHOW_TRIHEDRE"), 0, this);
- aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
- aAction->setCheckable(true);
- connect(aAction, SIGNAL(triggered()), this, SLOT(onTrihChanged()));
- myToolBar->addAction(aAction);
- myButsMap[ TrihId ] = aAction;
-
- if (myUseMultiAction) {
- myZoomBtns->insertAction(myButsMap[ FitAllId ]);
- myZoomBtns->insertAction(myButsMap[ FitRectId ]);
- myZoomBtns->insertAction(myButsMap[ ZoomId ]);
-
- myPanBtns->insertAction(myButsMap[ PanId ]);
- myPanBtns->insertAction(myButsMap[ GlobalPanId ]);
-
- myProjBtns->insertAction(myButsMap[ FrontId ]);
- myProjBtns->insertAction(myButsMap[ BackId ]);
- myProjBtns->insertAction(myButsMap[ TopId ]);
- myProjBtns->insertAction(myButsMap[ BottomId ]);
- myProjBtns->insertAction(myButsMap[ LeftId ]);
- myProjBtns->insertAction(myButsMap[ RightId ]);
- }
- else {
- myToolBar->addAction(myButsMap[ FitAllId ]);
- myToolBar->addAction(myButsMap[ FitRectId ]);
- myToolBar->addAction(myButsMap[ ZoomId ]);
-
- myToolBar->addAction(myButsMap[ PanId ]);
- myToolBar->addAction(myButsMap[ GlobalPanId ]);
-
- myToolBar->addAction(myButsMap[ FrontId ]);
- myToolBar->addAction(myButsMap[ BackId ]);
- myToolBar->addAction(myButsMap[ TopId ]);
- myToolBar->addAction(myButsMap[ BottomId ]);
- myToolBar->addAction(myButsMap[ LeftId ]);
- myToolBar->addAction(myButsMap[ RightId ]);
- }
-}
-
-/*!
- Custom event handler
-*/
-bool OCCViewer_ViewWidget::eventFilter(QObject* watched, QEvent* e)
-{
- if (e->type() == QEvent::ContextMenu)
- return true;
-
- bool aRes = false;
- int aReturn = -1;
- if (watched == myViewPort) {
- int aType = e->type();
- switch(aType) {
- case QEvent::MouseButtonPress:
- vpMousePressEvent((QMouseEvent*) e);
- aRes = true;
- aReturn = 1;
- break;
- case QEvent::MouseButtonRelease:
- vpMouseReleaseEvent((QMouseEvent*) e);
- aRes = true;
- aReturn = 1;
- break;
- case QEvent::MouseMove:
- vpMouseMoveEvent((QMouseEvent*) e);
- aRes = true;
- aReturn = 1;
- break;
- case QEvent::Wheel:
- {
- QWheelEvent* aEvent = (QWheelEvent*) e;
- double aDelta = aEvent->delta();
- double aScale = (aDelta < 0) ? 100./(-aDelta) : aDelta/100.;
- myViewPort->getView()->SetZoom(aScale);
- }
- aRes = true;
- aReturn = 1;
- break;
- default:
- break;
- }
- }
- if (aReturn == -1)
- aRes = QFrame::eventFilter(watched, e);
-
- if (watched == myViewPort && !myViewPort->getView().IsNull()) {
- if (e->type() == QEvent::MouseButtonRelease)
- viewZFitAll();
- }
-
- return aRes;
-}
-
-void OCCViewer_ViewWidget::set2dMode(OCCViewer_ViewWidget::Mode2dType theType)
-{
- my2dMode = theType;
-}
-
-QAction* OCCViewer_ViewWidget::action( const ButtonsType& theId )
-{
- return myButsMap.contains( theId ) ? myButsMap[theId] : 0;
-}
-
-void OCCViewer_ViewWidget::onActivated()
-{
- if(!sender() || !sender()->inherits("QtxAction"))
- return;
- QtxAction* anAction = (QtxAction*)sender();
- ActionsMap::const_iterator anIt = myButsMap.begin(), last = myButsMap.end();
- int aCurAction = -1;
- for (; anIt != last && aCurAction == -1; anIt++) {
- if (anIt.value() != anAction)
- continue;
- aCurAction = anIt.key();
- }
- switch(aCurAction) {
- case RotationId: activateRotation(); return;
- case FitAllId: viewerFitAll(); break;
- case FitRectId: activateWindowFit(); break;
- case ZoomId: activateZoom(); break;
- case PanId: activatePanning(); break;
- case GlobalPanId: activateGlPanning(); break;
- }
- viewZFitAll();
-}
-
-void OCCViewer_ViewWidget::viewerFitAll(const bool theUpdate)
-{
- myViewPort->fitAll(false, true, theUpdate);
- viewZFitAll();
-}
-
-void OCCViewer_ViewWidget::onTrihChanged()
-{
- QtxAction* anAction = myButsMap[TrihId];
- myShowTrihedron = anAction->isChecked();
- if (myShowTrihedron) {
- myAISContext->Display(myTrihedron);
- myAISContext->Deactivate(myTrihedron);
- }
- else
- myAISContext->Erase(myTrihedron);
-}
-/*!
- Processes transformation "front view"
-*/
-void OCCViewer_ViewWidget::onFrontView()
-{
- Handle(V3d_View) aView3d = myViewPort->getView();
- if (!aView3d.IsNull()) aView3d->SetProj (V3d_Xpos);
- viewerFitAll();
-}
-
-/*!
- Processes transformation "back view"
-*/
-void OCCViewer_ViewWidget::onBackView()
-{
- Handle(V3d_View) aView3d = myViewPort->getView();
- if (!aView3d.IsNull()) aView3d->SetProj (V3d_Xneg);
- viewerFitAll();
-}
-
-/*!
- Processes transformation "top view"
-*/
-void OCCViewer_ViewWidget::onTopView()
-{
- Handle(V3d_View) aView3d = myViewPort->getView();
- if (!aView3d.IsNull()) aView3d->SetProj (V3d_Zpos);
- viewerFitAll();
-}
-
-/*!
- Processes transformation "bottom view"
-*/
-void OCCViewer_ViewWidget::onBottomView()
-{
- Handle(V3d_View) aView3d = myViewPort->getView();
- if (!aView3d.IsNull()) aView3d->SetProj (V3d_Zneg);
- viewerFitAll();
-}
-
-/*!
- Processes transformation "left view"
-*/
-void OCCViewer_ViewWidget::onLeftView()
-{
- Handle(V3d_View) aView3d = myViewPort->getView();
- if (!aView3d.IsNull()) aView3d->SetProj (V3d_Yneg);
- viewerFitAll();
-}
-
-/*!
- Processes transformation "right view"
-*/
-void OCCViewer_ViewWidget::onRightView()
-{
- Handle(V3d_View) aView3d = myViewPort->getView();
- if (!aView3d.IsNull()) aView3d->SetProj (V3d_Ypos);
- viewerFitAll();
-}
-
-
-void OCCViewer_ViewWidget::viewZFitAll()
-{
- myViewPort->getView()->ZFitAll(Z_FIT_ALL_SIZE);
-}
-
-void OCCViewer_ViewWidget::activateZoom()
-{
- if (!transformRequested() && !myCursorIsHand)
- myCursor = cursor(); /* save old cursor */
-
- if (myOperation != ZOOMVIEW) {
- QPixmap zoomPixmap (imageZoomCursor);
- QCursor zoomCursor (zoomPixmap);
- if(setTransformRequested (ZOOMVIEW))
- setCursor(zoomCursor);
- }
-}
-
-void OCCViewer_ViewWidget::activateWindowFit()
-{
- if (!transformRequested() && !myCursorIsHand)
- myCursor = cursor(); /* save old cursor */
-
- if (myOperation != WINDOWFIT) {
- QCursor handCursor (Qt::PointingHandCursor);
- if(setTransformRequested (WINDOWFIT))
- setCursor (handCursor);
- myCursorIsHand = true;
- }
-}
-
-void OCCViewer_ViewWidget::activateRotation()
-{
- if (!transformRequested() && !myCursorIsHand)
- myCursor = cursor(); // save old cursor
-
- if (myOperation != ROTATE) {
- QPixmap rotatePixmap (imageRotateCursor);
- QCursor rotCursor (rotatePixmap);
- if(setTransformRequested (ROTATE))
- setCursor(rotCursor);
- }
-}
-
-void OCCViewer_ViewWidget::activatePanning()
-{
- if (!transformRequested() && !myCursorIsHand)
- myCursor = cursor(); // save old cursor
-
- if (myOperation != PANVIEW) {
- QCursor panCursor (Qt::SizeAllCursor);
- if(setTransformRequested (PANVIEW))
- setCursor(panCursor);
- }
-}
-
-void OCCViewer_ViewWidget::activateGlPanning()
-{
- Handle(V3d_View) aView3d = myViewPort->getView();
- if (!aView3d.IsNull()) {
- QPixmap globalPanPixmap (imageCrossCursor);
- QCursor glPanCursor (globalPanPixmap);
- myCurScale = aView3d->Scale();
- aView3d->FitAll(0.01, false);
- myCursor = cursor(); // save old cursor
- myViewPort->fitAll(); // fits view before selecting a new scene center
- if(setTransformRequested(PANGLOBAL))
- setCursor(glPanCursor);
- }
-}
-
-void OCCViewer_ViewWidget::vpMousePressEvent(QMouseEvent* theEvent)
-{
- myStartX = theEvent->x();
- myStartY = theEvent->y();
- switch (myOperation) {
- case WINDOWFIT:
- case PANGLOBAL:
- case ZOOMVIEW:
- case PANVIEW:
- break;
- case ROTATE:
- if (theEvent->button() == Qt::LeftButton) {
- myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
- }
- break;
- default:
- /* Try to activate a transformation */
- switch (getButtonState(theEvent)) {
- case ZOOMVIEW:
- activateZoom();
- break;
- case PANVIEW:
- activatePanning();
- break;
- case ROTATE:
- activateRotation();
- //myViewPort->startRotation(myStartX, myStartY);//, 0, mySelectedPoint);
- break;
- default:
- emit mousePressed(theEvent);
- break;
- }
- }
-}
-OCCViewer_ViewWidget::OperationType OCCViewer_ViewWidget::getButtonState(QMouseEvent* theEvent)
-{
- OperationType aOp = NOTHING;
- if((theEvent->modifiers() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::ZOOM]) &&
- (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::ZOOM]))
- aOp = ZOOMVIEW;
- else if((theEvent->modifiers() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::PAN]) &&
- (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::PAN]))
- aOp = PANVIEW;
- else if((theEvent->modifiers() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::ROTATE]) &&
- (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::ROTATE]) &&
- (my2dMode == No2dMode))
- aOp = ROTATE;
-
- return aOp;
-}
-
-void OCCViewer_ViewWidget::vpMouseReleaseEvent(QMouseEvent* theEvent)
-{
- switch (myOperation) {
- case NOTHING:
- emit mouseReleased(theEvent);
- break;
- case ROTATE:
- myViewPort->endRotation();
- resetState();
- break;
- case PANVIEW:
- case ZOOMVIEW:
- resetState();
- break;
-
- case PANGLOBAL:
- if (theEvent->button() == Qt::LeftButton) {
- myViewPort->setCenter(theEvent->x(), theEvent->y());
- myViewPort->getView()->SetScale(myCurScale);
- resetState();
- }
- break;
-
- case WINDOWFIT:
- if (theEvent->modifiers() == Qt::LeftButton) {
- myCurrX = theEvent->x();
- myCurrY = theEvent->y();
- QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
- if (!rect.isEmpty()) myViewPort->fitRect(rect);
- resetState();
- }
- break;
- }
-
- // NOTE: viewer 3D detects a rectangle of selection using this event
- // so we must emit it BEFORE resetting the selection rectangle
-
- if (theEvent->button() == Qt::LeftButton && myDrawRect) {
- myDrawRect = false;
- drawRect();
- resetState();
- myViewPort->update();
- }
-}
-
-void OCCViewer_ViewWidget::vpMouseMoveEvent(QMouseEvent* theEvent)
-{
- myCurrX = theEvent->x();
- myCurrY = theEvent->y();
- switch (myOperation) {
- case ROTATE:
- myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
- break;
- case ZOOMVIEW:
- myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
- myStartX = myCurrX;
- myStartY = myCurrY;
- break;
-
- case PANVIEW:
- myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
- myStartX = myCurrX;
- myStartY = myCurrY;
- break;
-
- case PANGLOBAL:
- break;
-
- default: {
- int aState = theEvent->modifiers();
- if (aState == Qt::LeftButton ||
- aState == ((int) Qt::LeftButton | (int) Qt::ShiftModifier)) {
- myDrawRect = true;
- if (myDrawRect) {
- drawRect();
- if (!myCursorIsHand) { // we are going to sketch a rectangle
- QCursor handCursor (Qt::PointingHandCursor);
- myCursorIsHand = true;
- myCursor = cursor();
- setCursor(handCursor);
- }
- }
- }
- else
- emit mouseMoving( theEvent );
- }
- }
-}
-
-/*!
- Sets the viewport to its initial state
- (no transformations in process etc.)
-*/
-void OCCViewer_ViewWidget::resetState()
-{
- myDrawRect = false;
- myRect.setLeft(2);
- myRect.setRight(0);
-
- /* make rectangle empty (left > right) */
- if (transformRequested() || myCursorIsHand)
- setCursor(myCursor);
- myCursorIsHand = false;
-
- setTransformRequested(NOTHING);
-}
-
-void OCCViewer_ViewWidget::drawRect()
-{
- QPainter aPainter(myViewPort);
- aPainter.setCompositionMode(QPainter::CompositionMode_Xor);
- aPainter.setPen(Qt::white);
- QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
- if (!myRect.isEmpty())
- aPainter.drawRect(myRect);
- aPainter.drawRect(aRect);
- myRect = aRect;
-}
-
-bool OCCViewer_ViewWidget::setTransformRequested (OperationType op)
-{
- myOperation = op;
- myViewPort->setMouseTracking(myOperation == NOTHING);
- return true;
-}
-
-void OCCViewer_ViewWidget::clearViewer(const bool theUpdate)
-{
- // check if trihedron is displayed
- Standard_Boolean isTrihedronDisplayed = myAISContext->IsDisplayed(myTrihedron);
-
- // get objects to be erased (all currently displayed objects)
- AIS_ListOfInteractive aList;
- myAISContext->DisplayedObjects(aList);
- AIS_ListIteratorOfListOfInteractive anIter(aList);
- for (; anIter.More(); anIter.Next()) {
- if (isTrihedronDisplayed && anIter.Value()->DynamicType() == STANDARD_TYPE(AIS_Trihedron))
- continue;
- // erase an object
- Handle(AIS_InteractiveObject) anIO = anIter.Value();
-#if OCC_VERSION_LARGE <= 0x06060000
- myAISContext->Erase(anIO, false, false);
-#else
- myAISContext->Erase(anIO, false);
-#endif
- }
-
- // display trihedron if necessary
- if (isTrihedronDisplayed)
- myAISContext->Display(myTrihedron, theUpdate);
- else if (theUpdate)
- myV3dViewer->Update();
- if (theUpdate)
- myAISContext->UpdateCurrentViewer();
-}