From 5f6f16e757f78b3714388dfa02bfd657fae88b29 Mon Sep 17 00:00:00 2001 From: Alexander Golubev Date: Fri, 24 Jul 2015 02:57:29 +0300 Subject: [PATCH] PartDesign/FeatureDressUp: implement a proper getBaseObject() The function getBaseShape() is removed and replaced with getBaseObject() because it doesn't make a lot of scense: getBaseShape() masked the base's class implementation (rather than redefine a virtual) which was better in words of code reuse. Also BaseFeature and Base properties relations are defined now in a little another way. --- src/Mod/PartDesign/App/FeatureDressUp.cpp | 33 +++++++++++------------ src/Mod/PartDesign/App/FeatureDressUp.h | 10 ++++--- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/Mod/PartDesign/App/FeatureDressUp.cpp b/src/Mod/PartDesign/App/FeatureDressUp.cpp index dae0a17cb..fba49cc21 100644 --- a/src/Mod/PartDesign/App/FeatureDressUp.cpp +++ b/src/Mod/PartDesign/App/FeatureDressUp.cpp @@ -64,20 +64,18 @@ void DressUp::positionByBaseFeature(void) this->Placement.setValue(base->Placement.getValue()); } -Part::TopoShape DressUp::getBaseShape() +Part::Feature *DressUp::getBaseObject() const { - App::DocumentObject* link = BaseFeature.getValue(); - if (!link) - link = this->Base.getValue(); // For legacy features - if (!link) - throw Base::Exception("No object linked"); - if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) - throw Base::Exception("Linked object is not a Part object"); - Part::Feature* base = static_cast(link); - const Part::TopoShape& shape = base->Shape.getShape(); - if (shape._Shape.IsNull()) - throw Base::Exception("Cannot draft invalid shape"); - return shape; + try { + return Feature::getBaseObject(); + } catch (const Base::Exception &) { + App::DocumentObject* base = Base.getValue(); + if(!base) + throw Base::Exception("No Base object linked"); + if(!base->isDerivedFrom(Part::Feature::getClassTypeId())) + throw Base::Exception("Linked object is not a Part object"); + return static_cast(base); + } } void DressUp::getContiniusEdges(Part::TopoShape TopShape, std::vector< std::string >& SubNames) { @@ -142,20 +140,21 @@ void DressUp::getContiniusEdges(Part::TopoShape TopShape, std::vector< std::stri else { SubNames.erase(SubNames.begin()+i); } - } + } } void DressUp::onChanged(const App::Property* prop) { - // the BaseFeature property should always link to the same feature as the Base + // the BaseFeature property should track the Base and vice-versa as long as + // the feature is inside a body (aka BaseFeature is nonzero) if (prop == &BaseFeature) { - if (Base.getValue() != BaseFeature.getValue()) { + if (BaseFeature.getValue() && Base.getValue() != BaseFeature.getValue()) { Base.setValue (BaseFeature.getValue()); } } else if (prop == &Base) { // track the vice-versa changes - if (Base.getValue() != BaseFeature.getValue()) { + if (BaseFeature.getValue() && Base.getValue() != BaseFeature.getValue()) { BaseFeature.setValue (Base.getValue()); } } diff --git a/src/Mod/PartDesign/App/FeatureDressUp.h b/src/Mod/PartDesign/App/FeatureDressUp.h index 4a9e42ade..35a0155c3 100644 --- a/src/Mod/PartDesign/App/FeatureDressUp.h +++ b/src/Mod/PartDesign/App/FeatureDressUp.h @@ -39,15 +39,19 @@ public: /** * Base feature and it's subelements to which dressup operation will be aplied to. - * It always refers to the same feature Feature::BaseFeature does, but unlike it - * the Base property also includes SubLinks. + * Unlike Feature::BaseFeature it includes Sublinks and set not only inside a body. + * But for consistancy if BaseFeature is nonzero this links to the same body as it. */ App::PropertyLinkSub Base; short mustExecute() const; /// updates the Placement property from the Placement of the BaseFeature void positionByBaseFeature(void); - Part::TopoShape getBaseShape(); + /** + * Returns the BaseFeature property's object if it's set othervice returns Base's + * feature property object otherviceeature property's object (if any) + */ + virtual Part::Feature* getBaseObject() const; /// extracts all edges from the subshapes (inkluding face edges) and furthermore adds /// all C0 continius edges to the vector void getContiniusEdges(Part::TopoShape, std::vector< std::string >&);