Files
UVtools/UVtools.WPF/Controls/Tools/ToolControl.axaml.cs
T
Tiago Conceição 3cd46728f1 v2.11.1
- **Shortcuts:**
   - (Add) (Ctrl + Shift + R) to turn on and cycle the Rotate modes
   - (Add) (Ctrl + Shift + F) to turn on and cycle the Flip modes
   - (Add) (Ctrl + Shift + B) to select the build volume as ROI
- **GUI:**
   - (Add) Allow to drag and drop '.uvtop' files into UVtools to sequential show and load operations from files
   - (Change) Rotate icon on layer preview
   - (Upgrade) AvaloniaUI from 0.10.3 to 0.10.4
- **Tools:**
   - (Add) 'Reset to defaults' button on every dialog
   - (Improvement) Window size and position handling
   - (Improvement) Constrain profile box width to not stretch the window
   - (Improvement) ROI section design
- **Dynamic lift:**
   - (Add) View buttons to show the largest/smallest layers
   - (Add) Light-off mode: Set the light-off with an extra delay
   - (Add) Light-off mode: Set the light-off without an extra delay
   - (Add) Light-off mode: Set the light-off to zero
   - (Improvement) Disable bottom and/or normal layer fields when the selected range is outside
- (Add) Settings - Automations: Light-off delay set modes
- (Fix) Exposure time finder: Add staircase, bullseye and counter triangles to feature count at thumbnail
2021-05-11 19:10:36 +01:00

94 lines
2.7 KiB
C#

using System.Threading.Tasks;
using Avalonia.Markup.Xaml;
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;
_baseOperation = value;
_baseOperation.SlicerFile = SlicerFile;
RaisePropertyChanged();
if (!wasNullBefore)
{
Callback(ToolWindow.Callbacks.Loaded);
}
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) : this()
{
BaseOperation = operation;
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
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());
}
}