diff --git a/LaserGRBL/GrblCommand.cs b/LaserGRBL/GrblCommand.cs index 3de1d076..9acc89bd 100644 --- a/LaserGRBL/GrblCommand.cs +++ b/LaserGRBL/GrblCommand.cs @@ -90,7 +90,7 @@ private static void LoadAppropriateErrors(GrblCore.GrblVersionInfo value) } } - public partial class GrblCommand : ICloneable, IGrblRow + public partial class GrblCommand : ICloneable, IGrblRow, IDisposable { public class Element { @@ -474,7 +474,12 @@ public int ImageIndex public override string ToString() { return this.mLine; } - } + + public void Dispose() + { + LinkedDisplayList = null; + } + } public class GrblMessage : IGrblRow { diff --git a/LaserGRBL/GrblFile.cs b/LaserGRBL/GrblFile.cs index 7fe1784b..9b121698 100644 --- a/LaserGRBL/GrblFile.cs +++ b/LaserGRBL/GrblFile.cs @@ -33,7 +33,7 @@ public enum CartesianQuadrant { I, II, III, IV, Mix, Unknown } private ProgramRange mRange = new ProgramRange(); private TimeSpan mEstimatedTotalTime; public List Commands => list; - private Tools.ThreadObject mLoadingThread = null; + private Thread mLoadingThread = null; public GrblFile() { @@ -44,9 +44,18 @@ public GrblFile(decimal x, decimal y, decimal x1, decimal y1) { mRange.UpdateXYRange(new GrblCommand.Element('X', x), new GrblCommand.Element('Y', y), false); mRange.UpdateXYRange(new GrblCommand.Element('X', x1), new GrblCommand.Element('Y', y1), false); - } + } + + private void ClearList() + { + foreach (GrblCommand command in list) + { + command.Dispose(); + } + list.Clear(); + } - public void SaveGCODE(string filename, bool header, bool footer, bool between, int cycles, bool useLFLineEndings, GrblCore core) + public void SaveGCODE(string filename, bool header, bool footer, bool between, int cycles, bool useLFLineEndings, GrblCore core) { try { @@ -98,7 +107,7 @@ private void SafeLoadFile(ThreadStart loadFileAction) MessageBox.Show(Strings.AlreadyLoading); return; } - mLoadingThread = new Tools.ThreadObject(null, 10, true, "SafeLoadFile", () => + mLoadingThread = new Thread(new ThreadStart(() => { try { @@ -112,7 +121,7 @@ private void SafeLoadFile(ThreadStart loadFileAction) { mLoadingThread = null; } - }, ThreadPriority.Normal); + })); mLoadingThread.Start(); } @@ -125,7 +134,7 @@ public void LoadFile(string filename, bool append) long start = Tools.HiResTimer.TotalMilliseconds; if (!append) - list.Clear(); + ClearList(); mRange.ResetRange(); if (System.IO.File.Exists(filename)) @@ -158,7 +167,7 @@ public void LoadImportedSVG(string filename, bool append, GrblCore core, ColorFi long start = Tools.HiResTimer.TotalMilliseconds; if (!append) - list.Clear(); + ClearList(); mRange.ResetRange(); @@ -345,7 +354,7 @@ public void LoadImagePotrace(Bitmap bmp, string filename, bool UseSpotRemoval, i long start = Tools.HiResTimer.TotalMilliseconds; if (!append) - list.Clear(); + ClearList(); //list.Add(new GrblCommand("G90")); //absolute (Moved to custom Header) @@ -504,7 +513,7 @@ public void LoadImageL2L(Bitmap bmp, string filename, L2LConf c, bool append, Gr long start = Tools.HiResTimer.TotalMilliseconds; if (!append) - list.Clear(); + ClearList(); mRange.ResetRange(); @@ -551,7 +560,7 @@ internal void GenerateCuttingTest(int f_col, int f_start, int f_end, int p_start long start = Tools.HiResTimer.TotalMilliseconds; - list.Clear(); + ClearList(); mRange.ResetRange(); double f_delta = f_col > 1 ? (f_end - f_start) / (double)(f_col - 1) : 0; @@ -629,7 +638,7 @@ public void GenerateGreyscaleTest(int f_row, int s_col, int f_start, int f_end, long start = Tools.HiResTimer.TotalMilliseconds; - list.Clear(); + ClearList(); mRange.ResetRange(); bool forward = true; @@ -745,7 +754,7 @@ internal void GenerateShakeTest(string axis, int flimit, int axislen, int cpower long start = Tools.HiResTimer.TotalMilliseconds; - list.Clear(); + ClearList(); mRange.ResetRange(); list.Add(new GrblCommand("M5")); //laser OFF @@ -800,58 +809,58 @@ private void GenerateShakeTest2(string axis, int flimit, int axislen, int o, int } } - //internal void GenerateShakeTest(string axis, int flimit, int axislen, int cpower, int cspeed) - //{ - // string filename = $"Shake Test {axis}"; - - // RiseOnFileLoading(filename); - - // long start = Tools.HiResTimer.TotalMilliseconds; - - // list.Clear(); - // mRange.ResetRange(); - - // list.Add(new GrblCommand("M5")); //laser OFF - // list.Add(new GrblCommand("G1 F1000 X0 Y0 S0")); //move to origin (slowly) - // list.Add(new GrblCommand($"G1 F{cspeed} X7 Y10")); //positioning - // list.Add(new GrblCommand("M4")); //laser ON - // list.Add(new GrblCommand($"G1 F{cspeed} S{cpower} X13 Y10")); //drow cross - // list.Add(new GrblCommand("M5")); //laser OFF - // list.Add(new GrblCommand($"G1 F{cspeed} X10 Y7")); //positioning - // list.Add(new GrblCommand("M4")); //laser ON - // list.Add(new GrblCommand($"G1 F{cspeed} S{cpower} X10 Y13")); //drow cross - // list.Add(new GrblCommand("M5")); //laser OFF - // list.Add(new GrblCommand("G1 F1000 X10 Y10 S0")); //move to cross center (slowly) - - // int ca = 10; - // int da = 1; - // while ((ca + da) < axislen) - // { - // ca += da; - // list.Add(new GrblCommand($"G1 F{flimit} {axis}{ca}")); - // ca -= da; - // list.Add(new GrblCommand($"G1 F{flimit} {axis}{ca}")); - // da += 5; - // } - - // list.Add(new GrblCommand($"G1 F{cspeed} X7 Y10")); //positioning - // list.Add(new GrblCommand("M4")); //laser ON - // list.Add(new GrblCommand($"G1 F{cspeed} S{cpower} X13 Y10")); //drow cross - // list.Add(new GrblCommand("M5")); //laser OFF - // list.Add(new GrblCommand($"G1 F{cspeed} X10 Y7")); //positioning - // list.Add(new GrblCommand("M4")); //laser ON - // list.Add(new GrblCommand($"G1 F{cspeed} S{cpower} X10 Y13")); //drow cross - // list.Add(new GrblCommand("M5")); //laser OFF - - // Analyze(); - // long elapsed = Tools.HiResTimer.TotalMilliseconds - start; - - // RiseOnFileLoaded(filename, elapsed); - //} - - // For Marlin, as we sen M106 command, we need to know last color send - //private int lastColorSend = 0; - private void ImageLine2Line(Bitmap bmp, L2LConf c) + //internal void GenerateShakeTest(string axis, int flimit, int axislen, int cpower, int cspeed) + //{ + // string filename = $"Shake Test {axis}"; + + // RiseOnFileLoading(filename); + + // long start = Tools.HiResTimer.TotalMilliseconds; + + // ClearList(); + // mRange.ResetRange(); + + // list.Add(new GrblCommand("M5")); //laser OFF + // list.Add(new GrblCommand("G1 F1000 X0 Y0 S0")); //move to origin (slowly) + // list.Add(new GrblCommand($"G1 F{cspeed} X7 Y10")); //positioning + // list.Add(new GrblCommand("M4")); //laser ON + // list.Add(new GrblCommand($"G1 F{cspeed} S{cpower} X13 Y10")); //drow cross + // list.Add(new GrblCommand("M5")); //laser OFF + // list.Add(new GrblCommand($"G1 F{cspeed} X10 Y7")); //positioning + // list.Add(new GrblCommand("M4")); //laser ON + // list.Add(new GrblCommand($"G1 F{cspeed} S{cpower} X10 Y13")); //drow cross + // list.Add(new GrblCommand("M5")); //laser OFF + // list.Add(new GrblCommand("G1 F1000 X10 Y10 S0")); //move to cross center (slowly) + + // int ca = 10; + // int da = 1; + // while ((ca + da) < axislen) + // { + // ca += da; + // list.Add(new GrblCommand($"G1 F{flimit} {axis}{ca}")); + // ca -= da; + // list.Add(new GrblCommand($"G1 F{flimit} {axis}{ca}")); + // da += 5; + // } + + // list.Add(new GrblCommand($"G1 F{cspeed} X7 Y10")); //positioning + // list.Add(new GrblCommand("M4")); //laser ON + // list.Add(new GrblCommand($"G1 F{cspeed} S{cpower} X13 Y10")); //drow cross + // list.Add(new GrblCommand("M5")); //laser OFF + // list.Add(new GrblCommand($"G1 F{cspeed} X10 Y7")); //positioning + // list.Add(new GrblCommand("M4")); //laser ON + // list.Add(new GrblCommand($"G1 F{cspeed} S{cpower} X10 Y13")); //drow cross + // list.Add(new GrblCommand("M5")); //laser OFF + + // Analyze(); + // long elapsed = Tools.HiResTimer.TotalMilliseconds - start; + + // RiseOnFileLoaded(filename, elapsed); + //} + + // For Marlin, as we sen M106 command, we need to know last color send + //private int lastColorSend = 0; + private void ImageLine2Line(Bitmap bmp, L2LConf c) { bool fast = true; List segments = GetSegments(bmp, c); @@ -1377,7 +1386,7 @@ internal void LoadImageCenterline(Bitmap bmp, string filename, bool useCornerThr long start = Tools.HiResTimer.TotalMilliseconds; if (!append) - list.Clear(); + ClearList(); mRange.ResetRange();