Beispiel #1
0
            public void ApplyCodePairs(DxfCodePairBufferReader buffer)
            {
                var pair = buffer.Peek();

                buffer.Advance();
                switch (pair.Code)
                {
                case 5:
                    ((IDxfItemInternal)this).Handle = DxfCommonConverters.HandleString(pair.StringValue);
                    break;

                case 8:
                    // just a re-iteration of the layer
                    break;

                case 67:
                    // just a re-iteration of the paper space setting
                    break;

                case 100:
                    Debug.Assert(pair.StringValue == AcDbEntityText || pair.StringValue == AcDbBlockEndText);
                    break;

                case DxfCodePairGroup.GroupCodeNumber:
                    var groupName = DxfCodePairGroup.GetGroupName(pair.StringValue);
                    ExtensionDataGroups.Add(DxfCodePairGroup.FromBuffer(buffer, groupName));
                    break;
                }
            }
Beispiel #2
0
        internal override bool TrySetPair(DxfCodePair pair)
        {
            switch (pair.Code)
            {
            case 3:
                _lastEntryName = pair.StringValue;
                break;

            case 280:
                this.IsHardOwner = BoolShort(pair.ShortValue);
                break;

            case 281:
                this.DuplicateRecordHandling = (DxfDictionaryDuplicateRecordHandling)(pair.ShortValue);
                break;

            case 350:
            case 360:
                Debug.Assert(_lastEntryName != null);
                var handle = DxfCommonConverters.HandleString(pair.StringValue);
                _items[_lastEntryName] = new DxfPointer(handle);
                _lastEntryName         = null;
                break;

            default:
                return(base.TrySetPair(pair));
            }

            return(true);
        }
Beispiel #3
0
        public void HandleStringConversions(ulong ulongValue, string stringValue)
        {
            // parsing
            Assert.Equal(stringValue, DxfCommonConverters.HandleString(new DxfHandle(ulongValue)));

            // display
            Assert.Equal(new DxfHandle(ulongValue), DxfCommonConverters.HandleString(stringValue));
        }
Beispiel #4
0
        internal override DxfObject PopulateFromBuffer(DxfCodePairBufferReader buffer)
        {
            var isReadyForSortHandles = false;

            while (buffer.ItemsRemain)
            {
                var pair = buffer.Peek();
                if (pair.Code == 0)
                {
                    break;
                }

                while (this.TrySetExtensionData(pair, buffer))
                {
                    pair = buffer.Peek();
                }

                switch (pair.Code)
                {
                case 5:
                    if (isReadyForSortHandles)
                    {
                        SortItemsPointers.Pointers.Add(new DxfPointer(DxfCommonConverters.HandleString(pair.StringValue)));
                    }
                    else
                    {
                        ((IDxfItemInternal)this).Handle = DxfCommonConverters.HandleString(pair.StringValue);
                        isReadyForSortHandles           = true;
                    }
                    break;

                case 100:
                    isReadyForSortHandles = true;
                    break;

                case 330:
                    ((IDxfItemInternal)this).OwnerHandle = DxfCommonConverters.HandleString(pair.StringValue);
                    isReadyForSortHandles = true;
                    break;

                case 331:
                    EntitiesPointers.Pointers.Add(new DxfPointer(DxfCommonConverters.HandleString(pair.StringValue)));
                    isReadyForSortHandles = true;
                    break;

                default:
                    if (!base.TrySetPair(pair))
                    {
                        ExcessCodePairs.Add(pair);
                    }
                    break;
                }

                buffer.Advance();
            }

            return(PostParse());
        }
