diff --git a/Etabs_Adapter/CRUD/Create/Opening.cs b/Etabs_Adapter/CRUD/Create/Opening.cs new file mode 100644 index 00000000..9978b402 --- /dev/null +++ b/Etabs_Adapter/CRUD/Create/Opening.cs @@ -0,0 +1,114 @@ +/* + * 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.Collections.Generic; +using System.Linq; +using BH.Engine.Adapter; +using BH.oM.Adapters.ETABS; +using BH.oM.Structure.Elements; +using BH.Engine.Structure; +using BH.Engine.Geometry; +using BH.Engine.Spatial; +using BH.Engine.Adapters.ETABS; +using BH.oM.Adapters.ETABS.Elements; +using BH.oM.Geometry; +using BH.oM.Analytical.Elements; + + +namespace BH.Adapter.ETABS +{ +#if Debug16 || Release16 + public partial class ETABS2016Adapter : BHoMAdapter +#elif Debug17 || Release17 + public partial class ETABS17Adapter : BHoMAdapter +#else + public partial class ETABSAdapter : BHoMAdapter +#endif + { + /***************************************************/ + /*** Create Methods ***/ + /***************************************************/ + + private bool CreateObject(Opening bhOpening) + { + bool success = true; + int retA = 0; + + double mergeTol = 1e-3; //Merging panel points to the mm, same behaviour as the default node comparer + + if (!CheckPropertyError(bhOpening, bhO => bhO.Edges, true)) + return false; + + for (int i = 0; i < bhOpening.Edges.Count; i++) + { + if (!CheckPropertyError(bhOpening, bhO => bhO.Edges[i], true)) + return false; + + if (!CheckPropertyError(bhOpening, bhO => bhO.Edges[i].Curve, true)) + return false; + } + + NonLinearEdgesCheck(bhOpening.Edges); + + List boundaryPoints = bhOpening.ControlPoints(true).CullDuplicates(mergeTol); + + int segmentCount = boundaryPoints.Count(); + double[] x = new double[segmentCount]; + double[] y = new double[segmentCount]; + double[] z = new double[segmentCount]; + for (int i = 0; i < segmentCount; i++) + { + x[i] = boundaryPoints[i].X; + y[i] = boundaryPoints[i].Y; + z[i] = boundaryPoints[i].Z; + } + + string openingName = GetAdapterId(bhOpening); + retA = m_model.AreaObj.AddByCoord(segmentCount, ref x, ref y, ref z, ref openingName, "Default"); + ETABSId etabsid = new ETABSId(); + etabsid.Id = openingName; + + //Label and story + string label = ""; + string story = ""; + string guid = null; + + if (m_model.AreaObj.GetLabelFromName(openingName, ref label, ref story) == 0) + { + etabsid.Label = label; + etabsid.Story = story; + } + + if (m_model.AreaObj.GetGUID(openingName, ref guid) == 0) + etabsid.PersistentId = guid; + + bhOpening.SetAdapterId(etabsid); + + m_model.AreaObj.SetOpening(openingName, true); + + return success; + } + + /***************************************************/ + + } +} \ No newline at end of file diff --git a/Etabs_Adapter/CRUD/Read/Opening.cs b/Etabs_Adapter/CRUD/Read/Opening.cs new file mode 100644 index 00000000..44f727fe --- /dev/null +++ b/Etabs_Adapter/CRUD/Read/Opening.cs @@ -0,0 +1,130 @@ +/* + * 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 BH.Engine.Adapter; +using BH.oM.Adapters.ETABS; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BH.oM.Structure.Elements; +using BH.oM.Structure.SurfaceProperties; +using BH.Engine.Adapters.ETABS; +using BH.oM.Geometry; +using BH.Engine.Geometry; +using BH.oM.Adapters.ETABS.Elements; +using BH.Engine.Structure; +using BH.Engine.Spatial; + + +namespace BH.Adapter.ETABS +{ +#if Debug16 || Release16 + public partial class ETABS2016Adapter : BHoMAdapter +#elif Debug17 || Release17 + public partial class ETABS17Adapter : BHoMAdapter +#else + public partial class ETABSAdapter : BHoMAdapter +#endif + { + /***************************************************/ + /*** Read Methods ***/ + /***************************************************/ + + private List ReadOpening(List ids = null) + { + + List openingNames = new List(); + List openingList = new List(); + + int nameCount = 0; + string[] nameArr = { }; + m_model.AreaObj.GetNameList(ref nameCount, ref nameArr); + + + bool isOpening = false; + openingNames = nameArr.Where(panelName => { + m_model.AreaObj.GetOpening(panelName, ref isOpening); + return isOpening; + }).ToList(); + + ids = FilterIds(ids, openingNames); + + foreach (string id in ids) + { + ETABSId etabsId = new ETABSId(); + etabsId.Id = id; + + Opening opening = new Opening(); + Polyline pl = GetOpeningPerimeter(id); + + opening.Edges = pl.SubParts().Select(x => new Edge { Curve = x }).ToList(); + + //Label and story + string label = ""; + string story = ""; + string guid = null; + if (m_model.AreaObj.GetLabelFromName(id, ref label, ref story) == 0) + { + etabsId.Label = label; + etabsId.Story = story; + } + + if (m_model.AreaObj.GetGUID(id, ref guid) == 0) + etabsId.PersistentId = guid; + + opening.SetAdapterId(etabsId); + openingList.Add(opening); + } + + return openingList; + } + + /***************************************************/ + + private Polyline GetOpeningOutline(string id) + { + string[] pName = null; + int pointCount = 0; + double pX1 = 0; + double pY1 = 0; + double pZ1 = 0; + m_model.AreaObj.GetPoints(id, ref pointCount, ref pName); + List pts = new List(); + for (int j = 0; j < pointCount; j++) + { + m_model.PointObj.GetCoordCartesian(pName[j], ref pX1, ref pY1, ref pZ1); + pts.Add(new Point() { X = pX1, Y = pY1, Z = pZ1 }); + } + pts.Add(pts[0]); + + Polyline pl = new Polyline() { ControlPoints = pts }; + + return pl; + } + + /***************************************************/ + + } +} diff --git a/Etabs_Adapter/CRUD/Read/_Read.cs b/Etabs_Adapter/CRUD/Read/_Read.cs index e2fad763..5a516bce 100644 --- a/Etabs_Adapter/CRUD/Read/_Read.cs +++ b/Etabs_Adapter/CRUD/Read/_Read.cs @@ -70,6 +70,8 @@ protected override IEnumerable IRead(Type type, IList ids, ActionCo return ReadMaterial(listIds); else if (type == typeof(Panel)) return ReadPanel(listIds); + else if (type == typeof(Opening)) + return ReadOpening(listIds); else if (type == typeof(ISurfaceProperty) || type.GetInterfaces().Contains(typeof(ISurfaceProperty))) return ReadSurfaceProperty(listIds); else if (type == typeof(LoadCombination)) diff --git a/Etabs_Adapter/Etabs_Adapter.csproj b/Etabs_Adapter/Etabs_Adapter.csproj index 5c16caea..814090cf 100644 --- a/Etabs_Adapter/Etabs_Adapter.csproj +++ b/Etabs_Adapter/Etabs_Adapter.csproj @@ -351,6 +351,7 @@ + @@ -365,6 +366,7 @@ +