From a74b22a76d4d08e4ea150ba73baccd2e2462bd3e Mon Sep 17 00:00:00 2001 From: AutoCAD_CSharpLib Date: Tue, 16 May 2023 18:06:55 +0200 Subject: [PATCH 1/2] block fix --- ACadSharp/Blocks/Block.cs | 4 +- ACadSharp/IO/CadDocumentBuilder.cs | 7 +++ .../DxfStreamReader/DxfBlockSectionReader.cs | 54 ++++++++++++++++++- 3 files changed, 62 insertions(+), 3 deletions(-) diff --git a/ACadSharp/Blocks/Block.cs b/ACadSharp/Blocks/Block.cs index eba764a..0d9ffa3 100644 --- a/ACadSharp/Blocks/Block.cs +++ b/ACadSharp/Blocks/Block.cs @@ -33,8 +33,8 @@ public class Block : Entity, INamedCadObject [DxfCodeValue(2, 3)] public string Name { - get { return BlockOwner.Name; } - set { BlockOwner.Name = value; } + get { return this.BlockOwner.Name; } + set { this.BlockOwner.Name = value; } } /// diff --git a/ACadSharp/IO/CadDocumentBuilder.cs b/ACadSharp/IO/CadDocumentBuilder.cs index 77b1b73..672fcdc 100644 --- a/ACadSharp/IO/CadDocumentBuilder.cs +++ b/ACadSharp/IO/CadDocumentBuilder.cs @@ -91,6 +91,13 @@ public bool TryGetCadObject(ulong? handle, out T value) where T : CadObject return false; } + public bool TryGetTableEntry(string name, out T entry) + where T : TableEntry + { + entry = cadObjects.Values.OfType().FirstOrDefault(e => e.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)); + return entry != null; + } + public T GetObjectTemplate(ulong handle) where T : CadTemplate { if (this.templates.TryGetValue(handle, out CadTemplate builder)) diff --git a/ACadSharp/IO/DXF/DxfStreamReader/DxfBlockSectionReader.cs b/ACadSharp/IO/DXF/DxfStreamReader/DxfBlockSectionReader.cs index 1669cb1..b007717 100644 --- a/ACadSharp/IO/DXF/DxfStreamReader/DxfBlockSectionReader.cs +++ b/ACadSharp/IO/DXF/DxfStreamReader/DxfBlockSectionReader.cs @@ -3,9 +3,11 @@ using ACadSharp.Exceptions; using ACadSharp.IO.Templates; using ACadSharp.Tables; +using CSMath; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Net; namespace ACadSharp.IO.DXF { @@ -65,6 +67,7 @@ private void readBlock() } else { + blckEntity = new Block(); this._builder.Notify($"Block Record {ownerHandle} not found for Block {handle} | {name}", NotificationType.Warning); } @@ -81,7 +84,8 @@ private void readBlock() Debug.Assert(this._reader.LastValueAsString == DxfSubclassMarker.BlockBegin); - this.readMapped(blckEntity, template); + //this.readMapped(blckEntity, template); + this.readBlockBegin(blckEntity); if (record == null && this._builder.DocumentToBuild.BlockRecords.TryGetValue(blckEntity.Name, out record)) { @@ -124,6 +128,54 @@ private void readBlock() this._builder.AddTemplate(template); } + private void readBlockBegin(Block blckEntity) + { + this._reader.ReadNext(); + + while (this._reader.LastDxfCode != DxfCode.Start + && this._reader.LastDxfCode != DxfCode.Subclass) + { + switch (this._reader.LastCode) + { + case 1: + blckEntity.XrefPath = this._reader.LastValueAsString; + break; + case 4: + blckEntity.Comments = this._reader.LastValueAsString; + break; + case 2: + case 3: + if (blckEntity.Owner == null && this._builder.TryGetTableEntry(this._reader.LastValueAsString, out BlockRecord record)) + { + record.BlockEntity = blckEntity; + this._builder.Notify($"Block record find by name {blckEntity.Name}", NotificationType.None); + } + else if (blckEntity.Owner == null) + { + throw new DxfException($"Could not find the block record for {blckEntity.Name} and handle {blckEntity.Handle}"); + } + break; + case 70: + blckEntity.Flags = (BlockTypeFlags)this._reader.LastValueAsShort; + break; + case 10: + blckEntity.BasePoint = new XYZ(this._reader.LastValueAsDouble, blckEntity.BasePoint.Y, blckEntity.BasePoint.Z); + break; + case 20: + blckEntity.BasePoint = new XYZ(blckEntity.BasePoint.X, this._reader.LastValueAsDouble, blckEntity.BasePoint.Z); + break; + case 30: + blckEntity.BasePoint = new XYZ(blckEntity.BasePoint.X, blckEntity.BasePoint.Y, this._reader.LastValueAsDouble); + break; + default: + this._builder.Notify($"Unhandeled dxf code : {this._reader.LastCode} with value : {this._reader.LastValue} for subclass {DxfSubclassMarker.BlockBegin}"); + break; + } + + this._reader.ReadNext(); + } + } + private void readBlockEnd(BlockEnd block) { CadEntityTemplate template = new CadEntityTemplate(block); From 7a7b4f17d850f6266a095defd57140721c51a2b6 Mon Sep 17 00:00:00 2001 From: AutoCAD_CSharpLib Date: Tue, 16 May 2023 18:07:33 +0200 Subject: [PATCH 2/2] suppress messages --- ACadSharp/IO/DXF/DxfReader.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ACadSharp/IO/DXF/DxfReader.cs b/ACadSharp/IO/DXF/DxfReader.cs index bd48eda..43d7ab3 100644 --- a/ACadSharp/IO/DXF/DxfReader.cs +++ b/ACadSharp/IO/DXF/DxfReader.cs @@ -177,7 +177,9 @@ public override CadHeader ReadHeader() if (this._reader.LastValueAsString == null || !headerMap.TryGetValue(currVar, out var data)) { +#if TEST this.triggerNotification($"Header variable not implemented {currVar}", NotificationType.NotImplemented); +#endif this._reader.ReadNext(); continue; }