Skip to content

Commit

Permalink
add space associations for all child elements
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewheumann committed Dec 5, 2023
1 parent afa646a commit 1689f7c
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 5 deletions.
3 changes: 3 additions & 0 deletions LayoutFunctions/ClassroomLayout/src/ClassroomLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public static ClassroomLayoutOutputs Execute(Dictionary<string, Model> inputMode
{
var componentInstance = InstantiateLayout(configs, width, depth, rect, room.Transform);
LayoutStrategies.SetLevelVolume(componentInstance, levelVolume?.Id);
LayoutStrategies.SetParentSpace(componentInstance, room.Id);
output.Model.AddElement(componentInstance);
}
else if (trimmedGeo.Count() > 0)
Expand All @@ -102,6 +103,7 @@ public static ClassroomLayoutOutputs Execute(Dictionary<string, Model> inputMode

var componentInstance = InstantiateLayout(configs, width, depth, cinchedPoly, room.Transform);
LayoutStrategies.SetLevelVolume(componentInstance, levelVolume?.Id);
LayoutStrategies.SetParentSpace(componentInstance, room.Id);
output.Model.AddElement(componentInstance);
}
try
Expand Down Expand Up @@ -135,6 +137,7 @@ public static ClassroomLayoutOutputs Execute(Dictionary<string, Model> inputMode
"Desk");

LayoutStrategies.SetLevelVolume(instance, levelVolume?.Id);
LayoutStrategies.SetParentSpace(instance, room.Id);
output.Model.AddElement(instance);
}
}
Expand Down
17 changes: 12 additions & 5 deletions LayoutFunctions/DataHall/src/DataHallLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static DataHallLayoutOutputs Execute(Dictionary<string, Model> inputModel
var floorGrid = new Grid2d(profile.Perimeter, alignment);
floorGrid.U.DivideByFixedLength(0.6096);
floorGrid.V.DivideByFixedLength(0.6096);
model.AddElement(ToModelLines(floorGrid, room.Transform));
model.AddElement(ToModelLines(floorGrid, room.Transform, room.Id));

double rackAngle = 0;
if (input.SwapColdHotPattern) rackAngle = 180;
Expand All @@ -115,22 +115,28 @@ public static DataHallLayoutOutputs Execute(Dictionary<string, Model> inputModel
}
if (cell.Type == "Hot Aisle")
{
model.AddElement(new Panel(cellRect, BuiltInMaterials.XAxis, room.Transform));
var panel = new Panel(cellRect, BuiltInMaterials.XAxis, room.Transform);
panel.AdditionalProperties["Space"] = room.Id;
model.AddElement(panel);
}
else if (cell.Type == "Cold Aisle")
{
model.AddElement(new Panel(cellRect, BuiltInMaterials.ZAxis, room.Transform));
var panel = new Panel(cellRect, BuiltInMaterials.ZAxis, room.Transform);
panel.AdditionalProperties["Space"] = room.Id;
model.AddElement(panel);
}
else if (cell.Type == "Forward Rack" && cellRect.Area().ApproximatelyEquals(width * depth, 0.01) && !intersectsColumn)
{
var centroid = cellRect.Centroid();
var rackInstance = dataRack.CreateInstance(alignment.Concatenated(new Transform(new Vector3(), rackAngle - 180)).Concatenated(new Transform(centroid)).Concatenated(room.Transform), "Rack");
rackInstance.AdditionalProperties["Space"] = room.Id;
model.AddElement(rackInstance);
}
else if (cell.Type == "Backward Rack" && cellRect.Area().ApproximatelyEquals(width * depth, 0.01) && !intersectsColumn)
{
var centroid = cellRect.Centroid();
var rackInstance = dataRack.CreateInstance(alignment.Concatenated(new Transform(new Vector3(), rackAngle)).Concatenated(new Transform(centroid)).Concatenated(room.Transform), "Rack");
rackInstance.AdditionalProperties["Space"] = room.Id;
model.AddElement(rackInstance);
}
}
Expand Down Expand Up @@ -170,14 +176,14 @@ private static bool CheckIntersectsWithColumns(Polygon? cellRect, List<Column> c
return columns.Any(column => cellRect.Intersects(column.Profile.Perimeter.TransformedPolygon(new Transform(column.Location))));
}

private static ModelLines ToModelLines(Grid2d grid, Transform transform)
private static ModelLines ToModelLines(Grid2d grid, Transform transform, System.Guid id)
{
var boundary = grid.GetTrimmedCellGeometry();
var uLines = grid.GetCellSeparators(GridDirection.U, true);
var vLines = grid.GetCellSeparators(GridDirection.V, true);
var curves = boundary.Concat(uLines).Concat(vLines).OfType<BoundedCurve>();

ModelLines ml = new ModelLines(transform: transform);
var ml = new ModelLines(transform: transform);
foreach (var b in boundary.Concat(curves))
{
var parameters = b.GetSubdivisionParameters();
Expand All @@ -188,6 +194,7 @@ private static ModelLines ToModelLines(Grid2d grid, Transform transform)
}
}
ml.SetSelectable(false);
ml.AdditionalProperties["Space"] = id;
return ml;
}
}
Expand Down
8 changes: 8 additions & 0 deletions LayoutFunctions/LayoutFunctionCommon/LayoutStrategies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -865,5 +865,13 @@ public static void SetParentSpace(ComponentInstance componentInstance, Guid? par
}
}
}

