Skip to content

Commit

Permalink
Refactor loading instruction to improve error handling and modularize…
Browse files Browse the repository at this point in the history
… initialization methods
  • Loading branch information
NATSUME Hiroaki committed Dec 20, 2024
1 parent 9e1c6dc commit b1f4b65
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
48 changes: 42 additions & 6 deletions Tunny/Component/LoadingInstruction.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.IO;
using System.Windows;
using System.Windows.Forms;

using CefSharp;
Expand Down Expand Up @@ -29,14 +28,51 @@ public class LoadingInstruction : GH_AssemblyPriority, IDisposable
public override GH_LoadingInstruction PriorityLoad()
{
TLog.InitializeLogger();
CefRuntime.SubscribeAnyCpuAssemblyResolver(TEnvVariables.ComponentFolder);
Runtime.PythonDLL = Path.Combine(TEnvVariables.PythonDllPath);
Grasshopper.Instances.ComponentServer.AddCategoryIcon("Tunny", Resource.TunnyIcon);
Grasshopper.Instances.ComponentServer.AddCategorySymbolName("Tunny", 'T');
Grasshopper.Instances.CanvasCreated += RegisterTunnyMenuItems;
InitializePythonDllPath();
InitializeTunnyMenuItem();
InitializeCefRuntimeResolver();

return GH_LoadingInstruction.Proceed;
}

private static void InitializeCefRuntimeResolver()
{
try
{
CefRuntime.SubscribeAnyCpuAssemblyResolver(TEnvVariables.ComponentFolder);
}
catch (Exception e)
{
TLog.Error($"CefSharp Assembly Resolver error: {e.Message}: {e.StackTrace}");
}
}

private void InitializeTunnyMenuItem()
{
try
{
Grasshopper.Instances.ComponentServer.AddCategoryIcon("Tunny", Resource.TunnyIcon);
Grasshopper.Instances.ComponentServer.AddCategorySymbolName("Tunny", 'T');
Grasshopper.Instances.CanvasCreated += RegisterTunnyMenuItems;
}
catch (Exception e)
{
TLog.Error($"Register Tunny Menu Items error: {e.Message}: {e.StackTrace}");
}
}

private static void InitializePythonDllPath()
{
try
{
Runtime.PythonDLL = Path.Combine(TEnvVariables.PythonDllPath);
}
catch (Exception e)
{
TLog.Error($"Python RuntimeDLL path set error: {e.Message}: {e.StackTrace}");
}
}

void RegisterTunnyMenuItems(GH_Canvas canvas)
{
TLog.MethodStart();
Expand Down
2 changes: 1 addition & 1 deletion Tunny/Component/Operation/ConstructFishEggByCsv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public ConstructFishEggByCsv()
protected override void RegisterInputParams(GH_InputParamManager pManager)
{
pManager.AddNumberParameter("Variables", "Vars", "Variables pair to enqueue optimize.", GH_ParamAccess.list);
pManager.AddTextParameter("CSV File", "CSV", "CSV file path to enqueue optimize.", GH_ParamAccess.item);
pManager.AddTextParameter("CSV File Path", "Path", "CSV file path to enqueue optimize.", GH_ParamAccess.item);
}

protected override void RegisterOutputParams(GH_OutputParamManager pManager)
Expand Down

0 comments on commit b1f4b65

Please sign in to comment.