Beispiel #5
0
        internal static DxfXDataItem FromBuffer(DxfCodePairBufferReader buffer)
        {
            var pair = buffer.Peek();

            buffer.Advance();
            switch ((DxfXDataType)pair.Code)
            {
            case DxfXDataType.String:
                return(new DxfXDataString(pair.StringValue));

            case DxfXDataType.ControlString:
                return(DxfXDataItemList.ListFromBuffer(buffer));

            case DxfXDataType.Layer:
                return(new DxfXDataLayerName(pair.StringValue));

            case DxfXDataType.BinaryData:
                return(new DxfXDataBinaryData(DxfCommonConverters.HexBytes(pair.StringValue)));

            case DxfXDataType.Handle:
                return(new DxfXDataHandle(DxfCommonConverters.HandleString(pair.StringValue)));

            case DxfXDataType.RealTriple:
                return(new DxfXData3Reals(ReadPoint(pair, buffer, pair.Code)));

            case DxfXDataType.WorldSpacePosition:
                return(new DxfXDataWorldSpacePosition(ReadPoint(pair, buffer, pair.Code)));

            case DxfXDataType.WorldSpaceDisplacement:
                return(new DxfXDataWorldSpaceDisplacement(ReadPoint(pair, buffer, pair.Code)));

            case DxfXDataType.WorldDirection:
                return(new DxfXDataWorldDirection(ReadPoint(pair, buffer, pair.Code)));

            case DxfXDataType.Real:
                return(new DxfXDataReal(pair.DoubleValue));

            case DxfXDataType.Distance:
                return(new DxfXDataDistance(pair.DoubleValue));

            case DxfXDataType.ScaleFactor:
                return(new DxfXDataScaleFactor(pair.DoubleValue));

            case DxfXDataType.Integer:
                return(new DxfXDataInteger(pair.ShortValue));

            case DxfXDataType.Long:
                return(new DxfXDataLong(pair.IntegerValue));

            default:
                return(null);    // unexpected XDATA code pair
            }
        }
Beispiel #6
0
        public void AssignOwnerHandlesInXDataTest()
        {
            // read a layout with its owner handle also specified in the XDATA
            var file = Parse(
                (0, "SECTION"),
                (2, "HEADER"),
                (9, "$ACADVER"),
                (1, "AC1027"),
                (0, "ENDSEC"),
                (0, "SECTION"),
                (2, "OBJECTS"),
                (0, "DICTIONARY"),
                (5, "BBBBBBBB"),
                (3, "some-layout"),
                (350, "CCCCCCCC"),
                (0, "LAYOUT"),
                (5, "CCCCCCCC"),
                (330, "BBBBBBBB"),
                (102, "{ACAD_REACTORS"),
                (330, "BBBBBBBB"),
                (102, "}"),
                (0, "ENDSEC"),
                (0, "EOF")
                );
            // sanity check to verify that it was read correctly
            var dict   = file.Objects.OfType <DxfDictionary>().Single();
            var layout = (DxfLayout)dict["some-layout"];

            Assert.Equal(new DxfHandle(0xBBBBBBBB), ((IDxfItemInternal)dict).Handle);
            Assert.Equal(new DxfHandle(0xCCCCCCCC), ((IDxfItemInternal)layout).Handle);

            // re-save the file to a garbage stream to re-assign handles
            using (var ms = new MemoryStream())
            {
                file.Save(ms);
            }

            // verify new handles and owners; note that the assigned handles are unlikely to be 0xBBBBBBBB and 0xCCCCCCCC again
            Assert.True(ReferenceEquals(layout.Owner, dict));
            Assert.NotEqual(new DxfHandle(0xBBBBBBBB), ((IDxfItemInternal)dict).Handle);
            Assert.NotEqual(new DxfHandle(0xCCCCCCCC), ((IDxfItemInternal)layout).Handle);
            var dictHandle = ((IDxfItemInternal)dict).Handle;

            Assert.Equal(dictHandle, ((IDxfItemInternal)layout).OwnerHandle);
            var layoutXDataGroups = ((IDxfHasXData)layout).ExtensionDataGroups.Single(g => g.GroupName == "ACAD_REACTORS");
            var ownerCodePair     = (DxfCodePair)layoutXDataGroups.Items.Single();

            Assert.Equal(330, ownerCodePair.Code);
            Assert.Equal(DxfCommonConverters.HandleString(dictHandle), ownerCodePair.StringValue);
        }
