refactor(PepLib.Core): reorganize files into logical folder structure

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>
This commit is contained in:
2026-01-23 09:29:13 -05:00
parent c5be48a807
commit 9088af52de
55 changed files with 137 additions and 76 deletions

View File

@@ -0,0 +1,280 @@
using PepLib.Codes;
using PepLib.Enums;
using PepLib.IO;
namespace PepLib.Models
{
public class Drawing
{
public DrawingInfo Info { get; set; }
public List<Loop> Loops { get; set; }
public Drawing()
{
Loops = new List<Loop>();
}
public static Drawing Load(string nestfile)
{
var reader = new DrawingReader();
reader.Read(nestfile);
return reader.Drawing;
}
public static Drawing Load(Stream stream)
{
var reader = new DrawingReader();
reader.Read(stream);
return reader.Drawing;
}
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 Loop GetLoop(int id)
{
string name = GetLoopName(id);
return GetLoop(name);
}
private Loop GetLoop(string name)
{
for (int i = 0; i < Loops.Count; ++i)
{
if (Loops[i].Name == name)
return Loops[i];
}
return null;
}
private string GetLoopName(int loopId)
{
return string.Format("{0}.loop-{1}", Info.Name, loopId.ToString().PadLeft(3, '0'));
}
public static bool TryLoad(string nestfile, out Drawing drawing)
{
try
{
drawing = Load(nestfile);
}
catch (Exception)
{
drawing = null;
return false;
}
return true;
}
public static bool TryLoad(Stream stream, out Drawing drawing)
{
try
{
drawing = Load(stream);
}
catch (Exception)
{
drawing = null;
return false;
}
return true;
}
#region DrawingInfo wrapper properties
public string Name
{
get { return Info.Name; }
set { Info.Name = value; }
}
public string Revision
{
get { return Info.Revision; }
set { Info.Revision = value; }
}
public string Customer
{
get { return Info.Customer; }
set { Info.Customer = value; }
}
public string Description
{
get { return Info.Description; }
set { Info.Description = value; }
}
public string Comment
{
get { return Info.Comment; }
set { Info.Comment = value; }
}
public string Notes
{
get { return Info.Notes; }
set { Info.Notes = value; }
}
public string Source
{
get { return Info.Source; }
set { Info.Source = value; }
}
public DateTime CreationDate
{
get { return Info.CreationDate; }
set { Info.CreationDate = value; }
}
public DateTime LastModifiedDate
{
get { return Info.LastModifiedDate; }
set { Info.LastModifiedDate = value; }
}
public DateTime LastReferenceDate
{
get { return Info.LastReferenceDate; }
set { Info.LastReferenceDate = value; }
}
public int MachineNumber
{
get { return Info.MachineNumber; }
set { Info.MachineNumber = value; }
}
public ApplicationType Application
{
get { return Info.Application; }
set { Info.Application = value; }
}
public int MaterialNumber
{
get { return Info.MaterialNumber; }
set { Info.MaterialNumber = value; }
}
public string MaterialGrade
{
get { return Info.MaterialGrade; }
set { Info.MaterialGrade = value; }
}
public string Specification
{
get { return Info.Specification; }
set { Info.Specification = value; }
}
public string Hardness
{
get { return Info.Hardness; }
set { Info.Hardness = value; }
}
public GrainType Grain
{
get { return Info.Grain; }
set { Info.Grain = value; }
}
public string ProgrammedBy
{
get { return Info.ProgrammedBy; }
set { Info.ProgrammedBy = value; }
}
public string CreatedBy
{
get { return Info.CreatedBy; }
set { Info.CreatedBy = value; }
}
public string Errors
{
get { return Info.Errors; }
set { Info.Errors = value; }
}
public DrawingType Type
{
get { return Info.Type; }
set { Info.Type = value; }
}
public string UserDefined1
{
get { return Info.UserDefined1; }
set { Info.UserDefined1 = value; }
}
public string UserDefined2
{
get { return Info.UserDefined2; }
set { Info.UserDefined2 = value; }
}
public string UserDefined3
{
get { return Info.UserDefined3; }
set { Info.UserDefined3 = value; }
}
public string UserDefined4
{
get { return Info.UserDefined4; }
set { Info.UserDefined4 = value; }
}
public string UserDefined5
{
get { return Info.UserDefined5; }
set { Info.UserDefined5 = value; }
}
public string UserDefined6
{
get { return Info.UserDefined6; }
set { Info.UserDefined6 = value; }
}
#endregion
}
}

