diff --git a/EtchBendLines/Bend.cs b/EtchBendLines/Bend.cs index 3cd79e1..aa7052b 100644 --- a/EtchBendLines/Bend.cs +++ b/EtchBendLines/Bend.cs @@ -53,71 +53,6 @@ namespace EtchBendLines return bend.Slope == this.Slope; } - public List GetEtchLines(double etchLength) - { - var lines = new List(); - - var startPoint = new Vector2(Line.StartPoint.X, Line.StartPoint.Y); - var endPoint = new Vector2(Line.EndPoint.X, Line.EndPoint.Y); - var bendLength = startPoint.DistanceTo(endPoint); - - if (bendLength < (etchLength * 3.0)) - { - lines.Add(new Line(Line.StartPoint, Line.EndPoint)); - } - else - { - var angle = startPoint.AngleTo(endPoint); - - if (Line.IsVertical()) - { - var x = Line.StartPoint.X; - - var bottomY1 = Math.Min(startPoint.Y, endPoint.Y); - var bottomY2 = bottomY1 + etchLength; - - var topY1 = Math.Max(startPoint.Y, endPoint.Y); - var topY2 = topY1 - etchLength; - - var p1 = new Vector2(x, bottomY1); - var p2 = new Vector2(x, bottomY2); - var p3 = new Vector2(x, topY1); - var p4 = new Vector2(x, topY2); - - lines.Add(new Line(p1, p2)); - lines.Add(new Line(p3, p4)); - } - else - { - var start = Line.StartPoint.ToVector2(); - var end = Line.EndPoint.ToVector2(); - - var x1 = Math.Cos(angle); - var y1 = Math.Sin(angle); - - var p1 = new Vector2(start.X, start.Y); - var p2 = new Vector2(start.X + x1, start.Y + y1); - var p3 = new Vector2(end.X, end.Y); - var p4 = new Vector2(end.X - x1, end.Y - y1); - - lines.Add(new Line(p1, p2)); - lines.Add(new Line(p3, p4)); - } - } - - var etchLayer = new Layer("ETCH") - { - Color = AciColor.Green, - }; - - foreach (var line in lines) - { - line.Layer = etchLayer; - } - - return lines; - } - public BendDirection Direction { get; set; } public double Length diff --git a/EtchBendLines/Etcher.cs b/EtchBendLines/Etcher.cs index 63a8aef..0e7c29a 100644 --- a/EtchBendLines/Etcher.cs +++ b/EtchBendLines/Etcher.cs @@ -1,4 +1,5 @@ using netDxf; +using netDxf.Entities; using netDxf.Tables; using System; using System.Collections.Generic; @@ -8,11 +9,16 @@ namespace EtchBendLines { public class Etcher { - public Layer BendLayer = new Layer("BEND") + public readonly Layer BendLayer = new Layer("BEND") { Color = AciColor.Yellow }; + static readonly Layer EtchLayer = new Layer("ETCH") + { + Color = AciColor.Green, + }; + public double EtchLength { get; set; } = 1.0; public double MaxBendRadius { get; set; } = 4.0; @@ -40,7 +46,9 @@ namespace EtchBendLines { bendLine.Line.Layer = BendLayer; bendLine.Line.Color = AciColor.ByLayer; + bendLine.BendNote.Layer = BendLayer; + bendLine.BendNote.Color = AciColor.ByLayer; } var upBends = bendLines.Where(b => b.Direction == BendDirection.Up); @@ -51,7 +59,7 @@ namespace EtchBendLines foreach (var bendline in upBends) { - var etchLines = bendline.GetEtchLines(EtchLength); + var etchLines = GetEtchLines(bendline.Line, EtchLength); foreach (var etchLine in etchLines) { @@ -86,5 +94,65 @@ namespace EtchBendLines return false; } + + public List GetEtchLines(Line bendLine, double etchLength) + { + var lines = new List(); + + var startPoint = new Vector2(bendLine.StartPoint.X, bendLine.StartPoint.Y); + var endPoint = new Vector2(bendLine.EndPoint.X, bendLine.EndPoint.Y); + var bendLength = startPoint.DistanceTo(endPoint); + + if (bendLength < (etchLength * 3.0)) + { + lines.Add(new Line(bendLine.StartPoint, bendLine.EndPoint)); + } + else + { + var angle = startPoint.AngleTo(endPoint); + + if (bendLine.IsVertical()) + { + var x = bendLine.StartPoint.X; + + var bottomY1 = Math.Min(startPoint.Y, endPoint.Y); + var bottomY2 = bottomY1 + etchLength; + + var topY1 = Math.Max(startPoint.Y, endPoint.Y); + var topY2 = topY1 - etchLength; + + var p1 = new Vector2(x, bottomY1); + var p2 = new Vector2(x, bottomY2); + var p3 = new Vector2(x, topY1); + var p4 = new Vector2(x, topY2); + + lines.Add(new Line(p1, p2)); + lines.Add(new Line(p3, p4)); + } + else + { + var start = bendLine.StartPoint.ToVector2(); + var end = bendLine.EndPoint.ToVector2(); + + var dx = Math.Cos(angle) * etchLength; + var dy = Math.Sin(angle) * etchLength; + + var p1 = new Vector2(start.X, start.Y); + var p2 = new Vector2(start.X + dx, start.Y + dy); + var p3 = new Vector2(end.X, end.Y); + var p4 = new Vector2(end.X - dx, end.Y - dy); + + lines.Add(new Line(p1, p2)); + lines.Add(new Line(p3, p4)); + } + } + + foreach (var line in lines) + { + line.Layer = EtchLayer; + } + + return lines; + } } }