Skip to content

Commit

Permalink
mline
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Jun 28, 2023
1 parent d723d37 commit 3b75823
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 124 deletions.
5 changes: 3 additions & 2 deletions ACadSharp/Entities/LwPolyLine.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using ACadSharp.Attributes;
using CSMath;
using System;
using System.Collections.Generic;
using System.Linq;

namespace ACadSharp.Entities
{
Expand All @@ -23,6 +21,9 @@ public partial class LwPolyline : Entity, IPolyline
/// <inheritdoc/>
public override string ObjectName => DxfFileToken.EntityLwPolyline;

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

/// <summary>
/// Polyline flag (bit-coded)
/// </summary>
Expand Down
17 changes: 8 additions & 9 deletions ACadSharp/Entities/MLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ namespace ACadSharp.Entities
[DxfSubClass(DxfSubclassMarker.MLine)]
public partial class MLine : Entity
{
/// <inheritdoc/>
public override ObjectType ObjectType => ObjectType.MLINE;

/// <inheritdoc/>
public override string ObjectName => DxfFileToken.EntityMLine;

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

/// <summary>
/// String of up to 32 characters.The name of the style used for this mline.An entry for this style must exist in the MLINESTYLE dictionary.
/// </summary>
/// <remarks>
/// Name reference: <br/>
/// String of up to 32 characters.The name of the style used for this mline.An entry for this style must exist in the MLINESTYLE dictionary.
/// Do not modify this field without also updating the associated entry in the MLINESTYLE dictionary
/// </remarks>
[DxfCodeValue(DxfReferenceType.Name, 2)]
public MLStyle MlStyleName { get { return this.MLStyle; } set{ this.MLStyle = value; } } //TODO: Fix duplicated MLStyle

/// <summary>
/// MLINESTYLE object
/// </summary>
[DxfCodeValue(DxfReferenceType.Handle, 340)]
[DxfCodeValue(DxfReferenceType.Handle | DxfReferenceType.Name, 340)]
public MLStyle MLStyle { get; set; }

/// <summary>
Expand Down Expand Up @@ -78,7 +78,6 @@ public override CadObject Clone()
{
MLine clone = (MLine)base.Clone();

clone.MlStyleName = (MLStyle)(this.MlStyleName?.Clone());
clone.MLStyle = (MLStyle)(this.MLStyle?.Clone());

clone.Vertices.Clear();
Expand Down
85 changes: 82 additions & 3 deletions ACadSharp/IO/DXF/DxfStreamReader/DxfSectionReaderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
using ACadSharp.IO.Templates;
using CSMath;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Numerics;

namespace ACadSharp.IO.DXF
{
Expand Down Expand Up @@ -175,8 +177,7 @@ protected CadEntityTemplate readEntity()
case DxfFileToken.EntityLine:
return this.readEntityCodes<Line>(new CadEntityTemplate<Line>(), readSubclassMap);
case DxfFileToken.EntityLwPolyline:
template = new CadLwPolylineTemplate();
break;
return this.readEntityCodes<LwPolyline>(new CadEntityTemplate<LwPolyline>(), readLwPolyline);
case DxfFileToken.EntityHatch:
template = new CadHatchTemplate(new Hatch());
break;
Expand All @@ -186,7 +187,7 @@ protected CadEntityTemplate readEntity()
case DxfFileToken.EntityMText:
return this.readEntityCodes<MText>(new CadTextEntityTemplate(new MText()), readTextEntity);
case DxfFileToken.EntityMLine:
return this.readEntityCodes<MLine>(new CadEntityTemplate<MLine>(), readSubclassMap);
return this.readEntityCodes<MLine>(new CadMLineTemplate(), readMLine);
case DxfFileToken.EntityPoint:
return this.readEntityCodes<Point>(new CadEntityTemplate<Point>(), readSubclassMap);
case DxfFileToken.EntityPolyline:
Expand Down Expand Up @@ -550,6 +551,84 @@ private bool readPolyline(CadEntityTemplate template, DxfMap map, string subclas
}
}

private bool readLwPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
{
CadEntityTemplate<LwPolyline> tmp = template as CadEntityTemplate<LwPolyline>;

LwPolyline.Vertex last = tmp.CadObject.Vertices.LastOrDefault();

switch (this._reader.Code)
{
case 10:
tmp.CadObject.Vertices.Add(new LwPolyline.Vertex(new XY(this._reader.ValueAsDouble, 0)));
return true;
case 20:
if (last is not null)
{
last.Location = new XY(last.Location.X, this._reader.ValueAsDouble);
}
return true;
case 40:
if (last is not null)
{
last.StartWidth = this._reader.ValueAsDouble;
}
return true;
case 41:
if (last is not null)
{
last.EndWidth = this._reader.ValueAsDouble;
}
return true;
case 42:
if (last is not null)
{
last.Bulge = this._reader.ValueAsDouble;
}
return true;
case 90:
//Vertex count
return true;
case 91:
if (last is not null)
{
last.Id = this._reader.ValueAsInt;
}
return true;
default:
return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
}
}

private bool readMLine(CadEntityTemplate template, DxfMap map, string subclass = null)
{
CadMLineTemplate tmp = template as CadMLineTemplate;

switch (this._reader.Code)
{
// String of up to 32 characters. The name of the style used for this mline. An entry for this style must exist in the MLINESTYLE dictionary.
// Do not modify this field without also updating the associated entry in the MLINESTYLE dictionary
case 2:
tmp.MLineStyleName = this._reader.ValueAsString;
return true;
case 72:
tmp.NVertex = this._reader.ValueAsInt;
return true;
case 73:
tmp.NElements = this._reader.ValueAsInt;
return true;
case 340:
tmp.MLineStyleHandle = this._reader.ValueAsHandle;
return true;
default:
if (!tmp.TryReadVertex(this._reader.Code, this._reader.Value))
{
return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
}
return true;
}
}

private bool readVertex(CadEntityTemplate template, DxfMap map, string subclass = null)
{
CadVertexTemplate tmp = template as CadVertexTemplate;
Expand Down
55 changes: 0 additions & 55 deletions ACadSharp/IO/Templates/CadLwPolylineTemplate.cs

This file was deleted.

68 changes: 13 additions & 55 deletions ACadSharp/IO/Templates/CadMLineTemplate.cs
Original file line number Diff line number Diff line change
@@ -1,76 +1,35 @@
using ACadSharp.Entities;
using ACadSharp.IO.DWG;
using ACadSharp.Objects;
using System.Collections.Generic;
using System.Linq;

namespace ACadSharp.IO.Templates
{
internal class CadMLineTemplate : CadEntityTemplate
internal class CadMLineTemplate : CadEntityTemplate<MLine>
{
public ulong? MLineStyleHandle { get; set; }

private List<int> _readedCodes = new List<int>();
public string MLineStyleName { get; set; }

private MLine.Vertex _currVertex;

private MLine.Vertex.Segment _currSegmentElement;
public int? NVertex { get; set; }

public CadMLineTemplate(MLine mline) : base(mline) { }
public int? NElements { get; set; }

public override bool AddHandle(int dxfcode, ulong handle)
{
bool value = base.AddHandle(dxfcode, handle);
if (value)
return value;

switch (dxfcode)
{
case 340:
this.MLineStyleHandle = handle;
value = true;
break;
}
private MLine.Vertex _currVertex;

return value;
}
private MLine.Vertex.Segment _currSegmentElement;

public override bool AddName(int dxfcode, string name)
{
bool value = base.AddName(dxfcode, name);
if (value)
return value;
public CadMLineTemplate() : base(new MLine()) { }

switch (dxfcode)
{
case 2:
return true;
}

return value;
}
public CadMLineTemplate(MLine mline) : base(mline) { }

public override bool CheckDxfCode(int dxfcode, object value)
public bool TryReadVertex(int dxfcode, object value)
{
bool found = base.CheckDxfCode(dxfcode, value);
if (found)
return found;


var mline = this.CadObject as MLine;

if (_currVertex == null)
{
//Make sure to work with none null value
_currVertex = new MLine.Vertex();
}

switch (dxfcode)
{
case 11:
this._currVertex = new MLine.Vertex();
mline.Vertices.Add(_currVertex);

_currVertex.Position = new CSMath.XYZ(
(double)value,
_currVertex.Position.Y,
Expand Down Expand Up @@ -138,17 +97,16 @@ public override bool CheckDxfCode(int dxfcode, object value)
_currVertex.Segments.Add(_currSegmentElement);
return true;
case 41:
_currSegmentElement.Parameters.Add((double)value);
_currSegmentElement?.Parameters.Add((double)value);
return true;
case 42:
_currSegmentElement.AreaFillParameters.Add((double)value);
_currSegmentElement?.AreaFillParameters.Add((double)value);
return true;
case 73:
case 75:
return true;
default:
return false;
}

return found;
}

public override void Build(CadDocumentBuilder builder)
Expand Down

0 comments on commit 3b75823

Please sign in to comment.