diff --git a/ACadSharp/Entities/Hatch.cs b/ACadSharp/Entities/Hatch.cs index d2cc2100..31335f8b 100644 --- a/ACadSharp/Entities/Hatch.cs +++ b/ACadSharp/Entities/Hatch.cs @@ -63,13 +63,13 @@ public partial class Hatch : Entity /// Hatch style /// [DxfCodeValue(75)] - public HatchStyleType HatchStyle { get; set; } + public HatchStyleType Style { get; set; } /// /// Hatch pattern type /// [DxfCodeValue(76)] - public HatchPatternType HatchPatternType { get; set; } + public HatchPatternType PatternType { get; set; } /// /// Hatch pattern angle (pattern fill only) @@ -126,6 +126,8 @@ public partial class Hatch : Entity [DxfCodeValue(DxfReferenceType.Count, 91)] public List Paths { get; set; } = new List(); + private HatchPattern _pattern = HatchPattern.Solid; + public Hatch() : base() { } public override CadObject Clone() diff --git a/ACadSharp/Entities/HatchPattern.cs b/ACadSharp/Entities/HatchPattern.cs index 99de948e..398b926a 100644 --- a/ACadSharp/Entities/HatchPattern.cs +++ b/ACadSharp/Entities/HatchPattern.cs @@ -6,10 +6,14 @@ namespace ACadSharp.Entities { public class HatchPattern { - public readonly static HatchPattern Solid = new HatchPattern("SOLID"); + public static HatchPattern Solid { get { return new HatchPattern("SOLID"); } } public class Line { + /// + /// Pattern line angle + /// + [DxfCodeValue(DxfReferenceType.IsAngle, 53)] public double Angle { get; internal set; } /// diff --git a/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs b/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs index d549a6c0..8cc5b467 100644 --- a/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs +++ b/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs @@ -4438,9 +4438,9 @@ private CadTemplate readHatch() #endregion Read the boundary path data //style BS 75 style of hatch 0==odd parity, 1==outermost, 2==whole area - hatch.HatchStyle = (HatchStyleType)this._objectReader.ReadBitShort(); + hatch.Style = (HatchStyleType)this._objectReader.ReadBitShort(); //patterntype BS 76 pattern type 0==user-defined, 1==predefined, 2==custom - hatch.HatchPatternType = (HatchPatternType)this._objectReader.ReadBitShort(); + hatch.PatternType = (HatchPatternType)this._objectReader.ReadBitShort(); if (!hatch.IsSolid) { diff --git a/ACadSharp/IO/DXF/DxfStreamWriter/DxfSectionWriterBase.Entities.cs b/ACadSharp/IO/DXF/DxfStreamWriter/DxfSectionWriterBase.Entities.cs index c5b8f638..a789e5f0 100644 --- a/ACadSharp/IO/DXF/DxfStreamWriter/DxfSectionWriterBase.Entities.cs +++ b/ACadSharp/IO/DXF/DxfStreamWriter/DxfSectionWriterBase.Entities.cs @@ -13,7 +13,6 @@ protected void writeEntity(T entity) //TODO: Implement complex entities in a separated branch switch (entity) { - case Hatch: case Mesh: case MLine: case MText: @@ -272,7 +271,7 @@ private void writeHatch(Hatch hatch) this._writer.Write(20, 0, map); this._writer.Write(30, hatch.Elevation, map); - this._writer.Write(210, hatch.Normal.X, map); + this._writer.Write(210, hatch.Normal, map); this._writer.Write(2, hatch.Pattern.Name, map); @@ -285,7 +284,15 @@ private void writeHatch(Hatch hatch) this.writeBoundaryPath(path); } - this.writeHatchPattern(hatch.Pattern); + this.writeHatchPattern(hatch, hatch.Pattern); + + this._writer.Write(98, hatch.SeedPoints.Count); + foreach (XY spoint in hatch.SeedPoints) + { + this._writer.Write(10, spoint); + } + + //TODO: Implement HatchGradientPattern } private void writeBoundaryPath(Hatch.BoundaryPath path) @@ -371,9 +378,31 @@ private void writeHatchBoundaryPathEdge(Hatch.BoundaryPath.Edge edge) } } - private void writeHatchPattern(HatchPattern pattern) + private void writeHatchPattern(Hatch hatch, HatchPattern pattern) { - //TODO: Hatch pattern need a refactor and a proper implementation + this._writer.Write(75, (short)hatch.Style); + this._writer.Write(76, (short)hatch.PatternType); + + if (!hatch.IsSolid) + { + this._writer.Write(52, pattern.Angle * MathUtils.RadToDeg); + this._writer.Write(41, pattern.Scale); + this._writer.Write(77, (short)(hatch.IsDouble ? 1 : 0)); + this._writer.Write(78, (short)pattern.Lines.Count); + foreach (HatchPattern.Line line in pattern.Lines) + { + this._writer.Write(53, line.Angle * (180.0 / System.Math.PI)); + this._writer.Write(43, line.BasePoint.X); + this._writer.Write(44, line.BasePoint.Y); + this._writer.Write(45, line.Offset.X); + this._writer.Write(46, line.Offset.Y); + this._writer.Write(79, (short)line.DashLengths.Count); + foreach (double dashLength in line.DashLengths) + { + this._writer.Write(49, dashLength); + } + } + } } private void writeEllipse(Ellipse ellipse)