Compare commits
11 Commits
1e66f9d960
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 89d987f6c6 | |||
| 78ae737adb | |||
| 2391eb7050 | |||
| dd7443ddb8 | |||
| e5daf748c6 | |||
| 774012021c | |||
| 214cc94816 | |||
| 04031a7677 | |||
| 3e4ab60366 | |||
| 2b30498147 | |||
| f664bd79a4 |
@@ -1,9 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<startup>
|
<startup>
|
||||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
|
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
|
||||||
</startup>
|
</startup>
|
||||||
<appSettings>
|
<appSettings>
|
||||||
<add key="MaxBendRadius" value="2.0"/>
|
<add key="MaxBendRadius" value="2.0"/>
|
||||||
|
<add key="EtchLength" value="1.0"/>
|
||||||
</appSettings>
|
</appSettings>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|||||||
16
EtchBendLines/AppConfig.cs
Normal file
16
EtchBendLines/AppConfig.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Configuration;
|
||||||
|
|
||||||
|
namespace EtchBendLines
|
||||||
|
{
|
||||||
|
public static class AppConfig
|
||||||
|
{
|
||||||
|
public static double GetDouble(string key)
|
||||||
|
{
|
||||||
|
if (!double.TryParse(ConfigurationManager.AppSettings[key], out var value))
|
||||||
|
throw new Exception($"Failed to convert AppSetting[\"{key}\"] to double.");
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
@@ -134,9 +69,7 @@ namespace EtchBendLines
|
|||||||
|
|
||||||
public double? Angle { get; set; }
|
public double? Angle { get; set; }
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
=> $"{Direction} {(Angle?.ToString("0.##") ?? "?")}° R{(Radius?.ToString("0.##") ?? "?")}";
|
||||||
return $"{Direction.ToString()} {Angle}° R{Radius}";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
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;
|
||||||
|
|
||||||
namespace EtchBendLines
|
namespace EtchBendLines
|
||||||
{
|
{
|
||||||
class BendLineExtractor
|
public class BendLineExtractor
|
||||||
{
|
{
|
||||||
public BendLineExtractor(string dxfFile)
|
public BendLineExtractor(string dxfFile)
|
||||||
{
|
{
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,9 +8,10 @@
|
|||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<RootNamespace>EtchBendLines</RootNamespace>
|
<RootNamespace>EtchBendLines</RootNamespace>
|
||||||
<AssemblyName>EtchBendLines</AssemblyName>
|
<AssemblyName>EtchBendLines</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
|
<TargetFrameworkProfile />
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
@@ -46,9 +47,11 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="AppConfig.cs" />
|
||||||
<Compile Include="Bend.cs" />
|
<Compile Include="Bend.cs" />
|
||||||
<Compile Include="BendDirection.cs" />
|
<Compile Include="BendDirection.cs" />
|
||||||
<Compile Include="BendLineExtractor.cs" />
|
<Compile Include="BendLineExtractor.cs" />
|
||||||
|
<Compile Include="Etcher.cs" />
|
||||||
<Compile Include="Extensions.cs" />
|
<Compile Include="Extensions.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
|||||||
182
EtchBendLines/Etcher.cs
Normal file
182
EtchBendLines/Etcher.cs
Normal file
@@ -0,0 +1,182 @@
|
|||||||
|
using netDxf;
|
||||||
|
using netDxf.Entities;
|
||||||
|
using netDxf.Tables;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace EtchBendLines
|
||||||
|
{
|
||||||
|
public class Etcher
|
||||||
|
{
|
||||||
|
public readonly Layer BendLayer = new Layer("BEND")
|
||||||
|
{
|
||||||
|
Color = AciColor.Yellow
|
||||||
|
};
|
||||||
|
|
||||||
|
static readonly Layer EtchLayer = new Layer("ETCH")
|
||||||
|
{
|
||||||
|
Color = AciColor.Green,
|
||||||
|
};
|
||||||
|
|
||||||
|
private const double DefaultEtchLength = 1.0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Maximum bend radius to be considered. Anything beyond this number will be rolled.
|
||||||
|
/// </summary>
|
||||||
|
public double MaxBendRadius { get; set; } = 4.0;
|
||||||
|
|
||||||
|
private DxfDocument LoadDocument(string path)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return DxfDocument.Load(path)
|
||||||
|
?? throw new InvalidOperationException("DXF load returned null");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new ApplicationException($"Failed to load DXF '{path}'", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<Bend> ExtractUpBends(DxfDocument doc)
|
||||||
|
{
|
||||||
|
// your existing BendLineExtractor logic
|
||||||
|
var extractor = new BendLineExtractor(doc);
|
||||||
|
return extractor.GetBendLines()
|
||||||
|
.Where(b => b.Direction == BendDirection.Up);
|
||||||
|
}
|
||||||
|
|
||||||
|
private HashSet<string> BuildExistingKeySet(DxfDocument doc)
|
||||||
|
=> new HashSet<string>(
|
||||||
|
doc.Lines
|
||||||
|
.Where(l => IsEtchLayer(l.Layer))
|
||||||
|
.Select(l => KeyFor(l.StartPoint, l.EndPoint))
|
||||||
|
);
|
||||||
|
|
||||||
|
private void InsertEtchLines(DxfDocument doc, IEnumerable<Bend> bends, HashSet<string> existingKeys, double etchLength)
|
||||||
|
{
|
||||||
|
foreach (var bend in bends)
|
||||||
|
{
|
||||||
|
foreach (var etch in GetEtchLines(bend.Line, etchLength))
|
||||||
|
{
|
||||||
|
var key = KeyFor(etch.StartPoint, etch.EndPoint);
|
||||||
|
if (existingKeys.Contains(key))
|
||||||
|
{
|
||||||
|
// ensure correct layer
|
||||||
|
var existing = doc.Lines.First(l => KeyFor(l) == key);
|
||||||
|
existing.Layer = EtchLayer;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
etch.Layer = EtchLayer;
|
||||||
|
doc.AddEntity(etch);
|
||||||
|
existingKeys.Add(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SaveDocument(DxfDocument doc, string path)
|
||||||
|
{
|
||||||
|
doc.Save(path);
|
||||||
|
Console.WriteLine($"→ Saved with etch lines: {path}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string KeyFor(Line l) => KeyFor(l.StartPoint, l.EndPoint);
|
||||||
|
|
||||||
|
private static string KeyFor(Vector3 a, Vector3 b) => $"{a.X:F3},{a.Y:F3}|{b.X:F3},{b.Y:F3}";
|
||||||
|
|
||||||
|
public void AddEtchLines(string filePath, double etchLength = DefaultEtchLength)
|
||||||
|
{
|
||||||
|
Console.WriteLine(filePath);
|
||||||
|
|
||||||
|
var doc = LoadDocument(filePath);
|
||||||
|
var upBends = ExtractUpBends(doc);
|
||||||
|
var existing = BuildExistingKeySet(doc);
|
||||||
|
|
||||||
|
InsertEtchLines(doc, upBends, existing, etchLength);
|
||||||
|
SaveDocument(doc, filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsEtchLayer(Layer layer)
|
||||||
|
{
|
||||||
|
if (layer == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (layer.Name.Equals(EtchLayer.Name, StringComparison.OrdinalIgnoreCase))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
switch (layer.Name)
|
||||||
|
{
|
||||||
|
case "ETCH":
|
||||||
|
case "SCRIBE":
|
||||||
|
case "SCRIBE-TEXT":
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<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;
|
||||||
|
}
|
||||||
|
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,42 +1,67 @@
|
|||||||
using netDxf;
|
using System;
|
||||||
using netDxf.Tables;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Configuration;
|
using System.Configuration;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
|
|
||||||
namespace EtchBendLines
|
namespace EtchBendLines
|
||||||
{
|
{
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
const double ETCH_LENGTH = 1.0;
|
|
||||||
|
|
||||||
static Layer BendLayer = new Layer("BEND")
|
|
||||||
{
|
|
||||||
Color = AciColor.Yellow
|
|
||||||
};
|
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
var path = AppDomain.CurrentDomain.BaseDirectory;
|
try
|
||||||
var files = Directory.GetFiles(path, "*.dxf", SearchOption.AllDirectories);
|
|
||||||
|
|
||||||
if (files == null || files.Length == 0)
|
|
||||||
{
|
{
|
||||||
Console.WriteLine($"No DXF files founds. Place DXF files in \"{AppDomain.CurrentDomain.BaseDirectory}\" and run this program again.");
|
Run(args);
|
||||||
PressAnyKeyToExit();
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Console.WriteLine($"An error occurred: {ex.Message}");
|
||||||
|
Console.ResetColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
PressAnyKeyToExit();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Run(string[] args)
|
||||||
|
{
|
||||||
|
var etchLength = AppConfig.GetDouble("EtchLength");
|
||||||
|
var maxRadius = AppConfig.GetDouble("MaxBendRadius");
|
||||||
|
|
||||||
|
var etcher = new Etcher
|
||||||
|
{
|
||||||
|
MaxBendRadius = maxRadius
|
||||||
|
};
|
||||||
|
|
||||||
|
var files = GetDxfFiles(args);
|
||||||
|
if (files.Count == 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"No DXF files found. Place DXF files in \"{AppDomain.CurrentDomain.BaseDirectory}\" and run this program again.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var file in files)
|
foreach (var file in files)
|
||||||
{
|
{
|
||||||
AddEtchLines(file);
|
etcher.AddEtchLines(file, etchLength);
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PressAnyKeyToExit();
|
static List<string> GetDxfFiles(string[] args)
|
||||||
|
{
|
||||||
|
var paths = args.Length > 0 ? args.ToList() : new List<string> { AppDomain.CurrentDomain.BaseDirectory };
|
||||||
|
var files = new List<string>();
|
||||||
|
|
||||||
|
foreach (var path in paths)
|
||||||
|
{
|
||||||
|
if (File.Exists(path))
|
||||||
|
files.Add(path);
|
||||||
|
else if (Directory.Exists(path))
|
||||||
|
files.AddRange(Directory.GetFiles(path, "*.dxf", SearchOption.AllDirectories));
|
||||||
|
}
|
||||||
|
|
||||||
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PressAnyKeyToExit()
|
static void PressAnyKeyToExit()
|
||||||
@@ -45,83 +70,6 @@ namespace EtchBendLines
|
|||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddEtchLines(string filePath)
|
|
||||||
{
|
|
||||||
Console.WriteLine(filePath);
|
|
||||||
|
|
||||||
var bendLineExtractor = new BendLineExtractor(filePath);
|
|
||||||
bendLineExtractor.MaxBendRadius = MaxBendRadius;
|
|
||||||
|
|
||||||
var bendLines = bendLineExtractor.GetBendLines();
|
|
||||||
|
|
||||||
if (bendLines.Count == 0)
|
|
||||||
{
|
|
||||||
Console.WriteLine("No bend lines found.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Found {bendLines.Count} bend lines.");
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var bendLine in bendLines)
|
|
||||||
{
|
|
||||||
bendLine.Line.Layer = BendLayer;
|
|
||||||
bendLine.Line.Color = AciColor.ByLayer;
|
|
||||||
bendLine.BendNote.Layer = BendLayer;
|
|
||||||
}
|
|
||||||
|
|
||||||
var upBends = bendLines.Where(b => b.Direction == BendDirection.Up);
|
|
||||||
var upBendCount = upBends.Count();
|
|
||||||
var downBendCount = bendLines.Count - upBendCount;
|
|
||||||
|
|
||||||
Console.WriteLine($"{upBendCount} Up {downBendCount} Down");
|
|
||||||
|
|
||||||
var partType = GetPartType(bendLines);
|
|
||||||
|
|
||||||
foreach (var bendline in upBends)
|
|
||||||
{
|
|
||||||
var etchLines = bendline.GetEtchLines(ETCH_LENGTH);
|
|
||||||
|
|
||||||
foreach (var etchLine in etchLines)
|
|
||||||
{
|
|
||||||
var existing = bendLineExtractor.DxfDocument.Lines
|
|
||||||
.Where(l => IsEtchLayer(l.Layer))
|
|
||||||
.FirstOrDefault(l => l.StartPoint.IsEqualTo(etchLine.StartPoint) && l.EndPoint.IsEqualTo(etchLine.EndPoint));
|
|
||||||
|
|
||||||
if (existing != null)
|
|
||||||
{
|
|
||||||
// ensure the layer is correct and skip adding the etch line since it already exists.
|
|
||||||
existing.Layer = etchLine.Layer;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
bendLineExtractor.DxfDocument.AddEntity(etchLine);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bendLineExtractor.DxfDocument.Save(filePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool IsEtchLayer(Layer layer)
|
|
||||||
{
|
|
||||||
if (layer.Name == "ETCH")
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (layer.Name == "SCRIBE")
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (layer.Name == "SCRIBE-TEXT")
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static double MaxBendRadius
|
|
||||||
{
|
|
||||||
get { return double.Parse(ConfigurationManager.AppSettings["MaxBendRadius"]); }
|
|
||||||
}
|
|
||||||
|
|
||||||
static PartType GetPartType(List<Bend> bends)
|
static PartType GetPartType(List<Bend> bends)
|
||||||
{
|
{
|
||||||
if (bends.Count == 0)
|
if (bends.Count == 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user