Skip to content

Commit

Permalink
Entities ownership for dxf
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Apr 16, 2022
1 parent 3c30ec4 commit e3bc144
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 32 deletions.
6 changes: 5 additions & 1 deletion ACadSharp/IO/DXF/DxfDocumentBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
using ACadSharp.IO.Templates;
using ACadSharp.Tables;
using System.Collections.Generic;

namespace ACadSharp.IO.DXF
{
internal class DxfDocumentBuilder : CadDocumentBuilder
{
public DxfDocumentBuilder(CadDocument document, NotificationEventHandler notification = null) : base(document, notification)
public DxfDocumentBuilder(CadDocument document, NotificationEventHandler notification = null) : base(document, notification) { }

public override void BuildDocument()
{
base.BuildDocument();
}
}
}
56 changes: 25 additions & 31 deletions ACadSharp/IO/DXF/DxfEntitiesSectionReader.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using ACadSharp.Exceptions;
using ACadSharp.Entities;
using ACadSharp.Exceptions;
using ACadSharp.IO.Templates;
using ACadSharp.Tables;
using System;

namespace ACadSharp.IO.DXF
Expand All @@ -24,40 +26,32 @@ public override void Read()
if (template == null)
continue;

//Add the object and the template to the builder
this._builder.Templates[template.CadObject.Handle] = template;
}
}
}

internal class DxfObjectsSectionReader : DxfSectionReaderBase
{
public DxfObjectsSectionReader(IDxfStreamReader reader, DxfDocumentBuilder builder, NotificationEventHandler notification = null)
: base(reader, builder, notification)
{
}

public override void Read()
{
//Advance to the first value in the section
this._reader.ReadNext();

//Loop until the section ends
while (this._reader.LastValueAsString != DxfFileToken.EndSection)
{
CadTemplate template = this.readObject();

if (template == null)
continue;
if (this._builder.TryGetCadObject(template.OwnerHandle.Value, out CadObject co))
{
switch (co)
{
case BlockRecord record:
record.Entities.Add(template.CadObject);
break;
case Polyline pline when template.CadObject is Vertex v:
pline.Vertices.Add(v);
break;
case Insert insert when template.CadObject is AttributeEntity att:
insert.Attributes.Add(att);
break;
default:
this._notification?.Invoke(null, new NotificationEventArgs($"The owner of entity {template.CadObject.Handle} is a {co.GetType().FullName} with handle {co.Handle}"));
break;
}
}
else
{
this._notification?.Invoke(null, new NotificationEventArgs($"Block record owner {template.OwnerHandle} not found for entity {template.CadObject.Handle}"));
}

//Add the object and the template to the builder
this._builder.Templates[template.CadObject.Handle] = template;
}
}

private CadTemplate readObject()
{
throw new NotImplementedException();
}
}
}
36 changes: 36 additions & 0 deletions ACadSharp/IO/DXF/DxfObjectsSectionReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using ACadSharp.IO.Templates;
using System;

namespace ACadSharp.IO.DXF
{
internal class DxfObjectsSectionReader : DxfSectionReaderBase
{
public DxfObjectsSectionReader(IDxfStreamReader reader, DxfDocumentBuilder builder, NotificationEventHandler notification = null)
: base(reader, builder, notification)
{
}

public override void Read()
{
//Advance to the first value in the section
this._reader.ReadNext();

//Loop until the section ends
while (this._reader.LastValueAsString != DxfFileToken.EndSection)
{
CadTemplate template = this.readObject();

if (template == null)
continue;

//Add the object and the template to the builder
this._builder.Templates[template.CadObject.Handle] = template;
}
}

private CadTemplate readObject()
{
throw new NotImplementedException();
}
}
}

0 comments on commit e3bc144

Please sign in to comment.