Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

call update representations on child elements as well #1052

Merged
merged 4 commits into from
Nov 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions Elements/src/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ public class Model

/// <summary>
/// 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.
/// </summary>
[JsonIgnore]
Expand Down Expand Up @@ -111,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();
Expand All @@ -136,6 +128,12 @@ public void AddElement(Element element, bool gatherSubElements = true, bool upda
{
if (!this.Elements.ContainsKey(e.Id))
{
// 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();
}
this.Elements.Add(e.Id, e);
}
}
Expand Down Expand Up @@ -272,8 +270,10 @@ public void ToJson(MemoryStream stream, bool indent = false, bool gatherSubEleme
/// </summary>
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);
}

/// <summary>
Expand Down
Loading