Skip to content

Commit

Permalink
dxf improve
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Dec 6, 2024
1 parent 81da939 commit 796c317
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/ACadSharp.Tests/IO/TableEntityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ACadSharp/Entities/TableEntity.Cell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public CellContent Content
}
else
{
return this.Contents.First();
return this.Contents.FirstOrDefault();
}
}
}
Expand Down
34 changes: 33 additions & 1 deletion src/ACadSharp/Entities/TableEntity.CellValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,43 @@ namespace ACadSharp.Entities
{
public partial class TableEntity
{
public enum ValueUnitType
{
/// <summary>
/// No units.
/// </summary>
NoUnits = 0,
/// <summary>
/// Distance.
/// </summary>
Distance = 1,
/// <summary>
/// Angle.
/// </summary>
Angle = 2,
/// <summary>
/// Area.
/// </summary>
Area = 4,
/// <summary>
/// Volumne.
/// </summary>
Volume = 8,
/// <summary>
/// Currency.
/// </summary>
Currency = 0x10,
/// <summary>
/// Percentage.
/// </summary>
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; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 32 additions & 1 deletion src/ACadSharp/IO/DXF/DxfStreamReader/DxfSectionReaderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/ACadSharp/IO/Templates/CadTableEntityTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CadTableCellContentTemplate> ContentTemplates { get; } = new();
Expand Down

0 comments on commit 796c317

Please sign in to comment.