Skip to content

Commit

Permalink
dictionary variable
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Jul 7, 2023
1 parent eabf67b commit ada742e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 67 deletions.
45 changes: 10 additions & 35 deletions ACadSharp/IO/DXF/DxfStreamReader/DxfObjectsSectionReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,14 @@ public override void Read()

private CadTemplate readObject()
{
CadTemplate template = null;

switch (this._reader.ValueAsString)
{
case DxfFileToken.ObjectDictionary:
return this.readDictionary();
case DxfFileToken.ObjectLayout:
return this.readObjectCodes<Layout>(new CadLayoutTemplate(), readLayout);
case DxfFileToken.ObjectDictionaryVar:
template = new CadTemplate<DictionaryVariable>(new DictionaryVariable());
break;
return this.readObjectCodes<DictionaryVariable>(new CadTemplate<DictionaryVariable>(new DictionaryVariable()), this.readObjectSubclassMap);
case DxfFileToken.ObjectSortEntsTable:
return this.readSortentsTable();
case DxfFileToken.ObjectXRecord:
Expand All @@ -72,37 +69,6 @@ private CadTemplate readObject()
while (this._reader.DxfCode != DxfCode.Start);
return null;
}

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

this.readCommonObjectData(template);

while (this._reader.DxfCode == DxfCode.Subclass)
{
switch (this._reader.ValueAsString)
{
case DxfSubclassMarker.DictionaryVariables:
this.readMapped<DictionaryVariable>(template.CadObject, template);
break;
case DxfSubclassMarker.Layout:
this.readMapped<Layout>(template.CadObject, template);
break;
case DxfSubclassMarker.PlotSettings:
this.readMapped<PlotSettings>(template.CadObject, template);
break;
case DxfSubclassMarker.XRecord:
this.readMapped<XRecrod>(template.CadObject, template);
break;
default:
this._builder.Notify($"Unhandeled dxf entity subclass {this._reader.ValueAsString}");
while (this._reader.DxfCode != DxfCode.Start)
this._reader.ReadNext();
break;
}
}

return template;
}

protected CadTemplate readObjectCodes<T>(CadTemplate template, ReadObjectDelegate<T> readEntity)
Expand All @@ -128,6 +94,15 @@ protected CadTemplate readObjectCodes<T>(CadTemplate template, ReadObjectDelegat
return template;
}

private bool readObjectSubclassMap(CadTemplate template, DxfMap map)
{
switch (this._reader.Code)
{
default:
return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[template.CadObject.SubclassMarker]);
}
}

