Skip to content

Commit

Permalink
Merge pull request #510 from DomCR/dict-w-default-fix
Browse files Browse the repository at this point in the history
Dictionary with def & blocks
  • Loading branch information
DomCR authored Dec 16, 2024
2 parents b3a0f21 + 83da807 commit bd749b5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3654,7 +3654,7 @@ private CadTemplate readBlockHeader()

//Common:
//Entry name TV 2
//Warning: names ended with a number are not readed in this method
//Warning: anonymous blocks do not write the full name, only *{type character}
string name = this._textReader.ReadVariableText();
if (name.Equals(BlockRecord.ModelSpaceName, System.StringComparison.CurrentCultureIgnoreCase) ||
name.Equals(BlockRecord.PaperSpaceName, System.StringComparison.CurrentCultureIgnoreCase))
Expand Down
30 changes: 24 additions & 6 deletions src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Objects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using CSUtilities.Converters;
using CSUtilities.IO;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

Expand Down Expand Up @@ -152,8 +153,25 @@ private void writeCadDictionaryWithDefault(CadDictionaryWithDefault dictionary)
private void writeDictionary(CadDictionary dictionary)
{
//Common:
//Numitems L number of dictonary items
this._writer.WriteBitLong(dictionary.Count());
//Numitems L number of dictionary items
List<NonGraphicalObject> entries = new List<NonGraphicalObject>();
foreach (var item in dictionary)
{
if (item is XRecord && !this.WriteXRecords)
{
continue;
}

if (item is UnknownNonGraphicalObject)
{
continue;
}

entries.Add(item);
}

//16
this._writer.WriteBitLong(entries.Count);

//R14 Only:
if (this._version == ACadVersion.AC1014)
Expand All @@ -171,16 +189,16 @@ private void writeDictionary(CadDictionary dictionary)
}

//Common:
foreach (var item in dictionary)
foreach (var item in entries)
{
if (item is XRecord && !this.WriteXRecords)
{
return;
continue;
}

if (item is UnknownNonGraphicalObject)
{
return;
continue;
}

this._writer.WriteVariableText(item.Name);
Expand Down Expand Up @@ -730,4 +748,4 @@ private void writeXRecord(XRecord xrecord)

}
}
}
}
11 changes: 9 additions & 2 deletions src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,15 @@ private void writeBlockHeader(BlockRecord record)

//Common:
//Entry name TV 2
//Warning: names ended with a number are not readed in this method
this._writer.WriteVariableText(record.Name);
if (record.Flags.HasFlag(BlockTypeFlags.Anonymous))
{
//Warning: anonymous blocks do not write the full name, only *{type character}
this._writer.WriteVariableText(record.Name.Substring(0, 2));
}
else
{
this._writer.WriteVariableText(record.Name);
}

this.writeXrefDependantBit(record);

Expand Down
5 changes: 4 additions & 1 deletion src/ACadSharp/Objects/CadDictionaryWithDefault.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ namespace ACadSharp.Objects
[DxfSubClass(DxfSubclassMarker.DictionaryWithDefault)]
public class CadDictionaryWithDefault : CadDictionary
{
/// <inheritdoc/>
public override ObjectType ObjectType { get { return ObjectType.UNLISTED; } }

public override string ObjectName => DxfFileToken.ObjectDictionary;
/// <inheritdoc/>
public override string ObjectName => DxfFileToken.ObjectDictionaryWithDefault;

/// <inheritdoc/>
public override string SubclassMarker => DxfSubclassMarker.DictionaryWithDefault;

/// <summary>
Expand Down

0 comments on commit bd749b5

Please sign in to comment.