fix: assign part colors to drawings created by BOM importer and MCP
Drawings created by BomImportForm and MCP InputTools were missing color assignments, causing them to render with default empty color instead of the standard part color palette. Moved PartColors and GetNextColor() to Drawing in Core so all consumers share one definition. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -12,8 +12,32 @@ namespace OpenNest
|
|||||||
public class Drawing
|
public class Drawing
|
||||||
{
|
{
|
||||||
private static int nextId;
|
private static int nextId;
|
||||||
|
private static int nextColorIndex;
|
||||||
private Program program;
|
private Program program;
|
||||||
|
|
||||||
|
public static readonly Color[] PartColors = new Color[]
|
||||||
|
{
|
||||||
|
Color.FromArgb(205, 92, 92), // Indian Red
|
||||||
|
Color.FromArgb(148, 103, 189), // Medium Purple
|
||||||
|
Color.FromArgb(75, 180, 175), // Teal
|
||||||
|
Color.FromArgb(210, 190, 75), // Goldenrod
|
||||||
|
Color.FromArgb(190, 85, 175), // Orchid
|
||||||
|
Color.FromArgb(185, 115, 85), // Sienna
|
||||||
|
Color.FromArgb(120, 100, 190), // Slate Blue
|
||||||
|
Color.FromArgb(200, 100, 140), // Rose
|
||||||
|
Color.FromArgb(80, 175, 155), // Sea Green
|
||||||
|
Color.FromArgb(195, 160, 85), // Dark Khaki
|
||||||
|
Color.FromArgb(175, 95, 160), // Plum
|
||||||
|
Color.FromArgb(215, 130, 130), // Light Coral
|
||||||
|
};
|
||||||
|
|
||||||
|
public static Color GetNextColor()
|
||||||
|
{
|
||||||
|
var color = PartColors[nextColorIndex % PartColors.Length];
|
||||||
|
nextColorIndex++;
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
public Drawing()
|
public Drawing()
|
||||||
: this(string.Empty, new Program())
|
: this(string.Empty, new Program())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ namespace OpenNest.Mcp.Tools
|
|||||||
|
|
||||||
var drawingName = name ?? Path.GetFileNameWithoutExtension(path);
|
var drawingName = name ?? Path.GetFileNameWithoutExtension(path);
|
||||||
var drawing = new Drawing(drawingName, pgm);
|
var drawing = new Drawing(drawingName, pgm);
|
||||||
|
drawing.Color = Drawing.GetNextColor();
|
||||||
_session.Drawings.Add(drawing);
|
_session.Drawings.Add(drawing);
|
||||||
|
|
||||||
var bbox = pgm.BoundingBox();
|
var bbox = pgm.BoundingBox();
|
||||||
@@ -155,6 +156,7 @@ namespace OpenNest.Mcp.Tools
|
|||||||
if (pgm == null)
|
if (pgm == null)
|
||||||
return "Error: failed to parse G-code";
|
return "Error: failed to parse G-code";
|
||||||
var gcodeDrawing = new Drawing(name, pgm);
|
var gcodeDrawing = new Drawing(name, pgm);
|
||||||
|
gcodeDrawing.Color = Drawing.GetNextColor();
|
||||||
_session.Drawings.Add(gcodeDrawing);
|
_session.Drawings.Add(gcodeDrawing);
|
||||||
var gcodeBbox = pgm.BoundingBox();
|
var gcodeBbox = pgm.BoundingBox();
|
||||||
return $"Created drawing '{name}': bbox={gcodeBbox.Width:F2} x {gcodeBbox.Length:F2}";
|
return $"Created drawing '{name}': bbox={gcodeBbox.Width:F2} x {gcodeBbox.Length:F2}";
|
||||||
@@ -164,6 +166,7 @@ namespace OpenNest.Mcp.Tools
|
|||||||
}
|
}
|
||||||
|
|
||||||
var drawing = shapeDef.GetDrawing();
|
var drawing = shapeDef.GetDrawing();
|
||||||
|
drawing.Color = Drawing.GetNextColor();
|
||||||
_session.Drawings.Add(drawing);
|
_session.Drawings.Add(drawing);
|
||||||
|
|
||||||
var bbox = drawing.Program.BoundingBox();
|
var bbox = drawing.Program.BoundingBox();
|
||||||
|
|||||||
@@ -79,21 +79,7 @@ int RunDataCollection(string dir, string dbPath, string saveDir, double s, strin
|
|||||||
Console.WriteLine($"Using template: {template}");
|
Console.WriteLine($"Using template: {template}");
|
||||||
}
|
}
|
||||||
|
|
||||||
var PartColors = new[]
|
var PartColors = Drawing.PartColors;
|
||||||
{
|
|
||||||
Color.FromArgb(205, 92, 92),
|
|
||||||
Color.FromArgb(148, 103, 189),
|
|
||||||
Color.FromArgb(75, 180, 175),
|
|
||||||
Color.FromArgb(210, 190, 75),
|
|
||||||
Color.FromArgb(190, 85, 175),
|
|
||||||
Color.FromArgb(185, 115, 85),
|
|
||||||
Color.FromArgb(120, 100, 190),
|
|
||||||
Color.FromArgb(200, 100, 140),
|
|
||||||
Color.FromArgb(80, 175, 155),
|
|
||||||
Color.FromArgb(195, 160, 85),
|
|
||||||
Color.FromArgb(175, 95, 160),
|
|
||||||
Color.FromArgb(215, 130, 130),
|
|
||||||
};
|
|
||||||
|
|
||||||
var sheetSuite = new[]
|
var sheetSuite = new[]
|
||||||
{
|
{
|
||||||
|
|||||||
+1
-15
@@ -13,21 +13,7 @@ namespace OpenNest
|
|||||||
private Color edgeSpacingColor;
|
private Color edgeSpacingColor;
|
||||||
private Color previewPartColor;
|
private Color previewPartColor;
|
||||||
|
|
||||||
public static readonly Color[] PartColors = new Color[]
|
public static Color[] PartColors => Drawing.PartColors;
|
||||||
{
|
|
||||||
Color.FromArgb(205, 92, 92), // Indian Red
|
|
||||||
Color.FromArgb(148, 103, 189), // Medium Purple
|
|
||||||
Color.FromArgb(75, 180, 175), // Teal
|
|
||||||
Color.FromArgb(210, 190, 75), // Goldenrod
|
|
||||||
Color.FromArgb(190, 85, 175), // Orchid
|
|
||||||
Color.FromArgb(185, 115, 85), // Sienna
|
|
||||||
Color.FromArgb(120, 100, 190), // Slate Blue
|
|
||||||
Color.FromArgb(200, 100, 140), // Rose
|
|
||||||
Color.FromArgb(80, 175, 155), // Sea Green
|
|
||||||
Color.FromArgb(195, 160, 85), // Dark Khaki
|
|
||||||
Color.FromArgb(175, 95, 160), // Plum
|
|
||||||
Color.FromArgb(215, 130, 130), // Light Coral
|
|
||||||
};
|
|
||||||
|
|
||||||
public static readonly ColorScheme Default = new ColorScheme
|
public static readonly ColorScheme Default = new ColorScheme
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -420,6 +420,7 @@ namespace OpenNest.Forms
|
|||||||
|
|
||||||
var drawingName = Path.GetFileNameWithoutExtension(part.DxfPath);
|
var drawingName = Path.GetFileNameWithoutExtension(part.DxfPath);
|
||||||
var drawing = new Drawing(drawingName);
|
var drawing = new Drawing(drawingName);
|
||||||
|
drawing.Color = Drawing.GetNextColor();
|
||||||
drawing.Source.Path = part.DxfPath;
|
drawing.Source.Path = part.DxfPath;
|
||||||
drawing.Quantity.Required = part.Qty ?? 1;
|
drawing.Quantity.Required = part.Qty ?? 1;
|
||||||
drawing.Material = new Material(material);
|
drawing.Material = new Material(material);
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace OpenNest.Forms
|
|||||||
{
|
{
|
||||||
public partial class CadConverterForm : Form
|
public partial class CadConverterForm : Form
|
||||||
{
|
{
|
||||||
private static int colorIndex;
|
|
||||||
private SimplifierViewerForm simplifierViewer;
|
private SimplifierViewerForm simplifierViewer;
|
||||||
private bool staleProgram = true;
|
private bool staleProgram = true;
|
||||||
|
|
||||||
@@ -622,7 +622,7 @@ namespace OpenNest.Forms
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
var drawing = new Drawing(item.Name);
|
var drawing = new Drawing(item.Name);
|
||||||
drawing.Color = GetNextColor();
|
drawing.Color = Drawing.GetNextColor();
|
||||||
drawing.Customer = item.Customer;
|
drawing.Customer = item.Customer;
|
||||||
drawing.Source.Path = item.Path;
|
drawing.Source.Path = item.Path;
|
||||||
drawing.Quantity.Required = item.Quantity;
|
drawing.Quantity.Required = item.Quantity;
|
||||||
@@ -671,12 +671,7 @@ namespace OpenNest.Forms
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static Color GetNextColor()
|
private static Color GetNextColor() => Drawing.GetNextColor();
|
||||||
{
|
|
||||||
var color = ColorScheme.PartColors[colorIndex % ColorScheme.PartColors.Length];
|
|
||||||
colorIndex++;
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool IsDirectoryWritable(string path)
|
private static bool IsDirectoryWritable(string path)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user