Skip to content

Commit

Permalink
Allow open collab spaces to have correct parent
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewheumann committed Feb 11, 2024
1 parent 7e90536 commit 85b781a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 54 deletions.
12 changes: 12 additions & 0 deletions LayoutFunctions/LayoutFunctionCommon/IHasParent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using Elements.Geometry;

namespace Elements
{
public interface IHasParent
{
Guid? Parent { get; set; }

Polygon ParentBoundary { get; set; }
}
}
24 changes: 15 additions & 9 deletions LayoutFunctions/LayoutFunctionCommon/LayoutStrategies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -909,22 +909,28 @@ public static void SetParentSpace(ComponentInstance componentInstance, ISpaceBou
{
foreach (var instance in componentInstance.Instances)
{
if (instance != null)
{
instance.AdditionalProperties["Space"] = parentSpaceBoundary.Id;
instance.AdditionalProperties["Space Boundary"] = parentSpaceBoundary.Boundary.Perimeter.TransformedPolygon(parentSpaceBoundary.Transform).Vertices;
}
SetParentSpace(instance, parentSpaceBoundary);
}
}
}

public static void SetParentSpace(ElementInstance elementInstance, ISpaceBoundary parentSpaceBoundary)
public static void SetParentSpace(Element element, ISpaceBoundary parentSpaceBoundary)
{
if (elementInstance != null)
if (element is null)
{
elementInstance.AdditionalProperties["Space"] = parentSpaceBoundary.Id;
elementInstance.AdditionalProperties["Space Boundary"] = parentSpaceBoundary.Boundary.Perimeter.TransformedPolygon(parentSpaceBoundary.Transform).Vertices;
return;
}

var id = parentSpaceBoundary.Id;
var spaceBoundary = parentSpaceBoundary.Boundary.Perimeter.TransformedPolygon(parentSpaceBoundary.Transform);
if (parentSpaceBoundary is IHasParent childSpace)
{
id = childSpace.Parent ?? id;
spaceBoundary = childSpace.ParentBoundary ?? spaceBoundary;
}
element.AdditionalProperties["Space"] = id;
element.AdditionalProperties["Space Boundary"] = spaceBoundary.Vertices;

}