private bool readPlotSettings(CadTemplate template, DxfMap map)
{
switch (this._reader.Code)
Expand Down
22 changes: 11 additions & 11 deletions ACadSharp/IO/DXF/DxfStreamReader/DxfSectionReaderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@ protected CadEntityTemplate readEntity()
case DxfFileToken.EntityArc:
return this.readEntityCodes<Arc>(new CadEntityTemplate<Arc>(), readArc);
case DxfFileToken.EntityCircle:
return this.readEntityCodes<Circle>(new CadEntityTemplate<Circle>(), readSubclassMap);
return this.readEntityCodes<Circle>(new CadEntityTemplate<Circle>(), readEntitySubclassMap);
case DxfFileToken.EntityDimension:
return this.readEntityCodes<Dimension>(new CadDimensionTemplate(), readDimension);
case DxfFileToken.Entity3DFace:
return this.readEntityCodes<Face3D>(new CadEntityTemplate<Face3D>(), readSubclassMap);
return this.readEntityCodes<Face3D>(new CadEntityTemplate<Face3D>(), readEntitySubclassMap);
case DxfFileToken.EntityEllipse:
return this.readEntityCodes<Ellipse>(new CadEntityTemplate<Ellipse>(), readSubclassMap);
return this.readEntityCodes<Ellipse>(new CadEntityTemplate<Ellipse>(), readEntitySubclassMap);
case DxfFileToken.EntityLine:
return this.readEntityCodes<Line>(new CadEntityTemplate<Line>(), readSubclassMap);
return this.readEntityCodes<Line>(new CadEntityTemplate<Line>(), readEntitySubclassMap);
case DxfFileToken.EntityLwPolyline:
return this.readEntityCodes<LwPolyline>(new CadEntityTemplate<LwPolyline>(), readLwPolyline);
case DxfFileToken.EntityHatch:
Expand All @@ -185,23 +185,23 @@ protected CadEntityTemplate readEntity()
case DxfFileToken.EntityMLine:
return this.readEntityCodes<MLine>(new CadMLineTemplate(), readMLine);
case DxfFileToken.EntityPoint:
return this.readEntityCodes<Point>(new CadEntityTemplate<Point>(), readSubclassMap);
return this.readEntityCodes<Point>(new CadEntityTemplate<Point>(), readEntitySubclassMap);
case DxfFileToken.EntityPolyline:
return this.readEntityCodes<Entity>(new CadPolyLineTemplate(), readPolyline);
case DxfFileToken.EntityRay:
return this.readEntityCodes<Ray>(new CadEntityTemplate<Ray>(), readSubclassMap);
return this.readEntityCodes<Ray>(new CadEntityTemplate<Ray>(), readEntitySubclassMap);
case DxfFileToken.EndSequence:
return this.readEntityCodes<Seqend>(new CadEntityTemplate<Seqend>(), readSubclassMap);
return this.readEntityCodes<Seqend>(new CadEntityTemplate<Seqend>(), readEntitySubclassMap);
case DxfFileToken.EntitySolid:
return this.readEntityCodes<Solid>(new CadEntityTemplate<Solid>(), readSubclassMap);
return this.readEntityCodes<Solid>(new CadEntityTemplate<Solid>(), readEntitySubclassMap);
case DxfFileToken.EntityText:
return this.readEntityCodes<TextEntity>(new CadTextEntityTemplate(new TextEntity()), readTextEntity);
case DxfFileToken.EntityVertex:
return this.readEntityCodes<Entity>(new CadVertexTemplate(), readVertex);
case DxfFileToken.EntityViewport:
return this.readEntityCodes<Viewport>(new CadViewportTemplate(), this.readViewport);
case DxfFileToken.EntityXline:
return this.readEntityCodes<XLine>(new CadEntityTemplate<XLine>(), readSubclassMap);
return this.readEntityCodes<XLine>(new CadEntityTemplate<XLine>(), readEntitySubclassMap);
case DxfFileToken.EntitySpline:
return this.readEntityCodes<Spline>(new CadSplineTemplate(), readSpline);
default:
Expand Down Expand Up @@ -268,7 +268,7 @@ private bool readArc(CadEntityTemplate template, DxfMap map, string subclass = n
default:
if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Arc]))
{
return this.readSubclassMap(template, map, DxfSubclassMarker.Circle);
return this.readEntitySubclassMap(template, map, DxfSubclassMarker.Circle);
}
return true;
}
Expand Down Expand Up @@ -708,7 +708,7 @@ private bool readViewport(CadEntityTemplate template, DxfMap map, string subclas
}
}

private bool readSubclassMap(CadEntityTemplate template, DxfMap map, string subclass = null)
private bool readEntitySubclassMap(CadEntityTemplate template, DxfMap map, string subclass = null)
{
string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;

Expand Down
21 changes: 0 additions & 21 deletions ACadSharp/IO/Templates/CadXRecordTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,5 @@ internal class CadXRecordTemplate : CadTemplate<XRecrod>
public CadXRecordTemplate() : base(new XRecrod()) { }

public CadXRecordTemplate(XRecrod cadObject) : base(cadObject) { }

public override bool CheckDxfCode(int dxfcode, object value)
{
switch (dxfcode)
{
//NOTE: Undocumented codes
case 370:
case 440:
return true;
}

//1-369 (except 5 and 105)
//These values can be used by an application in any way

//TODO: Finsih cadXrecordtemplate

if (dxfcode == 5 || dxfcode == 105 || dxfcode > 369)
return false;
else
return true;
}
}
}

0 comments on commit ada742e

Please sign in to comment.