Beispiel #7
0
        internal IEnumerable <DxfCodePair> GetValuePairs(DxfAcadVersion version, bool outputHandles, HashSet <IDxfItem> writtenItems)
        {
            BeforeWrite();

            var pairs = new List <DxfCodePair>();

            // common pairs
            pairs.Add(new DxfCodePair(0, DxfSection.TableText));
            pairs.Add(new DxfCodePair(2, TableTypeToName(TableType)));
            if (outputHandles && Handle.Value != 0)
            {
                pairs.Add(new DxfCodePair(5, DxfCommonConverters.HandleString(Handle)));
            }

            if (version >= DxfAcadVersion.R13)
            {
                foreach (var group in ExtensionDataGroups)
                {
                    group.AddValuePairs(pairs, version, outputHandles);
                }

                if (version >= DxfAcadVersion.R2000 && OwnerHandle.Value != 0)
                {
                    pairs.Add(new DxfCodePair(330, DxfCommonConverters.HandleString(OwnerHandle)));
                }

                pairs.Add(new DxfCodePair(100, "AcDbSymbolTable"));
            }

            var symbolItems = GetSymbolItems().Where(item => item != null).OrderBy(i => i.Name).ToList();

            pairs.Add(new DxfCodePair(70, (short)symbolItems.Count));
            if (version >= DxfAcadVersion.R2000 && TableClassName != null)
            {
                pairs.Add(new DxfCodePair(100, TableClassName));
            }

            foreach (var item in symbolItems)
            {
                if (writtenItems.Add(item))
                {
                    item.AddCommonValuePairs(pairs, version, outputHandles);
                    item.AddValuePairs(pairs, version, outputHandles);
                }
            }

            pairs.Add(new DxfCodePair(0, DxfSection.EndTableText));
            return(pairs);
        }
Beispiel #8
0
        internal void AddCodePairs(List <DxfCodePair> pairs)
        {
            pairs.Add(new DxfCodePair(1, "SectionTypeSettings"));
            pairs.Add(new DxfCodePair(90, SectionType));
            pairs.Add(new DxfCodePair(91, IsGenerationOption ? 1 : 0));
            pairs.Add(new DxfCodePair(92, SourceObjectHandles.Count));
            pairs.AddRange(SourceObjectHandles.Select(p => new DxfCodePair(330, DxfCommonConverters.HandleString(p))));
            pairs.Add(new DxfCodePair(331, DxfCommonConverters.HandleString(DestinationObjectHandle)));
            pairs.Add(new DxfCodePair(1, DestinationFileName));
            pairs.Add(new DxfCodePair(93, GeometrySettings.Count));
            pairs.Add(new DxfCodePair(2, "SectionGeometrySettings"));
            foreach (var geometry in GeometrySettings)
            {
                geometry.AddCodePairs(pairs);
            }

            pairs.Add(new DxfCodePair(3, "SectionTypeSettingsEnd"));
        }
