예제 #1
0
파일: Item.cs 프로젝트: 15831944/Sheet
        public void Serialize(StringBuilder sb, BlockItem block, string indent, ItemSerializeOptions options)
        {
            sb.Append(indent);
            sb.Append("BLOCK");
            sb.Append(options.ModelSeparator);
            sb.Append(block.Id);
            sb.Append(options.ModelSeparator);
            sb.Append(block.X);
            sb.Append(options.ModelSeparator);
            sb.Append(block.Y);
            sb.Append(options.ModelSeparator);
            sb.Append(block.Name);
            sb.Append(options.ModelSeparator);
            sb.Append(block.Width);
            sb.Append(options.ModelSeparator);
            sb.Append(block.Height);
            sb.Append(options.ModelSeparator);
            Serialize(sb, block.Backgroud, options);
            sb.Append(options.ModelSeparator);
            sb.Append(block.DataId);
            sb.Append(options.LineSeparator);

            Serialize(sb, block.Points, indent + options.IndentWhiteSpace, options);
            Serialize(sb, block.Lines, indent + options.IndentWhiteSpace, options);
            Serialize(sb, block.Rectangles, indent + options.IndentWhiteSpace, options);
            Serialize(sb, block.Ellipses, indent + options.IndentWhiteSpace, options);
            Serialize(sb, block.Texts, indent + options.IndentWhiteSpace, options);
            Serialize(sb, block.Images, indent + options.IndentWhiteSpace, options);
            Serialize(sb, block.Blocks, indent + options.IndentWhiteSpace, options);

            sb.Append(indent);
            sb.Append("END");
            sb.Append(options.LineSeparator);
        }
예제 #2
0
파일: Item.cs 프로젝트: 15831944/Sheet
 public void Move(BlockItem block, double x, double y)
 {
     Move(block.Points, x, y);
     Move(block.Lines, x, y);
     Move(block.Rectangles, x, y);
     Move(block.Ellipses, x, y);
     Move(block.Texts, x, y);
     Move(block.Images, x, y);
     Move(block.Blocks, x, y);
 }
예제 #3
0
파일: Item.cs 프로젝트: 15831944/Sheet
 public void MinMax(BlockItem block, ref double minX, ref double minY, ref double maxX, ref double maxY)
 {
     MinMax(block.Points, ref minX, ref minY, ref maxX, ref maxY);
     MinMax(block.Lines, ref minX, ref minY, ref maxX, ref maxY);
     MinMax(block.Rectangles, ref minX, ref minY, ref maxX, ref maxY);
     MinMax(block.Ellipses, ref minX, ref minY, ref maxX, ref maxY);
     MinMax(block.Texts, ref minX, ref minY, ref maxX, ref maxY);
     MinMax(block.Images, ref minX, ref minY, ref maxX, ref maxY);
     MinMax(block.Blocks, ref minX, ref minY, ref maxX, ref maxY);
 }
예제 #4
0
파일: Item.cs 프로젝트: 15831944/Sheet
        public void ResetPosition(BlockItem block, double originX, double originY, double width, double height)
        {
            double minX = width;
            double minY = height;
            double maxX = originX;
            double maxY = originY;

            MinMax(block, ref minX, ref minY, ref maxX, ref maxY);
            double x = -(maxX - (maxX - minX));
            double y = -(maxY - (maxY - minY));

            Move(block, x, y);
        }
예제 #5
0
파일: Item.cs 프로젝트: 15831944/Sheet
        public string SerializeContents(BlockItem block, ItemSerializeOptions options)
        {
            var sb = new StringBuilder();

            Serialize(sb, block.Points, "", options);
            Serialize(sb, block.Lines, "", options);
            Serialize(sb, block.Rectangles, "", options);
            Serialize(sb, block.Ellipses, "", options);
            Serialize(sb, block.Texts, "", options);
            Serialize(sb, block.Images, "", options);
            Serialize(sb, block.Blocks, "", options);

            return(sb.ToString());
        }
