Skip to content

Commit

Permalink
dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Jul 8, 2023
1 parent ada742e commit 4b02475
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 44 deletions.
60 changes: 20 additions & 40 deletions ACadSharp/IO/DXF/DxfStreamReader/DxfObjectsSectionReader.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ACadSharp.IO.Templates;
using ACadSharp.Objects;
using System;
using System.Linq;

namespace ACadSharp.IO.DXF
{
Expand Down Expand Up @@ -51,7 +52,7 @@ private CadTemplate readObject()
switch (this._reader.ValueAsString)
{
case DxfFileToken.ObjectDictionary:
return this.readDictionary();
return this.readObjectCodes<CadDictionary>(new CadDictionaryTemplate(), readDictionary);
case DxfFileToken.ObjectLayout:
return this.readObjectCodes<Layout>(new CadLayoutTemplate(), readLayout);
case DxfFileToken.ObjectDictionaryVar:
Expand Down Expand Up @@ -161,50 +162,29 @@ private void readXRecordEntries(XRecrod recrod)
}
}

private CadTemplate readDictionary()
private bool readDictionary(CadTemplate template, DxfMap map)
{
CadDictionary cadDictionary = new CadDictionary();
CadDictionaryTemplate template = new CadDictionaryTemplate(cadDictionary);
CadDictionaryTemplate tmp = template as CadDictionaryTemplate;

string lastKey = null;

//Jump the 0 marker
this._reader.ReadNext();

this.readCommonObjectData(template);

System.Diagnostics.Debug.Assert(DxfSubclassMarker.Dictionary == this._reader.ValueAsString);

//Jump the 100 marker
this._reader.ReadNext();

while (this._reader.DxfCode != DxfCode.Start)
switch (this._reader.Code)
{
switch (this._reader.Code)
{
case 280:
cadDictionary.HardOwnerFlag = this._reader.ValueAsBool;
break;
case 281:
cadDictionary.ClonningFlags = (DictionaryCloningFlags)this._reader.Value;
break;
case 3:
lastKey = this._reader.ValueAsString;
template.Entries.Add(lastKey, null);
break;
case 350: // Soft-owner ID/handle to entry object
case 360: // Hard-owner ID/handle to entry object
template.Entries[lastKey] = this._reader.ValueAsHandle;
break;
default:
this._builder.Notify($"Group Code not handled {this._reader.GroupCodeValue} for {typeof(CadDictionary)}, code : {this._reader.Code} | value : {this._reader.ValueAsString}");
break;
}

this._reader.ReadNext();
case 280:
cadDictionary.HardOwnerFlag = this._reader.ValueAsBool;
return true;
case 281:
cadDictionary.ClonningFlags = (DictionaryCloningFlags)this._reader.Value;
return true;
case 3:
tmp.Entries.Add(this._reader.ValueAsString, null);
return true;
case 350: // Soft-owner ID/handle to entry object
case 360: // Hard-owner ID/handle to entry object
tmp.Entries[tmp.Entries.LastOrDefault().Key] = this._reader.ValueAsHandle;
return true;
default:
return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Dictionary]);
}

return template;
}

private CadTemplate readSortentsTable()
Expand Down
8 changes: 8 additions & 0 deletions ACadSharp/IO/DXF/DxfStreamReader/DxfSectionReaderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ private bool readDimension(CadEntityTemplate template, DxfMap map, string subcla
case 3:
tmp.StyleName = this._reader.ValueAsString;
return true;
case 50:
var dim = new DimensionLinear();
tmp.SetDimensionObject(dim);
dim.Rotation = this._reader.ValueAsDouble;
map.SubClasses.Add(DxfSubclassMarker.LinearDimension, DxfClassMap.Create<DimensionLinear>());
return true;
//Undocumented codes
case 73:
case 74:
Expand Down Expand Up @@ -363,6 +369,8 @@ private bool readDimension(CadEntityTemplate template, DxfMap map, string subcla
tmp.SetDimensionObject(new DimensionOrdinate());
map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionOrdinate>());
return true;
case DxfSubclassMarker.LinearDimension:
return true;
default:
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions ACadSharp/IO/Templates/CadDictionaryTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ internal class CadDictionaryTemplate : CadTemplate<CadDictionary>
{
public Dictionary<string, ulong?> Entries { get; set; } = new Dictionary<string, ulong?>();

public CadDictionaryTemplate() : base(new CadDictionary()) { }

public CadDictionaryTemplate(CadDictionary dictionary) : base(dictionary) { }

public override void Build(CadDocumentBuilder builder)
Expand Down
10 changes: 6 additions & 4 deletions ACadSharp/Objects/CadDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,19 @@ public class CadDictionary : CadObject, IObservableCollection<CadObject>

public CadObject this[string entry] { get { return this._entries[entry]; } }

private Dictionary<string, CadObject> _entries { get; } = new Dictionary<string, CadObject>(); //TODO: Transform into an objservable collection
private readonly Dictionary<string, CadObject> _entries = new Dictionary<string, CadObject>(); //TODO: Transform into an objservable collection

/// <summary>
/// Creates the root dictionary with the default entries
/// </summary>
/// <returns></returns>
public static CadDictionary CreateRoot()
{
CadDictionary root = new CadDictionary();

root.Add(CadDictionary.AcadLayout, new CadDictionary());
//TODO: finish root dictionary implementation
CadDictionary root = new CadDictionary
{
{ AcadLayout, new CadDictionary() }
};

return root;
}
Expand Down

0 comments on commit 4b02475

Please sign in to comment.