public static void SetParentSpace(ElementInstance elementInstance, Guid parentSpaceId)
{
if (elementInstance != null)
{
elementInstance.AdditionalProperties["Space"] = parentSpaceId;
}
}
}
}
12 changes: 12 additions & 0 deletions LayoutFunctions/OpenOfficeLayout/Model.dib
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!meta

{"kernelInfo":{"defaultKernelName":"csharp","items":[{"aliases":[],"name":"csharp"}]}}

#!csharp

#r "nuget: Hypar.Elements, *-*"

#!csharp

var modelPath = "/Users/andrewheumann/Downloads/model 45.json";
Model.FromJson(File)
1 change: 1 addition & 0 deletions LayoutFunctions/OpenOfficeLayout/src/OpenOfficeLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ public static OpenOfficeLayoutOutputs Execute(Dictionary<string, Model> inputMod
foreach (var desk in desks)
{
LayoutStrategies.SetLevelVolume(desk as ElementInstance, levelVolume?.Id);
LayoutStrategies.SetParentSpace(desk as ElementInstance, ob.Id);
}
output.Model.AddElements(desks);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>EKN5BGA37XK4SY88</RequestId><HostId>QVRfH3TrGZQKXsMveW3bcXf2M6ghPoasNYLw2g7c0lGb3OSFD7Lf4OOK6sPbkgZLd10nxN6Fjhc=</HostId></Error>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>CMH857YEYZ5WRC90</RequestId><HostId>hOtw+YejhNRIAP2YyzyqSnUjP3wPHraUapiGGnH8Mwq0k6kSQLGiP2KlSyrql96/d6PcnrsdF0o=</HostId></Error>
2 changes: 2 additions & 0 deletions LayoutFunctions/PhoneBoothLayout/src/PhoneBoothLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public static PhoneBoothLayoutOutputs Execute(Dictionary<string, Model> inputMod
if (layout != null)
{
LayoutStrategies.SetLevelVolume(layout, levelVolume?.Id);
LayoutStrategies.SetParentSpace(layout, room.Id);
output.Model.AddElement(layout);
seatsCount++;
}
Expand All @@ -112,6 +113,7 @@ public static PhoneBoothLayoutOutputs Execute(Dictionary<string, Model> inputMod
if (layout != null)
{
LayoutStrategies.SetLevelVolume(layout, levelVolume?.Id);
LayoutStrategies.SetParentSpace(layout, room.Id);
output.Model.AddElement(layout);
seatsCount++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public static PrivateOfficeLayoutOutputs Execute(Dictionary<string, Model> input
{
var layout = InstantiateLayout(configs, width, depth, rect, levelVolume?.Transform ?? new Transform(), out var seats);
LayoutStrategies.SetLevelVolume(layout, levelVolume?.Id);
LayoutStrategies.SetParentSpace(layout, room.Id);
output.Model.AddElement(layout);
privateOfficeCount++;
seatsCount += seats;
Expand All @@ -134,6 +135,7 @@ public static PrivateOfficeLayoutOutputs Execute(Dictionary<string, Model> input
{
var layout = InstantiateLayout(configs, width, depth, cinchedPoly, levelVolume?.Transform ?? new Transform(), out var seats);
LayoutStrategies.SetLevelVolume(layout, levelVolume?.Id);
LayoutStrategies.SetParentSpace(layout, room.Id);
output.Model.AddElement(layout);
privateOfficeCount++;
seatsCount += seats;
Expand Down
2 changes: 2 additions & 0 deletions LayoutFunctions/ReceptionLayout/src/ReceptionLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public static ReceptionLayoutOutputs Execute(Dictionary<string, Model> inputMode
{
var layout = InstantiateLayout(configs, width, depth, rect, room.Transform, out var seats);
LayoutStrategies.SetLevelVolume(layout, levelVolume?.Id);
LayoutStrategies.SetParentSpace(layout, room.Id);
output.Model.AddElement(layout);
seatsCount += seats;
}
Expand All @@ -104,6 +105,7 @@ public static ReceptionLayoutOutputs Execute(Dictionary<string, Model> inputMode
// output.Model.AddElement(new ModelCurve(cinchedPoly, BuiltInMaterials.ZAxis, levelVolume.Transform));
var layout = InstantiateLayout(configs, width, depth, cinchedPoly, room.Transform, out var seats);
LayoutStrategies.SetLevelVolume(layout, levelVolume?.Id);
LayoutStrategies.SetParentSpace(layout, room.Id);
output.Model.AddElement(layout);
Console.WriteLine("🤷‍♂️ funny shape!!!");
seatsCount += seats;
Expand Down

0 comments on commit 1689f7c

Please sign in to comment.