Repository: FreeCAD/FreeCAD
File: src/App/GeoFeatureGroupExtension.cpp (C++)

Code before:
        if (parent && parent->hasObject(group->getExtendedObject())) {
            // Cyclic dependencies detected
            if (history.contains(parent)) {
                break;
            }
            return recursiveGroupPlacement(parent, history) * group->placement().getValue();
        }
    }

    return group->placement().getValue();
}

std::vector<DocumentObject*>
GeoFeatureGroupExtension::addObjects(std::vector<App::DocumentObject*> objects)
{

    std::vector<DocumentObject*> grp = Group.getValues();
    std::vector<DocumentObject*> ret;

    for (auto object : objects) {

        if (!allowObject(object)) {
            continue;
        }
        if (object->hasExtension(App::GeoFeatureGroupExtension::getExtensionClassTypeId())) {

            if (!hasObject(object)) {
                grp.push_back(object);
                ret.push_back(object);
            }
            continue;
        }

        // cross CoordinateSystem links are not allowed, so we need to move the whole link group
        std::vector<App::DocumentObject*> links = getCSRelevantLinks(object);
        links.push_back(object);

        for (auto obj : links) {
            // only one geofeaturegroup per object.
            auto* group = App::GeoFeatureGroupExtension::getGroupOfObject(obj);
            if (group && group != getExtendedObject()) {
                group->getExtensionByType<App::GroupExtension>()->removeObject(obj);
            }

            if (!hasObject(obj)) {
                grp.push_back(obj);
                ret.push_back(obj);
            }
        }
    }


Review comment (bug):
This could use a comment explaining why this code is here (and probably a link to the bug it's fixing).

Code after:
        if (parent && parent->hasObject(group->getExtendedObject())) {
            // Cyclic dependencies detected
            if (history.contains(parent)) {
                break;
            }
            return recursiveGroupPlacement(parent, history) * group->placement().getValue();
        }
    }

    return group->placement().getValue();
}

std::vector<DocumentObject*>
GeoFeatureGroupExtension::addObjects(std::vector<App::DocumentObject*> objects)
{

    std::vector<DocumentObject*> grp = Group.getValues();
    std::vector<DocumentObject*> ret;

    for (auto object : objects) {

        if (!allowObject(object)) {
            continue;
        }

        // Prevent from extracting children of nested groups fixed issue:#26743
        // As groups manage their own local coordinate systems and children.
        if (object->hasExtension(App::GeoFeatureGroupExtension::getExtensionClassTypeId())) {
            if (!hasObject(object)) {
                grp.push_back(object);
                ret.push_back(object);
            }
            continue;
        }

        // cross CoordinateSystem links are not allowed, so we need to move the whole link group
        std::vector<App::DocumentObject*> links = getCSRelevantLinks(object);
        links.push_back(object);

        for (auto obj : links) {
            // only one geofeaturegroup per object.
            auto* group = App::GeoFeatureGroupExtension::getGroupOfObject(obj);
            if (group && group != getExtendedObject()) {
                group->getExtensionByType<App::GroupExtension>()->removeObject(obj);
            }

            if (!hasObject(obj)) {
                grp.push_back(obj);
                ret.push_back(obj);
            }
        }