From 91777248bd99279a38c84000e444f121334f5d87 Mon Sep 17 00:00:00 2001 From: Artem Zhidkov Date: Fri, 26 Jun 2020 14:50:00 +0300 Subject: [PATCH] Task #3231: Sketcher Offset of a curve Keep offset edges within the Offset feature in order of the offset wire. --- src/SketchPlugin/SketchPlugin_Offset.cpp | 30 +++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/SketchPlugin/SketchPlugin_Offset.cpp b/src/SketchPlugin/SketchPlugin_Offset.cpp index 2d82f0153..cc5234943 100644 --- a/src/SketchPlugin/SketchPlugin_Offset.cpp +++ b/src/SketchPlugin/SketchPlugin_Offset.cpp @@ -55,6 +55,8 @@ #include #include #include +#include +#include #include #include @@ -297,6 +299,25 @@ static void setRefListValue(AttributeRefListPtr theList, int theListSize, theList->append(theValue); } +// Reorder shapes according to the wire's order +static void reorderShapes(ListOfShape& theShapes, GeomShapePtr theWire) +{ + std::set aShapes; + aShapes.insert(theShapes.begin(), theShapes.end()); + theShapes.clear(); + + GeomWirePtr aWire(new GeomAPI_Wire(theWire)); + GeomAPI_WireExplorer anExp(aWire); + for (; anExp.more(); anExp.next()) { + GeomShapePtr aCurEdge = anExp.current(); + auto aFound = aShapes.find(aCurEdge); + if (aFound != aShapes.end()) { + theShapes.push_back(aCurEdge); + aShapes.erase(aFound); + } + } +} + static void removeLastFromIndex(AttributeRefListPtr theList, int theListSize, int& theLastIndex) { if (theLastIndex < theListSize) { @@ -351,8 +372,12 @@ void SketchPlugin_Offset::addToSketch(const ListOfMakeShape& theOffsetAlgos) GeomShapePtr aBaseShape = aBaseFeature->lastResult()->shape(); ListOfShape aNewShapes; for (ListOfMakeShape::const_iterator anAlgoIt = theOffsetAlgos.begin(); - anAlgoIt != theOffsetAlgos.end() && aNewShapes.empty(); ++anAlgoIt) { + anAlgoIt != theOffsetAlgos.end(); ++anAlgoIt) { (*anAlgoIt)->generated(aBaseShape, aNewShapes); + if (!aNewShapes.empty()) { + reorderShapes(aNewShapes, (*anAlgoIt)->shape()); + break; + } } // store base feature @@ -647,6 +672,8 @@ bool SketchPlugin_Offset::findWires() } } + bool aWasBlocked = data()->blockSendAttributeUpdated(true); + // Gather chains of edges for (anEdgesIt = anEdgesList.begin(); anEdgesIt != anEdgesList.end(); anEdgesIt++) { FeaturePtr aFeature = ModelAPI_Feature::feature(*anEdgesIt); @@ -677,6 +704,7 @@ bool SketchPlugin_Offset::findWires() } // TODO: hilight selection in the viewer + data()->blockSendAttributeUpdated(aWasBlocked); return true; } -- 2.39.2