From aab7269172933b47368780565de0e65778839b8c Mon Sep 17 00:00:00 2001 From: "AMCBRIDGE\\ksloboda" Date: Fri, 25 Aug 2023 22:16:53 +0300 Subject: [PATCH] remove unnecessary parameters in the StandardLayoutOnAllLevels function --- .../LayoutFunctionCommon/LayoutStrategies.cs | 19 +- .../LoungeLayout/src/LoungeLayout.cs | 14 +- .../PantryLayout/src/PantryLayout.cs | 2 +- .../src/PrivateOfficeLayout.cs | 194 +----------------- .../ReceptionLayout/src/ReceptionLayout.cs | 3 +- .../src/SpaceConfigurationFromModel.cs | 2 +- 6 files changed, 17 insertions(+), 217 deletions(-) diff --git a/LayoutFunctions/LayoutFunctionCommon/LayoutStrategies.cs b/LayoutFunctions/LayoutFunctionCommon/LayoutStrategies.cs index 2ce06143..89af2a4c 100644 --- a/LayoutFunctions/LayoutFunctionCommon/LayoutStrategies.cs +++ b/LayoutFunctions/LayoutFunctionCommon/LayoutStrategies.cs @@ -146,9 +146,7 @@ public static void StandardLayoutOnAllLevels countSeats = null, Func getCentroid = null, TSpaceSettingsOverrideValueType defaultValue = default, - List> proxies = default /*, - Func, Dictionary>> getOverridesBySpaceBoundaryId = null, - Func>, TSpaceBoundary, IEnumerable, TSpaceSettingsOverrideValueType> getSpaceSettingsValue = null*/ + List> proxies = default ) where TLevelElements : Element, ILevelElements where TSpaceBoundary : Element, ISpaceBoundary @@ -175,8 +173,11 @@ public static void StandardLayoutOnAllLevels().Where(z => z.Name == programTypeName).ToList(); - var overridesBySpaceBoundaryId = OverrideUtilities.GetOverridesBySpaceBoundaryId(overrides?.SpaceSettings, getCentroid, levels); - // var overridesBySpaceBoundaryId = getOverridesBySpaceBoundaryId != null ? getOverridesBySpaceBoundaryId(levels) : new Dictionary>(); + var overridesBySpaceBoundaryId = + getCentroid != null ? + OverrideUtilities.GetOverridesBySpaceBoundaryId(overrides?.SpaceSettings, getCentroid, levels) : + new Dictionary(); + foreach (var lvl in levels) { var corridors = lvl.Elements.Where(e => e is Floor).OfType(); @@ -193,13 +194,12 @@ public static void StandardLayoutOnAllLevels(); foreach (var room in roomBoundaries) { - // var spaceSettingsValue = getSpaceSettingsValue != null ? getSpaceSettingsValue(overridesBySpaceBoundaryId, room, allSpaceBoundaries) : default; var spaceSettingsValue = defaultValue != null && proxies != null ? OverrideUtilities.MatchApplicableOverride( overridesBySpaceBoundaryId, OverrideUtilities.GetSpaceBoundaryProxy(room, roomBoundaries.Proxies(OverrideUtilities.SpaceBoundaryOverrideDependencyName)), defaultValue, proxies).Value : default; - ProcessRoom(room, outputModel, countSeats, configs, spaceSettingsValue, corridorSegments, levelVolume, wallCandidateLines); + ProcessRoom(room, outputModel, countSeats, configs, spaceSettingsValue, corridorSegments, levelVolume, wallCandidateLines); } double height = levelVolume?.Height ?? 3; @@ -217,13 +217,12 @@ public static void StandardLayoutOnAllLevels(room, outputModel, countSeats, configs, spaceSettingsValue); + ProcessRoom(room, outputModel, countSeats, configs, spaceSettingsValue); } OverrideUtilities.InstancePositionOverrides(overrides, outputModel); } @@ -248,7 +247,7 @@ private static void ProcessRoom inputModels, Elements.Serialization.glTF.GltfExtensions.UseReferencedContentExtension = true; var output = new LoungeLayoutOutputs(); - Func, Dictionary>> overridesBySpaceBoundaryId = (levels) => { - return OverrideUtilities.GetOverridesBySpaceBoundaryId, SpaceBoundary, LevelElements>(input.Overrides?.SpaceSettings.Select(s => s as ISpaceSettingsOverride).ToList(), (ov) => (ov as SpaceSettingsOverride).Identity.ParentCentroid, levels); - }; - - Func>, SpaceBoundary, IEnumerable, SpaceSettingsValue> spaceSettingsValue = (overridesId, room, roomBoundaries) => { - return OverrideUtilities.MatchApplicableOverride( - overridesId.ToDictionary(id => id.Key, id => id.Value as SpaceSettingsOverride), - OverrideUtilities.GetSpaceBoundaryProxy(room, roomBoundaries.Proxies(OverrideUtilities.SpaceBoundaryOverrideDependencyName)), - new SpaceSettingsValue(false, false), - proxies).Value; - }; - - LayoutStrategies.StandardLayoutOnAllLevels("Lounge", inputModels, input.Overrides, output.Model, false, "./LoungeConfigurations.json", default, CountSeats, overridesBySpaceBoundaryId, spaceSettingsValue); + LayoutStrategies.StandardLayoutOnAllLevels("Lounge", inputModels, input.Overrides, output.Model, false, "./LoungeConfigurations.json", default, CountSeats, (ov) => ov.Identity.ParentCentroid, new SpaceSettingsValue(false, false), proxies); output.Model.AddElements(proxies); return output; diff --git a/LayoutFunctions/PantryLayout/src/PantryLayout.cs b/LayoutFunctions/PantryLayout/src/PantryLayout.cs index 6200a99f..14b71c75 100644 --- a/LayoutFunctions/PantryLayout/src/PantryLayout.cs +++ b/LayoutFunctions/PantryLayout/src/PantryLayout.cs @@ -53,7 +53,7 @@ public static PantryLayoutOutputs Execute(Dictionary inputModels, Elements.Serialization.glTF.GltfExtensions.UseReferencedContentExtension = true; var layoutGeneration = new PantryLayoutGeneration(); - var result = layoutGeneration.StandardLayoutOnAllLevels("Pantry", inputModels, input.Overrides, (ov) => ov.Identity.ParentCentroid, new SpaceSettingsValue(false, false), false, "./PantryConfigurations.json"); + var result = layoutGeneration.StandardLayoutOnAllLevels("Pantry", inputModels, input.Overrides, false, "./PantryConfigurations.json", default, (ov) => ov.Identity.ParentCentroid, new SpaceSettingsValue(false, false)); var output = new PantryLayoutOutputs { Model = result.OutputModel, diff --git a/LayoutFunctions/PrivateOfficeLayout/src/PrivateOfficeLayout.cs b/LayoutFunctions/PrivateOfficeLayout/src/PrivateOfficeLayout.cs index 2de95a4c..57095617 100644 --- a/LayoutFunctions/PrivateOfficeLayout/src/PrivateOfficeLayout.cs +++ b/LayoutFunctions/PrivateOfficeLayout/src/PrivateOfficeLayout.cs @@ -62,196 +62,7 @@ public static PrivateOfficeLayoutOutputs Execute(Dictionary input var configJson = File.ReadAllText(Path.Combine(dir, "PrivateOfficeConfigurations.json")); var configs = JsonConvert.DeserializeObject(configJson); FlippedConfigurations.Init(configs); - - - var configsNames = new string[] { - "ClassroomLayout", - "LoungeLayout", - "MeetingRoomLayout", - "OpenCollabLayout", - "OpenOfficeLayout", - "PantryLayout", - "ReceptionLayout", - "PrivateOfficeLayout", - "PhoneBoothLayout", - }; - var configsNames1 = new string[] { - "ClassroomConfigurations", - "LoungeConfigurations", - "ConferenceRoomConfigurations", - "OpenCollaborationConfigurations", - "OpenOfficeDeskConfigurations", - "PantryConfigurations", - "ReceptionConfigurations", - "PrivateOfficeConfigurations", - "PhoneBoothConfigurations", - }; - - // var elements = new Dictionary>(); - // var elements1 = new Dictionary>(); - - var configJson0 = File.ReadAllText($"D:/Hypar/Forks/HyparSpace/LayoutFunctions/PrivateOfficeLayout/mirrored-catalog.json"); - var model = Model.FromJson(configJson0); - var catalog = model.AllElementsOfType().First(); - - // var elemNames = new Dictionary(); - // foreach (var item in catalog.Content) - // { - // if (item.Name.Contains(" Mirrored")) - // { - // elemNames.Add(item.Name.Replace(" Mirrored", "").Replace("1 Mirrored", ""), item); - // } - // else - // { - // var oldNameArray = item.Name.Split(" "); - // for (int j = 0; j < oldNameArray.Count(); j++) - // { - // oldNameArray[j] = - // oldNameArray[j] == "Left" ? "Right" : - // oldNameArray[j] == "Right" ? "Left" : - // oldNameArray[j]; - // } - // elemNames.Add(string.Join(" ", oldNameArray), item); - // } - // } - - // // var allCatalogs = new Dictionary(); - // // for (int i = 0; i < configsNames.Count(); i++) - // // { - // // // var configJson1 = File.ReadAllText($"D:/Hypar/Forks/HyparSpace/LayoutFunctions/{configsNames[i]}/catalog-mirrored.json"); - - // // var configJson1 = File.ReadAllText($"D:/Hypar/Forks/HyparSpace/LayoutFunctions/{configsNames[i]}/catalog.json"); - // // var model1 = Model.FromJson(configJson1); - // // var catalog1 = model1.AllElementsOfType().First(); - // // allCatalogs.Add(configsNames[i], catalog1); - // // } - - for (int i = 0; i < configsNames.Count(); i++) - { - var configJson1 = File.ReadAllText($"D:/Hypar/Forks/HyparSpace/LayoutFunctions/{configsNames[i]}/catalog.json"); - var model1 = Model.FromJson(configJson1); - var catalog1 = model1.AllElementsOfType().First(); - - var j = 0; - var ploi = new List(); - var redfploi = new List(); - while (j < catalog1.Content.Count()) - { - var item = catalog1.Content[j]; - var content = catalog.Content.FirstOrDefault(u => u.Name == item.Name); - var Reference = catalog.ReferenceConfiguration.Where(u => u.Name == item.Name); - if (content != null) - { - catalog1.Content.Remove(item); - ploi.Add(content); - - var oldReference = catalog1.ReferenceConfiguration.Where(u => u.Name == item.Name).ToList(); - for (int p = 0; p < oldReference.Count(); p++) - { - catalog1.ReferenceConfiguration.Remove(oldReference[p]); - } - redfploi.AddRange(Reference); - continue; - } - j++; - } - - foreach (var item in ploi) - { - catalog1.Content.Add(item); - } - - foreach (var item in redfploi) - { - catalog1.ReferenceConfiguration.Add(item); - } - - model1.ToJson($"D:/Hypar/Forks/HyparSpace/LayoutFunctions/{configsNames[i]}/catalog-out.json", true); - - // var configJson2 = File.ReadAllText($"D:/Hypar/Forks/HyparSpace/LayoutFunctions/{configsNames[i]}/{configsNames1[i]}.json"); - // var configs1 = JsonConvert.DeserializeObject(configJson2); - - // var allElem0 = configs1.SelectMany(c => c.Value.ContentItems).ToList(); - // // var allElem0 = configs1.SelectMany(c => c.Value.ContentItems).Where(e => !catalog1.Content.Any(cit => cit.Name == e.Name || cit.GltfLocation == e.Url)).ToList(); - // // var allElem00 = configs1.SelectMany(c => c.Value.ContentItems).Where(e => !catalog1.Content.Any(cit => cit.Name == e.Name && cit.GltfLocation == e.Url)).ToList(); - // // var allElem0 = catalog1.Content.Where(e => !configs1.SelectMany(c => c.Value.ContentItems).Any(cit => cit.Name == e.Name || e.GltfLocation == cit.Url)).ToList(); - // // var allElem00 = catalog1.Content.Where(e => !configs1.SelectMany(c => c.Value.ContentItems).Any(cit => cit.Name == e.Name && e.GltfLocation == cit.Url)).ToList(); - - // var j = 0; - // // add names - // while (j < allElem0.Count()) - // { - // var item = allElem0[j]; - // var elem = catalog1.Content.FirstOrDefault(c => c.GltfLocation == item.Url); - // if (elem != null) - // { - // item.Name = elem.Name; - // } - // j++; - // } - - // using (FileStream s = File.Create($"D:/Hypar/Forks/HyparSpace/LayoutFunctions/{configsNames[i]}/{configsNames1[i]}-out.json")) - // using (StreamWriter writer = new StreamWriter(s)) - // using (JsonTextWriter jsonWriter = new JsonTextWriter(writer)) - // { - // var serializer = new JsonSerializer(); - // serializer.Serialize(jsonWriter, configs1); - // jsonWriter.Flush(); - // } - - // j = 0; - // // remove not used - // while (j < catalog1.Content.Count()) - // { - // var item = catalog1.Content[j]; - // if (!allElem0.Any(e => e.Name == item.Name || e.Url == item.GltfLocation)) - // { - // var refes = catalog1.ReferenceConfiguration.Where(e => (e as ElementInstance).BaseDefinition?.Name == item.Name).ToList(); - // for (int k = refes.Count() - 1; k >= 0; k--) - // { - // catalog1.ReferenceConfiguration.Remove(refes[k]); - // } - // catalog1.Content.Remove(item); - // continue; - // } - // j++; - // } - - // // var allElem = configs1.SelectMany(c => c.Value.ContentItems.Select(it => (it.Name, it.Url))); - // var allElem = configs1.SelectMany(c => c.Value.ContentItems.Select(it => !string.IsNullOrEmpty(it.Name) ? it.Name : catalog1.Content.FirstOrDefault(cit => cit.Name == it.Name || cit.GltfLocation == it.Url)?.Name)).Distinct().OrderBy(n => n).ToList(); - // var allElem1 = configs1.SelectMany(c => c.Value.ContentItems.Select(it => (!string.IsNullOrEmpty(it.Name) ? it.Name : catalog1.Content.FirstOrDefault(cit => cit.Name == it.Name || cit.GltfLocation == it.Url)?.Name, it.Url))).Distinct().OrderBy(n => n).ToList(); - - // // elements.Add(configsNames[i], catalog.Content.Where(c => allElem.Contains(c.Name)).Select(c => c.Name).ToList()); - // // elements.Add(configsNames[i], catalog.Content.Where(c => allElem.Any(a => c.Name.Replace(" Mirrored", "") == a)).Select(c => c.Name).ToList()); - // // elements.Add(configsNames[i], allElem.Where(e => e != null && (e.Contains("Left") || e.Contains("Right"))).ToList()); - // elements.Add(configsNames[i], allElem); - // // elements1.Add(configsNames[i], allElem0.Select(n => (n.Name, n.GltfLocation)).ToList()); - // // elements1.Add(configsNames[i] + "1", allElem00.Select(n => (n.Name, n.GltfLocation)).ToList()); - // // elements1.Add(configsNames[i], allElem1.Where(n => string.IsNullOrEmpty(n.Item1)).ToList()); - // // elements1.Add(configsNames[i], catalog1.Content.Where(n => string.IsNullOrEmpty(n.Name)).Select(n => (n.Name, n.GltfLocation)).ToList()); - - // var elements4 = allElem.Distinct().OrderBy(n => n).Where(n => catalog.Content.Any(u => u.Name.Replace(" Mirrored", "").Replace("1 Mirrored", "") == n)); - // // var elements4 = allElem.Distinct().OrderBy(n => n).Where(n => elemNames.Any(u => u.Key == n)); - // foreach (var item in elements4) - // { - // var contentName = elemNames[item].Name; - // var content = catalog.Content.FirstOrDefault(u => u.Name == contentName); - // var Reference = catalog.ReferenceConfiguration.FirstOrDefault(u => u.Name == contentName); - // if (content != null) catalog1.Content.Add(content); - // if (Reference != null) catalog1.ReferenceConfiguration.Add(Reference); - } - - // model1.ToJson($"D:/Hypar/Forks/HyparSpace/LayoutFunctions/{configsNames[i]}/catalog-out.json", true); - - // // elements.Add(configsNames[i], catalog.Content.Where(c => allElem.Any(a => a.Name == c.Name) || allElem.Any(a => a.Url == c.GltfLocation)).Select(c => c.Name).ToList()); - // // elements1.Add(configsNames[i], configs1.Content.Where(c => t.Contains(c.Name) && (configJson2.Contains(c.Name) || configJson2.Contains(c.GltfLocation))).Select(c => (c.Name, c.GltfLocation)).DistinctBy(n => n.Name).OrderBy(n => n.Name).ToList()); - // // var ti = string.Join("\n", elements1.Last().Value.Select(e => e)); - // } - - // var elements5 = string.Join("\n", elements.SelectMany(e => e.Value).Distinct().OrderBy(n => n)); - // var elements2 = string.Join("\n", elements.SelectMany(e => e.Value).Distinct().OrderBy(n => n).Where(n => !catalog.Content.Any(u => u.Name.Replace(" Mirrored", "") == n))); - // var elements3 = string.Join("\n\n\n", elements.Select(es => es.Key + "\n" + string.Join("\n", es.Value.Distinct().OrderBy(n => n).Where(n => catalog.Content.Any(u => u.Name.Replace(" Mirrored", "") == n))))); - + var wallMat = new Material("Drywall", new Color(0.9, 0.9, 0.9, 1.0), 0.01, 0.01); var glassMat = new Material("Glass", new Color(0.7, 0.7, 0.7, 0.3), 0.3, 0.6); var mullionMat = new Material("Storefront Mullions", new Color(0.5, 0.5, 0.5, 1.0)); @@ -263,6 +74,7 @@ public static PrivateOfficeLayoutOutputs Execute(Dictionary input var corridors = lvl.Elements.OfType(); var corridorSegments = corridors.SelectMany(p => p.Profile.Segments()).ToList(); var privateOfficeBoundaries = lvl.Elements.OfType().Where(z => z.Name == "Private Office"); + var meetingRmBoundaryProxies = privateOfficeBoundaries.Proxies(OverrideUtilities.SpaceBoundaryOverrideDependencyName); var levelVolume = levelVolumes.FirstOrDefault(l => lvl.AdditionalProperties.TryGetValue("LevelVolumeId", out var levelVolumeId) && levelVolumeId as string == l.Id.ToString()) ?? @@ -275,7 +87,7 @@ public static PrivateOfficeLayoutOutputs Execute(Dictionary input var privateOfficeCount = 0; var config = OverrideUtilities.MatchApplicableOverride( overridesBySpaceBoundaryId, - OverrideUtilities.GetSpaceBoundaryProxy(room, privateOfficeBoundaries.Proxies(OverrideUtilities.SpaceBoundaryOverrideDependencyName)), + OverrideUtilities.GetSpaceBoundaryProxy(room, meetingRmBoundaryProxies), new SpaceSettingsValue( new SpaceSettingsValueOfficeSizing( input.OfficeSizing.AutomateOfficeSubdivisions, diff --git a/LayoutFunctions/ReceptionLayout/src/ReceptionLayout.cs b/LayoutFunctions/ReceptionLayout/src/ReceptionLayout.cs index 31014e1f..5657c374 100644 --- a/LayoutFunctions/ReceptionLayout/src/ReceptionLayout.cs +++ b/LayoutFunctions/ReceptionLayout/src/ReceptionLayout.cs @@ -70,6 +70,7 @@ public static ReceptionLayoutOutputs Execute(Dictionary inputMode var corridors = lvl.Elements.OfType(); var corridorSegments = corridors.SelectMany(p => p.Profile.Segments()); var meetingRmBoundaries = lvl.Elements.OfType().Where(z => z.Name == "Reception"); + var meetingRmBoundaryProxies = meetingRmBoundaries.Proxies(OverrideUtilities.SpaceBoundaryOverrideDependencyName); var levelVolume = levelVolumes.FirstOrDefault(l => lvl.AdditionalProperties.TryGetValue("LevelVolumeId", out var levelVolumeId) && levelVolumeId as string == l.Id.ToString()) ?? @@ -81,7 +82,7 @@ public static ReceptionLayoutOutputs Execute(Dictionary inputMode var spaceBoundary = room.Boundary; var config = OverrideUtilities.MatchApplicableOverride( overridesBySpaceBoundaryId, - OverrideUtilities.GetSpaceBoundaryProxy(room, meetingRmBoundaries.Proxies(OverrideUtilities.SpaceBoundaryOverrideDependencyName)), + OverrideUtilities.GetSpaceBoundaryProxy(room, meetingRmBoundaryProxies), new SpaceSettingsValue(false, false), proxies); var selectedConfigs = FlippedConfigurations.GetConfigs(config.Value.PrimaryAxisFlipLayout, config.Value.SecondaryAxisFlipLayout); diff --git a/SpaceConfigurationFromModel/src/SpaceConfigurationFromModel.cs b/SpaceConfigurationFromModel/src/SpaceConfigurationFromModel.cs index f5af89a5..8558a0da 100644 --- a/SpaceConfigurationFromModel/src/SpaceConfigurationFromModel.cs +++ b/SpaceConfigurationFromModel/src/SpaceConfigurationFromModel.cs @@ -8,7 +8,7 @@ namespace SpaceConfigurationFromModel { public static class SpaceConfigurationFromModel { - private class SpaceConfigurationFromModelLayoutGeneration : LayoutGeneration + private class SpaceConfigurationFromModelLayoutGeneration : LayoutGeneration { private readonly SpaceConfiguration spaceConfig;