Beispiel #9
0
            public IEnumerable <DxfCodePair> GetValuePairs(DxfAcadVersion version, bool outputHandles)
            {
                var list = new List <DxfCodePair>();

                list.Add(new DxfCodePair(0, EndBlockText));
                if (outputHandles && ((IDxfItemInternal)this).Handle.Value != 0)
                {
                    list.Add(new DxfCodePair(5, DxfCommonConverters.HandleString(((IDxfItemInternal)this).Handle)));
                }

                DxfXData.AddValuePairs(Parent.XData, list, version, outputHandles);

                if (version >= DxfAcadVersion.R14)
                {
                    foreach (var group in ExtensionDataGroups)
                    {
                        group.AddValuePairs(list, version, outputHandles);
                    }
                }

                if (version >= DxfAcadVersion.R2000)
                {
                    list.Add(new DxfCodePair(330, DxfCommonConverters.HandleString(((IDxfItemInternal)Parent).OwnerHandle)));
                }

                if (version >= DxfAcadVersion.R13)
                {
                    list.Add(new DxfCodePair(100, AcDbEntityText));
                }

                if (Parent.IsInPaperSpace)
                {
                    list.Add(new DxfCodePair(67, DxfCommonConverters.BoolShort(Parent.IsInPaperSpace)));
                }

                list.Add(new DxfCodePair(8, Parent.Layer));

                if (version >= DxfAcadVersion.R13)
                {
                    list.Add(new DxfCodePair(100, AcDbBlockEndText));
                }
                return(list);
            }
Beispiel #10
0
        internal static DxfTable FromBuffer(DxfCodePairBufferReader buffer)
        {
            var pair = buffer.Peek();

            buffer.Advance();
            if (pair.Code != 2)
            {
                throw new DxfReadException("Expected table type.", pair);
            }

            var tableType = pair.StringValue;

            // read common table values
            var commonValues = new List <DxfCodePair>();
            var groups       = new List <DxfCodePairGroup>();

            pair = buffer.Peek();
            while (pair != null && pair.Code != 0)
            {
                buffer.Advance();
                if (pair.Code == DxfCodePairGroup.GroupCodeNumber)
                {
                    var groupName = DxfCodePairGroup.GetGroupName(pair.StringValue);
                    groups.Add(DxfCodePairGroup.FromBuffer(buffer, groupName));
                }
                else
                {
                    commonValues.Add(pair);
                }

                pair = buffer.Peek();
            }

            DxfTable result;

            switch (tableType)
            {
            case DxfTable.AppIdText:
                result = DxfAppIdTable.ReadFromBuffer(buffer);
                break;

            case DxfTable.BlockRecordText:
                result = DxfBlockRecordTable.ReadFromBuffer(buffer);
                break;

            case DxfTable.DimStyleText:
                result = DxfDimStyleTable.ReadFromBuffer(buffer);
                break;

            case DxfTable.LayerText:
                result = DxfLayerTable.ReadFromBuffer(buffer);
                break;

            case DxfTable.LTypeText:
                result = DxfLTypeTable.ReadFromBuffer(buffer);
                break;

            case DxfTable.StyleText:
                result = DxfStyleTable.ReadFromBuffer(buffer);
                break;

            case DxfTable.UcsText:
                result = DxfUcsTable.ReadFromBuffer(buffer);
                break;

            case DxfTable.ViewText:
                result = DxfViewTable.ReadFromBuffer(buffer);
                break;

            case DxfTable.ViewPortText:
                result = DxfViewPortTable.ReadFromBuffer(buffer);
                break;

            default:
                SwallowTable(buffer);
                result = null;
                break;
            }

            if (result != null)
            {
                // set common values
                foreach (var common in commonValues)
                {
                    switch (common.Code)
                    {
                    case 5:
                        result.Handle = DxfCommonConverters.HandleString(common.StringValue);
                        break;

                    case 70:
                        // entry count, read dynamically
                        break;

                    case 330:
                        result.OwnerHandle = DxfCommonConverters.HandleString(common.StringValue);
                        break;
                    }
                }

                foreach (var group in groups)
                {
                    result.ExtensionDataGroups.Add(group);
                }

                result.AfterRead();
            }

            return(result);
        }
