Skip to content

Commit

Permalink
handle fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Dec 29, 2024
1 parent 15f7888 commit 0eb0d69
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
22 changes: 22 additions & 0 deletions src/ACadSharp.Tests/IO/WriterSingleObjectTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ACadSharp.Entities;
using ACadSharp.Objects;
using ACadSharp.Tables;
using ACadSharp.XData;
using CSMath;
using CSUtilities.Extensions;
using System;
Expand Down Expand Up @@ -468,6 +469,26 @@ public void AddBlockWithAttributes()
this.Document.Entities.Add(insert);
}

public void XData()
{
AppId app = new AppId("my_app");
this.Document.AppIds.Add(app);

Line line = new Line(XYZ.Zero, new XYZ(100, 100, 0));

List<ExtendedDataRecord> records = new();
records.Add(new ExtendedDataControlString(false));
records.Add(new ExtendedDataInteger16(5));
records.Add(new ExtendedDataString("my extended data string"));
//records.Add(new ExtendedDataBinaryChunk(new byte[] { 1, 2, 3, 4 }));
records.Add(new ExtendedDataControlString(true));

line.ExtendedData.Add(app, records);

this.Document.Entities.Add(line);
}


public void Deserialize(IXunitSerializationInfo info)
{
this.Name = info.GetValue<string>(nameof(this.Name));
Expand Down Expand Up @@ -525,6 +546,7 @@ static WriterSingleObjectTests()
Data.Add(new(nameof(SingleCaseGenerator.AddCustomScale)));
Data.Add(new(nameof(SingleCaseGenerator.AddCustomBookColor)));
Data.Add(new(nameof(SingleCaseGenerator.Dimensions)));
Data.Add(new(nameof(SingleCaseGenerator.XData)));
}

protected string getPath(string name, string ext, ACadVersion version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public void WriteShiftValue()

public void WriteBytes(byte[] bytes, int offset, int length)
{
throw new NotImplementedException();
this.Main.WriteBytes(bytes, offset, length);
}

public void WriteEnColor(Color color, Transparency transparency, bool isBookColor)
Expand Down
15 changes: 9 additions & 6 deletions src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,13 @@ private void writeExtendedDataEntry(AppId app, ExtendedData entry)

switch (record)
{
case ExtendedDataBinaryChunk binaryChunk:
mstream.WriteByte((byte)binaryChunk.Value.Length);
mstream.Write(binaryChunk.Value, 0, binaryChunk.Value.Length);
break;
case ExtendedDataInteger16 s16:
mstream.Write(LittleEndianConverter.Instance.GetBytes(s16.Value), 0, 2);
break;
case ExtendedDataString str:
//same as ReadTextUnicode()
if (this.R2007Plus)
Expand All @@ -373,20 +380,16 @@ private void writeExtendedDataEntry(AppId app, ExtendedData entry)
case ExtendedDataControlString control:
mstream.WriteByte((byte)(control.Value == '}' ? 1 : 0));
break;
case ExtendedDataBinaryChunk binaryChunk:
mstream.WriteByte((byte)binaryChunk.Value.Length);
mstream.Write(binaryChunk.Value, 0, binaryChunk.Value.Length);
break;
default:
throw new System.Exception();
}
}

this._writer.WriteBitShort((short)mstream.Length);

this._writer.HandleReference(DwgReferenceType.HardPointer, app.Handle);
this._writer.Main.HandleReference(DwgReferenceType.HardPointer, app.Handle);

this._writer.WriteBytes(mstream.GetBuffer());
this._writer.WriteBytes(mstream.GetBuffer(), 0, (int)mstream.Length);
}
}

Expand Down

0 comments on commit 0eb0d69

Please sign in to comment.