Skip to content

Commit

Permalink
CNX-9443 Rhino Compute units set as mm (#3460)
Browse files Browse the repository at this point in the history
* fix(rhino): Apply  preprocessor directives to RHINO7_OR_GREATER not just RHINO7

* fix: Unify getVersionedName + fix initial exception on document open

* chore: Flag GetVersionedAppName as obsolete

* fix: Remove unnecessary using statement
  • Loading branch information
AlanRynne authored Jun 3, 2024
1 parent e7450a2 commit dfb6d2e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;
using Microsoft.CSharp.RuntimeBinder;
using Rhino;
using Rhino.Display;
using Rhino.Geometry;
using Speckle.Core.Kits;
Expand All @@ -27,17 +26,9 @@ public static class Utilities
/// Gets the appropriate Grasshopper App name depending on the Version of Rhino currently running.
/// </summary>
/// <remarks>If running in Rhino >7, Rhino7 will be used as fallback.</remarks>
/// <returns><see cref="VersionedHostApplications.Grasshopper7"/> when Rhino 7 is running, <see cref="VersionedHostApplications.Grasshopper6"/> otherwise.</returns>
public static string GetVersionedAppName()
{
var version = HostApplications.Grasshopper.GetVersion(HostAppVersion.v6);
if (RhinoApp.Version.Major >= 7)
{
version = HostApplications.Grasshopper.GetVersion(HostAppVersion.v7);
}

return version;
}
/// <returns><see cref="VersionedHostApplications.Grasshopper7"/> when Rhino 7 is running, <see cref="VersionedHostApplications.Grasshopper8"/> when Rhino 8 is running, <see cref="VersionedHostApplications.Grasshopper6"/> otherwise.</returns>
[Obsolete("Use Loader.GetGrasshopperHostAppVersion instead")]
public static string GetVersionedAppName() => Loader.GetGrasshopperHostAppVersion();

public static ISpeckleConverter GetDefaultConverter()
{
Expand Down
20 changes: 13 additions & 7 deletions ConnectorGrasshopper/ConnectorGrasshopperShared/Loader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public override GH_LoadingInstruction PriorityLoad()
Setup.Init(GetRhinoHostAppVersion(), HostApplications.Rhino.Slug, logConfig);

Instances.CanvasCreated += OnCanvasCreated;
#if RHINO7

#if RHINO7_OR_GREATER
if (Instances.RunningHeadless)
{
// If GH is running headless, we listen for document added/removed events.
Expand Down Expand Up @@ -492,15 +493,15 @@ public static void KeepOpenOnDropdownCheck(ToolStripMenuItem ctl)

public static void DisposeHeadlessDoc()
{
#if RHINO7
#if RHINO7_OR_GREATER
_headlessDoc?.Dispose();
#endif
_headlessDoc = null;
}

public static void SetupHeadlessDoc()
{
#if RHINO7
#if RHINO7_OR_GREATER
// var templatePath = Path.Combine(Helpers.UserApplicationDataPath, "Speckle", "Templates",
// SpeckleGHSettings.HeadlessTemplateFilename);
// Console.WriteLine($"Setting up doc. Looking for '{templatePath}'");
Expand All @@ -510,7 +511,8 @@ public static void SetupHeadlessDoc()

_headlessDoc = RhinoDoc.CreateHeadless(null);
Console.WriteLine(
$"Headless run with doc '{_headlessDoc.Name ?? "Untitled"}'\n with template: '{_headlessDoc.TemplateFileUsed ?? "No template"}'\n with units: {_headlessDoc.ModelUnitSystem}");
$"Speckle - Backup headless doc is ready: '{_headlessDoc.Name ?? "Untitled"}'\n with template: '{_headlessDoc.TemplateFileUsed ?? "No template"}'\n with units: {_headlessDoc.ModelUnitSystem}");
Console.WriteLine("Speckle - To modify the units in a headless run, you can override the 'RhinoDoc.ActiveDoc' in the '.gh' file using a c#/python script.");
#endif
}

Expand All @@ -521,14 +523,18 @@ public static void SetupHeadlessDoc()
/// <returns></returns>
public static RhinoDoc GetCurrentDocument()
{
#if RHINO7
if (Instances.RunningHeadless && RhinoDoc.ActiveDoc == null)
#if RHINO7_OR_GREATER
if (Instances.RunningHeadless && RhinoDoc.ActiveDoc == null && _headlessDoc != null)
{
// Running headless, with no ActiveDoc override and _headlessDoc was correctly initialised.
// Only time the _headlessDoc is not set is upon document opening, where the components will
// check for this as their normal initialisation routine, but the document will be refreshed on every solution run.
Console.WriteLine(
$"Fetching headless doc '{_headlessDoc.Name ?? "Untitled"}'\n with template: '{_headlessDoc.TemplateFileUsed ?? "No template"}'");
$"Speckle - Fetching headless doc '{_headlessDoc?.Name ?? "Untitled"}'\n with template: '{_headlessDoc.TemplateFileUsed ?? "No template"}'");
Console.WriteLine(" Model units:" + _headlessDoc.ModelUnitSystem);
return _headlessDoc;
}

return RhinoDoc.ActiveDoc;
#else
return RhinoDoc.ActiveDoc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public override void AddedToDocument(GH_Document document)
break;
}
(Params.Output[0] as SpeckleBaseParam).UseSchemaTag = UseSchemaTag;
#if RHINO7
#if RHINO7_OR_GREATER
if (!Instances.RunningHeadless)
{
(Params.Output[0] as SpeckleBaseParam).ExpirePreview(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public override void AddedToDocument(GH_Document document)
}

((SpeckleBaseParam)Params.Output[0]).UseSchemaTag = UseSchemaTag;
#if RHINO7
#if RHINO7_OR_GREATER
if (!Instances.RunningHeadless)
{
(Params.Output[0] as SpeckleBaseParam).ExpirePreview(true);
Expand Down

0 comments on commit dfb6d2e

Please sign in to comment.