private static ContentConfiguration GetRotatedConfig(ContentConfiguration config, double degrees)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
using System;
using Elements.Geometry;
using Newtonsoft.Json;
namespace Elements
{
public partial class SpaceBoundary : GeometricElement, ISpaceBoundary
public partial class SpaceBoundary : GeometricElement, ISpaceBoundary, IHasParent
{
public Vector3? ParentCentroid { get; set; }
[JsonProperty("Config Id")]
public string ConfigId { get; set; }

public Guid? Parent { get; set; }

public Polygon ParentBoundary { get; set; }
}
}
51 changes: 8 additions & 43 deletions LayoutFunctions/OpenOfficeLayout/dependencies/SpaceBoundary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Elements
{
public partial class SpaceBoundary : ISpaceBoundary
public partial class SpaceBoundary : ISpaceBoundary, IHasParent
{
public List<Line> AdjacentCorridorEdges { get; set; } = null;
public Line AlignmentEdge { get; set; } = null;
Expand All @@ -28,6 +28,9 @@ public partial class SpaceBoundary : ISpaceBoundary
[JsonProperty("Config Id")]
public string ConfigId { get; set; } // unused by this layout type

public Guid? Parent { get; set; } = null;
public Polygon ParentBoundary { get; set; } = null;

[Newtonsoft.Json.JsonIgnore]
public LevelElements LevelElements { get; set; }

Expand Down Expand Up @@ -63,46 +66,6 @@ public void Collect(ProgramRequirement req)
this.CollectedSpaces.Add(req);
}

public List<SpaceBoundary> ResolveCollected()
{
var newSpaces = new List<SpaceBoundary>();
if (this.CollectedSpaces.Count > 0)
{
var runningX = 0.0;
var bonus = 0.0;
if (this.AvailableLength < 3)
{
bonus = this.AvailableLength / this.CollectedSpaces.Count;
}
foreach (var space in this.CollectedSpaces)
{
var depth = space.Depth.Value;
var width = space.Width.Value + bonus;
if (Math.Abs(this.Depth.Value - depth) < 3)
{
depth = this.Depth.Value;
}
var idealRect = Polygon.Rectangle(new Vector3(runningX, 0, 0), new Vector3(width + runningX, depth)).TransformedPolygon(this.FromAlignmentEdge);
var edge = new Line(new Vector3(runningX, 0, 0), new Vector3(width + runningX, 0)).TransformedLine(this.FromAlignmentEdge);
var newSb = SpaceBoundary.Make(idealRect, space.ProgramName, this.Transform, this.Representation.SolidOperations.OfType<Extrude>().First().Height, (Vector3)this.ParentCentroid, (Vector3)this.IndividualCentroid, this.AdjacentCorridorEdges);
newSb.AlignmentEdge = edge;
newSb.LevelElements = LevelElements;
newSb.Level = Level;
runningX += width;
newSpaces.Add(newSb);
}
if (this.AvailableLength > 3)
{
var idealRect = Polygon.Rectangle(new Vector3(runningX, 0, 0), new Vector3(this.AvailableLength + runningX, this.Depth.Value)).TransformedPolygon(this.FromAlignmentEdge);
var edge = new Line(new Vector3(runningX, 0, 0), new Vector3(this.AvailableLength + runningX, 0)).TransformedLine(this.FromAlignmentEdge);
var newSb = SpaceBoundary.Make(idealRect, this.ProgramName, this.Transform, this.Representation.SolidOperations.OfType<Extrude>().First().Height, (Vector3)this.ParentCentroid, (Vector3)this.IndividualCentroid, this.AdjacentCorridorEdges);
newSb.LevelElements = LevelElements;
newSb.Level = Level;
newSpaces.Add(newSb);
}
}
return newSpaces;
}
public static bool TryGetRequirementsMatch(string nameToFind, out ProgramRequirement fullRequirement)
{
if (Requirements.TryGetValue(nameToFind, out fullRequirement))
Expand Down Expand Up @@ -153,7 +116,7 @@ public string ProgramName
}
}
private static Random random = new Random(11);
public static SpaceBoundary Make(Profile profile, string displayName, Transform xform, double height, Vector3? parentCentroid = null, Vector3? individualCentroid = null, IEnumerable<Line> corridorSegments = null)
public static SpaceBoundary Make(Profile profile, string displayName, Transform xform, double height, SpaceBoundary parent, Vector3? parentCentroid = null, Vector3? individualCentroid = null, IEnumerable<Line> corridorSegments = null)
{
if (profile.Perimeter.IsClockWise())
{
Expand All @@ -176,7 +139,9 @@ public static SpaceBoundary Make(Profile profile, string displayName, Transform
Transform = xform,
Material = material ?? MaterialDict["unrecognized"],
Representation = representation,
Name = name
Name = name,
Parent = parent.Id,
ParentBoundary = parent.Boundary.Perimeter.TransformedPolygon(parent.Transform)
};
if (hasReqMatch)
{
Expand Down
2 changes: 1 addition & 1 deletion LayoutFunctions/OpenOfficeLayout/src/OpenOfficeLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public static OpenOfficeLayoutOutputs Execute(Dictionary<string, Model> inputMod
seatsCount += deskCount;
foreach (var profile in collabProfiles)
{
var sb = SpaceBoundary.Make(profile, "Open Collaboration", ob.Transform.Concatenated(new Transform(0, 0, -0.03)), 3, profile.Perimeter.Centroid(), profile.Perimeter.Centroid());
var sb = SpaceBoundary.Make(profile, "Open Collaboration", ob.Transform.Concatenated(new Transform(0, 0, -0.03)), 3, ob, profile.Perimeter.Centroid(), profile.Perimeter.Centroid());
sb.Representation = new Representation(new[] { new Lamina(profile.Perimeter, false) });
sb.AdditionalProperties.Add("Parent Level Id", lvl.Id);
output.Model.AddElement(sb);
Expand Down

0 comments on commit 85b781a

Please sign in to comment.