View File

@@ -0,0 +1,106 @@
using PepLib.Enums;
using PepLib.IO;
namespace PepLib.Models
{
public class DrawingInfo
{
public string Name { get; set; }
public string Revision { get; set; }
public string Customer { get; set; }
public string Description { get; set; }
public string Comment { get; set; }
public string Notes { get; set; }
public string Source { get; set; }
public DateTime CreationDate { get; set; }
public DateTime LastModifiedDate { get; set; }
public DateTime LastReferenceDate { get; set; }
public int MachineNumber { get; set; }
public ApplicationType Application { get; set; }
public int MaterialNumber { get; set; }
public string MaterialGrade { get; set; }
public string Specification { get; set; }
public string Hardness { get; set; }
public GrainType Grain { get; set; }
public string ProgrammedBy { get; set; }
public string CreatedBy { get; set; }
public string Errors { get; set; }
public DrawingType Type { get; set; }
public string UserDefined1 { get; set; }
public string UserDefined2 { get; set; }
public string UserDefined3 { get; set; }
public string UserDefined4 { get; set; }
public string UserDefined5 { get; set; }
public string UserDefined6 { get; set; }
public static DrawingInfo Load(string nestFile)
{
var reader = new DrawingInfoReader();
reader.Read(nestFile);
return reader.Info;
}
public static DrawingInfo Load(Stream stream)
{
var reader = new DrawingInfoReader();
reader.Read(stream);
return reader.Info;
}
public static bool TryLoad(string nestfile, out DrawingInfo drawingInfo)
{
try
{
drawingInfo = Load(nestfile);
}
catch (Exception)
{
drawingInfo = null;
return false;
}
return true;
}
public static bool TryLoad(Stream stream, out DrawingInfo drawingInfo)
{
try
{
drawingInfo = Load(stream);
}
catch (Exception)
{
drawingInfo = null;
return false;
}
return true;
}
}
}

View File

@@ -0,0 +1,58 @@
using PepLib.Codes;
using PepLib.Enums;
using PepLib.Geometry;
namespace PepLib.Models
{
public class Loop : Program
{
public Loop()
{
Mode = ProgrammingMode.Incremental;
}
public string Name { get; set; }
public Vector ReferencePoint { get; set; }
public DateTime LastReferenceDate { get; set; }
public string DrawingName { get; set; }
public string DxfPath { get; set; }
public override void Rotate(double angle)
{
base.Rotate(angle);
ReferencePoint = ReferencePoint.Rotate(angle);
}
public override void Rotate(double angle, Vector origin)
{
base.Rotate(angle, origin);
ReferencePoint = ReferencePoint.Rotate(angle);
}
public object Clone()
{
var loop = new Loop()
{
Name = this.Name,
ReferencePoint = this.ReferencePoint,
LastReferenceDate = this.LastReferenceDate,
DrawingName = this.DrawingName,
DxfPath = this.DxfPath,
Rotation = this.Rotation
};
var codes = new ICode[this.Count];
for (int i = 0; i < this.Count; ++i)
codes[i] = this[i].Clone();
loop.AddRange(codes);
return loop;
}
}
}

View File

@@ -0,0 +1,9 @@
namespace PepLib.Models
{
public class Machine
{
public int Id { get; set; }
public string Name { get; set; }
}
}

View File

@@ -0,0 +1,11 @@
namespace PepLib.Models
{
public class Material
{
public int Id { get; set; }
public string Grade { get; set; }
public double Density { get; set; }
}
}

131
PepLib.Core/Models/Nest.cs Normal file
View File

@@ -0,0 +1,131 @@
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;
}
}
}

View File

@@ -0,0 +1,9 @@
namespace PepLib.Models
{
public class NestDrawing
{
public string Name { get; set; }
public int QtyRequired { get; set; }
}
}

View File

