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

Fix null handling in FEMesh #385

Merged
merged 1 commit into from
Aug 3, 2021
Merged
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
71 changes: 41 additions & 30 deletions Etabs_Adapter/CRUD/Read/Mesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,17 @@ private List<FEMesh> ReadMesh(List<string> ids = null)

List<FEMesh> meshes = new List<FEMesh>();
Dictionary<string, Node> nodes = new Dictionary<string, Node>();
Dictionary<string, ISurfaceProperty> surfaceProps = ReadSurfaceProperty().ToDictionary(x => GetAdapterId<string>(x));

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

ETABSId etabsid = new ETABSId();
etabsid.Id = id;

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

string propertyName = "";

m_model.AreaObj.GetProperty(id, ref propertyName);
ISurfaceProperty panelProperty = ReadSurfaceProperty(new List<string>() { propertyName })[0];

FEMesh mesh = new FEMesh() { Property = panelProperty };

//Get out the "Element" ids, i.e. the mesh faces
int nbELem = 0;
string[] elemNames = new string[0];
Expand Down Expand Up @@ -121,35 +117,50 @@ private List<FEMesh> ReadMesh(List<string> ids = null)

}

//Set mesh nodes
mesh.Nodes = meshNodeIds.Select(x => nodes[x]).ToList();
//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 = "";

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

Vector normal = mesh.Faces.First().Normal(mesh); //Assuming flat mesh, all normals equal
Vector localX = Convert.FromCSILocalX(normal, orientation);
mesh = mesh.SetLocalOrientations(localX);
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
Vector localX = Convert.FromCSILocalX(normal, orientation);
mesh = mesh.SetLocalOrientations(localX);

//Label and story
string label = "";
string story = "";
if (m_model.AreaObj.GetLabelFromName(id, ref label, ref story) == 0)
{
etabsid.Label = label;
etabsid.Story = story;
}

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

//Label and story
string label = "";
string story = "";
if (m_model.AreaObj.GetLabelFromName(id, ref label, ref story) == 0)
SetAdapterId(mesh, etabsid);
meshes.Add(mesh);
}
else
{
etabsid.Label = label;
etabsid.Story = story;
BH.Engine.Reflection.Compute.RecordWarning("Mesh " + id.ToString() + " could not be pulled, because it contains no nodes");
}

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

SetAdapterId(mesh, etabsid);
meshes.Add(mesh);
}

return meshes;
Expand Down