diff --git a/src/Mod/TechDraw/App/AppTechDrawPy.cpp b/src/Mod/TechDraw/App/AppTechDrawPy.cpp index 60339f63e..4183dbc3a 100644 --- a/src/Mod/TechDraw/App/AppTechDrawPy.cpp +++ b/src/Mod/TechDraw/App/AppTechDrawPy.cpp @@ -145,7 +145,7 @@ private: EdgeWalker ew; ew.loadEdges(edgeList); ew.perform(); - std::vector rw = ew.getResultWires(); + std::vector rw = ew.getResultNoDups(); std::vector sortedWires = ew.sortStrip(rw,biggie); //false==>do not include biggest wires for (auto& w:sortedWires) { PyList_Append(result,new TopoShapeWirePy(new TopoShape(w))); @@ -179,17 +179,12 @@ private: throw Py::Exception(Part::PartExceptionOCCError, e->GetMessageString()); } - PyObject* result = PyList_New(0); - EdgeWalker ew; ew.loadEdges(edgeList); ew.perform(); - std::vector rw = ew.getResultWires(); - std::vector sortedWires = ew.sortStrip(rw,true); - for (auto& w:sortedWires) { - PyList_Append(result,new TopoShapeWirePy(new TopoShape(w))); - } - PyObject* outerWire = PyList_GetItem(result, 0); + std::vector rw = ew.getResultNoDups(); + std::vector sortedWires = ew.sortStrip(rw,true); + PyObject* outerWire = new TopoShapeWirePy(new TopoShape(*sortedWires.begin())); return Py::asObject(outerWire); } }; diff --git a/src/Mod/TechDraw/App/EdgeWalker.cpp b/src/Mod/TechDraw/App/EdgeWalker.cpp index 81f42a44b..757a558fd 100644 --- a/src/Mod/TechDraw/App/EdgeWalker.cpp +++ b/src/Mod/TechDraw/App/EdgeWalker.cpp @@ -341,11 +341,7 @@ std::vector EdgeWalker::sortStrip(std::vector fw, bool return sortedWires; // might happen in the middle of changes? } - if (includeBiggest) { - return sortedWires; // all the wires - } - - //remove the largest wire (OuterWire of graph) wf: still not convinced we should do this in all cases. + //find the largest wire (OuterWire of graph) using bbox Bnd_Box bigBox; if (sortedWires.size() && !sortedWires.front().IsNull()) { BRepBndLib::Add(sortedWires.front(), bigBox); @@ -366,10 +362,13 @@ std::vector EdgeWalker::sortStrip(std::vector fw, bool } } } + //unfortuneately, faces can have same bbox, but not be same size. need to weed out biggest if (toBeChecked.size() == 0) { //nobody had as big a bbox as first element of sortedWires - sortedWires.erase(sortedWires.begin()); + if (!includeBiggest) { + sortedWires.erase(sortedWires.begin()); + } } else if (toBeChecked.size() > 0) { BRepBuilderAPI_MakeFace mkFace(sortedWires.front()); const TopoDS_Face& face = mkFace.Face(); @@ -377,17 +376,29 @@ std::vector EdgeWalker::sortStrip(std::vector fw, bool BRepGProp::SurfaceProperties(face, props); double bigArea = props.Mass(); unsigned int bigIndex = 0; - for (unsigned int idx = 1; idx < toBeChecked.size(); idx++) { - BRepBuilderAPI_MakeFace mkFace2(sortedWires.at(idx)); + for (unsigned int idx = 0; idx < toBeChecked.size(); idx++) { + int iCheck = toBeChecked.at(idx); + BRepBuilderAPI_MakeFace mkFace2(sortedWires.at(iCheck)); const TopoDS_Face& face2 = mkFace2.Face(); BRepGProp::SurfaceProperties(face2, props); double area = props.Mass(); if (area > bigArea) { bigArea = area; - bigIndex = idx; + bigIndex = iCheck; } } - sortedWires.erase(sortedWires.begin() + bigIndex); + if (bigIndex == 0) { //first wire is the biggest + if (!includeBiggest) { + sortedWires.erase(sortedWires.begin()); + } + } else { //first wire is not the biggest + TopoDS_Wire bigWire = *(sortedWires.begin() + bigIndex); + sortedWires.erase(sortedWires.begin() + bigIndex); + if (includeBiggest) { + sortedWires.insert(sortedWires.begin(),bigWire); //doesn't happen often + } + } + } return sortedWires; }