-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGHC_TriState.cs
96 lines (88 loc) · 3.45 KB
/
GHC_TriState.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Collections.Generic;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Types;
using Rhino.Geometry;
using Tortoise.DataTypes;
using Microsoft.CSharp;
namespace Tortoise
{
public class GHC_TriState : GH_Component
{
/// <summary>
/// Initializes a new instance of the MyComponent1 class.
/// </summary>
public GHC_TriState()
: base("TriState Conversion", "TriState",
"Converts strings and numbers to a tri-state value: \"True\",\"False\", or \"Unknown\"",
"Tortoise", "Util")
{
}
/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddGenericParameter("Input", "I", "Input to convert to a tri-state value", GH_ParamAccess.item);
}
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.Register_GenericParam("TriState", "T", "TriState value of the input");
pManager.Register_GenericParam("Hard-coded TriState", "TT", "Hard-coded TriState value (should be unknown)");
}
/// <summary>
/// This is the method that actually does the work.
/// </summary>
/// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
protected override void SolveInstance(IGH_DataAccess DA)
{
// Use dynamic type to handle different input types
dynamic input = null;
if (!DA.GetData(0, ref input))
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "No input provided");
return;
}
// Determine the input type
string inputTypeString = input.GetType().ToString();
switch (inputTypeString)
{
case "Grasshopper.Kernel.Types.GH_String":
case "Grasshopper.Kernel.Types.GH_Integer":
case "Grasshopper.Kernel.Types.GH_Number":
case "Grasshopper.Kernel.Types.GH_Boolean":
// Create and set a new TriStateType instance based on the input
TriState tri = new TriState(input);
DA.SetData(0, tri);
DA.SetData(1, new TriState());
break;
default:
// Set error message for unsupported types
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input type not supported");
break;
}
}
/// <summary>
/// Provides an Icon for the component.
/// </summary>
protected override System.Drawing.Bitmap Icon
{
get
{
//You can add image files to your project resources and access them like this:
// return Resources.IconForThisComponent;
return null;
}
}
/// <summary>
/// Gets the unique ID for this component. Do not change this ID after release.
/// </summary>
public override Guid ComponentGuid
{
get { return new Guid("EAD2798E-1C22-41C7-8EE0-5DA1FC50FC61"); }
}
}
}