Skip to content

Commit

Permalink
Headless doc working and tested
Browse files Browse the repository at this point in the history
  • Loading branch information
spigach-tt committed Jan 6, 2025
1 parent e04d2d7 commit 2c0f637
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/compute.geometry/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ static class Config
/// </summary>
public static int LogRetainDays { get; private set; }

/// <summary>
/// RHINO_COMPUTE_CREATE_HEADLESS_DOC: create a headless Rhino document for each request.
/// </summary>
public static bool CreateHeadlessDoc { get; private set; }

public static string[] GetDeprecationWarnings() => _warnings.ToArray();

/// <summary>
Expand All @@ -50,6 +55,7 @@ public static void Load()
ApiKey = GetEnvironmentVariable<string>(RHINO_COMPUTE_KEY, null);
LogPath = GetEnvironmentVariable(RHINO_COMPUTE_LOG_PATH, Path.Combine(Path.GetTempPath(), "Compute", "Logs"), COMPUTE_LOG_PATH);
LogRetainDays = GetEnvironmentVariable(RHINO_COMPUTE_LOG_RETAIN_DAYS, 10, COMPUTE_LOG_RETAIN_DAYS);
CreateHeadlessDoc = GetEnvironmentVariable<bool>(RHINO_COMPUTE_CREATE_HEADLESS_DOC, false);

#if DEBUG
Debug = true;
Expand All @@ -73,6 +79,7 @@ public static void Load()
const string RHINO_COMPUTE_LOG_PATH = "RHINO_COMPUTE_LOG_PATH";
const string RHINO_COMPUTE_LOG_RETAIN_DAYS = "RHINO_COMPUTE_LOG_RETAIN_DAYS";
const string RHINO_COMPUTE_DEBUG = "RHINO_COMPUTE_DEBUG";
const string RHINO_COMPUTE_CREATE_HEADLESS_DOC = "RHINO_COMPUTE_CREATE_HEADLESS_DOC";

// deprecated
const string COMPUTE_BIND_URLS = "COMPUTE_BIND_URLS";
Expand Down
14 changes: 14 additions & 0 deletions src/compute.geometry/ResthopperEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Rhino.Geometry;
using Rhino;

namespace compute.geometry
{
Expand Down Expand Up @@ -75,6 +76,19 @@ static string GrasshopperSolveHelper(Schema input, string body, System.Diagnosti
SetDefaultTolerances(input.AbsoluteTolerance, input.AngleTolerance);
SetDefaultUnits(input.ModelUnits);

// Instantiate headless doc
if (Config.CreateHeadlessDoc)
{
RhinoDoc.ActiveDoc = RhinoDoc.CreateHeadless(null);
RhinoDoc.ActiveDoc.ModelAbsoluteTolerance = input.AbsoluteTolerance;
RhinoDoc.ActiveDoc.ModelAngleToleranceDegrees = input.AngleTolerance;

if (Enum.TryParse(input.ModelUnits, out UnitSystem units))
{
RhinoDoc.ActiveDoc.ModelUnitSystem = units;
}
}

int recursionLevel = input.RecursionLevel + 1;
definition.Definition.DefineConstant("ComputeRecursionLevel", new Grasshopper.Kernel.Expressions.GH_Variant(recursionLevel));

Expand Down

0 comments on commit 2c0f637

Please sign in to comment.