/// <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 <GH_Gradient> gradients = new List <GH_Gradient>(); List <GH_Gradient> defaultGradient = new List <GH_Gradient>(); List <object> gradientObjects = new List <object>(); List <object> defaultGradientObjects = new List <object>(); bool showPresets = false; bool showEditor = true; DA.GetData("Show Presets", ref showPresets); DA.GetData("Show Editor", ref showEditor); DA.GetDataList("Gradient(s)", gradientObjects); DA.GetDataList("Default Gradient", defaultGradientObjects); var hasDefault = Params.Input[1].SourceCount > 0; ExtractGradients(gradients, gradientObjects); List <HUI_Gradient> presets = new List <HUI_Gradient>(); if (hasDefault) { ExtractGradients(defaultGradient, defaultGradientObjects, 1); presets.Add(HUI_Gradient.FromGHGradient(defaultGradient.First())); } foreach (GH_Gradient g in gradients) { //w/ addition of the default value, have to make sure we don't double add a gradient var gradientToAdd = HUI_Gradient.FromGHGradient(g); if (presets.Select(p => p.ToString()).Any(p => p.Contains(gradientToAdd.ToString()))) { continue; } presets.Add(gradientToAdd); } HUI_GradientEditor hge = new HUI_GradientEditor(showPresets, showEditor, presets); DA.SetData("Gradient Editor", new UIElement_Goo(hge, "Gradient Editor", InstanceGuid, DA.Iteration)); }
/// <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 <GH_Gradient> gradients = new List <GH_Gradient>(); List <object> gradientObjects = new List <object>(); bool showPresets = false; bool showEditor = true; DA.GetData("Show Presets", ref showPresets); DA.GetData("Show Editor", ref showEditor); DA.GetDataList("Gradient(s)", gradientObjects); if (gradientObjects.Count > 0 && gradientObjects[0] is GH_ObjectWrapper) { foreach (GH_ObjectWrapper wrapper in gradientObjects.OfType <GH_ObjectWrapper>()) { GH_GradientControl editor = wrapper.Value as GH_GradientControl; gradients.Add(editor.Gradient); } } else { var doc = OnPingDocument(); doc.Objects.OfType <GH_GradientControl>().Where(ao => Params.Input[0].DependsOn(ao)).ToList().ForEach(g => gradients.Add(g.Gradient)); } List <HUI_Gradient> presets = new List <HUI_Gradient>(); foreach (GH_Gradient g in gradients) { presets.Add(HUI_Gradient.FromGHGradient(g)); } HUI_GradientEditor hge = new HUI_GradientEditor(showPresets, showEditor, presets); DA.SetData("Gradient Editor", new UIElement_Goo(hge, "Gradient Editor", InstanceGuid, DA.Iteration)); }