From 95a058c4ecddf5cacdc07d1ca6fbf310c83fd386 Mon Sep 17 00:00:00 2001 From: Eric Wassail Date: Fri, 3 Nov 2023 15:33:09 -0400 Subject: [PATCH 1/4] call update representations on child elements as well --- Elements/src/Model.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Elements/src/Model.cs b/Elements/src/Model.cs index 013a41f6e..018caa951 100644 --- a/Elements/src/Model.cs +++ b/Elements/src/Model.cs @@ -37,9 +37,8 @@ public class Model /// /// Collection of subelements from shared objects or RepresentationInstances (e.g. SolidRepresentation.Profile or RepresentationInstance.Material). - /// /// We do not serialize shared objects to json, but we do include them in other formats like gltf. - /// This collection contains all elements referenced directly by RepresentationInstances, such as Materials and Profiles. + /// This collection contains all elements referenced directly by RepresentationInstances, such as Materials and Profiles. /// These objects affect representation appearance and may be used at glTF creation time. /// [JsonIgnore] @@ -136,6 +135,10 @@ public void AddElement(Element element, bool gatherSubElements = true, bool upda { if (!this.Elements.ContainsKey(e.Id)) { + if (updateElementRepresentations && e is GeometricElement geoE) + { + geoE.UpdateRepresentations(); + } this.Elements.Add(e.Id, e); } } From 6d07083110deb73e81bd600da8ae2f940c84a165 Mon Sep 17 00:00:00 2001 From: Eric Wassail Date: Fri, 3 Nov 2023 15:41:38 -0400 Subject: [PATCH 2/4] update notes --- Elements/src/Model.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Elements/src/Model.cs b/Elements/src/Model.cs index 018caa951..bdf90a085 100644 --- a/Elements/src/Model.cs +++ b/Elements/src/Model.cs @@ -110,14 +110,7 @@ public void AddElement(Element element, bool gatherSubElements = true, bool upda return; } - // Some elements compute profiles and transforms - // during UpdateRepresentation. Call UpdateRepresentation - // here to ensure these values are correct in the JSON. - - // TODO: This is really expensive. This should be removed - // when all internal types have been updated to not create elements - // during UpdateRepresentation. This is now possible because - // geometry operations are reactive to changes in their properties. + // Function wrapper code no longer calls UpdateRepresentations, so we need to do it here. if (updateElementRepresentations && element is GeometricElement geo) { geo.UpdateRepresentations(); @@ -135,6 +128,8 @@ public void AddElement(Element element, bool gatherSubElements = true, bool upda { if (!this.Elements.ContainsKey(e.Id)) { + // Because function wrapper code doesn't called UpdateRepresentations any more + // we need to call it her for all nested elements while they are added. if (updateElementRepresentations && e is GeometricElement geoE) { geoE.UpdateRepresentations(); From 782cbd814bd3afb82ef431d28681a279bc6d9a89 Mon Sep 17 00:00:00 2001 From: Eric Wassail Date: Fri, 3 Nov 2023 17:20:05 -0400 Subject: [PATCH 3/4] fix default toJson behavior --- Elements/src/Model.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Elements/src/Model.cs b/Elements/src/Model.cs index bdf90a085..8aeca127b 100644 --- a/Elements/src/Model.cs +++ b/Elements/src/Model.cs @@ -270,8 +270,10 @@ public void ToJson(MemoryStream stream, bool indent = false, bool gatherSubEleme /// public string ToJson() { - // The arguments here are meant to match the default arguments of the ToJson(bool, bool) method above. - return ToJson(false, true); + // By default we don't want to update representations because the UpdateRepresentation + // method is called during function adding. Setting this to false makes the behavior + // match our function wrapping code behavior. + return ToJson(false, true, false); } /// From 2f62321cd55e153f56cf90ea060fcd023b44a9cb Mon Sep 17 00:00:00 2001 From: Eric Wassail Date: Mon, 6 Nov 2023 10:40:55 -0500 Subject: [PATCH 4/4] spelling --- Elements/src/Model.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Elements/src/Model.cs b/Elements/src/Model.cs index 8aeca127b..f0a6c689a 100644 --- a/Elements/src/Model.cs +++ b/Elements/src/Model.cs @@ -128,8 +128,8 @@ public void AddElement(Element element, bool gatherSubElements = true, bool upda { if (!this.Elements.ContainsKey(e.Id)) { - // Because function wrapper code doesn't called UpdateRepresentations any more - // we need to call it her for all nested elements while they are added. + // Because function wrapper code doesn't call UpdateRepresentations any more + // we need to call it here for all nested elements while they are added. if (updateElementRepresentations && e is GeometricElement geoE) { geoE.UpdateRepresentations();