From d81416d6067ad359376c2f7dccb2bbaa0659e577 Mon Sep 17 00:00:00 2001 From: Andrew Payne Date: Fri, 17 Nov 2023 14:50:06 -0500 Subject: [PATCH] updating some dependencies. updating some type handling. Modified ToJSON --- src/compute.geometry/GrasshopperDefinition.cs | 83 ++++++++++++++++++- src/compute.geometry/IO/Schema.cs | 12 ++- src/compute.geometry/ResthopperEndpoints.cs | 1 + src/compute.geometry/compute.geometry.csproj | 4 +- src/hops/Hops.csproj | 3 +- src/hops/RemoteDefinition.cs | 50 +++++++++-- 6 files changed, 142 insertions(+), 11 deletions(-) diff --git a/src/compute.geometry/GrasshopperDefinition.cs b/src/compute.geometry/GrasshopperDefinition.cs index 09b95cb1..9d1c6de4 100644 --- a/src/compute.geometry/GrasshopperDefinition.cs +++ b/src/compute.geometry/GrasshopperDefinition.cs @@ -920,6 +920,78 @@ public Schema Solve(int rhinoVersion) resthopperObjectList.Add(GetResthopperObject(rhValue, rhinoVersion)); } break; + case GH_Extrusion ghValue: + { + Extrusion rhValue = ghValue.Value; + resthopperObjectList.Add(GetResthopperObject(rhValue, rhinoVersion)); + } + break; + case GH_PointCloud ghValue: + { + PointCloud rhValue = ghValue.Value; + resthopperObjectList.Add(GetResthopperObject(rhValue, rhinoVersion)); + } + break; + case GH_InstanceReference ghValue: + { + InstanceReferenceGeometry rhValue = ghValue.Value; + resthopperObjectList.Add(GetResthopperObject(rhValue, rhinoVersion)); + } + break; + case GH_Hatch ghValue: + { + Hatch rhValue = ghValue.Value; + resthopperObjectList.Add(GetResthopperObject(rhValue, rhinoVersion)); + } + break; + case GH_LinearDimension ghValue: + { + LinearDimension rhValue = ghValue.Value; + resthopperObjectList.Add(GetResthopperObject(rhValue, rhinoVersion)); + } + break; + case GH_RadialDimension ghValue: + { + RadialDimension rhValue = ghValue.Value; + resthopperObjectList.Add(GetResthopperObject(rhValue, rhinoVersion)); + } + break; + case GH_AngularDimension ghValue: + { + AngularDimension rhValue = ghValue.Value; + resthopperObjectList.Add(GetResthopperObject(rhValue, rhinoVersion)); + } + break; + case GH_OrdinateDimension ghValue: + { + OrdinateDimension rhValue = ghValue.Value; + resthopperObjectList.Add(GetResthopperObject(rhValue, rhinoVersion)); + } + break; + case GH_Leader ghValue: + { + Leader rhValue = ghValue.Value; + resthopperObjectList.Add(GetResthopperObject(rhValue, rhinoVersion)); + } + break; + case GH_TextEntity ghValue: + { + TextEntity rhValue = ghValue.Value; + resthopperObjectList.Add(GetResthopperObject(rhValue, rhinoVersion)); + } + break; + case GH_TextDot ghValue: + { + TextDot rhValue = ghValue.Value; + resthopperObjectList.Add(GetResthopperObject(rhValue, rhinoVersion)); + } + break; + case GH_Centermark ghValue: + { + Centermark rhValue = ghValue.Value; + resthopperObjectList.Add(GetResthopperObject(rhValue, rhinoVersion)); + } + break; } } @@ -1149,7 +1221,16 @@ static ResthopperObject GetResthopperObject(object goo, int rhinoVerion) var v = (T)goo; ResthopperObject rhObj = new ResthopperObject(); rhObj.Type = goo.GetType().FullName; - rhObj.Data = JsonConvert.SerializeObject(v, GeometryResolver.Settings(rhinoVerion)); + + if (v is GeometryBase geometry) + { + rhObj.Data = geometry.ToJSON(new Rhino.FileIO.SerializationOptions() { RhinoVersion = rhinoVerion }); + } + else + { + rhObj.Data = JsonConvert.SerializeObject(v, GeometryResolver.Settings(rhinoVerion)); + } + return rhObj; } diff --git a/src/compute.geometry/IO/Schema.cs b/src/compute.geometry/IO/Schema.cs index 5c8c0194..45d643f5 100644 --- a/src/compute.geometry/IO/Schema.cs +++ b/src/compute.geometry/IO/Schema.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Newtonsoft.Json; +using Rhino.Geometry; namespace Resthopper.IO { @@ -118,11 +119,18 @@ public ResthopperObject() public ResthopperObject(object obj) { + if(obj is GeometryBase geometry) + { + Data = geometry.ToJSON(new Rhino.FileIO.SerializationOptions() { RhinoVersion = 7}); + } + else + { #if COMPUTE_CORE - Data = JsonConvert.SerializeObject(obj, compute.geometry.GeometryResolver.Settings); + Data = JsonConvert.SerializeObject(obj, compute.geometry.GeometryResolver.Settings); #else - Data = JsonConvert.SerializeObject(obj);//, compute.geometry.GeometryResolver.Settings); + Data = JsonConvert.SerializeObject(obj);//, compute.geometry.GeometryResolver.Settings); #endif + } Type = obj.GetType().FullName; } diff --git a/src/compute.geometry/ResthopperEndpoints.cs b/src/compute.geometry/ResthopperEndpoints.cs index cfa35df3..c34f1120 100644 --- a/src/compute.geometry/ResthopperEndpoints.cs +++ b/src/compute.geometry/ResthopperEndpoints.cs @@ -14,6 +14,7 @@ using Carter; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Routing; +using Rhino.Geometry; namespace compute.geometry { diff --git a/src/compute.geometry/compute.geometry.csproj b/src/compute.geometry/compute.geometry.csproj index 9b52cc78..1562ae95 100644 --- a/src/compute.geometry/compute.geometry.csproj +++ b/src/compute.geometry/compute.geometry.csproj @@ -27,9 +27,9 @@ - + - + diff --git a/src/hops/Hops.csproj b/src/hops/Hops.csproj index 549d94ce..f6274b86 100644 --- a/src/hops/Hops.csproj +++ b/src/hops/Hops.csproj @@ -49,9 +49,10 @@ - 7.4.21067.13001 + 8.0.23304.9001 compile; build; native; contentfiles; analyzers; buildtransitive + diff --git a/src/hops/RemoteDefinition.cs b/src/hops/RemoteDefinition.cs index c70200f1..cccf10e5 100644 --- a/src/hops/RemoteDefinition.cs +++ b/src/hops/RemoteDefinition.cs @@ -721,20 +721,60 @@ static IGH_Goo GooFromResthopperObject(ResthopperObject obj) case "Rhino.Geometry.NurbsCurve": case "Rhino.Geometry.PolylineCurve": case "Rhino.Geometry.SubD": + case "Rhino.Geometry.PointCloud": + case "Rhino.Geometry.InstanceReferenceGeometry": + case "Rhino.Geometry.Hatch": + case "Rhino.Geometry.LinearDimension": + case "Rhino.Geometry.AngularDimension": + case "Rhino.Geometry.RadialDimension": + case "Rhino.Geometry.OrdinateDimension": + case "Rhino.Geometry.TextEntity": + case "Rhino.Geometry.TextDot": + case "Rhino.Geometry.Leader": { Dictionary dict = JsonConvert.DeserializeObject>(data); var geometry = Rhino.Runtime.CommonObject.FromJSON(dict); - Surface surface = geometry as Surface; - if (surface != null) - geometry = surface.ToBrep(); - if (geometry is Brep) - return new Grasshopper.Kernel.Types.GH_Brep(geometry as Brep); + if (geometry is Extrusion) + return new Grasshopper.Kernel.Types.GH_Extrusion(geometry as Extrusion); + if (geometry is Surface) + return new Grasshopper.Kernel.Types.GH_Surface(geometry as Surface); + if (geometry is Brep brep) + { + if(brep.Faces.Count > 1) + { + return new Grasshopper.Kernel.Types.GH_Brep(brep); + } + else + { + return new Grasshopper.Kernel.Types.GH_Surface(brep); + } + } if (geometry is Curve) return new Grasshopper.Kernel.Types.GH_Curve(geometry as Curve); if (geometry is Mesh) return new Grasshopper.Kernel.Types.GH_Mesh(geometry as Mesh); if (geometry is SubD) return new Grasshopper.Kernel.Types.GH_SubD(geometry as SubD); + if (geometry is PointCloud) + return new Grasshopper.Kernel.Types.GH_PointCloud(geometry as PointCloud); + if (geometry is InstanceReferenceGeometry) + return new Grasshopper.Kernel.Types.GH_InstanceReference(geometry as InstanceReferenceGeometry); + if (geometry is Hatch) + return new Grasshopper.Kernel.Types.GH_Hatch(geometry as Hatch); + if (geometry is LinearDimension) + return new Grasshopper.Kernel.Types.GH_LinearDimension(geometry as LinearDimension); + if (geometry is AngularDimension) + return new Grasshopper.Kernel.Types.GH_AngularDimension(geometry as AngularDimension); + if (geometry is RadialDimension) + return new Grasshopper.Kernel.Types.GH_RadialDimension(geometry as RadialDimension); + if (geometry is OrdinateDimension) + return new Grasshopper.Kernel.Types.GH_OrdinateDimension(geometry as OrdinateDimension); + if (geometry is TextEntity) + return new Grasshopper.Kernel.Types.GH_TextEntity(geometry as TextEntity); + if (geometry is TextDot) + return new Grasshopper.Kernel.Types.GH_TextDot(geometry as TextDot); + if (geometry is Leader) + return new Grasshopper.Kernel.Types.GH_Leader(geometry as Leader); } break; }