Skip to content

Commit 7cbc513

Browse files
authored
Merge pull request #356 from DomCR/create-default-elements-fix
Create default elements fix
2 parents 0872606 + 303a75b commit 7cbc513

File tree

7 files changed

+34
-27
lines changed

7 files changed

+34
-27
lines changed

ACadSharp.Tests/IO/LocalSampleTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void ReadUserDwg(string test)
3232

3333
CadDocument doc = DwgReader.Read(test, this._dwgConfiguration, this.onNotification);
3434

35-
//return;
35+
return;
3636

3737
string outPath = Path.Combine(Path.GetDirectoryName(test), $"{Path.GetFileNameWithoutExtension(test)}.out.dxf");
3838
using (DxfWriter writer = new DxfWriter(outPath, doc, false))

ACadSharp/CadDocument.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ private bool updateCollection(string dictName, bool createDictionary, out CadDic
344344
}
345345
else if (createDictionary)
346346
{
347-
this.RootDictionary.Add(new CadDictionary(dictName));
347+
dictionary = new CadDictionary(dictName);
348+
this.RootDictionary.Add(dictionary);
348349
}
349350

350351
return dictionary != null;
@@ -360,10 +361,14 @@ private void addCadObject(CadObject cadObject)
360361
if (cadObject.Handle == 0 || this._cadObjects.ContainsKey(cadObject.Handle))
361362
{
362363
var nextHandle = this._cadObjects.Keys.Max() + 1;
363-
364-
this.Header.HandleSeed = nextHandle + 1;
364+
if (nextHandle < this.Header.HandleSeed)
365+
{
366+
nextHandle = this.Header.HandleSeed;
367+
}
365368

366369
cadObject.Handle = nextHandle;
370+
371+
this.Header.HandleSeed = nextHandle + 1;
367372
}
368373

369374
this._cadObjects.Add(cadObject.Handle, cadObject);

ACadSharp/Entities/CadImageBase.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,20 +200,12 @@ internal override void AssignDocument(CadDocument doc)
200200

201201
this._definition = this.updateCollection(this.Definition, doc.ImageDefinitions);
202202

203-
// The definitions entry is optional, some documents do not have it.
204-
if (this.Document.ImageDefinitions != null)
205-
{
206-
this.Document.ImageDefinitions.OnRemove += this.imageDefinitionsOnRemove;
207-
}
203+
this.Document.ImageDefinitions.OnRemove += this.imageDefinitionsOnRemove;
208204
}
209205

210206
internal override void UnassignDocument()
211207
{
212-
// The definitions entry is optional, some documents do not have it.
213-
if (this.Document.ImageDefinitions != null)
214-
{
215-
this.Document.ImageDefinitions.OnRemove -= this.imageDefinitionsOnRemove;
216-
}
208+
this.Document.ImageDefinitions.OnRemove -= this.imageDefinitionsOnRemove;
217209

218210
base.UnassignDocument();
219211

ACadSharp/IO/CadDocumentBuilder.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,6 @@ public CadDocumentBuilder(CadDocument document)
5252

5353
public virtual void BuildDocument()
5454
{
55-
foreach (ICadDictionaryTemplate dictionaryTemplate in dictionaryTemplates.Values)
56-
{
57-
dictionaryTemplate.Build(this);
58-
}
59-
60-
this.DocumentToBuild.UpdateCollections(false);
61-
6255
foreach (CadTemplate template in this.templates.Values)
6356
{
6457
template.Build(this);
@@ -215,5 +208,15 @@ public void AddDictionaryTemplate(ICadDictionaryTemplate dictionaryTemplate)
215208
this.dictionaryTemplates[dictionaryTemplate.CadObject.Handle] = dictionaryTemplate;
216209
this.cadObjects[dictionaryTemplate.CadObject.Handle] = dictionaryTemplate.CadObject;
217210
}
211+
212+
protected void buildDictionaries()
213+
{
214+
foreach (ICadDictionaryTemplate dictionaryTemplate in dictionaryTemplates.Values)
215+
{
216+
dictionaryTemplate.Build(this);
217+
}
218+
219+
this.DocumentToBuild.UpdateCollections(true);
220+
}
218221
}
219222
}

ACadSharp/IO/DWG/DwgDocumentBuilder.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
using ACadSharp.Entities;
22
using ACadSharp.IO.Templates;
3-
using ACadSharp.Tables;
4-
using ACadSharp.Tables.Collections;
5-
using System;
63
using System.Collections.Generic;
74

85
namespace ACadSharp.IO.DWG
@@ -41,6 +38,8 @@ public override void BuildDocument()
4138

4239
this.BuildTables();
4340

41+
this.buildDictionaries();
42+
4443
base.BuildDocument();
4544
}
4645
}

ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5287,6 +5287,7 @@ private CadTemplate readXRecord()
52875287
switch (groupCode)
52885288
{
52895289
case GroupCodeValueType.String:
5290+
case GroupCodeValueType.ExtendedDataString:
52905291
xRecord.Entries.Add(new XRecord.Entry(code, this._objectReader.ReadTextUnicode()));
52915292
break;
52925293
case GroupCodeValueType.Point3D:
@@ -5298,17 +5299,20 @@ private CadTemplate readXRecord()
52985299
)));
52995300
break;
53005301
case GroupCodeValueType.Double:
5302+
case GroupCodeValueType.ExtendedDataDouble:
53015303
xRecord.Entries.Add(new XRecord.Entry(code, this._objectReader.ReadDouble()));
53025304
break;
5305+
case GroupCodeValueType.Byte:
5306+
xRecord.Entries.Add(new XRecord.Entry(code, this._objectReader.ReadByte()));
5307+
break;
53035308
case GroupCodeValueType.Int16:
5309+
case GroupCodeValueType.ExtendedDataInt16:
53045310
xRecord.Entries.Add(new XRecord.Entry(code, this._objectReader.ReadShort()));
53055311
break;
53065312
case GroupCodeValueType.Int32:
5313+
case GroupCodeValueType.ExtendedDataInt32:
53075314
xRecord.Entries.Add(new XRecord.Entry(code, this._objectReader.ReadRawLong()));
53085315
break;
5309-
case GroupCodeValueType.Byte:
5310-
xRecord.Entries.Add(new XRecord.Entry(code, this._objectReader.ReadByte()));
5311-
break;
53125316
case GroupCodeValueType.Int64:
53135317
xRecord.Entries.Add(new XRecord.Entry(code, this._objectReader.ReadRawULong()));
53145318
break;
@@ -5319,9 +5323,11 @@ private CadTemplate readXRecord()
53195323
xRecord.Entries.Add(new XRecord.Entry(code, this._objectReader.ReadByte() > 0));
53205324
break;
53215325
case GroupCodeValueType.Chunk:
5326+
case GroupCodeValueType.ExtendedDataChunk:
53225327
xRecord.Entries.Add(new XRecord.Entry(code, this._objectReader.ReadBytes(this._objectReader.ReadByte())));
53235328
break;
53245329
case GroupCodeValueType.ObjectId:
5330+
case GroupCodeValueType.ExtendedDataHandle:
53255331
xRecord.Entries.Add(new XRecord.Entry(code, this._objectReader.ReadRawULong()));
53265332
break;
53275333
default:

ACadSharp/IO/DXF/DxfDocumentBuilder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public DxfDocumentBuilder(CadDocument document, DxfReaderConfiguration configura
2424

2525
public override void BuildDocument()
2626
{
27+
this.buildDictionaries();
28+
2729
this.RegisterTables();
2830

2931
this.BuildTables();

0 commit comments

Comments
 (0)