PartDesign: change SubShapeBinder claim children behavior

This commit is contained in:
Zheng, Lei
2020-03-04 21:02:07 +08:00
committed by wwmayer
parent 709cc591fd
commit 4364efca47
3 changed files with 61 additions and 3 deletions

View File

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

View File

@@ -106,6 +106,9 @@ public:
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;

View File

@@ -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;
}