wip: more cleanup and comments

This commit is contained in:
Dimitrie Stefanescu
2024-12-19 16:16:48 +00:00
parent 44105d7d75
commit 42c3ca1ec3
3 changed files with 34 additions and 15 deletions
@@ -83,7 +83,7 @@ public class CreateCollection : GH_Component, IGH_VariableParameterComponent
continue;
}
childCollection["topology"] = GetParamTopology(inputParam);
childCollection["topology"] = GrasshopperHelpers.GetParamTopology(inputParam);
foreach (var obj in data)
{
@@ -96,7 +96,7 @@ public class CreateCollection : GH_Component, IGH_VariableParameterComponent
try
{
var geometryBase = geoGeo.GeometricGooToGeometryBase();
var converted = ToSpeckleConversionContext.ToSpeckleConverter.Convert(geometryBase); // .Convert(geometryBase);
var converted = ToSpeckleConversionContext.ToSpeckleConverter.Convert(geometryBase);
var wrapper = new SpeckleObject() { GeometryBase = geometryBase, Base = converted };
childCollection.elements.Add(wrapper);
@@ -111,7 +111,7 @@ public class CreateCollection : GH_Component, IGH_VariableParameterComponent
{
// TODO remove copy pasta
var docObject = RhinoDoc.ActiveDoc.Objects.FindId(modelObject.Id.NotNull());
var converted = ToSpeckleConversionContext.ToSpeckleConverter.Convert(docObject.Geometry); // .Convert(docObject.Geometry);
var converted = ToSpeckleConversionContext.ToSpeckleConverter.Convert(docObject.Geometry);
var wrapper = new SpeckleObject() { GeometryBase = docObject.Geometry, Base = converted };
childCollection.elements.Add(wrapper);
@@ -183,14 +183,4 @@ public class CreateCollection : GH_Component, IGH_VariableParameterComponent
}
};
}
public string GetParamTopology(IGH_Param param)
{
string topology = "";
foreach (Grasshopper.Kernel.Data.GH_Path myPath in param.VolatileData.Paths)
{
topology += myPath.ToString(false) + "-" + param.VolatileData.get_Branch(myPath).Count + " ";
}
return topology;
}
}
@@ -6,6 +6,13 @@ using Speckle.Sdk.Models.Collections;
namespace Speckle.Connectors.Grasshopper8.Components.Collections;
/// <summary>
/// Given a collection and a path, this component will output the objects in the corresponding collection.
/// Note: This component does not flatten the selected collection - if it contains sub collections those will not
/// be outputted.
///
/// To extract those objects out, you should select that specific sub path as well.
/// </summary>
public class FilterObjectsByPaths : GH_Component
{
public override Guid ComponentGuid => new("77CAEE94-F0B9-4611-897C-71F2A22BA311");
@@ -65,12 +72,11 @@ public class FilterObjectsByPaths : GH_Component
var tree = GrasshopperHelpers.CreateDataTreeFromTopologyAndItems(topology, targetCollection.elements);
dataAccess.SetDataTree(0, tree);
}
// dataAccess.SetData(0, test);
}
private Collection FindCollection(Collection root, string unifiedPath)
{
var collectionNames = unifiedPath.Split(new string[] { " :: " }, StringSplitOptions.None).Skip(1).ToList();
var collectionNames = unifiedPath.Split([" :: "], StringSplitOptions.None).Skip(1).ToList();
Collection currentCollection = root;
while (collectionNames.Count != 0)
{
@@ -1,4 +1,5 @@
using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;
using Rhino;
@@ -101,6 +102,12 @@ public static class GrasshopperHelpers
throw new SpeckleException("Failed to cast IGH_GeometricGoo to geometry base");
}
/// <summary>
/// Creates a tree based of a string that encodes the grasshopper topology.
/// </summary>
/// <param name="topology"></param>
/// <param name="subset"></param>
/// <returns></returns>
public static DataTree<object> CreateDataTreeFromTopologyAndItems(string topology, System.Collections.IList subset)
{
var tree = new DataTree<object>();
@@ -131,4 +138,20 @@ public static class GrasshopperHelpers
return tree;
}
/// <summary>
/// Encodes a tree topology into an exhaustive string which can be used to recreate it using
/// <see cref="CreateDataTreeFromTopologyAndItems"/>.
/// </summary>
/// <param name="param"></param>
/// <returns></returns>
public static string GetParamTopology(IGH_Param param)
{
string topology = "";
foreach (GH_Path myPath in param.VolatileData.Paths)
{
topology += myPath.ToString(false) + "-" + param.VolatileData.get_Branch(myPath).Count + " ";
}
return topology;
}
}