Exemple #1
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);
        }
Exemple #2
0
        internal static DxfTablesSection TablesSectionFromBuffer(DxfCodePairBufferReader buffer)
        {
            var section = new DxfTablesSection();
            while (buffer.ItemsRemain)
            {
                var pair = buffer.Peek();
                buffer.Advance();
                if (DxfCodePair.IsSectionEnd(pair))
                {
                    break;
                }

                if (!IsTableStart(pair))
                {
                    throw new DxfReadException("Expected start of table.", pair);
                }

                var table = DxfTable.FromBuffer(buffer);
                if (table != null)
                {
                    switch (table.TableType)
                    {
                        case DxfTableType.AppId:
                            section.AppIdTable = (DxfAppIdTable)table;
                            break;
                        case DxfTableType.BlockRecord:
                            section.BlockRecordTable = (DxfBlockRecordTable)table;
                            break;
                        case DxfTableType.DimStyle:
                            section.DimStyleTable = (DxfDimStyleTable)table;
                            break;
                        case DxfTableType.Layer:
                            section.LayerTable = (DxfLayerTable)table;
                            break;
                        case DxfTableType.LType:
                            section.LTypeTable = (DxfLTypeTable)table;
                            break;
                        case DxfTableType.Style:
                            section.StyleTable = (DxfStyleTable)table;
                            break;
                        case DxfTableType.Ucs:
                            section.UcsTable = (DxfUcsTable)table;
                            break;
                        case DxfTableType.View:
                            section.ViewTable = (DxfViewTable)table;
                            break;
                        case DxfTableType.ViewPort:
                            section.ViewPortTable = (DxfViewPortTable)table;
                            break;
                        default:
                            throw new DxfReadException($"Unexpected table type {table.TableType}", pair);
                    }
                }
            }

            return section;
        }
        internal static DxfTablesSection TablesSectionFromBuffer(DxfCodePairBufferReader buffer)
        {
            var section = new DxfTablesSection();

            section.Clear();
            while (buffer.ItemsRemain)
            {
                var pair = buffer.Peek();
                buffer.Advance();
                if (DxfCodePair.IsSectionEnd(pair))
                {
                    break;
                }

                if (!IsTableStart(pair))
                {
                    throw new DxfReadException("Expected start of table.", pair);
                }

                var table = DxfTable.FromBuffer(buffer);
                if (table != null)
                {
                    switch (table.TableType)
                    {
                    case DxfTableType.AppId:
                        section.AppIdTable = (DxfAppIdTable)table;
                        break;

                    case DxfTableType.BlockRecord:
                        section.BlockRecordTable = (DxfBlockRecordTable)table;
                        break;

                    case DxfTableType.DimStyle:
                        section.DimStyleTable = (DxfDimStyleTable)table;
                        break;

                    case DxfTableType.Layer:
                        section.LayerTable = (DxfLayerTable)table;
                        break;

                    case DxfTableType.LType:
                        section.LTypeTable = (DxfLTypeTable)table;
                        break;

                    case DxfTableType.Style:
                        section.StyleTable = (DxfStyleTable)table;
                        break;

                    case DxfTableType.Ucs:
                        section.UcsTable = (DxfUcsTable)table;
                        break;

                    case DxfTableType.View:
                        section.ViewTable = (DxfViewTable)table;
                        break;

                    case DxfTableType.ViewPort:
                        section.ViewPortTable = (DxfViewPortTable)table;
                        break;

                    default:
                        throw new DxfReadException($"Unexpected table type {table.TableType}", pair);
                    }
                }
            }

            return(section);
        }