From bdba939f9f03aa4db96658d55224485dd07769b2 Mon Sep 17 00:00:00 2001 From: Kacper Donat Date: Mon, 11 Aug 2025 23:22:27 +0200 Subject: [PATCH] PartDesign: Implement preview for Draft --- src/Mod/PartDesign/App/FeatureDraft.cpp | 46 +++---------------- .../PartDesign/Gui/TaskDraftParameters.cpp | 1 + 2 files changed, 8 insertions(+), 39 deletions(-) diff --git a/src/Mod/PartDesign/App/FeatureDraft.cpp b/src/Mod/PartDesign/App/FeatureDraft.cpp index 6c826ab963..180d694979 100644 --- a/src/Mod/PartDesign/App/FeatureDraft.cpp +++ b/src/Mod/PartDesign/App/FeatureDraft.cpp @@ -43,6 +43,7 @@ #endif #include +#include #include #include #include @@ -276,49 +277,16 @@ App::DocumentObjectExecReturn *Draft::execute() Part::TopoShape baseShape(TopShape); baseShape.setTransform(Base::Matrix4D()); try { - BRepOffsetAPI_DraftAngle mkDraft; - // Note: - // LocOpe_SplitDrafts can split a face with a wire and apply draft to both parts - // Not clear though whether the face must have free boundaries - // LocOpe_DPrism can create a stand-alone draft prism. The sketch can only have a single - // wire, though. - // BRepFeat_MakeDPrism requires a support for the operation but will probably support multiple - // wires in the sketch + std::vector faces = getFaces(baseShape); - bool success; + TopoShape shape({}, getDocument()->getStringHasher()); + shape.makeElementDraft(baseShape, faces, pullDirection, angle, neutralPlane, reversed); - do { - success = true; - mkDraft.Init(baseShape.getShape()); - - for (std::vector::iterator it=SubVals.begin(); it != SubVals.end(); ++it) { - TopoDS_Face face = TopoDS::Face(baseShape.getSubShape(it->c_str())); - // TODO: What is the flag for? - mkDraft.Add(face, pullDirection, angle, neutralPlane); - if (!mkDraft.AddDone()) { - // Note: the function ProblematicShape returns the face on which the error occurred - // Note: mkDraft.Remove() stumbles on a bug in Draft_Modification::Remove() and is - // therefore unusable. See https://forum.freecad.org/viewtopic.php?f=10&t=3209&start=10#p25341 - // The only solution is to discard mkDraft and start over without the current face - // mkDraft.Remove(face); - Base::Console().error("Adding face failed on %s. Omitted\n", it->c_str()); - success = false; - SubVals.erase(it); - break; - } - } - } - while (!success); - - mkDraft.Build(); - if (!mkDraft.IsDone()) - return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Failed to create draft")); - - TopoDS_Shape shape = mkDraft.Shape(); - if (shape.IsNull()) + if (shape.isNull()) { return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Resulting shape is null")); + } - if (!isSingleSolidRuleSatisfied(shape)) { + if (!isSingleSolidRuleSatisfied(shape.getShape())) { return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Result has multiple solids: that is not currently supported.")); } diff --git a/src/Mod/PartDesign/Gui/TaskDraftParameters.cpp b/src/Mod/PartDesign/Gui/TaskDraftParameters.cpp index 00116e55cf..868ffb1db8 100644 --- a/src/Mod/PartDesign/Gui/TaskDraftParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskDraftParameters.cpp @@ -301,6 +301,7 @@ TaskDlgDraftParameters::TaskDlgDraftParameters(ViewProviderDraft* DressUpView) parameter = new TaskDraftParameters(DressUpView); Content.push_back(parameter); + Content.push_back(preview); } TaskDlgDraftParameters::~TaskDlgDraftParameters() = default;