-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeGraphComponent.cs
62 lines (52 loc) · 1.69 KB
/
DeGraphComponent.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using Grasshopper.Kernel;
using System;
using System.Linq;
using System.Reflection;
namespace Marmot
{
public class DeGraphComponent : GH_Component
{
public DeGraphComponent()
: base("DeGraph", "DeGraph",
"Deconstruct a graph into its subcomponents.",
"Marmot", "Graph")
{
}
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddGenericParameter("Graph", "G", "Graph object", GH_ParamAccess.item);
}
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddTextParameter("Rooms", "R", "Rooms of the graph", GH_ParamAccess.list);
pManager.AddTextParameter("Edges", "E", "Edges of the graph", GH_ParamAccess.list);
pManager.AddNumberParameter("Areas", "A", "Areas of the graph", GH_ParamAccess.list);
}
protected override void SolveInstance(IGH_DataAccess DA)
{
Graph graph = null;
if (!DA.GetData(0, ref graph)) return;
// Transforming the list of tuples into the desired format
var transformedEdges = graph.Edges.Select(
edge => $"{edge.Item1}-{edge.Item2}"
).ToList();
DA.SetDataList(0, graph.Nodes);
DA.SetDataList(1, transformedEdges);
DA.SetDataList(2, graph.Areas);
}
public override GH_Exposure Exposure => GH_Exposure.primary;
protected override System.Drawing.Bitmap Icon
{
get
{
string resourceName = "marmot.Icons.deGraph.png";
var assembly = Assembly.GetExecutingAssembly();
using (var stream = assembly.GetManifestResourceStream(resourceName))
{
return new System.Drawing.Bitmap(stream);
}
}
}
public override Guid ComponentGuid => new Guid("c35ca9bd-e0f0-4b38-9741-e98598f58831");
}
}