From 18f62f101667178a182942cfdda2fa1e4dcc3895 Mon Sep 17 00:00:00 2001 From: Arne Martensen Date: Sat, 15 Jun 2024 23:58:47 +0200 Subject: [PATCH 1/3] Loads can be pushed. --- .../CRUD/Create/BHoMDataStructure/Loading/Load.cs | 10 +++++----- RFEM6_Adapter/CRUD/NextId/NextId.cs | 6 +++--- .../CRUD/Read/BHoMDataStructure/Loading/Load.cs | 9 +++------ .../Convert/ToRFEM6/BHoMDataStructure/Loading/Load.cs | 6 +++--- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/RFEM6_Adapter/CRUD/Create/BHoMDataStructure/Loading/Load.cs b/RFEM6_Adapter/CRUD/Create/BHoMDataStructure/Loading/Load.cs index 61da953..5abc8e7 100644 --- a/RFEM6_Adapter/CRUD/Create/BHoMDataStructure/Loading/Load.cs +++ b/RFEM6_Adapter/CRUD/Create/BHoMDataStructure/Loading/Load.cs @@ -70,7 +70,7 @@ private bool CreateCollection(IEnumerable bhLoads) var currrSurfaceIds = (bhLoad as AreaUniformlyDistributedLoad).Objects.Elements.ToList().Select(e => m_PanelIDdict[e as Panel]).ToArray(); rfemAreaLoad.surfaces = currrSurfaceIds; //rfemAreaLoad. = currrSurfaceIds; - m_Model.set_surface_load(bhLoad.Loadcase.GetRFEM6ID(), rfemAreaLoad); + m_Model.set_surface_load(bhLoad.Loadcase.Number, rfemAreaLoad); continue; } @@ -106,7 +106,7 @@ private bool CreateCollection(IEnumerable bhLoads) int id = m_LoadcaseLoadIdDict[bhLoad.Loadcase][bhLoad.GetType().Name]; member_load member_load = (bhLoad as BarUniformlyDistributedLoad).ToRFEM6((member_load_load_type)nodalLoadType, id); var rfMemberLoad = member_load; - m_Model.set_member_load(bhLoad.Loadcase.GetRFEM6ID(), rfMemberLoad); + m_Model.set_member_load(bhLoad.Loadcase.Number, rfMemberLoad); continue; } @@ -116,7 +116,7 @@ private bool CreateCollection(IEnumerable bhLoads) UpdateLoadIdDictionary(bhLoad); int id = m_LoadcaseLoadIdDict[bhLoad.Loadcase][bhLoad.GetType().Name]; nodal_load rfPointLoad = (bhLoad as PointLoad).ToRFEM6((nodal_load_load_type)nodalLoadType, id); - m_Model.set_nodal_load(bhLoad.Loadcase.GetRFEM6ID(), rfPointLoad); + m_Model.set_nodal_load(bhLoad.Loadcase.Number, rfPointLoad); continue; } @@ -156,7 +156,7 @@ private bool CreateCollection(IEnumerable bhLoads) int id = m_LoadcaseLoadIdDict[bhLoad.Loadcase][bhLoad.GetType().Name + "_NonFreeLineLoad"]; var locatedEdte = edgeProsepectSet.Where(e => (edgeComparer).Equals(e, new Edge() { Curve = (bhLoad as GeometricalLineLoad).Location })).FirstOrDefault(); line_load rfLineLoad = (bhLoad as GeometricalLineLoad).ToRFEM6(id, locatedEdte.GetRFEM6ID(), (line_load_load_type)MomentOfForceLoad(bhLoad)); - m_Model.set_line_load(bhLoad.Loadcase.GetRFEM6ID(), rfLineLoad); + m_Model.set_line_load(bhLoad.Loadcase.Number, rfLineLoad); continue; } else @@ -203,7 +203,7 @@ private bool CreateCollection(IEnumerable bhLoads) // int id = m_LoadcaseLoadIdDict[bhLoad.Loadcase][bhLoad.GetType().Name + "_FreeLineLoad"]; free_line_load rfFreeLineLoad = (bhLoad as GeometricalLineLoad).ToRFEM6(id, currrSurfaceIds); - m_Model.set_free_line_load(bhLoad.Loadcase.GetRFEM6ID(), rfFreeLineLoad); + m_Model.set_free_line_load(bhLoad.Loadcase.Number, rfFreeLineLoad); continue; } diff --git a/RFEM6_Adapter/CRUD/NextId/NextId.cs b/RFEM6_Adapter/CRUD/NextId/NextId.cs index a182cd8..229e480 100644 --- a/RFEM6_Adapter/CRUD/NextId/NextId.cs +++ b/RFEM6_Adapter/CRUD/NextId/NextId.cs @@ -62,10 +62,10 @@ protected override object NextFreeId(Type objectType, bool refresh = false) int id = 0; - if (objectType.Name.Equals("PointLoad")|| objectType.Name.Equals("BarUniformlyDistributedLoad")|| objectType.Name.Equals("GeometricalLineLoad")|| objectType.Name.Equals("AreaUniformlyDistributedLoad")) + if (objectType.Name.Equals("PointLoad") || objectType.Name.Equals("BarUniformlyDistributedLoad") || objectType.Name.Equals("GeometricalLineLoad") || objectType.Name.Equals("AreaUniformlyDistributedLoad")) { - - id = m_Model.get_first_free_number(rfType.Value, 1); + + id = 0; } else diff --git a/RFEM6_Adapter/CRUD/Read/BHoMDataStructure/Loading/Load.cs b/RFEM6_Adapter/CRUD/Read/BHoMDataStructure/Loading/Load.cs index 024383f..15ef786 100644 --- a/RFEM6_Adapter/CRUD/Read/BHoMDataStructure/Loading/Load.cs +++ b/RFEM6_Adapter/CRUD/Read/BHoMDataStructure/Loading/Load.cs @@ -198,9 +198,6 @@ private List ReadLineLoad(List ids = null) private void UpdateLoadIdDictionary(ILoad load) { - - - //Determin LoadType. Lineloads are handled differently as there is the need to discriminate between free and non-free line loads var rfLoadType = load.GetType().ToRFEM6().Value; bool lineLoadhasFragments = false; @@ -238,7 +235,7 @@ private void UpdateLoadIdDictionary(ILoad load) } else { - int k = m_Model.get_first_free_number(rfLoadType, load.Loadcase.GetRFEM6ID()); + int k = m_Model.get_first_free_number(rfLoadType, load.Loadcase.Number); loadIdDict.Add(type, k); } } @@ -251,13 +248,13 @@ private void UpdateLoadIdDictionary(ILoad load) //type += "_" + geoLineLoad.Name; type += "_" + (!isFreeLineLoad ? "NonFreeLineLoad" : "FreeLineLoad"); //var rfLoadType = geoLineLoad.Name == "Free" ? rfModel.object_types.E_OBJECT_TYPE_FREE_LINE_LOAD : rfModel.object_types.E_OBJECT_TYPE_LINE_LOAD; - d.Add(type, m_Model.get_first_free_number(rfLoadType, load.Loadcase.GetRFEM6ID())); + d.Add(type, m_Model.get_first_free_number(rfLoadType, load.Loadcase.Number)); m_LoadcaseLoadIdDict.Add(load.Loadcase, d); } else { - d.Add(type, m_Model.get_first_free_number(load.GetType().ToRFEM6().Value, load.Loadcase.GetRFEM6ID())); + d.Add(type, m_Model.get_first_free_number(load.GetType().ToRFEM6().Value, load.Loadcase.Number)); m_LoadcaseLoadIdDict.Add(load.Loadcase, d); } diff --git a/RFEM6_Adapter/Convert/ToRFEM6/BHoMDataStructure/Loading/Load.cs b/RFEM6_Adapter/Convert/ToRFEM6/BHoMDataStructure/Loading/Load.cs index dd5b60b..86f14a9 100644 --- a/RFEM6_Adapter/Convert/ToRFEM6/BHoMDataStructure/Loading/Load.cs +++ b/RFEM6_Adapter/Convert/ToRFEM6/BHoMDataStructure/Loading/Load.cs @@ -242,7 +242,7 @@ public static rfModel.surface_load ToRFEM6(this AreaUniformlyDistributedLoad bhA no = loadCaseSpecificLoadId, comment = bhAreaLoad.Name, surfaces = bhAreaLoad.Objects.Elements.ToList().Select(x => (x as Panel).GetRFEM6ID()).ToArray(), - load_case = bhAreaLoad.Loadcase.GetRFEM6ID(), + load_case = bhAreaLoad.Loadcase.Number, load_caseSpecified = true, load_distribution = surface_load_load_distribution.LOAD_DISTRIBUTION_UNIFORM, load_distributionSpecified = true, @@ -342,7 +342,7 @@ public static rfModel.free_line_load ToRFEM6(this GeometricalLineLoad bhLineLoad surfaces_string = string.Join(" ", surfaceIds.Select(n => n.ToString())), no = loadCaseSpecificID, - load_case = bhLineLoad.Loadcase.GetRFEM6ID(), + load_case = bhLineLoad.Loadcase.Number, load_caseSpecified = true, load_distribution = free_line_load_load_distribution.LOAD_DISTRIBUTION_LINEAR, load_distributionSpecified = true, @@ -506,7 +506,7 @@ public static rfModel.line_load ToRFEM6(this GeometricalLineLoad bhLineLoad, int { no = id, lines = new int[] { foundEdgeId }, - load_case = bhLineLoad.Loadcase.GetRFEM6ID(), + load_case = bhLineLoad.Loadcase.Number, load_caseSpecified = true, load_distribution = line_load_load_distribution.LOAD_DISTRIBUTION_TRAPEZOIDAL, load_distributionSpecified = true, From f116ecfdea2d11b69ae85c6a9d204b0832859c8e Mon Sep 17 00:00:00 2001 From: Arne Martensen Date: Sun, 16 Jun 2024 10:23:46 +0200 Subject: [PATCH 2/3] .... --- .../BHoMDataStructure/Geometry/Panel.cs | 30 ++++---- RFEM6_Adapter/CRUD/Delete/_IDelete.cs | 4 + RFEM6_Adapter/Comparers/PanelComparer.cs | 74 +++++++++++++++++++ RFEM6_Adapter/RFEM6AdapterSettings.cs | 5 +- 4 files changed, 98 insertions(+), 15 deletions(-) create mode 100644 RFEM6_Adapter/Comparers/PanelComparer.cs diff --git a/RFEM6_Adapter/CRUD/Create/BHoMDataStructure/Geometry/Panel.cs b/RFEM6_Adapter/CRUD/Create/BHoMDataStructure/Geometry/Panel.cs index 313dead..8613a1a 100644 --- a/RFEM6_Adapter/CRUD/Create/BHoMDataStructure/Geometry/Panel.cs +++ b/RFEM6_Adapter/CRUD/Create/BHoMDataStructure/Geometry/Panel.cs @@ -39,22 +39,26 @@ namespace BH.Adapter.RFEM6 public partial class RFEM6Adapter { - private bool CreateCollection(IEnumerable bhPanels) - { + private bool CreateCollection(IEnumerable bhPanels) + { + foreach (Panel bhPanel in bhPanels) + { + rfModel.surface surface = bhPanel.ToRFEM6(); - foreach (Panel bhPanel in bhPanels) - { + if (m_PanelIDdict.ContainsKey(bhPanel)) + { + m_PanelIDdict[bhPanel] = bhPanel.GetRFEM6ID(); + } + else + { + m_PanelIDdict.Add(bhPanel, bhPanel.GetRFEM6ID()); + } - rfModel.surface surface = bhPanel.ToRFEM6(); - m_PanelIDdict.Add(bhPanel, bhPanel.GetRFEM6ID()); + m_Model.set_surface(surface); + } - - m_Model.set_surface(surface); - - } - - return true; - } + return true; + } } } diff --git a/RFEM6_Adapter/CRUD/Delete/_IDelete.cs b/RFEM6_Adapter/CRUD/Delete/_IDelete.cs index a0cc752..ed672a5 100644 --- a/RFEM6_Adapter/CRUD/Delete/_IDelete.cs +++ b/RFEM6_Adapter/CRUD/Delete/_IDelete.cs @@ -43,6 +43,10 @@ protected override int IDelete(Type type, IEnumerable ids, ActionConfig if (!rfemType.HasValue) { + //Avoind warking when type is edge + if (type.Name == "Edge") { return 0; } + + // Log a warning if the type is not supported BH.Engine.Base.Compute.RecordWarning($"Delete not implemented for obejcts of type {type.Name}."); return 0; } diff --git a/RFEM6_Adapter/Comparers/PanelComparer.cs b/RFEM6_Adapter/Comparers/PanelComparer.cs new file mode 100644 index 0000000..f524c6b --- /dev/null +++ b/RFEM6_Adapter/Comparers/PanelComparer.cs @@ -0,0 +1,74 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2024, 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 System; +using System.Collections.Generic; +using BH.oM.Structure.Elements; +using BH.Engine.Structure; +using System.Linq; +using BH.oM.Analytical.Elements; +using BH.oM.Geometry; +using BH.Engine.Geometry; +using BH.oM.Adapters.RFEM6.IntermediateDatastructure.Geometry; +using BH.Engine.Spatial; + +namespace BH.Adapter.RFEM6 +{ + public class PanelComparer : IEqualityComparer + { + /***************************************************/ + /**** Constructors ****/ + /***************************************************/ + + public PanelComparer() + { + + } + + /***************************************************/ + /**** Public Methods ****/ + /***************************************************/ + + public bool Equals(Panel panel0, Panel panel1) + { + + if(panel0.Centroid().Distance(panel1.Centroid())<0.001) return true; + + return false; + } + + /***************************************************/ + + public int GetHashCode(Panel panel) + { + //Check whether the object is null + return 0; + } + + /***************************************************/ + } +} + + + + + diff --git a/RFEM6_Adapter/RFEM6AdapterSettings.cs b/RFEM6_Adapter/RFEM6AdapterSettings.cs index 924177d..cafefa1 100644 --- a/RFEM6_Adapter/RFEM6AdapterSettings.cs +++ b/RFEM6_Adapter/RFEM6AdapterSettings.cs @@ -110,8 +110,9 @@ private Dictionary GenerateAdapterComparersSettings() {typeof(Edge), new EdgeComparer()}, {typeof(RFEMLineSupport), new RFEMLineSupportComparer() }, {typeof(RFEMLine), new RFEMLineComparer(3) }, - {typeof(Panel), new RFEMPanelComparer() }, - {typeof(Loadcase), new LoadCaseComparer() }, + //{typeof(Panel), new RFEMPanelComparer() }, + {typeof(Panel), new PanelComparer() }, + {typeof(Loadcase), new LoadCaseComparer() }, }; From 21c78cf4a3b1e44653c2e11a18199056b8de5563 Mon Sep 17 00:00:00 2001 From: Arne Martensen Date: Mon, 17 Jun 2024 12:04:42 +0200 Subject: [PATCH 3/3] pull works --- .../Read/BHoMDataStructure/Loading/Load.cs | 337 ++++++++++-------- 1 file changed, 179 insertions(+), 158 deletions(-) diff --git a/RFEM6_Adapter/CRUD/Read/BHoMDataStructure/Loading/Load.cs b/RFEM6_Adapter/CRUD/Read/BHoMDataStructure/Loading/Load.cs index 15ef786..d2ff072 100644 --- a/RFEM6_Adapter/CRUD/Read/BHoMDataStructure/Loading/Load.cs +++ b/RFEM6_Adapter/CRUD/Read/BHoMDataStructure/Loading/Load.cs @@ -38,233 +38,254 @@ namespace BH.Adapter.RFEM6 { - public partial class RFEM6Adapter - { + public partial class RFEM6Adapter + { - private List ReadBarLoad(List ids = null) - { - //Find all possible Load cases - Dictionary loadCaseMap = this.GetCachedOrReadAsDictionary(); - List loadCaseIds = loadCaseMap.Keys.ToList(); - Dictionary memberMap = this.GetCachedOrReadAsDictionary(); + private List ReadBarLoad(List ids = null) + { + //Find all possible Load cases + Dictionary loadCaseMap = this.GetCachedOrReadAsDictionary(); + List loadCaseIds = loadCaseMap.Keys.ToList(); + Dictionary memberMap = this.GetCachedOrReadAsDictionary(); - rfModel.object_with_children[] numbers = m_Model.get_all_object_numbers_by_type(rfModel.object_types.E_OBJECT_TYPE_MEMBER_LOAD); + rfModel.object_with_children[] numbers = m_Model.get_all_object_numbers_by_type(rfModel.object_types.E_OBJECT_TYPE_MEMBER_LOAD); - IEnumerable foundLoadCases = numbers.SelectMany(n => n.children.ToList().Select(child => m_Model.get_member_load(child, n.no))); + IEnumerable foundLoadCases = numbers.SelectMany(n => n.children.ToList().Select(child => m_Model.get_member_load(child, n.no))); - List loadCases = new List(); - foundLoadCases=foundLoadCases.OrderBy(n => n.load_case).ThenBy(t=>t.no); - foreach (rfModel.member_load memberLoad in foundLoadCases) - { + List loadCases = new List(); + foundLoadCases = foundLoadCases.OrderBy(n => n.load_case).ThenBy(t => t.no); + foreach (rfModel.member_load memberLoad in foundLoadCases) + { - loadCases.Add(memberLoad.FromRFEM(memberLoad.members.ToList().Select(m => memberMap[m]).ToList(), loadCaseMap[memberLoad.load_case])); + loadCases.Add(memberLoad.FromRFEM(memberLoad.members.ToList().Select(m => memberMap[m]).ToList(), loadCaseMap[memberLoad.load_case])); - } + } - return loadCases; - } + return loadCases; + } - private List ReadPointLoad(List ids = null) - { - //Find all possible Load cases - Dictionary loadCaseMap = this.GetCachedOrReadAsDictionary(); - Dictionary memberMap = this.GetCachedOrReadAsDictionary(); + private List ReadPointLoad(List ids = null) + { + //Find all possible Load cases + Dictionary loadCaseMap = this.GetCachedOrReadAsDictionary(); + Dictionary memberMap = this.GetCachedOrReadAsDictionary(); - rfModel.object_with_children[] numbers = m_Model.get_all_object_numbers_by_type(rfModel.object_types.E_OBJECT_TYPE_NODAL_LOAD); + rfModel.object_with_children[] numbers = m_Model.get_all_object_numbers_by_type(rfModel.object_types.E_OBJECT_TYPE_NODAL_LOAD); - //IEnumerable founeNodalLoad = numbers.ToList().Select(n => m_Model.get_nodal_load(n.children[0], n.no)); - IEnumerable founeNodalLoad = numbers.SelectMany(n => n.children.Select(child => m_Model.get_nodal_load(child, n.no))); + //IEnumerable founeNodalLoad = numbers.ToList().Select(n => m_Model.get_nodal_load(n.children[0], n.no)); + IEnumerable founeNodalLoad = numbers.SelectMany(n => n.children.Select(child => m_Model.get_nodal_load(child, n.no))); - List loads = new List(); - foreach (rfModel.nodal_load nodeLoad in founeNodalLoad) - { - if (nodeLoad.load_type == rfModel.nodal_load_load_type.LOAD_TYPE_MASS) - { + List loads = new List(); + foreach (rfModel.nodal_load nodeLoad in founeNodalLoad) + { + if (nodeLoad.load_type == rfModel.nodal_load_load_type.LOAD_TYPE_MASS) + { - BH.Engine.Base.Compute.RecordWarning($"Nodal Loads of type {nodeLoad.load_type} can not be read from RFEM6. If possible convert them to either Force, Moment or Components!"); - continue; - } + BH.Engine.Base.Compute.RecordWarning($"Nodal Loads of type {nodeLoad.load_type} can not be read from RFEM6. If possible convert them to either Force, Moment or Components!"); + continue; + } - loads.Add(nodeLoad.FromRFEM(nodeLoad.nodes.ToList().Select(m => memberMap[m]).ToList(), loadCaseMap[nodeLoad.load_case])); + loads.Add(nodeLoad.FromRFEM(nodeLoad.nodes.ToList().Select(m => memberMap[m]).ToList(), loadCaseMap[nodeLoad.load_case])); - } + } - return loads; - } + return loads; + } - private List ReadAreaLoad(List ids = null) - { - List loads = new List(); + private List ReadAreaLoad(List ids = null) + { + List loads = new List(); - //Find all possible Load cases - Dictionary loadCaseMap = this.GetCachedOrReadAsDictionary(); - Dictionary panelMap = this.GetCachedOrReadAsDictionary(); + //Find all possible Load cases + Dictionary loadCaseMap = this.GetCachedOrReadAsDictionary(); + Dictionary panelMap = this.GetCachedOrReadAsDictionary(); - rfModel.object_with_children[] numbers = m_Model.get_all_object_numbers_by_type(rfModel.object_types.E_OBJECT_TYPE_SURFACE_LOAD); + rfModel.object_with_children[] numbers = m_Model.get_all_object_numbers_by_type(rfModel.object_types.E_OBJECT_TYPE_SURFACE_LOAD); - //IEnumerable foundSurfaceLoad = numbers.ToList().Select(n => m_Model.get_surface_load(n.children[0], n.no)); - IEnumerable foundSurfaceLoad = numbers.SelectMany(n => n.children.Select(child => m_Model.get_surface_load(child, n.no))); + //IEnumerable foundSurfaceLoad = numbers.ToList().Select(n => m_Model.get_surface_load(n.children[0], n.no)); + IEnumerable foundSurfaceLoad = numbers.SelectMany(n => n.children.Select(child => m_Model.get_surface_load(child, n.no))); - foundSurfaceLoad = foundSurfaceLoad.OrderBy(n => n.load_case).ThenBy(t => t.no); - foreach (rfModel.surface_load surfaceLoad in foundSurfaceLoad) - { - List panels = surfaceLoad.surfaces.ToList().Select(s => panelMap[s]).ToList(); - Loadcase loadcase = loadCaseMap[surfaceLoad.load_case]; + foundSurfaceLoad = foundSurfaceLoad.OrderBy(n => n.load_case).ThenBy(t => t.no); + foreach (rfModel.surface_load surfaceLoad in foundSurfaceLoad) + { + List panels = surfaceLoad.surfaces.ToList().Select(s => panelMap[s]).ToList(); + Loadcase loadcase = loadCaseMap[surfaceLoad.load_case]; - if (!(surfaceLoad.load_distribution is rfModel.surface_load_load_distribution.LOAD_DISTRIBUTION_UNIFORM)) - { - Engine.Base.Compute.RecordNote("The current RFEM6 includes Surfaceloads with a non-uniformal load distributeion, these Loads will not be pulled."); - continue; - } + if (!(surfaceLoad.load_distribution is rfModel.surface_load_load_distribution.LOAD_DISTRIBUTION_UNIFORM)) + { + Engine.Base.Compute.RecordNote("The current RFEM6 includes Surfaceloads with a non-uniformal load distributeion, these Loads will not be pulled."); + continue; + } - loads.Add(surfaceLoad.FromRFEM(loadCaseMap[surfaceLoad.load_case], panels)); + loads.Add(surfaceLoad.FromRFEM(loadCaseMap[surfaceLoad.load_case], panels)); - } + } - return loads; - } + return loads; + } - private List ReadFreeLineLoad(List ids = null) - { - List loads = new List(); + private List ReadFreeLineLoad(List ids = null) + { + List loads = new List(); - Dictionary loadCaseMap = this.GetCachedOrReadAsDictionary(); - Dictionary panelMap = this.GetCachedOrReadAsDictionary(); + Dictionary loadCaseMap = this.GetCachedOrReadAsDictionary(); + Dictionary panelMap = this.GetCachedOrReadAsDictionary(); - rfModel.object_with_children[] numbers = m_Model.get_all_object_numbers_by_type(rfModel.object_types.E_OBJECT_TYPE_FREE_LINE_LOAD); - //rfModel.object_with_children[] numbers = m_Model.get_all_object_numbers_by_type(rfModel.object_types.line); + rfModel.object_with_children[] numbers = m_Model.get_all_object_numbers_by_type(rfModel.object_types.E_OBJECT_TYPE_FREE_LINE_LOAD); + + List foundFreeLineLoads = new List(); + foreach (var num in numbers ) { + var loadNumbers=num.children.ToList(); + + foreach (var loadNumber in loadNumbers) + { + var freeLineLoad = m_Model.get_free_line_load(loadNumber, num.no); + foundFreeLineLoads.Add(freeLineLoad); + } - //IEnumerable foundFreeLineLoads = numbers.ToList().Select(n => m_Model.get_free_line_load(n.children[0], n.no)); - IEnumerable foundFreeLineLoads = numbers.SelectMany(n => n.children.Select(child => m_Model.get_free_line_load(child, n.no))); + } + foreach (rfModel.free_line_load freeLineLoad in foundFreeLineLoads) + { + List panelList; + if (freeLineLoad.surfaces is null) + { + panelList = new List(); + } + else + { - foreach (rfModel.free_line_load freeLineLoad in foundFreeLineLoads) - { - List panelList; - if (freeLineLoad.surfaces.ToList().First() == 0) - { - panelList = new List(); - } - else - { + panelList = freeLineLoad.surfaces.ToList().Select(s => panelMap[s]).ToList(); - panelList = freeLineLoad.surfaces.ToList().Select(s => panelMap[s]).ToList(); + } + loads.Add(freeLineLoad.FromRFEM(loadCaseMap[freeLineLoad.load_case], panelList)); - } - loads.Add(freeLineLoad.FromRFEM(loadCaseMap[freeLineLoad.load_case], panelList)); + } - } + return loads; + } - return loads; - } + private List ReadLineLoad(List ids = null) + { + List loads = new List(); - private List ReadLineLoad(List ids = null) - { - List loads = new List(); + Dictionary loadCaseMap = this.GetCachedOrReadAsDictionary(); + Dictionary edgeDictionary = this.GetCachedOrReadAsDictionary(); - Dictionary loadCaseMap = this.GetCachedOrReadAsDictionary(); - Dictionary edgeDictionary = this.GetCachedOrReadAsDictionary(); + rfModel.object_with_children[] numbers = m_Model.get_all_object_numbers_by_type(rfModel.object_types.E_OBJECT_TYPE_LINE_LOAD); + //rfModel.object_with_children[] numbers = m_Model.get_all_object_numbers_by_type(rfModel.object_types.line); - rfModel.object_with_children[] numbers = m_Model.get_all_object_numbers_by_type(rfModel.object_types.E_OBJECT_TYPE_LINE_LOAD); - //rfModel.object_with_children[] numbers = m_Model.get_all_object_numbers_by_type(rfModel.object_types.line); + //IEnumerable foundFreeLineLoads = numbers.ToList().Select(n => m_Model.get_line_load(n.children[0], n.no)); + //IEnumerable foundFreeLineLoads = numbers.SelectMany(n => n.children.Select(child => m_Model.get_line_load(child, n.no))); - //IEnumerable foundFreeLineLoads = numbers.ToList().Select(n => m_Model.get_line_load(n.children[0], n.no)); - IEnumerable foundFreeLineLoads = numbers.SelectMany(n => n.children.Select(child => m_Model.get_line_load(child, n.no))); + List foundFreeLineLoads = new List(); + foreach (var num in numbers) + { + var loadNumbers = num.children.ToList(); - foreach (rfModel.line_load lineLoad in foundFreeLineLoads) - { + foreach (var loadNumber in loadNumbers) + { + var lineLoad = m_Model.get_line_load(loadNumber, num.no); + foundFreeLineLoads.Add(lineLoad); + } - List curveList = lineLoad.lines.ToList().Select(l => edgeDictionary[l].Curve).Where(cu => (cu is Line) || (cu is Polyline && cu.ControlPoints().Count == 2)).ToList(); - List lines = curveList.Select(k => new Line() { Start = k.ControlPoints().First(), End = k.ControlPoints().First() }).ToList(); - lines.ForEach(l => loads.Add(lineLoad.FromRFEM(loadCaseMap[lineLoad.load_case], l))); + } - } - return loads; - } + foreach (rfModel.line_load lineLoad in foundFreeLineLoads) + { - private void UpdateLoadIdDictionary(ILoad load) - { + List curveList = lineLoad.lines.ToList().Select(l => edgeDictionary[l].Curve).Where(cu => (cu is Line) || (cu is Polyline && cu.ControlPoints().Count == 2)).ToList(); + List lines = curveList.Select(k => new Line() { Start = k.ControlPoints().First(), End = k.ControlPoints().First() }).ToList(); + lines.ForEach(l => loads.Add(lineLoad.FromRFEM(loadCaseMap[lineLoad.load_case], l))); - //Determin LoadType. Lineloads are handled differently as there is the need to discriminate between free and non-free line loads - var rfLoadType = load.GetType().ToRFEM6().Value; - bool lineLoadhasFragments = false; - bool isFreeLineLoad = false; - if (load is GeometricalLineLoad geomLineLoad) - { + } - lineLoadhasFragments = load.Fragments.ToList().Any(f => f.GetType().Name == "RFEM6GeometricalLineLoadTypes"); - isFreeLineLoad = lineLoadhasFragments ? BH.Engine.Base.Query.GetAllFragments(load)[0].PropertyValue("geometrialLineLoadType").ToString().Equals("FreeLineLoad") : true; + return loads; + } - rfLoadType = (lineLoadhasFragments || isFreeLineLoad) ? rfModel.object_types.E_OBJECT_TYPE_FREE_LINE_LOAD : rfModel.object_types.E_OBJECT_TYPE_LINE_LOAD; - } - else - { + private void UpdateLoadIdDictionary(ILoad load) + { - rfLoadType = load.GetType().ToRFEM6().Value; - } + //Determin LoadType. Lineloads are handled differently as there is the need to discriminate between free and non-free line loads + var rfLoadType = load.GetType().ToRFEM6().Value; + bool lineLoadhasFragments = false; + bool isFreeLineLoad = false; + if (load is GeometricalLineLoad geomLineLoad) + { - //Check if the loadcase is already in the dictionary - if (m_LoadcaseLoadIdDict.TryGetValue(load.Loadcase, out Dictionary loadIdDict)) - { - String type = load.GetType().Name; + lineLoadhasFragments = load.Fragments.ToList().Any(f => f.GetType().Name == "RFEM6GeometricalLineLoadTypes"); + isFreeLineLoad = lineLoadhasFragments ? BH.Engine.Base.Query.GetAllFragments(load)[0].PropertyValue("geometrialLineLoadType").ToString().Equals("FreeLineLoad") : true; - if (load is GeometricalLineLoad geoLineLoad) - { - // Assuming 'Designation' is the property that indicates 'Free' or 'NonFree' - //type += "_" + geoLineLoad.Name; // e.g., "GeometricalLineLoad_Free" - type += "_" + (!isFreeLineLoad ? "NonFreeLineLoad" : "FreeLineLoad"); + rfLoadType = (lineLoadhasFragments || isFreeLineLoad) ? rfModel.object_types.E_OBJECT_TYPE_FREE_LINE_LOAD : rfModel.object_types.E_OBJECT_TYPE_LINE_LOAD; + } + else + { - } + rfLoadType = load.GetType().ToRFEM6().Value; + } - if (loadIdDict.TryGetValue(type, out int id)) - { - loadIdDict[type] = id + 1; - } - else - { - int k = m_Model.get_first_free_number(rfLoadType, load.Loadcase.Number); - loadIdDict.Add(type, k); - } - } - else - { - var d = new Dictionary(); - String type = load.GetType().Name; - if (load is GeometricalLineLoad geoLineLoad) - { - //type += "_" + geoLineLoad.Name; - type += "_" + (!isFreeLineLoad ? "NonFreeLineLoad" : "FreeLineLoad"); - //var rfLoadType = geoLineLoad.Name == "Free" ? rfModel.object_types.E_OBJECT_TYPE_FREE_LINE_LOAD : rfModel.object_types.E_OBJECT_TYPE_LINE_LOAD; - d.Add(type, m_Model.get_first_free_number(rfLoadType, load.Loadcase.Number)); - m_LoadcaseLoadIdDict.Add(load.Loadcase, d); + //Check if the loadcase is already in the dictionary + if (m_LoadcaseLoadIdDict.TryGetValue(load.Loadcase, out Dictionary loadIdDict)) + { + String type = load.GetType().Name; - } - else - { - d.Add(type, m_Model.get_first_free_number(load.GetType().ToRFEM6().Value, load.Loadcase.Number)); - m_LoadcaseLoadIdDict.Add(load.Loadcase, d); - } + if (load is GeometricalLineLoad geoLineLoad) + { + // Assuming 'Designation' is the property that indicates 'Free' or 'NonFree' + //type += "_" + geoLineLoad.Name; // e.g., "GeometricalLineLoad_Free" + type += "_" + (!isFreeLineLoad ? "NonFreeLineLoad" : "FreeLineLoad"); - } + } - } + if (loadIdDict.TryGetValue(type, out int id)) + { + loadIdDict[type] = id + 1; + } + else + { + int k = m_Model.get_first_free_number(rfLoadType, load.Loadcase.Number); + loadIdDict.Add(type, k); + } + } + else + { + var d = new Dictionary(); + String type = load.GetType().Name; + if (load is GeometricalLineLoad geoLineLoad) + { + //type += "_" + geoLineLoad.Name; + type += "_" + (!isFreeLineLoad ? "NonFreeLineLoad" : "FreeLineLoad"); + //var rfLoadType = geoLineLoad.Name == "Free" ? rfModel.object_types.E_OBJECT_TYPE_FREE_LINE_LOAD : rfModel.object_types.E_OBJECT_TYPE_LINE_LOAD; + d.Add(type, m_Model.get_first_free_number(rfLoadType, load.Loadcase.Number)); + m_LoadcaseLoadIdDict.Add(load.Loadcase, d); + } + else + { + d.Add(type, m_Model.get_first_free_number(load.GetType().ToRFEM6().Value, load.Loadcase.Number)); + m_LoadcaseLoadIdDict.Add(load.Loadcase, d); + } + } - } + } + + + + } }