Skip to content

Commit

Permalink
Stage 1 of refactoring for Goos
Browse files Browse the repository at this point in the history
  • Loading branch information
andyopayne committed Dec 1, 2023
1 parent 115db92 commit 2ee12da
Show file tree
Hide file tree
Showing 8 changed files with 475 additions and 308 deletions.
2 changes: 1 addition & 1 deletion src/HopsNetCore/HopsNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</ItemGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<StartProgram>C:\Program Files\Rhino 8\System\Rhino.exe</StartProgram>
<StartProgram>C:\dev\github\mcneel\rhino8\src4\bin\Debug\Rhino.exe</StartProgram>
<StartArguments></StartArguments>
<StartAction>Program</StartAction>
</PropertyGroup>
Expand Down
395 changes: 209 additions & 186 deletions src/compute.geometry/GrasshopperDefinition.cs

Large diffs are not rendered by default.

55 changes: 53 additions & 2 deletions src/compute.geometry/IO/GhPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GH_IO.Serialization;
using Grasshopper.Kernel.Types;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

Expand Down Expand Up @@ -80,17 +82,66 @@ public bool LastIndexSame(int i)
}
}

public class ValueTree
{
public string ParamName { get; set; }
}

public class DataTree<T>
public class GooTree : ValueTree
{
[JsonIgnore]
public Grasshopper.Kernel.Data.GH_Structure<IGH_Goo> Tree;
public string InnerTree
{
get
{
var base64 = string.Empty;
var archive = new GH_Archive();
archive.CreateNewRoot(true);
var chunk = archive.GetRootNode;

foreach (var list in Tree.Branches)
{
for (int i = 0; i < list.Count; i++)
{
var goo = list[i];
// Removing ref ID in order to send as internalized geometry
if (goo is IGH_GeometricGoo geometricGoo)
{
geometricGoo = geometricGoo.DuplicateGeometry();
geometricGoo.ReferenceID = Guid.Empty;
list[i] = geometricGoo;
}
}
}

Tree.Write(chunk);
var binary = archive.Serialize_Binary();
base64 = Convert.ToBase64String(binary);
return base64;
}
set
{
var base64 = value;
var binary = Convert.FromBase64String(base64);
var archive = new GH_Archive();
archive.Deserialize_Binary(binary);
var chunk = archive.GetRootNode;
Tree = new Grasshopper.Kernel.Data.GH_Structure<IGH_Goo>();
Tree.Read(chunk);
}
}
}

public class DataTree<T> : ValueTree
{
public DataTree() {
_tree = new Dictionary<string, List<T>>();
//_GhPathIndexer = new Dictionary<int, GhPath>();
}

private Dictionary<string, List<T>> _tree;
public string ParamName { get; set; }

//Dictionary<int, GhPath> _GhPathIndexer;


Expand Down
4 changes: 4 additions & 0 deletions src/compute.geometry/IO/Schema.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Grasshopper.Kernel.Types;
using Newtonsoft.Json;
using Rhino.Geometry;

Expand Down Expand Up @@ -40,6 +41,9 @@ public Schema() {}
[JsonProperty(PropertyName = "values")]
public List<DataTree<ResthopperObject>> Values { get; set; } = new List<DataTree<ResthopperObject>>();

[JsonProperty(PropertyName = "goos")]
public List<GooTree> Goos { get; set; } = new List<GooTree>();

// Return warnings from GH
[JsonProperty(PropertyName = "warnings", DefaultValueHandling = DefaultValueHandling.Ignore)]
public List<string> Warnings { get; set; } = new List<string>();
Expand Down
6 changes: 3 additions & 3 deletions src/compute.geometry/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ static void Main(string[] args)
// should use.
// (for McNeel devs only and only those devs who use the same path as Andy)

//string rhinoSystemDir = @"C:\dev\github\mcneel\rhino8\src4\bin\Debug";
//if (System.IO.File.Exists(rhinoSystemDir + "\\Rhino.exe"))
// RhinoInside.Resolver.RhinoSystemDirectory = rhinoSystemDir;
string rhinoSystemDir = @"C:\dev\github\mcneel\rhino8\src4\bin\Debug";
if (System.IO.File.Exists(rhinoSystemDir + "\\Rhino.exe"))
RhinoInside.Resolver.RhinoSystemDirectory = rhinoSystemDir;

#endif
StartTime = DateTime.Now;
Expand Down
2 changes: 1 addition & 1 deletion src/compute.geometry/ResthopperEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static string GrasshopperSolveHelper(Schema input, string body, System.Diagnosti
int recursionLevel = input.RecursionLevel + 1;
definition.Definition.DefineConstant("ComputeRecursionLevel", new Grasshopper.Kernel.Expressions.GH_Variant(recursionLevel));

definition.SetInputs(input.Values);
definition.SetInputs(input);
long decodeTime = stopwatch.ElapsedMilliseconds;
stopwatch.Restart();
var output = definition.Solve(input.DataVersion);
Expand Down
3 changes: 2 additions & 1 deletion src/hops/HopsComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,8 @@ void DefineInputsAndOutputs()
paramIndex = mgr.AddTextParameter(name, nickname, inputDescription, access, input.Default.ToString());
break;
case Grasshopper.Kernel.Parameters.Param_GenericObject _:
throw new Exception("generic param not supported");
paramIndex = mgr.AddGenericParameter(name, nickname, inputDescription, access);
break;
case Grasshopper.Kernel.Parameters.Param_Geometry _:
paramIndex = mgr.AddGeometryParameter(name, nickname, inputDescription, access);
break;
Expand Down
Loading

0 comments on commit 2ee12da

Please sign in to comment.