@@ -0,0 +1,66 @@
using PepLib.IO;
using System.Text;
namespace PepLib.Models
{
public class NestIndex
{
public string Directory { get; set; }
public List<NestInfo> Entries;
public NestIndex()
{
Entries = new List<NestInfo>();
}
public string GetPath(NestInfo entry)
{
return Path.Combine(Directory, entry.Name + ".zip");
}
public static NestIndex LoadFromDir(string directory)
{
var file = Path.Combine(directory, "pepfiles.lfn");
return Load(file);
}
public static NestIndex Load(string file)
{
if (!File.Exists(file))
return null;
var index = new NestIndex() { Directory = Path.GetDirectoryName(file) };
var stream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
var reader = new StreamReader(stream);
var buffer = new char[4000];
while (reader.Read(buffer, 0, buffer.Length) > 0)
{
var memstream = new MemoryStream(Encoding.ASCII.GetBytes(buffer));
var inforeader = new NestInfoReader();
inforeader.Read(memstream);
index.Entries.Add(inforeader.Info);
}
reader.Close();
return index;
}
public static NestIndex Build(string directory)
{
var index = new NestIndex() { Directory = directory };
foreach (var file in System.IO.Directory.GetFiles(directory, "*.zip"))
{
var reader = new NestInfoReader();
reader.Read(file);
index.Entries.Add(reader.Info);
}
return index;
}
}
}

View File

@@ -0,0 +1,98 @@
using PepLib.Enums;
using PepLib.IO;
namespace PepLib.Models
{
public class NestInfo
{
public string Name { get; set; }
public DateTime DateCreated { get; set; }
public DateTime DateLastModified { get; set; }
public StatusType Status { get; set; }
public int LoopCount { get; set; }
public int ProgramCount { get; set; }
public int PlateCount { get; set; }
public string Comments { get; set; }
public string Customer { get; set; }
public string ProgrammedBy { get; set; }
public int MaterialNumber { get; set; }
public string MaterialGrade { get; set; }
public string Notes { get; set; }
public string DefaultPlateSize { get; set; }
public string Kerf { get; set; }
public string PostedAs { get; set; }
public string Errors { get; set; }
public string UserDefined1 { get; set; }
public string UserDefined2 { get; set; }
public string UserDefined3 { get; set; }
public string UserDefined4 { get; set; }
public string UserDefined5 { get; set; }
public string UserDefined6 { get; set; }
public static NestInfo Load(string nestFile)
{
var reader = new NestInfoReader();
reader.Read(nestFile);
return reader.Info;
}
public static NestInfo Load(Stream stream)
{
var reader = new NestInfoReader();
reader.Read(stream);
return reader.Info;
}
public static bool TryLoad(string nestFile, out NestInfo nestInfo)
{
try
{
nestInfo = Load(nestFile);
}
catch (Exception)
{
nestInfo = null;
return false;
}
return true;
}
public static bool TryLoad(Stream stream, out NestInfo nestInfo)
{
try
{
nestInfo = Load(stream);
}
catch (Exception)
{
nestInfo = null;
return false;
}
return true;
}
}
}

127
PepLib.Core/Models/Part.cs Normal file
View File

@@ -0,0 +1,127 @@
using PepLib.Enums;
using PepLib.Geometry;
using PepLib.Interfaces;
namespace PepLib.Models
{
public class Part : IMovable
{
private Loop baseLoop;
private Vector location;
private Part()
{
BoundingBox = new Box();
}
public Box BoundingBox { get; protected set; }
public Vector Location
{
get { return location; }
set
{
BoundingBox.Offset(value - location);
location = value;
}
}
public string Name
{
get { return baseLoop.Name; }
set { baseLoop.Name = value; }
}
/// <summary>
/// Reference point relative to the part location.
/// </summary>
public Vector ReferencePoint
{
get { return baseLoop.ReferencePoint; }
set { baseLoop.ReferencePoint = value; }
}
/// <summary>
/// Reference point relative to the zero point.
/// </summary>
public Vector AbsoluteReferencePoint
{
get { return baseLoop.ReferencePoint + location; }
set { baseLoop.ReferencePoint = value - location; }
}
public DateTime LastReferenceDate
{
get { return baseLoop.LastReferenceDate; }
set { baseLoop.LastReferenceDate = value; }
}
public string DrawingName
{
get { return baseLoop.DrawingName; }
set { baseLoop.DrawingName = value; }
}
public string DxfPath
{
get { return baseLoop.DxfPath; }
set { baseLoop.DxfPath = value; }
}
public double Rotation
{
get { return baseLoop.Rotation; }
}
public bool IsDisplayOnly { get; set; } = false;
public void Rotate(double angle)
{
baseLoop.Rotate(angle);
location = Location.Rotate(angle);
UpdateBounds();
}
public void Rotate(double angle, Vector origin)
{
baseLoop.Rotate(angle);
location = Location.Rotate(angle, origin);
UpdateBounds();
}
public void Offset(double x, double y)
{
location = new Vector(location.X + x, location.Y + y);
BoundingBox.Offset(x, y);
}
public void Offset(Vector voffset)
{
location += voffset;
BoundingBox.Offset(voffset);
}
public Program Program
{
get { return baseLoop; }
}
public void UpdateBounds()
{
BoundingBox = baseLoop.GetBoundingBox();
BoundingBox.Offset(Location);
}
public static Part Create(Loop loop, Vector location, double rotation = 0.0)
{
var part = new Part();
part.baseLoop = (Loop)loop.Clone();
part.baseLoop.Mode = ProgrammingMode.Incremental;
part.baseLoop.Rotate(rotation);
part.Location = location;
part.UpdateBounds();
return part;
}
}
}

