Skip to content
This repository was archived by the owner on Aug 28, 2021. It is now read-only.

Commit e108e33

Browse files
authored
Merge pull request #298 from speckleworks/Matteo/dev
Schema builder enums
2 parents af0fc2b + 01c12f5 commit e108e33

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

SpeckleGrasshopper/ObjectCreation/SchemaBuilderComponent.cs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
using System.Linq;
1212
using System.Collections;
1313
using GH_IO.Serialization;
14+
using Grasshopper.Kernel.Special;
15+
using System.Drawing;
1416

1517
namespace SpeckleGrasshopper.UserDataUtils
1618
{
@@ -26,6 +28,8 @@ public class SchemaBuilderComponent : GH_Component, IGH_VariableParameterCompone
2628
public List<ToolStripItem> OptionalPropsItems;
2729
public bool CheckItAll = false;
2830

31+
private GH_Document _document;
32+
2933
public SchemaBuilderComponent( )
3034
: base( "Schema Builder Component", "SBC",
3135
"Builds Speckle Types through reflecting upon SpeckleCore and SpeckleKits.",
@@ -175,6 +179,21 @@ void RegisterPropertyAsInputParameter( PropertyInfo prop, int index )
175179
newInputParam.Access = GH_ParamAccess.item;
176180
}
177181
Params.RegisterInputParam( newInputParam, index );
182+
183+
184+
//add dropdown
185+
if (propType.IsEnum)
186+
{
187+
//expire solution so that node gets proper size
188+
ExpireSolution(true);
189+
190+
var instance = Activator.CreateInstance(propType);
191+
192+
var vals = Enum.GetValues(propType).Cast<Enum>().Select(x => x.ToString()).ToList();
193+
var options = CreateDropDown(propName, vals, Attributes.Bounds.X, Params.Input[index].Attributes.Bounds.Y);
194+
_document.AddObject(options, false);
195+
Params.Input[index].AddSource(options);
196+
}
178197
}
179198

180199
public void UnregisterPropertyInput( PropertyInfo myProp )
@@ -388,7 +407,13 @@ protected override void SolveInstance( IGH_DataAccess DA )
388407
DA.SetData( 0, outputObject );
389408
}
390409

391-
public bool CanInsertParameter( GH_ParameterSide side, int index )
410+
public override void AddedToDocument(GH_Document document)
411+
{
412+
_document = document;
413+
base.AddedToDocument(document);
414+
}
415+
416+
public bool CanInsertParameter( GH_ParameterSide side, int index )
392417
{
393418
return false;
394419
}
@@ -432,5 +457,25 @@ public override Guid ComponentGuid
432457
{
433458
get { return new Guid( "970d1754-b192-405f-a78b-98afb74ee6ca" ); }
434459
}
460+
461+
public static GH_ValueList CreateDropDown(string name, List<string> values, float x, float y)
462+
{
463+
var vallist = new GH_ValueList();
464+
vallist.CreateAttributes();
465+
vallist.Name = name;
466+
vallist.NickName = name + ":";
467+
vallist.Description = "Select an option...";
468+
vallist.ListMode = GH_ValueListMode.DropDown;
469+
vallist.ListItems.Clear();
470+
471+
for (int i = 0; i < values.Count; i++)
472+
{
473+
vallist.ListItems.Add(new GH_ValueListItem(values[i], i.ToString()));
474+
}
475+
476+
vallist.Attributes.Pivot = new PointF(x - 200, y -10);
477+
478+
return vallist;
479+
}
435480
}
436481
}

0 commit comments

Comments
 (0)