From c0d8dd5e00c11f343fda909b8868f04986ced273 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 26 Dec 2014 16:47:32 +0300 Subject: [PATCH] The local selection restore for a feature vertex (it is checked on the line feature) --- src/PartSet/PartSet_SketcherMgr.cpp | 140 +++++++++++++++++++++++++++- src/PartSet/PartSet_SketcherMgr.h | 28 ++++++ src/XGUI/XGUI_Displayer.cpp | 22 +++++ src/XGUI/XGUI_Displayer.h | 7 +- src/XGUI/XGUI_Selection.cpp | 34 +++++++ src/XGUI/XGUI_Selection.h | 11 +++ 6 files changed, 239 insertions(+), 3 deletions(-) diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 403fb7b1f..01e0fa98e 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -35,6 +36,9 @@ #include #include +#include +#include + #include #include @@ -265,12 +269,48 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve std::shared_ptr aSketchFeature = std::dynamic_pointer_cast(aFeature); if (aSketchFeature) { + // save the previous selection + ModuleBase_IWorkshop* aWorkshop = myModule->workshop(); + XGUI_ModuleConnector* aConnector = dynamic_cast(aWorkshop); + XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); + QIntList anActivatedModes; + + ResultPtr aResult = aSketchFeature->firstResult(); + + aDisplayer->getModesOfActivation(aResult, anActivatedModes); + + std::list aSelectedAttributes; + getCurrentSelection(aSketchFeature, myCurrentSketch, aWorkshop, aSelectedAttributes); + // save the previous selection: end + + aSketchFeature->move(dX, dY); ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, anEvent); + + // TODO: the selection restore should be after the AIS presentation is rebuilt + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_MOVED)); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); + + // restore the previous selection + aResult = aSketchFeature->firstResult(); + aDisplayer->activate(aResult, anActivatedModes); + + SelectMgr_IndexedMapOfOwner anOwnersToSelect; + getSelectionOwners(aSketchFeature, myCurrentSketch, aWorkshop, aSelectedAttributes, + anOwnersToSelect); + + ModuleBase_IViewer* aViewer = aWorkshop->viewer(); + Handle(AIS_InteractiveContext) aContext = aViewer->AISContext(); + for (Standard_Integer i = 1, n = anOwnersToSelect.Extent(); i <= n; i++) + aContext->AddOrRemoveSelected(anOwnersToSelect(i), false); // SetSelected() + + aContext->UpdateCurrentViewer(); + // restore the previous selection } } - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_MOVED)); - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); + // TODO: set here + //Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_MOVED)); + //Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); } myDragDone = true; myCurX = aX; @@ -417,3 +457,99 @@ void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr& th { myPlaneFilter->setPlane(thePln->impl()); } + +void PartSet_SketcherMgr::getCurrentSelection(const ObjectPtr& theObject, + const FeaturePtr& theSketch, + ModuleBase_IWorkshop* theWorkshop, + std::list& theSelectedAttributes) +{ + FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); + if (aFeature.get() == NULL) + return; + + ModuleBase_IViewer* aViewer = theWorkshop->viewer(); + Handle(AIS_InteractiveContext) aContext = aViewer->AISContext(); + XGUI_ModuleConnector* aConnector = dynamic_cast(theWorkshop); + XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); + + // TODO: check all results and IPresentable feature + ResultPtr aResult = aFeature->firstResult(); + + bool isVisibleSketch = aDisplayer->isVisible(aResult); + AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult); + + if (aAISObj.get() != NULL) { + Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl(); + for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) + { + Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast( + aContext->SelectedOwner()); + if (aBRepOwner.IsNull()) continue; + + Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast( + aBRepOwner->Selectable()); + if (anIO != anAISIO) continue; + + if (aBRepOwner->HasShape()) { + const TopoDS_Shape& aShape = aBRepOwner->Shape(); + TopAbs_ShapeEnum aShapeType = aShape.ShapeType(); + if (aShapeType == TopAbs_VERTEX) { + AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theObject, + aShape, theSketch); + if (aPntAttr.get() != NULL) + theSelectedAttributes.push_back(aPntAttr); + } + } + } + } +} + +void PartSet_SketcherMgr::getSelectionOwners(const ObjectPtr& theObject, + const FeaturePtr& theSketch, + ModuleBase_IWorkshop* theWorkshop, + const std::list& theSelectedAttributes, + SelectMgr_IndexedMapOfOwner& anOwnersToSelect) +{ + FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); + if (aFeature.get() == NULL) + return; + + ModuleBase_IViewer* aViewer = theWorkshop->viewer(); + Handle(AIS_InteractiveContext) aContext = aViewer->AISContext(); + XGUI_ModuleConnector* aConnector = dynamic_cast(theWorkshop); + XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); + + // TODO: check all results and IPresentable feature + ResultPtr aResult = aFeature->firstResult(); + + bool isVisibleSketch = aDisplayer->isVisible(aResult); + AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult); + + if (aAISObj.get() != NULL) { + Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl(); + + SelectMgr_IndexedMapOfOwner aSelectedOwners; + + XGUI_Selection::entityOwners(anAISIO, aContext, aSelectedOwners); + for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) { + Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i)); + if ( anOwner.IsNull() || !anOwner->HasShape() ) + continue; + const TopoDS_Shape& aShape = anOwner->Shape(); + TopAbs_ShapeEnum aShapeType = aShape.ShapeType(); + if (aShapeType == TopAbs_VERTEX) { + AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(aFeature, aShape, theSketch); + if (aPntAttr.get() != NULL) { + std::list::const_iterator anIt = theSelectedAttributes.begin(), + aLast = theSelectedAttributes.end(); + for (; anIt != aLast; anIt++) { + AttributePtr anAttrIt = *anIt; + if (anAttrIt.get() == aPntAttr.get()) { + anOwnersToSelect.Add(anOwner); + } + } + } + } + } + } +} diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index 813157829..9c79ee437 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -14,8 +14,10 @@ #include #include +#include #include +#include #include #include @@ -67,6 +69,32 @@ private: void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent, double& theX, double& theY); + /// Obtains the current selection of the object in the workshop viewer + /// It includes the selection in all modes of activation, even local context - vertexes, edges + /// The result is a list of attributes of the feature of the object + /// In addition, it retuns a list of selection modes, where the object is activated + /// \param theObject a feature or result object + /// \param theSketch a current sketch feature + /// \param theWorkshop a workshop to have an access to AIS context and displayer + /// \param theSelectedAttributes an out list of selected attributes + static void getCurrentSelection(const ObjectPtr& theObject, + const FeaturePtr& theSketch, + ModuleBase_IWorkshop* theWorkshop, + std::list& theSelectedAttributes); + + /// Applyes the current selection to the object in the workshop viewer + /// It includes the selection in all modes of activation, even local context - vertexes, edges + /// The result is a list of attributes of the feature of the object + /// In addition, it retuns a list of selection modes, where the object is activated + /// \param theObject a feature or result object + /// \param theSketch a current sketch feature + /// \param theWorkshop a workshop to have an access to AIS context and displayer + /// \param theSelectedAttributes an out list of selected attributes + static void getSelectionOwners(const ObjectPtr& theObject, + const FeaturePtr& theSketch, + ModuleBase_IWorkshop* theWorkshop, + const std::list& theSelectedAttributes, + SelectMgr_IndexedMapOfOwner& anOwnersToSelect); private: PartSet_Module* myModule; diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 3b0cbc3e6..c06aae88a 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -251,6 +251,28 @@ void XGUI_Displayer::activate(ObjectPtr theObject, const QIntList& theModes) } } +void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theModes) +{ + if (!isVisible(theObject)) + return; + + Handle(AIS_InteractiveContext) aContext = AISContext(); + if (aContext.IsNull()) + return; + + AISObjectPtr aAISObj = getAISObject(theObject); + + if (aAISObj.get() != NULL) { + Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl(); + TColStd_ListOfInteger aTColModes; + aContext->ActivatedModes(anAISIO, aTColModes); + TColStd_ListIteratorOfListOfInteger itr( aTColModes ); + for (; itr.More(); itr.Next() ) { + theModes.append(itr.Value()); + } + } +} + void XGUI_Displayer::activateObjects(const QIntList& theModes) { // In order to avoid doblications of selection modes diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index 0dfb1cae1..176f52bc4 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -93,7 +93,7 @@ class XGUI_EXPORT XGUI_Displayer void updateViewer(); /// Searches the interactive object by feature - /// \param theFeature the feature or NULL if it not visualized + /// \param theFeature the object or presentable feature /// \return theIO an interactive object AISObjectPtr getAISObject(ObjectPtr theFeature) const; @@ -110,6 +110,11 @@ class XGUI_EXPORT XGUI_Displayer /// \param theModes - modes on which it has to be activated (can be empty) void activate(ObjectPtr theFeature, const QIntList& theModes); + /// Returns the modes of activation + /// \param theFeature the feature or NULL if it not visualized + /// \param theModes - modes on which it is activated (can be empty) + void getModesOfActivation(ObjectPtr theObject, QIntList& theModes); + /// Activates the given object with default modes void activate(ObjectPtr theFeature); diff --git a/src/XGUI/XGUI_Selection.cpp b/src/XGUI/XGUI_Selection.cpp index a4ca2212d..7b4bb5ff1 100644 --- a/src/XGUI/XGUI_Selection.cpp +++ b/src/XGUI/XGUI_Selection.cpp @@ -14,6 +14,10 @@ #include +#include +#include +#include + #include XGUI_Selection::XGUI_Selection(XGUI_Workshop* theWorkshop) @@ -152,3 +156,33 @@ void XGUI_Selection::selectedShapes(NCollection_List& theList, } } } + +//************************************************************** +void XGUI_Selection::entityOwners(const Handle(AIS_InteractiveObject)& theObject, + const Handle(AIS_InteractiveContext)& theContext, + SelectMgr_IndexedMapOfOwner& theOwners) +{ + if (theObject.IsNull() || theContext.IsNull()) + return; + + TColStd_ListOfInteger aModes; + theContext->ActivatedModes(theObject, aModes); + + TColStd_ListIteratorOfListOfInteger anIt(aModes); + for (; anIt.More(); anIt.Next()) { + int aMode = anIt.Value(); + if (!theObject->HasSelection(aMode)) + continue; + + Handle(SelectMgr_Selection) aSelection = theObject->Selection(aMode); + for (aSelection->Init(); aSelection->More(); aSelection->Next()) { + Handle(SelectBasics_SensitiveEntity) anEntity = aSelection->Sensitive(); + if (anEntity.IsNull()) + continue; + Handle(SelectMgr_EntityOwner) anOwner = + Handle(SelectMgr_EntityOwner)::DownCast(anEntity->OwnerId()); + if (!anOwner.IsNull()) + theOwners.Add(anOwner); + } + } +} diff --git a/src/XGUI/XGUI_Selection.h b/src/XGUI/XGUI_Selection.h index cfefd28a0..c411d5ff0 100644 --- a/src/XGUI/XGUI_Selection.h +++ b/src/XGUI/XGUI_Selection.h @@ -18,6 +18,8 @@ #include #include +#include + class XGUI_Workshop; class XGUI_EXPORT XGUI_Selection : public ModuleBase_ISelection @@ -55,6 +57,15 @@ class XGUI_EXPORT XGUI_Selection : public ModuleBase_ISelection virtual void selectedShapes(NCollection_List& theShapes, std::list& theOwners) const; + //! Returns a list of selection entity owners of the interactive object + /// It depends on the modes, in which the object is activated in the context + /// \param theObject an object + /// \param theContext a viewer interactive context + /// \param theOwners a map of entity owners + static void entityOwners(const Handle_AIS_InteractiveObject& theObject, + const Handle_AIS_InteractiveContext& theContext, + SelectMgr_IndexedMapOfOwner& theOwners); + private: XGUI_Workshop* myWorkshop; }; -- 2.39.2