public BuildComponentFlyingGoose(string id, FabricStyle fabricStyleBody, FabricStyle fabricStyleCorner, Area area, bool trim)
            : base(id)
        {
            if (fabricStyleBody == null)
            {
                throw new ArgumentNullException(nameof(fabricStyleBody));
            }
            if (fabricStyleCorner == null)
            {
                throw new ArgumentNullException(nameof(fabricStyleCorner));
            }
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }

            if (area.Width < area.Height)
            {
                area = new Area(area.Height, area.Width);
            }

            m_area = area;

            m_fabricStyles = new FabricStyle[] { fabricStyleBody, fabricStyleCorner };

            m_trim = trim;

            m_styleKey = CreateStyleKey(fabricStyleBody, fabricStyleCorner, area);

            var halfSquareTriangleNode1 = new HalfSquareTriangleLayoutNode();

            halfSquareTriangleNode1.LayoutSites[0].Node = new TriangleShapeNode(fabricStyleCorner);
            halfSquareTriangleNode1.LayoutSites[1].Node = new TriangleShapeNode(fabricStyleBody);

            var halfSquareTriangleNode2 = new HalfSquareTriangleLayoutNode();

            halfSquareTriangleNode2.LayoutSites[0].Node = new TriangleShapeNode(fabricStyleCorner);
            halfSquareTriangleNode2.LayoutSites[1].Node = new TriangleShapeNode(fabricStyleBody);

            var gridLayoutNode = new GridLayoutNode(1, 2);

            gridLayoutNode.GetLayoutSite(0, 0).Node = halfSquareTriangleNode1;
            gridLayoutNode.GetLayoutSite(0, 1).Node = halfSquareTriangleNode2;
            gridLayoutNode.GetLayoutSite(0, 1).PathOrientation.PointOffset = 3;

            var scale = DimensionScale.CreateIdentity(area.Width.Unit);

            gridLayoutNode.UpdatePath(PathGeometries.Rectangle.CreatePath(area.Width, area.Height), PathOrientation.CreateDefault(), scale);

            m_gridLayoutNode = gridLayoutNode;
        }
示例#2
0
        private static Node CreateNode(Pattern <Patches> pattern)
        {
            int rowCount    = pattern.RowCount;
            int columnCount = pattern.ColumnCount;

            GridLayoutNode gridLayoutNode = new GridLayoutNode(rowCount, columnCount);

            for (int row = 0; row < rowCount; ++row)
            {
                for (int column = 0; column < columnCount; ++column)
                {
                    var node = (pattern.Values[row, column]) switch
                    {
                        Patches.Rectangle1 => new RectangleShapeNode(FabricStyle.Default)
                        {
                            Style = RectangleStyle1
                        },

                        Patches.Rectangle2 => new RectangleShapeNode(FabricStyle.Default)
                        {
                            Style = RectangleStyle2
                        },

                        _ => throw new InvalidOperationException(string.Format("Unknown patch {0}", pattern.Values[row, column])),
                    };
                    var layoutSite = gridLayoutNode.GetLayoutSite(row, column);
                    layoutSite.Node = node;
                }
            }

            return(gridLayoutNode.GetSimplified());
        }
示例#3
0
        public Node Create(Component component, NodeList childNodes)
        {
            if (component == null)
            {
                throw new ArgumentNullException(nameof(component));
            }

            if (component.Type != LayoutComponent.TypeName)
            {
                return(null);
            }
            if (component.Category != Constants.DefaultComponentCategory)
            {
                return(null);
            }

            var rowCount    = int.Parse(component.Parameters["RowCount"]);
            var columnCount = int.Parse(component.Parameters["ColumnCount"]);

            var layoutStyle = GetLayoutStyle(component.Name, rowCount, columnCount);

            var gridLayout = new GridLayoutNode(rowCount, columnCount)
            {
                ComponentType = component.Type,
                ComponentName = component.Name
            };

            for (var row = 0; row < gridLayout.RowCount; ++row)
            {
                for (var column = 0; column < gridLayout.ColumnCount; ++column)
                {
                    var colorIndex = layoutStyle[row, column];

                    var layoutSite = gridLayout.GetLayoutSite(row, column);
                    layoutSite.Style = colorIndex.ToString();

                    if (childNodes != null && childNodes.Count > 0)
                    {
                        var childNode = childNodes[colorIndex % childNodes.Count].Clone();
                        layoutSite.Node = childNode;
                    }
                }
            }

            return(gridLayout);
        }
