fix: close polygon offset shape and handle nest template load failure

Shape.OffsetEntity computed joins between consecutive offset segments
but never joined the last segment back to the first, leaving the
closing corner with a straight line instead of a proper miter/arc.
Track the first entity and apply the same join logic after the loop.

Also wrap nest template loading in try-catch so a corrupt template
file doesn't crash the app on startup — falls back to default nest.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-13 07:37:39 -04:00
parent 2216b8553f
commit 09fc8b889e
2 changed files with 76 additions and 33 deletions
+26 -8
View File
@@ -47,6 +47,17 @@ namespace OpenNest.Forms
// BestFitCache.CreateEvaluator = (drawing, spacing) => GpuEvaluatorFactory.Create(drawing, spacing);
}
private Nest CreateDefaultNest()
{
var nest = new Nest();
nest.Units = Properties.Settings.Default.DefaultUnit;
nest.PlateDefaults.EdgeSpacing = new Spacing(1, 1, 1, 1);
nest.PlateDefaults.PartSpacing = 1;
nest.PlateDefaults.Size = new OpenNest.Geometry.Size(100, 100);
nest.PlateDefaults.Quadrant = 1;
return nest;
}
private string GetNestName(DateTime date, int id)
{
var month = date.Month.ToString().PadLeft(2, '0');
@@ -326,17 +337,24 @@ namespace OpenNest.Forms
if (File.Exists(Properties.Settings.Default.NestTemplatePath))
{
var reader = new NestReader(Properties.Settings.Default.NestTemplatePath);
nest = reader.Read();
try
{
var reader = new NestReader(Properties.Settings.Default.NestTemplatePath);
nest = reader.Read();
}
catch (Exception ex)
{
MessageBox.Show(
$"Failed to load nest template:\n{ex.Message}\n\nA default nest will be created instead.",
"Template Error",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
nest = CreateDefaultNest();
}
}
else
{
nest = new Nest();
nest.Units = Properties.Settings.Default.DefaultUnit;
nest.PlateDefaults.EdgeSpacing = new Spacing(0, 0, 0, 0);
nest.PlateDefaults.PartSpacing = 0;
nest.PlateDefaults.Size = new OpenNest.Geometry.Size(100, 100);
nest.PlateDefaults.Quadrant = 1;
nest = CreateDefaultNest();
}
nest.DateCreated = DateTime.Now;