Ejemplo n.º 1
0
        protected virtual void OnLinetypeSegmentRemovedEvent(LinetypeSegment item)
        {
            LinetypeSegmentRemovedEventHandler ae = this.LinetypeSegmentRemoved;

            if (ae != null)
            {
                ae(this, new LinetypeSegmentChangeEventArgs(item));
            }
        }
Ejemplo n.º 2
0
        public static Linetype Load(string file, string linetypeName)
        {
            Linetype linetype = null;
            List <LinetypeSegment> segments = new List <LinetypeSegment>();

            using (StreamReader reader = new StreamReader(File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), true))
            {
                while (!reader.EndOfStream)
                {
                    string line = reader.ReadLine();
                    if (line == null)
                    {
                        throw new FileLoadException("Unknown error reading LIN file.", file);
                    }
                    // lines starting with semicolons are comments
                    if (line.StartsWith(";"))
                    {
                        continue;
                    }
                    // every line type definition starts with '*'
                    if (!line.StartsWith("*"))
                    {
                        continue;
                    }

                    // reading line type name and description
                    int    endName     = line.IndexOf(','); // the first semicolon divides the name from the description that might contain more semicolons
                    string name        = line.Substring(1, endName - 1);
                    string description = line.Substring(endName + 1, line.Length - endName - 1);

                    // remove start and end spaces
                    description = description.Trim();

                    if (name.Equals(linetypeName, StringComparison.OrdinalIgnoreCase))
                    {
                        // we have found the line type name, the next line of the file contains the line type definition
                        line = reader.ReadLine();
                        if (line == null)
                        {
                            throw new FileLoadException("Unknown error reading LIN file.", file);
                        }

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

                        // the index 0 is always A (alignment field)
                        for (int i = 1; i < tokens.Length; i++)
                        {
                            double length;
                            if (double.TryParse(tokens[i], out length))
                            {
                                // is the length followed by a shape o text segment
                                if (i + 1 < tokens.Length)
                                {
                                    if (tokens[i + 1].StartsWith("[", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        StringBuilder data = new StringBuilder();
                                        // there are two kinds of complex linetype Text and Shape,
                                        // the data is enclosed in brackets
                                        bool end = false;
                                        while (!end)
                                        {
                                            data.Append(tokens[++i]);
                                            data.Append(",");
                                            if (i >= tokens.Length)
                                            {
                                                return(null); // text and shape data must be enclosed by brackets
                                            }
                                            if (tokens[i].EndsWith("]"))
                                            {
                                                data.Append(tokens[i]);
                                                end = true;
                                            }
                                        }
                                        LinetypeSegment segment = ReadLineTypeComplexSegment(data.ToString(), length);
                                        if (segment != null)
                                        {
                                            segments.Add(segment);
                                        }
                                    }
                                    else
                                    {
                                        segments.Add(new LinetypeSimpleSegment(length));
                                    }
                                }
                                else
                                {
                                    segments.Add(new LinetypeSimpleSegment(length));
                                }
                            }
                            else
                            {
                                throw new FormatException("The linetype definition is not well formatted.");
                            }
                        }
                        linetype = new Linetype(name, segments, description);
                        break;
                    }
                }
            }
            return(linetype);
        }
Ejemplo n.º 3
0
 public LinetypeSegmentChangeEventArgs(LinetypeSegment item)
 {
     this.item = item;
 }