示例#1
0
        private static DxfMText GetMText(DxfBufferReader <DxfEntity> buffer)
        {
            if (buffer.ItemsRemain)
            {
                var entity = buffer.Peek();
                if (entity.EntityType == DxfEntityType.MText)
                {
                    buffer.Advance();
                    return((DxfMText)entity);
                }
            }

            return(new DxfMText());
        }
示例#2
0
        private static DxfSeqend GetSeqend(DxfBufferReader <DxfEntity> buffer)
        {
            if (buffer.ItemsRemain)
            {
                var entity = buffer.Peek();
                if (entity.EntityType == DxfEntityType.Seqend)
                {
                    buffer.Advance();
                    return((DxfSeqend)entity);
                }
            }

            return(new DxfSeqend());
        }
示例#3
0
        internal static List<DxfEntity> GatherEntities(IEnumerable<DxfEntity> entities)
        {
            var buffer = new DxfBufferReader<DxfEntity>(entities, (e) => e == null);
            var result = new List<DxfEntity>();
            while (buffer.ItemsRemain)
            {
                var entity = buffer.Peek();
                buffer.Advance();
                switch (entity.EntityType)
                {
                    case DxfEntityType.Attribute:
                        var att = (DxfAttribute)entity;
                        att.MText = GetMText(buffer);
                        break;
                    case DxfEntityType.AttributeDefinition:
                        var attdef = (DxfAttributeDefinition)entity;
                        attdef.MText = GetMText(buffer);
                        break;
                    case DxfEntityType.Insert:
                        var insert = (DxfInsert)entity;
                        if (insert.HasAttributes)
                        {
                            var attribs = new List<DxfAttribute>();
                            while (buffer.ItemsRemain)
                            {
                                var nextAtt = GetNextAttribute(buffer);
                                if (nextAtt == null) break;
                                attribs.Add(nextAtt);
                            }

                            insert.Attributes.AddRange(attribs);
                            insert.Seqend = GetSeqend(buffer);
                        }

                        break;
                    case DxfEntityType.Polyline:
                        var poly = (DxfPolyline)entity;
                        var verts = CollectWhileType(buffer, DxfEntityType.Vertex).Cast<DxfVertex>();
                        poly.Vertices.AddRange(verts);
                        poly.Seqend = GetSeqend(buffer);
                        break;
                    default:
                        break;
                }

                result.Add(entity);
            }

            return result;
        }
示例#4
0
        private static DxfAttribute GetNextAttribute(DxfBufferReader <DxfEntity> buffer)
        {
            if (buffer.ItemsRemain)
            {
                var entity = buffer.Peek();
                if (entity.EntityType == DxfEntityType.Attribute)
                {
                    buffer.Advance();
                    var attribute = (DxfAttribute)entity;
                    attribute.MText = GetMText(buffer);
                    return(attribute);
                }
            }

            return(null);
        }
示例#5
0
        private static IEnumerable <DxfEntity> CollectWhileType(DxfBufferReader <DxfEntity> buffer, DxfEntityType type)
        {
            var result = new List <DxfEntity>();

            while (buffer.ItemsRemain)
            {
                var entity = buffer.Peek();
                if (entity.EntityType != type)
                {
                    break;
                }
                buffer.Advance();
                result.Add(entity);
            }

            return(result);
        }
示例#6
0
        private static List <DxfObject> GatherObjects(IEnumerable <DxfObject> objects)
        {
            var buffer = new DxfBufferReader <DxfObject>(objects, o => o == null);
            var result = new List <DxfObject>();
            var defaultObjectHandles = new HashSet <uint>();

            while (buffer.ItemsRemain)
            {
                var obj = buffer.Peek();
                buffer.Advance();
                switch (obj.ObjectType)
                {
                case DxfObjectType.DictionaryWithDefault:
                    var dict = (DxfDictionaryWithDefault)obj;
                    if (dict.DefaultObjectPointer.Handle != 0u)
                    {
                        defaultObjectHandles.Add(dict.DefaultObjectPointer.Handle);
                    }
                    break;

                default:
                    break;
                }

                result.Add(obj);
            }

            // trim default objects from the resultant list because they shouldn't be directly accessible
            for (int i = result.Count - 1; i >= 0; i--)
            {
                if (defaultObjectHandles.Contains(((IDxfItemInternal)result[i]).Handle))
                {
                    result.RemoveAt(i);
                }
            }

            return(result);
        }
