Skip to content

Commit

Permalink
PartDesign: change SubShapeBinder claim children behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
realthunder authored and wwmayer committed Mar 20, 2020
1 parent 4a26bd0 commit d949447
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
38 changes: 38 additions & 0 deletions src/Mod/PartDesign/App/ShapeBinder.cpp
Expand Up @@ -301,6 +301,44 @@ void SubShapeBinder::setupObject() {
checkPropertyStatus();
}

App::DocumentObject *SubShapeBinder::getSubObject(const char *subname, PyObject **pyObj,
Base::Matrix4D *mat, bool transform, int depth) const
{
auto sobj = Part::Feature::getSubObject(subname,pyObj,mat,transform,depth);
if(sobj)
return sobj;
if(Data::ComplexGeoData::findElementName(subname)==subname)
return nullptr;

const char *dot = strchr(subname, '.');
if(!dot)
return nullptr;

App::GetApplication().checkLinkDepth(depth);
std::string name(subname,dot-subname);
for(auto &l : Support.getSubListValues()) {
auto obj = l.getValue();
if(!obj || !obj->getNameInDocument())
continue;
for(auto &sub : l.getSubValues()) {
auto sobj = obj->getSubObject(sub.c_str());
if(!sobj || !sobj->getNameInDocument())
continue;
if(subname[0] == '$') {
if(sobj->Label.getStrValue() != name.c_str()+1)
continue;
} else if(!boost::equals(sobj->getNameInDocument(), name))
continue;
name = Data::ComplexGeoData::noElementName(sub.c_str());
name += dot+1;
if(mat && transform)
*mat *= Placement.getValue().toMatrix();
return obj->getSubObject(name.c_str(),pyObj,mat,true,depth+1);
}
}
return nullptr;
}

void SubShapeBinder::update(SubShapeBinder::UpdateOption options) {
Part::TopoShape result;
std::vector<Part ::TopoShape> shapes;
Expand Down
3 changes: 3 additions & 0 deletions src/Mod/PartDesign/App/ShapeBinder.h
Expand Up @@ -106,6 +106,9 @@ class PartDesignExport SubShapeBinder : public Part::Feature {

virtual bool canLinkProperties() const override {return false;}

virtual App::DocumentObject *getSubObject(const char *subname, PyObject **pyObj=0,
Base::Matrix4D *mat=0, bool transform=true, int depth=0) const override;

protected:
virtual App::DocumentObjectExecReturn* execute(void) override;
virtual void onChanged(const App::Property *prop) override;
Expand Down
23 changes: 20 additions & 3 deletions src/Mod/PartDesign/Gui/ViewProviderShapeBinder.cpp
Expand Up @@ -343,9 +343,26 @@ void ViewProviderSubShapeBinder::updatePlacement(bool transaction) {

std::vector<App::DocumentObject*> ViewProviderSubShapeBinder::claimChildren(void) const {
std::vector<App::DocumentObject *> ret;
auto self = dynamic_cast<PartDesign::SubShapeBinder*>(getObject());
if(self && self->ClaimChildren.getValue() && self->Support.getValue())
ret.push_back(self->Support.getValue());
auto self = Base::freecad_dynamic_cast<PartDesign::SubShapeBinder>(getObject());
if(self && self->ClaimChildren.getValue() && self->Support.getValue()) {
std::set<App::DocumentObject *> objSet;
for(auto &l : self->Support.getSubListValues()) {
auto obj = l.getValue();
if(!obj)
continue;
const auto &subs = l.getSubValues();
if(subs.empty()) {
if(objSet.insert(obj).second)
ret.push_back(obj);
continue;
}
for(auto &sub : subs) {
auto sobj = obj->getSubObject(sub.c_str());
if(sobj && objSet.insert(sobj).second)
ret.push_back(sobj);
}
}
}
return ret;
}

0 comments on commit d949447

Please sign in to comment.