From: nds Date: Wed, 5 Apr 2017 09:53:16 +0000 (+0300) Subject: Issue #2059 point in sketch is created not on selected line of external sketchPlane... X-Git-Tag: V_2.7.0~71 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b87807aab0cec91d5fccd5e004c696b1b0356c77;p=modules%2Fshaper.git Issue #2059 point in sketch is created not on selected line of external sketchPlane: should store/restore local selection if shape was not changed --- diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index ea9bfeced..87cbaac30 100755 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -108,8 +108,9 @@ void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner, const FeaturePtr& theFeature, const FeaturePtr& theSketch, const ResultPtr& theResult, - std::set& aSelectedAttributes, - std::set& aSelectedResults) + std::set& theSelectedAttributes, + std::set& theSelectedResults, + TopTools_MapOfShape& theShapes) { Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner); if (aBRepOwner.IsNull()) @@ -118,16 +119,17 @@ void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner, aBRepOwner->Selectable()); if (aBRepOwner->HasShape()) { const TopoDS_Shape& aShape = aBRepOwner->Shape(); + theShapes.Add(aShape); TopAbs_ShapeEnum aShapeType = aShape.ShapeType(); if (aShapeType == TopAbs_VERTEX) { AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch); if (aPntAttr.get() != NULL) - aSelectedAttributes.insert(aPntAttr); + theSelectedAttributes.insert(aPntAttr); } else if (aShapeType == TopAbs_EDGE && - aSelectedResults.find(theResult) == aSelectedResults.end()) { - aSelectedResults.insert(theResult); + theSelectedResults.find(theResult) == theSelectedResults.end()) { + theSelectedResults.insert(theResult); } } } @@ -540,7 +542,7 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve for (; anIt != aLast; anIt++) { FeaturePtr aFeature = anIt.key(); - std::set anAttributes = anIt.value().first; + std::set anAttributes = anIt.value().myAttributes; // Process selection by attribute: the priority to the attribute if (!anAttributes.empty()) { std::set::const_iterator anAttIt = anAttributes.begin(), @@ -1489,8 +1491,9 @@ void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature, return; FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature); - std::set aSelectedAttributes = anIt.value().first; - std::set aSelectedResults = anIt.value().second; + SelectionInfo anInfo = anIt.value(); + std::set aSelectedAttributes = anInfo.myAttributes; + std::set aSelectedResults = anInfo.myResults; ModuleBase_IViewer* aViewer = theWorkshop->viewer(); @@ -1514,8 +1517,10 @@ void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature, // 2. found the feature results's owners std::list aResults = theFeature->results(); std::list::const_iterator aIt; - for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) - { + + const TopoDS_Shape aFirstShape = theFeature->firstResult()->shape()->impl(); + bool isSameShape = aFirstShape.IsEqual(anInfo.myFirstResultShape); + for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) { ResultPtr aResult = *aIt; AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult); if (aAISObj.get() == NULL) @@ -1524,10 +1529,11 @@ void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature, SelectMgr_IndexedMapOfOwner aSelectedOwners; aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners); + bool aFoundLocalShape = false; 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() ) + if ( anOwner.IsNull() || !anOwner->HasShape() || theOwnersToSelect.FindIndex(anOwner)) continue; const TopoDS_Shape& aShape = anOwner->Shape(); TopAbs_ShapeEnum aShapeType = aShape.ShapeType(); @@ -1535,15 +1541,34 @@ void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature, AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch); if (aPntAttr.get() != NULL && - aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) { + aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) + theOwnersToSelect.Add(anOwner); + else if (isSameShape && anInfo.myLocalSelectedShapes.Contains(aShape)) { theOwnersToSelect.Add(anOwner); } } else if (aShapeType == TopAbs_EDGE) { - bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end(); - if (aSelectedResults.find(aResult) != aSelectedResults.end() && - theOwnersToSelect.FindIndex(anOwner) <= 0) + if (isSameShape && anInfo.myLocalSelectedShapes.Contains(aShape)) { + // try to restore local selection on Shape result + // we can do this only if the shape was not changed theOwnersToSelect.Add(anOwner); + aFoundLocalShape = true; + break; + } + } + } + if (!aFoundLocalShape) { + // result owners are put in the list of selection only if local selected shapes were not + // found + if (aSelectedResults.find(aResult) != aSelectedResults.end()) { + 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() || theOwnersToSelect.FindIndex(anOwner)) + continue; + // select whole result + theOwnersToSelect.Add(anOwner); + } } } } @@ -1701,17 +1726,16 @@ void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly) std::set aSelectedAttributes; std::set aSelectedResults; - if (myCurrentSelection.find(aFeature) != myCurrentSelection.end()) { - std::pair, std::set > aPair = - myCurrentSelection.find(aFeature).value(); - aSelectedAttributes = aPair.first; - aSelectedResults = aPair.second; - } + SelectionInfo anInfo; + if (myCurrentSelection.find(aFeature) != myCurrentSelection.end()) + anInfo = myCurrentSelection.find(aFeature).value(); + const TopoDS_Shape aFirstShape = aFeature->firstResult()->shape()->impl(); + anInfo.myFirstResultShape = aFirstShape; Handle(SelectMgr_EntityOwner) anOwner = aPrs->owner(); if (aResult.get()) { getAttributesOrResults(anOwner, aFeature, aSketch, aResult, - aSelectedAttributes, aSelectedResults); + anInfo.myAttributes, anInfo.myResults, anInfo.myLocalSelectedShapes); } else { std::list aResults = aFeature->results(); @@ -1719,10 +1743,10 @@ void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly) for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) { ResultPtr aResult = *aIt; getAttributesOrResults(anOwner, aFeature, aSketch, aResult, - aSelectedAttributes, aSelectedResults); + anInfo.myAttributes, anInfo.myResults, anInfo.myLocalSelectedShapes); } } - myCurrentSelection[aFeature] = std::make_pair(aSelectedAttributes, aSelectedResults); + myCurrentSelection[aFeature] = anInfo; } //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str()); } @@ -1741,7 +1765,7 @@ void PartSet_SketcherMgr::restoreSelection() anOwnersToSelect.Clear(); for (; aSIt != aSLast; aSIt++) { getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection, - anOwnersToSelect); + anOwnersToSelect); } aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false); } diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index 7e0ce1f27..db177e582 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -23,6 +23,8 @@ #include #include +#include +#include #include #include @@ -315,8 +317,15 @@ private: ModuleBase_IWorkshop* theWorkshop, bool& theCanCommitOperation); - typedef QMap, std::set > > - FeatureToSelectionMap; + struct SelectionInfo + { + std::set myAttributes; + std::set myResults; + TopoDS_Shape myFirstResultShape; + TopTools_MapOfShape myLocalSelectedShapes; + }; + + typedef QMap FeatureToSelectionMap; /// 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 @@ -334,7 +343,7 @@ private: const FeaturePtr& theSketch, ModuleBase_IWorkshop* theWorkshop, const FeatureToSelectionMap& theSelection, - SelectMgr_IndexedMapOfOwner& anOwnersToSelect); + SelectMgr_IndexedMapOfOwner& theOwnersToSelect); /// Returns true if the created feature is visible /// \param diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 0d296dc09..8e556448f 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -591,8 +591,17 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo else { if (getPoint2d(aView, aShape, aX, aY)) setPoint(aX, aY); - else + else { + if (aShape.ShapeType() == TopAbs_EDGE) { + // point is taken from mouse event and set in attribute. It should be done before setting + // coinident constraint to the external line. If a point is created, it should be in + // the mouse clicked point + gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWindow->v3dView()); + PartSet_Tools::convertTo2D(aPoint, mySketch, aView, aX, aY); + setPoint(aX, aY); + } setValueState(Stored); // in case of edge selection, Apply state should also be updated + } bool anOrphanPoint = aShape.ShapeType() == TopAbs_VERTEX || isOrphanPoint(aSelectedFeature, mySketch, aX, aY); if (anExternal) {