Files
UVtools/UVtools.WPF/MainWindow.Suggestions.cs
T
Tiago Conceição 9f7722d369 v3.7.0
- **File formats:**
   - (Add) `TransitionLayerCount` modifier to: Chitubox Zip, CWS, JXS, OSLA, PW*, UVJ, ZCodex, ZCode
   - (Add) Utility methods for transition layers calculation/parse
   - (Improvement) Calculate and set `TransitionLayerCount` property in file decode based on layer exposure time configuration
- **GCode:**
   - (Improvement) GCode: Able to parse layer image file with appended numbers on the filename (Afecting CWS) (#577)
   - (Fix) Bad parsing of the file when it comes from Lychee or NovaMaker slicer (Afecting CWS)
   - (Fix) Incorrect parse of "Wait time before cure" from layers when printer require wait sync moves (Afecting CWS)
- **Tools:**
   - (Add) External tests: The Complete Resin 3D Printing Settings Guide for Beginners
   - (Add) External tests: 9 settings for faster printing
   - (Improvement) Fade exposure time: Set `TransitionLayerCount` property with the affected layer count
- **Suggestions:**
   - (Add) Transition layers: If you are printing flat on the build plate your model will print better when using a smooth transition exposure time instead of a harsh variation, resulting in reduced layer line effect and avoid possible problems due the large exposure difference.
                              This is not so important when your model print raised under a raft/supports unaffected by the bottom exposure, in that case, it's fine to ignore this.
   - (Add) Model position: Printing on a corner will reduce the FEP stretch forces when detaching from the model during a lift sequence, benefits are: Reduced lift height and faster printing, less stretch, less FEP marks, better FEP lifespan, easier to peel, less prone to failure and use the screen pixels more evenly.
                           If the model is too large to fit within the margin(s) on the screen, it will attempt to center it on that same axis to avoid touching on screen edge(s) and to give a sane margin from it.
- **Status bar:**
   - (Add) Transition layers: 0/-0.00s
   - (Improvement) Change "Layer Height: 0.000mm" to "Layers: count @ 0.000mm"
   - (Improvement) Change "Bottom layers: 0" to "Bottom layers: 0/0.000mm"
- (Change) Show user informative message about CTB Encrypted file format once per ten file loads
- (Upgrade) .NET from 6.0.9 to 6.0.10
- (Fix) Windows MSI installation not upgrading well when downgrade libraries
2022-10-12 01:16:34 +01:00

186 lines
5.5 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.
*/
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Threading;
using MessageBox.Avalonia.Enums;
using UVtools.Core.Managers;
using UVtools.Core.Suggestions;
using UVtools.WPF.Extensions;
using UVtools.WPF.Structures;
using UVtools.WPF.Windows;
namespace UVtools.WPF;
public partial class MainWindow
{
#region Members
private ListBox _suggestionsAvailableListBox;
#endregion
#region Properties
public Suggestion[] Suggestions
{
get => SuggestionManager.Instance.Suggestions;
set => SuggestionManager.Instance.Suggestions = value;
}
public RangeObservableCollection<Suggestion> SuggestionsAvailable { get; } = new();
public RangeObservableCollection<Suggestion> SuggestionsApplied { get; } = new();
#endregion
#region Methods
public void InitSuggestions()
{
_suggestionsAvailableListBox = this.FindControl<ListBox>("SuggestionsAvailableListBox");
}
public void PopulateSuggestions(bool tryToAutoApply = true)
{
var suggestionsAvailable = new List<Suggestion>();
var suggestionsApplied = new List<Suggestion>();
foreach (var suggestion in Suggestions)
{
suggestion.SlicerFile = SlicerFile;
if(!suggestion.Enabled || !suggestion.IsAvailable) continue;
if (tryToAutoApply)
{
if (suggestion.ExecuteIfAutoApply())
{
CanSave = true;
}
}
if(suggestion.IsApplied) suggestionsApplied.Add(suggestion);
else suggestionsAvailable.Add(suggestion);
}
SuggestionsAvailable.ReplaceCollection(suggestionsAvailable);
SuggestionsApplied.ReplaceCollection(suggestionsApplied);
}
public async void ApplySuggestionsClicked()
{
if (!IsFileLoaded || _suggestionsAvailableListBox.SelectedItems.Count == 0) return;
var suggestions = _suggestionsAvailableListBox.SelectedItems.Cast<Suggestion>().Where(suggestion => !suggestion.IsInformativeOnly).ToArray();
if (suggestions.Length == 0) return;
var sb = new StringBuilder($"Are you sure you want to apply the following {suggestions.Length} suggestions?:\n\n");
foreach (var suggestion in suggestions)
{
sb.AppendLine(suggestion.ConfirmationMessage);
}
if (await this.MessageBoxQuestion(sb.ToString(), "Apply suggestions?") != ButtonResult.Yes) return;
IsGUIEnabled = false;
ShowProgressWindow($"Applying {suggestions.Length} suggestions", false);
var executed = await Task.Factory.StartNew(() =>
{
uint executed = 0;
try
{
foreach (var suggestion in suggestions)
{
if (suggestion.Execute(Progress))
{
executed++;
}
}
}
catch (OperationCanceledException)
{ }
catch (Exception ex)
{
Dispatcher.UIThread.InvokeAsync(async () => await this.MessageBoxError(ex.ToString(), "Error while applying a suggestion"));
}
return executed;
});
IsGUIEnabled = true;
if (executed > 0)
{
CanSave = true;
ResetDataContext();
ForceUpdateActualLayer();
}
PopulateSuggestions(false);
}
public async void ApplySuggestionClicked(Suggestion suggestion)
{
if (!IsFileLoaded || suggestion is null || suggestion.IsInformativeOnly) return;
if (await this.MessageBoxQuestion($"Are you sure you want to apply the following suggestion?:\n\n{suggestion.ConfirmationMessage}", "Apply the suggestion?") != ButtonResult.Yes) return;
IsGUIEnabled = false;
ShowProgressWindow(suggestion.Title, false);
var result = await Task.Factory.StartNew(() =>
{
try
{
return suggestion.Execute(Progress);
}
catch (OperationCanceledException)
{
}
catch (Exception ex)
{
Dispatcher.UIThread.InvokeAsync(async () => await this.MessageBoxError(ex.ToString(), $"{suggestion.Title} Error"));
}
return false;
});
IsGUIEnabled = true;
if (result)
{
CanSave = true;
ResetDataContext();
ForceUpdateActualLayer();
}
PopulateSuggestions(false);
}
public async void ConfigureSuggestionsClicked()
{
if (!IsFileLoaded || Suggestions.Length == 0) return;
var window = new SuggestionSettingsWindow();
await window.ShowDialog(this);
PopulateSuggestions(false);
}
public async void ConfigureSuggestionClicked(Suggestion suggestion)
{
if (!IsFileLoaded || Suggestions.Length == 0) return;
var window = new SuggestionSettingsWindow(suggestion);
await window.ShowDialog(this);
PopulateSuggestions(false);
}
#endregion
}