Fixed reading drawing loops

This commit is contained in:
2019-04-20 15:18:01 -04:00
parent e3b3f2ee8b
commit 186311eebc
4 changed files with 59 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using PepLib.Codes;
using PepLib.IO; using PepLib.IO;
namespace PepLib namespace PepLib
@@ -30,6 +31,58 @@ namespace PepLib
return reader.Drawing; 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) public static bool TryLoad(string nestfile, out Drawing drawing)
{ {
try try

View File

@@ -22,7 +22,6 @@ namespace PepLib.IO
public void Read(Stream stream) public void Read(Stream stream)
{ {
var drawing = new Drawing();
var zipStream = new ZipInputStream(stream); var zipStream = new ZipInputStream(stream);
ZipEntry theEntry; ZipEntry theEntry;
@@ -58,12 +57,14 @@ namespace PepLib.IO
} }
if (Regex.IsMatch(extension, "loop-\\d\\d\\d")) if (Regex.IsMatch(extension, "loop-\\d\\d\\d"))
drawing.Loops.Add(ReadLoop(theEntry.FileName, memstream)); Drawing.Loops.Add(ReadLoop(theEntry.FileName, memstream));
memstream.Close(); memstream.Close();
} }
zipStream.Close(); zipStream.Close();
Drawing.ResolveLoops();
} }
public void Read(string nestFile) public void Read(string nestFile)

View File

@@ -33,8 +33,8 @@
<Prefer32Bit>false</Prefer32Bit> <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="DotNetZip, Version=1.12.0.0, Culture=neutral, PublicKeyToken=6583c7c814667745, processorArchitecture=MSIL"> <Reference Include="DotNetZip, Version=1.13.3.0, Culture=neutral, PublicKeyToken=6583c7c814667745, processorArchitecture=MSIL">
<HintPath>..\packages\DotNetZip.1.12.0\lib\net20\DotNetZip.dll</HintPath> <HintPath>..\..\packages\DotNetZip.1.13.3\lib\net40\DotNetZip.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
</ItemGroup> </ItemGroup>

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="DotNetZip" version="1.12.0" targetFramework="net461" /> <package id="DotNetZip" version="1.13.3" targetFramework="net461" />
</packages> </packages>