From 3f0ee7477faf16e6061ab5b73c5eb6c762e128da Mon Sep 17 00:00:00 2001 From: Isak Naslund Date: Fri, 9 Dec 2022 12:27:25 +0100 Subject: [PATCH 01/12] Add module getting objects with no set ID from loads --- .../GetLoadElementsWithoutId.cs | 74 +++++++++++++++++++ Structure_AdapterModules/ModuleLoader.cs | 5 ++ 2 files changed, 79 insertions(+) create mode 100644 Structure_AdapterModules/GetLoadElementsWithoutId.cs diff --git a/Structure_AdapterModules/GetLoadElementsWithoutId.cs b/Structure_AdapterModules/GetLoadElementsWithoutId.cs new file mode 100644 index 00000000..e872f10a --- /dev/null +++ b/Structure_AdapterModules/GetLoadElementsWithoutId.cs @@ -0,0 +1,74 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using BH.oM.Base; +using BH.oM.Adapter; +using System; +using System.Linq; +using System.Collections.Generic; +using System.Reflection; +using System.ComponentModel; +using BH.oM.Structure.Elements; +using System.Collections; +using BH.oM.Geometry; +using BH.oM.Structure.Constraints; +using BH.oM.Structure.Loads; + + +namespace BH.Adapter.Modules +{ + [Description("Get all elements that does not contain an adapter ID of the expected type. Avoids the need to again read and check against elements already in the model.")] + public class GetLoadElementsWithoutId : IGetDependencyModule, T> where T : IBHoMObject + { + /***************************************************/ + /**** Interface method ****/ + /***************************************************/ + + public IEnumerable GetDependencies(IEnumerable> objects) + { + List noIdLoadObjects = new List(); + foreach (IElementLoad load in objects) + { + if(load?.Objects?.Elements != null) + noIdLoadObjects.AddRange(load.Objects.Elements.Where(x => x != null && !x.Fragments.Contains(m_adapterIdType))); + } + return noIdLoadObjects; + } + + /***************************************************/ + /**** Constructors ****/ + /***************************************************/ + + public GetLoadElementsWithoutId(IBHoMAdapter adapter) + { + m_adapterIdType = adapter.AdapterIdFragmentType; + } + + /***************************************************/ + + private Type m_adapterIdType; + + /***************************************************/ + } +} + + diff --git a/Structure_AdapterModules/ModuleLoader.cs b/Structure_AdapterModules/ModuleLoader.cs index 5f608ffb..90d41c94 100644 --- a/Structure_AdapterModules/ModuleLoader.cs +++ b/Structure_AdapterModules/ModuleLoader.cs @@ -29,6 +29,7 @@ using BH.Adapter; using BH.oM.Adapter; using BH.oM.Base; +using BH.oM.Structure.Elements; namespace BH.Adapter.Modules.Structure { @@ -40,6 +41,10 @@ public static void LoadModules(this BHoMAdapter adapter) adapter.AdapterModules.Add(new CopyNodeProperties()); adapter.AdapterModules.Add(new GetCasesFromCombinations()); adapter.AdapterModules.Add(new GetCombinationsFromCombinations()); + adapter.AdapterModules.Add(new GetLoadElementsWithoutId(adapter)); + adapter.AdapterModules.Add(new GetLoadElementsWithoutId(adapter)); + adapter.AdapterModules.Add(new GetLoadElementsWithoutId(adapter)); + adapter.AdapterModules.Add(new GetLoadElementsWithoutId(adapter)); //Gravity loads } } } From eae2b44421c2fda06ad930f52cf5f001be432e95 Mon Sep 17 00:00:00 2001 From: Isak Naslund Date: Fri, 9 Dec 2022 15:14:58 +0100 Subject: [PATCH 02/12] Fix capital D --- Structure_AdapterModules/GetLoadElementsWithoutId.cs | 4 ++-- Structure_AdapterModules/ModuleLoader.cs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Structure_AdapterModules/GetLoadElementsWithoutId.cs b/Structure_AdapterModules/GetLoadElementsWithoutId.cs index e872f10a..51812d9f 100644 --- a/Structure_AdapterModules/GetLoadElementsWithoutId.cs +++ b/Structure_AdapterModules/GetLoadElementsWithoutId.cs @@ -37,7 +37,7 @@ namespace BH.Adapter.Modules { [Description("Get all elements that does not contain an adapter ID of the expected type. Avoids the need to again read and check against elements already in the model.")] - public class GetLoadElementsWithoutId : IGetDependencyModule, T> where T : IBHoMObject + public class GetLoadElementsWithoutID : IGetDependencyModule, T> where T : IBHoMObject { /***************************************************/ /**** Interface method ****/ @@ -58,7 +58,7 @@ public IEnumerable GetDependencies(IEnumerable> objects) /**** Constructors ****/ /***************************************************/ - public GetLoadElementsWithoutId(IBHoMAdapter adapter) + public GetLoadElementsWithoutID(IBHoMAdapter adapter) { m_adapterIdType = adapter.AdapterIdFragmentType; } diff --git a/Structure_AdapterModules/ModuleLoader.cs b/Structure_AdapterModules/ModuleLoader.cs index 90d41c94..4aaf9786 100644 --- a/Structure_AdapterModules/ModuleLoader.cs +++ b/Structure_AdapterModules/ModuleLoader.cs @@ -41,10 +41,10 @@ public static void LoadModules(this BHoMAdapter adapter) adapter.AdapterModules.Add(new CopyNodeProperties()); adapter.AdapterModules.Add(new GetCasesFromCombinations()); adapter.AdapterModules.Add(new GetCombinationsFromCombinations()); - adapter.AdapterModules.Add(new GetLoadElementsWithoutId(adapter)); - adapter.AdapterModules.Add(new GetLoadElementsWithoutId(adapter)); - adapter.AdapterModules.Add(new GetLoadElementsWithoutId(adapter)); - adapter.AdapterModules.Add(new GetLoadElementsWithoutId(adapter)); //Gravity loads + adapter.AdapterModules.Add(new GetLoadElementsWithoutID(adapter)); + adapter.AdapterModules.Add(new GetLoadElementsWithoutID(adapter)); + adapter.AdapterModules.Add(new GetLoadElementsWithoutID(adapter)); + adapter.AdapterModules.Add(new GetLoadElementsWithoutID(adapter)); //Gravity loads } } } From 04d9708f5c37b14cc5394e8522568705ccaee8e3 Mon Sep 17 00:00:00 2001 From: Isak Naslund Date: Fri, 9 Dec 2022 15:15:27 +0100 Subject: [PATCH 03/12] Dummy commit to force filename change --- .../{GetLoadElementsWithoutId.cs => GetLoadElementsWithoutID1.cs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Structure_AdapterModules/{GetLoadElementsWithoutId.cs => GetLoadElementsWithoutID1.cs} (100%) diff --git a/Structure_AdapterModules/GetLoadElementsWithoutId.cs b/Structure_AdapterModules/GetLoadElementsWithoutID1.cs similarity index 100% rename from Structure_AdapterModules/GetLoadElementsWithoutId.cs rename to Structure_AdapterModules/GetLoadElementsWithoutID1.cs From 598eac70722857ba3a74fb69465a7041a91370f3 Mon Sep 17 00:00:00 2001 From: Isak Naslund Date: Fri, 9 Dec 2022 15:15:42 +0100 Subject: [PATCH 04/12] Correct filename --- .../{GetLoadElementsWithoutID1.cs => GetLoadElementsWithoutID.cs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Structure_AdapterModules/{GetLoadElementsWithoutID1.cs => GetLoadElementsWithoutID.cs} (100%) diff --git a/Structure_AdapterModules/GetLoadElementsWithoutID1.cs b/Structure_AdapterModules/GetLoadElementsWithoutID.cs similarity index 100% rename from Structure_AdapterModules/GetLoadElementsWithoutID1.cs rename to Structure_AdapterModules/GetLoadElementsWithoutID.cs From ca3fe12bb51fdf07c100ad215db23366fa96e8bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isak=20N=C3=A4slund?= Date: Mon, 9 Jan 2023 08:12:22 +0100 Subject: [PATCH 05/12] Update Structure_AdapterModules/GetLoadElementsWithoutID.cs Co-authored-by: Fraser Greenroyd --- Structure_AdapterModules/GetLoadElementsWithoutID.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Structure_AdapterModules/GetLoadElementsWithoutID.cs b/Structure_AdapterModules/GetLoadElementsWithoutID.cs index 51812d9f..5e47e995 100644 --- a/Structure_AdapterModules/GetLoadElementsWithoutID.cs +++ b/Structure_AdapterModules/GetLoadElementsWithoutID.cs @@ -1,6 +1,6 @@ /* * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. + * Copyright (c) 2015 - 2023, the respective contributors. All rights reserved. * * Each contributor holds copyright over their respective contributions. * The project versioning (Git) records all such contribution source information. From 62e079b06ac7d7117b2636b17633ac267c71ceb2 Mon Sep 17 00:00:00 2001 From: Isak Naslund Date: Mon, 9 Jan 2023 08:46:16 +0100 Subject: [PATCH 06/12] Only add list of dependency objects if the list contains any items --- Adapter_Engine/Query/GetDependencyObjects.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Adapter_Engine/Query/GetDependencyObjects.cs b/Adapter_Engine/Query/GetDependencyObjects.cs index 518af31d..18575d54 100644 --- a/Adapter_Engine/Query/GetDependencyObjects.cs +++ b/Adapter_Engine/Query/GetDependencyObjects.cs @@ -59,9 +59,10 @@ public static Dictionary GetDependencyObjects(this IEnumer foreach (Type t in dependencyTypes) { MethodInfo generic = method.MakeGenericMethod(new Type[] { typeof(T), t }); - var list = generic.Invoke(null, new object[] { objects, adapter }); + IList list = generic.Invoke(null, new object[] { objects, adapter }) as IList; - dict.Add(t, list as IEnumerable); + if (list != null && list.Count != 0) + dict.Add(t, list); } return dict; From 5ba0025f9710e0a42f54a6d0be30f70a4c939cd9 Mon Sep 17 00:00:00 2001 From: Isak Naslund Date: Mon, 9 Jan 2023 09:14:04 +0100 Subject: [PATCH 07/12] Adding AdapterId to the test adapter and loading adapter modules --- .../Objects/StructuralAdapter.cs | 3 ++ .../Objects/StructuralAdapterId.cs | 46 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 .ci/code/BHoM_Adapter_Tests/Objects/StructuralAdapterId.cs diff --git a/.ci/code/BHoM_Adapter_Tests/Objects/StructuralAdapter.cs b/.ci/code/BHoM_Adapter_Tests/Objects/StructuralAdapter.cs index 6ccfe64f..dccf3907 100644 --- a/.ci/code/BHoM_Adapter_Tests/Objects/StructuralAdapter.cs +++ b/.ci/code/BHoM_Adapter_Tests/Objects/StructuralAdapter.cs @@ -73,6 +73,9 @@ public StructuralAdapter() { typeof(IElementLoad), new List{ typeof(Bar)} }, { typeof(IElementLoad), new List{ typeof(Node)} } }; + + AdapterIdFragmentType = typeof(StructuralAdapterId); + BH.Adapter.Modules.Structure.ModuleLoader.LoadModules(this); } protected override bool ICreate(IEnumerable objects, ActionConfig actionConfig = null) diff --git a/.ci/code/BHoM_Adapter_Tests/Objects/StructuralAdapterId.cs b/.ci/code/BHoM_Adapter_Tests/Objects/StructuralAdapterId.cs new file mode 100644 index 00000000..04225f3a --- /dev/null +++ b/.ci/code/BHoM_Adapter_Tests/Objects/StructuralAdapterId.cs @@ -0,0 +1,46 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2023, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using BH.oM.Base; +using System; +using System.Collections.Generic; +using System.ComponentModel; + +namespace BH.Tests.Adapter +{ + [Description("")] + public class StructuralAdapterId : IAdapterId + { + /***************************************************/ + /**** Properties ****/ + /***************************************************/ + + [Description("")] + public virtual object Id { get; set; } + + + /***************************************************/ + + } +} + + From 86ea8ba8144875393c6b0362b65b10119b17ae7b Mon Sep 17 00:00:00 2001 From: Isak Naslund Date: Mon, 9 Jan 2023 09:14:28 +0100 Subject: [PATCH 08/12] Adding Push tests testing added functionality of the PR --- .ci/code/BHoM_Adapter_Tests/PushTests.cs | 47 ++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/.ci/code/BHoM_Adapter_Tests/PushTests.cs b/.ci/code/BHoM_Adapter_Tests/PushTests.cs index 531ca507..8c16df72 100644 --- a/.ci/code/BHoM_Adapter_Tests/PushTests.cs +++ b/.ci/code/BHoM_Adapter_Tests/PushTests.cs @@ -176,5 +176,52 @@ public void DependencyOrder_UpdateAndFullPush() Assert.IsTrue(orderedObjects.Where(t => t.Item1 == typeof(Node)).First().Item2 == PushType.UpdateOnly, "For Node objects, UpdateOnly should have come before FullPush."); } + + [Test] + public void DependencyOrder_CreateLoadAllObjectsWithIds() + { + List bars = Create.RandomObjects(10); + for (int i = 0; i < bars.Count; i++) + { + Engine.Adapter.Modify.SetAdapterId(bars[i], new StructuralAdapterId { Id = i + 1 }); + } + BarUniformlyDistributedLoad load = Create.RandomObject(); + load.Objects.Elements = bars; + + sa.Push(new List { load }); + + string correctOrder = "BH.oM.Structure.Loads.Loadcase, BH.oM.Structure.Loads.BarUniformlyDistributedLoad"; //All bars contain Ids, hence no bars should be created even if there is a dependency on the bars + string createdOrder = string.Join(", ", sa.Created.Select(c => c.Item1.FullName)); + + Assert.AreEqual(correctOrder, createdOrder); + } + + [Test] + public void DependencyOrder_CreateLoadHalfObjectsWithIds() + { + int objectCount = 10; + List bars = Create.RandomObjects(objectCount); + int withIdCount = objectCount / 2; + int withoutIdCount = objectCount - withIdCount; + for (int i = 0; i < withIdCount; i++) + { + Engine.Adapter.Modify.SetAdapterId(bars[i], new StructuralAdapterId { Id = i + 1 }); + } + + //Shuffle the order fo the bars. + //Doing this to test that the order of bars with and without Id does not matter + Random random = new Random(2); + bars = bars.OrderBy(x => random.Next()).ToList(); + + BarUniformlyDistributedLoad load = Create.RandomObject(); + load.Objects.Elements = bars; + + sa.Push(new List { load }); + + Assert.IsTrue(sa.Created.Any(x => x.Item1 == typeof(Bar)), "No bars created."); + int barCreationCount = sa.Created.First(x => x.Item1 == typeof(Bar)).Item2.Count(); + + Assert.AreEqual(withoutIdCount, barCreationCount, "Wrong number of bars created."); + } } } \ No newline at end of file From 7738773bd03e7506b5c0dbc1bc0bfd746af159a3 Mon Sep 17 00:00:00 2001 From: Isak Naslund Date: Mon, 9 Jan 2023 14:01:19 +0100 Subject: [PATCH 09/12] Update desc --- Structure_AdapterModules/GetLoadElementsWithoutID.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Structure_AdapterModules/GetLoadElementsWithoutID.cs b/Structure_AdapterModules/GetLoadElementsWithoutID.cs index 5e47e995..fc23eca0 100644 --- a/Structure_AdapterModules/GetLoadElementsWithoutID.cs +++ b/Structure_AdapterModules/GetLoadElementsWithoutID.cs @@ -36,7 +36,7 @@ namespace BH.Adapter.Modules { - [Description("Get all elements that does not contain an adapter ID of the expected type. Avoids the need to again read and check against elements already in the model.")] + [Description("Get all elements that do not contain an adapter ID of the expected type from the provided IElementLoads. Avoids the need to again read and check against elements already in the model.")] public class GetLoadElementsWithoutID : IGetDependencyModule, T> where T : IBHoMObject { /***************************************************/ From 0a41c2d467b7adb56dc555733dffb0dae4ce0e7e Mon Sep 17 00:00:00 2001 From: Isak Naslund Date: Mon, 9 Jan 2023 14:03:22 +0100 Subject: [PATCH 10/12] Improve comments --- Structure_AdapterModules/ModuleLoader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Structure_AdapterModules/ModuleLoader.cs b/Structure_AdapterModules/ModuleLoader.cs index 4aaf9786..52ed5045 100644 --- a/Structure_AdapterModules/ModuleLoader.cs +++ b/Structure_AdapterModules/ModuleLoader.cs @@ -44,7 +44,7 @@ public static void LoadModules(this BHoMAdapter adapter) adapter.AdapterModules.Add(new GetLoadElementsWithoutID(adapter)); adapter.AdapterModules.Add(new GetLoadElementsWithoutID(adapter)); adapter.AdapterModules.Add(new GetLoadElementsWithoutID(adapter)); - adapter.AdapterModules.Add(new GetLoadElementsWithoutID(adapter)); //Gravity loads + adapter.AdapterModules.Add(new GetLoadElementsWithoutID(adapter)); //Here to handle GravityLoads that are IElementLoad } } } From 69c01418262ee835bd68c9641cc89234d6fda2aa Mon Sep 17 00:00:00 2001 From: Isak Naslund Date: Mon, 9 Jan 2023 14:16:51 +0100 Subject: [PATCH 11/12] Add specific module for gravity loads --- .../GetGravityLoadElementsWithoutID.cs | 74 +++++++++++++++++++ Structure_AdapterModules/ModuleLoader.cs | 3 +- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 Structure_AdapterModules/GetGravityLoadElementsWithoutID.cs diff --git a/Structure_AdapterModules/GetGravityLoadElementsWithoutID.cs b/Structure_AdapterModules/GetGravityLoadElementsWithoutID.cs new file mode 100644 index 00000000..cee973be --- /dev/null +++ b/Structure_AdapterModules/GetGravityLoadElementsWithoutID.cs @@ -0,0 +1,74 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2023, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using BH.oM.Base; +using BH.oM.Adapter; +using System; +using System.Linq; +using System.Collections.Generic; +using System.Reflection; +using System.ComponentModel; +using BH.oM.Structure.Elements; +using System.Collections; +using BH.oM.Geometry; +using BH.oM.Structure.Constraints; +using BH.oM.Structure.Loads; + + +namespace BH.Adapter.Modules +{ + [Description("Get all elements of type T that do not contain an adapter ID of the expected type from the provided GravityLoads. Avoids the need to again read and check against elements already in the model.")] + public class GetGravityLoadElementsWithoutID : IGetDependencyModule where T : IBHoMObject + { + /***************************************************/ + /**** Interface method ****/ + /***************************************************/ + + public IEnumerable GetDependencies(IEnumerable objects) + { + List noIdLoadObjects = new List(); + foreach (GravityLoad load in objects) + { + if(load?.Objects?.Elements != null) + noIdLoadObjects.AddRange(load.Objects.Elements.OfType().Where(x => x != null && !x.Fragments.Contains(m_adapterIdType))); + } + return noIdLoadObjects; + } + + /***************************************************/ + /**** Constructors ****/ + /***************************************************/ + + public GetGravityLoadElementsWithoutID(IBHoMAdapter adapter) + { + m_adapterIdType = adapter.AdapterIdFragmentType; + } + + /***************************************************/ + + private Type m_adapterIdType; + + /***************************************************/ + } +} + + diff --git a/Structure_AdapterModules/ModuleLoader.cs b/Structure_AdapterModules/ModuleLoader.cs index 52ed5045..1f812945 100644 --- a/Structure_AdapterModules/ModuleLoader.cs +++ b/Structure_AdapterModules/ModuleLoader.cs @@ -44,7 +44,8 @@ public static void LoadModules(this BHoMAdapter adapter) adapter.AdapterModules.Add(new GetLoadElementsWithoutID(adapter)); adapter.AdapterModules.Add(new GetLoadElementsWithoutID(adapter)); adapter.AdapterModules.Add(new GetLoadElementsWithoutID(adapter)); - adapter.AdapterModules.Add(new GetLoadElementsWithoutID(adapter)); //Here to handle GravityLoads that are IElementLoad + adapter.AdapterModules.Add(new GetGravityLoadElementsWithoutID(adapter)); + adapter.AdapterModules.Add(new GetGravityLoadElementsWithoutID(adapter)); } } } From 5f47edba87cd1279da507cc8227aedaf891a3d43 Mon Sep 17 00:00:00 2001 From: Isak Naslund Date: Mon, 9 Jan 2023 14:27:31 +0100 Subject: [PATCH 12/12] Fix correct output types for gravity load and add test --- .../Objects/StructuralAdapter.cs | 3 +- .ci/code/BHoM_Adapter_Tests/PushTests.cs | 36 +++++++++++++++++++ Structure_AdapterModules/ModuleLoader.cs | 3 +- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/.ci/code/BHoM_Adapter_Tests/Objects/StructuralAdapter.cs b/.ci/code/BHoM_Adapter_Tests/Objects/StructuralAdapter.cs index dccf3907..24d60c2c 100644 --- a/.ci/code/BHoM_Adapter_Tests/Objects/StructuralAdapter.cs +++ b/.ci/code/BHoM_Adapter_Tests/Objects/StructuralAdapter.cs @@ -71,7 +71,8 @@ public StructuralAdapter() {typeof(RigidLink), new List { typeof(LinkConstraint), typeof(Node) } }, {typeof(FEMesh), new List { typeof(Node), typeof(ISurfaceProperty)} }, { typeof(IElementLoad), new List{ typeof(Bar)} }, - { typeof(IElementLoad), new List{ typeof(Node)} } + { typeof(IElementLoad), new List{ typeof(Node)} }, + { typeof(GravityLoad), new List{ typeof(Bar), typeof(Panel), typeof(FEMesh)} } }; AdapterIdFragmentType = typeof(StructuralAdapterId); diff --git a/.ci/code/BHoM_Adapter_Tests/PushTests.cs b/.ci/code/BHoM_Adapter_Tests/PushTests.cs index 8c16df72..f77a0cb8 100644 --- a/.ci/code/BHoM_Adapter_Tests/PushTests.cs +++ b/.ci/code/BHoM_Adapter_Tests/PushTests.cs @@ -223,5 +223,41 @@ public void DependencyOrder_CreateLoadHalfObjectsWithIds() Assert.AreEqual(withoutIdCount, barCreationCount, "Wrong number of bars created."); } + + [Test] + public void DependencyOrder_CreateGravityLoadHalfObjectsWithIds() + { + int objectCount = 10; + List bars = Create.RandomObjects(objectCount); + List panels = Create.RandomObjects(objectCount); + int withIdCount = objectCount / 2; + int withoutIdCount = objectCount - withIdCount; + for (int i = 0; i < withIdCount; i++) + { + Engine.Adapter.Modify.SetAdapterId(bars[i], new StructuralAdapterId { Id = i + 1 }); + Engine.Adapter.Modify.SetAdapterId(panels[i], new StructuralAdapterId { Id = i + 1 }); + } + + //Shuffle the order fo the bars. + //Doing this to test that the order of bars with and without Id does not matter + Random random = new Random(2); + bars = bars.OrderBy(x => random.Next()).ToList(); + panels = panels.OrderBy(x => random.Next()).ToList(); + + GravityLoad load = Create.RandomObject(); + load.Objects.Elements = bars.Cast().Concat(panels).ToList(); + + sa.Push(new List { load }); + + Assert.IsTrue(sa.Created.Any(x => x.Item1 == typeof(Bar)), "No bars created."); + int barCreationCount = sa.Created.First(x => x.Item1 == typeof(Bar)).Item2.Count(); + + Assert.AreEqual(withoutIdCount, barCreationCount, "Wrong number of bars created."); + + Assert.IsTrue(sa.Created.Any(x => x.Item1 == typeof(Panel)), "No Panels created."); + int panelsCreationCount = sa.Created.First(x => x.Item1 == typeof(Panel)).Item2.Count(); + + Assert.AreEqual(withoutIdCount, panelsCreationCount, "Wrong number of Panels created."); + } } } \ No newline at end of file diff --git a/Structure_AdapterModules/ModuleLoader.cs b/Structure_AdapterModules/ModuleLoader.cs index 1f812945..3adb37b3 100644 --- a/Structure_AdapterModules/ModuleLoader.cs +++ b/Structure_AdapterModules/ModuleLoader.cs @@ -45,7 +45,8 @@ public static void LoadModules(this BHoMAdapter adapter) adapter.AdapterModules.Add(new GetLoadElementsWithoutID(adapter)); adapter.AdapterModules.Add(new GetLoadElementsWithoutID(adapter)); adapter.AdapterModules.Add(new GetGravityLoadElementsWithoutID(adapter)); - adapter.AdapterModules.Add(new GetGravityLoadElementsWithoutID(adapter)); + adapter.AdapterModules.Add(new GetGravityLoadElementsWithoutID(adapter)); + adapter.AdapterModules.Add(new GetGravityLoadElementsWithoutID(adapter)); } } }