App/Toponaming: import SubObjectT dependencies for SubShapeBinder

* Formatted and refactored code imported for the DocumentObject class
 * Formatted and refactored code imported for the SubObjectT class

Signed-off-by: CalligaroV <vincenzo.calligaro@gmail.com>
This commit is contained in:
CalligaroV
2024-04-11 18:09:40 +02:00
committed by Chris Hennes
parent ceb5478a37
commit 243e20248d
5 changed files with 127 additions and 84 deletions

View File

@@ -888,70 +888,93 @@ DocumentObject *DocumentObject::getSubObject(const char *subname,
return ret;
}
namespace
{
std::vector<DocumentObject*>
DocumentObject::getSubObjectList(const char *subname,
std::vector<int> *sublist,
bool flatten) const
getSubObjectListFlatten(const std::vector<App::DocumentObject*>& resNotFlatten,
std::vector<int>* const subsizes,
const App::DocumentObject* sobj,
App::DocumentObject** container,
bool& lastChild)
{
auto res {resNotFlatten};
auto linked = sobj->getLinkedObject();
if (container) {
auto grp = App::GeoFeatureGroupExtension::getGroupOfObject(linked);
if (grp != *container) {
container = nullptr;
}
else {
if (lastChild && !res.empty()) {
res.pop_back();
if (subsizes) {
subsizes->pop_back();
}
}
lastChild = true;
}
}
if (linked->getExtensionByType<App::GeoFeatureGroupExtension>(true)) {
*container = linked;
lastChild = false;
}
else if (linked != sobj || sobj->hasChildElement()) {
// Check for Link or LinkGroup
container = nullptr;
}
else if (auto ext = sobj->getExtensionByType<LinkBaseExtension>(true)) {
// check for Link array
if (ext->getElementCountValue() != 0) {
container = nullptr;
}
}
return res;
}
} // namespace
std::vector<DocumentObject*> DocumentObject::getSubObjectList(const char* subname,
std::vector<int>* const subsizes,
bool flatten) const
{
std::vector<DocumentObject*> res;
res.push_back(const_cast<DocumentObject*>(this));
if (sublist) sublist->push_back(0);
if(!subname || !subname[0])
if (subsizes) {
subsizes->push_back(0);
}
if (!subname || (subname[0] == 0)) {
return res;
}
auto element = Data::findElementName(subname);
std::string sub(subname,element-subname);
App::DocumentObject *container = nullptr;
std::string sub(subname, element - subname);
App::DocumentObject* container = nullptr;
bool lastChild = false;
if (flatten) {
auto linked = getLinkedObject();
if (linked->getExtensionByType<App::GeoFeatureGroupExtension>(true))
if (linked->getExtensionByType<App::GeoFeatureGroupExtension>(true)) {
container = const_cast<DocumentObject*>(this);
}
else if (auto grp = App::GeoFeatureGroupExtension::getGroupOfObject(linked)) {
container = grp;
lastChild = true;
}
}
for(auto pos=sub.find('.');pos!=std::string::npos;pos=sub.find('.',pos+1)) {
char c = sub[pos+1];
sub[pos+1] = 0;
for (auto pos = sub.find('.'); pos != std::string::npos; pos = sub.find('.', pos + 1)) {
char subTail = sub[pos + 1];
sub[pos + 1] = 0;
auto sobj = getSubObject(sub.c_str());
if(!sobj || !sobj->isAttachedToDocument())
if (!sobj || !sobj->isAttachedToDocument()) {
continue;
}
if (flatten) {
auto linked = sobj->getLinkedObject();
if (container) {
auto grp = App::GeoFeatureGroupExtension::getGroupOfObject(linked);
if (grp != container)
container = nullptr;
else {
if (lastChild && res.size()) {
res.pop_back();
if (sublist)
sublist->pop_back();
}
lastChild = true;
}
}
if (linked->getExtensionByType<App::GeoFeatureGroupExtension>(true)) {
container = linked;
lastChild = false;
}
else if (linked != sobj || sobj->hasChildElement()) {
// Check for Link or LinkGroup
container = nullptr;
}
else if (auto ext = sobj->getExtensionByType<LinkBaseExtension>(true)) {
// check for Link array
if (ext->getElementCountValue())
container = nullptr;
}
res = getSubObjectListFlatten(res, subsizes, sobj, &container, lastChild);
}
res.push_back(sobj);
if (sublist)
sublist->push_back(pos+1);
sub[pos+1] = c;
if (subsizes) {
subsizes->push_back((int)pos + 1);
}
sub[pos + 1] = subTail;
}
return res;
}