Files
PepApi.Core/PepLib.Core/IO/DrawingReader.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

98 lines
2.5 KiB
C#

using PepLib.Models;
using System.Diagnostics;
using System.IO.Compression;
using System.Text.RegularExpressions;
namespace PepLib.IO
{
public sealed class DrawingReader
{
public Drawing Drawing { get; private set; }
public DrawingReader()
{
Drawing = new Drawing();
}
public DrawingReader(Drawing drawing)
{
Drawing = drawing;
}
public void Read(Stream stream)
{
using (var zip = new ZipArchive(stream, ZipArchiveMode.Read, leaveOpen: true))
{
foreach (var entry in zip.Entries)
{
using var entryStream = entry.Open();
var memstream = new MemoryStream();
entryStream.CopyTo(memstream);
memstream.Seek(0, SeekOrigin.Begin);
var extension = Path.GetExtension(entry.FullName);
switch (extension)
{
case ".dir":
LoadInfo(memstream);
memstream.Close();
continue;
}
if (Regex.IsMatch(extension, "loop-\\d\\d\\d"))
Drawing.Loops.Add(ReadLoop(entry.FullName, memstream));
memstream.Close();
}
}
Drawing.ResolveLoops();
}
public void Read(string nestFile)
{
if (!File.Exists(nestFile))
{
var msg = string.Format("File Not Found: {0}", nestFile);
throw new FileNotFoundException(msg);
}
Stream stream = null;
try
{
stream = new FileStream(nestFile, FileMode.Open);
Read(stream);
}
finally
{
if (stream != null)
stream.Close();
}
}
private void LoadInfo(Stream stream)
{
try
{
Drawing.Info = DrawingInfo.Load(stream);
}
catch (Exception exception)
{
Debug.WriteLine(exception.Message);
Debug.WriteLine(exception.StackTrace);
}
}
private Loop ReadLoop(string name, Stream stream)
{
var reader = new LoopReader();
reader.Read(name, stream);
return reader.Loop;
}
}
}