Exemplo n.º 1
0
        internal static DxfBlocksSection BlocksSectionFromBuffer(DxfCodePairBufferReader buffer)
        {
            var section = new DxfBlocksSection();

            section.Clear();
            while (buffer.ItemsRemain)
            {
                var pair = buffer.Peek();
                if (DxfCodePair.IsSectionStart(pair))
                {
                    // done reading blocks, onto the next section
                    break;
                }
                else if (DxfCodePair.IsSectionEnd(pair))
                {
                    // done reading blocks
                    buffer.Advance(); // swallow (0, ENDSEC)
                    break;
                }

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

                buffer.Advance(); // swallow (0, CLASS)
                var block = DxfBlock.FromBuffer(buffer);
                if (block != null)
                {
                    section.Blocks.Add(block);
                }
            }

            return(section);
        }
Exemplo n.º 2
0
        internal static DxfBlocksSection BlocksSectionFromBuffer(DxfCodePairBufferReader buffer, DxfAcadVersion version)
        {
            var section = new DxfBlocksSection();
            while (buffer.ItemsRemain)
            {
                var pair = buffer.Peek();
                if (DxfCodePair.IsSectionStart(pair))
                {
                    // done reading blocks, onto the next section
                    break;
                }
                else if (DxfCodePair.IsSectionEnd(pair))
                {
                    // done reading blocks
                    buffer.Advance(); // swallow (0, ENDSEC)
                    break;
                }

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

                buffer.Advance(); // swallow (0, CLASS)
                var block = DxfBlock.FromBuffer(buffer, version);
                if (block != null)
                {
                    section.Blocks.Add(block);
                }
            }

            return section;
        }
Exemplo 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);
        }