-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
3,048 additions
and
2,451 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Grasshopper.Kernel; | ||
using Newtonsoft.Json.Linq; | ||
using Rhino.Geometry; | ||
using Swiftlet.Goo; | ||
using Swiftlet.Params; | ||
using Swiftlet.Util; | ||
|
||
namespace Swiftlet.Components | ||
{ | ||
public class CreateJsonArray : GH_Component | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the CreateJsonArray class. | ||
/// </summary> | ||
public CreateJsonArray() | ||
: base("Create JSON Array", "CJA", | ||
"Combine a list of JTokens into a JArray", | ||
NamingUtility.CATEGORY, NamingUtility.REQUEST) | ||
{ | ||
} | ||
public override GH_Exposure Exposure => GH_Exposure.secondary; | ||
|
||
/// <summary> | ||
/// Registers all the input parameters for this component. | ||
/// </summary> | ||
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager) | ||
{ | ||
pManager.AddParameter(new JTokenParam(), "JTokens", "JT", "JTokens to be combined into an array", GH_ParamAccess.list); | ||
} | ||
|
||
/// <summary> | ||
/// Registers all the output parameters for this component. | ||
/// </summary> | ||
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager) | ||
{ | ||
pManager.AddParameter(new JArrayParam(), "JArray", "JA", "Resulting JArray", GH_ParamAccess.item); | ||
} | ||
|
||
/// <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) | ||
{ | ||
List<JTokenGoo> goo = new List<JTokenGoo>(); | ||
DA.GetDataList(0, goo); | ||
|
||
List<JToken> tokens = goo.Select(o => o.Value).ToList(); | ||
JArray array = new JArray(); | ||
tokens.ForEach(t => array.Add(t)); | ||
|
||
DA.SetData(0, new JArrayGoo(array)); | ||
} | ||
|
||
/// <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 Properties.Resources.Icons_create_json_array_24x24; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets the unique ID for this component. Do not change this ID after release. | ||
/// </summary> | ||
public override Guid ComponentGuid | ||
{ | ||
get { return new Guid("be0d2120-8576-44b1-934f-1a70568907a2"); } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using Grasshopper.Kernel; | ||
using Newtonsoft.Json.Linq; | ||
using Rhino.Geometry; | ||
using Swiftlet.Goo; | ||
using Swiftlet.Params; | ||
using Swiftlet.Util; | ||
|
||
namespace Swiftlet.Components | ||
{ | ||
public class CreateJsonObject : GH_Component | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the CreateJsonObject class. | ||
/// </summary> | ||
public CreateJsonObject() | ||
: base("Create JSON Object", "CJO", | ||
"Create a JObject from keys and values", | ||
NamingUtility.CATEGORY, NamingUtility.REQUEST) | ||
{ | ||
} | ||
public override GH_Exposure Exposure => GH_Exposure.secondary; | ||
|
||
/// <summary> | ||
/// Registers all the input parameters for this component. | ||
/// </summary> | ||
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager) | ||
{ | ||
pManager.AddTextParameter("Keys", "K", "List of JObject keys", GH_ParamAccess.list); | ||
pManager.AddParameter(new JTokenParam(), "Values", "V", "List of JObject values", GH_ParamAccess.list); | ||
|
||
pManager[0].Optional = true; | ||
pManager[1].Optional = true; | ||
} | ||
|
||
/// <summary> | ||
/// Registers all the output parameters for this component. | ||
/// </summary> | ||
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager) | ||
{ | ||
pManager.AddParameter(new JObjectParam(), "JObject", "O", "Resulting JObject", GH_ParamAccess.item); | ||
} | ||
|
||
/// <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) | ||
{ | ||
List<string> keys = new List<string>(); | ||
List<JTokenGoo> values = new List<JTokenGoo>(); | ||
|
||
DA.GetDataList(0, keys); | ||
DA.GetDataList(1, values); | ||
|
||
if (keys.Count != values.Count) throw new Exception("The number of keys must match the number of values"); | ||
|
||
JObject obj = new JObject(); | ||
|
||
for (int i = 0; i < keys.Count; i++) | ||
{ | ||
string k = keys[i]; | ||
JToken v = values[i].Value; | ||
|
||
obj.Add(k, v); | ||
} | ||
|
||
DA.SetData(0, new JObjectGoo(obj)); | ||
} | ||
|
||
/// <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 Properties.Resources.Icons_create_json_object_24x24; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets the unique ID for this component. Do not change this ID after release. | ||
/// </summary> | ||
public override Guid ComponentGuid | ||
{ | ||
get { return new Guid("2892726b-fb0e-424a-877d-353f8ac18dc5"); } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using Grasshopper.Kernel; | ||
using Grasshopper.Kernel.Types; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using Rhino.Geometry; | ||
using Swiftlet.Goo; | ||
using Swiftlet.Params; | ||
using Swiftlet.Util; | ||
|
||
namespace Swiftlet.Components | ||
{ | ||
public class CreateJsonValue : GH_Component | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the CreateJsonValue class. | ||
/// </summary> | ||
public CreateJsonValue() | ||
: base("Create JSON Value", "CJV", | ||
"Turn a Grasshopper value into a JSON value", | ||
NamingUtility.CATEGORY, NamingUtility.REQUEST) | ||
{ | ||
} | ||
public override GH_Exposure Exposure => GH_Exposure.secondary; | ||
|
||
/// <summary> | ||
/// Registers all the input parameters for this component. | ||
/// </summary> | ||
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager) | ||
{ | ||
pManager.AddGenericParameter("Value", "V", "A string, integer, number, DateTime or boolean", GH_ParamAccess.item); | ||
} | ||
|
||
/// <summary> | ||
/// Registers all the output parameters for this component. | ||
/// </summary> | ||
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager) | ||
{ | ||
pManager.AddParameter(new JValueParam(), "JValue", "JV", "JSON Value", GH_ParamAccess.item); | ||
} | ||
|
||
/// <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) | ||
{ | ||
object obj = null; | ||
DA.GetData(0, ref obj); | ||
|
||
if (obj == null) return; | ||
|
||
if (obj is GH_String) | ||
{ | ||
GH_String str = obj as GH_String; | ||
DA.SetData(0, new JValueGoo(new JValue(str.Value))); | ||
} | ||
else if (obj is GH_Number) | ||
{ | ||
GH_Number num = obj as GH_Number; | ||
DA.SetData(0, new JValueGoo(new JValue(num.Value))); | ||
} | ||
else if (obj is GH_Integer) | ||
{ | ||
GH_Integer ghInt = obj as GH_Integer; | ||
DA.SetData(0, new JValueGoo(new JValue(ghInt.Value))); | ||
} | ||
else if (obj is GH_Boolean) | ||
{ | ||
GH_Boolean ghBool = obj as GH_Boolean; | ||
DA.SetData(0, new JValueGoo(new JValue(ghBool.Value))); | ||
} | ||
else if (obj is GH_Time) | ||
{ | ||
GH_Time time = obj as GH_Time; | ||
DA.SetData(0, new JValueGoo(new JValue(time.Value))); | ||
} | ||
else | ||
{ | ||
throw new Exception($"Unable to create a JValue from object of type {obj.GetType()}"); | ||
} | ||
} | ||
|
||
/// <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 Properties.Resources.Icons_create_json_value_24x24; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets the unique ID for this component. Do not change this ID after release. | ||
/// </summary> | ||
public override Guid ComponentGuid | ||
{ | ||
get { return new Guid("ca82e229-fcdb-415f-bd0b-5f37c1ef8c3f"); } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using Grasshopper.Kernel; | ||
using Newtonsoft.Json.Linq; | ||
using Rhino.Geometry; | ||
using Swiftlet.Goo; | ||
using Swiftlet.Params; | ||
using Swiftlet.Util; | ||
|
||
namespace Swiftlet.Components._2_Request | ||
{ | ||
public class RemoveJsonKey : GH_Component | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the RemoveJsonToken class. | ||
/// </summary> | ||
public RemoveJsonKey() | ||
: base("Remove JSON Key", "RJK", | ||
"Remove a key from JObject", | ||
NamingUtility.CATEGORY, NamingUtility.REQUEST) | ||
{ | ||
} | ||
public override GH_Exposure Exposure => GH_Exposure.tertiary; | ||
|
||
/// <summary> | ||
/// Registers all the input parameters for this component. | ||
/// </summary> | ||
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager) | ||
{ | ||
pManager.AddParameter(new JObjectParam(), "JObject", "JO", "JObject to remove the key from", GH_ParamAccess.item); | ||
pManager.AddTextParameter("Key", "K", "Key to be removed", GH_ParamAccess.item); | ||
} | ||
|
||
/// <summary> | ||
/// Registers all the output parameters for this component. | ||
/// </summary> | ||
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager) | ||
{ | ||
pManager.AddParameter(new JObjectParam(), "JObject", "JO", "Updated JObject", GH_ParamAccess.item); | ||
} | ||
|
||
/// <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) | ||
{ | ||
JObjectGoo goo = null; | ||
string key = string.Empty; | ||
|
||
DA.GetData(0, ref goo); | ||
DA.GetData(1, ref key); | ||
|
||
JObject obj = goo.Value.DeepClone() as JObject; | ||
try | ||
{ | ||
obj.Remove(key); | ||
} | ||
catch | ||
{ | ||
// pass | ||
} | ||
DA.SetData(0, new JObjectGoo(obj)); | ||
} | ||
|
||
/// <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 Properties.Resources.Icons_remove_json_key_24x24; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets the unique ID for this component. Do not change this ID after release. | ||
/// </summary> | ||
public override Guid ComponentGuid | ||
{ | ||
get { return new Guid("452cf748-8d55-42f8-b141-499b8f931891"); } | ||
} | ||
} | ||
} |
Oops, something went wrong.