diff --git a/LayoutFunctions/ClassroomLayout/dependencies/SpaceBoundary.cs b/LayoutFunctions/ClassroomLayout/dependencies/SpaceBoundary.cs index 56498781..90db1c65 100644 --- a/LayoutFunctions/ClassroomLayout/dependencies/SpaceBoundary.cs +++ b/LayoutFunctions/ClassroomLayout/dependencies/SpaceBoundary.cs @@ -1,9 +1,13 @@ using Elements.Geometry; +using Newtonsoft.Json; namespace Elements { public partial class SpaceBoundary : GeometricElement, ISpaceBoundary { public Vector3? ParentCentroid { get; set; } + + [JsonProperty("Config Id")] + public string ConfigId { get; set; } } } \ No newline at end of file diff --git a/LayoutFunctions/CustomLayout/dependencies/SpaceBoundary.cs b/LayoutFunctions/CustomLayout/dependencies/SpaceBoundary.cs index 56498781..b7f596a6 100644 --- a/LayoutFunctions/CustomLayout/dependencies/SpaceBoundary.cs +++ b/LayoutFunctions/CustomLayout/dependencies/SpaceBoundary.cs @@ -1,9 +1,13 @@ using Elements.Geometry; +using Newtonsoft.Json; namespace Elements { public partial class SpaceBoundary : GeometricElement, ISpaceBoundary { public Vector3? ParentCentroid { get; set; } + + [JsonProperty("Config Id")] + public string ConfigId { get; set; } } } \ No newline at end of file diff --git a/LayoutFunctions/LayoutFunctionCommon/ISpaceBoundary.cs b/LayoutFunctions/LayoutFunctionCommon/ISpaceBoundary.cs index d6a96717..5894e12b 100644 --- a/LayoutFunctions/LayoutFunctionCommon/ISpaceBoundary.cs +++ b/LayoutFunctions/LayoutFunctionCommon/ISpaceBoundary.cs @@ -21,6 +21,9 @@ public interface ISpaceBoundary public string DefaultWallType { get; set; } + [JsonProperty("Config Id", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string ConfigId { get; set; } + } } \ No newline at end of file diff --git a/LayoutFunctions/LayoutFunctionCommon/LayoutGeneration.cs b/LayoutFunctions/LayoutFunctionCommon/LayoutGeneration.cs index a146563f..04fad27a 100644 --- a/LayoutFunctions/LayoutFunctionCommon/LayoutGeneration.cs +++ b/LayoutFunctions/LayoutFunctionCommon/LayoutGeneration.cs @@ -61,6 +61,12 @@ public virtual LayoutGenerationResult StandardLayoutOnAllLevels(string programTy }; boundaryCurves.AddRange(spaceBoundary.Voids ?? new List()); + var configsForRoom = configs; + if (room.ConfigId != null) + { + configsForRoom = LayoutStrategies.LimitConfigsToId(configs, room, wallCandidateOptions); + } + var possibleConfigs = new List<(ConfigInfo configInfo, List wallCandidates)>(); foreach (var (OrientationGuideEdge, WallCandidates) in wallCandidateOptions) { @@ -68,7 +74,7 @@ public virtual LayoutGenerationResult StandardLayoutOnAllLevels(string programTy var grid = new Grid2d(boundaryCurves, orientationTransform); foreach (var cell in grid.GetCells()) { - var config = FindConfigByFit(configs, cell); + var config = FindConfigByFit(configsForRoom, cell); if (config != null) { possibleConfigs.Add((config.Value, WallCandidates)); @@ -238,7 +244,7 @@ protected virtual SpaceConfiguration DeserializeConfigJson(string configJson) KeyValuePair? selectedConfigPair = null; foreach (var configPair in orderedConfigs) { - if (configPair.Value.CellBoundary.Width < width && configPair.Value.CellBoundary.Depth < length) + if (configPair.Value.CellBoundary.Width < (width + Vector3.EPSILON) && configPair.Value.CellBoundary.Depth < (length + Vector3.EPSILON)) { selectedConfigPair = configPair; break; diff --git a/LayoutFunctions/LayoutFunctionCommon/LayoutStrategies.cs b/LayoutFunctions/LayoutFunctionCommon/LayoutStrategies.cs index 87190ea8..40049b75 100644 --- a/LayoutFunctions/LayoutFunctionCommon/LayoutStrategies.cs +++ b/LayoutFunctions/LayoutFunctionCommon/LayoutStrategies.cs @@ -211,7 +211,13 @@ public static HashSet StandardLayoutOnAllLevels(); - var layoutSucceeded = ProcessRoom(room, outputModel, countSeats, configs, corridorSegments, levelVolume, wallCandidateLines); + + var configsForRoom = configs; + if (room.ConfigId != null) + { + configsForRoom = LimitConfigsToId(configs, room); + } + var layoutSucceeded = ProcessRoom(room, outputModel, countSeats, configsForRoom, corridorSegments, levelVolume, wallCandidateLines); if (layoutSucceeded) { processedSpaces.Add(room.Id); } double height = room.Height == 0 ? 3 : room.Height; @@ -240,6 +246,38 @@ public static HashSet StandardLayoutOnAllLevels + /// Pringle-specific behavior to pick a specific config and orientation. This code only executes if the room has a `ConfigId` property, which is only set on pringle. + /// + public static SpaceConfiguration LimitConfigsToId(SpaceConfiguration originalConfigs, TSpaceBoundary room, List<(RoomEdge OrientationGuideEdge, List WallCandidates)> wallCandidateOptions = null) where TSpaceBoundary : Element, ISpaceBoundary + { + // If a set of wall candidate options are provided, limit to the one that aligns with the boundary's first edge. + // In the future, as room shapes become more editable, we might want to pass in an explicit "orientation edge" instead of just using the first edge. + if (wallCandidateOptions != null) + { + var roomOrientationEdge = room.Boundary.Perimeter.Segments().First(); + for (int i = wallCandidateOptions.Count - 1; i >= 0; i--) + { + var (OrientationGuideEdge, _) = wallCandidateOptions[i]; + if (OrientationGuideEdge.Line.Mid().DistanceTo(roomOrientationEdge.Mid()) > 0.01) + { + wallCandidateOptions.RemoveAt(i); + } + } + } + + // Limit the possible configs to the one specified by the room's ConfigId property, if it's found in the set. + var configId = room.ConfigId; + var newConfigs = new SpaceConfiguration(); + if (originalConfigs.ContainsKey(configId)) + { + newConfigs.Add(configId, originalConfigs[configId]); + return newConfigs; + } + + return originalConfigs; + } + /// /// Basically the same as StandardLayoutOnAllLevels, but without the actual furniture layout part — just the wall creation. diff --git a/LayoutFunctions/LoungeLayout/dependencies/SpaceBoundary.cs b/LayoutFunctions/LoungeLayout/dependencies/SpaceBoundary.cs index 73853484..ac0a45ee 100644 --- a/LayoutFunctions/LoungeLayout/dependencies/SpaceBoundary.cs +++ b/LayoutFunctions/LoungeLayout/dependencies/SpaceBoundary.cs @@ -1,9 +1,12 @@ using Elements.Geometry; +using Newtonsoft.Json; namespace Elements { public partial class SpaceBoundary : ISpaceBoundary { public Vector3? ParentCentroid { get; set; } + [JsonProperty("Config Id")] + public string ConfigId { get; set; } } } \ No newline at end of file diff --git a/LayoutFunctions/MeetingRoomLayout/dependencies/SpaceBoundary.cs b/LayoutFunctions/MeetingRoomLayout/dependencies/SpaceBoundary.cs index ed244d1f..7f3af68c 100644 --- a/LayoutFunctions/MeetingRoomLayout/dependencies/SpaceBoundary.cs +++ b/LayoutFunctions/MeetingRoomLayout/dependencies/SpaceBoundary.cs @@ -1,9 +1,11 @@ using Elements.Geometry; +using Newtonsoft.Json; namespace Elements { public partial class SpaceBoundary : GeometricElement, ISpaceBoundary { public Vector3? ParentCentroid { get; set; } - + [JsonProperty("Config Id")] + public string ConfigId { get; set; } } } \ No newline at end of file diff --git a/LayoutFunctions/OpenCollabLayout/dependencies/SpaceBoundary.cs b/LayoutFunctions/OpenCollabLayout/dependencies/SpaceBoundary.cs index ed244d1f..7f3af68c 100644 --- a/LayoutFunctions/OpenCollabLayout/dependencies/SpaceBoundary.cs +++ b/LayoutFunctions/OpenCollabLayout/dependencies/SpaceBoundary.cs @@ -1,9 +1,11 @@ using Elements.Geometry; +using Newtonsoft.Json; namespace Elements { public partial class SpaceBoundary : GeometricElement, ISpaceBoundary { public Vector3? ParentCentroid { get; set; } - + [JsonProperty("Config Id")] + public string ConfigId { get; set; } } } \ No newline at end of file diff --git a/LayoutFunctions/OpenOfficeLayout/dependencies/SpaceBoundary.cs b/LayoutFunctions/OpenOfficeLayout/dependencies/SpaceBoundary.cs index d349d071..68387b9b 100644 --- a/LayoutFunctions/OpenOfficeLayout/dependencies/SpaceBoundary.cs +++ b/LayoutFunctions/OpenOfficeLayout/dependencies/SpaceBoundary.cs @@ -4,6 +4,7 @@ using Elements.Geometry; using Elements.Geometry.Solids; using LayoutFunctionCommon; +using Newtonsoft.Json; namespace Elements { @@ -24,6 +25,9 @@ public partial class SpaceBoundary : ISpaceBoundary public int SpaceCount { get; set; } = 1; + [JsonProperty("Config Id")] + public string ConfigId { get; set; } // unused by this layout type + [Newtonsoft.Json.JsonIgnore] public LevelElements LevelElements { get; set; } diff --git a/LayoutFunctions/PantryLayout/dependencies/SpaceBoundary.cs b/LayoutFunctions/PantryLayout/dependencies/SpaceBoundary.cs index ed244d1f..b7f596a6 100644 --- a/LayoutFunctions/PantryLayout/dependencies/SpaceBoundary.cs +++ b/LayoutFunctions/PantryLayout/dependencies/SpaceBoundary.cs @@ -1,9 +1,13 @@ using Elements.Geometry; +using Newtonsoft.Json; + namespace Elements { public partial class SpaceBoundary : GeometricElement, ISpaceBoundary { public Vector3? ParentCentroid { get; set; } + [JsonProperty("Config Id")] + public string ConfigId { get; set; } } } \ No newline at end of file diff --git a/LayoutFunctions/PhoneBoothLayout/dependencies/SpaceBoundary.cs b/LayoutFunctions/PhoneBoothLayout/dependencies/SpaceBoundary.cs index 56498781..90db1c65 100644 --- a/LayoutFunctions/PhoneBoothLayout/dependencies/SpaceBoundary.cs +++ b/LayoutFunctions/PhoneBoothLayout/dependencies/SpaceBoundary.cs @@ -1,9 +1,13 @@ using Elements.Geometry; +using Newtonsoft.Json; namespace Elements { public partial class SpaceBoundary : GeometricElement, ISpaceBoundary { public Vector3? ParentCentroid { get; set; } + + [JsonProperty("Config Id")] + public string ConfigId { get; set; } } } \ No newline at end of file diff --git a/LayoutFunctions/PrivateOfficeLayout/dependencies/SpaceBoundary.cs b/LayoutFunctions/PrivateOfficeLayout/dependencies/SpaceBoundary.cs index 2b2109d5..c4065516 100644 --- a/LayoutFunctions/PrivateOfficeLayout/dependencies/SpaceBoundary.cs +++ b/LayoutFunctions/PrivateOfficeLayout/dependencies/SpaceBoundary.cs @@ -1,11 +1,15 @@ using Elements.Geometry; +using Newtonsoft.Json; namespace Elements { public partial class SpaceBoundary : GeometricElement, ISpaceBoundary { public Vector3? ParentCentroid { get; set; } - + public Vector3? IndividualCentroid { get; set; } + + [JsonProperty("Config Id")] + public string ConfigId { get; set; } } } \ No newline at end of file diff --git a/LayoutFunctions/ReceptionLayout/dependencies/SpaceBoundary.cs b/LayoutFunctions/ReceptionLayout/dependencies/SpaceBoundary.cs index 8d79f6b9..baf721b0 100644 --- a/LayoutFunctions/ReceptionLayout/dependencies/SpaceBoundary.cs +++ b/LayoutFunctions/ReceptionLayout/dependencies/SpaceBoundary.cs @@ -3,10 +3,14 @@ using System.Linq; using System.Collections.Generic; using Elements.Geometry; +using Newtonsoft.Json; + namespace Elements { public partial class SpaceBoundary : ISpaceBoundary { public Vector3? ParentCentroid { get; set; } + [JsonProperty("Config Id")] + public string ConfigId { get; set; } } } \ No newline at end of file diff --git a/SpaceConfigurationFromModel/dependencies/SpaceBoundary.cs b/SpaceConfigurationFromModel/dependencies/SpaceBoundary.cs index ed244d1f..0669512f 100644 --- a/SpaceConfigurationFromModel/dependencies/SpaceBoundary.cs +++ b/SpaceConfigurationFromModel/dependencies/SpaceBoundary.cs @@ -1,9 +1,12 @@ using Elements.Geometry; +using Newtonsoft.Json; namespace Elements { public partial class SpaceBoundary : GeometricElement, ISpaceBoundary { public Vector3? ParentCentroid { get; set; } + [JsonProperty("Config Id")] + public string ConfigId { get; set; } } } \ No newline at end of file