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

Structure_Engine: NullReferenceException on transform of a bar with null nodes fixed #3030

Merged
merged 2 commits into from
Mar 27, 2023
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
48 changes: 48 additions & 0 deletions Structure_Engine/Modify/Transform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public static partial class Modify
[Output("transformed", "Modified Node with unchanged properties, but transformed position and orientation.")]
public static Node Transform(this Node node, TransformMatrix transform, double tolerance = Tolerance.Distance)
{
if (node == null)
{
BH.Engine.Base.Compute.RecordError("Could not transform the Node because it was null.");
return null;
}

if (!transform.IsRigidTransformation(tolerance))
{
BH.Engine.Base.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
Expand All @@ -66,6 +72,18 @@ public static Node Transform(this Node node, TransformMatrix transform, double t
[Output("transformed", "Modified Bar with unchanged properties, but transformed nodes and orientation.")]
public static Bar Transform(this Bar bar, TransformMatrix transform, double tolerance = Tolerance.Distance)
{
if (bar == null)
{
BH.Engine.Base.Compute.RecordError("Could not transform the Bar because it was null.");
return null;
}

if (bar.StartNode?.Position == null || bar.EndNode?.Position == null)
{
BH.Engine.Base.Compute.RecordWarning("The bar could not be transformed because at least one of its nodes (or their location) is null.");
return bar;
}

if (!transform.IsRigidTransformation(tolerance))
{
BH.Engine.Base.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
Expand All @@ -92,6 +110,12 @@ public static Bar Transform(this Bar bar, TransformMatrix transform, double tole
[Output("transformed", "Modified RigidLink with unchanged properties, but transformed primary and secondary nodes.")]
public static RigidLink Transform(this RigidLink link, TransformMatrix transform, double tolerance = Tolerance.Distance)
{
if (link == null)
{
BH.Engine.Base.Compute.RecordError("Could not transform the RigidLink because it was null.");
return null;
}

if (!transform.IsRigidTransformation(tolerance))
{
BH.Engine.Base.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
Expand All @@ -113,6 +137,12 @@ public static RigidLink Transform(this RigidLink link, TransformMatrix transform
[Output("transformed", "Modified Edge with unchanged properties, but transformed location.")]
public static Edge Transform(this Edge edge, TransformMatrix transform, double tolerance = Tolerance.Distance)
{
if (edge == null)
{
BH.Engine.Base.Compute.RecordError("Could not transform the Edge because it was null.");
return null;
}

if (!transform.IsRigidTransformation(tolerance))
{
BH.Engine.Base.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
Expand All @@ -133,6 +163,12 @@ public static Edge Transform(this Edge edge, TransformMatrix transform, double t
[Output("transformed", "Modified Opening with unchanged properties, but transformed edges.")]
public static Opening Transform(this Opening opening, TransformMatrix transform, double tolerance = Tolerance.Distance)
{
if (opening == null)
{
BH.Engine.Base.Compute.RecordError("Could not transform the Opening because it was null.");
return null;
}

if (!transform.IsRigidTransformation(tolerance))
{
BH.Engine.Base.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
Expand All @@ -153,6 +189,12 @@ public static Opening Transform(this Opening opening, TransformMatrix transform,
[Output("transformed", "Modified Panel with unchanged properties, but transformed edges, openings and orientation angle.")]
public static Panel Transform(this Panel panel, TransformMatrix transform, double tolerance = Tolerance.Distance)
{
if (panel == null)
{
BH.Engine.Base.Compute.RecordError("Could not transform the Panel because it was null.");
return null;
}

if (!transform.IsRigidTransformation(tolerance))
{
BH.Engine.Base.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
Expand Down Expand Up @@ -181,6 +223,12 @@ public static Panel Transform(this Panel panel, TransformMatrix transform, doubl
[Output("transformed", "Modified FEMesh with unchanged properties, but transformed nodes.")]
public static FEMesh Transform(this FEMesh mesh, TransformMatrix transform, double tolerance = Tolerance.Distance)
{
if (mesh == null)
{
BH.Engine.Base.Compute.RecordError("Could not transform the FEMesh because it was null.");
return null;
}

if (!transform.IsRigidTransformation(tolerance))
{
BH.Engine.Base.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
Expand Down