Skip to content

Commit

Permalink
Merge pull request #172 from DomCR/DxfWriter-hatch
Browse files Browse the repository at this point in the history
Dxf writer Hatch
  • Loading branch information
DomCR authored Oct 9, 2023
2 parents 50853cb + 3a8c9f9 commit e889953
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
6 changes: 4 additions & 2 deletions ACadSharp/Entities/Hatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ public partial class Hatch : Entity
/// Hatch style
/// </summary>
[DxfCodeValue(75)]
public HatchStyleType HatchStyle { get; set; }
public HatchStyleType Style { get; set; }

/// <summary>
/// Hatch pattern type
/// </summary>
[DxfCodeValue(76)]
public HatchPatternType HatchPatternType { get; set; }
public HatchPatternType PatternType { get; set; }

/// <summary>
/// Hatch pattern angle (pattern fill only)
Expand Down Expand Up @@ -126,6 +126,8 @@ public partial class Hatch : Entity
[DxfCodeValue(DxfReferenceType.Count, 91)]
public List<BoundaryPath> Paths { get; set; } = new List<BoundaryPath>();

private HatchPattern _pattern = HatchPattern.Solid;

public Hatch() : base() { }

public override CadObject Clone()
Expand Down
6 changes: 5 additions & 1 deletion ACadSharp/Entities/HatchPattern.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/// <summary>
/// Pattern line angle
/// </summary>
[DxfCodeValue(DxfReferenceType.IsAngle, 53)]
public double Angle { get; internal set; }

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
39 changes: 34 additions & 5 deletions ACadSharp/IO/DXF/DxfStreamWriter/DxfSectionWriterBase.Entities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ protected void writeEntity<T>(T entity)
//TODO: Implement complex entities in a separated branch
switch (entity)
{
case Hatch:
case Mesh:
case MLine:
case MText:
Expand Down Expand Up @@ -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);

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e889953

Please sign in to comment.