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

Use-folder-content-update #87

Merged
merged 16 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
5 changes: 5 additions & 0 deletions LayoutFunctions/ClassroomLayout/hypar.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
"name": "Space Planning Zones",
"optional": false
},
{
"autohide": false,
"name": "Program Requirements",
"optional": true
},
{
"autohide": false,
"name": "Circulation",
Expand Down
8 changes: 6 additions & 2 deletions LayoutFunctions/ClassroomLayout/src/ClassroomLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ public static ClassroomLayoutOutputs Execute(Dictionary<string, Model> inputMode
}
var levelVolumes = LayoutStrategies.GetLevelVolumes<LevelVolume>(inputModels);
var output = new ClassroomLayoutOutputs();
var configJson = File.ReadAllText("./ClassroomConfigurations.json");
var configs = JsonConvert.DeserializeObject<SpaceConfiguration>(configJson);

string configJsonPath = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "ClassroomConfigurations.json");
SpaceConfiguration configs = ContentManagement.GetSpaceConfiguration(inputModels, configJsonPath, "Classroom");

// var configJson = File.ReadAllText("./ClassroomConfigurations.json");
// var configs = JsonConvert.DeserializeObject<SpaceConfiguration>(configJson);

int totalCountableSeats = 0;
int seatsAtDesk = 0;
Expand Down
13 changes: 13 additions & 0 deletions LayoutFunctions/LayoutFunctionCommon/CatalogWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

using Elements;
using System;
using System.Linq;
using System.Collections.Generic;
using Elements.Geometry;
namespace Elements
{
public partial class CatalogWrapper : Element
{
public string CatalogString { get; set; }
}
}
86 changes: 86 additions & 0 deletions LayoutFunctions/LayoutFunctionCommon/ContentManagement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Elements;
using Elements.Components;
using Newtonsoft.Json;

namespace LayoutFunctionCommon
{
public static class ContentManagement
{
public static bool LoadConfigAndCatalog<TProgramRequirement>(
Dictionary<string, Model> inputModels,
string programName,
out string configPath,
out string catalogPath
) where TProgramRequirement : Element, IProgramRequirement
{
configPath = null;
catalogPath = null;
if (!inputModels.TryGetValue("Program Requirements", out var programReqModel))
{
Console.WriteLine("Program Requirements model not found");
return false;
}
var programReqs = programReqModel.AllElementsAssignableFromType<TProgramRequirement>();
var req = programReqs?.FirstOrDefault(r => r.HyparSpaceType == programName);
if (req == null)
{
Console.WriteLine($"No Program Requirement found for {programName}.");
return false;
}
var (catPath, confPath) = WriteLayoutConfigs(req, programReqModel);
if (catPath == null || confPath == null)
{
Console.WriteLine($"No Space information for {programName}.");
return false;
}
configPath = confPath;
catalogPath = catPath;
return true;
}

public static (string catalogPath, string configPath) WriteLayoutConfigs(IProgramRequirement req, Model programReqModel)
{
if (!req.SpaceConfig.HasValue || !req.Catalog.HasValue)
{
return (null, null);
}

var tempDir = Path.GetTempPath();
var catalogPath = Path.Combine(tempDir, $"{req.Id}_catalog.json");
var configPath = Path.Combine(tempDir, $"{req.Id}_config.json");
if (File.Exists(catalogPath) && File.Exists(configPath))
{
return (catalogPath, configPath);
}

var catalogWrapper = programReqModel.GetElementOfType<CatalogWrapper>(req.Catalog.Value);
var catalogStringBase64 = catalogWrapper.CatalogString;
var bytes = Convert.FromBase64String(catalogStringBase64);
if (bytes != null)
{
File.WriteAllBytes(catalogPath, bytes);
}
var spaceConfig = programReqModel.GetElementOfType<SpaceConfigurationElement>(req.SpaceConfig.Value);
var config = spaceConfig.SpaceConfiguration;
File.WriteAllText(configPath, JsonConvert.SerializeObject(config));
return (catalogPath, configPath);
}

public static SpaceConfiguration GetSpaceConfiguration(Dictionary<string, Model> inputModels, string configJsonPath, string programName)
{
if (LoadConfigAndCatalog<ProgramRequirement>(inputModels, programName, out var configPath, out var catPath))
{
configJsonPath = configPath;
ContentCatalogRetrieval.SetCatalogFilePath(catPath);
}

var configJson = File.ReadAllText(configJsonPath);
var configs = JsonConvert.DeserializeObject<SpaceConfiguration>(configJson);
return configs;
}
}
}
16 changes: 16 additions & 0 deletions LayoutFunctions/LayoutFunctionCommon/IProgramRequirement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using Elements;
using Newtonsoft.Json;

