From d5eb7d018280921bbc89bfc4758d60846ec14d56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tiago=20Concei=C3=A7=C3=A3o?= Date: Sun, 26 Dec 2021 22:44:43 +0000 Subject: v2.27.4 - **UI:** - (Add) When converting file formats with multiple available versions, it will prompt to select the version to use - (Add) Remove CTBv4 from convert menu (Will require readjust settings for default extension if you are using an below extension) (#286) - (Change) Rename CTBv3 to CTB on the convert menu - (Fix) CXDLP: Set version 3 was setting wrong information --- CHANGELOG.md | 8 +++ UVtools.Core/FileFormats/CXDLPFile.cs | 13 ++++- UVtools.Core/FileFormats/ChituboxFile.cs | 6 ++- UVtools.Core/FileFormats/FDGFile.cs | 4 +- UVtools.Core/FileFormats/FileFormat.cs | 31 ++++++++++-- UVtools.Core/FileFormats/ImageFile.cs | 2 +- UVtools.Core/FileFormats/PHZFile.cs | 4 +- UVtools.Core/FileFormats/PhotonWorkshopFile.cs | 2 + UVtools.Core/FileFormats/VDTFile.cs | 2 + UVtools.Core/UVtools.Core.csproj | 2 +- UVtools.WPF/Controls/WindowEx.cs | 2 +- UVtools.WPF/MainWindow.axaml.cs | 21 ++++++-- UVtools.WPF/UVtools.WPF.csproj | 2 +- UVtools.WPF/Windows/VersionSelectorWindow.axaml | 46 +++++++++++++++++ UVtools.WPF/Windows/VersionSelectorWindow.axaml.cs | 58 ++++++++++++++++++++++ 15 files changed, 186 insertions(+), 17 deletions(-) create mode 100644 UVtools.WPF/Windows/VersionSelectorWindow.axaml create mode 100644 UVtools.WPF/Windows/VersionSelectorWindow.axaml.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 8212f7a..da5862e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 26/12/2021 - v2.27.4 + +- **UI:** + - (Add) When converting file formats with multiple available versions, it will prompt to select the version to use + - (Add) Remove CTBv4 from convert menu (Will require readjust settings for default extension if you are using an below extension) (#286) + - (Change) Rename CTBv3 to CTB on the convert menu +- (Fix) CXDLP: Set version 3 was setting wrong information + ## 24/12/2021 - v2.27.3 - **Encrypted CTB:** diff --git a/UVtools.Core/FileFormats/CXDLPFile.cs b/UVtools.Core/FileFormats/CXDLPFile.cs index b1be1e4..d766379 100644 --- a/UVtools.Core/FileFormats/CXDLPFile.cs +++ b/UVtools.Core/FileFormats/CXDLPFile.cs @@ -419,12 +419,23 @@ namespace UVtools.Core.FileFormats public override uint[] AvailableVersions { get; } = { 2, 3 }; + public override uint DefaultVersion => 2; + public override uint Version { get => HeaderSettings.Version; set { - base.Version = value; + if (base.Version == 3) + { + base.Version = 2; + SlicerInfoV3Settings.MyControl = 1; + } + else + { + base.Version = value; + } + HeaderSettings.Version = (ushort)base.Version; } } diff --git a/UVtools.Core/FileFormats/ChituboxFile.cs b/UVtools.Core/FileFormats/ChituboxFile.cs index 1c13442..c993e98 100644 --- a/UVtools.Core/FileFormats/ChituboxFile.cs +++ b/UVtools.Core/FileFormats/ChituboxFile.cs @@ -1068,10 +1068,10 @@ namespace UVtools.Core.FileFormats public override FileExtension[] FileExtensions { get; } = { new(typeof(ChituboxFile), "photon", "Chitubox Photon"), new(typeof(ChituboxFile), "cbddlp", "Chitubox CBDDLP"), - new(typeof(ChituboxFile), "ctb", $"Chitubox CTBv{USED_VERSION}"), + new(typeof(ChituboxFile), "ctb", "Chitubox CTB"), //new(typeof(ChituboxFile), "v2.ctb", "Chitubox CTBv2"), //new(typeof(ChituboxFile), "v3.ctb", "Chitubox CTBv3"), - new(typeof(ChituboxFile), "v4.ctb", "Chitubox CTBv4", false), + //new(typeof(ChituboxFile), "v4.ctb", "Chitubox CTBv4", false, false), //new(typeof(ChituboxFile), "encrypted.ctb", "Chitubox encrypted CTB"), }; @@ -1206,6 +1206,8 @@ namespace UVtools.Core.FileFormats public override uint[] AvailableVersions { get; } = { 1, 2, 3, 4 }; + public override uint DefaultVersion => USED_VERSION; + public override uint Version { get => HeaderSettings.Version; diff --git a/UVtools.Core/FileFormats/FDGFile.cs b/UVtools.Core/FileFormats/FDGFile.cs index 289a156..bdc88cc 100644 --- a/UVtools.Core/FileFormats/FDGFile.cs +++ b/UVtools.Core/FileFormats/FDGFile.cs @@ -660,7 +660,9 @@ namespace UVtools.Core.FileFormats new(200, 125) }; - public override uint[] AvailableVersions { get; } = { 1, 2 }; + public override uint[] AvailableVersions { get; } = { 2 }; + + public override uint DefaultVersion => 2; public override uint Version { diff --git a/UVtools.Core/FileFormats/FileFormat.cs b/UVtools.Core/FileFormats/FileFormat.cs index 78a3bec..4bd1b01 100644 --- a/UVtools.Core/FileFormats/FileFormat.cs +++ b/UVtools.Core/FileFormats/FileFormat.cs @@ -725,6 +725,8 @@ namespace UVtools.Core.FileFormats private bool _haveModifiedLayers; + private uint _version; + private byte _antiAliasing = 1; private ushort _bottomLayerCount = DefaultBottomLayerCount; @@ -775,7 +777,6 @@ namespace UVtools.Core.FileFormats private bool _suppressRebuildGCode; private readonly Timer _queueTimerPrintTime = new(QueueTimerPrintTime){AutoReset = false}; - private uint _version; #endregion @@ -883,8 +884,21 @@ namespace UVtools.Core.FileFormats public string FileExtension => Path.GetExtension(FileFullPath); public string FilenameNoExt => GetFileNameStripExtensions(FileFullPath); + /// + /// Gets the available versions to set in this file format + /// public virtual uint[] AvailableVersions { get; } + /// + /// Gets the amount of available versions in this file format + /// + public virtual byte AvailableVersionsCount => (byte)(AvailableVersions?.Length ?? 0); + + /// + /// Gets the default version to use in this file when not setting the version + /// + public virtual uint DefaultVersion => 0; + /// /// Gets or sets the version of this file format /// @@ -899,7 +913,7 @@ namespace UVtools.Core.FileFormats } RequireFullEncode = true; - RaiseAndSet(ref _version, value); + RaiseAndSetIfChanged(ref _version, value); } } @@ -3463,9 +3477,10 @@ namespace UVtools.Core.FileFormats /// /// Target file format /// Output path file + /// File version to use /// /// The converted file if successful, otherwise null - public virtual FileFormat Convert(Type to, string fileFullPath, OperationProgress progress = null) + public virtual FileFormat Convert(Type to, string fileFullPath, uint version = 0, OperationProgress progress = null) { if (!IsValid) return null; var found = AvailableFormats.Any(format => to == format.GetType()); @@ -3480,6 +3495,11 @@ namespace UVtools.Core.FileFormats if (!slicerFile.OnBeforeConvertFrom(this)) return null; if (!OnBeforeConvertTo(slicerFile)) return null; + if (version > 0 && version != DefaultVersion) + { + slicerFile.Version = version; + } + slicerFile.SuppressRebuildPropertiesWork(() => { slicerFile.LayerManager.Init(LayerManager.CloneLayers()); @@ -3589,10 +3609,11 @@ namespace UVtools.Core.FileFormats /// /// Target file format /// Output path file + /// File version /// /// TThe converted file if successful, otherwise null - public FileFormat Convert(FileFormat to, string fileFullPath, OperationProgress progress = null) - => Convert(to.GetType(), fileFullPath, progress); + public FileFormat Convert(FileFormat to, string fileFullPath, uint version = 0, OperationProgress progress = null) + => Convert(to.GetType(), fileFullPath, version, progress); /// /// Validate AntiAlias Level diff --git a/UVtools.Core/FileFormats/ImageFile.cs b/UVtools.Core/FileFormats/ImageFile.cs index f80b8f1..e13b738 100644 --- a/UVtools.Core/FileFormats/ImageFile.cs +++ b/UVtools.Core/FileFormats/ImageFile.cs @@ -107,7 +107,7 @@ namespace UVtools.Core.FileFormats this[0].LayerMat.Save(FileFullPath); } - public override FileFormat Convert(Type to, string fileFullPath, OperationProgress progress = null) + public override FileFormat Convert(Type to, string fileFullPath, uint version = 0, OperationProgress progress = null) { throw new NotSupportedException(); } diff --git a/UVtools.Core/FileFormats/PHZFile.cs b/UVtools.Core/FileFormats/PHZFile.cs index 6b1a692..ea78b7f 100644 --- a/UVtools.Core/FileFormats/PHZFile.cs +++ b/UVtools.Core/FileFormats/PHZFile.cs @@ -679,7 +679,9 @@ namespace UVtools.Core.FileFormats new(200, 125) }; - public override uint[] AvailableVersions { get; } = { 1, 2 }; + public override uint[] AvailableVersions { get; } = { 2 }; + + public override uint DefaultVersion => 2; public override uint Version { diff --git a/UVtools.Core/FileFormats/PhotonWorkshopFile.cs b/UVtools.Core/FileFormats/PhotonWorkshopFile.cs index 7fdbb2a..322907f 100644 --- a/UVtools.Core/FileFormats/PhotonWorkshopFile.cs +++ b/UVtools.Core/FileFormats/PhotonWorkshopFile.cs @@ -1109,6 +1109,8 @@ namespace UVtools.Core.FileFormats public override uint[] AvailableVersions { get; } = { VERSION_1, VERSION_515, VERSION_516 }; + public override uint DefaultVersion => VERSION_1; + public override uint Version { get => FileMarkSettings.Version; diff --git a/UVtools.Core/FileFormats/VDTFile.cs b/UVtools.Core/FileFormats/VDTFile.cs index 1504a63..98341e3 100644 --- a/UVtools.Core/FileFormats/VDTFile.cs +++ b/UVtools.Core/FileFormats/VDTFile.cs @@ -272,6 +272,8 @@ namespace UVtools.Core.FileFormats public override uint[] AvailableVersions { get; } = { 1 }; + public override uint DefaultVersion => 1; + public override uint Version { get => ManifestFile.FileVersion; diff --git a/UVtools.Core/UVtools.Core.csproj b/UVtools.Core/UVtools.Core.csproj index b6446e6..5b360be 100644 --- a/UVtools.Core/UVtools.Core.csproj +++ b/UVtools.Core/UVtools.Core.csproj @@ -10,7 +10,7 @@ https://github.com/sn4k3/UVtools https://github.com/sn4k3/UVtools MSLA/DLP, file analysis, calibration, repair, conversion and manipulation - 2.27.3 + 2.27.4 Copyright © 2020 PTRTECH UVtools.png AnyCPU;x64 diff --git a/UVtools.WPF/Controls/WindowEx.cs b/UVtools.WPF/Controls/WindowEx.cs index 5d7b0c3..7901b47 100644 --- a/UVtools.WPF/Controls/WindowEx.cs +++ b/UVtools.WPF/Controls/WindowEx.cs @@ -80,7 +80,7 @@ namespace UVtools.WPF.Controls public UserSettings Settings => UserSettings.Instance; - public FileFormat SlicerFile + public virtual FileFormat SlicerFile { get => App.SlicerFile; set => App.SlicerFile = value; diff --git a/UVtools.WPF/MainWindow.axaml.cs b/UVtools.WPF/MainWindow.axaml.cs index 35fbe7b..e4b6de6 100644 --- a/UVtools.WPF/MainWindow.axaml.cs +++ b/UVtools.WPF/MainWindow.axaml.cs @@ -1637,7 +1637,7 @@ namespace UVtools.WPF try { convertedFile = SlicerFile.Convert(convertToFormat, - Path.Combine(directory, $"{filename}.{convertFileExtension}"), + Path.Combine(directory, $"{filename}.{convertFileExtension}"), 0, Progress); return true; } @@ -1940,6 +1940,22 @@ namespace UVtools.WPF if (sender is not MenuItem item) return; if (item.Tag is not FileExtension fileExtension) return; + var fileFormat = fileExtension.GetFileFormat(); + uint version = fileFormat.DefaultVersion; + if (fileFormat.AvailableVersionsCount > 1) + { + var versionSelectorWindow = new VersionSelectorWindow(fileFormat, fileExtension); + await versionSelectorWindow.ShowDialog(this); + switch (versionSelectorWindow.DialogResult) + { + case DialogResults.OK: + version = versionSelectorWindow.Version; + break; + case DialogResults.Cancel: + return; + } + } + SaveFileDialog saveDialog = new() { InitialFileName = Path.GetFileNameWithoutExtension(SlicerFile.FileFullPath), @@ -1952,7 +1968,6 @@ namespace UVtools.WPF var result = await saveDialog.ShowAsync(this); if (string.IsNullOrEmpty(result)) return; - IsGUIEnabled = false; ShowProgressWindow($"Converting {Path.GetFileName(SlicerFile.FileFullPath)} to {Path.GetExtension(result)}"); @@ -1960,7 +1975,7 @@ namespace UVtools.WPF { try { - return SlicerFile.Convert(fileExtension.GetFileFormat(), result, Progress) is not null; + return SlicerFile.Convert(fileFormat, result, version, Progress) is not null; } catch (OperationCanceledException) { diff --git a/UVtools.WPF/UVtools.WPF.csproj b/UVtools.WPF/UVtools.WPF.csproj index 8517234..717d6a9 100644 --- a/UVtools.WPF/UVtools.WPF.csproj +++ b/UVtools.WPF/UVtools.WPF.csproj @@ -12,7 +12,7 @@ LICENSE https://github.com/sn4k3/UVtools Git - 2.27.3 + 2.27.4 AnyCPU;x64 UVtools.png README.md diff --git a/UVtools.WPF/Windows/VersionSelectorWindow.axaml b/UVtools.WPF/Windows/VersionSelectorWindow.axaml new file mode 100644 index 0000000..eadbd84 --- /dev/null +++ b/UVtools.WPF/Windows/VersionSelectorWindow.axaml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + diff --git a/UVtools.WPF/Windows/VersionSelectorWindow.axaml.cs b/UVtools.WPF/Windows/VersionSelectorWindow.axaml.cs new file mode 100644 index 0000000..1fb4ed9 --- /dev/null +++ b/UVtools.WPF/Windows/VersionSelectorWindow.axaml.cs @@ -0,0 +1,58 @@ +using Avalonia.Markup.Xaml; +using UVtools.Core.FileFormats; +using UVtools.WPF.Controls; + +namespace UVtools.WPF.Windows +{ + public partial class VersionSelectorWindow : WindowEx + { + private uint _version; + + public string DescriptionText => + $"This file format \"{FileExtension.Description}\" contains multiple available versions. Some versions may require a specific firmware version in order to run.\n" + + "Select the version you wish to use on the output file.\n" + + $"If unsure, use the default version {SlicerFile.DefaultVersion}."; + + public sealed override FileFormat SlicerFile { get; set; } + + public FileExtension FileExtension { get; set; } + + public uint Version + { + get => _version; + set => RaiseAndSetIfChanged(ref _version, value); + } + + public VersionSelectorWindow() + { + InitializeComponent(); + DialogResult = DialogResults.Cancel; + } + + public VersionSelectorWindow(FileFormat slicerFile, FileExtension fileExtension) : this() + { + SlicerFile = slicerFile; + FileExtension = fileExtension; + Version = slicerFile.DefaultVersion; + Title += $" - {FileExtension.Description}"; + DataContext = this; + } + + private void InitializeComponent() + { + AvaloniaXamlLoader.Load(this); + } + + public void SelectVersion() + { + DialogResult = Version == SlicerFile.DefaultVersion ? DialogResults.Unknown : DialogResults.OK; + Close(); + } + + public void SelectDefault() + { + DialogResult = DialogResults.Unknown; + Close(); + } + } +} -- cgit v1.2.3