From: jfa Date: Fri, 3 Jul 2020 14:14:05 +0000 (+0300) Subject: Task #3231: Sketcher Offset of a curve. Fix a bug with several edges, coincident... X-Git-Tag: V9_6_0a1~60^2~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ef02e2eb6acb331134c16fcbabbf85eee75617eb;p=modules%2Fshaper.git Task #3231: Sketcher Offset of a curve. Fix a bug with several edges, coincident in one point. --- diff --git a/src/SketchPlugin/SketchPlugin_Offset.cpp b/src/SketchPlugin/SketchPlugin_Offset.cpp index 4fb79fdec..7ea47ee0e 100644 --- a/src/SketchPlugin/SketchPlugin_Offset.cpp +++ b/src/SketchPlugin/SketchPlugin_Offset.cpp @@ -61,8 +61,6 @@ #include #include -#include - static const double tolerance = 1.e-7; SketchPlugin_Offset::SketchPlugin_Offset() @@ -131,10 +129,11 @@ void SketchPlugin_Offset::execute() // 5. Gather wires and make offset for each wire ListOfMakeShape anOffsetAlgos; + std::set aProcessedEdgesSet; for (anEdgesIt = anEdgesList.begin(); anEdgesIt != anEdgesList.end(); anEdgesIt++) { FeaturePtr aFeature = ModelAPI_Feature::feature(*anEdgesIt); if (aFeature.get()) { - if (anEdgesSet.find(aFeature) == anEdgesSet.end()) + if (aProcessedEdgesSet.find(aFeature) != aProcessedEdgesSet.end()) continue; // 5.a. End points (if any) @@ -145,13 +144,11 @@ void SketchPlugin_Offset::execute() std::list aChain; aChain.push_back(aFeature); if (aStartPoint && anEndPoint) { // not closed edge - bool isClosed = findWireOneWay(aFeature, aFeature, aStartPoint, anEdgesSet, aChain, true); + bool isClosed = findWireOneWay(aFeature, aFeature, aStartPoint, anEdgesSet, aProcessedEdgesSet, aChain, true); if (!isClosed) - findWireOneWay(aFeature, aFeature, anEndPoint, anEdgesSet, aChain, false); + findWireOneWay(aFeature, aFeature, anEndPoint, anEdgesSet, aProcessedEdgesSet, aChain, false); } - std::set::iterator aPos = anEdgesSet.find(aFeature); - if (aPos != anEdgesSet.end()) - anEdgesSet.erase(aPos); + aProcessedEdgesSet.insert(aFeature); // 5.c. Make wire ListOfShape aTopoChain; @@ -207,6 +204,7 @@ bool SketchPlugin_Offset::findWireOneWay (const FeaturePtr& theFirstEdge, const FeaturePtr& theEdge, const std::shared_ptr& theEndPoint, std::set& theEdgesSet, + std::set& theProcessedEdgesSet, std::list& theChain, const bool isPrepend) { @@ -274,12 +272,7 @@ bool SketchPlugin_Offset::findWireOneWay (const FeaturePtr& theFirstEdge, theChain.push_front(aNextEdgeFeature); else theChain.push_back(aNextEdgeFeature); - // remove from the set, if the set is used - if (theEdgesSet.size()) { - std::set::iterator aPos = theEdgesSet.find(aNextEdgeFeature); - if (aPos != theEdgesSet.end()) - theEdgesSet.erase(aPos); - } + theProcessedEdgesSet.insert(aNextEdgeFeature); // 4. Which end of aNextEdgeFeature we need to proceed std::shared_ptr aP1, aP2; @@ -290,7 +283,7 @@ bool SketchPlugin_Offset::findWireOneWay (const FeaturePtr& theFirstEdge, } // 5. Continue gathering the chain (recursive) - return findWireOneWay (theFirstEdge, aNextEdgeFeature, aP2, theEdgesSet, theChain, isPrepend); + return findWireOneWay (theFirstEdge, aNextEdgeFeature, aP2, theEdgesSet, theProcessedEdgesSet, theChain, isPrepend); } static void setRefListValue(AttributeRefListPtr theList, int theListSize, @@ -680,7 +673,7 @@ bool SketchPlugin_Offset::findWires() std::set anEdgesSet; // Processed set - std::set aProcessedSet; + std::set aProcessedEdgesSet; // Put all selected edges in a set to avoid adding them in reflist(EDGES_ID()) std::set aSelectedSet; @@ -698,9 +691,9 @@ bool SketchPlugin_Offset::findWires() for (anEdgesIt = anEdgesList.begin(); anEdgesIt != anEdgesList.end(); anEdgesIt++) { FeaturePtr aFeature = ModelAPI_Feature::feature(*anEdgesIt); if (aFeature.get()) { - if (aProcessedSet.find(aFeature) != aProcessedSet.end()) + if (aProcessedEdgesSet.find(aFeature) != aProcessedEdgesSet.end()) continue; - aProcessedSet.insert(aFeature); + aProcessedEdgesSet.insert(aFeature); // End points (if any) std::shared_ptr aStartPoint, anEndPoint; @@ -708,14 +701,13 @@ bool SketchPlugin_Offset::findWires() std::list aChain; aChain.push_back(aFeature); - bool isClosed = findWireOneWay(aFeature, aFeature, aStartPoint, anEdgesSet, aChain, true); + bool isClosed = findWireOneWay(aFeature, aFeature, aStartPoint, anEdgesSet, aProcessedEdgesSet, aChain, true); if (!isClosed) - findWireOneWay(aFeature, aFeature, anEndPoint, anEdgesSet, aChain, false); + findWireOneWay(aFeature, aFeature, anEndPoint, anEdgesSet, aProcessedEdgesSet, aChain, false); std::list::iterator aChainIt = aChain.begin(); for (; aChainIt != aChain.end(); ++aChainIt) { FeaturePtr aChainFeature = (*aChainIt); - aProcessedSet.insert(aChainFeature); if (aSelectedSet.find(aChainFeature) == aSelectedSet.end()) { aSelectedEdges->append(aChainFeature->lastResult()); } diff --git a/src/SketchPlugin/SketchPlugin_Offset.h b/src/SketchPlugin/SketchPlugin_Offset.h index 355e1e58f..3a809f302 100644 --- a/src/SketchPlugin/SketchPlugin_Offset.h +++ b/src/SketchPlugin/SketchPlugin_Offset.h @@ -129,6 +129,7 @@ private: /// \param[in] theEdge Current edge /// \param[in] theEndPoint Point of the Current edge, not belonging to a previous edge /// \param[in/out] theEdgesSet All edges to find among. If empty, all sketch edges assumed. + /// \param[in/out] theProcessedEdgesSet Already processed (put in chains) edges. /// \param[in/out] theChain Resulting edges /// \param[in] isPrepend if true, push new found edges to theChain front, else to the back /// \return \c true if the chain is closed @@ -136,6 +137,7 @@ private: const FeaturePtr& theEdge, const std::shared_ptr& theEndPoint, std::set& theEdgesSet, + std::set& theProcessedEdgesSet, std::list& theChain, const bool isPrepend = false); };