Make Origins work well with scoped links

This commit is contained in:
Stefan Tröger
2017-08-05 09:54:28 +02:00
committed by wmayer
parent febfed3c6c
commit 700741471f
5 changed files with 33 additions and 6 deletions

View File

@@ -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<GroupExtension>();

View File

@@ -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.

View File

@@ -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::vector<Docu
return App::GeoFeatureGroupExtension::addObjects(objs);
}
bool OriginGroupExtension::hasObject(const DocumentObject* obj, bool recursive) const {
if(obj == getOrigin() || getOrigin()->hasObject(obj))
return true;
return App::GroupExtension::hasObject(obj, recursive);
}
// Python feature ---------------------------------------------------------

View File

@@ -65,6 +65,7 @@ public:
void relinkToOrigin(App::DocumentObject* obj);
virtual std::vector<DocumentObject*> addObjects(std::vector<DocumentObject*> obj) override;
virtual bool hasObject(const DocumentObject* obj, bool recursive = false) const override;
protected:
/// Checks integrity of the Origin

View File

@@ -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')