Beispiel #1
0
        public override TableObject Clone(string newName)
        {
            ShapeStyle copy = new ShapeStyle(newName, this.file, this.size, this.widthFactor, this.obliqueAngle);

            foreach (XData data in this.XData.Values)
            {
                copy.XData.Add((XData)data.Clone());
            }

            return(copy);
        }
Beispiel #2
0
 public LinetypeShapeSegment(string name, ShapeStyle style, double length, Vector2 offset, LinetypeSegmentRotationType rotationType, double rotation, double scale) : base(LinetypeSegmentType.Shape, length)
 {
     if (string.IsNullOrEmpty(name))
     {
         throw new ArgumentNullException(nameof(name), "The linetype shape name should be at least one character long.");
     }
     this.name = name;
     if (style == null)
     {
         throw new ArgumentNullException(nameof(style));
     }
     this.style        = style;
     this.offset       = offset;
     this.rotationType = rotationType;
     this.rotation     = MathHelper.NormalizeAngle(rotation);
     if (scale <= 0)
     {
         throw new ArgumentOutOfRangeException(nameof(scale), scale, "The LinetypeShepeSegment scale must be greater than zero.");
     }
     this.scale = scale;
 }
Beispiel #3
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);
        }
Beispiel #4
0
 public LinetypeShapeSegment(string name, ShapeStyle style, double length) : this(name, style, length, Vector2.Zero, LinetypeSegmentRotationType.Relative, 0.0, 1.0)
 {
 }