示例#4
0
        public static Node Parse(IList <string> lines)
        {
            int size       = int.Parse(lines[0]);
            int styleCount = int.Parse(lines[1]);

            var patternLineOffset = 2;
            var styleLineOffset   = patternLineOffset + size;

            var gridLayout = new GridLayoutNode(size, size);

            for (int column = 0; column < size; ++column)
            {
                for (int row = 0; row < size; ++row)
                {
                    var cellDefinition  = lines[row + patternLineOffset].Substring(column, 1);
                    var styleDefinition = lines[row + styleLineOffset].Substring(column * styleCount, styleCount);

                    var layoutSite = gridLayout.GetLayoutSite(row, column);
                    PopulateLayoutSite(layoutSite, cellDefinition, styleDefinition);
                }
            }

            return(gridLayout);
        }
示例#5
0
        private void AddGridInputs(BuildComponentFactory factory, GridLayoutNode grid, bool trimTriangles)
        {
            List <Tuple <int, int> > consumedNodes = new List <Tuple <int, int> >();

            for (int row = 0; row < grid.RowCount; ++row)
            {
                for (int column = 0; column < grid.ColumnCount; ++column)
                {
                    if (!consumedNodes.Exists(r => r.Item1 == row && r.Item2 == column))
                    {
                        var layoutSite = grid.GetLayoutSite(row, column);
                        var columnSpan = grid.GetColumnSpan(row, column);
                        var rowSpan    = grid.GetRowSpan(row, column);

                        var fingerprint = GetFlyingGooseFingerprint(layoutSite.Node, layoutSite.PathOrientation.PointOffset);
                        if (fingerprint != null)
                        {
                            bool flyingGooseCreated = false;

                            LayoutSite layoutSiteRight = null; // Assume layout site does not exist.
                            if (column + columnSpan < grid.ColumnCount)
                            {
                                if (grid.GetLayoutSite(row, column + columnSpan).Node != null)
                                {
                                    if (grid.GetColumnSpan(row, column + columnSpan) == columnSpan &&
                                        grid.GetRowSpan(row, column + columnSpan) == rowSpan)
                                    {
                                        layoutSiteRight = grid.GetLayoutSite(row, column + columnSpan);
                                    }
                                }
                            }

                            if (layoutSiteRight != null)
                            {
                                var matchingRightFingerprint = GetFlyingGooseMatchingHorizontalFingerprint(layoutSite.Node, layoutSite.PathOrientation.PointOffset);

                                var rightFingerprint = GetFlyingGooseFingerprint(layoutSiteRight.Node, layoutSiteRight.PathOrientation.PointOffset);

                                if (rightFingerprint == matchingRightFingerprint)
                                {
                                    var halfSquareTriangle = (HalfSquareTriangleLayoutNode)layoutSite.Node;

                                    FabricStyle fabricStyleBody;
                                    FabricStyle fabricStyleCorner;
                                    switch (layoutSite.PathOrientation.PointOffset)
                                    {
                                    case 0:
                                    case 1:
                                        fabricStyleCorner = ((ShapeNode)halfSquareTriangle.LayoutSites[0].Node).FabricStyle;
                                        fabricStyleBody   = ((ShapeNode)halfSquareTriangle.LayoutSites[1].Node).FabricStyle;
                                        break;

                                    case 2:
                                    case 3:
                                        fabricStyleCorner = ((ShapeNode)halfSquareTriangle.LayoutSites[1].Node).FabricStyle;
                                        fabricStyleBody   = ((ShapeNode)halfSquareTriangle.LayoutSites[0].Node).FabricStyle;
                                        break;

                                    default:
                                        throw new InvalidOperationException("Unexpected point offset.");
                                    }

                                    var nodeBounds = halfSquareTriangle.Path.GetBounds();
                                    var width      = nodeBounds.MaximumX - nodeBounds.MinimumX;
                                    var height     = nodeBounds.MaximumY - nodeBounds.MinimumY;
                                    var area       = new Area(width * 2, height).Round();

                                    AddFlyingGooseInputs(factory, fabricStyleBody, fabricStyleCorner, area, trimTriangles);

                                    consumedNodes.Add(new Tuple <int, int>(row, column));
                                    consumedNodes.Add(new Tuple <int, int>(row, column + columnSpan));

                                    flyingGooseCreated = true;
                                }
                            }

                            LayoutSite layoutSiteDown = null; // Assume layout site does not exist.
                            if (row + rowSpan < grid.RowCount)
                            {
                                if (grid.GetLayoutSite(row + rowSpan, column).Node != null)
                                {
                                    if (grid.GetColumnSpan(row + rowSpan, column) == columnSpan &&
                                        grid.GetRowSpan(row + rowSpan, column) == rowSpan)
                                    {
                                        layoutSiteDown = grid.GetLayoutSite(row + rowSpan, column);
                                    }
                                }
                            }

                            if (!flyingGooseCreated && layoutSiteDown != null)
                            {
                                var matchingDownFingerprint = GetFlyingGooseMatchingVerticalFingerprint(layoutSite.Node, layoutSite.PathOrientation.PointOffset);

                                var downFingerprint = GetFlyingGooseFingerprint(layoutSiteDown.Node, layoutSiteDown.PathOrientation.PointOffset);

                                if (downFingerprint == matchingDownFingerprint)
                                {
                                    var halfSquareTriangle = (HalfSquareTriangleLayoutNode)layoutSite.Node;

                                    FabricStyle fabricStyleBody;
                                    FabricStyle fabricStyleCorner;
                                    switch (layoutSite.PathOrientation.PointOffset)
                                    {
                                    case 0:
                                    case 3:
                                        fabricStyleCorner = ((ShapeNode)halfSquareTriangle.LayoutSites[0].Node).FabricStyle;
                                        fabricStyleBody   = ((ShapeNode)halfSquareTriangle.LayoutSites[1].Node).FabricStyle;
                                        break;

                                    case 1:
                                    case 2:
                                        fabricStyleCorner = ((ShapeNode)halfSquareTriangle.LayoutSites[1].Node).FabricStyle;
                                        fabricStyleBody   = ((ShapeNode)halfSquareTriangle.LayoutSites[0].Node).FabricStyle;
                                        break;

                                    default:
                                        throw new InvalidOperationException("Unexpected point offset.");
                                    }

                                    var nodeBounds = halfSquareTriangle.Path.GetBounds();
                                    var width      = nodeBounds.MaximumX - nodeBounds.MinimumX;
                                    var height     = nodeBounds.MaximumY - nodeBounds.MinimumY;
                                    var area       = new Area(width * 2, height).Round();

                                    AddFlyingGooseInputs(factory, fabricStyleBody, fabricStyleCorner, area, trimTriangles);

                                    consumedNodes.Add(new Tuple <int, int>(row, column));
                                    consumedNodes.Add(new Tuple <int, int>(row + rowSpan, column));
                                }
                            }
                        }
                    }
                }
            }

            for (int row = 0; row < grid.RowCount; ++row)
            {
                for (int column = 0; column < grid.ColumnCount; ++column)
                {
                    if (!consumedNodes.Exists(r => r.Item1 == row && r.Item2 == column))
                    {
                        var child = grid.GetLayoutSite(row, column).Node;
                        if (child != null)
                        {
                            AddNodeInputs(factory, child, trimTriangles);
                        }
                    }
                }
            }
        }
