Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Adapter Support for Structure Openings #479

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions Etabs_Adapter/CRUD/Create/Opening.cs
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

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<BH.oM.Geometry.Point> 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<string>(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;
}

/***************************************************/

}
}
130 changes: 130 additions & 0 deletions Etabs_Adapter/CRUD/Read/Opening.cs
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

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<Opening> ReadOpening(List<string> ids = null)
{

List<string> openingNames = new List<string>();
List<Opening> openingList = new List<Opening>();

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<Point> pts = new List<Point>();
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;
}

/***************************************************/

}
}
2 changes: 2 additions & 0 deletions Etabs_Adapter/CRUD/Read/_Read.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ protected override IEnumerable<IBHoMObject> 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))
Expand Down
2 changes: 2 additions & 0 deletions Etabs_Adapter/Etabs_Adapter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@
<Compile Include="Convert\ToCSI\Vector.cs" />
<Compile Include="CRUD\Create\Loadcase.cs" />
<Compile Include="CRUD\Create\Diaphragm.cs" />
<Compile Include="CRUD\Create\Opening.cs" />
<Compile Include="CRUD\Create\SurfaceProperty.cs" />
<Compile Include="CRUD\Create\SectionProperty.cs" />
<Compile Include="CRUD\Create\Panel.cs" />
Expand All @@ -365,6 +366,7 @@
<Compile Include="CRUD\Delete\_Delete.cs" />
<Compile Include="CRUD\Read\Grid.cs" />
<Compile Include="CRUD\Read\Loadcase.cs" />
<Compile Include="CRUD\Read\Opening.cs" />
<Compile Include="CRUD\Read\Results\PierAndSpandrelResults.cs" />
<Compile Include="CRUD\Read\SectionProperty.cs" />
<Compile Include="CRUD\Read\Results\BarResults.cs" />
Expand Down