From d92b631dad48ae17646efbbfd0cd92a7c7e9089f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Tr=C3=B6ger?= Date: Sat, 5 Aug 2017 09:54:28 +0200 Subject: [PATCH] Make Origins work well with scoped links --- src/App/GroupExtension.cpp | 11 +++++++---- src/App/GroupExtension.h | 2 +- src/App/OriginGroupExtension.cpp | 11 ++++++++++- src/App/OriginGroupExtension.h | 1 + src/Mod/PartDesign/PartDesignTests/TestPad.py | 14 ++++++++++++++ 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/App/GroupExtension.cpp b/src/App/GroupExtension.cpp index 7c403ab6de..ce1d1083fa 100644 --- a/src/App/GroupExtension.cpp +++ b/src/App/GroupExtension.cpp @@ -209,17 +209,20 @@ bool GroupExtension::recursiveHasObject(const DocumentObject* obj, const GroupEx //the purpose is to prevent infinite recursion when groups form a cyclic graph. To do this //we store every group we processed on the current leave of the tree, and if we reach an //already processed group we know that it not really is a tree but a cycle. - history.push_back(this); + //we use hasObject with out recursion to allow override in derived classes + if(group->hasObject(obj, false)) + return true; + + //we checked for the searched object already with hasObject and did not find it, now we need to + //do the same for all subgroups for (auto child : group->Group.getValues()) { if(!child) continue; - if (child == obj) { - return true; - } else if ( child->hasExtension(GroupExtension::getExtensionClassTypeId()) ) { + if ( child->hasExtension(GroupExtension::getExtensionClassTypeId()) ) { auto ext = child->getExtensionByType(); diff --git a/src/App/GroupExtension.h b/src/App/GroupExtension.h index a12ac5ce63..7e504062a7 100644 --- a/src/App/GroupExtension.h +++ b/src/App/GroupExtension.h @@ -83,7 +83,7 @@ public: * @param obj the object to check for. * @param recursive if true check also if the obj is child of some sub group (default is false). */ - bool hasObject(const DocumentObject* obj, bool recursive=false) const; + virtual bool hasObject(const DocumentObject* obj, bool recursive=false) const; /** * Checks whether this group object is a child (or sub-child if enabled) * of the given group object. diff --git a/src/App/OriginGroupExtension.cpp b/src/App/OriginGroupExtension.cpp index 453f6d9e85..6089597426 100644 --- a/src/App/OriginGroupExtension.cpp +++ b/src/App/OriginGroupExtension.cpp @@ -42,7 +42,7 @@ OriginGroupExtension::OriginGroupExtension () { initExtensionType(OriginGroupExtension::getExtensionClassTypeId()); EXTENSION_ADD_PROPERTY_TYPE ( Origin, (0), 0, App::Prop_Hidden, "Origin linked to the group" ); - Origin.setScope(LinkScope::Global); + Origin.setScope(LinkScope::Child); } OriginGroupExtension::~OriginGroupExtension () @@ -193,6 +193,15 @@ std::vector< DocumentObject* > OriginGroupExtension::addObjects(std::vectorhasObject(obj)) + return true; + + return App::GroupExtension::hasObject(obj, recursive); +} + + // Python feature --------------------------------------------------------- diff --git a/src/App/OriginGroupExtension.h b/src/App/OriginGroupExtension.h index eecaef29d0..bb39143f5d 100644 --- a/src/App/OriginGroupExtension.h +++ b/src/App/OriginGroupExtension.h @@ -65,6 +65,7 @@ public: void relinkToOrigin(App::DocumentObject* obj); virtual std::vector addObjects(std::vector obj) override; + virtual bool hasObject(const DocumentObject* obj, bool recursive = false) const override; protected: /// Checks integrity of the Origin diff --git a/src/Mod/PartDesign/PartDesignTests/TestPad.py b/src/Mod/PartDesign/PartDesignTests/TestPad.py index 860bf43464..28f6e9ba6c 100644 --- a/src/Mod/PartDesign/PartDesignTests/TestPad.py +++ b/src/Mod/PartDesign/PartDesignTests/TestPad.py @@ -35,6 +35,20 @@ class TestPad(unittest.TestCase): self.Pad.Profile = self.PadSketch self.Doc.recompute() self.assertEqual(len(self.Pad.Shape.Faces), 6) + + def testSketchOnPlane(self): + self.Body = self.Doc.addObject('PartDesign::Body','Body') + self.PadSketch = self.Doc.addObject('Sketcher::SketchObject','SketchPad') + self.PadSketch.Support = (self.Doc.XY_Plane, ['']) + self.PadSketch.MapMode = 'FlatFace' + self.Body.addObject(self.PadSketch) + TestSketcherApp.CreateSlotPlateSet(self.PadSketch) + self.Doc.recompute() + self.Pad = self.Doc.addObject("PartDesign::Pad","Pad") + self.Pad.Profile = self.PadSketch + self.Body.addObject(self.Pad) + self.Doc.recompute() + self.assertEqual(len(self.Pad.Shape.Faces), 6) def testPadToFirstCase(self): self.Body = self.Doc.addObject('PartDesign::Body','Body')