From 14ef4c9d4e93f1e2d07275151f00ce3a820c9bb2 Mon Sep 17 00:00:00 2001 From: Artem Zhidkov Date: Wed, 1 Jul 2020 00:21:26 +0300 Subject: [PATCH] Task #3231: Sketcher Offset of a curve Improve searching of coincidences in context of B-spline curve --- src/SketchPlugin/SketchPlugin_Offset.cpp | 19 +++------ src/SketchPlugin/SketchPlugin_Tools.cpp | 53 ++++++++++++++++-------- src/SketchPlugin/SketchPlugin_Tools.h | 7 ---- 3 files changed, 42 insertions(+), 37 deletions(-) diff --git a/src/SketchPlugin/SketchPlugin_Offset.cpp b/src/SketchPlugin/SketchPlugin_Offset.cpp index f7f7b75e8..2f01c4a8c 100644 --- a/src/SketchPlugin/SketchPlugin_Offset.cpp +++ b/src/SketchPlugin/SketchPlugin_Offset.cpp @@ -215,19 +215,12 @@ bool SketchPlugin_Offset::findWireOneWay (const FeaturePtr& theFirstEdge, FeaturePtr aNextEdgeFeature; int nbFound = 0; - std::set aCoincPoints; - std::map aCoincPointsInArray; - SketchPlugin_Tools::findPointsCoincidentToPoint(theEndPoint, aCoincPoints, aCoincPointsInArray); - - // store all found attributes to a single array - std::set anAllCoincPoints; - anAllCoincPoints.insert(aCoincPoints.begin(), aCoincPoints.end()); - for (auto it = aCoincPointsInArray.begin(); it != aCoincPointsInArray.end(); ++it) - anAllCoincPoints.insert(it->first); - - std::set::iterator aPointsIt = anAllCoincPoints.begin(); - for (; aPointsIt != anAllCoincPoints.end(); aPointsIt++) { - AttributePtr aP = (*aPointsIt); + std::set aCoincPoints = + SketchPlugin_Tools::findPointsCoincidentToPoint(theEndPoint); + + std::set::iterator aPointsIt = aCoincPoints.begin(); + for (; aPointsIt != aCoincPoints.end(); aPointsIt++) { + AttributePoint2DPtr aP = (*aPointsIt); FeaturePtr aCoincFeature = std::dynamic_pointer_cast(aP->owner()); bool isInSet = (theEdgesSet.find(aCoincFeature) != theEdgesSet.end()); diff --git a/src/SketchPlugin/SketchPlugin_Tools.cpp b/src/SketchPlugin/SketchPlugin_Tools.cpp index b5db72f77..15222805b 100644 --- a/src/SketchPlugin/SketchPlugin_Tools.cpp +++ b/src/SketchPlugin/SketchPlugin_Tools.cpp @@ -231,26 +231,39 @@ public: } } - void coincidentPoints(const AttributePoint2DPtr& thePoint, - std::set& thePoints, - std::map& thePointsInArray) + std::set coincidentPoints(const AttributePoint2DPtr& thePoint) { collectCoincidentPoints(thePoint); + std::set aCoincPoints; auto aFound = find(thePoint, THE_DEFAULT_INDEX); if (aFound != myCoincidentPoints.end()) { for (auto it = aFound->begin(); it != aFound->end(); ++it) { AttributePoint2DPtr aPoint = std::dynamic_pointer_cast(it->first); if (aPoint) - thePoints.insert(aPoint); + aCoincPoints.insert(aPoint); else { AttributePoint2DArrayPtr aPointArray = std::dynamic_pointer_cast(it->first); - if (aPointArray) - thePointsInArray[aPointArray] = *it->second.begin(); + if (aPointArray) { + // this is a B-spline feature, the connection is possible + // to the first or the last point + FeaturePtr anOwner = ModelAPI_Feature::feature(aPointArray->owner()); + if (it->second.find(0) != it->second.end()) { + AttributePoint2DPtr aFirstPoint = std::dynamic_pointer_cast( + anOwner->attribute(SketchPlugin_BSpline::START_ID())); + aCoincPoints.insert(aFirstPoint); + } + if (it->second.find(aPointArray->size() - 1) != it->second.end()) { + AttributePoint2DPtr aFirstPoint = std::dynamic_pointer_cast( + anOwner->attribute(SketchPlugin_BSpline::END_ID())); + aCoincPoints.insert(aFirstPoint); + } + } } } } + return aCoincPoints; } private: @@ -344,6 +357,22 @@ private: if (aFound != aSeek->end() && aFound->second.find(theIndex) != aFound->second.end()) return aSeek; } + // nothing is found, but if the point is a B-spline boundary point, lets check it as poles array + FeaturePtr anOwner = ModelAPI_Feature::feature(thePoint->owner()); + if (anOwner->getKind() == SketchPlugin_BSpline::ID()) { + AttributePtr aPointsArray; + int anIndex = -1; + if (thePoint->id() == SketchPlugin_BSpline::START_ID()) { + aPointsArray = anOwner->attribute(SketchPlugin_BSpline::POLES_ID()); + anIndex = 0; + } + else if (thePoint->id() == SketchPlugin_BSpline::END_ID()) { + aPointsArray = anOwner->attribute(SketchPlugin_BSpline::POLES_ID()); + anIndex = std::dynamic_pointer_cast(aPointsArray)->size() - 1; + } + if (aPointsArray) + return find(aPointsArray, anIndex); + } return myCoincidentPoints.end(); } @@ -352,19 +381,9 @@ private: }; std::set findPointsCoincidentToPoint(const AttributePoint2DPtr& thePoint) -{ - std::set aPoints; - std::map aPointsInArray; - findPointsCoincidentToPoint(thePoint, aPoints, aPointsInArray); - return aPoints; -} - -void findPointsCoincidentToPoint(const AttributePoint2DPtr& thePoint, - std::set& thePoints, - std::map& thePointsInArray) { CoincidentPoints aCoincidentPoints; - aCoincidentPoints.coincidentPoints(thePoint, thePoints, thePointsInArray); + return aCoincidentPoints.coincidentPoints(thePoint); } diff --git a/src/SketchPlugin/SketchPlugin_Tools.h b/src/SketchPlugin/SketchPlugin_Tools.h index d7550bd0b..b87dee111 100644 --- a/src/SketchPlugin/SketchPlugin_Tools.h +++ b/src/SketchPlugin/SketchPlugin_Tools.h @@ -68,13 +68,6 @@ std::set findFeaturesCoincidentToPoint(const AttributePoint2DPtr& th /// Find all points the given point is coincident to. std::set findPointsCoincidentToPoint(const AttributePoint2DPtr& thePoint); -/// Find all points the given point is coincident to. -/// Returns GeomDataAPI_Point2D attribute and -/// GeomDataAPI_Point2DArray with the index of coincident point. -void findPointsCoincidentToPoint(const AttributePoint2DPtr& thePoint, - std::set& thePoints, - std::map& thePointsInArray); - void resetAttribute(SketchPlugin_Feature* theFeature, const std::string& theId); /// Create new constraint between given attributes -- 2.39.2