267
PepLib.Core/Models/Plate.cs Normal file
View File

@@ -0,0 +1,267 @@
using PepLib.Extensions;
using PepLib.Geometry;
using PepLib.Interfaces;
using PepLib.Utilities;
namespace PepLib.Models
{
public class Plate : IMovable
{
public Plate()
: this(60, 120)
{
}
public Plate(double width, double length)
: this(new Size(width, length))
{
}
public Plate(Size size)
{
EdgeSpacing = new Spacing();
Size = size;
Machine = new Machine();
Material = new Material();
Parts = new List<Part>();
Quadrant = 1;
}
public string Name { get; set; }
public string PostedFiles { get; set; }
public string HeatLot { get; set; }
public double Thickness { get; set; }
public double PartSpacing { get; set; }
public Spacing EdgeSpacing { get; set; }
public Size Size { get; set; }
public Machine Machine { get; set; }
public Material Material { get; set; }
public List<Part> Parts { get; set; }
public string Description { get; set; }
public int Duplicates { get; set; }
public int Quadrant { get; set; }
public int TorchCount { get; set; }
public void Rotate90CCW(bool keepSameQuadrant = true)
{
Size = new Size(Size.Width, Size.Height);
Rotate(MathHelper.HalfPI);
if (keepSameQuadrant)
{
switch (Quadrant)
{
case 1:
Offset(Size.Width, 0);
break;
case 2:
Offset(0, Size.Height);
break;
case 3:
Offset(-Size.Width, 0);
break;
case 4:
Offset(0, -Size.Height);
break;
}
}
else
{
Quadrant = Quadrant > 3 ? 1 : Quadrant + 1;
}
}
public void Rotate90CW(bool keepSameQuadrant = true)
{
const double oneAndHalfPI = Math.PI * 1.5;
Size = new Size(Size.Width, Size.Height);
Rotate(oneAndHalfPI);
if (keepSameQuadrant)
{
switch (Quadrant)
{
case 1:
Offset(0, Size.Height);
break;
case 2:
Offset(-Size.Width, 0);
break;
case 3:
Offset(0, -Size.Height);
break;
case 4:
Offset(Size.Width, 0);
break;
}
}
else
{
Quadrant = Quadrant < 2 ? 4 : Quadrant - 1;
}
}
public void Rotate180(bool keepSameQuadrant = true)
{
if (keepSameQuadrant)
{
Vector centerpt;
switch (Quadrant)
{
case 1:
centerpt = new Vector(Size.Width * 0.5, Size.Height * 0.5);
break;
case 2:
centerpt = new Vector(-Size.Width * 0.5, Size.Height * 0.5);
break;
case 3:
centerpt = new Vector(-Size.Width * 0.5, -Size.Height * 0.5);
break;
case 4:
centerpt = new Vector(Size.Width * 0.5, -Size.Height * 0.5);
break;
default:
return;
}
Rotate(Math.PI, centerpt);
}
else
{
Rotate(Math.PI);
Quadrant = (Quadrant + 2) % 4;
if (Quadrant == 0)
Quadrant = 4;
}
}
public void Rotate(double angle)
{
for (int i = 0; i < Parts.Count; ++i)
{
var part = Parts[i];
part.Rotate(angle);
}
}
public void Rotate(double angle, Vector origin)
{
for (int i = 0; i < Parts.Count; ++i)
{
var part = Parts[i];
part.Rotate(angle, origin);
}
}
public void Offset(double x, double y)
{
for (int i = 0; i < Parts.Count; ++i)
{
var part = Parts[i];
part.Offset(x, y);
}
}
public void Offset(Vector voffset)
{
for (int i = 0; i < Parts.Count; ++i)
{
var part = Parts[i];
part.Offset(voffset);
}
}
public int GetQtyNested(string drawing)
{
var name = drawing.ToUpper();
return Parts.Count(p => p.DrawingName.ToUpper() == name);
}
public Box GetBoundingBox(bool includeParts)
{
var plateBox = new Box();
switch (Quadrant)
{
case 1:
plateBox.X = 0;
plateBox.Y = 0;
break;
case 2:
plateBox.X = (float)-Size.Width;
plateBox.Y = 0;
break;
case 3:
plateBox.X = (float)-Size.Width;
plateBox.Y = (float)-Size.Height;
break;
case 4:
plateBox.X = 0;
plateBox.Y = (float)-Size.Height;
break;
default:
return new Box();
}
plateBox.Width = Size.Width;
plateBox.Height = Size.Height;
if (!includeParts)
return plateBox;
var boundingBox = new Box();
var partsBox = Parts.GetBoundingBox();
boundingBox.X = partsBox.Left < plateBox.Left
? partsBox.Left
: plateBox.Left;
boundingBox.Y = partsBox.Bottom < plateBox.Bottom
? partsBox.Bottom
: plateBox.Bottom;
boundingBox.Width = partsBox.Right > plateBox.Right
? partsBox.Right - boundingBox.X
: plateBox.Right - boundingBox.X;
boundingBox.Height = partsBox.Top > plateBox.Top
? partsBox.Top - boundingBox.Y
: plateBox.Top - boundingBox.Y;
return boundingBox;
}
}
}

