mirror of
https://github.com/riegera2412/UVtools.git
synced 2026-07-09 01:52:32 +02:00
2c7ad09dc0
- (Change) `Layer.IsBottomLayer` no longer calculate the value using the position of the layer, a new property `IsBottomLayerByHeight` is now used to get that result - (Improvement) Tool - Double exposure: Increase the bottom layer count per cloned bottom layer - (Improvement) Calibration - Exposure time finder: Set the absolute bottom layer count accordingly when also testing for bottom time - (Improvement) Goo: Enforce Wait times or Light-off-delay flag based on property set - (Fix) AnyCubic and Goo: `PerLayerSetting` flag was set inverted causing printer not to follow layer settings when it should and also the otherwise (#689) - (Fix) Tool - Scripting: Prevent from reload UI multiple times when using profiles (#694)
122 lines
3.4 KiB
C#
122 lines
3.4 KiB
C#
using Avalonia.Controls;
|
|
using Avalonia.Markup.Xaml;
|
|
using System.Threading.Tasks;
|
|
using UVtools.Core.Objects;
|
|
using UVtools.Core.Operations;
|
|
using UVtools.WPF.Extensions;
|
|
using UVtools.WPF.Windows;
|
|
|
|
namespace UVtools.WPF.Controls.Tools;
|
|
|
|
public class ToolControl : UserControlEx
|
|
{
|
|
private Operation _baseOperation;
|
|
|
|
public Operation BaseOperation
|
|
{
|
|
get => _baseOperation;
|
|
set
|
|
{
|
|
bool wasNullBefore = _baseOperation is null;
|
|
|
|
if (!wasNullBefore)
|
|
{
|
|
_baseOperation.ClearPropertyChangedListeners();
|
|
Callback(ToolWindow.Callbacks.BeforeLoadProfile);
|
|
}
|
|
|
|
_baseOperation = value;
|
|
_baseOperation.SlicerFile = SlicerFile;
|
|
RaisePropertyChanged();
|
|
|
|
if (!wasNullBefore)
|
|
{
|
|
Callback(ToolWindow.Callbacks.AfterLoadProfile);
|
|
}
|
|
|
|
if (DataContext is null) return;
|
|
ResetDataContext();
|
|
}
|
|
}
|
|
|
|
public ToolWindow ParentWindow { get; set; } = null;
|
|
|
|
public bool CanRun { get; set; } = true;
|
|
|
|
public ToolControl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public ToolControl(Operation operation)
|
|
{
|
|
BaseOperation = operation;
|
|
if (!ValidateSpawn()) return;
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void InitializeComponent()
|
|
{
|
|
AvaloniaXamlLoader.Load(this);
|
|
}
|
|
|
|
public bool ValidateSpawn()
|
|
{
|
|
if (Design.IsDesignMode) return true;
|
|
if(_baseOperation is null)
|
|
{
|
|
App.MainWindow.MessageBoxInfo("The operation does not contain a valid configuration.\n" +
|
|
"Please contact the support/developer.", BaseOperation.NotSupportedTitle).ConfigureAwait(false);
|
|
CanRun = false;
|
|
return false;
|
|
}
|
|
if (!_baseOperation.ValidateSpawn(out var message))
|
|
{
|
|
App.MainWindow.MessageBoxInfo(message, BaseOperation.NotSupportedTitle).ConfigureAwait(false);
|
|
CanRun = false;
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public virtual void Callback(ToolWindow.Callbacks callback) { }
|
|
|
|
public virtual bool UpdateOperation() => true;
|
|
|
|
/*public virtual void SetOperation(Operation operation)
|
|
{
|
|
BaseOperation = operation;
|
|
ResetDataContext();
|
|
}*/
|
|
|
|
/// <summary>
|
|
/// Validates if is safe to continue with operation
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public virtual async Task<bool> ValidateForm()
|
|
{
|
|
if (BaseOperation is null) return true;
|
|
if (!UpdateOperation()) return false;
|
|
return await ValidateFormFromString(BaseOperation.Validate());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Validates if is safe to continue with operation, if not shows a message box with the error
|
|
/// </summary>
|
|
/// <param name="text"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> ValidateFormFromString(string text)
|
|
{
|
|
if (string.IsNullOrEmpty(text)) return true;
|
|
await ParentWindow.MessageBoxError(text);
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Validates if is safe to continue with operation, if not shows a message box with the error
|
|
/// </summary>
|
|
/// <param name="text"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> ValidateFormFromString(ValueDescription text) => await ValidateFormFromString(text?.ToString());
|
|
} |