Files
CutList/CutList.Web/Services/CutListPackingService.cs
AJ Isaacs 9868df162d feat: Add CutList.Web Blazor Server application
Add a new web-based frontend for cut list optimization using:
- Blazor Server with .NET 8
- Entity Framework Core with MSSQL LocalDB
- Full CRUD for Materials, Suppliers, Projects, and Cutting Tools
- Supplier stock length management for quick project setup
- Integration with CutList.Core for bin packing optimization
- Print-friendly HTML reports with efficiency statistics

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 21:56:21 -05:00

66 lines
1.9 KiB
C#

using CutList.Core;
using CutList.Core.Nesting;
using CutList.Web.Data.Entities;
namespace CutList.Web.Services;
public class CutListPackingService
{
public PackResult Pack(IEnumerable<ProjectPart> parts, IEnumerable<ProjectStockBin> stockBins, decimal kerfInches)
{
var engine = new MultiBinEngine();
engine.Spacing = (double)kerfInches;
engine.Strategy = PackingStrategy.AdvancedFit;
// Convert stock bins to MultiBin
var multiBins = stockBins
.Where(b => b.LengthInches > 0)
.Select(b => new MultiBin((double)b.LengthInches, b.Quantity, b.Priority))
.ToList();
engine.SetBins(multiBins);
// Convert parts to BinItem (expand quantity)
var items = parts
.SelectMany(p => Enumerable.Range(0, p.Quantity)
.Select(_ => new BinItem(p.Name, (double)p.LengthInches)))
.ToList();
return engine.Pack(items);
}
public PackingSummary GetSummary(PackResult result)
{
var summary = new PackingSummary();
foreach (var bin in result.Bins)
{
summary.TotalBins++;
summary.TotalMaterial += bin.Length;
summary.TotalUsed += bin.UsedLength;
summary.TotalWaste += bin.RemainingLength;
summary.TotalPieces += bin.Items.Count;
}
summary.ItemsNotPlaced = result.ItemsNotUsed.Count;
if (summary.TotalMaterial > 0)
{
summary.Efficiency = summary.TotalUsed / summary.TotalMaterial * 100;
}
return summary;
}
}
public class PackingSummary
{
public int TotalBins { get; set; }
public int TotalPieces { get; set; }
public double TotalMaterial { get; set; }
public double TotalUsed { get; set; }
public double TotalWaste { get; set; }
public double Efficiency { get; set; }
public int ItemsNotPlaced { get; set; }
}