示例#6
0
        private static Node CreateNode(Pattern <Patches> pattern)
        {
            int rowCount    = pattern.RowCount;
            int columnCount = pattern.ColumnCount;

            GridLayoutNode gridLayoutNode = new GridLayoutNode(rowCount * 2, columnCount * 2);

            Styles styles = new Styles();

            for (int row = 0; row < rowCount; ++row)
            {
                for (int column = 0; column < columnCount; ++column)
                {
                    var layoutRow    = row * 2;
                    var layoutColumn = column * 2;

                    switch (pattern.Values[row, column])
                    {
                    case Patches.Rectangle1:
                    {
                        var layoutSite = gridLayoutNode.GetLayoutSite(layoutRow, layoutColumn);
                        gridLayoutNode.SetRowSpan(layoutRow, layoutColumn, 2);
                        gridLayoutNode.SetColumnSpan(layoutRow, layoutColumn, 2);

                        layoutSite.Node = CreateRectangleNode(styles.Rectangle1Style);
                    }
                    break;

                    case Patches.Rectangle2:
                    {
                        var layoutSite = gridLayoutNode.GetLayoutSite(layoutRow, layoutColumn);
                        gridLayoutNode.SetRowSpan(layoutRow, layoutColumn, 2);
                        gridLayoutNode.SetColumnSpan(layoutRow, layoutColumn, 2);

                        layoutSite.Node = CreateRectangleNode(styles.Rectangle2Style);
                    }
                    break;

                    case Patches.HalfSquareTriangle:
                    {
                        var layoutSite = gridLayoutNode.GetLayoutSite(layoutRow, layoutColumn);
                        gridLayoutNode.SetRowSpan(layoutRow, layoutColumn, 2);
                        gridLayoutNode.SetColumnSpan(layoutRow, layoutColumn, 2);

                        layoutSite.Node = CreateHalfSquareTriangleNode(styles.HalfSquareTriangleStyle1, styles.HalfSquareTriangleStyle2);
                    }
                    break;

                    case Patches.HalfSquareTriangle90:
                    {
                        var layoutSite = gridLayoutNode.GetLayoutSite(layoutRow, layoutColumn);
                        gridLayoutNode.SetRowSpan(layoutRow, layoutColumn, 2);
                        gridLayoutNode.SetColumnSpan(layoutRow, layoutColumn, 2);

                        layoutSite.Node = CreateHalfSquareTriangleNode(styles.HalfSquareTriangleStyle1, styles.HalfSquareTriangleStyle2);
                        layoutSite.PathOrientation.PointOffset = 3;
                    }
                    break;

                    case Patches.HalfSquareTriangle180:
                    {
                        var layoutSite = gridLayoutNode.GetLayoutSite(layoutRow, layoutColumn);
                        gridLayoutNode.SetRowSpan(layoutRow, layoutColumn, 2);
                        gridLayoutNode.SetColumnSpan(layoutRow, layoutColumn, 2);

                        layoutSite.Node = CreateHalfSquareTriangleNode(styles.HalfSquareTriangleStyle1, styles.HalfSquareTriangleStyle2);
                        layoutSite.PathOrientation.PointOffset = 2;
                    }
                    break;

                    case Patches.HalfSquareTriangle270:
                    {
                        var layoutSite = gridLayoutNode.GetLayoutSite(layoutRow, layoutColumn);
                        gridLayoutNode.SetRowSpan(layoutRow, layoutColumn, 2);
                        gridLayoutNode.SetColumnSpan(layoutRow, layoutColumn, 2);

                        layoutSite.Node = CreateHalfSquareTriangleNode(styles.HalfSquareTriangleStyle1, styles.HalfSquareTriangleStyle2);
                        layoutSite.PathOrientation.PointOffset = 1;
                    }
                    break;


                    case Patches.SplitRectangle:
                    {
                        // Left Patch
                        {
                            var layoutSite = gridLayoutNode.GetLayoutSite(layoutRow, layoutColumn);
                            gridLayoutNode.SetRowSpan(layoutRow, layoutColumn, 2);
                            layoutSite.Node = CreateRectangleNode(styles.SplitRectangleStyle1);
                        }

                        // Right Patch
                        {
                            var layoutSite = gridLayoutNode.GetLayoutSite(layoutRow, layoutColumn + 1);
                            gridLayoutNode.SetRowSpan(layoutRow, layoutColumn + 1, 2);
                            layoutSite.Node = CreateRectangleNode(styles.SplitRectangleStyle2);
                        }
                    }
                    break;

                    case Patches.SplitRectangle90:
                    {
                        // Top Patch
                        {
                            var layoutSite = gridLayoutNode.GetLayoutSite(layoutRow, layoutColumn);
                            gridLayoutNode.SetColumnSpan(layoutRow, layoutColumn, 2);
                            layoutSite.Node = CreateRectangleNode(styles.SplitRectangleStyle1);
                        }

                        // Bottom Patch
                        {
                            var layoutSite = gridLayoutNode.GetLayoutSite(layoutRow + 1, layoutColumn);
                            gridLayoutNode.SetColumnSpan(layoutRow + 1, layoutColumn, 2);
                            layoutSite.Node = CreateRectangleNode(styles.SplitRectangleStyle2);
                        }
                    }
                    break;

                    case Patches.SplitRectangle180:
                    {
                        // Right Patch
                        {
                            var layoutSite = gridLayoutNode.GetLayoutSite(layoutRow, layoutColumn + 1);
                            gridLayoutNode.SetRowSpan(layoutRow, layoutColumn + 1, 2);
                            layoutSite.Node = CreateRectangleNode(styles.SplitRectangleStyle1);
                        }

                        // Left Patch
                        {
                            var layoutSite = gridLayoutNode.GetLayoutSite(layoutRow, layoutColumn);
                            gridLayoutNode.SetRowSpan(layoutRow, layoutColumn, 2);
                            layoutSite.Node = CreateRectangleNode(styles.SplitRectangleStyle2);
                        }
                    }
                    break;

                    case Patches.SplitRectangle270:
                    {
                        // Bottom Patch
                        {
                            var layoutSite = gridLayoutNode.GetLayoutSite(layoutRow + 1, layoutColumn);
                            gridLayoutNode.SetColumnSpan(layoutRow + 1, layoutColumn, 2);
                            layoutSite.Node = CreateRectangleNode(styles.SplitRectangleStyle1);
                        }

                        // Top Patch
                        {
                            var layoutSite = gridLayoutNode.GetLayoutSite(layoutRow, layoutColumn);
                            gridLayoutNode.SetColumnSpan(layoutRow, layoutColumn, 2);
                            layoutSite.Node = CreateRectangleNode(styles.SplitRectangleStyle2);
                        }
                    }
                    break;

                    default:
                        throw new InvalidOperationException(string.Format("Unknown patch {0}", pattern.Values[row, column]));
                    }
                }
            }

            return(gridLayoutNode.GetSimplified());
        }