namespace Elements
{
public interface IProgramRequirement
{
[JsonProperty("Hypar Space Type")]
public string HyparSpaceType { get; set; }
public Guid? SpaceConfig { get; set; }
public Guid? Catalog { get; set; }
public Guid Id { get; set; }
}
}
15 changes: 10 additions & 5 deletions LayoutFunctions/LayoutFunctionCommon/LayoutGeneration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,23 @@ public virtual LayoutGenerationResult StandardLayoutOnAllLevels(string programTy
Dictionary<string, Model> inputModels,
dynamic overrides,
bool createWalls,
string configurationsPath,
string catalogPath = "catalog.json")
string configurationsPath)
{

var outputModel = new Model();
var totalSeats = 0;
ContentCatalogRetrieval.SetCatalogFilePath(catalogPath);

// ContentCatalogRetrieval.SetCatalogFilePath(catalogPath);
// var configJson = configurationsPath != null ? File.ReadAllText(configurationsPath) : "{}";
// var configs = DeserializeConfigJson(configJson);

string configJsonPath = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), configurationsPath);
SpaceConfiguration configs = ContentManagement.GetSpaceConfiguration(inputModels, configJsonPath, programTypeName);

var spacePlanningZones = inputModels["Space Planning Zones"];
var levels = GetLevels(inputModels, spacePlanningZones);
var levelVolumes = LayoutStrategies.GetLevelVolumes<TLevelVolume>(inputModels);
var configJson = configurationsPath != null ? File.ReadAllText(configurationsPath) : "{}";
var configs = DeserializeConfigJson(configJson);

var allSpaceBoundaries = spacePlanningZones.AllElementsAssignableFromType<TSpaceBoundary>().Where(z => (z.HyparSpaceType ?? z.Name) == programTypeName).ToList();
foreach (var lvl in levels)
{
Expand Down
12 changes: 8 additions & 4 deletions LayoutFunctions/LayoutFunctionCommon/LayoutStrategies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ public static HashSet<Guid> StandardLayoutOnAllLevels<TLevelElements, TLevelVolu
dynamic overrides, Model outputModel,
bool createWalls,
string configurationsPath,
string catalogPath = "catalog.json",
Func<LayoutInstantiated, int> countSeats = null
)
where TLevelElements : Element, ILevelElements
Expand All @@ -181,7 +180,14 @@ public static HashSet<Guid> StandardLayoutOnAllLevels<TLevelElements, TLevelVolu
where TCirculationSegment : Floor, ICirculationSegment
{
var processedSpaces = new HashSet<Guid>();
ContentCatalogRetrieval.SetCatalogFilePath(catalogPath);

// ContentCatalogRetrieval.SetCatalogFilePath(catalogPath);
// var configJson = configurationsPath != null ? File.ReadAllText(configurationsPath) : "{}";
// var configs = JsonConvert.DeserializeObject<SpaceConfiguration>(configJson);

string configJsonPath = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), configurationsPath);
SpaceConfiguration configs = ContentManagement.GetSpaceConfiguration(inputModels, configJsonPath, programTypeName);

var spacePlanningZones = inputModels["Space Planning Zones"];
var levels = spacePlanningZones.AllElementsAssignableFromType<TLevelElements>();

