Skip to content

Commit

Permalink
Fix drag&drop of geofeature groups. fixes #2835 fixes #2796
Browse files Browse the repository at this point in the history
  • Loading branch information
ickby authored and wwmayer committed Jun 19, 2017
1 parent 9ccb01e commit f3358ad
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/App/ExtensionContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ bool ExtensionContainer::hasExtension(const std::string& name) const {
}


Extension* ExtensionContainer::getExtension(Base::Type t) {
Extension* ExtensionContainer::getExtension(Base::Type t) const {

auto result = _extensions.find(t);
if(result == _extensions.end()) {
Expand All @@ -115,7 +115,7 @@ bool ExtensionContainer::hasExtensions() const {
return !_extensions.empty();
}

Extension* ExtensionContainer::getExtension(const std::string& name) {
Extension* ExtensionContainer::getExtension(const std::string& name) const {

//and for types derived from it, as they can be cast to the extension
for(auto entry : _extensions) {
Expand Down
6 changes: 3 additions & 3 deletions src/App/ExtensionContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ class AppExport ExtensionContainer : public App::PropertyContainer
bool hasExtension(Base::Type) const; //returns first of type (or derived from) and throws otherwise
bool hasExtension(const std::string& name) const; //this version does not check derived classes
bool hasExtensions() const;
App::Extension* getExtension(Base::Type); //returns first of type (or derived from) and throws otherwise
App::Extension* getExtension(const std::string& name); //this version does not check derived classes
App::Extension* getExtension(Base::Type) const;
App::Extension* getExtension(const std::string& name) const; //this version does not check derived classes

//returns first of type (or derived from) and throws otherwise
template<typename ExtensionT>
ExtensionT* getExtensionByType() {
ExtensionT* getExtensionByType() const {
return dynamic_cast<ExtensionT*>(getExtension(ExtensionT::getExtensionClassTypeId()));
};

Expand Down
8 changes: 4 additions & 4 deletions src/App/GeoFeatureGroupExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ std::vector<App::DocumentObject*> GeoFeatureGroupExtension::getGeoSubObjects ()
std::set<App::DocumentObject*> nextSearchSet;
for ( auto obj: curSearchSet) {
if ( isNonGeoGroup (obj) ) {
const App::DocumentObjectGroup *grp = static_cast<const App::DocumentObjectGroup *> (obj);
auto *grp = obj->getExtensionByType<App::GroupExtension>();
// Check if we havent already processed the element may happen in case of nontree structure
// Note: if the condition is false this generally indicates malformed structure
if ( processedGroups.find (grp) == processedGroups.end() ) {
Expand Down Expand Up @@ -127,7 +127,7 @@ bool GeoFeatureGroupExtension::geoHasObject (const DocumentObject* obj) const {
std::set<const App::DocumentObject*> nextSearchSet;
for ( auto obj: curSearchSet) {
if ( isNonGeoGroup (obj) ) {
const App::DocumentObjectGroup *grp = static_cast<const App::DocumentObjectGroup *> (obj);
auto *grp = obj->getExtensionByType<App::GroupExtension>();
if ( processedGroups.find (grp) == processedGroups.end() ) {
processedGroups.insert ( grp );
const auto & objs = grp->Group.getValues();
Expand All @@ -148,11 +148,11 @@ DocumentObject* GeoFeatureGroupExtension::getGroupOfObject(const DocumentObject*
GeoFeatureGroupExtension* grp = (*it)->getExtensionByType<GeoFeatureGroupExtension>();
if ( indirect ) {
if (grp->geoHasObject(obj)) {
return dynamic_cast<App::DocumentObject*>(grp);
return grp->getExtendedObject();
}
} else {
if (grp->hasObject(obj)) {
return dynamic_cast<App::DocumentObject*>(grp);
return grp->getExtendedObject();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/App/GeoFeatureGroupExtension.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class AppExport GeoFeatureGroupExtension : public App::GroupExtension

/// Returns true if the given DocumentObject is DocumentObjectGroup but not GeoFeatureGroup
static bool isNonGeoGroup(const DocumentObject* obj) {
return obj->hasExtension(GroupExtension::getExtensionClassTypeId()) &
return obj->hasExtension(GroupExtension::getExtensionClassTypeId()) &&
!obj->hasExtension(GeoFeatureGroupExtension::getExtensionClassTypeId());
}
};
Expand Down
9 changes: 7 additions & 2 deletions src/Gui/ViewProviderGeoFeatureGroupExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ std::vector< App::DocumentObject* > ViewProviderGeoFeatureGroupExtension::getLin
if(!obj)
return std::vector< App::DocumentObject* >();

//we get all linked objects, and that recursively
//if the object is a geofeaturegroup than all dependencies belong to that CS, we are not allowed
//to grap them
if(obj->hasExtension(App::GeoFeatureGroupExtension::getExtensionClassTypeId()))
return std::vector< App::DocumentObject* >();

//we get all linked objects
std::vector< App::DocumentObject* > result;
std::vector<App::Property*> list;
obj->getPropertyList(list);
Expand All @@ -123,7 +128,7 @@ std::vector< App::DocumentObject* > ViewProviderGeoFeatureGroupExtension::getLin

//collect all dependencies of those objects
std::vector< App::DocumentObject* > links;
for(App::DocumentObject *obj : result) {
for(App::DocumentObject *obj : result) {
auto vec = getLinkedObjects(obj);
links.insert(links.end(), vec.begin(), vec.end());
}
Expand Down

0 comments on commit f3358ad

Please sign in to comment.