diff --git a/GSA_Adapter/CRUD/Create.cs b/GSA_Adapter/CRUD/Create.cs index 1983234c..94dfb9d3 100644 --- a/GSA_Adapter/CRUD/Create.cs +++ b/GSA_Adapter/CRUD/Create.cs @@ -75,13 +75,15 @@ protected override bool ICreate(IEnumerable objects, ActionConfig actionCo /***************************************************/ +#if GSA_10_1 private bool CreateMaterials(IEnumerable materials) { bool success = true; foreach (IMaterialFragment material in materials) { - int index = m_gsaCom.GwaCommand("HIGHEST, " + Convert.ToGsaString(material.GetType())) + 1; - this.SetAdapterId(material, index); + string type = Convert.ToGsaString(material.GetType()); + int index = m_gsaCom.GwaCommand("HIGHEST, " + type) + 1; + this.SetAdapterId(material, $"{type.Split('_').Last()}:{index}"); success &= ComCall(Convert.IToGsaString(material, index.ToString())); } return success; @@ -89,6 +91,8 @@ private bool CreateMaterials(IEnumerable materials) /***************************************************/ +#endif + private bool CreateObject(BH.oM.Base.IBHoMObject obj) { return ComCall(Convert.IToGsaString(obj, GetAdapterId(obj).ToString())); diff --git a/GSA_Adapter/CRUD/Read.cs b/GSA_Adapter/CRUD/Read.cs index 3147533e..662d9b2e 100644 --- a/GSA_Adapter/CRUD/Read.cs +++ b/GSA_Adapter/CRUD/Read.cs @@ -105,27 +105,7 @@ protected override IEnumerable IRead(Type type, IList indices, Acti public List ReadMaterials(List ids = null) { - return ReadMaterials(ids, false); - } - - /***************************************************/ - - public List ReadMaterials(List ids = null, bool includeStandard = false) - { - List materials = ReadMaterialDictionary(ids, includeStandard).Select(x => x.Value).ToList(); - - if (ids != null && ids.Count != 0) - materials = materials.Where(x => ids.Contains(x.GSAId().ToString())).ToList(); - - return materials; - } - - public Dictionary ReadMaterialDictionary(List ids = null, bool includeStandard = false) - { - //List materials = ReadMaterials(null, false); List materials = new List(); - List keys = new List(); - Dictionary materialDictionary = new Dictionary(); #if GSA_10_1 string allProps = m_gsaCom.GwaCommand("GET_ALL, MAT_ANAL.1").ToString(); @@ -141,31 +121,33 @@ public Dictionary ReadMaterialDictionary(List string allProps = m_gsaCom.GwaCommand("GET_ALL, MAT").ToString(); #endif string[] matArr = string.IsNullOrWhiteSpace(allProps) ? new string[0] : allProps.Split('\n'); - matArr = matArr.Where(x => !string.IsNullOrWhiteSpace(x)).ToArray(); + matArr = matArr.Where(x => !string.IsNullOrWhiteSpace(x)).Distinct().ToArray(); if (ids == null) materials = matArr.Select(x => Convert.FromGsaMaterial(x)).Where(x => x != null).ToList(); else materials = matArr.Where(x => ids.Contains(x.Split(',')[1])).Select(x => Convert.FromGsaMaterial(x)).Where(x => x != null).ToList(); - if (includeStandard) - materials.AddRange(GetStandardGsaMaterials()); + return materials; + } - for (int i = 0; i < materials.Count(); i++) - { + /***************************************************/ + + public Dictionary ReadMaterialDictionary(List ids = null, bool includeStandard = false) + { #if GSA_10_1 - string key = matArr[i].Split(("_.").ToCharArray())[1] + ":" + materials[i].GSAId(); + Dictionary materials = GetCachedOrReadAsDictionary(ids); #else - string key = GetAdapterId(materials[i]).ToString(); + Dictionary materials = GetCachedOrReadAsDictionary(ids?.Select(x => int.Parse(x)).ToList()).ToDictionary(x => x.Key.ToString(), x => x.Value); #endif - if (!keys.Contains(key)) + if (includeStandard) + { + foreach (IMaterialFragment standardMaterial in GetStandardGsaMaterials()) { - keys.Add(key); - materialDictionary.Add(key, materials[i]); + materials[standardMaterial.Name] = standardMaterial; } } - - return materialDictionary; + return materials; } /***************************************************/ @@ -189,22 +171,16 @@ public List ReadLoadCases(List ids = null) public List ReadBars(List ids = null) { - //int[] potentialBeamRefs = GenerateIndices(ids, typeof(Bar)); - - //GsaElement[] gsaElements = new GsaElement[potentialBeamRefs.Length]; - //m_gsaCom.Elements(potentialBeamRefs, out gsaElements); #if GSA_10_1 - string allNodes = m_gsaCom.GwaCommand("GET_ALL, EL.4").ToString(); + string allBars = m_gsaCom.GwaCommand("GET_ALL, EL.4").ToString(); #else - string allNodes = m_gsaCom.GwaCommand("GET_ALL, EL.2").ToString(); + string allBars = m_gsaCom.GwaCommand("GET_ALL, EL.2").ToString(); #endif - string[] barArr = string.IsNullOrWhiteSpace(allNodes) ? new string[0] : allNodes.Split('\n'); + string[] barArr = string.IsNullOrWhiteSpace(allBars) ? new string[0] : allBars.Split('\n'); - List secPropList = ReadSectionProperties(); - List nodeList = ReadNodes(); - Dictionary secProps = secPropList.Where(x => x != null).ToDictionary(x => GetAdapterId(x).ToString()); - Dictionary nodes = nodeList.ToDictionary(x => GetAdapterId(x).ToString()); + Dictionary secProps = GetCachedOrReadAsDictionary(); + Dictionary nodes = GetCachedOrReadAsDictionary(); return Convert.FromGsaBars(barArr, secProps, nodes, ids); } @@ -224,8 +200,7 @@ public List ReadLoadCombinations(List ids = null) analList.Add(anal); } - List lCaseList = ReadLoadCases(); - Dictionary lCases = lCaseList.ToDictionary(x => x.Number.ToString()); + Dictionary lCases = GetCachedOrReadAsDictionary(); if (ids == null) lComabinations = analList.Select(x => Convert.FromGsaAnalTask(x, lCases)).ToList(); @@ -366,11 +341,8 @@ public List ReadFEMesh(List ids = null) GsaElement[] gsaElements = new GsaElement[potentialMeshRefs.Length]; m_gsaCom.Elements(potentialMeshRefs, out gsaElements); - List secPropList = ReadProperty2d(); - List nodeList = ReadNodes(); - - Dictionary props = secPropList.Where(x => x != null).ToDictionary(x => GetAdapterId(x).ToString()); - Dictionary nodes = nodeList.ToDictionary(x => GetAdapterId(x).ToString()); + Dictionary props = GetCachedOrReadAsDictionary(); + Dictionary nodes = GetCachedOrReadAsDictionary(); return Convert.FromGsaFEMesh(gsaElements, props, nodes); } @@ -392,11 +364,8 @@ public List ReadLinkConstraint(List ids = null) public List ReadRigidLink(List ids = null) { - List constraintList = ReadLinkConstraint(null); - List nodeList = ReadNodes(); - - Dictionary constraints = constraintList.ToDictionary(x => GetAdapterId(x).ToString()); - Dictionary nodes = nodeList.ToDictionary(x => GetAdapterId(x).ToString()); + Dictionary constraints = GetCachedOrReadAsDictionary(); + Dictionary nodes = GetCachedOrReadAsDictionary(); int[] potentialBeamRefs = GenerateIndices(ids, typeof(RigidLink)); GsaElement[] gsaElements = new GsaElement[potentialBeamRefs.Length]; @@ -414,19 +383,14 @@ public List ReadRigidLink(List ids = null) public List ReadSpacers(List ids = null) { - List nodeList = ReadNodes(); - List spacerProps = ReadSpacerProperties(); - - Dictionary nodes = nodeList.ToDictionary(x => GetAdapterId(x).ToString()); - Dictionary secProps = spacerProps.Where(x => x != null).ToDictionary(x => GetAdapterId(x).ToString()); + Dictionary nodes = GetCachedOrReadAsDictionary(); + Dictionary secProps = GetCachedOrReadAsDictionary(); int[] potentialBeamRefs = GenerateIndices(ids, typeof(Spacer)); GsaElement[] gsaElements = new GsaElement[potentialBeamRefs.Length]; m_gsaCom.Elements(potentialBeamRefs, out gsaElements); return Convert.FromGsaSpacers(gsaElements, secProps, nodes); - - } /***************************************/ @@ -469,6 +433,7 @@ private int[] GenerateIndices(List ids, Type elementType) private List GetStandardGsaMaterials() { +#if !GSA_10_1 List materials = new List(); materials.Add(new Steel() { Name = "STEEL" }); materials.Add(new Concrete() { Name = "CONC_SHORT" }); @@ -481,6 +446,10 @@ private List GetStandardGsaMaterials() } return materials; +#else + return new List(); +#endif + } /***************************************************/ diff --git a/GSA_Adapter/CRUD/Update.cs b/GSA_Adapter/CRUD/Update.cs index 626c3ac0..6c8821c1 100644 --- a/GSA_Adapter/CRUD/Update.cs +++ b/GSA_Adapter/CRUD/Update.cs @@ -27,6 +27,8 @@ using BH.Engine.Adapter; using BH.oM.Adapters.GSA; using BH.Engine.Adapters.GSA; +using BH.oM.Structure.MaterialFragments; +using System.Linq; namespace BH.Adapter.GSA { @@ -73,6 +75,18 @@ private bool Update(IEnumerable objects, ActionConfig actionConfig = nul } /***************************************************/ + +#if GSA_10_1 + private bool Update(IEnumerable materials, ActionConfig actionConfig = null) + { + bool success = true; + foreach (IMaterialFragment material in materials) + { + success &= ComCall(Convert.IToGsaString(material, material.MaterialId())); + } + return success; + } +#endif } } diff --git a/GSA_Adapter/Convert/FromGsa/Elements/Bar.cs b/GSA_Adapter/Convert/FromGsa/Elements/Bar.cs index 18f6f732..c5ea7b39 100644 --- a/GSA_Adapter/Convert/FromGsa/Elements/Bar.cs +++ b/GSA_Adapter/Convert/FromGsa/Elements/Bar.cs @@ -43,7 +43,7 @@ public static partial class Convert /**** Public Methods ****/ /***************************************************/ - public static List FromGsaBars(IEnumerable gsaElements, Dictionary secProps, Dictionary nodes) + public static List FromGsaBars(IEnumerable gsaElements, Dictionary secProps, Dictionary nodes) { List barList = new List(); @@ -71,8 +71,8 @@ public static List FromGsaBars(IEnumerable gsaElements, Diction } Node n1, n2; - nodes.TryGetValue(gsaBar.Topo[0].ToString(), out n1); - nodes.TryGetValue(gsaBar.Topo[1].ToString(), out n2); + nodes.TryGetValue(gsaBar.Topo[0], out n1); + nodes.TryGetValue(gsaBar.Topo[1], out n2); Bar bar = new Bar { StartNode = n1, EndNode = n2 }; bar.ApplyTaggedName(gsaBar.Name); @@ -82,7 +82,7 @@ public static List FromGsaBars(IEnumerable gsaElements, Diction bar.OrientationAngle = gsaBar.Beta; ISectionProperty prop; - secProps.TryGetValue(gsaBar.Property.ToString(), out prop); + secProps.TryGetValue(gsaBar.Property, out prop); bar.SectionProperty = prop; @@ -97,7 +97,7 @@ public static List FromGsaBars(IEnumerable gsaElements, Diction /***************************************************/ - public static List FromGsaBars(IEnumerable gsaStrings, Dictionary secProps, Dictionary nodes, List ids) + public static List FromGsaBars(IEnumerable gsaStrings, Dictionary secProps, Dictionary nodes, List ids) { List barList = new List(); @@ -135,15 +135,15 @@ public static List FromGsaBars(IEnumerable gsaStrings, Dictionary 10) diff --git a/GSA_Adapter/Convert/FromGsa/Elements/FEMesh.cs b/GSA_Adapter/Convert/FromGsa/Elements/FEMesh.cs index c5b749e1..bfe88e58 100644 --- a/GSA_Adapter/Convert/FromGsa/Elements/FEMesh.cs +++ b/GSA_Adapter/Convert/FromGsa/Elements/FEMesh.cs @@ -41,7 +41,7 @@ public static partial class Convert /**** Public Methods ****/ /***************************************************/ - public static List FromGsaFEMesh(IEnumerable gsaElements, Dictionary props, Dictionary nodes) + public static List FromGsaFEMesh(IEnumerable gsaElements, Dictionary props, Dictionary nodes) { List meshList = new List(); @@ -61,12 +61,12 @@ public static List FromGsaFEMesh(IEnumerable gsaElements, Di FEMeshFace face = new FEMeshFace() { NodeListIndices = Enumerable.Range(0, gsaMesh.NumTopo).ToList(), OrientationAngle = gsaMesh.Beta * System.Math.PI / 180 }; face.SetAdapterId(typeof(GSAId), id); ISurfaceProperty property; - props.TryGetValue(gsaMesh.Property.ToString(), out property); + props.TryGetValue(gsaMesh.Property, out property); FEMesh mesh = new FEMesh() { Faces = new List() { face }, - Nodes = gsaMesh.Topo.Select(x => nodes[x.ToString()]).ToList(), + Nodes = gsaMesh.Topo.Select(x => nodes[x]).ToList(), Property = property }; diff --git a/GSA_Adapter/Convert/FromGsa/Elements/RigidLink.cs b/GSA_Adapter/Convert/FromGsa/Elements/RigidLink.cs index 3dc2c76d..473afd01 100644 --- a/GSA_Adapter/Convert/FromGsa/Elements/RigidLink.cs +++ b/GSA_Adapter/Convert/FromGsa/Elements/RigidLink.cs @@ -41,7 +41,7 @@ public static partial class Convert /**** Public Methods ****/ /***************************************************/ - public static List FromGsaRigidLinks(IEnumerable gsaElements, Dictionary constraints, Dictionary nodes) + public static List FromGsaRigidLinks(IEnumerable gsaElements, Dictionary constraints, Dictionary nodes) { List linkList = new List(); @@ -50,17 +50,17 @@ public static List FromGsaRigidLinks(IEnumerable gsaEleme if (gsaLink.eType != 9) continue; - RigidLink face = new RigidLink() + RigidLink link = new RigidLink() { - PrimaryNode = nodes[gsaLink.Topo[0].ToString()], - SecondaryNodes = new List { nodes[gsaLink.Topo[1].ToString()] }, - Constraint = constraints[gsaLink.Property.ToString()] + PrimaryNode = nodes[gsaLink.Topo[0]], + SecondaryNodes = new List { nodes[gsaLink.Topo[1]] }, + Constraint = constraints[gsaLink.Property] }; - face.ApplyTaggedName(gsaLink.Name); + link.ApplyTaggedName(gsaLink.Name); int id = gsaLink.Ref; - face.SetAdapterId(typeof(GSAId), id); - linkList.Add(face); + link.SetAdapterId(typeof(GSAId), id); + linkList.Add(link); } return linkList; diff --git a/GSA_Adapter/Convert/FromGsa/Elements/Spacer.cs b/GSA_Adapter/Convert/FromGsa/Elements/Spacer.cs index 38686c75..5ed0fd65 100644 --- a/GSA_Adapter/Convert/FromGsa/Elements/Spacer.cs +++ b/GSA_Adapter/Convert/FromGsa/Elements/Spacer.cs @@ -46,7 +46,7 @@ public static partial class Convert /**** Public Methods ****/ /***************************************************/ - public static List FromGsaSpacers(IEnumerable gsaElements, Dictionary spaProps, Dictionary nodes) + public static List FromGsaSpacers(IEnumerable gsaElements, Dictionary spaProps, Dictionary nodes) { List spacerList = new List(); @@ -56,16 +56,14 @@ public static List FromGsaSpacers(IEnumerable gsaElements, D continue; Node n1, n2; - nodes.TryGetValue(gsaSpacer.Topo[0].ToString(), out n1); - nodes.TryGetValue(gsaSpacer.Topo[1].ToString(), out n2); + nodes.TryGetValue(gsaSpacer.Topo[0], out n1); + nodes.TryGetValue(gsaSpacer.Topo[1], out n2); Spacer spacer = new Spacer { StartNode = n1, EndNode = n2 }; spacer.ApplyTaggedName(gsaSpacer.Name); - - - SpacerProperty prop; - spaProps.TryGetValue(gsaSpacer.Property.ToString(), out prop); + SpacerProperty prop; + spaProps.TryGetValue(gsaSpacer.Property, out prop); spacer.SpacerProperty = prop; diff --git a/GSA_Adapter/Convert/FromGsa/Loads/LoadCombination.cs b/GSA_Adapter/Convert/FromGsa/Loads/LoadCombination.cs index 2aa9d865..b12df4d8 100644 --- a/GSA_Adapter/Convert/FromGsa/Loads/LoadCombination.cs +++ b/GSA_Adapter/Convert/FromGsa/Loads/LoadCombination.cs @@ -36,7 +36,7 @@ public static partial class Convert /**** Public Methods ****/ /***************************************************/ - public static LoadCombination FromGsaAnalTask(string gsaString, Dictionary lCases) + public static LoadCombination FromGsaAnalTask(string gsaString, Dictionary lCases) { if (string.IsNullOrWhiteSpace(gsaString)) @@ -61,7 +61,7 @@ public static LoadCombination FromGsaAnalTask(string gsaString, Dictionary(typeof(GSAId)).Split(':').Last(); +#else + return material.GSAId().ToString(); #endif + } + + /***************************************************/ private static string CommaSeparatedValues(Vector v) { @@ -238,8 +250,10 @@ private static string GetMaterialType(this IMaterialFragment material) return "CONCRETE"; else if (material is Aluminium) return "ALUMINIUM"; - else if (material is Timber) - return "TIMBER"; + else if (material is Fabric) + return "FABRIC"; + //else if (material is Timber) + // return "TIMBER"; else return "UNDEF"; #else diff --git a/GSA_Adapter/Convert/ToGsa/Properties/SectionProperty.cs b/GSA_Adapter/Convert/ToGsa/Properties/SectionProperty.cs index 6b2fa82e..bf38a505 100644 --- a/GSA_Adapter/Convert/ToGsa/Properties/SectionProperty.cs +++ b/GSA_Adapter/Convert/ToGsa/Properties/SectionProperty.cs @@ -60,8 +60,6 @@ private static string ToGsaString(this ISectionProperty prop, string index, stri prop.Name = prop.DescriptionOrName().ToGSACleanName(); string name = prop.TaggedName(); - string mat = prop.Material.GSAId().ToString();// materialId; //"STEEL";// material.Name; - string colour = "NO_RGB"; string principle = "NO"; string type = prop.SectionType(); @@ -81,6 +79,7 @@ private static string ToGsaString(this ISectionProperty prop, string index, stri //SECTION.7 | ref | colour | name | memb | pool | point | refY | refZ | mass | fraction | cost | left | right | slab | num { } string str = "SECTION.7," + index + "," + colour + "," + name + ",1D_GENERIC,0,CENTROID,0,0,0,1,0,0,0,0,1," + sectionComp + "," + prop.ISectionMaterialComp(); #else + string mat = prop.Material.GSAId().ToString();// materialId; //"STEEL";// material.Name; string str = "PROP_SEC" + "," + index + "," + name + "," + colour + "," + mat + "," + description + "," + principle + "," + type + "," + cost + "," + props + "," + mods + "," + plate_type + "," + calc_J; #endif return str; diff --git a/GSA_Adapter/Convert/ToGsa/Properties/SurfaceProperties.cs b/GSA_Adapter/Convert/ToGsa/Properties/SurfaceProperties.cs index 2df11335..3cb6c28b 100644 --- a/GSA_Adapter/Convert/ToGsa/Properties/SurfaceProperties.cs +++ b/GSA_Adapter/Convert/ToGsa/Properties/SurfaceProperties.cs @@ -46,7 +46,6 @@ private static string ToGsaString(ConstantThickness panProp, string index) { panProp.Name = panProp.DescriptionOrName().ToGSACleanName(); string name = panProp.TaggedName(); - string mat = panProp.Material.GSAId().ToString(); string command = "PROP_2D"; string colour = "NO_RGB"; @@ -83,6 +82,7 @@ private static string ToGsaString(ConstantThickness panProp, string index) //PROP_2D.7 | num | name | colour | type | axis | mat | mat_type | grade | design | profile | ref_pt | ref_z | mass | flex | shear | inplane | weight | return $"PROP_2D.7, {index}, {name}, {colour}, {type}, {axis}, {analNum}, {materialType}, {matNum}, {design}, {thick}, {ref_pt}, {ref_z}, {mass}, {bending}, {shear}, {inplane}, {weight}"; #else + string mat = panProp.Material.GSAId().ToString(); return command + "," + index + "," + name + "," + colour + "," + axis + "," + mat + "," + type + "," + thick + "," + weight + "," + mass + "," + bending + "," + inplane; #endif } @@ -119,7 +119,7 @@ public static List ToGsaStrings(this FabricPanelProperty panProp, string string name = panProp.TaggedName(); string colour = "NO_RGB"; string axis = "GLOBAL"; - string mat = panProp.Material.GSAId().ToString(); + string mat = panProp.Material.MaterialId(); string type = "FABRIC"; string thick = "0.1"; string mass = panProp.AdditionalMass.ToString(); diff --git a/GSA_Adapter/Convert/ToGsa/_ToGsa.cs b/GSA_Adapter/Convert/ToGsa/_ToGsa.cs index 8a5bc939..ea928623 100644 --- a/GSA_Adapter/Convert/ToGsa/_ToGsa.cs +++ b/GSA_Adapter/Convert/ToGsa/_ToGsa.cs @@ -34,7 +34,7 @@ using BH.oM.Adapters.GSA.SpacerProperties; using BH.oM.Adapters.GSA.Elements; using BH.oM.Base.Attributes; - +using BH.oM.Adapters.GSA.MaterialFragments; namespace BH.Adapter.GSA { @@ -56,9 +56,11 @@ public static string ToGsaString(this Type type) else if (type == typeof(Concrete)) return "MAT_CONCRETE"; else if (type == typeof(Timber)) - return "MAT_TIMBER"; + return "MAT_ANAL";//return "MAT_TIMBER"; else if (type == typeof(Aluminium)) - return "MAT_ALUMINIUM"; + return "MAT_ANAL";//return "MAT_ALUMINIUM"; + else if (type == typeof(Fabric)) + return "MAT_FABRIC";//return "MAT_ALUMINIUM"; else if (type == typeof(GenericIsotropicMaterial) || type == typeof(GenericOrthotropicMaterial)) return "MAT_ANAL"; #else