mirror of
https://github.com/riegera2412/UVtools.git
synced 2026-07-08 17:42:31 +02:00
ea4f7e0400
- **UI:** - (Improvement) Layer navigation load time by parallel `Mat` to `Bitmap` conversion - (Improvement) Allow to show exceptions without the stack trace and detailed trigger action by using the `MessageExceiption` (#644) - (Improvement) Allow progress to have and display a detailed log (#644) - (Improvement) Convert format to another with multiple versions will now only show the possible versions for the extension - **Suggestion - Wait time before cure:** - (Improvement) Set the first wait time based on first valid layer mass rather than use the fixed limit - (Improvement) Set zero time to empty and dummy layers - (Improvement) When creating the dummy layer also increment the bottom layer count as the created layer count as one - **PCB Exposure:** - (Add) Excellon Drill Format (drl) to cut off holes (Implementation may lack some advanced features, please confirm the result) (#646) - (Fix) Arc (G03) with negative offsets (I-/J-) was not drawing the shape correctly - (Fix) Implement the rotation for the outline primitive (#645) - **File formats:** - (Improvement) Formats now sanitize the selected version before encode given the file extension, if version is out of range it will force the last known version - (Fix) CBDDLP: Remove a table from the file that might cause layer corruption - (Add) Operations - `AfterCompleteReport` property: Gets or sets an report to show to the user after complete the operation with success - (Improvement) Suggestion - Wait time after cure: Set zero time to empty and dummy layers - (Improvement) Slight improvement on the contour intersection check, yields better performance on resin and suction cup detection - (Improvement) Allow to trigger message boxes from operations and scripts (#644) - (Upgrade) .NET from 6.0.12 to 6.0.13
204 lines
6.8 KiB
C#
204 lines
6.8 KiB
C#
using Avalonia;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Markup.Xaml;
|
|
using Avalonia.Threading;
|
|
using MessageBox.Avalonia.Enums;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using UVtools.Core.Extensions;
|
|
using UVtools.Core.Suggestions;
|
|
using UVtools.WPF.Controls;
|
|
using UVtools.WPF.Controls.Suggestions;
|
|
using UVtools.WPF.Extensions;
|
|
using UVtools.WPF.Structures;
|
|
|
|
namespace UVtools.WPF.Windows;
|
|
|
|
public partial class SuggestionSettingsWindow : WindowEx
|
|
{
|
|
private readonly ContentControl _activeSuggestionContentPanel;
|
|
|
|
private Suggestion _activeSuggestion;
|
|
private Suggestion _selectedSuggestion;
|
|
private bool _pendingChanges;
|
|
|
|
public Suggestion[] Suggestions => App.MainWindow.Suggestions;
|
|
|
|
public Suggestion SelectedSuggestion
|
|
{
|
|
get => _selectedSuggestion;
|
|
set
|
|
{
|
|
Dispatcher.UIThread.InvokeAsync(async () =>
|
|
{
|
|
bool recoverSuggestion = false;
|
|
if (_pendingChanges && _activeSuggestion is not null)
|
|
{
|
|
switch (await this.MessageBoxQuestion(
|
|
$"You have pending changes on '{_activeSuggestion.Title}' and you are about to discard them.\n" +
|
|
"Do you want to discard the changes?\n\n" +
|
|
"Yes: Discard changes\n" +
|
|
"No: Save changes\n" +
|
|
"Cancel: Continue editing",
|
|
"Pending changes", ButtonEnum.YesNoCancel))
|
|
{
|
|
case ButtonResult.Yes:
|
|
break;
|
|
case ButtonResult.No:
|
|
if (!await SaveSuggestion(false))
|
|
{
|
|
recoverSuggestion = true;
|
|
break;
|
|
}
|
|
SuggestionManager.SetSuggestion(_activeSuggestion.Clone(), true);
|
|
break;
|
|
case ButtonResult.Cancel:
|
|
case ButtonResult.Abort:
|
|
case ButtonResult.None:
|
|
recoverSuggestion = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
var oldSuggestion = _selectedSuggestion;
|
|
if (!RaiseAndSetIfChanged(ref _selectedSuggestion, value)) return;
|
|
if (recoverSuggestion)
|
|
{
|
|
RaiseAndSetIfChanged(ref _selectedSuggestion, oldSuggestion);
|
|
return;
|
|
}
|
|
|
|
ActiveSuggestion = value is null ? null : SuggestionManager.GetSuggestion(_selectedSuggestion.GetType()).Clone();
|
|
});
|
|
|
|
}
|
|
}
|
|
|
|
public Suggestion ActiveSuggestion
|
|
{
|
|
get => _activeSuggestion;
|
|
set
|
|
{
|
|
if(!RaiseAndSetIfChanged(ref _activeSuggestion, value) || value is null) return;
|
|
PendingChanges = false;
|
|
_activeSuggestion.PropertyChanged += (sender, e) => PendingChanges = true;
|
|
|
|
var type = typeof(SuggestionControl);
|
|
var classname = $"{type.Namespace}.{_activeSuggestion.GetType().Name}Control";
|
|
var controlType = Type.GetType(classname);
|
|
SuggestionControl control;
|
|
|
|
if (controlType is null)
|
|
{
|
|
control = new SuggestionControl(_activeSuggestion);
|
|
}
|
|
else
|
|
{
|
|
control = controlType.CreateInstance<SuggestionControl>(_activeSuggestion);
|
|
if (control is null) return;
|
|
}
|
|
|
|
_activeSuggestionContentPanel.Content = null;
|
|
_activeSuggestionContentPanel.Content = control;
|
|
}
|
|
}
|
|
|
|
public bool PendingChanges
|
|
{
|
|
get => _pendingChanges;
|
|
set => RaiseAndSetIfChanged(ref _pendingChanges, value);
|
|
}
|
|
|
|
public SuggestionSettingsWindow() : this(null) { }
|
|
|
|
public SuggestionSettingsWindow(Suggestion highlightSuggestion)
|
|
{
|
|
if (Design.IsDesignMode)
|
|
{
|
|
_activeSuggestion = new SuggestionBottomLayerCount();
|
|
}
|
|
|
|
DataContext = this;
|
|
|
|
InitializeComponent();
|
|
#if DEBUG
|
|
this.AttachDevTools();
|
|
#endif
|
|
|
|
_activeSuggestionContentPanel = this.FindControl<ContentControl>("ActiveSuggestionContentPanel");
|
|
|
|
if (highlightSuggestion is not null)
|
|
{
|
|
SelectedSuggestion = Suggestions.FirstOrDefault(suggestion => suggestion.GetType() == highlightSuggestion.GetType());
|
|
}
|
|
}
|
|
|
|
private void InitializeComponent()
|
|
{
|
|
AvaloniaXamlLoader.Load(this);
|
|
}
|
|
|
|
|
|
public async void ResetDefaults()
|
|
{
|
|
if (await this.MessageBoxQuestion(
|
|
"Are you sure you want to reset all suggestions to the default settings?",
|
|
"Reset all settings?") != ButtonResult.Yes) return;
|
|
|
|
SuggestionManager.Reset();
|
|
if (_activeSuggestion is null) return;
|
|
|
|
ActiveSuggestion = (Suggestion)Activator.CreateInstance(_activeSuggestion.GetType());
|
|
}
|
|
|
|
|
|
public async Task<bool> SaveSuggestion(bool promptBeforeSave = true)
|
|
{
|
|
if (_activeSuggestion is null) return false;
|
|
|
|
var result = _activeSuggestion.Validate();
|
|
if (!string.IsNullOrWhiteSpace(result))
|
|
{
|
|
if (await this.MessageBoxError(result,
|
|
$"{_activeSuggestion.Title} - Error") != ButtonResult.Yes) return false;
|
|
}
|
|
|
|
if (promptBeforeSave && await this.MessageBoxQuestion(
|
|
"Are you sure you want to save and overwrite previous settings?",
|
|
"Save suggestion changes?") != ButtonResult.Yes) return false;
|
|
|
|
SuggestionManager.SetSuggestion(_activeSuggestion.Clone(), true);
|
|
PendingChanges = false;
|
|
return true;
|
|
}
|
|
|
|
public async void SaveSuggestionClicked()
|
|
{
|
|
await SaveSuggestion();
|
|
}
|
|
|
|
public async void DiscardSuggestionClicked()
|
|
{
|
|
if (_activeSuggestion is null) return;
|
|
|
|
if (await this.MessageBoxQuestion(
|
|
"Are you sure you want to discard all changes and return to the last saved state?",
|
|
"Discard suggestion changes?") != ButtonResult.Yes) return;
|
|
|
|
ActiveSuggestion = SuggestionManager.GetSuggestion(_activeSuggestion.GetType()).Clone();
|
|
}
|
|
|
|
public async void ResetSuggestionClicked()
|
|
{
|
|
if (_activeSuggestion is null) return;
|
|
|
|
if (await this.MessageBoxQuestion(
|
|
"Are you sure you want to reset to the default settings?",
|
|
"Reset suggestion settings?") != ButtonResult.Yes) return;
|
|
|
|
ActiveSuggestion = (Suggestion)Activator.CreateInstance(_activeSuggestion.GetType());
|
|
SuggestionManager.SetSuggestion(_activeSuggestion.Clone(), true);
|
|
}
|
|
} |