Exemple #1
0
        private static LinetypeSegment ReadLineTypeComplexSegment(string data, double length)
        {
            // the data is enclosed in brackets
            if (data[0] != '[' || data[data.Length - 1] != ']')
            {
                return(null);
            }

            // the first data item in a complex linetype definition segment
            // can be a shape name or a text string, the last always is enclosed in ""
            LinetypeSegmentType type = data[1] != '"' ? LinetypeSegmentType.Shape : LinetypeSegmentType.Text;

            data = data.Substring(1, data.Length - 2);

            string  name;
            string  style;
            Vector2 position = Vector2.Zero;
            LinetypeSegmentRotationType rotationType = LinetypeSegmentRotationType.Relative;
            double rotation = 0.0;
            double scale    = 0.1;

            string[] tokens = data.Split(',');

            // at least two items must be present the shape name and file
            if (tokens.Length < 2)
            {
                return(null);
            }
            name  = tokens[0].Trim('"');
            style = tokens[1];
            for (int i = 2; i < tokens.Length; i++)
            {
                string value = tokens[i].Remove(0, 2);
                if (tokens[i].StartsWith("X=", StringComparison.InvariantCultureIgnoreCase))
                {
                    double x;
                    if (double.TryParse(value, out x))
                    {
                        position.X = x;
                    }
                }
                else if (tokens[i].StartsWith("Y=", StringComparison.InvariantCultureIgnoreCase))
                {
                    double y;
                    if (double.TryParse(value, out y))
                    {
                        position.Y = y;
                    }
                }
                else if (tokens[i].StartsWith("S=", StringComparison.InvariantCultureIgnoreCase))
                {
                    double s;
                    if (double.TryParse(value, out s))
                    {
                        scale = s;
                    }
                    if (scale <= 0.0)
                    {
                        scale = 0.1;
                    }
                }
                else if (tokens[i].StartsWith("R=", StringComparison.InvariantCultureIgnoreCase))
                {
                    rotationType = LinetypeSegmentRotationType.Relative;
                    rotation     = ReadRotation(value);
                }
                else if (tokens[i].StartsWith("Q=", StringComparison.InvariantCultureIgnoreCase))
                {
                    rotationType = LinetypeSegmentRotationType.Absolute;
                    rotation     = ReadRotation(value);
                }
                else if (tokens[i].StartsWith("U=", StringComparison.InvariantCultureIgnoreCase))
                {
                    rotationType = LinetypeSegmentRotationType.Upright;
                    rotation     = ReadRotation(value);
                }
            }

            if (type == LinetypeSegmentType.Text)
            {
                TextStyle textStyle = new TextStyle(style);
                return(new LinetypeTextSegment(name, textStyle, length, position, rotationType, rotation, scale));
            }
            if (type == LinetypeSegmentType.Shape)
            {
                ShapeStyle shapeStyle = new ShapeStyle(style);
                return(new LinetypeShapeSegment(name, shapeStyle, length, position, rotationType, rotation, scale));
            }

            return(null);
        }
 /// <summary>
 /// Initializes a new instance of the <c>LinetypeSegment</c> class.
 /// </summary>
 /// <param name="type">Type of the linetype segment.</param>
 /// <param name="length">Dash or space length of the segment.</param>
 protected LinetypeSegment(LinetypeSegmentType type, double length)
 {
     this.type   = type;
     this.length = length;
 }
Exemple #3
0
        private static LinetypeSegment ReadLineTypeComplexSegment(string[] data, double length)
        {
            // the data is enclosed in brackets
            Debug.Assert(data[0][0] == '[' || data[data.Length - 1][data[data.Length - 1].Length - 1] == ']', "The data is enclosed in brackets.");

            // the first data item in a complex linetype definition segment
            // can be a shape name or a text string, the last always is enclosed in ""
            LinetypeSegmentType type = data[0][1] == '"' ? LinetypeSegmentType.Text : LinetypeSegmentType.Shape;

            // remove the start and end brackets
            data[0] = data[0].Remove(0, 1);
            data[data.Length - 1] = data[data.Length - 1].Remove(data[data.Length - 1].Length - 1, 1);

            Vector2 position = Vector2.Zero;
            LinetypeSegmentRotationType rotationType = LinetypeSegmentRotationType.Relative;
            double rotation = 0.0;
            double scale    = 0.1;

            // at least two items must be present the shape name and file
            if (data.Length < 2)
            {
                return(null);
            }

            string name  = data[0].Trim('"');
            string style = data[1];

            for (int i = 2; i < data.Length; i++)
            {
                string value = data[i].Remove(0, 2);
                if (data[i].StartsWith("X=", StringComparison.InvariantCultureIgnoreCase))
                {
                    position.X = double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
                }
                else if (data[i].StartsWith("Y=", StringComparison.InvariantCultureIgnoreCase))
                {
                    position.Y = double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
                }
                else if (data[i].StartsWith("S=", StringComparison.InvariantCultureIgnoreCase))
                {
                    scale = double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
                    if (scale <= 0.0)
                    {
                        scale = 0.1;
                    }
                }
                else if (data[i].StartsWith("A=", StringComparison.InvariantCultureIgnoreCase))
                {
                    rotationType = LinetypeSegmentRotationType.Absolute;
                    rotation     = ReadRotation(value);
                }
                else if (data[i].StartsWith("R=", StringComparison.InvariantCultureIgnoreCase))
                {
                    rotationType = LinetypeSegmentRotationType.Relative;
                    rotation     = ReadRotation(value);
                }
                else if (data[i].StartsWith("U=", StringComparison.InvariantCultureIgnoreCase))
                {
                    rotationType = LinetypeSegmentRotationType.Upright;
                    rotation     = ReadRotation(value);
                }
            }

            if (type == LinetypeSegmentType.Text)
            {
                // complex text linetype segments only holds the name of the style
                TextStyle textStyle = new TextStyle(style, "simplex.shx");
                return(new LinetypeTextSegment(name, textStyle, length, position, rotationType, rotation, scale));
            }
            if (type == LinetypeSegmentType.Shape)
            {
                ShapeStyle shapeStyle = new ShapeStyle(style);
                return(new LinetypeShapeSegment(name, shapeStyle, length, position, rotationType, rotation, scale));
            }

            return(null);
        }