Expand All @@ -195,8 +201,6 @@ public static HashSet<Guid> StandardLayoutOnAllLevels<TLevelElements, TLevelVolu
}
}
var levelVolumes = GetLevelVolumes<TLevelVolume>(inputModels);
var configJson = configurationsPath != null ? File.ReadAllText(configurationsPath) : "{}";
var configs = JsonConvert.DeserializeObject<SpaceConfiguration>(configJson);
var allSpaceBoundaries = spacePlanningZones.AllElementsAssignableFromType<TSpaceBoundary>().Where(z => (z.HyparSpaceType ?? z.Name) == programTypeName).ToList();
foreach (var lvl in levels)
{
Expand Down
12 changes: 12 additions & 0 deletions LayoutFunctions/LayoutFunctionCommon/ProgramRequirement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using Newtonsoft.Json;

namespace Elements
{
public partial class ProgramRequirement : IProgramRequirement
{
[JsonProperty("Qualified Program Name")]
public string QualifiedProgramName => String.IsNullOrWhiteSpace(this.ProgramGroup) ? this.ProgramName : $"{this.ProgramGroup} - {this.ProgramName}";
public int CountPlaced { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Elements
public partial class ProgramRequirement : Element
{
[JsonConstructor]
public ProgramRequirement(string @programGroup, string @programName, Color? @color, double @areaPerSpace, int @spaceCount, double? @width, double? @depth, string @hyparSpaceType, ProgramRequirementCountType @countType, double @totalArea, System.Guid @id = default, string @name = null)
public ProgramRequirement(string @programGroup, string @programName, Color? @color, double @areaPerSpace, int @spaceCount, double? @width, double? @depth, string @hyparSpaceType, ProgramRequirementCountType @countType, double @totalArea, System.Guid? @spaceConfig, System.Guid? @layoutTypeId, System.Guid? @catalog, System.Guid @id = default, string @name = null)
: base(id, name)
{
this.ProgramGroup = @programGroup;
Expand All @@ -40,6 +40,9 @@ public ProgramRequirement(string @programGroup, string @programName, Color? @col
this.HyparSpaceType = @hyparSpaceType;
this.CountType = @countType;
this.TotalArea = @totalArea;
this.SpaceConfig = @spaceConfig;
this.LayoutTypeId = @layoutTypeId;
this.Catalog = @catalog;
}


Expand Down Expand Up @@ -96,6 +99,18 @@ public ProgramRequirement()
[JsonProperty("Total Area", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public double TotalArea { get; set; }

/// <summary>The guid of the space configuration</summary>
[JsonProperty("SpaceConfig", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.Guid? SpaceConfig { get; set; }

/// <summary>The guid of the layout type</summary>
[JsonProperty("Layout Type Id", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.Guid? LayoutTypeId { get; set; }

/// <summary>The guid of the catalog</summary>
[JsonProperty("Catalog", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.Guid? Catalog { get; set; }


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@

namespace Elements
{
#pragma warning disable // Disable all warnings
#pragma warning disable // Disable all warnings

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.1.21.0 (Newtonsoft.Json v13.0.0.0)")]
public enum ProgramRequirementCountType
{
[System.Runtime.Serialization.EnumMember(Value = @"Item")]
Item = 0,

[System.Runtime.Serialization.EnumMember(Value = @"Area Total")]
Area_Total = 1,

}
}
12 changes: 12 additions & 0 deletions LayoutFunctions/LayoutFunctionCommon/SpaceConfigurationElement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Linq;
using System.Collections.Generic;
using Elements.Geometry;
using Elements.Components;
namespace Elements
{
public partial class SpaceConfigurationElement : Element
{
public SpaceConfiguration SpaceConfiguration { get; set; }
}
}
67 changes: 43 additions & 24 deletions LayoutFunctions/LoungeLayout/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,45 @@
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/test/bin/Debug/netcoreapp3.1/LoungeLayout.Tests.dll",
"args": [],
"cwd": "${workspaceFolder}/test",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/test/bin/Debug/netcoreapp3.1/LoungeLayout.Tests.dll",
"args": [],
"cwd": "${workspaceFolder}/test",
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
},
{
"name": "Attach to Hypar Run",
"type": "coreclr",
"request": "attach",
"processName": "LoungeLayout.Server"
},
{
"name": "Launch Hypar Run (Run once only)",
"type": "coreclr",
"request": "launch",
"program": "${workspaceFolder}/server/bin/Debug/net6.0/LoungeLayout.Server.dll",
"args": [
"--workflow-id",
"${input:workflowId}"
],
"preLaunchTask": "server-build"
}
],
"inputs": [
{
"id": "workflowId",
"type": "promptString",
"description": "Enter the workflow id to run."
}
]
}
Loading
Loading