diff options
Diffstat (limited to 'UVtools.Core/FileFormats/CWSFile.cs')
-rw-r--r-- | UVtools.Core/FileFormats/CWSFile.cs | 155 |
1 files changed, 1 insertions, 154 deletions
diff --git a/UVtools.Core/FileFormats/CWSFile.cs b/UVtools.Core/FileFormats/CWSFile.cs index d620337..f8863bb 100644 --- a/UVtools.Core/FileFormats/CWSFile.cs +++ b/UVtools.Core/FileFormats/CWSFile.cs @@ -770,7 +770,7 @@ namespace UVtools.Core.FileFormats tr.Close(); } - LayerManager = new LayerManager(OutputSettings.LayersNum, this); + LayerManager.Init(OutputSettings.LayersNum); progress.ItemCount = OutputSettings.LayersNum; @@ -832,159 +832,6 @@ namespace UVtools.Core.FileFormats } } - /*inputFile.Entries.AsParallel().ForAllInApproximateOrder(zipArchiveEntry => - //foreach (var zipArchiveEntry in inputFile.Entries) - { - if (!zipArchiveEntry.Name.EndsWith(".png") || progress.Token.IsCancellationRequested) return; - - var layerIndexStr = string.Empty; - var layerStr = zipArchiveEntry.Name.Substring(0, zipArchiveEntry.Name.Length - 4); - for (int i = layerStr.Length-1; i >= 0; i--) - { - if(layerStr[i] < '0' || layerStr[i] > '9') break; - layerIndexStr = $"{layerStr[i]}{layerIndexStr}"; - } - - if (string.IsNullOrEmpty(layerIndexStr)) return; - - // - .png - 4 numbers - // string layerStr = zipArchiveEntry.Name.Substring(zipArchiveEntry.Name.Length - 4 - layerSize, layerSize); - uint layerIndex = uint.Parse(layerIndexStr); - - var startStr = $"{GCodeKeywordSlice} {layerIndex}"; - var stripGcode = - gcode.Substring(gcode.IndexOf(startStr, StringComparison.InvariantCultureIgnoreCase) + - startStr.Length); - - var endStr = $"{GCodeKeywordSlice} {layerIndex + 1}"; - var endIndex = stripGcode.IndexOf(endStr, StringComparison.InvariantCulture); - if (endIndex < 0) endIndex = stripGcode.Length; - stripGcode = stripGcode - .Substring(0, endIndex) - .Trim(' ', '\n', '\r', '\t'); - //var startCurrPos = stripGcode.Remove(0, ";currPos:".Length); - - float liftHeight = 0; - float liftSpeed = GetInitialLayerValueOrNormal(layerIndex, BottomLiftSpeed, LiftSpeed); - float retractSpeed = RetractSpeed; - float lightOffDelay = GetInitialLayerValueOrNormal(layerIndex, BottomLightOffDelay, LightOffDelay); - byte pwm = GetInitialLayerValueOrNormal(layerIndex, BottomLightPWM, LightPWM); ; - float exposureTime = GetInitialLayerValueOrNormal(layerIndex, BottomExposureTime, ExposureTime); - - //var currPos = Regex.Match(stripGcode, "G1 Z([+-]?([0-9]*[.])?[0-9]+)", RegexOptions.IgnoreCase); - var moveG1Regex = Regex.Match(stripGcode, @"G1 Z([+-]?([0-9]*[.])?[0-9]+) F(\d+)", RegexOptions.IgnoreCase); - var pwmM106Regex = Regex.Match(stripGcode, @"M106 S(\d+)", RegexOptions.IgnoreCase); - var waitRegex = Regex.Match(stripGcode, ";<Delay> (\\d+)", RegexOptions.IgnoreCase); - - if (moveG1Regex.Success) - { - var liftHeightTemp = float.Parse(moveG1Regex.Groups[1].Value, CultureInfo.InvariantCulture); - var liftSpeedTemp = float.Parse(moveG1Regex.Groups[3].Value, CultureInfo.InvariantCulture); - moveG1Regex = moveG1Regex.NextMatch(); - if (moveG1Regex.Success) - { - liftHeight = liftHeightTemp; - liftSpeed = liftSpeedTemp; - retractSpeed = float.Parse(moveG1Regex.Groups[3].Value, CultureInfo.InvariantCulture); - } - } - - if (pwmM106Regex.Success) - { - pwm = byte.Parse(pwmM106Regex.Groups[1].Value); - } - if (layerIndex == 0) - { - OutputSettings.BottomLightPWM = pwm; - } - - if (waitRegex.Success) - { - exposureTime = (float)Math.Round(float.Parse(waitRegex.Groups[1].Value, CultureInfo.InvariantCulture) / 1000f, 2); - waitRegex = waitRegex.NextMatch(); - if (waitRegex.Success) - { - lightOffDelay = (float)Math.Round(float.Parse(waitRegex.Groups[1].Value, CultureInfo.InvariantCulture) / 1000f, 2); - } - else // Only one match, meaning light off delay is not present - { - lightOffDelay = GetInitialLayerValueOrNormal(layerIndex, BottomLightOffDelay, LightOffDelay); - } - } - - byte[] buffer; - - lock (progress.Mutex) - { - using (var stream = zipArchiveEntry.Open()) - { - buffer = stream.ToArray(); - if (Printer == PrinterType.Unknown) - { - using (Mat mat = new Mat()) - { - CvInvoke.Imdecode(buffer, ImreadModes.AnyColor, mat); - Printer = mat.NumberOfChannels == 1 ? PrinterType.Elfin : PrinterType.BeneMono; - } - } - - stream.Close(); - } - } - - - if (Printer == PrinterType.BeneMono) - { - using (Mat mat = new Mat()) - { - CvInvoke.Imdecode(buffer, ImreadModes.Color, mat); - using (Mat matDecode = new Mat(mat.Height, mat.Step, DepthType.Cv8U, 1)) - { - var span = mat.GetPixelSpan<byte>(); - var spanDecode = matDecode.GetPixelSpan<byte>(); - for (int i = 0; i < span.Length; i++) - { - spanDecode[i] = span[i]; - } - - this[layerIndex] = - new Layer(layerIndex, matDecode, LayerManager) - { - ExposureTime = exposureTime, - LiftHeight = liftHeight, - LiftSpeed = liftSpeed, - RetractSpeed = retractSpeed, - LightOffDelay = lightOffDelay, - LightPWM = pwm, - }; - } - } - } - else - { - this[layerIndex] = - new Layer(layerIndex, buffer, LayerManager) - { - ExposureTime = exposureTime, - LiftHeight = liftHeight, - LiftSpeed = liftSpeed, - RetractSpeed = retractSpeed, - LightOffDelay = lightOffDelay, - LightPWM = pwm, - }; - } - - progress++; - }); - - // Fix missing values from configuration - if (LayerCount > 0 && this[0] is not null) - { - SuppressRebuildProperties = true; - BottomLiftHeight = this[0].LiftHeight; - BottomLightOffDelay = this[0].LightOffDelay; - SuppressRebuildProperties = false; - }*/ LayerManager.GetBoundingRectangle(progress); } |