View File

@@ -0,0 +1,368 @@
using PepLib.Codes;
using PepLib.Enums;
using PepLib.Geometry;
using PepLib.Interfaces;
using PepLib.IO;
using PepLib.Utilities;
namespace PepLib.Models
{
public class Program : List<ICode>, IMovable
{
private ProgrammingMode mode;
public Program(ProgrammingMode mode = ProgrammingMode.Absolute)
{
Mode = mode;
}
public ProgrammingMode Mode
{
get { return mode; }
set
{
if (value == ProgrammingMode.Absolute)
SetProgrammingModeAbs();
else
SetProgrammingModeInc();
}
}
public double Rotation { get; protected set; }
private void SetProgrammingModeInc()
{
if (mode == ProgrammingMode.Incremental)
return;
var pos = new Vector(0, 0);
for (int i = 0; i < Count; ++i)
{
var code = this[i];
var motion = code as Motion;
if (motion != null)
{
var pos2 = motion.EndPoint;
motion.Offset(-pos.X, -pos.Y);
pos = pos2;
}
}
mode = ProgrammingMode.Incremental;
}
private void SetProgrammingModeAbs()
{
if (mode == ProgrammingMode.Absolute)
return;
var pos = new Vector(0, 0);
for (int i = 0; i < Count; ++i)
{
var code = this[i];
var motion = code as Motion;
if (motion != null)
{
motion.Offset(pos);
pos = motion.EndPoint;
}
}
mode = ProgrammingMode.Absolute;
}
public virtual void Rotate(double angle)
{
var mode = Mode;
SetProgrammingModeAbs();
for (int i = 0; i < Count; ++i)
{
var code = this[i];
if (code.CodeType() == CodeType.SubProgramCall)
{
var subpgm = (SubProgramCall)code;
if (subpgm.Loop != null)
subpgm.Loop.Rotate(angle);
}
if (code is IMovable == false)
continue;
var code2 = (IMovable)code;
code2.Rotate(angle);
}
if (mode == ProgrammingMode.Incremental)
SetProgrammingModeInc();
Rotation = MathHelper.NormalizeAngleRad(Rotation + angle);
}
public virtual void Rotate(double angle, Vector origin)
{
var mode = Mode;
SetProgrammingModeAbs();
for (int i = 0; i < Count; ++i)
{
var code = this[i];
if (code.CodeType() == CodeType.SubProgramCall)
{
var subpgm = (SubProgramCall)code;
if (subpgm.Loop != null)
subpgm.Loop.Rotate(angle);
}
if (code is IMovable == false)
continue;
var code2 = (IMovable)code;
code2.Rotate(angle, origin);
}
if (mode == ProgrammingMode.Incremental)
SetProgrammingModeInc();
Rotation = MathHelper.NormalizeAngleRad(Rotation + angle);
}
public void Offset(double x, double y)
{
var mode = Mode;
SetProgrammingModeAbs();
for (int i = 0; i < Count; ++i)
{
var code = this[i];
if (code is IMovable == false)
continue;
var code2 = (IMovable)code;
code2.Offset(x, y);
}
if (mode == ProgrammingMode.Incremental)
SetProgrammingModeInc();
}
public void Offset(Vector voffset)
{
var mode = Mode;
SetProgrammingModeAbs();
for (int i = 0; i < Count; ++i)
{
var code = this[i];
if (code is IMovable == false)
continue;
var code2 = (IMovable)code;
code2.Offset(voffset);
}
if (mode == ProgrammingMode.Incremental)
SetProgrammingModeInc();
}
public Box GetBoundingBox()
{
var origin = new Vector(0, 0);
return GetBoundingBox(ref origin);
}
private Box GetBoundingBox(ref Vector pos)
{
double minX = 0.0;
double minY = 0.0;
double maxX = 0.0;
double maxY = 0.0;
for (int i = 0; i < Count; ++i)
{
var code = this[i];
switch (code.CodeType())
{
case CodeType.LinearMove:
{
var line = (LinearMove)code;
var pt = Mode == ProgrammingMode.Absolute ?
line.EndPoint :
line.EndPoint + pos;
if (pt.X > maxX)
maxX = pt.X;
else if (pt.X < minX)
minX = pt.X;
if (pt.Y > maxY)
maxY = pt.Y;
else if (pt.Y < minY)
minY = pt.Y;
pos = pt;
break;
}
case CodeType.RapidMove:
{
var line = (RapidMove)code;
var pt = Mode == ProgrammingMode.Absolute
? line.EndPoint
: line.EndPoint + pos;
if (pt.X > maxX)
maxX = pt.X;
else if (pt.X < minX)
minX = pt.X;
if (pt.Y > maxY)
maxY = pt.Y;
else if (pt.Y < minY)
minY = pt.Y;
pos = pt;
break;
}
case CodeType.CircularMove:
{
var arc = (CircularMove)code;
var radius = arc.CenterPoint.DistanceTo(arc.EndPoint);
Vector endpt;
Vector centerpt;
if (Mode == ProgrammingMode.Incremental)
{
endpt = arc.EndPoint + pos;
centerpt = arc.CenterPoint + pos;
}
else
{
endpt = arc.EndPoint;
centerpt = arc.CenterPoint;
}
double minX1;
double minY1;
double maxX1;
double maxY1;
if (pos.X < endpt.X)
{
minX1 = pos.X;
maxX1 = endpt.X;
}
else
{
minX1 = endpt.X;
maxX1 = pos.X;
}
if (pos.Y < endpt.Y)
{
minY1 = pos.Y;
maxY1 = endpt.Y;
}
else
{
minY1 = endpt.Y;
maxY1 = pos.Y;
}
var startAngle = pos.AngleFrom(centerpt);
var endAngle = endpt.AngleFrom(centerpt);
// switch the angle to counter clockwise.
if (arc.Rotation == RotationType.CW)
Generic.Swap(ref startAngle, ref endAngle);
startAngle = MathHelper.NormalizeAngleRad(startAngle);
endAngle = MathHelper.NormalizeAngleRad(endAngle);
if (MathHelper.IsAngleBetween(MathHelper.HalfPI, startAngle, endAngle))
maxY1 = centerpt.Y + radius;
if (MathHelper.IsAngleBetween(Math.PI, startAngle, endAngle))
minX1 = centerpt.X - radius;
const double oneHalfPI = Math.PI * 1.5;
if (MathHelper.IsAngleBetween(oneHalfPI, startAngle, endAngle))
minY1 = centerpt.Y - radius;
if (MathHelper.IsAngleBetween(MathHelper.TwoPI, startAngle, endAngle))
maxX1 = centerpt.X + radius;
if (maxX1 > maxX)
maxX = maxX1;
if (minX1 < minX)
minX = minX1;
if (maxY1 > maxY)
maxY = maxY1;
if (minY1 < minY)
minY = minY1;
pos = endpt;
break;
}
case CodeType.SubProgramCall:
{
var subpgm = (SubProgramCall)code;
var box = subpgm.Loop.GetBoundingBox(ref pos);
if (box.Left < minX)
minX = box.Left;
if (box.Right > maxX)
maxX = box.Right;
if (box.Bottom < minY)
minY = box.Bottom;
if (box.Top > maxY)
maxY = box.Top;
break;
}
}
}
return new Box(minX, minY, maxX - minX, maxY - minY);
}
public static Program Load(Stream stream)
{
var reader = new ProgramReader();
reader.Read(stream);
return reader.Program;
}
}
}

