1111using System . Linq ;
1212using System . Collections ;
1313using GH_IO . Serialization ;
14+ using Grasshopper . Kernel . Special ;
15+ using System . Drawing ;
1416
1517namespace 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