Files
PepApi.Core/PepLib.Core/IO/LoopReader.cs
AJ Isaacs 9088af52de 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>
2026-01-23 09:29:13 -05:00

134 lines
3.0 KiB
C#

using PepLib.Codes;
using PepLib.Geometry;
using PepLib.Models;
namespace PepLib.IO
{
internal sealed class LoopReader
{
public Loop Loop { get; private set; }
public LoopReader()
{
Loop = new Loop();
}
public LoopReader(Loop loop)
{
Loop = loop;
}
public void Read(string name, Stream stream)
{
var pgm = Program.Load(stream);
Loop.Name = name;
Loop.AddRange(pgm);
LoadInfo();
}
private void LoadInfo()
{
for (int i = Loop.Count - 1; i >= 0; --i)
{
var code = Loop[i];
if (code.CodeType() != CodeType.Comment)
continue;
var comment = (Comment)code;
if (LoadInfo(comment.Value))
Loop.RemoveAt(i);
}
}
private bool LoadInfo(string value)
{
if (value.StartsWith("REF"))
{
ParseReferenceData(value);
return true;
}
if (value.StartsWith("DRAWING"))
{
ParseDrawingData(value);
return true;
}
if (value.StartsWith("DXF"))
{
ParseDxfData(value);
return true;
}
return false;
}
private void ParseReferenceData(string data)
{
var parts = data.Split(',');
if (parts.Length != 3)
return;
int xindex = parts[0].IndexOf('X');
parts[0] = parts[0].Remove(0, xindex);
double x = 0;
double y = 0;
var xsplit = parts[0].Split('=');
if (xsplit.Length == 2)
x = ReadDouble(xsplit[1]);
var ysplit = parts[1].Split('=');
if (ysplit.Length == 2)
y = ReadDouble(ysplit[1]);
var datesplit = parts[2].Split('=');
if (datesplit.Length == 2)
{
DateTime date;
DateTime.TryParse(datesplit[1], out date);
Loop.LastReferenceDate = date;
}
Loop.ReferencePoint = new Vector(x, y);
}
private void ParseDrawingData(string data)
{
var index = data.IndexOf('=');
if (index == -1)
Loop.DrawingName = string.Empty;
Loop.DrawingName = data.Remove(0, index + 1).Trim();
}
private void ParseDxfData(string data)
{
var index = data.IndexOf('=');
if (index == -1)
Loop.DxfPath = string.Empty;
Loop.DxfPath = data.Remove(0, index + 1).Trim();
}
private static double ReadDouble(string s, double defaultValue = 0.0)
{
double f;
if (!double.TryParse(s, out f))
return defaultValue;
return f;
}
}
}