示例#7
0
        internal static List <DxfEntity> GatherEntities(IEnumerable <DxfEntity> entities)
        {
            var buffer = new DxfBufferReader <DxfEntity>(entities, (e) => e == null);
            var result = new List <DxfEntity>();

            while (buffer.ItemsRemain)
            {
                var entity = buffer.Peek();
                buffer.Advance();
                switch (entity.EntityType)
                {
                case DxfEntityType.Attribute:
                    var att = (DxfAttribute)entity;
                    att.MText = GetMText(buffer);
                    SetOwner(att.MText, att);
                    break;

                case DxfEntityType.AttributeDefinition:
                    var attdef = (DxfAttributeDefinition)entity;
                    attdef.MText = GetMText(buffer);
                    SetOwner(attdef.MText, attdef);
                    break;

                case DxfEntityType.Insert:
                    var insert = (DxfInsert)entity;
                    if (insert.HasAttributes)
                    {
                        var attribs = new List <DxfAttribute>();
                        while (buffer.ItemsRemain)
                        {
                            var nextAtt = GetNextAttribute(buffer);
                            if (nextAtt == null)
                            {
                                break;
                            }
                            attribs.Add(nextAtt);
                        }

                        foreach (var attrib in attribs)
                        {
                            insert.Attributes.Add(attrib);
                            SetOwner(attrib, insert);
                        }

                        insert.Seqend = GetSeqend(buffer);
                        SetOwner(insert.Seqend, insert);
                    }

                    break;

                case DxfEntityType.Polyline:
                    var poly  = (DxfPolyline)entity;
                    var verts = CollectWhileType(buffer, DxfEntityType.Vertex).Cast <DxfVertex>();
                    foreach (var vert in verts)
                    {
                        poly.Vertices.Add(vert);
                        SetOwner(vert, poly);
                    }

                    poly.Seqend = GetSeqend(buffer);
                    SetOwner(poly.Seqend, poly);
                    break;

                default:
                    break;
                }

                result.Add(entity);
            }

            return(result);
        }
示例#8
0
        private static List<DxfObject> GatherObjects(IEnumerable<DxfObject> objects)
        {
            var buffer = new DxfBufferReader<DxfObject>(objects, o => o == null);
            var result = new List<DxfObject>();
            var defaultObjectHandles = new HashSet<uint>();
            while (buffer.ItemsRemain)
            {
                var obj = buffer.Peek();
                buffer.Advance();
                switch (obj.ObjectType)
                {
                    case DxfObjectType.DictionaryWithDefault:
                        var dict = (DxfDictionaryWithDefault)obj;
                        if (dict.DefaultObjectPointer.Handle != 0u)
                        {
                            defaultObjectHandles.Add(dict.DefaultObjectPointer.Handle);
                        }
                        break;
                    default:
                        break;
                }

                result.Add(obj);
            }

            // trim default objects from the resultant list because they shouldn't be directly accessible
            for (int i = result.Count - 1; i >= 0; i--)
            {
                if (defaultObjectHandles.Contains(((IDxfItemInternal)result[i]).Handle))
                {
                    result.RemoveAt(i);
                }
            }

            return result;
        }
示例#9
0
        private static DxfSeqend GetSeqend(DxfBufferReader<DxfEntity> buffer)
        {
            if (buffer.ItemsRemain)
            {
                var entity = buffer.Peek();
                if (entity.EntityType == DxfEntityType.Seqend)
                {
                    buffer.Advance();
                    return (DxfSeqend)entity;
                }
            }

            return new DxfSeqend();
        }
示例#10
0
        private static DxfAttribute GetNextAttribute(DxfBufferReader<DxfEntity> buffer)
        {
            if (buffer.ItemsRemain)
            {
                var entity = buffer.Peek();
                if (entity.EntityType == DxfEntityType.Attribute)
                {
                    buffer.Advance();
                    var attribute = (DxfAttribute)entity;
                    attribute.MText = GetMText(buffer);
                    return attribute;
                }
            }

            return null;
        }
示例#11
0
        private static DxfMText GetMText(DxfBufferReader<DxfEntity> buffer)
        {
            if (buffer.ItemsRemain)
            {
                var entity = buffer.Peek();
                if (entity.EntityType == DxfEntityType.MText)
                {
                    buffer.Advance();
                    return (DxfMText)entity;
                }
            }

            return new DxfMText();
        }
示例#12
0
        private static IEnumerable<DxfEntity> CollectWhileType(DxfBufferReader<DxfEntity> buffer, DxfEntityType type)
        {
            var result = new List<DxfEntity>();
            while (buffer.ItemsRemain)
            {
                var entity = buffer.Peek();
                if (entity.EntityType != type)
                    break;
                buffer.Advance();
                result.Add(entity);
            }

            return result;
        }