mirror of
https://github.com/riegera2412/UVtools.git
synced 2026-07-08 17:42:31 +02:00
New methods OnBefore/AfterEncode and IsUsingTSMC improvement
- (Add) Methods: `OnBeforeEncode` and `OnAfterEncode` - (Improvement) `IsUsingTSMC` now also checks for BottomLiftHeight2 and BottomRetractHeight2
This commit is contained in:
@@ -1747,35 +1747,6 @@ public class ChituboxFile : FileFormat
|
||||
return false;
|
||||
}
|
||||
|
||||
private void SanitizeProperties()
|
||||
{
|
||||
if (IsCtbFile)
|
||||
{
|
||||
if (SlicerInfoSettings.AntiAliasLevel <= 1)
|
||||
{
|
||||
SlicerInfoSettings.AntiAliasLevel = HeaderSettings.AntiAliasLevel;
|
||||
}
|
||||
|
||||
HeaderSettings.AntiAliasLevel = 1;
|
||||
|
||||
if (HeaderSettings.Version <= 2)
|
||||
{
|
||||
SlicerInfoSettings.PerLayerSettings = PERLAYER_SETTINGS_CTBv2;
|
||||
PrintParametersSettings.Padding4 = 0x1234; // 4660
|
||||
}
|
||||
else if (HeaderSettings.Version == 3)
|
||||
{
|
||||
SlicerInfoSettings.PerLayerSettings = AllLayersAreUsingGlobalParameters ? PERLAYER_SETTINGS_DISALLOW : PERLAYER_SETTINGS_CTBv3;
|
||||
}
|
||||
else if (HeaderSettings.Version >= 4)
|
||||
{
|
||||
SlicerInfoSettings.PerLayerSettings = AllLayersAreUsingGlobalParameters ? PERLAYER_SETTINGS_DISALLOW : PERLAYER_SETTINGS_CTBv4;
|
||||
}
|
||||
}
|
||||
|
||||
SlicerInfoSettings.ModifiedTimestampMinutes = (uint)DateTimeExtensions.TimestampMinutes;
|
||||
}
|
||||
|
||||
private void SanitizeMagicVersion()
|
||||
{
|
||||
if (FileEndsWith(".ctb"))
|
||||
@@ -1814,10 +1785,38 @@ public class ChituboxFile : FileFormat
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnBeforeEncode(bool isPartialEncode)
|
||||
{
|
||||
if (IsCtbFile)
|
||||
{
|
||||
if (SlicerInfoSettings.AntiAliasLevel <= 1)
|
||||
{
|
||||
SlicerInfoSettings.AntiAliasLevel = HeaderSettings.AntiAliasLevel;
|
||||
}
|
||||
|
||||
HeaderSettings.AntiAliasLevel = 1;
|
||||
|
||||
if (HeaderSettings.Version <= 2)
|
||||
{
|
||||
SlicerInfoSettings.PerLayerSettings = PERLAYER_SETTINGS_CTBv2;
|
||||
PrintParametersSettings.Padding4 = 0x1234; // 4660
|
||||
}
|
||||
else if (HeaderSettings.Version == 3)
|
||||
{
|
||||
SlicerInfoSettings.PerLayerSettings = AllLayersAreUsingGlobalParameters ? PERLAYER_SETTINGS_DISALLOW : PERLAYER_SETTINGS_CTBv3;
|
||||
}
|
||||
else if (HeaderSettings.Version >= 4)
|
||||
{
|
||||
SlicerInfoSettings.PerLayerSettings = AllLayersAreUsingGlobalParameters ? PERLAYER_SETTINGS_DISALLOW : PERLAYER_SETTINGS_CTBv4;
|
||||
}
|
||||
}
|
||||
|
||||
SlicerInfoSettings.ModifiedTimestampMinutes = (uint)DateTimeExtensions.TimestampMinutes;
|
||||
}
|
||||
|
||||
protected override void EncodeInternally(OperationProgress progress)
|
||||
{
|
||||
SanitizeMagicVersion();
|
||||
SanitizeProperties();
|
||||
|
||||
HeaderSettings.PrintParametersSize = (uint)Helpers.Serializer.SizeOf(PrintParametersSettings);
|
||||
|
||||
@@ -2168,7 +2167,6 @@ public class ChituboxFile : FileFormat
|
||||
|
||||
protected override void PartialSaveInternally(OperationProgress progress)
|
||||
{
|
||||
SanitizeProperties();
|
||||
using var outputFile = new FileStream(TemporaryOutputFileFullPath, FileMode.Open, FileAccess.Write);
|
||||
outputFile.Seek(0, SeekOrigin.Begin);
|
||||
outputFile.WriteSerialize(HeaderSettings);
|
||||
|
||||
@@ -1429,7 +1429,7 @@ public abstract class FileFormat : BindableBase, IDisposable, IEquatable<FileFor
|
||||
/// <summary>
|
||||
/// True if the file global property is using TSMC, otherwise false when not using
|
||||
/// </summary>
|
||||
public bool IsUsingTSMC => (CanUseAnyLiftHeight2 || CanUseAnyRetractHeight2) && (LiftHeight2 > 0 || RetractHeight2 > 0);
|
||||
public bool IsUsingTSMC => (CanUseAnyLiftHeight2 || CanUseAnyRetractHeight2) && (BottomLiftHeight2 > 0 || BottomRetractHeight2 > 0 || LiftHeight2 > 0 || RetractHeight2 > 0);
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -3310,6 +3310,16 @@ public abstract class FileFormat : BindableBase, IDisposable, IEquatable<FileFor
|
||||
RaisePropertyChanged(nameof(Thumbnails));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Triggers before attempt to save/encode the file
|
||||
/// </summary>
|
||||
protected virtual void OnBeforeEncode(bool isPartialEncode){}
|
||||
|
||||
/// <summary>
|
||||
/// Triggers after save/encode the file
|
||||
/// </summary>
|
||||
protected virtual void OnAfterEncode(bool isPartialEncode) { }
|
||||
|
||||
/// <summary>
|
||||
/// Encode to an output file
|
||||
/// </summary>
|
||||
@@ -3325,13 +3335,13 @@ public abstract class FileFormat : BindableBase, IDisposable, IEquatable<FileFor
|
||||
{
|
||||
fileFullPath ??= FileFullPath ?? throw new ArgumentNullException(nameof(fileFullPath));
|
||||
|
||||
if (DecodeType == FileDecodeType.Partial)
|
||||
throw new InvalidOperationException("File was partial decoded, a full encode is not possible.");
|
||||
if (DecodeType == FileDecodeType.Partial) throw new InvalidOperationException("File was partial decoded, a full encode is not possible.");
|
||||
|
||||
progress ??= new OperationProgress();
|
||||
progress.Reset(OperationProgress.StatusEncodeLayers, LayerCount);
|
||||
|
||||
Sanitize();
|
||||
OnBeforeEncode(false);
|
||||
|
||||
for (var i = 0; i < Thumbnails.Length; i++)
|
||||
{
|
||||
@@ -3355,6 +3365,7 @@ public abstract class FileFormat : BindableBase, IDisposable, IEquatable<FileFor
|
||||
|
||||
// Move temporary output file in place
|
||||
File.Move(tempFile, fileFullPath, true);
|
||||
OnAfterEncode(false);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@@ -4578,14 +4589,13 @@ public abstract class FileFormat : BindableBase, IDisposable, IEquatable<FileFor
|
||||
|
||||
if (string.IsNullOrWhiteSpace(FileFullPath))
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(filePath))
|
||||
{
|
||||
Encode(filePath, progress);
|
||||
return;
|
||||
}
|
||||
throw new ArgumentNullException(nameof(FileFullPath), "Not encoded yet and both source and output files are null");
|
||||
if (string.IsNullOrWhiteSpace(filePath)) throw new ArgumentNullException(nameof(FileFullPath), "Not encoded yet and both source and output files are null");
|
||||
Encode(filePath, progress);
|
||||
return;
|
||||
}
|
||||
|
||||
OnBeforeEncode(true);
|
||||
|
||||
|
||||
// Backup old file name and prepare the temporary file to be written next
|
||||
var oldFilePath = FileFullPath!;
|
||||
@@ -4600,6 +4610,7 @@ public abstract class FileFormat : BindableBase, IDisposable, IEquatable<FileFor
|
||||
|
||||
// Move temporary output file in place
|
||||
File.Move(tempFile, FileFullPath, true);
|
||||
OnAfterEncode(true);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user