Skip to content

Commit

Permalink
entities setup
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Jun 21, 2023
1 parent 6db2c29 commit 8eeb068
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 4 deletions.
5 changes: 5 additions & 0 deletions ACadSharp.Tests/IO/IOTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ public IOTestsBase(ITestOutputHelper output)

protected void onNotification(object sender, NotificationEventArgs e)
{
if(e.NotificationType == NotificationType.Error)
{
throw e.Exception;
}

_output.WriteLine(e.Message);
}

Expand Down
3 changes: 3 additions & 0 deletions ACadSharp/Entities/Arc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public class Arc : Circle
/// <inheritdoc/>
public override string ObjectName => DxfFileToken.EntityArc;

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

/// <summary>
/// The start angle in radians.
/// </summary>
Expand Down
48 changes: 45 additions & 3 deletions ACadSharp/IO/DXF/DxfStreamReader/DxfSectionReaderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace ACadSharp.IO.DXF
{
internal abstract class DxfSectionReaderBase
{
public delegate bool ReadEntityDelegate<T>(CadEntityTemplate<T> template, DxfClassMap map) where T : Entity, new();

/// <summary>
/// Object reactors, list of handles
/// </summary>
Expand Down Expand Up @@ -155,8 +157,7 @@ protected CadEntityTemplate readEntity()
template = new CadTextEntityTemplate(new AttributeDefinition());
break;
case DxfFileToken.EntityArc:
template = new CadArcTemplate(new Arc());
break;
return this.readEntityCodes(new CadEntityTemplate<Arc>(), readArc);
case DxfFileToken.EntityCircle:
template = new CadEntityTemplate(new Circle());
break;
Expand Down Expand Up @@ -356,6 +357,47 @@ protected CadEntityTemplate readEntity()
return template;
}

protected CadEntityTemplate readEntityCodes<T>(CadEntityTemplate<T> template, ReadEntityDelegate<T> readEntity)
where T : Entity, new()
{
this._reader.ReadNext();

DxfMap map = DxfMap.Create<T>();

Debug.Assert(template.CadObject.SubclassMarker != DxfSubclassMarker.Entity);

while (this._reader.DxfCode != DxfCode.Start)
{
if (!readEntity(template, map.SubClasses[template.CadObject.SubclassMarker]))
{
this.readCommonEntityCodes(template, out bool isExtendedData, map);
if (isExtendedData)
continue;
}

if (this._reader.DxfCode != DxfCode.Start)
this._reader.ReadNext();
}

return template;
}

protected void readCommonEntityCodes(CadEntityTemplate template, out bool isExtendedData, DxfMap map = null)
{
DxfClassMap entityMap = map.SubClasses[DxfSubclassMarker.Entity];

isExtendedData = false;
if (!this.tryAssignCurrentValue(template.CadObject, entityMap))
{
this.readCommonCodes(template, out isExtendedData, map);
}
}

private bool readArc(CadEntityTemplate<Arc> template, DxfClassMap map)
{
throw new NotImplementedException();
}

protected void readMapped<T>(CadObject cadObject, CadTemplate template)
where T : CadObject
{
Expand Down Expand Up @@ -917,7 +959,7 @@ protected bool tryAssignCurrentValue(CadObject cadObject, DxfClassMap map)
}
else
{
this._builder.Notify("", NotificationType.Error, ex);
this._builder.Notify("An error occurred while assiging a property using mapper", NotificationType.Error, ex);
}
}

Expand Down
6 changes: 5 additions & 1 deletion ACadSharp/IO/Templates/CadArcTemplate.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
using System;
using ACadSharp.Entities;
using ACadSharp.IO.DXF;
using ACadSharp.Tables;

namespace ACadSharp.IO.Templates
{
[Obsolete]
internal class CadArcTemplate : CadEntityTemplate
{

public CadArcTemplate() : base(new Arc()) { }

public CadArcTemplate(Entity entity) : base(entity) { }


public override void Build(CadDocumentBuilder builder)
{
base.Build(builder);

return;

if (builder is DxfDocumentBuilder && this.CadObject is Arc arc)
{
arc.StartAngle *= MathUtils.DegToRad;
Expand Down
12 changes: 12 additions & 0 deletions ACadSharp/IO/Templates/CadEntityTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,16 @@ private void applyLineType(CadDocumentBuilder builder)
}
}
}

internal class CadEntityTemplate<T> : CadEntityTemplate
where T : Entity, new()
{
public new T CadObject { get { return (T)base.CadObject; } set { base.CadObject = value; } }

public CadEntityTemplate() : base(new T()) { }

public CadEntityTemplate(T entity) : base(entity)
{
}
}
}

0 comments on commit 8eeb068

Please sign in to comment.