Added option to replace sharp bends with radius.
This commit is contained in:
@@ -24,6 +24,10 @@ namespace EtchBendLines
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public double MaxBendRadius { get; set; } = 4;
|
public double MaxBendRadius { get; set; } = 4;
|
||||||
|
|
||||||
|
public double SharpRadius = 0.001;
|
||||||
|
|
||||||
|
public bool ReplaceSharpRadius { get; set; } = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The regular expression pattern the bend note must match
|
/// The regular expression pattern the bend note must match
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -36,6 +40,9 @@ namespace EtchBendLines
|
|||||||
var bends = new List<Bend>();
|
var bends = new List<Bend>();
|
||||||
var bendNotes = GetBendNotes();
|
var bendNotes = GetBendNotes();
|
||||||
|
|
||||||
|
if (ReplaceSharpRadius)
|
||||||
|
FixSharpBends();
|
||||||
|
|
||||||
foreach (var line in DxfDocument.Lines)
|
foreach (var line in DxfDocument.Lines)
|
||||||
{
|
{
|
||||||
if (line.Linetype.Name != "CENTERX2" && line.Layer.Name != "BEND")
|
if (line.Linetype.Name != "CENTERX2" && line.Layer.Name != "BEND")
|
||||||
@@ -57,19 +64,47 @@ namespace EtchBendLines
|
|||||||
|
|
||||||
private List<MText> GetBendNotes()
|
private List<MText> GetBendNotes()
|
||||||
{
|
{
|
||||||
var bendNotes = new List<MText>();
|
return DxfDocument.MTexts
|
||||||
|
.Where(t => GetBendDirection(t) != BendDirection.Unknown)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var text in DxfDocument.MTexts)
|
private void FixSharpBends()
|
||||||
{
|
{
|
||||||
var textAsUpper = text.Value.ToUpper();
|
var bendNotes = GetBendNotes();
|
||||||
|
|
||||||
if (textAsUpper.Contains("UP") || textAsUpper.Contains("DOWN"))
|
foreach (var bendNote in bendNotes)
|
||||||
{
|
{
|
||||||
bendNotes.Add(text);
|
var text = bendNote.Value?.ToUpper();
|
||||||
|
|
||||||
|
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<Bend> bendlines, IEnumerable<MText> bendNotes)
|
private static void AssignBendDirections(IEnumerable<Bend> bendlines, IEnumerable<MText> bendNotes)
|
||||||
@@ -82,15 +117,9 @@ namespace EtchBendLines
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
bendline.BendNote = bendNote;
|
bendline.BendNote = bendNote;
|
||||||
|
bendline.Direction = GetBendDirection(bendNote);
|
||||||
|
|
||||||
var note = bendNote.Value.ToUpper();
|
var note = bendNote.Value.ToUpper().Replace("SHARP", "R0");
|
||||||
|
|
||||||
if (note.Contains("UP"))
|
|
||||||
bendline.Direction = BendDirection.Up;
|
|
||||||
|
|
||||||
else if (note.Contains("DOWN") || note.Contains("DN"))
|
|
||||||
bendline.Direction = BendDirection.Down;
|
|
||||||
|
|
||||||
var match = bendNoteRegex.Match(note);
|
var match = bendNoteRegex.Match(note);
|
||||||
|
|
||||||
if (match.Success)
|
if (match.Success)
|
||||||
|
|||||||
@@ -45,6 +45,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Bend.cs" />
|
<Compile Include="Bend.cs" />
|
||||||
<Compile Include="BendDirection.cs" />
|
<Compile Include="BendDirection.cs" />
|
||||||
|
<Compile Include="BendLineExtractor.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" />
|
||||||
|
|||||||
Reference in New Issue
Block a user