Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Andy payne/8.x/list access #571

Open
wants to merge 2 commits into
base: 8.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 0 additions & 134 deletions src/compute.geometry/GrasshopperDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,12 @@ public void SetInputs(List<DataTree<ResthopperObject>> values)
IGH_ContextualParameter contextualParameter = inputGroup.Param as IGH_ContextualParameter;
if(contextualParameter != null)
{
var treeAccess = Convert.ToBoolean(contextualParameter.GetType().GetProperty("TreeAccess")?.GetValue(contextualParameter, null));
if (contextualParameter != null)
{
switch (ParamTypeName(inputGroup.Param))
{
case "Boolean":
{
if (treeAccess)
{
Grasshopper.DataTree<GH_Boolean> inputTree = new Grasshopper.DataTree<GH_Boolean>();
foreach (KeyValuePair<string, List<ResthopperObject>> entree in tree)
{
Expand All @@ -354,27 +351,10 @@ public void SetInputs(List<DataTree<ResthopperObject>> values)
contextualParameter.GetType()
.GetMethod("AssignContextualDataTree")?
.Invoke(contextualParameter, new object[] { inputTree });
}
else
{
foreach (KeyValuePair<string, List<ResthopperObject>> entree in tree)
{
bool[] booleans = new bool[entree.Value.Count];
for (int i = 0; i < booleans.Length; i++)
{
ResthopperObject restobj = entree.Value[i];
booleans[i] = JsonConvert.DeserializeObject<bool>(restobj.Data);
}
contextualParameter.AssignContextualData(booleans);
break;
}
}
}
break;
case "Number":
{
if (treeAccess)
{
Grasshopper.DataTree<GH_Number> inputTree = new Grasshopper.DataTree<GH_Number>();
foreach (KeyValuePair<string, List<ResthopperObject>> entree in tree)
{
Expand All @@ -389,27 +369,10 @@ public void SetInputs(List<DataTree<ResthopperObject>> values)
contextualParameter.GetType()
.GetMethod("AssignContextualDataTree")?
.Invoke(contextualParameter, new object[] { inputTree });
}
else
{
foreach (KeyValuePair<string, List<ResthopperObject>> entree in tree)
{
double[] doubles = new double[entree.Value.Count];
for (int i = 0; i < doubles.Length; i++)
{
ResthopperObject restobj = entree.Value[i];
doubles[i] = JsonConvert.DeserializeObject<double>(restobj.Data);
}
contextualParameter.AssignContextualData(doubles);
break;
}
}
}
break;
case "Integer":
{
if (treeAccess)
{
Grasshopper.DataTree<GH_Integer> inputTree = new Grasshopper.DataTree<GH_Integer>();
foreach (KeyValuePair<string, List<ResthopperObject>> entree in tree)
{
Expand All @@ -424,27 +387,10 @@ public void SetInputs(List<DataTree<ResthopperObject>> values)
contextualParameter.GetType()
.GetMethod("AssignContextualDataTree")?
.Invoke(contextualParameter, new object[] { inputTree });
}
else
{
foreach (KeyValuePair<string, List<ResthopperObject>> entree in tree)
{
int[] integers = new int[entree.Value.Count];
for (int i = 0; i < integers.Length; i++)
{
ResthopperObject restobj = entree.Value[i];
integers[i] = JsonConvert.DeserializeObject<int>(restobj.Data);
}
contextualParameter.AssignContextualData(integers);
break;
}
}
}
break;
case "Point":
{
if (treeAccess)
{
Grasshopper.DataTree<GH_Point> inputTree = new Grasshopper.DataTree<GH_Point>();
foreach (KeyValuePair<string, List<ResthopperObject>> entree in tree)
{
Expand All @@ -459,27 +405,10 @@ public void SetInputs(List<DataTree<ResthopperObject>> values)
contextualParameter.GetType()
.GetMethod("AssignContextualDataTree")?
.Invoke(contextualParameter, new object[] { inputTree });
}
else
{
foreach (KeyValuePair<string, List<ResthopperObject>> entree in tree)
{
Point3d[] points = new Point3d[entree.Value.Count];
for (int i = 0; i < entree.Value.Count; i++)
{
ResthopperObject restobj = entree.Value[i];
points[i] = JsonConvert.DeserializeObject<Rhino.Geometry.Point3d>(restobj.Data);
}
contextualParameter.AssignContextualData(points);
break;
}
}
}
break;
case "Line":
{
if (treeAccess)
{
Grasshopper.DataTree<GH_Line> inputTree = new Grasshopper.DataTree<GH_Line>();
foreach (KeyValuePair<string, List<ResthopperObject>> entree in tree)
{
Expand All @@ -494,27 +423,10 @@ public void SetInputs(List<DataTree<ResthopperObject>> values)
contextualParameter.GetType()
.GetMethod("AssignContextualDataTree")?
.Invoke(contextualParameter, new object[] { inputTree });
}
else
{
foreach (KeyValuePair<string, List<ResthopperObject>> entree in tree)
{
Line[] lines = new Line[entree.Value.Count];
for (int i = 0; i < entree.Value.Count; i++)
{
ResthopperObject restobj = entree.Value[i];
lines[i] = JsonConvert.DeserializeObject<Rhino.Geometry.Line>(restobj.Data);
}
contextualParameter.AssignContextualData(lines);
break;
}
}
}
break;
case "Text":
{
if (treeAccess)
{
Grasshopper.DataTree<GH_String> inputTree = new Grasshopper.DataTree<GH_String>();
foreach (KeyValuePair<string, List<ResthopperObject>> entree in tree)
{
Expand All @@ -539,40 +451,10 @@ public void SetInputs(List<DataTree<ResthopperObject>> values)
contextualParameter.GetType()
.GetMethod("AssignContextualDataTree")?
.Invoke(contextualParameter, new object[] { inputTree });
}
else
{
foreach (KeyValuePair<string, List<ResthopperObject>> entree in tree)
{
string[] strings = new string[entree.Value.Count];
for (int i = 0; i < entree.Value.Count; i++)
{
ResthopperObject restobj = entree.Value[i];
// 2 July 2021 S. Baer (Github issue #394)
// This is pretty hacky and I wish I understood json.net a bit more
// to figure out why it is throwing exceptions in certain cases.
// I'm hoping to support both embedded json inside of other json as
// well as plain strings.
try
{
// Use JsonConvert to properly unescape the string
strings[i] = JsonConvert.DeserializeObject<string>(restobj.Data);
}
catch (Exception)
{
strings[i] = System.Text.RegularExpressions.Regex.Unescape(restobj.Data);
}
}
contextualParameter.AssignContextualData(strings);
break;
}
}
}
break;
case "Geometry":
{
if (treeAccess)
{
Grasshopper.DataTree<IGH_GeometricGoo> inputTree = new Grasshopper.DataTree<IGH_GeometricGoo>();
foreach (KeyValuePair<string, List<ResthopperObject>> entree in tree)
{
Expand All @@ -589,22 +471,6 @@ public void SetInputs(List<DataTree<ResthopperObject>> values)
contextualParameter.GetType()
.GetMethod("AssignContextualDataTree")?
.Invoke(contextualParameter, new object[] { inputTree });
}
else
{
foreach (KeyValuePair<string, List<ResthopperObject>> entree in tree)
{
GeometryBase[] geometries = new GeometryBase[entree.Value.Count];
for (int i = 0; i < entree.Value.Count; i++)
{
ResthopperObject restobj = entree.Value[i];
var dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(restobj.Data);
geometries[i] = Rhino.Runtime.CommonObject.FromJSON(dict) as GeometryBase;
}
contextualParameter.AssignContextualData(geometries);
break;
}
}
}
break;
}
Expand Down
6 changes: 4 additions & 2 deletions src/hops/HopsComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
using System.Threading.Tasks;
using System.IO;
using Rhino;
using System.Linq;
using Newtonsoft.Json.Linq;

namespace Hops
{
Expand Down Expand Up @@ -222,7 +224,7 @@ protected override void SolveInstance(IGH_DataAccess DA)
}
else
{
for(int i=0; i<_workingSolveList.Count; i++)
for(int i = 0; i < _workingSolveList.Count; i++)
{
var output = _workingSolveList.SolvedSchema(i);
TaskList.Add(Task.FromResult(output));
Expand Down Expand Up @@ -254,7 +256,7 @@ protected override void SolveInstance(IGH_DataAccess DA)
if (inputSchema != null)
{
schema = _remoteDefinition.Solve(inputSchema, _cacheResultsInMemory);
if (_lastCreatedSchema==null)
if (_lastCreatedSchema == null)
_lastCreatedSchema = inputSchema;
}
else
Expand Down
Loading