fix(parts): normalize drawing names for matching
- Strip directories and extensions and compare using ToUpperInvariant - Improves resilience when sources differ in path/casing/extension formatting - Ensures accurate QtyNested across plates with duplicates
This commit is contained in:
@@ -117,14 +117,30 @@ namespace PepApi.Core
|
||||
part.QtyNested = 0;
|
||||
|
||||
var nestedOn = new List<int>();
|
||||
var partName = part.Name.ToUpper();
|
||||
// Normalize drawing names by stripping directories and extensions
|
||||
// to make matching resilient to format differences between sources.
|
||||
string Normalize(string? name)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(name)) return string.Empty;
|
||||
try
|
||||
{
|
||||
var fileOnly = System.IO.Path.GetFileNameWithoutExtension(name);
|
||||
return fileOnly.ToUpperInvariant();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return name.Trim().ToUpperInvariant();
|
||||
}
|
||||
}
|
||||
|
||||
var partName = Normalize(part.Name);
|
||||
|
||||
for (int i = 0; i < nest.Plates.Count; i++)
|
||||
{
|
||||
var plate = nest.Plates[i];
|
||||
var qtyNested = 0;
|
||||
|
||||
qtyNested = plate.Parts.Count(p => p.DrawingName?.ToUpper() == partName);
|
||||
qtyNested = plate.Parts.Count(p => Normalize(p.DrawingName) == partName);
|
||||
|
||||
// plate.Duplicates is actually the quantity, so 1 Duplicate = 1 plate
|
||||
qtyNested *= plate.Duplicates;
|
||||
|
||||
Reference in New Issue
Block a user