From 796c317f7506443a93e2189d7965d910419cd43c Mon Sep 17 00:00:00 2001 From: DomCR Date: Fri, 6 Dec 2024 10:17:37 +0100 Subject: [PATCH] dxf improve --- src/ACadSharp.Tests/IO/TableEntityTests.cs | 2 +- src/ACadSharp/Entities/TableEntity.Cell.cs | 2 +- .../Entities/TableEntity.CellValue.cs | 34 ++++++++++++++++++- .../DwgObjectReader.Entities.cs | 2 +- .../DxfStreamReader/DxfSectionReaderBase.cs | 33 +++++++++++++++++- .../IO/Templates/CadTableEntityTemplate.cs | 2 ++ 6 files changed, 70 insertions(+), 5 deletions(-) diff --git a/src/ACadSharp.Tests/IO/TableEntityTests.cs b/src/ACadSharp.Tests/IO/TableEntityTests.cs index 3e4816d8..4ed8ed61 100644 --- a/src/ACadSharp.Tests/IO/TableEntityTests.cs +++ b/src/ACadSharp.Tests/IO/TableEntityTests.cs @@ -43,7 +43,7 @@ public void ReadTableEntity(FileModel test) //First row TableEntity.Cell titleCell = table.GetCell(0, 0); Assert.False(titleCell.HasMultipleContent); - Assert.Equal("Hello this is a title", titleCell.Content.Value.FormatedValue); + Assert.Equal("Hello this is a title", titleCell.Content.Value.Value); TableEntity.Cell next = table.GetCell(0, 1); } diff --git a/src/ACadSharp/Entities/TableEntity.Cell.cs b/src/ACadSharp/Entities/TableEntity.Cell.cs index ba182e4a..a3c56aa4 100644 --- a/src/ACadSharp/Entities/TableEntity.Cell.cs +++ b/src/ACadSharp/Entities/TableEntity.Cell.cs @@ -104,7 +104,7 @@ public CellContent Content } else { - return this.Contents.First(); + return this.Contents.FirstOrDefault(); } } } diff --git a/src/ACadSharp/Entities/TableEntity.CellValue.cs b/src/ACadSharp/Entities/TableEntity.CellValue.cs index 0a54be3f..c9c6fc1c 100644 --- a/src/ACadSharp/Entities/TableEntity.CellValue.cs +++ b/src/ACadSharp/Entities/TableEntity.CellValue.cs @@ -4,11 +4,43 @@ namespace ACadSharp.Entities { public partial class TableEntity { + public enum ValueUnitType + { + /// + /// No units. + /// + NoUnits = 0, + /// + /// Distance. + /// + Distance = 1, + /// + /// Angle. + /// + Angle = 2, + /// + /// Area. + /// + Area = 4, + /// + /// Volumne. + /// + Volume = 8, + /// + /// Currency. + /// + Currency = 0x10, + /// + /// Percentage. + /// + Percentage = 0x20 + } + public class CellValue { public CellValueType ValueType { get; set; } - public int Units { get; set; } + public ValueUnitType Units { get; set; } public int Flags { get; set; } diff --git a/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.Entities.cs b/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.Entities.cs index 980448c8..42e544c6 100644 --- a/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.Entities.cs +++ b/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.Entities.cs @@ -354,7 +354,7 @@ private void readCustomTableDataValue(CellValue value) if (this.R2007Plus) { //Unit type BL 94 0 = no units, 1 = distance, 2 = angle, 4 = area, 8 = volume - value.Units = this._mergedReaders.ReadBitLong(); + value.Units = (ValueUnitType)this._mergedReaders.ReadBitLong(); //Format String TV 300 value.Format = this._mergedReaders.ReadVariableText(); //Value String TV 302 diff --git a/src/ACadSharp/IO/DXF/DxfStreamReader/DxfSectionReaderBase.cs b/src/ACadSharp/IO/DXF/DxfStreamReader/DxfSectionReaderBase.cs index f6b306c9..0cc194c6 100644 --- a/src/ACadSharp/IO/DXF/DxfStreamReader/DxfSectionReaderBase.cs +++ b/src/ACadSharp/IO/DXF/DxfStreamReader/DxfSectionReaderBase.cs @@ -354,9 +354,15 @@ private bool readTableEntity(CadEntityTemplate template, DxfMap map, string subc col.Width = this._reader.ValueAsDouble; table.Columns.Add(col); return true; + case 144: + tmp.CurrentCellTemplate.FormatTextHeight = this._reader.ValueAsDouble; + return true; case 145: tmp.CurrentCell.Rotation = this._reader.ValueAsDouble; return true; + case 170: + //Has data flag + return true; case 171: tmp.CreateCell((TableEntity.CellType)this._reader.ValueAsInt); return true; @@ -378,6 +384,9 @@ private bool readTableEntity(CadEntityTemplate template, DxfMap map, string subc case 178: tmp.CurrentCell.VirtualEdgeFlag = this._reader.ValueAsShort; return true; + case 179: + //Unknown value + return true; case 301: var content = new TableEntity.CellContent(); tmp.CurrentCell.Contents.Add(content); @@ -417,15 +426,37 @@ private void readCellValue(TableEntity.CellContent content) case 2: content.Value.Text += this._reader.ValueAsString; break; + case 11: + content.Value.Value = new XYZ(this._reader.ValueAsDouble, 0, 0); + break; + case 21: + content.Value.Value = new XYZ(0, this._reader.ValueAsDouble, 0); + break; + case 31: + content.Value.Value = new XYZ(0, 0, this._reader.ValueAsDouble); + break; case 302: //TODO: Fix this assignation to cell value content.Value.Value = this._reader.ValueAsString; break; - //TODO: Find this codes case 90: + content.Value.ValueType = (TableEntity.CellValueType)this._reader.ValueAsInt; + break; + case 91: + content.Value.Value = this._reader.ValueAsInt; + break; case 93: + content.Value.Flags = this._reader.ValueAsInt; + break; case 94: + content.Value.Units = (TableEntity.ValueUnitType)this._reader.ValueAsInt; + break; + case 140: + content.Value.Value = this._reader.ValueAsDouble; + break; case 300: + content.Value.Format = this._reader.ValueAsString; + break; default: this._builder.Notify($"[CELL_VALUE] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None); break; diff --git a/src/ACadSharp/IO/Templates/CadTableEntityTemplate.cs b/src/ACadSharp/IO/Templates/CadTableEntityTemplate.cs index c03da389..70c3f99b 100644 --- a/src/ACadSharp/IO/Templates/CadTableEntityTemplate.cs +++ b/src/ACadSharp/IO/Templates/CadTableEntityTemplate.cs @@ -74,6 +74,8 @@ internal class CadTableCellTemplate : ICadTemplate public int StyleId { get; internal set; } + public double? FormatTextHeight { get; set; } + public TableEntity.Cell Cell { get; } public List ContentTemplates { get; } = new();