From: vsv Date: Tue, 29 Apr 2014 09:04:34 +0000 (+0400) Subject: Define selection in Viewer 3d X-Git-Tag: V_0.2~107^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b79d895f103e77d30d0f1bf2114b3750a746ed94;p=modules%2Fshaper.git Define selection in Viewer 3d --- diff --git a/src/NewGeom/CMakeLists.txt b/src/NewGeom/CMakeLists.txt index 20404f8b1..4d7a3b3e4 100644 --- a/src/NewGeom/CMakeLists.txt +++ b/src/NewGeom/CMakeLists.txt @@ -7,6 +7,7 @@ SET(PROJECT_HEADERS NewGeom.h NewGeom_Module.h NewGeom_DataModel.h + NewGeom_OCCSelector.h ) SET(PROJECT_AUTOMOC @@ -16,6 +17,7 @@ SET(PROJECT_AUTOMOC SET(PROJECT_SOURCES NewGeom_Module.cpp NewGeom_DataModel.cpp + NewGeom_OCCSelector.cpp ) SET(PROJECT_RESOURCES diff --git a/src/XGUI/XGUI_SelectionMgr.cpp b/src/XGUI/XGUI_SelectionMgr.cpp index efca3fde5..0bba0d847 100644 --- a/src/XGUI/XGUI_SelectionMgr.cpp +++ b/src/XGUI/XGUI_SelectionMgr.cpp @@ -49,6 +49,7 @@ void XGUI_SelectionMgr::onObjectBrowserSelection() //************************************************************** void XGUI_SelectionMgr::onViewerSelection() { + // TODO: Highliht selected objects in Object Browser emit selectionChanged(); } diff --git a/src/XGUI/XGUI_Viewer.cpp b/src/XGUI/XGUI_Viewer.cpp index 23560ca86..20436bfbd 100644 --- a/src/XGUI/XGUI_Viewer.cpp +++ b/src/XGUI/XGUI_Viewer.cpp @@ -455,7 +455,6 @@ void XGUI_Viewer::addView(QMdiSubWindow* theView) // connect(aWindow, SIGNAL(contextMenuRequested( QContextMenuEvent* )), // this, SLOT (onContextMenuRequested( QContextMenuEvent* ))); - connect(aWindow, SIGNAL(mouseMoving(XGUI_ViewWindow*, QMouseEvent*)), this, SLOT(onMouseMove(XGUI_ViewWindow*, QMouseEvent*))); @@ -498,17 +497,26 @@ void XGUI_Viewer::onWindowMinimized(QMdiSubWindow* theWnd) } } +/*! + SLOT: called on mouse button press, stores current mouse position as start point for transformations +*/ +void XGUI_Viewer::onMousePressed(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent) +{ + myStartPnt.setX(theEvent->x()); myStartPnt.setY(theEvent->y()); + emit mousePress(theWindow, theEvent); +} + /*! SLOT: called on mouse move, processes hilighting */ void XGUI_Viewer::onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent) { - XGUI_ViewPort* aViewPort = theWindow->viewPort(); - Handle(V3d_View) aView3d = aViewPort->getView(); + if (!mySelectionEnabled) return; + myCurPnt.setX(theEvent->x()); myCurPnt.setY(theEvent->y()); + Handle(V3d_View) aView3d = theWindow->viewPort()->getView(); if ( !aView3d.IsNull() ) { myAISContext->MoveTo(theEvent->x(), theEvent->y(), aView3d); - mouseMoved(theEvent->pos()); } } @@ -517,7 +525,41 @@ void XGUI_Viewer::onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent) */ void XGUI_Viewer::onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent) { - myAISContext->Select(); + if (!mySelectionEnabled) return; + if (theEvent->button() != Qt::LeftButton) return; + + myEndPnt.setX(theEvent->x()); myEndPnt.setY(theEvent->y()); + bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier); + + //if (!aHasShift) + // emit deselection(); + + if (myStartPnt == myEndPnt) { + if (aHasShift && myMultiSelectionEnabled) + myAISContext->ShiftSelect(); + else + myAISContext->Select(); + } else { + if (aHasShift && myMultiSelectionEnabled) + myAISContext->ShiftSelect(myStartPnt.x(), myStartPnt.y(), + myEndPnt.x(), myEndPnt.y(), + theWindow->viewPort()->getView(), false ); + else + myAISContext->Select(myStartPnt.x(), myStartPnt.y(), + myEndPnt.x(), myEndPnt.y(), + theWindow->viewPort()->getView(), false ); + + int Nb = myAISContext->NbSelected(); + if( Nb>1 && !myMultiSelectionEnabled ) { + myAISContext->InitSelected(); + Handle( SelectMgr_EntityOwner ) anOwner = myAISContext->SelectedOwner(); + if( !anOwner.IsNull() ) { + myAISContext->ClearSelected( Standard_False ); + myAISContext->AddOrRemoveSelected( anOwner, Standard_False ); + } + } - emit mouseReleased(theEvent->pos()); + myAISContext->UpdateCurrentViewer(); + } + emit selectionChanged(); } diff --git a/src/XGUI/XGUI_Viewer.h b/src/XGUI/XGUI_Viewer.h index 23d66656a..b422e4034 100644 --- a/src/XGUI/XGUI_Viewer.h +++ b/src/XGUI/XGUI_Viewer.h @@ -74,6 +74,13 @@ public: /// \param theList - list objects to be selected void setObjectsSelected(const AIS_ListOfInteractive& theList); + /// Returns true if selection in the viewer is enabled + bool isSelectionEnabled() const { return mySelectionEnabled; } + + /// Enable or disable selectioon in the viewer + // \param toEnable - true or false (enable or disable selection) + void setSelectionEnabled(bool toEnable) { mySelectionEnabled = toEnable; } + /// Select the object in 3D viewer. /// \param theIO - list objects to be selected void setSelected(const Handle(AIS_InteractiveObject)& theIO) { myAISContext->SetSelected(theIO); } @@ -142,8 +149,8 @@ signals: void keyRelease(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent); void activated(XGUI_ViewWindow* theWindow); void selectionChanged(); - void mouseReleased(QPoint thePoint); - void mouseMoved(QPoint thePoint); + //void mouseReleased(QPoint thePoint); + //void mouseMoved(QPoint thePoint); public slots: void onWindowMinimized(QMdiSubWindow*); @@ -153,6 +160,7 @@ private slots: void onViewClosed(QMdiSubWindow*); void onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent); void onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent); + void onMousePressed(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent); private: void addView(QMdiSubWindow* theView); @@ -179,6 +187,9 @@ private: QList myViews; QMdiSubWindow* myActiveView; + + /// Points used for selection management + QPoint myStartPnt, myEndPnt, myCurPnt; }; #endif