예제 #6
0
파일: Item.cs 프로젝트: 15831944/Sheet
        private BlockItem DeserializeRootBlock(string[] lines, int length, ref int end, string name, int id, double x, double y, double width, double height, int dataId, ItemSerializeOptions options)
        {
            var root = new BlockItem(id, x, y, width, height, dataId, name, new ItemColor()
            {
                Alpha = 0, Red = 0, Green = 0, Blue = 0
            });

            for (; end < length; end++)
            {
                string line = lines[end].TrimStart(options.WhiteSpace);
                var    m    = line.Split(options.ModelSeparators);

                if (m.Length == 4 && string.Compare(m[0], "POINT", true) == 0)
                {
                    if (m.Length == 4)
                    {
                        var pointItem = DeserializePoint(m);
                        root.Points.Add(pointItem);
                    }
                    else
                    {
                        throw new Exception(string.Format("Invalid POINT item at line {0}", end + 1));
                    }
                }
                else if ((m.Length == 10 || m.Length == 12) && string.Compare(m[0], "LINE", true) == 0)
                {
                    if (m.Length == 10 || m.Length == 12)
                    {
                        var lineItem = DeserializeLine(m);
                        root.Lines.Add(lineItem);
                    }
                    else
                    {
                        throw new Exception(string.Format("Invalid LINE item at line {0}", end + 1));
                    }
                }
                else if (string.Compare(m[0], "RECTANGLE", true) == 0)
                {
                    if (m.Length == 15)
                    {
                        var rectangleItem = DeserializeRectangle(m);
                        root.Rectangles.Add(rectangleItem);
                    }
                    else
                    {
                        throw new Exception(string.Format("Invalid RECTANGLE item at line {0}", end + 1));
                    }
                }
                else if (string.Compare(m[0], "ELLIPSE", true) == 0)
                {
                    if (m.Length == 15)
                    {
                        var ellipseItem = DeserializeEllipse(m);
                        root.Ellipses.Add(ellipseItem);
                    }
                    else
                    {
                        throw new Exception(string.Format("Invalid ELLIPSE item at line {0}", end + 1));
                    }
                }
                else if (string.Compare(m[0], "TEXT", true) == 0)
                {
                    if (m.Length == 18)
                    {
                        var textItem = DeserializeText(m);
                        root.Texts.Add(textItem);
                    }
                    else
                    {
                        throw new Exception(string.Format("Invalid TEXT item at line {0}", end + 1));
                    }
                }
                else if (string.Compare(m[0], "IMAGE", true) == 0)
                {
                    if (m.Length == 7)
                    {
                        var imageItem = DeserializeImage(m);
                        root.Images.Add(imageItem);
                    }
                    else
                    {
                        throw new Exception(string.Format("Invalid IMAGE item at line {0}", end + 1));
                    }
                }
                else if (string.Compare(m[0], "BLOCK", true) == 0)
                {
                    if (m.Length == 12)
                    {
                        end++;
                        var blockItem = DeserializeBlockRecursive(lines, length, ref end, m, options);
                        root.Blocks.Add(blockItem);
                        continue;
                    }
                    else
                    {
                        throw new Exception(string.Format("Invalid BLOCK item at line {0}", end + 1));
                    }
                }
                else if (string.Compare(m[0], "END", true) == 0)
                {
                    if (m.Length == 1)
                    {
                        return(root);
                    }
                    else
                    {
                        throw new Exception(string.Format("Invalid END item at line {0}", end + 1));
                    }
                }
                else if (m[0].StartsWith("//"))
                {
                    continue;
                }
                else
                {
                    throw new Exception(string.Format("Invalid item at line {0}", end + 1));
                }
            }

            return(root);
        }
예제 #7
0
파일: Item.cs 프로젝트: 15831944/Sheet
 public string SerializeContents(BlockItem block)
 {
     return(SerializeContents(block, ItemSerializeOptions.Default));
 }