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>
132 lines
2.9 KiB
C#
132 lines
2.9 KiB
C#
using PepLib.Codes;
|
|
using PepLib.IO;
|
|
|
|
namespace PepLib.Models
|
|
{
|
|
public class Nest
|
|
{
|
|
public Nest()
|
|
{
|
|
Report = new Report();
|
|
Loops = new List<Loop>();
|
|
Plates = new List<Plate>();
|
|
Drawings = new List<NestDrawing>();
|
|
}
|
|
|
|
public Report Report { get; set; }
|
|
|
|
public List<Loop> Loops { get; set; }
|
|
|
|
public List<Plate> Plates { get; set; }
|
|
|
|
public List<NestDrawing> Drawings { get; set; }
|
|
|
|
public void ResolveLoops()
|
|
{
|
|
for (int i = 0; i < Loops.Count; ++i)
|
|
{
|
|
var loop = Loops[i];
|
|
ResolveLoops(loop);
|
|
}
|
|
}
|
|
|
|
private void ResolveLoops(Program pgm)
|
|
{
|
|
for (int i = 0; i < pgm.Count; ++i)
|
|
{
|
|
var code = pgm[i];
|
|
|
|
if (code.CodeType() != CodeType.SubProgramCall)
|
|
continue;
|
|
|
|
var subpgmcall = (SubProgramCall)code;
|
|
|
|
var loop = GetLoop(subpgmcall.LoopId);
|
|
|
|
if (loop == null)
|
|
throw new Exception("Loop not found");
|
|
|
|
subpgmcall.Loop = loop;
|
|
}
|
|
}
|
|
|
|
public int GetQtyNested(string drawing)
|
|
{
|
|
int qty = 0;
|
|
|
|
foreach (var plate in Plates)
|
|
qty += plate.GetQtyNested(drawing);
|
|
|
|
return qty;
|
|
}
|
|
|
|
private Loop GetLoop(string name)
|
|
{
|
|
for (int i = 0; i < Loops.Count; ++i)
|
|
{
|
|
if (Loops[i].Name == name)
|
|
return Loops[i];
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public Loop GetLoop(int id)
|
|
{
|
|
var ext = $".loop-{id.ToString().PadLeft(3, '0')}";
|
|
|
|
for (int i = 0; i < Loops.Count; ++i)
|
|
{
|
|
if (Loops[i].Name.EndsWith(ext))
|
|
return Loops[i];
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public static Nest Load(string nestfile)
|
|
{
|
|
var reader = new NestReader();
|
|
reader.Read(nestfile);
|
|
return reader.Nest;
|
|
}
|
|
|
|
public static Nest Load(Stream stream)
|
|
{
|
|
var reader = new NestReader();
|
|
reader.Read(stream);
|
|
return reader.Nest;
|
|
}
|
|
|
|
public static bool TryLoad(string nestfile, out Nest nest)
|
|
{
|
|
try
|
|
{
|
|
nest = Load(nestfile);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
nest = null;
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public static bool TryLoad(Stream stream, out Nest nest)
|
|
{
|
|
try
|
|
{
|
|
nest = Load(stream);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
nest = null;
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|