diff --git a/ETABS_Engine/ETABS_Engine.csproj b/ETABS_Engine/ETABS_Engine.csproj index 1e410fcb..2b57fea7 100644 --- a/ETABS_Engine/ETABS_Engine.csproj +++ b/ETABS_Engine/ETABS_Engine.csproj @@ -108,7 +108,6 @@ - diff --git a/ETABS_oM/ETABS_oM.csproj b/ETABS_oM/ETABS_oM.csproj index be7a2354..ad458e21 100644 --- a/ETABS_oM/ETABS_oM.csproj +++ b/ETABS_oM/ETABS_oM.csproj @@ -62,7 +62,9 @@ - + + + diff --git a/ETABS_oM/Enums/SectionDatabase.cs b/ETABS_oM/Enums/SectionDatabase.cs new file mode 100644 index 00000000..b1fad73c --- /dev/null +++ b/ETABS_oM/Enums/SectionDatabase.cs @@ -0,0 +1,65 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2020, 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 System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Adapters.ETABS +{ + [Description("The ETABS defined section databases to read sections from if the name of the sections you push share a name with one avalible in the database")] + public enum SectionDatabase + { + None = 0, + AISC14 = 1, + AISC14M = 2, + AISC15 = 3, + AISC15M = 4, + ArcelorMittal_British = 5, + ArcelorMittal_BritishHISTAR = 6, + ArcelorMittal_Europe = 7, + ArcelorMittal_EuropeHISTAR = 8, + ArcelorMittal_Japan = 9, + ArcelorMittal_Russia = 10, + ArcelorMittal_US_ASTM_A913 = 11, + ArcelorMittal_US_ASTM_A913M = 12, + ArcelorMittal_US_ASTM_A992 = 13, + ArcelorMittal_US_ASTM_A992M = 14, + Australia_NewZealand = 15, + BSShapes2006 = 16, + ChineseGB08 = 17, + CISC9 = 18, + CISC10 = 19, + CoreBraceBRB_2016 = 20, + Euro = 21, + Indian = 22, + JIS_G_3192_2014 = 23, + Nordic = 24, + Russian = 25, + SJIJoists = 26, + StarSeismicBRB = 27 + } +} + diff --git a/ETABS_Engine/Create/EtabsConfig.cs b/ETABS_oM/Settings/DataBaseSettings.cs similarity index 78% rename from ETABS_Engine/Create/EtabsConfig.cs rename to ETABS_oM/Settings/DataBaseSettings.cs index 876cbca1..dabcd6f4 100644 --- a/ETABS_Engine/Create/EtabsConfig.cs +++ b/ETABS_oM/Settings/DataBaseSettings.cs @@ -25,24 +25,20 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using BH.oM.Adapters.ETABS; +using BH.oM.Base; +using BH.oM.Reflection.Attributes; +using System.ComponentModel; - -namespace BH.Engine.ETABS +namespace BH.oM.Adapters.ETABS { - public static partial class Create + public class DatabaseSettings : IObject { /***************************************************/ - /**** Public Methods ****/ + /**** Public Properties ****/ /***************************************************/ - public static EtabsConfig EtabsConfig(bool replaceLoads = false) - { - return new EtabsConfig - { - ReplaceLoads = replaceLoads - }; - } + [Description("The ETABS defined section database to read sections from if the name of the sections you push share a name with one avalible in the database")] + public SectionDatabase SectionDatabase { get; set; } = SectionDatabase.None; /***************************************************/ } diff --git a/ETABS_oM/Config/EtabsConfig.cs b/ETABS_oM/Settings/EtabsSettings.cs similarity index 93% rename from ETABS_oM/Config/EtabsConfig.cs rename to ETABS_oM/Settings/EtabsSettings.cs index fee6216b..17cf4959 100644 --- a/ETABS_oM/Config/EtabsConfig.cs +++ b/ETABS_oM/Settings/EtabsSettings.cs @@ -31,7 +31,7 @@ namespace BH.oM.Adapters.ETABS { - public class EtabsConfig : BHoMObject + public class EtabsSettings : IObject { /***************************************************/ /**** Public Properties ****/ @@ -40,6 +40,9 @@ public class EtabsConfig : BHoMObject [Description("Sets whether the loads being pushed should overwrite existing loads on the same object within the same loadcase")] public bool ReplaceLoads { get; set; } = false; + [Description("")] + public DatabaseSettings DatabaseSettings { get; set; } = new DatabaseSettings(); + /***************************************************/ } } diff --git a/Etabs_Adapter/CRUD/Create/Load.cs b/Etabs_Adapter/CRUD/Create/Load.cs index f2b04146..17fcfb61 100644 --- a/Etabs_Adapter/CRUD/Create/Load.cs +++ b/Etabs_Adapter/CRUD/Create/Load.cs @@ -52,7 +52,7 @@ public partial class ETABS2016Adapter : BHoMAdapter private bool CreateObject(ILoad bhLoad) { - SetLoad(bhLoad as dynamic, this.EtabsConfig.ReplaceLoads); + SetLoad(bhLoad as dynamic, this.EtabsSettings.ReplaceLoads); return true; } diff --git a/Etabs_Adapter/CRUD/Create/SectionProperty.cs b/Etabs_Adapter/CRUD/Create/SectionProperty.cs index d1c35b8d..96f07841 100644 --- a/Etabs_Adapter/CRUD/Create/SectionProperty.cs +++ b/Etabs_Adapter/CRUD/Create/SectionProperty.cs @@ -75,7 +75,10 @@ private bool CreateObject(ISectionProperty bhSection) return true; } - SetSection(bhSection as dynamic); + if (!LoadFromDatabase(bhSection)) + { + SetSection(bhSection as dynamic); + } double[] modifiers = bhSection.Modifiers(); @@ -238,5 +241,174 @@ private void SetProfile(IProfile profile, string sectionName, IMaterialFragment } /***************************************************/ + + + private bool LoadFromDatabase(ISectionProperty bhSection) + { + if (EtabsSettings.DatabaseSettings.SectionDatabase == SectionDatabase.None) + return false; + + string bhName = bhSection.Name; + + // Formatt as uppercase and no spaces + bhName = bhName.ToUpper(); + bhName = bhName.Replace(" ", ""); + + // remove trailing zeros + string[] sub = bhName.Split('X'); + + for (int i = 0; i < sub.Length; i++) + { + if (sub[i].EndsWith(".0")) + sub[i] = string.Join("", sub[i].Take(sub[i].Length - 2).ToArray()); + } + + bhName = string.Join("X", sub); + + // Get char up intill first number + string startOfName = string.Concat(bhName.TakeWhile(c => c < '0' || c > '9')); + // look in dictionary if there's any discrepencies between etabs and BHoMs naming conventions (if so, replace) + string replace; + if (BHoMToEtabsNamingConventions(EtabsSettings.DatabaseSettings.SectionDatabase).TryGetValue(startOfName, out replace)) + bhName = bhName.Replace(startOfName, replace); + + // Look through a uppercase formatted list of avalible sectionnames, and return the index of the one who matches bhName + int index = m_DBSectionsNames.Select(x => x.ToUpper().Replace(" ", "")).ToList().IndexOf(bhName); + if (index == -1) + return false; + + // Try to get it from the database, return false on faliure + if (1 == m_model.PropFrame.ImportProp( + bhSection.Name, + bhSection.Material.Name, + ToEtabsFileName(EtabsSettings.DatabaseSettings.SectionDatabase), + m_DBSectionsNames[index])) + { + return false; + } + + // Notify user and return true to stop the adapter from creating a new Section + Engine.Reflection.Compute.RecordNote(bhSection.Name + " properties has been assigned from the database section " + bhName + "."); + return true; + } + + /***************************************************/ + + private Dictionary BHoMToEtabsNamingConventions(SectionDatabase sectionDatabase) + { + switch (sectionDatabase) + { + case SectionDatabase.BSShapes2006: + return new Dictionary() + { + { "UB", "UKB" }, + { "UC", "UKC" }, + { "UBP", "UKBP" }, + { "L", "UKA" }, + { "PFC", "UKPFC" }, + { "CHS", "CHHF" }, + { "RHS", "RHHF" }, + { "SHS", "SHHF" }, + { "TUB", "UKT" }, + { "TUC", "UKT" } + }; + case SectionDatabase.None: + case SectionDatabase.AISC14: + case SectionDatabase.AISC14M: + case SectionDatabase.AISC15: + case SectionDatabase.AISC15M: + case SectionDatabase.ArcelorMittal_British: + case SectionDatabase.ArcelorMittal_BritishHISTAR: + case SectionDatabase.ArcelorMittal_Europe: + case SectionDatabase.ArcelorMittal_EuropeHISTAR: + case SectionDatabase.ArcelorMittal_Japan: + case SectionDatabase.ArcelorMittal_Russia: + case SectionDatabase.ArcelorMittal_US_ASTM_A913: + case SectionDatabase.ArcelorMittal_US_ASTM_A913M: + case SectionDatabase.ArcelorMittal_US_ASTM_A992: + case SectionDatabase.ArcelorMittal_US_ASTM_A992M: + case SectionDatabase.Australia_NewZealand: + case SectionDatabase.ChineseGB08: + case SectionDatabase.CISC9: + case SectionDatabase.CISC10: + case SectionDatabase.CoreBraceBRB_2016: + case SectionDatabase.Euro: + case SectionDatabase.Indian: + case SectionDatabase.JIS_G_3192_2014: + case SectionDatabase.Nordic: + case SectionDatabase.Russian: + case SectionDatabase.SJIJoists: + case SectionDatabase.StarSeismicBRB: + default: + return new Dictionary(); + } + } + + /***************************************************/ + + private string ToEtabsFileName(SectionDatabase sectionDB) + { + switch (sectionDB) + { + case SectionDatabase.AISC14: + return "AISC14.xml"; + case SectionDatabase.AISC14M: + return "AISC14.xml"; + case SectionDatabase.AISC15: + return "AISC15.xml"; + case SectionDatabase.AISC15M: + return "AISC15M.xml"; + case SectionDatabase.ArcelorMittal_British: + return "ArcelorMittal_British.xml"; + case SectionDatabase.ArcelorMittal_BritishHISTAR: + return "ArcelorMittal_BritishHISTAR.xml"; + case SectionDatabase.ArcelorMittal_Europe: + return "ArcelorMittal_Europe.xml"; + case SectionDatabase.ArcelorMittal_EuropeHISTAR: + return "ArcelorMittal_EuropeHISTAR.xml"; + case SectionDatabase.ArcelorMittal_Japan: + return "ArcelorMittal_Japan.xml"; + case SectionDatabase.ArcelorMittal_Russia: + return "ArcelorMittal_Russia.xml"; + case SectionDatabase.ArcelorMittal_US_ASTM_A913: + return "ArcelorMittal_US_ASTM-A913.xml"; + case SectionDatabase.ArcelorMittal_US_ASTM_A913M: + return "ArcelorMittal_US_ASTM-A913M.xml"; + case SectionDatabase.ArcelorMittal_US_ASTM_A992: + return "ArcelorMittal_US_ASTM-A992.xml"; + case SectionDatabase.ArcelorMittal_US_ASTM_A992M: + return "ArcelorMittal_US_ASTM-A992M.xml"; + case SectionDatabase.Australia_NewZealand: + return "Australia-NewZealand.xml"; + case SectionDatabase.BSShapes2006: + return "BSShapes2006.xml"; + case SectionDatabase.ChineseGB08: + return "ChineseGB08.xml"; + case SectionDatabase.CISC9: + return "CISC9.xml"; + case SectionDatabase.CISC10: + return "CISC10.xml"; + case SectionDatabase.CoreBraceBRB_2016: + return "CoreBraceBRB_2016.xml"; + case SectionDatabase.Euro: + return "Euro.xml"; + case SectionDatabase.Indian: + return "Indian.xml"; + case SectionDatabase.JIS_G_3192_2014: + return "JIS-G-3192-2014.xml"; + case SectionDatabase.Nordic: + return "Nordic.xml"; + case SectionDatabase.Russian: + return "Russian.xml"; + case SectionDatabase.SJIJoists: + return "SJIJoists.xml"; + case SectionDatabase.StarSeismicBRB: + return "StarSeismicBRB.xml"; + default: + return ""; + } + } + + /***************************************************/ } } \ No newline at end of file diff --git a/Etabs_Adapter/CRUD/Read/SectionProperty.cs b/Etabs_Adapter/CRUD/Read/SectionProperty.cs index 8fc60ccb..2825550c 100644 --- a/Etabs_Adapter/CRUD/Read/SectionProperty.cs +++ b/Etabs_Adapter/CRUD/Read/SectionProperty.cs @@ -34,6 +34,7 @@ using BH.oM.Geometry; using BH.oM.Geometry.ShapeProfiles; using BH.oM.Adapters.ETABS.Fragments; +using BH.oM.Adapters.ETABS; #if Debug17 || Release17 using ETABSv17; #elif Debug18 || Release18 diff --git a/Etabs_Adapter/ETABSAdapter.cs b/Etabs_Adapter/ETABSAdapter.cs index 7d3b61d5..26cf7024 100644 --- a/Etabs_Adapter/ETABSAdapter.cs +++ b/Etabs_Adapter/ETABSAdapter.cs @@ -53,18 +53,18 @@ public partial class ETABS2016Adapter : BHoMAdapter public const string ID = "ETABS_id"; - public EtabsConfig EtabsConfig { get; set; } = new EtabsConfig(); + public EtabsSettings EtabsSettings { get; set; } = new EtabsSettings(); /***************************************************/ /**** Constructors ****/ /***************************************************/ #if Debug17 || Release17 - public ETABS17Adapter(string filePath = "", EtabsConfig etabsConfig = null, bool active = false) + public ETABS17Adapter(string filePath = "", EtabsSettings etabsSetting = null, bool active = false) #elif Debug18 || Release18 - public ETABS18Adapter(string filePath = "", EtabsConfig etabsConfig = null, bool active = false) - #else - public ETABS2016Adapter(string filePath = "", EtabsConfig etabsConfig = null, bool active = false) + public ETABS18Adapter(string filePath = "", EtabsSettings etabsSetting = null, bool active = false) +#else + public ETABS2016Adapter(string filePath = "", EtabsSettings etabsSetting = null, bool active = false) #endif { //Initialisation @@ -76,7 +76,7 @@ public ETABS2016Adapter(string filePath = "", EtabsConfig etabsConfig = null, bo { AdapterIdName = ID; - this.EtabsConfig = etabsConfig == null ? new EtabsConfig() : etabsConfig; + this.EtabsSettings = etabsSetting == null ? new EtabsSettings() : etabsSetting; //string pathToETABS = System.IO.Path.Combine(Environment.GetEnvironmentVariable("PROGRAMFILES"), "Computers and Structures", "ETABS 2016", "ETABS.exe"); //string pathToETABS = System.IO.Path.Combine("C:","Program Files", "Computers and Structures", "ETABS 2016", "ETABS.exe"); @@ -116,6 +116,7 @@ public ETABS2016Adapter(string filePath = "", EtabsConfig etabsConfig = null, bo m_model.File.NewBlank(); } + LoadSectionDatabaseNames(); } } @@ -125,6 +126,24 @@ public ETABS2016Adapter(string filePath = "", EtabsConfig etabsConfig = null, bo private cOAPI m_app; private cSapModel m_model; + private string[] m_DBSectionsNames; + + + /***************************************************/ + /**** Private Methods ****/ + /***************************************************/ + + private void LoadSectionDatabaseNames() + { + int num = 0; + eFramePropType[] types = null; + if (EtabsSettings.DatabaseSettings.SectionDatabase != SectionDatabase.None) + { + m_model.PropFrame.GetPropFileNameList( + ToEtabsFileName(EtabsSettings.DatabaseSettings.SectionDatabase), + ref num, ref m_DBSectionsNames, ref types); + } + } /***************************************************/