From ae6f7f25e8bc5a73d1e4baa1287ad6b44e89dbbf Mon Sep 17 00:00:00 2001 From: bgbsww Date: Tue, 9 Jul 2024 17:59:26 -0400 Subject: [PATCH] Toponaming: Missing suppress property and code --- src/Mod/Part/App/TopoShape.h | 2 + src/Mod/Part/App/TopoShapeExpansion.cpp | 26 +++++++++++ src/Mod/PartDesign/App/Feature.cpp | 57 +++++++++++++++++++++++++ src/Mod/PartDesign/App/Feature.h | 4 ++ 4 files changed, 89 insertions(+) diff --git a/src/Mod/Part/App/TopoShape.h b/src/Mod/Part/App/TopoShape.h index cceb920f8e..f67ce107e4 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -1438,6 +1438,8 @@ public: const char* marker = nullptr, std::string* postfix = nullptr) const; + long isElementGenerated(const Data::MappedName &name, int depth=1) const; + /** @name sub shape cached functions * * Mapped element names introduces some overhead when getting sub shapes diff --git a/src/Mod/Part/App/TopoShapeExpansion.cpp b/src/Mod/Part/App/TopoShapeExpansion.cpp index da60bf6a74..f8e3c6b4c0 100644 --- a/src/Mod/Part/App/TopoShapeExpansion.cpp +++ b/src/Mod/Part/App/TopoShapeExpansion.cpp @@ -5756,6 +5756,32 @@ bool TopoShape::isSame(const Data::ComplexGeoData& _other) const const auto& other = static_cast(_other); return Tag == other.Tag && Hasher == other.Hasher && _Shape.IsEqual(other._Shape); } + +long TopoShape::isElementGenerated(const Data::MappedName& _name, int depth) const +{ + long res = 0; + long tag = 0; + traceElement(_name, [&](const Data::MappedName& name, int offset, long tag2, long) { + (void)offset; + if (tag2 < 0) { + tag2 = -tag2; + } + if (tag && tag2 != tag) { + if (--depth < 1) { + return true; + } + } + tag = tag2; + if (depth == 1 && name.startsWith(genPostfix(), offset)) { + res = tag; + return true; + } + return false; + }); + + return res; +} + void TopoShape::cacheRelatedElements(const Data::MappedName& name, HistoryTraceType sameType, const QVector& names) const diff --git a/src/Mod/PartDesign/App/Feature.cpp b/src/Mod/PartDesign/App/Feature.cpp index 18330a374c..1614a9c94b 100644 --- a/src/Mod/PartDesign/App/Feature.cpp +++ b/src/Mod/PartDesign/App/Feature.cpp @@ -57,6 +57,7 @@ Feature::Feature() ADD_PROPERTY(BaseFeature,(nullptr)); ADD_PROPERTY_TYPE(_Body,(nullptr),"Base",(App::PropertyType)( App::Prop_ReadOnly|App::Prop_Hidden|App::Prop_Output|App::Prop_Transient),0); + ADD_PROPERTY(SuppressedShape,(TopoShape())); Placement.setStatus(App::Property::Hidden, true); BaseFeature.setStatus(App::Property::Hidden, true); @@ -68,6 +69,37 @@ Feature::Feature() App::DocumentObjectExecReturn* Feature::recompute() { +#ifdef FC_USE_TNP_FIX + SuppressedShape.setValue(TopoShape()); + + if (!Suppressed.getValue()) { + return Part::Feature::recompute(); + } + + bool failed = false; + try { + std::unique_ptr ret(Part::Feature::recompute()); + if (ret) { + throw Base::RuntimeError(ret->Why); + } + } + catch (Base::AbortException&) { + throw; + } + catch (Base::Exception& e) { + failed = true; + e.ReportException(); + FC_ERR("Failed to recompute suppressed feature " << getFullName()); + } + + if (!failed) { + updateSuppressedShape(); + } + else { + Shape.setValue(getBaseTopoShape(true)); + } + return App::DocumentObject::StdReturn; +#else try { auto baseShape = getBaseTopoShape(); if (Suppressed.getValue()) { @@ -81,6 +113,31 @@ App::DocumentObjectExecReturn* Feature::recompute() } return DocumentObject::recompute(); +#endif +} + +void Feature::updateSuppressedShape() +{ + auto baseShape = getBaseTopoShape(true); + TopoShape res(getID()); + TopoShape shape = Shape.getShape(); + shape.setPlacement(Base::Placement()); + std::vector generated; + if(!shape.isNull()) { + unsigned count = shape.countSubShapes(TopAbs_FACE); + for(unsigned i=1; i<=count; ++i) { + Data::MappedName mapped = shape.getMappedName( + Data::IndexedName::fromConst("Face", i)); + if(mapped && shape.isElementGenerated(mapped)) + generated.push_back(shape.getSubTopoShape(TopAbs_FACE, i)); + } + } + if(!generated.empty()) { + res.makeElementCompound(generated); + res.setPlacement(Placement.getValue()); + } + Shape.setValue(baseShape); + SuppressedShape.setValue(res); } short Feature::mustExecute() const diff --git a/src/Mod/PartDesign/App/Feature.h b/src/Mod/PartDesign/App/Feature.h index 916aa03100..06713a94be 100644 --- a/src/Mod/PartDesign/App/Feature.h +++ b/src/Mod/PartDesign/App/Feature.h @@ -58,6 +58,8 @@ public: App::PropertyLink BaseFeature; App::PropertyLinkHidden _Body; + /// Keep a copy of suppressed shapes so that we can restore them (and maybe display them) + Part::PropertyPartShape SuppressedShape; App::DocumentObjectExecReturn* recompute() override; short mustExecute() const override; @@ -108,6 +110,8 @@ protected: bool isSingleSolidRuleSatisfied(const TopoDS_Shape&, TopAbs_ShapeEnum type = TopAbs_SOLID); SingleSolidRuleMode singleSolidRuleMode(); + void updateSuppressedShape(); + /// Grab any point from the given face static const gp_Pnt getPointFromFace(const TopoDS_Face& f); /// Make a shape from a base plane (convenience method)