View File

@@ -0,0 +1,51 @@
namespace PepLib.Models
{
public partial class Report
{
public class Drawing
{
public string Customer { get; set; }
public string Name { get; set; }
public string Revision { get; set; }
public int QtyRequired { get; set; }
public int QtyNested { get; set; }
public int QtyRemaining
{
get { return QtyRequired - QtyNested; }
}
public double CutDistance { get; set; }
public double ScribeDistance { get; set; }
public double BevelDistance { get; set; }
public TimeSpan TotalCutTime { get; set; }
public int PierceCount { get; set; }
public int IntersectionCount { get; set; }
public double Area1 { get; set; }
public double Area2 { get; set; }
public bool IncludeRemnantInCost { get; set; }
public double NetWeight1 { get; set; }
public double NetWeight2 { get; set; }
public double GrossWeight { get; set; }
public double PercentOfMaterial { get; set; }
public double PercentOfCutTime { get; set; }
}
}
}

View File

@@ -0,0 +1,35 @@
namespace PepLib.Models
{
public partial class Report
{
public class Plate
{
public string Name { get; set; }
public double Thickness { get; set; }
public double Width { get; set; }
public double Length { get; set; }
public int MaterialNumber { get; set; }
public string MaterialGrade { get; set; }
public string MaterialDescription { get; set; }
public int Quantity { get; set; }
public double PlateUtilization { get; set; }
public double MaterialUtilization { get; set; }
public double Area1 { get; set; }
public double Area2 { get; set; }
public int BubblePierceCount { get; set; }
}
}
}

