Skip to content
Merged
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
147 changes: 147 additions & 0 deletions SAP2000_Adapter/CRUD/Read/Mesh.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2026, 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 BH.oM.Structure.Elements;
using BH.oM.Adapters.SAP2000;
using BH.oM.Geometry;
using BH.oM.Structure.Elements;
using BH.oM.Structure.SurfaceProperties;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BH.Engine.Structure;

namespace BH.Adapter.SAP2000
{
public partial class SAP2000Adapter
{
/***************************************************/

private List<FEMesh> ReadMesh(List<string> ids = null)
{
int nameCount = 0;
string[] nameArr = { };
m_model.AreaObj.GetNameList(ref nameCount, ref nameArr);

ids = FilterIds(ids, nameArr);

List<FEMesh> meshes = new List<FEMesh>();
Dictionary<string, Node> nodes = GetCachedOrReadAsDictionary<string, Node>();
Dictionary<string, ISurfaceProperty> surfaceProps = GetCachedOrReadAsDictionary<string, ISurfaceProperty>();

foreach (string id in ids)
{
FEMesh mesh = new FEMesh();

SAP2000Id sap2000id = new SAP2000Id();
sap2000id.Id = id;

List<string> meshNodeIds = new List<string>();

//Get out the "Element" ids, i.e. the mesh faces
int nbELem = 0;
string[] elemNames = new string[0];
m_model.AreaObj.GetElm(id, ref nbELem, ref elemNames);

for (int j = 0; j < nbELem; j++)
{
//Get out the name of the points for each face
int nbPts = 0;
string[] ptsNames = new string[0];
m_model.AreaElm.GetPoints(elemNames[j], ref nbPts, ref ptsNames);

FEMeshFace face = new FEMeshFace();

for (int k = 0; k < nbPts; k++)
{
string nodeId = ptsNames[k];
Node node;

//Check if node already has been pulled
if (!nodes.TryGetValue(nodeId, out node))
{
double x = 0, y = 0, z = 0;
m_model.PointElm.GetCoordCartesian(nodeId, ref x, ref y, ref z);
node = new Node() { Position = new Point { X = x, Y = y, Z = z } };
SetAdapterId(node, nodeId);
nodes[ptsNames[k]] = node;
}

//Check if node already has been added to the mesh
if (!meshNodeIds.Contains(nodeId))
meshNodeIds.Add(nodeId);

//Get corresponding node index
face.NodeListIndices.Add(meshNodeIds.IndexOf(nodeId));
}

//Add face to list
SetAdapterId(face, elemNames[j]);
mesh.Faces.Add(face);

}

//Set mesh nodes - if there are no nodes, don't create the mesh.
if (nodes.Count != 0 && mesh.Faces.Count != 0)
{
mesh.Nodes = meshNodeIds.Select(x => nodes[x]).ToList();

string propertyName = "";

m_model.AreaObj.GetProperty(id, ref propertyName);

if (propertyName != "None")
{
mesh.Property = surfaceProps[propertyName];
}

//Get local x-axis
double orientation = 0;
bool advanced = false;
m_model.AreaObj.GetLocalAxes(id, ref orientation, ref advanced);

Vector normal = mesh.Faces.First().Normal(mesh); //Assuming flat mesh, all normals equal
Comment thread
GCRA101 marked this conversation as resolved.
Vector localX = Convert.ToPanelLocalXAxis(normal, orientation);
mesh = mesh.SetLocalOrientations(localX);

// Get guid
string guid = null;
m_model.AreaObj.GetGUID(id, ref guid);
sap2000id.PersistentId = guid;

SetAdapterId(mesh, sap2000id);
meshes.Add(mesh);
}
else
{
BH.Engine.Base.Compute.RecordWarning("Mesh " + id.ToString() + " could not be pulled, because it contains no nodes");
}
}
BH.Engine.Base.Compute.RecordWarning("Meshes - Only one face normal vector is pulled from every mesh and it is applied to all the faces of the mesh.");
return meshes;
}

/***************************************************/
}
}
2 changes: 2 additions & 0 deletions SAP2000_Adapter/CRUD/Read/_IRead.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,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(FEMesh))
return ReadMesh(listIds);
else if (type == typeof(ISurfaceProperty) || type.GetInterfaces().Contains(typeof(ISurfaceProperty)))
return ReadSurfaceProperty(listIds);
else if (type == typeof(LoadCombination))
Expand Down
69 changes: 69 additions & 0 deletions SAP2000_Adapter/Convert/ToBHoM/Panel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2026, 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 BH.Engine;
using BH.Engine.Geometry;
using BH.oM.Geometry;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BH.Adapter.SAP2000
{
public static partial class Convert
{
/***************************************************/
/**** Public Methods ****/
/***************************************************/

public static Vector ToPanelLocalXAxis(Vector normal, double orientationAngle)
{
Vector locYref;

if (Query.IsParallel(normal, Vector.ZAxis)!=0)
{
//Vector is paralell to z-axis
locYref = Vector.YAxis;
}
else
{
//Vector is not paralell to z-axis
locYref = Vector.ZAxis.Project(new Plane { Normal = normal });
}

Vector localXref = locYref.CrossProduct(normal);

return localXref.Rotate(BH.Engine.Units.Convert.FromDegree(orientationAngle), normal);
}

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

}
}






9 changes: 8 additions & 1 deletion SAP2000_Adapter/SAP2000_Adapter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="Units_Engine">
<HintPath>$(ProgramData)\BHoM\Assemblies\Units_Engine.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AdapterActions\SetupPushConfig.cs" />
Expand All @@ -191,6 +196,7 @@
<Compile Include="Convert\ToBHoM\Constraint.cs" />
<Compile Include="Convert\ToBHoM\Loads.cs" />
<Compile Include="Convert\ToBHoM\Material.cs" />
<Compile Include="Convert\ToBHoM\Panel.cs" />
Comment thread
GCRA101 marked this conversation as resolved.
<Compile Include="Convert\ToSAP2000\Bar.cs" />
<Compile Include="Convert\ToSAP2000\Constraint.cs" />
<Compile Include="Convert\ToSAP2000\Loads.cs" />
Expand Down Expand Up @@ -221,6 +227,7 @@
<Compile Include="CRUD\Read\Errors.cs" />
<Compile Include="CRUD\Read\Loads.cs" />
<Compile Include="CRUD\Read\Material.cs" />
<Compile Include="CRUD\Read\Mesh.cs" />
<Compile Include="CRUD\Read\Node.cs" />
<Compile Include="CRUD\Read\Panel.cs" />
<Compile Include="CRUD\Read\LinkConstraint.cs" />
Expand Down Expand Up @@ -269,4 +276,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
3 changes: 2 additions & 1 deletion dependencies.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
BHoM/BHoM
BHoM/BHoM_Engine
BHoM/BHoM_Adapter
BHoM/BHoM_Adapter
BHoM/Localisation_Toolkit