Beispiel #11
0
        internal IEnumerable <DxfCodePair> GetValuePairs(DxfAcadVersion version, bool outputHandles)
        {
            var list = new List <DxfCodePair>();

            list.Add(new DxfCodePair(0, BlockText));
            if (outputHandles && ((IDxfItemInternal)this).Handle.Value != 0)
            {
                list.Add(new DxfCodePair(5, DxfCommonConverters.HandleString(((IDxfItemInternal)this).Handle)));
            }

            if (version >= DxfAcadVersion.R14)
            {
                foreach (var group in ExtensionDataGroups)
                {
                    group.AddValuePairs(list, version, outputHandles);
                }
            }

            if (version >= DxfAcadVersion.R13)
            {
                if (((IDxfItemInternal)this).OwnerHandle.Value != 0)
                {
                    list.Add(new DxfCodePair(330, DxfCommonConverters.HandleString(((IDxfItemInternal)this).OwnerHandle)));
                }

                list.Add(new DxfCodePair(100, AcDbEntityText));
            }

            if (IsInPaperSpace)
            {
                list.Add(new DxfCodePair(67, DxfCommonConverters.BoolShort(IsInPaperSpace)));
            }

            list.Add(new DxfCodePair(8, Layer));
            if (version >= DxfAcadVersion.R13)
            {
                list.Add(new DxfCodePair(100, AcDbBlockBeginText));
            }

            list.Add(new DxfCodePair(2, Name));
            list.Add(new DxfCodePair(70, (short)Flags));
            list.Add(new DxfCodePair(10, BasePoint.X));
            list.Add(new DxfCodePair(20, BasePoint.Y));
            list.Add(new DxfCodePair(30, BasePoint.Z));
            if (version >= DxfAcadVersion.R12)
            {
                list.Add(new DxfCodePair(3, Name));
            }

            list.Add(new DxfCodePair(1, XrefName));

            if (!string.IsNullOrEmpty(Description))
            {
                list.Add(new DxfCodePair(4, Description));
            }

            // entities in blocks need handles for some applications
            list.AddRange(Entities.SelectMany(e => e.GetValuePairs(version, outputHandles)));

            list.AddRange(EndBlock.GetValuePairs(version, outputHandles));

            return(list);
        }
Beispiel #12
0
        internal static DxfBlock FromBuffer(DxfCodePairBufferReader buffer)
        {
            if (!buffer.ItemsRemain)
            {
                return(null);
            }

            var block             = new DxfBlock();
            var readingBlockStart = true;
            var readingBlockEnd   = false;
            var entities          = new List <DxfEntity>();

            while (buffer.ItemsRemain)
            {
                var pair = buffer.Peek();
                if (DxfCodePair.IsSectionEnd(pair))
                {
                    // done reading blocks
                    buffer.Advance(); // swallow (0, ENDSEC)
                    break;
                }
                else if (IsBlockStart(pair))
                {
                    if (readingBlockStart)
                    {
                        // if another block is found, stop reading this one because some blocks don't specify (0, ENDBLK)
                        break;
                    }

                    break;
                }
                else if (IsBlockEnd(pair))
                {
                    if (!readingBlockStart)
                    {
                        throw new DxfReadException("Unexpected block end", pair);
                    }
                    readingBlockStart = false;
                    readingBlockEnd   = true;
                    buffer.Advance(); // swallow (0, ENDBLK)
                }
                else if (pair.Code == 0)
                {
                    // should be an entity
                    var entity = DxfEntity.FromBuffer(buffer);
                    if (entity != null)
                    {
                        // entity could be null if it's unsupported
                        entities.Add(entity);
                    }
                }
                else
                {
                    // read value pair
                    if (readingBlockStart)
                    {
                        buffer.Advance();
                        switch (pair.Code)
                        {
                        case 1:
                            block.XrefName = pair.StringValue;
                            break;

                        case 2:
                            block.Name = pair.StringValue;
                            break;

                        case 3:
                            break;

                        case 4:
                            block.Description = pair.StringValue;
                            break;

                        case 5:
                            ((IDxfItemInternal)block).Handle = DxfCommonConverters.HandleString(pair.StringValue);
                            break;

                        case 8:
                            block.Layer = pair.StringValue;
                            break;

                        case 10:
                            block.BasePoint = block.BasePoint.WithUpdatedX(pair.DoubleValue);
                            break;

                        case 20:
                            block.BasePoint = block.BasePoint.WithUpdatedY(pair.DoubleValue);
                            break;

                        case 30:
                            block.BasePoint = block.BasePoint.WithUpdatedZ(pair.DoubleValue);
                            break;

                        case 67:
                            block.IsInPaperSpace = DxfCommonConverters.BoolShort(pair.ShortValue);
                            break;

                        case 70:
                            block.Flags = pair.ShortValue;
                            break;

                        case 330:
                            ((IDxfItemInternal)block).OwnerHandle = DxfCommonConverters.HandleString(pair.StringValue);
                            break;

                        case DxfCodePairGroup.GroupCodeNumber:
                            var groupName = DxfCodePairGroup.GetGroupName(pair.StringValue);
                            block.ExtensionDataGroups.Add(DxfCodePairGroup.FromBuffer(buffer, groupName));
                            break;

                        case (int)DxfXDataType.ApplicationName:
                            DxfXData.PopulateFromBuffer(buffer, block.XData, pair.StringValue);
                            break;
                        }
                    }
                    else if (readingBlockEnd)
                    {
                        block.EndBlock.ApplyCodePairs(buffer);
                    }
                    else
                    {
                        throw new DxfReadException("Unexpected pair in block", pair);
                    }
                }
            }

            var collected = DxfEntitiesSection.GatherEntities(entities);

            foreach (var entity in collected)
            {
                block.Entities.Add(entity);
            }

            return(block);
        }
