From 994581e292727c6580c53ed0abb49df3254dd384 Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 25 Jun 2015 12:21:06 +0300 Subject: [PATCH] Issues #616, #618 The main modification is in the getCurrentSelection. The highlighted points should also be processed here. --- src/PartSet/PartSet_SketcherMgr.cpp | 111 +++++++++++++++------------- 1 file changed, 60 insertions(+), 51 deletions(-) diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 216df94a9..19dede5a3 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -90,9 +90,14 @@ return aRes; }*/ -void fillFeature2Attribute(const QList& theList, - QMap >& theFeature2AttributeMap, - const FeaturePtr theSketch) +// Fills the list of features the list of selected presentations. +// \param theList a list of selected presentations +// \param theSketch a sketch to project a vertex shape of a presentation to the plane +// and find the corresponded attribute +// \param theFeatureList an output list of features +void fillFeatureList(const QList& theList, + const FeaturePtr theSketch, + QList& theFeatureList) { QList aRes; @@ -102,29 +107,46 @@ void fillFeature2Attribute(const QList& theList, { ModuleBase_ViewerPrs aPrs = *anIt; FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object()); - if (aFeature.get() == NULL) - continue; + if (aFeature.get() && !theFeatureList.contains(aFeature)) + theFeatureList.append(aFeature); + } +} - QList anAttributes; - if (theFeature2AttributeMap.contains(aFeature)) { - anAttributes = theFeature2AttributeMap[aFeature]; +/// Fills attribute and result lists by the selected owner. In case if the attribute is found, +/// by the owner shape, it is put to the list. Otherwise if type of owner shape is edge, put the function +/// result as is to the list of results. +/// \param theOwner a viewer selected owner +/// \param theFeature a feature, where the attribute is searched +/// \param theSketch a current sketch +/// \param theSelectedAttribute an output list of attributes +/// \param theSelectedResults an output list of edge results +void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner, + const FeaturePtr& theFeature, const FeaturePtr& theSketch, + const ResultPtr& theResult, + std::set& aSelectedAttributes, + std::set& aSelectedResults) +{ + Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner); + if (aBRepOwner.IsNull()) + return; + Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast( + aBRepOwner->Selectable()); + if (aBRepOwner->HasShape()) { + const TopoDS_Shape& aShape = aBRepOwner->Shape(); + TopAbs_ShapeEnum aShapeType = aShape.ShapeType(); + if (aShapeType == TopAbs_VERTEX) { + AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, + aShape, theSketch); + if (aPntAttr.get() != NULL) + aSelectedAttributes.insert(aPntAttr); } - AttributePtr anAttr; - TopoDS_Shape aShape = aPrs.shape(); - if (!aShape.IsNull()) { - if (aShape.ShapeType() == TopAbs_VERTEX) { - anAttr = PartSet_Tools::findAttributeBy2dPoint(aFeature, aShape, theSketch); - if (anAttr.get() != NULL && !anAttributes.contains(anAttr)) - anAttributes.push_back(anAttr); - } + else if (aShapeType == TopAbs_EDGE && + aSelectedResults.find(theResult) == aSelectedResults.end()) { + aSelectedResults.insert(theResult); } - theFeature2AttributeMap[aFeature] = anAttributes; } } - - - PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule) : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false), myIsPropertyPanelValueChanged(false), myIsMouseOverWindow(false), @@ -950,29 +972,18 @@ void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature, 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()) + Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner(); + if (anOwner->Selectable() != anAISIO) continue; - Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast( - aBRepOwner->Selectable()); - if (anIO != anAISIO) + getAttributesOrResults(anOwner, theFeature, theSketch, aResult, + aSelectedAttributes, aSelectedResults); + } + for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) { + Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner(); + if (anOwner->Selectable() != 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(theFeature, - aShape, theSketch); - if (aPntAttr.get() != NULL) - aSelectedAttributes.insert(aPntAttr); - } - else if (aShapeType == TopAbs_EDGE && - aSelectedResults.find(aResult) == aSelectedResults.end()) { - aSelectedResults.insert(aResult); - } - } + getAttributesOrResults(anOwner, theFeature, theSketch, aResult, + aSelectedAttributes, aSelectedResults); } } theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults); @@ -1001,7 +1012,7 @@ void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature, if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) { Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl(); - SelectMgr_IndexedMapOfOwner aSelectedOwners; + SelectMgr_IndexedMapOfOwner aSelectedOwners; aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners); for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) { Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i); @@ -1120,25 +1131,23 @@ void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly) ModuleBase_IWorkshop* aWorkshop = myModule->workshop(); ModuleBase_ISelection* aSelect = aWorkshop->selection(); QList aHighlighted = aSelect->getHighlighted(); - - QMap > aFeature2AttributeMap; + + QList aFeatureList; if (theHighlightedOnly) { - fillFeature2Attribute(aHighlighted, aFeature2AttributeMap, myCurrentSketch); + fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList); } else { - fillFeature2Attribute(aHighlighted, aFeature2AttributeMap, myCurrentSketch); + fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList); QList aSelected = aSelect->getSelected(); - fillFeature2Attribute(aSelected, aFeature2AttributeMap, myCurrentSketch); + fillFeatureList(aSelected, myCurrentSketch, aFeatureList); } // 1. it is necessary to save current selection in order to restore it after the features moving myCurrentSelection.clear(); - QMap >::const_iterator anIt = aFeature2AttributeMap.begin(), - aLast = aFeature2AttributeMap.end(); + QList::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end(); for (; anIt != aLast; anIt++) { - FeaturePtr aFeature = anIt.key(); - getCurrentSelection(aFeature, myCurrentSketch, aWorkshop, myCurrentSelection); + getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection); } //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str()); } -- 2.39.2