View File

@@ -0,0 +1,121 @@
using PepLib.IO;
namespace PepLib.Models
{
public partial class Report
{
public Report()
{
Drawings = new List<Report.Drawing>();
Plates = new List<Report.Plate>();
}
public List<Report.Drawing> Drawings { get; set; }
public List<Report.Plate> Plates { get; set; }
public string Name { get; set; }
public string Customer { get; set; }
public DateTime DateProgrammed { get; set; }
public string Material { get; set; }
public string ProgrammedBy { get; set; }
public string Machine { get; set; }
public string Comments { get; set; }
public string Remarks { get; set; }
public TimeSpan TotalCutTime { get; set; }
public double TotalGasUsed { get; set; }
public double TotalRapidDistance { get; set; }
public int TotalHeadRaises { get; set; }
public double CutFeedrate { get; set; }
public double RapidFeedrate { get; set; }
public TimeSpan PierceTime { get; set; }
public int PlateCount()
{
return Plates.Sum(plate => plate.Quantity);
}
public int ProgramCount()
{
return Plates.Count;
}
public double CutDistance()
{
return Drawings.Sum(dwg => dwg.CutDistance);
}
public double ScribeDistance()
{
return Drawings.Sum(dwg => dwg.ScribeDistance);
}
public double BevelDistance()
{
return Drawings.Sum(dwg => dwg.BevelDistance);
}
public int TotalPierceCount()
{
return Drawings.Sum(dwg => dwg.PierceCount);
}
public static Report Load(string nestFile)
{
var reader = new ReportReader();
reader.Read(nestFile);
return reader.Report;
}
public static Report Load(Stream stream)
{
var reader = new ReportReader();
reader.Read(stream);
return reader.Report;
}
public static bool TryLoad(string nestfile, out Report report)
{
try
{
report = Load(nestfile);
}
catch (Exception)
{
report = null;
return false;
}
return true;
}
public static bool TryLoad(Stream stream, out Report report)
{
try
{
report = Load(stream);
}
catch (Exception)
{
report = null;
return false;
}
return true;
}
}
}