Extensions: Fix GeoFeatureGroup drag&drop
This commit is contained in:
@@ -57,7 +57,7 @@ void GeoFeatureGroupExtension::initExtension(ExtensionContainer* obj) {
|
||||
if(!obj->isDerivedFrom(App::GeoFeature::getClassTypeId()))
|
||||
throw Base::Exception("GeoFeatureGroupExtension can only be applied to GeoFeatures");
|
||||
|
||||
App::Extension::initExtension(obj);
|
||||
App::GroupExtension::initExtension(obj);
|
||||
}
|
||||
|
||||
PropertyPlacement& GeoFeatureGroupExtension::placement() {
|
||||
@@ -143,9 +143,9 @@ bool GeoFeatureGroupExtension::geoHasObject (const DocumentObject* obj) const {
|
||||
DocumentObject* GeoFeatureGroupExtension::getGroupOfObject(const DocumentObject* obj, bool indirect)
|
||||
{
|
||||
const Document* doc = obj->getDocument();
|
||||
std::vector<DocumentObject*> grps = doc->getObjectsOfType(GeoFeatureGroupExtension::getExtensionClassTypeId());
|
||||
std::vector<DocumentObject*> grps = doc->getObjectsWithExtension(GeoFeatureGroupExtension::getExtensionClassTypeId());
|
||||
for (std::vector<DocumentObject*>::const_iterator it = grps.begin(); it != grps.end(); ++it) {
|
||||
GeoFeatureGroupExtension* grp = (GeoFeatureGroupExtension*)(*it);
|
||||
GeoFeatureGroupExtension* grp = (*it)->getExtensionByType<GeoFeatureGroupExtension>();
|
||||
if ( indirect ) {
|
||||
if (grp->geoHasObject(obj)) {
|
||||
return dynamic_cast<App::DocumentObject*>(grp);
|
||||
|
||||
@@ -63,6 +63,11 @@ void GroupExtension::addObject(DocumentObject* obj)
|
||||
if(!allowObject(obj))
|
||||
return;
|
||||
|
||||
//only one group per object
|
||||
auto *group = App::GroupExtension::getGroupOfObject(obj);
|
||||
if(group && group != getExtendedObject())
|
||||
group->getExtensionByType<App::GroupExtension>()->removeObject(obj);
|
||||
|
||||
if (!hasObject(obj)) {
|
||||
std::vector<DocumentObject*> grp = Group.getValues();
|
||||
grp.push_back(obj);
|
||||
@@ -180,9 +185,9 @@ int GroupExtension::countObjectsOfType(const Base::Type& typeId) const
|
||||
DocumentObject* GroupExtension::getGroupOfObject(const DocumentObject* obj)
|
||||
{
|
||||
const Document* doc = obj->getDocument();
|
||||
std::vector<DocumentObject*> grps = doc->getObjectsOfType(GroupExtension::getExtensionClassTypeId());
|
||||
std::vector<DocumentObject*> grps = doc->getObjectsWithExtension(GroupExtension::getExtensionClassTypeId());
|
||||
for (std::vector<DocumentObject*>::const_iterator it = grps.begin(); it != grps.end(); ++it) {
|
||||
GroupExtension* grp = (GroupExtension*)(*it);
|
||||
GroupExtension* grp = (*it)->getExtensionByType<GroupExtension>();
|
||||
if (grp->hasObject(obj))
|
||||
return *it;
|
||||
}
|
||||
|
||||
@@ -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 ---------------------------------------------------------
|
||||
|
||||
|
||||
@@ -62,6 +62,11 @@ public:
|
||||
|
||||
/// Origin linked to the group
|
||||
PropertyLink Origin;
|
||||
|
||||
//changes all links of obj to a origin to point to this groupes origin
|
||||
void relinkToOrigin(App::DocumentObject* obj);
|
||||
|
||||
virtual void addObject(DocumentObject* obj);
|
||||
|
||||
protected:
|
||||
/// Checks integrity of the Origin
|
||||
|
||||
Reference in New Issue
Block a user