Added Files
This commit is contained in:
134
PepLib.Core/Nest.cs
Normal file
134
PepLib.Core/Nest.cs
Normal file
@@ -0,0 +1,134 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using PepLib.Codes;
|
||||
using PepLib.IO;
|
||||
|
||||
namespace PepLib
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user