diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 334956a70b..5d9ae049f9 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -8826,6 +8826,22 @@ void SketchObject::rebuildExternalGeometry(std::optional extToAdd { Base::StateLocker lock(managedoperation, true); // no need to check input data validity as this is an sketchobject managed operation. + // Analyze the state of existing external geometries to infer the desired state for new ones. + // If any geometry from a source link is "defining", we'll treat the whole link as "defining". + std::map linkIsDefiningMap; + for (const auto& geo : ExternalGeo.getValues()) { + auto egf = ExternalGeometryFacade::getFacade(geo); + if (!egf->getRef().empty()) { + bool isDefining = egf->testFlag(ExternalGeometryExtension::Defining); + if (linkIsDefiningMap.find(egf->getRef()) == linkIsDefiningMap.end()) { + linkIsDefiningMap[egf->getRef()] = isDefining; + } + else { + linkIsDefiningMap[egf->getRef()] = linkIsDefiningMap[egf->getRef()] && isDefining; + } + } + } + // get the actual lists of the externals auto Types = ExternalTypes.getValues(); auto Objects = ExternalGeometry.getValues(); @@ -9135,10 +9151,20 @@ void SketchObject::rebuildExternalGeometry(std::optional extToAdd // now update the geometries for(auto &geos : newGeos) { + if (geos.empty()) { + continue; + } + + // Get the reference key for this group of geometries. All geos in this vector share the same ref. + const std::string& key = ExternalGeometryFacade::getFacade(geos.front().get())->getRef(); + bool isLinkDefining = linkIsDefiningMap.count(key) ? linkIsDefiningMap[key] : false; + for(auto &geo : geos) { auto it = externalGeoMap.find(GeometryFacade::getId(geo.get())); if(it == externalGeoMap.end()) { // This is a new geometries. + // Set its defining state based on the inferred state of its parent link. + ExternalGeometryFacade::getFacade(geo.get())->setFlag(ExternalGeometryExtension::Defining, isLinkDefining); geoms.push_back(geo.release()); continue; }