diff --git a/EtchBendLines/BendLineExtractor.cs b/EtchBendLines/BendLineExtractor.cs
index 9d44c58..60568f8 100644
--- a/EtchBendLines/BendLineExtractor.cs
+++ b/EtchBendLines/BendLineExtractor.cs
@@ -24,6 +24,10 @@ namespace EtchBendLines
///
public double MaxBendRadius { get; set; } = 4;
+ public double SharpRadius = 0.001;
+
+ public bool ReplaceSharpRadius { get; set; } = true;
+
///
/// The regular expression pattern the bend note must match
///
@@ -36,6 +40,9 @@ namespace EtchBendLines
var bends = new List();
var bendNotes = GetBendNotes();
+ if (ReplaceSharpRadius)
+ FixSharpBends();
+
foreach (var line in DxfDocument.Lines)
{
if (line.Linetype.Name != "CENTERX2" && line.Layer.Name != "BEND")
@@ -57,19 +64,47 @@ namespace EtchBendLines
private List GetBendNotes()
{
- var bendNotes = new List();
+ return DxfDocument.MTexts
+ .Where(t => GetBendDirection(t) != BendDirection.Unknown)
+ .ToList();
+ }
- foreach (var text in DxfDocument.MTexts)
+ private void FixSharpBends()
+ {
+ var bendNotes = GetBendNotes();
+
+ foreach (var bendNote in bendNotes)
{
- var textAsUpper = text.Value.ToUpper();
+ var text = bendNote.Value?.ToUpper();
- if (textAsUpper.Contains("UP") || textAsUpper.Contains("DOWN"))
- {
- bendNotes.Add(text);
- }
+ if (text == null)
+ continue;
+
+ var index = text.IndexOf("SHARP");
+
+ if (index == -1)
+ continue;
+
+ bendNote.Value = bendNote.Value
+ .Remove(index, 5)
+ .Insert(index, $"R{SharpRadius}");
}
+ }
- return bendNotes;
+ private static BendDirection GetBendDirection(MText mText)
+ {
+ if (mText == null || mText.Value == null)
+ return BendDirection.Unknown;
+
+ var text = mText.Value.ToUpper();
+
+ if (text.Contains("UP"))
+ return BendDirection.Up;
+
+ if (text.Contains("DOWN") || text.Contains("DN"))
+ return BendDirection.Down;
+
+ return BendDirection.Unknown;
}
private static void AssignBendDirections(IEnumerable bendlines, IEnumerable bendNotes)
@@ -82,15 +117,9 @@ namespace EtchBendLines
continue;
bendline.BendNote = bendNote;
+ bendline.Direction = GetBendDirection(bendNote);
- var note = bendNote.Value.ToUpper();
-
- if (note.Contains("UP"))
- bendline.Direction = BendDirection.Up;
-
- else if (note.Contains("DOWN") || note.Contains("DN"))
- bendline.Direction = BendDirection.Down;
-
+ var note = bendNote.Value.ToUpper().Replace("SHARP", "R0");
var match = bendNoteRegex.Match(note);
if (match.Success)
diff --git a/EtchBendLines/EtchBendLines.csproj b/EtchBendLines/EtchBendLines.csproj
index 447afb6..e1af479 100644
--- a/EtchBendLines/EtchBendLines.csproj
+++ b/EtchBendLines/EtchBendLines.csproj
@@ -45,6 +45,7 @@
+