Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dwg writer Objects #180

Merged
merged 22 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ACadSharp.Tests/Common/Factory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private static CadObject createObject(Type type, Type original, bool randomize)
return null;
}

if (type == typeof(XRecrod)
if (type == typeof(XRecord)
|| type == typeof(PlotSettings)
|| type == typeof(Material)
|| type == typeof(MLStyle)
Expand Down
3 changes: 1 addition & 2 deletions ACadSharp.Tests/IO/DWG/DwgWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ static DwgWriterTests()
[MemberData(nameof(Versions))]
public void WriteEmptyTest(ACadVersion version)
{
string path = Path.Combine(_samplesOutFolder, $"out_empty_sample_{version}.dwg");
CadDocument doc = new CadDocument();
doc.Header.Version = version;

string path = Path.Combine(_samplesOutFolder, $"out_empty_sample_{version}.dwg");

using (var wr = new DwgWriter(path, doc))
{
if (isSupportedVersion(version))
Expand Down
44 changes: 24 additions & 20 deletions ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4033,7 +4033,7 @@ private CadTemplate readGroup()
//Numhandles BL # objhandles in this group
int numhandles = this._objectReader.ReadBitLong();
for (int index = 0; index < numhandles; ++index)
//Handle refs H parenthandle (soft pointer)
//the entries in the group(hard pointer)
template.Handles.Add(this.handleReference());

return template;
Expand Down Expand Up @@ -4103,12 +4103,16 @@ 1024 512

//R2018+:
if (this.R2018Plus)
{
//Line type handle H Line type handle (hard pointer)
elementTemplate.LinetypeHandle = this.handleReference();
}
//Before R2018:
else
{
//Ltindex BS Linetype index (yes, index)
elementTemplate.LinetypeIndex = this._objectReader.ReadBitShort();
}

template.ElementTemplates.Add(elementTemplate);
mlineStyle.Elements.Add(element);
Expand Down Expand Up @@ -4601,7 +4605,7 @@ private CadTemplate readWipeout()

private CadTemplate readXRecord()
{
XRecrod xRecord = new XRecrod();
XRecord xRecord = new XRecord();
CadXRecordTemplate template = new CadXRecordTemplate(xRecord);

this.readCommonNonEntityData(template);
Expand Down Expand Up @@ -4630,36 +4634,36 @@ private CadTemplate readXRecord()
case GroupCodeValueType.None:
break;
case GroupCodeValueType.String:
xRecord.Entries.Add(new XRecrod.Entry(code, this._objectReader.ReadTextUnicode()));
xRecord.Entries.Add(new XRecord.Entry(code, this._objectReader.ReadTextUnicode()));
break;
case GroupCodeValueType.Point3D:
xRecord.Entries.Add(new XRecrod.Entry(code,
xRecord.Entries.Add(new XRecord.Entry(code,
new XYZ(
this._objectReader.ReadDouble(),
this._objectReader.ReadDouble(),
this._objectReader.ReadDouble()
)));
break;
case GroupCodeValueType.Double:
xRecord.Entries.Add(new XRecrod.Entry(code, this._objectReader.ReadDouble()));
xRecord.Entries.Add(new XRecord.Entry(code, this._objectReader.ReadDouble()));
break;
case GroupCodeValueType.Int16:
xRecord.Entries.Add(new XRecrod.Entry(code, this._objectReader.ReadShort()));
xRecord.Entries.Add(new XRecord.Entry(code, this._objectReader.ReadShort()));
break;
case GroupCodeValueType.Int32:
xRecord.Entries.Add(new XRecrod.Entry(code, this._objectReader.ReadRawLong()));
xRecord.Entries.Add(new XRecord.Entry(code, this._objectReader.ReadRawLong()));
break;
case GroupCodeValueType.Int64:
xRecord.Entries.Add(new XRecrod.Entry(code, this._objectReader.ReadRawLong()));
xRecord.Entries.Add(new XRecord.Entry(code, this._objectReader.ReadRawLong()));
break;
case GroupCodeValueType.Handle:
xRecord.Entries.Add(new XRecrod.Entry(code, this._objectReader.ReadTextUnicode()));
xRecord.Entries.Add(new XRecord.Entry(code, this._objectReader.ReadTextUnicode()));
break;
case GroupCodeValueType.Bool:
xRecord.Entries.Add(new XRecrod.Entry(code, this._objectReader.ReadByte() > 0));
xRecord.Entries.Add(new XRecord.Entry(code, this._objectReader.ReadByte() > 0));
break;
case GroupCodeValueType.Chunk:
xRecord.Entries.Add(new XRecrod.Entry(code, this._objectReader.ReadBytes(this._objectReader.ReadByte())));
xRecord.Entries.Add(new XRecord.Entry(code, this._objectReader.ReadBytes(this._objectReader.ReadByte())));
break;
default:
break;
Expand All @@ -4668,8 +4672,10 @@ private CadTemplate readXRecord()

//R2000+:
if (this.R2000Plus)
{
//Cloning flag BS 280
xRecord.ClonningFlags = (DictionaryCloningFlags)this._objectReader.ReadBitShort();
}

long size = this._objectInitialPos + (long)(this._size * 8U) - 7L;
while (this._handlesReader.PositionInBits() < size)
Expand Down Expand Up @@ -4815,9 +4821,9 @@ private void readPlotSettings(PlotSettings plot)
plot.PaperSize = this._textReader.ReadVariableText();

//Plot origin 2BD 46,47 plotsettings origin offset in millimeters
var plotOrigin = this._objectReader.Read2BitDouble();
plot.PlotOriginX = plotOrigin.X;
plot.PlotOriginY = plotOrigin.Y;
plot.PlotOriginX = this._objectReader.ReadBitDouble();
plot.PlotOriginY = this._objectReader.ReadBitDouble();

//Paper units BS 72 plotsettings plot paper units
plot.PaperUnits = (PlotPaperUnits)this._objectReader.ReadBitShort();
//Plot rotation BS 73 plotsettings plot rotation
Expand All @@ -4826,13 +4832,11 @@ private void readPlotSettings(PlotSettings plot)
plot.PlotType = (PlotType)this._objectReader.ReadBitShort();

//Window min 2BD 48,49 plotsettings plot window area lower left
var windowLowerLeft = this._objectReader.Read2BitDouble();
plot.WindowLowerLeftX = windowLowerLeft.X;
plot.WindowLowerLeftY = windowLowerLeft.Y;
plot.WindowLowerLeftX = this._objectReader.ReadBitDouble();
plot.WindowLowerLeftY = this._objectReader.ReadBitDouble();
//Window max 2BD 140,141 plotsettings plot window area upper right
var windowUpperLeft = this._objectReader.Read2BitDouble();
plot.WindowUpperLeftX = windowUpperLeft.X;
plot.WindowUpperLeftY = windowUpperLeft.Y;
plot.WindowUpperLeftX = this._objectReader.ReadBitDouble();
plot.WindowUpperLeftY = this._objectReader.ReadBitDouble();

//R13 - R2000 Only:
if (this._version >= ACadVersion.AC1012 && this._version <= ACadVersion.AC1015)
Expand Down
21 changes: 15 additions & 6 deletions ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ namespace ACadSharp.IO.DWG
{
internal partial class DwgObjectWriter : DwgSectionIO
{
public override string SectionName => DwgSectionDefinition.AcDbObjects;

private void registerObject(CadObject cadObject)
{
this._writer.WriteSpearShift();
Expand Down Expand Up @@ -324,7 +322,7 @@ private void writeExtendedData(ExtendedDataDictionary data)

private void writeReactorsAndDictionaryHandle(CadObject cadObject)
{
//TODO: Write reactors and dictionary
//TODO: Write reactors

//Numreactors S number of reactors in this object
this._writer.WriteBitLong(0);
Expand All @@ -333,12 +331,17 @@ private void writeReactorsAndDictionaryHandle(CadObject cadObject)
// //[Reactors (soft pointer)]
// template.CadObject.Reactors.Add(this.handleReference(), null);

bool noDictionary = cadObject.XDictionary == null;

//R2004+:
if (this.R2004Plus)
{
_writer.WriteBit(true);
//_writer.WriteBit(cadObject.XDictionary == null);
//this._writer.HandleReference(DwgReferenceType.HardOwnership, cadObject.XDictionary);

this._writer.WriteBit(noDictionary);
if (!noDictionary)
{
this._writer.HandleReference(DwgReferenceType.HardOwnership, cadObject.XDictionary);
}
}
else
{
Expand All @@ -352,6 +355,12 @@ private void writeReactorsAndDictionaryHandle(CadObject cadObject)
//Has DS binary data B If 1 then this object has associated binary data stored in the data store
this._writer.WriteBit(false);
}

if (!noDictionary)
{
_dictionaries.Add(cadObject.XDictionary.Handle, cadObject.XDictionary);
_objects.Enqueue(cadObject.XDictionary);
}
}

private byte getEntMode(Entity entity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ private void writeEntity(Entity entity)
case MText:
//Unlisted
case Wipeout:
this.notify($"Entity type not implemented {entity.GetType().FullName}", NotificationType.NotImplemented);
return;
}

Expand Down
Loading