Ejemplo n.º 1
0
        internal static DxfObjectsSection ObjectsSectionFromBuffer(DxfCodePairBufferReader buffer)
        {
            var objects = new List<DxfObject>();
            objects.Clear();
            while (buffer.ItemsRemain)
            {
                var pair = buffer.Peek();
                if (DxfCodePair.IsSectionEnd(pair))
                {
                    // done reading objects
                    buffer.Advance(); // swallow (0, ENDSEC)
                    break;
                }

                if (pair.Code != 0)
                {
                    throw new DxfReadException("Expected new object.", pair);
                }

                var obj = DxfObject.FromBuffer(buffer);
                if (obj != null)
                {
                    objects.Add(obj);
                }
            }

            var section = new DxfObjectsSection();
            section.Objects.AddRange(objects);
            return section;
        }
Ejemplo n.º 2
0
        internal static DxfObjectsSection ObjectsSectionFromBuffer(DxfCodePairBufferReader buffer)
        {
            var objects = new List <DxfObject>();

            objects.Clear();
            while (buffer.ItemsRemain)
            {
                var pair = buffer.Peek();
                if (DxfCodePair.IsSectionEnd(pair))
                {
                    // done reading objects
                    buffer.Advance(); // swallow (0, ENDSEC)
                    break;
                }

                if (pair.Code != 0)
                {
                    throw new DxfReadException("Expected new object.", pair);
                }

                var obj = DxfObject.FromBuffer(buffer);
                if (obj != null)
                {
                    objects.Add(obj);
                }
            }

            var section = new DxfObjectsSection();

            section.Objects.AddRange(objects);
            return(section);
        }
Ejemplo n.º 3
0
        internal static DxfSection FromBuffer(DxfCodePairBufferReader buffer, DxfAcadVersion version)
        {
            Debug.Assert(buffer.ItemsRemain);
            var sectionType = buffer.Peek();

            buffer.Advance();
            if (sectionType.Code != 2)
            {
                throw new DxfReadException($"Expected code 2, got {sectionType.Code}", sectionType);
            }

            DxfSection section;

            switch (sectionType.StringValue)
            {
            case BlocksSectionText:
                section = DxfBlocksSection.BlocksSectionFromBuffer(buffer, version);
                break;

            case ClassesSectionText:
                section = DxfClassesSection.ClassesSectionFromBuffer(buffer, version);
                break;

            case EntitiesSectionText:
                section = DxfEntitiesSection.EntitiesSectionFromBuffer(buffer);
                break;

            case HeaderSectionText:
                section = DxfHeaderSection.HeaderSectionFromBuffer(buffer);
                break;

            case ObjectsSectionText:
                section = DxfObjectsSection.ObjectsSectionFromBuffer(buffer);
                break;

            case TablesSectionText:
                section = DxfTablesSection.TablesSectionFromBuffer(buffer);
                break;

            case ThumbnailImageSectionText:
                section = DxfThumbnailImageSection.ThumbnailImageSectionFromBuffer(buffer);
                break;

            default:
                SwallowSection(buffer);
                section = null;
                break;
            }

            return(section);
        }