Files
UVtools/UVtools.Cmd/ProgressBar.cs
T
Tiago Conceição 57b8a9dc84 v3.2.0
- **Core:**
   - (Add) Machine presets and able to load machine collection from PrusaSlicer
   - (Improvement) Core: Reference EmguCV runtimes into core instead of the UI project
- **File formats:**
   - **CXDLP:**
      - (Add) Detection support for Halot One Pro
      - (Add) Detection support for Halot One Plus
      - (Add) Detection support for Halot Sky Plus
      - (Add) Detection support for Halot Lite
      - (Improvement) Better handling and detection of printer model when converting
      - (Improvement) Discovered more fields meanings on format
      - (Fix) Exposure time in format is `round(time * 10, 1)`
      - (Fix) Speeds in format are in mm/s, was using mm/min before
   - (Add) JXS format for Uniformation GKone [Zip+GCode]
   - (Improvement) Saving and converting files now handle the file backup on Core instead on the UI, which prevents scripts and other projects lose the original file in case of error while saving
   - (Fix) After load files they was flagged as requiring a full encode, preventing fast save a fresh file
- **UVtoolsCmd:**
   - Bring back the commandline project
   - Consult README to see the available commands and syntax
   - Old terminal commands on UVtools still works for now, but consider switch to UVtoolsCmd or redirect the command using `UVtools --cmd "commands"`
- **Tools:**
   - **Change print resolution:**
      - (Add) Allow to change the display size to match the new printer
      - (Add) Machine presets to help set both resolution and display size to a correct printer and auto set fix pixel ratio
      - (Improvement) Real pixel pitch fixer due new display size information, this allow full transfers between different printers "without" invalidating the model size
      - (Improvement) Better arrangement of  the layout
   - (Add) Infill: Option "Reinforce infill if possible", it was always on before, now default is off and configurable
   - (Improvement) Always allow to export settings from tools
- **GCode:**
   - (Improvement) After print the last layer, do one lift with the same layer settings before attempt a fast move to top
   - (Improvement) Use the highest defined speed to send the build plate to top after finish print
   - (Improvement) Append a wait sync command in the end of gcode if needed
   - (Fix) When lift without a retract it still output the motor sync delay for the retract time and the wait time after retract
- **PrusaSlicer:**
   - (Add) Printer: Creality Halot One Pro CL-70
   - (Add) Printer: Creality Halot One Plus CL-79
   - (Add) Printer: Creality Halot Sky Plus CL-92
   - (Add) Printer: Creality Halot Lite CL-89L
   - (Add) Printer: Creality Halot Lite CL-89L
   - (Add) Printer: Creality CT133 Pro
   - (Add) Printer: Creality CT-005 Pro
   - (Add) Printer: Uniformation GKone
   - (Add) Printer: FlashForge Foto 8.9S
   - (Add) Printer: Elegoo Mars 2
   - (Improvement) Rename all Creality printers
   - (Fix) Creality model in print notes
2022-03-26 03:38:39 +00:00

126 lines
4.0 KiB
C#

/*
* GNU AFFERO GENERAL PUBLIC LICENSE
* Version 3, 19 November 2007
* Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*/
namespace UVtools.Cmd;
using System;
using System.Text;
using System.Threading;
/// <summary>
/// An ASCII progress bar
/// </summary>
public class ProgressBar : IDisposable
{
private const byte BlockCount = 10;
private readonly TimeSpan _animationInterval = TimeSpan.FromMilliseconds(125);
private const string Animation = @"|/-\";
private readonly Timer _timer;
private string _currentText = string.Empty;
private bool _disposed;
private int _animationIndex;
private double _lastProgressPercent = -1;
private readonly StringBuilder _outputBuilder = new();
public ProgressBar()
{
_timer = new Timer(TimerHandler);
// A progress bar is only for temporary display in a console window.
// If the console output is redirected to a file, draw nothing.
// Otherwise, we'll end up with a lot of garbage in the target file.
if (Program.Quiet || Program.NoProgress) return;
if(Console.IsOutputRedirected) Console.WriteLine();
ResetTimer();
}
private void TimerHandler(object? state)
{
lock (_timer)
{
if (_disposed) return;
if (Math.Abs(_lastProgressPercent - Program.Progress.ProgressPercent) > 0.009)
{
_lastProgressPercent = Program.Progress.ProgressPercent;
var progressBlockCount = (int)(_lastProgressPercent * BlockCount / 100);
if (Console.IsOutputRedirected)
{
var text = string.Format("[{0}{1}] {2:F2}% ({3:F2}s)",
new string('#', progressBlockCount), new string('-', BlockCount - progressBlockCount),
Program.Progress.ProgressPercent,
Program.StopWatch.ElapsedMilliseconds / 1000.0);
Console.WriteLine(text);
}
else
{
var text = string.Format("[{0}{1}] {2:F2}% {3} {4:F2}s",
new string('#', progressBlockCount), new string('-', BlockCount - progressBlockCount),
Program.Progress.ProgressPercent,
Animation[_animationIndex++ % Animation.Length],
Program.StopWatch.ElapsedMilliseconds / 1000.0);
UpdateText(text);
}
}
ResetTimer();
}
}
private void UpdateText(string text)
{
if (Console.IsOutputRedirected) return;
// Get length of common portion
var commonPrefixLength = 0;
var commonLength = Math.Min(_currentText.Length, text.Length);
while (commonPrefixLength < commonLength && text[commonPrefixLength] == _currentText[commonPrefixLength])
{
commonPrefixLength++;
}
// Backtrack to the first differing character
_outputBuilder.Clear();
_outputBuilder.Append('\b', _currentText.Length - commonPrefixLength);
// Output new suffix
_outputBuilder.Append(text[commonPrefixLength..]);
// If the new text is shorter than the old one: delete overlapping characters
var overlapCount = _currentText.Length - text.Length;
if (overlapCount > 0)
{
_outputBuilder.Append(' ', overlapCount);
_outputBuilder.Append('\b', overlapCount);
}
Console.Write(_outputBuilder);
_currentText = text;
}
private void ResetTimer()
{
_timer.Change(_animationInterval, TimeSpan.FromMilliseconds(-1));
}
public void Dispose()
{
TimerHandler(null);
lock (_timer)
{
_disposed = true;
UpdateText(string.Empty);
}
_timer.Dispose();
}
}