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); }
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; }
private static DxfPoint ReadPoint(DxfCodePair xCoord, DxfCodePairBufferReader buffer, int expectedFirstCode) { // first value var pair = xCoord; Debug.Assert(pair.Code == expectedFirstCode); var x = pair.DoubleValue; // second value Debug.Assert(buffer.ItemsRemain); pair = buffer.Peek(); Debug.Assert(pair.Code == expectedFirstCode + 10); var y = pair.DoubleValue; buffer.Advance(); // third value Debug.Assert(buffer.ItemsRemain); pair = buffer.Peek(); Debug.Assert(pair.Code == expectedFirstCode + 20); var z = pair.DoubleValue; buffer.Advance(); return(new DxfPoint(x, y, z)); }
internal override DxfObject PopulateFromBuffer(DxfCodePairBufferReader buffer) { bool readingData = false; while (buffer.ItemsRemain) { var pair = buffer.Peek(); if (pair.Code == 0) { break; } if (readingData) { DataPairs.Add(pair); } else { if (pair.Code == 280) { DuplicateRecordHandling = (DxfDictionaryDuplicateRecordHandling)pair.ShortValue; buffer.Advance(); readingData = true; continue; } if (base.TrySetPair(pair)) { buffer.Advance(); continue; } if (this.TrySetExtensionData(pair, buffer)) { continue; } if (pair.Code == 100) { Debug.Assert(pair.StringValue == "AcDbXrecord"); buffer.Advance(); continue; } else if (pair.Code == 5 || pair.Code == 105) { // these codes aren't allowed here ExcessCodePairs.Add(pair); } else { DataPairs.Add(pair); readingData = true; } } buffer.Advance(); } return(PostParse()); }
internal virtual DxfEntity PopulateFromBuffer(DxfCodePairBufferReader buffer) { while (buffer.ItemsRemain) { var pair = buffer.Peek(); if (pair.Code == 0) { break; } if (TrySetPair(pair)) { // pair was successfully applied; consume it buffer.Advance(); } else if (this.TrySetExtensionData(pair, buffer)) { // do nothing as TrySetExtensionData consumes as necessary } else { // track it for later use and consume it ExcessCodePairs.Add(pair); buffer.Advance(); } } return PostParse(); }
internal override DxfObject PopulateFromBuffer(DxfCodePairBufferReader buffer) { bool readingData = false; while (buffer.ItemsRemain) { var pair = buffer.Peek(); if (pair.Code == 0) { break; } if (readingData) { DataPairs.Add(pair); } else { if (pair.Code == 280) { DuplicateRecordHandling = (DxfDictionaryDuplicateRecordHandling)pair.ShortValue; buffer.Advance(); readingData = true; continue; } if (base.TrySetPair(pair)) { buffer.Advance(); continue; } if (this.TrySetExtensionData(pair, buffer)) { continue; } if (pair.Code == 100) { Debug.Assert(pair.StringValue == "AcDbXrecord"); buffer.Advance(); continue; } else if (pair.Code == 5 || pair.Code == 105) { // these codes aren't allowed here ExcessCodePairs.Add(pair); } else { DataPairs.Add(pair); readingData = true; } } buffer.Advance(); } return PostParse(); }
internal override DxfObject PopulateFromBuffer(DxfCodePairBufferReader buffer) { 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 1: Debug.Assert(pair.StringValue == "SectionTypeSettings"); buffer.Advance(); for (var sectionSettings = DxfSectionTypeSettings.FromBuffer(buffer); sectionSettings != null; sectionSettings = DxfSectionTypeSettings.FromBuffer(buffer)) { SectionTypeSettings.Add(sectionSettings); } break; case 90: SectionType = pair.IntegerValue; buffer.Advance(); break; case 91: var generationSettingsCount = pair.IntegerValue; buffer.Advance(); break; default: if (!base.TrySetPair(pair)) { ExcessCodePairs.Add(pair); } buffer.Advance(); break; } } return(PostParse()); }
internal static DxfHeaderSection HeaderSectionFromBuffer(DxfCodePairBufferReader buffer) { var section = new DxfHeaderSection(); string keyName = null; Func <short, bool> shortToBool = value => value != 0; while (buffer.ItemsRemain) { var pair = buffer.Peek(); buffer.Advance(); if (DxfCodePair.IsSectionEnd(pair)) { // done reading settings break; } if (pair.Code == 9) { // what setting to get keyName = pair.StringValue; } else { section.Header.SetHeaderVariable(keyName, pair); if (string.Compare(keyName, "$ACADVER", StringComparison.OrdinalIgnoreCase) == 0 && section.Header.Version >= DxfAcadVersion.R2007) { // R2007 and up should switch to a UTF8 reader buffer.SetUtf8Reader(); } } } return(section); }
internal static DxfAppId FromBuffer(DxfCodePairBufferReader buffer) { var item = new DxfAppId(); while (buffer.ItemsRemain) { var pair = buffer.Peek(); if (pair.Code == 0) { break; } buffer.Advance(); switch (pair.Code) { case 70: item.StandardFlags = (int)pair.ShortValue; break; case DxfCodePairGroup.GroupCodeNumber: var groupName = DxfCodePairGroup.GetGroupName(pair.StringValue); item.ExtensionDataGroups.Add(DxfCodePairGroup.FromBuffer(buffer, groupName)); break; case (int)DxfXDataType.ApplicationName: item.XData = DxfXData.FromBuffer(buffer, pair.StringValue); break; default: item.TrySetPair(pair); break; } } return item; }
internal static DxfClassesSection ClassesSectionFromBuffer(DxfCodePairBufferReader buffer, DxfAcadVersion version) { var section = new DxfClassesSection(); while (buffer.ItemsRemain) { var pair = buffer.Peek(); if (DxfCodePair.IsSectionEnd(pair)) { // done reading classes buffer.Advance(); // swallow (0, ENDSEC) break; } if (pair.Code != 0) { throw new DxfReadException("Expected new class.", pair); } var cls = DxfClass.FromBuffer(buffer, version); if (cls != null) { section.Classes.Add(cls); } } return section; }
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); }
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; }
public void ApplyCodePairs(DxfCodePairBufferReader buffer) { var pair = buffer.Peek(); buffer.Advance(); switch (pair.Code) { case 5: ((IDxfItemInternal)this).Handle = DxfCommonConverters.UIntHandle(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; } }
internal static DxfEntitiesSection EntitiesSectionFromBuffer(DxfCodePairBufferReader buffer) { var entities = new List <DxfEntity>(); entities.Clear(); while (buffer.ItemsRemain) { var pair = buffer.Peek(); if (DxfCodePair.IsSectionEnd(pair)) { // done reading entities buffer.Advance(); // swallow (0, ENDSEC) break; } if (pair.Code != 0) { throw new DxfReadException("Expected new entity.", pair); } var entity = DxfEntity.FromBuffer(buffer); if (entity != null) { entities.Add(entity); } } var section = new DxfEntitiesSection(); var collected = GatherEntities(entities); section.Entities.AddRange(collected); return(section); }
internal static DxfHeaderSection HeaderSectionFromBuffer(DxfCodePairBufferReader buffer) { var section = new DxfHeaderSection(); string keyName = null; Func <short, bool> shortToBool = value => value != 0; while (buffer.ItemsRemain) { var pair = buffer.Peek(); buffer.Advance(); if (DxfCodePair.IsSectionEnd(pair)) { // done reading settings break; } if (pair.Code == 9) { // what setting to get keyName = pair.StringValue; } else { section.Header.SetHeaderVariable(keyName, pair); } } return(section); }
internal virtual DxfObject PopulateFromBuffer(DxfCodePairBufferReader buffer) { 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; } if (!TrySetPair(pair)) { ExcessCodePairs.Add(pair); } buffer.Advance(); } return(PostParse()); }
internal static DxfClassesSection ClassesSectionFromBuffer(DxfCodePairBufferReader buffer, DxfAcadVersion version) { var section = new DxfClassesSection(); section.Clear(); while (buffer.ItemsRemain) { var pair = buffer.Peek(); if (DxfCodePair.IsSectionEnd(pair)) { // done reading classes buffer.Advance(); // swallow (0, ENDSEC) break; } if (pair.Code != 0) { throw new DxfReadException("Expected new class.", pair); } var cls = DxfClass.FromBuffer(buffer, version); if (cls != null) { section.Classes.Add(cls); } } return(section); }
internal static DxfEntitiesSection EntitiesSectionFromBuffer(DxfCodePairBufferReader buffer) { var entities = new List<DxfEntity>(); while (buffer.ItemsRemain) { var pair = buffer.Peek(); if (DxfCodePair.IsSectionEnd(pair)) { // done reading entities buffer.Advance(); // swallow (0, ENDSEC) break; } if (pair.Code != 0) { throw new DxfReadException("Expected new entity.", pair); } var entity = DxfEntity.FromBuffer(buffer); if (entity != null) { entities.Add(entity); } } var section = new DxfEntitiesSection(); var collected = GatherEntities(entities); section.Entities.AddRange(collected); return section; }
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()); }
internal override DxfEntity PopulateFromBuffer(DxfCodePairBufferReader buffer) { while (buffer.ItemsRemain) { var pair = buffer.Peek(); if (pair.Code == 0) { break; } while (this.TrySetExtensionData(pair, buffer)) { pair = buffer.Peek(); } switch (pair.Code) { case 10: // start a new vertex Vertices.Add(new DxfLwPolylineVertex()); Vertices.Last().X = pair.DoubleValue; break; case 20: Vertices.Last().Y = pair.DoubleValue; break; case 40: Vertices.Last().StartingWidth = pair.DoubleValue; break; case 41: Vertices.Last().EndingWidth = pair.DoubleValue; break; case 42: Vertices.Last().Bulge = pair.DoubleValue; break; case 91: Vertices.Last().Identifier = pair.IntegerValue; break; default: if (!base.TrySetPair(pair)) { ExcessCodePairs.Add(pair); } break; } buffer.Advance(); } return(PostParse()); }
private static void SwallowEntity(DxfCodePairBufferReader buffer) { while (buffer.ItemsRemain) { var pair = buffer.Peek(); if (pair.Code == 0) break; buffer.Advance(); } }
internal static void SwallowSection(DxfCodePairBufferReader buffer) { while (buffer.ItemsRemain) { var pair = buffer.Peek(); buffer.Advance(); if (DxfCodePair.IsSectionEnd(pair)) { break; } } }
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(); } switch (pair.Code) { case 5: // pointer to a new light LightsPointers.Pointers.Add(new DxfPointer(DxfCommonConverters.UIntHandle(pair.StringValue))); 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()); }
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.UIntHandle(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 } }
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); }
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.UIntHandle(pair.StringValue))); } else { ((IDxfItemInternal)this).Handle = DxfCommonConverters.UIntHandle(pair.StringValue); isReadyForSortHandles = true; } break; case 100: isReadyForSortHandles = true; break; case 330: ((IDxfItemInternal)this).OwnerHandle = DxfCommonConverters.UIntHandle(pair.StringValue); isReadyForSortHandles = true; break; case 331: EntitiesPointers.Pointers.Add(new DxfPointer(DxfCommonConverters.UIntHandle(pair.StringValue))); isReadyForSortHandles = true; break; default: ExcessCodePairs.Add(pair); break; } buffer.Advance(); } return PostParse(); }
internal override DxfObject PopulateFromBuffer(DxfCodePairBufferReader buffer) { bool readVersionNumber = false; while (buffer.ItemsRemain) { var pair = buffer.Peek(); if (pair.Code == 0) { break; } if (TrySetExtensionData(pair, buffer)) { pair = buffer.Peek(); } switch (pair.Code) { case 5: // start a new light item Lights.Add(new DxfLightListItem()); Lights.Last().Handle = UIntHandle(pair.StringValue); break; case 1: Lights.Last().Name = pair.StringValue; 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(); }
internal override DxfEntity PopulateFromBuffer(DxfCodePairBufferReader buffer) { while (buffer.ItemsRemain) { var pair = buffer.Peek(); if (pair.Code == 0) { break; } while (this.TrySetExtensionData(pair, buffer)) { pair = buffer.Peek(); } switch (pair.Code) { case 10: // start a new vertex Vertices.Add(new DxfLwPolylineVertex()); Vertices.Last().X = pair.DoubleValue; break; case 20: Vertices.Last().Y = pair.DoubleValue; break; case 40: Vertices.Last().StartingWidth = pair.DoubleValue; break; case 41: Vertices.Last().EndingWidth = pair.DoubleValue; break; case 42: Vertices.Last().Bulge = pair.DoubleValue; break; case 91: Vertices.Last().Identifier = pair.IntegerValue; break; default: if (!base.TrySetPair(pair)) { ExcessCodePairs.Add(pair); } break; } buffer.Advance(); } return PostParse(); }
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(); } switch (pair.Code) { case 5: // pointer to a new light LightsPointers.Pointers.Add(new DxfPointer(DxfCommonConverters.UIntHandle(pair.StringValue))); 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(); }
internal static DxfThumbnailImageSection ThumbnailImageSectionFromBuffer(DxfCodePairBufferReader buffer) { if (buffer.ItemsRemain) { var lengthPair = buffer.Peek(); buffer.Advance(); if (lengthPair.Code != 90) { return(null); } var length = lengthPair.IntegerValue; var lines = new List <string>(); while (buffer.ItemsRemain) { var pair = buffer.Peek(); buffer.Advance(); if (DxfCodePair.IsSectionEnd(pair)) { break; } Debug.Assert(pair.Code == 310); lines.Add(pair.StringValue); } var section = new DxfThumbnailImageSection(); section.Clear(); section.RawData = DxfCommonConverters.HexBytes(string.Join(string.Empty, lines.ToArray())); return(section); } return(null); }
internal static DxfThumbnailImageSection ThumbnailImageSectionFromBuffer(DxfCodePairBufferReader buffer) { if (buffer.ItemsRemain) { var lengthPair = buffer.Peek(); buffer.Advance(); if (lengthPair.Code != 90) { return(null); } var length = lengthPair.IntegerValue; var rawData = new List <byte>(); while (buffer.ItemsRemain) { var pair = buffer.Peek(); buffer.Advance(); if (DxfCodePair.IsSectionEnd(pair)) { break; } Debug.Assert(pair.Code == 310); rawData.AddRange(pair.BinaryValue); } var section = new DxfThumbnailImageSection(); section.Clear(); section.RawData = rawData.ToArray(); return(section); } return(null); }
internal override DxfObject PopulateFromBuffer(DxfCodePairBufferReader buffer) { bool isReadingPlotSettings = true; while (buffer.ItemsRemain) { var pair = buffer.Peek(); if (pair.Code == 0) { break; } while (this.TrySetExtensionData(pair, buffer)) { pair = buffer.Peek(); } if (isReadingPlotSettings) { if (pair.Code == 100 && pair.StringValue == "AcDbLayout") { isReadingPlotSettings = false; } else { if (!base.TrySetPair(pair)) { ExcessCodePairs.Add(pair); } } } else { if (!TrySetPair(pair)) { ExcessCodePairs.Add(pair); } } buffer.Advance(); } return(PostParse()); }
internal static DxfHeaderSection HeaderSectionFromBuffer(DxfCodePairBufferReader buffer) { var section = new DxfHeaderSection(); string keyName = null; Func <short, bool> shortToBool = value => value != 0; while (buffer.ItemsRemain) { var pair = buffer.Peek(); buffer.Advance(); if (DxfCodePair.IsSectionEnd(pair)) { // done reading settings break; } if (pair.Code == 9) { // what setting to get keyName = pair.StringValue; } else { section.Header.SetHeaderVariable(keyName, pair); if (string.Compare(keyName, "$DWGCODEPAGE", StringComparison.OrdinalIgnoreCase) == 0 && section.Header.Version <= DxfAcadVersion.R2004) { // R2004 and before should honor the specified code page if (DxfEncodingHelper.TryParseEncoding(pair.StringValue, out var codePage)) { var encoding = Encoding.GetEncoding(codePage); buffer.SetReaderEncoding(encoding); } } else if (string.Compare(keyName, "$ACADVER", StringComparison.OrdinalIgnoreCase) == 0 && section.Header.Version >= DxfAcadVersion.R2007) { // R2007 and up should switch to a UTF8 reader buffer.SetReaderEncoding(Encoding.UTF8); } } } return(section); }
internal override DxfObject PopulateFromBuffer(DxfCodePairBufferReader buffer) { bool isReadingPlotSettings = true; while (buffer.ItemsRemain) { var pair = buffer.Peek(); if (pair.Code == 0) { break; } if (TrySetExtensionData(pair, buffer)) { pair = buffer.Peek(); } if (isReadingPlotSettings) { if (pair.Code == 100 && pair.StringValue == "AcDbLayout") { isReadingPlotSettings = false; } else { if (!base.TrySetPair(pair)) { ExcessCodePairs.Add(pair); } } } else { if (!TrySetPair(pair)) { ExcessCodePairs.Add(pair); } } buffer.Advance(); } return PostParse(); }
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; }
public void ApplyCodePairs(DxfCodePairBufferReader buffer, DxfAcadVersion version) { var pair = buffer.Peek(); buffer.Advance(); switch (pair.Code) { case 5: Handle = DxfCommonConverters.UIntHandle(pair.StringValue); break; case 8: Debug.Assert(version >= DxfAcadVersion.R13); 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; } }
internal static DxfCodePairGroup FromBuffer(DxfCodePairBufferReader buffer, string groupName) { var items = new List<IDxfCodePairOrGroup>(); while (buffer.ItemsRemain) { var pair = buffer.Peek(); if (pair.Code == 0) { Debug.Assert(false, "Unexpected end of section/file while parsing group."); break; } buffer.Advance(); if (pair.Code == GroupCodeNumber) { if (pair.StringValue == "}") { // end of group break; } else if (pair.StringValue.StartsWith("{")) { // nested group var subGroupName = GetGroupName(pair.StringValue); var subGroup = FromBuffer(buffer, subGroupName); items.Add(subGroup); } else { throw new DxfReadException("Unexpected code pair group text", pair); } } else { items.Add(pair); } } return new DxfCodePairGroup(groupName, items); }
internal static DxfTable ReadFromBuffer(DxfCodePairBufferReader buffer) { var table = new DxfStyleTable(); table.Items.Clear(); while (buffer.ItemsRemain) { var pair = buffer.Peek(); buffer.Advance(); if (DxfTablesSection.IsTableEnd(pair)) { break; } if (pair.Code == 0 && pair.StringValue == DxfTable.StyleText) { var item = DxfStyle.FromBuffer(buffer); table.Items.Add(item); } } return(table); }
internal static DxfXDataItemList ListFromBuffer(DxfCodePairBufferReader buffer) { Debug.Assert(buffer.ItemsRemain); DxfCodePair pair; var items = new List <DxfXDataItem>(); while (buffer.ItemsRemain) { pair = buffer.Peek(); if (pair.Code == (int)DxfXDataType.ControlString && pair.StringValue == "}") { buffer.Advance(); break; } var item = DxfXDataItem.FromBuffer(buffer); if (item != null) { items.Add(item); } } return(new DxfXDataItemList(items)); }
internal override DxfObject PopulateFromBuffer(DxfCodePairBufferReader buffer) { bool readDuplicateFlag = false; while (buffer.ItemsRemain) { var pair = buffer.Peek(); if (pair.Code == 0) { break; } if (TrySetExtensionData(pair, buffer)) { pair = buffer.Peek(); } if (pair.Code == 280 && !readDuplicateFlag) { DuplicateRecordHandling = (DxfDictionaryDuplicateRecordHandling)pair.ShortValue; readDuplicateFlag = true; } else if (pair.Code == 5 || pair.Code == 105) { // these codes aren't allowed here ExcessCodePairs.Add(pair); } else { DataPairs.Add(pair); } buffer.Advance(); } return PostParse(); }
internal override DxfObject PopulateFromBuffer(DxfCodePairBufferReader buffer) { int code_280_index = 0; while (buffer.ItemsRemain) { var pair = buffer.Peek(); if (pair.Code == 0) { break; } while (this.TrySetExtensionData(pair, buffer)) { pair = buffer.Peek(); } switch (pair.Code) { case 3: this.Description = (pair.StringValue); buffer.Advance(); break; case 7: var style = DxfTableCellStyle.FromBuffer(buffer); CellStyles.Add(style); break; case 40: this.HorizontalCellMargin = (pair.DoubleValue); buffer.Advance(); break; case 41: this.VerticalCellMargin = (pair.DoubleValue); buffer.Advance(); break; case 70: this.FlowDirection = (DxfFlowDirection)(pair.ShortValue); buffer.Advance(); break; case 71: this.Flags = (pair.ShortValue); buffer.Advance(); break; case 280: switch (code_280_index) { case 0: this.Version = (DxfVersion)(pair.ShortValue); code_280_index++; break; case 1: this.IsTitleSuppressed = BoolShort(pair.ShortValue); code_280_index++; break; default: Debug.Assert(false, "Unexpected extra values for code 280"); break; } buffer.Advance(); break; case 281: this.IsColumnHeadingSuppressed = BoolShort(pair.ShortValue); buffer.Advance(); break; default: if (!base.TrySetPair(pair)) { ExcessCodePairs.Add(pair); } buffer.Advance(); break; } } return PostParse(); }
internal static DxfBlock FromBuffer(DxfCodePairBufferReader buffer, DxfAcadVersion version) { if (!buffer.ItemsRemain) { return null; } var block = new DxfBlock(); var readingBlockStart = true; var readingBlockEnd = false; 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); Debug.Assert(entity != null); if (entity != null) block.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.UIntHandle(pair.StringValue); break; case 8: block.Layer = pair.StringValue; break; case 10: block.BasePoint.X = pair.DoubleValue; break; case 20: block.BasePoint.Y = pair.DoubleValue; break; case 30: block.BasePoint.Z = 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.UIntHandle(pair.StringValue); break; case DxfCodePairGroup.GroupCodeNumber: var groupName = DxfCodePairGroup.GetGroupName(pair.StringValue); block.ExtensionDataGroups.Add(DxfCodePairGroup.FromBuffer(buffer, groupName)); break; case (int)DxfXDataType.ApplicationName: block.XData = DxfXData.FromBuffer(buffer, pair.StringValue); break; } } else if (readingBlockEnd) { block.EndBlock.ApplyCodePairs(buffer, version); } else { throw new DxfReadException("Unexpected pair in block", pair); } } } return block; }
internal static DxfViewPort FromBuffer(DxfCodePairBufferReader buffer) { var item = new DxfViewPort(); while (buffer.ItemsRemain) { var pair = buffer.Peek(); if (pair.Code == 0) { break; } buffer.Advance(); switch (pair.Code) { case 70: item.StandardFlags = (int)pair.ShortValue; break; case DxfCodePairGroup.GroupCodeNumber: var groupName = DxfCodePairGroup.GetGroupName(pair.StringValue); item.ExtensionDataGroups.Add(DxfCodePairGroup.FromBuffer(buffer, groupName)); break; case 10: item.LowerLeft.X = (pair.DoubleValue); break; case 20: item.LowerLeft.Y = (pair.DoubleValue); break; case 11: item.UpperRight.X = (pair.DoubleValue); break; case 21: item.UpperRight.Y = (pair.DoubleValue); break; case 12: item.ViewCenter.X = (pair.DoubleValue); break; case 22: item.ViewCenter.Y = (pair.DoubleValue); break; case 13: item.SnapBasePoint.X = (pair.DoubleValue); break; case 23: item.SnapBasePoint.Y = (pair.DoubleValue); break; case 14: item.SnapSpacing.X = (pair.DoubleValue); break; case 24: item.SnapSpacing.Y = (pair.DoubleValue); break; case 15: item.GridSpacing.X = (pair.DoubleValue); break; case 25: item.GridSpacing.Y = (pair.DoubleValue); break; case 16: item.ViewDirection.X = (pair.DoubleValue); break; case 26: item.ViewDirection.Y = (pair.DoubleValue); break; case 36: item.ViewDirection.Z = (pair.DoubleValue); break; case 17: item.TargetViewPoint.X = (pair.DoubleValue); break; case 27: item.TargetViewPoint.Y = (pair.DoubleValue); break; case 37: item.TargetViewPoint.Z = (pair.DoubleValue); break; case 40: item.ViewHeight = (pair.DoubleValue); break; case 41: item.ViewPortAspectRatio = (pair.DoubleValue); break; case 42: item.LensLength = (pair.DoubleValue); break; case 43: item.FrontClippingPlane = (pair.DoubleValue); break; case 44: item.BackClippingPlane = (pair.DoubleValue); break; case 45: item.ViewHeight = (pair.DoubleValue); break; case 50: item.SnapRotationAngle = (pair.DoubleValue); break; case 51: item.ViewTwistAngle = (pair.DoubleValue); break; case 68: item.Status = (pair.ShortValue); break; case 69: item.ID = (pair.ShortValue); break; case 71: item.ViewMode = (DxfViewMode)(pair.ShortValue); break; case 72: item.CircleZoomPercent = (int)(pair.ShortValue); break; case 73: item.FastZoom = BoolShort(pair.ShortValue); break; case 74: item.UCSIcon = BoolShort(pair.ShortValue); break; case 75: item.SnapOn = BoolShort(pair.ShortValue); break; case 76: item.GridOn = BoolShort(pair.ShortValue); break; case 77: item.SnapStyle = (pair.ShortValue); break; case 78: item.SnapIsoPair = (pair.ShortValue); break; case 1: item.PlotStyleSheet = (pair.StringValue); break; case 281: item.RenderMode = (DxfViewRenderMode)(pair.ShortValue); break; case 65: item.HasOwnUCS = BoolShort(pair.ShortValue); break; case 110: item.UCSOrigin.X = (pair.DoubleValue); break; case 120: item.UCSOrigin.Y = (pair.DoubleValue); break; case 130: item.UCSOrigin.Z = (pair.DoubleValue); break; case 111: item.UCSXAxis.X = (pair.DoubleValue); break; case 121: item.UCSXAxis.Y = (pair.DoubleValue); break; case 131: item.UCSXAxis.Z = (pair.DoubleValue); break; case 112: item.UCSYAxis.X = (pair.DoubleValue); break; case 122: item.UCSYAxis.Y = (pair.DoubleValue); break; case 132: item.UCSYAxis.Z = (pair.DoubleValue); break; case 79: item.OrthographicViewType = (DxfOrthographicViewType)(pair.ShortValue); break; case 146: item.UCSElevation = (pair.DoubleValue); break; case 345: item.UCSHandle = UIntHandle(pair.StringValue); break; case 346: item.BaseUCSHandle = UIntHandle(pair.StringValue); break; case 170: item.ShadePlotSetting = (DxfShadeEdgeMode)(pair.ShortValue); break; case 61: item.MajorGridLines = BoolShort(pair.ShortValue); break; case 332: item.BackgroundObjectPointer = UIntHandle(pair.StringValue); break; case 333: item.ShadePlotObjectPointer = UIntHandle(pair.StringValue); break; case 348: item.VisualStyleObjectPointer = UIntHandle(pair.StringValue); break; case 292: item.IsDefaultLightingOn = (pair.BoolValue); break; case 282: item.DefaultLightingType = (DxfDefaultLightingType)(pair.ShortValue); break; case 141: item.Brightness = (pair.DoubleValue); break; case 142: item.Contrast = (pair.DoubleValue); break; case 62: item.AmbientColor = DxfColor.FromRawValue(pair.ShortValue); break; case 421: item.AmbientColorInt = (pair.IntegerValue); break; case 431: item.AmbientColorName = (pair.StringValue); break; case (int)DxfXDataType.ApplicationName: item.XData = DxfXData.FromBuffer(buffer, pair.StringValue); break; default: item.TrySetPair(pair); break; } } return item; }
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.UIntHandle(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.UIntHandle(pair.StringValue); break; case DxfCodePairGroup.GroupCodeNumber: var groupName = DxfCodePairGroup.GetGroupName(pair.StringValue); block.ExtensionDataGroups.Add(DxfCodePairGroup.FromBuffer(buffer, groupName)); break; case (int)DxfXDataType.ApplicationName: block.XData = DxfXData.FromBuffer(buffer, 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; }
internal static DxfClass FromBuffer(DxfCodePairBufferReader buffer, DxfAcadVersion version) { var cls = new DxfClass(); // version R13 has varying values for the leading 0 code pair var pair = buffer.Peek(); Debug.Assert(pair.Code == 0); if (version <= DxfAcadVersion.R13) { cls.ClassDxfRecordName = pair.StringValue; } else { // swallow (0, CLASS) Debug.Assert(pair.StringValue == ClassText); } buffer.Advance(); while (buffer.ItemsRemain) { pair = buffer.Peek(); if (pair.Code == 0) { break; } buffer.Advance(); switch (pair.Code) { case 1: if (version <= DxfAcadVersion.R13) cls.CppClassName = pair.StringValue; else cls.ClassDxfRecordName = pair.StringValue; break; case 2: if (version <= DxfAcadVersion.R13) cls.ApplicationName = pair.StringValue; else cls.CppClassName = pair.StringValue; break; case 3: if (version >= DxfAcadVersion.R14) cls.ApplicationName = pair.StringValue; break; case 90: if (version <= DxfAcadVersion.R13) cls.ClassVersionNumber = pair.IntegerValue; else cls.ProxyCapabilities = new DxfProxyCapabilities(pair.IntegerValue); break; case 91: cls.InstanceCount = pair.IntegerValue; break; case 280: cls.WasClassLoadedWithFile = !DxfCommonConverters.BoolShort(pair.ShortValue); break; case 281: cls.IsEntity = DxfCommonConverters.BoolShort(pair.ShortValue); break; } } return cls; }
internal static DxfStyle FromBuffer(DxfCodePairBufferReader buffer) { var item = new DxfStyle(); while (buffer.ItemsRemain) { var pair = buffer.Peek(); if (pair.Code == 0) { break; } buffer.Advance(); switch (pair.Code) { case 70: item.StandardFlags = (int)pair.ShortValue; break; case DxfCodePairGroup.GroupCodeNumber: var groupName = DxfCodePairGroup.GetGroupName(pair.StringValue); item.ExtensionDataGroups.Add(DxfCodePairGroup.FromBuffer(buffer, groupName)); break; case 40: item.TextHeight = (pair.DoubleValue); break; case 41: item.WidthFactor = (pair.DoubleValue); break; case 50: item.ObliqueAngle = (pair.DoubleValue); break; case 71: item.TextGenerationFlags = (int)(pair.ShortValue); break; case 42: item.LastHeightUsed = (pair.DoubleValue); break; case 3: item.PrimaryFontFileName = (pair.StringValue); break; case 4: item.BigFontFileName = (pair.StringValue); break; case (int)DxfXDataType.ApplicationName: item.XData = DxfXData.FromBuffer(buffer, pair.StringValue); break; default: item.TrySetPair(pair); break; } } return item; }
internal static DxfDimStyle FromBuffer(DxfCodePairBufferReader buffer) { var item = new DxfDimStyle(); while (buffer.ItemsRemain) { var pair = buffer.Peek(); if (pair.Code == 0) { break; } buffer.Advance(); switch (pair.Code) { case 70: item.StandardFlags = (int)pair.ShortValue; break; case DxfCodePairGroup.GroupCodeNumber: var groupName = DxfCodePairGroup.GetGroupName(pair.StringValue); item.ExtensionDataGroups.Add(DxfCodePairGroup.FromBuffer(buffer, groupName)); break; case 3: item.DimensioningSuffix = (pair.StringValue); break; case 4: item.AlternateDimensioningSuffix = (pair.StringValue); break; case 5: item.ArrowBlockName = (pair.StringValue); break; case 6: item.FirstArrowBlockName = (pair.StringValue); break; case 7: item.SecondArrowBlockName = (pair.StringValue); break; case 40: item.DimensioningScaleFactor = (pair.DoubleValue); break; case 41: item.DimensioningArrowSize = (pair.DoubleValue); break; case 42: item.DimensionExtensionLineOffset = (pair.DoubleValue); break; case 43: item.DimensionLineIncrement = (pair.DoubleValue); break; case 44: item.DimensionExtensionLineExtension = (pair.DoubleValue); break; case 45: item.DimensionDistanceRoundingValue = (pair.DoubleValue); break; case 46: item.DimensionLineExtension = (pair.DoubleValue); break; case 47: item.DimensionPlusTolerance = (pair.DoubleValue); break; case 48: item.DimensionMinusTolerance = (pair.DoubleValue); break; case 140: item.DimensioningTextHeight = (pair.DoubleValue); break; case 141: item.CenterMarkSize = (pair.DoubleValue); break; case 142: item.DimensioningTickSize = (pair.DoubleValue); break; case 143: item.AlternateDimensioningScaleFactor = (pair.DoubleValue); break; case 144: item.DimensionLinearMeasurementScaleFactor = (pair.DoubleValue); break; case 145: item.DimensionVerticalTextPosition = (pair.DoubleValue); break; case 146: item.DimensionToleranceDisplacScaleFactor = (pair.DoubleValue); break; case 147: item.DimensionLineGap = (pair.DoubleValue); break; case 148: item.AlternateDimensioningUnitRounding = (pair.DoubleValue); break; case 71: item.GenerateDimensionTolerances = BoolShort(pair.ShortValue); break; case 72: item.GenerateDimensionLimits = BoolShort(pair.ShortValue); break; case 73: item.DimensionTextInsideHorizontal = BoolShort(pair.ShortValue); break; case 74: item.DimensionTextOutsideHorizontal = BoolShort(pair.ShortValue); break; case 75: item.SuppressFirstDimensionExtensionLine = BoolShort(pair.ShortValue); break; case 76: item.SuppressSecondDimensionExtensionLine = BoolShort(pair.ShortValue); break; case 77: item.TextAboveDimensionLine = BoolShort(pair.ShortValue); break; case 78: item.DimensionUnitZeroSuppression = (DxfUnitZeroSuppression)(pair.ShortValue); break; case 79: item.DimensionAngleZeroSuppression = (DxfUnitZeroSuppression)(pair.ShortValue); break; case 170: item.UseAlternateDimensioning = BoolShort(pair.ShortValue); break; case 171: item.AlternateDimensioningDecimalPlaces = (pair.ShortValue); break; case 172: item.ForceDimensionLineExtensionsOutsideIfTextExists = BoolShort(pair.ShortValue); break; case 173: item.UseSeparateArrowBlocksForDimensions = BoolShort(pair.ShortValue); break; case 174: item.ForceDimensionTextInsideExtensions = BoolShort(pair.ShortValue); break; case 175: item.SuppressOutsideExtensionDimensionLines = BoolShort(pair.ShortValue); break; case 176: item.DimensionLineColor = DxfColor.FromRawValue(pair.ShortValue); break; case 177: item.DimensionExtensionLineColor = DxfColor.FromRawValue(pair.ShortValue); break; case 178: item.DimensionTextColor = DxfColor.FromRawValue(pair.ShortValue); break; case 179: item.AngularDimensionPrecision = (pair.ShortValue); break; case 270: item.DimensionUnitFormat = (DxfUnitFormat)(pair.ShortValue); break; case 271: item.DimensionUnitToleranceDecimalPlaces = (pair.ShortValue); break; case 272: item.DimensionToleranceDecimalPlaces = (pair.ShortValue); break; case 273: item.AlternateDimensioningUnits = (DxfUnitFormat)(pair.ShortValue); break; case 274: item.AlternateDimensioningToleranceDecimalPlaces = (pair.ShortValue); break; case 275: item.DimensioningAngleFormat = (DxfAngleFormat)(pair.ShortValue); break; case 276: item.DimensionPrecision = (pair.ShortValue); break; case 277: item.DimensionNonAngularUnits = (DxfNonAngularUnits)(pair.ShortValue); break; case 278: item.DimensionDecimalSeparatorChar = (char)(pair.ShortValue); break; case 279: item.DimensionTextMovementRule = (DxfDimensionTextMovementRule)(pair.ShortValue); break; case 280: item.DimensionTextJustification = (DxfDimensionTextJustification)(pair.ShortValue); break; case 283: item.DimensionToleranceVerticalJustification = (DxfJustification)(pair.ShortValue); break; case 284: item.DimensionToleranceZeroSuppression = (DxfUnitZeroSuppression)(pair.ShortValue); break; case 285: item.AlternateDimensioningZeroSupression = (DxfUnitZeroSuppression)(pair.ShortValue); break; case 286: item.AlternateDimensioningToleranceZeroSupression = (DxfUnitZeroSuppression)(pair.ShortValue); break; case 287: item.DimensionTextAndArrowPlacement = (DxfDimensionFit)(pair.ShortValue); break; case 288: item.DimensionCursorControlsTextPosition = BoolShort(pair.ShortValue); break; case 289: item.DimensionTextAndArrowPlacement = (DxfDimensionFit)(pair.ShortValue); break; case 340: item.DimensionTextStyle = (pair.StringValue); break; case 341: item.DimensionLeaderBlockName = (pair.StringValue); break; case 342: item.ArrowBlockName = (pair.StringValue); break; case 343: item.FirstArrowBlockName = (pair.StringValue); break; case 344: item.SecondArrowBlockName = (pair.StringValue); break; case 371: item.DimensionLineWeight = DxfLineWeight.FromRawValue(pair.ShortValue); break; case 372: item.DimensionExtensionLineWeight = DxfLineWeight.FromRawValue(pair.ShortValue); break; case (int)DxfXDataType.ApplicationName: item.XData = DxfXData.FromBuffer(buffer, pair.StringValue); break; default: item.TrySetPair(pair); break; } } return item; }
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 DxfTable ReadFromBuffer(DxfCodePairBufferReader buffer) { var table = new DxfViewTable(); while (buffer.ItemsRemain) { var pair = buffer.Peek(); buffer.Advance(); if (DxfTablesSection.IsTableEnd(pair)) { break; } if (pair.Code == 0 && pair.StringValue == DxfTable.ViewText) { var item = DxfView.FromBuffer(buffer); table.Items.Add(item); } } return table; }
internal static DxfSectionGeometrySettings FromBuffer(DxfCodePairBufferReader buffer) { var stillReading = true; var settings = new DxfSectionGeometrySettings(); if (buffer.Peek()?.Code != 90) { // only code 90 can start one of these return(null); } while (buffer.ItemsRemain && stillReading) { var pair = buffer.Peek(); switch (pair.Code) { case 1: settings.PlotstyleName = pair.StringValue; break; case 2: settings.HatchPatternName = pair.StringValue; break; case 3: Debug.Assert(pair.StringValue == "SectionGeometrySettingsEnd"); stillReading = false; break; case 6: settings.LinetypeName = pair.StringValue; break; case 8: settings.LayerName = pair.StringValue; break; case 40: settings.LinetypeScale = pair.DoubleValue; break; case 41: settings.HatchAngle = pair.DoubleValue; break; case 42: settings.HatchScale = pair.DoubleValue; break; case 43: settings.HatchSpacing = pair.DoubleValue; break; case 63: settings.Color = DxfColor.FromRawValue(pair.ShortValue); break; case 70: settings.FaceTransparency = pair.ShortValue; break; case 71: settings.EdgeTransparency = pair.ShortValue; break; case 72: settings.HatchPatternType = pair.ShortValue; break; case 90: settings.SectionType = pair.IntegerValue; break; case 91: settings.GeometryCount = pair.IntegerValue; break; case 92: settings.BitFlags = pair.IntegerValue; break; case 370: settings.LineWeight = pair.ShortValue; break; default: // unexpected end, return immediately without consuming the code pair return(settings); } buffer.Advance(); } return(settings); }
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.UIntHandle(pair.StringValue)); buffer.Advance(); break; case 331: settings.DestinationObjectHandle = DxfCommonConverters.UIntHandle(pair.StringValue); buffer.Advance(); break; default: return(settings); } } return(settings); }
internal static DxfLineType FromBuffer(DxfCodePairBufferReader buffer) { var item = new DxfLineType(); while (buffer.ItemsRemain) { var pair = buffer.Peek(); if (pair.Code == 0) { break; } buffer.Advance(); switch (pair.Code) { case 70: item.StandardFlags = (int)pair.ShortValue; break; case DxfCodePairGroup.GroupCodeNumber: var groupName = DxfCodePairGroup.GetGroupName(pair.StringValue); item.ExtensionDataGroups.Add(DxfCodePairGroup.FromBuffer(buffer, groupName)); break; case 3: item.Description = (pair.StringValue); break; case 72: item.AlignmentCode = (pair.ShortValue); break; case 73: item.ElementCount = (pair.ShortValue); break; case 40: item.TotalPatternLength = (pair.DoubleValue); break; case 49: item.DashDotSpaceLengths.Add((pair.DoubleValue)); break; case 74: item.ComplexLinetypeElementTypes.Add((pair.ShortValue)); break; case 75: item.ShapeNumbers.Add((pair.ShortValue)); break; case 340: item.StylePointers.Add((pair.StringValue)); break; case 46: item.ScaleValues.Add((pair.DoubleValue)); break; case 50: item.RotationAngles.Add((pair.DoubleValue)); break; case 44: item.XOffsets.Add((pair.DoubleValue)); break; case 45: item.YOffsets.Add((pair.DoubleValue)); break; case 9: item.TextStrings.Add((pair.StringValue)); break; case (int)DxfXDataType.ApplicationName: item.XData = DxfXData.FromBuffer(buffer, pair.StringValue); break; default: item.TrySetPair(pair); break; } } return item; }
internal static void SwallowTable(DxfCodePairBufferReader buffer) { while (buffer.ItemsRemain) { var pair = buffer.Peek(); buffer.Advance(); if (DxfTablesSection.IsTableEnd(pair)) break; } }
internal static DxfUcs FromBuffer(DxfCodePairBufferReader buffer) { var item = new DxfUcs(); while (buffer.ItemsRemain) { var pair = buffer.Peek(); if (pair.Code == 0) { break; } buffer.Advance(); switch (pair.Code) { case 70: item.StandardFlags = (int)pair.ShortValue; break; case DxfCodePairGroup.GroupCodeNumber: var groupName = DxfCodePairGroup.GetGroupName(pair.StringValue); item.ExtensionDataGroups.Add(DxfCodePairGroup.FromBuffer(buffer, groupName)); break; case 10: item.Origin.X = (pair.DoubleValue); break; case 20: item.Origin.Y = (pair.DoubleValue); break; case 30: item.Origin.Z = (pair.DoubleValue); break; case 11: item.XAxis.X = (pair.DoubleValue); break; case 21: item.XAxis.Y = (pair.DoubleValue); break; case 31: item.XAxis.Z = (pair.DoubleValue); break; case 12: item.YAxis.X = (pair.DoubleValue); break; case 22: item.YAxis.Y = (pair.DoubleValue); break; case 32: item.YAxis.Z = (pair.DoubleValue); break; case 79: item.OrthographicViewType = (DxfOrthographicViewType)(pair.ShortValue); break; case 146: item.Elevation = (pair.DoubleValue); break; case 346: item.BaseUcsHandle = UIntHandle(pair.StringValue); break; case 71: item.OrthographicType = (DxfOrthographicViewType)(pair.ShortValue); break; case 13: item.OrthographicOrigin.X = (pair.DoubleValue); break; case 23: item.OrthographicOrigin.Y = (pair.DoubleValue); break; case 33: item.OrthographicOrigin.Z = (pair.DoubleValue); break; case (int)DxfXDataType.ApplicationName: item.XData = DxfXData.FromBuffer(buffer, pair.StringValue); break; default: item.TrySetPair(pair); break; } } return item; }
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.UIntHandle(common.StringValue); break; case 70: result.MaxEntries = common.ShortValue; break; case 330: result.OwnerHandle = DxfCommonConverters.UIntHandle(common.StringValue); break; } } result.ExtensionDataGroups.AddRange(groups); result.AfterRead(); } return result; }
internal static DxfView FromBuffer(DxfCodePairBufferReader buffer) { var item = new DxfView(); while (buffer.ItemsRemain) { var pair = buffer.Peek(); if (pair.Code == 0) { break; } buffer.Advance(); switch (pair.Code) { case 70: item.StandardFlags = (int)pair.ShortValue; break; case DxfCodePairGroup.GroupCodeNumber: var groupName = DxfCodePairGroup.GetGroupName(pair.StringValue); item.ExtensionDataGroups.Add(DxfCodePairGroup.FromBuffer(buffer, groupName)); break; case 40: item.ViewHeight = (pair.DoubleValue); break; case 10: item.ViewCenterPoint.X = (pair.DoubleValue); break; case 20: item.ViewCenterPoint.Y = (pair.DoubleValue); break; case 41: item.ViewWidth = (pair.DoubleValue); break; case 11: item.ViewDirection.X = (pair.DoubleValue); break; case 21: item.ViewDirection.Y = (pair.DoubleValue); break; case 31: item.ViewDirection.Z = (pair.DoubleValue); break; case 12: item.TargetPoint.X = (pair.DoubleValue); break; case 22: item.TargetPoint.Y = (pair.DoubleValue); break; case 32: item.TargetPoint.Z = (pair.DoubleValue); break; case 42: item.LensLength = (pair.DoubleValue); break; case 43: item.FrontClippingPlane = (pair.DoubleValue); break; case 44: item.BackClippingPlane = (pair.DoubleValue); break; case 50: item.TwistAngle = (pair.DoubleValue); break; case 71: item.ViewMode = (pair.ShortValue); break; case 281: item.RenderMode = (DxfViewRenderMode)(pair.ShortValue); break; case 72: item.IsAssociatedUCSPresent = BoolShort(pair.ShortValue); break; case 73: item.IsCameraPlottable = BoolShort(pair.ShortValue); break; case 332: item.BackgroundObjectPointer = UIntHandle(pair.StringValue); break; case 334: item.SelectionObjectPointer = UIntHandle(pair.StringValue); break; case 348: item.VisualStyleObjectPointer = UIntHandle(pair.StringValue); break; case 361: item.SunOwnershipPointer = UIntHandle(pair.StringValue); break; case 110: item.UCSOrigin.X = (pair.DoubleValue); break; case 120: item.UCSOrigin.Y = (pair.DoubleValue); break; case 130: item.UCSOrigin.Z = (pair.DoubleValue); break; case 111: item.UCSXAxis.X = (pair.DoubleValue); break; case 121: item.UCSXAxis.Y = (pair.DoubleValue); break; case 131: item.UCSXAxis.Z = (pair.DoubleValue); break; case 112: item.UCSYAxis.X = (pair.DoubleValue); break; case 122: item.UCSYAxis.Y = (pair.DoubleValue); break; case 132: item.UCSYAxis.Z = (pair.DoubleValue); break; case 79: item.OrthographicViewType = (DxfOrthographicViewType)(pair.ShortValue); break; case 146: item.UCSElevation = (pair.DoubleValue); break; case 345: item.UCSHandle = UIntHandle(pair.StringValue); break; case 346: item.BaseUCSHandle = UIntHandle(pair.StringValue); break; case (int)DxfXDataType.ApplicationName: item.XData = DxfXData.FromBuffer(buffer, pair.StringValue); break; default: item.TrySetPair(pair); break; } } return item; }
internal override DxfObject PopulateFromBuffer(DxfCodePairBufferReader buffer) { int code_280_index = 0; while (buffer.ItemsRemain) { var pair = buffer.Peek(); if (pair.Code == 0) { break; } while (this.TrySetExtensionData(pair, buffer)) { pair = buffer.Peek(); } switch (pair.Code) { case 3: this.Description = (pair.StringValue); buffer.Advance(); break; case 7: var style = DxfTableCellStyle.FromBuffer(buffer); CellStyles.Add(style); break; case 40: this.HorizontalCellMargin = (pair.DoubleValue); buffer.Advance(); break; case 41: this.VerticalCellMargin = (pair.DoubleValue); buffer.Advance(); break; case 70: this.FlowDirection = (DxfFlowDirection)(pair.ShortValue); buffer.Advance(); break; case 71: this.Flags = (pair.ShortValue); buffer.Advance(); break; case 280: switch (code_280_index) { case 0: this.Version = (DxfVersion)(pair.ShortValue); code_280_index++; break; case 1: this.IsTitleSuppressed = BoolShort(pair.ShortValue); code_280_index++; break; default: Debug.Assert(false, "Unexpected extra values for code 280"); break; } buffer.Advance(); break; case 281: this.IsColumnHeadingSuppressed = BoolShort(pair.ShortValue); buffer.Advance(); break; default: if (!base.TrySetPair(pair)) { ExcessCodePairs.Add(pair); } buffer.Advance(); break; } } return(PostParse()); }
internal static DxfBlockRecord FromBuffer(DxfCodePairBufferReader buffer) { var item = new DxfBlockRecord(); while (buffer.ItemsRemain) { var pair = buffer.Peek(); if (pair.Code == 0) { break; } buffer.Advance(); switch (pair.Code) { case DxfCodePairGroup.GroupCodeNumber: var groupName = DxfCodePairGroup.GetGroupName(pair.StringValue); item.ExtensionDataGroups.Add(DxfCodePairGroup.FromBuffer(buffer, groupName)); break; case 340: item.LayoutHandle = UIntHandle(pair.StringValue); break; case 70: item.InsertionUnits = (DxfUnits)(pair.ShortValue); break; case 280: item.Explodability = BoolShort(pair.ShortValue); break; case 281: item.Scalability = BoolShort(pair.ShortValue); break; case 310: item._bitmapPreviewData.Add((pair.StringValue)); break; case (int)DxfXDataType.ApplicationName: item.XData = DxfXData.FromBuffer(buffer, pair.StringValue); break; default: item.TrySetPair(pair); break; } } return item; }
internal static DxfLayer FromBuffer(DxfCodePairBufferReader buffer) { var item = new DxfLayer(); while (buffer.ItemsRemain) { var pair = buffer.Peek(); if (pair.Code == 0) { break; } buffer.Advance(); switch (pair.Code) { case 70: item.StandardFlags = (int)pair.ShortValue; break; case DxfCodePairGroup.GroupCodeNumber: var groupName = DxfCodePairGroup.GetGroupName(pair.StringValue); item.ExtensionDataGroups.Add(DxfCodePairGroup.FromBuffer(buffer, groupName)); break; case 62: item.Color = DxfColor.FromRawValue(pair.ShortValue); break; case 6: item.LinetypeName = (pair.StringValue); break; case 290: item.IsLayerPlotted = (pair.BoolValue); break; case 370: item.LineWeight = DxfLineWeight.FromRawValue(pair.ShortValue); break; case 390: item.PlotStylePointer = UIntHandle(pair.StringValue); break; case 347: item.MaterialHandle = UIntHandle(pair.StringValue); break; case (int)DxfXDataType.ApplicationName: item.XData = DxfXData.FromBuffer(buffer, pair.StringValue); break; default: item.TrySetPair(pair); break; } } return item; }
internal static DxfTableCellStyle FromBuffer(DxfCodePairBufferReader buffer) { var seenName = false; var style = new DxfTableCellStyle(); while (buffer.ItemsRemain) { var pair = buffer.Peek(); switch (pair.Code) { case 7: if (seenName) { // found another cell style; return without consuming return(style); } else { style.Name = pair.StringValue; seenName = true; } break; case 62: style.TextColor = DxfColor.FromRawValue(pair.ShortValue); break; case 63: style.CellFillColor = DxfColor.FromRawValue(pair.ShortValue); break; case 64: style.Border1Color = DxfColor.FromRawValue(pair.ShortValue); break; case 65: style.Border2Color = DxfColor.FromRawValue(pair.ShortValue); break; case 66: style.Border3Color = DxfColor.FromRawValue(pair.ShortValue); break; case 67: style.Border4Color = DxfColor.FromRawValue(pair.ShortValue); break; case 68: style.Border5Color = DxfColor.FromRawValue(pair.ShortValue); break; case 69: style.Border6Color = DxfColor.FromRawValue(pair.ShortValue); break; case 90: style.CellDataType = pair.IntegerValue; break; case 91: style.CellUnitType = pair.IntegerValue; break; case 140: style.TextHeight = pair.DoubleValue; break; case 170: style.CellAlignment = pair.ShortValue; break; case 274: style.BorderLineweight1 = pair.ShortValue; break; case 275: style.BorderLineweight2 = pair.ShortValue; break; case 276: style.BorderLineweight3 = pair.ShortValue; break; case 277: style.BorderLineweight4 = pair.ShortValue; break; case 278: style.BorderLineweight5 = pair.ShortValue; break; case 279: style.BorderLineweight6 = pair.ShortValue; break; case 283: style.IsBackgroundColorEnabled = DxfCommonConverters.BoolShort(pair.ShortValue); break; case 284: style.IsBorder1Visible = DxfCommonConverters.BoolShort(pair.ShortValue); break; case 285: style.IsBorder2Visible = DxfCommonConverters.BoolShort(pair.ShortValue); break; case 286: style.IsBorder3Visible = DxfCommonConverters.BoolShort(pair.ShortValue); break; case 287: style.IsBorder4Visible = DxfCommonConverters.BoolShort(pair.ShortValue); break; case 288: style.IsBorder5Visible = DxfCommonConverters.BoolShort(pair.ShortValue); break; case 289: style.IsBorder6Visible = DxfCommonConverters.BoolShort(pair.ShortValue); break; default: // unknown code, return without consuming the pair return(style); } buffer.Advance(); } return(style); }