/// <summary> /// Construct a set of elements from this rule for a given definition. /// </summary> /// <param name="definition">The definition to instantiate.</param> public List <Element> Instantiate(ComponentDefinition definition) { var arrayElements = new List <Element>(); var newVertices = PolylinePlacementRule.TransformPolyline(this, definition); var path = new Polygon(newVertices); var grid2d = new Grid2d(path, definition.OrientationGuide); GridCreationRule(grid2d); var cells = grid2d.GetCells().Where(c => !c.IsTrimmed()).SelectMany(c => c.GetTrimmedCellGeometry()).OfType <Polygon>().Where(c => c.Area().ApproximatelyEquals(CellDefinition.CellLength * CellDefinition.CellWidth)); foreach (var element in CellDefinition.Elements) { foreach (var cell in cells) { var transform = new Transform(element.Transform); transform.Concatenate(definition.OrientationGuide); transform.Concatenate(new Transform(cell.Vertices[2])); element.IsElementDefinition = true; var instance = element.CreateInstance(transform, null); arrayElements.Add(instance); } } arrayElements.AddRange(cells.Select(c => new ModelCurve(c))); return(arrayElements); }
/// <summary> /// Construct a set of elements from this rule for a given definition. /// </summary> /// <param name="definition">The definition to instantiate.</param> public List <Element> Instantiate(ComponentDefinition definition) { var transformedVertices = PolylinePlacementRule.TransformPolyline(this, definition); var newVertices = AnchorTransformer == null ? transformedVertices : AnchorTransformer(transformedVertices); return(Component.Instantiate(newVertices).Instances); }
/// <summary> /// Construct a set of elements from this rule for a given definition. /// </summary> /// <param name="definition">The definition to instantiate.</param> public List <Element> Instantiate(ComponentDefinition definition) { var arrayElements = new List <Element>(); var newVertices = PolylinePlacementRule.TransformPolyline(this, definition); var path = IsClosed ? new Polygon(newVertices) : new Polyline(newVertices); var grid1d = new Grid1d(path); switch (SpacingRule.SpacingMode) { case SpacingMode.ByLength: grid1d.DivideByFixedLength(SpacingRule.Value); break; case SpacingMode.ByApproximateLength: grid1d.DivideByApproximateLength(SpacingRule.Value); break; case SpacingMode.ByCount: grid1d.DivideByCount((int)SpacingRule.Value); break; } var separators = grid1d.GetCellSeparators(); foreach (var sep in separators) { ElementDefinition.IsElementDefinition = true; var transform = new Transform(definition.OrientationGuide); transform.Concatenate(new Transform(sep)); var instance = ElementDefinition.CreateInstance(transform, Guid.NewGuid().ToString()); arrayElements.Add(instance); } return(arrayElements); }