private Panel GenParmPanel(HB.ModifierBase modifier) { var hbObj = modifier; var panel = new DynamicLayout(); panel.DefaultSpacing = new Size(5, 5); panel.DefaultPadding = new Padding(5); var properties = hbObj.GetType().GetProperties().Where(_ => _.CanWrite); if (properties.Count() > 15) { panel.Height = 360; panel.BeginScrollable(); } var name = new TextBox(); hbObj.DisplayName = hbObj.DisplayName ?? hbObj.Identifier; name.TextBinding.Bind(() => hbObj.DisplayName, (v) => hbObj.DisplayName = v); panel.AddRow("Name", name); foreach (var item in properties) { if (item.Name == "Identifier" || item.Name == "Type" || item.Name == "DisplayName") { continue; } var value = item.GetValue(hbObj); var type = item.PropertyType; if (value is string stringvalue) { var textBox = new TextBox(); //textBox.Text = stringvalue; textBox.TextBinding.Bind(() => stringvalue, (v) => item.SetValue(hbObj, v)); panel.AddRow(item.Name, textBox); } else if (value is double numberValue) { var numberTB = new MaskedTextBox(); numberTB.Provider = new NumericMaskedTextProvider() { AllowDecimal = true }; numberTB.TextBinding.Bind(() => numberValue.ToString(), (v) => item.SetValue(hbObj, Convert.ChangeType(v, type))); panel.AddRow(item.Name, numberTB); } else if (value is int intValue) { var numberTB = new NumericStepper(); numberTB.DecimalPlaces = 0; numberTB.Value = intValue; panel.AddRow(item.Name, numberTB); } else if (Nullable.GetUnderlyingType(type) != null) { var enumType = Nullable.GetUnderlyingType(type); if (!enumType.IsEnum) { continue; } var values = Enum.GetNames(enumType).ToList(); var dropdown = new DropDown(); var dropDownItems = values.Select(_ => new ListItem() { Text = _, Key = _ }); dropdown.Items.AddRange(dropDownItems); var currentValue = item.GetValue(hbObj, null).ToString(); dropdown.SelectedKeyBinding.Bind( () => currentValue, (v) => item.SetValue(hbObj, Enum.Parse(enumType, v)) ); panel.AddRow(item.Name, dropdown); } else if (type.IsEnum) { var values = Enum.GetNames(type).ToList(); var dropdown = new DropDown(); var dropDownItems = values.Select(_ => new ListItem() { Text = _, Key = _ }); dropdown.Items.AddRange(dropDownItems); var currentValue = item.GetValue(hbObj, null).ToString(); dropdown.SelectedKeyBinding.Bind( () => currentValue, (v) => item.SetValue(hbObj, Enum.Parse(type, v)) ); panel.AddRow(item.Name, dropdown); } } panel.AddRow(null, null); return(panel); }
public static void AddModifier(this ModelRadianceProperties modelRadianceCollection, ModifierBase modifier) { modelRadianceCollection.Modifiers = modelRadianceCollection.Modifiers ?? new List <AnyOf <Plastic, Glass, BSDF, Glow, Light, Trans, Metal, Void, Mirror> >(); var exist = modelRadianceCollection.Modifiers.OfType <ModifierBase>().Any(_ => _.Identifier == modifier.Identifier); if (exist) { return; } switch (modifier) { case Plastic obj: modelRadianceCollection.Modifiers.Add(obj); break; case Glass obj: modelRadianceCollection.Modifiers.Add(obj); break; case Trans obj: modelRadianceCollection.Modifiers.Add(obj); break; case Metal obj: modelRadianceCollection.Modifiers.Add(obj); break; case Mirror obj: modelRadianceCollection.Modifiers.Add(obj); break; case Glow obj: modelRadianceCollection.Modifiers.Add(obj); break; case Light obj: modelRadianceCollection.Modifiers.Add(obj); break; case BSDF obj: modelRadianceCollection.Modifiers.Add(obj); break; default: throw new ArgumentException($"{modifier.GetType()}({modifier.Identifier}) is not added to model"); } }