Skip to content

Commit

Permalink
Merge pull request #632 from mcneel/AndyPayne/8.x/HopsUpdate3
Browse files Browse the repository at this point in the history
updating some dependencies. updating some type handling. Modified ToJSON
  • Loading branch information
andyopayne authored Nov 17, 2023
2 parents a8319b8 + d81416d commit f2f6bdd
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 11 deletions.
83 changes: 82 additions & 1 deletion src/compute.geometry/GrasshopperDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,78 @@ public Schema Solve(int rhinoVersion)
resthopperObjectList.Add(GetResthopperObject<Mesh>(rhValue, rhinoVersion));
}
break;
case GH_Extrusion ghValue:
{
Extrusion rhValue = ghValue.Value;
resthopperObjectList.Add(GetResthopperObject<Extrusion>(rhValue, rhinoVersion));
}
break;
case GH_PointCloud ghValue:
{
PointCloud rhValue = ghValue.Value;
resthopperObjectList.Add(GetResthopperObject<PointCloud>(rhValue, rhinoVersion));
}
break;
case GH_InstanceReference ghValue:
{
InstanceReferenceGeometry rhValue = ghValue.Value;
resthopperObjectList.Add(GetResthopperObject<InstanceReferenceGeometry>(rhValue, rhinoVersion));
}
break;
case GH_Hatch ghValue:
{
Hatch rhValue = ghValue.Value;
resthopperObjectList.Add(GetResthopperObject<Hatch>(rhValue, rhinoVersion));
}
break;
case GH_LinearDimension ghValue:
{
LinearDimension rhValue = ghValue.Value;
resthopperObjectList.Add(GetResthopperObject<LinearDimension>(rhValue, rhinoVersion));
}
break;
case GH_RadialDimension ghValue:
{
RadialDimension rhValue = ghValue.Value;
resthopperObjectList.Add(GetResthopperObject<RadialDimension>(rhValue, rhinoVersion));
}
break;
case GH_AngularDimension ghValue:
{
AngularDimension rhValue = ghValue.Value;
resthopperObjectList.Add(GetResthopperObject<AngularDimension>(rhValue, rhinoVersion));
}
break;
case GH_OrdinateDimension ghValue:
{
OrdinateDimension rhValue = ghValue.Value;
resthopperObjectList.Add(GetResthopperObject<OrdinateDimension>(rhValue, rhinoVersion));
}
break;
case GH_Leader ghValue:
{
Leader rhValue = ghValue.Value;
resthopperObjectList.Add(GetResthopperObject<Leader>(rhValue, rhinoVersion));
}
break;
case GH_TextEntity ghValue:
{
TextEntity rhValue = ghValue.Value;
resthopperObjectList.Add(GetResthopperObject<TextEntity>(rhValue, rhinoVersion));
}
break;
case GH_TextDot ghValue:
{
TextDot rhValue = ghValue.Value;
resthopperObjectList.Add(GetResthopperObject<TextDot>(rhValue, rhinoVersion));
}
break;
case GH_Centermark ghValue:
{
Centermark rhValue = ghValue.Value;
resthopperObjectList.Add(GetResthopperObject<Centermark>(rhValue, rhinoVersion));
}
break;
}
}

Expand Down Expand Up @@ -1149,7 +1221,16 @@ static ResthopperObject GetResthopperObject<T>(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;
}

Expand Down
12 changes: 10 additions & 2 deletions src/compute.geometry/IO/Schema.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Rhino.Geometry;

namespace Resthopper.IO
{
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions src/compute.geometry/ResthopperEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Carter;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Rhino.Geometry;

namespace compute.geometry
{
Expand Down
4 changes: 2 additions & 2 deletions src/compute.geometry/compute.geometry.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@

<ItemGroup>
<PackageReference Include="Carter" Version="7.0.0" />
<PackageReference Include="Grasshopper" Version="8.0.23031.14305-wip" ExcludeAssets="runtime"/>
<PackageReference Include="Grasshopper" Version="8.0.23304.9001" ExcludeAssets="runtime" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="RhinoCommon" Version="8.0.23031.14305-wip" ExcludeAssets="runtime"/>
<PackageReference Include="RhinoCommon" Version="8.0.23304.9001" ExcludeAssets="runtime" />
<PackageReference Include="Serilog" Version="3.0.2-dev-02044" />
<PackageReference Include="Serilog.AspNetCore" Version="6.1.0" />
<PackageReference Include="Serilog.Expressions" Version="3.4.1" />
Expand Down
3 changes: 2 additions & 1 deletion src/hops/Hops.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Grasshopper">
<Version>7.4.21067.13001</Version>
<Version>8.0.23304.9001</Version>
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="resources\Close_Toolbar_Active_20x20.png" />
Expand Down
50 changes: 45 additions & 5 deletions src/hops/RemoteDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(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;
}
Expand Down

0 comments on commit f2f6bdd

Please sign in to comment.