fix: assign colors to SpecialLayers and ConvertProgram entities

ConvertProgram.ToGeometry() created entities without setting Color,
defaulting to Color.Empty (alpha=0). After ededc7b switched from
Pens.White to per-entity colors, these rendered fully transparent.

- Add explicit colors to all SpecialLayers (Cut=White, Rapid=Gray, etc.)
- Set entity Color from layer in ConvertProgram for lines, arcs, circles
- Add GetEntityPen fallback: treat Empty/alpha-0 as White
- Add bend line rendering and selection in EntityView/CadConverterForm
- Fix SolidWorksBendDetector MText formatting strip for bend notes

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-24 21:57:50 -04:00
parent 6916f5ecca
commit d5b5ab57e3
5 changed files with 79 additions and 18 deletions

View File

@@ -17,9 +17,13 @@ namespace OpenNest.IO.Bending
public double MaxBendRadius { get; set; } = 4.0;
private static readonly Regex BendNoteRegex = new Regex(
@"\b(?<direction>UP|DOWN|DN)\s+(?<angle>\d+(\.\d+)?)°?\s*R\s*(?<radius>\d+(\.\d+)?)\b",
@"(?<direction>UP|DOWN|DN)\s+(?<angle>\d+(\.\d+)?)[^A-Z\d]*R\s*(?<radius>\d+(\.\d+)?)",
RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex MTextFormatRegex = new Regex(
@"\\[fHCTQWASpOoLlKk][^;]*;|\\P|[{}]|%%[dDpPcC]",
RegexOptions.Compiled);
public List<Bend> DetectBends(CadDocument document)
{
var bendLines = FindBendLines(document);
@@ -45,9 +49,10 @@ namespace OpenNest.IO.Bending
var note = FindClosestBendNote(line, bendNotes);
if (note != null)
{
bend.Direction = GetBendDirection(note.Value);
bend.NoteText = note.Value;
ParseBendNote(note.Value, bend);
var noteText = StripMTextFormatting(note.Value);
bend.Direction = GetBendDirection(noteText);
bend.NoteText = noteText;
ParseBendNote(noteText, bend);
}
if (!bend.Radius.HasValue || bend.Radius.Value <= MaxBendRadius)
@@ -106,6 +111,24 @@ namespace OpenNest.IO.Bending
}
}
private static string StripMTextFormatting(string text)
{
if (string.IsNullOrEmpty(text))
return text;
// Replace known DXF special characters
var result = text
.Replace("%%d", "°").Replace("%%D", "°")
.Replace("%%p", "±").Replace("%%P", "±")
.Replace("%%c", "⌀").Replace("%%C", "⌀");
// Strip MText formatting codes and braces
result = MTextFormatRegex.Replace(result, " ");
// Collapse multiple spaces
return Regex.Replace(result.Trim(), @"\s+", " ");
}
private MText FindClosestBendNote(ACadSharp.Entities.Line bendLine, List<MText> notes)
{
if (notes.Count == 0) return null;