/// <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 <Curve> shapeCrvs = new List <Curve>(); List <System.Drawing.Color> fillCol = new List <System.Drawing.Color>(); List <double> strokeWeights = new List <double>(); List <System.Drawing.Color> strokeCol = new List <System.Drawing.Color>(); double scale = 1.0; int width = 0; int height = 0; bool hasFill = DA.GetDataList <System.Drawing.Color>("Fill Color", fillCol); bool hasWeight = DA.GetDataList <double>("Stroke Weight", strokeWeights); bool hasStrokeCol = DA.GetDataList <System.Drawing.Color>("Stroke Color", strokeCol); DA.GetData <double>("Scale", ref scale); if (!DA.GetDataList <Curve>("Shapes", shapeCrvs)) { return; } //Set up a grid to contain all shapes ClickableShapeGrid G = new ClickableShapeGrid(); G.clickMode = clickMode; if (DA.GetData <int>("Width", ref width)) { G.Width = width; } if (DA.GetData <int>("Height", ref height)) { G.Height = height; } int i = 0; //For all the curves the user inputs foreach (Curve c in shapeCrvs) { //Set up a new path object Path path = new Path(); //create a list to contain the single curve List <Curve> crvList = new List <Curve>(); crvList.Add(c); //Set the path's data to the curve path.Data = CreateShape_Component.pathGeomFromCrvs(crvList, scale, false); //set all the properties if (hasFill) { path.Fill = new SolidColorBrush(HUI_Util.ToMediaColor(fillCol[i % fillCol.Count])); } if (hasWeight) { path.StrokeThickness = strokeWeights[i % strokeWeights.Count]; } if (hasStrokeCol) { path.Stroke = new SolidColorBrush(HUI_Util.ToMediaColor(strokeCol[i % strokeCol.Count])); } i++; //add the path object to the grid G.Children.Add(path); } //Pass out the grid DA.SetData("Shape", new UIElement_Goo(G, "Shape", 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) { //placeholder variable to hold the generic element object object ShapeObject = null; if (!DA.GetData <object>("Shape to Modify", ref ShapeObject)) { return; } //Get grid container out of generic object ClickableShapeGrid G = HUI_Util.GetUIElement <ClickableShapeGrid>(ShapeObject); List <bool> oldStates = new List <bool>(G.SelectedStates.ToArray()); //change the shape if (G != null) { List <Curve> shapeCrvs = new List <Curve>(); List <System.Drawing.Color> fillCol = new List <System.Drawing.Color>(); List <double> strokeWeights = new List <double>(); List <System.Drawing.Color> strokeCol = new List <System.Drawing.Color>(); double scale = 1.0; int width = 0; int height = 0; Path oldpath = getPath(G.Children); bool hasWeight = false; bool hasStrokeCol = false; bool hasFill = false; DA.GetData <double>("Scale", ref scale); //Populate variables and store boolean results for later use. hasFill = DA.GetDataList <System.Drawing.Color>("Fill Colors", fillCol); hasWeight = DA.GetDataList <double>("Stroke Weights", strokeWeights); hasStrokeCol = DA.GetDataList <System.Drawing.Color>("Stroke Colors", strokeCol); //If the user has specified new shapes: if (DA.GetDataList <Curve>("Shape Curves", shapeCrvs)) { //G.Children.Clear(); //remove all shape children var itemsToRemove = G.Children.OfType <FrameworkElement>() .Where(c => (c is Shape)).ToList(); itemsToRemove .ForEach(g => G.Children.Remove(g)); int i = 0; //for all the curves foreach (Curve c in shapeCrvs) { Path path = new Path(); List <Curve> crvList = new List <Curve>(); //We're passing a single curve as a list so that the multiple curves are not interpreted as "composite" - //and therefore would be unable to be styled separately. crvList.Add(c); // Get Geometry from rhino curve objects. Note that "rebase" is set to false - so that relative position of // multiple curves is preserved. This is the primary difference with the setShape component (as well as list access) path.Data = Components.UI_Elements.CreateShape_Component.pathGeomFromCrvs(crvList, scale, false); if (hasFill) { path.Fill = new SolidColorBrush(HUI_Util.ToMediaColor(fillCol[i % fillCol.Count])); //hacky fix to approximate longest list matching } else { path.Fill = oldpath.Fill; } if (hasWeight) { path.StrokeThickness = strokeWeights[i % strokeWeights.Count]; //hacky fix to approximate longest list matching } else { path.StrokeThickness = oldpath.StrokeThickness; } if (hasStrokeCol) { path.Stroke = new SolidColorBrush(HUI_Util.ToMediaColor(strokeCol[i % strokeCol.Count])); //hacky fix to approximate longest list matching } else { path.Stroke = oldpath.Stroke; } i++; //Add the new path to the Grid G.Children.Add(path); } } //If the user has specified new dimensions for the container, update its dimensions, otherwise use the old ones. if (DA.GetData <int>("Width", ref width)) { G.Width = width; } else { G.Width = oldpath.Width; } if (DA.GetData <int>("Height", ref height)) { G.Height = height; } else { G.Height = oldpath.Height; } } if (G.Children.Count == oldStates.Count && G.clickMode == ClickableShapeGrid.ClickMode.ToggleMode) { G.SelectedStates = oldStates; G.UpdateAppearance(); } }