Beispiel #13
0
        internal static DxfSectionTypeSettings FromBuffer(DxfCodePairBufferReader buffer)
        {
            if (buffer.Peek()?.Code == 0)
            {
                return(null);
            }

            var settings = new DxfSectionTypeSettings();

            while (buffer.ItemsRemain)
            {
                var pair = buffer.Peek();
                if (pair.Code == 0)
                {
                    break;
                }

                switch (pair.Code)
                {
                case 1:
                    settings.DestinationFileName = pair.StringValue;
                    buffer.Advance();
                    break;

                case 2:
                    Debug.Assert(pair.StringValue == "SectionGeometrySettings");
                    buffer.Advance();
                    for (var geometry = DxfSectionGeometrySettings.FromBuffer(buffer); geometry != null; geometry = DxfSectionGeometrySettings.FromBuffer(buffer))
                    {
                        settings.GeometrySettings.Add(geometry);
                    }
                    break;

                case 3:
                    Debug.Assert(pair.StringValue == "SectionTypeSettingsEnd");
                    buffer.Advance();
                    break;

                case 90:
                    settings.SectionType = pair.IntegerValue;
                    buffer.Advance();
                    break;

                case 91:
                    settings.IsGenerationOption = pair.IntegerValue != 0;
                    buffer.Advance();
                    break;

                case 92:
                    var sourceObjectsCount = pair.IntegerValue;
                    buffer.Advance();
                    break;

                case 93:
                    var generationSettingsCount = pair.IntegerValue;
                    buffer.Advance();
                    break;

                case 330:
                    settings.SourceObjectHandles.Add(DxfCommonConverters.HandleString(pair.StringValue));
                    buffer.Advance();
                    break;

                case 331:
                    settings.DestinationObjectHandle = DxfCommonConverters.HandleString(pair.StringValue);
                    buffer.Advance();
                    break;

                default:
                    return(settings);
                }
            }

            return(settings);
        }
Beispiel #14
0
 protected static string HandleString(DxfHandle handle)
 {
     return(DxfCommonConverters.HandleString(handle));
 }
Beispiel #15
0
 protected static DxfHandle HandleString(string s)
 {
     return(DxfCommonConverters.HandleString(s));
 }
