Files
UVtools/UVtools.Core/Operations/OperationLayerClone.cs
T
Tiago Conceição ea4f7e0400 v3.11.0
- **UI:**
  - (Improvement) Layer navigation load time by parallel `Mat` to `Bitmap` conversion
  - (Improvement) Allow to show exceptions without the stack trace and detailed trigger action by using the `MessageExceiption` (#644)
  - (Improvement) Allow progress to have and display a detailed log (#644)
  - (Improvement) Convert format to another with multiple versions will now only show the possible versions for the extension
- **Suggestion - Wait time before cure:**
  - (Improvement) Set the first wait time based on first valid layer mass rather than use the fixed limit
  - (Improvement) Set zero time to empty and dummy layers
  - (Improvement) When creating the dummy layer also increment the bottom layer count as the created layer count as one
- **PCB Exposure:**
  - (Add) Excellon Drill Format (drl) to cut off holes (Implementation may lack some advanced features, please confirm the result) (#646)
  - (Fix) Arc (G03) with negative offsets (I-/J-) was not drawing the shape correctly
  - (Fix) Implement the rotation for the outline primitive (#645)
- **File formats:**
  - (Improvement) Formats now sanitize the selected version before encode given the file extension, if version is out of range it will force the last known version
  - (Fix) CBDDLP: Remove a table from the file that might cause layer corruption
- (Add) Operations - `AfterCompleteReport` property: Gets or sets an report to show to the user after complete the operation with success
- (Improvement) Suggestion - Wait time after cure: Set zero time to empty and dummy layers
- (Improvement) Slight improvement on the contour intersection check, yields better performance on resin and suction cup detection
- (Improvement) Allow to trigger message boxes from operations and scripts (#644)
- (Upgrade) .NET from 6.0.12 to 6.0.13
2023-01-16 02:03:51 +00:00

158 lines
4.6 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
void Increment()
{
}
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
}