mirror of
https://github.com/riegera2412/UVtools.git
synced 2026-07-09 01:52:32 +02:00
a648610d59
- **File formats:** - (Add) Wait time before cure: The time to rest/wait in seconds before cure a new layer - (Add) Wait time before after: The time to rest/wait in seconds after cure a new layer - (Add) Wait time after lift: The time to rest/wait in seconds after a lift/peel move - (Change) All gcode file formats dropped light-off delay field in favor of new 'Wait time before cure' field, setting light-off delay still valid but it redirects to the new field - (Change) Reorder 'Light-off delay' before 'Exposure time' - (Improvement) Recalculate the print time when a related property changes - (Fix) Generic time estimation calculation was ignoring exposure times - (Fix) Unable to load files with uppercase extensions - (Fix) ZIP: Use G1 at end of gcode instead of G0 - (Fix) CWS: Use G1 for movements - **(Fix) CXDLP:** (#240) - Layer area calculation - Validation checksum - **(Fix) ZCODE:** - Use G1 at end of gcode instead of G0 to prevent crash to top bug on firmware - Put back the M18 motors off at end of gcode - **GCode Builder/Parser:** - (Add) Allow to choose between G0 and G1 for layer movements and end gcode - (Fix) Safe guard: If the total print height is larger than set machine Z, do not raise/lower print on completeness - (Fix) Light-off delay is the real delay time and not the calculated movement of the lifts plus the extra time - (Improvement) Parse gcode line by line instead searching on a group of layers to allow a better control and identification - **Tools:** - **Change print parameters:** - (Add) Tooltips to labels - (Add) Sun UTF-8 to the Light PWM value unit to describe intensity - (Improvement) Dynamic lifts: Round lift height and speed to 1 decimal - (Fix) Exposure time finder: Time estimation when using 'Use different settings for layers with same Z positioning' - **Prusa Slicer:** - (Add) Note keyword: BottomWaitBeforeCure_xxx - (Add) Note keyword: WaitBeforeCure_xxx - (Add) Note keyword: BottomWaitAfterCure_xxx - (Add) Note keyword: WaitAfterCure_xxx - (Add) Note keyword: BottomWaitAfterLift_xxx - (Add) Note keyword: WaitAfterLift_xxx - (Change) Uniz IBEE: Remove light-off delay and implement wait time keywords - **macOS:** (#236) - (Remove) osx legacy packages from build and downloads - (Fix) macOS: Simplify the libcvextern.dylib and remove libtesseract dependency - (Fix) macOS: Include libusb-1.0.0.dylib - Note: `brew install libusb` still required - **UI:** - (Fix) Refresh gcode does not update text on UI for ZIP, CWS, ZCODEX files - (Fix) Operations: Import a .uvtop file by drag and drop into the UI would not load the layer range - (Change) When convert a file, the result dialog will have Yes, No and Cancel actions, where No will open the converted file on current window, while Cancel will not perform any action (The old No behaviour)
373 lines
14 KiB
C#
373 lines
14 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;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Diagnostics;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using Avalonia;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Input;
|
|
using MessageBox.Avalonia.Enums;
|
|
using UVtools.Core;
|
|
using UVtools.Core.FileFormats;
|
|
using UVtools.Core.Objects;
|
|
using UVtools.WPF.Extensions;
|
|
using UVtools.WPF.Structures;
|
|
using Bitmap = Avalonia.Media.Imaging.Bitmap;
|
|
using Helpers = UVtools.WPF.Controls.Helpers;
|
|
|
|
namespace UVtools.WPF
|
|
{
|
|
public partial class MainWindow
|
|
{
|
|
public RangeObservableCollection<SlicerProperty> SlicerProperties { get; } = new();
|
|
public DataGrid PropertiesGrid;
|
|
public DataGrid CurrentLayerGrid;
|
|
|
|
private uint _visibleThumbnailIndex;
|
|
private Bitmap _visibleThumbnailImage;
|
|
private RangeObservableCollection<ValueDescription> _currentLayerProperties = new();
|
|
|
|
public RangeObservableCollection<ValueDescription> CurrentLayerProperties
|
|
{
|
|
get => _currentLayerProperties;
|
|
set => RaiseAndSetIfChanged(ref _currentLayerProperties, value);
|
|
}
|
|
|
|
public void InitInformation()
|
|
{
|
|
PropertiesGrid = this.Find<DataGrid>(nameof(PropertiesGrid));
|
|
CurrentLayerGrid = this.Find<DataGrid>(nameof(CurrentLayerGrid));
|
|
PropertiesGrid.KeyUp += GridOnKeyUp;
|
|
CurrentLayerGrid.KeyUp += GridOnKeyUp;
|
|
/*CurrentLayerGrid.BeginningEdit += (sender, e) =>
|
|
{
|
|
if (e.Row.DataContext is StringTag stringTag)
|
|
{
|
|
if (e.Column.DisplayIndex == 0
|
|
|| e.Row.DataContext.ToString() != nameof(LayerCache.Layer.ExposureTime)
|
|
&& e.Row.DataContext.ToString() != nameof(LayerCache.Layer.LightPWM)
|
|
)
|
|
{
|
|
e.Cancel = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
e.Cancel = true;
|
|
}
|
|
};
|
|
CurrentLayerGrid.RowEditEnding += (sender, e) =>
|
|
{
|
|
if (e.EditAction == DataGridEditAction.Cancel) return;
|
|
if (!(e.Row.DataContext is StringTag stringTag)) return;
|
|
if (float.TryParse(stringTag.TagString, out var result)) return;
|
|
e.Cancel = true;
|
|
};
|
|
CurrentLayerGrid.RowEditEnded += (sender, e) =>
|
|
{
|
|
if (e.EditAction == DataGridEditAction.Cancel) return;
|
|
if (!(e.Row.DataContext is StringTag stringTag)) return;
|
|
switch (stringTag.Content)
|
|
{
|
|
//case nameof(LayerCache.)
|
|
}
|
|
};*/
|
|
|
|
}
|
|
|
|
private void GridOnKeyUp(object? sender, KeyEventArgs e)
|
|
{
|
|
if (sender is DataGrid dataGrid)
|
|
{
|
|
switch (e.Key)
|
|
{
|
|
case Key.Escape:
|
|
dataGrid.SelectedItems.Clear();
|
|
break;
|
|
case Key.Multiply:
|
|
foreach (var item in dataGrid.Items)
|
|
{
|
|
if (dataGrid.SelectedItems.Contains(item))
|
|
dataGrid.SelectedItems.Remove(item);
|
|
else
|
|
dataGrid.SelectedItems.Add(item);
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
#region Thumbnails
|
|
public uint VisibleThumbnailIndex
|
|
{
|
|
get => _visibleThumbnailIndex;
|
|
set
|
|
{
|
|
if (value == 0)
|
|
{
|
|
RaiseAndSetIfChanged(ref _visibleThumbnailIndex, value);
|
|
RaisePropertyChanged(nameof(ThumbnailCanGoPrevious));
|
|
RaisePropertyChanged(nameof(ThumbnailCanGoNext));
|
|
VisibleThumbnailImage = null;
|
|
return;
|
|
}
|
|
|
|
if (!IsFileLoaded) return;
|
|
var index = value - 1;
|
|
if (index >= SlicerFile.CreatedThumbnailsCount) return;
|
|
if (SlicerFile.Thumbnails[index] is null || SlicerFile.Thumbnails[index].IsEmpty) return;
|
|
if (!RaiseAndSetIfChanged(ref _visibleThumbnailIndex, value)) return;
|
|
|
|
VisibleThumbnailImage = SlicerFile.Thumbnails[index].ToBitmap();
|
|
RaisePropertyChanged(nameof(ThumbnailCanGoPrevious));
|
|
RaisePropertyChanged(nameof(ThumbnailCanGoNext));
|
|
}
|
|
}
|
|
|
|
public bool ThumbnailCanGoPrevious => SlicerFile is { } && _visibleThumbnailIndex > 1;
|
|
public bool ThumbnailCanGoNext => SlicerFile is { } && _visibleThumbnailIndex < SlicerFile.CreatedThumbnailsCount;
|
|
|
|
public void ThumbnailGoPrevious()
|
|
{
|
|
if (!ThumbnailCanGoPrevious) return;
|
|
VisibleThumbnailIndex--;
|
|
}
|
|
|
|
public void ThumbnailGoNext()
|
|
{
|
|
if (!ThumbnailCanGoNext) return;
|
|
VisibleThumbnailIndex++;
|
|
}
|
|
|
|
public Bitmap VisibleThumbnailImage
|
|
{
|
|
get => _visibleThumbnailImage;
|
|
set
|
|
{
|
|
RaiseAndSetIfChanged(ref _visibleThumbnailImage, value);
|
|
RaisePropertyChanged(nameof(VisibleThumbnailResolution));
|
|
}
|
|
}
|
|
|
|
public string VisibleThumbnailResolution => _visibleThumbnailImage is null ? null : $"{{Width: {_visibleThumbnailImage.Size.Width}, Height: {_visibleThumbnailImage.Size.Height}}}";
|
|
|
|
public async void OnClickThumbnailSave()
|
|
{
|
|
if (SlicerFile is null) return;
|
|
if (ReferenceEquals(SlicerFile.Thumbnails[_visibleThumbnailIndex - 1], null))
|
|
{
|
|
return; // This should never happen!
|
|
}
|
|
var dialog = new SaveFileDialog
|
|
{
|
|
Filters = Helpers.PngFileFilter,
|
|
Directory = Path.GetDirectoryName(SlicerFile.FileFullPath),
|
|
InitialFileName = $"{Path.GetFileNameWithoutExtension(SlicerFile.FileFullPath)}_thumbnail{_visibleThumbnailIndex}.png"
|
|
};
|
|
|
|
var filepath = await dialog.ShowAsync(this);
|
|
|
|
if (!string.IsNullOrEmpty(filepath))
|
|
{
|
|
SlicerFile.Thumbnails[_visibleThumbnailIndex - 1].Save(filepath);
|
|
}
|
|
}
|
|
|
|
public async void OnClickThumbnailImport()
|
|
{
|
|
if (_visibleThumbnailIndex <= 0) return;
|
|
if (ReferenceEquals(SlicerFile.Thumbnails[_visibleThumbnailIndex - 1], null))
|
|
{
|
|
return; // This should never happen!
|
|
}
|
|
|
|
var dialog = new OpenFileDialog
|
|
{
|
|
Filters = Helpers.ImagesFileFilter,
|
|
AllowMultiple = false
|
|
};
|
|
|
|
var filepath = await dialog.ShowAsync(this);
|
|
|
|
if (filepath is null || filepath.Length <= 0) return;
|
|
int i = (int)(_visibleThumbnailIndex - 1);
|
|
SlicerFile.SetThumbnail(i, filepath[0]);
|
|
VisibleThumbnailImage = SlicerFile.Thumbnails[i].ToBitmap();
|
|
}
|
|
#endregion
|
|
|
|
#region Slicer Properties
|
|
|
|
public async void OnClickPropertiesSaveFile()
|
|
{
|
|
if (SlicerFile?.Configs is null) return;
|
|
|
|
var dialog = new SaveFileDialog
|
|
{
|
|
Filters = Helpers.IniFileFilter,
|
|
Directory = Path.GetDirectoryName(SlicerFile.FileFullPath),
|
|
InitialFileName = $"{Path.GetFileNameWithoutExtension(SlicerFile.FileFullPath)}_properties.ini"
|
|
};
|
|
|
|
var file = await dialog.ShowAsync(this);
|
|
|
|
if (string.IsNullOrEmpty(file)) return;
|
|
|
|
try
|
|
{
|
|
using (TextWriter tw = new StreamWriter(file))
|
|
{
|
|
foreach (var config in SlicerFile.Configs)
|
|
{
|
|
var type = config.GetType();
|
|
tw.WriteLine($"[{type.Name}]");
|
|
foreach (var property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
|
|
{
|
|
if (property.Name.Equals("Item")) continue;
|
|
var value = property.GetValue(config);
|
|
switch (value)
|
|
{
|
|
case null:
|
|
continue;
|
|
case IList list:
|
|
tw.WriteLine($"{property.Name} = {list.Count}");
|
|
break;
|
|
default:
|
|
tw.WriteLine($"{property.Name} = {value}");
|
|
break;
|
|
}
|
|
}
|
|
tw.WriteLine();
|
|
}
|
|
tw.Close();
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
await this.MessageBoxError(e.ToString(), "Error occur while save properties");
|
|
return;
|
|
}
|
|
|
|
var result = await this.MessageBoxQuestion(
|
|
"Properties save was successful. Do you want open the file in the default editor?",
|
|
"Properties save complete");
|
|
if (result != ButtonResult.Yes) return;
|
|
|
|
App.StartProcess(file);
|
|
}
|
|
|
|
public void OnClickPropertiesSaveClipboard()
|
|
{
|
|
if (SlicerFile?.Configs is null) return;
|
|
var sb = new StringBuilder();
|
|
foreach (var config in SlicerFile.Configs)
|
|
{
|
|
var type = config.GetType();
|
|
sb.AppendLine($"[{type.Name}]");
|
|
foreach (var property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
|
|
{
|
|
if (property.Name.Equals("Item")) continue;
|
|
var value = property.GetValue(config);
|
|
switch (value)
|
|
{
|
|
case null:
|
|
continue;
|
|
case IList list:
|
|
sb.AppendLine($"{property.Name} = {list.Count}");
|
|
break;
|
|
default:
|
|
sb.AppendLine($"{property.Name} = {value}");
|
|
break;
|
|
}
|
|
}
|
|
|
|
sb.AppendLine();
|
|
}
|
|
|
|
Application.Current.Clipboard.SetTextAsync(sb.ToString());
|
|
}
|
|
|
|
public void RefreshProperties()
|
|
{
|
|
SlicerProperties.Clear();
|
|
if (SlicerFile.Configs is null) return;
|
|
foreach (var config in SlicerFile.Configs)
|
|
{
|
|
var type = config.GetType();
|
|
foreach (var property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
|
|
{
|
|
if (property.Name.Equals("Item")) continue;
|
|
var value = property.GetValue(config);
|
|
switch (value)
|
|
{
|
|
case null:
|
|
continue;
|
|
case IList list:
|
|
SlicerProperties.Add(new SlicerProperty(property.Name, list.Count.ToString(),
|
|
config.GetType().Name));
|
|
break;
|
|
default:
|
|
SlicerProperties.Add(
|
|
new SlicerProperty(property.Name, value.ToString(), config.GetType().Name));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Current Layer
|
|
|
|
public void RefreshCurrentLayerData()
|
|
{
|
|
|
|
var layer = LayerCache.Layer;
|
|
CurrentLayerProperties.Clear();
|
|
CurrentLayerProperties.Add(new ValueDescription($"{layer.Index}", nameof(layer.Index)));
|
|
CurrentLayerProperties.Add(new ValueDescription($"{Layer.ShowHeight(layer.LayerHeight)}mm", nameof(layer.LayerHeight)));
|
|
CurrentLayerProperties.Add(new ValueDescription($"{Layer.ShowHeight(layer.PositionZ)}mm", nameof(layer.PositionZ)));
|
|
CurrentLayerProperties.Add(new ValueDescription(layer.IsBottomLayer.ToString(), nameof(layer.IsBottomLayer)));
|
|
CurrentLayerProperties.Add(new ValueDescription(layer.IsModified.ToString(), nameof(layer.IsModified)));
|
|
CurrentLayerProperties.Add(new ValueDescription($"{layer.ExposureTime:F2}s", nameof(layer.ExposureTime)));
|
|
|
|
if (SlicerFile.SupportPerLayerSettings)
|
|
{
|
|
|
|
if (SlicerFile.CanUseLayerLiftHeight)
|
|
CurrentLayerProperties.Add(new ValueDescription($"{layer.LiftHeight.ToString(CultureInfo.InvariantCulture)}mm @ {layer.LiftSpeed.ToString(CultureInfo.InvariantCulture)}mm/min", nameof(layer.LiftHeight)));
|
|
if (SlicerFile.CanUseLayerRetractSpeed)
|
|
CurrentLayerProperties.Add(new ValueDescription($"{layer.RetractSpeed}mm/min", nameof(layer.RetractSpeed)));
|
|
|
|
if (SlicerFile.CanUseLayerLightOffDelay)
|
|
CurrentLayerProperties.Add(new ValueDescription($"{layer.LightOffDelay}s", nameof(layer.LightOffDelay)));
|
|
|
|
if (SlicerFile.CanUseLayerWaitTimeBeforeCure)
|
|
CurrentLayerProperties.Add(new ValueDescription($"{layer.WaitTimeBeforeCure}/{layer.WaitTimeAfterCure}/{layer.WaitTimeAfterLift}s", "WaitTimes:"));
|
|
|
|
if (SlicerFile.CanUseLayerLightPWM)
|
|
CurrentLayerProperties.Add(new ValueDescription(layer.LightPWM.ToString(), nameof(layer.LightPWM)));
|
|
}
|
|
var materialMillilitersPercent = layer.MaterialMillilitersPercent;
|
|
if (!float.IsNaN(materialMillilitersPercent))
|
|
{
|
|
CurrentLayerProperties.Add(new ValueDescription($"{layer.MaterialMilliliters}ml ({materialMillilitersPercent:F2}%)", nameof(layer.MaterialMilliliters)));
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
}
|
|
}
|