Skip to content

Commit

Permalink
xdata dwg fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Jan 11, 2025
1 parent c023e93 commit 0669593
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/ACadSharp.Tests/IO/WriterSingleObjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,12 @@ public void XData()
records.Add(new ExtendedDataInteger32(33));
records.Add(new ExtendedDataString("my extended data string"));
records.Add(new ExtendedDataHandle(5));
records.Add(new ExtendedDataReal(25.35));
records.Add(new ExtendedDataScale(0.66));
records.Add(new ExtendedDataDistance(481.48));
records.Add(new ExtendedDataDirection(new XYZ(4, 3, 2)));
records.Add(new ExtendedDataCoordinate(new XYZ(8, 7, 4)));
records.Add(new ExtendedDataWorldCoordinate(new XYZ(85, 74, 47)));
records.Add(new ExtendedDataLayer(layer.Handle));
records.Add(new ExtendedDataBinaryChunk(new byte[] { 1, 2, 3, 4 }));
records.Add(new ExtendedDataControlString(true));
Expand Down
12 changes: 9 additions & 3 deletions src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,13 @@ private void writeEntityMode(Entity entity)

private void writeExtendedData(ExtendedDataDictionary data)
{
//EED size BS size of extended entity data, if any
foreach (var item in data.Entries)
if (this.WriteXData)
{
writeExtendedDataEntry(item.Key, item.Value);
//EED size BS size of extended entity data, if any
foreach (var item in data.Entries)
{
writeExtendedDataEntry(item.Key, item.Value);
}
}

this._writer.WriteBitShort(0);
Expand Down Expand Up @@ -364,6 +367,9 @@ private void writeExtendedDataEntry(AppId app, ExtendedData entry)
case ExtendedDataInteger32 s32:
mstream.Write(LittleEndianConverter.Instance.GetBytes(s32.Value), 0, 4);
break;
case ExtendedDataReal real:
mstream.Write(LittleEndianConverter.Instance.GetBytes(real.Value), 0, 8);
break;
case ExtendedDataScale scale:
mstream.Write(LittleEndianConverter.Instance.GetBytes(scale.Value), 0, 8);
break;
Expand Down
5 changes: 4 additions & 1 deletion src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ internal partial class DwgObjectWriter : DwgSectionIO

public bool WriteXRecords { get; }

public bool WriteXData { get; }

private Dictionary<ulong, CadDictionary> _dictionaries = new();

private Queue<CadObject> _objects = new();
Expand All @@ -40,14 +42,15 @@ internal partial class DwgObjectWriter : DwgSectionIO

private Entity _next;

public DwgObjectWriter(Stream stream, CadDocument document, Encoding encoding, bool writeXRecords = true) : base(document.Header.Version)
public DwgObjectWriter(Stream stream, CadDocument document, Encoding encoding, bool writeXRecords = true, bool writeXData = true) : base(document.Header.Version)
{
this._stream = stream;
this._document = document;

this._msmain = new MemoryStream();
this._writer = DwgStreamWriterBase.GetMergedWriter(document.Header.Version, this._msmain, encoding);
this.WriteXRecords = writeXRecords;
this.WriteXData = writeXData;
}

public void Write()
Expand Down
7 changes: 6 additions & 1 deletion src/ACadSharp/IO/DWG/DwgWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,12 @@ private void writeRevHistory()
private void writeObjects()
{
MemoryStream stream = new MemoryStream();
DwgObjectWriter writer = new DwgObjectWriter(stream, this._document, this._encoding, this.Configuration.WriteXRecords);
DwgObjectWriter writer = new DwgObjectWriter(
stream,
this._document,
this._encoding,
this.Configuration.WriteXRecords,
this.Configuration.WriteXData);
writer.OnNotification += this.triggerNotification;
writer.Write();

Expand Down

0 comments on commit 0669593

Please sign in to comment.