Move 38 files from root directory into organized subfolders: - Enums/ (7 files): StatusType, ApplicationType, DrawingType, etc. - Geometry/ (5 files): Vector, Box, Size, Spacing, Node - Models/ (15 files): Nest, Plate, Part, Program, Report, etc. - Utilities/ (7 files): MathHelper, Tolerance, ZipHelper, etc. - Extensions/ (2 files): PartListExtensions, PlateListExtensions - Interfaces/ (1 file): IMovable Update namespaces to follow folder hierarchy (e.g., PepLib.Models). Add GlobalUsings.cs for internal backward compatibility. Update Codes/ and IO/ files with new using statements. Update PepApi.Core consumers to reference new namespaces. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
249 lines
7.0 KiB
C#
249 lines
7.0 KiB
C#
using PepLib.Models;
|
|
using Material = PepApi.Core.Models.Material;
|
|
using Part = PepApi.Core.Models.Part;
|
|
using Plate = PepApi.Core.Models.Plate;
|
|
using Size = PepApi.Core.Models.Size;
|
|
|
|
namespace PepApi.Core
|
|
{
|
|
internal static class PepHelper
|
|
{
|
|
public static bool IsTestSquare(PepLib.Models.Part part)
|
|
{
|
|
if (part == null || part.DrawingName == null)
|
|
return false;
|
|
|
|
var drawingName = part.DrawingName.ToUpper();
|
|
|
|
if (drawingName.Contains("TEST SQUARE"))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public static int GetTestSquareCount(Nest nest)
|
|
{
|
|
var count = 0;
|
|
|
|
foreach (var plate in nest.Plates)
|
|
{
|
|
foreach (var part in plate.Parts)
|
|
{
|
|
if (IsTestSquare(part))
|
|
count++;
|
|
}
|
|
}
|
|
|
|
return count;
|
|
}
|
|
|
|
public static bool AreTestSquaresInCorrectOrder(PepLib.Models.Plate plate)
|
|
{
|
|
var partsStarted = false;
|
|
|
|
foreach (var part in plate.Parts)
|
|
{
|
|
var isTestSquare = IsTestSquare(part);
|
|
|
|
if (isTestSquare)
|
|
{
|
|
if (partsStarted)
|
|
{
|
|
// test square found after a part
|
|
// test squares must be cut first
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (part.IsDisplayOnly)
|
|
continue;
|
|
|
|
partsStarted = true;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public static bool AreTestSquaresInCorrectOrder(PepLib.Models.Nest nest)
|
|
{
|
|
foreach (var plate in nest.Plates)
|
|
{
|
|
if (!AreTestSquaresInCorrectOrder(plate))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public static string GetStatus(int statusNum)
|
|
{
|
|
switch (statusNum)
|
|
{
|
|
case -1: return "Deleted";
|
|
case 0: return "To be cut";
|
|
case 1: return "Quote";
|
|
case 2: return "Has been cut";
|
|
case 3: return "Hold";
|
|
case 4: return "Quote, accepted, to be cut";
|
|
case 5: return "Quote, accepted, has been cut";
|
|
case 6: return "Quote, accepted, hold";
|
|
case 7: return "Quote, accepted, moved to wip";
|
|
case 8: return "Quote, rejected";
|
|
case 9: return "Quote, timed out";
|
|
default: return "N/A";
|
|
}
|
|
}
|
|
|
|
public static string GetApplication(int applicationID)
|
|
{
|
|
switch (applicationID)
|
|
{
|
|
case 1: return "Laser";
|
|
case 2: return "Plasma";
|
|
default: return "N/A";
|
|
}
|
|
}
|
|
|
|
public static void UpdateQtyNested(Part part, Nest nest)
|
|
{
|
|
part.QtyNested = 0;
|
|
|
|
var nestedOn = new List<int>();
|
|
// 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 => Normalize(p.DrawingName) == partName);
|
|
|
|
// plate.Duplicates is actually the quantity, so 1 Duplicate = 1 plate
|
|
qtyNested *= plate.Duplicates;
|
|
|
|
if (qtyNested > 0)
|
|
{
|
|
part.QtyNested += qtyNested;
|
|
nestedOn.Add(i);
|
|
}
|
|
}
|
|
|
|
part.NestedOn = nestedOn.ToArray();
|
|
}
|
|
|
|
public static List<Part> GetParts(Nest nest)
|
|
{
|
|
var parts = new List<Part>();
|
|
|
|
for (int i = 0; i < nest.Drawings.Count; i++)
|
|
{
|
|
var drawing = nest.Drawings[i];
|
|
|
|
if (drawing.Name.IsNullOrWhiteSpace())
|
|
continue;
|
|
|
|
var dwg = nest.Drawings.FirstOrDefault(d => d.Name == drawing.Name);
|
|
|
|
var part = new Part
|
|
{
|
|
Name = drawing.Name,
|
|
QtyRequired = dwg?.QtyRequired ?? 0
|
|
};
|
|
|
|
UpdateQtyNested(part, nest);
|
|
|
|
parts.Add(part);
|
|
}
|
|
|
|
return parts;
|
|
}
|
|
|
|
public static List<Plate> GetPlates(Nest nest)
|
|
{
|
|
var plates = new List<Plate>();
|
|
|
|
for (int i = 0; i < nest.Plates.Count; i++)
|
|
{
|
|
var plate = nest.Plates[i];
|
|
|
|
var p = new Plate
|
|
{
|
|
Name = plate.Name,
|
|
Material = GetMaterial(plate),
|
|
Qty = plate.Duplicates,
|
|
Thickness = plate.Thickness,
|
|
Size = new Size
|
|
{
|
|
Width = plate.Size.Height,
|
|
Length = plate.Size.Width
|
|
}
|
|
};
|
|
|
|
plates.Add(p);
|
|
}
|
|
|
|
return plates;
|
|
}
|
|
|
|
public static List<Plate> CombineLikePlates(IEnumerable<Plate> plates)
|
|
{
|
|
var combinedPlatesList = new List<Plate>();
|
|
var uniquePlates = plates.GroupBy(p => p.ToString());
|
|
|
|
foreach (var item in uniquePlates)
|
|
{
|
|
var plate = item.First();
|
|
plate.Name = string.Empty;
|
|
plate.Qty = item.Sum((Plate p) => p.Qty);
|
|
|
|
combinedPlatesList.Add(plate);
|
|
}
|
|
|
|
return combinedPlatesList
|
|
.OrderBy(p => p.Material.Number)
|
|
.ThenBy(p => p.Material.Grade)
|
|
.ThenBy(p => p.Size.Width)
|
|
.ThenBy(p => p.Size.Length)
|
|
.ToList();
|
|
}
|
|
|
|
public static Material GetMaterial(PepLib.Models.Plate plate)
|
|
{
|
|
return new Material
|
|
{
|
|
Number = plate.Material.Id,
|
|
Grade = plate.Material.Grade,
|
|
Thickness = plate.Thickness,
|
|
Description = plate.Description
|
|
};
|
|
}
|
|
|
|
public static Material GetMaterial(PepLib.Models.Nest nest)
|
|
{
|
|
return GetMaterial(nest.Plates.First());
|
|
}
|
|
}
|
|
}
|