示例#1
0
        /// <summary>
        /// Initializes this entity file object with the content of a file.
        /// </summary>
        /// <param name="sr">The file to read the definition from.</param>
        /// <returns>The number of translation blocks that were loaded.</returns>
        internal int Create(StreamReader sr)
        {
            // If we previously created stuff, get rid of it.
            ResetContents();

            // While we have not reached the end of file, search for a
            // record that contains the "BEGIN" keyword. As we find each
            // one, create an EntityBlock object, and ask it to load
            // the block.

            List <EntityBlock> blocks = new List <EntityBlock>();
            string             buf;

            while ((buf = sr.ReadLine()) != null)
            {
                // Trim off any leading and trailing whitespace.
                string str = buf.Trim();

                // Skip blank records.
                if (str.Length == 0)
                {
                    continue;
                }

                // If we have the BEGIN keyword, create an additional
                // EntityBlock object and load it.
                if (String.Compare(str, "BEGIN", true) == 0)
                {
                    try
                    {
                        EntityBlock block = new EntityBlock();
                        block.Create(sr);
                        blocks.Add(block);
                    }

                    catch { }
                }
            }

            // Return the number of translation blocks that we loaded.
            m_Blocks = blocks.ToArray();
            return(m_Blocks.Length);
        }
示例#2
0
        /// <summary>
        /// Tries to return the name of a derived entity type for a specific line.
        /// </summary>
        /// <param name="line">The line to process.</param>
        /// <param name="layer">The layer of interest (in the same address space as
        /// the map that contains the line).</param>
        /// <returns>The name of the derived entity type (null if not found).</returns>
        internal string GetDerivedType(IDivider line, ILayer layer)
        {
            // Return if the line does not have an entity type (it SHOULD do)
            IEntity ent = line.Line.EntityType;

            if (ent == null)
            {
                return(null);
            }

            // Get the translation block (if any) that refers to the line's entity type.
            string      entName = ent.Name;
            string      lyrName = layer.Name;
            EntityBlock block   = Array.Find <EntityBlock>(m_Blocks, eb => eb.IsMatch(entName, lyrName));

            // Return if the line's entity type is not associated with a translation.
            if (block == null)
            {
                return(null);
            }

            // Get the polygons on either side of the line (the REAL
            // user-perceived polygons, not phantoms).
            Polygon leftPol  = (line.Left == null ? null : line.Left.RealPolygon);
            Polygon rightPol = (line.Right == null ? null : line.Right.RealPolygon);

            // Get the entity types for the adjacent polygons (if any).
            IEntity leftEnt  = (leftPol == null ? null : leftPol.EntityType);
            IEntity rightEnt = (rightPol == null ? null : rightPol.EntityType);

            if (leftEnt != null || rightEnt != null)
            {
                string e1 = (leftEnt == null ? String.Empty : leftEnt.Name);
                string e2 = (rightEnt == null ? String.Empty : rightEnt.Name);

                return(block.GetDerivedType(e1, e2));
            }

            return(null);
        }
示例#3
0
        /// <summary>
        /// Initializes this entity file object with the content of a file.
        /// </summary>
        /// <param name="sr">The file to read the definition from.</param>
        /// <returns>The number of translation blocks that were loaded.</returns>
        internal int Create(StreamReader sr)
        {
            // If we previously created stuff, get rid of it.
            ResetContents();

            // While we have not reached the end of file, search for a
            // record that contains the "BEGIN" keyword. As we find each
            // one, create an EntityBlock object, and ask it to load
            // the block.

            List<EntityBlock> blocks = new List<EntityBlock>();
            string buf;

            while ((buf=sr.ReadLine())!=null)
            {
                // Trim off any leading and trailing whitespace.
                string str = buf.Trim();

                // Skip blank records.
                if (str.Length==0)
                    continue;

                // If we have the BEGIN keyword, create an additional
                // EntityBlock object and load it.
                if (String.Compare(str, "BEGIN", true)==0)
                {
                    try
                    {
                        EntityBlock block = new EntityBlock();
                        block.Create(sr);
                        blocks.Add(block);
                    }

                    catch { }
                }
            }

            // Return the number of translation blocks that we loaded.
            m_Blocks = blocks.ToArray();
            return m_Blocks.Length;
        }