mirror of
https://github.com/riegera2412/UVtools.git
synced 2026-07-08 17:42:31 +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)
153 lines
4.5 KiB
C#
153 lines
4.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.Linq;
|
|
using System.Text;
|
|
using UVtools.Core.FileFormats;
|
|
|
|
namespace UVtools.Core.Operations;
|
|
|
|
|
|
public sealed class OperationLayerClone : Operation
|
|
{
|
|
#region Members
|
|
private uint _clones = 1;
|
|
private bool _keepSamePositionZ;
|
|
|
|
#endregion
|
|
|
|
#region Overrides
|
|
|
|
public override LayerRangeSelection StartLayerRangeSelection => LayerRangeSelection.Current;
|
|
public override bool CanROI => false;
|
|
public override bool PassActualLayerIndex => true;
|
|
public override string IconClass => "fa-solid fa-clone";
|
|
public override string Title => "Clone layers";
|
|
public override string Description =>
|
|
"Clone layers.\n\n" +
|
|
"Useful to increase the height of the model or add additional structure by duplicating layers. For example, can be used to increase the raft height for added stability.";
|
|
public override string ConfirmationText =>
|
|
$"clone layers {LayerIndexStart} through {LayerIndexEnd}, {Clones} time{(Clones != 1 ? "s" : "")}?";
|
|
|
|
public override string ProgressTitle =>
|
|
$"Cloning layers {LayerIndexStart} through {LayerIndexEnd}, {Clones} time{(Clones != 1 ? "s" : "")}";
|
|
|
|
public override string ProgressAction => "Cloned layers";
|
|
|
|
public override bool CanCancel => false;
|
|
|
|
public override bool CanHaveProfiles => false;
|
|
|
|
public override string? ValidateInternally()
|
|
{
|
|
var sb = new StringBuilder();
|
|
if (Clones <= 0)
|
|
{
|
|
sb.AppendLine("Clones must be a positive number");
|
|
}
|
|
|
|
return sb.ToString();
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
var result = $"[Clones: {Clones}]" + LayerRangeString;
|
|
if (!string.IsNullOrEmpty(ProfileName)) result = $"{ProfileName}: {result}";
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
/// <summary>
|
|
/// Gets or sets if cloned layers will keep same position z or get the height rebuilt
|
|
/// </summary>
|
|
public bool KeepSamePositionZ
|
|
{
|
|
get => _keepSamePositionZ;
|
|
set => RaiseAndSetIfChanged(ref _keepSamePositionZ, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets the number of clones
|
|
/// </summary>
|
|
public uint Clones
|
|
{
|
|
get => _clones;
|
|
set
|
|
{
|
|
if(!RaiseAndSetIfChanged(ref _clones, value)) return;
|
|
RaisePropertyChanged(nameof(ExtraLayers));
|
|
}
|
|
}
|
|
|
|
public uint ExtraLayers => (uint)Math.Max(0, ((int)LayerIndexEnd - LayerIndexStart + 1) * _clones);
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
public OperationLayerClone() { }
|
|
|
|
public OperationLayerClone(FileFormat slicerFile) : base(slicerFile) { }
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
protected override bool ExecuteInternally(OperationProgress progress)
|
|
{
|
|
uint totalClones = (LayerIndexEnd - LayerIndexStart + 1) * Clones;
|
|
progress.Reset(ProgressAction, totalClones);
|
|
|
|
var oldLayers = SlicerFile.ToArray();
|
|
|
|
SlicerFile.Init(SlicerFile.LayerCount + totalClones);
|
|
|
|
//var newLayers = new Layer[SlicerFile.LayerCount + totalClones];
|
|
uint newLayerIndex = 0;
|
|
float incrementedPositionZ = 0;
|
|
for (uint layerIndex = 0; layerIndex < oldLayers.Length; layerIndex++)
|
|
{
|
|
SlicerFile[newLayerIndex++] = oldLayers[layerIndex];
|
|
|
|
if (!_keepSamePositionZ && incrementedPositionZ > 0)
|
|
{
|
|
oldLayers[layerIndex].PositionZ += incrementedPositionZ;
|
|
}
|
|
|
|
if (layerIndex < LayerIndexStart || layerIndex > LayerIndexEnd) continue;
|
|
float increment = SlicerFile[layerIndex].RelativePositionZ;
|
|
for (uint i = 0; i < _clones; i++)
|
|
{
|
|
SlicerFile[newLayerIndex] = oldLayers[layerIndex].Clone();
|
|
|
|
if (!_keepSamePositionZ)
|
|
{
|
|
incrementedPositionZ += increment;
|
|
SlicerFile[newLayerIndex].PositionZ += increment * (i + 1);
|
|
}
|
|
|
|
newLayerIndex++;
|
|
progress++;
|
|
}
|
|
}
|
|
|
|
SlicerFile.SuppressRebuildPropertiesWork(() =>
|
|
{
|
|
SlicerFile.Layers = SlicerFile.Layers; // Reassign for update
|
|
});
|
|
|
|
|
|
return !progress.Token.IsCancellationRequested;
|
|
}
|
|
|
|
#endregion
|
|
} |