Skip to content

Commit

Permalink
#3096 - improve UX on dodgy breps
Browse files Browse the repository at this point in the history
#3142 fallback method fo IInternalEdges
  • Loading branch information
Fraser Greenroyd committed Aug 14, 2023
1 parent 3ee9f92 commit fd47862
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Environment_Engine/Create/Panel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static List<Panel> Panels(this List<ISurface> surfaces, string connectedS
if (connectedSpaceName == null)
connectedSpaceName = "auto" + Guid.NewGuid().ToString();

List<Panel> panels = surfaces.Select(x => x.Panel(connectedSpaceName, angleTolerance, panelType)).ToList();
List<Panel> panels = surfaces.Select(x => x.Panel(connectedSpaceName, angleTolerance, panelType)).Where(x => x != null).ToList();

if (panelType == PanelType.Undefined)
{
Expand All @@ -97,6 +97,11 @@ public static List<Panel> Panels(this List<ISurface> surfaces, string connectedS
[Output("panel", "An Environment Panels representing a closed space generated from the provided Brep geometry")]
public static Panel Panel(this ISurface surface, string connectedSpaceName = null, double angleTolerance = BH.oM.Geometry.Tolerance.Angle, PanelType panelType = PanelType.Undefined)
{
if(surface.GetType() == typeof(NurbsSurface))
{
BH.Engine.Base.Compute.RecordError($"Creating Environmental Panels from surfaces of type NurbsSurface is not supported. Please extract the geometry manually and assign to panels using other create methods.");
return null;
}

if (connectedSpaceName == null)
connectedSpaceName = Guid.NewGuid().ToString();
Expand All @@ -116,9 +121,16 @@ public static Panel Panel(this ISurface surface, string connectedSpaceName = nul
});
}

var externalEdges = surface.IExternalEdges();
if(externalEdges == null)
{
BH.Engine.Base.Compute.RecordWarning($"Surface could not query external edges for surface being converted to panel with space name {connectedSpaceName}. Surface was of type {surface.GetType().Name}.");
externalEdges = new List<ICurve>();
}

return new Panel
{
ExternalEdges = surface.IExternalEdges().Select(x => x.ICollapseToPolyline(angleTolerance)).ToList().Join().ToEdges(),
ExternalEdges = externalEdges.Select(x => x.ICollapseToPolyline(angleTolerance)).ToList().Join().ToEdges(),
ConnectedSpaces = new List<string> { connectedSpaceName },
Openings = openings,
Type = panelType,
Expand Down
10 changes: 10 additions & 0 deletions Geometry_Engine/Query/InternalEdges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ public static List<ICurve> IInternalEdges(this ISurface surface)
return InternalEdges(surface as dynamic);
}

/***************************************************/
/**** Private Fallback Methods ****/
/***************************************************/

private static List<ICurve> InternalEdges(this object surface)
{
Base.Compute.RecordError($"InternalEdges is not implemented for objects of type: {surface.GetType().Name}.");
return null;
}

/***************************************************/
}
}
Expand Down

0 comments on commit fd47862

Please sign in to comment.