Extensions: Fix GeoFeatureGroup drag&drop
This commit is contained in:
@@ -129,6 +129,69 @@ void OriginGroupExtension::onExtendedUnsetupObject () {
|
||||
GeoFeatureGroupExtension::onExtendedUnsetupObject ();
|
||||
}
|
||||
|
||||
void OriginGroupExtension::relinkToOrigin(App::DocumentObject* obj)
|
||||
{
|
||||
//we get all links and replace the origin objects if needed (subnames need not to change, they
|
||||
//would stay the same)
|
||||
std::vector< App::DocumentObject* > result;
|
||||
std::vector<App::Property*> list;
|
||||
obj->getPropertyList(list);
|
||||
for(App::Property* prop : list) {
|
||||
if(prop->getTypeId().isDerivedFrom(App::PropertyLink::getClassTypeId())) {
|
||||
|
||||
auto p = static_cast<App::PropertyLink*>(prop);
|
||||
if(!p->getValue() || !p->getValue()->isDerivedFrom(App::OriginFeature::getClassTypeId()))
|
||||
continue;
|
||||
|
||||
p->setValue(getOrigin()->getOriginFeature(static_cast<OriginFeature*>(p->getValue())->Role.getValue()));
|
||||
}
|
||||
else if(prop->getTypeId().isDerivedFrom(App::PropertyLinkList::getClassTypeId())) {
|
||||
auto p = static_cast<App::PropertyLinkList*>(prop);
|
||||
auto vec = p->getValues();
|
||||
std::vector<App::DocumentObject*> result;
|
||||
bool changed = false;
|
||||
for(App::DocumentObject* o : vec) {
|
||||
if(!o || !o->isDerivedFrom(App::OriginFeature::getClassTypeId()))
|
||||
result.push_back(o);
|
||||
else {
|
||||
result.push_back(getOrigin()->getOriginFeature(static_cast<OriginFeature*>(o)->Role.getValue()));
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if(changed)
|
||||
static_cast<App::PropertyLinkList*>(prop)->setValues(result);
|
||||
}
|
||||
else if(prop->getTypeId().isDerivedFrom(App::PropertyLinkSub::getClassTypeId())) {
|
||||
auto p = static_cast<App::PropertyLinkSub*>(prop);
|
||||
if(!p->getValue() || !p->getValue()->isDerivedFrom(App::OriginFeature::getClassTypeId()))
|
||||
continue;
|
||||
|
||||
p->setValue(getOrigin()->getOriginFeature(static_cast<OriginFeature*>(p->getValue())->Role.getValue()));
|
||||
}
|
||||
else if(prop->getTypeId().isDerivedFrom(App::PropertyLinkSubList::getClassTypeId())) {
|
||||
auto p = static_cast<App::PropertyLinkList*>(prop);
|
||||
auto vec = p->getValues();
|
||||
std::vector<App::DocumentObject*> result;
|
||||
bool changed = false;
|
||||
for(App::DocumentObject* o : vec) {
|
||||
if(!o || !o->isDerivedFrom(App::OriginFeature::getClassTypeId()))
|
||||
result.push_back(o);
|
||||
else {
|
||||
result.push_back(getOrigin()->getOriginFeature(static_cast<OriginFeature*>(o)->Role.getValue()));
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if(changed)
|
||||
static_cast<App::PropertyLinkList*>(prop)->setValues(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OriginGroupExtension::addObject(DocumentObject* obj) {
|
||||
relinkToOrigin(obj);
|
||||
App::GeoFeatureGroupExtension::addObject(obj);
|
||||
}
|
||||
|
||||
|
||||
// Python feature ---------------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user