Beispiel #16
0
        internal override DxfObject PopulateFromBuffer(DxfCodePairBufferReader buffer)
        {
            bool readVersionNumber = false;

            while (buffer.ItemsRemain)
            {
                var pair = buffer.Peek();
                if (pair.Code == 0)
                {
                    break;
                }

                while (this.TrySetExtensionData(pair, buffer))
                {
                    pair = buffer.Peek();
                }

                if (pair.Code == 0)
                {
                    break;
                }

                switch (pair.Code)
                {
                case 5:
                    if (readVersionNumber)
                    {
                        // pointer to a new light
                        LightsPointers.Pointers.Add(new DxfPointer(DxfCommonConverters.HandleString(pair.StringValue)));
                    }
                    else
                    {
                        // might still be the handle
                        if (!base.TrySetPair(pair))
                        {
                            ExcessCodePairs.Add(pair);
                        }
                    }
                    break;

                case 1:
                    // don't worry about the name; it'll be read from the light entity directly
                    break;

                case 90:
                    if (readVersionNumber)
                    {
                        // count of lights is ignored since it's implicitly set by reading the values
                    }
                    else
                    {
                        Version           = pair.IntegerValue;
                        readVersionNumber = true;
                    }
                    break;

                default:
                    if (!base.TrySetPair(pair))
                    {
                        ExcessCodePairs.Add(pair);
                    }
                    break;
                }

                buffer.Advance();
            }

            return(PostParse());
        }
Beispiel #17
0
        internal void AddValuePairs(List <DxfCodePair> pairs, DxfAcadVersion version, bool outputHandles)
        {
            var code = (int)Type;

            switch (this)
            {
            case DxfXDataString s:
                pairs.Add(new DxfCodePair(code, s.Value));
                break;

            case DxfXDataItemList l:
                AddListValuePairs(l.Items, pairs, version, outputHandles);
                break;

            case DxfXDataLayerName l:
                pairs.Add(new DxfCodePair(code, l.Value));
                break;

            case DxfXDataBinaryData b:
                pairs.Add(new DxfCodePair(code, DxfCommonConverters.HexBytes(b.Value)));
                break;

            case DxfXDataHandle h:
                pairs.Add(new DxfCodePair(code, DxfCommonConverters.HandleString(h.Value)));
                break;

            case DxfXData3Reals r:
                pairs.Add(new DxfCodePair(code, r.Value.X));
                pairs.Add(new DxfCodePair(code + 10, r.Value.Y));
                pairs.Add(new DxfCodePair(code + 20, r.Value.Z));
                break;

            case DxfXDataWorldSpacePosition w:
                pairs.Add(new DxfCodePair(code, w.Value.X));
                pairs.Add(new DxfCodePair(code + 10, w.Value.Y));
                pairs.Add(new DxfCodePair(code + 20, w.Value.Z));
                break;

            case DxfXDataWorldSpaceDisplacement w:
                pairs.Add(new DxfCodePair(code, w.Value.X));
                pairs.Add(new DxfCodePair(code + 10, w.Value.Y));
                pairs.Add(new DxfCodePair(code + 20, w.Value.Z));
                break;

            case DxfXDataWorldDirection w:
                pairs.Add(new DxfCodePair(code, w.Value.X));
                pairs.Add(new DxfCodePair(code + 10, w.Value.Y));
                pairs.Add(new DxfCodePair(code + 20, w.Value.Z));
                break;

            case DxfXDataReal r:
                pairs.Add(new DxfCodePair(code, r.Value));
                break;

            case DxfXDataDistance d:
                pairs.Add(new DxfCodePair(code, d.Value));
                break;

            case DxfXDataScaleFactor s:
                pairs.Add(new DxfCodePair(code, s.Value));
                break;

            case DxfXDataInteger i:
                pairs.Add(new DxfCodePair(code, i.Value));
                break;

            case DxfXDataLong l:
                pairs.Add(new DxfCodePair(code, l.Value));
                break;

            default:
                throw new InvalidOperationException("Unexpected XDATA item " + Type);
            }
        }