Compare commits
4 Commits
04031a7677
...
dd7443ddb8
| Author | SHA1 | Date | |
|---|---|---|---|
| dd7443ddb8 | |||
| e5daf748c6 | |||
| 774012021c | |||
| 214cc94816 |
@@ -53,71 +53,6 @@ namespace EtchBendLines
|
|||||||
return bend.Slope == this.Slope;
|
return bend.Slope == this.Slope;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Line> GetEtchLines(double etchLength)
|
|
||||||
{
|
|
||||||
var lines = new List<Line>();
|
|
||||||
|
|
||||||
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 BendDirection Direction { get; set; }
|
||||||
|
|
||||||
public double Length
|
public double Length
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using netDxf;
|
using netDxf;
|
||||||
using netDxf.Entities;
|
using netDxf.Entities;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
@@ -31,7 +32,10 @@ namespace EtchBendLines
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The regular expression pattern the bend note must match
|
/// The regular expression pattern the bend note must match
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static readonly Regex bendNoteRegex = new Regex(@"(?<direction>UP|DOWN|DN)\s*(?<angle>\d*(\.\d*)?)°\s*R\s*(?<radius>\d*(\.\d*)?)");
|
static readonly Regex bendNoteRegex = new Regex(
|
||||||
|
@"\b(?<direction>UP|DOWN|DN)\s+(?<angle>\d+(\.\d+)?)°?\s*R\s*(?<radius>\d+(\.\d+)?)\b",
|
||||||
|
RegexOptions.Compiled | RegexOptions.IgnoreCase
|
||||||
|
);
|
||||||
|
|
||||||
public DxfDocument DxfDocument { get; private set; }
|
public DxfDocument DxfDocument { get; private set; }
|
||||||
|
|
||||||
@@ -45,7 +49,7 @@ namespace EtchBendLines
|
|||||||
|
|
||||||
foreach (var line in DxfDocument.Lines)
|
foreach (var line in DxfDocument.Lines)
|
||||||
{
|
{
|
||||||
if (line.Linetype.Name != "CENTERX2" && line.Layer.Name != "BEND")
|
if (!IsBendLine(line))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var bend = new Bend
|
var bend = new Bend
|
||||||
@@ -62,6 +66,11 @@ namespace EtchBendLines
|
|||||||
return bends.Where(b => b.Radius <= MaxBendRadius).ToList();
|
return bends.Where(b => b.Radius <= MaxBendRadius).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool IsBendLine(Line line)
|
||||||
|
{
|
||||||
|
return line.Linetype.Name == "CENTERX2" && line.Layer.Name == "BEND";
|
||||||
|
}
|
||||||
|
|
||||||
private List<MText> GetBendNotes()
|
private List<MText> GetBendNotes()
|
||||||
{
|
{
|
||||||
return DxfDocument.MTexts
|
return DxfDocument.MTexts
|
||||||
@@ -124,8 +133,10 @@ namespace EtchBendLines
|
|||||||
|
|
||||||
if (match.Success)
|
if (match.Success)
|
||||||
{
|
{
|
||||||
bendline.Radius = double.Parse(match.Groups["radius"].Value);
|
var radius = match.Groups["radius"].Value;
|
||||||
bendline.Angle = double.Parse(match.Groups["angle"].Value);
|
var angle = match.Groups["angle"].Value;
|
||||||
|
bendline.Radius = double.Parse(radius, CultureInfo.InvariantCulture);
|
||||||
|
bendline.Angle = double.Parse(angle, CultureInfo.InvariantCulture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using netDxf;
|
using netDxf;
|
||||||
|
using netDxf.Entities;
|
||||||
using netDxf.Tables;
|
using netDxf.Tables;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -8,11 +9,16 @@ namespace EtchBendLines
|
|||||||
{
|
{
|
||||||
public class Etcher
|
public class Etcher
|
||||||
{
|
{
|
||||||
public Layer BendLayer = new Layer("BEND")
|
public readonly Layer BendLayer = new Layer("BEND")
|
||||||
{
|
{
|
||||||
Color = AciColor.Yellow
|
Color = AciColor.Yellow
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static readonly Layer EtchLayer = new Layer("ETCH")
|
||||||
|
{
|
||||||
|
Color = AciColor.Green,
|
||||||
|
};
|
||||||
|
|
||||||
public double EtchLength { get; set; } = 1.0;
|
public double EtchLength { get; set; } = 1.0;
|
||||||
|
|
||||||
public double MaxBendRadius { get; set; } = 4.0;
|
public double MaxBendRadius { get; set; } = 4.0;
|
||||||
@@ -40,7 +46,9 @@ namespace EtchBendLines
|
|||||||
{
|
{
|
||||||
bendLine.Line.Layer = BendLayer;
|
bendLine.Line.Layer = BendLayer;
|
||||||
bendLine.Line.Color = AciColor.ByLayer;
|
bendLine.Line.Color = AciColor.ByLayer;
|
||||||
|
|
||||||
bendLine.BendNote.Layer = BendLayer;
|
bendLine.BendNote.Layer = BendLayer;
|
||||||
|
bendLine.BendNote.Color = AciColor.ByLayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
var upBends = bendLines.Where(b => b.Direction == BendDirection.Up);
|
var upBends = bendLines.Where(b => b.Direction == BendDirection.Up);
|
||||||
@@ -51,7 +59,7 @@ namespace EtchBendLines
|
|||||||
|
|
||||||
foreach (var bendline in upBends)
|
foreach (var bendline in upBends)
|
||||||
{
|
{
|
||||||
var etchLines = bendline.GetEtchLines(EtchLength);
|
var etchLines = GetEtchLines(bendline.Line, EtchLength);
|
||||||
|
|
||||||
foreach (var etchLine in etchLines)
|
foreach (var etchLine in etchLines)
|
||||||
{
|
{
|
||||||
@@ -86,5 +94,65 @@ namespace EtchBendLines
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Line> GetEtchLines(Line bendLine, double etchLength)
|
||||||
|
{
|
||||||
|
var lines = new List<Line>();
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user