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:
@@ -1,4 +1,5 @@
|
||||
using OpenNest.Geometry;
|
||||
using OpenNest.Bending;
|
||||
using OpenNest.Geometry;
|
||||
using OpenNest.Math;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
@@ -10,6 +11,8 @@ namespace OpenNest.Controls
|
||||
public class EntityView : DrawControl
|
||||
{
|
||||
public List<Entity> Entities;
|
||||
public List<Bend> Bends = new List<Bend>();
|
||||
public int SelectedBendIndex = -1;
|
||||
|
||||
private readonly Pen gridPen = new Pen(Color.FromArgb(70, 70, 70));
|
||||
private readonly Dictionary<int, Pen> penCache = new Dictionary<int, Pen>();
|
||||
@@ -49,6 +52,8 @@ namespace OpenNest.Controls
|
||||
DrawEntity(e.Graphics, entity, pen);
|
||||
}
|
||||
|
||||
DrawBendLines(e.Graphics);
|
||||
|
||||
#if DRAW_OFFSET
|
||||
|
||||
var offsetShape = new Shape();
|
||||
@@ -106,6 +111,9 @@ namespace OpenNest.Controls
|
||||
|
||||
private Pen GetEntityPen(Color color)
|
||||
{
|
||||
if (color.IsEmpty || color.A == 0)
|
||||
color = Color.White;
|
||||
|
||||
// Clamp dark colors to ensure visibility on dark background
|
||||
var brightness = (color.R * 299 + color.G * 587 + color.B * 114) / 1000;
|
||||
if (brightness < 80)
|
||||
@@ -130,6 +138,29 @@ namespace OpenNest.Controls
|
||||
penCache.Clear();
|
||||
}
|
||||
|
||||
private void DrawBendLines(Graphics g)
|
||||
{
|
||||
if (Bends == null || Bends.Count == 0)
|
||||
return;
|
||||
|
||||
using var bendPen = new Pen(Color.Yellow, 1.5f)
|
||||
{
|
||||
DashStyle = DashStyle.Dash
|
||||
};
|
||||
using var selectedPen = new Pen(Color.Cyan, 2.5f)
|
||||
{
|
||||
DashStyle = DashStyle.Dash
|
||||
};
|
||||
|
||||
for (var i = 0; i < Bends.Count; i++)
|
||||
{
|
||||
var bend = Bends[i];
|
||||
var pt1 = PointWorldToGraph(bend.StartPoint);
|
||||
var pt2 = PointWorldToGraph(bend.EndPoint);
|
||||
g.DrawLine(i == SelectedBendIndex ? selectedPen : bendPen, pt1, pt2);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
|
||||
@@ -134,6 +134,7 @@ namespace OpenNest.Forms
|
||||
entityView1.ClearPenCache();
|
||||
entityView1.Entities.Clear();
|
||||
entityView1.Entities.AddRange(item.Entities);
|
||||
entityView1.Bends = item.Bends ?? new List<Bend>();
|
||||
|
||||
item.Entities.ForEach(e => e.IsVisible = true);
|
||||
if (item.Entities.Any(e => e.Layer != null))
|
||||
@@ -174,7 +175,7 @@ namespace OpenNest.Forms
|
||||
|
||||
private void OnBendLineSelected(object sender, int index)
|
||||
{
|
||||
// TODO: Highlight bend line in EntityView
|
||||
entityView1.SelectedBendIndex = index;
|
||||
entityView1.Invalidate();
|
||||
}
|
||||
|
||||
@@ -184,6 +185,8 @@ namespace OpenNest.Forms
|
||||
if (item == null || index < 0 || index >= item.Bends.Count) return;
|
||||
|
||||
item.Bends.RemoveAt(index);
|
||||
entityView1.Bends = item.Bends;
|
||||
entityView1.SelectedBendIndex = -1;
|
||||
filterPanel.LoadItem(item.Entities, item.Bends);
|
||||
entityView1.Invalidate();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user