Skip to content

Commit

Permalink
insert
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Aug 22, 2023
1 parent b69e32e commit 03960b3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 35 deletions.
27 changes: 15 additions & 12 deletions ACadSharp/Entities/Insert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using ACadSharp.Tables;
using CSMath;
using System;
using System.Linq;

namespace ACadSharp.Entities
{
Expand All @@ -25,18 +26,6 @@ public class Insert : Entity
/// <inheritdoc/>
public override string SubclassMarker => DxfSubclassMarker.Insert;

/// <summary>
/// Attributes from the block reference
/// </summary>
/// <remarks>
/// If an attribute should be added in this collection a definition will be added into the block reference as well
/// </remarks>
//66 Variable attributes-follow flag(optional; default = 0);
// if the value of attributes-follow flag is 1, a series of
// attribute entities is expected to follow the insert, terminated by a seqend entity
[DxfCodeValue(DxfReferenceType.Ignored, 66)]
public SeqendCollection<AttributeEntity> Attributes { get; }

/// <summary>
/// Gets the insert block definition
/// </summary>
Expand Down Expand Up @@ -106,6 +95,20 @@ public class Insert : Entity
[DxfCodeValue(45)]
public double RowSpacing { get; set; } = 0;

/// <summary>
/// True if the insert has attribute entities in it
/// </summary>
[DxfCodeValue(DxfReferenceType.Ignored, 66)]
public bool HasAttributes { get { return this.Attributes.Any(); } }

/// <summary>
/// Attributes from the block reference
/// </summary>
/// <remarks>
/// If an attribute should be added in this collection a definition will be added into the block reference as well
/// </remarks>
public SeqendCollection<AttributeEntity> Attributes { get; }

internal Insert(bool onAdd = true) : base()
{
this.Attributes = new SeqendCollection<AttributeEntity>(this);
Expand Down
44 changes: 44 additions & 0 deletions ACadSharp/IO/DXF/DxfStreamWriter/DxfSectionWriterBase.Entities.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ACadSharp.Entities;
using System;
using System.Linq;

namespace ACadSharp.IO.DXF
{
Expand All @@ -25,6 +26,9 @@ protected void writeEntity<T>(T entity)
case Ellipse ellipse:
this.writeEllipse(ellipse);
break;
case Insert insert:
this.writeInsert(insert);
break;
case Line line:
this.writeLine(line);
break;
Expand Down Expand Up @@ -92,6 +96,46 @@ private void writeEllipse(Ellipse ellipse)
this._writer.Write(42, ellipse.EndParameter, map);
}

private void writeInsert(Insert insert)
{
DxfClassMap map = DxfClassMap.Create<Insert>();

this._writer.Write(DxfCode.Subclass, DxfSubclassMarker.Insert);

this._writer.Write(2, insert.Block.Name, map);

this._writer.Write(10, insert.InsertPoint, map);

this._writer.Write(41, insert.XScale, map);
this._writer.Write(42, insert.YScale, map);
this._writer.Write(43, insert.ZScale, map);

this._writer.Write(50, insert.Rotation, map);


this._writer.Write(70, (short)insert.ColumnCount);
this._writer.Write(71, (short)insert.RowCount);

this._writer.Write(44, insert.ColumnSpacing);
this._writer.Write(45, insert.RowSpacing);

this._writer.Write(210, insert.Normal, map);

if (insert.HasAttributes)
{
this._writer.Write(66, 1);

//WARNING: Write extended data before attributes

foreach (var att in insert.Attributes)
{
this.writeEntity(att);
}

this.writeSeqend(insert.Attributes.Seqend);
}
}

private void writeLine(Line line)
{
DxfClassMap map = DxfClassMap.Create<Line>();
Expand Down
23 changes: 0 additions & 23 deletions ACadSharp/IO/DXF/DxfStreamWriter/DxfSectionWriterBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,29 +310,6 @@ private void writeLwVertex(LwPolyline.Vertex v)
this._writer.Write(91, v.Id);
}

private void writeInsert(Insert insert)
{
DxfClassMap entityMap = DxfClassMap.Create<Entity>();
DxfClassMap insertMap = DxfClassMap.Create<Insert>();

this._writer.Write(DxfCode.Start, insert.ObjectName);

this.writeCommonObjectData(insert);

this.writeClassMap(entityMap, insert);

this.writeClassMap(insertMap, insert);

//this._writer.Write(66, 0);

//if (insert.Attributes.Any())
if (false)
{
this._writer.Write(66, 1);
this.writeCollection(insert.Attributes);
}
}

protected void notify(string message, NotificationType notificationType = NotificationType.None, Exception ex = null)
{
this.OnNotification?.Invoke(this, new NotificationEventArgs(message, notificationType, ex));
Expand Down

0 comments on commit 03960b3

Please sign in to comment.